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