opennurbs_objref.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #if !defined(ON_OBJREF_INC_)
00018 #define ON_OBJREF_INC_
00019 
00020 class ON_CLASS ON_ObjRefEvaluationParameter
00021 {
00022 public:
00023   ON_ObjRefEvaluationParameter();
00024   ~ON_ObjRefEvaluationParameter();
00025 
00026   void Default();
00027 
00028   bool Write( ON_BinaryArchive& ) const;
00029   bool Read( ON_BinaryArchive& );
00030 
00031 
00032   // If m_point != ON_UNSET_POINT and m_t_type != 0, then
00033   // m_t_type, m_t, and m_t_ci record the m_geometry evaluation
00034   // parameters of the m_point.
00035   //
00036   //  m_t_type values
00037   //
00038   //  0: no parameter values; m_t_ci and m_t[] have no meaning.
00039   //
00040   //  1: m_geometry points to a curve, m_t[0] is a curve
00041   //     parameter for m_point, and m_t_ci has no meaning.
00042   //
00043   //  2: m_geometry points to surface or single faced brep,
00044   //     (m_t[0],m_t[1]) is a surface parameter for m_point,
00045   //     and m_t_ci has no meaning.
00046   //     In this case, m_component_index may not be set or,
00047   //     if m_geometry points to a brep face, m_component_index
00048   //     may identify the face in the parent brep.
00049   //
00050   //  3: m_geometry points to a brep edge with an associated
00051   //     trim and m_t[0] is the edge parameter for m_point.
00052   //     m_t_ci is the ON_BrepTrim component index and m_t[1]
00053   //     is the ON_BrepTrim parameter that corresponds to the
00054   //     edge point.  m_s[0] and m_s[1] are normalized parameters.
00055   //     In this case m_component_index identifies the
00056   //     the edge in the brep and m_t_ci identifies a trim.
00057   //
00058   //  4: m_geometry points to a mesh or mesh face and 
00059   //     m_t_ci identifies the mesh face.
00060   //     If the face is a triangle, the barycentric coordinates
00061   //     of m_point are(m_t[0], m_t[1], m_t[2]) and m_t[3] is zero. 
00062   //     If the mesh face is a quadrangle, the barycentric coordinates
00063   //     of m_point are (m_t[0], m_t[1], m_t[2], m_t[3]) and at least 
00064   //     one of the coordinates is zero.  In both cases, the point
00065   //     can be evaluated using the formula
00066   //     m_t[0]*mesh.m_V[f.vi[0]] + ... + m_t[3]*mesh.m_V[f.vi[3]],
00067   //     where f = mesh.m_F[m_component_index.m_index].
00068   //     In this case, if m_geometry points to a mesh, then
00069   //     m_component_index !=  m_t_ci.
00070   //
00071   //  5: m_geometry points to a mesh or mesh edge and m_t_ci
00072   //     identifies the mesh edge. The normalized coordinate of
00073   //     the point on the mesh edge is m_t[0].  The point can be evaluated
00074   //     using the formula
00075   //     m_t[0]*mesh.m_V[v0] + (1.0-m_t[0])*mesh.m_V[v1],
00076   //     where v0 and v1 are the indices of the mesh vertices at
00077   //     the edge's ends.
00078   //     In this case, if m_geometry points to a mesh, then
00079   //     m_component_index !=  m_t_ci.
00080   //
00081   //  6: m_geometry points to a NURBS cage and (m_t[0],m_t[1],m_t[2])
00082   //     are cage evaluation parameters.
00083   //
00084   //  7: m_geometry points to an annotation object and m_t_ci identifies
00085   //     a point on the annotation object.
00086   //
00087   //  8: m_geometry points to a mesh or mesh vertex object and m_t_ci
00088   //     identifies a vertex on the mesh object.
00089   //
00090   int m_t_type;
00091 private:
00092   int m_reserved; // for future use to record snap info.
00093 public:
00094   double m_t[4];
00095   ON_Interval m_s[3]; // curve/surface/cage domains
00096   ON_COMPONENT_INDEX m_t_ci; // Not necesarily the same as m_component_index
00097                              // See comment above for details.
00098 };
00099 
00100 class ON_CLASS ON_ObjRef_IRefID
00101 {
00102 public:
00103   ON_ObjRef_IRefID();
00104   ~ON_ObjRef_IRefID();
00105 
00106   bool Write(ON_BinaryArchive&) const;
00107   bool Read(ON_BinaryArchive&);
00108 
00109   void Default();
00110 
00111   // m_iref_uuid is the CRhinoInstanceObject's uuid stored
00112   // in its ON_3dmObjectAttributes.m_uuid.
00113   ON_UUID  m_iref_uuid;
00114 
00115   // m_iref_xform is the value stored in ON_InstanceRef.m_xform.
00116   ON_Xform m_iref_xform;
00117 
00118   // m_idef_uuid is the instance definition id stored in
00119   // ON_InstanceRef.m_instance_definition_uuid and
00120   // ON_InstanceDefinition.m_uuid.
00121   ON_UUID  m_idef_uuid;
00122 
00123   // m_geometry_index is the index of the uuid of the pertinant
00124   // piece of geometry in the ON_InstanceRef.m_object_uuid[] 
00125   // array.  This index is identical to the index of the
00126   // geometry's CRhinoObject in the
00127   // CRhinoInstanceDefinition.m_objects[] array.
00128   int m_idef_geometry_index;
00129 
00130   // m_geometry_xform is the transformation to map the
00131   // base geometry to world coordinates.  If the
00132   // instance reference is not nested, then
00133   // m_geometry_xform = m_iref_xform.  If the instance
00134   // reference is nested, then
00135   //   m_geometry_xform = m_iref_xform * .... * T1
00136   // where the Ts are the transformations from the children.
00137   ON_Xform m_geometry_xform;
00138 
00139   // If this ON_ObjRef_IRefID is the first entry in the 
00140   // ON_ObjRef.m__iref[] array, then it references a "real"
00141   // piece of geometry (not a nested instance reference).  
00142   // If the reference is to a subobject of the real piece
00143   // of geometry, then m_component_index records
00144   // the subobject index.
00145   // In all other cases, m_component_index is not set.
00146   ON_COMPONENT_INDEX m_component_index;
00147 
00148   // If this ON_ObjRef_IRefID is the first entry in the 
00149   // ON_ObjRef.m__iref[] array, then it references a "real"
00150   // piece of geometry (not a nested instance reference).  
00151   // If there is an evaluation parameter for the geometry,
00152   // it is saved in m_evp.
00153   // In all other cases, m_evp is not set.
00154   ON_ObjRefEvaluationParameter m_evp;
00155 };
00156 
00157 #if defined(ON_DLL_TEMPLATE)
00158 // This stuff is here because of a limitation in the way Microsoft
00159 // handles templates and DLLs.  See Microsoft's knowledge base 
00160 // article ID Q168958 for details.
00161 #pragma warning( push )
00162 #pragma warning( disable : 4231 )
00163 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_ObjRef_IRefID>;
00164 #pragma warning( pop )
00165 #endif
00166 
00167 class ON_CLASS ON_ObjRef
00168 {
00169 public:
00170   ON_ObjRef();
00171   ON_ObjRef(const ON_ObjRef& src);
00172   ON_ObjRef& operator=(const ON_ObjRef& src);
00173   ~ON_ObjRef();
00174 
00175   void Destroy();
00176   bool Write( ON_BinaryArchive& ) const;
00177   bool Read( ON_BinaryArchive& );
00178 
00179   // In Rhino, this uuid is the persistent id of the CRhinoObject
00180   // that owns the referenced geometry.  The value of the
00181   // CRhinoObject id is stored on ON_3dmObjectAttributes.m_uuid.
00182   ON_UUID m_uuid;
00183 
00184   // The m_geometry and m_parent_geometry pointers are runtime values
00185   // that point to the object being referenced.  The destructor 
00186   // ~ON_ObjRef  does not delete the objects these pointers reference.
00187   //
00188   // m_geometry_type records the type of geometry m_geometry points to.
00189   //
00190   // When the referenced object is a subobject, like a part of a brep 
00191   // or mesh, m_geometry points to the subobject and m_parent_geometry 
00192   // points to the parent object, like the brep or mesh.  In this case
00193   // m_component_index records the location of the subobject.
00194   //
00195   // Parts of instance reference objects:
00196   //   When the geometry belongs to an instance reference
00197   //   m_uuid is the id of the CRhinoInstanceObject,
00198   //   m_parent_geometry points to the instance definition
00199   //   geometry or a transformed proxy, and m_geometry points
00200   //   to the piece of m_geometry.  The m__iref[] array records
00201   //   the connection between the instance reference and the
00202   //   geometry the ON_ObjRef refers to.
00203   //
00204   //   For example if the ON_ObjRef is to an edge of a brep in
00205   //   and instance reference, m_uuid would be the Rhino id of
00206   //   the CRhinoInstanceObject, m_parent_geometry would point
00207   //   to a, possibly proxy, ON_Brep object, m_geometry would point
00208   //   to the ON_BrepEdge in the ON_Brep, m_component_index would
00209   //   record the edge's index in the ON_Brep.m_E[] array and 
00210   //   m_geometry_type would be ON::curve_object or ON::brep_edge.
00211   //   m__iref->Last() would contain the information about the
00212   //   top level instance reference.  If the brep was at the bottom
00213   //   of a chain of instance references, m__iref[0] would be the
00214   //   reference that immediately used the brep.
00215   const ON_Geometry* m_geometry;
00216   const ON_Geometry* m_parent_geometry;
00217   ON_COMPONENT_INDEX m_component_index;
00218   int m_geometry_type;
00219 
00220   // If m_runtime_sn > 0, then it is the value of a Rhino object's
00221   // CRhinoObject::m_runtime_object_serial_number field.
00222   // The serial number is used instead of the pointer to
00223   // prevent crashes in cases when the CRhinoObject is deleted
00224   // but an ON_ObjRef continues to reference the Rhino object.
00225   // The value of m_runtime_sn is not saved in archives because
00226   // it generally changes if you save and reload an archive.
00227   unsigned int m_runtime_sn;
00228 
00229   // If m_point != ON_UNSET_POINT, then the ObjRef resolves to 
00230   // a point location.  The point location is saved here so the
00231   // information can persist if the object itself vanishes.
00232   ON_3dPoint m_point;
00233 
00234   // If the point was the result of some type of object snap, then
00235   // the object snap is recorded here. 
00236   ON::osnap_mode m_osnap_mode;
00237 
00238   // If m_point != ON_UNSET_POINT and m_evp.m_t_type != 0, then
00239   // m_evp records the records the m_geometry evaluation
00240   // parameters for the m_point.
00241   ON_ObjRefEvaluationParameter m_evp;
00242 
00243   // If m__iref[] is not empty, then m_uuid identifies
00244   // and instance reference (ON_InstanceRef/CRhinoInstanceObject)
00245   // and m__iref[] records the chain of instance references from
00246   // the base piece of geometry to the instance reference.
00247   // The top level instance reference is last in the list.
00248   ON_SimpleArray<ON_ObjRef_IRefID> m__iref;
00249 
00250   /*
00251   Description:
00252     Expert user tool to decrement reference counts.  Most
00253     users will never need to call this tool.  It is called
00254     by ~ON_ObjRef and used in rare cases when a
00255     ON_ObjRef needs to reference an object only by uuid
00256     and component index.
00257   */
00258   void DecrementProxyReferenceCount();
00259 
00260   /*
00261   Description:
00262     Expert user tool to initialize the ON_ObjRef 
00263     m__proxy1, m__proxy2, and m__proxy_ref_count fields.
00264   */
00265   void SetProxy( 
00266           ON_Object* proxy1, 
00267           ON_Object* proxy2, 
00268           bool bCountReferences 
00269           );
00270 
00271   bool SetParentIRef( const ON_InstanceRef& iref,
00272                       ON_UUID iref_id,
00273                       int idef_geometry_index
00274                       );
00275 
00276   /*
00277   Returns:
00278      0:  This ON_ObjRef is not counting references.
00279     >0:  Number of references.
00280   */
00281   int ProxyReferenceCount() const;
00282 
00283   /*
00284   Parameters:
00285     proxy_object_index - [in] 1 or 2.
00286   Returns:
00287     A pointer to the requested proxy object.
00288   */
00289   const ON_Object* ProxyObject(int proxy_object_index) const;
00290 
00291   /*
00292   Description:
00293     This tool is used in rare situations when the object ids 
00294     stored in the uuid list need to be remapped.
00295   Parameters:
00296     uuid_remap - [in]
00297       Is it critical that uuid_remap[] be sorted with respect
00298       to ON_UuidPair::CompareFirstUuid.
00299   */
00300   void RemapObjectId( const ON_SimpleArray<ON_UuidPair>& uuid_remap );
00301 
00302 private:
00303   // In simple (and the most common) cases where m_geometry
00304   // is managed by something outside of the ON_ObjRef class,
00305   // m__proxy_ref_count is NULL.  In this case, the m__proxy1
00306   // and m__proxy2 pointers may still be used to store 
00307   // references to a parent object.
00308   //
00309   // In cases when the referenced geometry pointed at by
00310   // m_geometry is not being managed by another class,
00311   // m_proxy1 and m_proxy2 are not NULL and *m_proxy_ref_count 
00312   // counts the number of ON_ObjRef classes that refer to m__proxy1/2.
00313   // When the last ON_ObjRef is destroyed, m__proxy1/2 is deleted.
00314   // When the ON_ObjRef is using reference counting and managing
00315   // m__proxy1/2, m_geometry points to some part of m__proxy1/2 and
00316   // m_geometry is destroyed when m__proxy1/2 is destroyed.
00317   //
00318   // The convention is to use m__proxy1 to store
00319   // ON_MeshVertex/Edge/FaceRefs and CRhinoPolyEdges
00320   // and m__proxy2 to store transformed copies if instance
00321   // definition geometry.  
00322   ON_Object* m__proxy1;
00323   ON_Object* m__proxy2;
00324   int* m__proxy_ref_count;
00325   //ON__INT_PTR m_reserved;
00326 };
00327 
00328 #if defined(ON_DLL_TEMPLATE)
00329 // This stuff is here because of a limitation in the way Microsoft
00330 // handles templates and DLLs.  See Microsoft's knowledge base 
00331 // article ID Q168958 for details.
00332 #pragma warning( push )
00333 #pragma warning( disable : 4231 )
00334 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_ObjRef>;
00335 #pragma warning( pop )
00336 #endif
00337 
00338 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:02