Point Cloud Library (PCL)  1.9.1-dev
opennurbs_objref.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_OBJREF_INC_)
18 #define ON_OBJREF_INC_
19 
21 {
22 public:
25 
26  void Default();
27 
28  bool Write( ON_BinaryArchive& ) const;
29  bool Read( ON_BinaryArchive& );
30 
31 
32  // If m_point != ON_UNSET_POINT and m_t_type != 0, then
33  // m_t_type, m_t, and m_t_ci record the m_geometry evaluation
34  // parameters of the m_point.
35  //
36  // m_t_type values
37  //
38  // 0: no parameter values; m_t_ci and m_t[] have no meaning.
39  //
40  // 1: m_geometry points to a curve, m_t[0] is a curve
41  // parameter for m_point, and m_t_ci has no meaning.
42  //
43  // 2: m_geometry points to surface or single faced brep,
44  // (m_t[0],m_t[1]) is a surface parameter for m_point,
45  // and m_t_ci has no meaning.
46  // In this case, m_component_index may not be set or,
47  // if m_geometry points to a brep face, m_component_index
48  // may identify the face in the parent brep.
49  //
50  // 3: m_geometry points to a brep edge with an associated
51  // trim and m_t[0] is the edge parameter for m_point.
52  // m_t_ci is the ON_BrepTrim component index and m_t[1]
53  // is the ON_BrepTrim parameter that corresponds to the
54  // edge point. m_s[0] and m_s[1] are normalized parameters.
55  // In this case m_component_index identifies the
56  // the edge in the brep and m_t_ci identifies a trim.
57  //
58  // 4: m_geometry points to a mesh or mesh face and
59  // m_t_ci identifies the mesh face.
60  // If the face is a triangle, the barycentric coordinates
61  // of m_point are(m_t[0], m_t[1], m_t[2]) and m_t[3] is zero.
62  // If the mesh face is a quadrangle, the barycentric coordinates
63  // of m_point are (m_t[0], m_t[1], m_t[2], m_t[3]) and at least
64  // one of the coordinates is zero. In both cases, the point
65  // can be evaluated using the formula
66  // m_t[0]*mesh.m_V[f.vi[0]] + ... + m_t[3]*mesh.m_V[f.vi[3]],
67  // where f = mesh.m_F[m_component_index.m_index].
68  // In this case, if m_geometry points to a mesh, then
69  // m_component_index != m_t_ci.
70  //
71  // 5: m_geometry points to a mesh or mesh edge and m_t_ci
72  // identifies the mesh edge. The normalized coordinate of
73  // the point on the mesh edge is m_t[0]. The point can be evaluated
74  // using the formula
75  // m_t[0]*mesh.m_V[v0] + (1.0-m_t[0])*mesh.m_V[v1],
76  // where v0 and v1 are the indices of the mesh vertices at
77  // the edge's ends.
78  // In this case, if m_geometry points to a mesh, then
79  // m_component_index != m_t_ci.
80  //
81  // 6: m_geometry points to a NURBS cage and (m_t[0],m_t[1],m_t[2])
82  // are cage evaluation parameters.
83  //
84  // 7: m_geometry points to an annotation object and m_t_ci identifies
85  // a point on the annotation object.
86  //
87  // 8: m_geometry points to a mesh or mesh vertex object and m_t_ci
88  // identifies a vertex on the mesh object.
89  //
90  int m_t_type;
91 private:
92  int m_reserved; // for future use to record snap info.
93 public:
94  double m_t[4];
95  ON_Interval m_s[3]; // curve/surface/cage domains
96  ON_COMPONENT_INDEX m_t_ci; // Not necesarily the same as m_component_index
97  // See comment above for details.
98 };
99 
100 class ON_CLASS ON_ObjRef_IRefID
101 {
102 public:
104  ~ON_ObjRef_IRefID();
105 
106  bool Write(ON_BinaryArchive&) const;
107  bool Read(ON_BinaryArchive&);
108 
109  void Default();
110 
111  // m_iref_uuid is the CRhinoInstanceObject's uuid stored
112  // in its ON_3dmObjectAttributes.m_uuid.
114 
115  // m_iref_xform is the value stored in ON_InstanceRef.m_xform.
117 
118  // m_idef_uuid is the instance definition id stored in
119  // ON_InstanceRef.m_instance_definition_uuid and
120  // ON_InstanceDefinition.m_uuid.
122 
123  // m_geometry_index is the index of the uuid of the pertinant
124  // piece of geometry in the ON_InstanceRef.m_object_uuid[]
125  // array. This index is identical to the index of the
126  // geometry's CRhinoObject in the
127  // CRhinoInstanceDefinition.m_objects[] array.
129 
130  // m_geometry_xform is the transformation to map the
131  // base geometry to world coordinates. If the
132  // instance reference is not nested, then
133  // m_geometry_xform = m_iref_xform. If the instance
134  // reference is nested, then
135  // m_geometry_xform = m_iref_xform * .... * T1
136  // where the Ts are the transformations from the children.
138 
139  // If this ON_ObjRef_IRefID is the first entry in the
140  // ON_ObjRef.m__iref[] array, then it references a "real"
141  // piece of geometry (not a nested instance reference).
142  // If the reference is to a subobject of the real piece
143  // of geometry, then m_component_index records
144  // the subobject index.
145  // In all other cases, m_component_index is not set.
146  ON_COMPONENT_INDEX m_component_index;
147 
148  // If this ON_ObjRef_IRefID is the first entry in the
149  // ON_ObjRef.m__iref[] array, then it references a "real"
150  // piece of geometry (not a nested instance reference).
151  // If there is an evaluation parameter for the geometry,
152  // it is saved in m_evp.
153  // In all other cases, m_evp is not set.
155 };
156 
157 #if defined(ON_DLL_TEMPLATE)
158 // This stuff is here because of a limitation in the way Microsoft
159 // handles templates and DLLs. See Microsoft's knowledge base
160 // article ID Q168958 for details.
161 #pragma warning( push )
162 #pragma warning( disable : 4231 )
163 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_ObjRef_IRefID>;
164 #pragma warning( pop )
165 #endif
166 
167 class ON_CLASS ON_ObjRef
168 {
169 public:
170  ON_ObjRef();
171  ON_ObjRef(const ON_ObjRef& src);
172  ON_ObjRef& operator=(const ON_ObjRef& src);
173  ~ON_ObjRef();
174 
175  void Destroy();
176  bool Write( ON_BinaryArchive& ) const;
177  bool Read( ON_BinaryArchive& );
178 
179  // In Rhino, this uuid is the persistent id of the CRhinoObject
180  // that owns the referenced geometry. The value of the
181  // CRhinoObject id is stored on ON_3dmObjectAttributes.m_uuid.
183 
184  // The m_geometry and m_parent_geometry pointers are runtime values
185  // that point to the object being referenced. The destructor
186  // ~ON_ObjRef does not delete the objects these pointers reference.
187  //
188  // m_geometry_type records the type of geometry m_geometry points to.
189  //
190  // When the referenced object is a subobject, like a part of a brep
191  // or mesh, m_geometry points to the subobject and m_parent_geometry
192  // points to the parent object, like the brep or mesh. In this case
193  // m_component_index records the location of the subobject.
194  //
195  // Parts of instance reference objects:
196  // When the geometry belongs to an instance reference
197  // m_uuid is the id of the CRhinoInstanceObject,
198  // m_parent_geometry points to the instance definition
199  // geometry or a transformed proxy, and m_geometry points
200  // to the piece of m_geometry. The m__iref[] array records
201  // the connection between the instance reference and the
202  // geometry the ON_ObjRef refers to.
203  //
204  // For example if the ON_ObjRef is to an edge of a brep in
205  // and instance reference, m_uuid would be the Rhino id of
206  // the CRhinoInstanceObject, m_parent_geometry would point
207  // to a, possibly proxy, ON_Brep object, m_geometry would point
208  // to the ON_BrepEdge in the ON_Brep, m_component_index would
209  // record the edge's index in the ON_Brep.m_E[] array and
210  // m_geometry_type would be ON::curve_object or ON::brep_edge.
211  // m__iref->Last() would contain the information about the
212  // top level instance reference. If the brep was at the bottom
213  // of a chain of instance references, m__iref[0] would be the
214  // reference that immediately used the brep.
217  ON_COMPONENT_INDEX m_component_index;
219 
220  // If m_runtime_sn > 0, then it is the value of a Rhino object's
221  // CRhinoObject::m_runtime_object_serial_number field.
222  // The serial number is used instead of the pointer to
223  // prevent crashes in cases when the CRhinoObject is deleted
224  // but an ON_ObjRef continues to reference the Rhino object.
225  // The value of m_runtime_sn is not saved in archives because
226  // it generally changes if you save and reload an archive.
227  unsigned int m_runtime_sn;
228 
229  // If m_point != ON_UNSET_POINT, then the ObjRef resolves to
230  // a point location. The point location is saved here so the
231  // information can persist if the object itself vanishes.
233 
234  // If the point was the result of some type of object snap, then
235  // the object snap is recorded here.
236  ON::osnap_mode m_osnap_mode;
237 
238  // If m_point != ON_UNSET_POINT and m_evp.m_t_type != 0, then
239  // m_evp records the records the m_geometry evaluation
240  // parameters for the m_point.
242 
243  // If m__iref[] is not empty, then m_uuid identifies
244  // and instance reference (ON_InstanceRef/CRhinoInstanceObject)
245  // and m__iref[] records the chain of instance references from
246  // the base piece of geometry to the instance reference.
247  // The top level instance reference is last in the list.
249 
250  /*
251  Description:
252  Expert user tool to decrement reference counts. Most
253  users will never need to call this tool. It is called
254  by ~ON_ObjRef and used in rare cases when a
255  ON_ObjRef needs to reference an object only by uuid
256  and component index.
257  */
258  void DecrementProxyReferenceCount();
259 
260  /*
261  Description:
262  Expert user tool to initialize the ON_ObjRef
263  m__proxy1, m__proxy2, and m__proxy_ref_count fields.
264  */
265  void SetProxy(
266  ON_Object* proxy1,
267  ON_Object* proxy2,
268  bool bCountReferences
269  );
270 
271  bool SetParentIRef( const ON_InstanceRef& iref,
272  ON_UUID iref_id,
273  int idef_geometry_index
274  );
275 
276  /*
277  Returns:
278  0: This ON_ObjRef is not counting references.
279  >0: Number of references.
280  */
281  int ProxyReferenceCount() const;
282 
283  /*
284  Parameters:
285  proxy_object_index - [in] 1 or 2.
286  Returns:
287  A pointer to the requested proxy object.
288  */
289  const ON_Object* ProxyObject(int proxy_object_index) const;
290 
291  /*
292  Description:
293  This tool is used in rare situations when the object ids
294  stored in the uuid list need to be remapped.
295  Parameters:
296  uuid_remap - [in]
297  Is it critical that uuid_remap[] be sorted with respect
298  to ON_UuidPair::CompareFirstUuid.
299  */
300  void RemapObjectId( const ON_SimpleArray<ON_UuidPair>& uuid_remap );
301 
302 private:
303  // In simple (and the most common) cases where m_geometry
304  // is managed by something outside of the ON_ObjRef class,
305  // m__proxy_ref_count is NULL. In this case, the m__proxy1
306  // and m__proxy2 pointers may still be used to store
307  // references to a parent object.
308  //
309  // In cases when the referenced geometry pointed at by
310  // m_geometry is not being managed by another class,
311  // m_proxy1 and m_proxy2 are not NULL and *m_proxy_ref_count
312  // counts the number of ON_ObjRef classes that refer to m__proxy1/2.
313  // When the last ON_ObjRef is destroyed, m__proxy1/2 is deleted.
314  // When the ON_ObjRef is using reference counting and managing
315  // m__proxy1/2, m_geometry points to some part of m__proxy1/2 and
316  // m_geometry is destroyed when m__proxy1/2 is destroyed.
317  //
318  // The convention is to use m__proxy1 to store
319  // ON_MeshVertex/Edge/FaceRefs and CRhinoPolyEdges
320  // and m__proxy2 to store transformed copies if instance
321  // definition geometry.
322  ON_Object* m__proxy1;
323  ON_Object* m__proxy2;
324  int* m__proxy_ref_count;
325  //ON__INT_PTR m_reserved;
326 };
327 
328 #if defined(ON_DLL_TEMPLATE)
329 // This stuff is here because of a limitation in the way Microsoft
330 // handles templates and DLLs. See Microsoft's knowledge base
331 // article ID Q168958 for details.
332 #pragma warning( push )
333 #pragma warning( disable : 4231 )
334 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_ObjRef>;
335 #pragma warning( pop )
336 #endif
337 
338 #endif
ON_UUID m_uuid
const ON_Geometry * m_geometry
unsigned int m_runtime_sn
ON_3dPoint m_point
ON_SimpleArray< ON_ObjRef_IRefID > m__iref
ON_COMPONENT_INDEX m_component_index
const ON_Geometry * m_parent_geometry
ON_ObjRefEvaluationParameter m_evp
ON_COMPONENT_INDEX m_component_index
ON::osnap_mode m_osnap_mode
ON_ObjRefEvaluationParameter m_evp