3 // Created: Wed Jan 23 16:49:00 2002
4 // Author: Jean-Michel BOULCOURT
5 // <jmb@coulox.paris1.matra-dtv.fr>
8 #include "SMDS_Mesh.ixx"
9 #include "SMDS_MapIteratorOfExtendedOrientedMap.hxx"
10 #include "SMDS_ListOfMeshElement.hxx"
11 #include "SMDS_ListIteratorOfListOfMeshElement.hxx"
12 #include "SMDS_MeshNode.hxx"
13 #include "SMDS_MeshEdge.hxx"
14 #include "SMDS_MeshFace.hxx"
15 #include "SMDS_MeshTriangle.hxx"
16 #include "SMDS_MeshQuadrangle.hxx"
17 #include "SMDS_MeshVolume.hxx"
18 #include "SMDS_MeshTetrahedron.hxx"
19 #include "SMDS_MeshPyramid.hxx"
20 #include "SMDS_MeshPrism.hxx"
21 #include "SMDS_MeshHexahedron.hxx"
22 #include "SMDS_ListOfMesh.hxx"
23 #include "SMDS_ListIteratorOfListOfMesh.hxx"
26 #include <Standard_ErrorHandler.hxx>
27 #include <Standard_NoSuchObject.hxx>
29 #include "utilities.h"
32 //=======================================================================
33 //function : SMDS_Mesh
34 //purpose : creation of a new mesh object
35 //=======================================================================
37 SMDS_Mesh::SMDS_Mesh(const Standard_Integer nbnodes,
38 const Standard_Integer nbedges,
39 const Standard_Integer nbfaces,
40 const Standard_Integer nbvolumes)
41 :myNodes(nbnodes),myEdges(nbedges),myFaces(nbfaces),myVolumes(nbvolumes),
42 myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
43 myElementIDFactory(new SMDS_MeshElementIDFactory()),myHasInverse(Standard_False)
47 //=======================================================================
48 //function : SMDS_Mesh
50 //=======================================================================
52 SMDS_Mesh::SMDS_Mesh(const Handle(SMDS_Mesh)& parent,
53 const Standard_Integer nbnodes)
54 :myNodes(nbnodes),myParent(parent),myNodeIDFactory(parent->myNodeIDFactory),
55 myElementIDFactory(parent->myElementIDFactory),
56 myHasInverse(Standard_False)
60 //=======================================================================
61 //function : AddSubMesh
62 //purpose : create an submesh
63 //=======================================================================
65 Handle(SMDS_Mesh) SMDS_Mesh::AddSubMesh()
67 Handle(SMDS_Mesh) submesh = new SMDS_Mesh(this);
68 if (!submesh.IsNull()) {
69 myChildren.Append(submesh);
76 //=======================================================================
78 //purpose : create a MeshNode and returns an ID
79 //=======================================================================
81 Standard_Integer SMDS_Mesh::AddNode(const Standard_Real x,
82 const Standard_Real y,
83 const Standard_Real z)
85 Standard_Integer ID = myNodeIDFactory->GetFreeID();
87 Handle(SMDS_MeshElement) node = new SMDS_MeshNode(ID,x,y,z);
93 //=======================================================================
95 //purpose : create a MeshNode. Returns False if the ID already exists
96 //=======================================================================
98 Standard_Boolean SMDS_Mesh::AddNodeWithID(const Standard_Real x,
99 const Standard_Real y,
100 const Standard_Real z,
101 const Standard_Integer ID)
104 // find the MeshNode corresponding to ID
105 Handle(SMDS_MeshElement) node;
109 node = new SMDS_MeshNode(ID,x,y,z);
111 return Standard_True;
113 return Standard_False;
117 //=======================================================================
119 //purpose : add an existing node in the mesh (useful for submesh)
120 //=======================================================================
122 Standard_Boolean SMDS_Mesh::AddNode(const Standard_Integer ID)
124 // find the MeshNode corresponding to ID
125 Handle(SMDS_MeshElement) node;
129 if (!node.IsNull()) {
131 return Standard_True;;
133 return Standard_False;
136 //=======================================================================
139 //=======================================================================
141 Standard_Boolean SMDS_Mesh::AddNode(const Handle(SMDS_MeshElement)& node)
144 if (!node.IsNull()) {
146 if (!myParent.IsNull()) {
147 myParent->AddNode(node);
149 return Standard_True;
151 return Standard_False;
155 //=======================================================================
158 //=======================================================================
160 Standard_Integer SMDS_Mesh::AddEdge(const Standard_Integer idnode1,
161 const Standard_Integer idnode2)
163 Standard_Integer ID = myElementIDFactory->GetFreeID();
165 if (AddEdgeWithID(idnode1,idnode2,ID))
172 //=======================================================================
175 //=======================================================================
177 Standard_Boolean SMDS_Mesh::AddEdgeWithID(const Standard_Integer idnode1,
178 const Standard_Integer idnode2,
179 const Standard_Integer ID)
181 Handle(SMDS_MeshElement) edge,elem;
182 Standard_Boolean successAdd = Standard_False;
184 // find the MeshNode corresponding to idnode1
185 if (AddNode(idnode1)) {
186 // find the MeshNode corresponding to idnode2
187 if (AddNode(idnode2)) {
188 elem = CreateEdge(ID,idnode1,idnode2);
189 edge = FindEdge(elem);
194 successAdd = myElementIDFactory->BindID(ID,edge);
202 //=======================================================================
205 //=======================================================================
207 Standard_Integer SMDS_Mesh::AddFace(const Standard_Integer idnode1,
208 const Standard_Integer idnode2,
209 const Standard_Integer idnode3)
211 Standard_Integer ID = myElementIDFactory->GetFreeID();
213 if (AddFaceWithID(idnode1,idnode2,idnode3,ID))
220 //=======================================================================
223 //=======================================================================
225 Standard_Boolean SMDS_Mesh::AddFaceWithID(const Standard_Integer idnode1,
226 const Standard_Integer idnode2,
227 const Standard_Integer idnode3,
228 const Standard_Integer ID)
230 Handle(SMDS_MeshElement) face,elem;
231 Standard_Boolean successAdd = Standard_False;
233 // find the MeshNode corresponding to idnode1
234 if (AddNode(idnode1)) {
235 // find the MeshNode corresponding to idnode2
236 if (AddNode(idnode2)) {
237 // find the MeshNode corresponding to idnode3
238 if (AddNode(idnode3)) {
239 elem = CreateFace(ID,idnode1,idnode2,idnode3);
240 face = FindFace(elem);
245 successAdd = myElementIDFactory->BindID(ID,face);
255 //=======================================================================
258 //=======================================================================
260 Standard_Integer SMDS_Mesh::AddFace(const Standard_Integer idnode1,
261 const Standard_Integer idnode2,
262 const Standard_Integer idnode3,
263 const Standard_Integer idnode4)
265 Standard_Integer ID = myElementIDFactory->GetFreeID();
267 if (AddFaceWithID(idnode1,idnode2,idnode3,idnode4,ID))
275 //=======================================================================
278 //=======================================================================
280 Standard_Boolean SMDS_Mesh::AddFaceWithID(const Standard_Integer idnode1,
281 const Standard_Integer idnode2,
282 const Standard_Integer idnode3,
283 const Standard_Integer idnode4,
284 const Standard_Integer ID)
286 Handle(SMDS_MeshElement) face,elem;
287 Standard_Boolean successAdd = Standard_False;
289 // find the MeshNode corresponding to idnode1
290 if (AddNode(idnode1)) {
291 // find the MeshNode corresponding to idnode2
292 if (AddNode(idnode2)) {
293 // find the MeshNode corresponding to idnode3
294 if (AddNode(idnode3)) {
295 // find the MeshNode corresponding to idnode4
296 if (AddNode(idnode4)) {
297 elem = CreateFace(ID,idnode1,idnode2,idnode3,idnode4);
298 face = FindFace(elem);
303 successAdd = myElementIDFactory->BindID(ID,face);
315 //=======================================================================
316 //function : AddVolume
317 //purpose : Tetrahedra
318 //=======================================================================
320 Standard_Integer SMDS_Mesh::AddVolume(const Standard_Integer idnode1,
321 const Standard_Integer idnode2,
322 const Standard_Integer idnode3,
323 const Standard_Integer idnode4)
325 Standard_Integer ID = myElementIDFactory->GetFreeID();
327 if (AddVolumeWithID(idnode1,idnode2,idnode3,idnode4,ID))
334 //=======================================================================
335 //function : AddVolume
336 //purpose : Tetrahedra
337 //=======================================================================
339 Standard_Boolean SMDS_Mesh::AddVolumeWithID(const Standard_Integer idnode1,
340 const Standard_Integer idnode2,
341 const Standard_Integer idnode3,
342 const Standard_Integer idnode4,
343 const Standard_Integer ID)
345 Handle(SMDS_MeshElement) volume,elem;
346 Standard_Boolean successAdd = Standard_False;
348 // find the MeshNode corresponding to idnode1
349 if (AddNode(idnode1)) {
350 // find the MeshNode corresponding to idnode2
351 if (AddNode(idnode2)) {
352 // find the MeshNode corresponding to idnode3
353 if (AddNode(idnode3)) {
354 // find the MeshNode corresponding to idnode4
355 if (AddNode(idnode4)) {
356 elem = CreateVolume(ID,idnode1,idnode2,idnode3,idnode4);
357 volume = FindVolume(elem);
358 if (volume.IsNull()) {
360 myVolumes.Add(volume);
362 successAdd = myElementIDFactory->BindID(ID,volume);
372 //=======================================================================
373 //function : AddVolume
375 //=======================================================================
377 Standard_Integer SMDS_Mesh::AddVolume(const Standard_Integer idnode1,
378 const Standard_Integer idnode2,
379 const Standard_Integer idnode3,
380 const Standard_Integer idnode4,
381 const Standard_Integer idnode5)
383 Standard_Integer ID = myElementIDFactory->GetFreeID();
385 if (AddVolumeWithID(idnode1,idnode2,idnode3,idnode4,idnode5,ID))
392 //=======================================================================
393 //function : AddVolume
395 //=======================================================================
397 Standard_Boolean SMDS_Mesh::AddVolumeWithID(const Standard_Integer idnode1,
398 const Standard_Integer idnode2,
399 const Standard_Integer idnode3,
400 const Standard_Integer idnode4,
401 const Standard_Integer idnode5,
402 const Standard_Integer ID)
404 Handle(SMDS_MeshElement) volume,elem;
405 Standard_Boolean successAdd = Standard_False;
407 // find the MeshNode corresponding to idnode1
408 if (AddNode(idnode1)) {
409 // find the MeshNode corresponding to idnode2
410 if (AddNode(idnode2)) {
411 // find the MeshNode corresponding to idnode3
412 if (AddNode(idnode3)) {
413 // find the MeshNode corresponding to idnode4
414 if (AddNode(idnode4)) {
415 // find the MeshNode corresponding to idnode5
416 if (AddNode(idnode5)) {
417 elem = CreateVolume(ID,idnode1,idnode2,idnode3,idnode4,idnode5);
418 volume = FindVolume(elem);
419 if (volume.IsNull()) {
421 myVolumes.Add(volume);
423 successAdd = myElementIDFactory->BindID(ID,volume);
434 //=======================================================================
435 //function : AddVolume
437 //=======================================================================
439 Standard_Integer SMDS_Mesh::AddVolume(const Standard_Integer idnode1,
440 const Standard_Integer idnode2,
441 const Standard_Integer idnode3,
442 const Standard_Integer idnode4,
443 const Standard_Integer idnode5,
444 const Standard_Integer idnode6)
446 Standard_Integer ID = myElementIDFactory->GetFreeID();
448 if (AddVolumeWithID(idnode1,idnode2,idnode3,idnode4,
456 //=======================================================================
457 //function : AddVolume
459 //=======================================================================
461 Standard_Boolean SMDS_Mesh::AddVolumeWithID(const Standard_Integer idnode1,
462 const Standard_Integer idnode2,
463 const Standard_Integer idnode3,
464 const Standard_Integer idnode4,
465 const Standard_Integer idnode5,
466 const Standard_Integer idnode6,
467 const Standard_Integer ID)
469 Handle(SMDS_MeshElement) volume,elem;
470 Standard_Boolean successAdd = Standard_False;
472 // find the MeshNode corresponding to idnode1
473 if (AddNode(idnode1)) {
474 // find the MeshNode corresponding to idnode2
475 if (AddNode(idnode2)) {
476 // find the MeshNode corresponding to idnode3
477 if (AddNode(idnode3)) {
478 // find the MeshNode corresponding to idnode4
479 if (AddNode(idnode4)) {
480 // find the MeshNode corresponding to idnode5
481 if (AddNode(idnode5)) {
482 // find the MeshNode corresponding to idnode6
483 if (AddNode(idnode6)) {
484 elem = CreateVolume(ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
485 volume = FindVolume(elem);
486 if (volume.IsNull()) {
488 myVolumes.Add(volume);
490 successAdd = myElementIDFactory->BindID(ID,volume);
502 //=======================================================================
503 //function : AddVolume
504 //purpose : Hexahedra
505 //=======================================================================
507 Standard_Integer SMDS_Mesh::AddVolume(const Standard_Integer idnode1,
508 const Standard_Integer idnode2,
509 const Standard_Integer idnode3,
510 const Standard_Integer idnode4,
511 const Standard_Integer idnode5,
512 const Standard_Integer idnode6,
513 const Standard_Integer idnode7,
514 const Standard_Integer idnode8)
516 Standard_Integer ID = myElementIDFactory->GetFreeID();
518 if (AddVolumeWithID(idnode1,idnode2,idnode3,idnode4,
519 idnode5,idnode6,idnode7,idnode8,ID))
526 //=======================================================================
527 //function : AddVolume
528 //purpose : Hexahedra
529 //=======================================================================
531 Standard_Boolean SMDS_Mesh::AddVolumeWithID(const Standard_Integer idnode1,
532 const Standard_Integer idnode2,
533 const Standard_Integer idnode3,
534 const Standard_Integer idnode4,
535 const Standard_Integer idnode5,
536 const Standard_Integer idnode6,
537 const Standard_Integer idnode7,
538 const Standard_Integer idnode8,
539 const Standard_Integer ID)
541 Handle(SMDS_MeshElement) volume,elem;
542 Standard_Boolean successAdd = Standard_False;
544 // find the MeshNode corresponding to idnode1
545 if (AddNode(idnode1)) {
546 // find the MeshNode corresponding to idnode2
547 if (AddNode(idnode2)) {
548 // find the MeshNode corresponding to idnode3
549 if (AddNode(idnode3)) {
550 // find the MeshNode corresponding to idnode4
551 if (AddNode(idnode4)) {
552 // find the MeshNode corresponding to idnode5
553 if (AddNode(idnode5)) {
554 // find the MeshNode corresponding to idnode6
555 if (AddNode(idnode6)) {
556 // find the MeshNode corresponding to idnode7
557 if (AddNode(idnode7)) {
558 // find the MeshNode corresponding to idnode8
559 if (AddNode(idnode8)) {
560 elem = CreateVolume(ID,idnode1,idnode2,idnode3,idnode4,idnode5,
561 idnode6,idnode7,idnode8);
562 volume = FindVolume(elem);
563 if (volume.IsNull()) {
565 myVolumes.Add(volume);
567 successAdd = myElementIDFactory->BindID(ID,volume);
582 //=======================================================================
584 //purpose : returns the MeshNode corresponding to the ID
585 //=======================================================================
587 Handle(SMDS_MeshElement) SMDS_Mesh::GetNode(const Standard_Integer idnode) const
590 Handle(SMDS_MeshElement) node;
592 Handle(SMDS_MeshElement) elem = FindNode(idnode);
593 if (!elem.IsNull()) { // found one correspondance
596 if (!myParent.IsNull())
597 node = myParent->GetNode(idnode);
603 //=======================================================================
604 //function : FindNode
606 //=======================================================================
608 Handle(SMDS_MeshElement) SMDS_Mesh::FindNode(const Standard_Integer ID) const
610 Handle(SMDS_MeshElement) elem;
611 if (myNodes.ContainsID(ID))
612 elem = myNodes.FindID(ID);
616 //=======================================================================
617 //function : FindNode
619 //=======================================================================
621 Handle(SMDS_MeshElement) SMDS_Mesh::FindNode(const Handle(SMDS_MeshElement)& node) const
623 Handle(SMDS_MeshElement) elem;
624 if (myNodes.Contains(node))
625 elem = myNodes.Find(node);
630 //=======================================================================
631 //function : CreateEdge
633 //=======================================================================
635 Handle(SMDS_MeshElement) SMDS_Mesh::CreateEdge(const Standard_Integer ID,
636 const Standard_Integer idnode1,
637 const Standard_Integer idnode2) const
639 Handle(SMDS_MeshEdge) edge = new SMDS_MeshEdge(ID,idnode1,idnode2);
644 //=======================================================================
645 //function : CreateFace
647 //=======================================================================
649 Handle(SMDS_MeshElement) SMDS_Mesh::CreateFace(const Standard_Integer ID,
650 const Standard_Integer idnode1,
651 const Standard_Integer idnode2,
652 const Standard_Integer idnode3) const
654 Handle(SMDS_MeshFace) face = new SMDS_MeshTriangle(ID,idnode1,idnode2,idnode3);
659 //=======================================================================
660 //function : CreateFace
662 //=======================================================================
664 Handle(SMDS_MeshElement) SMDS_Mesh::CreateFace(const Standard_Integer ID,
665 const Standard_Integer idnode1,
666 const Standard_Integer idnode2,
667 const Standard_Integer idnode3,
668 const Standard_Integer idnode4) const
670 Handle(SMDS_MeshFace) face = new SMDS_MeshQuadrangle(ID,idnode1,idnode2,idnode3,idnode4);
674 //=======================================================================
675 //function : CreateVolume
677 //=======================================================================
679 Handle(SMDS_MeshElement) SMDS_Mesh::CreateVolume(const Standard_Integer ID,
680 const Standard_Integer idnode1,
681 const Standard_Integer idnode2,
682 const Standard_Integer idnode3,
683 const Standard_Integer idnode4) const
685 Handle(SMDS_MeshVolume) volume = new SMDS_MeshTetrahedron(ID,idnode1,idnode2,idnode3,idnode4);
689 //=======================================================================
690 //function : CreateVolume
692 //=======================================================================
694 Handle(SMDS_MeshElement) SMDS_Mesh::CreateVolume(const Standard_Integer ID,
695 const Standard_Integer idnode1,
696 const Standard_Integer idnode2,
697 const Standard_Integer idnode3,
698 const Standard_Integer idnode4,
699 const Standard_Integer idnode5) const
701 Handle(SMDS_MeshVolume) volume = new SMDS_MeshPyramid(ID,idnode1,idnode2,idnode3,idnode4,idnode5);
705 //=======================================================================
706 //function : CreateVolume
708 //=======================================================================
710 Handle(SMDS_MeshElement) SMDS_Mesh::CreateVolume(const Standard_Integer ID,
711 const Standard_Integer idnode1,
712 const Standard_Integer idnode2,
713 const Standard_Integer idnode3,
714 const Standard_Integer idnode4,
715 const Standard_Integer idnode5,
716 const Standard_Integer idnode6) const
718 Handle(SMDS_MeshVolume) volume = new SMDS_MeshPrism(ID,idnode1,idnode2,idnode3,idnode4,idnode5,idnode6);
722 //=======================================================================
723 //function : CreateVolume
725 //=======================================================================
727 Handle(SMDS_MeshElement) SMDS_Mesh::CreateVolume(const Standard_Integer ID,
728 const Standard_Integer idnode1,
729 const Standard_Integer idnode2,
730 const Standard_Integer idnode3,
731 const Standard_Integer idnode4,
732 const Standard_Integer idnode5,
733 const Standard_Integer idnode6,
734 const Standard_Integer idnode7,
735 const Standard_Integer idnode8) const
737 Handle(SMDS_MeshVolume) volume = new SMDS_MeshHexahedron(ID,idnode1,idnode2,idnode3,idnode4,
738 idnode5,idnode6,idnode7,idnode8);
742 //=======================================================================
743 //function : Contains
745 //=======================================================================
747 Standard_Boolean SMDS_Mesh::Contains(const Handle(SMDS_MeshElement)& elem) const
749 Standard_Boolean isinmesh = Standard_False;
750 if (myNodes.Contains(elem))
751 isinmesh = Standard_True;
752 else if (myEdges.Contains(elem))
753 isinmesh = Standard_True;
754 else if (myFaces.Contains(elem))
755 isinmesh = Standard_True;
756 else if (myVolumes.Contains(elem))
757 isinmesh = Standard_True;
762 //=======================================================================
763 //function : FindEdge
765 //=======================================================================
767 Handle(SMDS_MeshElement) SMDS_Mesh::FindEdge(const Handle(SMDS_MeshElement)& edge) const
769 Handle(SMDS_MeshElement) elem;
770 if (myEdges.Contains(edge))
771 elem = myEdges.Find(edge);
776 //=======================================================================
777 //function : FindFace
779 //=======================================================================
781 Handle(SMDS_MeshElement) SMDS_Mesh::FindFace(const Handle(SMDS_MeshElement)& face) const
783 Handle(SMDS_MeshElement) elem;
784 if (myFaces.Contains(face))
785 elem = myFaces.Find(face);
791 //=======================================================================
792 //function : FindVolume
794 //=======================================================================
796 Handle(SMDS_MeshElement) SMDS_Mesh::FindVolume(const Handle(SMDS_MeshElement)& volume) const
798 Handle(SMDS_MeshElement) elem;
799 if (myVolumes.Contains(volume))
800 elem = myVolumes.Find(volume);
806 //=======================================================================
807 //function : FreeNode
809 //=======================================================================
811 void SMDS_Mesh::FreeNode(const Handle(SMDS_MeshElement)& node)
813 myNodes.Remove(node);
815 SMDS_ListIteratorOfListOfMesh itmsh(myChildren);
816 for (;itmsh.More(); itmsh.Next()) {
817 const Handle(SMDS_Mesh)& submesh = itmsh.Value();
818 submesh->RemoveNode(node->GetID());
824 //=======================================================================
825 //function : RemoveNode
827 //=======================================================================
829 void SMDS_Mesh::RemoveNode(const Standard_Integer IDnode)
831 // find the MeshNode corresponding to IDnode
832 Handle(SMDS_MeshElement) node = FindNode(IDnode);
833 if (RemoveNode(node)) {
834 if (myParent.IsNull()) { // if no parent we can release the ID
835 myNodeIDFactory->ReleaseID(IDnode);
841 //=======================================================================
842 //function : RemoveNode
844 //=======================================================================
846 Standard_Boolean SMDS_Mesh::RemoveNode(const Handle(SMDS_MeshElement)& node)
848 Standard_Boolean successRemove = Standard_False;
850 if (!node.IsNull()) {
851 if (myHasInverse && myNodes.Contains(node)) {
852 SMDS_MapOfMeshOrientedElement map(1);
853 BuildMapNodeAncestors(node,map);
854 RemoveAncestors(node,map);
858 successRemove = Standard_True;
861 return successRemove;
864 //=======================================================================
865 //function : RemoveEdge
867 //=======================================================================
869 void SMDS_Mesh::RemoveEdge(const Standard_Integer idnode1, const Standard_Integer idnode2)
871 Handle(SMDS_MeshElement) edge = FindEdge(idnode1,idnode2);
875 //=======================================================================
876 //function : RemoveEdge
878 //=======================================================================
880 void SMDS_Mesh::RemoveEdge(const Handle(SMDS_MeshElement)& edge)
883 if (!edge.IsNull()) {
884 myEdges.Remove(edge);
886 myElementIDFactory->ReleaseID(edge->GetID());
891 //=======================================================================
892 //function : RemoveFace
894 //=======================================================================
896 void SMDS_Mesh::RemoveFace(const Standard_Integer idnode1,
897 const Standard_Integer idnode2,
898 const Standard_Integer idnode3)
900 Handle(SMDS_MeshElement) face = FindFace(idnode1,idnode2,idnode3);
904 //=======================================================================
905 //function : RemoveFace
907 //=======================================================================
909 void SMDS_Mesh::RemoveFace(const Standard_Integer idnode1,
910 const Standard_Integer idnode2,
911 const Standard_Integer idnode3,
912 const Standard_Integer idnode4)
914 Handle(SMDS_MeshElement) face = FindFace(idnode1,idnode2,idnode3,idnode4);
919 //=======================================================================
920 //function : RemoveFace
922 //=======================================================================
924 void SMDS_Mesh::RemoveFace(const Handle(SMDS_MeshElement)& face)
926 if (!face.IsNull()) {
927 myFaces.Remove(face);
928 myElementIDFactory->ReleaseID(face->GetID());
932 //=======================================================================
933 //function : RemoveVolume
935 //=======================================================================
937 void SMDS_Mesh::RemoveVolume(const Handle(SMDS_MeshElement)& volume)
939 if (myVolumes.Contains(volume)) {
940 myVolumes.Remove(volume);
941 myElementIDFactory->ReleaseID(volume->GetID());
945 //=======================================================================
946 //function : RemoveElement
948 //=======================================================================
950 void SMDS_Mesh::RemoveElement(const Standard_Integer IDelem,const Standard_Boolean removenodes)
952 Handle(SMDS_MeshElement) elem = myElementIDFactory->MeshElement(IDelem);
953 RemoveElement(elem,removenodes);
959 //=======================================================================
960 //function : RemoveElement
962 //=======================================================================
964 void SMDS_Mesh::RemoveElement(const Handle(SMDS_MeshElement)& elem,const Standard_Boolean removenodes)
966 if ( elem->IsKind(STANDARD_TYPE(SMDS_MeshEdge)) ) {
968 } else if ( elem->IsKind(STANDARD_TYPE(SMDS_MeshNode))) {
971 } else if ( elem->IsKind(STANDARD_TYPE(SMDS_MeshFace))) {
973 } else if ( elem->IsKind(STANDARD_TYPE(SMDS_MeshVolume))) {
976 MESSAGE( "remove function : unknown type" );
980 Standard_Integer nbcnx = elem->NbNodes();
982 for (i=1; i <= nbcnx; ++i) {
983 RemoveInverseElement(GetNode(i,elem),elem);
988 for (i=1; i <= nbcnx; ++i) {
989 if (GetNode(i,elem)->InverseElements().IsEmpty())
990 FreeNode(GetNode(i,elem));
996 //=======================================================================
997 //function : RemoveFromParent
999 //=======================================================================
1001 Standard_Boolean SMDS_Mesh::RemoveFromParent()
1003 if (myParent.IsNull())
1004 return Standard_False;
1006 return (myParent->RemoveSubMesh(this));
1010 //=======================================================================
1011 //function : RemoveSubMesh
1013 //=======================================================================
1015 Standard_Boolean SMDS_Mesh::RemoveSubMesh(const Handle(SMDS_Mesh)& aMesh)
1017 Standard_Boolean found = Standard_False;
1019 SMDS_ListIteratorOfListOfMesh itmsh(myChildren);
1020 for (;itmsh.More() && !found; itmsh.Next()) {
1021 Handle(SMDS_Mesh) submesh;
1022 submesh = itmsh.Value();
1023 if (submesh == aMesh) {
1024 found = Standard_True;
1025 myChildren.Remove(itmsh);
1032 //=======================================================================
1033 //function : RemoveInverseElement
1035 //=======================================================================
1037 void SMDS_Mesh::RemoveInverseElement(const Handle(SMDS_MeshElement)& elem,
1038 const Handle(SMDS_MeshElement)& parent) const
1043 Handle(SMDS_MeshNode)& node = *((Handle(SMDS_MeshNode)*)&elem);
1044 node->RemoveInverseElement(parent);
1047 //=======================================================================
1048 //function : RemoveAncestors
1050 //=======================================================================
1052 void SMDS_Mesh::RemoveAncestors(const Handle(SMDS_MeshElement)& elem,
1053 const SMDS_MapOfMeshOrientedElement& map)
1059 SMDS_MapIteratorOfExtendedOrientedMap itAnc(map);
1061 for (;itAnc.More();itAnc.Next()) {
1062 const Handle(SMDS_MeshElement)& ME = itAnc.Key();
1063 Standard_Integer nbcnx = ME->NbNodes();
1065 for (Standard_Integer i=1; i <= nbcnx; ++i) {
1066 RemoveInverseElement(GetNode(i,ME),ME);
1070 SMDS_MapIteratorOfExtendedOrientedMap itAnc2(map);
1072 for (;itAnc2.More();itAnc2.Next()) {
1073 const Handle(SMDS_MeshElement)& ME = itAnc2.Key();
1078 //=======================================================================
1079 //function : BuildMapNodeAncestors
1081 //=======================================================================
1083 void SMDS_Mesh::BuildMapNodeAncestors(const Handle(SMDS_MeshElement)& ME,
1084 SMDS_MapOfMeshOrientedElement& map) const
1090 Standard_Integer nbcnx = ME->NbNodes();
1092 for (Standard_Integer i=1; i <= nbcnx; ++i) {
1093 const SMDS_ListOfMeshElement& lstInvElements = GetNode(i,ME)->InverseElements();
1095 SMDS_ListIteratorOfListOfMeshElement it(lstInvElements);
1096 for (;it.More();it.Next()) {
1097 const Handle(SMDS_MeshElement)& meParent = it.Value();
1098 if (Contains(meParent))
1107 //=======================================================================
1108 //function : BuildMapEdgeAncestors
1110 //=======================================================================
1112 void SMDS_Mesh::BuildMapEdgeAncestors(const Handle(SMDS_MeshElement)& ME,
1113 SMDS_MapOfMeshOrientedElement& map) const
1119 Standard_Integer nbcnx = ME->NbNodes();
1121 for (Standard_Integer i=1; i <= nbcnx; ++i) {
1122 const SMDS_ListOfMeshElement& lstInvElements = GetNode(i,ME)->InverseElements();
1124 SMDS_ListIteratorOfListOfMeshElement it(lstInvElements);
1125 for (;it.More();it.Next()) {
1126 const Handle(SMDS_MeshElement)& meParent = it.Value();
1127 if ( !meParent->IsKind(STANDARD_TYPE(SMDS_MeshEdge)) && Contains(meParent))
1136 //=======================================================================
1137 //function : BuildMapFaceAncestors
1139 //=======================================================================
1141 void SMDS_Mesh::BuildMapFaceAncestors(const Handle(SMDS_MeshElement)& ME,
1142 SMDS_MapOfMeshOrientedElement& map) const
1148 Standard_Integer nbcnx = ME->NbNodes();
1150 for (Standard_Integer i=1; i <= nbcnx; ++i) {
1151 const SMDS_ListOfMeshElement& lstInvElements = GetNode(i,ME)->InverseElements();
1153 SMDS_ListIteratorOfListOfMeshElement it(lstInvElements);
1154 for (;it.More();it.Next()) {
1155 const Handle(SMDS_MeshElement)& meParent = it.Value();
1156 if ( !meParent->IsKind(STANDARD_TYPE(SMDS_MeshEdge))
1157 && ( !meParent->IsKind(STANDARD_TYPE(SMDS_MeshFace))) && Contains(meParent) )
1166 //=======================================================================
1167 //function : FindEdge
1169 //=======================================================================
1171 Handle(SMDS_MeshElement) SMDS_Mesh::FindEdge(const Standard_Integer idnode1,
1172 const Standard_Integer idnode2 ) const
1174 Handle(SMDS_MeshEdge) edge = new SMDS_MeshEdge(0,idnode1,idnode2);
1175 return FindEdge(edge);
1178 //=======================================================================
1179 //function : FindFace
1181 //=======================================================================
1183 Handle(SMDS_MeshElement) SMDS_Mesh::FindFace(const Standard_Integer idnode1,
1184 const Standard_Integer idnode2,
1185 const Standard_Integer idnode3 ) const
1187 Handle(SMDS_MeshFace) face = new SMDS_MeshTriangle(0,idnode1,idnode2,idnode3);
1188 return FindFace(face);
1191 //=======================================================================
1192 //function : FindFace
1194 //=======================================================================
1196 Handle(SMDS_MeshElement) SMDS_Mesh::FindFace(const Standard_Integer idnode1,
1197 const Standard_Integer idnode2,
1198 const Standard_Integer idnode3,
1199 const Standard_Integer idnode4 ) const
1201 Handle(SMDS_MeshFace) face = new SMDS_MeshQuadrangle(0,idnode1,idnode2,idnode3,idnode4);
1202 return FindFace(face);
1205 //=======================================================================
1206 //function : FindElement
1208 //=======================================================================
1210 Handle(SMDS_MeshElement) SMDS_Mesh::FindElement(const Standard_Integer IDelem) const
1212 return myElementIDFactory->MeshElement(IDelem);
1215 //=======================================================================
1216 //function : GetNode
1218 //=======================================================================
1220 Handle(SMDS_MeshNode) SMDS_Mesh::GetNode(const Standard_Integer rank,
1221 const Handle(SMDS_MeshElement)& ME) const
1224 const Standard_Integer idnode = ME->GetConnection(rank); // take care, no control of bounds
1226 Handle(SMDS_MeshElement) elem = FindNode(idnode);
1227 Handle(SMDS_MeshNode)& node = *((Handle(SMDS_MeshNode)*)&elem);
1233 //=======================================================================
1234 //function : DumpNodes
1236 //=======================================================================
1238 void SMDS_Mesh::DumpNodes() const
1240 MESSAGE( "dump nodes of mesh : " );
1242 SMDS_MapIteratorOfExtendedOrientedMap itnode(myNodes);
1244 for (;itnode.More();itnode.Next()) {
1245 const Handle(SMDS_MeshElement)& node = itnode.Key();
1254 //=======================================================================
1255 //function : DumpEdges
1257 //=======================================================================
1259 void SMDS_Mesh::DumpEdges() const
1261 MESSAGE( "dump edges of mesh : " );
1263 SMDS_MapIteratorOfExtendedOrientedMap itedge(myEdges);
1265 for (;itedge.More();itedge.Next()) {
1266 const Handle(SMDS_MeshElement)& edge = itedge.Key();
1273 //=======================================================================
1274 //function : DumpFaces
1276 //=======================================================================
1278 void SMDS_Mesh::DumpFaces() const
1280 MESSAGE( "dump faces of mesh : " );
1282 SMDS_MapIteratorOfExtendedOrientedMap itface(myFaces);
1284 for (;itface.More();itface.Next()) {
1285 const Handle(SMDS_MeshElement)& face = itface.Key();
1291 //=======================================================================
1292 //function : DumpVolumes
1294 //=======================================================================
1296 void SMDS_Mesh::DumpVolumes() const
1298 MESSAGE( "dump volumes of mesh : " );
1300 SMDS_MapIteratorOfExtendedOrientedMap itvol(myVolumes);
1302 for (;itvol.More();itvol.Next()) {
1303 const Handle(SMDS_MeshElement)& volume = itvol.Key();
1310 //=======================================================================
1311 //function : DebugStats
1313 //=======================================================================
1315 void SMDS_Mesh::DebugStats() const
1317 //VRV: T2.4 impossible to use Logger server
1318 MESSAGE( "Debug stats of mesh : " );
1320 MESSAGE( "===== NODES =====" );
1321 myNodes.Statistics(cout);
1323 MESSAGE( "===== EDGES =====" );
1324 myEdges.Statistics(cout);
1326 MESSAGE( "===== FACES =====" );
1327 myFaces.Statistics(cout);
1329 MESSAGE( "===== VOLUMES =====" );
1330 myVolumes.Statistics(cout);
1331 //VRV: T2.4 impossible to use Logger server
1333 MESSAGE( "End Debug stats of mesh " );
1336 SMDS_MapIteratorOfExtendedOrientedMap itnode(myNodes);
1337 Standard_Integer sizeofnodes = 0;
1338 Standard_Integer sizeoffaces = 0;
1341 for (;itnode.More();itnode.Next()) {
1342 const Handle(SMDS_MeshElement)& node = itnode.Key();
1344 Standard_Transient *p = node->This();
1345 sizeofnodes += sizeof( *((SMDS_MeshNode *)p) );
1347 SMDS_ListIteratorOfListOfMeshElement it(node->InverseElements());
1348 for (;it.More();it.Next()) {
1349 const Handle(SMDS_MeshElement)& me = it.Value();
1350 sizeofnodes += sizeof(me);
1355 SMDS_MapIteratorOfExtendedOrientedMap itface(myFaces);
1357 for (;itface.More();itface.Next()) {
1358 const Handle(SMDS_MeshElement)& face = itface.Key();
1360 Standard_Transient *p = face->This();
1361 sizeoffaces += sizeof( *((SMDS_MeshFace *)p) );
1364 MESSAGE( "total size of node elements = " << sizeofnodes );;
1365 MESSAGE( "total size of face elements = " << sizeoffaces );;
1371 //=======================================================================
1372 //function : RebuildAllInverseConnections
1374 //=======================================================================
1376 void SMDS_Mesh::RebuildAllInverseConnections()
1378 if (!myParent.IsNull())
1379 myParent->RebuildAllInverseConnections();
1382 // Clear all inverseconnections from nodes
1383 SMDS_MapIteratorOfExtendedOrientedMap itnode(myNodes);
1385 for (;itnode.More();itnode.Next()) {
1386 const Handle(SMDS_MeshElement)& elem = itnode.Key();
1387 elem->ClearInverseElements();
1391 RebuildInverseConnections();
1393 SMDS_ListIteratorOfListOfMesh itmsh(myChildren);
1394 for (;itmsh.More(); itmsh.Next()) {
1395 Handle(SMDS_Mesh) submesh;
1396 submesh = itmsh.Value();
1398 submesh->RebuildInverseConnections();
1404 //=======================================================================
1405 //function : RebuildInverseConnections
1407 //=======================================================================
1409 void SMDS_Mesh::RebuildInverseConnections()
1411 // rebuld inverse connections to volumes
1412 SMDS_MapIteratorOfExtendedOrientedMap itvol(myVolumes);
1414 for (;itvol.More();itvol.Next()) {
1415 const Handle(SMDS_MeshElement)& vol = itvol.Key();
1417 Standard_Integer nbcnx = vol->NbNodes();
1418 for (Standard_Integer inode=1; inode<=nbcnx; ++inode) {
1419 Standard_Integer idnode = vol->GetConnection(inode);
1420 Handle(SMDS_MeshElement) node = FindNode(idnode);
1422 node->AddInverseElement(vol);
1427 // rebuld inverse connections to faces
1428 SMDS_MapIteratorOfExtendedOrientedMap itface(myFaces);
1430 for (;itface.More();itface.Next()) {
1431 const Handle(SMDS_MeshElement)& face = itface.Key();
1433 Standard_Integer nbcnx = face->NbNodes();
1434 for (Standard_Integer inode=1; inode<=nbcnx; ++inode) {
1435 Standard_Integer idnode = face->GetConnection(inode);
1436 Handle(SMDS_MeshElement) node = FindNode(idnode);
1438 node->AddInverseElement(face);
1443 // rebuld inverse connections to edges
1444 SMDS_MapIteratorOfExtendedOrientedMap itedge(myEdges);
1446 for (;itedge.More();itedge.Next()) {
1447 const Handle(SMDS_MeshElement)& edge = itedge.Key();
1449 Standard_Integer nbcnx = edge->NbNodes();
1450 for (Standard_Integer inode=1; inode<=nbcnx; ++inode) {
1451 Standard_Integer idnode = edge->GetConnection(inode);
1452 Handle(SMDS_MeshElement) node = FindNode(idnode);
1454 node->AddInverseElement(edge);
1459 myHasInverse = Standard_True;
1463 //=======================================================================
1464 //function : SubMeshIterator
1465 //purpose : returns the ith SubMesh
1466 //=======================================================================
1468 void SMDS_Mesh::SubMeshIterator(SMDS_ListIteratorOfListOfMesh& itmsh) const
1470 itmsh.Initialize(myChildren);