opennurbs_brep.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 ////////////////////////////////////////////////////////////////
18 //
19 // Definition of b-rep and its parts
20 //
21 ////////////////////////////////////////////////////////////////
22 
23 #if !defined(OPENNURBS_BREP_INC_)
24 #define OPENNURBS_BREP_INC_
25 
26 class ON_BrepTrim;
27 class ON_BrepEdge;
28 class ON_BrepLoop;
29 class ON_BrepFace;
30 
31 
32 // TEMPORARY DEFINES SO I DON'T BREAK THE BUILD
33 //#define m_vertex_user_i m_vertex_user.i
34 //#define m_trim_user_i m_trim_user.i
35 //#define m_edge_user_i m_edge_user.i
36 //#define m_loop_user_i m_loop_user.i
37 //#define m_face_user_i m_face_user.i
38 
39 // Description:
40 // Brep vertex information is stored in ON_BrepVertex classes.
41 // ON_Brep.m_V[] is an array of all the vertices in the brep.
42 //
43 // If a vertex is a point on a face, then brep.m_E[m_ei]
44 // will be an edge with no 3d curve. This edge will have
45 // a single trim with type ON_BrepTrim::ptonsrf. There
46 // will be a loop containing this single trim.
47 // Use ON_Brep::NewPointOnFace() to create vertices that are
48 // points on faces.
49 class ON_CLASS ON_BrepVertex : public ON_Point
50 {
51  ON_OBJECT_DECLARE(ON_BrepVertex);
52 
53 public:
54  // Union available for application use.
55  // The constructor zeros m_vertex_user.
56  // The value is of m_vertex_user is not saved in 3DM
57  // archives and may be changed by some computations.
58  mutable ON_U m_vertex_user;
59 
61 
62  // index of the vertex in the ON_Brep.m_V[] array
63  int m_vertex_index = -1;
64 
65  /////////////////////////////////////////////////////////////////
66  // Construction
67  //
68  // In general, you should not directly create ON_BrepVertex classes.
69  // Use ON_Brep::NewVertex instead.
70  ON_BrepVertex();
72  int // vertex index
73  );
75 
76  // virtual ON_Object::SizeOf override
77  unsigned int SizeOf() const override;
78 
79  // virtual ON_Object::DataCRC override
80  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
81 
82  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
83 
84  // virtual ON_Object::Dump() override
85  void Dump( ON_TextLog& ) const override; // for debugging
86 
87  // virtual ON_Object::Write() override
88  bool Write( ON_BinaryArchive& ) const override;
89 
90  // virtual ON_Object::Read() override
91  bool Read( ON_BinaryArchive& ) override;
92 
93  // virtual ON_Geometry::ComponentIndex() override
94  ON_COMPONENT_INDEX ComponentIndex() const override;
95 
96  /////////////////////////////////////////////////////////////////
97  // Interface
98 
99  // Description:
100  // Set vertex location.
101  // Parameters:
102  // point - [in] 3d vertex location
103  bool SetPoint(
104  const ON_3dPoint& // point
105  );
106 
107  // Returns:
108  // Vertex location.
109  ON_3dPoint Point() const;
110 
111  // Returns:
112  // value of ON_BrepVertex::m_tolerance
113  // Remarks:
114  // Use ON_Brep::SetVertexTolerance( ON_BrepVertex& ) to set tolerances.
115  double Tolerance() const;
116 
117  // Returns:
118  // number of edges that begin or end at this vertex.
119  int EdgeCount() const;
120 
121  /////////////////////////////////////////////////////////////////
122  // Implementation
123 
124  // indices of edges starting/ending at this vertex
125  //
126  // For closed edges, edge.m_vi[0] = edge.m_vi[1] and
127  // edge.m_edge_index appears twice in the m_ei[] array.
128  // The first occurance of edge.m_edge_index in m_ei[]
129  // is for the closed edge starting the vertex.
130  // The second occurance of edge,m_edge_index in m_ei[]
131  // is for the closed edge ending at the vertex.
132  // C.f. ON_Brep::Next/PrevEdge().
133  ON_SimpleArray<int> m_ei;
134 
135  // accuracy of vertex point (>=0.0 or ON_UNSET_VALUE)
136  //
137  // A value of ON_UNSET_VALUE indicates that the
138  // tolerance should be computed.
139  //
140  // A value of 0.0 indicates that the distance
141  // from the vertex to any applicable edge or trim
142  // end is <= ON_ZERO_TOLERANCE
143  //
144  // If an edge begins or ends at this vertex,
145  // then the distance from the vertex's
146  // 3d point to the appropriate end of the
147  // edge's 3d curve must be <= this tolerance.
148  //
149  // If a trim begins or ends at this vertex,
150  // then the distance from the vertex's 3d point
151  // to the 3d point on the surface obtained by
152  // evaluating the surface at the appropriate
153  // end of the trimming curve must be <= this
154  // tolerance.
155  double m_tolerance = ON_UNSET_VALUE;
156 
157 private:
158  ON_BrepVertex( const ON_BrepVertex& ) = delete;
159 };
161 /*
162 Description:
163  Brep edge information is stored in ON_BrepEdge classes.
164  ON_Brep.m_E[] is an array of all the edges in the brep.
165 
166  An ON_BrepEdge is derived from ON_CurveProxy so the the
167  edge can supply easy to use evaluation tools via
168  the ON_Curve virtual member functions.
169 
170  Note well that the domains and orientations of the curve
171  m_C3[edge.m_c3i] and the edge as a curve may not
172  agree.
173 */
174 
175 // April 24, 2017 Dale Lear
176 // ON_Curve::Trim(const ON_Interval&) is a virtual function and ON_BrepEdge derives
177 // from ON_CurveProxy which derives from ON_Curve. The ON_Brep::Trim(int) function was
178 // added and mistakenly named "Trim". This all happened about twenty years ago.
179 //
180 // Both the virtual ON_Curve::Trim(const ON_Interval&) and ON_BrepEdge::Trim(int) functions
181 // are widely used. At some point the functionON_Brep::Trim() will be deprecated and the 4263
182 // warning ON_Brep::Trim(int) generates will be disabled for the definition of class ON_BrepEdge.
183 // In version 7, ON_Brep::Trim(int) will be deleted and the warning will no longer be disabled.
184 #pragma ON_PRAGMA_WARNING_PUSH
185 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4263)
186 #pragma ON_PRAGMA_WARNING_DISABLE_MSC(4264)
187 
188 class ON_CLASS ON_BrepEdge : public ON_CurveProxy
189 {
190  ON_OBJECT_DECLARE(ON_BrepEdge);
191 
192 public:
193 
194  // Union available for application use.
195  // The constructor zeros m_edge_user.
196  // The value is of m_edge_user is not saved in 3DM
197  // archives and may be changed by some computations.
198  mutable ON_U m_edge_user;
199 
201 
202  // index of edge in ON_Brep.m_E[] array
203  int m_edge_index = -1;
205 
206  // virtual ON_Curve::IsClosed override
207  bool IsClosed() const override;
208 
209  /////////////////////////////////////////////////////////////////
210  // Construction
211  //
212  // In general, you should not directly create ON_BrepEdge classes.
213  // Use ON_Brep::NewVertex instead.
214  ON_BrepEdge();
215  ON_BrepEdge(int); // edge index
217 
218  // virtual ON_Object function
219  // The ON_BrepEdge override returns ON::curve_object.
220  ON::object_type ObjectType() const override;
221 
222  /*
223  Returns:
224  Brep this edge belongs to.
225  */
226  ON_Brep* Brep() const;
227 
228 
229  /*
230  Parameters:
231  eti - [in] index into the edge's m_ti[] array.
232  Returns:
233  The trim brep.m_T[edge.m_ti[eti]];
234  Remarks:
235  This version of "Trim" hides the virtual function ON_CurveProxy::Trim(const ON_Interval&),
236  which is a good thing. Special care must be takend when changing the geometry
237  of a brep edge to insure vertex, trim, and edge information remains valid.
238  */
239  ON_BrepTrim* Trim( int eti ) const;
240 
241  /*
242  Returns:
243  Number of trims attached to this edge.
244  */
245  int TrimCount() const;
246 
247  /*
248  Parameters:
249  evi - [in] 0 or 1
250  Returns:
251  Brep vertex at specified end of the edge.
252  */
253  ON_BrepVertex* Vertex(int evi) const;
254 
255  // virtual ON_Object::SizeOf override
256  unsigned int SizeOf() const override;
257 
258  // virtual ON_Object::DataCRC override
259  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
260 
261  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
262 
263  // virtual ON_Object::Dump() override
264  void Dump( ON_TextLog& ) const override; // for debugging
265 
266  // virtual ON_Object::Write() override
267  bool Write( ON_BinaryArchive& ) const override;
268 
269  // virtual ON_Object::Read() override
270  bool Read( ON_BinaryArchive& ) override;
271 
272  // virtual ON_Geometry::ComponentIndex() override
273  ON_COMPONENT_INDEX ComponentIndex() const override;
274 
275  // virtual ON_Curve::Reverse override
276  bool Reverse() override;
277 
278  /* Not necessary. Base class does the right thing. ON_CurveProxy does not have an override.
279  // virtual ON_Curve::SetStartPoint override
280  bool SetStartPoint(
281  ON_3dPoint start_point
282  );
283 
284  // virtual ON_Curve::SetEndPoint override
285  bool SetEndPoint(
286  ON_3dPoint end_point
287  );
288  */
289 
290 
291  /////////////////////////////////////////////////////////////////
292  // Implementation
293 
294  /*
295  Returns:
296  brep.m_C3[] index of the 3d curve geometry used by this edge
297  or -1.
298  */
299  int EdgeCurveIndexOf() const;
300 
301  /*
302  Returns:
303  3d curve geometry used by this edge or nullptr.
304  */
305  const ON_Curve* EdgeCurveOf() const;
306 
307  /*
308  Description:
309  Expert user tool that replaces the 3d curve geometry
310  of an edge
311  Parameters;
312  c3i - [in] brep 3d curve index of new curve
313  Returns:
314  True if successful.
315  Example:
316 
317  ON_Curve* pCurve = ...;
318  int c3i = brep.AddEdgeCurve(pCurve);
319  edge.ChangeEdgeCurve(c3i);
320 
321  Remarks:
322  Sets m_c3i, calls SetProxyCurve, cleans runtime caches.
323  */
324  bool ChangeEdgeCurve(
325  int c3i
326  );
327 
328  /*
329  Description:
330  When an edge is modified, the m_pline[].e values need
331  to be set to ON_UNSET_VALUE by calling UnsetPlineEdgeParameters().
332  */
333  void UnsetPlineEdgeParameters();
334 
335  // index of 3d curve in m_C3[] array
336  // (edge.m_curve also points to m_C3[m_c3i])
337  int m_c3i = -1;
339  // indices of starting/ending vertex
340  //
341  // For closed edges, m_vi[0] = m_vi[1] and m_edge_index
342  // appears twice in the m_V[m_vi[0]].m_ei[] array.
343  // The first occurance of m_edge_index in m_V[m_vi[0]].m_ei[]
344  // is for the closed edge starting the vertex. The second
345  // occurance of m_edge_index in m_V[m_vi[0]].m_ei[]
346  // is for the closed edge edge ending at the vertex.
347  // C.f. ON_Brep::Next/PrevEdge().
348  int m_vi[2];
350  // indices of Trims that use this edge
351  ON_SimpleArray<int> m_ti;
353  // accuracy of edge curve (>=0.0 or ON_UNSET_VALUE)
354  //
355  // A value of ON_UNSET_VALUE indicates that the
356  // tolerance should be computed.
357  //
358  // The maximum distance from the edge's 3d curve
359  // to any surface of a face that has this edge as
360  // a portion of its boundary must be <= this
361  // tolerance.
362  double m_tolerance = ON_UNSET_VALUE;
364 private:
365  friend class ON_Brep;
366  ON_Brep* m_brep = nullptr; // so isolated edge class edge can get at it's 3d curve
367  ON_BrepEdge( const ON_BrepEdge& ) = delete;
368 };
369 
370 #pragma ON_PRAGMA_WARNING_POP
371 
372 struct ON_BrepTrimPoint
373 {
374  ON_2dPoint p; // 2d surface parameter space point
375  double t; // corresponding trim curve parameter
376  double e; // corresponding edge curve parameter (ON_UNSET_VALUE if unknown)
377 };
378 
379 #if defined(ON_DLL_TEMPLATE)
380 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BrepTrimPoint>;
381 #endif
382 
383 
384 /*
385 Description:
386  Brep trim information is stored in ON_BrepTrim classes.
387  ON_Brep.m_T[] is an array of all the trim in the brep.
388 
389  An ON_BrepTrim is derived from ON_CurveProxy so the the
390  trim can supply easy to use evaluation tools via
391  the ON_Curve virtual member functions.
392 
393  Note well that the domains and orientations of the curve
394  m_C2[trim.m_c2i] and the trin as a curve may not
395  agree.
396 */
397 class ON_CLASS ON_BrepTrim : public ON_CurveProxy
398 {
399  ON_OBJECT_DECLARE(ON_BrepTrim);
400 
401 public:
402  void DestroyRuntimeCache( bool bDelete = true ) override;
403 
404  // virtual ON_Object::SizeOf override
405  unsigned int SizeOf() const override;
406 
407  // Union available for application use.
408  // The constructor zeros m_trim_user.
409  // The value is of m_trim_user is not saved in 3DM
410  // archives and may be changed by some computations.
411  mutable ON_U m_trim_user;
412 
414 
415  int m_trim_index = -1; // index of trim in ON_Brep.m_T[] array
416 
417  // types of trim - access through m_type member. Also see m_iso and ON_Surface::ISO
418  enum TYPE
419  {
420  unknown = 0,
421  boundary = 1, // trim is connected to an edge, is part of an outer,
422  // inner or slit loop, and is the only trim connected
423  // to the edge.
424  mated = 2, // trim is connected to an edge, is part of an outer,
425  // inner or slit loop, no other trim from the same
426  // loop is connected to the edge, and at least one
427  // trim from a different loop is connected to the edge.
428  seam = 3, // trim is connected to an edge, is part of an outer,
429  // inner or slit loop, and one other trim from the
430  // same loop is connected to the edge.
431  // (There can be other mated trims that are also
432  // connected to the edge. For example, the non-mainfold
433  // edge that results when a surface edge lies in the
434  // middle of another surface.) Non-mainfold "cuts"
435  // have seam trims too.
436  singular = 4, // trim is part of an outer loop, the trim's 2d curve
437  // runs along the singular side of a surface, and the
438  // trim is NOT connected to an edge. (There is no 3d
439  // edge because the surface side is singular.)
440  crvonsrf = 5, // trim is connected to an edge, is the only trim in
441  // a crfonsrf loop, and is the only trim connected to
442  // the edge.
443  ptonsrf = 6, // trim is a point on a surface, trim.m_pbox is records
444  // surface parameters, and is the only trim
445  // in a ptonsrf loop. This trim is not connected
446  // to an edge and has no 2d curve.
447  slit = 7, // 17 Nov 2006 - reserved for future use
448  // currently an invalid value
449  trim_type_count = 8,
450  force_32_bit_trim_type = 0xFFFFFFFF
451  };
452 
453  /////////////////////////////////////////////////////////////////
454  // Construction
455  //
456  // In general, you should not directly create ON_BrepTrim classes.
457  // Use ON_Brep::NewTrim instead.
458  ON_BrepTrim();
459  ON_BrepTrim(int); // trim index
460  ON_BrepTrim& operator=(const ON_BrepTrim&);
461 
462  /*
463  Returns:
464  Brep that this trim belongs to.
465  */
466  ON_Brep* Brep() const;
467 
468  /*
469  Returns:
470  Brep loop that this trim belongs to.
471  */
472  ON_BrepLoop* Loop() const;
473 
474  /*
475  Returns:
476  Brep face this trim belongs to.
477  */
478  ON_BrepFace* Face() const;
479 
480  /*
481  Returns:
482  Brep edge this trim uses or belongs to. This will
483  be nullptr for singular trims.
484  */
485  ON_BrepEdge* Edge() const;
486 
487  /*
488  Parameters:
489  tvi - [in] 0 or 1
490  Returns:
491  Brep vertex at specified end of the trim.
492  */
493  ON_BrepVertex* Vertex(int tvi) const;
494 
495  /////////////////////////////////////////////////////////////////
496  // ON_Object overrides
497  //
498  // (Trims are purely topologicial - geometry queries should be
499  // directed at the trim's 2d curve or the trim's edge's 3d curve.)
500 
501  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
502 
503  void Dump( ON_TextLog& ) const override; // for debugging
504 
505  bool Write( ON_BinaryArchive& ) const override;
506 
507  bool Read( ON_BinaryArchive& ) override;
508 
509  // virtual ON_Geometry::ComponentIndex() override
510  ON_COMPONENT_INDEX ComponentIndex() const override;
511 
512  // virtual ON_Curve::Reverse override
513  // Reverses curve - caller must make sure trim's m_bRev3d
514  // flags are properly updated. Use
515  // ON_Brep::FlipTrim to reverse and trim and update all
516  // m_bRev3d informtion.
517  bool Reverse() override;
518 
519  /* Not necessary Base clasee does the same.
520  // virtual ON_Curve::SetStartPoint override
521  bool SetStartPoint(
522  ON_3dPoint start_point
523  ) override;
524 
525  // virtual ON_Curve::SetEndPoint override
526  bool SetEndPoint(
527  ON_3dPoint end_point
528  ) override;
529 */
530  /////////////////////////////////////////////////////////////////
531  // Interface
532 
533  /*
534  Description:
535  Expert user tool that replaces the 2d curve geometry
536  of a trim
537  Parameters;
538  c2i - [in] brep 2d curve index of new curve
539  Returns:
540  True if successful.
541  Example:
542 
543  ON_Curve* pCurve = ...;
544  int c2i = brep.AddTrimCurve(pCurve);
545  trim.ChangeTrimCurve(c2i);
546 
547  Remarks:
548  Sets m_c2i, calls SetProxyCurve, cleans runtime caches,
549  and updates m_pbox.
550  */
551  bool ChangeTrimCurve( int c2i );
552 
553  /*
554  Description:
555  Destroy parameter space information.
556  Currently, this involves destroying m_pline
557  and m_pbox. Parameter space information should
558  be destroyed when the location of a trim
559  curve is changed.
560  */
561  void DestroyPspaceInformation();
562 
563  /*
564  Description:
565  Expert user function.
566  Removes a trim from an edge.
567  Parameters:
568  bRemoveFromStartVertex - [in] if true, the trim
569  is removed from its start vertex by setting
570  m_vi[0] to -1.
571  bRemoveFromEndVertex - [in] if true, the trim
572  is removed from its start vertex by setting
573  m_vi[1] to -1.
574  Remarks:
575  If the trim is attached to an edge (m_ei>=0), then
576  the trim is removed from the edge and the edge's
577  m_ti[] list. The trim's m_bRev3d and tolerance values
578  are not changed.
579  */
580  bool RemoveFromEdge(
581  bool bRemoveFromStartVertex,
582  bool bRemoveFromEndVertex
583  );
584 
585  /*
586  Description:
587  Expert user function.
588  Attaches a trim to an edge.
589  Parameters:
590  edge_index - [in] index of an edge.
591  bRev3d - [in] value for trim's m_bRev3d field.
592  Remarks:
593  If the trim is attached to an edge (m_ei>=0), then
594  the trim is removed from the edge and the edge's
595  m_ti[] list. The trim's tolerance values are not
596  changed.
597  */
598  bool AttachToEdge(
599  int edge_index,
600  bool bRev3d
601  );
602 
603  /*
604  Returns:
605  2d curve geometry used by this trim or nullptr
606  */
607  const ON_Curve* TrimCurveOf() const;
608 
609  /*
610  Returns:
611  3d curve geometry used by this trim or nullptr.
612  */
613  const ON_Curve* EdgeCurveOf() const;
614 
615  /*
616  Returns:
617  3d surface geometry used by this trim or nullptr
618  */
619  const ON_Surface* SurfaceOf() const;
620 
621  /*
622  Returns:
623  brep.m_C2[] 2d curve index of the 2d curve geometry used by
624  this trim or -1.
625  */
626  int TrimCurveIndexOf() const;
627 
628  /*
629  Returns:
630  brep.m_C3[] 3d curve index of the 3d curve geometry used by
631  this trim or -1.
632  */
633  int EdgeCurveIndexOf() const;
634 
635  /*
636  Returns:
637  brep.m_S[] surface index of the 3d surface geometry used by
638  this trim or -1.
639  */
640  int SurfaceIndexOf() const;
641 
642  /*
643  Returns:
644  brep.m_F[] face index of the face used by this trim or -1.
645  */
646  int FaceIndexOf() const;
647 
648  /*
649  Returns:
650  True if the trim satisfies these four criteria.
651  1) is part of a loop
652  2) is connected to a 3d edge
653  3) one other trim from the same loop is connected to the edge
654  4) The 2d trim curve for the other trim is the reverse
655  of the 2d trim curve for this trim.
656  Remarks:
657  In order for IsSlit() to work correctly, the m_type and m_iso
658  fields must be set correctly. In V4 SR1, this function will
659  be removed and ON_BrepTrim::slit will be added as a type.
660  */
661  bool IsSlit() const;
662 
663  /*
664  Returns:
665  True if the trim satisfies these four criteria.
666  1) is part of a loop
667  2) is connected to a 3d edge
668  3) one other trim from the same loop is connected to the edge
669  4) the 2d trim curve for this trim lies along the side of
670  the face's parameter space and the 2d curve for the other
671  trim lies on the opposite side of the face's parameter
672  space.
673  Remarks:
674  In order for IsSeam() to work correctly, the m_type and m_iso
675  fields must be set correctly. In V4 SR1, this function will
676  be removed and ON_BrepTrim::slit will be added as a type.
677  */
678  bool IsSeam() const;
679 
680  /*
681  Description:
682  Expert user tool that tranforms all the parameter space (2d)
683  trimming curves in this loop. Only 2d curve geometry is
684  changed. The caller is responsible for reversing loops,
685  toggle m_bRev, flags, etc.
686  Parameters:
687  xform - [in] Transformation applied to 2d curve geometry.
688  Returns
689  True if successful. If false is returned, the brep
690  may be invalid.
691  */
692  bool TransformTrim( const ON_Xform& xform );
694  // index of the 2d parameter space trimming curve
695  int m_c2i = -1;
697  // index of 3d edge (-1 if ON_BrepTrim is singular)
698  int m_ei = -1;
700  // Indices of start/end vertices. Trims along singular
701  // sides and trims that correspond to closed 3d edges
702  // have m_vi[0] = m_vi[1]. Note that singular trims
703  // and trims on the closed edge of a closed surface can
704  // have an open 2d trimming curve and still have
705  // m_vi[0] = m_vi[1].
706  int m_vi[2];
707 
708  // true if the 2d trim and 3d edge have opposite orientations.
709  bool m_bRev3d = false;
710 
711  TYPE m_type = ON_BrepTrim::unknown;
713 
714  // index of loop that uses this trim
715  int m_li = -1;
716 
717  // The values in m_tolerance[] record the accuracy of
718  // the parameter space trimming curves.
719  //
720  // Remarks:
721  // m_tolerance[0] = accuracy of parameter space curve
722  // in first ( "u" ) parameter
723  //
724  // m_tolerance[1] = accuracy of parameter space curve
725  // in second ( "v" ) parameter
726  //
727  // A value of ON_UNSET_VALUE indicates that the
728  // tolerance should be computed. If the value >= 0.0,
729  // then the tolerance is set. If the value is
730  // ON_UNSET_VALUE, then the tolrance needs to be
731  // computed.
732  //
733  // If the trim is not singular, then the trim must
734  // have an edge. If P is a 3d point on the edge's
735  // curve and surface(u,v) = Q is the point on the
736  // surface that is closest to P, then there must
737  // be a parameter t in the interval [m_t[0], m_t[1]]
738  // such that
739  //
740  // |u - curve2d(t)[0]| <= m_tolerance[0]
741  //
742  // and
743  //
744  // |v - curve2d(t)[1]| <= m_tolerance[1]
745  //
746  // If P is the 3d point for the vertex brep.m_V[m_vi[k]]
747  // and (uk,vk) is the corresponding end of the trim's
748  // parameter space curve, then there must be a surface
749  // parameter (u,v) such that:
750  //
751  // * the distance from the 3d point surface(u,v) to P
752  // is <= brep.m_V[m_vi[k]].m_tolerance,
753  // * |u-uk| <= m_tolerance[0].
754  // * |v-vk| <= m_tolerance[1].
755  double m_tolerance[2];
756 
757  // Runtime polyline approximation of trimming curve.
758  // This information is not saved in 3DM archives.
760 
761  /*
762  Description:
763  When an edge is modified, the m_pline[].e values need
764  to be set to ON_UNSET_VALUE by calling UnsetPlineEdgeParameters().
765  */
766  void UnsetPlineEdgeParameters();
768  // Runtime parameter space trimming curve bounding box.
769  // This information is not saved in 3DM archives.
770  ON_BoundingBox m_pbox;
772 public:
773  // values stored in legacy file formats - ignore
774 
775  void m__legacy_flags_Set(int,int); // used internally - ignore
776  bool m__legacy_flags_Get(int*,int*) const; // used internally - ignore
777  double m__legacy_2d_tol = ON_UNSET_VALUE; // used internally - ignore
778  double m__legacy_3d_tol = ON_UNSET_VALUE; // used internally - ignore
779  int m__legacy_flags = 0; // used internally - ignore
780 
781 private:
782  friend class ON_Brep;
783  ON_Brep* m_brep = nullptr; // so isolated edge class edge can get at it's 3d curve
784  ON_BrepTrim( const ON_BrepTrim& ) = delete;
785 };
786 
787 class ON_CLASS ON_BrepLoop : public ON_Geometry
788 {
789  ON_OBJECT_DECLARE(ON_BrepLoop);
790 
791 public:
792  void DestroyRuntimeCache( bool bDelete = true ) override;
793 
794  // virtual ON_Geometry overrides
795  // A loop is derived from ON_Geometry so that is can
796  // be passed around to things that expect ON_Geometry
797  // pointers. It is not a very useful stand-alone object.
798 
799  /*
800  Description:
801  virtual ON_Geometry::Dimension() override.
802  Returns:
803  2
804  */
805  int Dimension() const override;
806 
807  // virtual ON_Geometry GetBBox override
808  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
809 
810  // virtual ON_Geometry::Transform() override.
811  bool Transform(
812  const ON_Xform& xform
813  ) override;
814 public:
815  /*
816  Returns:
817  Brep that the loop belongs to.
818  */
819  ON_Brep* Brep() const;
820 
821  /*
822  Returns:
823  Brep face this loop belongs to.
824  */
825  ON_BrepFace* Face() const;
826 
827  /*
828  Parameters:
829  lti - [in] index into the loop's m_ti[] array.
830  Returns:
831  The trim brep.m_T[loop.m_ti[lti]];
832  */
833  ON_BrepTrim* Trim( int lti ) const;
834 
835  /*
836  Returns:
837  Number of trims in this loop.
838  */
839  int TrimCount() const;
841  // Union available for application use.
842  // The constructor zeros m_loop_user.
843  // The value is of m_loop_user is not saved in 3DM
844  // archives and may be changed by some computations.
845  mutable ON_U m_loop_user;
846 
848 
849  int m_loop_index = -1; // index of loop in ON_Brep.m_L[] array
850 
851  enum TYPE {
852  unknown = 0,
853  outer = 1, // 2d loop curves form a simple closed curve with a counterclockwise orientation
854  inner = 2, // 2d loop curves form a simple closed curve with a clockwise orientation
855  slit = 3, // always closed - used internally during splitting operations
856  crvonsrf = 4, // "loop" is a curveonsrf made from a single
857  // (open or closed) trim that is has type ON_BrepTrim::crvonsrf.
858  ptonsrf = 5, // "loop" is a ptonsrf made from a single
859  // trim that is has type ON_BrepTrim::ptonsrf.
860  type_count = 6
861  };
862 
863  ON_BrepLoop();
864  ON_BrepLoop(int); // loop index
865  ON_BrepLoop& operator=(const ON_BrepLoop&);
866 
867  /////////////////////////////////////////////////////////////////
868  // ON_Object overrides
869  //
870  // (Loops and trims are purely topologicial - geometry queries should be
871  // directed at the trim's 2d curve or the trim's edge's 3d curve.)
872 
873  // virtual ON_Object::SizeOf override
874  unsigned int SizeOf() const override;
875 
876  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
877 
878  void Dump( ON_TextLog& ) const override; // for debugging
879 
880  bool Write( ON_BinaryArchive& ) const override;
881 
882  bool Read( ON_BinaryArchive& ) override;
883 
884  // virtual ON_Geometry::ComponentIndex() override
885  ON_COMPONENT_INDEX ComponentIndex() const override;
886 
887  /////////////////////////////////////////////////////////////////
888  // Interface
889 
890  //////////
891  // Returns the index i such that loop.m_ti[i] = trim.m_trim_index.
892  // Returns -1 if the trim is not in this loop
893  int IndexOfTrim( const ON_BrepTrim& ) const;
894 
895  /*
896  Returns:
897  brep.m_S[] surface index of the 3d surface geometry used by
898  this loop or -1.
899  */
900  int SurfaceIndexOf() const;
901 
902  /*
903  Returns:
904  Pointer to the surface geometry used by the loop.
905  */
906  const ON_Surface* SurfaceOf() const;
907 
908  /*
909  Description:
910  Expert user tool that tranforms all the parameter space (2d)
911  trimming curves in this loop. Only 2d curve geometry is
912  changed. The caller is responsible for reversing loops,
913  toggle m_bRev, flags, etc.
914  Parameters:
915  xform - [in] Transformation applied to 2d curve geometry.
916  Returns
917  True if successful. If false is returned, the brep
918  may be invalid.
919  */
920  bool TransformTrim( const ON_Xform& xform );
921 
922  ON_SimpleArray<int> m_ti; // trim indices
923  TYPE m_type = ON_BrepLoop::unknown;
924  int m_fi = -1; // index of face that uses this loop
925 
926  //////////
927  // parameter space trimming loop bounding box
928  // runtime information - not saved
929  ON_BoundingBox m_pbox;
930 private:
931  friend class ON_Brep;
932  ON_Brep* m_brep = nullptr;
933  ON_BrepLoop(const ON_BrepLoop&) = delete;
934 };
935 
936 
937 class ON_CLASS ON_BrepFace : public ON_SurfaceProxy
938 {
939  ON_OBJECT_DECLARE(ON_BrepFace);
940 
941 public:
942  void DestroyRuntimeCache( bool bDelete = true ) override;
943 
944  // Union available for application use.
945  // The constructor zeros m_face_user.
946  // The value is of m_face_user is not saved in 3DM
947  // archives and may be changed by some computations.
948  mutable ON_U m_face_user;
949 
951 
952  int m_face_index = -1; // index of face in ON_Brep.m_F[] array
953 
954  ON_BrepFace();
955  ~ON_BrepFace();
956  ON_BrepFace(int);
957  ON_BrepFace& operator=(const ON_BrepFace&);
958 
959  /*
960  Returns:
961  Brep that the face belongs to.
962  */
963  ON_Brep* Brep() const;
964 
965  /*
966  Parameters:
967  fli - [in] index into the face's m_li[] array.
968  Returns:
969  The loop brep.m_L[face.m_li[fli]];
970  */
971  ON_BrepLoop* Loop( int fli ) const;
972 
973  /*
974  Returns:
975  Number of loops in this face.
976  */
977  int LoopCount() const;
978 
979  /*
980  Returns:
981  Outer boundary loop for this face.
982  */
983  ON_BrepLoop* OuterLoop() const;
984 
985  /*
986  Parameters:
987  dir
988  1: side with underlying surface normal
989  pointing into the topology region
990  -1: side with underlying surface normal
991  pointing out of the topology region
992  Returns:
993  Brep region topology face side. If the region
994  topology has not be created by calling
995  ON_Brep::RegionToplogy(), then nullptr is returned.
996  */
997  class ON_BrepFaceSide* FaceSide(int dir) const;
998 
999 
1000  /////////////////////////////////////////////////////////////////
1001  // ON_Object overrides
1002  //
1003  // (Faces are purely topologicial - geometry queries should be
1004  // directed at the face's 3d surface.)
1005 
1006  // virtual ON_Object::SizeOf override
1007  unsigned int SizeOf() const override;
1008 
1009  // virtual ON_Object::DataCRC override
1010  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
1011 
1012  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
1013 
1014  void Dump( ON_TextLog& ) const override; // for debugging
1015 
1016  bool Write( ON_BinaryArchive& ) const override;
1017 
1018  bool Read( ON_BinaryArchive& ) override;
1019 
1020  // virtual ON_Geometry::ComponentIndex() override
1021  ON_COMPONENT_INDEX ComponentIndex() const override;
1022 
1023  // virtual ON_Geometry::ClearBoundingBox() override
1024  void ClearBoundingBox() override;
1025 
1026  // virtual ON_Geometry GetBBox override
1027  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
1028 
1029 
1030  /*
1031  Description:
1032  This is an override of the virtual ON_Surface::Reverse
1033  function. It toggles the face's m_bRev flag so the abstract
1034  orientation of the face does not change.
1035  Parameters:
1036  dir - [in] 0 = reverse "s" parameter, 1 = reverse "t" parameter
1037  The domain changes from [a,b] to [-a,-b]
1038  Returns:
1039  True if successful.
1040  Remarks:
1041  The range of the face's trimming curves and the orientation direction
1042  of then loops are changed so that the resulting face is still valid.
1043  */
1044  bool Reverse(
1045  int dir
1046  ) override;
1047 
1048  /*
1049  Description:
1050  This is an override of the virtual ON_Surface::Transpose
1051  function. It toggles the face's m_bRev flag so the abstract
1052  orientation of the face does not change.
1053  Returns:
1054  True if successful.
1055  Remarks:
1056  The range of the face's trimming curves and the orientation direction
1057  of then loops are changed so that the resulting face is still valid.
1058  */
1059  bool Transpose() override;
1060 
1061  /*
1062  Description:
1063  This is an override of the virtual ON_Surface::SetDomain
1064  function.
1065  Parameters:
1066  dir - [in] 0 = set "u" domain, 1 = set "v" domain.
1067  t0 - [in]
1068  t1 - [in] t0 < t1 The new domain is the interval (t0,t1)
1069  Returns:
1070  True if successful.
1071  */
1072  bool SetDomain(
1073  int dir,
1074  double t0,
1075  double t1
1076  ) override;
1077 
1078  /*
1079  //////////
1080  // Change the domain of a face
1081  // This changes the parameterization of the face's surface and transforms
1082  // the "u" and "v" coordinates of all the face's parameter space trimming
1083  // curves. The locus of the face is not changed.
1084  */
1085  bool SetDomain(
1086  ON_Interval udom,
1087  ON_Interval vdom
1088  );
1089 
1090  /////////////////////////////////////////////////////////////////
1091  // Rendering Interface
1092  //int MaterialIndex() const; // if -1, use parent's material definition
1093  //void SetMaterialIndex(int);
1094 
1095  // If true is returne, then ~ON_BrepFace will delete mesh.
1096  bool SetMesh( ON::mesh_type, ON_Mesh* mesh );
1097 
1098  const ON_Mesh* Mesh( ON::mesh_type mesh_type ) const;
1099 
1100  /*
1101  Description:
1102  Destroy meshes used to render and analyze surface and polysrf
1103  objects.
1104  Parameters:
1105  mesh_type - [in] type of mesh to destroy
1106  bDeleteMesh - [in] if true, cached mesh is deleted.
1107  If false, pointer to cached mesh is just set to nullptr.
1108  See Also:
1109  CRhinoObject::GetMeshes
1110  CRhinoObject::MeshCount
1111  CRhinoObject::IsMeshable
1112  */
1113  void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh = true );
1114 
1115  /////////////////////////////////////////////////////////////////
1116  // "Expert" Interface
1117 
1118  /*
1119  Description:
1120  Expert user tool that tranforms all the parameter space (2d)
1121  trimming curves on this face. Only 2d curve geometry is
1122  changed. The caller is responsible for reversing loops,
1123  toggle m_bRev, flags, etc.
1124  Parameters:
1125  xform - [in] Transformation applied to 2d curve geometry.
1126  Returns
1127  True if successful. If false is returned, the brep
1128  may be invalid.
1129  */
1130  bool TransformTrim( const ON_Xform& xform );
1131 
1132  /*
1133  Description:
1134  Expert user tool that replaces the 3d surface geometry
1135  use by the face.
1136  Parameters;
1137  si - [in] brep surface index of new surface
1138  bTransformTrimCurves - [in]
1139  If unsure, then pass true.
1140  If the surface's domain has changed and you are certain
1141  its parameterization still jibes with the trim curve
1142  locations, then pass false.
1143  Returns:
1144  True if successful.
1145  Example:
1146 
1147  ON_Surface* pSurface = ...;
1148  int si = brep.AddSurface(pSurface);
1149  face.ChangeSurface(si);
1150 
1151  Remarks:
1152  If the face had a surface and new surface has a different
1153  shape, then you probably want to call something like
1154  ON_Brep::RebuildEdges() to move the 3d edge curves so they
1155  will lie on the new surface. This doesn't delete the old
1156  surface; call ON_Brep::CullUnusedSurfaces() or ON_Brep::Compact
1157  to remove unused surfaces.
1158  See Also:
1159  ON_Brep::RebuildEdges
1160  ON_Brep::CullUnusedSurfaces
1161  */
1162  bool ChangeSurface(
1163  int si
1164  );
1165  bool ChangeSurface(
1166  int si,
1167  bool bTransformTrimCurves
1168  );
1169 
1170  /*
1171  Returns:
1172  brep.m_S[] surface index of the 3d surface geometry used by
1173  this face or -1.
1174  */
1175  int SurfaceIndexOf() const;
1176 
1177  /*
1178  Returns:
1179  Pointer to the surface geometry used by the face.
1180  */
1181  const ON_Surface* SurfaceOf() const;
1182 
1183 
1184  ON_SimpleArray<int> m_li; // loop indices (outer loop is m_li[0])
1185  int m_si = -1; // index of surface in b-rep m_S[] array
1186  bool m_bRev = false; // true if face orientation is opposite
1187  // of natural surface orientation
1188 
1189  // m_face_material_channel provides a way to have individual
1190  // brep faces use a rendering material that is different
1191  // from the rendering material used by the parent brep.
1192  // If m_face_material_channel is zero
1193  // channel and m_face_material_channel.m_j is the back face
1194  // materal. The default is (0,0) which indicates the face
1195  // should use the parent brep's material.
1196  // If "mat" is the brep's rendering material and
1197  // 0 < m_material_channel.m_i < mat.m_material_channel.Count(),
1198  // then this face should use the material with id
1199  // mat.m_material_channel[face.m_material_channel.m_i-1].m_id.
1200  // If m_material_channel.m_i or the id is invalid in any way,
1201  // then the default should be used.
1202  int m_face_material_channel = 0;
1203 
1204  // Persistent id for this face. Default is ON_nil_uuid.
1205  ON_UUID m_face_uuid = ON_nil_uuid;
1206 private:
1207  ON_BoundingBox m_bbox; // 3d bounding box
1208  ON_Interval m_domain[2]; // rectangular bounds of 2d curves
1209  ON_Mesh* m_render_mesh = nullptr;
1210  ON_Mesh* m_analysis_mesh = nullptr;
1211  ON_Mesh* m_preview_mesh = nullptr;
1212  //int m_material_index; // if 0 (default), ON_Brep's object attributes
1213  // // determine material.
1214 private:
1215  friend class ON_Brep;
1216  ON_Brep* m_brep = nullptr;
1217  ON_BrepFace( const ON_BrepFace& ) = delete;
1218 };
1219 
1220 class ON_CLASS ON_BrepFaceSide : public ON_Object
1221 {
1222  ON_OBJECT_DECLARE(ON_BrepFaceSide);
1223 public:
1224  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
1225 
1226  // Union available for application use.
1227  // The constructor zeros m_faceside_user.
1228  // The value is of m_faceside_user is not saved in 3DM
1229  // archives and may be changed by some computations.
1230  mutable ON_U m_faceside_user;
1231 
1232  // index of face side in ON_BrepRegionTopology.m_FS[] array
1233  int m_faceside_index;
1234 
1235  ON_BrepFaceSide();
1236  ~ON_BrepFaceSide();
1237  ON_BrepFaceSide& operator=(const ON_BrepFaceSide&);
1238 
1239  bool Write(ON_BinaryArchive& binary_archive) const override;
1240  bool Read(ON_BinaryArchive& binary_archive) override;
1242 
1243  /*
1244  Returns:
1245  Brep this face side belongs to.
1246  */
1247  const class ON_Brep* Brep() const;
1248 
1249  /*
1250  Returns:
1251  Region topology this face side belongs to.
1252  */
1253  const class ON_BrepRegionTopology* RegionTopology() const;
1254 
1255  /*
1256  Returns:
1257  Region the face side belongs to.
1258  */
1259  const class ON_BrepRegion* Region() const;
1260 
1261  /*
1262  Returns:
1263  Face this side belongs to.
1264  */
1265  const class ON_BrepFace* Face() const;
1267  /*
1268  Returns:
1269  +1: underlying geometric surface normal points
1270  into region.
1271  -1: underlying geometric surface normal points
1272  out of region.
1273  */
1274  int SurfaceNormalDirection() const;
1275 
1276 public:
1277  int m_ri; // region index
1278  // m_ri = -1 indicates this faceside overlaps
1279  // another faceside. Generally this is a flaw
1280  // in an ON_Brep.
1281  int m_fi; // face index
1282  int m_srf_dir; // 1 ON_BrepFace's surface normal points into region
1283  // -1 ON_BrepFace's surface normal points out of region
1284 
1285 private:
1286  friend class ON_Brep;
1287  friend class ON_BrepRegionTopology;
1288  ON_BrepRegionTopology* m_rtop;
1289  ON_BrepFaceSide( const ON_BrepFaceSide& );
1290 };
1291 
1292 class ON_CLASS ON_BrepRegion : public ON_Object
1293 {
1294  ON_OBJECT_DECLARE(ON_BrepRegion);
1295 public:
1296  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
1297 
1298  // Union available for application use.
1299  // The constructor zeros m_region_user.
1300  // The value is of m_region_user is not saved in 3DM
1301  // archives and may be changed by some computations.
1302  mutable ON_U m_region_user;
1303 
1304  // index of region in ON_BrepRegionTopology.m_R[] array
1305  int m_region_index;
1306 
1307  ON_BrepRegion();
1308  ~ON_BrepRegion();
1309  ON_BrepRegion& operator=(const ON_BrepRegion&);
1311  bool Write(ON_BinaryArchive& binary_archive) const override;
1312  bool Read(ON_BinaryArchive& binary_archive) override;
1313 
1314  /*
1315  Returns:
1316  Brep this region belongs to.
1317  */
1318  const ON_Brep* Brep() const;
1319 
1320  /*
1321  Returns:
1322  Region topology this region belongs to.
1323  */
1324  class ON_BrepRegionTopology* RegionTopology() const;
1325 
1326  /*
1327  Parameter:
1328  rfsi - [in] index into the region's m_fsi[] array.
1329  Returns:
1330  The face side in rtop.m_FS[m_fsi[rsi]], where
1331  rtop is the ON_BrepRegionTopology class this
1332  region belongs to.
1333  */
1334  ON_BrepFaceSide* FaceSide(int rfsi) const;
1335 
1336  /*
1337  Returns:
1338  True if the region is finite.
1339  */
1340  bool IsFinite() const;
1341 
1342  /*
1343  Returns:
1344  Region bounding box.
1345  */
1346  const ON_BoundingBox& BoundingBox() const;
1347 
1348  ON_SimpleArray<int> m_fsi; // indices of face sides
1349  int m_type; // 0 = infinte, 1 = bounded
1350  ON_BoundingBox m_bbox;
1351 
1352  /*
1353  Description:
1354  Get the boundary of a region as a brep object.
1355  If the region is finite, the boundary will be a closed
1356  manifold brep. The boundary may have more than one
1357  connected component.
1358  Parameters:
1359  brep - [in] if not nullptr, the brep form is put into
1360  this brep.
1361  Returns: the region boundary as a brep or nullptr if the
1362  calculation fails.
1363  */
1364  ON_Brep* RegionBoundaryBrep( ON_Brep* brep = nullptr ) const;
1365 
1366 
1367 private:
1368  friend class ON_Brep;
1369  friend class ON_BrepRegionTopology;
1370  ON_BrepRegionTopology* m_rtop;
1372 };
1373 
1374 #if defined(ON_DLL_TEMPLATE)
1375 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BrepVertex>;
1376 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepVertex>;
1377 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BrepEdge>;
1378 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepEdge>;
1379 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BrepTrim>;
1380 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepTrim>;
1381 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BrepLoop>;
1382 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepLoop>;
1383 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_BrepFace>;
1384 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepFace>;
1385 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepFaceSide>;
1386 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_BrepRegion>;
1387 #endif
1388 
1389 class ON_CLASS ON_BrepVertexArray : public ON_ObjectArray<ON_BrepVertex>
1390 {
1391 public:
1394 
1395  bool Read( ON_BinaryArchive& );
1396  bool Write( ON_BinaryArchive& ) const;
1397 
1398  unsigned int SizeOf() const;
1399 };
1400 
1401 class ON_CLASS ON_BrepEdgeArray : public ON_ObjectArray<ON_BrepEdge>
1402 {
1403 public:
1405  ~ON_BrepEdgeArray();
1406  bool Read( ON_BinaryArchive& );
1407  bool Write( ON_BinaryArchive& ) const;
1408 
1409  unsigned int SizeOf() const;
1410 };
1411 
1412 class ON_CLASS ON_BrepTrimArray : public ON_ObjectArray<ON_BrepTrim>
1413 {
1414 public:
1415  ON_BrepTrimArray();
1416  ~ON_BrepTrimArray();
1417  bool Read( ON_BinaryArchive& );
1418  bool Write( ON_BinaryArchive& ) const;
1419 
1420  unsigned int SizeOf() const;
1421 };
1422 
1424 {
1425 public:
1426  ON_BrepLoopArray();
1427  ~ON_BrepLoopArray();
1428  bool Read( ON_BinaryArchive& );
1429  bool Write( ON_BinaryArchive& ) const;
1430 
1431  unsigned int SizeOf() const;
1432 };
1433 
1434 class ON_CLASS ON_BrepFaceArray : public ON_ObjectArray<ON_BrepFace>
1435 {
1436 public:
1437  ON_BrepFaceArray();
1438  ~ON_BrepFaceArray();
1439  bool Read( ON_BinaryArchive& );
1440  bool Write( ON_BinaryArchive& ) const;
1441 
1442  unsigned int SizeOf() const;
1443 };
1444 
1446 {
1447 public:
1451  bool Read( ON_BinaryArchive& );
1452  bool Write( ON_BinaryArchive& ) const;
1453 
1454  unsigned int SizeOf() const;
1455 
1456 private:
1457  bool Internal_ReadV5( ON_BinaryArchive& );
1458  bool Internal_ReadV6( ON_BinaryArchive& );
1459 
1460  bool Internal_WriteV5( ON_BinaryArchive& ) const;
1461  bool Internal_WriteV6( ON_BinaryArchive& ) const;
1462 };
1463 
1464 class ON_CLASS ON_BrepRegionArray : public ON_ObjectArray<ON_BrepRegion>
1465 {
1466 public:
1469 
1470  bool Read( ON_BinaryArchive& );
1471  bool Write( ON_BinaryArchive& ) const;
1473  unsigned int SizeOf() const;
1474 
1475 private:
1476  bool Internal_ReadV5( ON_BinaryArchive& );
1477  bool Internal_ReadV6( ON_BinaryArchive& );
1478 
1479  bool Internal_WriteV5( ON_BinaryArchive& ) const;
1480  bool Internal_WriteV6( ON_BinaryArchive& ) const;
1481 };
1482 
1483 class ON_CLASS ON_BrepRegionTopology
1484 {
1485 public:
1489  ON_BrepRegionTopology& operator=(const ON_BrepRegionTopology&);
1490 
1491  ON_BrepFaceSideArray m_FS;
1492  ON_BrepRegionArray m_R;
1493 
1494 
1495  const ON_Brep* Brep() const;
1496  bool IsValid( ON_TextLog* text_log = 0 ) const;
1497  bool Read( ON_BinaryArchive& );
1498  bool Write( ON_BinaryArchive& ) const;
1499 
1500  unsigned int SizeOf() const;
1501 
1502  bool Transform(
1503  const ON_Xform& xform
1504  );
1505 
1506 
1507 private:
1508  friend class ON_V5_BrepRegionTopologyUserData;
1509  friend class ON_Brep;
1510  const ON_Brep* m_brep = nullptr;
1511 };
1512 
1513 class ON_CLASS ON_Brep : public ON_Geometry
1514 {
1515  ON_OBJECT_DECLARE(ON_Brep);
1516 
1517 public:
1518 
1519  /////////////////////////////////////////////////////////////////
1520  //
1521  // Component status interface
1522  //
1523  //
1524 
1525  //virtual
1526  unsigned int ClearComponentStates(
1527  ON_ComponentStatus states_to_clear
1528  ) const override;
1529 
1530  //virtual
1531  unsigned int GetComponentsWithSetStates(
1532  ON_ComponentStatus states_filter,
1533  bool bAllEqualStates,
1535  ) const override;
1536 
1537  //virtual
1538  unsigned int SetComponentStates(
1539  ON_COMPONENT_INDEX component_index,
1540  ON_ComponentStatus states_to_set
1541  ) const override;
1542 
1543  //virtual
1544  unsigned int ClearComponentStates(
1545  ON_COMPONENT_INDEX component_index,
1546  ON_ComponentStatus states_to_clear
1547  ) const override;
1548 
1549  //virtual
1550  unsigned int SetComponentStatus(
1551  ON_COMPONENT_INDEX component_index,
1552  ON_ComponentStatus status_to_copy
1553  ) const override;
1554 
1555  //virtual
1556  ON_AggregateComponentStatus AggregateComponentStatus() const override;
1557 
1558  //virtual
1559  void MarkAggregateComponentStatusAsNotCurrent() const override;
1560 
1561  // virtual ON_Object::DestroyRuntimeCache override
1562  void DestroyRuntimeCache( bool bDelete = true ) override;
1563 
1564  // virtual ON_Object::SizeOf override
1565  unsigned int SizeOf() const override;
1566 
1567  // virtual ON_Object::DataCRC override
1568  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
1569 
1570  // virtual ON_Geometry override
1571  bool EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const override;
1572 
1573 public:
1574 
1575 
1576  /*
1577  Description:
1578  Use ON_Brep::New() instead of new ON_Brep() when writing
1579  Rhino plug-ins (or when openNURBS is used as a Microsoft
1580  DLL and you need to create a new ON_Brep in a different
1581  .EXE or .DLL).
1582  Example:
1583 
1584  // bad - ON_Brep* pBrep = new ON_Brep();
1585  ON_Brep* pBrep = ON_Brep::New(); // good
1586  ...
1587  delete pBrep;
1588  pBrep = nullptr;
1589 
1590  Returns:
1591  Pointer to an ON_Brep. Destroy by calling delete.
1592  Remarks:
1593  When openNURBS is used as a Microsoft DLL, the CL.EXE
1594  compiler uses local vtables for classes that are new-ed
1595  in other executables but uses the ordinary vtable for
1596  for classes that are allocated in functions like
1597  ON_BrepCylinder(), ON_NurbsSurfaceQuadrilateral(),
1598  ON_Cylinder::RevSurfaceForm(nullptr), etc.
1599  Using static New() functions like ON_Brep::New() insures
1600  that identical classes has the same vtable and makes
1601  all code run identically.
1602  */
1603  static ON_Brep* New();
1604 
1605  /*
1606  Description:
1607  Use ON_Brep::New(const ON_Brep& src) instead
1608  of new ON_Brep(const ON_Brep& src).
1609  Returns:
1610  Pointer to an ON_Brep. Destroy by calling delete.
1611  Remarks:
1612  See static ON_Brep* ON_Brep::New() for details.
1613  */
1614  static ON_Brep* New(const ON_Brep&);
1615 
1616  // Construction
1617  ON_Brep();
1618  ~ON_Brep();
1619  ON_Brep(const ON_Brep&);
1620  ON_Brep& operator=(const ON_Brep&);
1621 
1622  // Override of virtual ON_Object::MemoryRelocate
1623  void MemoryRelocate() override;
1624 
1625 
1626  /*
1627  Description:
1628  Does nothing. Will be deleted in next version.
1629  */
1630  ON_DEPRECATED_MSG("Does nothing. Delete call.")
1631  bool IsDuplicate(
1632  const ON_Brep& other,
1633  double tolerance = ON_ZERO_TOLERANCE
1634  ) const;
1635 
1636  /////////////////////////////////////////////////////////////////
1637  // construction/destruction helpers
1638 
1639  // returns Brep to state it has after default construction
1640  void Destroy();
1641 
1642  // call if memory pool used by b-rep members becomes invalid
1643  void EmergencyDestroy();
1644 
1645  /*
1646  Description:
1647  Calculates polygon mesh approximation of the brep
1648  and appends one mesh for each face to the mesh_list[]
1649  array.
1650  Parameters:
1651  mp - [in] meshing parameters
1652  mesh_list - [out] meshes are appended to this array.
1653  Returns:
1654  Number of meshes appended to mesh_list[] array.
1655  */
1656  int CreateMesh(
1657  const ON_MeshParameters& mp,
1658  ON_SimpleArray<ON_Mesh*>& mesh_list
1659  ) const;
1660 
1661  /*
1662  Description:
1663  Destroy meshes used to render and analyze brep.
1664  Parameters:
1665  mesh_type - [in] type of mesh to destroy
1666  bDeleteMesh - [in] if true, cached meshes are deleted.
1667  If false, pointers to cached meshes are just set to nullptr.
1668  See Also:
1669  ON_Brep::GetMesh
1670  ON_BrepFace::DestroyMesh
1671  ON_BrepFace::Mesh
1672  ON_BrepFace::SetMesh
1673  */
1674  void DestroyMesh( ON::mesh_type mesh_type, bool bDeleteMesh = true );
1675 
1676  /*
1677  Description:
1678  Get cached meshes used to render and analyze brep.
1679  Parameters:
1680  mesh_type - [in] type of mesh to get
1681  meshes - [out] meshes are appended to this array. The ON_Brep
1682  owns these meshes so they cannot be modified.
1683  Returns:
1684  Number of meshes added to array. (Same as m_F.Count())
1685  See Also:
1686  ON_Brep::DestroyMesh
1687  ON_BrepFace::DestroyMesh
1688  ON_BrepFace::Mesh
1689  ON_BrepFace::SetMesh
1690  */
1691  int GetMesh( ON::mesh_type mesh_type, ON_SimpleArray< const ON_Mesh* >& meshes ) const;
1692 
1693 
1694  /*
1695  Description:
1696  Create a brep from a surface. The resulting surface has an outer
1697  boundary made from four trims. The trims are ordered so that
1698  they run along the south, east, north, and then west side of the
1699  surface's parameter space.
1700  Parameters:
1701  pSurface - [in] pointer to a surface. The brep will manage this
1702  pointer and delete it in ~ON_Brep.
1703  Returns:
1704  @untitled table
1705  true successful
1706  When true is returned, the pSurface pointer is added to the
1707  brep's m_S[] array and it will be deleted by the brep's
1708  destructor.
1709  false
1710  brep cannot be created from this surface.
1711  When false is returned, then the caller is responsible
1712  for deleting pSurface unless it was previously added
1713  to the brep's m_S[] array.
1714  Remarks:
1715  The surface class must be created with new so that the
1716  delete in ~ON_Brep will not cause a crash.
1717  */
1718  bool Create(
1719  ON_Surface*& pSurface
1720  );
1721 
1722  bool Create(
1723  ON_NurbsSurface*& pNurbsSurface
1724  );
1725 
1726  bool Create(
1727  ON_PlaneSurface*& pPlaneSurface
1728  );
1729 
1730  bool Create(
1731  ON_RevSurface*& pRevSurface
1732  );
1733 
1734  bool Create(
1735  ON_SumSurface*& pSumSurface
1736  );
1737 
1738  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
1739 
1740  /*
1741  Description:
1742  Tests the brep to see if its topology information is
1743  valid.
1744  Parameters:
1745  text_log - [in] if the brep topology is not valid and
1746  text_log is not nullptr, then a brief english
1747  description of the problem is appended to the log.
1748  The information appended to text_log is suitable for
1749  low-level debugging purposes by programmers and is
1750  not intended to be useful as a high level user
1751  interface tool.
1752  Returns:
1753  @untitled table
1754  true brep topology is valid
1755  false brep topology is not valid
1756  Remarks:
1757  ON_Brep::IsValidTopology can be called at any time.
1758  See Also:
1759  ON_Brep::IsValid
1760  ON_Brep::IsValidGeometry
1761  ON_Brep::IsValidTolerancesAndFlags
1762  */
1763  bool IsValidTopology( ON_TextLog* text_log = nullptr ) const;
1764 
1765 
1766  /*
1767  Description:
1768  Expert user function that tests the brep to see if its
1769  geometry information is valid. The value of
1770  brep.IsValidTopology() must be true before
1771  brep.IsValidGeometry() can be safely called.
1772  Parameters:
1773  text_log - [in] if the brep geometry is not valid and
1774  text_log is not nullptr, then a brief english
1775  description of the problem is appended to the log.
1776  The information appended to text_log is suitable for
1777  low-level debugging purposes by programmers and is
1778  not intended to be useful as a high level user
1779  interface tool.
1780  Returns:
1781  @untitled table
1782  true brep geometry is valid
1783  false brep geometry is not valid
1784  Remarks:
1785  ON_Brep::IsValidTopology must be true before you can
1786  safely call ON_Brep::IsValidGeometry.
1787  See Also:
1788  ON_Brep::IsValid
1789  ON_Brep::IsValidTopology
1790  ON_Brep::IsValidTolerancesAndFlags
1791  */
1792  bool IsValidGeometry( ON_TextLog* text_log = nullptr ) const;
1793 
1794  /*
1795  Description:
1796  Expert user function that tests the brep to see if its
1797  tolerances and flags are valid. The values of
1798  brep.IsValidTopology() and brep.IsValidGeometry() must
1799  be true before brep.IsValidTolerancesAndFlags() can
1800  be safely called.
1801  Parameters:
1802  text_log - [in] if the brep tolerance or flags are not
1803  valid and text_log is not nullptr, then a brief english
1804  description of the problem is appended to the log.
1805  The information appended to text_log is suitable for
1806  low-level debugging purposes by programmers and is
1807  not intended to be useful as a high level user
1808  interface tool.
1809  Returns:
1810  @untitled table
1811  true brep tolerance and flags are valid
1812  false brep tolerance and flags are not valid
1813  Remarks:
1814  ON_Brep::IsValidTopology and ON_Brep::IsValidGeometry
1815  must be true before you can safely call
1816  ON_Brep::IsValidTolerancesAndFlags.
1817  See Also:
1818  ON_Brep::IsValid
1819  ON_Brep::IsValidTopology
1820  ON_Brep::IsValidGeometry
1821  */
1822  bool IsValidTolerancesAndFlags( ON_TextLog* text_log = nullptr ) const;
1823 
1824  // Description:
1825  // Tests brep to see if it is valid for
1826  // saving in V2 3DM archives.
1827  // Returns:
1828  // true if brep is valid for V2 3DM archives.
1829  // Remarks:
1830  // V2 breps could not have dangling curves.
1831  bool IsValidForV2() const;
1832  bool IsValidForV2( const ON_BrepTrim& ) const;
1833  bool IsValidForV2( const ON_BrepEdge& ) const;
1834 
1835 
1836  // virtual ON_Objet::Dump() override
1837  void Dump( ON_TextLog& ) const override; // for debugging
1838 
1839  // virtual ON_Objet::Write() override
1840  bool Write( ON_BinaryArchive& ) const override;
1841 
1842  // virtual ON_Objet::Read() override
1843  bool Read( ON_BinaryArchive& ) override;
1844 
1845  // virtual ON_Objet::ObjectType() override
1846  ON::object_type ObjectType() const override;
1847 
1848  // virtual ON_Geometry::Dimension() override
1849  int Dimension() const override;
1850 
1851  // virtual ON_Geometry::ClearBoundingBox() override
1852  void ClearBoundingBox() override;
1853 
1854  // virtual ON_Geometry GetTightBoundingBox override
1855  bool GetTightBoundingBox( class ON_BoundingBox& tight_bbox, bool bGrowBox = false, const class ON_Xform* xform = nullptr ) const override;
1856 
1857  // virtual ON_Geometry GetBBox override
1858  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
1859 
1860  // virtual ON_Geometry::Transform() override
1861  bool Transform(
1862  const ON_Xform&
1863  ) override;
1864 
1865 
1866  // virtual ON_Geometry::SwapCoordinates() override
1867  bool SwapCoordinates(
1868  int, int // indices of coords to swap
1869  ) override;
1870 
1871 
1872  // virtual ON_Geometry::HasBrepForm() override
1873  bool HasBrepForm() const override; // returns true
1874 
1875  /*
1876  Description:
1877  If possible, BrepForm() creates a brep form of the
1878  ON_Geometry.
1879  Parameters:
1880  brep - [in] if not nullptr, brep is used to store the brep
1881  form of the geometry.
1882  Result:
1883  If brep is not nullptr, then brep = this, otherwise
1884  a duplicate of this is returned.
1885  Remarks:
1886  Override of virtual ON_Geometry::BrepForm
1887  */
1888  ON_Brep* BrepForm( ON_Brep* brep = nullptr ) const override;
1889 
1890  /////////////////////////////////////////////////////////////////
1891  // Creation Interface
1892 
1893  // These add a new geometry piece to the b-rep and return the
1894  // index that should be used to reference the geometry.
1895  // -1 is returned if the input is not acceptable.
1896  // ~ON_Brep() will delete the geometry.
1897  int AddTrimCurve( ON_Curve* ); // 2d curve used by ON_BrepTrim
1898  int AddEdgeCurve( ON_Curve* ); // 3d curve used by ON_BrepEdge
1899  int AddSurface( ON_Surface* ); // 3d surface used by ON_BrepFace
1900 
1901  // Description:
1902  // Set 3d curve geometry used by a b-rep edge.
1903  // Parameters:
1904  // edge - [in]
1905  // c3_index - [in] index of 3d curve in m_C3[] array
1906  // sub_domain - [in] if not nullptr, sub_domain is an increasing
1907  // sub interval of m_C3[c3_index]->Domain().
1908  // Returns:
1909  // true if successful.
1910  bool SetEdgeCurve(
1911  ON_BrepEdge& edge,
1912  int c3_index,
1913  const ON_Interval* sub_domain = nullptr
1914  );
1915 
1916  // Description:
1917  // Set 2d curve geometry used by a b-rep trim.
1918  // Parameters:
1919  // trim - [in]
1920  // c2_index - [in] index of 2d curve in m_C2[] array
1921  // sub_domain - [in] if not nullptr, sub_domain is an increasing
1922  // sub interval of m_C2[c2_index]->Domain().
1923  // Returns:
1924  // true if successful.
1925  bool SetTrimCurve(
1926  ON_BrepTrim& trim,
1927  int c2_index,
1928  const ON_Interval* sub_domain = nullptr
1929  );
1930 
1931  // These add a new topology piece to the b-rep and return a
1932  // reference that is intended to be used for initialization.
1933  ON_BrepVertex& NewVertex();
1934  ON_BrepVertex& NewVertex(
1935  ON_3dPoint vertex_point,
1936  double vertex_tolerance = ON_UNSET_VALUE
1937  );
1938 
1939  ON_BrepEdge& NewEdge(
1940  int = -1 // 3d curve index
1941  );
1942  ON_BrepEdge& NewEdge(
1943  ON_BrepVertex&, // start vertex
1944  ON_BrepVertex&, // end vertex
1945  int = -1, // 3d curve index
1946  const ON_Interval* = nullptr, // sub_domain
1947  double edge_tolerance = ON_UNSET_VALUE
1948  );
1949 
1950  /*
1951  Description:
1952  Add a new face to a brep. An incomplete face is added.
1953  The caller must create and fill in the loops used by
1954  the face.
1955  Parameters:
1956  si - [in] index of surface in brep's m_S[] array
1957  Returns:
1958  Reference to new face.
1959  Remarks:
1960  Adding a new face may grow the dynamic m_F array. When
1961  this happens pointers and references to memory in the
1962  previous m_F[] array may become invalid. Use face indices
1963  if this is an issue.
1964  Example:
1965  See ON_BrepBox and ON_BrepSphere source code.
1966  See Also:
1967  ON_Brep::AddSurface
1968  */
1969  ON_BrepFace& NewFace(
1970  int si = -1
1971  );
1972 
1973  /*
1974  Description:
1975  Add a new face to a brep. This creates a complete face with
1976  new vertices at the surface corners, new edges along the surface
1977  boundary, etc. The loop of the returned face has four trims that
1978  correspond to the south, east, north, and west side of the
1979  surface in that order. If you use this version of NewFace to
1980  add an exiting brep, then you are responsible for using a tool
1981  like ON_Brep::JoinEdges() to hook the new face to its
1982  neighbors.
1983  Parameters:
1984  surface - [in] surface is copied.
1985  Returns:
1986  Pointer to new face.
1987  Remarks:
1988  Adding a new face may grow the dynamic arrays used to store
1989  vertices, edges, faces, loops, and trims. When these dyamic
1990  arrays are grown, any pointers and references to memory in
1991  the previous arrays may become invalid. Use indices
1992  if this is an issue.
1993  See Also:
1994  ON_Brep::JoinEdges
1995  ON_Brep::AddSurface
1996  */
1997  ON_BrepFace* NewFace(
1998  const ON_Surface& surface
1999  );
2000 
2001  /*
2002  Description:
2003  Add a new face to brep. This version is for expert users.
2004  Parameters:
2005  pSurface - [in] the returned face will have an outer loop
2006  that goes around the edges of the surface.
2007  vid - [in/out] four vertex indices that specify the vertices at
2008  the (sw,se,nw,ne) corners. If the input value
2009  of a vertex index is -1, then the vertex will be
2010  created.
2011  eid - [in/out] four edge indices that specify the edges for
2012  the (south,east,north,west) sides. If the input value
2013  of an edge index is -1, then the edge will be created.
2014  bRev3d - [in/out] four values of the trim m_bRev3d flags of
2015  the (south,east,north,west) sides.
2016  Returns:
2017  Pointer to the new face or nullptr if input is not valid.
2018  If null is returned, then the caller must delete pSurace
2019  unless it was previously added to the brep's m_S[] array.
2020  Remarks:
2021  Adding a new face may grow the dynamic m_F array. When
2022  this happens pointers and references to memory in the
2023  previous m_F[] array may become invalid. Use face indices
2024  if this is an issue.
2025  Example:
2026  See ON_BrepBox and ON_BrepSphere source code.
2027  See Also:
2028  ON_Brep::AddSurface
2029  ON_Brep::AddFace( int si )
2030  ON_Brep::Create( ON_Surface*& )
2031  */
2032  ON_BrepFace* NewFace(
2033  ON_Surface* pSurface,
2034  int vid[4],
2035  int eid[4],
2036  bool bRev3d[4]
2037  );
2038 
2039  /*
2040  Description:
2041  Add a new face to the brep whose surface geometry is a
2042  ruled surface between two edges.
2043  Parameters:
2044  edgeA - [in] The south side of the face's surface will
2045  run along edgeA.
2046  bRevEdgeA - [in] true if the new face's outer boundary
2047  orientation along edgeA is opposite the orientation
2048  of edgeA.
2049  edgeB - [in] The north side of the face's surface will
2050  run along edgeA.
2051  bRevEdgeB - [in] true if the new face's outer boundary
2052  orientation along edgeB is opposite the orientation
2053  of edgeB.
2054  Returns:
2055  A pointer to the new face or a nullptr if the new face could
2056  not be created.
2057  */
2058  ON_BrepFace* NewRuledFace(
2059  const ON_BrepEdge& edgeA,
2060  bool bRevEdgeA,
2061  const ON_BrepEdge& edgeB,
2062  bool bRevEdgeB
2063  );
2064 
2065  /*
2066  Description:
2067  Add a new face to the brep whose surface geometry is a
2068  ruled cone with the edge as the base and the vertex as
2069  the apex point.
2070  Parameters:
2071  vertex - [in] The apex of the cone will be at this vertex.
2072  The north side of the surface's parameter
2073  space will be a singular point at the vertex.
2074  edge - [in] The south side of the face's surface will
2075  run along this edge.
2076  bRevEdge - [in] true if the new face's outer boundary
2077  orientation along the edge is opposite the
2078  orientation of edge.
2079  Returns:
2080  A pointer to the new face or a nullptr if the new face could
2081  not be created.
2082  */
2083  ON_BrepFace* NewConeFace(
2084  const ON_BrepVertex& vertex,
2085  const ON_BrepEdge& edge,
2086  bool bRevEdge
2087  );
2088 
2089  /*
2090  Description:
2091  Create a new empty boundary loop. The new loop will not be part of a face and
2092  will not include any trim curves.
2093  Returns:
2094  New boundary loop.
2095  */
2096  ON_BrepLoop& NewLoop( ON_BrepLoop::TYPE );
2097 
2098  /*
2099  Description:
2100  Create a new boundary loop on a face. After you get this
2101  ON_BrepLoop, you still need to create the vertices, edges,
2102  and trims that define the loop.
2103  Returns:
2104  New loop that needs to be filled in.
2105  */
2106  ON_BrepLoop& NewLoop( ON_BrepLoop::TYPE loop_type, ON_BrepFace& face );
2107 
2108  /*
2109  Description:
2110  Create a new outer boundary loop that runs along the sides
2111  of the face's surface. All the necessary trims, edges,
2112  and vertices are created and added to the brep.
2113  Parameters:
2114  face_index - [in] index of face that needs an outer boundary
2115  that runs along the sides of its surface.
2116  Returns:
2117  New outer boundary loop that is complete.
2118  */
2119  ON_BrepLoop* NewOuterLoop( int face_index );
2120 
2121  /*
2122  Description:
2123  Add a new face to brep. This version is for expert users.
2124  Parameters:
2125  face_index - [in] index of face that will get a new outer
2126  loop running around the sides of the face's
2127  underlying surface.
2128  vid - [in/out] four vertex indices that specify the vertices at
2129  the (sw,se,nw,ne) corners. If the input value
2130  of a vertex index is -1, then the vertex will be
2131  created.
2132  eid - [in/out] four edge indices that specify the edges for
2133  the (south,east,north,west) sides. If the input value
2134  of an edge index is -1, then the edge will be created.
2135  bRev3d - [in/out] four values of the trim m_bRev3d flags of
2136  the (south,east,north,west) sides.
2137  Returns:
2138  Pointer to the new loop or nullptr if input is not valid.
2139  Remarks:
2140  Adding a new loop may grow the dynamic m_L array. When
2141  this happens pointers and references to memory in the
2142  previous m_L[] array may become invalid. Use face indices
2143  if this is an issue.
2144  See Also:
2145  ON_Brep::NewFace
2146  */
2147  ON_BrepLoop* NewOuterLoop(
2148  int face_index,
2149  int vid[4],
2150  int eid[4],
2151  bool bRev3d[4]
2152  );
2153 
2154  /*
2155  Description:
2156  Add a planar trimming loop to a planar face.
2157  Parameters:
2158  face_index - [in] index of planar face. The underlying
2159  suface must be an ON_PlaneSurface.
2160  loop_type - [in] type of loop to add. If loop_type is
2161  ON_BrepLoop::unknown, then the loop direction is tested
2162  and the the new loops type will be set to
2163  ON_BrepLoop::outer or ON_BrepLoop::inner. If the loop_type
2164  is ON_BrepLoop::outer, then the direction of the new loop
2165  is tested and flipped if it is clockwise. If the loop_type
2166  is ON_BrepLoop::inner, then the direction of the new loop
2167  is tested and flipped if it is counter-clockwise.
2168  boundary - [in] a list of 3d curves that form a simple (no self
2169  intersections) closed curve. These curves define the 3d
2170  edge geometry and should be near the planar surface.
2171  bDuplicateCurves - [in] If true, then duplicates of the curves
2172  in the boundary array are added to the brep. If false, the
2173  curves in the boundary array are added to the brep and will
2174  be deleted by ON_Brep::~ON_Brep.
2175  Returns:
2176  true if successful. The new loop will be brep.m_L.Last().
2177  */
2178  bool NewPlanarFaceLoop(
2179  int face_index,
2180  ON_BrepLoop::TYPE loop_type,
2181  ON_SimpleArray<ON_Curve*>& boundary,
2182  bool bDuplicateCurves = true
2183  );
2184 
2185 
2186  /*
2187  Description:
2188  Add a new trim that will be part of an inner, outer, or slit loop
2189  to the brep.
2190  Parameters:
2191  c2i - [in] index of 2d trimming curve
2192  Returns:
2193  new trim
2194  Example:
2195  int c2i = brep->AddTrimCurve( p2dCurve );
2196  ON_BrepTrim& trim = NewTrim( edge, bRev3d, loop, c2i );
2197  trim.m_ei = ...;
2198  trim.m_li = ...;
2199  trim.m_tolerance[0] = ...;
2200  trim.m_tolerance[1] = ...;
2201  trim.m_type = ...;
2202  trim.m_iso = ...;
2203  Remarks:
2204  You should set the trim's ON_BrepTrim::m_tolerance, ON_BrepTrim::m_type,
2205  ON_BrepTrim::m_iso, ON_BrepTrim::m_li, and ON_BrepTrim::m_ei values.
2206  In general, you should try to use the
2207  ON_BrepTrim::NewTrim( edge, bRev3d, loop, c2i ) version of NewTrim.
2208  If you want to add a singular trim, use ON_Brep::NewSingularTrim.
2209  If you want to add a crvonsrf trim, use ON_Brep::NewCurveOnFace.
2210  If you want to add a ptonsrf trim, use ON_Brep::NewPointOnFace.
2211  See Also:
2212  ON_Brep::SetTrimTypeFlags
2213  ON_Brep::SetTrimIsoFlags
2214  ON_Brep::NewSingularTrim
2215  ON_Brep::NewPointOnFace
2216  ON_Brep::NewCurveOnFace
2217  */
2218  ON_BrepTrim& NewTrim(
2219  int c2i = -1
2220  );
2221 
2222  /*
2223  Description:
2224  Add a new trim that will be part of an inner, outer, or slit loop
2225  to the brep.
2226  Parameters:
2227  bRev3d - [in] ON_BrepTrim::m_bRev3d value. true if the
2228  edge and trim have opposite directions.
2229  loop - [in] trim is appended to this loop
2230  c2i - [in] index of 2d trimming curve
2231  Returns:
2232  new trim
2233  Example:
2234  int c2i = brep->AddTrimCurve( p2dCurve );
2235  ON_BrepTrim& trim = NewTrim( edge, bRev3d, loop, c2i );
2236  trim.m_ei = ...;
2237  trim.m_tolerance[0] = ...;
2238  trim.m_tolerance[1] = ...;
2239  trim.m_type = ...;
2240  trim.m_iso = ...;
2241  Remarks:
2242  You should set the trim's ON_BrepTrim::m_tolerance, ON_BrepTrim::m_type,
2243  ON_BrepTrim::m_iso, and ON_BrepTrim::m_ei values.
2244  In general, you should try to use the
2245  ON_BrepTrim::NewTrim( edge, bRev3d, loop, c2i ) version of NewTrim.
2246  If you want to add a singular trim, use ON_Brep::NewSingularTrim.
2247  If you want to add a crvonsrf trim, use ON_Brep::NewCurveOnFace.
2248  If you want to add a ptonsrf trim, use ON_Brep::NewPointOnFace.
2249  See Also:
2250  ON_Brep::SetTrimTypeFlags
2251  ON_Brep::SetTrimIsoFlags
2252  ON_Brep::NewSingularTrim
2253  ON_Brep::NewPointOnFace
2254  ON_Brep::NewCurveOnFace
2255  */
2256  ON_BrepTrim& NewTrim(
2257  bool bRev3d,
2258  ON_BrepLoop& loop,
2259  int c2i = -1
2260  );
2261 
2262  /*
2263  Description:
2264  Add a new trim that will be part of an inner, outer, or slit loop
2265  to the brep.
2266  Parameters:
2267  edge - [in] 3d edge associated with this trim
2268  bRev3d - [in] ON_BrepTrim::m_bRev3d value. true if the
2269  edge and trim have opposite directions.
2270  c2i - [in] index of 2d trimming curve
2271  Returns:
2272  new trim
2273  Example:
2274  int c2i = brep->AddTrimCurve( p2dCurve );
2275  ON_BrepTrim& trim = NewTrim( edge, bRev3d, c2i );
2276  trim.m_li = ...;
2277  trim.m_tolerance[0] = ...;
2278  trim.m_tolerance[1] = ...;
2279  trim.m_type = ...;
2280  trim.m_iso = ...;
2281  Remarks:
2282  You should set the trim's ON_BrepTrim::m_tolerance,
2283  ON_BrepTrim::m_type, ON_BrepTrim::m_iso,
2284  and ON_BrepTrim::m_li values.
2285  In general, you should try to use the
2286  ON_BrepTrim::NewTrim( edge, bRev3d, loop, c2i ) version of NewTrim.
2287  If you want to add a singular trim, use ON_Brep::NewSingularTrim.
2288  If you want to add a crvonsrf trim, use ON_Brep::NewCurveOnFace.
2289  If you want to add a ptonsrf trim, use ON_Brep::NewPointOnFace.
2290  See Also:
2291  ON_Brep::SetTrimTypeFlags
2292  ON_Brep::SetTrimIsoFlags
2293  ON_Brep::NewSingularTrim
2294  ON_Brep::NewPointOnFace
2295  ON_Brep::NewCurveOnFace
2296  */
2297  ON_BrepTrim& NewTrim(
2298  ON_BrepEdge& edge,
2299  bool bRev3d,
2300  int c2i = -1
2301  );
2302 
2303  /*
2304  Description:
2305  Add a new trim that will be part of an inner, outer, or slit loop
2306  to the brep.
2307  Parameters:
2308  edge - [in] 3d edge associated with this trim
2309  bRev3d - [in] ON_BrepTrim::m_bRev3d value. true if the
2310  edge and trim have opposite directions.
2311  loop - [in] trim is appended to this loop
2312  c2i - [in] index of 2d trimming curve
2313  Returns:
2314  new trim
2315  Example:
2316  int c2i = brep->AddTrimCurve( p2dCurve );
2317  ON_BrepTrim& trim = brep->NewTrim( edge, bRev3d, loop, c2i );
2318  trim.m_tolerance[0] = ...;
2319  trim.m_tolerance[1] = ...;
2320  Remarks:
2321  You should set the trim's ON_BrepTrim::m_tolerance values.
2322  If c2i is -1, you must set the trim's ON_BrepTrim::m_iso values.
2323  This version of NewTrim sets the trim.m_type value. If the
2324  input edge or loop are not currently valid, then you may
2325  need to adjust the trim.m_type value.
2326  If you want to add a singular trim, use ON_Brep::NewSingularTrim.
2327  If you want to add a crvonsrf trim, use ON_Brep::NewCurveOnFace.
2328  If you want to add a ptonsrf trim, use ON_Brep::NewPointOnFace.
2329  See Also:
2330  ON_Brep::SetTrimTypeFlags
2331  ON_Brep::SetTrimIsoFlags
2332  ON_Brep::NewSingularTrim
2333  ON_Brep::NewPointOnFace
2334  ON_Brep::NewCurveOnFace
2335  */
2336  ON_BrepTrim& NewTrim(
2337  ON_BrepEdge& edge,
2338  bool bRev3d,
2339  ON_BrepLoop& loop,
2340  int c2i = -1
2341  );
2342 
2343  /*
2344  Description:
2345  Add a new singular trim to the brep.
2346  Parameters:
2347  vertex - [in] vertex along collapsed surface edge
2348  loop - [in] trim is appended to this loop
2349  iso - [in] one of ON_Surface::S_iso, ON_Surface::E_iso,
2350  ON_Surface::N_iso, or ON_Surface::W_iso.
2351  c2i - [in] index of 2d trimming curve
2352  Returns:
2353  new trim
2354  See Also:
2355  ON_Brep::NewTrim
2356  */
2357  ON_BrepTrim& NewSingularTrim(
2358  const ON_BrepVertex& vertex,
2359  ON_BrepLoop& loop,
2360  ON_Surface::ISO iso,
2361  int c2i = -1
2362  );
2363 
2364  /*
2365  Description:
2366  Adds a new point on face to the brep.
2367  Parameters:
2368  face - [in] face that vertex lies on
2369  s,t - [in] surface parameters
2370  Returns:
2371  new vertex that represents the point on face.
2372  Remarks:
2373  If a vertex is a point on a face, then brep.m_E[m_ei]
2374  will be an edge with no 3d curve. This edge will have
2375  a single trim with type ON_BrepTrim::ptonsrf. There
2376  will be a loop containing this single trim.
2377  */
2378  ON_BrepVertex& NewPointOnFace(
2379  ON_BrepFace& face,
2380  double s,
2381  double t
2382  );
2383 
2384  /*
2385  Description:
2386  Add a new curve on face to the brep.
2387  Parameters:
2388  face - [in] face that curve lies on
2389  edge - [in] 3d edge associated with this curve on surface
2390  bRev3d - [in] true if the 3d edge and the 2d parameter space
2391  curve have opposite directions.
2392  c2i - [in] index of 2d curve in face's parameter space
2393  Returns:
2394  new trim that represents the curve on surface
2395  Remarks:
2396  You should set the trim's ON_BrepTrim::m_tolerance and
2397  ON_BrepTrim::m_iso values.
2398  */
2399  ON_BrepTrim& NewCurveOnFace(
2400  ON_BrepFace& face,
2401  ON_BrepEdge& edge,
2402  bool bRev3d = false,
2403  int c2i = -1
2404  );
2405 
2406  // appends a copy of brep to this and updates
2407  // indices of appended brep parts. Duplicates are not removed.
2408  void Append(
2409  const ON_Brep& // brep
2410  );
2411 
2412  // This function can be used to compute vertex information for a
2413  // b-rep when everything but the m_V array is properly filled in.
2414  // It is intended to be used when creating a ON_Brep from a
2415  // definition that does not include explicit vertex information.
2416  void SetVertices(void);
2417 
2418  // This function can be used to set the ON_BrepTrim::m_iso
2419  // flag. It is intended to be used when creating a ON_Brep from
2420  // a definition that does not include compatible parameter space
2421  // type information.
2422  // See Also: ON_BrepSetFlagsAndTolerances
2423  bool SetTrimIsoFlags(); // sets all trim iso flags
2424  bool SetTrimIsoFlags( ON_BrepFace& );
2425  bool SetTrimIsoFlags( ON_BrepLoop& );
2426  bool SetTrimIsoFlags( ON_BrepTrim& );
2427 
2428 
2429  /*
2430  Description:
2431  Calculate the type (singular, mated, boundary, etc.) of
2432  an ON_BrepTrim object.
2433  Parameters:
2434  trim - [in]
2435  bLazy - [in] if true and trim.m_type is set to something other
2436  than ON_BrepTrim::unknown, then no calculation is
2437  performed and the value of trim.m_type is returned.
2438  If false, the value of trim.m_type is ignored and is caluculated.
2439  Returns:
2440  Type of trim.
2441  Remarks:
2442  The trim must be connected to a valid loop.
2443  See Also:
2444  ON_Brep::SetTrimTypeFlags
2445  */
2446  ON_BrepTrim::TYPE TrimType(
2447  const ON_BrepTrim& trim,
2448  bool bLazy = true
2449  ) const;
2450 
2451  // This function can be used to set the ON_BrepTrim::m_type
2452  // flag. If the optional bLazy argument is true, then only
2453  // trims with m_type = unknown are set.
2454  // See Also: ON_BrepSetFlagsAndTolerances
2455  bool SetTrimTypeFlags( bool bLazy = false ); // sets all trim iso flags
2456  bool SetTrimTypeFlags( ON_BrepFace&, bool bLazy = false );
2457  bool SetTrimTypeFlags( ON_BrepLoop&, bool bLazy = false );
2458  bool SetTrimTypeFlags( ON_BrepTrim&, bool bLazy = false );
2459 
2460  // GetTrim2dStart() evaluates the start of the
2461  // parameter space (2d) trim curve.
2462  bool GetTrim2dStart(
2463  int trim_index, // index of ON_BrepTrim in m_T[] array
2464  ON_2dPoint&
2465  ) const;
2466 
2467  // GetTrim2dEnd() evaluates end of the
2468  // parameter space (2d) trim curve.
2469  bool GetTrim2dEnd(
2470  int, // index of ON_BrepTrim in m_T[] array
2471  ON_2dPoint&
2472  ) const;
2473 
2474  // GetTrim3dStart() evaluates the 3d surface at the start of the
2475  // parameter space (2d) trim curve.
2476  bool GetTrim3dStart(
2477  int, // index of ON_BrepTrim in m_T[] array
2478  ON_3dPoint&
2479  ) const;
2480 
2481  // GetTrim3dEnd() evaluates the 3d surface at the end of the
2482  // parameter space (2d) trim curve.
2483  bool GetTrim3dEnd(
2484  int, // index of ON_BrepTrim in m_T[] array
2485  ON_3dPoint&
2486  ) const;
2487 
2488  // This function examines the 2d parameter space curves and returns
2489  // the loop's type based on their orientation. Use this function for
2490  // debugging loop orientation problems.
2491  ON_BrepLoop::TYPE ComputeLoopType( const ON_BrepLoop& ) const;
2492 
2493  // These set the various tolerances. The optional bool argument
2494  // is called bLazy. If bLazy is false, the tolerance is recomputed
2495  // from its definition. If bLazy is true, the tolerance is computed
2496  // only if its current value is negative.
2497  bool SetVertexTolerance( ON_BrepVertex& vertex, bool bLazy = false ) const;
2498  virtual
2499  bool SetTrimTolerance( ON_BrepTrim& trim, bool bLazy = false ) const;
2500  virtual
2501  bool SetEdgeTolerance( ON_BrepEdge& edge, bool bLazy = false ) const;
2502 
2503  /*
2504  Description:
2505  Set the brep's vertex tolerances.
2506  Parameters:
2507  bLazy - [in] if true, only vertex tolerances with the value
2508  ON_UNSET_VALUE will be set. If false, the vertex tolerance
2509  is recomputed from the geometry in the brep.
2510  Returns:
2511  true if successful.
2512  See Also:
2513  ON_Brep::SetVertexTolerance
2514  ON_Brep::SetTrimTolerance
2515  ON_Brep::SetEdgeTolerance
2516  ON_Brep::SetVertexTolerances
2517  ON_Brep::SetTrimTolerances
2518  ON_Brep::SetEdgeTolerances
2519  ON_Brep::SetTolerancesAndFlags
2520  */
2521  bool SetVertexTolerances( bool bLazy = false );
2522 
2523  /*
2524  Description:
2525  Set the brep's trim tolerances.
2526  Parameters:
2527  bLazy - [in] if true, only trim tolerances with the value
2528  ON_UNSET_VALUE will be set. If false, the trim tolerance
2529  is recomputed from the geometry in the brep.
2530  Returns:
2531  true if successful.
2532  See Also:
2533  ON_Brep::SetVertexTolerance
2534  ON_Brep::SetTrimTolerance
2535  ON_Brep::SetEdgeTolerance
2536  ON_Brep::SetVertexTolerances
2537  ON_Brep::SetTrimTolerances
2538  ON_Brep::SetEdgeTolerances
2539  ON_Brep::SetTolerancesAndFlags
2540  */
2541  bool SetTrimTolerances( bool bLazy = false );
2542 
2543  /*
2544  Description:
2545  Set the brep's edge tolerances.
2546  Parameters:
2547  bLazy - [in] if true, only edge tolerances with the value
2548  ON_UNSET_VALUE will be set. If false, the edge tolerance
2549  is recomputed from the geometry in the brep.
2550  Returns:
2551  true if successful.
2552  See Also:
2553  ON_Brep::SetVertexTolerance
2554  ON_Brep::SetTrimTolerance
2555  ON_Brep::SetEdgeTolerance
2556  ON_Brep::SetVertexTolerances
2557  ON_Brep::SetTrimTolerances
2558  ON_Brep::SetEdgeTolerances
2559  ON_Brep::SetTolerancesAndFlags
2560  */
2561  bool SetEdgeTolerances( bool bLazy = false );
2562 
2563 
2564  /*
2565  Description:
2566  Set the trim parameter space bounding box (trim.m_pbox).
2567  Parameters:
2568  trim - [in]
2569  bLazy - [in] if true and trim.m_pbox is valid, then
2570  the box is not set.
2571  Returns:
2572  true if trim ends up with a valid bounding box.
2573  */
2574  virtual
2575  bool SetTrimBoundingBox( ON_BrepTrim& trim, bool bLazy=false );
2576 
2577  /*
2578  Description:
2579  Set the loop parameter space bounding box (loop.m_pbox).
2580  Parameters:
2581  loop - [in]
2582  bLazy - [in] if true and loop trim trim.m_pbox is valid,
2583  then that trim.m_pbox is not recalculated.
2584  Returns:
2585  true if loop ends up with a valid bounding box.
2586  */
2587  virtual
2588  bool SetTrimBoundingBoxes( ON_BrepLoop& loop, bool bLazy=false );
2589 
2590 
2591  /*
2592  Description:
2593  Set the loop and trim parameter space bounding boxes
2594  for every loop and trim in the face
2595  Parameters:
2596  face - [in]
2597  bLazy - [in] if true and trim trim.m_pbox is valid,
2598  then that trim.m_pbox is not recalculated.
2599  Returns:
2600  true if all the face's loop and trim parameter space bounding
2601  boxes are valid.
2602  */
2603  virtual
2604  bool SetTrimBoundingBoxes( ON_BrepFace& face, bool bLazy=false );
2605 
2606  /*
2607  Description:
2608  Set the loop and trim parameter space bounding boxes
2609  for every loop and trim in the brep.
2610  Parameters:
2611  bLazy - [in] if true and trim trim.m_pbox is valid,
2612  then that trim.m_pbox is not recalculated.
2613  Returns:
2614  true if all the loop and trim parameter space bounding boxes
2615  are valid.
2616  */
2617  virtual
2618  bool SetTrimBoundingBoxes( bool bLazy=false );
2619 
2620  /*
2621  Description:
2622  Set tolerances and flags in a brep
2623  Parameters:
2624  bLazy - [in] if true, only flags and tolerances that are not
2625  set will be calculated.
2626  bSetVertexTolerances - [in] true to compute vertex.m_tolerance values
2627  bSetEdgeTolerances - [in] true to compute edge.m_tolerance values
2628  bSetTrimTolerances - [in] true to compute trim.m_tolerance[0,1] values
2629  bSetTrimIsoFlags - [in] true to compute trim.m_iso values
2630  bSetTrimTypeFlags - [in] true to compute trim.m_type values
2631  bSetLoopTypeFlags - [in] true to compute loop.m_type values
2632  bSetTrimBoxes - [in] true to compute trim.m_pbox values
2633  See Also:
2634  ON_Brep::SetVertexTolerance
2635  ON_Brep::SetEdgeTolerance
2636  ON_Brep::SetTrimTolerance
2637  ON_Brep::SetTrimTypeFlags
2638  ON_Brep::SetTrimIsoFlags
2639  ON_Brep::ComputeLoopType
2640  ON_Brep::SetTrimBoundingBox
2641  ON_Brep::SetTrimBoundingBoxes
2642  */
2643  void SetTolerancesBoxesAndFlags(
2644  bool bLazy = false,
2645  bool bSetVertexTolerances = true,
2646  bool bSetEdgeTolerances = true,
2647  bool bSetTrimTolerances = true,
2648  bool bSetTrimIsoFlags = true,
2649  bool bSetTrimTypeFlags = true,
2650  bool bSetLoopTypeFlags = true,
2651  bool bSetTrimBoxes = true
2652  );
2653 
2654 
2655  /////////////////////////////////////////////////////////////////
2656  // Query Interface
2657 
2658  /*
2659  Description:
2660  Determine how many brep faces reference m_S[surface_index].
2661  Parameters:
2662  surface_index - [in] index of the surface in m_S[] array
2663  max_count - [in] counting stops if max_count > 0 and
2664  at least max_count faces use the surface.
2665  Returns:
2666  Number of brep faces that reference the surface.
2667  */
2668  int SurfaceUseCount(
2669  int surface_index,
2670  int max_count=0 )
2671  const;
2672  /*
2673  Description:
2674  Determine how many brep edges reference m_C3[c3_index].
2675  Parameters:
2676  c3_index - [in] index of the 3d curve in m_C3[] array
2677  max_count - [in] counting stops if max_count > 0 and
2678  at least max_count edges use the 3d curve.
2679  Returns:
2680  Number of brep edges that reference the 3d curve.
2681  */
2682  int EdgeCurveUseCount(
2683  int c3_index,
2684  int max_count=0 )
2685  const;
2686 
2687  /*
2688  Description:
2689  Determine how many brep trims reference m_C2[c2_index].
2690  Parameters:
2691  c2_index - [in] index of the 2d curve in m_C2[] array
2692  max_count - [in] counting stops if max_count > 0 and
2693  at least max_count trims use the 2d curve.
2694  Returns:
2695  Number of brep trims that reference the 2d curve.
2696  */
2697  int TrimCurveUseCount(
2698  int c2_index,
2699  int max_count=0 )
2700  const;
2701 
2702  /*
2703  Description:
2704  Get a single 3d curve that traces the entire loop
2705  Parameters:
2706  loop - [in] loop whose 3d curve should be duplicated
2707  bRevCurveIfFaceRevIsTrue - [in] If false, the returned
2708  3d curve has an orientation compatible with the
2709  2d curve returned by Loop2dCurve().
2710  If true and the m_bRev flag of the loop's face
2711  is true, then the returned curve is reversed.
2712  Returns:
2713  A pointer to a 3d ON_Curve. The caller must delete
2714  this curve.
2715  */
2716  ON_Curve* Loop3dCurve(
2717  const ON_BrepLoop& loop,
2718  bool bRevCurveIfFaceRevIsTrue = false
2719  ) const;
2720 
2721  /*
2722  Description:
2723  Get a list of 3d curves that trace the non-seam edge
2724  portions of an entire loop
2725  Parameters:
2726  loop - [in] loop whose 3d curve should be duplicated
2727  curve_list - [out] 3d curves are appended to this list
2728  bRevCurveIfFaceRevIsTrue - [in] If false, the returned
2729  3d curves have an orientation compatible with the
2730  2d curve returned by Loop2dCurve().
2731  If true and the m_bRev flag of the loop's face
2732  is true, then the returned curves are reversed.
2733  Returns:
2734  Number of curves appended to curve_list.
2735  */
2736  int Loop3dCurve(
2737  const ON_BrepLoop& loop,
2738  ON_SimpleArray<ON_Curve*>& curve_list,
2739  bool bRevCurveIfFaceRevIsTrue = false
2740  ) const;
2741 
2742 
2743  /*
2744  Description:
2745  Get a 3d curve that traces the entire loop
2746  Parameters:
2747  loop - [in] loop whose 2d curve should be duplicated
2748  Returns:
2749  A pointer to a 2d ON_Curve. The caller must delete
2750  this curve.
2751  */
2752  ON_Curve* Loop2dCurve( const ON_BrepLoop& loop ) const;
2753 
2754  /*
2755  Description:
2756  Determine orientation of a brep.
2757  Returns:
2758  @untitle table
2759  +2 brep is a solid but orientation cannot be computed
2760  +1 brep is a solid with outward facing normals
2761  -1 brep is a solid with inward facing normals
2762  0 brep is not a solid
2763  Remarks:
2764  The base class implementation returns 2 or 0. This
2765  function is overridden in the Rhino SDK and returns
2766  +1, -1, or 0.
2767  See Also:
2768  ON_Brep::IsSolid
2769  */
2770  virtual
2771  int SolidOrientation() const;
2772 
2773  /*
2774  Description:
2775  Test brep to see if it is a solid. (A "solid" is
2776  a closed oriented manifold.)
2777  Returns:
2778  @untitled table
2779  true brep is a solid
2780  fals brep is not a solid
2781  See Also:
2782  ON_Brep::SolidOrientation
2783  ON_Brep::IsManifold
2784  */
2785  bool IsSolid() const;
2786 
2787  /*
2788  Description:
2789  Test brep to see if it is an oriented manifold.
2790  Parameters:
2791  pbIsOriented - [in] if not null, *pbIsOriented is set
2792  to true if b-rep is an oriented manifold and false
2793  if brep is not an oriented manifold.
2794  pbHasBoundary - [in] if not null, *pbHasBoundary is set
2795  to true if b-rep has a boundary edge and false if
2796  brep does not have a boundary edge.
2797  Returns:
2798  true brep is a manifold
2799  fals brep is not a manifold
2800  See Also:
2801  ON_Brep::IsSolid
2802  */
2803  bool IsManifold( // returns true if b-rep is an oriented manifold
2804  bool* pbIsOriented = nullptr,
2805  bool* pbHasBoundary = nullptr
2806  ) const;
2807 
2808  /*
2809  Description:
2810  Determine if P is inside Brep. This question only makes sense
2811  when the brep is a closed manifold. This function does not
2812  not check for closed or manifold, so result is not valid in
2813  those cases. Intersects a line through P with brep, finds
2814  the intersection point Q closest to P, and looks at face
2815  normal at Q. If the point Q is on an edge or the intersection
2816  is not transverse at Q, then another line is used.
2817  Parameters:
2818  P - [in] 3d point
2819  tolerance - [in] 3d distance tolerance used for intersection
2820  and determining strict inclusion.
2821  bStrictlInside - [in] If bStrictlInside is true, then this
2822  function will return false if the distance from P is within
2823  tolerance of a brep face.
2824  Returns:
2825  True if P is in, false if not. See parameter bStrictlyIn.
2826  */
2827  bool IsPointInside(
2828  ON_3dPoint P,
2829  double tolerance,
2830  bool bStrictlyInside
2831  ) const;
2832 
2833 
2834  bool IsSurface() const; // returns true if the b-rep has a single face
2835  // and that face is geometrically the same
2836  // as the underlying surface. I.e., the face
2837  // has trivial trimming. In this case, the
2838  // surface is m_S[0].
2839  // The flag m_F[0].m_bRev records
2840  // the correspondence between the surface's
2841  // natural parametric orientation and the
2842  // orientation of the b-rep.
2843 
2844 
2845  bool FaceIsSurface( // returns true if the face has a single
2846  int // index of face // outer boundary and that boundary runs
2847  ) const; // along the edges of the underlying surface.
2848  // In this case the geometry of the surface
2849  // is the same as the geometry of the face.
2850  // If FaceIsSurface() is true, then
2851  // m_S[m_F[face_index].m_si] is the surface.
2852  // The flag m_F[face_index].m_bRev records
2853  // the correspondence between the surface's
2854  // natural parametric orientation and the
2855  // orientation of face in the b-rep.
2856 
2857  bool LoopIsSurfaceBoundary( // returns true if the loop's trims all run
2858  int // index of loop // along the edge's of the underlying surface's
2859  ) const; // parameter space.
2860 
2861  /////////////////////////////////////////////////////////////////
2862  // Modification Interface
2863 
2864  //////////
2865  // Clears all ON_BrepFace.m_bRev flags by ON_BrepFace::Transpose
2866  // on each face with a true m_bRev.
2867  bool FlipReversedSurfaces();
2868 
2869  //////////
2870  // Change the domain of a trim's 2d curve. This changes only the
2871  // parameterization of the 2d trimming curve; the locus of the
2872  // 2d trimming curve is not changed.
2873  bool SetTrimDomain(
2874  int, // index of trim in m_T[] array
2875  const ON_Interval&
2876  );
2877 
2878  //////////
2879  // Change the domain of an edge. This changes only the
2880  // parameterization of the 3d edge curve; the locus of the
2881  // 3d edge curve is not changed.
2882  bool SetEdgeDomain(
2883  int, // index of edge in m_E[] array
2884  const ON_Interval&
2885  );
2886 
2887  // Reverses entire brep orientation of all faces by toggling
2888  // value of all face's ON_BrepFace::m_bRev flag.
2889  void Flip();
2890 
2891  // reverses orientation of a face by toggling ON_BrepFace::m_bRev
2892  void FlipFace(ON_BrepFace&);
2893 
2894  // Reverses orientation of trimming loop.
2895  // This function is intended to be used by brep experts and does
2896  // does NOT modify ON_BrepLoop::m_type. You should make sure
2897  // ON_BrepLoop::m_type jibes with the loop's direction. (Outer loops
2898  // should be counter-clockwise and inner loops should be clockwise.)
2899  // You can use ON_Brep::LoopDirection() to determine the direction of
2900  // a loop.
2901  void FlipLoop(ON_BrepLoop&); // reverses orientation of trimming loop
2902 
2903  // LoopDirection() examines the 2d trimming curve geometry that defines
2904  // the loop and returns
2905  //
2906  // @untitled table
2907  // +1 the loop is a counter-clockwise loop.
2908  // -1 the loop is a clockwise loop.
2909  // 0 the loop is not a continuous closed loop.
2910  //
2911  // Since LoopDirection() calculates its result based on the 2d trimming
2912  // curve geometry, it can be use to set ON_BrepLoop::m_type to outer/inner
2913  // when translating from data definition where this distinction is murky.
2914  int LoopDirection( const ON_BrepLoop& ) const;
2915 
2916 
2917  /*
2918  Description:
2919  Sort the face.m_li[] array by loop type
2920  (outer, inner, slit, crvonsrf, ptonsrf)
2921  Parameters:
2922  face - [in/out] face whose m_li[] array should be sorted.
2923  Returns:
2924  @untitled table
2925  true success
2926  false failure - no loops or loops with unset loop.m_type
2927  See Also:
2928  ON_Brep::ComputeLoopType
2929  ON_Brep::LoopDirection
2930  */
2931  bool SortFaceLoops( ON_BrepFace& face ) const;
2932 
2933 
2934 
2935  /*
2936  Description:
2937  Expert user function.
2938  Turn an edge into a series of naked or seam edges.
2939  One for each trim at the original edge that comes from a unique face.
2940  These edges will share the 3d curve of the original edge. The original edge will
2941  still be valid and will have m_ti[0] unchanged.
2942  */
2943  bool DisconnectEdgeFaces(int eid);
2944 
2945  /*
2946  Description:
2947  Expert user function.
2948  See Also:
2949  ON_Brep::JoinEdges
2950  */
2951  bool CombineCoincidentVertices(ON_BrepVertex&, ON_BrepVertex&); // moves information to first vertex and deletes second
2952 
2953  /*
2954  Description:
2955  Expert user function.
2956  See Also:
2957  ON_Brep::JoinEdges
2958  */
2959  bool CombineCoincidentEdges(ON_BrepEdge&, ON_BrepEdge&); // moves information to first edge and deletes second
2960 
2961  /*
2962  Description:
2963  Expert user function.
2964  Combines contiguous edges into a single edge. The edges
2965  must share a common vertex, then angle between the edge
2966  tangents are the common vertex must be less than or
2967  equal to angle_tolerance_radians, and any associated
2968  trims must be contiguous in there respective boundaries.
2969  Parameters;
2970  edge_index0 - [in]
2971  edge_index1 - [in]
2972  angle_tolerance_radians - [in]
2973  Returns:
2974  Pointer to the new edge or nullptr if the edges cannot
2975  be combined into a single edge.
2976  Remarks:
2977  The input edges are deleted but are still in the
2978  brep's m_E[] arrays. Use ON_Brep::Compact to remove
2979  the unused edges.
2980  */
2981  ON_BrepEdge* CombineContiguousEdges(
2982  int edge_index0,
2983  int edge_iindex1,
2984  double angle_tolerance_radians = ON_PI/180.0
2985  );
2986 
2987 
2988  // These remove a topology piece from a b-rep but do not
2989  // rearrange the arrays that hold the brep objects. The
2990  // deleted objects have their indices set to -1. Deleting
2991  // an object that is connected to other objects will
2992  // modify thos objects.
2993  void DeleteVertex(ON_BrepVertex& vertex);
2994  void DeleteEdge(ON_BrepEdge& edge, bool bDeleteEdgeVertices); // pass true to delete vertices used only by edge
2995  void DeleteTrim(ON_BrepTrim& trim, bool bDeleteTrimEdges); // pass true to delete edges and vertices used only by trim
2996  void DeleteLoop(ON_BrepLoop& loop, bool bDeleteLoopEdges); // pass true to delete edges and vertices used only by trim
2997  void DeleteFace(ON_BrepFace& face, bool bDeleteFaceEdges); // pass true to delete edges and vertices used only by face
2998  void DeleteSurface(int s_index);
2999  void Delete2dCurve(int c2_index);
3000  void Delete3dCurve(int c3_index);
3001 
3002  // Description:
3003  // Set m_vertex_user.i, m_edge_user.i, m_face_user.i, m_loop_user.i,
3004  // and m_trim_user.i values of faces of component including
3005  // m_F[face_index] to label. Numbering starts at 1.
3006  // Parameters:
3007  // face_index - [in] index of face in component
3008  // label - [in] value for m_*_user.i
3009  // Returns:
3010  // Remarks:
3011  // Chases through trim lists of face edges to find adjacent faces.
3012  // Does NOT check for vertex-vertex connections
3013  void LabelConnectedComponent(
3014  int face_index,
3015  int label
3016  ) const;
3017 
3018  /*
3019  Description:
3020  Set m_vertex_user.i, m_edge_user.i, m_face_user.i, m_loop_user.i,
3021  and m_trim_user.i values values to distinguish connected components.
3022  Parameters:
3023  Returns:
3024  number of connected components
3025  Remarks:
3026  For each face in the ith component, sets m_face_user.i to i>0.
3027  Chases through trim lists of face edges to find adjacent faces.
3028  Numbering starts at 1. Does NOT check for vertex-vertex connections.
3029  See Also:
3030  ON_Brep::GetConnectedComponents
3031  */
3032  int LabelConnectedComponents() const;
3033 
3034  /*
3035  Description:
3036  If this brep has two or more connected components,
3037  then duplicates of the connected components are appended
3038  to the components[] array.
3039  Parameters:
3040  components - [in] connected components are appended to this array.
3041  bDuplicateMeshes - [in] if true, any meshes on this brep are copied
3042  to the output breps.
3043  Returns:
3044  Number of connected components appended to components[] or zero
3045  if this brep has only one connected component.
3046  See Also:
3047  ON_Brep::GetConnectedComponents
3048  */
3049  int GetConnectedComponents(
3050  ON_SimpleArray< ON_Brep* >& components,
3051  bool bDuplicateMeshes
3052  ) const;
3053 
3054  /*
3055  Description:
3056  Copy a subset of this brep.
3057  Parameters:
3058  subfi_count - [in] length of sub_fi[] array.
3059  sub_fi - [in] array of face indices in this
3060  brep to copy. (If any values inf sub_fi[]
3061  are out of range or if sub_fi[] contains
3062  duplicates, this function will return null.)
3063  sub_brep - [in] if this pointer is not null,
3064  then the subbrep will be created in this
3065  class.
3066  Returns:
3067  If the input is valid, a pointer to the
3068  subbrep is returned. If the input is not
3069  valid, null is returned. The faces in
3070  in the subbrep's m_F array are in the same
3071  order as they were specified in sub_fi[].
3072  */
3073  ON_Brep* SubBrep(
3074  int subfi_count,
3075  const int* sub_fi,
3076  ON_Brep* sub_brep = 0
3077  ) const;
3078 
3079  ///////////////////////////////////////////////////////////////////////
3080  //
3081  // region topology
3082  //
3083  bool HasRegionTopology() const;
3084 
3085  /*
3086  Description:
3087  Get region topology information:
3088  In order to keep the ON_Brep class efficient, rarely used
3089  region topology information is not maintained. If you
3090  require this information, call RegionTopology().
3091  */
3092  const ON_BrepRegionTopology& RegionTopology() const;
3093 
3094  /*
3095  Description:
3096  Destroy region topology information.
3097  */
3098  void DestroyRegionTopology();
3099 
3100  // Description:
3101  // Duplicate a single brep face.
3102  // Parameters:
3103  // face_index - [in] index of face to duplicate
3104  // bDuplicateMeshes - [in] if true, any attached meshes are duplicated
3105  // Returns:
3106  // Single face brep.
3107  // Remarks:
3108  // The m_vertex_user.i, m_edge_user.i, m_face_user.i, m_loop_user.i,
3109  // and m_trim_user.i values of the returned brep are are set to the
3110  // indices of the objects they duplicate.
3111  // See Also:
3112  // ON_Brep::DeleteFace, ON_Brep::ExtractFace
3113  ON_Brep* DuplicateFace(
3114  int face_index,
3115  bool bDuplicateMeshes
3116  ) const;
3117 
3118  // Description:
3119  // Duplicate a a subset of a brep
3120  // Parameters:
3121  // face_count - [in] length of face_index[] array
3122  // face_index - [in] array of face indices
3123  // bDuplicateMeshes - [in] if true, any attached meshes are duplicated
3124  // Returns:
3125  // A brep made by duplicating the faces listed in the face_index[] array.
3126  // Remarks:
3127  // The m_vertex_user.i, m_edge_user.i, m_face_user.i, m_loop_user.i,
3128  // and m_trim_user.i values of the returned brep are are set to the
3129  // indices of the objects they duplicate.
3130  // See Also:
3131  // ON_Brep::DuplicateFace
3132  ON_Brep* DuplicateFaces(
3133  int face_count,
3134  const int* face_index,
3135  bool bDuplicateMeshes
3136  ) const;
3137 
3138  // Description:
3139  // Extract a face from a brep.
3140  // Parameters:
3141  // face_index - [in] index of face to extract
3142  // Returns:
3143  // Single face brep.
3144  // See Also:
3145  // ON_Brep::DeleteFace, ON_Brep::DuplicateFace
3146  ON_Brep* ExtractFace(
3147  int face_index
3148  );
3149 
3150 
3151  /*
3152  Description:
3153  Standardizes the relationship between an ON_BrepEdge
3154  and the 3d curve it uses. When done, the edge will
3155  be the only edge that references its 3d curve, the
3156  domains of the edge and 3d curve will be the same,
3157  and the edge will use the entire locus of the 3d curve.
3158  Parameters:
3159  edge_index - [in] index of edge to standardize.
3160  bAdjustEnds - [in] if true, move edge curve endpoints to vertices
3161  See Also:
3162  ON_Brep::StandardizeEdgeCurves
3163  ON_Brep::Standardize
3164  */
3165  bool StandardizeEdgeCurve( int edge_index, bool bAdjustEnds );
3166 
3167 
3168  /*
3169  Description:
3170  Expert user only. Same as above, but to be used when the edge
3171  curve use count is known for the edge.
3172  Standardizes the relationship between an ON_BrepEdge
3173  and the 3d curve it uses. When done, the edge will
3174  be the only edge that references its 3d curve, the
3175  domains of the edge and 3d curve will be the same,
3176  and the edge will use the entire locus of the 3d curve.
3177  Parameters:
3178  edge_index - [in] index of edge to standardize.
3179  bAdjustEnds - [in] if true, move edge curve endpoints to vertices
3180  EdgeCurveUse - [in] if > 1, then the edge curve for this edge is used by more than one
3181  edge. if 1, then the edge curve is used only for this edge.
3182  If <= 0, then use count is unknown.
3183  See Also:
3184  ON_Brep::StandardizeEdgeCurves
3185  ON_Brep::Standardize
3186  */
3187  bool StandardizeEdgeCurve( int edge_index, bool bAdjustEnds, int EdgeCurveUse );
3188 
3189 
3190  /*
3191  Description:
3192  Standardize all edges in the brep.
3193  Parameters:
3194  bAdjustEnds - [in] if true, move edge curve endpoints to vertices
3195  See Also:
3196  ON_Brep::StandardizeEdgeCurve
3197  ON_Brep::Standardize
3198  */
3199  void StandardizeEdgeCurves( bool bAdjustEnds );
3200 
3201  /*
3202  Description:
3203  Standardizes the relationship between an ON_BrepTrim
3204  and the 2d curve it uses. When done, the trim will
3205  be the only trim that references its 2d curve, the
3206  domains of the trim and 2d curve will be the same,
3207  and the trim will use the entire locus of the 2d curve.
3208  Parameters:
3209  trim_index - [in] index of trim to standardize.
3210  See Also:
3211  ON_Brep::StandardizeTrimCurves
3212  ON_Brep::Standardize
3213  */
3214  bool StandardizeTrimCurve( int trim_index );
3215 
3216  /*
3217  Description:
3218  Standardize all trims in the brep.
3219  See Also:
3220  ON_Brep::StandardizeTrimCurve
3221  ON_Brep::Standardize
3222  */
3223  void StandardizeTrimCurves();
3224 
3225  /*
3226  Description:
3227  Standardizes the relationship between an ON_BrepFace
3228  and the 3d surface it uses. When done, the face will
3229  be the only face that references its 3d surface, and
3230  the orientations of the face and 3d surface will be
3231  the same.
3232  Parameters:
3233  face_index - [in] index of face to standardize.
3234  See Also:
3235  ON_Brep::StardardizeFaceSurfaces
3236  ON_Brep::Standardize
3237  */
3238  bool StandardizeFaceSurface( int face_index );
3239 
3240  /*
3241  Description:
3242  Standardize all faces in the brep.
3243  See Also:
3244  ON_Brep::StandardizeFaceSurface
3245  ON_Brep::Standardize
3246  */
3247  void StandardizeFaceSurfaces();
3248 
3249  /*
3250  Description:
3251  Standardize all trims, edges, and faces in the brep.
3252  Remarks:
3253  After standardizing, there may be unused curves and surfaces
3254  in the brep. Call ON_Brep::Compact to remove these unused
3255  curves and surfaces.
3256  See Also:
3257  ON_Brep::StandardizeTrimCurves
3258  ON_Brep::StandardizeEdgeCurves
3259  ON_Brep::StandardizeFaceSurface
3260  ON_Brep::Compact
3261  */
3262  void Standardize();
3263 
3264 
3265  /*
3266  Description:
3267  Sometimes the ON_Surface used by a face extends far
3268  beyond the face's outer boundary. ShrinkSurface uses
3269  ON_Surface::Trim to remove portions of the surface that
3270  extend beyond the face's outer boundary loop.
3271  Parameters:
3272  face - [in] face to test and whose surface should be shrunk.
3273  DisableSide - [in] This is a bit field. A set bit indicates not to shrink
3274  the surface on a given side. The default of 0 enables shrinking
3275  on all four sides.
3276  @table
3277  value meaning
3278  0x0001 Dont shrink on the west side of domain.
3279  0x0002 Dont shrink on the south side of domain.
3280  0x0004 Dont shrink on the east side of domain.
3281  0x0008 Dont shrink on the north side of domain.
3282  Returns:
3283  @untitled table
3284  true successful
3285  false failure
3286  Remarks:
3287  If a surface needs to be shrunk it is copied. After shrinking,
3288  you may want to call ON_Brep::CullUnusedSurfaces to remove
3289  any unused surfaces.
3290  See Also:
3291  ON_Brep::ShrinkSurfaces
3292  ON_Brep::CullUnusedSurfaces
3293  */
3294  bool ShrinkSurface( ON_BrepFace& face, int DisableSide=0 );
3295 
3296  /*
3297  Description:
3298  Sometimes the ON_Surface used by a face extends far
3299  beyond the face's outer boundary. ShrinkSurfaces calls
3300  ON_Shrink::ShrinkSurface on each face to remove portions
3301  of surfaces that extend beyond their face's outer boundary
3302  loop.
3303  Returns:
3304  @untitled table
3305  true successful
3306  false failure
3307  Remarks:
3308  If a surface needs to be shrunk it is copied. After shrinking,
3309  you may want to call ON_Brep::CullUnusedSurfaces to remove
3310  any unused surfaces.
3311  See Also:
3312  ON_Brep::ShrinkSurface
3313  ON_Brep::CullUnusedSurfaces
3314  */
3315  bool ShrinkSurfaces();
3316 
3317  /*
3318  Description:
3319  Uses the CullUnused*() members to delete any unreferenced
3320  objects from arrays, reindexes as needed, and shrinks
3321  arrays to minimum required size.
3322  See Also:
3323  ON_Brep::CullUnusedFaces
3324  ON_Brep::CullUnusedLoops
3325  ON_Brep::CullUnusedTrims
3326  ON_Brep::CullUnusedEdges
3327  ON_Brep::CullUnusedVertices
3328  ON_Brep::CullUnused3dCurves
3329  ON_Brep::CullUnused2dCurves
3330  ON_Brep::CullUnusedSurfaces
3331  */
3332  bool Compact();
3333 
3334  bool CullUnusedFaces(); // culls faces with m_face_index == -1
3335  bool CullUnusedLoops(); // culls loops with m_loop_index == -1
3336  bool CullUnusedTrims(); // culls trims with m_trim_index == -1
3337  bool CullUnusedEdges(); // culls edges with m_edge_index == -1
3338  bool CullUnusedVertices(); // culls vertices with m_vertex_index == -1
3339  bool CullUnused3dCurves(); // culls 2d curves not referenced by a trim
3340  bool CullUnused2dCurves(); // culls 3d curves not referenced by an edge
3341  bool CullUnusedSurfaces(); // culls surfaces not referenced by a face
3342 
3343  /////////////////////////////////////////////////////////////////
3344  // Navigation Interface
3345 
3346  // for moving around loops - returns trim index of prev/next trim in loop
3347  int PrevTrim(
3348  int // index of current trim (m_trim_index)
3349  ) const;
3350  int NextTrim(
3351  int // index of current trim (m_trim_index)
3352  ) const;
3353 
3354  //Same as NextTrim and PrevTrim, but skips over trims with type singular
3355  int PrevNonsingularTrim(
3356  int // index of current trim (m_trim_index)
3357  ) const;
3358  int NextNonsingularTrim(
3359  int // index of current trim (m_trim_index)
3360  ) const;
3361 
3362  /*
3363  Description:
3364  This is a simple tool for getting running through the edges
3365  that begin and end at a vertex.
3366  Parameters:
3367  current_edge_index - [in]
3368  endi - [in] 0 = use the edge start vertex, 1 = use the edge end vertex
3369  prev_endi - [out] 0 if previous edge begins at the vertex,
3370  1 if previous edge ends at the vertex
3371  Returns:
3372  edge index of the previous edge or -1 if there is only one edge
3373  that begins or ends at the vertex.
3374  Remarks:
3375  This is a tool that simplifies searching through the
3376  ON_BrepVertex.m_ei[] array.
3377  The edges are in no particular order.
3378  See Also:
3379  ON_Brep::NextEdge
3380  */
3381  int PrevEdge(
3382  int current_edge_index,
3383  int endi,
3384  int* prev_endi = nullptr
3385  ) const;
3386 
3387  /*
3388  Description:
3389  This is a simple tool for getting running through the edges
3390  that begin and end at a vertex.
3391  Parameters:
3392  current_edge_index - [in]
3393  endi - [in] 0 = use the edge start vertex, 1 = use the edge end vertex
3394  next_endi - [out] 0 if next edge begins at the vertex,
3395  1 if next edge ends at the vertex
3396  Returns:
3397  edge index of the next edge or -1 if there is only one edge
3398  that begins or ends at the vertex.
3399  Remarks:
3400  This is a tool that simplifies searching through the
3401  ON_BrepVertex.m_ei[] array.
3402  The edges are in no particular order.
3403  See Also:
3404  ON_Brep::NextEdge
3405  */
3406  int NextEdge(
3407  int current_edge_index,
3408  int endi,
3409  int* next_endi = nullptr
3410  ) const;
3411 
3412  /*
3413  Description:
3414  Get a brep component from its index.
3415  Parameters:
3416  component_index - [in]
3417  Returns:
3418  A const pointer to the component. Do not delete
3419  the returned object. It points to an object managed
3420  by this brep.
3421  See Also:
3422  ON_Brep::Face
3423  ON_Brep::Edge
3424  ON_Brep::Loop
3425  ON_Brep::Trim
3426  ON_Brep::Vertex
3427  */
3428  const ON_Geometry* BrepComponent(
3429  ON_COMPONENT_INDEX ci
3430  ) const;
3431 
3432  /*
3433  Description:
3434  Get vertex from trim index or component index.
3435  Parameters:
3436  vertex_index - [in] either an index into m_V[] or a component index
3437  of type brep_vertex.
3438  Returns:
3439  If the index is a valid vertex index or a valid vertex component
3440  index, then a pointer to the ON_BrepVertex is returned. Otherwise
3441  nullptr is returned.
3442  See Also
3443  ON_Brep::Component( const ON_BrepVertex& )
3444  */
3445  ON_BrepVertex* Vertex( int vertex_index ) const;
3446  ON_BrepVertex* Vertex( ON_COMPONENT_INDEX vertex_index ) const;
3447 
3448  /*
3449  Description:
3450  Get edge from edge index or component index.
3451  Parameters:
3452  edge_index - [in] either an index into m_E[] or a component index
3453  of type brep_edge.
3454  Returns:
3455  If the index is a valid edge index or a valid edge component
3456  index, then a pointer to the ON_BrepEdge is returned. Otherwise
3457  nullptr is returned.
3458  See Also
3459  ON_Brep::Component( const ON_BrepEdge& )
3460  */
3461  ON_BrepEdge* Edge( int edge_index ) const;
3462  ON_BrepEdge* Edge( ON_COMPONENT_INDEX edge_index ) const;
3463 
3464  /*
3465  Description:
3466  Get trim from trim index or component index.
3467  Parameters:
3468  trim_index - [in] either an index into m_T[] or a component index
3469  of type brep_trim.
3470  Returns:
3471  If the index is a valid trim index or a valid trim component
3472  index, then a pointer to the ON_BrepTrim is returned. Otherwise
3473  nullptr is returned.
3474  See Also
3475  ON_Brep::Component( const ON_BrepTrim& )
3476  */
3477  ON_BrepTrim* Trim( int trim_index ) const;
3478  ON_BrepTrim* Trim( ON_COMPONENT_INDEX trim_index ) const;
3479 
3480  /*
3481  Description:
3482  Get loop from loop index or component index.
3483  Parameters:
3484  loop_index - [in] either an index into m_L[] or a component index
3485  of type brep_loop.
3486  Returns:
3487  If the index is a valid loop index or a valid loop component
3488  index, then a pointer to the ON_BrepLoop is returned. Otherwise
3489  nullptr is returned.
3490  See Also
3491  ON_Brep::Component( const ON_BrepLoop& )
3492  */
3493  ON_BrepLoop* Loop( int loop_index ) const;
3494  ON_BrepLoop* Loop( ON_COMPONENT_INDEX loop_index ) const;
3495 
3496  /*
3497  Description:
3498  Get face from face index or component index.
3499  Parameters:
3500  face_index - [in] either an index into m_F[] or a component index
3501  of type brep_face.
3502  Returns:
3503  If the index is a valid face index or a valid face component
3504  index, then a pointer to the ON_BrepFace is returned. Otherwise
3505  nullptr is returned.
3506  See Also
3507  ON_Brep::Component( const ON_BrepFace& )
3508  */
3509  ON_BrepFace* Face( int face_index ) const;
3510  ON_BrepFace* Face( ON_COMPONENT_INDEX face_index ) const;
3511 
3512  //Match endpoints of adjacent trims. If a trim needs to be adjusted, copy the 2d curve if necessary,
3513  //convert to nurb form, yank cvs. Compact() should be called afterwards. Returns false if error in
3514  //computation, Trims must be from same face and meet at a common vertex.
3515  //These are expert user functions. When in doubt use MatchTrimEnds() on the entire Brep.
3516 
3517  /*
3518  Description:
3519  Match the end of a trim to the start of the next trim.
3520  Parameters:
3521  T0 - [in] brep trim
3522  T1 - [in] brep trim that comes immediately after T0 in the same loop
3523  Returns:
3524  true if either trim's 2d curve is changed
3525  */
3526  bool MatchTrimEnds(ON_BrepTrim& T0,
3527  ON_BrepTrim& T1
3528  );
3529 
3530  /*
3531  Description:
3532  Match the endpoints of a trim to the next and previous trim
3533  Parameters:
3534  trim_index - [in] index into m_T
3535  Returns:
3536  true if any trim's 2d curve is changed
3537  */
3538  bool MatchTrimEnds(int trim_index);
3539 
3540  /*
3541  Description:
3542  Match the endpoints of all trims in a loop
3543  Parameters:
3544  Loop - [in] brep loop
3545  Returns:
3546  true if any trim's 2d curve is changed
3547  */
3548  bool MatchTrimEnds(ON_BrepLoop& Loop);
3549 
3550  /*
3551  Description:
3552  Match the endpoints of all trims in a brep
3553  Parameters:
3554  Returns:
3555  true if any trim's 2d curve is changed
3556  */
3557  bool MatchTrimEnds();
3558 
3559  /*
3560  Description:
3561  Convert the 2d curve of a trim to an ON_NurbsCurve
3562  Parameters:
3563  T - [in] brep trim
3564  Returns:
3565  Pointer to m_C2[T.m_c2i]
3566  NOTE: After calling this, m_C2[T.m_c2i] will be a nurbs curve only referenced by
3567  T, with domain = T.m_t. Caller should not delete the returned curve since its memory is owned
3568  by the brep (this).
3569  */
3570  ON_NurbsCurve* MakeTrimCurveNurb(ON_BrepTrim& T);
3571 
3572  /*
3573  Description:
3574  Check for slit trims and slit boundaries in each face.
3575  Returns:
3576  true if any slits were found
3577  */
3578  bool HasSlits() const;
3579 
3580  /*
3581  Description:
3582  Check for slit trims and slit boundaries in a face.
3583  Returns:
3584  true if any slits were found
3585  */
3586  bool HasSlits(const ON_BrepFace& F) const;
3587 
3588  /*
3589  Description:
3590  Check for slit trims in a loop.
3591  Returns:
3592  true if any slits were found
3593  */
3594  bool HasSlits(const ON_BrepLoop& L) const;
3595 
3596  /*
3597  Description:
3598  remove slit trims and slit boundaries from each face.
3599  Returns:
3600  true if any slits were removed
3601  Remarks:
3602  Caller should call Compact() afterwards.
3603  */
3604  bool RemoveSlits();
3605 
3606  /*
3607  Description:
3608  remove slit trims and slit boundaries from a face.
3609  Parameters:
3610  F - [in] brep face
3611  Returns:
3612  true if any slits were removed
3613  Remarks:
3614  Caller should call Compact() when done.
3615  */
3616  bool RemoveSlits(ON_BrepFace& F);
3617 
3618  /*
3619  Description:
3620  remove slit trims from a loop.
3621  Parameters:
3622  L - [in] brep loop
3623  Returns:
3624  true if any slits were removed
3625  Remarks:
3626  Caller should call Compact() when done.
3627  If all trims are removed, the loop will be marked as deleted.
3628  */
3629  bool RemoveSlits(ON_BrepLoop& L);
3630 
3631  /*
3632  Description:
3633  If fid0 != fid1 and m_F[fid0] and m_F[fid1] have the same surface (m_si is identical),
3634  and they are joined along a set of edges that do not have any other faces, then this will
3635  combine the two faces into one.
3636  Parameters:
3637  fid0, fid1 - [in] indices into m_F of faces to be merged.
3638  Returns:
3639  id of merged face if faces were successfully merged. -1 if not merged.
3640  Remarks:
3641  Caller should call Compact() when done.
3642  */
3643  int MergeFaces(int fid0, int fid1);
3644 
3645  /*
3646  Description:
3647  Merge all possible faces that have the same m_si
3648  Returns:
3649  true if any faces were successfully merged.
3650  Remarks:
3651  Caller should call Compact() when done.
3652  */
3653  bool MergeFaces();
3654 
3655  /*
3656  Description:
3657  Removes nested polycurves from the m_C2[] and m_C3[] arrays.
3658  Parameters:
3659  bExtractSingleSegments - [in] if true, polycurves with a
3660  single segment are replaced with the segment curve.
3661  bEdges - [in] if true, the m_C3[] array is processed
3662  bTrimCurves - [in] if true, the m_C2[] array is processed.
3663  Returns:
3664  True if any nesting was removed and false if no nesting
3665  was removed.
3666  */
3667  bool RemoveNesting(
3668  bool bExtractSingleSegments,
3669  bool bEdges = true,
3670  bool bTrimCurves = true
3671  );
3672 
3673  /*
3674  Description:
3675  Expert user tool to collapse a "short" edge to a vertex.
3676  The edge is removed and the topology is repaired
3677  so that everything that used to connect to the edge
3678  connects the specified vertex.
3679  Parameters:
3680  edge_index - [in] index of edge to remove
3681  bCloseTrimGap - [in] if true and the removal of the
3682  edge creates a gap in the parameter space trimming
3683  loop, then the 2d trim curves will be adjusted to
3684  close the gap.
3685  vertex_index - [in] if >= 0, this the edge is collapsed
3686  to this vertex. Otherwise a vertex is automatically
3687  selected or created.
3688  Returns:
3689  True if edge was successfully collapsed.
3690  Remarks:
3691  After you finish cleaning up the brep, you need
3692  to call ON_Brep::Compact() to remove unused edge,
3693  trim, and vertex information from the brep's m_E[],
3694  m_V[], m_T[], m_C2[], and m_C3[] arrays.
3695  */
3696  bool CollapseEdge(
3697  int edge_index,
3698  bool bCloseTrimGap = true,
3699  int vertex_index = -1
3700  );
3701 
3702  /*
3703  Description:
3704  Expert user tool to move trims and edges from
3705  one vertex to another.
3706  Parameters:
3707  old_vi - [in] index of old vertex
3708  new_vi - [in] index of new vertex
3709  bClearTolerances - [in] if true, then tolerances of
3710  edges and trims that are connected ot the old
3711  vertex are set to ON_UNSET_VALUE.
3712  vertex_index - [in] if >= 0, this the edge is collapsed
3713  to this vertex. Otherwise a vertex is automatically
3714  selected or created.
3715  Returns:
3716  True if successful.
3717  Remarks:
3718  After you finish cleaning up the brep, you need
3719  to call ON_Brep::Compact() to remove unused edge,
3720  trim, and vertex information from the brep's m_E[],
3721  m_V[], m_T[], m_C2[], and m_C3[] arrays.
3722  */
3723  bool ChangeVertex(
3724  int old_vi,
3725  int new_vi,
3726  bool bClearTolerances
3727  );
3728 
3729  /*
3730  Description:
3731  Expert user tool to remove any gap between adjacent trims.
3732  Parameters:
3733  trim0 - [in]
3734  trim1 - [in]
3735  Returns:
3736  True if successful.
3737  Remarks:
3738  The trims must be in the same trimming loop. The vertex
3739  at the end of trim0 must be the same as the vertex at
3740  the start of trim1. The trim's m_iso and m_type flags
3741  need to be correctly set.
3742  */
3743  bool CloseTrimGap(
3744  ON_BrepTrim& trim0,
3745  ON_BrepTrim& trim1
3746  );
3747 
3748  /*
3749  Description:
3750  Remove edges that are not connected to a face.
3751  Parameters:
3752  bDeleteVertices - [in] if true, then the vertices
3753  at the ends of the wire edges are deleted if
3754  they are not connected to face trimming edges.
3755  Returns:
3756  Number of edges that were removed.
3757  Remarks:
3758  After you finish cleaning up the brep, you need
3759  to call ON_Brep::Compact() to remove unused edge,
3760  trim, and vertex information from the brep's m_E[],
3761  m_V[], m_T[], m_C2[], and m_C3[] arrays.
3762 
3763  If you want to remove wire edges and wiere
3764  After you finish cleaning up the brep, you need
3765  to call ON_Brep::Compact() to remove deleted vertices
3766  from the m_V[] array.
3767  See Also:
3768  ON_Brep::RemoveWireVertices
3769  */
3770  int RemoveWireEdges( bool bDeleteVertices = true );
3771 
3772  /*
3773  Description:
3774  Remove vertices that are not connected to an edge.
3775  Returns:
3776  Number of vertices that were deleted.
3777  Remarks:
3778  After you finish cleaning up the brep, you need
3779  to call ON_Brep::Compact() to remove deleted
3780  vertices from the m_V[] array.
3781  See Also:
3782  ON_Brep::RemoveWireEdges
3783  */
3784  int RemoveWireVertices();
3785 
3786  /////////////////////////////////////////////////////////////////
3787  // "Expert" Interface
3788 
3789  void Set_user(ON_U u) const; // set every brep m_*_user value to u
3790  void Clear_vertex_user_i() const; // zero all brep's m_vertex_user values
3791  void Clear_edge_user_i(int) const; // zero all brep's m_edge_user values
3792  void Clear_edge_user_i() const; // zero all brep's m_edge_user values
3793  void Clear_trim_user_i() const; // zero all brep's m_trim_user values
3794  void Clear_loop_user_i() const; // zero all brep's m_loop_user values
3795  void Clear_face_user_i() const; // zero all brep's m_face_user values
3796  void Clear_user_i() const; // zero all brep's m_*_user values
3797 
3798  // Union available for application use.
3799  // The constructor zeros m_brep_user.
3800  // The value is of m_brep_user is not saved in 3DM
3801  // archives and may be changed by some computations.
3802  mutable ON_U m_brep_user;
3803 
3804  // geometry
3805  // (all geometry is deleted by ~ON_Brep(). Pointers can be nullptr
3806  // or not referenced. Use Compact() to remove unreferenced geometry.
3807  ON_CurveArray m_C2; // Pointers to parameter space trimming curves
3808  // (used by trims).
3809  ON_CurveArray m_C3; // Pointers to 3d curves (used by edges).
3810  ON_SurfaceArray m_S; // Pointers to parametric surfaces (used by faces)
3811 
3812  // topology
3813  // (all topology is deleted by ~ON_Brep(). Objects can be unreferenced.
3814  // Use Compact() to to remove unreferenced geometry.
3815  ON_BrepVertexArray m_V; // vertices
3816  ON_BrepEdgeArray m_E; // edges
3817  ON_BrepTrimArray m_T; // trims
3818  ON_BrepLoopArray m_L; // loops
3819  ON_BrepFaceArray m_F; // faces
3820 
3821 protected:
3822  friend class ON_BrepFace;
3823  friend class ON_BrepRegion;
3824  friend class ON_BrepFaceSide;
3825  friend class ON_V5_BrepRegionTopologyUserData;
3826  ON_BoundingBox m_bbox;
3827  mutable class ON_BrepRegionTopology* m_region_topology = nullptr;
3828  static class ON_BrepRegionTopology* Internal_RegionTopologyPointer(
3829  const ON_Brep* brep,
3830  bool bValidateFaceCount
3831  );
3832  void Internal_AttachV5RegionTopologyAsUserData(
3833  ON_BinaryArchive& archive
3834  ) const;
3835 
3836  mutable ON_AggregateComponentStatus m_aggregate_status;
3837 
3838  // Never directly set m_is_solid, use calls to IsSolid() and/or
3839  // SolidOrientation() when you need to know the answer to this
3840  // question.
3841  // 0 = unset
3842  // 1 = solid with normals pointing out
3843  // 2 = solid with normals pointing in
3844  // 3 = not solid
3845  int m_is_solid = 0;
3846 
3847  // These are friends so legacy tol values stored in v1 3dm files
3848  // can be used to set brep edge and trimming tolerances with a call
3849  // to ON_Brep::SetTolsFromLegacyValues().
3850  friend bool ON_BinaryArchive::ReadV1_TCODE_LEGACY_FAC(ON_Object**,ON_3dmObjectAttributes*);
3851  friend bool ON_BinaryArchive::ReadV1_TCODE_LEGACY_SHL(ON_Object**,ON_3dmObjectAttributes*);
3852  void Initialize();
3853 
3854  // helpers to set ON_BrepTrim::m_iso flag
3855  void SetTrimIsoFlag(int,double[6]);
3856  void SetTrimIsoFlag(int);
3857 
3858  // helpers to create and set vertices
3859  bool SetEdgeVertex(const int, const int, const int );
3860  bool HopAcrossEdge( int&, int& ) const;
3861  bool SetTrimStartVertex( const int, const int);
3862  void SetLoopVertices(const int);
3863  void ClearTrimVertices();
3864  void ClearEdgeVertices();
3865 
3866  // helpers for SwapFaceParameters()
3867  bool SwapLoopParameters(
3868  int // index of loop
3869  );
3870  bool SwapTrimParameters(
3871  int // index of trim
3872  );
3873 
3874  // helpers for validation checking
3875  bool IsValidTrim(int trim_index,ON_TextLog* text_log) const;
3876  bool IsValidTrimTopology(int trim_index,ON_TextLog* text_log) const;
3877  bool IsValidTrimGeometry(int trim_index,ON_TextLog* text_log) const;
3878  bool IsValidTrimTolerancesAndFlags(int trim_index,ON_TextLog* text_log) const;
3879 
3880  bool IsValidLoop(int loop_index,ON_TextLog* text_log) const;
3881  bool IsValidLoopTopology(int loop_index,ON_TextLog* text_log) const;
3882  bool IsValidLoopGeometry(int loop_index,ON_TextLog* text_log) const;
3883  bool IsValidLoopTolerancesAndFlags(int loop_index,ON_TextLog* text_log) const;
3884 
3885  bool IsValidFace(int face_index,ON_TextLog* text_log) const;
3886  bool IsValidFaceTopology(int face_index,ON_TextLog* text_log) const;
3887  bool IsValidFaceGeometry(int face_index,ON_TextLog* text_log) const;
3888  bool IsValidFaceTolerancesAndFlags(int face_index,ON_TextLog* text_log) const;
3889 
3890  bool IsValidEdge(int edge_index,ON_TextLog* text_log) const;
3891  bool IsValidEdgeTopology(int edge_index,ON_TextLog* text_log) const;
3892  bool IsValidEdgeGeometry(int edge_index,ON_TextLog* text_log) const;
3893  bool IsValidEdgeTolerancesAndFlags(int edge_index,ON_TextLog* text_log) const;
3894 
3895  bool IsValidVertex(int vertex_index,ON_TextLog* text_log) const;
3896  bool IsValidVertexTopology(int vertex_index,ON_TextLog* text_log) const;
3897  bool IsValidVertexGeometry(int vertex_index,ON_TextLog* text_log) const;
3898  bool IsValidVertexTolerancesAndFlags(int vertex_index,ON_TextLog* text_log) const;
3899 
3900  void SetTolsFromLegacyValues();
3901 
3902  // read helpers to support various versions
3903  bool ReadOld100( ON_BinaryArchive& ); // reads legacy old RhinoIO toolkit b-rep
3904  bool ReadOld101( ON_BinaryArchive& ); // reads legacy Rhino 1.1 b-rep
3905  bool ReadOld200( ON_BinaryArchive&, int ); // reads legacy trimmed surface
3906  ON_Curve* Read100_BrepCurve( ON_BinaryArchive& ) const;
3907  ON_Surface* Read100_BrepSurface( ON_BinaryArchive& ) const;
3908 
3909  // helpers for reading legacy v1 trimmed surfaces and breps
3910  bool ReadV1_LegacyTrimStuff( ON_BinaryArchive&, ON_BrepFace&, ON_BrepLoop& );
3911  bool ReadV1_LegacyTrim( ON_BinaryArchive&, ON_BrepFace&, ON_BrepLoop& );
3912  bool ReadV1_LegacyLoopStuff( ON_BinaryArchive&, ON_BrepFace& );
3913  bool ReadV1_LegacyLoop( ON_BinaryArchive&, ON_BrepFace& );
3914  bool ReadV1_LegacyFaceStuff( ON_BinaryArchive& );
3915  bool ReadV1_LegacyShellStuff( ON_BinaryArchive& );
3916 };
3917 
3918 ///////////////////////////////////////////////////////////////////////////////
3919 //
3920 // brep construction tools
3921 //
3922 
3923 /*
3924 Description:
3925  Create a brep representation of a mesh.
3926 Parameters:
3927  mesh_topology - [in]
3928  bTrimmedTriangles - [in] if true, triangles in the mesh
3929  will be represented by trimmed planes in the brep.
3930  If false, triangles in the mesh will be represented by
3931  untrimmed singular bilinear NURBS surfaces in the brep.
3932  pBrep - [in] If not nullptr, this the mesh representation will
3933  be put into this brep.
3934 Example:
3935 
3936  ON_Mesh mesh = ...;
3937  ON_Brep* pBrep = ON_BrepFromMesh( mesh.Topology() );
3938  ...
3939  delete pBrep;
3940 
3941 See Also
3942  ON_BrepFromMesh( const ON_Mesh& mesh, ... );
3943 */
3944 ON_DECL
3945 ON_Brep* ON_BrepFromMesh(
3946  const ON_MeshTopology& mesh_topology,
3947  bool bTrimmedTriangles = true,
3948  ON_Brep* pBrep = nullptr
3949  );
3950 
3951 /*
3952 Description:
3953  Get an ON_Brep definition of a box.
3954 Parameters:
3955  box_corners - [in] 8 points defining the box corners
3956  arranged as the vN lables indicate.
3957 
3958  v7_______e6_____v6
3959  |\ |\
3960  | e7 | e5
3961  | \ ______e4_____\
3962  e11 v4 | v5
3963  | | e10 |
3964  | | | |
3965  v3---|---e2----v2 e9
3966  \ e8 \ |
3967  e3 | e1 |
3968  \ | \ |
3969  \v0_____e0_____\v1
3970 
3971  pBrep - [in] if not nullptr, this brep will be used and
3972  returned.
3973 Returns:
3974  An ON_Brep representation of the box with topology
3975 
3976  edge vertices
3977  m_E[ 0] m_V[0], m_V[1]
3978  m_E[ 1] m_V[1], m_V[2]
3979  m_E[ 2] m_V[2], m_V[3]
3980  m_E[ 3] m_V[3], m_V[0]
3981  m_E[ 4] m_V[4], m_V[5]
3982  m_E[ 5] m_V[5], m_V[6]
3983  m_E[ 6] m_V[6], m_V[7]
3984  m_E[ 7] m_V[7], m_V[4]
3985  m_E[ 8] m_V[0], m_V[4]
3986  m_E[ 9] m_V[1], m_V[5]
3987  m_E[10] m_V[2], m_V[6]
3988  m_E[11] m_V[3], m_V[7]
3989 
3990  face boundary edges
3991  m_F[0] +m_E[0] +m_E[9] -m_E[4] -m_E[8]
3992  m_F[1] +m_E[1] +m_E[10] -m_E[5] -m_E[9]
3993  m_F[2] +m_E[2] +m_E[11] -m_E[6] -m_E[10]
3994  m_F[3] +m_E[3] +m_E[8] -m_E[7] -m_E[11]
3995  m_F[4] -m_E[3] -m_E[2] -m_E[1] -m_E[0]
3996 // m_F[5] +m_E[4] +m_E[5] +m_E[6] +m_E[7]
3997 */
3998 ON_DECL
3999 ON_Brep* ON_BrepBox( const ON_3dPoint* box_corners, ON_Brep* pBrep = nullptr );
4000 
4001 /*
4002 Description:
4003  Get an ON_Brep definition of a wedge.
4004 Parameters:
4005  corners - [in] 6 points defining the box corners
4006  arranged as the vN lables indicate.
4007 
4008  /v5
4009  /|\
4010  / | \
4011  e5 | e4
4012  / e8 \
4013  /__e3_____\
4014  v3| | |v4
4015  | | |
4016  | /v2 |
4017  e6 / \ e7
4018  | / \ |
4019  | e2 e1|
4020  |/ \|
4021  /____e0___\
4022  v0 v1
4023 
4024  pBrep - [in] if not nullptr, this brep will be used and
4025  returned.
4026 Returns:
4027  An ON_Brep representation of the wedge with topology
4028 
4029  edge vertices
4030  m_E[ 0] m_V[0], m_V[1]
4031  m_E[ 1] m_V[1], m_V[2]
4032  m_E[ 2] m_V[2], m_V[0]
4033  m_E[ 3] m_V[3], m_V[4]
4034  m_E[ 4] m_V[4], m_V[5]
4035  m_E[ 5] m_V[5], m_V[0]
4036  m_E[ 6] m_V[0], m_V[3]
4037  m_E[ 7] m_V[1], m_V[4]
4038  m_E[ 8] m_V[2], m_V[5]
4039 
4040  face boundary edges
4041  m_F[0] +m_E[0] +m_E[7] -m_E[3] -m_E[6]
4042  m_F[1] +m_E[1] +m_E[8] -m_E[4] -m_E[7]
4043  m_F[2] +m_E[2] +m_E[6] -m_E[5] -m_E[8]
4044  m_F[3] +m_E[3] +m_E[8] -m_E[7] -m_E[11]
4045  m_F[4] -m_E[2] -m_E[1] -m_E[0]
4046  m_F[5] +m_E[3] +m_E[4] +m_E[5]
4047 */
4048 ON_DECL
4049 ON_Brep* ON_BrepWedge( const ON_3dPoint* corners, ON_Brep* pBrep = nullptr );
4050 
4051 /*
4052 Description:
4053  Get an ON_Brep definition of a sphere.
4054 Parameters:
4055  sphere - [in]
4056  pBrep - [in] if not nullptr, this brep will be used and
4057  returned.
4058 Returns:
4059  An ON_Brep representation of the sphere with a single face,
4060  a single edge along the seam, and vertices at the north
4061  and south poles.
4062 */
4063 ON_DECL
4064 ON_Brep* ON_BrepSphere( const ON_Sphere& sphere, ON_Brep* pBrep = nullptr );
4065 
4066 /*
4067 Description:
4068  Get an ON_Brep definition of a sphere.
4069 Parameters:
4070  Center - [in] Center of sphere
4071  radius - [int] Radius of shphere
4072  pBrep - [in] if not nullptr, this brep will be used and
4073  returned.
4074 Returns:
4075  An ON_Brep representation of the sphere with six similar faces,
4076  each an untrimmed rational quadratic surface
4077 */
4078 ON_DECL
4079 ON_Brep* ON_BrepQuadSphere( const ON_3dPoint& Center, double radius, ON_Brep* pBrep = nullptr );
4080 
4081 /*
4082 Description:
4083  Get an ON_Brep definition of a torus.
4084 Parameters:
4085  torus - [in]
4086  pBrep - [in] if not nullptr, this brep will be used and
4087  returned.
4088 Returns:
4089  An ON_Brep representation of the torus with a single face
4090  a two edges along the seams.
4091 */
4092 ON_DECL
4093 ON_Brep* ON_BrepTorus( const ON_Torus& torus, ON_Brep* pBrep = nullptr );
4094 
4095 /*
4096 Description:
4097  Get an ON_Brep definition of a cylinder.
4098 Parameters:
4099  cylinder - [in] cylinder.IsFinite() must be true
4100  bCapBottom - [in] if true end at cylinder.m_height[0] should be capped
4101  bCapTop - [in] if true end at cylinder.m_height[1] should be capped
4102  pBrep - [in] if not nullptr, this brep will be used and
4103  returned.
4104 Returns:
4105  An ON_Brep representation of the cylinder with a single
4106  face for the cylinder, an edge along the cylinder seam,
4107  and vertices at the bottom and top ends of this seam edge.
4108  The optional bottom/top caps are single faces with one
4109  circular edge starting and ending at the bottom/top vertex.
4110 */
4111 ON_DECL
4112 ON_Brep* ON_BrepCylinder( const ON_Cylinder& cylinder,
4113  bool bCapBottom,
4114  bool bCapTop,
4115  ON_Brep* pBrep = nullptr );
4116 
4117 /*
4118 Description:
4119  Get an ON_Brep definition of a cone.
4120 Parameters:
4121  cylinder - [in] cylinder.IsFinite() must be true
4122  bCapBase - [in] if true the base of the cone should be capped.
4123  pBrep - [in] if not nullptr, this brep will be used and
4124  returned.
4125 Returns:
4126  An ON_Brep representation of the cone with a single
4127  face for the cone, an edge along the cone seam,
4128  and vertices at the base and apex ends of this seam edge.
4129  The optional cap is asingle face with one circular edge
4130  starting and ending at the base vertex.
4131 */
4132 ON_DECL
4133 ON_Brep* ON_BrepCone(
4134  const ON_Cone& cone,
4135  bool bCapBottom,
4136  ON_Brep* pBrep = nullptr
4137  );
4138 
4139 /*
4140 Description:
4141  Get an ON_Brep form of a surface of revolution.
4142 Parameters:
4143  pRevSurface - [in] pointer to a surface of revolution.
4144  The brep will manage this pointer and delete it in ~ON_Brep.
4145  bCapStart - [in] if true, the start of the revolute is
4146  not on the axis of revolution, and the surface of revolution
4147  is closed, then a circular cap will be added to close
4148  of the hole at the start of the revolute.
4149  bCapEnd - [in] if true, the end of the revolute is
4150  not on the axis of revolution, and the surface of revolution
4151  is closed, then a circular cap will be added to close
4152  of the hole at the end of the revolute.
4153  pBrep - [in] if not nullptr, this brep will be used and
4154  returned.
4155 Returns:
4156  @untitled table
4157  true successful
4158  false brep cannot be created from this surface.
4159 Remarks:
4160  The surface class must be created with new because
4161  it will be destroyed with the delete operator
4162  in ~ON_Brep.
4163 */
4164 ON_DECL
4165 ON_Brep* ON_BrepRevSurface(
4166  ON_RevSurface*& pRevSurface,
4167  bool bCapStart,
4168  bool bCapEnd,
4169  ON_Brep* pBrep = nullptr
4170  );
4171 
4172 
4173 
4174 /*
4175 Description:
4176  Create an ON_Brep trimmed plane.
4177 Parameters:
4178  plane - [in] plane that will be trimmed.
4179  boundary - [in] a simple (no self intersections) closed
4180  curve that defines the outer boundary of the trimmed
4181  plane. This curve is copied for use in the brep.
4182  pBrep - [in] if not nullptr, this brep will be used and returned.
4183 Returns:
4184  An ON_Brep representation of the trimmed plane with a single face.
4185 See Also:
4186  ON_Brep::NewPlanarFaceLoop()
4187 */
4188 ON_DECL
4189 ON_Brep* ON_BrepTrimmedPlane(
4190  const ON_Plane& plane,
4191  const ON_Curve& boundary,
4192  ON_Brep* pBrep = nullptr );
4193 
4194 /*
4195 Description:
4196  Get an ON_Brep definition of a trimmed plane.
4197 Parameters:
4198  plane - [in] plane that will be trimmed.
4199  boundary - [in] a list of 3d curves that form a simple
4200  (no self intersections) closed curve that defines the
4201  outer boundary of the trimmed plane.
4202  bDuplicateCurves - [in] if true, duplicates of the
4203  curves in the boundary array are used in the brep. If false
4204  the curves in the boundary array are used in the brep
4205  and the brep's destructor will delete the curves.
4206  pBrep - [in] if not nullptr, this brep will be used and
4207  returned.
4208 Returns:
4209  An ON_Brep representation of the trimmed plane with a singe face.
4210 See Also:
4211  ON_Brep::NewPlanarFaceLoop()
4212 */
4213 ON_DECL
4214 ON_Brep* ON_BrepTrimmedPlane(
4215  const ON_Plane& plane,
4216  ON_SimpleArray<ON_Curve*>& boundary,
4217  bool bDuplicateCurves = true,
4218  ON_Brep* pBrep = nullptr );
4219 
4220 
4221 /*
4222 Description:
4223  Extrude a brep
4224 Parameters:
4225  brep - [in/out]
4226  path_curve - [in] path to extrude along.
4227  bCap - [in] if true, the extusion is capped with a translation
4228  of the input brep.
4229 Returns:
4230  True if successful.
4231 See Also:
4232  ON_BrepExtrudeFace
4233  ON_BrepExtrudeLoop
4234  ON_BrepExtrudeEdge
4235  ON_BrepExtrudeVertex
4236  ON_BrepConeFace
4237  ON_BrepConeLoop
4238  ON_BrepConeEdge
4239 Remarks:
4240  The new faces are appended to brep.m_F[]. It is the caller's
4241  responsibility to insure the result does not self intersect.
4242 */
4243 ON_DECL
4244 bool ON_BrepExtrude(
4245  ON_Brep& brep,
4246  const ON_Curve& path_curve,
4247  bool bCap = true
4248  );
4249 
4250 /*
4251 Description:
4252  Extrude a face in a brep.
4253 Parameters:
4254  brep - [in/out]
4255  face_index - [in] index of face to extrude.
4256  path_curve - [in] path to extrude along.
4257  bCap - [in] if true, the extusion is capped with a translation
4258  of the face being extruded.
4259 Example:
4260  Extrude a face along a vector.
4261 
4262  ON_Brep brep = ...;
4263  int face_index = ...;
4264  ON_3dVector v = ...;
4265  ON_LineCurve line_curve( ON_Line( ON_3dPoint::Origin, vector ) );
4266  ON_BrepExtrudeFace( brep, face_index, line_curve, true );
4267 
4268 Returns:
4269  @untitled table
4270  0 failure
4271  1 successful - no cap added
4272  2 successful - cap added as last face
4273 See Also:
4274  ON_BrepExtrude
4275  ON_BrepExtrudeLoop
4276  ON_BrepExtrudeEdge
4277  ON_BrepExtrudeVertex
4278  ON_BrepConeFace
4279  ON_BrepConeLoop
4280  ON_BrepConeEdge
4281 Remarks:
4282  The new faces are appended to brep.m_F[]. If a cap is requested
4283  it is the last face in the returned brep.m_F[]
4284 */
4285 ON_DECL
4286 int ON_BrepExtrudeFace(
4287  ON_Brep& brep,
4288  int face_index,
4289  const ON_Curve& path_curve,
4290  bool bCap = true
4291  );
4292 
4293 /*
4294 Description:
4295  Extrude a loop in a brep.
4296 Parameters:
4297  brep - [in/out]
4298  loop_index - [in] index of face to extrude.
4299  path_curve - [in] path to extrude along.
4300  bCap - [in] if true and the loop is closed, the extusion
4301  is capped.
4302 Returns:
4303  @untitled table
4304  0 failure
4305  1 successful - no cap added
4306  2 successful - cap added as last face
4307 See Also:
4308  ON_BrepExtrude
4309  ON_BrepExtrudeFace
4310  ON_BrepExtrudeEdge
4311  ON_BrepExtrudeVertex
4312  ON_BrepConeFace
4313  ON_BrepConeLoop
4314  ON_BrepConeEdge
4315 Remarks:
4316  The new faces are appended to brep.m_F[]. If a cap is requested
4317  it is the last face in the returned brep.m_F[]
4318 */
4319 ON_DECL
4320 int ON_BrepExtrudeLoop(
4321  ON_Brep& brep,
4322  int loop_index,
4323  const ON_Curve& path_curve,
4324  bool bCap = true
4325  );
4326 
4327 /*
4328 Description:
4329  Extrude an edge in a brep.
4330 Parameters:
4331  brep - [in/out]
4332  edge_index - [in] index of face to extrude.
4333  path_curve - [in] path to extrude along.
4334 Returns:
4335  @untitled table
4336  0 failure
4337  1 successful
4338 See Also:
4339  ON_BrepExtrude
4340  ON_BrepExtrudeFace
4341  ON_BrepExtrudeLoop
4342  ON_BrepExtrudeVertex
4343  ON_BrepConeFace
4344  ON_BrepConeLoop
4345  ON_BrepConeEdge
4346 Remarks:
4347  The new face is appended to brep.m_F[].
4348 */
4349 ON_DECL
4350 int ON_BrepExtrudeEdge(
4351  ON_Brep& brep,
4352  int edge_index,
4353  const ON_Curve& path_curve
4354  );
4355 
4356 
4357 /*
4358 Description:
4359  Extrude a vertex in a brep.
4360 Parameters:
4361  brep - [in/out]
4362  vertex_index - [in] index of vertex to extrude.
4363  path_curve - [in] path to extrude along.
4364 Returns:
4365  @untitled table
4366  0 failure
4367  1 successful
4368 See Also:
4369  ON_BrepExtrude
4370  ON_BrepExtrudeFace
4371  ON_BrepExtrudeLoop
4372  ON_BrepExtrudeEdge
4373  ON_BrepConeFace
4374  ON_BrepConeLoop
4375  ON_BrepConeEdge
4376 Remarks:
4377  The new vertex is appended to brep.m_V[] and
4378  the new edge is appended to brep.m_E[].
4379 */
4380 ON_DECL
4381 int ON_BrepExtrudeVertex(
4382  ON_Brep& brep,
4383  int vertex_index,
4384  const ON_Curve& path_curve
4385  );
4386 
4387 
4388 /*
4389 Description:
4390  Cone a face in a brep.
4391 Parameters:
4392  brep - [in/out]
4393  face_index - [in] index of face to extrude.
4394  apex_point - [in] apex of cone.
4395 Returns:
4396  @untitled table
4397  0 failure
4398  1 successful
4399 See Also:
4400  ON_BrepExtrudeFace
4401  ON_BrepExtrudeLoop
4402  ON_BrepExtrudeEdge
4403  ON_BrepExtrudeVertex
4404  ON_BrepConeFace
4405  ON_BrepConeLoop
4406  ON_BrepConeEdge
4407 Remarks:
4408  The new faces are appended to brep.m_F[].
4409 */
4410 ON_DECL
4411 int ON_BrepConeFace(
4412  ON_Brep& brep,
4413  int face_index,
4414  ON_3dPoint apex_point
4415  );
4416 
4417 /*
4418 Description:
4419  Cone a loop in a brep.
4420 Parameters:
4421  brep - [in/out]
4422  loop_index - [in] index of face to extrude.
4423  apex_point - [in] apex of cone.
4424 Returns:
4425  @untitled table
4426  0 failure
4427  1 successful
4428 See Also:
4429  ON_BrepExtrudeFace
4430  ON_BrepExtrudeLoop
4431  ON_BrepExtrudeEdge
4432  ON_BrepExtrudeVertex
4433  ON_BrepConeFace
4434  ON_BrepConeLoop
4435  ON_BrepConeEdge
4436 Remarks:
4437  The new faces are appended to brep.m_F[].
4438 */
4439 ON_DECL
4440 bool ON_BrepConeLoop(
4441  ON_Brep& brep,
4442  int loop_index,
4443  ON_3dPoint apex_point
4444  );
4445 
4446 /*
4447 Description:
4448  Cone an edge in a brep.
4449 Parameters:
4450  brep - [in/out]
4451  edge_index - [in] index of face to extrude.
4452  apex_point - [in] apex of cone.
4453 Returns:
4454  @untitled table
4455  0 failure
4456  1 successful
4457 See Also:
4458  ON_BrepExtrudeFace
4459  ON_BrepExtrudeLoop
4460  ON_BrepExtrudeEdge
4461  ON_BrepExtrudeVertex
4462  ON_BrepConeFace
4463  ON_BrepConeLoop
4464  ON_BrepConeEdge
4465 Remarks:
4466  The new face is appended to brep.m_F[].
4467 */
4468 ON_DECL
4469 int ON_BrepConeEdge(
4470  ON_Brep& brep,
4471  int edge_index,
4472  ON_3dPoint apex_point
4473  );
4474 
4475 //These merge adjacent faces that have the same underlying surface.
4476 ON_DECL
4477 int ON_BrepMergeFaces(ON_Brep& B, int fid0, int fid1);
4478 
4479 ON_DECL
4480 bool ON_BrepMergeFaces(ON_Brep& B);
4481 
4482 //This removes all slit trims from F that are not joined to another face.
4483 //Unlike ON_Brep::RemoveSlits(), this will remove slit pairs from a loop in cases
4484 //that will result in the creation of more loops. Caller is responsible for calling
4485 //ON_Brep::Compact() to get rid of deleted trims and loops.
4486 
4487 ON_DECL
4488 bool ON_BrepRemoveSlits(ON_BrepFace& F);
4489 
4490 //Merges all possible edges
4491 ON_DECL
4492 void ON_BrepMergeAllEdges(ON_Brep& B);
4493 
4494 /*
4495 Description:
4496  Merges two breps into a single brep. The
4497  result may be non-manifold or have multiple
4498  connected components.
4499 Parameters:
4500  brep0 - [in]
4501  brep1 - [in]
4502  tolerance - [in]
4503 Returns:
4504  Merged brep or nullptr if calculation failed.
4505 */
4506 ON_DECL
4507 ON_Brep* ON_MergeBreps(
4508  const ON_Brep& brep0,
4509  const ON_Brep& brep1,
4510  double tolerance
4511  );
4512 
4513 /*
4514 Description:
4515  Very low level utility. Order edges around a vertex.
4516 Parameters:
4517  B - [in]
4518  vid - [in]
4519  trim_ends - [out] trim_ends[a].i is a trim index, trim_ends[a].j is 0 for start or 1 for end.
4520  The nth is B.m_T[trim_ends[n].i].Edge(). If bClosed is false, then the first and last edges will be naked.
4521  bClosed - [out] If true, then all edges at the vertex have exactly two trims
4522 Returns:
4523  True if the order can be found. If any edge at the vertex is non-manifold, or if more than two are naked, then false.
4524 */
4525 ON_DECL
4526 bool ON_OrderEdgesAroundVertex(const ON_Brep& B, int vid,
4527  ON_SimpleArray<ON_2dex>& trim_ends,
4528  bool& bClosed);
4529 
4530 
4531 /*
4532 Description:
4533 Very low level utility. Order edges around a vertex.
4534 Parameters:
4535 B - [in]
4536 vid - [in]
4537 trim_ends - [out] trim_ends[a].i is a trim index, trim_ends[a].j is 0 for start or 1 for end.
4538 The nth is B.m_T[trim_ends[n].i].Edge(). If bClosed is false, then the first and last edges will be naked.
4539 Must have at least as many ON2dex as the vertex has edges.
4540 bClosed - [out] If true, then all edges at the vertex have exactly two trims
4541 Returns:
4542 True if the order can be found. If any edge at the vertex is non-manifold, or if more than two are naked, then false.
4543 NOTE: If you don't know how many edges are at the vertex, caall the version that takes an ON_SimpleArray.
4544 */
4545 ON_DECL
4546 bool ON_OrderEdgesAroundVertex(const ON_Brep& B, int vid,
4547  ON_2dex* trim_ends,//Must be at as big as the edge count at the vertex
4548  bool& bClosed);
4549 
4550 
4551 #endif
Definition: opennurbs_brep.h:1348
Definition: opennurbs_curve.h:1168
Definition: opennurbs_mesh.h:1866
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
Definition: opennurbs_brep.h:917
bool Write(ON_BinaryArchive &) const override
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
Brep vertex information is stored in ON_BrepVertex classes. ON_Brep.m_V[] is an array of all the vert...
Definition: opennurbs_brep.h:50
Brep edge information is stored in ON_BrepEdge classes. ON_Brep.m_E[] is an array of all the edges in...
Definition: opennurbs_brep.h:192
Definition: opennurbs_surface.h:74
Definition: opennurbs_nurbssurface.h:62
Definition: opennurbs_brep.h:1256
ON_Point & operator=(const ON_Point &)
Lightweight right circular cone. Use ON_ConeSurface if you need ON_Cone geometry as a virtual ON_Surf...
Definition: opennurbs_cone.h:27
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
bool IsValid(class ON_TextLog *text_log=nullptr) const override
ON_Object overrides.
Definition: opennurbs_planesurface.h:22
bool IsValid(class ON_TextLog *text_log=nullptr) const override
Tests an object to see if its data members are correctly initialized.
ON_Cylinder is a right circular cylinder.
Definition: opennurbs_cylinder.h:27
Definition: opennurbs_brep.h:776
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override
virtual ON_Object::DataCRC override
Definition: opennurbs_brep.h:373
void Dump(ON_TextLog &) const override
Creates a text dump of the object.
virtual ON_COMPONENT_INDEX ComponentIndex() const
If this piece of geometry is a component in something larger, like an ON_BrepEdge in an ON_Brep...
Definition: opennurbs_surfaceproxy.h:26
Base class for all geometry classes that must provide runtime class id. Provides interface for common...
Definition: opennurbs_geometry.h:37
TYPE
types of trim - access through m_type member. Also see m_iso and ON_Surface::ISO
Definition: opennurbs_brep.h:418
Definition: opennurbs_point.h:277
Definition: opennurbs_surface.h:910
bool Read(ON_BinaryArchive &) override
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_brep.h:1404
unsigned int SizeOf() const override
virtual ON_Object::SizeOf override
virtual unsigned int SizeOf() const
bool Write(ON_BinaryArchive &) const override
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
Definition: opennurbs_brep.h:1382
Definition: opennurbs_compstat.h:396
Definition: opennurbs_brep.h:420
Definition: opennurbs_bounding_box.h:25
ON_U m_trim_user
Definition: opennurbs_brep.h:411
bool Read(ON_BinaryArchive &) override
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_mesh.h:24
Definition: opennurbs_xform.h:28
ON_CurveProxy & operator=(const ON_CurveProxy &)
Definition: opennurbs_brep.h:1423
ISO
pure virtual class for surface objects
Definition: opennurbs_surface.h:72
Definition: opennurbs_brep.h:1393
Definition: opennurbs_curveproxy.h:37
Definition: opennurbs_mesh.h:2188
Definition: opennurbs_compstat.h:88
Definition: opennurbs_brep.h:1360
void Dump(ON_TextLog &) const override
Creates a text dump of the object.
ON::object_type ObjectType() const override
overrides virtual ON_Object::ObjectType.
Definition: opennurbs_brep.h:1442
bool Reverse() override
Reverse the direction of the curve.
surface of revolution
Definition: opennurbs_sumsurface.h:23
Top level OpenNURBS objects have geometry and attributes. The geometry is stored in some class derive...
Definition: opennurbs_3dm_attributes.h:41
Definition: opennurbs_brep.h:1472
Pure virtual base class for all classes that must provide runtime class id or support object level 3D...
Definition: opennurbs_object.h:460
TYPE
Definition: opennurbs_brep.h:835
bool IsClosed(void) const override
Test a curve to see if it is closed.
Definition: opennurbs_nurbscurve.h:26
The torus is defined by a major circle and minor radius. The torus is parameterized by (major_angle...
Definition: opennurbs_torus.h:28
Definition: opennurbs_brep.h:1371
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_defines.h:394
static const ON_ComponentStatus NoneSet
Definition: opennurbs_compstat.h:92
Definition: opennurbs_objref.h:163
Definition: opennurbs_point.h:460
Definition: opennurbs_pointgeometry.h:24
Definition: opennurbs_brep.h:836
virtual ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Returns a CRC calculated from the information that defines the object. This CRC can be used as a quic...
Definition: opennurbs_plane.h:20
surface of revolution
Definition: opennurbs_revsurface.h:21
Definition: opennurbs_surface.h:57
Definition: opennurbs_brep.h:1189
bool Trim(const ON_Interval &domain) override
override of virtual ON_Curve::Trim
Brep trim information is stored in ON_BrepTrim classes. ON_Brep.m_T[] is an array of all the trim in ...
Definition: opennurbs_brep.h:397
Definition: opennurbs_point.h:46
Definition: opennurbs_sphere.h:22