67 vtkInformationVector **inputVector,
68 vtkInformationVector *outputVector)
70 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
71 vtkInformation *outInfo = outputVector->GetInformationObject(0);
73 vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
74 vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkErrorMacro(
"Name of seam scalars array not specified.");
82 vtkDoubleArray* sourceArray = vtkDoubleArray::New();
84 vtkIdType numberOfPoints = input->GetNumberOfPoints();
88 if (input->GetPointData()->GetArray(this->SeamScalarsArrayName))
90 sourceArray->DeepCopy(input->GetPointData()->GetArray(this->SeamScalarsArrayName));
94 vtkErrorMacro(
"Seam scalars with name specified does not exist and seam function not specified.");
100 sourceArray->SetNumberOfTuples(input->GetNumberOfPoints());
101 double point[3], value;
102 for (vtkIdType i=0; i<numberOfPoints; i++)
104 input->GetPoint(i,point);
106 sourceArray->SetValue(i,value);
110 vtkIdType numberOfCells = input->GetNumberOfCells();
112 vtkUnsignedCharArray* visitedArray = vtkUnsignedCharArray::New();
113 visitedArray->SetNumberOfTuples(numberOfPoints);
114 visitedArray->FillComponent(0,0.0);
116 vtkDoubleArray* seamArray = vtkDoubleArray::New();
118 seamArray->SetNumberOfTuples(numberOfPoints);
119 seamArray->FillComponent(0,0.0);
124 vtkIdType firstSeamPointId = -1;
128 const vtkIdType *pts;
130 for (vtkIdType i=0; i<numberOfCells; i++)
132 input->GetCellPoints(i,npts,pts);
133 for (vtkIdType j=0; j<npts-1; j++)
135 vtkIdType point0Id = pts[j];
136 vtkIdType point1Id = pts[j+1];
137 double point0Value = sourceArray->GetTuple1(point0Id);
138 double point1Value = sourceArray->GetTuple1(point1Id);
139 if (point0Value * point1Value < 0.0)
141 double point0[3], point1[3];
142 input->GetPoint(point0Id,point0);
143 input->GetPoint(point1Id,point1);
144 double dist0 = vtkMath::Distance2BetweenPoints(point0,this->
ClosestPoint);
145 double dist1 = vtkMath::Distance2BetweenPoints(point1,this->
ClosestPoint);
149 firstSeamPointId = point0Id;
154 firstSeamPointId = point1Id;
161 std::queue<vtkIdType> seamQueue;
163 seamQueue.push(firstSeamPointId);
165 std::queue<vtkIdType> leftQueue;
166 std::queue<vtkIdType> rightQueue;
171 while (!seamQueue.empty())
173 vtkIdType point0Id = seamQueue.front();
175 double point0Value = sourceArray->GetTuple1(point0Id);
176 visitedArray->SetValue(point0Id,1);
177 seamArray->SetValue(point0Id,point0Value);
178 input->GetPointCells(point0Id,ncells,cells);
179 for (vtkIdType i=0; i<ncells; i++)
181 vtkIdType cellId = cells[i];
182 input->GetCellPoints(cellId,npts,pts);
183 for (vtkIdType j=0; j<npts; j++)
185 vtkIdType point1Id = pts[j];
186 if (visitedArray->GetValue(point1Id) == 1)
190 double point1Value = sourceArray->GetTuple1(point1Id);
191 if (point0Value * point1Value > 0.0)
193 seamArray->SetValue(point1Id,point1Value);
194 if (point1Value > 0.0)
196 rightQueue.push(point1Id);
200 leftQueue.push(point1Id);
204 visitedArray->SetValue(point1Id,1);
205 seamArray->SetValue(point1Id,point1Value);
206 seamQueue.push(point1Id);
211 const double leftValue = -1.0;
212 const double rightValue = 1.0;
214 while(!leftQueue.empty())
216 vtkIdType point0Id = leftQueue.front();
218 visitedArray->SetValue(point0Id,1);
219 input->GetPointCells(point0Id,ncells,cells);
220 for (vtkIdType i=0; i<ncells; i++)
222 vtkIdType cellId = cells[i];
223 input->GetCellPoints(cellId,npts,pts);
224 for (vtkIdType j=0; j<npts; j++)
226 vtkIdType point1Id = pts[j];
227 if (visitedArray->GetValue(point1Id) == 1)
231 visitedArray->SetValue(point1Id,1);
232 seamArray->SetValue(point1Id,leftValue);
233 leftQueue.push(point1Id);
238 while(!rightQueue.empty())
240 vtkIdType point0Id = rightQueue.front();
242 visitedArray->SetValue(point0Id,1);
243 input->GetPointCells(point0Id,ncells,cells);
244 for (vtkIdType i=0; i<ncells; i++)
246 vtkIdType cellId = cells[i];
247 input->GetCellPoints(cellId,npts,pts);
248 for (vtkIdType j=0; j<npts; j++)
250 vtkIdType point1Id = pts[j];
251 if (visitedArray->GetValue(point1Id) == 1)
255 visitedArray->SetValue(point1Id,1);
256 seamArray->SetValue(point1Id,rightValue);
257 rightQueue.push(point1Id);
262 output->DeepCopy(input);
263 output->GetPointData()->AddArray(seamArray);
266 visitedArray->Delete();
267 sourceArray->Delete();