Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vtkThickPlane.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #include "vtkThickPlane.h"
15 #include "vtkMath.h"
16 #include "vtkObjectFactory.h"
17 
19 
20 // Construct plane passing through origin and normal to z-axis.
22 {
23  this->Normal[0] = 0.0;
24  this->Normal[1] = 0.0;
25  this->Normal[2] = 1.0;
26 
27  this->Origin[0] = 0.0;
28  this->Origin[1] = 0.0;
29  this->Origin[2] = 0.0;
30 }
31 
32 // Evaluate plane equation for point x[3].
34 {
35  return this->EvaluateFunction(x[0],x[1],x[2]);
36 }
37 
38 // Evaluate plane equation for point x,y,z.
39 double vtkThickPlane::EvaluateFunction(double x,double y,double z)
40 {
41  // PointPlaneDistance = Distance - Normal*Point
42  double ppd = Distance - ( this->Normal[0]*x +
43  this->Normal[1]*y +
44  this->Normal[2]*z );
45 
46  if( std::abs(ppd) <= Thickness )
47  {
48  count++;
49  return 0;
50  }
51 
52  if( ppd >= 0 )
53  return ppd - Thickness;
54 
55  return std::abs(ppd + Thickness);
56 }
57 
58 // Evaluate function gradient at point x[3].
59 void vtkThickPlane::EvaluateGradient(double vtkNotUsed(x)[3], double n[3])
60 {
61  for (int i=0; i<3; i++)
62  {
63  n[i] = this->Normal[i];
64  }
65 }
66 
67 void vtkThickPlane::SetPose (double _n1, double _n2, double _n3, double _o1, double _o2, double _o3)
68 {
69  SetNormal(_n1,_n2,_n3);
70  SetOrigin(_o1,_o2,_o3);
71  Distance = Normal[0]*Origin[0]+Normal[1]*Origin[1]+Normal[2]*Origin[2];
72  if(Distance < 0.0)
73  {
74  Distance = -Distance;
75  Normal[0] = -Normal[0];
76  Normal[1] = -Normal[1];
77  Normal[2] = -Normal[2];
78  }
79 }
80 
81 void vtkThickPlane::SetPose (double _n[3], double _o[3])
82 {
83  SetPose(_n[0],_n[1],_n[2],_o[0],_o[1],_o[2]);
84 }
85 
86 void vtkThickPlane::SetNormal (double _arg1, double _arg2, double _arg3)
87 {
88  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << Normal << " to (" << _arg1 << "," << _arg2 << "," << _arg3 << ")");
89  if ((this->Normal[0] != _arg1)||(this->Normal[1] != _arg2)||(this->Normal[2] != _arg3))
90  {
91  double length = sqrt(_arg1*_arg1+_arg2*_arg2+_arg3*_arg3);
92  this->Normal[0] = _arg1/length;
93  this->Normal[1] = _arg2/length;
94  this->Normal[2] = _arg3/length;
95  this->Modified();
96  }
97 };
98 
99 void vtkThickPlane::SetNormal (double _arg[3])
100 {
101  this->SetNormal (_arg[0], _arg[1], _arg[2]);
102 }
103 
104 void vtkThickPlane::SetOrigin (double _arg1, double _arg2, double _arg3)
105 {
106  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << Origin << " to (" << _arg1 << "," << _arg2 << "," << _arg3 << ")");
107  if ((this->Normal[0] != _arg1)||(this->Normal[1] != _arg2)||(this->Normal[2] != _arg3))
108  {
109  this->Origin[0] = _arg1;
110  this->Origin[1] = _arg2;
111  this->Origin[2] = _arg3;
112  this->Modified();
113  }
114 };
115 
116 void vtkThickPlane::SetOrigin (double _arg[3])
117 {
118  this->SetOrigin (_arg[0], _arg[1], _arg[2]);
119 }
120 
121 void vtkThickPlane::SetThickness (double _arg)
122 {
123  Thickness = std::abs(_arg);
124 }
125 
126 #define VTK_PLANE_TOL 1.0e-06
127 
128 void vtkThickPlane::PrintSelf(ostream& os, vtkIndent indent)
129 {
130  this->Superclass::PrintSelf(os,indent);
131 
132  os << indent << "Normal: (" << this->Normal[0] << ", "
133  << this->Normal[1] << ", " << this->Normal[2] << ")\n";
134 
135  os << indent << "Origin: (" << this->Origin[0] << ", "
136  << this->Origin[1] << ", " << this->Origin[2] << ")\n";
137 
138  os << indent << "Thickness: " << this->Thickness << "\n";
139 }
virtual void SetPose(double _n1, double _n2, double _n3, double _o1, double _o2, double _o3)
double EvaluateFunction(double x[3]) override
virtual void SetOrigin(double _arg1, double _arg2, double _arg3)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void SetNormal(double _arg1, double _arg2, double _arg3)
double Normal[3]
Definition: vtkThickPlane.h:82
vtkStandardNewMacro(vtkThickPlane)
virtual const char * GetClassName() const
double Thickness
Definition: vtkThickPlane.h:84
void EvaluateGradient(double x[3], double g[3]) override
virtual void SetThickness(double _arg)
double Origin[3]
Definition: vtkThickPlane.h:83