1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Partitioning/decimation module for the SALOME v3.2 platform
22 * \file MULTIPR_Elements.hxx
24 * \brief Class Elements = table of elements in a mesh.
25 * All elements share the same type (e.g. MED_MAILLE) and the same geometric description (e.g. TETRA10).
26 * Each element has a family and a table of connectivity.
27 * Optional: each element has a name and an id.
29 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
34 #ifndef MULTIPR_ELEMENTS_HXX
35 #define MULTIPR_ELEMENTS_HXX
37 //*****************************************************************************
39 //*****************************************************************************
54 //*****************************************************************************
56 //*****************************************************************************
61 //*****************************************************************************
63 //*****************************************************************************
70 * Builds an empty set of elements (default constructor).
75 * Builds an empty set of elements with of the defined geometry type.
76 * \param pGeomType The geometry type.
78 Elements(med_geometrie_element pGeomType);
82 * Destructor. Removes everything.
87 * Resets this object in its state by default (empty). Cleans memory.
91 //---------------------------------------------------------------------
92 // Basic accessors/mutators
93 //---------------------------------------------------------------------
96 * Returns true iff this object contains no elements (table of elements is empty).
97 * \return true iff this object contains no elements.
99 bool isEmpty() const { return (mNum == 0); }
102 * Returns true iff elements have a name.
103 * \return true iff elements have a name.
105 bool isNames() const { return (mNames != NULL); }
108 * Returns true iff elements have an identifier (= a number).
109 * \return true iff elements have an identifier (= a number).
111 bool isIdentifiers() const { return (mId != NULL); }
114 * Returns the number of elements.
115 * \return the number of elements.
117 int getNumberOfElements() const { return mNum; }
120 * Returns the type of primitives (e.g. MED_TETRA10).
121 * \return the type of primitives
123 med_geometrie_element getTypeOfPrimitives() const { return mGeom; }
126 * Returns the number of nodes that composed an element.
127 * \return the number of nodes that composed an element.
129 int getNumberOfNodesByElement() const { return mNumNodesByElt; }
132 * Returns the family associated with an element.
133 * \param pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1].
134 * \return the family associated with an element.
135 * \throw IndexOutOfBoundsException if pIndex is invalid.
137 med_int getFamilyIdentifier(med_int pIndex) const;
140 * Returns the connectivity of one element.
141 * \param pIndex must be in [0..NUMBER_OF_ELEMENTS-1].
142 * \return a pointer towards the table of connectivity of the element.
143 * \throw IndexOutOfBoundsException if pIndex is invalid.
145 const med_int* getConnectivity(int pIndex) const;
148 * Returns the coordinates of all the nodes of one element.
149 * \param pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1].
150 * \param pNodes table of nodes, used to retrieve coordinates.
151 * \param pCoo (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10).
152 * \param pFirst only get the pFirst coordinates.
153 * \throw IndexOutOfBoundsException if pIndex is invalid.
155 void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const;
157 //---------------------------------------------------------------------
159 //---------------------------------------------------------------------
162 * Constructor. Creates a subset of this set of elements from a set of indices.
163 * \param pSetIndices set of indices (start at 1).
164 * \return a restriction of this set of elements.
166 Elements* extractSubSet(const std::set<med_int>& pSetIndices) const;
169 * Create a subset of elements containing the given nodes.
170 * \param pSetOfNodes The set of nodes.
171 * \param pSubSetOfElements The subset of elements to fill.
172 * \throw IllegalStateException if pSetOfNodes and pSubSetOfElements are not different.
174 void extractSubSetFromNodes(const std::set<med_int>& pSetOfNodes, std::set<med_int>& pSubSetOfElements) const;
177 * Returns the set of indices (starting at 1) of all nodes used by this set of elements.
178 * \return the set of indices of all nodes used by this set of elements.
180 const std::set<med_int>& getSetOfNodes();
183 * Returns the set of families referenced by this set of elements.
184 * Each family is described by its identifier.
185 * \return Returns the set of families referenced by this set of elements.
187 std::set<med_int> getSetOfFamilies() const;
190 * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... *
191 * This method is intended to be used after extractSubSet().
197 * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... *
198 * This method is intended to be used after extractSubSet().
199 * This remap method allows to use the same set of nodes with several mesh type.
200 * \param pSetOfNodes The set of nodes index extracted from the original med file.
202 void remap(std::set<med_int>& pSetOfNodes);
206 * Builds a new set of elements by merging two set of elements (this and pElements) if possible.
207 * Merge is partial because Id and Names are not take into account.
208 * \param pElements any set of nodes to be merged with this.
210 * \return a new set of nodes.
211 * \throw IllegalStateException if the two sets of elements are incompatible.
213 Elements* mergePartial(Elements* pElements, int pOffset);
214 Elements* mergePartial(std::vector<Elements*> pElements, std::vector<int>& pOffsets);
216 //---------------------------------------------------------------------
218 //---------------------------------------------------------------------
221 * Reads a set of elements from a MED file.
222 * You must give: name of mesh, dimension of the mesh, type of entity and type of elements.
223 * \param pMEDfile any valid MED file opened for reading.
224 * \param pMeshName name of the mesh.
225 * \param pMeshDim dimension of the mesh.
226 * \param pEntity entity to be read (e.g. MED_MAILLE).
227 * \param pGeom type of primitves to be read (e.g. MED_TETRA10).
228 * \throw IOException if any i/o error occurs.
234 med_entite_maillage pEntity,
235 med_geometrie_element pGeom);
238 * Writes this set of elements to a MED file.
239 * WARNING: mesh must have been created and added to the MED file before.
240 * \param pMEDfile any valid MED file opened for writing.
241 * \param pMeshName name of the mesh.
242 * \param pMeshDim dimension of the mesh.
243 * \throw IOException if any i/o error occurs.
245 void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim);
248 * Sets the flag which control the stream operator <<.
249 * \param pFlag new flag value.
251 void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; }
254 * Dumps any Elements to the given output stream.
255 * \param pOs any output stream.
256 * \param pE any Elements.
257 * \return the output stream pOs.
259 friend std::ostream& operator<<(std::ostream& pOs, Elements& pE);
264 * Builds the set of nodes used by this set of elements.
265 * If the set already exist, then it is cleared and a new set is computed.
267 void buildSetOfNodes();
271 med_int mNum; /**< Number of elements. */
272 med_entite_maillage mEntity; /**< Type of entity, e.g. MED_MAILLE. */
273 med_geometrie_element mGeom; /**< Type of primitive, e.g. MED_TETRA10. */
274 int mDim; /**< Dimension of elements = mGeom / 100. */
275 int mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */
276 med_int* mId; /**< Optional; for each element, its identifier; NULL if undefined. */
277 med_int* mFamIdent; /**< For each element, its family (identifier). */
278 char* mNames; /**< Optional; for each element, its name; NULL if undefined. */
279 med_int* mCon; /**< For each element, list of nodes (index in 1..*) = table of connectivity. */
280 std::set<med_int> mSetOfNodes; /**< Set of all nodes used by this set of elements. */
282 bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */
286 // do not allow copy constructor
287 Elements(const Elements&);
290 Elements& operator=(const Elements&);
292 // do not allow operator ==
293 bool operator==(const Elements&);
298 } // namespace MULTIPR
301 #endif // MULTIPR_NODES_HXX