Salome HOME
IPAL22422 : TC6.3.0:hangup importing python dump
[modules/smesh.git] / src / SMDS / SMDS_Mesh.cxx
index d6f7e1813f23d8b5d56944b27b7e4cc3ccfdcb3a..72aa928c979880a80d2223d13d47b2c3c19dd7f7 100644 (file)
@@ -154,6 +154,9 @@ SMDS_Mesh::SMDS_Mesh()
   myGrid->Initialize();
   myGrid->Allocate();
   vtkPoints* points = 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.
+  points->SetDataType(VTK_DOUBLE);
   points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
   myGrid->SetPoints( points );
   points->Delete();
@@ -210,8 +213,7 @@ SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
   // find the MeshNode corresponding to ID
   const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
   if(!node){
-    // TODO ID < 1
-    if (ID <= 0)
+    if (ID < 1)
       {
         MESSAGE("=============>  Bad Node Id: " << ID);
         ID = myNodeIDFactory->GetFreeID();
@@ -219,6 +221,7 @@ SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
     myNodeIDFactory->adjustMaxId(ID);
     SMDS_MeshNode * node = myNodePool->getNew();
     node->init(ID, myMeshId, 0, x, y, z);
+
     if (ID >= myNodes.size())
     {
         myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
@@ -269,7 +272,7 @@ SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int I
   //MESSAGE("Add0DElementWithID" << ID)
   SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
   if (myElementIDFactory->BindID(ID, el0d)) {
-    SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
+    //SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
     //node->AddInverseElement(el0d);// --- fait avec BindID
     adjustmyCellsCapacity(ID);
     myCells[ID] = el0d;
@@ -1162,7 +1165,7 @@ SMDS_MeshFace* SMDS_Mesh::AddPolygonalFaceWithID
   else
     {
 //#ifdef VTK_HAVE_POLYHEDRON
-    MESSAGE("AddPolygonalFaceWithID vtk " << ID);
+    //MESSAGE("AddPolygonalFaceWithID vtk " << ID);
     vector<vtkIdType> nodeIds;
     nodeIds.clear();
     vector<const SMDS_MeshNode*>::iterator it = nodes.begin();
@@ -1257,7 +1260,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
   else
     {
 //#ifdef VTK_HAVE_POLYHEDRON
-      MESSAGE("AddPolyhedralVolumeWithID vtk " << ID);
+      //MESSAGE("AddPolyhedralVolumeWithID vtk " << ID);
       vector<vtkIdType> nodeIds;
       nodeIds.clear();
       vector<const SMDS_MeshNode*>::iterator it = nodes.begin();
@@ -1310,7 +1313,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolume
   return v;
 }
 
-SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<int>& vtkNodeIds)
+SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds)
 {
   int ID = myElementIDFactory->GetFreeID();
   SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeFromVtkIdsWithID(vtkNodeIds, ID);
@@ -1318,7 +1321,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIds(const std::vector<int>& vtkNodeI
   return v;
 }
 
-SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<int>& vtkNodeIds, const int ID)
+SMDS_MeshVolume* SMDS_Mesh::AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds, const int ID)
 {
   SMDS_VtkVolume *volvtk = myVolumePool->getNew();
   volvtk->init(vtkNodeIds, this);
@@ -2309,9 +2312,9 @@ void SMDS_Mesh::DebugStats() const
 ///////////////////////////////////////////////////////////////////////////////
 int SMDS_Mesh::NbNodes() const
 {
-       //MESSAGE(myGrid->GetNumberOfPoints());
-       //MESSAGE(myInfo.NbNodes());
-       //MESSAGE(myNodeMax);
+        //MESSAGE(myGrid->GetNumberOfPoints());
+        //MESSAGE(myInfo.NbNodes());
+        //MESSAGE(myNodeMax);
     return myInfo.NbNodes();
 }
 
@@ -2387,6 +2390,7 @@ SMDS_Mesh::~SMDS_Mesh()
     while (itn->more())
       {
         const SMDS_MeshNode *node = itn->next();
+        ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
         myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
       }
   }
@@ -2485,6 +2489,7 @@ void SMDS_Mesh::Clear()
   while (itn->more())
     {
       SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
+      node->SetPosition(SMDS_SpacePosition::originSpacePosition());
       myNodePool->destroy(node);
     }
   myNodes.clear();
@@ -2503,7 +2508,10 @@ void SMDS_Mesh::Clear()
   myGrid->Initialize();
   myGrid->Allocate();
   vtkPoints* points = vtkPoints::New();
-  points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
+  // 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.
+  points->SetDataType(VTK_DOUBLE);
+  points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
   myGrid->SetPoints( points );
   points->Delete();
   myGrid->BuildLinks();
@@ -2988,8 +2996,10 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement *        elem,
   //MESSAGE("SMDS_Mesh::RemoveElement " << elem->getVtkId() << " " << removenodes);
   // get finite elements built on elem
   set<const SMDS_MeshElement*> * s1;
-  if (elem->GetType() == SMDSAbs_0DElement || elem->GetType() == SMDSAbs_Edge && !hasConstructionEdges()
-      || elem->GetType() == SMDSAbs_Face && !hasConstructionFaces() || elem->GetType() == SMDSAbs_Volume)
+  if (    (elem->GetType() == SMDSAbs_0DElement)
+      || ((elem->GetType() == SMDSAbs_Edge) && !hasConstructionEdges())
+      || ((elem->GetType() == SMDSAbs_Face) && !hasConstructionFaces())
+      ||  (elem->GetType() == SMDSAbs_Volume) )
     {
       s1 = new set<const SMDS_MeshElement*> ();
       s1->insert(elem);
@@ -3116,7 +3126,10 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement *        elem,
           myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
           removedNodes.push_back((*it));
           if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
+          {
+            ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
             myNodePool->destroy((SMDS_MeshNode*) vtkElem);
+          }
           else
             delete (*it);
           it++;
@@ -3146,6 +3159,7 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
     if (!itFe->more()) { // free node
       myNodes[elemId] = 0;
       myInfo.myNbNodes--;
+      ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
       myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
       myNodeIDFactory->ReleaseID(elemId, vtkId);
     }
@@ -3395,8 +3409,8 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
   myInfo.myNbQuadEdges++;
 
 //  if (!registerElement(ID, edge)) {
-//       RemoveElement(edge, false);
-//       edge = NULL;
+//        RemoveElement(edge, false);
+//        edge = NULL;
 //  }
   return edge;
 
@@ -3540,7 +3554,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
   if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
   if(hasConstructionEdges()) {
     // creation quadratic edges - not implemented
-       return 0;
+        return 0;
   }
   else
   {
@@ -4077,8 +4091,8 @@ void SMDS_Mesh::updateNodeMinMax()
   myNodeMin = 0;
   if (myNodes.size() == 0)
   {
-       myNodeMax=0;
-       return;
+        myNodeMax=0;
+        return;
   }
   while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
     myNodeMin++;
@@ -4114,7 +4128,7 @@ void SMDS_Mesh::adjustStructure()
 
 void SMDS_Mesh::dumpGrid(string ficdump)
 {
-       MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
+        MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
 //  vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
 //  aWriter->SetFileName(ficdump.c_str());
 //  aWriter->SetInput(myGrid);
@@ -4129,35 +4143,35 @@ void SMDS_Mesh::dumpGrid(string ficdump)
   ficcon << "-------------------------------- points " <<  nbPoints << endl;
   for (int i=0; i<nbPoints; i++)
   {
-       ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
+        ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
   }
   int nbCells = myGrid->GetNumberOfCells();
   ficcon << "-------------------------------- cells " <<  nbCells << endl;
   for (int i=0; i<nbCells; i++)
   {
-//     MESSAGE(i << " " << myGrid->GetCell(i));
-//     MESSAGE("  " << myGrid->GetCell(i)->GetCellType());
-       ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
-       int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
-       vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
-       for (int j=0; j<nbptcell; j++)
-       {
-               ficcon << " " <<  listid->GetId(j);
-       }
-       ficcon << endl;
+//      MESSAGE(i << " " << myGrid->GetCell(i));
+//      MESSAGE("  " << myGrid->GetCell(i)->GetCellType());
+        ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
+        int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
+        vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
+        for (int j=0; j<nbptcell; j++)
+        {
+                ficcon << " " <<  listid->GetId(j);
+        }
+        ficcon << endl;
   }
   ficcon << "-------------------------------- connectivity " <<  nbPoints << endl;
-       vtkCellLinks *links = myGrid->GetCellLinks();
+        vtkCellLinks *links = myGrid->GetCellLinks();
   for (int i=0; i<nbPoints; i++)
   {
-       int ncells = links->GetNcells(i);
-       vtkIdType *cells = links->GetCells(i);
-       ficcon << i << " - " << ncells << " -";
-       for (int j=0; j<ncells; j++)
-       {
-               ficcon << " " << cells[j];
-       }
-       ficcon << endl;
+        int ncells = links->GetNcells(i);
+        vtkIdType *cells = links->GetCells(i);
+        ficcon << i << " - " << ncells << " -";
+        for (int j=0; j<ncells; j++)
+        {
+                ficcon << " " << cells[j];
+        }
+        ficcon << endl;
   }
   ficcon.close();