Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MULTIPR / MULTIPR_Profil.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Partitioning/decimation module for the SALOME v3.2 platform
20 //
21 /**
22  * \file    MULTIPR_Profil.hxx
23  *
24  * \brief   Class Profil used to managed MED profil.
25  *          Profil is just a list of indices related to elements (NODES, CELLS).
26  *          !!! currently not used !!!
27  *
28  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
29  * 
30  * \date    01/2007
31  */
32
33 #ifndef MULTIPR_PROFIL_HXX
34 #define MULTIPR_PROFIL_HXX
35
36 //*****************************************************************************
37 // Includes section
38 //*****************************************************************************
39
40 extern "C"
41 {
42     #include "med.h"
43 }
44
45 #include <vector>
46 #include <set>
47 #include <iostream>
48
49 namespace multipr
50 {
51
52 enum eProfilBinding
53 {
54     Undef,
55     OnNodes,
56     OnElements
57 };
58
59 //*****************************************************************************
60 // Class Profil
61 //*****************************************************************************
62
63 class Profil
64 {
65 public:
66
67     /** 
68      * Builds an empty profil (default constructor).
69      */
70     Profil();
71     
72     /**
73      * Copy constructor.
74      * \param pProfil The profil to copy.
75      */
76     Profil(const Profil& pProfil);
77     
78     /**
79      * Destructor. Removes everything.
80      */
81     ~Profil();
82     
83     /**
84      * Resets this object in its state by default (empty). Cleans memory.
85      */
86     void reset();
87     
88     /**
89      * Creates a profil from its name (reset before).
90      * \param  pName name of the profil to be created.
91      * \throw  NullArgumentException if pName is NULL.
92      */
93     void create(const char* pName);
94     
95     //---------------------------------------------------------------------
96     // Basic accessors/mutators
97     //---------------------------------------------------------------------
98     
99     /**
100      * Returns the name of this profil.
101      * \return the name of this profil.
102      */
103     const char* getName() const;
104     
105     /**
106      * Get the complete set of elements of this profile.
107      * \return The set of elements.
108      */
109     std::set< med_int>& getSet() { return mTable; }
110     
111     /**
112      * Adds a new element to this profil.
113      * \param  pElt element to be added; must be >= 1.
114      */
115     void add(med_int pElt);
116     
117     /**
118      * Find the given element in the profile.
119      * \param pElt The index of the element.
120      * \return true if the element was found.
121      */
122     bool    find(med_int pElt);
123     
124     /**
125      * Assign a set of element to this profile.
126      * \param pElt The set of element to assign.
127      */
128     void    set(std::set< med_int>& pElt) { this->mTable = pElt; }
129     
130     /**
131      * Select the elements of pIn contained in this profile. The two parameters pIn 
132      * and pOut MUST be different.
133      * \param pIn Set of elements to filter.
134      * \param pOut The result.
135      * \throw IllegalStateException if pIn and pOut are not different.
136      */
137     void    filterSetOfElement(std::set<med_int>& pIn, std::set<med_int>& pOut);
138     
139     /**
140      * Extract a profil. The two parameters pIn 
141      * and pOut MUST be different.
142      * \param pIn Set of elements to extract.
143      * \param pOut The result.
144      * \throw IllegalStateException if pIn and pOut are not different.
145      */
146     void    extractSetOfElement(const std::set<med_int>& pIn, std::set<med_int>& pOut);
147     
148     /**
149      * Returns the association of the profile.
150      * \return OnNodes or OnElements or Undef.
151      */
152     eProfilBinding      getBinding() { return mBinding; }
153     
154     /**
155      * Return the index of the geometry (if any) associated with this profile.
156      * If this profile is on nodes it will return 0. Since the geometry index starts at
157      * 0 use getBinding to know if its on elements.
158      * \return the index of the geometry.
159      */
160     unsigned            getGeomIdx() { return mGeomIdx; }
161     
162     //---------------------------------------------------------------------
163     // I/O
164     //---------------------------------------------------------------------
165     
166     /**
167      * Reads a Profil from a MED file.
168      * \param  pMEDfile     any valid MED file opened for reading.
169      * \param  pIndexProfil index of the profil to be read; must be >= 1.
170      * \throw  IOException  if any i/o error occurs.
171      */
172     void readMED(med_idt pMEDfile, med_int pIndexProfil);
173
174     /**
175      * Try to find in the MED file if this profile is associated to the nodes
176      * or the elements. If the profile is associated with elements it will get the
177      * index of the geometry.
178      * \param pMEDfile any valid MED file opened for reading.
179      * \param pMeshName The name of the mesh.
180      * \throw IllegalStateException if the profile is empty.
181      */
182     void    readProfilBinding(med_idt pMEDfile, char* pMeshName);
183         
184     /**
185      * Writes this profil to a MED file.
186      * \param  pMEDfile    any valid MED file opened for writing.
187      * \throw  IOException if any i/o error occurs.
188      */
189     void writeMED(med_idt pMEDfile);
190     
191     /**
192      * Dumps any Profil to the given output stream.
193      * \param  pOs any output stream.
194      * \param  pP  any Profil.
195      * \return the output stream pOs.
196      */
197     friend std::ostream& operator<<(std::ostream& pOs, Profil& pP);
198     
199 private:
200     
201     char                mName[MED_TAILLE_NOM + 1];  /**< Name of the profil. */
202     std::set<med_int>   mTable;                     /**< Table of elements. */
203     eProfilBinding      mBinding;                   /**< Profil of nodes or elements. */
204     unsigned            mGeomIdx;                   /**< If this profile is on elements, the index of the geometry. */
205     
206 private:
207     
208     // do not allow copy
209     Profil& operator=(const Profil&);
210     
211     // do not allow operator ==
212     bool operator==(const Profil&); 
213     
214 }; // class Profil
215
216
217 } // namespace MULTIPR
218
219
220 #endif // MULTIPR_PROFIL_HXX
221
222 // EOF