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

Boundaries of a surface, stored in the surface's own point data. More...

#include <vtkvmtkBoundaryLabels.h>

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

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkBoundaryLabels * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkBoundaryLabels * SafeDownCast (vtkObjectBase *o)
static vtkvmtkBoundaryLabels * New ()
static const char * GetDefaultBoundaryLabelsArrayName ()
static const char * GetDefaultBoundaryPointOrderArrayName ()
static vtkIdType GetInvalidBoundaryLabel ()
static bool HasBoundaryLabels (vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName)
static bool GetBoundaries (vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName, vtkPolyData *boundaries, vtkIdList *boundaryLabels)
static bool GetOrExtractBoundaries (vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName, vtkPolyData *boundaries, vtkIdList *boundaryLabels, vtkObject *warningSource=nullptr)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkBoundaryLabels ()
 ~vtkvmtkBoundaryLabels () override

Detailed Description

Boundaries of a surface, stored in the surface's own point data.

A boundary has no identity of its own in these filters: it is referred to by its position in the list vtkvmtkPolyDataBoundaryExtractor returns, and that order falls out of the input's cell and point numbering. Two filters agree on which boundary is which only for as long as they are handed the very same mesh, so any filter that renumbers points, merges them, or rebuilds the surface silently permutes the ids, and a caller that carried an id across it ends up pointing at the wrong vessel end.

This class stores the whole extraction result in two point data arrays instead, so that the answer travels with the mesh:

  • the labels array holds, on each point of a boundary, the label of the boundary it belongs to, and InvalidBoundaryLabel on every other point. This is the boundary's identity, and it is also the cell entity id of the cap that closes that boundary: the cappers here read a label as the id to give the cap they build, so the one number names the vessel end in the point data and names its face in the cell data. Labels therefore start above the wall rather than at zero – vtkvmtkPolyDataBoundaryLabeler::CellEntityIdOffset is where that is decided. InvalidBoundaryLabel is negative and so is no cell entity id at all: it says the point is on no boundary, not that it belongs to any particular face.
  • the point order array holds that point's index within its boundary, 0..n-1, and InvalidBoundaryLabel elsewhere. This is the ring's order and its winding direction.

Both are written as vtkIntArray rather than the vtkIdTypeArray they would otherwise be. VTK takes an array of vtkIdType to be point ids, which cannot be interpolated onto a point that did not exist before, so it drops such an array outright rather than carry it: passing a labeled surface through vtkClipPolyData loses vtkIdTypeArray point data and keeps every other numeric type. Since surviving that is the whole point of storing the boundaries this way, they are ints. They are read back through vtkDataArray and rounded, so an array a filter has passed through as some other type is read just the same.

Neither array records a point id, so nothing in them is invalidated by renumbering. Merging coincident points keeps them (both copies of a boundary point carry the same pair), moving points keeps them, and appending points leaves the existing entries alone. Contrast a stored copy of the extractor's output, whose point scalars are input point ids and so mean nothing once the mesh they indexed has changed.

A labels array on its own would not be enough to skip the extraction: it says which points belong to a boundary but not in what order, and the cap triangle fan and the flow extension rings both need the ordered ring.

GetBoundaries() rebuilds, from the two arrays alone, a vtkPolyData in the form vtkvmtkPolyDataBoundaryExtractor produces, so a filter can use it in place of extracting.

This class does not label anything: it is the format and the reader, not the writer. To put labels on a surface use vtkvmtkPolyDataBoundaryLabeler, which is the filter that works the boundaries out and writes the two arrays, and which is what a caller normally wants. What lives here is what both ends of that arrangement have to agree on – the default array names, the value that means "not on a boundary", and the reading of the arrays back into boundaries – so that vtkvmtkCapPolyData and vtkvmtkPolyDataFlowExtensionsFilter can consume what the labeler wrote without either of them owning the format. Use it directly to read the boundaries of a surface that is already labeled, and to check whether a surface carries the arrays at all.

See also
vtkvmtkPolyDataBoundaryLabeler, vtkvmtkPolyDataBoundaryExtractor, vtkvmtkCapPolyData, vtkvmtkPolyDataFlowExtensionsFilter

Definition at line 87 of file vtkvmtkBoundaryLabels.h.

Member Typedef Documentation

◆ Superclass

Definition at line 90 of file vtkvmtkBoundaryLabels.h.

Constructor & Destructor Documentation

◆ vtkvmtkBoundaryLabels()

vtkvmtkBoundaryLabels::vtkvmtkBoundaryLabels ( )
inlineprotected

Definition at line 160 of file vtkvmtkBoundaryLabels.h.

160{}

◆ ~vtkvmtkBoundaryLabels()

vtkvmtkBoundaryLabels::~vtkvmtkBoundaryLabels ( )
inlineoverrideprotected

Definition at line 161 of file vtkvmtkBoundaryLabels.h.

161{}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkBoundaryLabels::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkBoundaryLabels * vtkvmtkBoundaryLabels::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 254 of file vtkvmtkBoundaryLabels.cxx.

255{
256 this->Superclass::PrintSelf(os,indent);
257}

◆ New()

vtkvmtkBoundaryLabels * vtkvmtkBoundaryLabels::New ( )
static

◆ GetDefaultBoundaryLabelsArrayName()

const char * vtkvmtkBoundaryLabels::GetDefaultBoundaryLabelsArrayName ( )
inlinestatic

Name the filters use for the labels array unless told otherwise.

Definition at line 98 of file vtkvmtkBoundaryLabels.h.

98{ return "BoundaryLabels"; }

◆ GetDefaultBoundaryPointOrderArrayName()

const char * vtkvmtkBoundaryLabels::GetDefaultBoundaryPointOrderArrayName ( )
inlinestatic

Name the filters use for the point order array unless told otherwise.

Definition at line 103 of file vtkvmtkBoundaryLabels.h.

103{ return "BoundaryPointOrder"; }

◆ GetInvalidBoundaryLabel()

vtkIdType vtkvmtkBoundaryLabels::GetInvalidBoundaryLabel ( )
inlinestatic

Value both arrays carry on a point that is not on a boundary. Any negative value is read the same way, so a label is always non-negative.

Definition at line 109 of file vtkvmtkBoundaryLabels.h.

109{ return -1; }

◆ HasBoundaryLabels()

bool vtkvmtkBoundaryLabels::HasBoundaryLabels ( vtkPolyData * surface,
const char * boundaryLabelsArrayName,
const char * boundaryPointOrderArrayName )
static

Whether surface carries both arrays, sized to its points. Says nothing about whether their contents still describe the surface: only GetBoundaries() can answer that.

Definition at line 66 of file vtkvmtkBoundaryLabels.cxx.

67{
68 return GetSingleComponentPointArray(surface,boundaryLabelsArrayName) != nullptr
69 && GetSingleComponentPointArray(surface,boundaryPointOrderArrayName) != nullptr;
70}

◆ GetBoundaries()

bool vtkvmtkBoundaryLabels::GetBoundaries ( vtkPolyData * surface,
const char * boundaryLabelsArrayName,
const char * boundaryPointOrderArrayName,
vtkPolyData * boundaries,
vtkIdList * boundaryLabels )
static

Rebuild the boundaries of surface from the two arrays, without extracting them.

boundaries is filled in the form vtkvmtkPolyDataBoundaryExtractor produces - the boundary points copied into their own vtkPoints, one polyline cell per boundary, and point scalars holding the id, in surface, of each of those points - so that it can be used wherever the extractor's output is. Boundaries come out in ascending label order, and boundaryLabels, if given, receives the label of each cell of boundaries in turn.

Returns false, leaving boundaries empty, when the arrays are missing or no longer describe surface, in which case the caller should extract the boundaries instead. What is checked is that every label owns a whole run of point order values, 0..n-1, with none missing, none repeated, and at least three points - enough to catch an array left over from an earlier mesh, a merge that collapsed two points of a ring onto one, and the fractional values a clipping filter leaves behind when it interpolates the arrays onto the points it creates. A boundary whose points were all removed simply disappears, which is not an error.

Nor is a boundary that is no longer open. The labels stay on the points of a boundary that has been capped, on purpose, as a record of which vessel end that ring was, so a surface that has been through a capper carries rings with cells on both sides of them. Only rings every edge of which still has a single cell behind it are returned, which is what the extractor would have found; a surface every boundary of which has been closed comes back with none, the same answer as for a surface that never had any.

Definition at line 72 of file vtkvmtkBoundaryLabels.cxx.

73{
74 if (!boundaries)
75 {
76 return false;
77 }
78
79 boundaries->Initialize();
80 if (boundaryLabels)
81 {
82 boundaryLabels->Initialize();
83 }
84
85 vtkDataArray* labelsArray = GetSingleComponentPointArray(surface,boundaryLabelsArrayName);
86 vtkDataArray* orderArray = GetSingleComponentPointArray(surface,boundaryPointOrderArrayName);
87 if (!labelsArray || !orderArray)
88 {
89 return false;
90 }
91
92 // Gather the points of each boundary, keyed by label so that the boundaries come out in
93 // ascending label order however the points happen to be numbered.
94 std::map<vtkIdType,std::vector<std::pair<vtkIdType,vtkIdType> > > pointsByLabel;
95 vtkIdType numberOfPoints = surface->GetNumberOfPoints();
96 for (vtkIdType pointId=0; pointId<numberOfPoints; pointId++)
97 {
98 vtkIdType label = GetValue(labelsArray,pointId);
99 if (label < 0)
100 {
101 continue;
102 }
103 vtkIdType order = GetValue(orderArray,pointId);
104 if (order < 0)
105 {
106 // On a boundary by one array and not by the other: the two no longer agree, so neither
107 // can be trusted.
108 return false;
109 }
110 pointsByLabel[label].push_back(std::make_pair(order,pointId));
111 }
112
113 if (pointsByLabel.empty())
114 {
115 // A closed surface has no boundaries, and saying so is a valid answer rather than a
116 // failure. The arrays are still there, so the caller has nothing to fall back to.
117 vtkNew<vtkPoints> emptyPoints;
118 vtkNew<vtkCellArray> emptyLines;
119 vtkNew<vtkIdTypeArray> emptyScalars;
120 boundaries->SetPoints(emptyPoints);
121 boundaries->SetLines(emptyLines);
122 boundaries->GetPointData()->SetScalars(emptyScalars);
123 return true;
124 }
125
126 // Cell links, to tell an edge that still has only one cell behind it from one that has been
127 // closed since. Built on a copy of the structure rather than on surface itself: BuildLinks on
128 // the caller's own polydata leaves it holding a reference it did not ask for.
129 vtkNew<vtkPolyData> working;
130 working->CopyStructure(surface);
131 working->BuildLinks();
132 vtkNew<vtkIdList> edgeNeighbors;
133
134 std::vector<vtkIdType> closedLabels;
135 for (std::map<vtkIdType,std::vector<std::pair<vtkIdType,vtkIdType> > >::iterator
136 boundary=pointsByLabel.begin(); boundary!=pointsByLabel.end(); ++boundary)
137 {
138 std::vector<std::pair<vtkIdType,vtkIdType> >& ring = boundary->second;
139 // A ring of fewer than three points is not one the extractor would have emitted
140 // (see vtkvmtkPolyDataBoundaryExtractor, which requires more than two).
141 if (ring.size() < 3)
142 {
143 return false;
144 }
145 std::sort(ring.begin(),ring.end());
146 // The order values have to be the whole run 0..n-1. A gap, a repeat, or a value off the end
147 // means the ring this describes is not the ring that is there now.
148 for (size_t index=0; index<ring.size(); index++)
149 {
150 if (ring[index].first != static_cast<vtkIdType>(index))
151 {
152 return false;
153 }
154 }
155 // A ring the arrays describe is not necessarily still an open boundary. The labels are left
156 // on the points of a boundary that has been capped, on purpose, as a record of which vessel
157 // end that ring was -- so a surface that has been through a capper carries rings with cells
158 // on both sides of them. Handing one of those back as a boundary has it capped a second
159 // time, over the cap already there, which is not an error anywhere it would be noticed: the
160 // surface comes back closed, of very nearly the right size, and non-manifold along every rim.
161 // What the extractor would return is the test, and it returns open boundaries only.
162 size_t numberOfRingPoints = ring.size();
163 bool stillOpen = true;
164 for (size_t index=0; index<numberOfRingPoints && stillOpen; index++)
165 {
166 working->GetCellEdgeNeighbors(-1,ring[index].second,
167 ring[(index+1)%numberOfRingPoints].second,edgeNeighbors);
168 // One cell behind the edge and it is on the boundary of the surface; two and it is inside
169 // it. Zero means the two points are no longer joined by an edge at all, which is no more
170 // an open boundary than the others.
171 stillOpen = (edgeNeighbors->GetNumberOfIds() == 1);
172 }
173 if (!stillOpen)
174 {
175 closedLabels.push_back(boundary->first);
176 }
177 }
178 for (size_t index=0; index<closedLabels.size(); index++)
179 {
180 pointsByLabel.erase(closedLabels[index]);
181 }
182
183 // Each point of a boundary is listed once, the way vtkvmtkPolyDataBoundaryExtractor lists
184 // them, so that a boundary reconstructed from the arrays is the boundary the extractor would
185 // have produced and the two ways of getting the boundaries of a surface are interchangeable.
186 vtkNew<vtkPoints> newPoints;
187 vtkNew<vtkCellArray> newLines;
188 vtkNew<vtkIdTypeArray> newScalars;
189 vtkNew<vtkIdList> newCell;
190
191 for (std::map<vtkIdType,std::vector<std::pair<vtkIdType,vtkIdType> > >::iterator
192 boundary=pointsByLabel.begin(); boundary!=pointsByLabel.end(); ++boundary)
193 {
194 const std::vector<std::pair<vtkIdType,vtkIdType> >& ring = boundary->second;
195
196 newCell->Initialize();
197 newCell->SetNumberOfIds(static_cast<vtkIdType>(ring.size()));
198 for (size_t index=0; index<ring.size(); index++)
199 {
200 vtkIdType pointId = ring[index].second;
201 newCell->SetId(static_cast<vtkIdType>(index),newPoints->InsertNextPoint(surface->GetPoint(pointId)));
202 newScalars->InsertNextValue(pointId);
203 }
204
205 newLines->InsertNextCell(newCell);
206
207 if (boundaryLabels)
208 {
209 boundaryLabels->InsertNextId(boundary->first);
210 }
211 }
212
213 boundaries->SetPoints(newPoints);
214 boundaries->SetLines(newLines);
215 boundaries->GetPointData()->SetScalars(newScalars);
216
217 return true;
218}

◆ GetOrExtractBoundaries()

bool vtkvmtkBoundaryLabels::GetOrExtractBoundaries ( vtkPolyData * surface,
const char * boundaryLabelsArrayName,
const char * boundaryPointOrderArrayName,
vtkPolyData * boundaries,
vtkIdList * boundaryLabels,
vtkObject * warningSource = nullptr )
static

The boundaries of surface, read from the labels when both array names are given and the arrays still describe it, and extracted with vtkvmtkPolyDataBoundaryExtractor otherwise.

boundaries is filled either way, in the form the extractor produces, so a filter can work from it without knowing which of the two happened. boundaryLabels holds the label of each boundary when the labels were used and is emptied when they were not, and the return value says which – and so says what a boundary's id means: its label with the labels in use, and its position in the extraction order without them.

A surface that names the arrays but no longer carries ones describing it falls back to extraction, which renames every cap a caller had chosen an id for. Pass the calling filter as warningSource to have that said rather than passed over.

Definition at line 220 of file vtkvmtkBoundaryLabels.cxx.

221{
222 if (!surface || !boundaries)
223 {
224 return false;
225 }
226
227 if (boundaryLabels)
228 {
229 boundaryLabels->Reset();
230 }
231
232 if (boundaryLabelsArrayName && boundaryLabelsArrayName[0]
233 && boundaryPointOrderArrayName && boundaryPointOrderArrayName[0])
234 {
235 if (vtkvmtkBoundaryLabels::GetBoundaries(surface,boundaryLabelsArrayName,boundaryPointOrderArrayName,boundaries,boundaryLabels))
236 {
237 return true;
238 }
239 if (warningSource)
240 {
241 vtkWarningWithObjectMacro(warningSource,<<"The boundary label arrays are missing from the input surface or no longer describe it; "
242 <<"extracting its boundaries instead, and naming the caps by position.");
243 }
244 }
245
246 vtkNew<vtkvmtkPolyDataBoundaryExtractor> boundaryExtractor;
247 boundaryExtractor->SetInputData(surface);
248 boundaryExtractor->Update();
249 boundaries->ShallowCopy(boundaryExtractor->GetOutput());
250
251 return false;
252}
static bool GetBoundaries(vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName, vtkPolyData *boundaries, vtkIdList *boundaryLabels)

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