Salome HOME
#17828 [CEA 17805] Polyhedron Mesh volume calculation and volume orientation criterion
authoreap <eap@opencascade.com>
Tue, 15 Oct 2019 13:04:58 +0000 (16:04 +0300)
committereap <eap@opencascade.com>
Tue, 15 Oct 2019 13:04:58 +0000 (16:04 +0300)
   Implement ChangePolyhedronNodes()

+ Enable  Orientation of Faces in wireframe mode

src/OBJECT/SMESH_DeviceActor.cxx
src/SMDS/SMDS_Mesh.cxx
src/SMDS/SMDS_Mesh.hxx
src/SMDS/SMDS_MeshVolume.cxx
src/SMDS/SMDS_MeshVolume.hxx
src/SMDS/SMDS_UnstructuredGrid.cxx
src/SMESHDS/SMESHDS_Mesh.cxx
src/SMESHDS/SMESHDS_Mesh.hxx
src/SMESHUtils/SMESH_Slot.cxx

index 7cbf49a4436550456caa75610a7c58ded2f4277d..e9c904f25bdd45f2405b8f1b3a2b48ba537c188c 100644 (file)
@@ -749,7 +749,7 @@ SMESH_DeviceActor
 {
   bool aShowFaceOrientation = myIsFacesOriented;
   aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()  
-  aShowFaceOrientation &= myRepresentation == eSurface;
+  aShowFaceOrientation &= ( myRepresentation != ePoint );
   myFaceOrientation->SetVisibility(aShowFaceOrientation);
 }
 
index d6a40165c1ec7fb99e9ce13bd7d3454afcc47de8..b4cac78c9ca585bcd04b92411ba4f5540843fe49 100644 (file)
@@ -1044,6 +1044,31 @@ bool SMDS_Mesh::RemoveSubMesh(const SMDS_Mesh * aMesh)
   return found;
 }
 
+//=======================================================================
+//function : ChangePolyhedronNodes
+//purpose  :
+//=======================================================================
+
+bool SMDS_Mesh::ChangePolyhedronNodes(const SMDS_MeshElement *                 element,
+                                      const std::vector<const SMDS_MeshNode*>& nodes,
+                                      const std::vector<int>&                  quantities)
+{
+  // keep current nodes of element
+  std::set<const SMDS_MeshNode*> oldNodes( element->begin_nodes(), element->end_nodes() );
+
+  // change nodes
+  bool Ok = false;
+  if ( const SMDS_MeshVolume* vol = DownCast<SMDS_MeshVolume>( element ))
+    Ok = vol->ChangeNodes( nodes, quantities );
+
+  if ( Ok )
+  {
+    setMyModified();
+    updateInverseElements( element, &nodes[0], nodes.size(), oldNodes );
+  }
+  return Ok;
+}
+
 //=======================================================================
 //function : ChangeElementNodes
 //purpose  :
@@ -1062,14 +1087,30 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
     Ok = cell->ChangeNodes(nodes, nbnodes);
 
   if ( Ok )
+  {
     setMyModified();
+    updateInverseElements( element, nodes, nbnodes, oldNodes );
+  }
+  return Ok;
+}
+
+//=======================================================================
+//function : updateInverseElements
+//purpose  : update InverseElements when element changes node
+//=======================================================================
 
-  if ( Ok && GetGrid()->HasLinks() ) // update InverseElements
+void SMDS_Mesh::updateInverseElements( const SMDS_MeshElement *        element,
+                                       const SMDS_MeshNode* const*     nodes,
+                                       const int                       nbnodes,
+                                       std::set<const SMDS_MeshNode*>& oldNodes )
+{
+  if ( GetGrid()->HasLinks() ) // update InverseElements
   {
     std::set<const SMDS_MeshNode*>::iterator it;
 
     // AddInverseElement to new nodes
-    for ( int i = 0; i < nbnodes; i++ ) {
+    for ( int i = 0; i < nbnodes; i++ )
+    {
       it = oldNodes.find( nodes[i] );
       if ( it == oldNodes.end() )
         // new node
@@ -1086,7 +1127,6 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
     }
   }
 
-  return Ok;
 }
 
 const SMDS_Mesh0DElement* SMDS_Mesh::Find0DElement(const SMDS_MeshNode * node)
index 3da801f598891de96fcb6ec2b957ef86a5421904..da7c9d5f85e48eaa3977bbccebb90cba888cc5db 100644 (file)
@@ -613,6 +613,9 @@ public:
   bool ChangeElementNodes(const SMDS_MeshElement * elem,
                           const SMDS_MeshNode    * nodes[],
                           const int                nbnodes);
+  bool ChangePolyhedronNodes(const SMDS_MeshElement *                 elem,
+                             const std::vector<const SMDS_MeshNode*>& nodes,
+                             const std::vector<int>&                  quantities);
 
   //virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1);
   // Renumber all nodes or elements.
@@ -708,7 +711,7 @@ public:
   void Modified();
   vtkMTimeType GetMTime() const;
 
-protected:
+ protected:
   SMDS_Mesh(SMDS_Mesh * parent);
 
   void addChildrenWithNodes(std::set<const SMDS_MeshElement*>& setOfChildren,
@@ -725,6 +728,11 @@ protected:
     else if (z < zmin) zmin = z;
   }
 
+  void updateInverseElements( const SMDS_MeshElement *        element,
+                              const SMDS_MeshNode* const*     nodes,
+                              const int                       nbnodes,
+                              std::set<const SMDS_MeshNode*>& oldNodes );
+
   void setNbShapes( size_t nbShapes );
 
 
index ec1ecc0c049544800ec1ca0b9aa8c0fa8abf5a85..ee9eb939fa0a11fbe1e681b9aff2753162271ad5 100644 (file)
@@ -75,6 +75,45 @@ void SMDS_MeshVolume::init( const std::vector<vtkIdType>& vtkNodeIds )
   SMDS_MeshCell::init( aType, vtkNodeIds );
 }
 
+bool SMDS_MeshVolume::ChangeNodes(const std::vector<const SMDS_MeshNode*>& nodes,
+                                  const std::vector<int>&                  quantities) const
+{
+  if ( !IsPoly() )
+    return false;
+
+  vtkIdType nFaces = 0;
+  vtkIdType* ptIds = 0;
+  getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
+
+  // stream size and nb faces should not change
+
+  if ((int) quantities.size() != nFaces )
+  {
+    return false;
+  }
+  int id = 0, nbPoints = 0;
+  for ( int i = 0; i < nFaces; i++ )
+  {
+    int nodesInFace = ptIds[id];
+    nbPoints += nodesInFace;
+    id += (nodesInFace + 1);
+  }
+  if ((int) nodes.size() != nbPoints )
+  {
+    return false;
+  }
+
+  // update ptIds
+  size_t iP = 0, iN = 0;
+  for ( size_t i = 0; i < quantities.size(); ++i )
+  {
+    ptIds[ iP++ ] = quantities[ i ]; // nb face nodes
+    for ( int j = 0; j < quantities[ i ]; ++j )
+      ptIds[ iP++ ] = nodes[ iN++ ]->GetVtkID();
+  }
+  return true;
+}
+
 const SMDS_MeshNode* SMDS_MeshVolume::GetNode(const int ind) const
 {
   if ( !IsPoly() )
index 76fabc2017a8359db2c38d2484d993ff3cb73b0b..84a2a64cfc749ee580bc2a28adef2063b3a0ac4c 100644 (file)
@@ -59,8 +59,12 @@ class SMDS_EXPORT SMDS_MeshVolume : public SMDS_MeshCell
   virtual SMDS_ElemIteratorPtr nodesIterator() const = 0;
   virtual SMDS_NodeIteratorPtr nodeIterator() const = 0;
 
+  bool ChangeNodes(const std::vector<const SMDS_MeshNode*>& nodes,
+                   const std::vector<int>&                  quantities) const;
+
   // 1 <= face_ind <= NbFaces()
   int NbFaceNodes (const int face_ind) const;
+
   // 1 <= face_ind <= NbFaces()
   // 1 <= node_ind <= NbFaceNodes()
   const SMDS_MeshNode* GetFaceNode (const int face_ind, const int node_ind) const;
index 72cb0fa000d0971db372c43508e9c0d06986a608..8594efb8f9967dde5cce5bc25196ba09385f3789 100644 (file)
@@ -158,18 +158,15 @@ int SMDS_UnstructuredGrid::InsertNextLinkedCell(int type, int npts, vtkIdType *p
     i++;
     for (int k = 0; k < nbnodes; k++)
     {
-      setOfNodes.insert(pts[i]);
+      if ( setOfNodes.insert( pts[i] ).second )
+      {
+        this->Links->ResizeCellList( pts[i], 1 );
+        this->Links->AddCellReference( cellid, pts[i] );
+      }
       i++;
     }
   }
 
-  std::set<vtkIdType>::iterator it = setOfNodes.begin();
-  for (; it != setOfNodes.end(); ++it)
-  {
-    this->Links->ResizeCellList(*it, 1);
-    this->Links->AddCellReference(cellid, *it);
-  }
-
   return cellid;
 }
 
index 6c91b4e5312c0661a5879aa67f93c268c8a4a105..b0c90a803f20a25321fdb21cdb75922789ab5466 100644 (file)
@@ -246,17 +246,17 @@ bool SMESHDS_Mesh::ChangePolygonNodes
 
 //=======================================================================
 //function : ChangePolyhedronNodes
-//purpose  : 
+//purpose  :
 //=======================================================================
-bool SMESHDS_Mesh::ChangePolyhedronNodes
-(const SMDS_MeshElement * elem,
std::vector<const SMDS_MeshNode*> nodes,
std::vector<int>                  quantities)
+bool SMESHDS_Mesh
+::ChangePolyhedronNodes (const SMDS_MeshElement *                 elem,
                        const std::vector<const SMDS_MeshNode*>& nodes,
                        const std::vector<int> &                 quantities)
 {
   ASSERT(nodes.size() > 3);
 
-  //if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
-  return false;
+  if ( !SMDS_Mesh::ChangePolyhedronNodes( elem, nodes, quantities ))
+    return false;
 
   int i, len = nodes.size();
   std::vector<int> nodes_ids (len);
@@ -270,7 +270,7 @@ bool SMESHDS_Mesh::ChangePolyhedronNodes
 
 //=======================================================================
 //function : Renumber
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
index 5ca8a2df4c6c13a858437efcf1730cef85524078..0a15cd448a377efa2c4989b44f72a093e5c23307 100644 (file)
@@ -597,9 +597,9 @@ class SMESHDS_EXPORT SMESHDS_Mesh : public SMDS_Mesh
                           const int                nbnodes);
   bool ChangePolygonNodes(const SMDS_MeshElement * elem,
                           std::vector<const SMDS_MeshNode*> nodes);
-  bool ChangePolyhedronNodes(const SMDS_MeshElement * elem,
-                             std::vector<const SMDS_MeshNode*> nodes,
-                             std::vector<int>                  quantities);
+  bool ChangePolyhedronNodes(const SMDS_MeshElement *                 elem,
+                             const std::vector<const SMDS_MeshNode*>& nodes,
+                             const std::vector<int>&                  quantities);
   bool ModifyCellNodes(int smdsVolId, std::map<int,int> localClonedNodeIds);
   void Renumber (const bool isNodes, const int startID=1, const int deltaID=1);
 
index b17225edc7a83dac24011fee79b042f2826fdecc..00521c0b52968e20360b775ed56656a4a95f186f 100644 (file)
@@ -806,10 +806,10 @@ SMESH_MeshAlgos::MakeSlot( SMDS_ElemIteratorPtr             theSegmentIt,
           isOut( intPnt[1].myNode, planeNormal, intPnt[1].myIsOutPln, 1 );
           const Segment * closeSeg[2] = { 0, 0 };
           if ( intPnt[0].myIsOutPln[0] )
-            closeSeg[0] = findTooCloseSegment( intPnt[0], 0.5 * theWidth - tol, tol,
+            closeSeg[0] = findTooCloseSegment( intPnt[0], 0.5 * theWidth - 1e-3*tol, tol,
                                                segment, n1, segmentsOfNode );
           if ( intPnt[1].myIsOutPln[0] )
-            closeSeg[1] = findTooCloseSegment( intPnt[1], 0.5 * theWidth - tol, tol,
+            closeSeg[1] = findTooCloseSegment( intPnt[1], 0.5 * theWidth - 1e-3*tol, tol,
                                                segment, n1, segmentsOfNode );
           int nbCut = bool( closeSeg[0] ) + bool( closeSeg[1] );
           if ( nbCut == 0 )