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_SCENEHOOK 0x00100000 // A scene hook
49 
50 #define GR_PICK_ALL 0x001f3fff // Everything above
51 
53 {
58 };
59 
61 {
67 };
68 
70 {
71 public:
73  { memset(myData, 0, sizeof(myData)); }
74  GR_PickRecord(const int *data)
75  { memcpy(myData, data, sizeof(myData)); }
76  GR_PickRecord(const int *base_data, const int *component_data)
77  {
78  memcpy(myData, base_data, sizeof(myData)/2);
79  memcpy(&myData[3], component_data, sizeof(myData)/2);
80  }
82  const int *component_data)
83  {
84  memcpy(myData, base.myData, sizeof(myData)/2);
85  if (base.isGeometry())
86  {
87  myData[3] = component_data[0] + 1;
88  myData[4] = component_data[1] + 1;
89  myData[5] = component_data[2] + 1;
90  }
91  else
92  memcpy(&myData[3], component_data, sizeof(myData)/2);
93  }
94 
95  void clear()
96  { memset(myData, 0, sizeof(myData)); }
97  bool isSet() const
98  { return (myData[0] != 0); }
99  bool operator==(const GR_PickRecord &cmp) const
100  { return (memcmp(myData, cmp.myData, sizeof(myData)) == 0); }
101  bool operator!=(const GR_PickRecord &cmp) const
102  { return !(*this == cmp); }
103 
104  int getPickType() const
105  { return myData[0]; }
106  bool isGeometry() const
107  { return (myData[0] & GR_PICK_GEOALL) != 0; }
108  bool isHandle() const
109  { return (myData[0] & GR_PICK_HANDLE) != 0; }
110  bool isObject() const
111  { return (myData[0]&(GR_PICK_OBJECT|GR_PICK_XRAY_OBJECT))!=0; }
112  bool isFloor() const
113  { return (myData[0] & GR_PICK_FLOORALL) != 0; }
114  bool isSceneHook() const
115  { return (myData[0] & GR_PICK_SCENEHOOK) != 0; }
116 
117  int getObjectId() const
118  { UT_ASSERT(isObject()); return myData[3]; }
119 
120  int getHandleIndex() const
121  { UT_ASSERT(isHandle()); return myData[1]; }
122  int getHandlePickType() const
123  { UT_ASSERT(!isSet() || isHandle()); return myData[3]; }
124  int getHandleValue1() const
125  { UT_ASSERT(!isSet() || isHandle()); return myData[4]; }
126  int getHandleValue2() const
127  { UT_ASSERT(!isSet() || isHandle()); return myData[5]; }
128 
129  int getFloorId() const
130  { UT_ASSERT(isFloor()); return myData[1]; }
131  int getFloorValue1() const
132  { UT_ASSERT(!isSet() || isFloor()); return myData[3]; }
133  int getFloorValue2() const
134  { UT_ASSERT(!isSet() || isFloor()); return myData[4]; }
135  int getFloorValue3() const
136  { UT_ASSERT(!isSet() || isFloor()); return myData[5]; }
137 
138  int getLookId() const
139  { UT_ASSERT(isGeometry() || isObject()); return myData[1]; }
140  int getDetailIndex() const
141  { UT_ASSERT(isGeometry() || isObject()); return myData[2]; }
142 
143  int getSceneHookId() const
144  { UT_ASSERT(isSceneHook()); return myData[1]; }
145 
146  int getComponentId1() const
147  { UT_ASSERT(isGeometry()||isSceneHook()); return myData[3]-1; }
148  int getComponentId2() const
149  { UT_ASSERT(isGeometry()||isSceneHook()); return myData[4]-1; }
150  int getComponentId3() const
151  { UT_ASSERT(isGeometry()||isSceneHook()); return myData[5]-1; }
152 
153  void changeComponent(int pick, int id1, int id2 = -1, int id3 = -1)
154  {
155  UT_ASSERT(isGeometry());
156  myData[0] = pick;
157  myData[3] = id1 + 1;
158  myData[4] = id2 + 1;
159  myData[5] = id3 + 1;
160  }
161 
162  void dump(std::ostream &os) const;
163 
164  static int comparatorFast(const GR_PickRecord *p1,
165  const GR_PickRecord *p2)
166  {
167  // We are only interested in comparing the first three
168  // values in the pick record. We don't really care
169  // about sorting the specific component ids. This
170  // saves a lot of time on a big sort.
171  return memcmp(p1->myData, p2->myData, sizeof(int)*3);
172  }
173  static int comparatorForDups(const GR_PickRecord *p1,
174  const GR_PickRecord *p2)
175  {
176  // Compare everything, otherwise duplicates may not end
177  // up next to each other.
178  return memcmp(p1->myData, p2->myData, sizeof(int)*6);
179  }
180 
181  static bool areEquivalentEdges(const GR_PickRecord &p1,
182  const GR_PickRecord &p2)
183  {
184  if (p1.getPickType() == GR_PICK_GEOEDGE &&
186  {
187  // Identical edges are equialent.
188  if (p1.myData[1] == p2.myData[1] &&
189  p1.myData[2] == p2.myData[2] &&
190  p1.myData[4] == p2.myData[4] &&
191  p1.myData[5] == p2.myData[5])
192  return true;
193  // Non-identical edges are equivalent if they differ
194  // only in swapping their last two component ids.
195  if (p1.myData[1] == p2.myData[1] &&
196  p1.myData[2] == p2.myData[2] &&
197  p1.myData[4] == p2.myData[5] &&
198  p1.myData[5] == p2.myData[4])
199  return true;
200  }
201 
202  return false;
203  }
204 
205 private:
206  int myData[6];
207 };
209 
210 static inline std::ostream &
211 operator<<(std::ostream &os, const GR_PickRecord &pr)
212 { pr.dump(os); return os; }
213 
214 #endif
void dump(std::ostream &os) const
int getFloorValue2() const
bool isSceneHook() const
int getComponentId1() const
#define GR_PICK_OBJECT
Definition: GR_PickRecord.h:37
int getDetailIndex() const
int getSceneHookId() const
int getHandlePickType() const
#define GR_PICK_SCENEHOOK
Definition: GR_PickRecord.h:48
bool isFloor() const
int getFloorId() const
int getComponentId2() const
#define GR_PICK_GEOALL
Definition: GR_PickRecord.h:34
bool isHandle() const
bool operator!=(const GR_PickRecord &cmp) const
bool isGeometry() const
int getPickType() const
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
bool isObject() const
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
Definition: DataType.h:133
int getObjectId() const
GR_PickRecord(const int *base_data, const int *component_data)
Definition: GR_PickRecord.h:76
#define GR_PICK_GEOEDGE
Definition: GR_PickRecord.h:25
#define GR_API
Definition: GR_API.h:10
int getHandleValue2() const
static int comparatorForDups(const GR_PickRecord *p1, const GR_PickRecord *p2)
#define GR_PICK_HANDLE
Definition: GR_PickRecord.h:36
int getFloorValue1() const
GR_PickGeometry
Definition: GR_PickRecord.h:60
bool operator==(const GR_PickRecord &cmp) const
Definition: GR_PickRecord.h:99
GR_PickRecord(const GR_PickRecord &base, const int *component_data)
Definition: GR_PickRecord.h:81
GR_PickCompMode
Definition: GR_PickRecord.h:52
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:156
#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:74
Definition: format.h:895
bool isSet() const
Definition: GR_PickRecord.h:97
int getHandleIndex() const