HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PickRecord.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_PickRecord (C++)
7  *
8  * COMMENTS:
9  * Holds information about a single picked entity.
10  *
11  */
12 
13 #ifndef __GR_PickRecord_h__
14 #define __GR_PickRecord_h__
15 
16 #include "GR_API.h"
17 #include <UT/UT_Assert.h>
18 #include <SYS/SYS_TypeDecorate.h>
19 #include <iosfwd>
20 #include <string.h>
21 
22 // Entities we can pick:
23 #define GR_PICK_GEOPOINT 0x00000001 // GEO_Point
24 #define GR_PICK_GUIDEPOINT 0x00000002 // "guide" points (sphere, tube...)
25 #define GR_PICK_GEOEDGE 0x00000004 // edge between two GEO_Points
26 #define GR_PICK_GUIDEEDGE 0x00000008 // "guide" edges (sphere, tube...)
27 #define GR_PICK_PRIMITIVE 0x00000010 // Primitives
28 #define GR_PICK_POINTNORMAL 0x00000020 // GEO_Point normal
29 #define GR_PICK_PRIMNORMAL 0x00000040 // Primitive normals
30 #define GR_PICK_BREAKPOINT 0x00000080 // primitive break points
31 #define GR_PICK_MIDPOINT 0x00000100 // midpoint of a GEO_Edge
32 #define GR_PICK_VERTEX 0x00000200 // GEO_Vertex
33 #define GR_PICK_STATEPOINT 0x00000400 // point drawn by the current state
34 #define GR_PICK_GEOALL 0x000007ff // all of the geometry pick types
35 
36 #define GR_PICK_HANDLE 0x00000800
37 #define GR_PICK_OBJECT 0x00001000
38 #define GR_PICK_XRAY_OBJECT 0x00002000
39 
40 // WARNING: If you change these, update any matching defines in the $SHS/glsl
41 // directory or snapping to the construction plane will break.
42 #define GR_PICK_FLOOREDGE 0x00010000
43 #define GR_PICK_FLOORPOINT 0x00020000
44 #define GR_PICK_UVTILEEDGE 0x00040000
45 #define GR_PICK_UVTILEPOINT 0x00080000
46 #define GR_PICK_FLOORALL 0x000f0000 // all of the floor pick types
47 
48 #define GR_PICK_ALL 0x000f1fff // Everything above
49 
51 {
52 public:
54  { memset(myData, 0, sizeof(myData)); }
55  GR_PickRecord(const int *data)
56  { memcpy(myData, data, sizeof(myData)); }
57  GR_PickRecord(const int *base_data, const int *component_data)
58  {
59  memcpy(myData, base_data, sizeof(myData)/2);
60  memcpy(&myData[3], component_data, sizeof(myData)/2);
61  }
63  const int *component_data)
64  {
65  memcpy(myData, base.myData, sizeof(myData)/2);
66  if (base.isGeometry())
67  {
68  myData[3] = component_data[0] + 1;
69  myData[4] = component_data[1] + 1;
70  myData[5] = component_data[2] + 1;
71  }
72  else
73  memcpy(&myData[3], component_data, sizeof(myData)/2);
74  }
75 
76  void clear()
77  { memset(myData, 0, sizeof(myData)); }
78  bool isSet() const
79  { return (myData[0] != 0); }
80  bool operator==(const GR_PickRecord &cmp) const
81  { return (memcmp(myData, cmp.myData, sizeof(myData)) == 0); }
82  bool operator!=(const GR_PickRecord &cmp) const
83  { return !(*this == cmp); }
84 
85  int getPickType() const
86  { return myData[0]; }
87  bool isGeometry() const
88  { return (myData[0] & GR_PICK_GEOALL) != 0; }
89  bool isHandle() const
90  { return (myData[0] & GR_PICK_HANDLE) != 0; }
91  bool isObject() const
92  { return (myData[0]&(GR_PICK_OBJECT|GR_PICK_XRAY_OBJECT))!=0; }
93  bool isFloor() const
94  { return (myData[0] & GR_PICK_FLOORALL) != 0; }
95 
96  int getObjectId() const
97  { UT_ASSERT(isObject()); return myData[3]; }
98 
99  int getHandleIndex() const
100  { UT_ASSERT(isHandle()); return myData[1]; }
101  int getHandlePickType() const
102  { UT_ASSERT(!isSet() || isHandle()); return myData[3]; }
103  int getHandleValue1() const
104  { UT_ASSERT(!isSet() || isHandle()); return myData[4]; }
105  int getHandleValue2() const
106  { UT_ASSERT(!isSet() || isHandle()); return myData[5]; }
107 
108  int getFloorId() const
109  { UT_ASSERT(isFloor()); return myData[1]; }
110  int getFloorValue1() const
111  { UT_ASSERT(!isSet() || isFloor()); return myData[3]; }
112  int getFloorValue2() const
113  { UT_ASSERT(!isSet() || isFloor()); return myData[4]; }
114  int getFloorValue3() const
115  { UT_ASSERT(!isSet() || isFloor()); return myData[5]; }
116 
117  int getLookId() const
118  { UT_ASSERT(isGeometry() || isObject()); return myData[1]; }
119  int getDetailIndex() const
120  { UT_ASSERT(isGeometry() || isObject()); return myData[2]; }
121 
122  int getComponentId1() const
123  { UT_ASSERT(isGeometry()); return myData[3]-1; }
124  int getComponentId2() const
125  { UT_ASSERT(isGeometry()); return myData[4]-1; }
126  int getComponentId3() const
127  { UT_ASSERT(isGeometry()); return myData[5]-1; }
128 
129  void changeComponent(int pick, int id1, int id2 = -1, int id3 = -1)
130  {
131  UT_ASSERT(isGeometry());
132  myData[0] = pick;
133  myData[3] = id1 + 1;
134  myData[4] = id2 + 1;
135  myData[5] = id3 + 1;
136  }
137 
138  void dump(std::ostream &os) const;
139 
140  static int comparatorFast(const GR_PickRecord *p1,
141  const GR_PickRecord *p2)
142  {
143  // We are only interested in comparing the first three
144  // values in the pick record. We don't really care
145  // about sorting the specific component ids. This
146  // saves a lot of time on a big sort.
147  return memcmp(p1->myData, p2->myData, sizeof(int)*3);
148  }
149  static int comparatorForDups(const GR_PickRecord *p1,
150  const GR_PickRecord *p2)
151  {
152  // Compare everything, otherwise duplicates may not end
153  // up next to each other.
154  return memcmp(p1->myData, p2->myData, sizeof(int)*6);
155  }
156 
157  static bool areEquivalentEdges(const GR_PickRecord &p1,
158  const GR_PickRecord &p2)
159  {
160  if (p1.getPickType() == GR_PICK_GEOEDGE &&
162  {
163  // Identical edges are equialent.
164  if (p1.myData[1] == p2.myData[1] &&
165  p1.myData[2] == p2.myData[2] &&
166  p1.myData[4] == p2.myData[4] &&
167  p1.myData[5] == p2.myData[5])
168  return true;
169  // Non-identical edges are equivalent if they differ
170  // only in swapping their last two component ids.
171  if (p1.myData[1] == p2.myData[1] &&
172  p1.myData[2] == p2.myData[2] &&
173  p1.myData[4] == p2.myData[5] &&
174  p1.myData[5] == p2.myData[4])
175  return true;
176  }
177 
178  return false;
179  }
180 
181 private:
182  int myData[6];
183 };
185 
186 static inline std::ostream &
187 operator<<(std::ostream &os, const GR_PickRecord &pr)
188 { pr.dump(os); return os; }
189 
190 #endif
void dump(std::ostream &os) const
int getFloorValue2() const
int getComponentId1() const
#define GR_PICK_OBJECT
Definition: GR_PickRecord.h:37
int getDetailIndex() const
int getHandlePickType() const
bool isFloor() const
Definition: GR_PickRecord.h:93
int getFloorId() const
int getComponentId2() const
#define GR_PICK_GEOALL
Definition: GR_PickRecord.h:34
bool isHandle() const
Definition: GR_PickRecord.h:89
bool operator!=(const GR_PickRecord &cmp) const
Definition: GR_PickRecord.h:82
bool isGeometry() const
Definition: GR_PickRecord.h:87
int getPickType() const
Definition: GR_PickRecord.h:85
bool isObject() const
Definition: GR_PickRecord.h:91
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
Definition: DataType.h:133
int getObjectId() const
Definition: GR_PickRecord.h:96
GR_PickRecord(const int *base_data, const int *component_data)
Definition: GR_PickRecord.h:57
#define GR_PICK_GEOEDGE
Definition: GR_PickRecord.h:25
#define GR_API
Definition: GR_API.h:10
GLboolean * data
Definition: glcorearb.h:130
int getHandleValue2() const
static int comparatorForDups(const GR_PickRecord *p1, const GR_PickRecord *p2)
#define GR_PICK_HANDLE
Definition: GR_PickRecord.h:36
int cmp(T a, T b)
Definition: ImathFun.h:119
int getFloorValue1() const
bool operator==(const GR_PickRecord &cmp) const
Definition: GR_PickRecord.h:80
GR_PickRecord(const GR_PickRecord &base, const int *component_data)
Definition: GR_PickRecord.h:62
int getFloorValue3() const
void changeComponent(int pick, int id1, int id2=-1, int id3=-1)
int getComponentId3() const
int getHandleValue1() const
SYS_DECLARE_IS_POD(GR_PickRecord)
static bool areEquivalentEdges(const GR_PickRecord &p1, const GR_PickRecord &p2)
static int comparatorFast(const GR_PickRecord *p1, const GR_PickRecord *p2)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126
#define GR_PICK_FLOORALL
Definition: GR_PickRecord.h:46
#define GR_PICK_XRAY_OBJECT
Definition: GR_PickRecord.h:38
int getLookId() const
GR_PickRecord(const int *data)
Definition: GR_PickRecord.h:55
bool isSet() const
Definition: GR_PickRecord.h:78
int getHandleIndex() const
Definition: GR_PickRecord.h:99