VTK  9.5.20250711
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
134
135#include <cmath> // for std::abs
136
137VTK_ABI_NAMESPACE_BEGIN
138class vtkPoints; // forward declaration
139
140class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALAUTO vtkPlane : public vtkImplicitFunction
141{
142public:
146 static vtkPlane* New();
147
149 void PrintSelf(ostream& os, vtkIndent indent) override;
150
152
156 void EvaluateFunction(vtkDataArray* input, vtkDataArray* output) override;
157 double EvaluateFunction(double x[3]) override;
159
163 void EvaluateGradient(double x[3], double g[3]) override;
164
166
169 virtual void SetNormal(double x, double y, double z);
170 virtual void SetNormal(const double normal[3]);
171 vtkGetVectorMacro(Normal, double, 3);
173
175
179 virtual void SetOrigin(double x, double y, double z);
180 virtual void SetOrigin(const double origin[3]);
181 vtkGetVectorMacro(Origin, double, 3);
183
185
189 VTK_MARSHALEXCLUDE(VTK_MARSHAL_EXCLUDE_IS_REDUNDANT)
190 virtual void SetOffset(double _arg);
191 VTK_MARSHALEXCLUDE(VTK_MARSHAL_EXCLUDE_IS_REDUNDANT)
192 vtkGetMacro(Offset, double);
194
196
199 virtual void SetAxisAligned(bool _arg);
200 vtkGetMacro(AxisAligned, bool);
202
208 void Push(double distance);
209
211
216 static void ProjectPoint(
217 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
218 void ProjectPoint(const double x[3], double xproj[3]);
220
222
226 static void ProjectVector(
227 const double v[3], const double origin[3], const double normal[3], double vproj[3]);
228 void ProjectVector(const double v[3], double vproj[3]);
230
232
237 static void GeneralizedProjectPoint(
238 const double x[3], const double origin[3], const double normal[3], double xproj[3]);
239 void GeneralizedProjectPoint(const double x[3], double xproj[3]);
241
245 static double Evaluate(double normal[3], double origin[3], double x[3]);
246
248
252 static double DistanceToPlane(double x[3], double n[3], double p0[3]);
253 double DistanceToPlane(double x[3]);
255
257
265 static int IntersectWithLine(
266 const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3]);
267 int IntersectWithLine(const double p1[3], const double p2[3], double& t, double x[3]);
269
271
281 static int IntersectWithFinitePlane(double n[3], double o[3], double pOrigin[3], double px[3],
282 double py[3], double x0[3], double x1[3]);
283 int IntersectWithFinitePlane(
284 double pOrigin[3], double px[3], double py[3], double x0[3], double x1[3]);
286
288
295 static bool ComputeBestFittingPlane(vtkPoints* pts, double* origin, double* normal);
297
299
302 void DeepCopy(vtkPlane* plane);
304
305protected:
306 vtkPlane() = default;
307 ~vtkPlane() override = default;
308
309 // Construct plane passing through origin and normal to z-axis.
310 double Normal[3] = { 0.0, 0.0, 1.0 };
311 double Origin[3] = { 0.0, 0.0, 0.0 };
312
313private:
314 vtkPlane(const vtkPlane&) = delete;
315 void operator=(const vtkPlane&) = delete;
316
317 // If AxisAligned is enabled, sets axis to the nearest canonical axis.
318 void ComputeInternalNormal();
319 // Shifts the origin in the direction of the normal by the offset.
320 void ComputeInternalOrigin();
321 // Computes InternalNormal and InternalOrigin.
322 void InternalUpdates();
323
324 double Offset = 0.0;
325 bool AxisAligned = false;
326
328
334 double InternalNormal[3] = { 0.0, 0.0, 1.0 };
335 double InternalOrigin[3] = { 0.0, 0.0, 0.0 };
337};
338
339// Generally the normal should be normalized
340inline double vtkPlane::Evaluate(double normal[3], double origin[3], double x[3])
341{
342 return normal[0] * (x[0] - origin[0]) + normal[1] * (x[1] - origin[1]) +
343 normal[2] * (x[2] - origin[2]);
344}
345
346// Assumes normal is normalized
347inline double vtkPlane::DistanceToPlane(double x[3], double n[3], double p0[3])
348{
349 return (std::abs(n[0] * (x[0] - p0[0]) + n[1] * (x[1] - p0[1]) + n[2] * (x[2] - p0[2])));
350}
351
352VTK_ABI_NAMESPACE_END
353#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:141
virtual void SetOrigin(double x, double y, double z)
Set/get point through which plane passes.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetOrigin(const double origin[3])
Set/get point through which plane passes.
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 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:340
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:347
double EvaluateFunction(double x[3]) override
Evaluate plane equation for point x[3].
void EvaluateFunction(vtkDataArray *input, vtkDataArray *output) override
Evaluate plane equation for point x[3].
represent and manipulate 3D points
Definition vtkPoints.h:139
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)