VMTK
Loading...
Searching...
No Matches
vtkvmtkSurfaceDistance Class Reference

Calculate the Euclidean distance of one surface from another. More...

#include <vtkvmtkSurfaceDistance.h>

Inheritance diagram for vtkvmtkSurfaceDistance:
[legend]
Collaboration diagram for vtkvmtkSurfaceDistance:
[legend]

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkSurfaceDistance * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetDistanceArrayName (const char *)
virtual char * GetDistanceArrayName ()
virtual void SetSignedDistanceArrayName (const char *)
virtual char * GetSignedDistanceArrayName ()
virtual void SetDistanceVectorsArrayName (const char *)
virtual char * GetDistanceVectorsArrayName ()
virtual void SetReferenceSurface (vtkPolyData *)
virtual vtkPolyData * GetReferenceSurface ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkSurfaceDistance * SafeDownCast (vtkObjectBase *o)
static vtkvmtkSurfaceDistance * New ()

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkSurfaceDistance ()
 ~vtkvmtkSurfaceDistance ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override

Protected Attributes

char * DistanceArrayName
char * DistanceVectorsArrayName
char * SignedDistanceArrayName
vtkPolyData * ReferenceSurface

Detailed Description

Calculate the Euclidean distance of one surface from another.

Definition at line 34 of file vtkvmtkSurfaceDistance.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkSurfaceDistance::Superclass

Definition at line 37 of file vtkvmtkSurfaceDistance.h.

Constructor & Destructor Documentation

◆ vtkvmtkSurfaceDistance()

vtkvmtkSurfaceDistance::vtkvmtkSurfaceDistance ( )
protected

Definition at line 37 of file vtkvmtkSurfaceDistance.cxx.

38{
39 this->DistanceArrayName = NULL;
40 this->DistanceVectorsArrayName = NULL;
41 this->SignedDistanceArrayName = NULL;
42 this->ReferenceSurface = NULL;
43}

◆ ~vtkvmtkSurfaceDistance()

vtkvmtkSurfaceDistance::~vtkvmtkSurfaceDistance ( )
protected

Definition at line 45 of file vtkvmtkSurfaceDistance.cxx.

46{
47 if (this->ReferenceSurface)
48 {
49 this->ReferenceSurface->Delete();
50 this->ReferenceSurface = NULL;
51 }
52
53 if (this->DistanceArrayName)
54 {
55 delete[] this->DistanceArrayName;
56 this->DistanceArrayName = NULL;
57 }
58
60 {
61 delete[] this->DistanceVectorsArrayName;
62 this->DistanceVectorsArrayName = NULL;
63 }
64
66 {
67 delete[] this->SignedDistanceArrayName;
68 this->SignedDistanceArrayName = NULL;
69 }
70}

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkSurfaceDistance::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkSurfaceDistance::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkSurfaceDistance * vtkvmtkSurfaceDistance::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkSurfaceDistance::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkSurfaceDistance * vtkvmtkSurfaceDistance::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkSurfaceDistance::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 236 of file vtkvmtkSurfaceDistance.cxx.

237{
238 this->Superclass::PrintSelf(os,indent);
239}

◆ New()

vtkvmtkSurfaceDistance * vtkvmtkSurfaceDistance::New ( )
static

◆ SetDistanceArrayName()

virtual void vtkvmtkSurfaceDistance::SetDistanceArrayName ( const char * )
virtual

Set/Get the name of the array where the computed distance has to be stored.

◆ GetDistanceArrayName()

virtual char * vtkvmtkSurfaceDistance::GetDistanceArrayName ( )
virtual

Set/Get the name of the array where the computed distance has to be stored.

◆ SetSignedDistanceArrayName()

virtual void vtkvmtkSurfaceDistance::SetSignedDistanceArrayName ( const char * )
virtual

Set/Get the name of the array where the computed distance has to be stored.

◆ GetSignedDistanceArrayName()

virtual char * vtkvmtkSurfaceDistance::GetSignedDistanceArrayName ( )
virtual

Set/Get the name of the array where the computed distance has to be stored.

◆ SetDistanceVectorsArrayName()

virtual void vtkvmtkSurfaceDistance::SetDistanceVectorsArrayName ( const char * )
virtual

Set/Get the name of the array where the computed distance vectors have to be stored.

◆ GetDistanceVectorsArrayName()

virtual char * vtkvmtkSurfaceDistance::GetDistanceVectorsArrayName ( )
virtual

Set/Get the name of the array where the computed distance vectors have to be stored.

◆ SetReferenceSurface()

virtual void vtkvmtkSurfaceDistance::SetReferenceSurface ( vtkPolyData * )
virtual

Set/Get the reference surface to compute distance from.

◆ GetReferenceSurface()

virtual vtkPolyData * vtkvmtkSurfaceDistance::GetReferenceSurface ( )
virtual

Set/Get the reference surface to compute distance from.

◆ RequestData()

int vtkvmtkSurfaceDistance::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 72 of file vtkvmtkSurfaceDistance.cxx.

76{
77 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
78 vtkInformation *outInfo = outputVector->GetInformationObject(0);
79
80 vtkPolyData *input = vtkPolyData::SafeDownCast(
81 inInfo->Get(vtkDataObject::DATA_OBJECT()));
82 vtkPolyData *output = vtkPolyData::SafeDownCast(
83 outInfo->Get(vtkDataObject::DATA_OBJECT()));
84
85 vtkIdType i, j;
86 vtkIdType numberOfPoints, numberOfCellPoints;
87 vtkIdType cellId, pointId;
88 int subId;
89 double point[3], closestPoint[3];
90 double distance2, distance, signedDistance;
91 double pcoords[3];
92 double pointNormal[3], *normal;
93 double distanceVector[3];
94 double *weights;
95 double dot;
96 bool computeDistance, computeDistanceVectors, computeSignedDistance;
97 vtkDoubleArray *distanceArray, *distanceVectorsArray, *signedDistanceArray;
98 vtkDataArray *normals;
99 vtkCellLocator *locator;
100 vtkGenericCell *genericCell;
101 vtkCell *cell;
102
103 if (!this->ReferenceSurface)
104 {
105 vtkErrorMacro(<<"No reference surface!");
106 return 1;
107 }
108
110 {
111 vtkErrorMacro(<<"No array names set!");
112 return 1;
113 }
114
115 distanceArray = vtkDoubleArray::New();
116 distanceVectorsArray = vtkDoubleArray::New();
117 signedDistanceArray = vtkDoubleArray::New();
118 normals = NULL;
119
120 locator = vtkCellLocator::New();
121 genericCell = vtkGenericCell::New();
122
123 numberOfPoints = input->GetNumberOfPoints();
124
125 computeDistance = false;
126 computeDistanceVectors = false;
127 computeSignedDistance = false;
128
129 if (this->DistanceArrayName)
130 {
131 computeDistance = true;
132 distanceArray->SetName(this->DistanceArrayName);
133 distanceArray->SetNumberOfComponents(1);
134 distanceArray->SetNumberOfTuples(numberOfPoints);
135 }
136
137 if (this->DistanceVectorsArrayName)
138 {
139 computeDistanceVectors = true;
140 distanceVectorsArray->SetName(this->DistanceVectorsArrayName);
141 distanceVectorsArray->SetNumberOfComponents(3);
142 distanceVectorsArray->SetNumberOfTuples(numberOfPoints);
143 }
144
145 if (this->SignedDistanceArrayName)
146 {
147 computeSignedDistance = true;
148 signedDistanceArray->SetName(this->SignedDistanceArrayName);
149 signedDistanceArray->SetNumberOfComponents(1);
150 signedDistanceArray->SetNumberOfTuples(numberOfPoints);
151 normals = this->ReferenceSurface->GetPointData()->GetNormals();
152 if (!normals)
153 {
154 vtkErrorMacro(<<"Signed distance requires point normals to be defined over ReferenceSurface!");
155 return 1;
156 }
157 }
158
159 locator->SetDataSet(this->ReferenceSurface);
160 locator->BuildLocator();
161
162 for (i=0; i<numberOfPoints; i++)
163 {
164 input->GetPoint(i,point);
165 locator->FindClosestPoint(point,closestPoint,genericCell,cellId,subId,distance2);
166 distanceVector[0] = point[0] - closestPoint[0];
167 distanceVector[1] = point[1] - closestPoint[1];
168 distanceVector[2] = point[2] - closestPoint[2];
169 distance = sqrt(distance2);
170
171 if (computeDistance)
172 {
173 distanceArray->SetTuple1(i,distance);
174 }
175
176 if (computeDistanceVectors)
177 {
178 distanceVectorsArray->SetTuple3(i,-distanceVector[0],-distanceVector[1],-distanceVector[2]);
179 }
180
181 if (computeSignedDistance)
182 {
183 cell = this->ReferenceSurface->GetCell(cellId);
184 numberOfCellPoints = cell->GetNumberOfPoints();
185 weights = new double[numberOfCellPoints];
186 cell->EvaluatePosition(point,NULL,subId,pcoords,distance2,weights);
187 pointNormal[0] = 0.0;
188 pointNormal[1] = 0.0;
189 pointNormal[2] = 0.0;
190 for (j=0; j<numberOfCellPoints; j++)
191 {
192 pointId = cell->GetPointId(j);
193 normal = normals->GetTuple3(pointId);
194 pointNormal[0] += weights[j] * normal[0];
195 pointNormal[1] += weights[j] * normal[1];
196 pointNormal[2] += weights[j] * normal[2];
197 }
198 dot = vtkMath::Dot(distanceVector,pointNormal);
199 signedDistance = distance;
200 // distance is positive if distanceVector and normal have negative dot
201 if (dot>0.0)
202 {
203 signedDistance *= -1.0;
204 }
205 signedDistanceArray->SetTuple1(i,signedDistance);
206 delete[] weights;
207 }
208 }
209
210 output->DeepCopy(input);
211
212 if (computeDistance)
213 {
214 output->GetPointData()->AddArray(distanceArray);
215 }
216
217 if (computeDistanceVectors)
218 {
219 output->GetPointData()->AddArray(distanceVectorsArray);
220 }
221
222 if (computeSignedDistance)
223 {
224 output->GetPointData()->AddArray(signedDistanceArray);
225 }
226
227 distanceArray->Delete();
228 distanceVectorsArray->Delete();
229 signedDistanceArray->Delete();
230 locator->Delete();
231 genericCell->Delete();
232
233 return 1;
234}

Member Data Documentation

◆ DistanceArrayName

char* vtkvmtkSurfaceDistance::DistanceArrayName
protected

Definition at line 80 of file vtkvmtkSurfaceDistance.h.

◆ DistanceVectorsArrayName

char* vtkvmtkSurfaceDistance::DistanceVectorsArrayName
protected

Definition at line 81 of file vtkvmtkSurfaceDistance.h.

◆ SignedDistanceArrayName

char* vtkvmtkSurfaceDistance::SignedDistanceArrayName
protected

Definition at line 82 of file vtkvmtkSurfaceDistance.h.

◆ ReferenceSurface

vtkPolyData* vtkvmtkSurfaceDistance::ReferenceSurface
protected

Definition at line 83 of file vtkvmtkSurfaceDistance.h.


The documentation for this class was generated from the following files: