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