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