VTK  9.0.20201201
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 =========================================================================*/
25 #ifndef vtkPlane_h
26 #define vtkPlane_h
27 
28 #include "vtkCommonDataModelModule.h" // For export macro
29 #include "vtkImplicitFunction.h"
30 
31 class vtkPoints; // forward declaration
32 
33 class VTKCOMMONDATAMODEL_EXPORT vtkPlane : public vtkImplicitFunction
34 {
35 public:
39  static vtkPlane* New();
40 
41  vtkTypeMacro(vtkPlane, vtkImplicitFunction);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
45 
49  void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
50  double EvaluateFunction(double x[3]) override;
52 
56  void EvaluateGradient(double x[3], double g[3]) override;
57 
59 
62  vtkSetVector3Macro(Normal, double);
63  vtkGetVectorMacro(Normal, double, 3);
65 
67 
71  vtkSetVector3Macro(Origin, double);
72  vtkGetVectorMacro(Origin, double, 3);
74 
80  void Push(double distance);
81 
83 
88  static void ProjectPoint(
89  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
90  void ProjectPoint(const double x[3], double xproj[3]);
92 
94 
98  static void ProjectVector(
99  const double v[3], const double origin[3], const double normal[3], double vproj[3]);
100  void ProjectVector(const double v[3], double vproj[3]);
102 
104 
109  static void GeneralizedProjectPoint(
110  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
111  void GeneralizedProjectPoint(const double x[3], double xproj[3]);
113 
117  static double Evaluate(double normal[3], double origin[3], double x[3]);
118 
120 
124  static double DistanceToPlane(double x[3], double n[3], double p0[3]);
125  double DistanceToPlane(double x[3]);
127 
129 
137  static int IntersectWithLine(
138  const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
139  int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
141 
143 
153  static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
154  double py[3], double x0[3], double x1[3]);
155  int IntersectWithFinitePlane(
156  double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
158 
160 
167  static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
169 
170 protected:
171  vtkPlane();
172  ~vtkPlane() override = default;
173 
174  double Normal[3];
175  double Origin[3];
176 
177 private:
178  vtkPlane(const vtkPlane&) = delete;
179  void operator=(const vtkPlane&) = delete;
180 };
181 
182 // Generally the normal should be normalized
183 inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
184 {
185  return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
186  normal[2] * (x[2] - origin[2]);
187 }
188 
189 // Assumes normal is normalized
190 inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
191 {
192 #define vtkPlaneAbs(x) ((x) < 0 ? -(x) : (x))
193  return (vtkPlaneAbs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
194 }
195 
196 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkPlane
perform various plane computations
Definition: vtkPlane.h:33
vtkPlane::Evaluate
static double Evaluate(double normal[3], double origin[3], double x[3])
Quick evaluation of plane equation n(x-origin)=0.
Definition: vtkPlane.h:183
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkX3D::Normal
Definition: vtkX3D.h:51
vtkImplicitFunction::EvaluateFunction
virtual double EvaluateFunction(double x[3])=0
Evaluate function at position x-y-z and return value.
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkPlaneAbs
#define vtkPlaneAbs(x)
vtkImplicitFunction
abstract interface for implicit functions
Definition: vtkImplicitFunction.h:60
vtkPlane::DistanceToPlane
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:190
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkImplicitFunction::EvaluateGradient
virtual void EvaluateGradient(double x[3], double g[3])=0
Evaluate function gradient at position x-y-z and pass back vector.
vtkImplicitFunction.h
vtkImplicitFunction::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.