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

Give each open boundary of a surface a label that stays with it. More...

#include <vtkvmtkPolyDataBoundaryLabeler.h>

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

Public Types

enum  { BOUNDARY_EXTRACTION_ORDER , CLOSEST_TO_PLANE_ORIGIN , ON_PLANE , MATCH_EXISTING_LABELS }
typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataBoundaryLabeler * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual vtkIdType GetNumberOfBoundaries ()
virtual vtkIdList * GetBoundaryLabels ()
virtual vtkIdList * GetUnmatchedPlaneLabels ()
virtual void SetBoundaryLabelsArrayName (const char *)
virtual char * GetBoundaryLabelsArrayName ()
virtual void SetBoundaryPointOrderArrayName (const char *)
virtual char * GetBoundaryPointOrderArrayName ()
virtual void SetLabelingMode (int)
virtual int GetLabelingMode ()
void SetLabelingModeToBoundaryExtractionOrder ()
void SetLabelingModeToClosestToPlaneOrigin ()
void SetLabelingModeToOnPlane ()
void SetLabelingModeToMatchExistingLabels ()
virtual void SetCellEntityIdOffset (vtkIdType)
virtual vtkIdType GetCellEntityIdOffset ()
virtual void SetAnnular (bool)
virtual bool GetAnnular ()
virtual void AnnularOn ()
virtual void AnnularOff ()
virtual void SetAnnularOuterBoundaryOffset (vtkIdType)
virtual vtkIdType GetAnnularOuterBoundaryOffset ()
virtual void SetPlaneOrigins (vtkPoints *)
virtual vtkPoints * GetPlaneOrigins ()
virtual void SetPlaneNormals (vtkDoubleArray *)
virtual vtkDoubleArray * GetPlaneNormals ()
virtual void SetPlaneLabels (vtkIdList *)
virtual vtkIdList * GetPlaneLabels ()
virtual void SetMaximumDistanceFromPlane (double)
virtual double GetMaximumDistanceFromPlane ()
virtual void SetMaximumDistanceFromPlaneOrigin (double)
virtual double GetMaximumDistanceFromPlaneOrigin ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataBoundaryLabeler ()
 ~vtkvmtkPolyDataBoundaryLabeler () override
int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void LabelAnnularPairs (vtkPolyData *boundaries, std::vector< vtkIdType > &labels)

Protected Attributes

char * BoundaryLabelsArrayName
char * BoundaryPointOrderArrayName
int LabelingMode
vtkIdType CellEntityIdOffset
bool Annular
vtkIdType AnnularOuterBoundaryOffset
vtkPoints * PlaneOrigins
vtkDoubleArray * PlaneNormals
vtkIdList * PlaneLabels
double MaximumDistanceFromPlane
double MaximumDistanceFromPlaneOrigin
vtkIdType NumberOfBoundaries
vtkIdList * BoundaryLabels
vtkIdList * UnmatchedPlaneLabels

Detailed Description

Give each open boundary of a surface a label that stays with it.

Extracts the open boundaries of the input surface and records them in two point data arrays, so that later filters can tell the boundaries apart without extracting them again and without relying on the extraction order staying put. See vtkvmtkBoundaryLabels for what the arrays hold and why they are point data.

This is meant to be the one place the boundaries of a surface are worked out. A boundary is identified here, once, from geometry the caller already has – the points it clicked, or the planes it cut with – and from then on the label is carried by the mesh rather than recomputed, so vtkvmtkCapPolyData and vtkvmtkPolyDataFlowExtensionsFilter can be told which vessel end is which without the caller having to translate ids across each of them.

A boundary's label is the cell entity id its cap will carry. That is the whole point of the numbering: a cap is asked for by the same number that names the vessel end it closes, so nothing has to be translated between the point data that says which end a boundary is and the cell data a solver reads its boundary conditions off. Labels therefore start above the wall, at CellEntityIdOffset+1, rather than at zero – see CellEntityIdOffset.

The labeling modes differ only in where the labels come from:

  • BoundaryExtractionOrder gives boundary i the label i+1+CellEntityIdOffset, i being its position in the order vtkvmtkPolyDataBoundaryExtractor returns the boundaries in. These are exactly the ids vtkvmtkCapPolyData would have given the caps had it been left to number them itself, so a surface labeled this way is capped exactly as an unlabeled one is.
  • ClosestToPlaneOrigin gives each plane's label to the boundary lying nearest its origin. The plane's normal is not used, so a caller with nothing but a position to point at a vessel end with can give the position as the origin and leave the normals unset.
  • OnPlane gives a boundary a plane's label when every one of its points lies in that plane, within MaximumDistanceFromPlane. A boundary only partly in the plane is left alone rather than claimed, so a hole the surface already had cannot take the label of a cut. Where more than one boundary lies in the same plane, the one nearest its origin is taken and the rest are left to be labeled in their own right, so which of them it is does not come down to which the extractor happened to reach first.

Both take a boundary only when it lies entirely within MaximumDistanceFromPlaneOrigin of the plane's origin, which is what keeps a match local. A plane is infinite and a surface is not: without that, a boundary on a different branch that happens to be coplanar with this cut, or one merely nearest to it across a gap, would be claimed on the strength of a coincidence.

  • MatchExistingLabels gives a boundary the label a strict majority of its own points already carry, and is how a surface is brought back into line after a filter that knew nothing about the arrays. Nothing is matched by distance: a boundary whose points do not agree – a newly cut one, whose points are all new – gets a fresh label rather than the label of whichever boundary happens to lie nearest. It matches the labels, not the geometry, and repairs neither: the boundaries are whatever the extractor finds in the mesh as it stands.

In every mode a boundary that ends up with no label of its own is given a fresh one, above every label already in use and never below CellEntityIdOffset+1, so no two boundaries ever share a label and none of them is mistaken for the wall. Planes that matched no boundary are reported in UnmatchedPlaneLabels rather than passed over in silence.

This is the class to use. It uses vtkvmtkBoundaryLabels internally – the names of the two arrays and the value that means "not on a boundary" come from there, and that class is what reads the arrays back into boundaries again – but vtkvmtkBoundaryLabels only defines and reads the format, and labels nothing itself.

What makes going through this filter better than letting each filter work the boundaries out for itself is that the boundary information ends up stored in the mesh. Downstream filters do not extract the boundaries again: they read them from the arrays. That keeps them consistent, since every filter is then looking at the same boundaries in the same order rather than at whatever three separate extractions happen to agree on, and it saves the work of extracting them over and over, which on a large surface is not free.

See also
vtkvmtkBoundaryLabels, vtkvmtkPolyDataBoundaryExtractor, vtkvmtkCapPolyData, vtkvmtkPolyDataFlowExtensionsFilter

Definition at line 99 of file vtkvmtkPolyDataBoundaryLabeler.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkPolyDataBoundaryLabeler::Superclass

Definition at line 102 of file vtkvmtkPolyDataBoundaryLabeler.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataBoundaryLabeler()

vtkvmtkPolyDataBoundaryLabeler::vtkvmtkPolyDataBoundaryLabeler ( )
protected

Definition at line 76 of file vtkvmtkPolyDataBoundaryLabeler.cxx.

77{
78 this->BoundaryLabelsArrayName = nullptr;
80 this->BoundaryPointOrderArrayName = nullptr;
82
84 this->CellEntityIdOffset = 1;
85 this->Annular = false;
86 this->AnnularOuterBoundaryOffset = 1000;
87
88 this->PlaneOrigins = nullptr;
89 this->PlaneNormals = nullptr;
90 this->PlaneLabels = nullptr;
91 this->MaximumDistanceFromPlane = 0.0;
93
94 this->NumberOfBoundaries = 0;
95 this->BoundaryLabels = vtkIdList::New();
96 this->UnmatchedPlaneLabels = vtkIdList::New();
97}
static const char * GetDefaultBoundaryLabelsArrayName()
static const char * GetDefaultBoundaryPointOrderArrayName()
virtual void SetBoundaryLabelsArrayName(const char *)
virtual void SetBoundaryPointOrderArrayName(const char *)

◆ ~vtkvmtkPolyDataBoundaryLabeler()

vtkvmtkPolyDataBoundaryLabeler::~vtkvmtkPolyDataBoundaryLabeler ( )
overrideprotected

Definition at line 99 of file vtkvmtkPolyDataBoundaryLabeler.cxx.

100{
101 this->SetBoundaryLabelsArrayName(nullptr);
102 this->SetBoundaryPointOrderArrayName(nullptr);
103
104 this->SetPlaneOrigins(nullptr);
105 this->SetPlaneNormals(nullptr);
106 this->SetPlaneLabels(nullptr);
107
108 this->BoundaryLabels->Delete();
109 this->BoundaryLabels = nullptr;
110 this->UnmatchedPlaneLabels->Delete();
111 this->UnmatchedPlaneLabels = nullptr;
112}
virtual void SetPlaneNormals(vtkDoubleArray *)
virtual void SetPlaneLabels(vtkIdList *)
virtual void SetPlaneOrigins(vtkPoints *)

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataBoundaryLabeler::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataBoundaryLabeler * vtkvmtkPolyDataBoundaryLabeler::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 564 of file vtkvmtkPolyDataBoundaryLabeler.cxx.

565{
566 this->Superclass::PrintSelf(os,indent);
567}

◆ New()

vtkvmtkPolyDataBoundaryLabeler * vtkvmtkPolyDataBoundaryLabeler::New ( )
static

◆ SetBoundaryLabelsArrayName()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetBoundaryLabelsArrayName ( const char * )
virtual

Set/Get the name of the point data array where each boundary point's label is written. Defaults to vtkvmtkBoundaryLabels::GetDefaultBoundaryLabelsArrayName().

◆ GetBoundaryLabelsArrayName()

virtual char * vtkvmtkPolyDataBoundaryLabeler::GetBoundaryLabelsArrayName ( )
virtual

Set/Get the name of the point data array where each boundary point's label is written. Defaults to vtkvmtkBoundaryLabels::GetDefaultBoundaryLabelsArrayName().

◆ SetBoundaryPointOrderArrayName()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetBoundaryPointOrderArrayName ( const char * )
virtual

Set/Get the name of the point data array where each boundary point's index within its own boundary is written. Defaults to vtkvmtkBoundaryLabels::GetDefaultBoundaryPointOrderArrayName().

◆ GetBoundaryPointOrderArrayName()

virtual char * vtkvmtkPolyDataBoundaryLabeler::GetBoundaryPointOrderArrayName ( )
virtual

Set/Get the name of the point data array where each boundary point's index within its own boundary is written. Defaults to vtkvmtkBoundaryLabels::GetDefaultBoundaryPointOrderArrayName().

◆ SetLabelingMode()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetLabelingMode ( int )
virtual

Set/Get where the labels come from. See the class documentation.

◆ GetLabelingMode()

virtual int vtkvmtkPolyDataBoundaryLabeler::GetLabelingMode ( )
virtual

Set/Get where the labels come from. See the class documentation.

◆ SetLabelingModeToBoundaryExtractionOrder()

void vtkvmtkPolyDataBoundaryLabeler::SetLabelingModeToBoundaryExtractionOrder ( )
inline

Set/Get where the labels come from. See the class documentation.

Definition at line 142 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ SetLabelingModeToClosestToPlaneOrigin()

void vtkvmtkPolyDataBoundaryLabeler::SetLabelingModeToClosestToPlaneOrigin ( )
inline

Set/Get where the labels come from. See the class documentation.

Definition at line 143 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ SetLabelingModeToOnPlane()

void vtkvmtkPolyDataBoundaryLabeler::SetLabelingModeToOnPlane ( )
inline

Set/Get where the labels come from. See the class documentation.

Definition at line 144 of file vtkvmtkPolyDataBoundaryLabeler.h.

144{ this->SetLabelingMode(ON_PLANE); }

◆ SetLabelingModeToMatchExistingLabels()

void vtkvmtkPolyDataBoundaryLabeler::SetLabelingModeToMatchExistingLabels ( )
inline

Set/Get where the labels come from. See the class documentation.

Definition at line 145 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ SetCellEntityIdOffset()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetCellEntityIdOffset ( vtkIdType )
virtual

Set/Get the cell entity id of the wall, which the labels are numbered above. Default 1, the same value vtkvmtkCapPolyData's own CellEntityIdOffset defaults to.

A label is the cell entity id of the cap that will close its boundary, and the cappers leave CellEntityIdOffset on the cells they copied from their input. So the first id a cap may take is CellEntityIdOffset+1: this is what keeps a label off the wall, and off the 0 the volume elements of a mesh carry. Set it to whatever the capper this surface will go to is set to.

◆ GetCellEntityIdOffset()

virtual vtkIdType vtkvmtkPolyDataBoundaryLabeler::GetCellEntityIdOffset ( )
virtual

Set/Get the cell entity id of the wall, which the labels are numbered above. Default 1, the same value vtkvmtkCapPolyData's own CellEntityIdOffset defaults to.

A label is the cell entity id of the cap that will close its boundary, and the cappers leave CellEntityIdOffset on the cells they copied from their input. So the first id a cap may take is CellEntityIdOffset+1: this is what keeps a label off the wall, and off the 0 the volume elements of a mesh carry. Set it to whatever the capper this surface will go to is set to.

◆ SetAnnular()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetAnnular ( bool )
virtual

Set/Get whether the input is a walled surface, whose open boundaries come in pairs – an inner boundary and the outer one facing it across the wall thickness.

With this off (default) every boundary is labelled on its own, and the two boundaries of a wall end up with unrelated labels. With it on the boundaries are paired by barycenter distance, the inner boundary of each pair is labelled as it would have been anyway, and its outer partner takes that label plus AnnularOuterBoundaryOffset. Of a pair, the inner is whichever has the smaller mean radius.

The point of the arrangement is that the two labels of a wall are then related by a known constant, and the inner one is always the lower of the two: a filter that caps the annulus between them names its cap after the lower id, and so always names it after the vessel end the caller meant, whichever way round the pair was found. An odd boundary with no partner keeps the label it was given.

◆ GetAnnular()

virtual bool vtkvmtkPolyDataBoundaryLabeler::GetAnnular ( )
virtual

Set/Get whether the input is a walled surface, whose open boundaries come in pairs – an inner boundary and the outer one facing it across the wall thickness.

With this off (default) every boundary is labelled on its own, and the two boundaries of a wall end up with unrelated labels. With it on the boundaries are paired by barycenter distance, the inner boundary of each pair is labelled as it would have been anyway, and its outer partner takes that label plus AnnularOuterBoundaryOffset. Of a pair, the inner is whichever has the smaller mean radius.

The point of the arrangement is that the two labels of a wall are then related by a known constant, and the inner one is always the lower of the two: a filter that caps the annulus between them names its cap after the lower id, and so always names it after the vessel end the caller meant, whichever way round the pair was found. An odd boundary with no partner keeps the label it was given.

◆ AnnularOn()

virtual void vtkvmtkPolyDataBoundaryLabeler::AnnularOn ( )
virtual

Set/Get whether the input is a walled surface, whose open boundaries come in pairs – an inner boundary and the outer one facing it across the wall thickness.

With this off (default) every boundary is labelled on its own, and the two boundaries of a wall end up with unrelated labels. With it on the boundaries are paired by barycenter distance, the inner boundary of each pair is labelled as it would have been anyway, and its outer partner takes that label plus AnnularOuterBoundaryOffset. Of a pair, the inner is whichever has the smaller mean radius.

The point of the arrangement is that the two labels of a wall are then related by a known constant, and the inner one is always the lower of the two: a filter that caps the annulus between them names its cap after the lower id, and so always names it after the vessel end the caller meant, whichever way round the pair was found. An odd boundary with no partner keeps the label it was given.

◆ AnnularOff()

virtual void vtkvmtkPolyDataBoundaryLabeler::AnnularOff ( )
virtual

Set/Get whether the input is a walled surface, whose open boundaries come in pairs – an inner boundary and the outer one facing it across the wall thickness.

With this off (default) every boundary is labelled on its own, and the two boundaries of a wall end up with unrelated labels. With it on the boundaries are paired by barycenter distance, the inner boundary of each pair is labelled as it would have been anyway, and its outer partner takes that label plus AnnularOuterBoundaryOffset. Of a pair, the inner is whichever has the smaller mean radius.

The point of the arrangement is that the two labels of a wall are then related by a known constant, and the inner one is always the lower of the two: a filter that caps the annulus between them names its cap after the lower id, and so always names it after the vessel end the caller meant, whichever way round the pair was found. An odd boundary with no partner keeps the label it was given.

◆ SetAnnularOuterBoundaryOffset()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetAnnularOuterBoundaryOffset ( vtkIdType )
virtual

Set/Get what is added to an inner boundary's label to give its outer partner's, when Annular is on. Default 1000.

It has to be larger than the highest label the surface will ever carry, or an outer boundary's label collides with some other boundary's inner one.

◆ GetAnnularOuterBoundaryOffset()

virtual vtkIdType vtkvmtkPolyDataBoundaryLabeler::GetAnnularOuterBoundaryOffset ( )
virtual

Set/Get what is added to an inner boundary's label to give its outer partner's, when Annular is on. Default 1000.

It has to be larger than the highest label the surface will ever carry, or an outer boundary's label collides with some other boundary's inner one.

◆ SetPlaneOrigins()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetPlaneOrigins ( vtkPoints * )
virtual

Set/Get the origins of the planes, one per plane. A point is a plane whose normal is never asked for, so this is also where a caller with only positions to offer puts them.

◆ GetPlaneOrigins()

virtual vtkPoints * vtkvmtkPolyDataBoundaryLabeler::GetPlaneOrigins ( )
virtual

Set/Get the origins of the planes, one per plane. A point is a plane whose normal is never asked for, so this is also where a caller with only positions to offer puts them.

◆ SetPlaneNormals()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetPlaneNormals ( vtkDoubleArray * )
virtual

Set/Get the normals of the planes, one 3-component tuple per plane. They need not be unit length. Required by the OnPlane mode and ignored by the others.

◆ GetPlaneNormals()

virtual vtkDoubleArray * vtkvmtkPolyDataBoundaryLabeler::GetPlaneNormals ( )
virtual

Set/Get the normals of the planes, one 3-component tuple per plane. They need not be unit length. Required by the OnPlane mode and ignored by the others.

◆ SetPlaneLabels()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetPlaneLabels ( vtkIdList * )
virtual

Set/Get the label to give the boundary each plane matches. Entry i belongs to plane i. When not set, plane i is taken to carry the label i+1+CellEntityIdOffset.

A label set here is taken as it stands, so a caller choosing its own is the one responsible for keeping them above the wall: a label of CellEntityIdOffset or below names a cap that cannot be told from the wall it is set into.

◆ GetPlaneLabels()

virtual vtkIdList * vtkvmtkPolyDataBoundaryLabeler::GetPlaneLabels ( )
virtual

Set/Get the label to give the boundary each plane matches. Entry i belongs to plane i. When not set, plane i is taken to carry the label i+1+CellEntityIdOffset.

A label set here is taken as it stands, so a caller choosing its own is the one responsible for keeping them above the wall: a label of CellEntityIdOffset or below names a cap that cannot be told from the wall it is set into.

◆ SetMaximumDistanceFromPlane()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetMaximumDistanceFromPlane ( double )
virtual

Set/Get how far any point of a boundary may be from a plane for that boundary to count as lying in it. Used by the OnPlane mode, which requires a positive value: a plane is infinite, so with no limit every boundary lies in every plane.

◆ GetMaximumDistanceFromPlane()

virtual double vtkvmtkPolyDataBoundaryLabeler::GetMaximumDistanceFromPlane ( )
virtual

Set/Get how far any point of a boundary may be from a plane for that boundary to count as lying in it. Used by the OnPlane mode, which requires a positive value: a plane is infinite, so with no limit every boundary lies in every plane.

◆ SetMaximumDistanceFromPlaneOrigin()

virtual void vtkvmtkPolyDataBoundaryLabeler::SetMaximumDistanceFromPlaneOrigin ( double )
virtual

Set/Get how far any point of a boundary may be from a plane's origin for that boundary to be a candidate for that plane's label. A boundary is considered only when it lies entirely within this distance – one point of it beyond and it is passed over, however well the rest of it fits – which is what confines a match to the neighbourhood of the origin. Zero or less puts no limit on it. Used by both the ClosestToPlaneOrigin and the OnPlane modes.

◆ GetMaximumDistanceFromPlaneOrigin()

virtual double vtkvmtkPolyDataBoundaryLabeler::GetMaximumDistanceFromPlaneOrigin ( )
virtual

Set/Get how far any point of a boundary may be from a plane's origin for that boundary to be a candidate for that plane's label. A boundary is considered only when it lies entirely within this distance – one point of it beyond and it is passed over, however well the rest of it fits – which is what confines a match to the neighbourhood of the origin. Zero or less puts no limit on it. Used by both the ClosestToPlaneOrigin and the OnPlane modes.

◆ GetNumberOfBoundaries()

virtual vtkIdType vtkvmtkPolyDataBoundaryLabeler::GetNumberOfBoundaries ( )
virtual

Number of open boundaries found in the input, valid after Update().

◆ GetBoundaryLabels()

virtual vtkIdList * vtkvmtkPolyDataBoundaryLabeler::GetBoundaryLabels ( )
virtual

The label given to each boundary, in the order the boundaries were extracted, valid after Update(). Use it to relate a label back to a positional boundary id, for a filter that has not been told the array names.

◆ GetUnmatchedPlaneLabels()

virtual vtkIdList * vtkvmtkPolyDataBoundaryLabeler::GetUnmatchedPlaneLabels ( )
virtual

The labels of the planes that claimed no boundary, valid after Update(). A plane lands here when nothing was near enough, when the boundary it would have claimed had already been taken by an earlier plane, or when its boundary is not there at all – a cut that removed another cut's boundary, say.

◆ RequestData()

int vtkvmtkPolyDataBoundaryLabeler::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotected

Definition at line 114 of file vtkvmtkPolyDataBoundaryLabeler.cxx.

118{
119 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
120 vtkInformation *outInfo = outputVector->GetInformationObject(0);
121
122 vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
123 vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
124
125 // The mesh is untouched; only the two arrays are new, so pass everything through and add them
126 // to the output's own point data rather than to the input's.
127 output->CopyStructure(input);
128 output->GetPointData()->PassData(input->GetPointData());
129 output->GetCellData()->PassData(input->GetCellData());
130
131 this->NumberOfBoundaries = 0;
132 this->BoundaryLabels->Initialize();
133 this->UnmatchedPlaneLabels->Initialize();
134
137 {
138 vtkErrorMacro(<<"Both BoundaryLabelsArrayName and BoundaryPointOrderArrayName have to be set.");
139 return 1;
140 }
141
142 const vtkIdType invalidLabel = vtkvmtkBoundaryLabels::GetInvalidBoundaryLabel();
143 vtkIdType numberOfPoints = input->GetNumberOfPoints();
144
145 vtkNew<vtkIntArray> labelsArray;
146 labelsArray->SetName(this->BoundaryLabelsArrayName);
147 labelsArray->SetNumberOfTuples(numberOfPoints);
148 labelsArray->FillComponent(0,static_cast<double>(invalidLabel));
149
150 vtkNew<vtkIntArray> orderArray;
151 orderArray->SetName(this->BoundaryPointOrderArrayName);
152 orderArray->SetNumberOfTuples(numberOfPoints);
153 orderArray->FillComponent(0,static_cast<double>(invalidLabel));
154
155 vtkNew<vtkvmtkPolyDataBoundaryExtractor> boundaryExtractor;
156 boundaryExtractor->SetInputData(input);
157 boundaryExtractor->Update();
158 vtkPolyData* boundaries = boundaryExtractor->GetOutput();
159 vtkDataArray* boundaryPointIds = boundaries->GetPointData()->GetScalars();
160
161 // The points of each boundary, as ids into the input, in the order the extractor walked them.
162 std::vector<std::vector<vtkIdType> > rings;
163 for (vtkIdType boundaryIndex=0; boundaryIndex<boundaries->GetNumberOfCells(); boundaryIndex++)
164 {
165 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(boundaryIndex));
166 if (!boundary || !boundaryPointIds)
167 {
168 continue;
169 }
170 vtkIdType numberOfBoundaryPoints = boundary->GetNumberOfPoints();
171 std::vector<vtkIdType> ring;
172 ring.reserve(numberOfBoundaryPoints);
173 for (vtkIdType j=0; j<numberOfBoundaryPoints; j++)
174 {
175 ring.push_back(static_cast<vtkIdType>(vtkMath::Round(
176 boundaryPointIds->GetComponent(boundary->GetPointId(j),0))));
177 }
178 rings.push_back(ring);
179 }
180
181 vtkIdType numberOfBoundaries = static_cast<vtkIdType>(rings.size());
182 std::vector<vtkIdType> labels(rings.size(),invalidLabel);
183
184 // Labels already in use, so that a boundary given a fresh one never collides with a label a
185 // end point asked for, or with one that is on the surface already but on no boundary any more.
186 // It starts at the wall rather than at invalidLabel because a label is a cap's cell entity id,
187 // and the first id a cap may take is the one above the wall (see CellEntityIdOffset).
188 vtkIdType highestLabelInUse = this->CellEntityIdOffset;
189
190 vtkIdType numberOfPlanes = 0;
192 && this->PlaneOrigins)
193 {
194 numberOfPlanes = this->PlaneOrigins->GetNumberOfPoints();
195 if (this->LabelingMode == ON_PLANE
196 && this->PlaneNormals && this->PlaneNormals->GetNumberOfTuples() < numberOfPlanes)
197 {
198 numberOfPlanes = this->PlaneNormals->GetNumberOfTuples();
199 }
200 }
201 std::vector<vtkIdType> planeLabels(numberOfPlanes,invalidLabel);
202 std::vector<bool> planeMatched(numberOfPlanes,false);
203 for (vtkIdType planeIndex=0; planeIndex<numberOfPlanes; planeIndex++)
204 {
205 planeLabels[planeIndex] = this->PlaneLabels && planeIndex < this->PlaneLabels->GetNumberOfIds()
206 ? this->PlaneLabels->GetId(planeIndex) : planeIndex+1+this->CellEntityIdOffset;
207 if (planeLabels[planeIndex] > highestLabelInUse)
208 {
209 highestLabelInUse = planeLabels[planeIndex];
210 }
211 }
212
213 switch (this->LabelingMode)
214 {
216 {
217 for (vtkIdType planeIndex=0; planeIndex<numberOfPlanes; planeIndex++)
218 {
219 double origin[3];
220 this->PlaneOrigins->GetPoint(planeIndex,origin);
221 vtkIdType nearestBoundary = -1;
222 double nearestDistance = 0.0;
223 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
224 {
225 double boundaryNearestDistance, boundaryFurthestDistance;
226 DistancesFromPoint(input,rings[boundaryIndex],origin,boundaryNearestDistance,boundaryFurthestDistance);
227 // Entirely within, or not a candidate at all: one point of the boundary out beyond the
228 // limit and it is passed over, however near the rest of it comes.
229 if (this->MaximumDistanceFromPlaneOrigin > 0.0
230 && boundaryFurthestDistance > this->MaximumDistanceFromPlaneOrigin)
231 {
232 continue;
233 }
234 if (nearestBoundary == -1 || boundaryNearestDistance < nearestDistance)
235 {
236 nearestBoundary = boundaryIndex;
237 nearestDistance = boundaryNearestDistance;
238 }
239 }
240 if (nearestBoundary == -1)
241 {
242 continue;
243 }
244 // A boundary an earlier plane already took is not handed over: the second plane is
245 // reported unmatched instead, rather than silently moved to a boundary it did not choose.
246 if (labels[nearestBoundary] != invalidLabel)
247 {
248 continue;
249 }
250 labels[nearestBoundary] = planeLabels[planeIndex];
251 planeMatched[planeIndex] = true;
252 }
253 break;
254 }
255 case ON_PLANE:
256 {
257 if (this->MaximumDistanceFromPlane <= 0.0)
258 {
259 vtkErrorMacro(<<"MaximumDistanceFromPlane has to be positive in the OnPlane mode; no boundary was matched to a plane.");
260 break;
261 }
262 if (!this->PlaneNormals)
263 {
264 vtkErrorMacro(<<"PlaneNormals has to be set in the OnPlane mode; no boundary was matched to a plane.");
265 break;
266 }
267 // A plane at a time, taking the nearest of the boundaries that qualify for it. Doing it
268 // the other way round - a boundary at a time, first plane that fits - would let two
269 // boundaries lying in the same plane be told apart by nothing but which of them the
270 // extractor happened to reach first, which is the dependence on mesh numbering this whole
271 // arrangement exists to be rid of.
272 for (vtkIdType planeIndex=0; planeIndex<numberOfPlanes; planeIndex++)
273 {
274 double origin[3], normal[3];
275 this->PlaneOrigins->GetPoint(planeIndex,origin);
276 this->PlaneNormals->GetTuple(planeIndex,normal);
277 if (vtkMath::Normalize(normal) == 0.0)
278 {
279 continue;
280 }
281
282 vtkIdType nearestBoundary = -1;
283 double nearestDistance = 0.0;
284 vtkIdType numberOfQualifyingBoundaries = 0;
285 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
286 {
287 // A boundary an earlier plane already took carries that plane's label and is not on
288 // offer to this one.
289 if (labels[boundaryIndex] != invalidLabel)
290 {
291 continue;
292 }
293 // A plane is infinite and a surface is not, so lying in the plane is not on its own
294 // enough: the boundary has to be near this origin too, or a boundary on another branch
295 // that happens to be coplanar with this cut would be claimed by it.
296 double boundaryNearestDistance, boundaryFurthestDistance;
297 DistancesFromPoint(input,rings[boundaryIndex],origin,boundaryNearestDistance,boundaryFurthestDistance);
298 if (this->MaximumDistanceFromPlaneOrigin > 0.0
299 && boundaryFurthestDistance > this->MaximumDistanceFromPlaneOrigin)
300 {
301 continue;
302 }
303 // Every point of the boundary has to be in the plane, so that a boundary lying only
304 // partly in it - a hole the surface already had, or another cut's - is left alone
305 // rather than claimed by the wrong plane.
306 bool inPlane = true;
307 for (size_t j=0; j<rings[boundaryIndex].size(); j++)
308 {
309 double boundaryPoint[3];
310 input->GetPoint(rings[boundaryIndex][j],boundaryPoint);
311 double offset[3];
312 for (int k=0; k<3; k++)
313 {
314 offset[k] = boundaryPoint[k] - origin[k];
315 }
316 if (fabs(vtkMath::Dot(offset,normal)) >= this->MaximumDistanceFromPlane)
317 {
318 inPlane = false;
319 break;
320 }
321 }
322 if (!inPlane)
323 {
324 continue;
325 }
326 numberOfQualifyingBoundaries++;
327 if (nearestBoundary == -1 || boundaryNearestDistance < nearestDistance)
328 {
329 nearestBoundary = boundaryIndex;
330 nearestDistance = boundaryNearestDistance;
331 }
332 }
333
334 if (nearestBoundary == -1)
335 {
336 continue;
337 }
338 if (numberOfQualifyingBoundaries > 1)
339 {
340 // Answerable by geometry, but only just: say so, because it usually means
341 // MaximumDistanceFromPlaneOrigin is looser than the surface warrants.
342 vtkWarningMacro(<<numberOfQualifyingBoundaries<<" boundaries lie in the plane of the one labelled "
343 <<planeLabels[planeIndex]<<"; the nearest to its origin was taken.");
344 }
345 labels[nearestBoundary] = planeLabels[planeIndex];
346 planeMatched[planeIndex] = true;
347 }
348 break;
349 }
351 {
352 vtkDataArray* existingLabels = input->GetPointData()->GetArray(this->BoundaryLabelsArrayName);
353 if (existingLabels && existingLabels->GetNumberOfComponents() == 1
354 && existingLabels->GetNumberOfTuples() == numberOfPoints)
355 {
356 for (vtkIdType pointId=0; pointId<numberOfPoints; pointId++)
357 {
358 vtkIdType label = static_cast<vtkIdType>(vtkMath::Round(existingLabels->GetComponent(pointId,0)));
359 if (label > highestLabelInUse)
360 {
361 highestLabelInUse = label;
362 }
363 }
364 // A boundary keeps the label a strict majority of its points agree on. Anything less is
365 // not a boundary that came through a filter intact: a newly cut one is made of new
366 // points, which carry no label of their own or, where a filter interpolated the array
367 // onto them, one that no majority backs.
368 std::map<vtkIdType,std::pair<vtkIdType,vtkIdType> > bestClaimByLabel;
369 std::vector<vtkIdType> claimedLabel(rings.size(),invalidLabel);
370 std::vector<vtkIdType> claimCount(rings.size(),0);
371 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
372 {
373 std::map<vtkIdType,vtkIdType> counts;
374 for (size_t j=0; j<rings[boundaryIndex].size(); j++)
375 {
376 vtkIdType label = static_cast<vtkIdType>(vtkMath::Round(
377 existingLabels->GetComponent(rings[boundaryIndex][j],0)));
378 if (label >= 0)
379 {
380 counts[label]++;
381 }
382 }
383 vtkIdType ringSize = static_cast<vtkIdType>(rings[boundaryIndex].size());
384 for (std::map<vtkIdType,vtkIdType>::iterator count=counts.begin(); count!=counts.end(); ++count)
385 {
386 if (count->second * 2 > ringSize)
387 {
388 claimedLabel[boundaryIndex] = count->first;
389 claimCount[boundaryIndex] = count->second;
390 break;
391 }
392 }
393 if (claimedLabel[boundaryIndex] == invalidLabel)
394 {
395 continue;
396 }
397 // A label two boundaries both claim - a cut that split one boundary into two, say -
398 // can only stay with one of them.
399 std::map<vtkIdType,std::pair<vtkIdType,vtkIdType> >::iterator best =
400 bestClaimByLabel.find(claimedLabel[boundaryIndex]);
401 if (best == bestClaimByLabel.end())
402 {
403 bestClaimByLabel[claimedLabel[boundaryIndex]] =
404 std::make_pair(claimCount[boundaryIndex],boundaryIndex);
405 }
406 else
407 {
408 vtkWarningMacro(<<"More than one boundary carries the label "<<claimedLabel[boundaryIndex]
409 <<"; it stays with the one holding it most widely and the others are relabeled.");
410 if (claimCount[boundaryIndex] > best->second.first)
411 {
412 best->second = std::make_pair(claimCount[boundaryIndex],boundaryIndex);
413 }
414 }
415 }
416 for (std::map<vtkIdType,std::pair<vtkIdType,vtkIdType> >::iterator best=bestClaimByLabel.begin();
417 best!=bestClaimByLabel.end(); ++best)
418 {
419 labels[best->second.second] = best->first;
420 }
421 }
422 break;
423 }
425 default:
426 {
427 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
428 {
429 // The id vtkvmtkCapPolyData gives the cap of the boundary in this position when it is
430 // left to number the caps itself, so that labeling a surface this way and not labeling
431 // it at all come to the same thing.
432 labels[boundaryIndex] = boundaryIndex+1+this->CellEntityIdOffset;
433 if (labels[boundaryIndex] > highestLabelInUse)
434 {
435 highestLabelInUse = labels[boundaryIndex];
436 }
437 }
438 break;
439 }
440 }
441
442 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
443 {
444 if (labels[boundaryIndex] > highestLabelInUse)
445 {
446 highestLabelInUse = labels[boundaryIndex];
447 }
448 }
449 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
450 {
451 if (labels[boundaryIndex] == invalidLabel)
452 {
453 labels[boundaryIndex] = ++highestLabelInUse;
454 }
455 }
456
457 if (this->Annular)
458 {
459 this->LabelAnnularPairs(boundaries,labels);
460 }
461
462 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
463 {
464 for (size_t j=0; j<rings[boundaryIndex].size(); j++)
465 {
466 labelsArray->SetValue(rings[boundaryIndex][j],static_cast<int>(labels[boundaryIndex]));
467 orderArray->SetValue(rings[boundaryIndex][j],static_cast<int>(j));
468 }
469 this->BoundaryLabels->InsertNextId(labels[boundaryIndex]);
470 }
471
472 for (vtkIdType planeIndex=0; planeIndex<numberOfPlanes; planeIndex++)
473 {
474 if (!planeMatched[planeIndex])
475 {
476 this->UnmatchedPlaneLabels->InsertNextId(planeLabels[planeIndex]);
477 }
478 }
479
480 this->NumberOfBoundaries = numberOfBoundaries;
481
482 output->GetPointData()->AddArray(labelsArray);
483 output->GetPointData()->AddArray(orderArray);
484
485 return 1;
486}
static vtkIdType GetInvalidBoundaryLabel()
void LabelAnnularPairs(vtkPolyData *boundaries, std::vector< vtkIdType > &labels)

◆ LabelAnnularPairs()

void vtkvmtkPolyDataBoundaryLabeler::LabelAnnularPairs ( vtkPolyData * boundaries,
std::vector< vtkIdType > & labels )
protected

Pair the boundaries by barycenter distance and give each outer boundary its inner partner's label plus AnnularOuterBoundaryOffset. See Annular.

Definition at line 488 of file vtkvmtkPolyDataBoundaryLabeler.cxx.

489{
490 vtkIdType numberOfBoundaries = boundaries->GetNumberOfCells();
491 if (numberOfBoundaries < 2)
492 {
493 return;
494 }
495
496 // Barycenter and mean radius of each boundary: the first pairs them, the second says which of
497 // a pair is the inner one.
498 std::vector<std::vector<double> > barycenters(numberOfBoundaries,std::vector<double>(3,0.0));
499 std::vector<double> meanRadii(numberOfBoundaries,0.0);
500 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
501 {
502 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(boundaryIndex));
503 if (!boundary)
504 {
505 continue;
506 }
507 double barycenter[3];
508 vtkvmtkBoundaryReferenceSystems::ComputeBoundaryBarycenter(boundary->GetPoints(),barycenter);
509 for (int j=0; j<3; j++)
510 {
511 barycenters[boundaryIndex][j] = barycenter[j];
512 }
513 meanRadii[boundaryIndex] = vtkvmtkBoundaryReferenceSystems::ComputeBoundaryMeanRadius(boundary->GetPoints(),barycenter);
514 }
515
516 // Each boundary still unpaired takes the closest boundary still unpaired, which is how the
517 // annular cappers pair them too.
518 std::vector<bool> paired(numberOfBoundaries,false);
519 for (vtkIdType boundaryIndex=0; boundaryIndex<numberOfBoundaries; boundaryIndex++)
520 {
521 if (paired[boundaryIndex])
522 {
523 continue;
524 }
525 vtkIdType closestIndex = -1;
526 double closestDistance2 = 0.0;
527 for (vtkIdType candidateIndex=boundaryIndex+1; candidateIndex<numberOfBoundaries; candidateIndex++)
528 {
529 if (paired[candidateIndex])
530 {
531 continue;
532 }
533 double distance2 = vtkMath::Distance2BetweenPoints(&barycenters[boundaryIndex][0],&barycenters[candidateIndex][0]);
534 if (closestIndex == -1 || distance2 < closestDistance2)
535 {
536 closestIndex = candidateIndex;
537 closestDistance2 = distance2;
538 }
539 }
540 if (closestIndex == -1)
541 {
542 // An odd boundary with nothing left to pair with keeps the label it was given.
543 vtkWarningMacro(<<"Annular labeling: the boundary labelled "<<labels[boundaryIndex]
544 <<" has no partner, so it keeps its label and no outer label is derived from it.");
545 break;
546 }
547
548 paired[boundaryIndex] = true;
549 paired[closestIndex] = true;
550
551 vtkIdType innerIndex = boundaryIndex;
552 vtkIdType outerIndex = closestIndex;
553 if (meanRadii[outerIndex] < meanRadii[innerIndex])
554 {
555 std::swap(innerIndex,outerIndex);
556 }
557
558 // The inner boundary keeps the label it was given; the outer one is named after it, so the
559 // pair reads as one vessel end and the inner label is the lower of the two.
560 labels[outerIndex] = labels[innerIndex] + this->AnnularOuterBoundaryOffset;
561 }
562}
static void ComputeBoundaryBarycenter(vtkPoints *points, double barycenter[3])
static double ComputeBoundaryMeanRadius(vtkPoints *points, double barycenter[3])

Member Data Documentation

◆ BoundaryLabelsArrayName

char* vtkvmtkPolyDataBoundaryLabeler::BoundaryLabelsArrayName
protected

Definition at line 279 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ BoundaryPointOrderArrayName

char* vtkvmtkPolyDataBoundaryLabeler::BoundaryPointOrderArrayName
protected

Definition at line 280 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ LabelingMode

int vtkvmtkPolyDataBoundaryLabeler::LabelingMode
protected

Definition at line 282 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ CellEntityIdOffset

vtkIdType vtkvmtkPolyDataBoundaryLabeler::CellEntityIdOffset
protected

Definition at line 283 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ Annular

bool vtkvmtkPolyDataBoundaryLabeler::Annular
protected

Definition at line 284 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ AnnularOuterBoundaryOffset

vtkIdType vtkvmtkPolyDataBoundaryLabeler::AnnularOuterBoundaryOffset
protected

Definition at line 285 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ PlaneOrigins

vtkPoints* vtkvmtkPolyDataBoundaryLabeler::PlaneOrigins
protected

Definition at line 287 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ PlaneNormals

vtkDoubleArray* vtkvmtkPolyDataBoundaryLabeler::PlaneNormals
protected

Definition at line 288 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ PlaneLabels

vtkIdList* vtkvmtkPolyDataBoundaryLabeler::PlaneLabels
protected

Definition at line 289 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ MaximumDistanceFromPlane

double vtkvmtkPolyDataBoundaryLabeler::MaximumDistanceFromPlane
protected

Definition at line 290 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ MaximumDistanceFromPlaneOrigin

double vtkvmtkPolyDataBoundaryLabeler::MaximumDistanceFromPlaneOrigin
protected

Definition at line 291 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ NumberOfBoundaries

vtkIdType vtkvmtkPolyDataBoundaryLabeler::NumberOfBoundaries
protected

Definition at line 293 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ BoundaryLabels

vtkIdList* vtkvmtkPolyDataBoundaryLabeler::BoundaryLabels
protected

Definition at line 294 of file vtkvmtkPolyDataBoundaryLabeler.h.

◆ UnmatchedPlaneLabels

vtkIdList* vtkvmtkPolyDataBoundaryLabeler::UnmatchedPlaneLabels
protected

Definition at line 295 of file vtkvmtkPolyDataBoundaryLabeler.h.


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