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