79 vtkInformation *vtkNotUsed(request),
80 vtkInformationVector **inputVector,
81 vtkInformationVector *outputVector)
83 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
84 vtkInformation *outInfo = outputVector->GetInformationObject(0);
86 vtkPolyData *input = vtkPolyData::SafeDownCast(
87 inInfo->Get(vtkDataObject::DATA_OBJECT()));
88 vtkPolyData *output = vtkPolyData::SafeDownCast(
89 outInfo->Get(vtkDataObject::DATA_OBJECT()));
93 vtkErrorMacro(<<
"InterpolatedArrayName not set.");
99 vtkErrorMacro(<<
"Values not set");
105 vtkErrorMacro(<<
"ValuesIds not set");
109 if (this->
Values->GetNumberOfTuples() != this->ValuesIds->GetNumberOfIds())
111 vtkErrorMacro(<<
"Inconsistent number of values/ids");
115 int numberOfInputPoints = input->GetNumberOfPoints();
117 output->DeepCopy(input);
122 bool createArray = !interpolatedArray;
126 interpolatedArray = vtkDoubleArray::New();
128 interpolatedArray->SetNumberOfComponents(this->
Values->GetNumberOfComponents());
129 interpolatedArray->SetNumberOfTuples(numberOfInputPoints);
130 for (
int i=0; i<interpolatedArray->GetNumberOfComponents(); i++)
132 interpolatedArray->FillComponent(i, this->
DefaultValue);
134 output->GetPointData()->AddArray(interpolatedArray);
137 int numberOfComponents = std::min(interpolatedArray->GetNumberOfComponents(),this->Values->GetNumberOfComponents());
141 attribFilter->SetInputData(input);
144 attribFilter->Update();
145 vtkDataArray *abscissaArray = attribFilter->GetOutput()->GetPointData()->GetArray(
"Abscissa");
148 vtkBitArray *hasValueArray = vtkBitArray::New();
149 hasValueArray->SetNumberOfComponents(1);
150 hasValueArray->SetNumberOfTuples(numberOfInputPoints);
151 hasValueArray->FillComponent(0,
false);
153 for (
int i=0; i<this->
ValuesIds->GetNumberOfIds(); i++)
155 hasValueArray->SetValue(this->
ValuesIds->GetId(i),
true);
156 for (
int j=0; j<numberOfComponents; j++)
158 interpolatedArray->SetComponent(this->
ValuesIds->GetId(i),j,this->Values->GetComponent(i,j));
162 int numberOfInputCells = input->GetNumberOfCells();
165 for (
int i=0; i<numberOfInputCells; i++)
167 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(input->GetCell(i));
173 int numberOfLinePoints = polyLine->GetNumberOfPoints();
175 bool foundValue =
false;
178 while ((startInd<numberOfLinePoints) && (!foundValue))
180 foundValue = hasValueArray->GetValue(polyLine->GetPointId(startInd++));
184 if ((startInd==numberOfLinePoints) && (!foundValue))
191 std::vector<double> startVal(numberOfComponents);
192 for (
int j=0; j<numberOfComponents; j++)
194 startVal[j] = interpolatedArray->GetComponent(polyLine->GetPointId(startInd),j);
196 double startAbs = abscissaArray->GetComponent(polyLine->GetPointId(startInd),0);
198 for (
int j=0; j<startInd; j++)
200 for (
int k=0; k<numberOfComponents; k++)
202 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,startVal[k]);
204 hasValueArray->SetValue(polyLine->GetPointId(j),
true);
207 int endInd = startInd + 1;
209 while (endInd<numberOfLinePoints)
211 foundValue = hasValueArray->GetValue(polyLine->GetPointId(endInd));
215 std::vector<double> endVal(numberOfComponents);
216 for (
int j=0; j<numberOfComponents; j++)
218 endVal[j] = interpolatedArray->GetComponent(polyLine->GetPointId(endInd),j);
220 double endAbs = abscissaArray->GetComponent(polyLine->GetPointId(endInd),0);
221 double absDiff = endAbs - startAbs;
224 float invAbsDiff = 1./absDiff;
225 for (
int j=startInd+1;j<endInd;j++)
227 double currAbs = abscissaArray->GetComponent(polyLine->GetPointId(j),0);
228 for (
int k=0; k<numberOfComponents; k++)
230 double newVal = startVal[k] + (currAbs - startAbs)*invAbsDiff*(endVal[k] - startVal[k]);
231 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,newVal);
233 hasValueArray->SetValue(polyLine->GetPointId(j),
true);
245 for (
int j=startInd+1; j<numberOfLinePoints; j++)
247 for (
int k=0; k<numberOfComponents; k++)
249 interpolatedArray->SetComponent(polyLine->GetPointId(j),k,startVal[k]);
251 hasValueArray->SetValue(polyLine->GetPointId(j),
true);
255 if (createArray) interpolatedArray->Delete();
256 attribFilter->Delete();
257 hasValueArray->Delete();