1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHDS : management of mesh data and SMESH document
24 // File : SMESH_Mesh.cxx
25 // Author : Yves FRICAUD, OCC
29 #include "SMESHDS_Mesh.hxx"
31 #include "SMESHDS_Group.hxx"
32 #include "SMDS_VertexPosition.hxx"
33 #include "SMDS_EdgePosition.hxx"
34 #include "SMDS_FacePosition.hxx"
35 #include "SMDS_SpacePosition.hxx"
36 #include "SMDS_Downward.hxx"
37 #include "SMESHDS_GroupOnGeom.hxx"
39 #include <Standard_ErrorHandler.hxx>
40 #include <Standard_OutOfRange.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
45 #include "utilities.h"
49 /*Standard_Boolean IsEqual( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
51 return S1.IsSame( S2 );
54 //=======================================================================
57 //=======================================================================
58 SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode):
60 myIsEmbeddedMode(theIsEmbeddedMode),
63 myScript = new SMESHDS_Script(theIsEmbeddedMode);
65 SetPersistentId(theMeshID);
68 //=======================================================================
69 bool SMESHDS_Mesh::IsEmbeddedMode()
71 return myIsEmbeddedMode;
74 //================================================================================
76 * \brief Store ID persistent during lifecycle
78 * Initially it was used to have a persistent reference to the mesh from the hypothesis
80 //================================================================================
82 void SMESHDS_Mesh::SetPersistentId(int id)
87 //================================================================================
89 * \brief Return ID persistent during lifecycle
91 //================================================================================
93 int SMESHDS_Mesh::GetPersistentId() const
95 return myPersistentID;
98 //=======================================================================
99 //function : ShapeToMesh
101 //=======================================================================
102 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
104 if ( !myShape.IsNull() && S.IsNull() )
106 // removal of a shape to mesh, delete ...
108 myShapeToHypothesis.Clear();
109 // - shape indices in SMDS_Position of nodes
110 map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
111 for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
112 if ( !i_sub->second->IsComplexSubmesh() ) {
113 SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes();
114 while ( nIt->more() )
115 i_sub->second->RemoveNode(nIt->next(), false);
119 TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin();
120 for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm )
122 myShapeIndexToSubMesh.clear();
123 myIndexToShape.Clear();
124 // - groups on geometry
125 set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
126 while ( gr != myGroups.end() ) {
127 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
128 myGroups.erase( gr++ );
136 TopExp::MapShapes(myShape, myIndexToShape);
140 //=======================================================================
141 //function : AddHypothesis
143 //=======================================================================
145 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
146 const SMESHDS_Hypothesis * H)
148 if (!myShapeToHypothesis.IsBound(SS.Oriented(TopAbs_FORWARD))) {
149 list<const SMESHDS_Hypothesis *> aList;
150 myShapeToHypothesis.Bind(SS.Oriented(TopAbs_FORWARD), aList);
152 list<const SMESHDS_Hypothesis *>& alist =
153 myShapeToHypothesis(SS.Oriented(TopAbs_FORWARD)); // ignore orientation of SS
155 //Check if the Hypothesis is still present
156 list<const SMESHDS_Hypothesis*>::iterator ith = find(alist.begin(),alist.end(), H );
158 if (alist.end() != ith) return false;
164 //=======================================================================
165 //function : RemoveHypothesis
167 //=======================================================================
169 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
170 const SMESHDS_Hypothesis * H)
172 if( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) )
174 list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S.Oriented(TopAbs_FORWARD) );
175 list<const SMESHDS_Hypothesis*>::iterator ith=find(alist.begin(),alist.end(), H );
176 if (ith != alist.end())
185 //=======================================================================
188 //=======================================================================
189 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
190 SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
191 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
195 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
196 SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
197 if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
201 //=======================================================================
202 //function : MoveNode
204 //=======================================================================
205 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
207 SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
209 myScript->MoveNode(n->GetID(), x, y, z);
212 //=======================================================================
213 //function : ChangeElementNodes
215 //=======================================================================
217 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
218 const SMDS_MeshNode * nodes[],
221 //MESSAGE("SMESHDS_Mesh::ChangeElementNodes");
222 if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
225 vector<int> IDs( nbnodes );
226 for ( int i = 0; i < nbnodes; i++ )
227 IDs [ i ] = nodes[ i ]->GetID();
228 myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
233 //=======================================================================
234 //function : ChangePolygonNodes
236 //=======================================================================
237 bool SMESHDS_Mesh::ChangePolygonNodes
238 (const SMDS_MeshElement * elem,
239 vector<const SMDS_MeshNode*> nodes)
241 ASSERT(nodes.size() > 3);
243 return ChangeElementNodes(elem, &nodes[0], nodes.size());
246 //=======================================================================
247 //function : ChangePolyhedronNodes
249 //=======================================================================
250 bool SMESHDS_Mesh::ChangePolyhedronNodes
251 (const SMDS_MeshElement * elem,
252 std::vector<const SMDS_MeshNode*> nodes,
253 std::vector<int> quantities)
255 ASSERT(nodes.size() > 3);
257 if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
260 int i, len = nodes.size();
261 std::vector<int> nodes_ids (len);
262 for (i = 0; i < len; i++) {
263 nodes_ids[i] = nodes[i]->GetID();
265 myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
270 //=======================================================================
271 //function : Renumber
273 //=======================================================================
275 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
277 // TODO not possible yet to have node numbers not starting to O and continuous.
278 if (!this->isCompacted())
280 // SMDS_Mesh::Renumber( isNodes, startID, deltaID );
281 // myScript->Renumber( isNodes, startID, deltaID );
284 //=======================================================================
285 //function : Add0DElement
287 //=======================================================================
288 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID(int nodeID, int ID)
290 SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElementWithID(nodeID, ID);
291 if (anElem) myScript->Add0DElement(ID, nodeID);
295 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID
296 (const SMDS_MeshNode * node, int ID)
298 return Add0DElementWithID(node->GetID(), ID);
301 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
303 SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElement(node);
304 if (anElem) myScript->Add0DElement(anElem->GetID(), node->GetID());
308 //=======================================================================
309 //function :AddEdgeWithID
311 //=======================================================================
312 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
314 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
315 if(anElem) myScript->AddEdge(ID,n1,n2);
319 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
320 const SMDS_MeshNode * n2,
323 return AddEdgeWithID(n1->GetID(),
328 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
329 const SMDS_MeshNode * n2)
331 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
332 if(anElem) myScript->AddEdge(anElem->GetID(),
338 //=======================================================================
341 //=======================================================================
342 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
344 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
345 if(anElem) myScript->AddFace(ID,n1,n2,n3);
349 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
350 const SMDS_MeshNode * n2,
351 const SMDS_MeshNode * n3,
354 return AddFaceWithID(n1->GetID(),
360 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
361 const SMDS_MeshNode * n2,
362 const SMDS_MeshNode * n3)
364 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
365 if(anElem) myScript->AddFace(anElem->GetID(),
372 //=======================================================================
375 //=======================================================================
376 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
378 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
379 if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
383 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
384 const SMDS_MeshNode * n2,
385 const SMDS_MeshNode * n3,
386 const SMDS_MeshNode * n4,
389 return AddFaceWithID(n1->GetID(),
396 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
397 const SMDS_MeshNode * n2,
398 const SMDS_MeshNode * n3,
399 const SMDS_MeshNode * n4)
401 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
402 if(anElem) myScript->AddFace(anElem->GetID(),
410 //=======================================================================
411 //function :AddVolume
413 //=======================================================================
414 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
416 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
417 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
421 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
422 const SMDS_MeshNode * n2,
423 const SMDS_MeshNode * n3,
424 const SMDS_MeshNode * n4,
427 return AddVolumeWithID(n1->GetID(),
434 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
435 const SMDS_MeshNode * n2,
436 const SMDS_MeshNode * n3,
437 const SMDS_MeshNode * n4)
439 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
440 if(anElem) myScript->AddVolume(anElem->GetID(),
448 //=======================================================================
449 //function :AddVolume
451 //=======================================================================
452 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
454 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
455 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
459 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
460 const SMDS_MeshNode * n2,
461 const SMDS_MeshNode * n3,
462 const SMDS_MeshNode * n4,
463 const SMDS_MeshNode * n5,
466 return AddVolumeWithID(n1->GetID(),
474 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
475 const SMDS_MeshNode * n2,
476 const SMDS_MeshNode * n3,
477 const SMDS_MeshNode * n4,
478 const SMDS_MeshNode * n5)
480 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
481 if(anElem) myScript->AddVolume(anElem->GetID(),
490 //=======================================================================
491 //function :AddVolume
493 //=======================================================================
494 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
496 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
497 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
501 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
502 const SMDS_MeshNode * n2,
503 const SMDS_MeshNode * n3,
504 const SMDS_MeshNode * n4,
505 const SMDS_MeshNode * n5,
506 const SMDS_MeshNode * n6,
509 return AddVolumeWithID(n1->GetID(),
518 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
519 const SMDS_MeshNode * n2,
520 const SMDS_MeshNode * n3,
521 const SMDS_MeshNode * n4,
522 const SMDS_MeshNode * n5,
523 const SMDS_MeshNode * n6)
525 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
526 if(anElem) myScript->AddVolume(anElem->GetID(),
536 //=======================================================================
537 //function :AddVolume
539 //=======================================================================
540 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
542 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
543 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
547 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
548 const SMDS_MeshNode * n2,
549 const SMDS_MeshNode * n3,
550 const SMDS_MeshNode * n4,
551 const SMDS_MeshNode * n5,
552 const SMDS_MeshNode * n6,
553 const SMDS_MeshNode * n7,
554 const SMDS_MeshNode * n8,
557 return AddVolumeWithID(n1->GetID(),
568 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
569 const SMDS_MeshNode * n2,
570 const SMDS_MeshNode * n3,
571 const SMDS_MeshNode * n4,
572 const SMDS_MeshNode * n5,
573 const SMDS_MeshNode * n6,
574 const SMDS_MeshNode * n7,
575 const SMDS_MeshNode * n8)
577 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
578 if(anElem) myScript->AddVolume(anElem->GetID(),
591 //=======================================================================
592 //function :AddVolume
593 //purpose : add hexagonal prism
594 //=======================================================================
595 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
596 int n5, int n6, int n7, int n8,
597 int n9, int n10, int n11, int n12,
600 SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, ID);
601 if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
605 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
606 const SMDS_MeshNode * n2,
607 const SMDS_MeshNode * n3,
608 const SMDS_MeshNode * n4,
609 const SMDS_MeshNode * n5,
610 const SMDS_MeshNode * n6,
611 const SMDS_MeshNode * n7,
612 const SMDS_MeshNode * n8,
613 const SMDS_MeshNode * n9,
614 const SMDS_MeshNode * n10,
615 const SMDS_MeshNode * n11,
616 const SMDS_MeshNode * n12,
619 return AddVolumeWithID(n1->GetID(),
634 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
635 const SMDS_MeshNode * n2,
636 const SMDS_MeshNode * n3,
637 const SMDS_MeshNode * n4,
638 const SMDS_MeshNode * n5,
639 const SMDS_MeshNode * n6,
640 const SMDS_MeshNode * n7,
641 const SMDS_MeshNode * n8,
642 const SMDS_MeshNode * n9,
643 const SMDS_MeshNode * n10,
644 const SMDS_MeshNode * n11,
645 const SMDS_MeshNode * n12)
647 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
648 if(anElem) myScript->AddVolume(anElem->GetID(),
665 //=======================================================================
666 //function : AddPolygonalFace
668 //=======================================================================
669 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<int>& nodes_ids,
672 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
674 myScript->AddPolygonalFace(ID, nodes_ids);
679 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
680 (const std::vector<const SMDS_MeshNode*>& nodes,
683 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
685 int i, len = nodes.size();
686 std::vector<int> nodes_ids (len);
687 for (i = 0; i < len; i++) {
688 nodes_ids[i] = nodes[i]->GetID();
690 myScript->AddPolygonalFace(ID, nodes_ids);
695 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
696 (const std::vector<const SMDS_MeshNode*>& nodes)
698 SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
700 int i, len = nodes.size();
701 std::vector<int> nodes_ids (len);
702 for (i = 0; i < len; i++) {
703 nodes_ids[i] = nodes[i]->GetID();
705 myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
710 //=======================================================================
711 //function : AddPolyhedralVolume
713 //=======================================================================
714 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (const std::vector<int>& nodes_ids,
715 const std::vector<int>& quantities,
718 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
720 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
725 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
726 (const std::vector<const SMDS_MeshNode*>& nodes,
727 const std::vector<int>& quantities,
730 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
732 int i, len = nodes.size();
733 std::vector<int> nodes_ids (len);
734 for (i = 0; i < len; i++) {
735 nodes_ids[i] = nodes[i]->GetID();
737 myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
742 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
743 (const std::vector<const SMDS_MeshNode*>& nodes,
744 const std::vector<int>& quantities)
746 SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
748 int i, len = nodes.size();
749 std::vector<int> nodes_ids (len);
750 for (i = 0; i < len; i++) {
751 nodes_ids[i] = nodes[i]->GetID();
753 myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
758 //=======================================================================
759 //function : removeFromContainers
761 //=======================================================================
763 static void removeFromContainers (map<int,SMESHDS_SubMesh*>& theSubMeshes,
764 set<SMESHDS_GroupBase*>& theGroups,
765 list<const SMDS_MeshElement*>& theElems,
768 if ( theElems.empty() )
772 // Element can belong to several groups
773 if ( !theGroups.empty() )
775 set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
776 for ( ; GrIt != theGroups.end(); GrIt++ )
778 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
779 if ( !group || group->IsEmpty() ) continue;
781 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
782 for ( ; elIt != theElems.end(); elIt++ )
784 group->SMDSGroup().Remove( *elIt );
785 if ( group->IsEmpty() ) break;
790 const bool deleted=true;
792 // Rm from sub-meshes
793 // Element should belong to only one sub-mesh
794 if ( !theSubMeshes.empty() )
796 SMESHDS_Mesh* mesh = theSubMeshes.begin()->second->getParent();
797 list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
799 for ( ; elIt != theElems.end(); ++elIt )
800 if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() ))
801 sm->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt), deleted );
804 for ( ; elIt != theElems.end(); ++elIt )
805 if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() ))
806 sm->RemoveElement( *elIt, deleted );
811 //=======================================================================
812 //function : RemoveNode
814 //=======================================================================
815 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
817 if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
819 SMESHDS_SubMesh* subMesh=0;
820 map<int,SMESHDS_SubMesh*>::iterator SubIt =
821 myShapeIndexToSubMesh.find( n->getshapeId() );
822 if ( SubIt != myShapeIndexToSubMesh.end() )
823 subMesh = SubIt->second;
825 SubIt = myShapeIndexToSubMesh.begin();
826 for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ )
827 if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( n ))
828 subMesh = SubIt->second;
830 RemoveFreeNode( n, subMesh, true);
834 myScript->RemoveNode(n->GetID());
836 list<const SMDS_MeshElement *> removedElems;
837 list<const SMDS_MeshElement *> removedNodes;
839 SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
841 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
842 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
845 //=======================================================================
846 //function : RemoveFreeNode
848 //=======================================================================
849 void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n,
850 SMESHDS_SubMesh * subMesh,
853 myScript->RemoveNode(n->GetID());
856 // Node can belong to several groups
857 if (fromGroups && !myGroups.empty()) {
858 set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
859 for (; GrIt != myGroups.end(); GrIt++) {
860 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
861 if (!group || group->IsEmpty()) continue;
862 group->SMDSGroup().Remove(n);
867 // Node should belong to only one sub-mesh
869 subMesh->RemoveNode(n,/*deleted=*/false);
871 SMDS_Mesh::RemoveFreeElement(n);
874 //=======================================================================
875 //function : RemoveElement
877 //========================================================================
878 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
880 if (elt->GetType() == SMDSAbs_Node)
882 RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
885 if (!hasConstructionEdges() && !hasConstructionFaces())
887 SMESHDS_SubMesh* subMesh=0;
888 map<int,SMESHDS_SubMesh*>::iterator SubIt = myShapeIndexToSubMesh.begin();
889 for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ )
890 if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( elt ))
891 subMesh = SubIt->second;
892 //MESSAGE("subMesh " << elt->getshapeId());
893 RemoveFreeElement( elt, subMesh, true);
897 myScript->RemoveElement(elt->GetID());
899 list<const SMDS_MeshElement *> removedElems;
900 list<const SMDS_MeshElement *> removedNodes;
902 SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
904 removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
907 //=======================================================================
908 //function : RemoveFreeElement
910 //========================================================================
911 void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
912 SMESHDS_SubMesh * subMesh,
915 //MESSAGE(" --------------------------------> SMESHDS_Mesh::RemoveFreeElement " << subMesh << " " << fromGroups);
916 if (elt->GetType() == SMDSAbs_Node) {
917 RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh);
921 if (hasConstructionEdges() || hasConstructionFaces())
922 // this methods is only for meshes without descendants
925 myScript->RemoveElement(elt->GetID());
928 // Node can belong to several groups
929 if ( fromGroups && !myGroups.empty() ) {
930 set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
931 for (; GrIt != myGroups.end(); GrIt++) {
932 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
933 if (group && !group->IsEmpty())
934 group->SMDSGroup().Remove(elt);
939 // Element should belong to only one sub-mesh
941 subMesh->RemoveElement(elt, /*deleted=*/false);
943 SMDS_Mesh::RemoveFreeElement(elt);
946 //================================================================================
948 * \brief Remove all data from the mesh
950 //================================================================================
952 void SMESHDS_Mesh::ClearMesh()
954 myScript->ClearMesh();
958 map<int,SMESHDS_SubMesh*>::iterator sub, subEnd = myShapeIndexToSubMesh.end();
959 for ( sub = myShapeIndexToSubMesh.begin(); sub != subEnd; ++sub )
960 sub->second->Clear();
963 TGroups::iterator group, groupEnd = myGroups.end();
964 for ( group = myGroups.begin(); group != groupEnd; ++group ) {
965 if ( SMESHDS_Group* g = dynamic_cast<SMESHDS_Group*>(*group)) {
966 SMDSAbs_ElementType groupType = g->GetType();
968 g->SetType( groupType );
973 //================================================================================
975 * \brief return submesh by shape
976 * \param shape - the sub-shape
977 * \retval SMESHDS_SubMesh* - the found submesh
979 * search of submeshes is optimized
981 //================================================================================
983 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape )
985 if ( shape.IsNull() )
988 if ( !myCurSubShape.IsNull() && shape.IsSame( myCurSubShape ))
991 getSubmesh( ShapeToIndex( shape ));
992 myCurSubShape = shape;
996 //================================================================================
998 * \brief return submesh by sub-shape index
999 * \param Index - the sub-shape index
1000 * \retval SMESHDS_SubMesh* - the found submesh
1001 * search of submeshes is optimized
1003 //================================================================================
1005 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const int Index )
1007 //Update or build submesh
1008 if ( Index != myCurSubID ) {
1009 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
1010 if ( it == myShapeIndexToSubMesh.end() )
1011 it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh(this, Index) )).first;
1012 myCurSubMesh = it->second;
1014 myCurSubShape.Nullify(); // myCurSubShape no more corresponds to submesh
1016 return myCurSubMesh;
1019 //================================================================================
1021 * \brief Add element or node to submesh
1022 * \param elem - element to add
1023 * \param subMesh - submesh to be filled in
1025 //================================================================================
1027 bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh )
1029 if ( elem && subMesh ) {
1030 if ( elem->GetType() == SMDSAbs_Node )
1031 subMesh->AddNode( static_cast<const SMDS_MeshNode* >( elem ));
1033 subMesh->AddElement( elem );
1039 //=======================================================================
1040 //function : SetNodeOnVolume
1042 //=======================================================================
1043 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
1044 const TopoDS_Shell & S)
1046 if ( add( aNode, getSubmesh(S) ))
1047 aNode->SetPosition ( SMDS_SpacePosition::originSpacePosition() );
1050 //=======================================================================
1051 //function : SetNodeOnVolume
1053 //=======================================================================
1054 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode * aNode,
1055 const TopoDS_Solid & S)
1057 if ( add( aNode, getSubmesh(S) ))
1058 aNode->SetPosition ( SMDS_SpacePosition::originSpacePosition() );
1061 //=======================================================================
1062 //function : SetNodeOnFace
1064 //=======================================================================
1065 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode * aNode,
1066 const TopoDS_Face & S,
1070 if ( add( aNode, getSubmesh(S) ))
1071 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
1074 //=======================================================================
1075 //function : SetNodeOnEdge
1077 //=======================================================================
1078 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode * aNode,
1079 const TopoDS_Edge & S,
1082 if ( add( aNode, getSubmesh(S) ))
1083 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
1086 //=======================================================================
1087 //function : SetNodeOnVertex
1089 //=======================================================================
1090 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode * aNode,
1091 const TopoDS_Vertex & S)
1093 if ( add( aNode, getSubmesh(S) ))
1094 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
1097 //=======================================================================
1098 //function : UnSetNodeOnShape
1100 //=======================================================================
1101 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
1103 int shapeId = aNode->getshapeId();
1106 map<int, SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find(shapeId);
1107 if (it != myShapeIndexToSubMesh.end())
1108 it->second->RemoveNode(aNode, /*deleted=*/false);
1112 //=======================================================================
1113 //function : SetMeshElementOnShape
1115 //=======================================================================
1116 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
1117 const TopoDS_Shape & S)
1119 add( anElement, getSubmesh(S) );
1122 //=======================================================================
1123 //function : UnSetMeshElementOnShape
1125 //=======================================================================
1126 void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem,
1127 const TopoDS_Shape & S)
1129 int Index = myIndexToShape.FindIndex(S);
1131 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
1132 if ( it != myShapeIndexToSubMesh.end() )
1134 if (elem->GetType() == SMDSAbs_Node)
1135 it->second->RemoveNode(static_cast<const SMDS_MeshNode*> (elem), /*deleted=*/false);
1137 it->second->RemoveElement(elem, /*deleted=*/false);
1141 //=======================================================================
1142 //function : ShapeToMesh
1144 //=======================================================================
1145 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
1150 //=======================================================================
1151 //function : IsGroupOfSubShapes
1152 //purpose : return true if at least one sub-shape of theShape is a sub-shape
1153 // of myShape or theShape == myShape
1154 //=======================================================================
1156 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
1158 if ( myIndexToShape.Contains(theShape) )
1161 for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1162 if (IsGroupOfSubShapes( it.Value() ))
1168 ///////////////////////////////////////////////////////////////////////////////
1169 /// Return the sub mesh linked to the a given TopoDS_Shape or NULL if the given
1170 /// TopoDS_Shape is unknown
1171 ///////////////////////////////////////////////////////////////////////////////
1172 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
1174 int Index = ShapeToIndex(S);
1175 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
1176 if (anIter != myShapeIndexToSubMesh.end())
1177 return anIter->second;
1182 ///////////////////////////////////////////////////////////////////////////////
1183 /// Return the sub mesh by Id of shape it is linked to
1184 ///////////////////////////////////////////////////////////////////////////////
1185 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const
1187 TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
1188 if (anIter != myShapeIndexToSubMesh.end())
1189 return anIter->second;
1194 //=======================================================================
1195 //function : SubMeshIndices
1197 //=======================================================================
1198 list<int> SMESHDS_Mesh::SubMeshIndices() const
1200 list<int> anIndices;
1201 std::map<int,SMESHDS_SubMesh*>::const_iterator anIter = myShapeIndexToSubMesh.begin();
1202 for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
1203 anIndices.push_back((*anIter).first);
1208 //=======================================================================
1209 //function : GetHypothesis
1211 //=======================================================================
1213 const list<const SMESHDS_Hypothesis*>&
1214 SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const
1216 if ( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) ) // ignore orientation of S
1217 return myShapeToHypothesis.Find( S.Oriented(TopAbs_FORWARD) );
1219 static list<const SMESHDS_Hypothesis*> empty;
1223 //================================================================================
1225 * \brief returns true if the hypothesis is assigned to any sub-shape
1227 //================================================================================
1229 bool SMESHDS_Mesh::IsUsedHypothesis(const SMESHDS_Hypothesis * H) const
1231 ShapeToHypothesis::Iterator s2h( myShapeToHypothesis );
1232 for ( ; s2h.More(); s2h.Next() )
1233 if ( std::find( s2h.Value().begin(), s2h.Value().end(), H ) != s2h.Value().end() )
1238 //=======================================================================
1239 //function : GetScript
1241 //=======================================================================
1242 SMESHDS_Script* SMESHDS_Mesh::GetScript()
1247 //=======================================================================
1248 //function : ClearScript
1250 //=======================================================================
1251 void SMESHDS_Mesh::ClearScript()
1256 //=======================================================================
1257 //function : HasMeshElements
1259 //=======================================================================
1260 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S) const
1262 if (myShape.IsNull()) MESSAGE("myShape is NULL");
1263 int Index = myIndexToShape.FindIndex(S);
1264 return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
1267 //=======================================================================
1268 //function : HasHypothesis
1270 //=======================================================================
1271 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
1273 return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD));
1276 //=======================================================================
1277 //function : NewSubMesh
1279 //=======================================================================
1280 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
1282 SMESHDS_SubMesh* SM = 0;
1283 TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index);
1284 if (anIter == myShapeIndexToSubMesh.end())
1286 SM = new SMESHDS_SubMesh(this, Index);
1287 myShapeIndexToSubMesh[Index]=SM;
1290 SM = anIter->second;
1294 //=======================================================================
1295 //function : AddCompoundSubmesh
1297 //=======================================================================
1299 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
1300 TopAbs_ShapeEnum type)
1303 if ( IsGroupOfSubShapes( S ))
1305 aMainIndex = myIndexToShape.Add( S );
1306 bool all = ( type == TopAbs_SHAPE );
1307 if ( all ) // corresponding simple submesh may exist
1308 aMainIndex = -aMainIndex;
1309 //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
1310 SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
1311 if ( !aNewSub->IsComplexSubmesh() ) // is empty
1313 int shapeType = Max( TopAbs_SOLID, all ? myShape.ShapeType() : type );
1314 int typeLimit = all ? TopAbs_VERTEX : type;
1315 for ( ; shapeType <= typeLimit; shapeType++ )
1317 TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
1318 for ( ; exp.More(); exp.Next() )
1320 int index = myIndexToShape.FindIndex( exp.Current() );
1322 aNewSub->AddSubMesh( NewSubMesh( index ));
1330 //=======================================================================
1331 //function : IndexToShape
1333 //=======================================================================
1334 const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const
1338 return myIndexToShape.FindKey(ShapeIndex);
1340 catch ( Standard_OutOfRange )
1343 static TopoDS_Shape nullShape;
1347 //================================================================================
1349 * \brief Return max index of sub-mesh
1351 //================================================================================
1353 int SMESHDS_Mesh::MaxSubMeshIndex() const
1355 return myShapeIndexToSubMesh.empty() ? 0 : myShapeIndexToSubMesh.rbegin()->first;
1358 //=======================================================================
1359 //function : ShapeToIndex
1361 //=======================================================================
1362 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
1364 if (myShape.IsNull())
1365 MESSAGE("myShape is NULL");
1367 int index = myIndexToShape.FindIndex(S);
1372 //=======================================================================
1373 //function : SetNodeOnVolume
1375 //=======================================================================
1376 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
1378 //add(aNode, getSubmesh(Index));
1379 if ( add( aNode, getSubmesh( Index )))
1380 ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition());
1383 //=======================================================================
1384 //function : SetNodeOnFace
1386 //=======================================================================
1387 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index, double u, double v)
1389 //Set Position on Node
1390 if ( add( aNode, getSubmesh( Index )))
1391 aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
1394 //=======================================================================
1395 //function : SetNodeOnEdge
1397 //=======================================================================
1398 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode,
1402 //Set Position on Node
1403 if ( add( aNode, getSubmesh( Index )))
1404 aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
1407 //=======================================================================
1408 //function : SetNodeOnVertex
1410 //=======================================================================
1411 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
1413 //Set Position on Node
1414 if ( add( aNode, getSubmesh( Index )))
1415 aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
1418 //=======================================================================
1419 //function : SetMeshElementOnShape
1421 //=======================================================================
1422 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
1425 add( anElement, getSubmesh( Index ));
1428 //=======================================================================
1429 //function : ~SMESHDS_Mesh
1431 //=======================================================================
1432 SMESHDS_Mesh::~SMESHDS_Mesh()
1437 TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin();
1438 for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm )
1439 delete i_sm->second;
1443 //********************************************************************
1444 //********************************************************************
1445 //******** *********
1446 //***** Methods for addition of quadratic elements ******
1447 //******** *********
1448 //********************************************************************
1449 //********************************************************************
1451 //=======================================================================
1452 //function : AddEdgeWithID
1454 //=======================================================================
1455 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID)
1457 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,n12,ID);
1458 if(anElem) myScript->AddEdge(ID,n1,n2,n12);
1462 //=======================================================================
1463 //function : AddEdge
1465 //=======================================================================
1466 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
1467 const SMDS_MeshNode* n2,
1468 const SMDS_MeshNode* n12)
1470 SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2,n12);
1471 if(anElem) myScript->AddEdge(anElem->GetID(),
1478 //=======================================================================
1479 //function : AddEdgeWithID
1481 //=======================================================================
1482 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
1483 const SMDS_MeshNode * n2,
1484 const SMDS_MeshNode * n12,
1487 return AddEdgeWithID(n1->GetID(),
1494 //=======================================================================
1495 //function : AddFace
1497 //=======================================================================
1498 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1499 const SMDS_MeshNode * n2,
1500 const SMDS_MeshNode * n3,
1501 const SMDS_MeshNode * n12,
1502 const SMDS_MeshNode * n23,
1503 const SMDS_MeshNode * n31)
1505 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n12,n23,n31);
1506 if(anElem) myScript->AddFace(anElem->GetID(),
1507 n1->GetID(), n2->GetID(), n3->GetID(),
1508 n12->GetID(), n23->GetID(), n31->GetID());
1512 //=======================================================================
1513 //function : AddFaceWithID
1515 //=======================================================================
1516 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
1517 int n12,int n23,int n31, int ID)
1519 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,ID);
1520 if(anElem) myScript->AddFace(ID,n1,n2,n3,n12,n23,n31);
1524 //=======================================================================
1525 //function : AddFaceWithID
1527 //=======================================================================
1528 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1529 const SMDS_MeshNode * n2,
1530 const SMDS_MeshNode * n3,
1531 const SMDS_MeshNode * n12,
1532 const SMDS_MeshNode * n23,
1533 const SMDS_MeshNode * n31,
1536 return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1537 n12->GetID(), n23->GetID(), n31->GetID(),
1542 //=======================================================================
1543 //function : AddFace
1545 //=======================================================================
1546 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1547 const SMDS_MeshNode * n2,
1548 const SMDS_MeshNode * n3,
1549 const SMDS_MeshNode * n4,
1550 const SMDS_MeshNode * n12,
1551 const SMDS_MeshNode * n23,
1552 const SMDS_MeshNode * n34,
1553 const SMDS_MeshNode * n41)
1555 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41);
1556 if(anElem) myScript->AddFace(anElem->GetID(),
1557 n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1558 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID());
1562 //=======================================================================
1563 //function : AddFaceWithID
1565 //=======================================================================
1566 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
1567 int n12,int n23,int n34,int n41, int ID)
1569 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,ID);
1570 if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41);
1574 //=======================================================================
1575 //function : AddFaceWithID
1577 //=======================================================================
1578 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1579 const SMDS_MeshNode * n2,
1580 const SMDS_MeshNode * n3,
1581 const SMDS_MeshNode * n4,
1582 const SMDS_MeshNode * n12,
1583 const SMDS_MeshNode * n23,
1584 const SMDS_MeshNode * n34,
1585 const SMDS_MeshNode * n41,
1588 return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1589 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1594 //=======================================================================
1595 //function : AddFace
1597 //=======================================================================
1598 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
1599 const SMDS_MeshNode * n2,
1600 const SMDS_MeshNode * n3,
1601 const SMDS_MeshNode * n4,
1602 const SMDS_MeshNode * n12,
1603 const SMDS_MeshNode * n23,
1604 const SMDS_MeshNode * n34,
1605 const SMDS_MeshNode * n41,
1606 const SMDS_MeshNode * nCenter)
1608 SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
1609 if(anElem) myScript->AddFace(anElem->GetID(),
1610 n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1611 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1616 //=======================================================================
1617 //function : AddFaceWithID
1619 //=======================================================================
1620 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
1621 int n12,int n23,int n34,int n41,
1622 int nCenter, int ID)
1624 SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,ID);
1625 if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
1629 //=======================================================================
1630 //function : AddFaceWithID
1632 //=======================================================================
1633 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
1634 const SMDS_MeshNode * n2,
1635 const SMDS_MeshNode * n3,
1636 const SMDS_MeshNode * n4,
1637 const SMDS_MeshNode * n12,
1638 const SMDS_MeshNode * n23,
1639 const SMDS_MeshNode * n34,
1640 const SMDS_MeshNode * n41,
1641 const SMDS_MeshNode * nCenter,
1644 return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1645 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1646 nCenter->GetID(), ID);
1650 //=======================================================================
1651 //function : AddVolume
1653 //=======================================================================
1654 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1655 const SMDS_MeshNode * n2,
1656 const SMDS_MeshNode * n3,
1657 const SMDS_MeshNode * n4,
1658 const SMDS_MeshNode * n12,
1659 const SMDS_MeshNode * n23,
1660 const SMDS_MeshNode * n31,
1661 const SMDS_MeshNode * n14,
1662 const SMDS_MeshNode * n24,
1663 const SMDS_MeshNode * n34)
1665 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1666 if(anElem) myScript->AddVolume(anElem->GetID(),
1667 n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1668 n12->GetID(), n23->GetID(), n31->GetID(),
1669 n14->GetID(), n24->GetID(), n34->GetID());
1673 //=======================================================================
1674 //function : AddVolumeWithID
1676 //=======================================================================
1677 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1678 int n12,int n23,int n31,
1679 int n14,int n24,int n34, int ID)
1681 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n12,n23,
1682 n31,n14,n24,n34,ID);
1683 if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
1687 //=======================================================================
1688 //function : AddVolumeWithID
1689 //purpose : 2d order tetrahedron of 10 nodes
1690 //=======================================================================
1691 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1692 const SMDS_MeshNode * n2,
1693 const SMDS_MeshNode * n3,
1694 const SMDS_MeshNode * n4,
1695 const SMDS_MeshNode * n12,
1696 const SMDS_MeshNode * n23,
1697 const SMDS_MeshNode * n31,
1698 const SMDS_MeshNode * n14,
1699 const SMDS_MeshNode * n24,
1700 const SMDS_MeshNode * n34,
1703 return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1704 n12->GetID(), n23->GetID(), n31->GetID(),
1705 n14->GetID(), n24->GetID(), n34->GetID(), ID);
1709 //=======================================================================
1710 //function : AddVolume
1712 //=======================================================================
1713 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1714 const SMDS_MeshNode * n2,
1715 const SMDS_MeshNode * n3,
1716 const SMDS_MeshNode * n4,
1717 const SMDS_MeshNode * n5,
1718 const SMDS_MeshNode * n12,
1719 const SMDS_MeshNode * n23,
1720 const SMDS_MeshNode * n34,
1721 const SMDS_MeshNode * n41,
1722 const SMDS_MeshNode * n15,
1723 const SMDS_MeshNode * n25,
1724 const SMDS_MeshNode * n35,
1725 const SMDS_MeshNode * n45)
1727 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n12,n23,n34,n41,
1730 myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1731 n3->GetID(), n4->GetID(), n5->GetID(),
1732 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1733 n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID());
1737 //=======================================================================
1738 //function : AddVolumeWithID
1740 //=======================================================================
1741 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
1742 int n12,int n23,int n34,int n41,
1743 int n15,int n25,int n35,int n45, int ID)
1745 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,
1747 n15,n25,n35,n45,ID);
1748 if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n12,n23,n34,n41,
1753 //=======================================================================
1754 //function : AddVolumeWithID
1755 //purpose : 2d order pyramid of 13 nodes
1756 //=======================================================================
1757 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1758 const SMDS_MeshNode * n2,
1759 const SMDS_MeshNode * n3,
1760 const SMDS_MeshNode * n4,
1761 const SMDS_MeshNode * n5,
1762 const SMDS_MeshNode * n12,
1763 const SMDS_MeshNode * n23,
1764 const SMDS_MeshNode * n34,
1765 const SMDS_MeshNode * n41,
1766 const SMDS_MeshNode * n15,
1767 const SMDS_MeshNode * n25,
1768 const SMDS_MeshNode * n35,
1769 const SMDS_MeshNode * n45,
1772 return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1773 n4->GetID(), n5->GetID(),
1774 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1775 n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID(),
1780 //=======================================================================
1781 //function : AddVolume
1783 //=======================================================================
1784 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1785 const SMDS_MeshNode * n2,
1786 const SMDS_MeshNode * n3,
1787 const SMDS_MeshNode * n4,
1788 const SMDS_MeshNode * n5,
1789 const SMDS_MeshNode * n6,
1790 const SMDS_MeshNode * n12,
1791 const SMDS_MeshNode * n23,
1792 const SMDS_MeshNode * n31,
1793 const SMDS_MeshNode * n45,
1794 const SMDS_MeshNode * n56,
1795 const SMDS_MeshNode * n64,
1796 const SMDS_MeshNode * n14,
1797 const SMDS_MeshNode * n25,
1798 const SMDS_MeshNode * n36)
1800 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n12,n23,n31,
1801 n45,n56,n64,n14,n25,n36);
1803 myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1804 n3->GetID(), n4->GetID(), n5->GetID(), n6->GetID(),
1805 n12->GetID(), n23->GetID(), n31->GetID(),
1806 n45->GetID(), n56->GetID(), n64->GetID(),
1807 n14->GetID(), n25->GetID(), n36->GetID());
1811 //=======================================================================
1812 //function : AddVolumeWithID
1814 //=======================================================================
1815 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
1816 int n4, int n5, int n6,
1817 int n12,int n23,int n31,
1818 int n45,int n56,int n64,
1819 int n14,int n25,int n36, int ID)
1821 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,
1825 if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n12,n23,n31,
1826 n45,n56,n64,n14,n25,n36);
1830 //=======================================================================
1831 //function : AddVolumeWithID
1832 //purpose : 2d order Pentahedron with 15 nodes
1833 //=======================================================================
1834 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1835 const SMDS_MeshNode * n2,
1836 const SMDS_MeshNode * n3,
1837 const SMDS_MeshNode * n4,
1838 const SMDS_MeshNode * n5,
1839 const SMDS_MeshNode * n6,
1840 const SMDS_MeshNode * n12,
1841 const SMDS_MeshNode * n23,
1842 const SMDS_MeshNode * n31,
1843 const SMDS_MeshNode * n45,
1844 const SMDS_MeshNode * n56,
1845 const SMDS_MeshNode * n64,
1846 const SMDS_MeshNode * n14,
1847 const SMDS_MeshNode * n25,
1848 const SMDS_MeshNode * n36,
1851 return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
1852 n4->GetID(), n5->GetID(), n6->GetID(),
1853 n12->GetID(), n23->GetID(), n31->GetID(),
1854 n45->GetID(), n56->GetID(), n64->GetID(),
1855 n14->GetID(), n25->GetID(), n36->GetID(),
1860 //=======================================================================
1861 //function : AddVolume
1862 //purpose : add quadratic hexahedron
1863 //=======================================================================
1864 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1865 const SMDS_MeshNode * n2,
1866 const SMDS_MeshNode * n3,
1867 const SMDS_MeshNode * n4,
1868 const SMDS_MeshNode * n5,
1869 const SMDS_MeshNode * n6,
1870 const SMDS_MeshNode * n7,
1871 const SMDS_MeshNode * n8,
1872 const SMDS_MeshNode * n12,
1873 const SMDS_MeshNode * n23,
1874 const SMDS_MeshNode * n34,
1875 const SMDS_MeshNode * n41,
1876 const SMDS_MeshNode * n56,
1877 const SMDS_MeshNode * n67,
1878 const SMDS_MeshNode * n78,
1879 const SMDS_MeshNode * n85,
1880 const SMDS_MeshNode * n15,
1881 const SMDS_MeshNode * n26,
1882 const SMDS_MeshNode * n37,
1883 const SMDS_MeshNode * n48)
1885 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
1890 myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1891 n3->GetID(), n4->GetID(), n5->GetID(),
1892 n6->GetID(), n7->GetID(), n8->GetID(),
1893 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1894 n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1895 n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID());
1899 //=======================================================================
1900 //function : AddVolumeWithID
1902 //=======================================================================
1903 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
1904 int n5, int n6, int n7, int n8,
1905 int n12,int n23,int n34,int n41,
1906 int n56,int n67,int n78,int n85,
1907 int n15,int n26,int n37,int n48, int ID)
1909 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
1912 n15,n26,n37,n48,ID);
1913 if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
1914 n56,n67,n78,n85,n15,n26,n37,n48);
1918 //=======================================================================
1919 //function : AddVolumeWithID
1920 //purpose : 2d order Hexahedrons with 20 nodes
1921 //=======================================================================
1922 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
1923 const SMDS_MeshNode * n2,
1924 const SMDS_MeshNode * n3,
1925 const SMDS_MeshNode * n4,
1926 const SMDS_MeshNode * n5,
1927 const SMDS_MeshNode * n6,
1928 const SMDS_MeshNode * n7,
1929 const SMDS_MeshNode * n8,
1930 const SMDS_MeshNode * n12,
1931 const SMDS_MeshNode * n23,
1932 const SMDS_MeshNode * n34,
1933 const SMDS_MeshNode * n41,
1934 const SMDS_MeshNode * n56,
1935 const SMDS_MeshNode * n67,
1936 const SMDS_MeshNode * n78,
1937 const SMDS_MeshNode * n85,
1938 const SMDS_MeshNode * n15,
1939 const SMDS_MeshNode * n26,
1940 const SMDS_MeshNode * n37,
1941 const SMDS_MeshNode * n48,
1944 return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
1945 n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
1946 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1947 n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1948 n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
1952 //=======================================================================
1953 //function : AddVolume
1954 //purpose : add tri-quadratic hexahedron of 27 nodes
1955 //=======================================================================
1957 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
1958 const SMDS_MeshNode * n2,
1959 const SMDS_MeshNode * n3,
1960 const SMDS_MeshNode * n4,
1961 const SMDS_MeshNode * n5,
1962 const SMDS_MeshNode * n6,
1963 const SMDS_MeshNode * n7,
1964 const SMDS_MeshNode * n8,
1965 const SMDS_MeshNode * n12,
1966 const SMDS_MeshNode * n23,
1967 const SMDS_MeshNode * n34,
1968 const SMDS_MeshNode * n41,
1969 const SMDS_MeshNode * n56,
1970 const SMDS_MeshNode * n67,
1971 const SMDS_MeshNode * n78,
1972 const SMDS_MeshNode * n85,
1973 const SMDS_MeshNode * n15,
1974 const SMDS_MeshNode * n26,
1975 const SMDS_MeshNode * n37,
1976 const SMDS_MeshNode * n48,
1977 const SMDS_MeshNode * n1234,
1978 const SMDS_MeshNode * n1256,
1979 const SMDS_MeshNode * n2367,
1980 const SMDS_MeshNode * n3478,
1981 const SMDS_MeshNode * n1458,
1982 const SMDS_MeshNode * n5678,
1983 const SMDS_MeshNode * nCenter)
1985 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
1989 n1234,n1256,n2367,n3478,n1458,n5678,nCenter);
1991 myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
1992 n3->GetID(), n4->GetID(), n5->GetID(),
1993 n6->GetID(), n7->GetID(), n8->GetID(),
1994 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
1995 n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
1996 n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
1997 n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
1998 n1458->GetID(),n5678->GetID(),nCenter->GetID());
2002 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
2003 int n5, int n6, int n7, int n8,
2004 int n12,int n23,int n34,int n41,
2005 int n56,int n67,int n78,int n85,
2006 int n15,int n26,int n37,int n48,
2007 int n1234,int n1256,int n2367,int n3478,
2008 int n1458,int n5678,int nCenter,
2011 SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
2015 n1234, n1256, n2367, n3478,
2016 n1458, n5678, nCenter,
2018 if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
2019 n56,n67,n78,n85,n15,n26,n37,n48,
2020 n1234, n1256, n2367, n3478,
2021 n1458, n5678, nCenter);
2025 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
2026 const SMDS_MeshNode * n2,
2027 const SMDS_MeshNode * n3,
2028 const SMDS_MeshNode * n4,
2029 const SMDS_MeshNode * n5,
2030 const SMDS_MeshNode * n6,
2031 const SMDS_MeshNode * n7,
2032 const SMDS_MeshNode * n8,
2033 const SMDS_MeshNode * n12,
2034 const SMDS_MeshNode * n23,
2035 const SMDS_MeshNode * n34,
2036 const SMDS_MeshNode * n41,
2037 const SMDS_MeshNode * n56,
2038 const SMDS_MeshNode * n67,
2039 const SMDS_MeshNode * n78,
2040 const SMDS_MeshNode * n85,
2041 const SMDS_MeshNode * n15,
2042 const SMDS_MeshNode * n26,
2043 const SMDS_MeshNode * n37,
2044 const SMDS_MeshNode * n48,
2045 const SMDS_MeshNode * n1234,
2046 const SMDS_MeshNode * n1256,
2047 const SMDS_MeshNode * n2367,
2048 const SMDS_MeshNode * n3478,
2049 const SMDS_MeshNode * n1458,
2050 const SMDS_MeshNode * n5678,
2051 const SMDS_MeshNode * nCenter,
2054 return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
2055 n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
2056 n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
2057 n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
2058 n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
2059 n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
2060 n1458->GetID(),n5678->GetID(),nCenter->GetID(), ID);
2063 void SMESHDS_Mesh::compactMesh()
2065 int newNodeSize = 0;
2066 int nbNodes = myNodes.size();
2067 int nbVtkNodes = myGrid->GetNumberOfPoints();
2068 MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes);
2069 int nbNodeTemp = nbVtkNodes;
2070 if (nbNodes > nbVtkNodes)
2071 nbNodeTemp = nbNodes;
2072 vector<int> idNodesOldToNew;
2073 idNodesOldToNew.clear();
2074 idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1
2076 for (int i = 0; i < nbNodes; i++)
2080 int vtkid = myNodes[i]->getVtkId();
2081 idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
2085 bool areNodesModified = (newNodeSize < nbVtkNodes);
2086 MESSAGE("------------------------- compactMesh Nodes Modified: " << areNodesModified);
2087 areNodesModified = true;
2089 int newCellSize = 0;
2090 int nbCells = myCells.size();
2091 int nbVtkCells = myGrid->GetNumberOfCells();
2092 MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells);
2093 int nbCellTemp = nbVtkCells;
2094 if (nbCells > nbVtkCells)
2095 nbCellTemp = nbCells;
2096 vector<int> idCellsOldToNew;
2097 idCellsOldToNew.clear();
2098 idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1
2100 for (int i = 0; i < nbCells; i++)
2104 // //idCellsOldToNew[i] = myCellIdVtkToSmds[i]; // valid vtk indexes are > = 0
2105 // int vtkid = myCells[i]->getVtkId();
2106 // idCellsOldToNew[vtkid] = i; // old vtkId --> old smdsId (not used in input)
2110 if (areNodesModified)
2111 myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize);
2113 myGrid->compactGrid(idNodesOldToNew, 0, idCellsOldToNew, newCellSize);
2115 int nbVtkPts = myGrid->GetNumberOfPoints();
2116 nbVtkCells = myGrid->GetNumberOfCells();
2117 if (nbVtkPts != newNodeSize)
2119 MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
2120 if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
2122 if (nbVtkCells != newCellSize)
2124 MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
2125 if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
2128 // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory
2130 if (areNodesModified)
2132 MESSAGE("-------------- modify myNodes");
2133 SetOfNodes newNodes;
2134 newNodes.resize(newNodeSize+1,0); // 0 not used, SMDS numbers 1..n
2136 for (int i = 0; i < nbNodes; i++)
2140 newSmdsId++; // SMDS id start to 1
2141 int oldVtkId = myNodes[i]->getVtkId();
2142 int newVtkId = idNodesOldToNew[oldVtkId];
2143 //MESSAGE("myNodes["<< i << "] vtkId " << oldVtkId << " --> " << newVtkId);
2144 myNodes[i]->setVtkId(newVtkId);
2145 myNodes[i]->setId(newSmdsId);
2146 newNodes[newSmdsId] = myNodes[i];
2147 //MESSAGE("myNodes["<< i << "] --> newNodes[" << newSmdsId << "]");
2150 myNodes.swap(newNodes);
2151 this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
2152 MESSAGE("myNodes.size " << myNodes.size());
2155 // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells
2157 int vtkIndexSize = myCellIdVtkToSmds.size();
2159 for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++)
2161 int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
2164 int newVtkId = idCellsOldToNew[oldVtkId];
2165 if (newVtkId > maxVtkId)
2166 maxVtkId = newVtkId;
2167 //MESSAGE("myCells["<< oldSmdsId << "] vtkId " << oldVtkId << " --> " << newVtkId);
2168 myCells[oldSmdsId]->setVtkId(newVtkId);
2171 // MESSAGE("myCells.size()=" << myCells.size()
2172 // << " myCellIdSmdsToVtk.size()=" << myCellIdSmdsToVtk.size()
2173 // << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
2175 SetOfCells newCells;
2176 //vector<int> newSmdsToVtk;
2177 vector<int> newVtkToSmds;
2179 assert(maxVtkId < newCellSize);
2180 newCells.resize(newCellSize+1, 0); // 0 not used, SMDS numbers 1..n
2181 //newSmdsToVtk.resize(newCellSize+1, -1);
2182 newVtkToSmds.resize(newCellSize+1, -1);
2184 int myCellsSize = myCells.size();
2186 for (int i = 0; i < myCellsSize; i++)
2190 newSmdsId++; // SMDS id start to 1
2191 assert(newSmdsId <= newCellSize);
2192 newCells[newSmdsId] = myCells[i];
2193 newCells[newSmdsId]->setId(newSmdsId);
2194 //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]");
2195 int idvtk = myCells[i]->getVtkId();
2196 //newSmdsToVtk[newSmdsId] = idvtk;
2197 assert(idvtk < newCellSize);
2198 newVtkToSmds[idvtk] = newSmdsId;
2202 myCells.swap(newCells);
2203 //myCellIdSmdsToVtk.swap(newSmdsToVtk);
2204 myCellIdVtkToSmds.swap(newVtkToSmds);
2205 MESSAGE("myCells.size()=" << myCells.size()
2206 << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
2207 this->myElementIDFactory->emptyPool(newSmdsId);
2209 this->myScript->SetModified(true); // notify GUI client for buildPrs when update
2211 // --- compact list myNodes and myElements in submeshes
2213 map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.begin();
2214 for(; it != myShapeIndexToSubMesh.end(); ++it)
2216 (*it).second->compactList();
2221 void SMESHDS_Mesh::CleanDownWardConnectivity()
2223 myGrid->CleanDownwardConnectivity();
2226 void SMESHDS_Mesh::BuildDownWardConnectivity(bool withEdges)
2228 myGrid->BuildDownwardConnectivity(withEdges);
2231 /*! change some nodes in cell without modifying type or internal connectivity.
2232 * Nodes inverse connectivity is maintained up to date.
2233 * @param vtkVolId vtk id of the cell.
2234 * @param localClonedNodeIds map old node id to new node id.
2235 * @return ok if success.
2237 bool SMESHDS_Mesh::ModifyCellNodes(int vtkVolId, std::map<int,int> localClonedNodeIds)
2239 myGrid->ModifyCellNodes(vtkVolId, localClonedNodeIds);