VTK  9.4.20251007
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
18
19#ifndef vtkPlane_h
20#define vtkPlane_h
21
22#include "vtkCommonDataModelModule.h" // For export macro
23#include "vtkImplicitFunction.h"
24
25VTK_ABI_NAMESPACE_BEGIN
26class vtkPoints; // forward declaration
27
28class VTKCOMMONDATAMODEL_EXPORT vtkPlane : public vtkImplicitFunction
29{
30public:
34 static vtkPlane* New();
35
37 void PrintSelf(ostream& os, vtkIndent indent) override;
38
40
44 void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
45 double EvaluateFunction(double x[3]) override;
47
51 void EvaluateGradient(double x[3], double g[3]) override;
52
54
57 vtkSetVector3Macro(Normal, double);
58 vtkGetVectorMacro(Normal, double, 3);
60
62
66 vtkSetVector3Macro(Origin, double);
67 vtkGetVectorMacro(Origin, double, 3);
69
75 void Push(double distance);
76
78
83 static void ProjectPoint(
84 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
85 void ProjectPoint(const double x[3], double xproj[3]);
87
89
93 static void ProjectVector(
94 const double v[3], const double origin[3], const double normal[3], double vproj[3]);
95 void ProjectVector(const double v[3], double vproj[3]);
97
99
105 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
106 void GeneralizedProjectPoint(const double x[3], double xproj[3]);
108
112 static double Evaluate(double normal[3], double origin[3], double x[3]);
113
115
119 static double DistanceToPlane(double x[3], double n[3], double p0[3]);
120 double DistanceToPlane(double x[3]);
122
124
133 const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
134 int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
136
138
148 static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
149 double py[3], double x0[3], double x1[3]);
151 double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
153
155
162 static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
164
165protected:
167 ~vtkPlane() override = default;
168
169 double Normal[3];
170 double Origin[3];
171
172private:
173 vtkPlane(const vtkPlane&) = delete;
174 void operator=(const vtkPlane&) = delete;
175};
176
177// Generally the normal should be normalized
178inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
179{
180 return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
181 normal[2] * (x[2] - origin[2]);
182}
183
184// Assumes normal is normalized
185inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
186{
187#define vtkPlaneAbs(x) ((x) < 0 ? -(x) : (x))
188 return (vtkPlaneAbs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
189}
190
191VTK_ABI_NAMESPACE_END
192#endif
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:29
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.
double Normal[3]
Definition vtkPlane.h:169
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
double Origin[3]
Definition vtkPlane.h:170
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 vtkPlane * New()
Construct plane passing through origin and normal to z-axis.
static double Evaluate(double normal[3], double origin[3], double x[3])
Quick evaluation of plane equation n(x-origin)=0.
Definition vtkPlane.h:178
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:185
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 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:30
#define vtkDataArray
#define vtkPlaneAbs(x)