Salome HOME
IMP 23373: [CEA 1170] Optimization of a 3D mesh using MG-Tetra
[modules/smesh.git] / src / SMDS / SMDS_MeshElementIDFactory.cxx
index 602fc4620dd300ee557e6a049ef56402f691e3d7..a029b101ec7324ae2e8b8f6952cb6532d0318565 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -53,33 +53,29 @@ SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():
 
 int SMDS_MeshElementIDFactory::SetInVtkGrid(SMDS_MeshElement * elem)
 {
-   // --- retrieve nodes ID
+  // --- retrieve nodes ID
 
   SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(elem);
   assert(cell);
-  vector<vtkIdType> nodeIds;
+  vector<vtkIdType> nodeIds( elem->NbNodes() );
   SMDS_ElemIteratorPtr it = elem->nodesIterator();
-  while(it->more())
+  for( int i = 0; it->more(); ++i )
   {
-      int nodeId = (static_cast<const SMDS_MeshNode*>(it->next()))->getVtkId();
-      MESSAGE("   node in cell " << cell->getVtkId() << " : " << nodeId)
-      nodeIds.push_back(nodeId);
+    int nodeId = (static_cast<const SMDS_MeshNode*>(it->next()))->getVtkId();
+    nodeIds[i] = nodeId;
   }
 
   // --- insert cell in vtkUnstructuredGrid
 
-  vtkUnstructuredGrid * grid = myMesh->getGrid();
-  //int locType = elem->GetType();
-  int typ = VTK_VERTEX;//GetVtkCellType(locType);
-  int cellId = grid->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]);
-  cell->setVtkId(cellId); 
-  //MESSAGE("SMDS_MeshElementIDFactory::SetInVtkGrid " << cellId);
+  int typ = VTK_VERTEX;
+  int cellId = myMesh->getGrid()->InsertNextLinkedCell(typ, nodeIds.size(), &nodeIds[0]);
+  cell->setVtkId(cellId);
   return cellId;
 }
 
 //=======================================================================
 //function : BindID
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
@@ -95,7 +91,7 @@ bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
 //=======================================================================
 SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
 {
-  if ((ID<1) || (ID>=myMesh->myCells.size()))
+  if ( ID<1 || ID >= (int) myMesh->myCells.size() )
     return NULL;
   const SMDS_MeshElement* elem = GetMesh()->FindElement(ID);
   return (SMDS_MeshElement*)(elem);
@@ -122,17 +118,16 @@ int SMDS_MeshElementIDFactory::GetFreeID()
 void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId)
 {
   if (ID < 1) // TODO check case ID == O
-    {
-      MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID);
-      return;
-    }
-  //MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID smdsId vtkId " << ID << " " << vtkId);
+  {
+    MESSAGE("~~~~~~~~~~~~~~ SMDS_MeshElementIDFactory::ReleaseID ID = " << ID);
+    return;
+  }
   if (vtkId >= 0)
-    {
-      assert(vtkId < myMesh->myCellIdVtkToSmds.size());
-      myMesh->myCellIdVtkToSmds[vtkId] = -1;
-      myMesh->setMyModified();
-    }
+  {
+    assert(vtkId < (int)myMesh->myCellIdVtkToSmds.size());
+    myMesh->myCellIdVtkToSmds[vtkId] = -1;
+    myMesh->setMyModified();
+  }
   SMDS_MeshIDFactory::ReleaseID(ID);
   if (ID == myMax)
     myMax = 0;
@@ -142,24 +137,24 @@ void SMDS_MeshElementIDFactory::ReleaseID(int ID, int vtkId)
 
 //=======================================================================
 //function : updateMinMax
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMDS_MeshElementIDFactory::updateMinMax() const
 {
   myMin = INT_MAX;
   myMax = 0;
-  for (int i = 0; i < myMesh->myCells.size(); i++)
+  for (size_t i = 0; i < myMesh->myCells.size(); i++)
+  {
+    if (myMesh->myCells[i])
     {
-      if (myMesh->myCells[i])
-        {
-          int id = myMesh->myCells[i]->GetID();
-          if (id > myMax)
-            myMax = id;
-          if (id < myMin)
-            myMin = id;
-        }
+      int id = myMesh->myCells[i]->GetID();
+      if (id > myMax)
+        myMax = id;
+      if (id < myMin)
+        myMin = id;
     }
+  }
   if (myMin == INT_MAX)
     myMin = 0;
 }
@@ -171,12 +166,11 @@ void SMDS_MeshElementIDFactory::updateMinMax() const
 
 SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
 {
-    return myMesh->elementsIterator(SMDSAbs_All);
+  return myMesh->elementsIterator(SMDSAbs_All);
 }
 
 void SMDS_MeshElementIDFactory::Clear()
 {
-  //myMesh->myCellIdSmdsToVtk.clear();
   myMesh->myCellIdVtkToSmds.clear();
   myMin = myMax = 0;
   SMDS_MeshIDFactory::Clear();