VTK  9.7.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
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 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkPoints; // forward declaration
30 
31 class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALAUTO vtkPlane : public vtkImplicitFunction
32 {
33 public:
37  static vtkPlane* New();
38 
39  vtkTypeMacro(vtkPlane, vtkImplicitFunction);
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 
128  static void GeneralizedProjectPoint(
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 
156  static int IntersectWithLine(
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]);
174  int IntersectWithFinitePlane(
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 
196 protected:
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 
204 private:
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
231 inline 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
238 inline 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 
243 VTK_ABI_NAMESPACE_END
244 #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:238
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
#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT
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:31
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_MARSHALAUTO
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:30