VTK  9.4.20250308
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
128#ifndef vtkPlane_h
129#define vtkPlane_h
130
131#include "vtkCommonDataModelModule.h" // For export macro
132#include "vtkImplicitFunction.h"
133
134#include <cmath> // for std::abs
135
136VTK_ABI_NAMESPACE_BEGIN
137class vtkPoints; // forward declaration
138
139class VTKCOMMONDATAMODEL_EXPORT vtkPlane : public vtkImplicitFunction
140{
141public:
145 static vtkPlane* New();
146
148 void PrintSelf(ostream& os, vtkIndent indent) override;
149
151
155 void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
156 double EvaluateFunction(double x[3]) override;
158
162 void EvaluateGradient(double x[3], double g[3]) override;
163
165
168 virtual void SetNormal(double x, double y, double z);
169 virtual void SetNormal(const double normal[3]);
170 vtkGetVectorMacro(Normal, double, 3);
172
174
178 virtual void SetOrigin(double x, double y, double z);
179 virtual void SetOrigin(const double origin[3]);
180 vtkGetVectorMacro(Origin, double, 3);
182
184
188 virtual void SetOffset(double _arg);
189 vtkGetMacro(Offset, double);
191
193
196 virtual void SetAxisAligned(bool _arg);
197 vtkGetMacro(AxisAligned, bool);
199
205 void Push(double distance);
206
208
213 static void ProjectPoint(
214 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
215 void ProjectPoint(const double x[3], double xproj[3]);
217
219
223 static void ProjectVector(
224 const double v[3], const double origin[3], const double normal[3], double vproj[3]);
225 void ProjectVector(const double v[3], double vproj[3]);
227
229
235 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
236 void GeneralizedProjectPoint(const double x[3], double xproj[3]);
238
242 static double Evaluate(double normal[3], double origin[3], double x[3]);
243
245
249 static double DistanceToPlane(double x[3], double n[3], double p0[3]);
250 double DistanceToPlane(double x[3]);
252
254
263 const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
264 int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
266
268
278 static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
279 double py[3], double x0[3], double x1[3]);
281 double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
283
285
292 static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
294
296
299 void DeepCopy(vtkPlane* plane);
301
302protected:
303 vtkPlane() = default;
304 ~vtkPlane() override = default;
305
306 // Construct plane passing through origin and normal to z-axis.
307 double Normal[3] = { 0.0, 0.0, 1.0 };
308 double Origin[3] = { 0.0, 0.0, 0.0 };
309
310private:
311 vtkPlane(const vtkPlane&) = delete;
312 void operator=(const vtkPlane&) = delete;
313
314 // If AxisAligned is enabled, sets axis to the nearest canonical axis.
315 void ComputeInternalNormal();
316 // Shifts the origin in the direction of the normal by the offset.
317 void ComputeInternalOrigin();
318 // Computes InternalNormal and InternalOrigin.
319 void InternalUpdates();
320
321 double Offset = 0.0;
322 bool AxisAligned = false;
323
325
331 double InternalNormal[3] = { 0.0, 0.0, 1.0 };
332 double InternalOrigin[3] = { 0.0, 0.0, 0.0 };
334};
335
336// Generally the normal should be normalized
337inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
338{
339 return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
340 normal[2] * (x[2] - origin[2]);
341}
342
343// Assumes normal is normalized
344inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
345{
346 return (std::abs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
347}
348
349VTK_ABI_NAMESPACE_END
350#endif
abstract superclass for arrays of numeric data
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:108
perform various plane computations
Definition vtkPlane.h:140
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.
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.
void ProjectPoint(const double x[3], double xproj[3])
Project a point x 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.
~vtkPlane() override=default
virtual void SetOrigin(const double origin[3])
Set/get point through which plane passes.
vtkPlane()=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,...
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].
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.
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:337
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:344
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:139