VTK  9.6.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
18
19#ifndef vtkPlane_h
20#define vtkPlane_h
21
22#include "vtkCommonDataModelModule.h" // For export macro
23#include "vtkImplicitFunction.h"
24#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
25
26#include <cmath> // for std::abs
27
28VTK_ABI_NAMESPACE_BEGIN
29class vtkPoints; // forward declaration
30
31class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALAUTO vtkPlane : public vtkImplicitFunction
32{
33public:
37 static vtkPlane* New();
38
40 void PrintSelf(ostream& os, vtkIndent indent) override;
41
43
47 void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
48 double EvaluateFunction(double x[3]) override;
50
54 void EvaluateGradient(double x[3], double g[3]) override;
55
57
60 virtual void SetNormal(double x, double y, double z);
61 virtual void SetNormal(const double normal[3]);
62 vtkGetVectorMacro(Normal, double, 3);
64
66
70 virtual void SetOrigin(double x, double y, double z);
71 virtual void SetOrigin(const double origin[3]);
72 vtkGetVectorMacro(Origin, double, 3);
74
76
81 virtual void SetOffset(double _arg);
83 vtkGetMacro(Offset, double);
85
87
90 virtual void SetAxisAligned(bool _arg);
91 vtkGetMacro(AxisAligned, bool);
93
99 void Push(double distance);
100
102
107 static void ProjectPoint(
108 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
109 void ProjectPoint(const double x[3], double xproj[3]);
111
113
117 static void ProjectVector(
118 const double v[3], const double origin[3], const double normal[3], double vproj[3]);
119 void ProjectVector(const double v[3], double vproj[3]);
121
123
129 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
130 void GeneralizedProjectPoint(const double x[3], double xproj[3]);
132
136 static double Evaluate(double normal[3], double origin[3], double x[3]);
137
139
143 static double DistanceToPlane(double x[3], double n[3], double p0[3]);
144 double DistanceToPlane(double x[3]);
146
148
157 const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
158 int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
160
162
172 static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
173 double py[3], double x0[3], double x1[3]);
175 double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
177
179
186 static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
188
190
193 void DeepCopy(vtkPlane* plane);
195
196protected:
197 vtkPlane() = default;
198 ~vtkPlane() override = default;
199
200 // Construct plane passing through origin and normal to z-axis.
201 double Normal[3] = { 0.0, 0.0, 1.0 };
202 double Origin[3] = { 0.0, 0.0, 0.0 };
203
204private:
205 vtkPlane(const vtkPlane&) = delete;
206 void operator=(const vtkPlane&) = delete;
207
208 // If AxisAligned is enabled, sets axis to the nearest canonical axis.
209 void ComputeInternalNormal();
210 // Shifts the origin in the direction of the normal by the offset.
211 void ComputeInternalOrigin();
212 // Computes InternalNormal and InternalOrigin.
213 void InternalUpdates();
214
215 double Offset = 0.0;
216 bool AxisAligned = false;
217
219
225 double InternalNormal[3] = { 0.0, 0.0, 1.0 };
226 double InternalOrigin[3] = { 0.0, 0.0, 0.0 };
228};
229
230// Generally the normal should be normalized
231inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
232{
233 return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
234 normal[2] * (x[2] - origin[2]);
235}
236
237// Assumes normal is normalized
238inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
239{
240 return (std::abs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
241}
242
243VTK_ABI_NAMESPACE_END
244#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
perform various plane computations
Definition vtkPlane.h:32
double Normal[3]
Definition vtkPlane.h:201
virtual void SetOrigin(double x, double y, double z)
Set/get point through which plane passes.
virtual void SetOffset(double _arg)
The origin is shifted in the direction of the normal by the offset.
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.
virtual void SetAxisAligned(bool _arg)
Accessors for AxisAligned, which locks normal to plane to be aligned with x, y, or z axis.
virtual void SetOrigin(const double origin[3])
Set/get point through which plane passes.
vtkPlane()=default
double Origin[3]
Definition vtkPlane.h:202
void Push(double distance)
Translate the plane in the direction of the normal by the distance specified.
virtual void SetNormal(const double normal[3])
Set/get plane normal.
void EvaluateGradient(double x[3], double g[3]) override
Evaluate function gradient at point x[3].
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.
virtual void SetNormal(double x, double y, double z)
Set/get plane normal.
static double Evaluate(double normal[3], double origin[3], double x[3])
Quick evaluation of plane equation n(x-origin)=0.
Definition vtkPlane.h:231
void DeepCopy(vtkPlane *plane)
Perform a deep copy of the given plane.
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:238
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 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 VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)