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

Estimate the plane that locally cuts a tubular surface transversally at a given seed point. More...

#include <vtkvmtkPolyDataNormalPlaneEstimator.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataNormalPlaneEstimator * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual double * GetOrigin ()
virtual void GetOrigin (double data[3])
virtual double * GetNormal ()
virtual void GetNormal (double data[3])
virtual void SetOriginPointId (vtkIdType)
virtual vtkIdType GetOriginPointId ()
virtual void SetUseConnectivity (int)
virtual int GetUseConnectivity ()
virtual void UseConnectivityOn ()
virtual void UseConnectivityOff ()
virtual void SetMinimumNeighborhoodSize (int)
virtual int GetMinimumNeighborhoodSize ()

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

vtkIdType OriginPointId
double Origin [3]
double Normal [3]
int UseConnectivity
int MinimumNeighborhoodSize

Detailed Description

Estimate the plane that locally cuts a tubular surface transversally at a given seed point.

Given a seed point (OriginPointId) on a tubular surface (e.g. a vessel wall), this filter estimates the normal of the plane that is locally perpendicular to the tube's axis at that point, together with the point's coordinates (Origin). It works purely from the surface point normals: starting from the local average edge length at the seed, it grows a search radius around Origin and, for every neighboring point whose normal is sufficiently different from (not nearly parallel or nearly antiparallel to) the normal at Origin, accumulates the cross product of the two normals into a running estimate of the plane normal; the estimate for the smallest radius that gathers at least MinimumNeighborhoodSize neighbors and produces a consistent (non-conflicting) cross-product direction is kept. If the input already has point normals they are reused, otherwise they are computed internally with vtkPolyDataNormals.

This is used by the vmtksurfaceendclipper pype script to compute, at a manually or automatically picked seed point on a vessel end, the origin and normal of the plane fed to vtkvmtkTopologicalSeamFilter and vtkClipPolyData in order to cut the vessel end perpendicularly to its axis.

See also
vtkvmtkTopologicalSeamFilter

Definition at line 50 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

Member Typedef Documentation

◆ Superclass

Definition at line 53 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataNormalPlaneEstimator()

vtkvmtkPolyDataNormalPlaneEstimator::vtkvmtkPolyDataNormalPlaneEstimator ( )
protected

◆ ~vtkvmtkPolyDataNormalPlaneEstimator()

vtkvmtkPolyDataNormalPlaneEstimator::~vtkvmtkPolyDataNormalPlaneEstimator ( )
protected

Definition at line 52 of file vtkvmtkPolyDataNormalPlaneEstimator.cxx.

53{
54}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataNormalPlaneEstimator::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataNormalPlaneEstimator * vtkvmtkPolyDataNormalPlaneEstimator::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 247 of file vtkvmtkPolyDataNormalPlaneEstimator.cxx.

248{
249 this->Superclass::PrintSelf(os,indent);
250}

◆ New()

vtkvmtkPolyDataNormalPlaneEstimator * vtkvmtkPolyDataNormalPlaneEstimator::New ( )
static

◆ SetOriginPointId()

virtual void vtkvmtkPolyDataNormalPlaneEstimator::SetOriginPointId ( vtkIdType )
virtual

Set/Get the id, in the input poly data, of the point at which the transversal plane is estimated. Must be set before Update() is called; default is -1 (unset), which causes RequestData to report an error and return without computing Origin/Normal.

◆ GetOriginPointId()

virtual vtkIdType vtkvmtkPolyDataNormalPlaneEstimator::GetOriginPointId ( )
virtual

Set/Get the id, in the input poly data, of the point at which the transversal plane is estimated. Must be set before Update() is called; default is -1 (unset), which causes RequestData to report an error and return without computing Origin/Normal.

◆ GetOrigin() [1/2]

virtual double * vtkvmtkPolyDataNormalPlaneEstimator::GetOrigin ( )
virtual

Get the coordinates of OriginPointId, copied directly from the input poly data. Valid only after Update() has been called.

◆ GetOrigin() [2/2]

virtual void vtkvmtkPolyDataNormalPlaneEstimator::GetOrigin ( double data[3])
virtual

◆ GetNormal() [1/2]

virtual double * vtkvmtkPolyDataNormalPlaneEstimator::GetNormal ( )
virtual

Get the estimated unit normal of the plane that locally cuts the tubular surface transversally at Origin, obtained by accumulating cross products of surface point normals over a neighborhood grown around Origin. Valid only after Update() has been called.

◆ GetNormal() [2/2]

virtual void vtkvmtkPolyDataNormalPlaneEstimator::GetNormal ( double data[3])
virtual

◆ SetUseConnectivity()

virtual void vtkvmtkPolyDataNormalPlaneEstimator::SetUseConnectivity ( int )
virtual

Toggle whether the neighborhood search used to estimate the plane normal is restricted to points belonging to the same connected region as OriginPointId (as determined by vtkPolyDataConnectivityFilter). When on, points from other, disconnected parts of the input are ignored even if they fall within the current search radius. Default: on.

◆ GetUseConnectivity()

virtual int vtkvmtkPolyDataNormalPlaneEstimator::GetUseConnectivity ( )
virtual

Toggle whether the neighborhood search used to estimate the plane normal is restricted to points belonging to the same connected region as OriginPointId (as determined by vtkPolyDataConnectivityFilter). When on, points from other, disconnected parts of the input are ignored even if they fall within the current search radius. Default: on.

◆ UseConnectivityOn()

virtual void vtkvmtkPolyDataNormalPlaneEstimator::UseConnectivityOn ( )
virtual

Toggle whether the neighborhood search used to estimate the plane normal is restricted to points belonging to the same connected region as OriginPointId (as determined by vtkPolyDataConnectivityFilter). When on, points from other, disconnected parts of the input are ignored even if they fall within the current search radius. Default: on.

◆ UseConnectivityOff()

virtual void vtkvmtkPolyDataNormalPlaneEstimator::UseConnectivityOff ( )
virtual

Toggle whether the neighborhood search used to estimate the plane normal is restricted to points belonging to the same connected region as OriginPointId (as determined by vtkPolyDataConnectivityFilter). When on, points from other, disconnected parts of the input are ignored even if they fall within the current search radius. Default: on.

◆ SetMinimumNeighborhoodSize()

virtual void vtkvmtkPolyDataNormalPlaneEstimator::SetMinimumNeighborhoodSize ( int )
virtual

Set/Get the minimum number of neighboring points that must fall within the current search radius (grown iteratively in steps of the local average edge length at OriginPointId) before that radius is accepted for estimating the plane normal. Default: 10.

◆ GetMinimumNeighborhoodSize()

virtual int vtkvmtkPolyDataNormalPlaneEstimator::GetMinimumNeighborhoodSize ( )
virtual

Set/Get the minimum number of neighboring points that must fall within the current search radius (grown iteratively in steps of the local average edge length at OriginPointId) before that radius is accepted for estimating the plane normal. Default: 10.

◆ RequestData()

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

Definition at line 56 of file vtkvmtkPolyDataNormalPlaneEstimator.cxx.

60{
61 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
62 vtkInformation *outInfo = outputVector->GetInformationObject(0);
63
64 vtkPolyData *input = vtkPolyData::SafeDownCast(
65 inInfo->Get(vtkDataObject::DATA_OBJECT()));
66 vtkPolyData *output = vtkPolyData::SafeDownCast(
67 outInfo->Get(vtkDataObject::DATA_OBJECT()));
68
69 if (this->OriginPointId == -1)
70 {
71 vtkErrorMacro("Origin point id not specified");
72 return 1;
73 }
74
75 input->BuildCells();
76 input->BuildLinks();
77
78 vtkFloatArray* normals = vtkFloatArray::New();
79
80 if (input->GetPointData()->GetNormals())
81 {
82 normals->DeepCopy(input->GetPointData()->GetNormals());
83 }
84 else
85 {
86 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
87 normalsFilter->SetInputData(input);
88 normalsFilter->AutoOrientNormalsOn();
89 normalsFilter->FlipNormalsOn();
90 normalsFilter->ConsistencyOn();
91 normalsFilter->ComputeCellNormalsOff();
92 normalsFilter->SplittingOff();
93 normalsFilter->Update();
94
95 normals->DeepCopy(normalsFilter->GetOutput()->GetPointData()->GetNormals());
96
97 normalsFilter->Delete();
98 }
99
100 vtkPointLocator* locator = vtkPointLocator::New();
101 locator->SetDataSet(input);
102 locator->BuildLocator();
103
104 vtkIdTypeArray* connectivityArray = vtkIdTypeArray::New();
105 if (this->UseConnectivity)
106 {
107 vtkPolyDataConnectivityFilter* connectivityFilter = vtkPolyDataConnectivityFilter::New();
108 connectivityFilter->SetInputData(input);
109 connectivityFilter->SetExtractionModeToAllRegions();
110 connectivityFilter->ColorRegionsOn();
111 connectivityFilter->Update();
112
113 connectivityArray->DeepCopy(connectivityFilter->GetOutput()->GetPointData()->GetScalars());
114 connectivityFilter->Delete();
115 }
116
117 vtkIdType npts, *cells;
118 vtkIdType ncells;
119
120 input->GetPointCells(this->OriginPointId,ncells,cells);
121
122 double averageLength = 0.0;
123
124 for (vtkIdType i=0; i<ncells; i++)
125 {
126 averageLength += sqrt(input->GetCell(cells[i])->GetLength2());
127 }
128 averageLength /= ncells;
129
130 double radiusStep = averageLength;
131
132 double direction[3];
133 double normal0[3], normal1[3];
134
135 input->GetPoint(this->OriginPointId,this->Origin);
136 normals->GetTuple(this->OriginPointId,normal1);
137
138 vtkIdType regionId = -1;
139 if (this->UseConnectivity)
140 {
141 regionId = connectivityArray->GetValue(this->OriginPointId);
142 }
143
144 vtkIdList* pointIdsWithinRadius = vtkIdList::New();
145
146 bool doneOnce = false;
147
148 // Future improvement: only consider topologically connected vertices
149
150 for (int k=0; k<100; k++)
151 {
152 pointIdsWithinRadius->Initialize();
153
154 double radius = k * radiusStep;
155 locator->FindPointsWithinRadius(radius,this->Origin,pointIdsWithinRadius);
156
157 vtkIdType numberOfIds = pointIdsWithinRadius->GetNumberOfIds();
158
159 vtkIdType neighborhoodSize = numberOfIds;
160
161 if (this->UseConnectivity)
162 {
163 for (vtkIdType i=0; i<numberOfIds; i++)
164 {
165 vtkIdType id = pointIdsWithinRadius->GetId(i);
166 if (connectivityArray->GetValue(id) == regionId)
167 {
168 neighborhoodSize += 1;
169 }
170 }
171 }
172
173 if (neighborhoodSize < this->MinimumNeighborhoodSize)
174 {
175 continue;
176 }
177
178 double kdirection[3];
179 kdirection[0] = kdirection[1] = kdirection[2] = 0.0;
180
181 bool done = false;
182
183 for (vtkIdType i=0; i<numberOfIds; i++)
184 {
185 vtkIdType id = pointIdsWithinRadius->GetId(i);
186
187 if (this->UseConnectivity && connectivityArray->GetValue(id) != regionId)
188 {
189 continue;
190 }
191
192 normals->GetTuple(id,normal0);
193
194 double dot = vtkMath::Dot(normal0,normal1);
195
196 if (fabs(dot) > 0.6) {
197 continue;
198 }
199
200 if (dot < -0.5 && doneOnce) {
201 done = true;
202 break;
203 }
204
205 double cross[3];
206 vtkMath::Cross(normal0,normal1,cross);
207
208 if (vtkMath::Dot(kdirection,cross) < 0.0) {
209 cross[0] *= -1.0;
210 cross[1] *= -1.0;
211 cross[2] *= -1.0;
212 }
213
214 kdirection[0] += cross[0];
215 kdirection[1] += cross[1];
216 kdirection[2] += cross[2];
217 doneOnce = true;
218 }
219
220 if (!doneOnce)
221 {
222 continue;
223 }
224
225 vtkMath::Normalize(kdirection);
226
227 if (done)
228 {
229 break;
230 }
231
232 this->Normal[0] = kdirection[0];
233 this->Normal[1] = kdirection[1];
234 this->Normal[2] = kdirection[2];
235 }
236
237 vtkMath::Normalize(this->Normal);
238
239 normals->Delete();
240 locator->Delete();
241 pointIdsWithinRadius->Delete();
242 connectivityArray->Delete();
243
244 return 1;
245}

Member Data Documentation

◆ OriginPointId

vtkIdType vtkvmtkPolyDataNormalPlaneEstimator::OriginPointId
protected

Definition at line 109 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

◆ Origin

double vtkvmtkPolyDataNormalPlaneEstimator::Origin[3]
protected

Definition at line 111 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

◆ Normal

double vtkvmtkPolyDataNormalPlaneEstimator::Normal[3]
protected

Definition at line 112 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

◆ UseConnectivity

int vtkvmtkPolyDataNormalPlaneEstimator::UseConnectivity
protected

Definition at line 114 of file vtkvmtkPolyDataNormalPlaneEstimator.h.

◆ MinimumNeighborhoodSize

int vtkvmtkPolyDataNormalPlaneEstimator::MinimumNeighborhoodSize
protected

Definition at line 115 of file vtkvmtkPolyDataNormalPlaneEstimator.h.


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