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
92 {
93 vtkErrorMacro(<<"InterpolatedArrayName not set.");
94 return 1;
95 }
96
98 {
99 vtkErrorMacro(<<"Values not set");
100 return 1;
101 }
102
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
121
122 bool createArray = !interpolatedArray;
123
124 if (createArray)
125 {
126 interpolatedArray = vtkDoubleArray::New();
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
141 attribFilter->SetInputData(input);
144 attribFilter->Update();
145 vtkDataArray *abscissaArray = attribFilter->GetOutput()->GetPointData()->GetArray("Abscissa");
146
147
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
178 while ((startInd<numberOfLinePoints) && (!foundValue))
179 {
180 foundValue = hasValueArray->GetValue(polyLine->GetPointId(startInd++));
181 }
182
183
184 if ((startInd==numberOfLinePoints) && (!foundValue))
185 {
186 continue;
187 }
188
189
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
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
237 startInd = endInd;
238 startVal = endVal;
239 startAbs = endAbs;
240 }
241 endInd++;
242 }
243
244
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()