#include <list>
#include <climits>
+using namespace std;
+
SMDS_CellLinks* SMDS_CellLinks::New()
{
return new SMDS_CellLinks();
// --- type = VTK_POLYHEDRON
int cellid = this->InsertNextCell(type, npts, pts);
- std::set<vtkIdType> setOfNodes;
+ set<vtkIdType> setOfNodes;
setOfNodes.clear();
int nbfaces = npts;
int i = 0;
}
}
- std::set<vtkIdType>::iterator it = setOfNodes.begin();
+ set<vtkIdType>::iterator it = setOfNodes.begin();
for (; it != setOfNodes.end(); ++it)
{
this->Links->ResizeCellList(*it, 1);
}
void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize,
- std::vector<int>& idCellsNewToOld, int newCellSize)
+ std::vector<int>& idCellsOldToNew, int newCellSize)
{
+ int alreadyCopied = 0;
+
this->DeleteLinks();
- // IDs of VTK nodes always correspond to SMDS IDs but there can be "holes" in SMDS numeration.
- // We compact only if there were holes
+ // --- if newNodeSize, create a new compacted vtkPoints
- int oldNodeSize = this->GetNumberOfPoints();
- bool updateNodes = ( oldNodeSize > newNodeSize );
- if ( true /*updateNodes*/ )
+ if ( newNodeSize )
{
- // 21125: EDF 1233 SMESH: Degradation of precision in a test case for quadratic conversion
- // Use double type for storing coordinates of nodes instead float.
+ // rnv: to fix bug "21125: EDF 1233 SMESH: Degradation of precision in a test case for quadratic conversion"
+ // using double type for storing coordinates of nodes instead float.
vtkPoints *newPoints = vtkPoints::New();
- newPoints->SetDataType( VTK_DOUBLE );
- newPoints->SetNumberOfPoints( newNodeSize );
+ newPoints->SetDataType(VTK_DOUBLE);
+ newPoints->SetNumberOfPoints(newNodeSize);
+
+ int oldNodeSize = idNodesOldToNew.size();
- int i = 0, alreadyCopied = 0;
+ int i = 0;
while ( i < oldNodeSize )
{
// skip a hole if any
this->SetPoints(newPoints);
newPoints->Delete();
}
- else
- {
- this->Points->Squeeze();
- this->Points->Modified();
- }
+ this->Points->Squeeze();
- // Compact cells if VTK IDs do not correspond to SMDS IDs or nodes compacted
+ // --- create new compacted Connectivity, Locations and Types
- int oldCellSize = this->Types->GetNumberOfTuples();
- bool updateCells = ( updateNodes || newCellSize != oldCellSize );
- for ( int newID = 0, nbIDs = idCellsNewToOld.size(); newID < nbIDs && !updateCells; ++newID )
- updateCells = ( idCellsNewToOld[ newID ] != newID );
+ int oldCellSize = this->Types->GetNumberOfTuples();
- if ( false /*!updateCells*/ ) // no holes in elements
+ if ( !newNodeSize && oldCellSize == newCellSize ) // no holes in elements
{
this->Connectivity->Squeeze();
this->Locations->Squeeze();
this->FaceLocations->Squeeze();
this->Faces->Squeeze();
}
- this->Connectivity->Modified();
+ for ( int i = 0; i < oldCellSize; ++i )
+ idCellsOldToNew[i] = i;
return;
}
-
- if ((int) idNodesOldToNew.size() < oldNodeSize )
- {
- idNodesOldToNew.reserve( oldNodeSize );
- for ( int i = idNodesOldToNew.size(); i < oldNodeSize; ++i )
- idNodesOldToNew.push_back( i );
- }
-
- // --- create new compacted Connectivity, Locations and Types
-
- int newConnectivitySize = this->Connectivity->GetNumberOfConnectivityEntries();
- if ( newCellSize != oldCellSize )
- for ( int i = 0; i < oldCellSize - 1; ++i )
- if ( this->Types->GetValue( i ) == VTK_EMPTY_CELL )
- newConnectivitySize -= this->Locations->GetValue( i+1 ) - this->Locations->GetValue( i );
-
vtkCellArray *newConnectivity = vtkCellArray::New();
newConnectivity->Initialize();
- newConnectivity->Allocate( newConnectivitySize );
+ int oldCellDataSize = this->Connectivity->GetData()->GetSize();
+ newConnectivity->Allocate(oldCellDataSize);
vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New();
newTypes->Initialize();
newLocations->Initialize();
newLocations->SetNumberOfValues(newCellSize);
- std::vector< vtkIdType > pointsCell(1024); // --- points id to fill a new cell
+ // TODO some polyhedron may be huge (only in some tests)
+ vtkIdType tmpid[NBMAXNODESINCELL];
+ vtkIdType *pointsCell = &tmpid[0]; // --- points id to fill a new cell
- copyBloc(newTypes, idCellsNewToOld, idNodesOldToNew,
- newConnectivity, newLocations, pointsCell );
+ 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);
+ }
+ newConnectivity->Squeeze();
if (vtkDoubleArray* diameters =
vtkDoubleArray::SafeDownCast( vtkDataSet::CellData->GetScalars() )) // Balls
{
- vtkDoubleArray* newDiameters = vtkDoubleArray::New();
- newDiameters->SetNumberOfComponents(1);
- for ( int newCellID = 0; newCellID < newCellSize; newCellID++ )
+ for (int oldCellID = 0; oldCellID < oldCellSize; oldCellID++)
{
- if ( newTypes->GetValue( newCellID ) == VTK_POLY_VERTEX )
- {
- int oldCellID = idCellsNewToOld[ newCellID ];
- newDiameters->InsertValue( newCellID, diameters->GetValue( oldCellID ));
- }
- vtkDataSet::CellData->SetScalars( newDiameters );
+ if (this->Types->GetValue(oldCellID) == VTK_EMPTY_CELL)
+ continue;
+ int newCellId = idCellsOldToNew[ oldCellID ];
+ if (newTypes->GetValue(newCellId) == VTK_POLY_VERTEX)
+ diameters->SetValue( newCellId, diameters->GetValue( oldCellID ));
}
}
vtkIdTypeArray *newFaces = vtkIdTypeArray::New();
newFaces->Initialize();
newFaces->Allocate(this->Faces->GetSize());
- for ( int newCellID = 0; newCellID < newCellSize; newCellID++ )
+ for (int i = 0; i < oldCellSize; i++)
{
- if ( newTypes->GetValue( newCellID ) == VTK_POLYHEDRON )
+ if (this->Types->GetValue(i) == VTK_EMPTY_CELL)
+ continue;
+ int newCellId = idCellsOldToNew[i];
+ if (newTypes->GetValue(newCellId) == VTK_POLYHEDRON)
{
- int oldCellId = idCellsNewToOld[ newCellID ];
- newFaceLocations->InsertNextValue( newFaces->GetMaxId()+1 );
- int oldFaceLoc = this->FaceLocations->GetValue( oldCellId );
- int nCellFaces = this->Faces->GetValue( oldFaceLoc++ );
- newFaces->InsertNextValue( nCellFaces );
- for ( int n = 0; n < nCellFaces; n++ )
+ newFaceLocations->InsertNextValue(newFaces->GetMaxId()+1);
+ int oldFaceLoc = this->FaceLocations->GetValue(i);
+ int nCellFaces = this->Faces->GetValue(oldFaceLoc++);
+ newFaces->InsertNextValue(nCellFaces);
+ for (int n=0; n<nCellFaces; n++)
{
- int nptsInFace = this->Faces->GetValue( oldFaceLoc++ );
- newFaces->InsertNextValue( nptsInFace );
- for ( int k = 0; k < nptsInFace; k++ )
+ int nptsInFace = this->Faces->GetValue(oldFaceLoc++);
+ newFaces->InsertNextValue(nptsInFace);
+ for (int k=0; k<nptsInFace; k++)
{
- int oldpt = this->Faces->GetValue( oldFaceLoc++ );
- newFaces->InsertNextValue( idNodesOldToNew[ oldpt ]);
+ int oldpt = this->Faces->GetValue(oldFaceLoc++);
+ newFaces->InsertNextValue(idNodesOldToNew[oldpt]);
}
}
}
}
newFaceLocations->Squeeze();
newFaces->Squeeze();
- this->SetCells( newTypes, newLocations, newConnectivity, newFaceLocations, newFaces );
+ this->SetCells(newTypes, newLocations, newConnectivity, newFaceLocations, newFaces);
newFaceLocations->Delete();
newFaces->Delete();
}
else
{
- this->SetCells( newTypes, newLocations, newConnectivity, FaceLocations, Faces );
+ this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces);
}
newTypes->Delete();
if (nbPoints > 0)
{
memcpy(target, source, 3 * sizeof(double) * nbPoints);
- alreadyCopied += nbPoints;
+ for (int j = start; j < end; j++)
+ idNodesOldToNew[j] = alreadyCopied++; // old vtkId --> new vtkId
}
}
-void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray * newTypes,
- const std::vector<int>& idCellsNewToOld,
- const std::vector<int>& idNodesOldToNew,
- vtkCellArray* newConnectivity,
- vtkIdTypeArray* newLocations,
- std::vector<vtkIdType>& pointsCell)
+void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes,
+ std::vector<int>& idCellsOldToNew,
+ std::vector<int>& idNodesOldToNew,
+ vtkCellArray* newConnectivity,
+ vtkIdTypeArray* newLocations,
+ vtkIdType* pointsCell,
+ int& alreadyCopied,
+ int start,
+ int end)
{
- for ( size_t iNew = 0; iNew < idCellsNewToOld.size(); iNew++ )
+ for (int j = start; j < end; j++)
{
- int iOld = idCellsNewToOld[ iNew ];
- newTypes->SetValue( iNew, this->Types->GetValue( iOld ));
- vtkIdType oldLoc = this->Locations->GetValue( iOld );
+ newTypes->SetValue(alreadyCopied, this->Types->GetValue(j));
+ idCellsOldToNew[j] = alreadyCopied; // old vtkId --> new vtkId
+ vtkIdType oldLoc = this->Locations->GetValue(j);
vtkIdType nbpts;
vtkIdType *oldPtsCell = 0;
- this->Connectivity->GetCell( oldLoc, nbpts, oldPtsCell );
- if ((vtkIdType) pointsCell.size() < nbpts )
- pointsCell.resize( nbpts );
- for ( int l = 0; l < nbpts; l++ )
+ this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell);
+ assert(nbpts < NBMAXNODESINCELL);
+ for (int l = 0; l < nbpts; l++)
{
int oldval = oldPtsCell[l];
pointsCell[l] = idNodesOldToNew[oldval];
}
- /*int newcnt = */newConnectivity->InsertNextCell( nbpts, pointsCell.data() );
- int newLoc = newConnectivity->GetInsertLocation( nbpts );
- newLocations->SetValue( iNew, newLoc );
+ /*int newcnt = */newConnectivity->InsertNextCell(nbpts, pointsCell);
+ int newLoc = newConnectivity->GetInsertLocation(nbpts);
+ newLocations->SetValue(alreadyCopied, newLoc);
+ alreadyCopied++;
}
}
int connEdgeId = _downArray[vtkEdgeType]->addCell(vtkEdgeId);
SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
downEdge->setNodes(connEdgeId, vtkEdgeId);
- std::vector<int> vtkIds;
+ vector<int> vtkIds;
int nbVtkCells = downEdge->computeVtkCells(connEdgeId, vtkIds);
int downFaces[1000];
unsigned char downTypes[1000];
// --- check if the edge is already registered by exploration of the faces
//CHRONO(41);
- std::vector<int> vtkIds;
+ vector<int> vtkIds;
unsigned char vtkEdgeType = edgesWithNodes.elems[iedge].vtkType;
int *pts = &edgesWithNodes.elems[iedge].nodeIds[0];
SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
CHRONOSTOP(23);CHRONO(24);
- // compact downward connectivity structure: adjust downward arrays size, replace std::vector<vector int>> by a single std::vector<int>
+ // compact downward connectivity structure: adjust downward arrays size, replace vector<vector int>> by a single vector<int>
// 3D first then 2D and last 1D to release memory before edge upCells reorganization, (temporary memory use)
for (int vtkType = VTK_QUADRATIC_PYRAMID; vtkType >= 0; vtkType--)
std::map<int, std::map<long, int> >& nodeQuadDomains)
{
//MESSAGE("extrudeVolumeFromFace " << vtkVolId);
- std::vector<vtkIdType> orderedOriginals( originalNodes.begin(), originalNodes.end() );
+ vector<vtkIdType> orderedOriginals;
+ orderedOriginals.clear();
+ set<int>::const_iterator it = originalNodes.begin();
+ for (; it != originalNodes.end(); ++it)
+ orderedOriginals.push_back(*it);
int dim = 0;
int nbNodes = this->getOrderedNodesOfFace(vtkVolId, dim, orderedOriginals);
- std::vector<vtkIdType> orderedNodes;
+ vector<vtkIdType> orderedNodes;
bool isQuadratic = false;
switch (orderedOriginals.size())
{
double *coords = this->GetPoint(oldId);
SMDS_MeshNode *newNode = _mesh->AddNode(coords[0], coords[1], coords[2]);
- newId = newNode->GetVtkID();
+ newId = newNode->getVtkId();
if (! nodeQuadDomains.count(oldId))
{
std::map<long, int> emptyMap;