X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMDS%2FSMDS_UnstructuredGrid.cxx;h=65139c880e608f95881581e35746d1638ae9faea;hb=293e2534c037c652f037bd800f5e83d2f94a38a0;hp=ec30d5b641015af30f76375cb4815831d7c837a3;hpb=96cbac20480e2cb492d4f26cfd609c11a1ee8389;p=modules%2Fsmesh.git diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index ec30d5b64..65139c880 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -134,90 +134,89 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n // TODO utiliser mieux vtk pour faire plus simple (plus couteux ?) MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1); - int startHole = 0; - int endHole = 0; - int startBloc = 0; - int endBloc = 0; int alreadyCopied = 0; - int holes = 0; - typedef enum - { - lookHoleStart, lookHoleEnd, lookBlocEnd - } enumState; - enumState compactState = lookHoleStart; - - // if (this->Links) - // { - // this->Links->UnRegister(this); - // this->Links = 0; - // } + // if (this->Links) + // { + // this->Links->UnRegister(this); + // this->Links = 0; + // } // --- if newNodeSize, create a new compacted vtkPoints - vtkPoints *newPoints = 0; + vtkPoints *newPoints = vtkPoints::New(); + newPoints->SetDataType(VTK_DOUBLE); + newPoints->SetNumberOfPoints(newNodeSize); if (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" // 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(); - for (int i = 0; i < oldNodeSize; i++) - { - //MESSAGE(" " << i << " " << idNodesOldToNew[i]); - switch (compactState) - { - case lookHoleStart: - if (idNodesOldToNew[i] < 0) - { - MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize); - startHole = i; - if (!alreadyCopied) // copy the first bloc - { - MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize); - copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole); - } - compactState = lookHoleEnd; - } - break; - case lookHoleEnd: - if (idNodesOldToNew[i] >= 0) - { - MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize); - endHole = i; - startBloc = i; - compactState = lookBlocEnd; - } - break; - case lookBlocEnd: - if (idNodesOldToNew[i] < 0) - endBloc = i; // see nbPoints below - else if (i == (oldNodeSize - 1)) - endBloc = i + 1; - if (endBloc) - { - MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize); - 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); - } + int i = 0; + while ( i < oldNodeSize ) + { + // skip a hole if any + while ( i < oldNodeSize && idNodesOldToNew[i] < 0 ) + ++i; + int startBloc = i; + // look for a block end + while ( i < oldNodeSize && idNodesOldToNew[i] >= 0 ) + ++i; + int endBloc = i; + copyNodes(newPoints, idNodesOldToNew, alreadyCopied, startBloc, endBloc); + } +// for (int i = 0; i < oldNodeSize; i++) +// { +// //MESSAGE(" " << i << " " << idNodesOldToNew[i]); +// switch (compactState) +// { +// case lookHoleStart: +// if (idNodesOldToNew[i] < 0) +// { +// MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize); +// startHole = i; +// if (!alreadyCopied) // copy the first bloc +// { +// MESSAGE("--------- copy first nodes before hole " << i << " " << oldNodeSize); +// copyNodes(newPoints, idNodesOldToNew, alreadyCopied, 0, startHole); +// } +// compactState = lookHoleEnd; +// } +// break; +// case lookHoleEnd: +// if (idNodesOldToNew[i] >= 0) +// { +// MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize); +// endHole = i; +// startBloc = i; +// compactState = lookBlocEnd; +// } +// break; +// case lookBlocEnd: +// if (idNodesOldToNew[i] < 0) +// endBloc = i; // see nbPoints below +// else if (i == (oldNodeSize - 1)) +// endBloc = i + 1; +// if (endBloc) +// { +// MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize); +// 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(); } @@ -239,74 +238,82 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n newLocations->Initialize(); 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) vtkIdType tmpid[NBMAXNODESINCELL]; vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell - for (int i = 0; i < oldCellSize; i++) - { - switch (compactState) - { - case lookHoleStart: - if (this->Types->GetValue(i) == VTK_EMPTY_CELL) - { - MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize); - startHole = i; - compactState = lookHoleEnd; - if (!alreadyCopied) // copy the first bloc - { - MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize); - copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, - alreadyCopied, 0, startHole); - } - } - break; - case lookHoleEnd: - if (this->Types->GetValue(i) != VTK_EMPTY_CELL) - { - MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize); - endHole = i; - startBloc = i; - compactState = lookBlocEnd; - holes += endHole - startHole; - } - break; - case lookBlocEnd: - endBloc = 0; - if (this->Types->GetValue(i) == VTK_EMPTY_CELL) - endBloc = i; - 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); - } + alreadyCopied = 0; + int i = 0; + while ( i < oldCellSize ) + { + // skip a hole if any + while ( i < oldCellSize && this->Types->GetValue(i) == VTK_EMPTY_CELL ) + ++i; + int startBloc = i; + // look for a block end + while ( i < oldCellSize && this->Types->GetValue(i) != VTK_EMPTY_CELL ) + ++i; + int endBloc = i; + if ( endBloc > startBloc ) + copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, + alreadyCopied, startBloc, endBloc); + } +// for (int i = 0; i < oldCellSize; i++) +// { +// switch (compactState) +// { +// case lookHoleStart: +// if (this->Types->GetValue(i) == VTK_EMPTY_CELL) +// { +// MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize); +// startHole = i; +// compactState = lookHoleEnd; +// if (!alreadyCopied) // copy the first bloc +// { +// MESSAGE("--------- copy first bloc before hole " << i << " " << oldCellSize); +// copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell, +// alreadyCopied, 0, startHole); +// } +// } +// break; +// case lookHoleEnd: +// if (this->Types->GetValue(i) != VTK_EMPTY_CELL) +// { +// MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize); +// endHole = i; +// startBloc = i; +// compactState = lookBlocEnd; +// holes += endHole - startHole; +// } +// break; +// case lookBlocEnd: +// endBloc = 0; +// if (this->Types->GetValue(i) == VTK_EMPTY_CELL) +// endBloc = i; +// 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(); //newTypes->Squeeze(); //newLocations->Squeeze(); - if (newNodeSize) + if (1/*newNodeSize*/) { MESSAGE("------- newNodeSize, setPoints"); this->SetPoints(newPoints); @@ -359,6 +366,7 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int n else this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces); + newPoints->Delete(); newTypes->Delete(); newLocations->Delete(); newConnectivity->Delete(); @@ -403,7 +411,7 @@ void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, std::vector pointsCell[l] = idNodesOldToNew[oldval]; //MESSAGE(" " << oldval << " " << pointsCell[l]); } - int newcnt = newConnectivity->InsertNextCell(nbpts, pointsCell); + /*int newcnt = */newConnectivity->InsertNextCell(nbpts, pointsCell); int newLoc = newConnectivity->GetInsertLocation(nbpts); //MESSAGE(newcnt << " " << newLoc); newLocations->SetValue(alreadyCopied, newLoc); @@ -574,7 +582,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges) int vtkVolId = i; // MESSAGE("vtk volume " << vtkVolId); //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 @@ -805,15 +813,15 @@ int SMDS_UnstructuredGrid::GetNeighbors(int* neighborsVtkIds, int* downIds, unsi { int vtkType = this->GetCellType(vtkId); int cellDim = SMDS_Downward::getCellDimension(vtkType); - if (cellDim != 3) - return 0; // TODO voisins des faces ou edges + if (cellDim <2) + return 0; // TODO voisins des edges = edges connectees int cellId = this->_cellIdToDownId[vtkId]; int nbCells = _downArray[vtkType]->getNumberOfDownCells(cellId); const int *downCells = _downArray[vtkType]->getDownCells(cellId); const unsigned char* downTyp = _downArray[vtkType]->getDownTypes(cellId); - // --- iteration on faces of the 3D cell. + // --- iteration on faces of the 3D cell (or edges on the 2D cell). int nb = 0; for (int i = 0; i < nbCells; i++) @@ -824,7 +832,8 @@ int SMDS_UnstructuredGrid::GetNeighbors(int* neighborsVtkIds, int* downIds, unsi const int *upCells = _downArray[cellType]->getUpCells(downId); const unsigned char* upTypes = _downArray[cellType]->getUpTypes(downId); - // --- max 2 upCells, one is this cell, the other is a neighbor + // ---for a volume, max 2 upCells, one is this cell, the other is a neighbor + // for a face, number of neighbors (connected faces) not known for (int j = 0; j < nbUp; j++) { @@ -876,11 +885,10 @@ void SMDS_UnstructuredGrid::ModifyCellNodes(int vtkVolId, std::map loc } } -/*! Create a volume (prism or hexahedron) by duplication of a face. - * the nodes of the new face are already created. +/*! reorder the nodes of a face * @param vtkVolId vtk id of a volume containing the face, to get an orientation for the face. - * @param localClonedNodeIds map old node id to new node id. - * @return vtk id of the new volume. + * @param orderedNodes list of nodes to reorder (in out) + * @return size of the list */ int SMDS_UnstructuredGrid::getOrderedNodesOfFace(int vtkVolId, std::vector& orderedNodes) {