opennurbs_polyedgecurve.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_POLYEDGECURVE_INC_)
18 #define ON_POLYEDGECURVE_INC_
19 
20 class ON_PolyEdgeSegment;
21 
22 class ON_CLASS ON_PolyEdgeCurve : public ON_PolyCurve
23 {
24  ON_OBJECT_DECLARE(ON_PolyEdgeCurve);
25 
26 public:
29  // default copy constructor and operator= are fine.
30 
31  // virtual ON_Object::DestroyRuntimeCache override
32  void DestroyRuntimeCache( bool bDelete = true ) override;
33 
34  // virtual ON_Curve::IsClosed override
35  bool IsClosed() const override;
36 
37  // virtual ON_Curve::DuplicateCurve override
38  ON_Curve* DuplicateCurve() const override;
39 
40  /*
41  Description:
42  Create a one segment ON_PolyEdgeCurve curve that uses a
43  single edge.
44  */
45  bool Create(
46  const ON_BrepTrim* trim,
47  const ON_UUID& object_id
48  );
49 
50  /*
51  Description:
52  Create a one segment ON_PolyEdgeCurve curve that uses a
53  single curve.
54  */
55  bool Create(
56  const ON_Curve* curve,
57  const ON_UUID& object_id
58  );
59 
60  int SegmentCount() const;
61 
63  int segment_index
64  ) const;
65 
66  ON_PolyEdgeSegment* operator[](int) const;
67 
68  bool Prepend( ON_PolyEdgeSegment* new_segment ); // Prepend curve.
69  bool Append( ON_PolyEdgeSegment* new_segment ); // Append curve.
70  bool Insert(
71  int segment_index,
72  ON_PolyEdgeSegment* new_segment
73  );
74 
75  // if the segment is an edge, the following
76  // return non-nullptr pointers.
77  const ON_BrepEdge* EdgeAt(double t) const;
78  const ON_BrepTrim* TrimAt(double t) const;
79  const ON_Brep* BrepAt(double t) const;
80  const ON_BrepFace* FaceAt(double t) const;
81  const ON_Surface* SurfaceAt(double t) const;
82  ON_Surface::ISO IsoType( double t) const;
83 
84  double EdgeParameter(double t) const;
85 
86  // Test if there are any surface edges in the polyedge
87  bool ContainsAnyEdges() const;
88  // Test if all segments of the polyedge are surface edges
89  bool ContainsAllEdges() const;
90 
91 
92  /*
93  Description:
94  See if this polyedge has an edge as one of its segments
95  Parameters:
96  edge - [in] the edge to look for
97  Returns:
98  -1: edge is not in the polyedge
99  >=0: index of first segment that uses the edge
100  */
101  int FindEdge( const ON_BrepEdge* edge) const;
102 
103  /*
104  Description:
105  See if this polyedge has a trim as one of its segments
106  Parameters:
107  trim - [in] the trim to look for
108  Returns:
109  -1: trim is not in the polyedge
110  >=0: index of first segment that uses the trim
111  */
112  int FindTrim( const ON_BrepTrim* trim) const;
113 
114  /*
115  Description:
116  See if this polyedge has a wire curve as one of its segments
117  Parameters:
118  curve - [in] the curve to look for
119  Returns:
120  -1: trim is not in the polyedge
121  >=0: index of first segment that uses the curve
122  */
123  int FindCurve( const ON_Curve* curve) const;
124 
125 
126  // OBSOLETE and unreliable. Use FindCurve, FindEdge, or FindTrim
127  //bool Contains( const ON_Curve* curve) const;
128 
129  // virtual ON_Curve overrides do nothing
130  // to prevent changing edge
131  bool SetStartPoint(ON_3dPoint start_point) override;
132  bool SetEndPoint(ON_3dPoint end_point) override;
133  bool ChangeClosedCurveSeam( double t ) override;
134  bool PrependAndMatch(ON_Curve*);
135  bool AppendAndMatch(ON_Curve*);
136 
137  // 7-1-03 lw added override to unset cached closed flag
138  // when a segment is removed
139  bool Remove(); // remove last
140  bool Remove( int index);
141 };
142 
143 class ON_CLASS ON_PolyEdgeSegment : public ON_CurveProxy
144 {
145  ON_OBJECT_DECLARE(ON_PolyEdgeSegment);
146 public:
147  // construction
148 
151  // default copy constructor and operator= are fine.
152 
153  // virtual ON_Object::DestroyRuntimeCache override
154  void DestroyRuntimeCache( bool bDelete = true ) override;
155 
156  bool Write( ON_BinaryArchive& ) const override;
157 
158  bool Read( ON_BinaryArchive& ) override;
159 
160  // virtual ON_Curve::IsClosed override
161  bool IsClosed() const override;
162 
163 
164  // virtual ON_Curve::DuplicateCurve override
165  ON_Curve* DuplicateCurve() const override;
166 
167  /*
168  Description:
169  Creates a polyedge segment that uses the entire edge
170  and has the same domain as the edge.
171  Parameters:
172  trim - [in]
173  Returns:
174  true if successful (edge was valid and trim_index was valid)
175  Remarks:
176  Use ON_Curve::SetDomain, ON_Curve::Trim, ON_Curve::Reverse,
177  etc., to tweak the domain, support, direction etc.
178  */
179  bool Create(
180  const ON_BrepTrim* trim,
181  const ON_UUID& object_id
182  );
183 
184  /*
185  Description:
186  Creates a polyedge segment that uses the entire curve
187  and has the same domain as the curve.
188  Parameters:
189  curve - [in]
190  Remarks:
191  Use ON_Curve::SetDomain, ON_Curve::Trim, ON_Curve::Reverse,
192  etc., to tweak the domain, support, direction etc.
193  */
194  bool Create(
195  const ON_Curve* curve,
196  const ON_UUID& object_id
197  );
198 
199  const ON_BrepEdge* BrepEdge() const;
200  const ON_BrepTrim* BrepTrim() const;
201  const ON_Brep* Brep() const;
202  const ON_BrepFace* BrepFace() const;
203  const ON_Surface* Surface() const;
204  ON_Surface::ISO IsoType() const;
205 
206  double EdgeParameter(double t) const;
207 
208  /*
209  Returns:
210  True if this segment has an ON_BrepEdge and the direction of
211  the ON_BrepEdge is the reverse of the direction of the segment.
212  */
213  bool ReversedEdgeDir() const;
214 
215  /*
216  Returns:
217  True if this segment has an ON_BrepTrim and the direction of
218  the ON_BrepTrime is the reverse of the direction of the segment.
219  */
220  bool ReversedTrimDir() const;
221 
222  /*
223  Returns:
224  subdomain of the edge that this segment uses. This can
225  be different than the domain returned by this->Domain().
226  */
227  ON_Interval EdgeDomain() const;
229  /*
230  Returns:
231  subdomain of the trim that this segment uses. This can
232  be different than the domain returned by this->Domain().
233  */
234  ON_Interval TrimDomain() const;
236 
237  // m_object_id = id of a brep or curve object in Rhino
238  ON_UUID m_object_id;
239  // When the Rhino object is a brep, m_component_index
240  // refers to either an edge or a trim.
241  ON_COMPONENT_INDEX m_component_index;
242  // corresponding domain of the edge - see note below
243  ON_Interval m_edge_domain = ON_Interval::EmptyInterval;
244  // corresponding domain of the trim - see note below
245  ON_Interval m_trim_domain = ON_Interval::EmptyInterval;
246 
247 
248  // When m_component_index refers to an ON_BrepTrim, there
249  // are four domains and 4 classes derived from ON_Curve
250  // that play a role in the polyedge segment. It is possible
251  // for all 4 of these domains to be different.
252  //
253  // "this" ON_PolyEdgeSegment is an ON_ProxyCurve. The
254  // evaluation domain of "this" is
255  // = this->Domain()
256  // = ON_ProxyCurve::m_this_domain
257  //
258  // ON_ProxyCurve::m_real_curve points to the curve in the
259  // c3 = ON_Brep::m_C3[edge.m_c3i]. "this" is a proxy for some
260  // sub-interval of c3.
261  // = this->ProxyCurveDomain()
262  // = ON_ProxyCurve::m_real_curve_domain
263  //
264  // The edge, an ON_BrepEdge, is also a proxy based on c3,
265  // and the edge's evaluation domain is edge.m_this_domain.
266  // ON_PolyEdgeSegment::m_edge_domain records the increasing
267  // subinterval of edge.m_this_domain that corresponds
268  // to the portion of c3 "this" is using.
269  //
270  // The trim, an ON_BrepTrim, is a proxy based on a curve
271  // in ON_Brep::m_C2[]. Some portion of the trim corresponds
272  // to the portion of the edge we are using. m_trim_domain
273  // is an increasing, possible subinterval, of the trim's domain
274  // ON_BrepTrim::m_this_domain.
275 
276  // Runtime helpers
277  const void* m_parent_object; // CRhinoBrepObject or CRhinoCurveObject
278  const ON_Brep* m_brep;
279  const ON_BrepTrim* m_trim; // 2d trim in m_brep
280  const ON_BrepEdge* m_edge; // 3d edge in m_brep
281  const ON_BrepFace* m_face;
282  const ON_Surface* m_surface;
283 
284 
285 private:
286  friend class ON_PolyEdgeCurve;
287  void ClearEvalCacheHelper();
288 
289  // parameter evaluation cache
290  double m_t;
291  double m_edge_t;
292  double m_trim_t;
293  double m_srf_uv[2];
294  int m_trim_hint;
295  int m_edge_hint;
296 
297  // surface evaluation cache
298  int m_evsrf_hint[2];
299  double m_evsrf_uv[2];
300  ON_3dPoint m_evsrf_pt;
301  ON_3dVector m_evsrf_du;
302  ON_3dVector m_evsrf_dv;
303  ON_3dVector m_evsrf_duu;
304  ON_3dVector m_evsrf_duv;
305  ON_3dVector m_evsrf_dvv;
306  ON_3dVector m_evsrf_tan;
307 
308  void Init();
309 };
310 
311 #endif
bool PrependAndMatch(ON_Curve *)
bool SetStartPoint(ON_3dPoint start_point) override
Force the curve to start at a specified point.
void DestroyRuntimeCache(bool bDelete=true) override
virtual ON_Object::DestroyRuntimeCache override
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 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
bool SetEndPoint(ON_3dPoint end_point) override
Force the curve to end at a specified point.
bool Insert(int, ON_Curve *)
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
bool Append(ON_Curve *)
ON_Curve * SegmentCurve(int segment_index) const
Returns a pointer to a segment curve.
bool IsClosed(void) const override
Test a curve to see if it is closed.
bool Read(ON_BinaryArchive &) override
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
ON_Curve * operator[](int) const
These operator[] functions return nullptr if index is out of range.
Definition: opennurbs_polyedgecurve.h:138
void DestroyRuntimeCache(bool bDelete=true) override
virtual ON_Object::DestroyRuntimeCache override
ON_Curve * DuplicateCurve() const override
ON_Curve overrides.
An ON_PolyCurve is an ON_Curve represented by a sequence of contiguous ON_Curve segments. A valid polycurve is represented by an array m_segment of Count()>=1 curve objects and a strictly increasing array m_t of Count()+1 parameter values. The i-th curve segment, when considered as part of the polycurve, is affinely reparamaterized from m_t[i] to m_t[i+1], i.e., m_segment[i].Domain()[0] is mapped to m_t[i] and m_segment[i].Domain()[1] is mapped to m_t[i+1].
Definition: opennurbs_polycurve.h:35
ISO
pure virtual class for surface objects
Definition: opennurbs_surface.h:72
Definition: opennurbs_curveproxy.h:37
bool AppendAndMatch(ON_Curve *)
bool Prepend(ON_Curve *)
Definition: opennurbs_polyedgecurve.h:22
Definition: opennurbs_brep.h:1472
static const ON_Interval EmptyInterval
Definition: opennurbs_point.h:49
ON_Curve * DuplicateCurve() const override
Get a duplicate of the curve.
bool IsClosed(void) const override
Test a curve to see if it is closed.
Definition: opennurbs_archive.h:1783
Definition: opennurbs_point.h:460
Definition: opennurbs_surface.h:57
bool ChangeClosedCurveSeam(double t) override
If this curve is closed, then modify it so that the start/end point is at curve parameter t...
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:1152
Definition: opennurbs_point.h:46