QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_xform.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
17//
18// defines ON_Xform (4 x 4 transformation matrix)
19//
21
22#if !defined(ON_XFORM_INC_)
23#define ON_XFORM_INC_
24
25class ON_Matrix;
26
28{
29public:
30 double m_xform[4][4]; // [i][j] = row i, column j. I.e.,
31 //
32 // [0][0] [0][1] [0][2] [0][3]
33 // [1][0] [1][1] [1][2] [1][3]
34 // [2][0] [2][1] [2][2] [2][3]
35 // [3][0] [3][1] [3][2] [3][3]
36
37 // use implicit destructor, copy constructor
38 ON_Xform(); // zero matrix
39
40 ON_Xform( int ); // diagonal matrix (d,d,d,1)
41 ON_Xform( double ); // diagonal matrix (d,d,d,1)
42
43#if defined(ON_COMPILER_MSC)
44 // Microsoft's compiler won't pass double m[4][4] as a const double[4][4] arg.
45 // Gnu's compiler handles this.
46 ON_Xform( double[4][4] ); // from standard double m[4][4]
47 ON_Xform( float[4][4] ); // from standard float m[4][4]
48#endif
49
50 ON_Xform( const double[4][4] ); // from standard double m[4][4]
51 ON_Xform( const float[4][4] ); // from standard float m[4][4]
52
53 ON_Xform( const double* ); // from array of 16 doubles (row0,row1,row2,row3)
54 ON_Xform( const float* ); // from array of 16 floats (row0,row1,row2,row3)
55
56 ON_Xform( const ON_Matrix& ); // from upper left 4x4 of an
57 // arbitrary matrix. Any missing
58 // rows/columns are set to identity.
59 ON_Xform(const ON_3dPoint& P, // as a frame.
60 const ON_3dVector& X,
61 const ON_3dVector& Y,
62 const ON_3dVector& Z);
63
64 // use implicit operator=(const ON_3dVector&), operator==
65
66 double* operator[](int);
67 const double* operator[](int) const;
68
69 // xform = scalar results in a diagonal 3x3 with bottom row = 0,0,0,1
70 ON_Xform& operator=( int );
71 ON_Xform& operator=( float );
72 ON_Xform& operator=( double );
73 ON_Xform& operator=( const ON_Matrix& ); // from upper left 4x4 of an
74 // arbitrary matrix. Any missing
75 // rows/columns are set to identity.
76
77 // All non-commutative operations have "this" as left hand side and
78 // argument as right hand side.
79 ON_2dPoint operator*( const ON_2dPoint& ) const;
80 ON_3dPoint operator*( const ON_3dPoint& ) const;
81 ON_4dPoint operator*( const ON_4dPoint& ) const;
82
83 ON_2dVector operator*( const ON_2dVector& ) const;
84 ON_3dVector operator*( const ON_3dVector& ) const;
85
86 ON_Xform operator*( const ON_Xform& /*rhs*/ ) const;
87 ON_Xform operator+( const ON_Xform& ) const;
88 ON_Xform operator-( const ON_Xform& /*rhs*/ ) const;
89
90 /*
91 Description:
92 Test the entries of the transformation matrix
93 to see if they are valid number.
94 Returns:
95 True if ON_IsValid() is true for every number
96 in the transformation matrix.
97 */
98 bool IsValid() const;
99
100 /*
101 Returns:
102 true if matrix is the identity transformation
103
104 1 0 0 0
105 0 1 0 0
106 0 0 1 0
107 0 0 0 1
108 Remarks:
109 The test for zero is fabs(x) <= zero_tolerance.
110 The test for one is fabs(x-1) <= zero_tolerance.
111 */
112 bool IsIdentity( double zero_tolerance = 0.0) const;
113
114 /*
115 Returns:
116 true if matrix is a pure translation
117
118 1 0 0 dx
119 0 1 0 dy
120 0 0 1 dz
121 0 0 0 1
122 Remarks:
123 The test for zero is fabs(x) <= zero_tolerance.
124 The test for one is fabs(x-1) <= zero_tolerance.
125 */
126 bool IsTranslation( double zero_tolerance = 0.0) const;
127
128 /*
129 Returns:
130 true if matrix is the zero transformation
131
132 0 0 0 0
133 0 0 0 0
134 0 0 0 0
135 0 0 0 *
136 */
137 bool IsZero() const;
138
139 /*
140 Description:
141 A similarity transformation can be broken into a sequence
142 of dialations, translations, rotations, and reflections.
143 Returns:
144 +1: This transformation is an orientation preserving similarity.
145 -1: This transformation is an orientation reversing similarity.
146 0: This transformation is not a similarity.
147 */
148 int IsSimilarity() const;
149
150
151 int Compare( const ON_Xform& other ) const;
152
153
154 // matrix operations
155 void Transpose(); // transposes 4x4 matrix
156
157 int
158 Rank( // returns 0 to 4
159 double* = NULL // If not NULL, returns minimum pivot
160 ) const;
161
162 double
163 Determinant( // returns determinant of 4x4 matrix
164 double* = NULL // If not NULL, returns minimum pivot
165 ) const;
166
167 bool
168 Invert( // If matrix is non-singular, returns true,
169 // otherwise returns false and sets matrix to
170 // pseudo inverse.
171 double* = NULL // If not NULL, returns minimum pivot
172 );
173
175 Inverse( // If matrix is non-singular, returns inverse,
176 // otherwise returns pseudo inverse.
177 double* = NULL // If not NULL, returns minimum pivot
178 ) const;
179
180 /*
181 Description:
182 When transforming 3d point and surface or mesh normals
183 two different transforms must be used.
184 If P_xform transforms the point, then the inverse
185 transpose of P_xform must be used to tranform normal
186 vectors.
187 Parameters:
188 N_xform - [out]
189 Returns:
190 The determinant of the transformation.
191 If non-zero, "this" is invertable and N_xform can be calculated.
192 False if "this" is not invertable, in which case
193 the returned N_xform = this with the right hand column
194 and bottom row zeroed out.
195 */
196 double GetSurfaceNormalXform( ON_Xform& N_xform ) const;
197
198 /*
199 Description:
200 If a texture mapping is applied to an object, the object
201 is subsequently transformed by T, and the texture mapping
202 needs to be recalculated, then two transforms are required
203 to recalcalculate the texture mapping.
204 Parameters:
205 P_xform - [out]
206 Transform to apply to points before applying the
207 texture mapping transformation.
208 N_xform - [out]
209 Transform to apply to surface normals before applying
210 the texture mapping transformation.
211 Returns:
212 The determinant of the "this" transformation.
213 If non-zero, "this" is invertable and P_xform and N_xform
214 were calculated.
215 False if "this" is not invertable, in which case
216 the returned P_xform and N_xform are the identity.
217 */
218 double GetMappingXforms( ON_Xform& P_xform, ON_Xform& N_xform ) const;
219
220 // Description:
221 // Computes matrix * transpose([x,y,z,w]).
222 //
223 // Parameters:
224 // x - [in]
225 // y - [in]
226 // z - [in]
227 // z - [in]
228 // ans - [out] = matrix * transpose([x,y,z,w])
229 void ActOnLeft(
230 double, // x
231 double, // y
232 double, // z
233 double, // w
234 double[4] // ans
235 ) const;
236
237 // Description:
238 // Computes [x,y,z,w] * matrix.
239 //
240 // Parameters:
241 // x - [in]
242 // y - [in]
243 // z - [in]
244 // z - [in]
245 // ans - [out] = [x,y,z,w] * matrix
246 void ActOnRight(
247 double, // x
248 double, // y
249 double, // z
250 double, // w
251 double[4] // ans
252 ) const;
253
255 // standard transformations
256
257 // All zeros including the bottom row.
258 void Zero();
259
260 // diagonal is (1,1,1,1)
261 void Identity();
262
263 // diagonal 3x3 with bottom row = 0,0,0,1
264 void Diagonal(double);
265
266 /*
267 Description:
268 Create non-uniform scale transformation with the origin as
269 a fixed point.
270 Parameters:
271 fixed_point - [in]
272 x_scale_factor - [in]
273 y_scale_factor - [in]
274 z_scale_factor - [in]
275 Remarks:
276 The diagonal is (x_scale_factor, y_scale_factor, z_scale_factor, 1)
277 */
278 void Scale(
279 double x_scale_factor,
280 double y_scale_factor,
281 double z_scale_factor
282 );
283
284 /*
285 Description:
286 Create non-uniform scale transformation with the origin as
287 a fixed point.
288 Parameters:
289 fixed_point - [in]
290 scale_vector - [in]
291 Remarks:
292 The diagonal is (scale_vector.x, scale_vector.y, scale_vector.z, 1)
293 */
294 void Scale(
295 const ON_3dVector& scale_vector
296 );
297
298 /*
299 Description:
300 Create uniform scale transformation with a specified
301 fixed point.
302 Parameters:
303 fixed_point - [in]
304 scale_factor - [in]
305 */
306 void Scale
307 (
308 ON_3dPoint fixed_point,
309 double scale_factor
310 );
311
312 /*
313 Description:
314 Create non-uniform scale transformation with a specified
315 fixed point.
316 Parameters:
317 plane - [in] plane.origin is the fixed point
318 x_scale_factor - [in] plane.xaxis scale factor
319 y_scale_factor - [in] plane.yaxis scale factor
320 z_scale_factor - [in] plane.zaxis scale factor
321 */
322 void Scale
323 (
324 const ON_Plane& plane,
325 double x_scale_factor,
326 double y_scale_factor,
327 double z_scale_factor
328 );
329
330 /*
331 Description:
332 Create shear transformation.
333 Parameters:
334 plane - [in] plane.origin is the fixed point
335 x1 - [in] plane.xaxis scale factor
336 y1 - [in] plane.yaxis scale factor
337 z1 - [in] plane.zaxis scale factor
338 */
339 void Shear
340 (
341 const ON_Plane& plane,
342 const ON_3dVector& x1,
343 const ON_3dVector& y1,
344 const ON_3dVector& z1
345 );
346
347 // Right column is (d.x, d.y,d.z, 1).
348 void Translation(
349 const ON_3dVector& // d
350 );
351
352 // Right column is (dx, dy, dz, 1).
353 void Translation(
354 double, // dx
355 double, // dy
356 double // dz
357 );
358
359 // Description:
360 // Get transformation that projects to a plane
361 // Parameters:
362 // plane - [in] plane to project to
363 // Remarks:
364 // This transformaton maps a 3d point P to the
365 // point plane.ClosestPointTo(Q).
366 void PlanarProjection(
367 const ON_Plane& plane
368 );
369
370 // Description:
371 // The Rotation() function is overloaded and provides several
372 // ways to compute a rotation transformation. A positive
373 // rotation angle indicates a counter-clockwise (right hand rule)
374 // rotation about the axis of rotation.
375 //
376 // Parameters:
377 // sin_angle - sin(rotation angle)
378 // cos_angle - cos(rotation angle)
379 // rotation_axis - 3d unit axis of rotation
380 // rotation_center - 3d center of rotation
381 //
382 // Remarks:
383 // In the overloads that take frames, the frames should
384 // be right hand orthonormal frames
385 // (unit vectors with Z = X x Y).
386 // The resulting rotation fixes
387 // the origin (0,0,0), maps initial X to
388 // final X, initial Y to final Y, and initial Z to final Z.
389 //
390 // In the overload that takes frames with center points,
391 // if the initial and final center are equal, then that
392 // center point is the fixed point of the rotation. If
393 // the initial and final point differ, then the resulting
394 // transform is the composition of a rotation fixing P0
395 // and translation from P0 to P1. The resulting
396 // transformation maps P0 to P1, P0+X0 to P1+X1, ...
397 //
398 // The rotation transformations that map frames to frames
399 // are not the same as the change of basis transformations
400 // for those frames. See ON_Xform::ChangeBasis().
401 //
402 void Rotation(
403 double sin_angle,
404 double cos_angle,
405 ON_3dVector rotation_axis,
406 ON_3dPoint rotation_center
407 );
408
409 // Parameters:
410 // angle - rotation angle in radians
411 // rotation_axis - 3d unit axis of rotation
412 // rotation_center - 3d center of rotation
413 void Rotation(
414 double angle_radians,
415 ON_3dVector rotation_axis,
416 ON_3dPoint rotation_center
417 );
418
419 /*
420 Description:
421 Calculate the minimal transformation that rotates
422 start_dir to end_dir while fixing rotation_center.
423 */
424 void Rotation(
425 ON_3dVector start_dir,
426 ON_3dVector end_dir,
427 ON_3dPoint rotation_center
428 );
429
430 // Parameters:
431 // X0 - initial frame X
432 // Y0 - initial frame Y
433 // Z0 - initial frame Z
434 // X1 - final frame X
435 // Y1 - final frame Y
436 // Z1 - final frame Z
437 //
438 void Rotation(
439 const ON_3dVector& X0,
440 const ON_3dVector& Y0,
441 const ON_3dVector& Z0,
442 const ON_3dVector& X1,
443 const ON_3dVector& Y1,
444 const ON_3dVector& Z1
445 );
446
447 // Parameters:
448 // P0 - initial frame center
449 // X0 - initial frame X
450 // Y0 - initial frame Y
451 // Z0 - initial frame Z
452 // P1 - initial frame center
453 // X1 - final frame X
454 // Y1 - final frame Y
455 // Z1 - final frame Z
456 void Rotation(
457 const ON_3dPoint& P0,
458 const ON_3dVector& X0,
459 const ON_3dVector& Y0,
460 const ON_3dVector& Z0,
461 const ON_3dPoint& P1,
462 const ON_3dVector& X1,
463 const ON_3dVector& Y1,
464 const ON_3dVector& Z1
465 );
466
467 /*
468 Description:
469 Create rotation transformation that maps plane0 to plane1.
470 Parameters:
471 plane0 - [in]
472 plane1 - [in]
473 */
474 void Rotation(
475 const ON_Plane& plane0,
476 const ON_Plane& plane1
477 );
478
479 /*
480 Description:
481 Create mirror transformation matrix.
482 Parameters:
483 point_on_mirror_plane - [in] point on mirror plane
484 normal_to_mirror_plane - [in] normal to mirror plane
485 Remarks:
486 The mirror transform maps a point Q to
487 Q - (2*(Q-P)oN)*N, where
488 P = point_on_mirror_plane and N = normal_to_mirror_plane.
489 */
490 void Mirror(
491 ON_3dPoint point_on_mirror_plane,
492 ON_3dVector normal_to_mirror_plane
493 );
494
495 // Description: The ChangeBasis() function is overloaded
496 // and provides several
497 // ways to compute a change of basis transformation.
498 //
499 // Parameters:
500 // plane0 - inital plane
501 // plane1 - final plane
502 //
503 // Returns:
504 // @untitled table
505 // true success
506 // false vectors for initial frame are not a basis
507 //
508 // Remarks:
509 // If you have points defined with respect to planes, the
510 // version of ChangeBasis() that takes two planes computes
511 // the transformation to change coordinates from one plane to
512 // another. The predefined world plane ON_world_plane can
513 // be used as an argument.
514 //
515 // If P = plane0.Evaluate( a0,b0,c0 ) and
516 //
517 // (a1,b1,c1) = ChangeBasis(plane0,plane1)*ON_3dPoint(a0,b0,c0),
518 //
519 // then P = plane1.Evaluate( a1, b1, c1 )
520 //
521 // The version of ChangeBasis() that takes six vectors
522 // maps (a0,b0,c0) to (a1,b1,c1) where
523 // a0*X0 + b0*Y0 + c0*Z0 = a1*X1 + b1*Y1 + c1*Z1
524 //
525 // The version of ChangeBasis() that takes six vectors
526 // with center points
527 // maps (a0,b0,c0) to (a1,b1,c1) where
528 // P0 + a0*X0 + b0*Y0 + c0*Z0 = P1 + a1*X1 + b1*Y1 + c1*Z1
529 //
530 // The change of basis transformation is not the same as
531 // the rotation transformation that rotates one orthonormal
532 // frame to another. See ON_Xform::Rotation().
533 bool ChangeBasis(
534 const ON_Plane& plane0,
535 const ON_Plane& plane1
536 );
537
538 // Description:
539 // Get a change of basis transformation.
540 // Parameters:
541 // X0 - initial basis X (X0,Y0,Z0 can be any 3d basis)
542 // Y0 - initial basis Y
543 // Z0 - initial basis Z
544 // X1 - final basis X (X1,Y1,Z1 can be any 3d basis)
545 // Y1 - final basis Y
546 // Z1 - final basis Z
547 // Remarks:
548 // Change of basis transformations and rotation transformations
549 // are often confused. This is a change of basis transformation.
550 // If Q = a0*X0 + b0*Y0 + c0*Z0 = a1*X1 + b1*Y1 + c1*Z1
551 // then this transform will map the point (a0,b0,c0) to (a1,b1,c1)
552 bool ChangeBasis(
553 const ON_3dVector& X0,
554 const ON_3dVector& Y0,
555 const ON_3dVector& Z0,
556 const ON_3dVector& X1,
557 const ON_3dVector& Y1,
558 const ON_3dVector& Z1
559 );
560
561 // Parameters:
562 // P0 - initial center
563 // X0 - initial basis X (X0,Y0,Z0 can be any 3d basis)
564 // Y0 - initial basis Y
565 // Z0 - initial basis Z
566 // P1 - final center
567 // X1 - final basis X (X1,Y1,Z1 can be any 3d basis)
568 // Y1 - final basis Y
569 // Z1 - final basis Z
570 // Remarks:
571 // Change of basis transformations and rotation transformations
572 // are often confused. This is a change of basis transformation.
573 // If Q = P0 + a0*X0 + b0*Y0 + c0*Z0 = P1 + a1*X1 + b1*Y1 + c1*Z1
574 // then this transform will map the point (a0,b0,c0) to (a1,b1,c1)
575 bool ChangeBasis(
576 const ON_3dPoint& P0,
577 const ON_3dVector& X0,
578 const ON_3dVector& Y0,
579 const ON_3dVector& Z0,
580 const ON_3dPoint& P1,
581 const ON_3dVector& X1,
582 const ON_3dVector& Y1,
583 const ON_3dVector& Z1
584 );
585
586 // standard viewing transformations
587 void WorldToCamera(
588 const ON_3dPoint&, // CameraLocation
589 const ON_3dVector&, // unit CameraX vector (right)
590 const ON_3dVector&, // unit CameraY vector (up)
591 const ON_3dVector& // unit CameraZ vector (from screen to camera)
592 );
593 void CameraToWorld(
594 const ON_3dPoint&, // CameraLocation
595 const ON_3dVector&, // unit CameraX vector (right)
596 const ON_3dVector&, // unit CameraY vector (up)
597 const ON_3dVector& // unit CameraZ vector (from screen to camera)
598 );
599 bool CameraToClip( // maps viewport frustum to -1 <= x,y,z <= 1 box
600 ON_BOOL32, // true for perspective, false for orthographic
601 double, double, // left != right (usually left < right )
602 double, double, // bottom != top (usually bottom < top )
603 double, double // near != far (usually 0 < near < far )
604 );
605
606 // maps -1 <= x,y,z <= 1 box to viewport frustum
607 bool ClipToCamera(
608 int, // true for perspective, false for orthographic
609 double, double, // left != right (usually left < right )
610 double, double, // bottom != top (usually bottom < top )
611 double, double // near != far an bot are non-zero (usually 0 < near < far )
612 );
613
614 // Computes transform that maps the clipping box
615 //
616 // -1<x<1,-1<y<1,-1<z<1
617 //
618 // to the screen box
619 //
620 // (left,right) X (bottom,top) X (near,far)
621 bool ClipToScreen(
622 double, // left
623 double, // right
624 double, // bottom
625 double, // top
626 double, // near_z
627 double // far_z
628 );
629
630 // Computes transform that maps the screen box
631 //
632 // (left,right) X (bottom,top) X (near,far)
633 //
634 // to the clipping box
635 //
636 // -1<x<1,-1<y<1,-1<z<1
637 bool ScreenToClip(
638 double, // left
639 double, // right
640 double, // bottom
641 double, // top
642 double, // near_z
643 double // far_z
644 );
645
646 // Description: Computes homogeneous point clipping flags and
647 // returns an int with bits set to indicate if the point
648 // is outside of the clipping box.
649 //
650 // Parameters:
651 // point - [in] 4d homogeneous clipping coordinate point
652 //
653 // Returns:
654 // @table
655 // bit point location
656 // 1 x/w < -1
657 // 2 x/w > +1
658 // 4 y/w < -1
659 // 8 y/w > +1
660 // 16 z/w < -1
661 // 32 z/w > +1
662 //
663 int ClipFlag4d(
664 const double* // point
665 ) const;
666
667 // Parameters:
668 // count - [in] number of 4d points
669 // stride - [in] (>=4)
670 // points - [in] 4d clipping coordinate points
671 // (array of stride*count doubles)
672 // bTestZ - [in] (default=true) if false, do not test "z" coordinate
673 //
674 int ClipFlag4d(
675 int, // count
676 int, // stride
677 const double*, // points
678 ON_BOOL32 = true // bTeztZ
679 ) const;
680
681 // Description:
682 // Computes 3d point clipping flags and
683 // returns an int with bits set to indicate if the point
684 // is outside of the clipping box.
685 //
686 // Parameters:
687 // point - [in] 3d clipping coordinate point
688 //
689 // Returns:
690 // @table
691 // bit point location
692 // 1 x < -1
693 // 2 x > +1
694 // 4 y < -1
695 // 8 y > +1
696 // 16 z < -1
697 // 32 z > +1
698 int ClipFlag3d(
699 const double* // point
700 ) const;
701
702 // Parameters:
703 // count - [in] number of 3d points
704 // stride - [in] (>=3)
705 // points - [in] 3d clipping coordinate points (array of stride*count doubles)
706 // bTestZ - [in] (default=true) if false, do not test "z" coordinate
707 //
708 int ClipFlag3d(
709 int, // count
710 int, // stride
711 const double*, // points
712 ON_BOOL32 = true // bTestZ
713 ) const;
714
715 // Description: Computes 3d clipping flags for a 3d bounding
716 // box and returns an int with bits set to indicate if
717 // the bounding box is outside of the clipping box.
718 //
719 // Parameters:
720 // boxmin - [in] 3d boxmin corner
721 // boxmax - [in] 3d boxmax corner
722 //
723 // Returns:
724 // @table
725 // bit box location
726 // 1 boxmax x < -1
727 // 2 boxmin x > +1
728 // 4 boxmax y < -1
729 // 8 boxmin y > +1
730 // 16 boxmax z < -1
731 // 32 boxmin z > +1
732 int ClipFlag3dBox(
733 const double*, // boxmin
734 const double* // boxmax
735 ) const;
736
737
738 /*
739 Description:
740 Calculates the transformation that linearly maps
741 old_interval to new_interval.
742 Parameters:
743 dir - [in] 0 = x, 1 = y, 2= z;
744 old_interval - [in]
745 new_interval - [in]
746 */
747 bool IntervalChange(
748 int dir,
749 ON_Interval old_interval,
750 ON_Interval new_interval
751 );
752};
753
755{
756public:
758
759 // The transformation m_xform transforms the view frustum,
760 // in object coordinates to the (-1,+1)^3 clipping
761 // coordinate box.
763
764 enum
765 {
766 max_clip_plane_count = 16, // must be <= 25
767 frustum_bitmask = 0x0000003F,
768 near_plane_bitmask = 0x00000020,
769 far_plane_bitmask = 0x00000010,
770 clip_plane_bitmask = 0x7FFFFFC0,
771 negw_bitmask = 0x80000000
772 };
773
774 // Up to 25 additional clipping planes in object coordinates.
775 // The convex region that is the intersection of the positive
776 // side of these planes is the active region.
777 int m_clip_plane_count; // (0 <= m_clip_plane_count <= max_clip_plane_count)
778 ON_PlaneEquation m_clip_plane[max_clip_plane_count];
779
780 /*
781 Description:
782 The "view frustum" is the frustum the m_xform transformation
783 maps to clipping coordinate box (-1,+1)^3. These functions
784 determine if some portion of the convex hull of the test points
785 is inside the view frustum.
786 Parameters:
787 P - [in] point
788 box - [in] bounding box
789 count - [in] number of points
790 p - [in] array of points
791 bEnableClippingPlanes - [in]
792 If true, then the additional clipping planes are tested.
793 If false, then the additional clipping planes are ignored.
794 Returns:
795 0 = No part of the of the convex hull of the tested points
796 is in the view frustum.
797 1 = A portion of the convex hull of the otested points may
798 be in the view frustum.
799 2 = The entire convex hull of the tested points is in the
800 view frustum.
801 */
802 int InViewFrustum(
803 ON_3dPoint P
804 ) const;
805 int InViewFrustum(
806 const ON_BoundingBox& bbox
807 ) const;
808 int InViewFrustum(
809 int count,
810 const ON_3fPoint* p
811 ) const;
812 int InViewFrustum(
813 int count,
814 const ON_3dPoint* p
815 ) const;
816 int InViewFrustum(
817 int count,
818 const ON_4dPoint* p
819 ) const;
820
821 /*
822 Description:
823 The "clip plane region" is the convex hull of the planes in
824 the m_clip_plane[] array. These functions determine if
825 some portion of the convex hull of the test points is inside
826 the clip plane region.
827 Parameters:
828 P - [in] point
829 box - [in] bounding box
830 count - [in] number of points
831 p - [in] array of points
832 bEnableClippingPlanes - [in]
833 If true, then the additional clipping planes are tested.
834 If false, then the additional clipping planes are ignored.
835 Returns:
836 0 = No part of the of the convex hull of the tested points
837 is in the clip plane region.
838 1 = A portion of the convex hull of the tested points may
839 be in the clip plane region.
840 2 = The entire convex hull of the tested points is in the
841 clip plane region.
842 */
843 int InClipPlaneRegion(
844 ON_3dPoint P
845 ) const;
846 int InClipPlaneRegion(
847 const ON_BoundingBox& bbox
848 ) const;
849 int InClipPlaneRegion(
850 int count,
851 const ON_3fPoint* p
852 ) const;
853 int InClipPlaneRegion(
854 int count,
855 const ON_3dPoint* p
856 ) const;
857 int InClipPlaneRegion(
858 int count,
859 const ON_4dPoint* p
860 ) const;
861
862
863 /*
864 Description:
865 The "visible area" is the intersection of the view frustum,
866 defined by m_xform, and the clipping region, defined by the
867 m_clip_plane[] array. These functions determing if some
868 portion of the convex hull of the test points is visible.
869 Parameters:
870 P - [in] point
871 box - [in] bounding box
872 count - [in] number of points
873 p - [in] array of points
874 Returns:
875 0 = no part of the object is in the region.
876 1 = a portion of the object is in the region
877 2 = entire object is in clipping region
878 */
879 int IsVisible(
880 ON_3dPoint P
881 ) const;
882 int IsVisible(
883 const ON_BoundingBox& bbox
884 ) const;
885 int IsVisible(
886 int count,
887 const ON_3fPoint* p
888 ) const;
889 int IsVisible(
890 int count,
891 const ON_3dPoint* p
892 ) const;
893 int IsVisible(
894 int count,
895 const ON_4dPoint* p
896 ) const;
897
898 /*
899 Description:
900 Transform a list of 4d homogenous points while testing
901 for visibility.
902 Parameters:
903 count - [in] number of points
904 p - [in/out] array of points to test and transform
905 If 0 is returned, some of the points may not
906 be transformed. In all other cases, the output
907 points are transformed by m_xform.
908 pflags - [out]
909 0 when the point is in the visible region.
910 Otherwise the bits are set to indicate which planes clip the
911 intput point.
912 0x01 left of the view frusturm
913 0x02 right of the view frustum
914 0x04 below the view frustum
915 0x08 above the view frustum
916 0x10 behind the view frustum (too far)
917 0x20 in front of the view frustum (too near)
918
919 0x10 below m_clip_plane[0]
920 0x20 below m_clip_plane[1]
921 ...
922 0x40000000 below m_clip_plane[24]
923
924 0x80000000 transformation created a non-positive weight
925 Returns:
926 0 = convex hull of the points is not in the region.
927 The m_cull_bits field reports which plane or planes
928 culled the point set.
929 1 = a portion of the convex hull is in the region.
930 The m_cull_bits field reports which plane or planes
931 culled the point set.
932 2 = all points are in the region.
933 The m_cull_bits field will be zero.
934 */
935 int TransformPoints( int count, ON_4dPoint* p ) const;
936 int TransformPoints( int count, ON_4dPoint* p, unsigned int* pflags ) const;
937
938
939 /*
940 Description:
941 Transform a pont and return the clipping information.
942 Parameters:
943 P - [in] point ot transform
944 Q - [out] transformed point
945 Returns:
946 0 when the point is in the visible region.
947 Otherwise the bits are set to indicate which planes clip the
948 intput point.
949 0x01 left of the view frusturm
950 0x02 right of the view frustum
951 0x04 below the view frustum
952 0x08 above the view frustum
953 0x10 behind the view frustum (too far)
954 0x20 in front of the view frustum (too near)
955
956 0x10 below m_clip_plane[0]
957 0x20 below m_clip_plane[1]
958 ...
959 0x40000000 below m_clip_plane[24]
960
961 0x80000000 transformation created a non-positive weight
962 */
963 unsigned int TransformPoint(
964 const ON_4dPoint& P,
965 ON_4dPoint& Q
966 ) const;
967 unsigned int TransformPoint(
968 const ON_3dPoint& P,
969 ON_3dPoint& Q
970 ) const;
971 unsigned int TransformPoint(
972 const ON_3fPoint& P,
973 ON_3dPoint& Q
974 ) const;
975
976 /*
977 Description:
978 Calculate the interval for the segment of a line that
979 is in the clip plane region.
980 Parameters:
981 P0 - [in] start point
982 P1 - [in] end point
983 t0 - [out] start parameter
984 t1 - [out] end parameter
985 Returns:
986 True if some portion of the line is visible and
987 0.0 <= *t0 <= *t1 <= 1.0.
988 */
989 bool GetLineClipPlaneParamters(
990 ON_4dPoint P0,
991 ON_4dPoint P1,
992 double* t0,
993 double* t1
994 ) const;
995
996};
997
998
1000{
1001public:
1002 ON_Localizer();
1003 ~ON_Localizer();
1004
1005 ON_Localizer(const ON_Localizer&);
1006 ON_Localizer& operator=(const ON_Localizer&);
1007
1008 void Destroy();
1009 bool Read(ON_BinaryArchive&);
1010 bool Write(ON_BinaryArchive&) const;
1011
1012 /*
1013 Descrption:
1014 Creates a cylindrical localizer.
1015 If d = distance from the point to the line,
1016 then the localizer has the following behavior:
1017
1018 point distance localizer value
1019 d <= r0 < r1 or d >= r0 > r1 0
1020 d >= r1 > r0 or d <= r1 < r0 1
1021
1022 For values of d between r0 and r1, the localizer
1023 smoothly transitions between 0 to 1.
1024
1025 Parameters:
1026 P - [in] cylinder axis point
1027 D - [in] cylinder axis direction
1028 r0 - [in]
1029 r1 - [in]
1030 r0 and r1 are radii that control where the localizer is nonzero.
1031 Both r0 and r1 must be postive and the cannot be equal.
1032 If 0 < r0 < r1, then the localizer is zero for points
1033 inside the cylinder of radius r0 and one for points outside
1034 the cylinder of radius r1.
1035 If 0 < r1 < r0, then the localizer is one for points
1036 inside the cylinder of radius r1 and zero for points outside
1037 the cylinder of radius r0.
1038
1039 Returns:
1040 True if the input is value and the localizer is initialized.
1041 */
1042 bool CreateCylinderLocalizer( ON_3dPoint P, ON_3dVector D, double r0, double r1 );
1043
1044 /*
1045 Descrption:
1046 Creates a planar localizer.
1047 If d = signed distance from the point to the plane,
1048 then the localizer has the following behavior:
1049
1050 point distance localizer value
1051 d <= h0 < h1 or d >= h0 > h1 0
1052 d >= h1 > h0 or d <= h1 < h0 1
1053
1054 For values of d between h0 and h1, the localizer
1055 smoothly transitions between 0 to 1.
1056
1057 Parameters:
1058 P - [in] point on plane
1059 N - [in] normal to plane
1060 h0 - [in]
1061 h1 - [in]
1062 h0 and h1 are signed distances that control where the
1063 localizer is nonzero.
1064
1065 Returns:
1066 True if the input is value and the localizer is initialized.
1067 */
1068 bool CreatePlaneLocalizer( ON_3dPoint P, ON_3dVector N, double h0, double h1 );
1069
1070 /*
1071 Descrption:
1072 Creates a spherical localizer.
1073 If d = distance from the point to the center of the sphere,
1074 then the localizer has the following behavior:
1075
1076 point distance localizer value
1077 d <= r0 < r1 or d >= r0 > r1 0
1078 d >= r1 > r0 or d <= r1 < r0 1
1079
1080 For values of d between r0 and r1, the localizer
1081 smoothly transitions between 0 to 1.
1082
1083 Parameters:
1084 P - [in] center of sphere
1085 r0 - [in]
1086 r1 - [in]
1087 r0 and r1 are radii that control where the localizer is nonzero.
1088 Both r0 and r1 must be postive and the cannot be equal.
1089 If 0 < r0 < r1, then the localizer is zero for points
1090 inside the cylinder of radius r0 and one for points outside
1091 the cylinder of radius r1.
1092 If 0 < r1 < r0, then the localizer is one for points
1093 inside the cylinder of radius r1 and zero for points outside
1094 the cylinder of radius r0.
1095
1096 Returns:
1097 True if the input is value and the localizer is initialized.
1098 */
1099 bool CreateSphereLocalizer( ON_3dPoint P, double r0, double r1 );
1100
1101 /*
1102 Description:
1103 Evaluators.
1104 Parameters:
1105 P - [in]
1106 Evaluation point
1107 distance - [in]
1108 Evaluation distance
1109 Returns:
1110 Value of the localizer.
1111 */
1112 double Value(ON_3dPoint P) const;
1113 double Value(double distance) const;
1114
1115 /*
1116 Parameters:
1117 bbox - [in]
1118 Returns:
1119 True if localizer is identically zero inside bbox.
1120 */
1121 bool IsZero( const ON_BoundingBox& bbox ) const;
1122
1123 enum TYPE
1124 {
1125 no_type = 0,
1126 sphere_type = 1,
1127 plane_type = 2,
1128 cylinder_type = 3,
1129 curve_type = 4,
1130 surface_type = 5,
1131 distance_type = 6,
1132 force_32bit_localizer_type = 0xFFFFFFFF
1134
1136
1142};
1143
1144
1146{
1147public:
1148 ON_SpaceMorph();
1149 virtual ~ON_SpaceMorph();
1150
1151 /*
1152 Description:
1153 Morphs euclidean point.
1154 Parameters:
1155 point - [in]
1156 Returns:
1157 Morphed point.
1158 Remarks:
1159 If you are morphing simple objects like points and
1160 meshes, then you can simply morph the locations.
1161 If you are morphing more complicated objects like
1162 NURBS geometry, then your override should
1163 pay attention to the values of m_bQuickPreview,
1164 m_bPreserveStructure, and m_tolerance.
1165 */
1166 virtual
1168 ON_3dPoint point
1169 ) const = 0;
1170
1171 /*
1172 Description:
1173 Get the first derivative of the morph function.
1174 Parameters:
1175 rst - [in] evalation parameters
1176 Dr - [out] (dx/dr, dy/dr, dz/dr)
1177 Ds - [out] (dx/ds, dy/ds, dz/ds)
1178 Dt - [out] (dx/dt, dy/dt, dz/dt)
1179 Returns:
1180 True if successful.
1181 */
1182 virtual
1183 bool Ev1Der(
1184 ON_3dPoint rst,
1185 ON_3dPoint& xyz,
1186 ON_3dVector& Dr,
1187 ON_3dVector& Ds,
1188 ON_3dVector& Dt
1189 ) const;
1190
1191
1192
1193 /*
1194 Description:
1195 Provides a quick way to determine if a morph function
1196 is the identity (doesn't move the points) on a region
1197 of space.
1198 Parameters:
1199 bbox - [in] region of space to test.
1200 Returns:
1201 The default always returns false. If you override
1202 this function, then return true when every point
1203 in the bounding box is fixed by the morph.
1204 */
1205 virtual
1206 bool IsIdentity( const ON_BoundingBox& bbox ) const;
1207
1208 /*
1209 Description:
1210 Morphs rational point.
1211 Parameters:
1212 point - [in]
1213 Returns:
1214 Morphed point.
1215 Remarks:
1216 Default morphs euclidean location and preserves weight.
1217 */
1218 virtual
1219 ON_4dPoint MorphPoint(
1220 ON_4dPoint point
1221 ) const;
1222
1223 /*
1224 Description:
1225 Morphs vector.
1226 Parameters:
1227 tail_point - [in] tail point
1228 vector - [in]
1229 Returns:
1230 Morphed vector.
1231 Remakrs:
1232 Default returns difference of morphed tail+vector and tail.
1233 */
1234 virtual
1235 ON_3dVector MorphVector(
1236 ON_3dPoint tail_point,
1237 ON_3dVector vector
1238 ) const;
1239
1240 /*
1241 Description:
1242 Morphs point list
1243 Parameters:
1244 dim - [in]
1245 is_rat - [in]
1246 count - [in]
1247 stride - [in]
1248 point - [in/out]
1249 */
1250 void MorphPointList(
1251 int dim,
1252 int is_rat,
1253 int count,
1254 int stride,
1255 double* point
1256 ) const;
1257
1258 /*
1259 Description:
1260 Morphs point list
1261 Parameters:
1262 dim - [in]
1263 is_rat - [in]
1264 count - [in]
1265 stride - [in]
1266 point - [in/out]
1267 */
1268 void MorphPointList(
1269 int dim,
1270 int is_rat,
1271 int count,
1272 int stride,
1273 float* point
1274 ) const;
1275
1276 /*
1277 Description:
1278 Returns the desired accuracy of the morph.
1279 This value is primarily used for deforming
1280 surfaces and breps.
1281 Returns:
1282 3d fitting tolerance.
1283 Remarks:
1284 The default is 0.0 and any value <= 0.0 is
1285 ignored by morphing functions.
1286 The value returned by Tolerance() does not
1287 affect the way meshes and points are morphed.
1288 */
1289 double Tolerance() const;
1290
1291 /*
1292 Description:
1293 Set the 3d fitting tolerance used when morphing
1294 surfaces and breps.
1295 Parameters:
1296 tolerance - [in] values < 0.0 are treated as 0.0.
1297 */
1298 void SetTolerance(
1299 double tolerance
1300 );
1301
1302 /*
1303 Returns:
1304 True if the morph should be done as quickly as
1305 possible because the result is being used for
1306 some type of dynamic preview. If QuickPreview
1307 is true, the tolerance may be ignored.
1308 Remarks:
1309 The value returned by QuickPreview() does not
1310 affect the way meshes and points are morphed.
1311 The default is false.
1312 */
1313 bool QuickPreview() const;
1314
1315 /*
1316 Description:
1317 Set the quick preview value.
1318 Parameters:
1319 bQuickPreview - [in]
1320 */
1321 void SetQuickPreview(
1322 bool bQuickPreview
1323 );
1324
1325 /*
1326 Returns:
1327 True if the morph should be done in a way that
1328 preserves the structure of the geometry.
1329 In particular, for NURBS objects, true
1330 means that only the control points are moved.
1331 Remarks:
1332 The value returned by PreserveStructure() does not
1333 affect the way meshes and points are morphed.
1334 The default is false.
1335 */
1336 bool PreserveStructure() const;
1337
1338 /*
1339 Description:
1340 Set the preserve structure value.
1341 Parameters:
1342 bPreserveStructure - [in]
1343 */
1344 void SetPreserveStructure(
1345 bool bPreserveStructure
1346 );
1347
1348private:
1352};
1353
1354#if defined(ON_DLL_TEMPLATE)
1355
1356// This stuff is here because of a limitation in the way Microsoft
1357// handles templates and DLLs. See Microsoft's knowledge base
1358// article ID Q168958 for details.
1359#pragma warning( push )
1360#pragma warning( disable : 4231 )
1361ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Xform>;
1362ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Localizer>;
1363#pragma warning( pop )
1364#endif
1365
1366#endif
Mirrors selected entities.
Definition Mirror.js:11
Definition opennurbs_point.h:253
Definition opennurbs_point.h:655
Definition opennurbs_point.h:403
Definition opennurbs_point.h:931
Definition opennurbs_fpoint.h:172
Definition opennurbs_point.h:555
Definition opennurbs_archive.h:152
Definition opennurbs_bounding_box.h:25
Definition opennurbs_array.h:760
Definition opennurbs_xform.h:755
ON_Xform m_xform
Definition opennurbs_xform.h:762
int m_clip_plane_count
Definition opennurbs_xform.h:777
Definition opennurbs_point.h:46
Definition opennurbs_xform.h:1000
TYPE
Definition opennurbs_xform.h:1124
class ON_NurbsCurve * m_nurbs_curve
Definition opennurbs_xform.h:1140
ON_3dPoint m_P
Definition opennurbs_xform.h:1138
TYPE m_type
Definition opennurbs_xform.h:1135
class ON_NurbsSurface * m_nurbs_surface
Definition opennurbs_xform.h:1141
ON_Interval m_d
Definition opennurbs_xform.h:1137
ON_3dVector m_V
Definition opennurbs_xform.h:1139
Definition opennurbs_matrix.h:22
Definition opennurbs_nurbscurve.h:27
Definition opennurbs_nurbssurface.h:62
Definition opennurbs_point.h:1169
Definition opennurbs_plane.h:20
Definition opennurbs_array.h:46
Definition opennurbs_xform.h:1146
bool m_bQuickPreview
Definition opennurbs_xform.h:1350
bool m_bPreserveStructure
Definition opennurbs_xform.h:1351
double m_tolerance
Definition opennurbs_xform.h:1349
virtual ON_3dPoint MorphPoint(ON_3dPoint point) const =0
Definition opennurbs_xform.h:28
Scales selected entities.
Definition Scale.js:11
#define ON_CLASS
Definition opennurbs_defines.h:91
ON_DECL ON_2fPoint operator*(int, const ON_2fPoint &)
Definition opennurbs_point.cpp:1718
#define N
Definition opennurbs_rand.cpp:70
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362