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