OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkPlane.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkPlane.h,v $
5   Language:  C++
6   Date:      $Date: 2003/01/06 20:36:14 $
7   Version:   $Revision: 1.50 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
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.
16
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.
24
25 #ifndef __vtkPlane_h
26 #define __vtkPlane_h
27
28 #include "vtkImplicitFunction.h"
29
30 class VTK_COMMON_EXPORT vtkPlane : public vtkImplicitFunction
31 {
32 public:
33   // Description
34   // Construct plane passing through origin and normal to z-axis.
35   static vtkPlane *New();
36
37   vtkTypeRevisionMacro(vtkPlane,vtkImplicitFunction);
38   void PrintSelf(ostream& os, vtkIndent indent);
39
40   // Description
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); } ;
45
46   // Description
47   // Evaluate function gradient at point x[3].
48   void EvaluateGradient(float x[3], float g[3]);
49
50   // Description:
51   // Set/get plane normal. Plane is defined by point and normal.
52   vtkSetVector3Macro(Normal,float);
53   vtkGetVectorMacro(Normal,float,3);
54
55   // Description:
56   // Set/get point through which plane passes. Plane is defined by point 
57   // and normal.
58   vtkSetVector3Macro(Origin,float);
59   vtkGetVectorMacro(Origin,float,3);
60
61   // Description:
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);
66
67   // Description
68   // Project a point x onto plane defined by origin and normal. The 
69   // projected point is returned in xproj. NOTE : normal assumed to
70   // have magnitude 1.
71   static void ProjectPoint(float x[3], float origin[3], float normal[3], 
72                            float xproj[3]);
73   static void ProjectPoint(double x[3], double origin[3], double normal[3], 
74                            double xproj[3]);
75
76   // Description
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 
79   // have magnitude 1.
80   static void GeneralizedProjectPoint(float x[3], float origin[3],
81                                       float normal[3], float xproj[3]);
82   
83   // Description:
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]);
87
88   // Description:
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]);
92   
93   // Description:
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
98   // are parallel.
99   static int IntersectWithLine(float p1[3], float p2[3], float n[3], 
100                                float p0[3], float& t, float x[3]);
101
102
103 protected:
104   vtkPlane();
105   ~vtkPlane() {};
106
107   float Normal[3];
108   float Origin[3];
109
110 private:
111   vtkPlane(const vtkPlane&);  // Not implemented.
112   void operator=(const vtkPlane&);  // Not implemented.
113 };
114
115 inline float vtkPlane::Evaluate(float normal[3], float origin[3], float x[3])
116 {
117   return normal[0]*(x[0]-origin[0]) + normal[1]*(x[1]-origin[1]) + 
118          normal[2]*(x[2]-origin[2]);
119 }
120 inline float vtkPlane::Evaluate(double normal[3], double origin[3],double x[3])
121 {
122   return static_cast<float> (normal[0]*(x[0]-origin[0]) + normal[1]*(x[1]-origin[1]) + 
123          normal[2]*(x[2]-origin[2]));
124 }
125
126 inline float vtkPlane::DistanceToPlane(float x[3], float n[3], float p0[3])
127 {
128 #define vtkPlaneAbs(x) ((x)<0?-(x):(x))
129   return ((float) vtkPlaneAbs(n[0]*(x[0]-p0[0]) + n[1]*(x[1]-p0[1]) + 
130                               n[2]*(x[2]-p0[2])));
131 }
132
133 #endif
134
135