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

Interpolate a point-based array from a set of provided values. More...

#include <vtkvmtkCenterlineInterpolateArray.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkCenterlineInterpolateArray * NewInstance () const
virtual void SetDefaultValue (double)
virtual double GetDefaultValue ()
virtual void SetValues (vtkDataArray *)
virtual vtkDataArray * GetValues ()
virtual void SetValuesIds (vtkIdList *)
virtual vtkIdList * GetValuesIds ()
virtual void SetInterpolatedArrayName (const char *)
virtual char * GetInterpolatedArrayName ()

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

char * InterpolatedArrayName
double DefaultValue
vtkDataArray * Values
vtkIdList * ValuesIds

Detailed Description

Interpolate a point-based array from a set of provided values.

Given a sparse set of values (Values) attached to a subset of the input poly data's points (ValuesIds), vtkvmtkCenterlineInterpolateArray produces a dense point-data array (InterpolatedArrayName) covering all points of every polyline cell (e.g. a set of centerlines). Along each polyline, the value at points lying between two provided points is obtained by linear interpolation with respect to arc length (abscissa); points before the first provided value or after the last one are set to that nearest provided value (constant extrapolation). Points on cells that contain no provided value at all, or that are not polylines, are set to DefaultValue.

Definition at line 48 of file vtkvmtkCenterlineInterpolateArray.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkCenterlineInterpolateArray::Superclass

Definition at line 52 of file vtkvmtkCenterlineInterpolateArray.h.

Constructor & Destructor Documentation

◆ vtkvmtkCenterlineInterpolateArray()

vtkvmtkCenterlineInterpolateArray::vtkvmtkCenterlineInterpolateArray ( )
protected

◆ ~vtkvmtkCenterlineInterpolateArray()

vtkvmtkCenterlineInterpolateArray::~vtkvmtkCenterlineInterpolateArray ( )
protected

Definition at line 57 of file vtkvmtkCenterlineInterpolateArray.cxx.

58{
59 if (this->InterpolatedArrayName)
60 {
61 delete[] this->InterpolatedArrayName;
62 this->InterpolatedArrayName = NULL;
63 }
64
65 if (this->Values)
66 {
67 this->Values->Delete();
68 this->Values = NULL;
69 }
70
71 if (this->ValuesIds)
72 {
73 this->ValuesIds->Delete();
74 this->ValuesIds = NULL;
75 }
76}

Member Function Documentation

◆ New()

vtkvmtkCenterlineInterpolateArray * vtkvmtkCenterlineInterpolateArray::New ( )
static

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkCenterlineInterpolateArray::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkCenterlineInterpolateArray * vtkvmtkCenterlineInterpolateArray::NewInstance ( ) const

◆ SetDefaultValue()

virtual void vtkvmtkCenterlineInterpolateArray::SetDefaultValue ( double )
virtual

Default value to fill in when no data is available

◆ GetDefaultValue()

virtual double vtkvmtkCenterlineInterpolateArray::GetDefaultValue ( )
virtual

Default value to fill in when no data is available

◆ SetValues()

virtual void vtkvmtkCenterlineInterpolateArray::SetValues ( vtkDataArray * )
virtual

Set/Get the values from which to interpolate

◆ GetValues()

virtual vtkDataArray * vtkvmtkCenterlineInterpolateArray::GetValues ( )
virtual

Set/Get the values from which to interpolate

◆ SetValuesIds()

virtual void vtkvmtkCenterlineInterpolateArray::SetValuesIds ( vtkIdList * )
virtual

Set/Get the point ids corresponding to the provided values

◆ GetValuesIds()

virtual vtkIdList * vtkvmtkCenterlineInterpolateArray::GetValuesIds ( )
virtual

Set/Get the point ids corresponding to the provided values

◆ SetInterpolatedArrayName()

virtual void vtkvmtkCenterlineInterpolateArray::SetInterpolatedArrayName ( const char * )
virtual

Set/Get the name of the resulting array Commonly named "InterpolatedRadius" or "ResolutionArray", depending on context.

◆ GetInterpolatedArrayName()

virtual char * vtkvmtkCenterlineInterpolateArray::GetInterpolatedArrayName ( )
virtual

Set/Get the name of the resulting array Commonly named "InterpolatedRadius" or "ResolutionArray", depending on context.

◆ RequestData()

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

Definition at line 78 of file vtkvmtkCenterlineInterpolateArray.cxx.

82{
83 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
84 vtkInformation *outInfo = outputVector->GetInformationObject(0);
85
86 vtkPolyData *input = vtkPolyData::SafeDownCast(
87 inInfo->Get(vtkDataObject::DATA_OBJECT()));
88 vtkPolyData *output = vtkPolyData::SafeDownCast(
89 outInfo->Get(vtkDataObject::DATA_OBJECT()));
90
91 if (!this->InterpolatedArrayName)
92 {
93 vtkErrorMacro(<<"InterpolatedArrayName not set.");
94 return 1;
95 }
96
97 if (!this->Values)
98 {
99 vtkErrorMacro(<<"Values not set");
100 return 1;
101 }
102
103 if (!this->ValuesIds)
104 {
105 vtkErrorMacro(<<"ValuesIds not set");
106 return 1;
107 }
108
109 if (this->Values->GetNumberOfTuples() != this->ValuesIds->GetNumberOfIds())
110 {
111 vtkErrorMacro(<<"Inconsistent number of values/ids");
112 return 1;
113 }
114
115 int numberOfInputPoints = input->GetNumberOfPoints();
116
117 output->DeepCopy(input);
118
119
120 vtkDataArray* interpolatedArray = output->GetPointData()->GetArray(this->InterpolatedArrayName);
121
122 bool createArray = !interpolatedArray;
123
124 if (createArray)
125 {
126 interpolatedArray = vtkDoubleArray::New();
127 interpolatedArray->SetName(this->InterpolatedArrayName);
128 interpolatedArray->SetNumberOfComponents(this->Values->GetNumberOfComponents());
129 interpolatedArray->SetNumberOfTuples(numberOfInputPoints);
130 for (int i=0; i<interpolatedArray->GetNumberOfComponents(); i++)
131 {
132 interpolatedArray->FillComponent(i, this->DefaultValue);
133 }
134 output->GetPointData()->AddArray(interpolatedArray);
135 }
136
137 int numberOfComponents = std::min(interpolatedArray->GetNumberOfComponents(),this->Values->GetNumberOfComponents());
138
139 //Compute abscissas for the centerlines
140 vtkvmtkCenterlineAttributesFilter *attribFilter = vtkvmtkCenterlineAttributesFilter::New();
141 attribFilter->SetInputData(input);
142 attribFilter->SetAbscissasArrayName("Abscissa");
143 attribFilter->SetParallelTransportNormalsArrayName("ParallelTransportNormals");
144 attribFilter->Update();
145 vtkDataArray *abscissaArray = attribFilter->GetOutput()->GetPointData()->GetArray("Abscissa");
146
147 //Indicates which point have values
148 vtkBitArray *hasValueArray = vtkBitArray::New();
149 hasValueArray->SetNumberOfComponents(1);
150 hasValueArray->SetNumberOfTuples(numberOfInputPoints);
151 hasValueArray->FillComponent(0,false);
152
153 for (int i=0; i<this->ValuesIds->GetNumberOfIds(); i++)
154 {
155 hasValueArray->SetValue(this->ValuesIds->GetId(i),true);
156 for (int j=0; j<numberOfComponents; j++)
157 {
158 interpolatedArray->SetComponent(this->ValuesIds->GetId(i),j,this->Values->GetComponent(i,j));
159 }
160 }
161
162 int numberOfInputCells = input->GetNumberOfCells();
163
164
165 for (int i=0; i<numberOfInputCells; i++)
166 {
167 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(input->GetCell(i));
168 if (!polyLine)
169 {
170 continue;
171 }
172
173 int numberOfLinePoints = polyLine->GetNumberOfPoints();
174
175 bool foundValue = false;
176 int startInd = 0;
177 //Find the first point having a value
178 while ((startInd<numberOfLinePoints) && (!foundValue))
179 {
180 foundValue = hasValueArray->GetValue(polyLine->GetPointId(startInd++));
181 }
182
183 //If no point with a value has been found skip to next line
184 if ((startInd==numberOfLinePoints) && (!foundValue))
185 {
186 continue;
187 }
188
189 //Otherwise we have our first value fill the previous points with this value
190 startInd--;
191 std::vector<double> startVal(numberOfComponents);
192 for (int j=0; j<numberOfComponents; j++)
193 {
194 startVal[j] = interpolatedArray->GetComponent(polyLine->GetPointId(startInd),j);
195 }
196 double startAbs = abscissaArray->GetComponent(polyLine->GetPointId(startInd),0);
197
198 for (int j=0; j<startInd; j++)
199 {
200 for (int k=0; k<numberOfComponents; k++)
201 {
202 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,startVal[k]);
203 }
204 hasValueArray->SetValue(polyLine->GetPointId(j),true);
205 }
206
207 int endInd = startInd + 1;
208 foundValue = false;
209 while (endInd<numberOfLinePoints)
210 {
211 foundValue = hasValueArray->GetValue(polyLine->GetPointId(endInd));
212 if (foundValue)
213 {
214 //Interpolate between the start and end values
215 std::vector<double> endVal(numberOfComponents);
216 for (int j=0; j<numberOfComponents; j++)
217 {
218 endVal[j] = interpolatedArray->GetComponent(polyLine->GetPointId(endInd),j);
219 }
220 double endAbs = abscissaArray->GetComponent(polyLine->GetPointId(endInd),0);
221 double absDiff = endAbs - startAbs;
222 if (absDiff!=0.)
223 {
224 float invAbsDiff = 1./absDiff;
225 for (int j=startInd+1;j<endInd;j++)
226 {
227 double currAbs = abscissaArray->GetComponent(polyLine->GetPointId(j),0);
228 for (int k=0; k<numberOfComponents; k++)
229 {
230 double newVal = startVal[k] + (currAbs - startAbs)*invAbsDiff*(endVal[k] - startVal[k]);
231 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,newVal);
232 }
233 hasValueArray->SetValue(polyLine->GetPointId(j),true);
234 }
235 }
236 //Replace the end value by the start value
237 startInd = endInd;
238 startVal = endVal;
239 startAbs = endAbs;
240 }
241 endInd++;
242 }
243
244 //Fill the remaining values
245 for (int j=startInd+1; j<numberOfLinePoints; j++)
246 {
247 for (int k=0; k<numberOfComponents; k++)
248 {
249 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,startVal[k]);
250 }
251 hasValueArray->SetValue(polyLine->GetPointId(j),true);
252 }
253 }
254
255 if (createArray) interpolatedArray->Delete();
256 attribFilter->Delete();
257 hasValueArray->Delete();
258
259 return 1;
260}
virtual void SetAbscissasArrayName(const char *)
virtual void SetParallelTransportNormalsArrayName(const char *)
static vtkvmtkCenterlineAttributesFilter * New()

Member Data Documentation

◆ InterpolatedArrayName

char* vtkvmtkCenterlineInterpolateArray::InterpolatedArrayName
protected

Definition at line 94 of file vtkvmtkCenterlineInterpolateArray.h.

◆ DefaultValue

double vtkvmtkCenterlineInterpolateArray::DefaultValue
protected

Definition at line 96 of file vtkvmtkCenterlineInterpolateArray.h.

◆ Values

vtkDataArray* vtkvmtkCenterlineInterpolateArray::Values
protected

Definition at line 97 of file vtkvmtkCenterlineInterpolateArray.h.

◆ ValuesIds

vtkIdList* vtkvmtkCenterlineInterpolateArray::ValuesIds
protected

Definition at line 98 of file vtkvmtkCenterlineInterpolateArray.h.


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