QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_mesh.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
16#if !defined(OPENNURBS_MESH_INC_)
17#define OPENNURBS_MESH_INC_
18
19class ON_Mesh;
21class ON_MeshEdgeRef;
22class ON_MeshFaceRef;
23#if defined(OPENNURBS_PLUS)
24class ON_MMX_POINT;
25class ON_MESH_POINT;
26#endif
27
29//
30// Class ON_Mesh
31//
33{
34 // surface meshing perameters
35public:
36 static
37 double Tolerance( double relative_tolerance, double actual_size );
38
41 // C++ default works fine // ON_MeshParameters(const ON_MeshParameters& );
42 // C++ default works fine // ON_MeshParameters& operator=(const ON_MeshParameters&);
43
44 bool operator!=(const ON_MeshParameters&) const;
45 bool operator==(const ON_MeshParameters&) const;
46
47 // compares with mesh's mesh parameters
48 bool operator==(const ON_Mesh&) const;
49 bool operator!=(const ON_Mesh&) const;
50
51 void Dump( ON_TextLog& test_log ) const;
52
53 void Default();
54
55 /*
56 Description:
57 Tool for provding a simple slider interface.
58 Parameters:
59 density - [in] 0.0 <= density <= 1.0
60 0 quickly creates coarse meshes.
61 1 creates accurate meshes but takes lots of time.
62 */
63 void Set(
64 double density,
65 double min_edge_length = 0.0001
66 );
67
68 /*
69 Description:
70 Sets the meshing parameters to create "jagged and faster"
71 render meshes.
72 */
73 void JaggedAndFasterMeshParameters();
74
75 /*
76 Description:
77 Sets the meshing parameters to create "smooth and slower"
78 render meshes.
79 */
80 void SmoothAndSlowerMeshParameters();
81
82 /*
83 Description:
84 Sets the meshing parameters to create the default
85 analysis mesh.
86 */
87 void DefaultAnalysisMeshParameters();
88
89 // Compare() ignores weld and curvature settings
90 // Ignores m_min_tolerance setting.
91 int Compare( const ON_MeshParameters& ) const;
92
93 bool Write( ON_BinaryArchive& ) const;
94 bool Read( ON_BinaryArchive& );
95
96 // Meshing happens in two stages. The first stage creates a
97 // rectangular grid. The second stage refines the grid until
98 // the mesh meets all meshing requirements. The third stage
99 // combines coincident vertices if the resulting mesh is a composite.
100
101 bool m_bCustomSettings; // false - if these settings were used to create
102 // a mesh and the app settings don't match,
103 // then remesh the object using the app
104 // settings.
105 // true - these settings are customized for a
106 // particular object - ignore app mesh
107 // settings.
108
109 bool m_bComputeCurvature; // false - (default) - ON_Mesh::m_K[] not computed
110 // true - ON_Mesh::m_K[] computed
111
112 bool m_bSimplePlanes; // false - (default) planar surfaces are meshed
113 // using the controls below.
114 // true - planar surfaces are meshed using
115 // minimal number of triangles and
116 // aspect/edge controls are ignored.
117
118 bool m_bRefine; // false - skip stage 2
119 // true - (default) do stage 2
120
121 bool m_bJaggedSeams; // false - (default) edges of meshes of joined
122 // b-rep faces match with no gaps or
123 // "T" joints.
124 // true - faces in b-reps are meshed independently.
125 // This is faster but results in gaps and
126 // "T" joints along seams between faces.
127
128 unsigned char m_reserved1;
129 unsigned char m_reserved2;
130 unsigned char m_mesher; // 0 = slow mesher, 1 = fast mesher
131
132 int m_texture_range; // 1: normalized
133 //
134 // each face has a normalized texture range
135 // [0,1]x[0,1].
136 //
137 // 2: packed normalized (default)
138 //
139 // each face in a polysurface is assigned
140 // a texture range that is a subrectangle
141 // of [0,1]x[0,1]. The subrectangles are
142 // mutually disjoint and packed into
143 // into [0,1]x[0,1] in a way that minimizes
144 // distortion and maximizes the coverage
145 // of [0,1]x[0,1]. (This texture style
146 // is suitable for creating texture maps
147 // with popular 3D painting programs.)
148
149 // These controls are used in both stages
150
151 double m_tolerance; // maximum distance from center of edge to surface
152
153
154 double m_relative_tolerance; // If 0 < m_relative_tolerance < 1,
155 double m_min_tolerance; // then the maximum distance from the
156 // center of an edge to the surface will
157 // be <= T, where T is the larger of
158 // (m_min_tolerance,d*m_relative_tolerance),
159 // where d is an esimate of the size of the
160 // object being meshed.
161
162
163 double m_min_edge_length; // edges shorter than m_min_edge_length will
164 // not be split even if the do not meet other
165 // meshing requirements
166
167 double m_max_edge_length; // edges longer than m_max_edge_length will
168 // be split even when they meet all other
169 // meshing requirements
170
171 // These controls are used during stage 1 to generate the grid
172 double m_grid_aspect_ratio; // desired aspect ratio of quads in grid
173 // 0.0 = any aspect ratio is acceptable
174 // values >0 and < sqrt(2) are treated as sqrt(2)
175 int m_grid_min_count; // minimum number of quads in initial grid
176 int m_grid_max_count; // desired masimum number of quads in initial grid
177 double m_grid_angle; // (in radians) maximum angle between surface
178 // normal evaluated at adjacent vertices.
179 // 0.0 is treated as pi.
180 double m_grid_amplification; // The parameters above generate a grid.
181 // If you want fewer quads, set m_grid_amplification
182 // to a value < 1. If you want more quads,
183 // set m_grid_amplification to a value > 1.
184 // default = 1 and values <= 0 are treated as 1.
185
186 // These controls are used during stage 2 to refine the grid
187 double m_refine_angle; // (in radians) maximum angle in radians between
188 // surface normal evaluated at adjacent vertices.
189
190 // These controls are used during stage 3
191 int m_face_type; // 0 = mixed triangle and quads
192 // 1 = all triangles
193 // 2 = all quads
194};
195
197{
198public:
203
204 void Destroy();
205 void EmergencyDestroy();
206
207 bool Set( ON::curvature_style,
208 int, // Kcount,
209 const ON_SurfaceCurvature*, // K[]
210 const ON_3fVector*, // N[] surface normals needed for normal sectional curvatures
211 double = 0.0 // if > 0, value is used for "infinity"
212 );
213
214 bool Write( ON_BinaryArchive& ) const;
215 bool Read( ON_BinaryArchive& );
216
217 ON::curvature_style m_style;
218
219 double m_infinity; // curvature values >= this are considered infinite
220 // and not used to compute the m_average or m_adev
221 int m_count_infinite; // number of "infinte" values
222 int m_count; // count of "finite" values
223 double m_mode; // mode of "finite" values
224 double m_average; // average of "finite" values
225 double m_adev; // average deviation of "finite" values
226
228};
229
231//
232// Class ON_MeshTopology
233//
234
236{
237 // m_tope_count = number of topological edges that begin or
238 // end at this topological vertex.
240
241 // m_topei[] is an array of length m_tope_count with the indices
242 // of the topological edges that begin or end at this topological
243 // vertex. Generally, these edges are listed in no particular
244 // order. If you want the edges listed "radially", then call
245 // ON_MeshTopology::SortVertexEdges.
246 const int* m_topei;
247
248 // m_v_count = number of ON_Mesh vertices that correspond to
249 // this topological vertex.
251
252 // m_vi[] is an array of length m_v_count with the indices of the
253 // ON_Mesh vertices that correspond to this topological vertex.
254 const int* m_vi;
255};
256
258{
259 // m_topvi[] = indices of the topological verteices where the
260 // edge begins and ends.
261 int m_topvi[2];
262
263 // m_topf_count = number of topological faces tat share this topological edge
265
266 // m_topfi[] is an array of length m_topf_count with the indices of the
267 // topological faces that share this topological edge.
268 const int* m_topfi;
269};
270
272{
273 /*
274 m_topei[] = indices of the topological edges that bound the face.
275 If m_topei[2] = m_topei[3], then the face is a triangle, otherwise
276 the face is a quad.
277
278 NOTE WELL:
279 The topological edge with index m_topei[k] ENDS at the
280 vertex corresponding to ON_MeshFace.vi[k]. So, ...
281
282 If the face is a quad, (ON_MeshFace.vi[2]!=ON_MeshFace.vi[3]),
283 the topological edge with index m_topei[0] STARTS at
284 ON_MeshFace.vi[3] and ENDS at ON_MeshFace.vi[0],
285 the topological edge with index m_topei[1] STARTS at
286 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1],
287 the topological edge with index m_topei[2] STARTS at
288 ON_MeshFace.vi[1] and ENDS at ON_MeshFace.vi[2], and
289 the topological edge with index m_topei[3] STARTS at
290 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1],
291
292 If the face is a triangle, (ON_MeshFace.vi[2]==ON_MeshFace.vi[3]),
293 the topological edge with index m_topei[0] STARTS at
294 ON_MeshFace.vi[2] and ENDS at ON_MeshFace.vi[0],
295 the topological edge with index m_topei[1] STARTS at
296 ON_MeshFace.vi[0] and ENDS at ON_MeshFace.vi[1],
297 the topological edge with index m_topei[2] STARTS at
298 ON_MeshFace.vi[1] and ENDS at ON_MeshFace.vi[2].
299 */
300 int m_topei[4];
301
302 /*
303 If m_reve[i] is 0, then the orientation of the edge matches the
304 orientation of the face. If m_reve[i] is 1, then the orientation
305 of the edge is opposite that of the face.
306 */
307 char m_reve[4];
308
309 /*
310 Description:
311 A topological mesh face is a valid triangle if m_topei[0],
312 m_topei[1], m_topei[2] are distinct edges and
313 m_topei[3]=m_topei[2].
314 Returns:
315 True if face is a triangle.
316 */
317 bool IsTriangle() const;
318
319 /*
320 Description:
321 A topological mesh face is a valid quad if m_topei[0],
322 m_topei[1], m_topei[2], and m_topei[3] are distinct edges.
323 Returns:
324 True if face is a quad.
325 */
326 bool IsQuad() const;
327
328 /*
329 Description:
330 A topological mesh face is valid if m_topei[0], m_topei[1],
331 and m_topei[2] are mutually distinct, and m_topei[3] is
332 either equal to m_topei[2] or mutually distinct from the
333 first three indices.
334 Returns:
335 True if face is valid.
336 */
337 bool IsValid( ) const;
338};
339
341{
342public:
343 int vi[4]; // vertex index - vi[2]==vi[3] for tirangles
344 bool IsTriangle() const;
345 bool IsQuad() const;
346 bool IsValid(
347 int // number of vertices in mesh
348 ) const;
349 void Flip();
350};
351
353{
354 // ON_Mesh faces with indices fi[0] <= i < fi[1] reference
355 // vertices with indices vi[0] <= j < vi[1].
356 int vi[2]; // subinterval of mesh m_V[] array
357 int fi[2]; // subinterval of mesh m_F[] array
358 int vertex_count; // = vi[1] - vi[0];
359 int triangle_count; // tris + 2*quads >= fi[1] - fi[0]
360};
361
362#if defined(ON_DLL_TEMPLATE)
363// This stuff is here because of a limitation in the way Microsoft
364// handles templates and DLLs. See Microsoft's knowledge base
365// article ID Q168958 for details.
366#pragma warning( push )
367#pragma warning( disable : 4231 )
368ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshFace>;
369ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyVertex>;
370ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyEdge>;
371ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MeshTopologyFace>;
372ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<struct ON_MeshPart>;
373#pragma warning( pop )
374#endif
375
377{
378 // A mesh topology class is always associated with an ON_Mesh
379 // and can be retrieved by calling ON_Mesh::Topology()
380public:
383
384 bool IsValid() const;
385
386 void Dump( ON_TextLog& ) const;
387
389 // The parent ON_Mesh geometry used to compute this mesh topology.
391
393 // number of topoligical vertices (<= m_mesh.VertexCount())
394 int TopVertexCount() const;
395
397 // number of topoligical edges
398 int TopEdgeCount() const;
399
401 // number of topoligical faces (same as m_mesh.FaceCount())
402 int TopFaceCount() const;
403
404 /*
405 Description:
406 Get a vertex reference to a mesh vertex index.
407 Parameters:
408 ci - [in] component index with type mesh_vertex or meshtop_vertex.
409 Returns:
410 a reference to the vertex
411 */
412 ON_MeshVertexRef VertexRef(ON_COMPONENT_INDEX ci) const;
413
414 ON_MeshVertexRef VertexRef(int topv_index) const;
415
416 /*
417 Description:
418 Get an edge reference.
419 Parameters:
420 ci - [in] component index with type meshtop_edge.
421 Returns:
422 a reference to the edge
423 */
424 ON_MeshEdgeRef EdgeRef(ON_COMPONENT_INDEX ci) const;
425
426 ON_MeshEdgeRef EdgeRef(int tope_index) const;
427
428 /*
429 Description:
430 Get a face reference from a mesh face index.
431 Parameters:
432 ci - [in] component index with type mesh_face.
433 Returns:
434 a reference to the face.
435 Remarks:
436 The OM_Mesh.m_F[] and ON_MeshTopology.m_topf[] arrays
437 are parallel arrays; corresponding faces have identical
438 indices.
439 */
440 ON_MeshFaceRef FaceRef(ON_COMPONENT_INDEX ci) const;
441
442 ON_MeshFaceRef FaceRef(int topf_index) const;
443
444
445 /*
446 Description:
447 Get the 3d point location of a vertex.
448 Parameters:
449 topv_index - [in];
450 Returns:
451 Location of vertex.
452 */
453 ON_3fPoint TopVertexPoint(
454 int topv_index
455 ) const;
456
457 /*
458 Description:
459 Get the 3d line along an edge.
460 Parameters:
461 tope_index - [in];
462 Returns:
463 Line along edge. If input is not valid,
464 the line.from and to are ON_UNSET_POINT
465 */
466 ON_Line TopEdgeLine(
467 int tope_index
468 ) const;
469
471 // returns index of edge that connects topological vertices
472 // returns -1 if no edge is found.
473 int TopEdge(
474 int, int // ON_MeshTopology vertex topology indices
475 ) const;
476
478 // returns ON_MeshTopology vertex topology index of a face
479 // corner. The face is triangle iv TopFaceVertex(2) = TopFaceVertex(3)
480 bool GetTopFaceVertices(
481 int, // ON_MeshTopology face topology index (= ON_Mesh face index)
482 int[4] // ON_MeshTopology vertex indices returned here
483 ) const;
484
485 /*
486 Description:
487 Sort the m_topei[] list of a mesh topology vertex so that
488 the edges are in radial order. The "const" is a white
489 lie to make this function easier to call.
490 Parameter:
491 topvi - [in] index of vertex in m_topv[] array.
492 Remarks:
493 A nonmanifold edge is treated as a boundary edge with respect
494 to sorting. If any boundary or nonmanifold edges end at the
495 vertex, then the first edge will be a boundary or nonmanifold
496 edge.
497 */
498 bool SortVertexEdges( int topvi ) const;
499
500 /*
501 Description:
502 Sort the m_topei[] list of every mesh topology vertex so
503 that the edges are in radial order. The "const" is a white
504 lie to make this function easier to call.
505 Remarks:
506 Same as
507 for ( int topvi = 0; topvi < m_topv.Count(); topvi++ )
508 SortVertexEdges(topvi);
509 */
510 bool SortVertexEdges() const;
511
512 /*
513 Description:
514 Returns true if the topological vertex is hidden.
515 Parameters:
516 topvi - [in] mesh topology vertex index.
517 Returns:
518 True if mesh topology vertex is hidden.
519 Remarks:
520 The mesh topology vertex is hidden if and only if
521 all the ON_Mesh vertices it represents is hidden.
522 */
523 bool TopVertexIsHidden( int topvi ) const;
524
525 /*
526 Description:
527 Returns true if the topological edge is hidden.
528 Parameters:
529 topei - [in] mesh topology edge index.
530 Returns:
531 True if mesh topology edge is hidden.
532 Remarks:
533 The mesh topology edge is hidden if and only if
534 either of its mesh topology vertices is hidden.
535 */
536 bool TopEdgeIsHidden( int topei ) const;
537
538 /*
539 Description:
540 Returns true if the topological face is hidden.
541 Parameters:
542 topfi - [in] mesh topology face index.
543 Returns:
544 True if mesh topology face is hidden.
545 Remarks:
546 The mesh topology face is hidden if and only if
547 any of its mesh topology edges are hidden.
548 */
549 bool TopFaceIsHidden( int topfi ) const;
550
552 // m_topv_map[] has length m_mesh.VertexCount() and
553 // m_topv[m_topv_map[vi]] is the topological mesh vertex that is assocated
554 // the with the mesh vertex m_mesh.m_V[vi].
556
558 // Array of topological mesh vertices. See the comments in the definition
559 // of ON_MeshTopologyVertex for details.
561
563 // Array of topological mesh edges. See the comments in the definition
564 // of ON_MeshTopologyEdge for details.
566
568 // Array of topological mesh faces. The topological face
569 // m_topf[fi] corresponds to the mesh face ON_Mesh.m_F[fi].
570 // See the comments in the definition of ON_MeshTopologyFace
571 // for details. To get the indices of the mesh topology
572 // vertices at the face corners use
573 // topvi = m_topv_map[m_mesh.m_F[fi].vi[n]]
575
576 /*
577 Description:
578 Expert user function for efficiently getting the
579 integer arrays used by the ON_MeshTopologyVertex
580 and ON_MeshTopologyEdge classes.
581 Parameters:
582 count - [in] number of integers in array
583 Returns:
584 pointer to integer array. The array memory
585 will be freed by ~ON_MeshTopology()
586 */
587 int* GetIntArray(int count);
588
589private:
590 friend class ON_Mesh;
591
592 bool Create();
593 void Destroy();
594 void EmergencyDestroy();
595
596 // efficient workspaces for
597 struct memchunk
598 {
599 struct memchunk* next;
600 } *m_memchunk;
602
603private:
604 // no implementation
607};
608
610{
611 // Number of N-gon corners (N >= 3)
612 int N;
613
614 // N-gon vertex indices
615 // An array of N indices into the mesh's m_V[] vertex array.
616 // If the ON_MeshNgon is returned by the ON_MeshNgonList::AddNgon()
617 // function, then the memory for vi is managed by the ON_MeshNgonList
618 // class.
619 int* vi;
620
621 // N-gon face indices
622 // An array of N indices into the mesh's m_F[] face array.
623 // Often, only N-2 indices are used. Unused indices are set to -1.
624 // If the ON_MeshNgon is returned by the ON_MeshNgonList::AddNgon()
625 // function, then the memory for fi is managed by the ON_MeshNgonList
626 // class.
627 int* fi;
628};
629
631{
632public:
636 ON_MeshNgonList& operator=(const ON_MeshNgonList&);
637
638
639 /*
640 Description:
641 Add an N-gon to the list
642 Parameters:
643 N - [in] number of vertices ( >= 5)
644 vi - [in] array of N vertex indices into the mesh's m_V[] array.
645 fi - [in] array of N face indices into the mesh's m_F[] array.
646 Unused indices are set to -1. In many cases
647 there are N-2 valid indices and these are triangles.
648 Remarks:
649 Adding an N-gon may invalidate any pointers previously
650 returned by Ngon.
651 */
652 bool AddNgon(int N, const int* vi, const int* fi);
653 struct ON_MeshNgon* AddNgon(int N);
654
655 /*
656 Returns:
657 Number of Ngons
658 */
659 int NgonCount() const;
660
661 /*
662 Parameters:
663 Ngon_index - [in] zero based index
664 Returns:
665 NULL or a pointer to the Ngon
666 */
667 ON_MeshNgon* Ngon(int Ngon_index) const;
668
669 /*
670 Description:
671 If you know about how many ngons you will need,
672 then use the function to reserve space for them.
673 */
674 bool ReserveNgonCapacity(int capacity);
675
676 /*
677 Description:
678 Destroy N-gon list
679 */
680 void Destroy();
681
682 /*
683 Returns:
684 Approximate number of bytes used by this class.
685 */
686 unsigned int SizeOf() const;
687
688private:
693};
694
696{
697public:
700
701 // maximum number of vertices in a partition
703 // maximum number of triangles in a partition (quads count as 2 triangles)
705
706 // Partition i uses
707 // vertices m_V[j] where
708 //
709 // m_part[i].vi[0] <= j < m_part[i].vi[1]
710 //
711 // and uses faces m_F[k] where
712 //
713 // m_part[i].fi[0] <= k < m_part[i].fi[1]
715};
716
717
718
720{
721public:
723 void Default();
724 bool Write(ON_BinaryArchive&) const;
725 bool Read(ON_BinaryArchive&);
726 void Dump( ON_TextLog& ) const;
727 void Transform( const ON_Xform& xform );
728 void Set(const ON_TextureMapping& mapping);
729
730 /*
731 Description:
732 Sets the tag to the value the meshes have that
733 come out of ON_Brep::CreateMesh().
734 */
735 void SetDefaultSurfaceParameterMappingTag();
736
737 int Compare( const ON_MappingTag& other,
738 bool bCompareId = true,
739 bool bCompareCRC = true,
740 bool bCompareXform = true
741 ) const;
742
743 /*
744 Returns:
745 True if the mapping tag is set.
746 */
747 bool IsSet() const;
748
749 /*
750 Returns:
751 True if the mapping tag is for a mapping with
752 type ON_TextureMapping::srfp_mapping with
753 m_uvw = identity.
754 */
755 bool IsDefaultSurfaceParameterMapping() const;
756
757 // Identifies the mapping used to create the texture
758 // coordinates and records transformations applied
759 // to the mesh after the texture coordinates were
760 // calculated. If the texture mapping does not
761 // change when the mesh is transformed, then set
762 // m_mesh_xform to zero so that compares will work right.
763 //
764 //
765 ON_UUID m_mapping_id; // ON_TextureMapping::m_mapping_id
766 ON_TextureMapping::TYPE m_mapping_type; // ON_TextureMapping::m_type
767 ON__UINT32 m_mapping_crc; // ON_TextureMapping::MappingCRC()
769};
770
772{
773public:
775
777 int m_dim; // 1, 2, or 3
778 ON_SimpleArray<ON_3fPoint> m_T; // texture coordinates
779};
780
781
782#if defined(ON_DLL_TEMPLATE)
783// This stuff is here because of a limitation in the way Microsoft
784// handles templates and DLLs. See Microsoft's knowledge base
785// article ID Q168958 for details.
786#pragma warning( push )
787#pragma warning( disable : 4231 )
788ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_MappingTag>;
789ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_TextureCoordinates>;
790#pragma warning( pop )
791#endif
792
793
795{
797public:
798 ON_Mesh();
799 ON_Mesh(
800 int, // initial face array capacity
801 int, // initial vertex array capacity
802 bool, // true if mesh has vertex normals
803 bool // true if mesh has texture coordinates
804 );
805 ON_Mesh( const ON_Mesh& );
806 ON_Mesh& operator=( const ON_Mesh& );
807 ~ON_Mesh();
808
809 // Override of virtual ON_Object::MemoryRelocate
810 void MemoryRelocate();
811
812 // virtual ON_Object::DestroyRuntimeCache override
813 void DestroyRuntimeCache( bool bDelete = true );
814
815 void Destroy();
816 void EmergencyDestroy(); // Call only when memory used by this class's
817 // members will soon become invalid for reasons
818 // beyond your control. EmergencyDestroy() zeros
819 // anything that could possibly cause
820 // ~ON_Mesh() to crash. Calling
821 // EmergencyDestroy() under normal conditions
822 // will result in ~ON_Mesh() leaking
823 // memory.
824
825 const class ON_MeshTree* MeshTree() const;
826
827 void DestroyTree( bool bDeleteTree = true );
828
830 // ON_Object overrides
831
832 // virtual ON_Object::SizeOf override
833 unsigned int SizeOf() const;
834
835 // virtual ON_Object::DataCRC override
836 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
837
838 /*
839 Description:
840 Tests an object to see if its data members are correctly
841 initialized.
842 Parameters:
843 text_log - [in] if the object is not valid and text_log
844 is not NULL, then a brief englis description of the
845 reason the object is not valid is appened to the log.
846 The information appended to text_log is suitable for
847 low-level debugging purposes by programmers and is
848 not intended to be useful as a high level user
849 interface tool.
850 Returns:
851 @untitled table
852 true object is valid
853 false object is invalid, uninitialized, etc.
854 Remarks:
855 Overrides virtual ON_Object::IsValid
856 */
857 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
858
859 void Dump( ON_TextLog& ) const; // for debugging
860
861 ON_BOOL32 Write( ON_BinaryArchive& ) const;
862
864
865 ON::object_type ObjectType() const;
866
868 // ON_Geometry overrides
869
870 int Dimension() const;
871
872 ON_BOOL32 GetBBox( // returns true if successful
873 double*, // minimum
874 double*, // maximum
875 ON_BOOL32 = false // true means grow box
876 ) const;
877
878 /*
879 Description:
880 Get tight bounding box of the mesh.
881 Parameters:
882 tight_bbox - [in/out] tight bounding box
883 bGrowBox -[in] (default=false)
884 If true and the input tight_bbox is valid, then returned
885 tight_bbox is the union of the input tight_bbox and the
886 mesh's tight bounding box.
887 xform -[in] (default=NULL)
888 If not NULL, the tight bounding box of the transformed
889 mesh is calculated. The mesh is not modified.
890 Returns:
891 True if the returned tight_bbox is set to a valid
892 bounding box.
893 */
894 bool GetTightBoundingBox(
895 ON_BoundingBox& tight_bbox,
896 int bGrowBox = false,
897 const ON_Xform* xform = 0
898 ) const;
899
901 const ON_Xform&
902 );
903
904 // virtual ON_Geometry::IsDeformable() override
905 bool IsDeformable() const;
906
907 // virtual ON_Geometry::MakeDeformable() override
908 bool MakeDeformable();
909
910 ON_BOOL32 SwapCoordinates(
911 int, int // indices of coords to swap
912 );
913
914 // virtual ON_Geometry override
915 bool Morph( const ON_SpaceMorph& morph );
916
917 // virtual ON_Geometry override
918 bool IsMorphable() const;
919
920 // virtual ON_Geometry override
921 bool EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const;
922
923
925 // Interface
926 //
927
928 // creation
929 bool SetVertex(
930 int, // vertex index
931 const ON_3dPoint& // vertex location
932 );
933 bool SetVertex(
934 int, // vertex index
935 const ON_3fPoint& // vertex location
936 );
937 bool SetVertexNormal(
938 int, // vertex index
939 const ON_3dVector& // unit normal
940 );
941 bool SetVertexNormal(
942 int, // vertex index
943 const ON_3fVector& // unit normal
944 );
945 bool SetTextureCoord(
946 int, // vertex index
947 double, double // texture coordinates
948 );
949 bool SetTriangle(
950 int, // face index
951 int,int,int // vertex indices
952 );
953 bool SetQuad(
954 int, // face index
955 int,int,int,int // vertex indices
956 );
957
958 /*
959 Description:
960 Get a vertex reference to a mesh vertex index.
961 Parameters:
962 ci - [in] component index with type mesh_vertex or meshtop_vertex.
963 Returns:
964 a reference to the vertex
965 */
966 ON_MeshVertexRef VertexRef(ON_COMPONENT_INDEX ci) const;
967
968 ON_MeshVertexRef VertexRef(int mesh_V_index) const;
969
970 /*
971 Description:
972 Get an edge reference from a mesh topology edge index.
973 Parameters:
974 ci - [in] component index with type meshtop_edge
975 Returns:
976 a reference to the edge
977 */
978 ON_MeshEdgeRef EdgeRef(ON_COMPONENT_INDEX ci) const;
979
980 ON_MeshEdgeRef EdgeRef(int tope_index) const;
981
982 /*
983 Description:
984 Get a face reference from a mesh face index.
985 Parameters:
986 ci - [in] component index with type mesh_face.
987 Returns:
988 a reference to the face
989 */
990 ON_MeshFaceRef FaceRef(ON_COMPONENT_INDEX ci) const;
991
992 ON_MeshFaceRef FaceRef(int mesh_F_index) const;
993
994 /*
995 Parameters:
996 ci - [in] a component index with type mesh_vertex, meshtop_vertex,
997 meshtop_edge, or mesh_face.
998 Returns:
999 A pointer to an ON_MeshVertexRef, ON_MeshEdgeRef, or ON_MeshFaceRef.
1000 The caller must delete the returned object when it is no longer
1001 needed.
1002 See Also:
1003 ON_Mesh::VertexRef
1004 ON_Mesh::EdgeRef
1005 ON_Mesh::FaceRef
1006 */
1007 ON_Geometry* MeshComponent(
1008 ON_COMPONENT_INDEX ci
1009 ) const;
1010
1011 // query
1012 int VertexCount() const;
1013 int FaceCount() const;
1014 int QuadCount() const; // number of faces that are quads
1015 int TriangleCount() const; // number of faces that are triangles
1016 bool HasVertexNormals() const; // normals at vertices
1017 bool HasFaceNormals() const;
1018 bool HasTextureCoordinates() const;
1019 bool HasSurfaceParameters() const;
1020 bool HasPrincipalCurvatures() const;
1021 bool HasVertexColors() const;
1022
1023 /*
1024 Returns:
1025 Number of vertices that are hidden.
1026 */
1027 int HiddenVertexCount() const;
1028
1029 bool GetCurvatureStats(
1030 ON::curvature_style,
1032 ) const;
1033
1034 void InvalidateVertexBoundingBox(); // Call if defining geometry is changed by
1035 // directly manipulating the m_V[] array.
1036 void InvalidateVertexNormalBoundingBox(); // Call if defining geometry is changed by
1037 // directly manipulating the m_N[] array.
1038 void InvalidateTextureCoordinateBoundingBox(); // Call if defining geometry is changed by
1039 // directly manipulating the m_T[] array.
1040 void InvalidateCurvatureStats(); // Call if defining geometry is changed by
1041 // directly manipulating the m_T[] array.
1042 void InvalidateBoundingBoxes(); // Invalidates all cached bounding box information.
1043
1044
1045 void Flip(); // reverses face orientations and flips vertex and face normals
1046
1047 void FlipVertexNormals(); // reverses vertex normals
1048 void FlipFaceNormals(); // reverses face normals
1049 void FlipFaceOrientation(); // reverses face orientation (does nothing to normals)
1050
1051 void SetMeshParameters( const ON_MeshParameters& );
1052 const ON_MeshParameters* MeshParameters() const;
1053 void DeleteMeshParameters();
1054
1055
1056 bool UnitizeVertexNormals();
1057 bool UnitizeFaceNormals();
1058 bool CountQuads();
1059
1060 /*
1061 Description:
1062 Splits all quads along the short diagonal.
1063 */
1064 bool ConvertQuadsToTriangles();
1065
1066 /*
1067 Description:
1068 Joins adjacent triangles into quads if the resulting quad
1069 is nice.
1070 Parameters:
1071 angle_tol_radians - [in] Used to compare adjacent
1072 triangles' face normals. For two triangles to be considered,
1073 the angle between their face normals has to be <= angle_tol_radians.
1074 When in doubt use ON_PI/90.0 (2 degrees).
1075 min_diagonal_length_ratio - [in] ( <= 1.0) For two triangles to be
1076 considered the ratio of the resulting quad's diagonals
1077 (length of the shortest diagonal)/(length of longest diagonal).
1078 has to be >= min_diagonal_length_ratio.
1079 When in doubt us .875.
1080 */
1081 bool ConvertTrianglesToQuads(
1082 double angle_tol_radians,
1083 double min_diagonal_length_ratio
1084 );
1085
1086 bool ComputeFaceNormals(); // compute face normals for all faces
1087 bool ComputeFaceNormal(int); // computes face normal of indexed face
1088
1089 int CullDegenerateFaces(); // returns number of degenerate faces
1090 int CullUnusedVertices(); // returns number of culled vertices
1091
1092 // Description:
1093 // Removes any unreferenced objects from arrays, reindexes as needed,
1094 // and shrinks arrays to minimum required size.
1095 bool Compact();
1096
1097 bool ComputeVertexNormals(); // uses face normals to cook up a vertex normal
1098
1100 // Scales textures so the texture domains are [0,1] and
1101 // eliminates any texture rotations.
1102 bool NormalizeTextureCoordinates();
1103
1105 // Description:
1106 // Transposes the texture coordinates
1107 // Returns
1108 // true - success
1109 bool TransposeTextureCoordinates();
1110 bool TransposeSurfaceParameters();
1111
1113 // Description:
1114 // Reverse one coordinate direction of the texture coordinates, within texture domain m_tex_domain
1115 // Parameters:
1116 // dir -[in] - dir=0 first texture coordinate is reversed
1117 // dir=1 second texture coordinate is reversed
1118 // Returns
1119 // true - success
1120 bool ReverseTextureCoordinates( int dir );
1121 bool ReverseSurfaceParameters( int dir );
1122
1123
1124
1125 /*
1126 Description:
1127 Use a texture mapping function to set the m_T[] values.
1128 Parameters:
1129 mapping - [in]
1130 mesh_xform - [in]
1131 If not NULL, the mapping calculation is performed as
1132 if the mesh were transformed by mesh_xform; the
1133 location of the mesh is not changed.
1134 bLazy - [in]
1135 If true and the m_T[] values were set using the same
1136 mapping parameters, then no calculation is performed.
1137 Returns:
1138 True if successful.
1139 See Also:
1140 ON_TextureMapping::GetTextureCoordinates
1141 */
1142 bool SetTextureCoordinates(
1143 const class ON_TextureMapping& mapping,
1144 const class ON_Xform* mesh_xform = 0,
1145 bool bLazy = true
1146 );
1147
1148 bool HasCachedTextureCoordinates() const;
1149
1150 const ON_TextureCoordinates* CachedTextureCoordinates(
1151 const ON_UUID& mapping_id
1152 ) const;
1153
1154 const ON_TextureCoordinates* SetCachedTextureCoordinates(
1155 const class ON_TextureMapping& mapping,
1156 const class ON_Xform* mesh_xform = 0,
1157 bool bLazy = true
1158 );
1159
1160 bool EvaluateMeshGeometry( const ON_Surface& ); // evaluate surface at tcoords
1161 // to set mesh geometry
1162
1163 // finds all coincident vertices and merges them if break angle is small enough
1164 bool CombineCoincidentVertices(
1165 ON_3fVector, // coordinate tols for considering vertices
1166 // to be coincident
1167 double // cosine normal angle tolerance in radians
1168 // if vertices are coincident, then they are combined
1169 // if NormalA o NormalB >= this value
1170 );
1171
1172 /*
1173 Description:
1174 Combines identical vertices.
1175 Parameters:
1176 bIgnoreVertexNormals - [in] If true, then vertex normals
1177 are ignored when comparing vertices.
1178 bIgnoreTextureCoordinates - [in] If true, then vertex
1179 texture coordinates, colors, and principal curvatures
1180 are ignored when comparing vertices.
1181 Returns:
1182 True if the mesh is changed, in which case the returned
1183 mesh will have fewer vertices than the input mesh.
1184 */
1185 bool CombineIdenticalVertices(
1186 bool bIgnoreVertexNormals = false,
1187 bool bIgnoreTextureCoordinates = false
1188 );
1189
1190 void Append( const ON_Mesh& ); // appends a copy of mesh to this and updates
1191 // indices of appended mesh parts
1192
1193 void SetClosed(int);
1194
1195 /*
1196 Returns:
1197 True if every mesh "edge" has two or more faces.
1198 */
1199 bool IsClosed() const;
1200
1201 /*
1202 Description:
1203 Determine if the mesh is a manifold.
1204 Parameters:
1205 bTopologicalTest - [in]
1206 If true, the query treats coincident vertices as
1207 the same.
1208 pbIsOriented - [out]
1209 If the input pointer is not NULL, then the returned
1210 value of *pbIsOriented will be true if the mesh
1211 is a manifold and adjacent faces have compatible
1212 face normals.
1213 pbHasBoundary - [out]
1214 If the input pointer is not NULL, then the returned
1215 value of *pbHasBoundary will be true if the mesh
1216 is a manifold and there is at least one "edge"
1217 with no adjacent faces have compatible
1218 face normals.
1219 Returns:
1220 True if every mesh "edge" has at most two adjacent faces.
1221 */
1222 bool IsManifold(
1223 bool bTopologicalTest,
1224 bool* pbIsOriented = NULL,
1225 bool* pbHasBoundary = NULL
1226 ) const;
1227
1228 /*
1229 Description:
1230 Appends a list of mesh edges that begin or end at the specified
1231 vertices to the edges[] array.
1232 Parameters:
1233 vcount - [in]
1234 number of vertices
1235 vertex_index - [in]
1236 array of vertex indices
1237 bNoDuplicates - [in]
1238 If true, then only one edges[] is added for each edge,
1239 the first vertex index will alwasy be less than the
1240 second, and the returned elements are sorted in dictionary
1241 order.
1242 If false and an edge is shared by multiple faces, then
1243 there will be an edges[] element added for each face and the
1244 order of the vertex indicies will indicate the orientation
1245 of the edge with respect to the face. No sorting is performed
1246 in this case.
1247 edges - [out]
1248 Edges that begin or end at one of the specified vertices are
1249 appended to this array. Each ON_2dex records the start and
1250 end vertex index.
1251 Returns:
1252 Number of ON_2dex values appended to the edges[] array.
1253 */
1254 int GetVertexEdges(
1255 int vcount,
1256 const int* vertex_index,
1257 bool bNoDuplicates,
1259 ) const;
1260
1261 /*
1262 Description:
1263 Appends a list of mesh edges to the edges[] array.
1264 Parameters:
1265 edges - [out]
1266 Each edges[] element is a pair of vertex indices. There
1267 is at least one face in the mesh with an edge running between
1268 the indicies.
1269 Returns:
1270 Number of ON_2dex values appended to the edges[] array.
1271 */
1272 int GetMeshEdges(
1274 ) const;
1275
1276#if defined(OPENNURBS_PLUS)
1277
1278 /*
1279 Description:
1280 Get the point on the mesh that is closest to P.
1281 Parameters:
1282 P - [in] test point
1283 Q - [out] point on the mesh
1284 maximum_distance = 0.0 - [in]
1285 optional upper bound on the distance
1286 from P to the mesh. If you are only
1287 interested in finding a point Q on the
1288 mesh when P.DistanceTo(Q) < maximum_distance,
1289 then set maximum_distance to that value.
1290 Returns:
1291 True if successful. If false, the value of Q
1292 is undefined.
1293 */
1294 bool GetClosestPoint(
1295 const ON_3dPoint& P,
1296 ON_MESH_POINT* Q,
1297 double maximum_distance = 0.0
1298 ) const;
1299
1300 /*
1301 Description:
1302 Quickly intersect this mesh with meshB. Ignore overlaps
1303 and near misses.
1304 Parameters:
1305 meshB - [in]
1306 lines - [out] Intersection lines are appended to
1307 this list.
1308 Returns:
1309 number of lines appended to lines[] array.
1310 Remarks:
1311 The InstersectMesh function will will create a meshtree, a mesh topology
1312 and face normals of this mesh and meshB. Note: if you create these in
1313 multiple memory pools you run the risk of crashing or leaking memory if
1314 you are not careful.
1315 */
1316 int IntersectMesh(
1317 const ON_Mesh& meshB,
1319 ) const;
1320
1321 /*
1322 Description:
1323 Carefully intersect this mesh with meshB.
1324 Parameters:
1325 meshB - [in]
1326 x - [out] Each element of x is a polyline of ON_MMX_POINTs.
1327 intersection_tolerance - [in]
1328 overlap_tolerance - [in]
1329 Returns:
1330 number of olylines appended to x[] array.
1331 Remarks:
1332 The InstersectMesh function will will create a meshtree, a mesh topology
1333 and face normals of this mesh and meshB. Note: if you create these in
1334 multiple memory pools you run the risk of crashing or leaking memory if
1335 you are not careful.
1336 */
1337 int IntersectMesh(
1338 const ON_Mesh& meshB,
1340 double intersection_tolerance = 0.0,
1341 double overlap_tolerance = 0.0
1342 ) const;
1343
1344#endif
1345
1346 /*
1347 Description:
1348 Compute area of the mesh.
1349 Parameters:
1350 error_estimate - [out] if not NULL, an upper bound on the error
1351 in the area calculation is returned.
1352 Example:
1353
1354 ON_Mesh mesh = ...;
1355 double area, error_estimate;
1356 area = mesh.Area(&error_estimate);
1357 printf("mesh area = %g (+/- %g)\n",area,error_estimate);
1358
1359 Returns:
1360 Area of the mesh.
1361 */
1362 double Area( double* error_estimate = NULL ) const;
1363
1364 /*
1365 Description:
1366 Compute area centroid of the mesh.
1367 Parameters:
1368 area - [out] it not NULL, area of the mesh
1369 Returns:
1370 Location of area centroid.
1371 See Also:
1372 ON_Mesh::AreaMassProperties
1373 */
1374 ON_3dPoint AreaCentroid(
1375 double* area = NULL
1376 ) const;
1377
1378 /*
1379 Description:
1380 Calculate area mass properties of the mesh.
1381 Parameters:
1382 mp - [out]
1383 bArea - [in] true to calculate area
1384 bFirstMoments - [in] true to calculate area first moments,
1385 area and area centroid.
1386 bSecondMoments - [in] true to calculate area second moments.
1387 bProductMoments - [in] true to calculate area product moments.
1388 Returns:
1389 True if successful.
1390 */
1391 bool AreaMassProperties(
1393 bool bArea = true,
1394 bool bFirstMoments = true,
1395 bool bSecondMoments = true,
1396 bool bProductMoments = true
1397 ) const;
1398
1399
1400 /*
1401 Description:
1402 Compute volume of the mesh.
1403 Parameters:
1404 base_point - [in] optional base point When computing the volume of
1405 solid defined by several meshes, pass the same base_point to each call
1406 to volume. When computing the volume of a solid defined by a single
1407 mesh, the center of the bounding box is a good choice for base_point.
1408 error_estimate - [out] if not NULL, an upper bound on the error
1409 in the volume calculation is returned.
1410 Returns:
1411 volume of the mesh.
1412 Example:
1413
1414 // Assume a solid is enclosed by 3 meshes, mesh1, mesh2, and mesh3.
1415 // The volume of the solid can be computed as follows.
1416 ON_Mesh mesh1=..., mesh2=..., mesh3=...;
1417 // use the center of the solid's bounding box as a common base point.
1418 ON_BoundingBox bbox = mesh1.BoundingBox();
1419 mesh2.GetBoundingBox(bbox,true);
1420 mesh3.GetBoundingBox(bbox,true);
1421 ON_3dPoint base_point = bbox.Center()
1422 double vol1_err, vol2_err, vol3_err;
1423 double vol1 = mesh1.Volume(base_point,&vol1_err);
1424 double vol2 = mesh2.Volume(base_point,&vol2_err);
1425 double vol3 = mesh3.Volume(base_point,&vol3_err);
1426 double volume = vol1 + vol2 + vol3;
1427 double error_estimate = vol1_err + vol2_err + vol3_err;
1428 printf("mesh volumd = %g (+/- %g)\n",volume,error_estimate);
1429 */
1430 double Volume(
1431 ON_3dPoint base_point = ON_origin,
1432 double* error_estimate = NULL
1433 ) const;
1434
1435
1436 /*
1437 Description:
1438 Compute volume centroid of the mesh.
1439 Parameters:
1440 base_point - [in] When computing the centroid of a solid
1441 volume defined by several meshes, pass the same base_point
1442 to each call to GetVolumeCentroid() and add the answers.
1443 When computing the centroid of a solid defined by a single
1444 mesh, the center of the bounding box is a good choice for base_point.
1445 volume - [out] it not NULL, Volume of the mesh
1446 Returns:
1447 Location of the volume centroid.
1448 */
1449 ON_3dPoint VolumeCentroid(
1450 ON_3dPoint base_point = ON_origin,
1451 double* volume = NULL
1452 ) const;
1453
1454 /*
1455 Description:
1456 Calculate volume mass properties of the mesh.
1457 Parameters:
1458 base_point - [in] When computing the volume mass properties
1459 of a solid volume defined by several meshes, pass the same
1460 base_point to each call to VolumeMassProperties() and add
1461 the answers. When computing the volume mass properties of
1462 a solid defined by a single mesh, the center of the
1463 bounding box is a good choice for base_point. If the mesh
1464 is closed, you can pass ON_UNSET_POINT and the
1465 center of the bounding box will be used.
1466 mp - [out]
1467 bVolume - [in] true to calculate volume
1468 bFirstMoments - [in] true to calculate volume first moments,
1469 volume, and volume centroid.
1470 bSecondMoments - [in] true to calculate volume second moments.
1471 bProductMoments - [in] true to calculate volume product moments.
1472 base_point - [in]
1473 If the surface is closed, then pass ON_UNSET_VALUE.
1474
1475 This parameter is for expert users who are computing a
1476 volume whose boundary is defined by several non-closed
1477 breps, surfaces, and meshes.
1478
1479 When computing the volume, volume centroid, or volume
1480 first moments of a volume whose boundary is defined by
1481 several breps, surfaces, and meshes, pass the same
1482 base_point to each call to VolumeMassProperties.
1483
1484 When computing the volume second moments or volume product
1485 moments of a volume whose boundary is defined by several
1486 breps, surfaces, and meshes, you MUST pass the entire
1487 volume's centroid as the base_point and the input mp
1488 parameter must contain the results of a previous call
1489 to VolumeMassProperties(mp,true,true,false,false,base_point).
1490 In particular, in this case, you need to make two sets of
1491 calls; use first set to calculate the volume centroid and
1492 the second set calculate the second moments and product
1493 moments.
1494 Returns:
1495 True if successful.
1496 */
1497 bool VolumeMassProperties(
1498 ON_MassProperties& mp,
1499 bool bVolume = true,
1500 bool bFirstMoments = true,
1501 bool bSecondMoments = true,
1502 bool bProductMoments = true,
1503 ON_3dPoint base_point = ON_UNSET_POINT
1504 ) const;
1505
1507 //
1508 // mesh editing
1509 //
1510
1511 /*
1512 Description:
1513 Replace a mesh edge with a vertex at its center and update
1514 adjacent faces as needed.
1515 Parameters:
1516 topei - [in] index of edge in MeshTopology().m_tope[] array
1517 Returns:
1518 true if successful.
1519 */
1520 bool CollapseEdge( int topei );
1521
1522 /*
1523 Description:
1524 Tests a mesh edge to see if it is valid as input to
1525 ON_Mesh::SwapMeshEdge.
1526 Parameters:
1527 topei - [in] index of edge in MeshTopology().m_tope[] array
1528 Returns:
1529 true if edge can be swapped by ON_Mesh::SwapMeshEdge.
1530 See Also:
1531 ON_Mesh::SwapEdge
1532 */
1533 bool IsSwappableEdge( int topei );
1534
1535
1536 /*
1537 Description:
1538 If the edge is shared by two triangular face, then
1539 the edge is "swapped".
1540 Parameters:
1541 topei - [in] index of edge in MeshTopology().m_tope[] array
1542 Returns:
1543 true if successful
1544 See Also:
1545 ON_Mesh::IsSwappableEdge
1546 */
1547 bool SwapEdge( int topei );
1548
1549 /*
1550 Description:
1551 Removes a face from a mesh and does not alter the
1552 geometry of the remaining mesh.
1553 Parameters:
1554 meshfi - [in] index of face in ON_Mesh.m_F[] array
1555 Remarks:
1556 This function calls DestroyTopology() and DestroyPartition().
1557 The caller is responsible for calling Compact() if that step
1558 is required.
1559 Returns:
1560 true if successful
1561 */
1562 bool DeleteFace( int meshfi );
1563
1564 /*
1565 Description:
1566 Destroys the m_H[] array and sets m_hidden_count=0.
1567 */
1568 void DestroyHiddenVertexArray();
1569
1570 /*
1571 Returns:
1572 If the mesh has some hidden vertices, then an array
1573 of length VertexCount() is returned and the i-th
1574 element is true if the i-th vertex is hidden.
1575 If no vertices are hidden, NULL is returned.
1576 */
1577 const bool* HiddenVertexArray() const;
1578
1579 /*
1580 Description:
1581 Set the runtime vertex hidden flag.
1582 Parameters:
1583 meshvi - [in] mesh vertex index
1584 bHidden - [in] true to hide vertex
1585 */
1586 void SetVertexHiddenFlag( int meshvi, bool bHidden );
1587
1588 /*
1589 Description:
1590 Returns true if the mesh vertex is hidden. This is a runtime
1591 setting that is not saved in 3dm files.
1592 Parameters:
1593 meshvi - [in] mesh vertex index.
1594 Returns:
1595 True if mesh vertex is hidden.
1596 */
1597 bool VertexIsHidden( int meshvi ) const;
1598
1599 /*
1600 Description:
1601 Returns true if the mesh face is hidden. This is a runtime
1602 setting that is not saved in 3dm files.
1603 Parameters:
1604 meshfi - [in] mesh face index.
1605 Returns:
1606 True if mesh face is hidden.
1607 Remarks:
1608 A face is hidden if, and only if, at least one of its
1609 vertices is hidden.
1610 */
1611 bool FaceIsHidden( int meshvi ) const;
1612
1613
1615 //
1616 // mesh topology
1617 //
1618 // In order to keep the mesh facet definition simple and make the mesh
1619 // definition easily used in common rendering application, if two facets
1620 // share a vertex location but have different normals, curvatures,
1621 // textures, etc., at that common vertex location, then the vertex is
1622 // duplicated. When the topology of the mesh needs to be known,
1623 // use Topology() to get a class that provides complete topological
1624 // information about the mesh.
1625 const ON_MeshTopology& Topology() const;
1626
1628 // If you modify the mesh in any way that may change its topology,
1629 // then call DestroyTopology(). Specifically if you add or remove
1630 // vertices or face, change vertex locations, or change the face m_vi[]
1631 // values, then you must call DestroyTopology().
1632 void DestroyTopology();
1633
1635 //
1636 // mesh partitions
1637 //
1638 // In ancient times, some rendering engines were only able to process
1639 // small batches of triangles and th CreatePartition() function was
1640 // provided to partition the mesh into subsets of vertices and faces
1641 // that those renering engines could handle.
1642 //
1643 const ON_MeshPartition* CreatePartition(
1644 int, // maximum number of vertices in a partition
1645 int // maximum number of triangles in a partition
1646 );
1647 const ON_MeshPartition* Partition() const;
1648 void DestroyPartition();
1649
1650 /*
1651 Description:
1652 Extract the portion of this mesh defined by mesh_part.
1653 Parameters:
1654 mesh_part - [in]
1655 defines portion of the mesh to extract.
1656 mesh - [in] (can be null, cannot be = "this).
1657 If mesh is no null, the extracted mesh will be put into
1658 this mesh. If mesh is null, the extracted mesh will
1659 be created in a mesh allocated on the heap using the
1660 new operator.
1661 Returns:
1662 A pointer to the submesh. If the input mesh parameter is null,
1663 then the caller must delete this mesh when it is no longer needed.
1664 If the input is invalid, then null is returned.
1665 */
1666 ON_Mesh* MeshPart(
1667 const ON_MeshPart& mesh_part,
1668 ON_Mesh* mesh
1669 ) const;
1670
1672 //
1673 // mesh N-gon lists.
1674 // ON_Mesh objects support faces that are triangle or quads.
1675 // When a mesh is created from a format that supports N-gons
1676 // for N larger than 4, an optional N-gon list can be added
1677 // that specifies the vertices and faces that make up the N-gon.
1678 //
1679
1680 /*
1681 Description:
1682 If the mesh has an N-gon list, return a pointer to it.
1683 Returns:
1684 A pointer to the current N-gon list or NULL.
1685 */
1686 const class ON_MeshNgonList* NgonList() const;
1687
1688 /*
1689 Description:
1690 If an N-gon list exists, it is returned and can be modified.
1691 If no N-gon list exists, a new empty list is returned and
1692 it can be modified.
1693 Returns:
1694 A pointer to the N-gon list that can be modified.
1695 */
1696 class ON_MeshNgonList* ModifyNgonList();
1697
1698 /*
1699 Description:
1700 Destroy any existing N-gon list.
1701 */
1702 void DestroyNgonList();
1703
1704
1706 // Implementation - mesh geometry
1707
1708 // m_V[] - vertex locations
1709 // In a case where adjacent facets share a vertex
1710 // location but have distinct normals or texture
1711 // coordinates at that location, the vertex must
1712 // be duplicated.
1714
1715 // m_F[] facets (triangles or quads)
1717
1718 // m_N[] OPTIONAL vertex unit normals
1719 // If m_N[] is empty or m_N.Count() != m_V.Count(),
1720 // Either m_N[] has zero count or it m_N[j] is the
1721 // the unit vertex normal at m_V[j].
1723
1724 // m_FN[] OPTIONAL face unit normals
1725 // If m_FN[] is empty or m_FN.Count() != m_F.Count(),
1726 // then m_FN is ignored. Otherwise m_FN[j] is the
1727 // unit normal for the facet m_F[j].
1729
1731 // Implementation - texture coordinates
1732 //
1733 // OPTIONAL texture coordinates for each vertex
1734
1735 // It would be nice if this were an ON_TextureCoordinates,
1736 // but that breaks lots of checked out code that assumes
1737 // m_T is an array of ON_2fPoints.
1738 ON_MappingTag m_Ttag; // OPTIONAL tag for values in m_T[]
1739 ON_2fPointArray m_T; // OPTIONAL texture coordinates for each vertex
1740
1741 // RUNTIME ONLY
1742 // This array is used to cache texture coordinates used by
1743 // rendering applications that require 1d texture coordinates,
1744 // 3d texture coordinates, or multiple sets of texture
1745 // coordinates (e.g. blended textures with different mappings).
1746 // Users are responsible for verifying
1747 // m_TC[i].m_T.Count() = m_V.Count()
1749
1750 // If m_T.Count() == m_V.Count(), then the mesh has texture coordinates
1751 // and m_T[j] is the texture coordinate for vertex m_V[j].
1752 //
1753 // When opennurbs or Rhino meshes an ON_Surface or ON_Brep, the texture
1754 // coordinates have a "canonical" linear relationship with the surface
1755 // parameters that is described in the next section. However, various
1756 // mappings, spherical, planar, cylindrical, etc., can be applied that
1757 // change the values of the texture coordinates.
1758 //
1759 // If a texture mapping function was used to set the m_T[] values,
1760 // then the id and serial number of the mapping function is saved
1761 // in m_mapping_id and m_mapping_sn. The intended use of these fields
1762 // is to make it easy to avoid unnecessary recalculation.
1763 // If a mesh is modified, then m_mapping_id should be set to nil
1764 // and m_mapping_crc should be set to 0.
1765 //
1767
1768
1770 // Implementation - surface parameters and packed texture
1771 // information
1772 //
1773 // If m_S.Count() == m_V.Count(), then the mesh is a tesselation
1774 // of a parameteric surface and m_S[j] is the surface parameter at
1775 // m_V[j]. Storing values in m_S[] is OPTIONAL.
1776 //
1777 // If m_srf_scale[] has positive values, then they report
1778 // the world coordinate size of a rectangle that would
1779 // minimize texture distortion if it were mapped to the
1780 // mesh using normalized surface evaluation parameters.
1781 // This information is used to calculate high quality
1782 // packed texture coordinates.
1784 ON_Interval m_srf_domain[2]; // surface evaluation domain.
1785 double m_srf_scale[2];
1786
1787
1788 // Packed texture information.
1789 //
1790 // If either of the m_packed_tex_domain[] intervals is a
1791 // proper subinterval of (0,1), then a texture packing
1792 // calculation assigned this subrectangle to this mesh.
1793
1794 ON_Interval m_packed_tex_domain[2];
1795
1796 // The m_packed_tex_rotate setting is valid only when
1797 // m_S, m_srf_domain, m_packed_scale[] and
1798 // m_packed_tex_domain[] are all valid and the texture
1799 // coordinates are based on surface evaluation parameters.
1800 // In this special situation, this boolean records the
1801 // correspondence between the the surface parameters, (u,v),
1802 // and the packed texture coordinates, (s,t),
1803 //
1804 // m_packed_tex_rotate = false:
1805 // a = m_srf_domain[0].NormalizedParameterAt(u);
1806 // b = m_srf_domain[1].NormalizedParameterAt(v);
1807 // s = m_packed_tex_domain[0].ParameterAt(a);
1808 // t = m_packed_tex_domain[1].ParameterAt(b);
1809 //
1810 // x = m_packed_tex_domain[0].NormalizedParameterAt(s);
1811 // y = m_packed_tex_domain[1].NormalizedParameterAt(t);
1812 // u = m_srf_domain[0].ParameterAt(x);
1813 // v = m_srf_domain[1].ParameterAt(y);
1814 //
1815 // m_packed_tex_rotate = true:
1816 // a = m_srf_domain[0].NormalizedParameterAt(u);
1817 // b = m_srf_domain[1].NormalizedParameterAt(v);
1818 // s = m_packed_tex_domain[0].ParameterAt(a);
1819 // t = m_packed_tex_domain[1].ParameterAt(1.0-b);
1820 //
1821 // x = m_packed_tex_domain[0].NormalizedParameterAt(s);
1822 // y = m_packed_tex_domain[1].NormalizedParameterAt(t);
1823 // u = m_srf_domain[0].ParameterAt(y);
1824 // v = m_srf_domain[1].ParameterAt(1.0 - x);
1826
1827 /*
1828 Returns:
1829 True if the m_srf_scale[] values are positive and
1830 the m_packed_tex_domain[] intervals are set to values
1831 that describe a proper subrectangle of (0,1)x(0,1).
1832 True does not necessarily mean the current values in
1833 m_T[] are packed texture coordinates.
1834 */
1835 bool HasPackedTextureRegion() const;
1836
1838 // Implementation - curvature
1839
1840 ON_SimpleArray<ON_SurfaceCurvature> m_K; // OPTIONAL surface curvatures
1841 // Either m_K[] has zero count or it has the same
1842 // count as m_V[], in which case m_K[j] reports
1843 // the surface curvatures at m_V[j].
1844
1846 // Implementation - false color
1847 ON_MappingTag m_Ctag; // OPTIONAL tag for values in m_C[]
1848 ON_SimpleArray<ON_Color> m_C; // OPTIONAL vertex color
1849 // Either m_C[] has zero count or it has the same
1850 // count as m_V[], in which case m_C[j] reports
1851 // the color assigned to m_V[j].
1852
1854 // Implementation - runtime vertex visibility - not saved in 3dm files.
1855 ON_SimpleArray<bool> m_H; // OPTIONAL vertex visibility.
1856 // If m_H.Count() = m_V.Count(), then
1857 // m_H[vi] is true if the vertex m_V[vi]
1858 // is hidden. Otherwise, all vertices are visible.
1859 int m_hidden_count; // number of vertices that are hidden
1860 // = number of true values in m_H[] array.
1861
1863 // Implementation - runtime UI information
1864 const ON_Object* m_parent; // runtime parent geometry (use ...::Cast() to get it)
1865
1866protected:
1867 friend class ON_MeshVertexRef;
1868 friend class ON_MeshEdgeRef;
1869 friend class ON_MeshFaceRef;
1870
1871
1873 // Implementation - mesh topology
1875
1876 ON_MeshParameters* m_mesh_parameters; // If mesh was created from a parametric surface,
1877 // these parameters were used to create the mesh.
1881
1882 int m_closed; // -1=unknown 0=mesh is not closed, 1 = mesh is closed, 2 = closed with duplicate vertices
1883
1884 // The bounding boxes are valid if m_?box[0][0] <= m_?box[0][1];
1885 float m_vbox[2][3]; // 3d bounding box of all referenced vertices
1886 float m_nbox[2][3]; // 3d bounding box of all referenced unit normals
1887 // (for estimation of Gauss map bounds)
1888 float m_tbox[2][2]; // 2d bounding box of all referenced texture coordinates
1889 ON_MeshCurvatureStats* m_kstat[4]; // gaussian,mean,min,max,sectionx,sectiony,sectionz
1890
1891 // sub-mesh information rendering large meshes
1893
1894 class ON_MeshTree* m_mtree;
1895
1896private:
1897 bool Write_1( ON_BinaryArchive& ) const; // uncompressed 1.x format
1898 bool Write_2( int, ON_BinaryArchive& ) const; // compressed 2.x format
1899 bool Read_1( ON_BinaryArchive& );
1900 bool Read_2( int, ON_BinaryArchive& );
1901 bool WriteFaceArray( int, int, ON_BinaryArchive& ) const;
1902 bool ReadFaceArray( int, int, ON_BinaryArchive& );
1903 bool SwapEdge_Helper( int, bool );
1904};
1905
1907{
1909public:
1912 ON_MeshVertexRef& operator=(const ON_MeshVertexRef&);
1913
1914
1915 // parent mesh
1917
1918 // m_mesh->m_V[] index
1919 // (can be -1 when m_top_vi references a shared vertex location)
1921
1922 // m_mesh->m_top.m_tope[] index
1924
1925
1926 /*
1927 Description:
1928 Override of the virtual ON_Geometry::ComponentIndex().
1929 Returns:
1930 A component index for the vertex. The type of the returned
1931 component index can be
1932 ON_COMPONENT_INDEX::mesh_vertex,
1933 ON_COMPONENT_INDEX::meshtop_vertex, or
1934 ON_COMPONENT_INDEX::invalid_type.
1935 */
1936 ON_COMPONENT_INDEX ComponentIndex() const;
1937
1938 /*
1939 Returns:
1940 The mesh topology associated with this
1941 mesh vertex reference or NULL if it doesn't
1942 exist.
1943 */
1944 const ON_MeshTopology* MeshTopology() const;
1945
1946 /*
1947 Returns:
1948 The 3d location of the mesh vertex. Returns
1949 ON_UNSET_POINT is this ON_MeshVertexRef is not
1950 valid.
1951 */
1952 ON_3dPoint Point() const;
1953
1954 /*
1955 Returns:
1956 The mesh topology vertex associated with this
1957 mesh vertex reference.
1958 */
1959 const ON_MeshTopologyVertex* MeshTopologyVertex() const;
1960
1961 // overrides of virtual ON_Object functions
1962 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
1963 void Dump( ON_TextLog& ) const;
1964 unsigned int SizeOf() const;
1965 ON::object_type ObjectType() const;
1966
1967 // overrides of virtual ON_Geometry functions
1968 int Dimension() const;
1969 ON_BOOL32 GetBBox(
1970 double* boxmin,
1971 double* boxmax,
1972 int bGrowBox = false
1973 ) const;
1975 const ON_Xform& xform
1976 );
1977};
1978
1980{
1982public:
1985 ON_MeshEdgeRef& operator=(const ON_MeshEdgeRef&);
1986
1987 // parent mesh
1989
1990 // m_mesh->m_top.m_tope[] index
1992
1993 /*
1994 Description:
1995 Override of the virtual ON_Geometry::ComponentIndex().
1996 Returns:
1997 A mesh component index for the edge. The type is
1998 ON_COMPONENT_INDEX::meshtop_edge and the index is the
1999 index into the ON_MeshTopology.m_tope[] array.
2000 */
2001 ON_COMPONENT_INDEX ComponentIndex() const;
2002
2003 /*
2004 Returns:
2005 The mesh topology associated with this
2006 mesh edge reference or NULL if it doesn't
2007 exist.
2008 */
2009
2010 const ON_MeshTopology* MeshTopology() const;
2011 /*
2012 Returns:
2013 The 3d location of the mesh edge. Returns
2014 ON_UNSET_POINT,ON_UNSET_POINT, is this ON_MeshEdgeRef
2015 is not valid.
2016 */
2017 ON_Line Line() const;
2018
2019 /*
2020 Returns:
2021 The mesh topology edge associated with this
2022 mesh edge reference.
2023 */
2024 const ON_MeshTopologyEdge* MeshTopologyEdge() const;
2025
2026 // overrides of virtual ON_Object functions
2027 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
2028 void Dump( ON_TextLog& ) const;
2029 unsigned int SizeOf() const;
2030 ON::object_type ObjectType() const;
2031
2032 // overrides of virtual ON_Geometry functions
2033 int Dimension() const;
2034 ON_BOOL32 GetBBox(
2035 double* boxmin,
2036 double* boxmax,
2037 int bGrowBox = false
2038 ) const;
2040 const ON_Xform& xform
2041 );
2042};
2043
2045{
2047public:
2050 ON_MeshFaceRef& operator=(const ON_MeshFaceRef&);
2051
2052 // parent mesh
2054
2055 // m_mesh->m_F[] and m_mesh->m_top.m_tope[] index.
2057
2058 /*
2059 Description:
2060 Override of the virtual ON_Geometry::ComponentIndex().
2061 Returns:
2062 A mesh component index for the face. The type is
2063 ON_COMPONENT_INDEX::mesh_face and the index is the
2064 index into the ON_Mesh.m_F[] array.
2065 */
2066 ON_COMPONENT_INDEX ComponentIndex() const;
2067
2068 /*
2069 Returns:
2070 The mesh topology associated with this
2071 mesh face reference or NULL if it doesn't
2072 exist.
2073 */
2074 const ON_MeshTopology* MeshTopology() const;
2075
2076 /*
2077 Returns:
2078 The mesh face associated with this mesh face reference.
2079 */
2080 const ON_MeshFace* MeshFace() const;
2081
2082 /*
2083 Returns:
2084 The mesh topology face associated with this
2085 mesh face reference.
2086 */
2087 const ON_MeshTopologyFace* MeshTopologyFace() const;
2088
2089 // overrides of virtual ON_Object functions
2090 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
2091 void Dump( ON_TextLog& ) const;
2092 unsigned int SizeOf() const;
2093 ON::object_type ObjectType() const;
2094
2095 // overrides of virtual ON_Geometry functions
2096 int Dimension() const;
2097 ON_BOOL32 GetBBox(
2098 double* boxmin,
2099 double* boxmax,
2100 int bGrowBox = false
2101 ) const;
2103 const ON_Xform& xform
2104 );
2105};
2106
2107/*
2108Description:
2109 Calculate a quick and dirty polygon mesh approximation
2110 of a surface.
2111Parameters:
2112 surface - [in]
2113 mesh_density - [in] If <= 10, this number controls
2114 the relative polygon count. If > 10, this number
2115 specifies a target number of polygons.
2116 mesh - [in] if not NULL, the polygon mesh will be put
2117 on this mesh.
2118Returns:
2119 A polygon mesh approximation of the surface or NULL
2120 if the surface could not be meshed.
2121*/
2122ON_DECL
2124 const ON_Surface& surface,
2125 int mesh_density = 0,
2126 ON_Mesh* mesh = 0
2127 );
2128
2129/*
2130Description:
2131 Calculate a quick and dirty polygon mesh approximation
2132 of a surface.
2133Parameters:
2134 surface - [in]
2135 u_count - [in] >= 2 Number of "u" parameters in u[] array.
2136 u - [in] u parameters
2137 v_count - [in] >= 2 Number of "v" parameters in v[] array.
2138 v - [in] v parameters
2139 mesh - [in] if not NULL, the polygon mesh will be put
2140 on this mesh.
2141Returns:
2142 A polygon mesh approximation of the surface or NULL
2143 if the surface could not be meshed.
2144*/
2145ON_DECL
2147 const ON_Surface& surface,
2148 int u_count,
2149 const double* u,
2150 int v_count,
2151 const double* v,
2152 ON_Mesh* mesh = 0
2153 );
2154
2155/*
2156Description:
2157 Finds the barycentric coordinates of the point on a
2158 triangle that is closest to P.
2159Parameters:
2160 A - [in] triangle corner
2161 B - [in] triangle corner
2162 C - [in] triangle corner
2163 P - [in] point to test
2164 a - [out] barycentric coordinate
2165 b - [out] barycentric coordinate
2166 c - [out] barycentric coordinate
2167 If ON_ClosestPointToTriangle() returns true, then
2168 (*a)*A + (*b)*B + (*c)*C is the point on the
2169 triangle's plane that is closest to P. It is
2170 always the case that *a + *b + *c = 1, but this
2171 function will return negative barycentric
2172 coordinate if the point on the plane is not
2173 inside the triangle.
2174Returns:
2175 True if the triangle is not degenerate. False if the
2176 triangle is degenerate; in this case the returned
2177 closest point is the input point that is closest to P.
2178*/
2179ON_DECL
2182 ON_3dPoint P,
2183 double* a, double* b, double* c
2184 );
2185
2186
2187/*
2188Description:
2189 Finds the barycentric coordinates of the point on a
2190 triangle that is closest to P.
2191Parameters:
2192 A - [in] triangle corner
2193 B - [in] triangle corner
2194 C - [in] triangle corner
2195 P - [in] point to test
2196 a - [out] barycentric coordinate
2197 b - [out] barycentric coordinate
2198 c - [out] barycentric coordinate
2199 If ON_ClosestPointToTriangle() returns true, then
2200 (*a)*A + (*b)*B + (*c)*C is the point on the
2201 triangle's plane that is closest to P. It is
2202 always the case that *a + *b + *c = 1, but this
2203 function will return negative barycentric
2204 coordinate if the point on the plane is not
2205 inside the triangle.
2206Returns:
2207 True if the triangle is not degenerate. False if the
2208 triangle is degenerate; in this case the returned
2209 closest point is the input point that is closest to P.
2210*/
2211ON_DECL
2213 const ON_3dPoint& A,
2214 const ON_3dPoint& B,
2215 const ON_3dPoint& C,
2216 ON_3dPoint P,
2217 double* a, double* b, double* c
2218 );
2219
2220
2221/*
2222Description:
2223 Calculate a mesh representation of the NURBS surface's control polygon.
2224Parameters:
2225 nurbs_surface - [in]
2226 bCleanMesh - [in] If true, then degenerate quads are cleaned
2227 up to be triangles. Surfaces with singular
2228 sides are a common source of degenerate qauds.
2229 input_mesh - [in] If NULL, then the returned mesh is created
2230 by a class to new ON_Mesh(). If not null, then this
2231 mesh will be used to store the conrol polygon.
2232Returns:
2233 If successful, a pointer to a mesh.
2234*/
2235ON_DECL
2237 const ON_NurbsSurface& nurbs_surface,
2238 bool bCleanMesh,
2239 ON_Mesh* input_mesh = NULL
2240 );
2241
2242/*
2243Description:
2244 Finds the intersection between a line segment an a triangle.
2245Parameters:
2246 A - [in] triangle corner
2247 B - [in] triangle corner
2248 C - [in] triangle corner
2249 P - [in] start of line segment
2250 Q - [in] end of line segment
2251 abc - [out]
2252 barycentric coordinates of intersection point(s)
2253 t - [out] line coordinate of intersection point(s)
2254Returns:
2255 0 - no intersection
2256 1 - one intersection point
2257 2 - intersection segment
2258*/
2259ON_DECL
2261 const ON_3dPoint& A,
2262 const ON_3dPoint& B,
2263 const ON_3dPoint& C,
2264 const ON_3dPoint& P,
2265 const ON_3dPoint& Q,
2266 double abc[2][3],
2267 double t[2],
2268 double tol
2269 );
2270
2271/*
2272Description:
2273 Finds the unit normal to the triangle
2274Parameters:
2275 A - [in] triangle corner
2276 B - [in] triangle corner
2277 C - [in] triangle corner
2278Returns:
2279 Unit normal
2280*/
2281ON_DECL
2283 const ON_3dPoint& A,
2284 const ON_3dPoint& B,
2285 const ON_3dPoint& C
2286 );
2287
2288/*
2289Description:
2290 Triangulate a 2D simple closed polygon.
2291Parameters:
2292 point_count - [in] number of points in polygon ( >= 3 )
2293 point_stride - [in]
2294 P - [in]
2295 i-th point = (P[i*point_stride], P[i*point_stride+1])
2296 tri_stride - [in]
2297 triangle - [out]
2298 array of (point_count-2)*tri_stride integers
2299Returns:
2300 True if successful. In this case, the polygon is trianglulated into
2301 point_count-2 triangles. The indices of the 3 points that are the
2302 corner of the i-th (0<= i < point_count-2) triangle are
2303 (triangle[i*tri_stride], triangle[i*tri_stride+1], triangle[i*tri_stride+2]).
2304Remarks:
2305 Do NOT duplicate the start/end point; i.e., a triangle will have
2306 a point count of 3 and P will specify 3 distinct non-collinear points.
2307*/
2308ON_DECL
2310 int point_count,
2311 int point_stride,
2312 const double* P,
2313 int tri_stride,
2314 int* triangle
2315 );
2316
2317/*
2318Description:
2319 Fill in a 2d region with triangles.
2320Parameters:
2321 point_count - [in] number of 2d points.
2322 point_stride - [in] i-th point = (point[j],point[j+1]), where
2323 j = i*point_stride.
2324 point - [in] 2d point locations. It is ok to include points that are inside the region
2325 but not at the ednd of an edge. Duplicate points are not permitted.
2326 edge_count - [in] number of edges (if 0, then the input list of point
2327 is treated as a counterclockwise closed polyline.
2328 edge_stride - [in] i-th edge connects points (edge[j],edge[j+1]) where
2329 j = i*edge_stride.
2330 edge - [in] indices of edge ends. Edges can intersect only at shared end points.
2331 edge_side - [in] if NULL, the triangles are built on the left side
2332 of the edges. If not NULL, then
2333 edge[i] determines which side(s) of the edge need
2334 triangles. 1 = left side only, 2 = right side only, 3 = both sides
2335 triangles - [out] triangles are appended to this list. The (i,j,k) are
2336 vertex indices.
2337Returns:
2338 Number of triangles appended to triangles[] array.
2339*/
2340ON_DECL
2341int ON_Mesh2dRegion(
2342 int point_count,
2343 int point_stride,
2344 const double* point,
2345 int edge_count,
2346 int edge_stride,
2347 const int* edge,
2348 const int* edge_side,
2349 ON_SimpleArray<ON_3dex>& triangles
2350 );
2351
2352#endif
2353
2354
@ Line
Definition RSMetaType.h:40
@ Point
Definition RSMetaType.h:50
@ Transform
Definition RSMetaType.h:67
Base class for all dimensioning tools.
Definition Dimension.js:18
Definition opennurbs_array.h:353
Definition opennurbs_array.h:376
Definition opennurbs_point.h:403
Definition opennurbs_point.h:931
Definition opennurbs_array.h:602
Definition opennurbs_fpoint.h:172
Definition opennurbs_array.h:727
Definition opennurbs_fpoint.h:623
Definition opennurbs_archive.h:152
Definition opennurbs_bounding_box.h:25
Definition opennurbs_array.h:760
Definition opennurbs_geometry.h:36
Definition opennurbs_point.h:46
Definition opennurbs_line.h:20
Definition opennurbs_mesh.h:720
ON_TextureMapping::TYPE m_mapping_type
Definition opennurbs_mesh.h:766
ON_Xform m_mesh_xform
Definition opennurbs_mesh.h:768
ON__UINT32 m_mapping_crc
Definition opennurbs_mesh.h:767
ON_UUID m_mapping_id
Definition opennurbs_mesh.h:765
Definition opennurbs_massprop.h:25
Definition opennurbs_mesh.h:197
ON::curvature_style m_style
Definition opennurbs_mesh.h:217
double m_infinity
Definition opennurbs_mesh.h:219
int m_count
Definition opennurbs_mesh.h:222
ON_Interval m_range
Definition opennurbs_mesh.h:227
double m_adev
Definition opennurbs_mesh.h:225
double m_mode
Definition opennurbs_mesh.h:223
double m_average
Definition opennurbs_mesh.h:224
int m_count_infinite
Definition opennurbs_mesh.h:221
Definition opennurbs_mesh.h:1980
const ON_Mesh * m_mesh
Definition opennurbs_mesh.h:1988
int m_top_ei
Definition opennurbs_mesh.h:1991
ON_OBJECT_DECLARE(ON_MeshEdgeRef)
Definition opennurbs_mesh.h:341
Definition opennurbs_mesh.h:2045
int m_mesh_fi
Definition opennurbs_mesh.h:2056
ON_OBJECT_DECLARE(ON_MeshFaceRef)
const ON_Mesh * m_mesh
Definition opennurbs_mesh.h:2053
Definition opennurbs_mesh.h:795
ON_SimpleArray< ON_MeshFace > m_F
Definition opennurbs_mesh.h:1716
int m_closed
Definition opennurbs_mesh.h:1882
int m_triangle_count
Definition opennurbs_mesh.h:1880
int m_quad_count
Definition opennurbs_mesh.h:1879
int m_invalid_count
Definition opennurbs_mesh.h:1878
ON_ClassArray< ON_TextureCoordinates > m_TC
Definition opennurbs_mesh.h:1748
ON_SimpleArray< bool > m_H
Definition opennurbs_mesh.h:1855
friend class ON_MeshEdgeRef
Definition opennurbs_mesh.h:1868
ON_SimpleArray< ON_Color > m_C
Definition opennurbs_mesh.h:1848
int m_hidden_count
Definition opennurbs_mesh.h:1859
ON_MappingTag m_Ttag
Definition opennurbs_mesh.h:1738
ON_3fVectorArray m_FN
Definition opennurbs_mesh.h:1728
ON_MeshPartition * m_partition
Definition opennurbs_mesh.h:1892
ON_3fPointArray m_V
Definition opennurbs_mesh.h:1713
ON_MeshTopology m_top
Definition opennurbs_mesh.h:1874
const ON_Object * m_parent
Definition opennurbs_mesh.h:1864
bool m_packed_tex_rotate
Definition opennurbs_mesh.h:1825
ON_SimpleArray< ON_SurfaceCurvature > m_K
Definition opennurbs_mesh.h:1840
ON_OBJECT_DECLARE(ON_Mesh)
ON_MappingTag m_Ctag
Definition opennurbs_mesh.h:1847
friend class ON_MeshFaceRef
Definition opennurbs_mesh.h:1869
ON_MeshParameters * m_mesh_parameters
Definition opennurbs_mesh.h:1876
const class ON_MeshTree * MeshTree() const
class ON_MeshTree * m_mtree
Definition opennurbs_mesh.h:1894
ON_2dPointArray m_S
Definition opennurbs_mesh.h:1783
ON_3fVectorArray m_N
Definition opennurbs_mesh.h:1722
ON_2fPointArray m_T
Definition opennurbs_mesh.h:1739
friend class ON_MeshVertexRef
Definition opennurbs_mesh.h:1867
Definition opennurbs_mesh.h:631
ON_MeshNgon * m_ngons
Definition opennurbs_mesh.h:691
int m_ngons_count
Definition opennurbs_mesh.h:689
struct ON_NGON_MEMBLK * m_memblk_list
Definition opennurbs_mesh.h:692
int m_ngons_capacity
Definition opennurbs_mesh.h:690
Definition opennurbs_mesh.h:33
double m_relative_tolerance
Definition opennurbs_mesh.h:154
unsigned char m_mesher
Definition opennurbs_mesh.h:130
double m_min_tolerance
Definition opennurbs_mesh.h:155
bool m_bJaggedSeams
Definition opennurbs_mesh.h:121
double m_min_edge_length
Definition opennurbs_mesh.h:163
double m_tolerance
Definition opennurbs_mesh.h:151
double m_grid_angle
Definition opennurbs_mesh.h:177
bool m_bComputeCurvature
Definition opennurbs_mesh.h:109
int m_grid_max_count
Definition opennurbs_mesh.h:176
int m_texture_range
Definition opennurbs_mesh.h:132
double m_grid_aspect_ratio
Definition opennurbs_mesh.h:172
unsigned char m_reserved2
Definition opennurbs_mesh.h:129
bool m_bRefine
Definition opennurbs_mesh.h:118
int m_face_type
Definition opennurbs_mesh.h:191
double m_refine_angle
Definition opennurbs_mesh.h:187
bool m_bSimplePlanes
Definition opennurbs_mesh.h:112
double m_grid_amplification
Definition opennurbs_mesh.h:180
bool m_bCustomSettings
Definition opennurbs_mesh.h:101
unsigned char m_reserved1
Definition opennurbs_mesh.h:128
int m_grid_min_count
Definition opennurbs_mesh.h:175
double m_max_edge_length
Definition opennurbs_mesh.h:167
Definition opennurbs_mesh.h:696
int m_partition_max_vertex_count
Definition opennurbs_mesh.h:702
ON_SimpleArray< struct ON_MeshPart > m_part
Definition opennurbs_mesh.h:714
int m_partition_max_triangle_count
Definition opennurbs_mesh.h:704
Definition opennurbs_mesh.h:377
friend class ON_Mesh
Definition opennurbs_mesh.h:590
ON_MeshTopology & operator=(const ON_MeshTopology &)
bool m_bIsValid
Definition opennurbs_mesh.h:601
ON_SimpleArray< int > m_topv_map
Definition opennurbs_mesh.h:555
ON_SimpleArray< ON_MeshTopologyEdge > m_tope
Definition opennurbs_mesh.h:565
ON_MeshTopology(const ON_MeshTopology &)
ON_SimpleArray< ON_MeshTopologyVertex > m_topv
Definition opennurbs_mesh.h:560
const ON_Mesh * m_mesh
Definition opennurbs_mesh.h:390
ON_SimpleArray< ON_MeshTopologyFace > m_topf
Definition opennurbs_mesh.h:574
Definition opennurbs_mesh.h:1907
const ON_Mesh * m_mesh
Definition opennurbs_mesh.h:1916
int m_mesh_vi
Definition opennurbs_mesh.h:1920
ON_OBJECT_DECLARE(ON_MeshVertexRef)
int m_top_vi
Definition opennurbs_mesh.h:1923
Definition opennurbs_nurbssurface.h:62
Definition opennurbs_objref.h:167
Definition opennurbs_object.h:393
Definition opennurbs_array.h:46
Definition opennurbs_xform.h:1146
Definition opennurbs_point.h:1533
Definition opennurbs_surface.h:58
Definition opennurbs_textlog.h:20
Definition opennurbs_mesh.h:772
ON_MappingTag m_tag
Definition opennurbs_mesh.h:776
int m_dim
Definition opennurbs_mesh.h:777
ON_SimpleArray< ON_3fPoint > m_T
Definition opennurbs_mesh.h:778
Definition opennurbs_texture_mapping.h:37
TYPE
Definition opennurbs_texture_mapping.h:592
Definition opennurbs_uuid.h:31
Definition opennurbs_xform.h:28
#define ON_DECL
Definition opennurbs_defines.h:92
#define ON_CLASS
Definition opennurbs_defines.h:91
ON_DECL ON_Mesh * ON_ControlPolygonMesh(const ON_NurbsSurface &nurbs_surface, bool bCleanMesh, ON_Mesh *input_mesh=NULL)
Definition opennurbs_mesh_tools.cpp:693
ON_DECL ON_3dVector ON_TriangleNormal(const ON_3dPoint &A, const ON_3dPoint &B, const ON_3dPoint &C)
Definition opennurbs_mesh.cpp:8101
ON_DECL ON_Mesh * ON_MeshSurface(const ON_Surface &surface, int mesh_density=0, ON_Mesh *mesh=0)
Definition opennurbs_mesh.cpp:329
ON_DECL int ON_Mesh2dRegion(int point_count, int point_stride, const double *point, int edge_count, int edge_stride, const int *edge, const int *edge_side, ON_SimpleArray< ON_3dex > &triangles)
Definition opennurbs_mesh.cpp:8595
ON_DECL bool ON_ClosestPointToTriangleFast(const ON_3dPoint &A, const ON_3dPoint &B, const ON_3dPoint &C, ON_3dPoint P, double *a, double *b, double *c)
Definition opennurbs_mesh.cpp:8041
ON_DECL bool ON_Mesh2dPolygon(int point_count, int point_stride, const double *P, int tri_stride, int *triangle)
ON_DECL int ON_LineTriangleIntersect(const ON_3dPoint &A, const ON_3dPoint &B, const ON_3dPoint &C, const ON_3dPoint &P, const ON_3dPoint &Q, double abc[2][3], double t[2], double tol)
Definition opennurbs_mesh.cpp:8174
ON_DECL bool ON_ClosestPointToTriangle(ON_3dPoint A, ON_3dPoint B, ON_3dPoint C, ON_3dPoint P, double *a, double *b, double *c)
Definition opennurbs_mesh.cpp:7988
const ON_3dPoint ON_origin(0.0, 0.0, 0.0)
const ON_3dPoint ON_UNSET_POINT(ON_UNSET_VALUE, ON_UNSET_VALUE, ON_UNSET_VALUE)
#define N
Definition opennurbs_rand.cpp:70
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362
unsigned int ON__UINT32
Definition opennurbs_system.h:326
Definition opennurbs_mesh.h:610
int * vi
Definition opennurbs_mesh.h:619
int N
Definition opennurbs_mesh.h:612
int * fi
Definition opennurbs_mesh.h:627
Definition opennurbs_mesh.h:353
int vertex_count
Definition opennurbs_mesh.h:358
int vi[2]
Definition opennurbs_mesh.h:356
int triangle_count
Definition opennurbs_mesh.h:359
int fi[2]
Definition opennurbs_mesh.h:357
Definition opennurbs_mesh.h:598
struct memchunk * next
Definition opennurbs_mesh.h:599
Definition opennurbs_mesh.h:258
int m_topvi[2]
Definition opennurbs_mesh.h:261
const int * m_topfi
Definition opennurbs_mesh.h:268
int m_topf_count
Definition opennurbs_mesh.h:264
Definition opennurbs_mesh.h:272
Definition opennurbs_mesh.h:236
const int * m_vi
Definition opennurbs_mesh.h:254
const int * m_topei
Definition opennurbs_mesh.h:246
int m_tope_count
Definition opennurbs_mesh.h:239
int m_v_count
Definition opennurbs_mesh.h:250
Definition opennurbs_mesh_ngon.cpp:15