1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include "MEDMEM_Mesh.hxx"
21 #include "MEDMEM_CellModel.hxx"
23 using namespace MEDMEM ;
24 using namespace MED_EN ;
26 int main (int argc, char ** argv) {
28 // const string MedFile = "polyedres.med" ;
29 // const string MeshName = "Erreur orientation" ;
30 // const string MedFile = "polygones.med" ;
31 // const string MeshName = "Bord" ;
32 const string MedFile = "pointe.med" ;
33 const string MeshName = "maa1" ;
34 MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
37 cout << "Mesh name : " << myMesh.getName() << endl << endl ;
39 // we get all type for cell entity :
40 int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
41 const CELLMODEL * Types = myMesh.getCellsTypes(MED_CELL) ;
43 cout << "Show Connectivity (Nodal) :" << endl ;
44 // this example use access with a specified medGeometryElement through
46 for (int i=0; i<NumberOfTypes; i++) {
47 cout << "For type " << Types[i].getName() << " : " << endl ;
48 medGeometryElement myType = Types[i].getType() ;
49 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
50 int NomberOfNodesPerCell = Types[i].getNumberOfNodes() ;
51 const int * Connectivity =
52 myMesh.getConnectivity(MED_FULL_INTERLACE,
56 for (int j=0; j<NumberOfElements; j++){
57 cout << "Element "<< j+1 <<" : " ;
58 for (int k=0; k<NomberOfNodesPerCell; k++)
59 cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
63 cout << "Show Reverse Nodal Connectivity :" << endl ;
64 // this example use global access with index array
65 int NumberOfNodes = myMesh.getNumberOfNodes() ;
66 const int * ReverseNodalConnectivity =
67 myMesh.getReverseConnectivity(MED_NODAL) ;
68 const int * ReverseNodalConnectivityIndex =
69 myMesh.getReverseConnectivityIndex(MED_NODAL) ;
70 for (int i=0; i<NumberOfNodes; i++) {
71 cout << "Node "<<i+1<<" : " ;
72 int IndexBegin = ReverseNodalConnectivityIndex[i] ;
73 int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
74 for (int j=IndexBegin; j<IndexEnd; j++)
75 // Index value begin at 1 so use j-1
76 cout << ReverseNodalConnectivity[j-1] << " " ;
80 cout << "Show Connectivity (Descending) :" << endl ;
81 // this example use global access with index array
82 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
83 const int * DescendingConnectivity =
84 myMesh.getConnectivity(MED_FULL_INTERLACE,
88 const int * DescendingConnectivityIndex =
89 myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
90 for (int i=0; i<NumberOfElements; i++) {
91 cout << "Element "<<i+1<<" : " ;
92 int IndexBegin = DescendingConnectivityIndex[i] ;
93 int IndexEnd = DescendingConnectivityIndex[i+1] ;
94 for (int j=IndexBegin; j<IndexEnd; j++)
95 // Index value begin at 1 so use j-1
96 cout << DescendingConnectivity[j-1] << " " ;
100 cout << "Show Reverse Descending Connectivity :" << endl ;
101 // this example use global access with Index array
102 const int * ReverseDescendingConnectivity =
103 myMesh.getReverseConnectivity(MED_DESCENDING) ;
104 const int * ReverseDescendingConnectivityIndex =
105 myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
107 int MeshDimension = myMesh.getMeshDimension() ;
108 int NumberOfConstituents = 0;
110 medEntityMesh ConstituentEntity ;
111 // test if we have face (3D) or edge (2D)
112 if (MeshDimension==3) {
113 Constituent = "Face" ;
114 ConstituentEntity = MED_FACE ;
116 if (MeshDimension==2) {
117 Constituent = "Edge" ;
118 ConstituentEntity = MED_EDGE ;
121 NumberOfConstituents =
122 myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
124 if (MeshDimension==1) {
125 MESSAGE("ERROR : MeshDimension = 1 !");
126 MESSAGE("We could not see Reverse Descending Connectivity.") ;
128 for (int i=0; i<NumberOfConstituents; i++) {
129 cout << Constituent << " " << i+1 << " : " ;
130 int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
131 int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
132 for (int j=IndexBegin;j<IndexEnd;j++)
133 // Index value begin at 1 so use j-1
134 cout << ReverseDescendingConnectivity[j-1] << " " ;
138 cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
139 // this example use global access with index array
140 const int * ConstituentConnectivity =
141 myMesh.getConnectivity(MED_FULL_INTERLACE,
145 const int * ConstituentConnectivityIndex =
146 myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
147 for (int i=0; i<NumberOfConstituents; i++) {
148 cout << Constituent << " " << i+1 << " : " ;
149 int IndexBegin = ConstituentConnectivityIndex[i] ;
150 int IndexEnd = ConstituentConnectivityIndex[i+1] ;
151 for (int j=IndexBegin; j<IndexEnd; j++)
152 // Index value begin at 1 so use j-1
153 cout << ConstituentConnectivity[j-1]<<" ";
157 int nbPolygons = myMesh.getNumberOfPolygons();
158 if ( nbPolygons > 0 )
160 cout << "Show Connectivity (Nodal) of POLYGONS:" << endl ;
161 const int* Connectivity = myMesh.getPolygonsConnectivity(MED_NODAL,MED_CELL);
162 const int* ConnectivityIndex = myMesh.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL);
163 for (int j=0; j<nbPolygons; j++){
164 cout << "Polygon "<< j+1 <<" : " ;
165 int IndexBegin = ConnectivityIndex[j];
166 int IndexEnd = ConnectivityIndex[j+1];
167 for (int k=IndexBegin; k<IndexEnd; k++)
168 cout << Connectivity[k-1]<<" ";
173 int nbPolyhedrons = myMesh.getNumberOfPolyhedron();
174 if ( nbPolyhedrons > 0 )
176 cout << "Show Connectivity (Nodal) of POLYHEDRONS:" << endl ;
177 const int* Connectivity = myMesh.getPolyhedronConnectivity(MED_NODAL);
178 const int* FaceIndex = myMesh.getPolyhedronFacesIndex();
179 const int* Index = myMesh.getPolyhedronIndex(MED_NODAL);
180 for (int j=0; j<nbPolyhedrons; j++){
181 cout << "Polyhedron "<< j+1 <<" : " << endl;
182 int FaceIndexBegin = Index[j];
183 int FaceIndexEnd = Index[j+1];
184 for (int k=FaceIndexBegin; k<FaceIndexEnd; k++) {
185 cout << " Face " << k - FaceIndexBegin + 1 << " : ";
186 int IndexBegin = FaceIndex[k-1];
187 int IndexEnd = FaceIndex[k];
188 for (int i=IndexBegin; i<IndexEnd; i++)
189 cout << Connectivity[i-1]<<" ";