VTK  9.3.1
vtkPlane.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
16 #ifndef vtkPlane_h
17 #define vtkPlane_h
18 
19 #include "vtkCommonDataModelModule.h" // For export macro
20 #include "vtkImplicitFunction.h"
21 
22 VTK_ABI_NAMESPACE_BEGIN
23 class vtkPoints; // forward declaration
24 
25 class VTKCOMMONDATAMODEL_EXPORT vtkPlane : public vtkImplicitFunction
26 {
27 public:
31  static vtkPlane* New();
32 
33  vtkTypeMacro(vtkPlane, vtkImplicitFunction);
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
37 
41  void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
42  double EvaluateFunction(double x[3]) override;
44 
48  void EvaluateGradient(double x[3], double g[3]) override;
49 
51 
54  vtkSetVector3Macro(Normal, double);
55  vtkGetVectorMacro(Normal, double, 3);
57 
59 
63  vtkSetVector3Macro(Origin, double);
64  vtkGetVectorMacro(Origin, double, 3);
66 
72  void Push(double distance);
73 
75 
80  static void ProjectPoint(
81  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
82  void ProjectPoint(const double x[3], double xproj[3]);
84 
86 
90  static void ProjectVector(
91  const double v[3], const double origin[3], const double normal[3], double vproj[3]);
92  void ProjectVector(const double v[3], double vproj[3]);
94 
96 
101  static void GeneralizedProjectPoint(
102  const double x[3], const double origin[3], const double normal[3], double xproj[3]);
103  void GeneralizedProjectPoint(const double x[3], double xproj[3]);
105 
109  static double Evaluate(double normal[3], double origin[3], double x[3]);
110 
112 
116  static double DistanceToPlane(double x[3], double n[3], double p0[3]);
117  double DistanceToPlane(double x[3]);
119 
121 
129  static int IntersectWithLine(
130  const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
131  int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
133 
135 
145  static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
146  double py[3], double x0[3], double x1[3]);
147  int IntersectWithFinitePlane(
148  double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
150 
152 
159  static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
161 
162 protected:
163  vtkPlane();
164  ~vtkPlane() override = default;
165 
166  double Normal[3];
167  double Origin[3];
168 
169 private:
170  vtkPlane(const vtkPlane&) = delete;
171  void operator=(const vtkPlane&) = delete;
172 };
173 
174 // Generally the normal should be normalized
175 inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
176 {
177  return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
178  normal[2] * (x[2] - origin[2]);
179 }
180 
181 // Assumes normal is normalized
182 inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
183 {
184 #define vtkPlaneAbs(x) ((x) < 0 ? -(x) : (x))
185  return (vtkPlaneAbs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
186 }
187 
188 VTK_ABI_NAMESPACE_END
189 #endif
abstract interface for implicit functions
virtual double EvaluateFunction(double x[3])=0
Evaluate function at position x-y-z and return value.
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:182
static double Evaluate(double normal[3], double origin[3], double x[3])
Quick evaluation of plane equation n(x-origin)=0.
Definition: vtkPlane.h:175
#define vtkPlaneAbs(x)
virtual void EvaluateGradient(double x[3], double g[3])=0
Evaluate function gradient at position x-y-z and pass back vector.
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
perform various plane computations
Definition: vtkPlane.h:25
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represent and manipulate 3D points
Definition: vtkPoints.h:28