SALOME_ExtractPolyDataGeometry
::GetElemVTKId(vtkIdType theID)
{
- if(!myStoreMapping || myIsDoneShallowCopy){
+ if(!myStoreMapping || myIsDoneShallowCopy)
return theID;
- }
+
vtkIdType iEnd = myElemVTK2ObjIds.size();
for(vtkIdType i = 0; i < iEnd; i++)
if(myElemVTK2ObjIds[i] == theID)
SALOME_ExtractPolyDataGeometry
::GetNodeVTKId(vtkIdType theID)
{
- return theID;
+ if(!myStoreMapping || myIsDoneShallowCopy)
+ return theID;
+
+ vtkIdType iEnd = myNodeVTK2ObjIds.size();
+ for(vtkIdType i = 0; i < iEnd; i++)
+ if(myNodeVTK2ObjIds[i] == theID)
+ return i;
+
+ return -1;
}
SALOME_ExtractPolyDataGeometry
::GetNodeObjId(int theVtkID)
{
- return theVtkID;
+ if(!myStoreMapping || myIsDoneShallowCopy)
+ return theVtkID;
+
+ if(theVtkID < myNodeVTK2ObjIds.size())
+ return myNodeVTK2ObjIds[theVtkID];
+
+ return -1;
}
SALOME_ExtractPolyDataGeometry
::Execute2()
{
- vtkPolyData *input = this->GetInput();
+ vtkIdType ptId, numPts, numCells, i, cellId, newCellId, newId, *pointMap;
+ vtkIdList *cellPts;
+ vtkCell *cell;
+ int numCellPts;
+ vtkFloatingPointType *x;
+ vtkFloatingPointType multiplier;
+ vtkPoints *newPts;
+ vtkIdList *newCellPts;
+ vtkDataSet *input = this->GetInput();
vtkPointData *pd = input->GetPointData();
vtkCellData *cd = input->GetCellData();
vtkPolyData *output = this->GetOutput();
vtkPointData *outputPD = output->GetPointData();
vtkCellData *outputCD = output->GetCellData();
- vtkPoints *inPts=input->GetPoints();
- vtkIdType numPts, i, cellId = -1, newId;
- float multiplier;
- vtkCellArray *inVerts=NULL, *inLines=NULL, *inPolys=NULL, *inStrips=NULL;
- vtkCellArray *newVerts=NULL, *newLines=NULL, *newPolys=NULL, *newStrips=NULL;
-
- vtkDebugMacro(<< "Extracting poly data geometry");
+ int npts;
+ numCells = input->GetNumberOfCells();
+ numPts = input->GetNumberOfPoints();
if ( ! this->ImplicitFunction )
{
return;
}
- numPts = input->GetNumberOfPoints();
+ newCellPts = vtkIdList::New();
+ newCellPts->Allocate(VTK_CELL_SIZE);
if ( this->ExtractInside )
{
multiplier = 1.0;
}
- else
+ else
{
multiplier = -1.0;
}
- // Use a templated function to access the points. The points are
- // passed through, but scalar values are generated.
- vtkFloatArray *newScalars = vtkFloatArray::New();
- newScalars->SetNumberOfValues(numPts);
-
- for (int ptId=0; ptId < numPts; ptId++ )
+ // Loop over all points determining whether they are inside the
+ // implicit function. Copy the points and point data if they are.
+ //
+ pointMap = new vtkIdType[numPts]; // maps old point ids into new
+ for (i=0; i < numPts; i++)
{
- newScalars->SetValue(ptId, this->ImplicitFunction->
- FunctionValue(inPts->GetPoint(ptId))*multiplier);
+ pointMap[i] = -1;
}
- output->SetPoints(inPts);
- outputPD->PassData(pd);
+ output->Allocate(numCells/4); //allocate storage for geometry/topology
+ newPts = vtkPoints::New();
+ newPts->Allocate(numPts/4,numPts);
+ outputPD->CopyAllocate(pd);
+ outputCD->CopyAllocate(cd);
+ vtkFloatArray *newScalars = NULL;
- // Now loop over all cells to see whether they are inside the implicit
- // function. Copy if they are. Note: there is an awful hack here, that
- // can result in bugs. The cellId is assumed to be arranged starting
- // with the verts, then lines, then polys, then strips.
- //
- int numIn;
- vtkIdType npts = 0;
- vtkIdType *pts = 0;
- if ( input->GetNumberOfVerts() )
- {
- inVerts = input->GetVerts();
- newVerts = vtkCellArray::New();
- newVerts->Allocate(inVerts->GetSize());
- }
- if ( input->GetNumberOfLines() )
- {
- inLines = input->GetLines();
- newLines = vtkCellArray::New();
- newLines->Allocate(inLines->GetSize());
- }
- if ( input->GetNumberOfPolys() )
- {
- inPolys = input->GetPolys();
- newPolys = vtkCellArray::New();
- newPolys->Allocate(inPolys->GetSize());
- }
- if ( input->GetNumberOfStrips() )
- {
- inStrips = input->GetStrips();
- newStrips = vtkCellArray::New();
- newStrips->Allocate(inStrips->GetSize());
- }
-
- // verts
- if ( newVerts && !this->GetAbortExecute() )
+ if(myStoreMapping){
+ myElemVTK2ObjIds.reserve(numCells);
+ myNodeVTK2ObjIds.reserve(numPts);
+ }
+
+ if ( ! this->ExtractBoundaryCells )
{
- for (inVerts->InitTraversal(); inVerts->GetNextCell(npts,pts); )
+ for ( ptId=0; ptId < numPts; ptId++ )
{
- for (numIn=0, i=0; i<npts; i++)
+ x = input->GetPoint(ptId);
+ if ( (this->ImplicitFunction->FunctionValue(x)*multiplier) < 0.0 )
{
- if ( newScalars->GetValue(pts[i]) <= 0.0 )
- {
- numIn++;
- }
- }
- if ( (numIn == npts) || (this->ExtractBoundaryCells && numIn > 0) )
- {
- newId = newVerts->InsertNextCell(npts,pts);
+ newId = newPts->InsertNextPoint(x);
+ pointMap[ptId] = newId;
if(myStoreMapping)
- myElemVTK2ObjIds.push_back(newId);
- outputCD->CopyData(cd, cellId, newId);
+ myNodeVTK2ObjIds.push_back(ptId);
+ outputPD->CopyData(pd,ptId,newId);
}
- cellId++;
}
}
- this->UpdateProgress (0.6);
-
- // lines
- if ( newLines && !this->GetAbortExecute() )
+ else
{
- for (inLines->InitTraversal(); inLines->GetNextCell(npts,pts); )
+ // To extract boundary cells, we have to create supplemental information
+ if ( this->ExtractBoundaryCells )
{
- for (numIn=0, i=0; i<npts; i++)
+ vtkFloatingPointType val;
+ newScalars = vtkFloatArray::New();
+ newScalars->SetNumberOfValues(numPts);
+
+ for (ptId=0; ptId < numPts; ptId++ )
{
- if ( newScalars->GetValue(pts[i]) <= 0.0 )
+ x = input->GetPoint(ptId);
+ val = this->ImplicitFunction->FunctionValue(x) * multiplier;
+ newScalars->SetValue(ptId, val);
+ if ( val < 0.0 )
{
- numIn++;
+ newId = newPts->InsertNextPoint(x);
+ pointMap[ptId] = newId;
+ if(myStoreMapping)
+ myNodeVTK2ObjIds.push_back(ptId);
+ outputPD->CopyData(pd,ptId,newId);
}
}
- if ( (numIn == npts) || (this->ExtractBoundaryCells && numIn > 0) )
- {
- newId = newLines->InsertNextCell(npts,pts);
- if(myStoreMapping)
- myElemVTK2ObjIds.push_back(newId);
- outputCD->CopyData(cd, cellId, newId);
- }
- cellId++;
}
}
- this->UpdateProgress (0.75);
-
- // polys
- if ( newPolys && !this->GetAbortExecute() )
+
+ // Now loop over all cells to see whether they are inside implicit
+ // function (or on boundary if ExtractBoundaryCells is on).
+ //
+ for (cellId=0; cellId < numCells; cellId++)
{
- for (inPolys->InitTraversal(); inPolys->GetNextCell(npts,pts); )
+ cell = input->GetCell(cellId);
+ cellPts = cell->GetPointIds();
+ numCellPts = cell->GetNumberOfPoints();
+
+ newCellPts->Reset();
+ if ( ! this->ExtractBoundaryCells ) //requires less work
{
- for (numIn=0, i=0; i<npts; i++)
+ for ( npts=0, i=0; i < numCellPts; i++, npts++)
{
- if ( newScalars->GetValue(pts[i]) <= 0.0 )
+ ptId = cellPts->GetId(i);
+ if ( pointMap[ptId] < 0 )
{
- numIn++;
+ break; //this cell won't be inserted
+ }
+ else
+ {
+ newCellPts->InsertId(i,pointMap[ptId]);
}
}
- if ( (numIn == npts) || (this->ExtractBoundaryCells && numIn > 0) )
- {
- newId = newPolys->InsertNextCell(npts,pts);
- if(myStoreMapping)
- myElemVTK2ObjIds.push_back(newId);
- outputCD->CopyData(cd, cellId, newId);
- }
- cellId++;
- }
- }
- this->UpdateProgress (0.90);
-
- // strips
- if ( newStrips && !this->GetAbortExecute() )
- {
- for (inStrips->InitTraversal(); inStrips->GetNextCell(npts,pts); )
+ } //if don't want to extract boundary cells
+
+ else //want boundary cells
{
- for (numIn=0, i=0; i<npts; i++)
+ for ( npts=0, i=0; i < numCellPts; i++ )
{
- if ( newScalars->GetValue(pts[i]) <= 0.0 )
+ ptId = cellPts->GetId(i);
+ if ( newScalars->GetValue(ptId) <= 0.0 )
{
- numIn++;
+ npts++;
}
}
- if ( (numIn == npts) || (this->ExtractBoundaryCells && numIn > 0) )
+ if ( npts > 0 )
{
- newId = newStrips->InsertNextCell(npts,pts);
- if(myStoreMapping)
- myElemVTK2ObjIds.push_back(newId);
- outputCD->CopyData(cd, cellId, newId);
- }
- cellId++;
+ for ( i=0; i < numCellPts; i++ )
+ {
+ ptId = cellPts->GetId(i);
+ if ( pointMap[ptId] < 0 )
+ {
+ x = input->GetPoint(ptId);
+ newId = newPts->InsertNextPoint(x);
+ pointMap[ptId] = newId;
+ if(myStoreMapping)
+ myNodeVTK2ObjIds.push_back(ptId);
+ outputPD->CopyData(pd,ptId,newId);
+ }
+ newCellPts->InsertId(i,pointMap[ptId]);
+ }
+ }//a boundary or interior cell
+ }//if mapping boundary cells
+
+ if ( npts >= numCellPts || (this->ExtractBoundaryCells && npts > 0) )
+ {
+ newCellId = output->InsertNextCell(cell->GetCellType(),newCellPts);
+ if(myStoreMapping)
+ myElemVTK2ObjIds.push_back(cellId);
+ outputCD->CopyData(cd,cellId,newCellId);
}
- }
- this->UpdateProgress (1.0);
-
+ }//for all cells
+
// Update ourselves and release memory
//
- newScalars->Delete();
+ delete [] pointMap;
+ newCellPts->Delete();
+ output->SetPoints(newPts);
+ newPts->Delete();
- if ( newVerts )
- {
- output->SetVerts(newVerts);
- newVerts->Delete();
- }
- if ( newLines )
- {
- output->SetLines(newLines);
- newLines->Delete();
- }
- if ( newPolys )
- {
- output->SetPolys(newPolys);
- newPolys->Delete();
- }
- if ( newStrips )
+ if ( this->ExtractBoundaryCells )
{
- output->SetStrips(newStrips);
- newStrips->Delete();
+ newScalars->Delete();
}
+
+ output->Squeeze();
}