VTK  9.2.5
vtkPlane.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPlane.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
137 #ifndef vtkPlane_h
138 #define vtkPlane_h
139 
140 #include "vtkCommonDataModelModule.h" // For export macro
141 #include "vtkImplicitFunction.h"
142 
143 class vtkPoints; // forward declaration
144 
145 class VTKCOMMONDATAMODEL_EXPORT vtkPlane : public vtkImplicitFunction
146 {
147 public:
151  static vtkPlane* New();
152 
154  void PrintSelf(ostream& os, vtkIndent indent) override;
155 
157 
161  void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
162  double EvaluateFunction(double x[3]) override;
164 
168  void EvaluateGradient(double x[3], double g[3]) override;
169 
171 
174  vtkSetVector3Macro(Normal, double);
175  vtkGetVectorMacro(Normal, double, 3);
177 
179 
183  vtkSetVector3Macro(Origin, double);
184  vtkGetVectorMacro(Origin, double, 3);
186 
192  void Push(double distance);
193 
195 
200  static void ProjectPoint(
201  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
202  void ProjectPoint(const double x[3], double xproj[3]);
204 
206 
210  static void ProjectVector(
211  const double v[3], const double origin[3], const double normal[3], double vproj[3]);
212  void ProjectVector(const double v[3], double vproj[3]);
214 
216 
222  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
223  void GeneralizedProjectPoint(const double x[3], double xproj[3]);
225 
229  static double Evaluate(double normal[3], double origin[3], double x[3]);
230 
232 
236  static double DistanceToPlane(double x[3], double n[3], double p0[3]);
237  double DistanceToPlane(double x[3]);
239 
241 
249  static int IntersectWithLine(
250  const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
251  int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
253 
255 
265  static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
266  double py[3], double x0[3], double x1[3]);
268  double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
270 
272 
279  static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
281 
282 protected:
284  ~vtkPlane() override = default;
285 
286  double Normal[3];
287  double Origin[3];
288 
289 private:
290  vtkPlane(const vtkPlane&) = delete;
291  void operator=(const vtkPlane&) = delete;
292 };
293 
294 // Generally the normal should be normalized
295 inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
296 {
297  return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
298  normal[2] * (x[2] - origin[2]);
299 }
300 
301 // Assumes normal is normalized
302 inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
303 {
304 #define vtkPlaneAbs(x) ((x) < 0 ? -(x) : (x))
305  return (vtkPlaneAbs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
306 }
307 
308 #endif
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:165
abstract interface for implicit functions
virtual double EvaluateFunction(double x[3])=0
Evaluate function at position x-y-z and return value.
a simple class to control print indentation
Definition: vtkIndent.h:119
perform various plane computations
Definition: vtkPlane.h:146
double DistanceToPlane(double x[3])
Return the distance of a point x to a plane defined by n(x-p0) = 0.
void GeneralizedProjectPoint(const double x[3], double xproj[3])
Project a point x onto plane defined by origin and normal.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void ProjectVector(const double v[3], const double origin[3], const double normal[3], double vproj[3])
Project a vector v onto plane defined by origin and normal.
void ProjectPoint(const double x[3], double xproj[3])
Project a point x onto plane defined by origin and normal.
~vtkPlane() override=default
void Push(double distance)
Translate the plane in the direction of the normal by the distance specified.
int IntersectWithLine(const double p1[3], const double p2[3], double &t, double x[3])
Given a line defined by the two points p1,p2; and a plane defined by the normal n and point p0,...
void EvaluateGradient(double x[3], double g[3]) override
Evaluate function gradient at point x[3].
int IntersectWithFinitePlane(double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3])
Given two planes, one infinite and one finite, defined by the normal n and point o (infinite plane),...
static void GeneralizedProjectPoint(const double x[3], const double origin[3], const double normal[3], double xproj[3])
Project a point x onto plane defined by origin and normal.
static bool ComputeBestFittingPlane(vtkPoints *pts, double *origin, double *normal)
Given a set of points calculate the best-fitting origin and normal for the plane.
static double Evaluate(double normal[3], double origin[3], double x[3])
Quick evaluation of plane equation n(x-origin)=0.
Definition: vtkPlane.h:295
static double DistanceToPlane(double x[3], double n[3], double p0[3])
Return the distance of a point x to a plane defined by n(x-p0) = 0.
Definition: vtkPlane.h:302
double EvaluateFunction(double x[3]) override
Evaluate plane equation for point x[3].
static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3])
Given two planes, one infinite and one finite, defined by the normal n and point o (infinite plane),...
static vtkPlane * New()
Construct plane passing through origin and normal to z-axis.
static int IntersectWithLine(const double p1[3], const double p2[3], double n[3], double p0[3], double &t, double x[3])
Given a line defined by the two points p1,p2; and a plane defined by the normal n and point p0,...
void ProjectVector(const double v[3], double vproj[3])
Project a vector v onto plane defined by origin and normal.
void EvaluateFunction(vtkDataArray *input, vtkDataArray *output) override
Evaluate plane equation for point x[3].
static void ProjectPoint(const double x[3], const double origin[3], const double normal[3], double xproj[3])
Project a point x onto plane defined by origin and normal.
represent and manipulate 3D points
Definition: vtkPoints.h:149
@ Normal
Definition: vtkX3D.h:51
#define vtkPlaneAbs(x)