1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkPlane.h,v $
6 Date: $Date: 2003/01/06 20:36:14 $
7 Version: $Revision: 1.50 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkPlane - perform various plane computations
19 // .SECTION Description
20 // vtkPlane provides methods for various plane computations. These include
21 // projecting points onto a plane, evaluating the plane equation, and
22 // returning plane normal. vtkPlane is a concrete implementation of the
23 // abstract class vtkImplicitFunction.
28 #include "vtkImplicitFunction.h"
30 class VTK_COMMON_EXPORT vtkPlane : public vtkImplicitFunction
34 // Construct plane passing through origin and normal to z-axis.
35 static vtkPlane *New();
37 vtkTypeRevisionMacro(vtkPlane,vtkImplicitFunction);
38 void PrintSelf(ostream& os, vtkIndent indent);
41 // Evaluate plane equation for point x[3].
42 float EvaluateFunction(float x[3]);
43 float EvaluateFunction(float x, float y, float z)
44 {return this->vtkImplicitFunction::EvaluateFunction(x, y, z); } ;
47 // Evaluate function gradient at point x[3].
48 void EvaluateGradient(float x[3], float g[3]);
51 // Set/get plane normal. Plane is defined by point and normal.
52 vtkSetVector3Macro(Normal,float);
53 vtkGetVectorMacro(Normal,float,3);
56 // Set/get point through which plane passes. Plane is defined by point
58 vtkSetVector3Macro(Origin,float);
59 vtkGetVectorMacro(Origin,float,3);
62 // Translate the plane in the direction of the normal by the
63 // distance specified. Negative values move the plane in the
64 // opposite direction.
65 void Push(float distance);
68 // Project a point x onto plane defined by origin and normal. The
69 // projected point is returned in xproj. NOTE : normal assumed to
71 static void ProjectPoint(float x[3], float origin[3], float normal[3],
73 static void ProjectPoint(double x[3], double origin[3], double normal[3],
77 // Project a point x onto plane defined by origin and normal. The
78 // projected point is returned in xproj. NOTE : normal does NOT have to
80 static void GeneralizedProjectPoint(float x[3], float origin[3],
81 float normal[3], float xproj[3]);
84 // Quick evaluation of plane equation n(x-origin)=0.
85 static float Evaluate(float normal[3], float origin[3], float x[3]);
86 static float Evaluate(double normal[3], double origin[3], double x[3]);
89 // Return the distance of a point x to a plane defined by n(x-p0) = 0. The
90 // normal n[3] must be magnitude=1.
91 static float DistanceToPlane(float x[3], float n[3], float p0[3]);
94 // Given a line defined by the two points p1,p2; and a plane defined by the
95 // normal n and point p0, compute an intersection. The parametric
96 // coordinate along the line is returned in t, and the coordinates of
97 // intersection are returned in x. A zero is returned if the plane and line
99 static int IntersectWithLine(float p1[3], float p2[3], float n[3],
100 float p0[3], float& t, float x[3]);
111 vtkPlane(const vtkPlane&); // Not implemented.
112 void operator=(const vtkPlane&); // Not implemented.
115 inline float vtkPlane::Evaluate(float normal[3], float origin[3], float x[3])
117 return normal[0]*(x[0]-origin[0]) + normal[1]*(x[1]-origin[1]) +
118 normal[2]*(x[2]-origin[2]);
120 inline float vtkPlane::Evaluate(double normal[3], double origin[3],double x[3])
122 return static_cast<float> (normal[0]*(x[0]-origin[0]) + normal[1]*(x[1]-origin[1]) +
123 normal[2]*(x[2]-origin[2]));
126 inline float vtkPlane::DistanceToPlane(float x[3], float n[3], float p0[3])
128 #define vtkPlaneAbs(x) ((x)<0?-(x):(x))
129 return ((float) vtkPlaneAbs(n[0]*(x[0]-p0[0]) + n[1]*(x[1]-p0[1]) +