Salome HOME
PR: double nodes and flat elements for ASTER calculations in progress
[modules/smesh.git] / src / SMDS / SMDS_MeshNode.cxx
index c574b867121dcd51d2a894d22dac859e6a12869b..07f1d8d21b4e4565de8f7aec4fef1165787e5263 100644 (file)
 #include "SMDS_Mesh.hxx"
 #include <vtkUnstructuredGrid.h>
 
-#define protected public
-#include <vtkCellLinks.h>
-#define protected protected
-
 #include "utilities.h"
 #include "Utils_SALOME_Exception.hxx"
 #include <cassert>
@@ -65,25 +61,25 @@ SMDS_MeshNode::SMDS_MeshNode(int id, int meshId, int shapeId, double x, double y
 
 void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, double z)
 {
+  SMDS_MeshElement::init(id, meshId, shapeId);
   myVtkID = id -1;
   assert(myVtkID >= 0);
-  myID = id;
-  myMeshId = meshId;
-  myShapeId = shapeId;
-  myIdInShape = -1;
   //MESSAGE("Node " << myID << " " << myVtkID << " (" << x << ", " << y << ", " << z << ")");
   SMDS_Mesh* mesh = SMDS_Mesh::_meshList[myMeshId];
-  vtkUnstructuredGrid * grid = mesh->getGrid();
+  SMDS_UnstructuredGrid * grid = mesh->getGrid();
   vtkPoints *points = grid->GetPoints();
   points->InsertPoint(myVtkID, x, y, z);
-  vtkCellLinks *cellLinks = grid->GetCellLinks();
-  if (myVtkID >=cellLinks->Size)
-         cellLinks->Resize(myVtkID+SMDS_Mesh::chunkSize);
+  SMDS_CellLinks *cellLinks = dynamic_cast<SMDS_CellLinks*>(grid->GetCellLinks());
+  assert(cellLinks);
+  if (myVtkID >= cellLinks->GetLinksSize())
+          cellLinks->ResizeL(myVtkID+SMDS_Mesh::chunkSize);
 }
 
 SMDS_MeshNode::~SMDS_MeshNode()
 {
   nbNodes--;
+  if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() )
+    delete myPosition, myPosition = 0;
 }
 
 //=======================================================================
@@ -117,7 +113,11 @@ void SMDS_MeshNode::Print(ostream & OS) const
 
 void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
 {
-        myPosition = aPos;
+  if ( myPosition &&
+       myPosition != SMDS_SpacePosition::originSpacePosition() &&
+       myPosition != aPos )
+    delete myPosition;
+  myPosition = aPos;
 }
 
 //=======================================================================
@@ -220,7 +220,7 @@ private:
                            SMDSAbs_ElementType type):
     myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
   {
-       //MESSAGE("myNcells " << myNcells);
+        //MESSAGE("myNcells " << myNcells);
        for (; iter<ncells; iter++)
         {
            int vtkId = myCells[iter];
@@ -231,7 +231,7 @@ private:
                myFiltCells.push_back((SMDS_MeshElement*)elem);
         }
         myNcells = myFiltCells.size();
-               //MESSAGE("myNcells " << myNcells);
+        //MESSAGE("myNcells " << myNcells);
        iter = 0;
         //MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells);
   }
@@ -315,9 +315,12 @@ vtkIdType SMDS_MeshNode::GetVtkType() const
 //=======================================================================
 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
 {
-    const SMDS_MeshCell *cell = dynamic_cast<const SMDS_MeshCell*>(ME);
-    assert(cell);
-    SMDS_Mesh::_meshList[myMeshId]->getGrid()->AddReferenceToCell(myVtkID, cell->getVtkId());
+  const SMDS_MeshCell *cell = dynamic_cast<const SMDS_MeshCell*> (ME);
+  assert(cell);
+  SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
+  vtkCellLinks *Links = grid->GetCellLinks();
+  Links->ResizeCellList(myVtkID, 1);
+  Links->AddCellReference(cell->getVtkId(), myVtkID);
 }
 
 //=======================================================================