opennurbs_geometry.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 // virtual base class for all geomtric objects
20 //
21 ////////////////////////////////////////////////////////////////
22 
23 #if !defined(OPENNURBS_GEOMETRY_INC_)
24 #define OPENNURBS_GEOMETRY_INC_
25 
26 class ON_Brep;
27 
28 ////////////////////////////////////////////////////////////////
29 
30 // Description:
31 // Base class for all geometry classes that must
32 // provide runtime class id. Provides interface
33 // for common geometric operations like finding bounding
34 // boxes and transforming.
35 //
36 class ON_CLASS ON_Geometry : public ON_Object
37 {
38  // Any object derived from ON_Geometry should have a
39  // ON_OBJECT_DECLARE(ON_...);
40  // as the last line of its class definition and a
41  // ON_OBJECT_IMPLEMENT( ON_..., ON_baseclass );
42  // in a .cpp file.
43  //
44  // See the definition of ON_Object for details.
45  ON_OBJECT_DECLARE(ON_Geometry);
46 
47 public:
48  const static ON_Geometry Unset;
49 
50 public:
51  ON_Geometry() = default;
52  ~ON_Geometry() = default;
53  ON_Geometry(const ON_Geometry&) = default;
54  ON_Geometry& operator=(const ON_Geometry&) = default;
55 
56 #if defined(ON_HAS_RVALUEREF)
57  // rvalue copy constructor
58  ON_Geometry( ON_Geometry&& ) ON_NOEXCEPT;
59 
60  // The rvalue assignment operator calls ON_Object::operator=(ON_Object&&)
61  // which could throw exceptions. See the implementation of
62  // ON_Object::operator=(ON_Object&&) for details.
63  ON_Geometry& operator=( ON_Geometry&& );
64 #endif
65 
66  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
67 
68  // Description:
69  // Get object's 3d axis aligned bounding box.
70  // Returns:
71  // 3d bounding box.
72  // Remarks:
73  // Uses virtual GetBBox() function to calculate the result.
74  ON_BoundingBox BoundingBox() const;
75 
76  // Description:
77  // Get object's 3d axis aligned bounding box or the
78  // union of the input box with the object's bounding box.
79  // Parameters:
80  // bbox - [in/out] 3d axis aligned bounding box
81  // bGrowBox - [in] (default=false)
82  // If true, then the union of the input bbox and the
83  // object's bounding box is returned in bbox.
84  // If false, the object's bounding box is returned in bbox.
85  // Returns:
86  // true if object has bounding box and calculation was successful.
87  // Remarks:
88  // Uses virtual GetBBox() function to calculate the result.
89  bool GetBoundingBox(
90  ON_BoundingBox& bbox,
91  bool bGrowBox = false
92  ) const;
93 
94  // Description:
95  // Get corners of object's 3d axis aligned bounding box
96  // or the union of the input box with the object's bounding
97  // box.
98  // Parameters:
99  // bbox_min - [in/out] minimum corner of the 3d bounding box
100  // bbox_max - [in/out] maximum corner of the 3d bounding box
101  // bGrowBox - [in] (default=false)
102  // If true, then the union of the input bbox and the
103  // object's bounding box is returned.
104  // If false, the object's bounding box is returned.
105  // Returns:
106  // true if successful.
107  bool GetBoundingBox(
108  ON_3dPoint& bbox_min,
109  ON_3dPoint& bbox_max,
110  bool bGrowBox = false
111  ) const;
112 
113  // Description:
114  // Rotates the object about the specified axis. A positive
115  // rotation angle results in a counter-clockwise rotation
116  // about the axis (right hand rule).
117  // Parameters:
118  // sin_angle - [in] sine of rotation angle
119  // cos_angle - [in] sine of rotation angle
120  // rotation_axis - [in] direction of the axis of rotation
121  // rotation_center - [in] point on the axis of rotation
122  // Returns:
123  // true if object successfully rotated
124  // Remarks:
125  // Uses virtual Transform() function to calculate the result.
126  bool Rotate(
127  double sin_angle,
128  double cos_angle,
129  const ON_3dVector& rotation_axis,
130  const ON_3dPoint& rotation_center
131  );
132 
133  // Description:
134  // Rotates the object about the specified axis. A positive
135  // rotation angle results in a counter-clockwise rotation
136  // about the axis (right hand rule).
137  // Parameters:
138  // rotation_angle - [in] angle of rotation in radians
139  // rotation_axis - [in] direction of the axis of rotation
140  // rotation_center - [in] point on the axis of rotation
141  // Returns:
142  // true if object successfully rotated
143  // Remarks:
144  // Uses virtual Transform() function to calculate the result.
145  bool Rotate(
146  double rotation_angle,
147  const ON_3dVector& rotation_axis,
148  const ON_3dPoint& rotation_center
149  );
150 
151  // Description:
152  // Translates the object along the specified vector.
153  // Parameters:
154  // translation_vector - [in] translation vector
155  // Returns:
156  // true if object successfully translated
157  // Remarks:
158  // Uses virtual Transform() function to calculate the result.
159  bool Translate(
160  const ON_3dVector& translation_vector
161  );
162 
163  // Description:
164  // Scales the object by the specified facotor. The scale is
165  // centered at the origin.
166  // Parameters:
167  // scale_factor - [in] scale factor
168  // Returns:
169  // true if object successfully scaled
170  // Remarks:
171  // Uses virtual Transform() function to calculate the result.
172  bool Scale(
173  double scale_factor
174  );
175 
176  // Description:
177  // Dimension of the object.
178  // Returns:
179  // Dimension of the object.
180  // Remarks:
181  // The dimension is typically three. For parameter space trimming
182  // curves the dimension is two. In rare cases the dimension can
183  // be one or greater than three.
184  virtual int Dimension() const;
185 
186  // Description:
187  // This is the virtual function that actually calculates axis
188  // aligned bounding boxes.
189  // Parameters:
190  // boxmin - [in/out] array of Dimension() doubles
191  // boxmax - [in/out] array of Dimension() doubles
192  // bGrowBox - [in] (default=false)
193  // If true, then the union of the input bbox and the
194  // object's bounding box is returned in bbox.
195  // If false, the object's bounding box is returned in bbox.
196  // Returns:
197  // true if object has bounding box and calculation was successful
198  virtual bool GetBBox(
199  double* boxmin,
200  double* boxmax,
201  bool bGrowBox = false
202  ) const;
203 
204  /*
205  Description:
206  Get tight bounding box.
207  Parameters:
208  tight_bbox - [in/out] tight bounding box
209  bGrowBox -[in] (default=false)
210  If true and the input tight_bbox is valid, then returned
211  tight_bbox is the union of the input tight_bbox and the
212  curve's tight bounding box.
213  xform -[in] (default=nullptr)
214  If not nullptr, the tight bounding box of the transformed
215  geometry is calculated. The geometry is not modified.
216  Returns:
217  True if a valid tight_bbox is returned.
218  Remarks:
219  In general, GetTightBoundingBox is slower that BoundingBox,
220  especially when xform is not null.
221  */
222  virtual bool GetTightBoundingBox(
223  class ON_BoundingBox& tight_bbox,
224  bool bGrowBox = false,
225  const class ON_Xform* xform = nullptr
226  ) const;
227 
228  // Description:
229  // Some objects cache bounding box information.
230  // If you modify an object, then call ClearBoundingBox()
231  // to inform the object that any cached bounding boxes
232  // are invalid.
233  //
234  // Remarks:
235  // Generally, ClearBoundingBox() overrides
236  // simply invalidate a cached bounding box and then wait
237  // for a call to GetBBox() before recomputing the bounding box.
238  //
239  // The default implementation does nothing.
240  virtual void ClearBoundingBox();
241 
242  /*
243  Description:
244  Transforms the object.
245 
246  Parameters:
247  xform - [in] transformation to apply to object.
248  If xform.IsSimilarity() is zero, then you may
249  want to call MakeSquishy() before calling
250  Transform.
251 
252  Remarks:
253  When overriding this function, be sure to include a call
254  to ON_Object::TransformUserData() which takes care of
255  transforming any ON_UserData that may be attached to
256  the object.
257 
258  See Also:
259  ON_Geometry::IsDeformable();
260 
261  Remarks:
262  Classes derived from ON_Geometry should call
263  ON_Geometry::Transform() to handle user data
264  transformations and then transform their
265  definition.
266  */
267  virtual
268  bool Transform(
269  const ON_Xform& xform
270  );
271 
272  /*
273  Returns:
274  True if object can be accuratly modified with
275  "squishy" transformations like projections,
276  shears, an non-uniform scaling.
277  See Also:
278  ON_Geometry::MakeDeformable();
279  */
280  virtual
281  bool IsDeformable() const;
282 
283  /*
284  Description:
285  If possible, converts the object into a form that can
286  be accuratly modified with "squishy" transformations
287  like projections, shears, an non-uniform scaling.
288  Returns:
289  False if object cannot be converted to a deformable
290  object. True if object was already deformable or
291  was converted into a deformable object.
292  See Also:
293  ON_Geometry::IsDeformable();
294  */
295  virtual
296  bool MakeDeformable();
297 
298  // Description:
299  // Swaps object coordinate values with indices i and j.
300  //
301  // Parameters:
302  // i - [in] coordinate index
303  // j - [in] coordinate index
304  //
305  // Remarks:
306  // The default implementation uses the virtual Transform()
307  // function to calculate the result. If you are creating
308  // an object where Transform() is slow, coordinate swapping
309  // will be frequently used, and coordinate swapping can
310  // be quickly accomplished, then override this function.
311  //
312  // Example:
313  //
314  // ON_Point point(7,8,9);
315  // point.SwapCoordinates(0,2);
316  // // point = (9,8,7)
317  virtual
318  bool SwapCoordinates(
319  int i,
320  int j
321  );
322 
323 
324 
325  /*
326  Description:
327  Query an object to see if it has an ON_Brep form.
328  Result:
329  Returns true if the virtual ON_Geometry::BrepForm can compute
330  an ON_Brep representation of this object.
331  Remarks:
332  The default implementation of ON_Geometry::BrepForm returns
333  false.
334  See Also
335  ON_Geometry::BrepForm
336  */
337  virtual
338  bool HasBrepForm() const;
339 
340  /*
341  Description:
342  If possible, BrepForm() creates a brep form of the
343  ON_Geometry.
344  Parameters:
345  brep - [in] if not nullptr, brep is used to store the brep
346  form of the geometry.
347  Result:
348  Returns a pointer to on ON_Brep or nullptr. If the brep
349  parameter is not nullptr, then brep is returned if the
350  geometry has a brep form and nullptr is returned if the
351  geometry does not have a brep form.
352  Remarks:
353  The caller is responsible for managing the brep memory.
354  See Also
355  ON_Geometry::HasBrepForm
356  */
357  virtual
358  class ON_Brep* BrepForm(
359  class ON_Brep* brep = nullptr
360  ) const;
361 
362  /*
363  Description:
364  If this piece of geometry is a component in something
365  larger, like an ON_BrepEdge in an ON_Brep, then this
366  function returns the component index.
367  Returns:
368  This object's component index. If this object is
369  not a sub-piece of a larger geometric entity, then
370  the returned index has
371  m_type = ON_COMPONENT_INDEX::invalid_type
372  and
373  m_index = -1.
374  */
375  virtual
376  ON_COMPONENT_INDEX ComponentIndex() const;
377 
378  /*
379  Description:
380  Evaluate the location of a point from the object
381  reference.
382  Parameters:
383  objref - [in]
384  point - [out]
385  If the evaluation cannot be performed, ON_3dPoint::UnsetPoint
386  is returned.
387  Returns:
388  True if successful.
389  */
390  virtual
391  bool EvaluatePoint(
392  const class ON_ObjRef& objref,
393  ON_3dPoint& P
394  ) const;
395 };
396 
397 #endif
398 
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...
Base class for all geometry classes that must provide runtime class id. Provides interface for common...
Definition: opennurbs_geometry.h:37
Definition: opennurbs_bounding_box.h:25
Definition: opennurbs_xform.h:28
bool EvaluatePoint(const class ON_ObjRef &objref, ON_3dPoint &P) const override
virtual ON_Geometry override
ON_Object & operator=(const ON_Object &)
virtual bool IsValid(class ON_TextLog *text_log=nullptr) const
Tests an object to see if its data members are correctly initialized.
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
Definition: opennurbs_textlog.h:20
Definition: opennurbs_objref.h:163
Definition: opennurbs_point.h:460
ON_Brep * BrepForm(ON_Brep *brep=nullptr) const override
If possible, BrepForm() creates a brep form of the ON_Geometry.
Definition: opennurbs_point.h:1152