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(OPENNURBS_MESH_INC_) 00018 #define OPENNURBS_MESH_INC_ 00019 00021 // 00022 // Class ON_Mesh 00023 // 00024 class ON_CLASS ON_MeshParameters 00025 { 00026 // surface meshing perameters 00027 public: 00028 00029 enum MESH_STYLE 00030 { 00031 // All of these enum values must be in the range 0-255 because 00032 // unsigned chars are use for storage in some locations. 00033 unset_mesh_style = 0, 00034 render_mesh_fast = 1, // Use ON_MeshParameters::FastRenderMesh 00035 render_mesh_quality = 2, // Use ON_MeshParameters::QualityRenderMesh 00036 // 3 - 8 reserved for future predefined render mesh styles 00037 render_mesh_custom = 9,// Use ON_3dmSettings::m_CustomRenderMeshSettings 00038 render_mesh_per_object = 10 // Use ON_Object::GetMeshParameters(). 00039 }; 00040 00041 /* 00042 Description: 00043 Parameters that create render meshes where meshing 00044 speed is prefered over mesh quality. 00045 */ 00046 static 00047 const ON_MeshParameters FastRenderMesh; 00048 00049 /* 00050 Description: 00051 Parameters that create render meshes where mesh quality 00052 is prefered over meshing speed. 00053 */ 00054 static 00055 const ON_MeshParameters QualityRenderMesh; 00056 00057 /* 00058 Description: 00059 Get a value to use for tolerance based on the relative_tolerance 00060 and actual size. 00061 Parameters: 00062 relative_tolerance - [in] 00063 See m_relative_tolerance field 00064 actual_size - [in] 00065 Diagonal ov object bounding box or some similar measure of 00066 an object's 3d size. 00067 Returns: 00068 A value that can be used for m_tolerance if no 00069 user specified value is available. 00070 */ 00071 static 00072 double Tolerance( double relative_tolerance, double actual_size ); 00073 00074 /* 00075 Description: 00076 Get a value to use for minimum edge length base on max_edge_length 00077 and tolerance settings. 00078 Parameters: 00079 max_edge_length - [in] 00080 3d maximum edge length used to create mesh. 00081 tolerance - [in] 00082 3d distance tolerance used to create mesh. 00083 Returns: 00084 A value that can be used for m_min_edge_length if no 00085 user specified value is available. 00086 */ 00087 static 00088 double MinEdgeLength( double max_edge_length, double tolerance ); 00089 00090 ON_MeshParameters(); 00091 ~ON_MeshParameters(); 00092 // C++ default works fine // ON_MeshParameters(const ON_MeshParameters& ); 00093 // C++ default works fine // ON_MeshParameters& operator=(const ON_MeshParameters&); 00094 00095 bool operator!=(const ON_MeshParameters&) const; 00096 bool operator==(const ON_MeshParameters&) const; 00097 00098 // compares with mesh's mesh parameters 00099 bool operator==(const ON_Mesh&) const; 00100 bool operator!=(const ON_Mesh&) const; 00101 00102 void Dump( ON_TextLog& test_log ) const; 00103 00104 void Default(); 00105 00106 /* 00107 Description: 00108 Tool for provding a simple slider interface. 00109 Parameters: 00110 density - [in] 0.0 <= density <= 1.0 00111 0 quickly creates coarse meshes. 00112 1 creates accurate meshes but takes lots of time. 00113 */ 00114 void Set( 00115 double density, 00116 double min_edge_length = 0.0001 00117 ); 00118 00119 /* 00120 Description: 00121 Sets the meshing parameters to ON_MeshParameters::FastRenderMesh. 00122 */ 00123 ON_DEPRECATED 00124 void JaggedAndFasterMeshParameters(); 00125 00126 /* 00127 Description: 00128 Sets the meshing parameters to ON_MeshParameters::QualityRenderMesh. 00129 */ 00130 ON_DEPRECATED 00131 void SmoothAndSlowerMeshParameters(); 00132 00133 /* 00134 Description: 00135 Sets the meshing parameters to create the default 00136 analysis mesh. 00137 */ 00138 void DefaultAnalysisMeshParameters(); 00139 00140 // Compare() ignores weld and curvature settings 00141 // Ignores m_min_tolerance setting. 00142 int Compare( const ON_MeshParameters& ) const; 00143 00144 /* 00145 Description: 00146 Compares all meshing parameters that control mesh geometry. 00147 Does not compare m_bCustomSettings, m_bComputeCurvature, 00148 m_bDoublePrecision, m_min_tolerance, and m_texture_range. 00149 */ 00150 int CompareGeometrySettings( const ON_MeshParameters& ) const; 00151 00152 00153 bool Write( ON_BinaryArchive& ) const; 00154 bool Read( ON_BinaryArchive& ); 00155 ON__UINT32 DataCRC(ON__UINT32) const; 00156 00157 00158 // Meshing happens in two stages. The first stage creates a 00159 // rectangular grid. The second stage refines the grid until 00160 // the mesh meets all meshing requirements. The third stage 00161 // combines coincident vertices if the resulting mesh is a composite. 00162 00163 bool m_bCustomSettings; // false - if these settings were used to create 00164 // a mesh and the app settings don't match, 00165 // then remesh the object using the app 00166 // settings. 00167 // true - these settings are customized for a 00168 // particular object - ignore app mesh 00169 // settings. 00170 00171 bool m_bComputeCurvature; // false - (default) - ON_Mesh::m_K[] not computed 00172 // true - ON_Mesh::m_K[] computed 00173 00174 bool m_bSimplePlanes; // false - (default) planar surfaces are meshed 00175 // using the controls below. 00176 // true - planar surfaces are meshed using 00177 // minimal number of triangles and 00178 // aspect/edge controls are ignored. 00179 00180 bool m_bRefine; // false - skip stage 2 00181 // true - (default) do stage 2 00182 00183 bool m_bJaggedSeams; // false - (default) edges of meshes of joined 00184 // b-rep faces match with no gaps or 00185 // "T" joints. 00186 // true - faces in b-reps are meshed independently. 00187 // This is faster but results in gaps and 00188 // "T" joints along seams between faces. 00189 00190 bool m_bDoublePrecision; // false - (default) the mesh vertices will be 00191 // float precision values in the m_V[] array. 00192 // true - The mesh vertices will be double precision 00193 // values in the DoublePrecisionVertices() 00194 // array. Float precision values will also 00195 // be returned in the m_V[] array. 00196 bool m_bCustomSettingsEnabled; // false - if these settings should be ignored 00197 // when used as per object custom render mesh 00198 // settings. 00199 // true - ignore these settings. 00200 unsigned char m_mesher; // 0 = slow mesher, 1 = fast mesher 00201 00202 int m_texture_range; // 1: normalized 00203 // 00204 // each face has a normalized texture range 00205 // [0,1]x[0,1]. 00206 // 00207 // 2: packed normalized (default) 00208 // 00209 // each face in a polysurface is assigned 00210 // a texture range that is a subrectangle 00211 // of [0,1]x[0,1]. The subrectangles are 00212 // mutually disjoint and packed into 00213 // into [0,1]x[0,1] in a way that minimizes 00214 // distortion and maximizes the coverage 00215 // of [0,1]x[0,1]. (This texture style 00216 // is suitable for creating texture maps 00217 // with popular 3D painting programs.) 00218 00219 private: 00220 unsigned int m_reserved2; 00221 public: 00222 00223 // These controls are used in both stages 00224 00225 double m_tolerance; // maximum distance from center of edge to surface 00226 00227 00228 double m_relative_tolerance; // If 0 < m_relative_tolerance < 1, 00229 double m_min_tolerance; // then the maximum distance from the 00230 // center of an edge to the surface will 00231 // be <= T, where T is the larger of 00232 // (m_min_tolerance,d*m_relative_tolerance), 00233 // where d is an esimate of the size of the 00234 // object being meshed. 00235 00236 00237 double m_min_edge_length; // edges shorter than m_min_edge_length will 00238 // not be split even if the do not meet other 00239 // meshing requirements 00240 00241 double m_max_edge_length; // edges longer than m_max_edge_length will 00242 // be split even when they meet all other 00243 // meshing requirements 00244 00245 // These controls are used during stage 1 to generate the grid 00246 double m_grid_aspect_ratio; // desired aspect ratio of quads in grid 00247 // 0.0 = any aspect ratio is acceptable 00248 // values >0 and < sqrt(2) are treated as sqrt(2) 00249 int m_grid_min_count; // minimum number of quads in initial grid 00250 int m_grid_max_count; // desired masimum number of quads in initial grid 00251 double m_grid_angle; // (in radians) maximum angle between surface 00252 // normal evaluated at adjacent vertices. 00253 // 0.0 is treated as pi. 00254 double m_grid_amplification; // The parameters above generate a grid. 00255 // If you want fewer quads, set m_grid_amplification 00256 // to a value < 1. If you want more quads, 00257 // set m_grid_amplification to a value > 1. 00258 // default = 1 and values <= 0 are treated as 1. 00259 00260 // These controls are used during stage 2 to refine the grid 00261 double m_refine_angle; // (in radians) maximum angle in radians between 00262 // surface normal evaluated at adjacent vertices. 00263 00264 // These controls are used during stage 3 00265 int m_face_type; // 0 = mixed triangle and quads 00266 // 1 = all triangles 00267 // 2 = all quads 00268 private: 00269 unsigned int m_reserved3; 00270 }; 00271 00272 class ON_CLASS ON_MeshCurvatureStats 00273 { 00274 public: 00275 ON_MeshCurvatureStats(); 00276 ~ON_MeshCurvatureStats(); 00277 ON_MeshCurvatureStats(const ON_MeshCurvatureStats& ); 00278 ON_MeshCurvatureStats& operator=(const ON_MeshCurvatureStats&); 00279 00280 void Destroy(); 00281 void EmergencyDestroy(); 00282 00283 bool Set( ON::curvature_style, 00284 int, // Kcount, 00285 const ON_SurfaceCurvature*, // K[] 00286 const ON_3fVector*, // N[] surface normals needed for normal sectional curvatures 00287 double = 0.0 // if > 0, value is used for "infinity" 00288 ); 00289 00290 bool Write( ON_BinaryArchive& ) const; 00291 bool Read( ON_BinaryArchive& ); 00292 00293 ON::curvature_style m_style; 00294 00295 double m_infinity; // curvature values >= this are considered infinite 00296 // and not used to compute the m_average or m_adev 00297 int m_count_infinite; // number of "infinte" values 00298 int m_count; // count of "finite" values 00299 double m_mode; // mode of "finite" values 00300 double m_average; // average of "finite" values 00301 double m_adev; // average deviation of "finite" values 00302 00303 ON_Interval m_range; 00304 }; 00305 00307 // 00308 // Class ON_MeshTopology 00309 // 00310 00311 struct ON_MeshTopologyVertex 00312 { 00313 // m_tope_count = number of topological edges that begin or 00314 // end at this topological vertex. 00315 int m_tope_count; 00316 00317 // m_topei[] is an array of length m_tope_count with the indices 00318 // of the topological edges that begin or end at this topological 00319 // vertex. Generally, these edges are listed in no particular 00320 // order. If you want the edges listed "radially", then call 00321 // ON_MeshTopology::SortVertexEdges. 00322 const int* m_topei; 00323 00324 // m_v_count = number of ON_Mesh vertices that correspond to 00325 // this topological vertex. 00326 int m_v_count; 00327 00328 // m_vi[] is an array of length m_v_count with the indices of the 00329 // ON_Mesh vertices that correspond to this topological vertex. 00330 const int* m_vi; 00331 }; 00332 00333 struct ON_MeshTopologyEdge 00334 { 00335 // m_topvi[] = indices of the topological verteices where the 00336 // edge begins and ends. 00337 int m_topvi[2]; 00338 00339 // m_topf_count = number of topological faces tat share this topological edge 00340 int m_topf_count; 00341 00342 // m_topfi[] is an array of length m_topf_count with the indices of the 00343 // topological faces that share this topological edge. 00344 const int* m_topfi; 00345 }; 00346 00347 struct ON_CLASS ON_MeshTopologyFace 00348 { 00349 /* 00350 m_topei[] = indices of the topological edges that bound the face. 00351 If m_topei[2] = m_topei[3], then the face is a triangle, otherwise 00352 the face is a quad. 00353 00354 NOTE WELL: 00355 The topological edge with index m_topei[k] ENDS at the 00356 vertex corresponding to ON_MeshFace.vi[k]. So, ... 00357 00358 If the face is a quad, (ON_MeshFace.vi[2]!=ON_MeshFace.vi[3]), 00359 the topological edge with index m_topei[0] STARTS at 00360 ON_MeshFace.vi[3] and ENDS at ON_MeshFace.vi[0], 00361 the topological edge with index m_topei[1] STARTS at 00362 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1], 00363 the topological edge with index m_topei[2] STARTS at 00364 ON_MeshFace.vi[1] and ENDS at ON_MeshFace.vi[2], and 00365 the topological edge with index m_topei[3] STARTS at 00366 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1], 00367 00368 If the face is a triangle, (ON_MeshFace.vi[2]==ON_MeshFace.vi[3]), 00369 the topological edge with index m_topei[0] STARTS at 00370 ON_MeshFace.vi[2] and ENDS at ON_MeshFace.vi[0], 00371 the topological edge with index m_topei[1] STARTS at 00372 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1], 00373 the topological edge with index m_topei[2] STARTS at 00374 ON_MeshFace.vi[1] and ENDS at ON_MeshFace.vi[2]. 00375 */ 00376 int m_topei[4]; 00377 00378 /* 00379 If m_reve[i] is 0, then the orientation of the edge matches the 00380 orientation of the face. If m_reve[i] is 1, then the orientation 00381 of the edge is opposite that of the face. 00382 */ 00383 char m_reve[4]; 00384 00385 /* 00386 Description: 00387 A topological mesh face is a valid triangle if m_topei[0], 00388 m_topei[1], m_topei[2] are distinct edges and 00389 m_topei[3]=m_topei[2]. 00390 Returns: 00391 True if face is a triangle. 00392 */ 00393 bool IsTriangle() const; 00394 00395 /* 00396 Description: 00397 A topological mesh face is a valid quad if m_topei[0], 00398 m_topei[1], m_topei[2], and m_topei[3] are distinct edges. 00399 Returns: 00400 True if face is a quad. 00401 */ 00402 bool IsQuad() const; 00403 00404 /* 00405 Description: 00406 A topological mesh face is valid if m_topei[0], m_topei[1], 00407 and m_topei[2] are mutually distinct, and m_topei[3] is 00408 either equal to m_topei[2] or mutually distinct from the 00409 first three indices. 00410 Returns: 00411 True if face is valid. 00412 */ 00413 bool IsValid( ) const; 00414 }; 00415 00416 class ON_CLASS ON_MeshFace 00417 { 00418 public: 00419 int vi[4]; // vertex index - vi[2]==vi[3] for tirangles 00420 00421 /* 00422 Returns: 00423 True if vi[2] == vi[3]; 00424 Remarks: 00425 Assumes the face is valid. 00426 */ 00427 bool IsTriangle() const; 00428 00429 /* 00430 Returns: 00431 True if vi[2] != vi[3]; 00432 Remarks: 00433 Assumes the face is valid. 00434 */ 00435 bool IsQuad() const; 00436 00437 /* 00438 Description: 00439 Determine if a face is valid by checking that the vertices 00440 are distinct. 00441 Parameters: 00442 mesh_vertex_count - [in] 00443 number of vertices in the mesh 00444 V - [in] 00445 optional array of mesh_vertex_count vertex locations. 00446 Returns: 00447 true 00448 The face is valid. 00449 false 00450 The face is not valid. It may be possible to repair the 00451 face by calling ON_MeshFace::Repair(). 00452 */ 00453 bool IsValid( 00454 int mesh_vertex_count 00455 ) const; 00456 bool IsValid( 00457 int mesh_vertex_count, 00458 const ON_3fPoint* V 00459 ) const; 00460 bool IsValid( 00461 int mesh_vertex_count, 00462 const ON_3dPoint* V 00463 ) const; 00464 00465 /* 00466 Description: 00467 Reverses the order of the vertices in v[]. 00468 vi[0] is not changed. 00469 */ 00470 void Flip(); 00471 00472 /* 00473 Description: 00474 If IsValid() returns false, then you can use Repair() 00475 to attempt to create a valid triangle. 00476 Parameters: 00477 mesh_vertex_count - [in] 00478 number of vertices in the mesh 00479 V - [in] 00480 optional array of mesh_vertex_count vertex locations. 00481 Returns: 00482 true 00483 repair was successful and v[0], v[1], vi[2] have distinct valid 00484 values and v[2] == v[3]. 00485 false 00486 this face's vi[] values cannot be repaired 00487 */ 00488 bool Repair( 00489 int mesh_vertex_count 00490 ); 00491 bool Repair( 00492 int mesh_vertex_count, 00493 const ON_3fPoint* V 00494 ); 00495 bool Repair( 00496 int mesh_vertex_count, 00497 const ON_3dPoint* V 00498 ); 00499 00500 /* 00501 Description: 00502 Compute the face normal 00503 Parameters: 00504 dV - [in] double precision vertex array for the mesh 00505 fV - [in] float precision vertex array for the mesh 00506 FN - [out] face normal 00507 Returns: 00508 true if FN is valid. 00509 */ 00510 bool ComputeFaceNormal( const ON_3dPoint* dV, ON_3dVector& FN ) const; 00511 bool ComputeFaceNormal( const ON_3fPoint* fV, ON_3dVector& FN ) const; 00512 }; 00513 00514 struct ON_MeshFaceSide 00515 { 00516 int vi[2]; // vertex indices 00517 int fi; // mesh m_F[] array face index 00518 unsigned char side; // edge connects mesh m_V[m_F[fi].vi[side]] and m_V[m_F[fi].vi[(side+1)%4]] 00519 unsigned char dir; // 0 = counterclockwise, 1 = clockwise (reversed) 00520 unsigned short value; // Set to zero by ON_Mesh::GetFaceSideList(). Can be used as needed. 00521 }; 00522 00523 00524 /* 00525 Description: 00526 Sort the sides[] array of ON_MeshFaceSide structs in dictionary 00527 order by "vi[0]", "vi[1]", "fi", and "side" values. 00528 Paramters: 00529 sides_count - [in] 00530 number of elements in the sides[] array. 00531 sides - [in/out] 00532 Remarks: 00533 The function is thread safe. 00534 */ 00535 ON_DECL 00536 void ON_SortMeshFaceSidesByVertexIndex( 00537 int sides_count, 00538 struct ON_MeshFaceSide* sides 00539 ); 00540 00541 struct ON_MeshPart 00542 { 00543 // ON_Mesh faces with indices fi[0] <= i < fi[1] reference 00544 // vertices with indices vi[0] <= j < vi[1]. 00545 int vi[2]; // subinterval of mesh m_V[] array 00546 int fi[2]; // subinterval of mesh m_F[] array 00547 int vertex_count; // = vi[1] - vi[0]; 00548 int triangle_count; // tris + 2*quads >= fi[1] - fi[0] 00549 }; 00550 00551 #if defined(ON_DLL_TEMPLATE) 00552 // This stuff is here because of a limitation in the way Microsoft 00553 // handles templates and DLLs. See Microsoft's knowledge base 00554 // article ID Q168958 for details. 00555 #pragma warning( push ) 00556 #pragma warning( disable : 4231 ) 00557 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshFace>; 00558 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyVertex>; 00559 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyEdge>; 00560 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyFace>; 00561 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<struct ON_MeshPart>; 00562 #pragma warning( pop ) 00563 #endif 00564 00565 class ON_CLASS ON_MeshTopology 00566 { 00567 // A mesh topology class is always associated with an ON_Mesh 00568 // and can be retrieved by calling ON_Mesh::Topology() 00569 public: 00570 ON_MeshTopology(); 00571 ~ON_MeshTopology(); 00572 00573 bool IsValid() const; 00574 00575 void Dump( ON_TextLog& ) const; 00576 00578 // The parent ON_Mesh geometry used to compute this mesh topology. 00579 const ON_Mesh* m_mesh; 00580 00582 // number of topoligical vertices (<= m_mesh.VertexCount()) 00583 int TopVertexCount() const; 00584 00586 // number of topoligical edges 00587 int TopEdgeCount() const; 00588 00590 // number of topoligical faces (same as m_mesh.FaceCount()) 00591 int TopFaceCount() const; 00592 00593 /* 00594 Description: 00595 Get a vertex reference to a mesh vertex index. 00596 Parameters: 00597 ci - [in] component index with type mesh_vertex or meshtop_vertex. 00598 Returns: 00599 a reference to the vertex 00600 */ 00601 class ON_MeshVertexRef VertexRef(ON_COMPONENT_INDEX ci) const; 00602 00603 class ON_MeshVertexRef VertexRef(int topv_index) const; 00604 00605 /* 00606 Description: 00607 Get an edge reference. 00608 Parameters: 00609 ci - [in] component index with type meshtop_edge. 00610 Returns: 00611 a reference to the edge 00612 */ 00613 class ON_MeshEdgeRef EdgeRef(ON_COMPONENT_INDEX ci) const; 00614 00615 class ON_MeshEdgeRef EdgeRef(int tope_index) const; 00616 00617 /* 00618 Description: 00619 Get a face reference from a mesh face index. 00620 Parameters: 00621 ci - [in] component index with type mesh_face. 00622 Returns: 00623 a reference to the face. 00624 Remarks: 00625 The OM_Mesh.m_F[] and ON_MeshTopology.m_topf[] arrays 00626 are parallel arrays; corresponding faces have identical 00627 indices. 00628 */ 00629 class ON_MeshFaceRef FaceRef(ON_COMPONENT_INDEX ci) const; 00630 00631 class ON_MeshFaceRef FaceRef(int topf_index) const; 00632 00633 00634 /* 00635 Description: 00636 Get the 3d point location of a vertex. 00637 Parameters: 00638 topv_index - [in]; 00639 Returns: 00640 Location of vertex. 00641 */ 00642 ON_3fPoint TopVertexPoint( 00643 int topv_index 00644 ) const; 00645 00646 /* 00647 Description: 00648 Get the 3d line along an edge. 00649 Parameters: 00650 tope_index - [in]; 00651 Returns: 00652 Line along edge. If input is not valid, 00653 the line.from and to are ON_UNSET_POINT 00654 */ 00655 ON_Line TopEdgeLine( 00656 int tope_index 00657 ) const; 00658 00660 // returns index of edge that connects topological vertices 00661 // returns -1 if no edge is found. 00662 int TopEdge( 00663 int vtopi0, 00664 int vtopi1 // ON_MeshTopology vertex topology indices 00665 ) const; 00666 00668 // returns ON_MeshTopology vertex topology index of a face 00669 // corner. The face is triangle iv TopFaceVertex(2) = TopFaceVertex(3) 00670 bool GetTopFaceVertices( 00671 int topfi, // ON_MeshTopology face topology index (= ON_Mesh face index) 00672 int topvi[4] // ON_MeshTopology vertex indices returned here 00673 ) const; 00674 00675 /* 00676 Description: 00677 Sort the m_topei[] list of a mesh topology vertex so that 00678 the edges are in radial order. The "const" is a white 00679 lie to make this function easier to call. 00680 Parameter: 00681 topvi - [in] index of vertex in m_topv[] array. 00682 Remarks: 00683 A nonmanifold edge is treated as a boundary edge with respect 00684 to sorting. If any boundary or nonmanifold edges end at the 00685 vertex, then the first edge will be a boundary or nonmanifold 00686 edge. 00687 */ 00688 bool SortVertexEdges( int topvi ) const; 00689 00690 /* 00691 Description: 00692 Sort the m_topei[] list of every mesh topology vertex so 00693 that the edges are in radial order. The "const" is a white 00694 lie to make this function easier to call. 00695 Remarks: 00696 Same as 00697 for ( int topvi = 0; topvi < m_topv.Count(); topvi++ ) 00698 SortVertexEdges(topvi); 00699 */ 00700 bool SortVertexEdges() const; 00701 00702 /* 00703 Description: 00704 Returns true if the topological vertex is hidden. 00705 Parameters: 00706 topvi - [in] mesh topology vertex index. 00707 Returns: 00708 True if mesh topology vertex is hidden. 00709 Remarks: 00710 The mesh topology vertex is hidden if and only if 00711 all the ON_Mesh vertices it represents is hidden. 00712 */ 00713 bool TopVertexIsHidden( int topvi ) const; 00714 00715 /* 00716 Description: 00717 Returns true if the topological edge is hidden. 00718 Parameters: 00719 topei - [in] mesh topology edge index. 00720 Returns: 00721 True if mesh topology edge is hidden. 00722 Remarks: 00723 The mesh topology edge is hidden if and only if 00724 either of its mesh topology vertices is hidden. 00725 */ 00726 bool TopEdgeIsHidden( int topei ) const; 00727 00728 /* 00729 Description: 00730 Returns true if the topological face is hidden. 00731 Parameters: 00732 topfi - [in] mesh topology face index. 00733 Returns: 00734 True if mesh topology face is hidden. 00735 Remarks: 00736 The mesh topology face is hidden if and only if 00737 any of its mesh topology edges are hidden. 00738 */ 00739 bool TopFaceIsHidden( int topfi ) const; 00740 00742 // m_topv_map[] has length m_mesh.VertexCount() and 00743 // m_topv[m_topv_map[vi]] is the topological mesh vertex that is assocated 00744 // the with the mesh vertex m_mesh.m_V[vi]. 00745 ON_SimpleArray<int> m_topv_map; 00746 00748 // Array of topological mesh vertices. See the comments in the definition 00749 // of ON_MeshTopologyVertex for details. 00750 ON_SimpleArray<ON_MeshTopologyVertex> m_topv; 00751 00753 // Array of topological mesh edges. See the comments in the definition 00754 // of ON_MeshTopologyEdge for details. 00755 ON_SimpleArray<ON_MeshTopologyEdge> m_tope; 00756 00758 // Array of topological mesh faces. The topological face 00759 // m_topf[fi] corresponds to the mesh face ON_Mesh.m_F[fi]. 00760 // See the comments in the definition of ON_MeshTopologyFace 00761 // for details. To get the indices of the mesh topology 00762 // vertices at the face corners use 00763 // topvi = m_topv_map[m_mesh.m_F[fi].vi[n]] 00764 ON_SimpleArray<ON_MeshTopologyFace> m_topf; 00765 00766 /* 00767 Description: 00768 Expert user function for efficiently getting the 00769 integer arrays used by the ON_MeshTopologyVertex 00770 and ON_MeshTopologyEdge classes. 00771 Parameters: 00772 count - [in] number of integers in array 00773 Returns: 00774 pointer to integer array. The array memory 00775 will be freed by ~ON_MeshTopology() 00776 */ 00777 int* GetIntArray(int count); 00778 00779 private: 00780 friend class ON_Mesh; 00781 00782 bool Create(); 00783 void Destroy(); 00784 void EmergencyDestroy(); 00785 00786 // efficient workspaces for 00787 struct memchunk 00788 { 00789 struct memchunk* next; 00790 } *m_memchunk; 00791 00792 // NOTE: this field is a bool with valid values of 0 and 1. 00793 volatile int m_b32IsValid; // sizeof(m_bIsValid) must be 4 - it is used in sleep locks. 00794 // 0: Not Valid 00795 // 1: Valid 00796 // -1: Sleep locked - ON_Mesh::Topology() calculation is in progress 00797 int WaitUntilReady(int sleep_value) const; // waits until m_b32IsValid >= 0 00798 00799 private: 00800 // no implementation 00801 ON_MeshTopology(const ON_MeshTopology&); 00802 ON_MeshTopology& operator=(const ON_MeshTopology&); 00803 }; 00804 00805 struct ON_MeshNgon 00806 { 00807 // Number of N-gon corners (N >= 3) 00808 int N; 00809 00810 // N-gon vertex indices 00811 // An array of N indices into the mesh's m_V[] vertex array. 00812 // If the ON_MeshNgon is returned by the ON_MeshNgonList::AddNgon() 00813 // function, then the memory for vi is managed by the ON_MeshNgonList 00814 // class. 00815 int* vi; 00816 00817 // N-gon face indices 00818 // An array of N indices into the mesh's m_F[] face array. 00819 // Often, only N-2 indices are used. Unused indices are set to -1. 00820 // If the ON_MeshNgon is returned by the ON_MeshNgonList::AddNgon() 00821 // function, then the memory for fi is managed by the ON_MeshNgonList 00822 // class. 00823 int* fi; 00824 }; 00825 00826 class ON_CLASS ON_MeshNgonList 00827 { 00828 public: 00829 ON_MeshNgonList(); 00830 ~ON_MeshNgonList(); 00831 ON_MeshNgonList(const ON_MeshNgonList&); 00832 ON_MeshNgonList& operator=(const ON_MeshNgonList&); 00833 00834 00835 /* 00836 Description: 00837 Add an N-gon to the list 00838 Parameters: 00839 N - [in] number of vertices ( >= 5) 00840 vi - [in] array of N vertex indices into the mesh's m_V[] array. 00841 fi - [in] array of N face indices into the mesh's m_F[] array. 00842 Unused indices are set to -1. In many cases 00843 there are N-2 valid indices and these are triangles. 00844 Remarks: 00845 Adding an N-gon may invalidate any pointers previously 00846 returned by Ngon. 00847 */ 00848 bool AddNgon(int N, const int* vi, const int* fi); 00849 struct ON_MeshNgon* AddNgon(int N); 00850 00851 /* 00852 Returns: 00853 Number of Ngons 00854 */ 00855 int NgonCount() const; 00856 00857 /* 00858 Parameters: 00859 Ngon_index - [in] zero based index 00860 Returns: 00861 NULL or a pointer to the Ngon 00862 */ 00863 ON_MeshNgon* Ngon(int Ngon_index) const; 00864 00865 /* 00866 Description: 00867 If you know about how many ngons you will need, 00868 then use the function to reserve space for them. 00869 */ 00870 bool ReserveNgonCapacity(int capacity); 00871 00872 /* 00873 Description: 00874 Destroy N-gon list 00875 */ 00876 void Destroy(); 00877 00878 /* 00879 Returns: 00880 Approximate number of bytes used by this class. 00881 */ 00882 unsigned int SizeOf() const; 00883 00884 private: 00885 int m_ngons_count; 00886 int m_ngons_capacity; 00887 ON_MeshNgon* m_ngons; 00888 struct ON_NGON_MEMBLK* m_memblk_list; 00889 }; 00890 00891 class ON_CLASS ON_MeshPartition 00892 { 00893 public: 00894 ON_MeshPartition(); 00895 ~ON_MeshPartition(); 00896 00897 // maximum number of vertices in a partition 00898 int m_partition_max_vertex_count; 00899 // maximum number of triangles in a partition (quads count as 2 triangles) 00900 int m_partition_max_triangle_count; 00901 00902 // Partition i uses 00903 // vertices m_V[j] where 00904 // 00905 // m_part[i].vi[0] <= j < m_part[i].vi[1] 00906 // 00907 // and uses faces m_F[k] where 00908 // 00909 // m_part[i].fi[0] <= k < m_part[i].fi[1] 00910 ON_SimpleArray<struct ON_MeshPart> m_part; 00911 }; 00912 00913 00914 00915 class ON_CLASS ON_MappingTag 00916 { 00917 public: 00918 ON_MappingTag(); 00919 void Default(); 00920 bool Write(ON_BinaryArchive&) const; 00921 bool Read(ON_BinaryArchive&); 00922 void Dump( ON_TextLog& ) const; 00923 void Transform( const ON_Xform& xform ); 00924 void Set(const ON_TextureMapping& mapping); 00925 00926 /* 00927 Description: 00928 Sets the tag to the value the meshes have that 00929 come out of ON_Brep::CreateMesh(). 00930 */ 00931 void SetDefaultSurfaceParameterMappingTag(); 00932 00933 int Compare( const ON_MappingTag& other, 00934 bool bCompareId = true, 00935 bool bCompareCRC = true, 00936 bool bCompareXform = true 00937 ) const; 00938 00939 /* 00940 Returns: 00941 True if the mapping tag is set. 00942 */ 00943 bool IsSet() const; 00944 00945 /* 00946 Returns: 00947 True if the mapping tag is for a mapping with 00948 type ON_TextureMapping::srfp_mapping with 00949 m_uvw = identity. 00950 */ 00951 bool IsDefaultSurfaceParameterMapping() const; 00952 00953 // Identifies the mapping used to create the texture 00954 // coordinates and records transformations applied 00955 // to the mesh after the texture coordinates were 00956 // calculated. If the texture mapping does not 00957 // change when the mesh is transformed, then set 00958 // m_mesh_xform to zero so that compares will work right. 00959 // 00960 // 00961 ON_UUID m_mapping_id; // ON_TextureMapping::m_mapping_id 00962 ON_TextureMapping::TYPE m_mapping_type; // ON_TextureMapping::m_type 00963 ON__UINT32 m_mapping_crc; // ON_TextureMapping::MappingCRC() 00964 ON_Xform m_mesh_xform; 00965 }; 00966 00967 class ON_CLASS ON_TextureCoordinates 00968 { 00969 public: 00970 ON_TextureCoordinates(); 00971 00972 ON_MappingTag m_tag; 00973 int m_dim; // 1, 2, or 3 00974 ON_SimpleArray<ON_3fPoint> m_T; // texture coordinates 00975 }; 00976 00977 00978 #if defined(ON_DLL_TEMPLATE) 00979 // This stuff is here because of a limitation in the way Microsoft 00980 // handles templates and DLLs. See Microsoft's knowledge base 00981 // article ID Q168958 for details. 00982 #pragma warning( push ) 00983 #pragma warning( disable : 4231 ) 00984 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MappingTag>; 00985 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_TextureCoordinates>; 00986 #pragma warning( pop ) 00987 #endif 00988 00989 class ON_CLASS ON_Mesh : public ON_Geometry 00990 { 00991 ON_OBJECT_DECLARE(ON_Mesh); 00992 public: 00993 ON_Mesh(); 00994 ON_Mesh( 00995 int initial_face_array_capacity, // initial face array capacity 00996 int initial_vertex_array_capacity, // initial vertex array capacity 00997 bool has_vertex_normals, // true if mesh has vertex normals 00998 bool has_texture_coordinates // true if mesh has texture coordinates 00999 ); 01000 ON_Mesh( const ON_Mesh& ); 01001 ON_Mesh& operator=( const ON_Mesh& ); 01002 ~ON_Mesh(); 01003 01004 // Override of virtual ON_Object::MemoryRelocate 01005 void MemoryRelocate(); 01006 01007 // virtual ON_Object::DestroyRuntimeCache override 01008 void DestroyRuntimeCache( bool bDelete = true ); 01009 01010 void Destroy(); 01011 void EmergencyDestroy(); // Call only when memory used by this class's 01012 // members will soon become invalid for reasons 01013 // beyond your control. EmergencyDestroy() zeros 01014 // anything that could possibly cause 01015 // ~ON_Mesh() to crash. Calling 01016 // EmergencyDestroy() under normal conditions 01017 // will result in ~ON_Mesh() leaking 01018 // memory. 01019 01020 void DestroyTree( bool bDeleteTree = true ); 01021 01023 // ON_Object overrides 01024 01025 // virtual ON_Object::SizeOf override 01026 unsigned int SizeOf() const; 01027 01028 // virtual ON_Object::DataCRC override 01029 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 01030 01031 /* 01032 Description: 01033 Tests an object to see if its data members are correctly 01034 initialized. 01035 Parameters: 01036 text_log - [in] if the object is not valid and text_log 01037 is not NULL, then a brief englis description of the 01038 reason the object is not valid is appened to the log. 01039 The information appended to text_log is suitable for 01040 low-level debugging purposes by programmers and is 01041 not intended to be useful as a high level user 01042 interface tool. 01043 Returns: 01044 @untitled table 01045 true object is valid 01046 false object is invalid, uninitialized, etc. 01047 Remarks: 01048 Overrides virtual ON_Object::IsValid 01049 */ 01050 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 01051 01052 void Dump( ON_TextLog& ) const; // for debugging 01053 01054 ON_BOOL32 Write( ON_BinaryArchive& ) const; 01055 01056 ON_BOOL32 Read( ON_BinaryArchive& ); 01057 01058 ON::object_type ObjectType() const; 01059 01061 // ON_Geometry overrides 01062 01063 int Dimension() const; 01064 01065 ON_BOOL32 GetBBox( // returns true if successful 01066 double*, // minimum 01067 double*, // maximum 01068 ON_BOOL32 = false // true means grow box 01069 ) const; 01070 01071 /* 01072 Description: 01073 Get tight bounding box of the mesh. 01074 Parameters: 01075 tight_bbox - [in/out] tight bounding box 01076 bGrowBox -[in] (default=false) 01077 If true and the input tight_bbox is valid, then returned 01078 tight_bbox is the union of the input tight_bbox and the 01079 mesh's tight bounding box. 01080 xform -[in] (default=NULL) 01081 If not NULL, the tight bounding box of the transformed 01082 mesh is calculated. The mesh is not modified. 01083 Returns: 01084 True if the returned tight_bbox is set to a valid 01085 bounding box. 01086 */ 01087 bool GetTightBoundingBox( 01088 ON_BoundingBox& tight_bbox, 01089 int bGrowBox = false, 01090 const ON_Xform* xform = 0 01091 ) const; 01092 01093 ON_BOOL32 Transform( 01094 const ON_Xform& 01095 ); 01096 01097 // virtual ON_Geometry::IsDeformable() override 01098 bool IsDeformable() const; 01099 01100 // virtual ON_Geometry::MakeDeformable() override 01101 bool MakeDeformable(); 01102 01103 ON_BOOL32 SwapCoordinates( 01104 int, int // indices of coords to swap 01105 ); 01106 01107 // virtual ON_Geometry override 01108 bool EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const; 01109 01110 01112 // Interface 01113 // 01114 01115 // creation 01116 bool SetVertex( 01117 int, // vertex index 01118 const ON_3dPoint& // vertex location 01119 ); 01120 bool SetVertex( 01121 int, // vertex index 01122 const ON_3fPoint& // vertex location 01123 ); 01124 bool SetVertexNormal( 01125 int, // vertex index 01126 const ON_3dVector& // unit normal 01127 ); 01128 bool SetVertexNormal( 01129 int, // vertex index 01130 const ON_3fVector& // unit normal 01131 ); 01132 bool SetTextureCoord( 01133 int, // vertex index 01134 double, double // texture coordinates 01135 ); 01136 bool SetTriangle( 01137 int, // face index 01138 int,int,int // vertex indices 01139 ); 01140 bool SetQuad( 01141 int, // face index 01142 int,int,int,int // vertex indices 01143 ); 01144 01145 /* 01146 Description: 01147 Get a vertex reference to a mesh vertex index. 01148 Parameters: 01149 ci - [in] component index with type mesh_vertex or meshtop_vertex. 01150 Returns: 01151 a reference to the vertex 01152 */ 01153 ON_MeshVertexRef VertexRef(ON_COMPONENT_INDEX ci) const; 01154 01155 ON_MeshVertexRef VertexRef(int mesh_V_index) const; 01156 01157 /* 01158 Description: 01159 Get an edge reference from a mesh topology edge index. 01160 Parameters: 01161 ci - [in] component index with type meshtop_edge 01162 Returns: 01163 a reference to the edge 01164 */ 01165 ON_MeshEdgeRef EdgeRef(ON_COMPONENT_INDEX ci) const; 01166 01167 ON_MeshEdgeRef EdgeRef(int tope_index) const; 01168 01169 /* 01170 Description: 01171 Get a face reference from a mesh face index. 01172 Parameters: 01173 ci - [in] component index with type mesh_face. 01174 Returns: 01175 a reference to the face 01176 */ 01177 ON_MeshFaceRef FaceRef(ON_COMPONENT_INDEX ci) const; 01178 01179 ON_MeshFaceRef FaceRef(int mesh_F_index) const; 01180 01181 /* 01182 Parameters: 01183 ci - [in] a component index with type mesh_vertex, meshtop_vertex, 01184 meshtop_edge, or mesh_face. 01185 Returns: 01186 A pointer to an ON_MeshVertexRef, ON_MeshEdgeRef, or ON_MeshFaceRef. 01187 The caller must delete the returned object when it is no longer 01188 needed. 01189 See Also: 01190 ON_Mesh::VertexRef 01191 ON_Mesh::EdgeRef 01192 ON_Mesh::FaceRef 01193 */ 01194 ON_Geometry* MeshComponent( 01195 ON_COMPONENT_INDEX ci 01196 ) const; 01197 01198 // query 01199 int VertexCount() const; 01200 int FaceCount() const; 01201 int QuadCount() const; // number of faces that are quads 01202 int TriangleCount() const; // number of faces that are triangles 01203 int InvalidFaceCount() const; // number of face that have invalid m_vi[] values. 01204 bool HasVertexNormals() const; // normals at vertices 01205 bool HasFaceNormals() const; 01206 bool HasTextureCoordinates() const; 01207 bool HasSurfaceParameters() const; 01208 bool HasPrincipalCurvatures() const; 01209 bool HasVertexColors() const; 01210 01211 /* 01212 Returns: 01213 Number of vertices that are hidden. 01214 */ 01215 int HiddenVertexCount() const; 01216 01217 bool GetCurvatureStats( 01218 ON::curvature_style, 01219 ON_MeshCurvatureStats& 01220 ) const; 01221 01222 void InvalidateVertexBoundingBox(); // Call if defining geometry is changed by 01223 // directly manipulating the m_V[] array. 01224 void InvalidateVertexNormalBoundingBox(); // Call if defining geometry is changed by 01225 // directly manipulating the m_N[] array. 01226 void InvalidateTextureCoordinateBoundingBox(); // Call if defining geometry is changed by 01227 // directly manipulating the m_T[] array. 01228 void InvalidateCurvatureStats(); // Call if defining geometry is changed by 01229 // directly manipulating the m_T[] array. 01230 void InvalidateBoundingBoxes(); // Invalidates all cached bounding box information. 01231 01232 01233 void Flip(); // reverses face orientations and flips vertex and face normals 01234 01235 void FlipVertexNormals(); // reverses vertex normals 01236 void FlipFaceNormals(); // reverses face normals 01237 void FlipFaceOrientation(); // reverses face orientation (does nothing to normals) 01238 01239 void SetMeshParameters( const ON_MeshParameters& ); 01240 const ON_MeshParameters* MeshParameters() const; 01241 void DeleteMeshParameters(); 01242 01243 01244 bool UnitizeVertexNormals(); 01245 bool UnitizeFaceNormals(); 01246 bool CountQuads(); 01247 01248 /* 01249 Description: 01250 Splits all quads along the short diagonal. 01251 */ 01252 bool ConvertQuadsToTriangles(); 01253 01254 /* 01255 Description: 01256 Joins adjacent triangles into quads if the resulting quad 01257 is nice. 01258 Parameters: 01259 angle_tol_radians - [in] Used to compare adjacent 01260 triangles' face normals. For two triangles to be considered, 01261 the angle between their face normals has to be <= angle_tol_radians. 01262 When in doubt use ON_PI/90.0 (2 degrees). 01263 min_diagonal_length_ratio - [in] ( <= 1.0) For two triangles to be 01264 considered the ratio of the resulting quad's diagonals 01265 (length of the shortest diagonal)/(length of longest diagonal). 01266 has to be >= min_diagonal_length_ratio. 01267 When in doubt us .875. 01268 */ 01269 bool ConvertTrianglesToQuads( 01270 double angle_tol_radians, 01271 double min_diagonal_length_ratio 01272 ); 01273 01274 bool ComputeFaceNormals(); // compute face normals for all faces 01275 bool ComputeFaceNormal(int); // computes face normal of indexed face 01276 01277 /* 01278 Description: 01279 Get a list of pairs of faces that clash. 01280 Parameters: 01281 max_pair_count - [in] 01282 If max_pair_count > 0, then at most this many pairs 01283 will be appended to the clashing_pairs[] array. 01284 If max_pair_count <= 0, then all clashing pairs 01285 will be appended to the clashing_pairs[] array. 01286 clashing_pairs - [out] 01287 The faces indices of clashing pairs are appended 01288 to this array. 01289 Returns: 01290 Number of pairs appended to clashing_pairs[]. 01291 */ 01292 int GetClashingFacePairs( 01293 int max_pair_count, 01294 ON_SimpleArray< ON_2dex >& clashing_pairs 01295 ) const; 01296 01297 /* 01298 Description: 01299 Cull clashing faces from the mesh. 01300 Parameters: 01301 what_to_cull - [in] 01302 0: when a pair of faces clash, cull both faces 01303 1: when a pair of faces clash, leave the face with the 01304 longest edge. 01305 2: when a pair of faces clash, cull the face with the 01306 longest edge. 01307 3: when a pair of faces clash, leave the face with 01308 the largest area. 01309 4: when a pair of faces clash, cull the face with 01310 the largest area. 01311 Returns: 01312 Number of faces culled from the mesh. 01313 Remarks: 01314 If a large face clashes with many small faces, the large 01315 face and one small face will be removed. When a degenerate 01316 face is encountered, it is also culled. 01317 */ 01318 int CullClashingFaces( int what_to_cull ); 01319 01320 int CullDegenerateFaces(); // returns number of degenerate faces 01321 01322 int CullUnusedVertices(); // returns number of culled vertices 01323 01324 // Description: 01325 // Removes any unreferenced objects from arrays, reindexes as needed, 01326 // and shrinks arrays to minimum required size. 01327 bool Compact(); 01328 01329 bool ComputeVertexNormals(); // uses face normals to cook up a vertex normal 01330 01332 // Scales textures so the texture domains are [0,1] and 01333 // eliminates any texture rotations. 01334 bool NormalizeTextureCoordinates(); 01335 01337 // Description: 01338 // Transposes the texture coordinates 01339 // Returns 01340 // true - success 01341 bool TransposeTextureCoordinates(); 01342 bool TransposeSurfaceParameters(); 01343 01345 // Description: 01346 // Reverse one coordinate direction of the texture coordinates, within texture domain m_tex_domain 01347 // Parameters: 01348 // dir -[in] - dir=0 first texture coordinate is reversed 01349 // dir=1 second texture coordinate is reversed 01350 // Returns 01351 // true - success 01352 bool ReverseTextureCoordinates( int dir ); 01353 bool ReverseSurfaceParameters( int dir ); 01354 01355 01356 01357 /* 01358 Description: 01359 Use a texture mapping function to set the m_T[] values. 01360 Parameters: 01361 mapping - [in] 01362 mesh_xform - [in] 01363 If not NULL, the mapping calculation is performed as 01364 if the mesh were transformed by mesh_xform; the 01365 location of the mesh is not changed. 01366 bLazy - [in] 01367 If true and the m_T[] values were set using the same 01368 mapping parameters, then no calculation is performed. 01369 Returns: 01370 True if successful. 01371 See Also: 01372 ON_TextureMapping::GetTextureCoordinates 01373 */ 01374 bool SetTextureCoordinates( 01375 const class ON_TextureMapping& mapping, 01376 const class ON_Xform* mesh_xform = 0, 01377 bool bLazy = true 01378 ); 01379 01380 bool HasCachedTextureCoordinates() const; 01381 01382 const ON_TextureCoordinates* CachedTextureCoordinates( 01383 const ON_UUID& mapping_id 01384 ) const; 01385 01386 const ON_TextureCoordinates* SetCachedTextureCoordinates( 01387 const class ON_TextureMapping& mapping, 01388 const class ON_Xform* mesh_xform = 0, 01389 bool bLazy = true 01390 ); 01391 01392 bool EvaluateMeshGeometry( const ON_Surface& ); // evaluate surface at tcoords 01393 // to set mesh geometry 01394 01395 // finds all coincident vertices and merges them if break angle is small enough 01396 bool CombineCoincidentVertices( 01397 ON_3fVector, // coordinate tols for considering vertices 01398 // to be coincident 01399 double // cosine normal angle tolerance in radians 01400 // if vertices are coincident, then they are combined 01401 // if NormalA o NormalB >= this value 01402 ); 01403 01404 /* 01405 Description: 01406 Combines identical vertices. 01407 Parameters: 01408 bIgnoreVertexNormals - [in] If true, then vertex normals 01409 are ignored when comparing vertices. 01410 bIgnoreTextureCoordinates - [in] If true, then vertex 01411 texture coordinates, colors, and principal curvatures 01412 are ignored when comparing vertices. 01413 Returns: 01414 True if the mesh is changed, in which case the returned 01415 mesh will have fewer vertices than the input mesh. 01416 */ 01417 bool CombineIdenticalVertices( 01418 bool bIgnoreVertexNormals = false, 01419 bool bIgnoreTextureCoordinates = false 01420 ); 01421 01422 void Append( const ON_Mesh& ); // appends a copy of mesh to this and updates 01423 // indices of appended mesh parts 01424 01425 /* 01426 Description: 01427 Append a list of meshes. This function is much more efficient 01428 than making repeated calls to ON_Mesh::Append(const ON_Mesh&) 01429 when lots of meshes are being joined into a single large mesh. 01430 Parameters: 01431 count - [in] 01432 length of meshes[] array. 01433 meshes - [in] 01434 array of meshes to append. 01435 */ 01436 void Append( int count, const ON_Mesh* const* meshes ); 01437 01438 /* 01439 Description: 01440 Expert user function to set m_is_closed member. 01441 Setting this value correctly after a mesh is constructed 01442 can save time when IsClosed() is called. 01443 This function sets the private member variable m_is_closed. 01444 Paramters: 01445 closed - [in] 01446 0: The mesh is not closed. There is at least one face with an 01447 edge that is geometrically distinct (as an unoriented line segment) 01448 from all other edges. 01449 1: The mesh is closed. Every geometrically distict edge is used 01450 by two or more faces. 01451 */ 01452 void SetClosed(int closed); 01453 01454 /* 01455 Returns: 01456 True if every mesh "edge" has two or more faces. 01457 */ 01458 bool IsClosed() const; 01459 01460 /* 01461 Returns: 01462 True if every mesh "edge" has at most two faces. 01463 */ 01464 bool IsManifold() const; 01465 01466 /* 01467 Returns: 01468 True if the mesh is manifold and every pair of faces 01469 that share an "edge" have compatible orientations. 01470 */ 01471 bool IsOriented() const; 01472 01473 /* 01474 Description: 01475 Determine if the mesh is a manifold. 01476 Parameters: 01477 bTopologicalTest - [in] 01478 If true, the query treats coincident vertices as 01479 the same. 01480 pbIsOriented - [out] 01481 If the input pointer is not NULL, then the returned 01482 value of *pbIsOriented will be true if the mesh 01483 is a manifold and adjacent faces have compatible 01484 face normals. 01485 pbHasBoundary - [out] 01486 If the input pointer is not NULL, then the returned 01487 value of *pbHasBoundary will be true if the mesh 01488 is a manifold and there is at least one "edge" 01489 with no adjacent faces have compatible 01490 face normals. 01491 Returns: 01492 True if every mesh "edge" has at most two adjacent faces. 01493 */ 01494 bool IsManifold( 01495 bool bTopologicalTest, 01496 bool* pbIsOriented = NULL, 01497 bool* pbHasBoundary = NULL 01498 ) const; 01499 01500 /* 01501 Description: 01502 Expert user function to set m_is_solid member. 01503 Setting this value correctly after a mesh is constructed 01504 can save time when IsSolid() is called. 01505 This function sets the private member variable m_is_solid. 01506 If solid is nonzero, it will set m_is_closed to 1. 01507 Paramters: 01508 solid - [in] 01509 0: The mesh is not an oriented manifold solid mesh. Either 01510 the mesh is not closed, not manifold, or the faces are 01511 not oriented compatibly. 01512 1: The mesh is an oriented manifold solid whose face normals 01513 point outwards. 01514 -1: The mesh is an oriented manifold solid whose face normals 01515 point inwards. 01516 */ 01517 void SetSolidOrientation(int solid_orientation); 01518 01519 /* 01520 Description: 01521 Determine orientation of a mesh. 01522 Returns: 01523 +1 mesh is a solid with outward facing normals 01524 -1 mesh is a solid with inward facing normals 01525 0 mesh is not a solid 01526 See Also: 01527 ON_Mesh::IsSolid 01528 */ 01529 int SolidOrientation() const; 01530 01531 /* 01532 Description: 01533 Test mesh to see if it is a solid. (A "solid" is 01534 a closed oriented manifold.) 01535 Returns: 01536 true mesh is a solid 01537 fals mesh is not a solid 01538 See Also: 01539 ON_Mesh::SolidOrientation 01540 ON_Mesh::IsManifold 01541 */ 01542 bool IsSolid() const; 01543 01544 /* 01545 Description: 01546 Appends a list of mesh edges that begin or end at the specified 01547 vertices to the edges[] array. 01548 Parameters: 01549 vcount - [in] 01550 number of vertices 01551 vertex_index - [in] 01552 array of vertex indices 01553 bNoDuplicates - [in] 01554 If true, then only one edges[] is added for each edge, 01555 the first vertex index will alwasy be less than the 01556 second, and the returned elements are sorted in dictionary 01557 order. 01558 If false and an edge is shared by multiple faces, then 01559 there will be an edges[] element added for each face and the 01560 order of the vertex indicies will indicate the orientation 01561 of the edge with respect to the face. No sorting is performed 01562 in this case. 01563 edges - [out] 01564 Edges that begin or end at one of the specified vertices are 01565 appended to this array. Each ON_2dex records the start and 01566 end vertex index. 01567 Returns: 01568 Number of ON_2dex values appended to the edges[] array. 01569 */ 01570 int GetVertexEdges( 01571 int vcount, 01572 const int* vertex_index, 01573 bool bNoDuplicates, 01574 ON_SimpleArray<ON_2dex>& edges 01575 ) const; 01576 01577 01578 /* 01579 Description: 01580 Appends a list of mesh edges to the edges[] array. 01581 Parameters: 01582 edges - [out] 01583 Each edges[] element is a pair of vertex indices. There 01584 is at least one face in the mesh with an edge running between 01585 the indicies. 01586 Returns: 01587 Number of ON_2dex values appended to the edges[] array. 01588 */ 01589 int GetMeshEdges( 01590 ON_SimpleArray<ON_2dex>& edges 01591 ) const; 01592 01593 /* 01594 Description: 01595 Assign a unique id to each vertex location. Coincident vertices 01596 get the same id. 01597 Parameters: 01598 first_vid - [in] 01599 Initial vertex id. Typically 1 or 0. 01600 Vid - [out] 01601 If not null, then Vid[] sould be an array of length VertexCount(). 01602 and the vertex ids will be stored in this array. If null, 01603 the array will be allocated by calling onmalloc(). The returned 01604 array Vid[i] is the id of the vertex m_V[i]. If m_V[i] and 01605 m_V[j] are the same 3d point, then Vid[i] and Vid[j] will have 01606 the same value. 01607 Vindex - [out] (can be null) 01608 If Vindex is not null, then it must have length at least m_V.Count() 01609 and the returned array will be a permutation of (0,1,...,m_V.Count()-1) 01610 such (Vid[Vindex[0]], Vid[Vindex[1]], ..., Vid[Vindex[m_V.Count()-1]]) 01611 is an increasing list of value. 01612 Returns: 01613 null if the mesh has no vertices. 01614 An array of length VertexCount(). If vertices m_V[i] and m_V[j] 01615 are coincident, then Vid[i] = Vid[j]. The id values begin at first_vid. 01616 The maximum vertex id is Vid[Vindex[m_V.Count()-1]]. The number of 01617 unique vertex locations is (Vid[Vindex[m_V.Count()-1]] - first_vid + 1). 01618 */ 01619 int* GetVertexLocationIds( 01620 int first_vid, 01621 int* Vid, 01622 int* Vindex 01623 ) const; 01624 01625 /* 01626 Description: 01627 Get a list of the sides of every face. 01628 Parameters: 01629 Vid - [in] (can be null) 01630 If Vid is null, then the mesh m_V[] index values are used to set 01631 the ON_MeshFaceSide::vi[] values. 01632 If Vid is not null, then it must be an array of length VertexCount(). 01633 The value Vid[mesh m_V[] index] will be used to set the 01634 ON_MeshFaceSide::vi[] values. 01635 sides - [out] 01636 If the input value of sides is not null, then sides[] must be long 01637 enough to hold the returned side list. The maximum posssible length 01638 is 4*FaceCount() for a mesh contining FaceCount() nondegenerate quads. 01639 If the input value of sides is null, memory will be allocated using 01640 onmalloc() and the caller is responsible for calling onfree() at an 01641 appropriate time. This function fills in the sides[] array 01642 with face side information. The returned list is sorted by sides[].fi 01643 and the sides[].side and each element has vi[0] <= vi[1]. 01644 The function ON_SortMeshFaceSidesByVertexIndex() can be used to sort the 01645 list by the sides[].vi[] values. 01646 Returns: 01647 Number of elements added to sides[]. 01648 Remarks: 01649 Faces with out of range ON_MeshFace.vi[] values are skipped. 01650 Degenerate faces are processed, but degenerate sides (equal vertex indices) 01651 are not added to the list. 01652 */ 01653 int GetMeshFaceSideList( 01654 const int* Vid, 01655 struct ON_MeshFaceSide*& sides 01656 ) const; 01657 01658 /* 01659 Description: 01660 Get a list of the geometrically uniqued edges in a mesh. 01661 Parameters: 01662 edge_list - [out] 01663 The edge list for this mesh is appended to edge_list[]. 01664 The ON_2dex i and j values are mesh->m_V[] array indices. 01665 There is exactly one element in edge_list[] for each 01666 unoriented 3d line segment in the mesh. The edges are 01667 oriented the same way the corresponding ON_MeshTopology 01668 edge is oriented. 01669 ci_meshtop_edge_map - [out] 01670 If you call the verson of GetMeshEdgeList() with the ci_meshtop_edge_map[], 01671 parameter, then the edge in edge_list[i] cooresponds to the edge 01672 in ON_MeshTopology.m_tope[ci_meshtop_edge_map[i]]. The value 01673 ci_meshtop_edge_map[i] is useful if you need to convert an edge_list[] 01674 index into an ON_COMPONENT_INDEX with type meshtop_edge. 01675 ci_meshtop_vertex_map - [out] 01676 If you call the verson of GetMeshEdgeList() with the ci_meshtop_vertex_map[], 01677 parameter, then the vertex m_V[i] cooresponds to the vertex 01678 in ON_MeshTopology.m_topv[ci_meshtop_vertex_map[i]]. The value 01679 ci_meshtop_vertex_map[i] is useful if you need to convert an m_V[] 01680 index into an ON_COMPONENT_INDEX with type meshtop_vertex. 01681 edge_list_partition - [out] (can be null) 01682 The edge_list[] is always ordered so that edge_types 01683 are partitioned into contiguous regions. The edge_list_partition[5] 01684 values report the edge type regions. 01685 * If edge_type_partition[0] <= ei < edge_type_partition[1], then 01686 edge_list[ei] is an edge of exactly two faces and the vertices 01687 used by the faces are identical. These are also called 01688 "manifold edges". 01689 * If edge_type_partition[1] <= ei < edge_type_partition[2], then 01690 edge_list[ei] is an edge of exactly two faces, but at least 01691 one of the vertices is duplicated. These are also called 01692 "crease edges". 01693 * If edge_type_partition[2] <= ei < edge_type_partition[3], then 01694 edge_list[ei] is an edge of 3 or more faces. These are also called 01695 "nonmanifold edges". 01696 * If edge_type_partition[3] <= ei < edge_type_partition[4], 01697 then edge_list[ei] is a boundary edge of exactly one mesh face. 01698 These are also called "naked edges". 01699 Returns: 01700 Number of edges added to edge_list[]. 01701 Remarks: 01702 This calculation also sets m_closed. If you modify the mesh's 01703 m_V or m_F information after calling this function, be sure to 01704 clear m_is_closed. 01705 */ 01706 int GetMeshEdgeList( 01707 ON_SimpleArray<ON_2dex>& edge_list, 01708 int edge_type_partition[5] 01709 ) const; 01710 01711 int GetMeshEdgeList( 01712 ON_SimpleArray<ON_2dex>& edge_list, 01713 ON_SimpleArray<int>& ci_meshtop_edge_map, 01714 int edge_type_partition[5] 01715 ) const; 01716 01717 int GetMeshEdgeList( 01718 ON_SimpleArray<ON_2dex>& edge_list, 01719 ON_SimpleArray<int>& ci_meshtop_edge_map, 01720 ON_SimpleArray<int>& ci_meshtop_vertex_map, 01721 int edge_type_partition[5] 01722 ) const; 01723 01725 // 01726 // mesh editing 01727 // 01728 01729 /* 01730 Description: 01731 Replace a mesh edge with a vertex at its center and update 01732 adjacent faces as needed. 01733 Parameters: 01734 topei - [in] index of edge in MeshTopology().m_tope[] array 01735 Returns: 01736 true if successful. 01737 */ 01738 bool CollapseEdge( int topei ); 01739 01740 /* 01741 Description: 01742 Tests a mesh edge to see if it is valid as input to 01743 ON_Mesh::SwapMeshEdge. 01744 Parameters: 01745 topei - [in] index of edge in MeshTopology().m_tope[] array 01746 Returns: 01747 true if edge can be swapped by ON_Mesh::SwapMeshEdge. 01748 See Also: 01749 ON_Mesh::SwapEdge 01750 */ 01751 bool IsSwappableEdge( int topei ); 01752 01753 01754 /* 01755 Description: 01756 If the edge is shared by two triangular face, then 01757 the edge is "swapped". 01758 Parameters: 01759 topei - [in] index of edge in MeshTopology().m_tope[] array 01760 Returns: 01761 true if successful 01762 See Also: 01763 ON_Mesh::IsSwappableEdge 01764 */ 01765 bool SwapEdge( int topei ); 01766 01767 /* 01768 Description: 01769 Removes a face from a mesh and does not alter the 01770 geometry of the remaining mesh. 01771 Parameters: 01772 meshfi - [in] index of face in ON_Mesh.m_F[] array 01773 Remarks: 01774 This function calls DestroyTopology() and DestroyPartition(). 01775 The caller is responsible for calling Compact() if that step 01776 is required. 01777 Returns: 01778 true if successful 01779 */ 01780 bool DeleteFace( int meshfi ); 01781 01782 /* 01783 Description: 01784 Destroys the m_H[] array and sets m_hidden_count=0. 01785 */ 01786 void DestroyHiddenVertexArray(); 01787 01788 /* 01789 Returns: 01790 If the mesh has some hidden vertices, then an array 01791 of length VertexCount() is returned and the i-th 01792 element is true if the i-th vertex is hidden. 01793 If no vertices are hidden, NULL is returned. 01794 */ 01795 const bool* HiddenVertexArray() const; 01796 01797 /* 01798 Description: 01799 Set the runtime vertex hidden flag. 01800 Parameters: 01801 meshvi - [in] mesh vertex index 01802 bHidden - [in] true to hide vertex 01803 */ 01804 void SetVertexHiddenFlag( int meshvi, bool bHidden ); 01805 01806 /* 01807 Description: 01808 Returns true if the mesh vertex is hidden. This is a runtime 01809 setting that is not saved in 3dm files. 01810 Parameters: 01811 meshvi - [in] mesh vertex index. 01812 Returns: 01813 True if mesh vertex is hidden. 01814 */ 01815 bool VertexIsHidden( int meshvi ) const; 01816 01817 /* 01818 Description: 01819 Returns true if the mesh face is hidden. This is a runtime 01820 setting that is not saved in 3dm files. 01821 Parameters: 01822 meshfi - [in] mesh face index. 01823 Returns: 01824 True if mesh face is hidden. 01825 Remarks: 01826 A face is hidden if, and only if, at least one of its 01827 vertices is hidden. 01828 */ 01829 bool FaceIsHidden( int meshvi ) const; 01830 01831 01833 // 01834 // mesh topology 01835 // 01836 // In order to keep the mesh facet definition simple and make the mesh 01837 // definition easily used in common rendering application, if two facets 01838 // share a vertex location but have different normals, curvatures, 01839 // textures, etc., at that common vertex location, then the vertex is 01840 // duplicated. When the topology of the mesh needs to be known, 01841 // use Topology() to get a class that provides complete topological 01842 // information about the mesh. 01843 const ON_MeshTopology& Topology() const; 01844 01846 // If you modify the mesh in any way that may change its topology, 01847 // then call DestroyTopology(). Specifically if you add or remove 01848 // vertices or face, change vertex locations, or change the face m_vi[] 01849 // values, then you must call DestroyTopology(). 01850 void DestroyTopology(); 01851 01852 /* 01853 Returns: 01854 This is an expert user function that returns true if the topology 01855 information is already calculated and cached. It can be used to 01856 to avoid calling the Topology() function when the expensive creation 01857 step will be performed. 01858 */ 01859 bool TopologyExists() const; 01860 01861 01863 // 01864 // mesh partitions 01865 // 01866 // In ancient times, some rendering engines were only able to process 01867 // small batches of triangles and th CreatePartition() function was 01868 // provided to partition the mesh into subsets of vertices and faces 01869 // that those renering engines could handle. 01870 // 01871 const ON_MeshPartition* CreatePartition( 01872 int, // maximum number of vertices in a partition 01873 int // maximum number of triangles in a partition 01874 ); 01875 const ON_MeshPartition* Partition() const; 01876 void DestroyPartition(); 01877 01878 /* 01879 Description: 01880 Extract the portion of this mesh defined by mesh_part. 01881 Parameters: 01882 mesh_part - [in] 01883 defines portion of the mesh to extract. 01884 mesh - [in] (can be null, cannot be = "this). 01885 If mesh is no null, the extracted mesh will be put into 01886 this mesh. If mesh is null, the extracted mesh will 01887 be created in a mesh allocated on the heap using the 01888 new operator. 01889 Returns: 01890 A pointer to the submesh. If the input mesh parameter is null, 01891 then the caller must delete this mesh when it is no longer needed. 01892 If the input is invalid, then null is returned. 01893 */ 01894 ON_Mesh* MeshPart( 01895 const ON_MeshPart& mesh_part, 01896 ON_Mesh* mesh 01897 ) const; 01898 01899 /* 01900 Description: 01901 Create a mesh that is a single face of this mesh. 01902 Parameters: 01903 Returns: 01904 A pointer to the submesh. If the input mesh parameter is null, 01905 then the caller must delete this mesh when it is no longer needed. 01906 If the input is invalid, then null is returned. 01907 */ 01908 ON_Mesh* DuplicateFace( 01909 int face_index, 01910 ON_Mesh* mesh 01911 ) const; 01912 01914 // 01915 // mesh N-gon lists. 01916 // ON_Mesh objects support faces that are triangle or quads. 01917 // When a mesh is created from a format that supports N-gons 01918 // for N larger than 4, an optional N-gon list can be added 01919 // that specifies the vertices and faces that make up the N-gon. 01920 // 01921 01922 /* 01923 Description: 01924 If the mesh has an N-gon list, return a pointer to it. 01925 Returns: 01926 A pointer to the current N-gon list or NULL. 01927 */ 01928 const class ON_MeshNgonList* NgonList() const; 01929 01930 /* 01931 Description: 01932 If an N-gon list exists, it is returned and can be modified. 01933 If no N-gon list exists, a new empty list is returned and 01934 it can be modified. 01935 Returns: 01936 A pointer to the N-gon list that can be modified. 01937 */ 01938 class ON_MeshNgonList* ModifyNgonList(); 01939 01940 /* 01941 Description: 01942 Destroy any existing N-gon list. 01943 */ 01944 void DestroyNgonList(); 01945 01947 // 01948 // mesh components 01949 // ON_Mesh objects can consist of sets of faces that are isolated 01950 // from any other sets of faces. The following 2 functions will 01951 // dissect a mesh into these sets, called components. Not to be 01952 // confused with ON_COMPONENT_INDEX. 01953 01954 /* 01955 Description: 01956 Calculates the components of a mesh and sets a label for each face in 01957 the facet_component_labels array. 01958 Parameters: 01959 bUseVertexConnections- [in] 01960 If this parameter is true, then facets that share a common vertex 01961 are considered connected. 01962 If this parameter is false, then facets must share an edge to 01963 be considered connected. 01964 bUseTopologicalConnections - [in] 01965 If this parameter is true, then geometric location is used 01966 to determine if facets are connected. 01967 If this parameter is false, then facets must share the same vertex 01968 or vertices to be considered connected. 01969 facet_component_labels- [out] 01970 facet_component_labels[] will be an array with the same size 01971 as ON_Mesh.m_F.Count() and facet_component_labels[i] 01972 is the component id m_F[i] belongs to. The component id 01973 will be 1 to the number of compoents. 01974 Returns: 01975 Number of components on success, 0 on failure 01976 */ 01977 01978 int GetConnectedComponents( bool bUseVertexConnections, 01979 bool bTopologicalConnections, 01980 ON_SimpleArray<int>& facet_component_labels 01981 ) const; 01982 01983 /* 01984 Description: 01985 Calculates the components of a mesh and sets a label for each face in 01986 the facet_component_labels array. 01987 Parameters: 01988 bUseVertexConnections- [in] 01989 If this parameter is true, then facets that share a common vertex 01990 are considered connected. 01991 If this parameter is false, then facets must share an edge to 01992 be considered connected. 01993 bUseTopologicalConnections - [in] 01994 If this parameter is true, then geometric location is used 01995 to determine if facets are connected. 01996 If this parameter is false, then facets must share the same vertex 01997 or vertices to be considered connected. 01998 components - [out] 01999 New components are appended to this array 02000 if this parameter is null, then the components are just counted. 02001 Returns: 02002 Number of components on success, 0 on failure 02003 */ 02004 02005 int GetConnectedComponents( bool bUseVertexConnections, 02006 bool bTopologicalConnections, 02007 ON_SimpleArray<ON_Mesh*>* components 02008 ) const; 02009 02010 02012 // 02013 // Double precision vertex support 02014 // 02015 02016 /* 02017 Returns: 02018 True if the mesh has single and double precision 02019 vertices, and the values of the two sets are synchronized. 02020 */ 02021 bool HasSynchronizedDoubleAndSinglePrecisionVertices() const; 02022 02023 /* 02024 Returns: 02025 True if the mesh has double precision vertices. 02026 Remarks: 02027 This function returns true if a mesh has double 02028 precision vertex information, even if it is not 02029 updated. 02030 02031 Use ON_Mesh::DoublePrecisionVerticesAreValid() 02032 and ON_Mesh::SinglePrecisionVerticesAreValid() to 02033 check the validity. 02034 02035 Use ON_Mesh::UpdateDoublePrecisionVertices() 02036 or ON_Mesh::UpdateSinglePrecisionVertices() to synchronize 02037 values of single and double precision vertices. 02038 */ 02039 bool HasDoublePrecisionVertices() const; 02040 02041 /* 02042 Parameters: 02043 bEnableDoublePrecisionVertices - [in] 02044 True to enable use of double precision vertices. 02045 False to destroy any existing precision vertices. 02046 */ 02047 void EnableDoublePrecisionVertices(bool bEnableDoublePrecisionVertices); 02048 02049 /* 02050 Description: 02051 If you modify the values of double precision vertices, 02052 then you must call UpdateSinglePrecisonVertices(). 02053 Remarks: 02054 If double precision vertices are not present, this function 02055 does nothing. 02056 */ 02057 void UpdateSinglePrecisionVertices(); 02058 02059 /* 02060 Description: 02061 If you modify the values of the single precision vertices 02062 in m_V[], then you must call UpdateDoublePrecisionVertices(). 02063 Remarks: 02064 If double precision vertices are not present, this function 02065 does nothing. 02066 */ 02067 void UpdateDoublePrecisionVertices(); 02068 02069 /* 02070 Description: 02071 If you have modified the single precision vertices 02072 and are certain they are valid, then call this 02073 function to update crc information. 02074 Remarks: 02075 If double precision vertices are not present, this function 02076 does nothing. 02077 */ 02078 void SetSinglePrecisionVerticesAsValid(); 02079 02080 /* 02081 Description: 02082 If you have modified the double precision vertices 02083 and are certain they are valid, then call this 02084 function to update crc information. 02085 Remarks: 02086 If double precision vertices are not present, this function 02087 does nothing. 02088 */ 02089 void SetDoublePrecisionVerticesAsValid(); 02090 02091 /* 02092 Description: 02093 The functions UpdateSinglePrecisionVertices(), 02094 UpdateDoublePrecisionVertices(), and 02095 SetSinglePrecisionVerticesAsValid() save 02096 the count and crc of the single precision vertex 02097 array. True is returned if there are no 02098 double precision vertices or the current 02099 count and crc of the single precision 02100 vertex array match the saved values. 02101 Remarks: 02102 If double precision vertices are not present, this function 02103 does nothing and returns true. 02104 */ 02105 bool SinglePrecisionVerticesAreValid() const; 02106 02107 /* 02108 Description: 02109 The functions UpdateSinglePrecisionVertices(), 02110 UpdateDoublePrecisionVertices(), and 02111 SetDoublePrecisionVerticesAsValid() save 02112 the count and crc of the double precision vertex 02113 array. True is returned if the current 02114 count and crc of the double precision 02115 vertex array match the saved values. 02116 Remarks: 02117 If double precision vertices are not present, this function 02118 does nothing and returns true. 02119 */ 02120 bool DoublePrecisionVerticesAreValid() const; 02121 02122 /* 02123 Description: 02124 The function removes all double precision vertex information. 02125 */ 02126 void DestroyDoublePrecisionVertices(); 02127 02128 02130 // Implementation - mesh geometry 02131 02132 // Vertex locations 02133 // In a case where adjacent facets share a vertex 02134 // location but have distinct normals or texture 02135 // coordinates at that location, the vertex must 02136 // be duplicated. 02137 02138 /* 02139 Description: 02140 Get double precision vertices. If they do not exist, 02141 they will be created and match the existing single 02142 precision vertices. 02143 Returns: 02144 Array of double precision vertices. If you modify the 02145 values in this array, you must make the same modifications 02146 to the single precision vertices, or call 02147 UpdateSinglePrecisonVertices(). 02148 Example: 02149 02150 // add a bunch of double precision information 02151 ON_3dPointArray& dv = mesh.DoublePrecisionVertices(); 02152 for ( i = 0; i < lots; i++ ) 02153 { 02154 dv[i] = ... 02155 } 02156 // This call updates the single precison values 02157 // in m_V[] and sets all the counts and CRCs that 02158 // are used in validity checking. 02159 mesh.UpdateSinglePrecisonVertices(); 02160 02161 Remarks: 02162 Avoid mulitple calls to DoublePrecisionVertices(). 02163 It is most efficient to make one call, save a local 02164 reference, and use the local reference as needed. 02165 */ 02166 ON_3dPointArray& DoublePrecisionVertices(); 02167 const ON_3dPointArray& DoublePrecisionVertices() const; 02168 02169 /* 02170 Description: 02171 Get single precision vertices. 02172 Returns: 02173 Array of float precision vertices. If you modify the 02174 values in this array, you must make the same modifications 02175 to the double precision vertices, or call 02176 UpdateSinglePrecisonVertices(). 02177 */ 02178 ON_3fPointArray& SinglePrecisionVertices(); 02179 const ON_3fPointArray& SinglePrecisionVertices() const; 02180 02181 /* 02182 Description: 02183 In general,use one of 02184 ON_Mesh::SinglePrecisionVertices() 02185 or 02186 ON_Mesh::DoublePrecisionVertices() 02187 to get the array of vertex locations. If you modify 02188 m_V[] directly and HasDoublePrecisionVertices() is true, 02189 then you must make the same modifications to the array 02190 returned by DoublePrecisionVertices(). 02191 */ 02192 ON_3fPointArray m_V; 02193 02194 /* 02195 Returns: 02196 Location of the vertex. If double precision vertices 02197 are present, the double precision vertex location is 02198 returned. If vertex_index is out of range, 02199 ON_UNSET_VALUE is returned. 02200 */ 02201 ON_3dPoint Vertex(int vertex_index) const; 02202 02203 // m_F[] facets (triangles or quads) 02204 ON_SimpleArray<ON_MeshFace> m_F; 02205 02206 // m_N[] OPTIONAL vertex unit normals 02207 // If m_N[] is empty or m_N.Count() != m_V.Count(), 02208 // Either m_N[] has zero count or it m_N[j] is the 02209 // the unit vertex normal at m_V[j]. 02210 ON_3fVectorArray m_N; 02211 02212 // m_FN[] OPTIONAL face unit normals 02213 // If m_FN[] is empty or m_FN.Count() != m_F.Count(), 02214 // then m_FN is ignored. Otherwise m_FN[j] is the 02215 // unit normal for the facet m_F[j]. 02216 ON_3fVectorArray m_FN; 02217 02219 // Implementation - texture coordinates 02220 // 02221 // OPTIONAL texture coordinates for each vertex 02222 02223 // It would be nice if this were an ON_TextureCoordinates, 02224 // but that breaks lots of checked out code that assumes 02225 // m_T is an array of ON_2fPoints. 02226 ON_MappingTag m_Ttag; // OPTIONAL tag for values in m_T[] 02227 ON_2fPointArray m_T; // OPTIONAL texture coordinates for each vertex 02228 02229 // RUNTIME ONLY 02230 // This array is used to cache texture coordinates used by 02231 // rendering applications that require 1d texture coordinates, 02232 // 3d texture coordinates, or multiple sets of texture 02233 // coordinates (e.g. blended textures with different mappings). 02234 // Users are responsible for verifying 02235 // m_TC[i].m_T.Count() = m_V.Count() 02236 ON_ClassArray<ON_TextureCoordinates> m_TC; 02237 02238 // If m_T.Count() == m_V.Count(), then the mesh has texture coordinates 02239 // and m_T[j] is the texture coordinate for vertex m_V[j]. 02240 // 02241 // When opennurbs or Rhino meshes an ON_Surface or ON_Brep, the texture 02242 // coordinates have a "canonical" linear relationship with the surface 02243 // parameters that is described in the next section. However, various 02244 // mappings, spherical, planar, cylindrical, etc., can be applied that 02245 // change the values of the texture coordinates. 02246 // 02247 // If a texture mapping function was used to set the m_T[] values, 02248 // then the id and serial number of the mapping function is saved 02249 // in m_mapping_id and m_mapping_sn. The intended use of these fields 02250 // is to make it easy to avoid unnecessary recalculation. 02251 // If a mesh is modified, then m_mapping_id should be set to nil 02252 // and m_mapping_crc should be set to 0. 02253 // 02255 02256 02258 // Implementation - surface parameters and packed texture 02259 // information 02260 // 02261 // If m_S.Count() == m_V.Count(), then the mesh is a tesselation 02262 // of a parameteric surface and m_S[j] is the surface parameter at 02263 // m_V[j]. Storing values in m_S[] is OPTIONAL. 02264 // 02265 // If m_srf_scale[] has positive values, then they report 02266 // the world coordinate size of a rectangle that would 02267 // minimize texture distortion if it were mapped to the 02268 // mesh using normalized surface evaluation parameters. 02269 // This information is used to calculate high quality 02270 // packed texture coordinates. 02271 ON_2dPointArray m_S; 02272 ON_Interval m_srf_domain[2]; // surface evaluation domain. 02273 double m_srf_scale[2]; 02274 02275 02276 // Packed texture information. 02277 // 02278 // If either of the m_packed_tex_domain[] intervals is a 02279 // proper subinterval of (0,1), then a texture packing 02280 // calculation assigned this subrectangle to this mesh. 02281 02282 ON_Interval m_packed_tex_domain[2]; 02283 02284 // The m_packed_tex_rotate setting is valid only when 02285 // m_S, m_srf_domain, m_packed_scale[] and 02286 // m_packed_tex_domain[] are all valid and the texture 02287 // coordinates are based on surface evaluation parameters. 02288 // In this special situation, this boolean records the 02289 // correspondence between the the surface parameters, (u,v), 02290 // and the packed texture coordinates, (s,t), 02291 // 02292 // m_packed_tex_rotate = false: 02293 // a = m_srf_domain[0].NormalizedParameterAt(u); 02294 // b = m_srf_domain[1].NormalizedParameterAt(v); 02295 // s = m_packed_tex_domain[0].ParameterAt(a); 02296 // t = m_packed_tex_domain[1].ParameterAt(b); 02297 // 02298 // x = m_packed_tex_domain[0].NormalizedParameterAt(s); 02299 // y = m_packed_tex_domain[1].NormalizedParameterAt(t); 02300 // u = m_srf_domain[0].ParameterAt(x); 02301 // v = m_srf_domain[1].ParameterAt(y); 02302 // 02303 // m_packed_tex_rotate = true: 02304 // a = m_srf_domain[0].NormalizedParameterAt(u); 02305 // b = m_srf_domain[1].NormalizedParameterAt(v); 02306 // s = m_packed_tex_domain[0].ParameterAt(a); 02307 // t = m_packed_tex_domain[1].ParameterAt(1.0-b); 02308 // 02309 // x = m_packed_tex_domain[0].NormalizedParameterAt(s); 02310 // y = m_packed_tex_domain[1].NormalizedParameterAt(t); 02311 // u = m_srf_domain[0].ParameterAt(y); 02312 // v = m_srf_domain[1].ParameterAt(1.0 - x); 02313 bool m_packed_tex_rotate; 02314 02315 /* 02316 Returns: 02317 True if the m_srf_scale[] values are positive and 02318 the m_packed_tex_domain[] intervals are set to values 02319 that describe a proper subrectangle of (0,1)x(0,1). 02320 True does not necessarily mean the current values in 02321 m_T[] are packed texture coordinates. 02322 */ 02323 bool HasPackedTextureRegion() const; 02324 02326 // Implementation - curvature 02327 02328 ON_SimpleArray<ON_SurfaceCurvature> m_K; // OPTIONAL surface curvatures 02329 // Either m_K[] has zero count or it has the same 02330 // count as m_V[], in which case m_K[j] reports 02331 // the surface curvatures at m_V[j]. 02332 02334 // Implementation - false color 02335 ON_MappingTag m_Ctag; // OPTIONAL tag for values in m_C[] 02336 ON_SimpleArray<ON_Color> m_C; // OPTIONAL vertex color 02337 // Either m_C[] has zero count or it has the same 02338 // count as m_V[], in which case m_C[j] reports 02339 // the color assigned to m_V[j]. 02340 02342 // Implementation - runtime vertex visibility - not saved in 3dm files. 02343 ON_SimpleArray<bool> m_H; // OPTIONAL vertex visibility. 02344 // If m_H.Count() = m_V.Count(), then 02345 // m_H[vi] is true if the vertex m_V[vi] 02346 // is hidden. Otherwise, all vertices are visible. 02347 int m_hidden_count; // number of vertices that are hidden 02348 // = number of true values in m_H[] array. 02349 02351 // Implementation - runtime UI information 02352 const ON_Object* m_parent; // runtime parent geometry (use ...::Cast() to get it) 02353 02354 protected: 02355 friend class ON_MeshVertexRef; 02356 friend class ON_MeshEdgeRef; 02357 friend class ON_MeshFaceRef; 02358 02359 02361 // Implementation - mesh topology 02362 ON_MeshTopology m_top; 02363 02364 ON_MeshParameters* m_mesh_parameters; // If mesh was created from a parametric surface, 02365 // these parameters were used to create the mesh. 02366 int m_invalid_count; 02367 int m_quad_count; 02368 int m_triangle_count; 02369 02370 private: 02371 char m_mesh_is_closed; // 0 = unset, 1 = all edges have 2 or more faces, 2 = at least one boundary edge 02372 char m_mesh_is_manifold; // 0 = unset, 1 = all edges have 1 or 2 faces, 2 = not manifold 02373 char m_mesh_is_oriented; // 0 = unset, 1 = faces normals agree across all edges that have 2 faces, 2 = not oriented 02374 char m_mesh_is_solid; // 0 = unset, 1 = solid with outward face normals, 2 = solid with inward face normals, 3 = not solid 02375 02376 protected: 02377 // The bounding boxes are valid if m_?box[0][0] <= m_?box[0][1]; 02378 float m_vbox[2][3]; // 3d bounding box of all referenced vertices 02379 float m_nbox[2][3]; // 3d bounding box of all referenced unit normals 02380 // (for estimation of Gauss map bounds) 02381 float m_tbox[2][2]; // 2d bounding box of all referenced texture coordinates 02382 ON_MeshCurvatureStats* m_kstat[4]; // gaussian,mean,min,max,sectionx,sectiony,sectionz 02383 02384 // sub-mesh information rendering large meshes 02385 ON_MeshPartition* m_partition; 02386 02387 private: 02388 bool Write_1( ON_BinaryArchive& ) const; // uncompressed 1.x format 02389 bool Write_2( int, ON_BinaryArchive& ) const; // compressed 2.x format 02390 bool Read_1( ON_BinaryArchive& ); 02391 bool Read_2( int, ON_BinaryArchive& ); 02392 bool WriteFaceArray( int, int, ON_BinaryArchive& ) const; 02393 bool ReadFaceArray( int, int, ON_BinaryArchive& ); 02394 bool SwapEdge_Helper( int, bool ); 02395 }; 02396 02397 class ON_CLASS ON_MeshVertexRef : public ON_Geometry 02398 { 02399 ON_OBJECT_DECLARE(ON_MeshVertexRef); 02400 public: 02401 ON_MeshVertexRef(); 02402 ~ON_MeshVertexRef(); 02403 ON_MeshVertexRef& operator=(const ON_MeshVertexRef&); 02404 02405 02406 // parent mesh 02407 const ON_Mesh* m_mesh; 02408 02409 // m_mesh->m_V[] index 02410 // (can be -1 when m_top_vi references a shared vertex location) 02411 int m_mesh_vi; 02412 02413 // m_mesh->m_top.m_tope[] index 02414 int m_top_vi; 02415 02416 02417 /* 02418 Description: 02419 Override of the virtual ON_Geometry::ComponentIndex(). 02420 Returns: 02421 A component index for the vertex. The type of the returned 02422 component index can be 02423 ON_COMPONENT_INDEX::mesh_vertex, 02424 ON_COMPONENT_INDEX::meshtop_vertex, or 02425 ON_COMPONENT_INDEX::invalid_type. 02426 */ 02427 ON_COMPONENT_INDEX ComponentIndex() const; 02428 02429 /* 02430 Returns: 02431 The mesh topology associated with this 02432 mesh vertex reference or NULL if it doesn't 02433 exist. 02434 */ 02435 const ON_MeshTopology* MeshTopology() const; 02436 02437 /* 02438 Returns: 02439 The 3d location of the mesh vertex. Returns 02440 ON_UNSET_POINT is this ON_MeshVertexRef is not 02441 valid. 02442 */ 02443 ON_3dPoint Point() const; 02444 02445 /* 02446 Returns: 02447 The mesh topology vertex associated with this 02448 mesh vertex reference. 02449 */ 02450 const ON_MeshTopologyVertex* MeshTopologyVertex() const; 02451 02452 // overrides of virtual ON_Object functions 02453 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 02454 void Dump( ON_TextLog& ) const; 02455 unsigned int SizeOf() const; 02456 ON::object_type ObjectType() const; 02457 02458 // overrides of virtual ON_Geometry functions 02459 int Dimension() const; 02460 ON_BOOL32 GetBBox( 02461 double* boxmin, 02462 double* boxmax, 02463 int bGrowBox = false 02464 ) const; 02465 ON_BOOL32 Transform( 02466 const ON_Xform& xform 02467 ); 02468 }; 02469 02470 class ON_CLASS ON_MeshEdgeRef : public ON_Geometry 02471 { 02472 ON_OBJECT_DECLARE(ON_MeshEdgeRef); 02473 public: 02474 ON_MeshEdgeRef(); 02475 ~ON_MeshEdgeRef(); 02476 ON_MeshEdgeRef& operator=(const ON_MeshEdgeRef&); 02477 02478 // parent mesh 02479 const ON_Mesh* m_mesh; 02480 02481 // m_mesh->m_top.m_tope[] index 02482 int m_top_ei; 02483 02484 /* 02485 Description: 02486 Override of the virtual ON_Geometry::ComponentIndex(). 02487 Returns: 02488 A mesh component index for the edge. The type is 02489 ON_COMPONENT_INDEX::meshtop_edge and the index is the 02490 index into the ON_MeshTopology.m_tope[] array. 02491 */ 02492 ON_COMPONENT_INDEX ComponentIndex() const; 02493 02494 /* 02495 Returns: 02496 The mesh topology associated with this 02497 mesh edge reference or NULL if it doesn't 02498 exist. 02499 */ 02500 02501 const ON_MeshTopology* MeshTopology() const; 02502 /* 02503 Returns: 02504 The 3d location of the mesh edge. Returns 02505 ON_UNSET_POINT,ON_UNSET_POINT, is this ON_MeshEdgeRef 02506 is not valid. 02507 */ 02508 ON_Line Line() const; 02509 02510 /* 02511 Returns: 02512 The mesh topology edge associated with this 02513 mesh edge reference. 02514 */ 02515 const ON_MeshTopologyEdge* MeshTopologyEdge() const; 02516 02517 // overrides of virtual ON_Object functions 02518 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 02519 void Dump( ON_TextLog& ) const; 02520 unsigned int SizeOf() const; 02521 ON::object_type ObjectType() const; 02522 02523 // overrides of virtual ON_Geometry functions 02524 int Dimension() const; 02525 ON_BOOL32 GetBBox( 02526 double* boxmin, 02527 double* boxmax, 02528 int bGrowBox = false 02529 ) const; 02530 ON_BOOL32 Transform( 02531 const ON_Xform& xform 02532 ); 02533 }; 02534 02535 class ON_CLASS ON_MeshFaceRef : public ON_Geometry 02536 { 02537 ON_OBJECT_DECLARE(ON_MeshFaceRef); 02538 public: 02539 ON_MeshFaceRef(); 02540 ~ON_MeshFaceRef(); 02541 ON_MeshFaceRef& operator=(const ON_MeshFaceRef&); 02542 02543 // parent mesh 02544 const ON_Mesh* m_mesh; 02545 02546 // m_mesh->m_F[] and m_mesh->m_top.m_tope[] index. 02547 int m_mesh_fi; 02548 02549 /* 02550 Description: 02551 Override of the virtual ON_Geometry::ComponentIndex(). 02552 Returns: 02553 A mesh component index for the face. The type is 02554 ON_COMPONENT_INDEX::mesh_face and the index is the 02555 index into the ON_Mesh.m_F[] array. 02556 */ 02557 ON_COMPONENT_INDEX ComponentIndex() const; 02558 02559 /* 02560 Returns: 02561 The mesh topology associated with this 02562 mesh face reference or NULL if it doesn't 02563 exist. 02564 */ 02565 const ON_MeshTopology* MeshTopology() const; 02566 02567 /* 02568 Returns: 02569 The mesh face associated with this mesh face reference. 02570 */ 02571 const ON_MeshFace* MeshFace() const; 02572 02573 /* 02574 Returns: 02575 The mesh topology face associated with this 02576 mesh face reference. 02577 */ 02578 const ON_MeshTopologyFace* MeshTopologyFace() const; 02579 02580 // overrides of virtual ON_Object functions 02581 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 02582 void Dump( ON_TextLog& ) const; 02583 unsigned int SizeOf() const; 02584 ON::object_type ObjectType() const; 02585 02586 // overrides of virtual ON_Geometry functions 02587 int Dimension() const; 02588 ON_BOOL32 GetBBox( 02589 double* boxmin, 02590 double* boxmax, 02591 int bGrowBox = false 02592 ) const; 02593 ON_BOOL32 Transform( 02594 const ON_Xform& xform 02595 ); 02596 }; 02597 02598 /* 02599 Description: 02600 Calculate a mesh representation of the NURBS surface's control polygon. 02601 Parameters: 02602 nurbs_surface - [in] 02603 bCleanMesh - [in] If true, then degenerate quads are cleaned 02604 up to be triangles. Surfaces with singular 02605 sides are a common source of degenerate qauds. 02606 input_mesh - [in] If NULL, then the returned mesh is created 02607 by a class to new ON_Mesh(). If not null, then this 02608 mesh will be used to store the conrol polygon. 02609 Returns: 02610 If successful, a pointer to a mesh. 02611 */ 02612 ON_DECL 02613 ON_Mesh* ON_ControlPolygonMesh( 02614 const ON_NurbsSurface& nurbs_surface, 02615 bool bCleanMesh, 02616 ON_Mesh* input_mesh = NULL 02617 ); 02618 02619 /* 02620 Description: 02621 Finds the unit normal to the triangle 02622 Parameters: 02623 A - [in] triangle corner 02624 B - [in] triangle corner 02625 C - [in] triangle corner 02626 Returns: 02627 Unit normal 02628 */ 02629 ON_DECL 02630 ON_3dVector ON_TriangleNormal( 02631 const ON_3dPoint& A, 02632 const ON_3dPoint& B, 02633 const ON_3dPoint& C 02634 ); 02635 02636 02637 /* 02638 Description: 02639 Finds the unit normal to the triangle 02640 Parameters: 02641 A - [in] triangle corner 02642 B - [in] triangle corner 02643 C - [in] triangle corner 02644 a - [out] must not be null 02645 b - [out] must not be null 02646 c - [out] must not be null 02647 d - [out] must not be null 02648 The equation of the plane is a*x + b*y + c*z + d = 0 02649 ev_tol - [out] 02650 If ev_tol is not null, then it is the maximum absolute 02651 value of the plane equation evaluated at A,B,C. Mathematically, 02652 ev_tol is zero. Since these computations are performed with 02653 finite precision doubles, ev_tol is generally not zero. 02654 Returns: 02655 Unit normal 02656 */ 02657 ON_DECL 02658 bool ON_GetTrianglePlaneEquation( 02659 const ON_3dPoint& A, 02660 const ON_3dPoint& B, 02661 const ON_3dPoint& C, 02662 double* a, 02663 double* b, 02664 double* c, 02665 double* d, 02666 double* evaluation_tol 02667 ); 02668 02669 #endif