1 // Copyright (C) 2007-2013 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 #include "MEDMEM_Mesh.hxx"
25 using namespace MEDMEM ;
26 using namespace MED_EN ;
28 int main (int argc, char ** argv)
30 // const string MedFile = "polyedres.med" ;
31 // const string MeshName = "Erreur orientation" ;
32 // const string MedFile = "polygones.med" ;
33 // const string MeshName = "Bord" ;
34 const string MedFile = "pointe.med" ;
35 const string MeshName = "maa1" ;
36 MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
38 cout << "Mesh name : " << myMesh.getName() << endl << endl ;
40 // we get all type for cell entity :
41 int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
42 cout << "Show Connectivity (Nodal) :" << endl ;
43 // this example use access with a specified medGeometryElement array
44 const medGeometryElement * Types = myMesh.getTypes(MED_CELL);
45 string * cellTypeNames = myMesh.getCellTypeNames(MED_CELL);
46 for (int i=0; i<NumberOfTypes; i++) {
47 cout << "For type " << cellTypeNames[i] << " : " << endl ;
48 medGeometryElement myType = Types[i] ;
49 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
50 int NomberOfNodesPerCell = Types[i]%100 ;
51 const int * Connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,myType);
52 for (int j=0; j<NumberOfElements; j++){
53 cout << "Element "<< j+1 <<" : " ;
54 for (int k=0; k<NomberOfNodesPerCell; k++)
55 cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
59 cout << "Show Reverse Nodal Connectivity :" << endl ;
60 // this example use global access with index array
61 int NumberOfNodes = myMesh.getNumberOfNodes() ;
62 const int * ReverseNodalConnectivity =
63 myMesh.getReverseConnectivity(MED_NODAL) ;
64 const int * ReverseNodalConnectivityIndex =
65 myMesh.getReverseConnectivityIndex(MED_NODAL) ;
66 for (int i=0; i<NumberOfNodes; i++) {
67 cout << "Node "<<i+1<<" : " ;
68 int IndexBegin = ReverseNodalConnectivityIndex[i] ;
69 int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
70 for (int j=IndexBegin; j<IndexEnd; j++)
71 // Index value begin at 1 so use j-1
72 cout << ReverseNodalConnectivity[j-1] << " " ;
76 cout << "Show Connectivity (Descending) :" << endl ;
77 // this example use global access with index array
78 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
79 const int * DescendingConnectivity =
80 myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
81 const int * DescendingConnectivityIndex =
82 myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
83 for (int i=0; i<NumberOfElements; i++) {
84 cout << "Element "<<i+1<<" : " ;
85 int IndexBegin = DescendingConnectivityIndex[i] ;
86 int IndexEnd = DescendingConnectivityIndex[i+1] ;
87 for (int j=IndexBegin; j<IndexEnd; j++)
88 // Index value begin at 1 so use j-1
89 cout << DescendingConnectivity[j-1] << " " ;
93 cout << "Show Reverse Descending Connectivity :" << endl ;
94 // this example use global access with Index array
95 const int * ReverseDescendingConnectivity =
96 myMesh.getReverseConnectivity(MED_DESCENDING) ;
97 const int * ReverseDescendingConnectivityIndex =
98 myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
100 int MeshDimension = myMesh.getMeshDimension() ;
101 int NumberOfConstituents = 0;
103 medEntityMesh ConstituentEntity ;
104 // test if we have face (3D) or edge (2D)
105 if (MeshDimension==3) {
106 Constituent = "Face" ;
107 ConstituentEntity = MED_FACE ;
109 if (MeshDimension==2) {
110 Constituent = "Edge" ;
111 ConstituentEntity = MED_EDGE ;
114 NumberOfConstituents =
115 myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
117 if (MeshDimension==1) {
118 MESSAGE_MED("ERROR : MeshDimension = 1 !");
119 MESSAGE_MED("We could not see Reverse Descending Connectivity.") ;
121 for (int i=0; i<NumberOfConstituents; i++) {
122 cout << Constituent << " " << i+1 << " : " ;
123 int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
124 int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
125 for (int j=IndexBegin;j<IndexEnd;j++)
126 // Index value begin at 1 so use j-1
127 cout << ReverseDescendingConnectivity[j-1] << " " ;
131 cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
132 // this example use global access with index array
133 const int * ConstituentConnectivity =
134 myMesh.getConnectivity(MED_NODAL,ConstituentEntity,MED_ALL_ELEMENTS);
135 const int * ConstituentConnectivityIndex =
136 myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
137 for (int i=0; i<NumberOfConstituents; i++) {
138 cout << Constituent << " " << i+1 << " : " ;
139 int IndexBegin = ConstituentConnectivityIndex[i] ;
140 int IndexEnd = ConstituentConnectivityIndex[i+1] ;
141 for (int j=IndexBegin; j<IndexEnd; j++)
142 // Index value begin at 1 so use j-1
143 cout << ConstituentConnectivity[j-1]<<" ";