fix bug of compactGrid() that the last block of nodes and elements is

not copied if there is no hole after it
This commit is contained in:
eap 2011-02-01 13:42:33 +00:00
parent f7c8f718f9
commit 6b012bc7d8

View File

@ -134,18 +134,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
// TODO utiliser mieux vtk pour faire plus simple (plus couteux ?) // TODO utiliser mieux vtk pour faire plus simple (plus couteux ?)
MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1); MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1);
int startHole = 0;
int endHole = 0;
int startBloc = 0;
int endBloc = 0;
int alreadyCopied = 0; int alreadyCopied = 0;
int holes = 0;
typedef enum
{
lookHoleStart, lookHoleEnd, lookBlocEnd
} enumState;
enumState compactState = lookHoleStart;
// if (this->Links) // if (this->Links)
// { // {
@ -155,69 +144,79 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
// --- if newNodeSize, create a new compacted vtkPoints // --- if newNodeSize, create a new compacted vtkPoints
vtkPoints *newPoints = 0; vtkPoints *newPoints = vtkPoints::New();
newPoints->SetDataType(VTK_DOUBLE);
newPoints->SetNumberOfPoints(newNodeSize);
if (newNodeSize) if (newNodeSize)
{ {
MESSAGE("-------------- compactGrid, newNodeSize " << newNodeSize); MESSAGE("-------------- compactGrid, newNodeSize " << newNodeSize);
newPoints = vtkPoints::New();
// rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion" // rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
// using double type for storing coordinates of nodes instead float. // using double type for storing coordinates of nodes instead float.
newPoints->SetDataType(VTK_DOUBLE);
newPoints->Initialize();
newPoints->Allocate(newNodeSize);
newPoints->SetNumberOfPoints(newNodeSize);
int oldNodeSize = idNodesOldToNew.size(); int oldNodeSize = idNodesOldToNew.size();
for (int i = 0; i < oldNodeSize; i++) int i = 0;
{ while ( i < oldNodeSize )
//MESSAGE(" " << i << " " << idNodesOldToNew[i]); {
switch (compactState) // skip a hole if any
{ while ( i < oldNodeSize && idNodesOldToNew[i] < 0 )
case lookHoleStart: ++i;
if (idNodesOldToNew[i] < 0) int startBloc = i;
{ // look for a block end
MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize); while ( i < oldNodeSize && idNodesOldToNew[i] >= 0 )
startHole = i; ++i;
if (!alreadyCopied) // copy the first bloc int endBloc = i;
{ copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc);
MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize); }
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole); // for (int i = 0; i < oldNodeSize; i++)
} // {
compactState = lookHoleEnd; // //MESSAGE(" " << i << " " << idNodesOldToNew[i]);
} // switch (compactState)
break; // {
case lookHoleEnd: // case lookHoleStart:
if (idNodesOldToNew[i] >= 0) // if (idNodesOldToNew[i] < 0)
{ // {
MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize); // MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize);
endHole = i; // startHole = i;
startBloc = i; // if (!alreadyCopied) // copy the first bloc
compactState = lookBlocEnd; // {
} // MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize);
break; // copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole);
case lookBlocEnd: // }
if (idNodesOldToNew[i] < 0) // compactState = lookHoleEnd;
endBloc = i; // see nbPoints below // }
else if (i == (oldNodeSize - 1)) // break;
endBloc = i + 1; // case lookHoleEnd:
if (endBloc) // if (idNodesOldToNew[i] >= 0)
{ // {
MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize); // MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc); // endHole = i;
compactState = lookHoleEnd; // startBloc = i;
startHole = i; // compactState = lookBlocEnd;
endHole = 0; // }
startBloc = 0; // break;
endBloc = 0; // case lookBlocEnd:
} // if (idNodesOldToNew[i] < 0)
break; // endBloc = i; // see nbPoints below
} // else if (i == (oldNodeSize - 1))
} // endBloc = i + 1;
if (!alreadyCopied) // no hole, but shorter, no need to modify idNodesOldToNew // if (endBloc)
{ // {
MESSAGE("------------- newNodeSize, shorter " << oldNodeSize); // MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize);
copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, newNodeSize); // copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc);
} // compactState = lookHoleEnd;
// startHole = i;
// endHole = 0;
// startBloc = 0;
// endBloc = 0;
// }
// break;
// }
// }
// if (!alreadyCopied) // no hole, but shorter, no need to modify idNodesOldToNew
// {
// MESSAGE("------------- newNodeSize, shorter " << oldNodeSize);
// copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, newNodeSize);
// }
newPoints->Squeeze(); newPoints->Squeeze();
} }
@ -239,74 +238,82 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
newLocations->Initialize(); newLocations->Initialize();
newLocations->SetNumberOfValues(newCellSize); newLocations->SetNumberOfValues(newCellSize);
startHole = 0;
endHole = 0;
startBloc = 0;
endBloc = 0;
alreadyCopied = 0;
holes = 0;
compactState = lookHoleStart;
// TODO some polyhedron may be huge (only in some tests) // TODO some polyhedron may be huge (only in some tests)
vtkIdType tmpid[NBMAXNODESINCELL]; vtkIdType tmpid[NBMAXNODESINCELL];
vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell
for (int i = 0; i < oldCellSize; i++) alreadyCopied = 0;
{ int i = 0;
switch (compactState) while ( i < oldCellSize )
{ {
case lookHoleStart: // skip a hole if any
if (this->Types->GetValue(i) == VTK_EMPTY_CELL) while ( i < oldCellSize && this->Types->GetValue(i) == VTK_EMPTY_CELL )
{ ++i;
MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize); int startBloc = i;
startHole = i; // look for a block end
compactState = lookHoleEnd; while ( i < oldCellSize && this->Types->GetValue(i) != VTK_EMPTY_CELL )
if (!alreadyCopied) // copy the first bloc ++i;
{ int endBloc = i;
MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize); if ( endBloc > startBloc )
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
alreadyCopied, 0, startHole); alreadyCopied, startBloc, endBloc);
} }
} // for (int i = 0; i < oldCellSize; i++)
break; // {
case lookHoleEnd: // switch (compactState)
if (this->Types->GetValue(i) != VTK_EMPTY_CELL) // {
{ // case lookHoleStart:
MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize); // if (this->Types->GetValue(i) == VTK_EMPTY_CELL)
endHole = i; // {
startBloc = i; // MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize);
compactState = lookBlocEnd; // startHole = i;
holes += endHole - startHole; // compactState = lookHoleEnd;
} // if (!alreadyCopied) // copy the first bloc
break; // {
case lookBlocEnd: // MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize);
endBloc = 0; // copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
if (this->Types->GetValue(i) == VTK_EMPTY_CELL) // alreadyCopied, 0, startHole);
endBloc = i; // }
else if (i == (oldCellSize - 1)) // }
endBloc = i + 1; // break;
if (endBloc) // case lookHoleEnd:
{ // if (this->Types->GetValue(i) != VTK_EMPTY_CELL)
MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize); // {
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, // MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize);
alreadyCopied, startBloc, endBloc); // endHole = i;
compactState = lookHoleEnd; // startBloc = i;
} // compactState = lookBlocEnd;
break; // holes += endHole - startHole;
} // }
} // break;
if (!alreadyCopied) // no hole, but shorter // case lookBlocEnd:
{ // endBloc = 0;
MESSAGE(" -------- newCellSize, shorter " << oldCellSize); // if (this->Types->GetValue(i) == VTK_EMPTY_CELL)
copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, 0, // endBloc = i;
oldCellSize); // else if (i == (oldCellSize - 1))
} // endBloc = i + 1;
// if (endBloc)
// {
// MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize);
// copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
// alreadyCopied, startBloc, endBloc);
// compactState = lookHoleEnd;
// }
// break;
// }
// }
// if (!alreadyCopied) // no hole, but shorter
// {
// MESSAGE(" -------- newCellSize, shorter " << oldCellSize);
// copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, alreadyCopied, 0,
// oldCellSize);
// }
newConnectivity->Squeeze(); newConnectivity->Squeeze();
//newTypes->Squeeze(); //newTypes->Squeeze();
//newLocations->Squeeze(); //newLocations->Squeeze();
if (newNodeSize) if (1/*newNodeSize*/)
{ {
MESSAGE("------- newNodeSize, setPoints"); MESSAGE("------- newNodeSize, setPoints");
this->SetPoints(newPoints); this->SetPoints(newPoints);
@ -359,6 +366,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
else else
this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces); this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces);
newPoints->Delete();
newTypes->Delete(); newTypes->Delete();
newLocations->Delete(); newLocations->Delete();
newConnectivity->Delete(); newConnectivity->Delete();
@ -403,7 +411,7 @@ void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, std::vector
pointsCell[l] = idNodesOldToNew[oldval]; pointsCell[l] = idNodesOldToNew[oldval];
//MESSAGE(" " << oldval << " " << pointsCell[l]); //MESSAGE(" " << oldval << " " << pointsCell[l]);
} }
int newcnt = newConnectivity->InsertNextCell(nbpts, pointsCell); /*int newcnt = */newConnectivity->InsertNextCell(nbpts, pointsCell);
int newLoc = newConnectivity->GetInsertLocation(nbpts); int newLoc = newConnectivity->GetInsertLocation(nbpts);
//MESSAGE(newcnt << " " << newLoc); //MESSAGE(newcnt << " " << newLoc);
newLocations->SetValue(alreadyCopied, newLoc); newLocations->SetValue(alreadyCopied, newLoc);
@ -574,7 +582,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges)
int vtkVolId = i; int vtkVolId = i;
// MESSAGE("vtk volume " << vtkVolId); // MESSAGE("vtk volume " << vtkVolId);
//ASSERT(_downArray[vtkType]); //ASSERT(_downArray[vtkType]);
int connVolId = _downArray[vtkType]->addCell(vtkVolId); /*int connVolId = */_downArray[vtkType]->addCell(vtkVolId);
// --- find all the faces of the volume, describe the faces by their nodes // --- find all the faces of the volume, describe the faces by their nodes