From: apo Date: Thu, 18 Jan 2007 07:14:35 +0000 (+0000) Subject: To fix regression with mapping of outside Gauss Points X-Git-Tag: WP1_2_3_17-01-2007_Data_format_at_entry_of_visualization_pipeline X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d0b061374c2471ad14eac143206f2f29abacbe2;p=modules%2Fvisu.git To fix regression with mapping of outside Gauss Points --- diff --git a/src/PIPELINE/SALOME_ExtractGeometry.cxx b/src/PIPELINE/SALOME_ExtractGeometry.cxx index f59c35c0..ad5dbd60 100755 --- a/src/PIPELINE/SALOME_ExtractGeometry.cxx +++ b/src/PIPELINE/SALOME_ExtractGeometry.cxx @@ -97,9 +97,9 @@ vtkIdType SALOME_ExtractGeometry ::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) @@ -112,9 +112,9 @@ vtkIdType SALOME_ExtractGeometry ::GetNodeVTKId(vtkIdType theID) { - if (!myStoreMapping||myIsDoneShallowCopy){ + if(!myStoreMapping || myIsDoneShallowCopy) return theID; - } + vtkIdType iEnd = myNodeVTK2ObjIds.size(); for(vtkIdType i = 0; i < iEnd; i++) if(myNodeVTK2ObjIds[i] == theID) diff --git a/src/PIPELINE/SALOME_ExtractPolyDataGeometry.cxx b/src/PIPELINE/SALOME_ExtractPolyDataGeometry.cxx index 987aaa62..6d9aa05e 100644 --- a/src/PIPELINE/SALOME_ExtractPolyDataGeometry.cxx +++ b/src/PIPELINE/SALOME_ExtractPolyDataGeometry.cxx @@ -89,9 +89,9 @@ vtkIdType 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) @@ -104,7 +104,15 @@ vtkIdType 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; } @@ -127,7 +135,13 @@ vtkIdType SALOME_ExtractPolyDataGeometry ::GetNodeObjId(int theVtkID) { - return theVtkID; + if(!myStoreMapping || myIsDoneShallowCopy) + return theVtkID; + + if(theVtkID < myNodeVTK2ObjIds.size()) + return myNodeVTK2ObjIds[theVtkID]; + + return -1; } @@ -159,19 +173,23 @@ void 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 ) { @@ -179,184 +197,157 @@ SALOME_ExtractPolyDataGeometry 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; iGetPoint(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; iSetNumberOfValues(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; iGetValue(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; iGetValue(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(); }