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

Creates a reference system consisting of a radius and normals on top of boundaries. More...

#include <vtkvmtkBoundaryReferenceSystems.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkBoundaryReferenceSystems * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetBoundaryRadiusArrayName (const char *)
virtual char * GetBoundaryRadiusArrayName ()
virtual void SetBoundaryNormalsArrayName (const char *)
virtual char * GetBoundaryNormalsArrayName ()
virtual void SetPoint1ArrayName (const char *)
virtual char * GetPoint1ArrayName ()
virtual void SetPoint2ArrayName (const char *)
virtual char * GetPoint2ArrayName ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkBoundaryReferenceSystems * SafeDownCast (vtkObjectBase *o)
static vtkvmtkBoundaryReferenceSystems * New ()
static void ComputeBoundaryBarycenter (vtkPoints *points, double barycenter[3])
static double ComputeBoundaryMeanRadius (vtkPoints *points, double barycenter[3])
static void ComputeBoundaryNormal (vtkPoints *points, double barycenter[3], double normal[3])
static void OrientBoundaryNormalOutwards (vtkPolyData *surface, vtkPolyData *boundaries, vtkIdType boundaryCellId, double normal[3], double outwardNormal[3])
static void ComputeReferenceSystemPoints (double origin[3], double normal[3], double radius, double point1[3], double point2[3])

Protected Member Functions

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

Protected Attributes

char * BoundaryRadiusArrayName
char * BoundaryNormalsArrayName
char * Point1ArrayName
char * Point2ArrayName

Detailed Description

Creates a reference system consisting of a radius and normals on top of boundaries.

This class has methods to estimate the location of the boundary barycenter location, the boundary mean radius, and outward normals to the boundary.

As a filter, it takes a surface with open boundaries (e.g. the inlet/outlet caps removed) as input and outputs a vtkPolyData of vertex points, one per boundary, located at each boundary's origin, with the per-boundary radius/normal/in-plane reference points stored as point data arrays (see BoundaryRadiusArrayName, BoundaryNormalsArrayName, Point1ArrayName, Point2ArrayName). This is the filter behind the vmtkboundaryreferencesystems pype script; a typical use is specifying CFD boundary conditions at each inlet/outlet of a vascular model.

See also
vtkvmtkCapPolyData, vtkvmtkPolyDataBoundaryExtractor

Definition at line 46 of file vtkvmtkBoundaryReferenceSystems.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkBoundaryReferenceSystems::Superclass

Definition at line 49 of file vtkvmtkBoundaryReferenceSystems.h.

Constructor & Destructor Documentation

◆ vtkvmtkBoundaryReferenceSystems()

vtkvmtkBoundaryReferenceSystems::vtkvmtkBoundaryReferenceSystems ( )
protected

◆ ~vtkvmtkBoundaryReferenceSystems()

vtkvmtkBoundaryReferenceSystems::~vtkvmtkBoundaryReferenceSystems ( )
protected

Definition at line 47 of file vtkvmtkBoundaryReferenceSystems.cxx.

48{
50 {
51 delete[] this->BoundaryRadiusArrayName;
52 this->BoundaryRadiusArrayName = NULL;
53 }
54
56 {
57 delete[] this->BoundaryNormalsArrayName;
58 this->BoundaryNormalsArrayName = NULL;
59 }
60
61 if (this->Point1ArrayName)
62 {
63 delete[] this->Point1ArrayName;
64 this->Point1ArrayName = NULL;
65 }
66
67 if (this->Point2ArrayName)
68 {
69 delete[] this->Point2ArrayName;
70 this->Point2ArrayName = NULL;
71 }
72}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkBoundaryReferenceSystems::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkBoundaryReferenceSystems * vtkvmtkBoundaryReferenceSystems::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 376 of file vtkvmtkBoundaryReferenceSystems.cxx.

377{
378 this->Superclass::PrintSelf(os,indent);
379}

◆ New()

vtkvmtkBoundaryReferenceSystems * vtkvmtkBoundaryReferenceSystems::New ( )
static

◆ SetBoundaryRadiusArrayName()

virtual void vtkvmtkBoundaryReferenceSystems::SetBoundaryRadiusArrayName ( const char * )
virtual

Set/Get the name of the point data array (one 3-component tuple per output vertex/boundary) where the mean boundary radius is stored. Commonly named "BoundaryRadius".

◆ GetBoundaryRadiusArrayName()

virtual char * vtkvmtkBoundaryReferenceSystems::GetBoundaryRadiusArrayName ( )
virtual

Set/Get the name of the point data array (one 3-component tuple per output vertex/boundary) where the mean boundary radius is stored. Commonly named "BoundaryRadius".

◆ SetBoundaryNormalsArrayName()

virtual void vtkvmtkBoundaryReferenceSystems::SetBoundaryNormalsArrayName ( const char * )
virtual

Set/Get the name of the point data array where the outward-pointing normal to each boundary plane is stored. Commonly named "BoundaryNormals".

◆ GetBoundaryNormalsArrayName()

virtual char * vtkvmtkBoundaryReferenceSystems::GetBoundaryNormalsArrayName ( )
virtual

Set/Get the name of the point data array where the outward-pointing normal to each boundary plane is stored. Commonly named "BoundaryNormals".

◆ SetPoint1ArrayName()

virtual void vtkvmtkBoundaryReferenceSystems::SetPoint1ArrayName ( const char * )
virtual

Set/Get the name of the point data array where the first in-plane reference point of each boundary is stored (together with the origin, defines an arbitrary x axis on the boundary plane; see ComputeReferenceSystemPoints). Commonly named "Point1".

◆ GetPoint1ArrayName()

virtual char * vtkvmtkBoundaryReferenceSystems::GetPoint1ArrayName ( )
virtual

Set/Get the name of the point data array where the first in-plane reference point of each boundary is stored (together with the origin, defines an arbitrary x axis on the boundary plane; see ComputeReferenceSystemPoints). Commonly named "Point1".

◆ SetPoint2ArrayName()

virtual void vtkvmtkBoundaryReferenceSystems::SetPoint2ArrayName ( const char * )
virtual

Set/Get the name of the point data array where the second in-plane reference point of each boundary is stored (together with the origin and Point1, fully defines the boundary plane's local coordinate frame; see ComputeReferenceSystemPoints). Commonly named "Point2".

◆ GetPoint2ArrayName()

virtual char * vtkvmtkBoundaryReferenceSystems::GetPoint2ArrayName ( )
virtual

Set/Get the name of the point data array where the second in-plane reference point of each boundary is stored (together with the origin and Point1, fully defines the boundary plane's local coordinate frame; see ComputeReferenceSystemPoints). Commonly named "Point2".

◆ ComputeBoundaryBarycenter()

void vtkvmtkBoundaryReferenceSystems::ComputeBoundaryBarycenter ( vtkPoints * points,
double barycenter[3] )
static

Compute the barycenter (mean position) of the given ordered boundary points.

Definition at line 74 of file vtkvmtkBoundaryReferenceSystems.cxx.

75{
76 int numberOfPoints;
77 double weightSum, weight;
78 vtkIdType i;
79
80 // accounts for edge length
81
82 numberOfPoints = points->GetNumberOfPoints();
83
84 weightSum = 0.0;
85
86 barycenter[0] = 0.0;
87 barycenter[1] = 0.0;
88 barycenter[2] = 0.0;
89
90 double point0[3], point1[3];
91
92 for (i=0; i<numberOfPoints; i++)
93 {
94 points->GetPoint(i,point0);
95 points->GetPoint((i+1)%numberOfPoints,point1);
96 weight = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
97 if (weight < VTK_VMTK_DOUBLE_TOL)
98 {
99 continue;
100 }
101 weightSum += weight;
102
103 barycenter[0] += (point0[0] + point1[0])/2.0 * weight;
104 barycenter[1] += (point0[1] + point1[1])/2.0 * weight;
105 barycenter[2] += (point0[2] + point1[2])/2.0 * weight;
106 }
107
108 barycenter[0] /= weightSum;
109 barycenter[1] /= weightSum;
110 barycenter[2] /= weightSum;
111}
#define VTK_VMTK_DOUBLE_TOL

◆ ComputeBoundaryMeanRadius()

double vtkvmtkBoundaryReferenceSystems::ComputeBoundaryMeanRadius ( vtkPoints * points,
double barycenter[3] )
static

Compute the mean distance of the given boundary points from their barycenter.

Definition at line 113 of file vtkvmtkBoundaryReferenceSystems.cxx.

114{
115 int numberOfPoints = points->GetNumberOfPoints();
116
117 // TODO: weight by edge length as for barycenter
118
119 double meanRadius = 0.0;
120
121 for (int i=0; i<numberOfPoints; i++)
122 {
123 meanRadius += sqrt(vtkMath::Distance2BetweenPoints(points->GetPoint(i),barycenter));
124 }
125
126 meanRadius /= numberOfPoints;
127
128 return meanRadius;
129}

◆ ComputeBoundaryNormal()

void vtkvmtkBoundaryReferenceSystems::ComputeBoundaryNormal ( vtkPoints * points,
double barycenter[3],
double normal[3] )
static

Compute a (non-normalized) normal to the plane best fitting the given boundary points, about their barycenter.

Definition at line 131 of file vtkvmtkBoundaryReferenceSystems.cxx.

132{
133 int numberOfPoints;
134 double point[3], vector1[3], vector0[3], cross[3], sumCross[3] = {0.0f,0.0f,0.0f};
135 vtkIdType i, j;
136
137 // TODO: weight by edge length as for barycenter
138
139 numberOfPoints = points->GetNumberOfPoints();
140
141 points->GetPoint(numberOfPoints-1,point);
142 vector0[0] = point[0] - barycenter[0];
143 vector0[1] = point[1] - barycenter[1];
144 vector0[2] = point[2] - barycenter[2];
145
146 for (i=0; i<numberOfPoints; i++)
147 {
148 points->GetPoint(i,point);
149 vector1[0] = point[0] - barycenter[0];
150 vector1[1] = point[1] - barycenter[1];
151 vector1[2] = point[2] - barycenter[2];
152
153 vtkMath::Cross(vector1,vector0,cross);
154
155 for (j=0; j<3; j++)
156 {
157 vector0[j] = vector1[j];
158 sumCross[j] += cross[j];
159 }
160 }
161
162 vtkMath::Normalize(sumCross);
163
164 for (j=0; j<3; j++)
165 {
166 normal[j] = sumCross[j];
167 }
168}

◆ OrientBoundaryNormalOutwards()

void vtkvmtkBoundaryReferenceSystems::OrientBoundaryNormalOutwards ( vtkPolyData * surface,
vtkPolyData * boundaries,
vtkIdType boundaryCellId,
double normal[3],
double outwardNormal[3] )
static

Flip normal if needed so that it points away from the body of surface, and store the result in outwardNormal. boundaryCellId is the id, within boundaries, of the boundary polyline that normal was computed for.

Definition at line 170 of file vtkvmtkBoundaryReferenceSystems.cxx.

171{
172 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(boundaryCellId));
173
174 int k=0;
175 if (!boundary)
176 {
177 for (k=0; k<3; k++)
178 {
179 outwardNormal[k] = normal[k];
180 }
181 return;
182 }
183
184 surface->BuildCells();
185 surface->BuildLinks();
186
187 vtkIdType *cells;
188 vtkIdType npts;
189 const vtkIdType *pts;
190 vtkIdType ncells;
191
192 double boundaryPoint[3], neighborPoint[3];
193
194 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
195
196 int j;
197 vtkIdList* boundaryIds = vtkIdList::New();
198 for (j=0; j<numberOfBoundaryPoints; j++)
199 {
200 boundaryIds->InsertNextId(static_cast<vtkIdType>(vtkMath::Round(boundaries->GetPointData()->GetScalars()->GetComponent(boundary->GetPointId(j),0))));
201 }
202
203 double neighborsToBoundaryNormal[3];
204 neighborsToBoundaryNormal[0] = neighborsToBoundaryNormal[1] = neighborsToBoundaryNormal[2] = 0.0;
205 for (j=0; j<numberOfBoundaryPoints; j++)
206 {
207 surface->GetPointCells(boundaryIds->GetId(j),ncells,cells);
208 for (int c=0; c<ncells; c++)
209 {
210 surface->GetCellPoints(cells[c],npts,pts);
211 for (int p=0; p<npts; p++)
212 {
213 if (boundaryIds->IsId(pts[p]) == -1)
214 {
215 surface->GetPoint(boundaryIds->GetId(j),boundaryPoint);
216 surface->GetPoint(pts[p],neighborPoint);
217 for (k=0; k<3; k++)
218 {
219 neighborsToBoundaryNormal[k] += boundaryPoint[k] - neighborPoint[k];
220 }
221 }
222 }
223 }
224 }
225
226 for (k=0; k<3; k++)
227 {
228 outwardNormal[k] = normal[k];
229 }
230
231 vtkMath::Normalize(neighborsToBoundaryNormal);
232
233 if (vtkMath::Dot(normal,neighborsToBoundaryNormal) < 0.0)
234 {
235 for (k=0; k<3; k++)
236 {
237 outwardNormal[k] *= -1.0;
238 }
239 }
240
241 boundaryIds->Delete();
242}

◆ ComputeReferenceSystemPoints()

void vtkvmtkBoundaryReferenceSystems::ComputeReferenceSystemPoints ( double origin[3],
double normal[3],
double radius,
double point1[3],
double point2[3] )
static

Given a boundary reference system (origin, normal, radius), compute two additional points, point1 and point2, lying on the boundary plane at the given radius from origin, such that (origin, point1) defines an arbitrary in-plane x axis and (origin, point1, point2) defines the boundary plane – used to fully pin down a local coordinate frame at each boundary (e.g. for specifying CFD boundary conditions).

Definition at line 244 of file vtkvmtkBoundaryReferenceSystems.cxx.

245{
246 point1[0] = point1[1] = point1[2] = 0.0;
247 point2[0] = point2[1] = point2[2] = 0.0;
248
249 double x_p[3], y_p[3], x[3];
250
251 x[0] = 1.0;
252 x[1] = 0.0;
253 x[2] = 0.0;
254
255 vtkMath::Cross(normal,x,x_p);
256 vtkMath::Normalize(x_p);
257
258 vtkMath::Cross(normal,x_p,y_p);
259 vtkMath::Normalize(y_p);
260
261 for (int i=0; i<3; i++)
262 {
263 point1[i] = origin[i] + x_p[i] * radius;
264 point2[i] = origin[i] + y_p[i] * radius;
265 }
266}

◆ RequestData()

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

Definition at line 268 of file vtkvmtkBoundaryReferenceSystems.cxx.

272{
273 // get the info objects
274 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
275 vtkInformation *outInfo = outputVector->GetInformationObject(0);
276
277 // get the input and output
278 vtkPolyData *input = vtkPolyData::SafeDownCast(
279 inInfo->Get(vtkDataObject::DATA_OBJECT()));
280 vtkPolyData *output = vtkPolyData::SafeDownCast(
281 outInfo->Get(vtkDataObject::DATA_OBJECT()));
282
283 if (!this->BoundaryRadiusArrayName)
284 {
285 vtkErrorMacro(<< "BoundaryRadiusArrayName not specified.");
286 return 1;
287 }
288
289 if (!this->BoundaryNormalsArrayName)
290 {
291 vtkErrorMacro(<< "BoundaryNormalsArrayName not specified.");
292 return 1;
293 }
294
295 if (!this->Point1ArrayName)
296 {
297 vtkErrorMacro(<< "Point1ArrayName not specified.");
298 return 1;
299 }
300
301 if (!this->Point2ArrayName)
302 {
303 vtkErrorMacro(<< "Point2ArrayName not specified.");
304 return 1;
305 }
306
307 vtkPoints* outputPoints = vtkPoints::New();
308 vtkCellArray* outputVerts = vtkCellArray::New();
309 vtkDoubleArray* outputRadius = vtkDoubleArray::New();
310 outputRadius->SetName(this->BoundaryRadiusArrayName);
311 vtkDoubleArray* outputNormals = vtkDoubleArray::New();
312 outputNormals->SetName(this->BoundaryNormalsArrayName);
313 outputNormals->SetNumberOfComponents(3);
314 vtkDoubleArray* point1Array = vtkDoubleArray::New();
315 point1Array->SetName(this->Point1ArrayName);
316 point1Array->SetNumberOfComponents(3);
317 vtkDoubleArray* point2Array = vtkDoubleArray::New();
318 point2Array->SetName(this->Point2ArrayName);
319 point2Array->SetNumberOfComponents(3);
320
321 vtkvmtkPolyDataBoundaryExtractor* boundaryExtractor = vtkvmtkPolyDataBoundaryExtractor::New();
322 boundaryExtractor->SetInputData(input);
323
324 boundaryExtractor->Update();
325
326 vtkPolyData* boundaries = boundaryExtractor->GetOutput();
327
328 double barycenter[3], normal[3], outwardNormal[3], meanRadius;
329
330 for (int i=0; i<boundaries->GetNumberOfCells(); i++)
331 {
332 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(i));
333
334 if (!boundary)
335 {
336 vtkErrorMacro(<<"Boundary not a vtkPolyLine");
337 continue;
338 }
339
340 this->ComputeBoundaryBarycenter(boundary->GetPoints(),barycenter);
341 meanRadius = this->ComputeBoundaryMeanRadius(boundary->GetPoints(),barycenter);
342 this->ComputeBoundaryNormal(boundary->GetPoints(),barycenter,normal);
343 this->OrientBoundaryNormalOutwards(input,boundaries,i,normal,outwardNormal);
344 double point1[3], point2[3];
345 this->ComputeReferenceSystemPoints(barycenter,normal,meanRadius,point1,point2);
346
347 vtkIdType pointId = outputPoints->InsertNextPoint(barycenter);
348 outputVerts->InsertNextCell(1);
349 outputVerts->InsertCellPoint(pointId);
350 outputNormals->InsertNextTuple(outwardNormal);
351 outputRadius->InsertNextValue(meanRadius);
352 point1Array->InsertNextTuple(point1);
353 point2Array->InsertNextTuple(point2);
354 }
355
356 output->SetPoints(outputPoints);
357 output->SetVerts(outputVerts);
358 output->GetPointData()->AddArray(outputNormals);
359 output->GetPointData()->SetActiveNormals(this->BoundaryNormalsArrayName);
360 output->GetPointData()->AddArray(outputRadius);
361 output->GetPointData()->SetActiveScalars(this->BoundaryRadiusArrayName);
362 output->GetPointData()->AddArray(point1Array);
363 output->GetPointData()->AddArray(point2Array);
364
365 outputPoints->Delete();
366 outputVerts->Delete();
367 outputNormals->Delete();
368 outputRadius->Delete();
369 point1Array->Delete();
370 point2Array->Delete();
371 boundaryExtractor->Delete();
372
373 return 1;
374}
static void ComputeBoundaryBarycenter(vtkPoints *points, double barycenter[3])
static void OrientBoundaryNormalOutwards(vtkPolyData *surface, vtkPolyData *boundaries, vtkIdType boundaryCellId, double normal[3], double outwardNormal[3])
static void ComputeBoundaryNormal(vtkPoints *points, double barycenter[3], double normal[3])
static void ComputeReferenceSystemPoints(double origin[3], double normal[3], double radius, double point1[3], double point2[3])
static double ComputeBoundaryMeanRadius(vtkPoints *points, double barycenter[3])
static vtkvmtkPolyDataBoundaryExtractor * New()

Member Data Documentation

◆ BoundaryRadiusArrayName

char* vtkvmtkBoundaryReferenceSystems::BoundaryRadiusArrayName
protected

Definition at line 134 of file vtkvmtkBoundaryReferenceSystems.h.

◆ BoundaryNormalsArrayName

char* vtkvmtkBoundaryReferenceSystems::BoundaryNormalsArrayName
protected

Definition at line 135 of file vtkvmtkBoundaryReferenceSystems.h.

◆ Point1ArrayName

char* vtkvmtkBoundaryReferenceSystems::Point1ArrayName
protected

Definition at line 136 of file vtkvmtkBoundaryReferenceSystems.h.

◆ Point2ArrayName

char* vtkvmtkBoundaryReferenceSystems::Point2ArrayName
protected

Definition at line 137 of file vtkvmtkBoundaryReferenceSystems.h.


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