Salome HOME
yfr : Merge with v1.2
[modules/smesh.git] / src / SMDS / SMDSControl_BoundaryFaces.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org or email : webmaster@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMDSControl_BoundaryFaces.cxx
24 //  Author : Jean-Michel BOULCOURT
25 //  Module : SMESH
26
27 using namespace std;
28 #include "SMDSControl_BoundaryFaces.ixx"
29 #include "SMDSControl.hxx"
30
31 #include "SMDS_MeshVolumesIterator.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_MeshFace.hxx"
34 #include "SMDS_MeshTriangle.hxx"
35 #include "SMDS_MeshQuadrangle.hxx"
36 #include "SMDS_MapIteratorOfExtendedMap.hxx"
37
38 //=======================================================================
39 //function : SMDSControl_BoundaryFaces
40 //purpose  : 
41 //=======================================================================
42
43 SMDSControl_BoundaryFaces::SMDSControl_BoundaryFaces(const Handle(SMDS_Mesh)& M)
44   :SMDSControl_MeshBoundary(M)
45 {
46 }
47
48 //=======================================================================
49 //function : Compute
50 //purpose  : 
51 //=======================================================================
52
53 void SMDSControl_BoundaryFaces::Compute()
54 {
55   myBoundaryMesh = myMesh->AddSubMesh();
56   SMDS_MeshVolumesIterator itvol(myMesh);
57   
58   Standard_Integer idnode[4]; // max number of nodes for a face
59   Standard_Integer nbnode;
60
61   for (;itvol.More();itvol.Next()) {
62     Handle(SMDS_MeshElement) ME = itvol.Value();
63
64
65     Standard_Integer nbfaces = ME->NbFaces();
66
67     for (Standard_Integer iface=1; iface<=nbfaces; ++iface) {
68
69       ME->GetFaceDefinedByNodes(iface,idnode,nbnode);
70       // Triangle
71       if (nbnode == 3) {
72         Handle(SMDS_MeshElement) face = new SMDS_MeshTriangle(0,idnode[0],idnode[1],idnode[2]);
73         if (!myBoundaryFaces.Add(face))
74           myBoundaryFaces.Remove(face);
75
76           
77       } else {
78         // Quadrangle
79           
80         Handle(SMDS_MeshElement) face = new SMDS_MeshQuadrangle(0,idnode[0],idnode[1],idnode[2],idnode[3]);
81         if (!myBoundaryFaces.Add(face))
82           myBoundaryFaces.Remove(face);
83           
84       }
85     } // end iface
86
87   } // end itvol
88
89   SMDS_MapIteratorOfExtendedMap itbound(myBoundaryFaces);
90
91   for (;itbound.More();itbound.Next()) {
92     const Handle(SMDS_MeshElement)& face = itbound.Key();
93     if (face->NbNodes() == 3)
94       myBoundaryMesh->AddFace(face->GetConnection(1),face->GetConnection(2),face->GetConnection(3));
95     else
96       myBoundaryMesh->AddFace(face->GetConnection(1),face->GetConnection(2),face->GetConnection(3),
97                               face->GetConnection(4));
98   }
99
100 }
101         
102