Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
mesh_io.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_MESH_NEW_MESH_IO
41#define GEOGRAM_MESH_NEW_MESH_IO
42
47#include <geogram/mesh/mesh.h>
48#include <string>
49
55namespace GEO {
56
57 class InputGeoFile;
58 class OutputGeoFile;
59
67 MESH_NO_ATTRIBUTES = 0,
68 MESH_VERTEX_REGION = 1,
69 MESH_VERTEX_TEX_COORD = 2,
70 MESH_VERTEX_COLOR = 4,
71 MESH_FACET_REGION = 8,
72 MESH_CELL_REGION = 16,
73 MESH_EDGE_REGION = 32,
74 MESH_ALL_ATTRIBUTES = 255
75 };
76
77
83 class GEOGRAM_API MeshIOFlags {
84 public:
89
97 return dimension_;
98 }
99
106 dimension_ = x;
107 }
108
114 return attributes_;
115 }
116
122 attributes_ = x;
123 }
124
131 attributes_ = MeshAttributesFlags(attributes_ | x);
132 }
133
140 attributes_ = MeshAttributesFlags(attributes_ & ~x);
141 }
142
152 return (attributes_ & x) != 0;
153 }
154
159 MeshElementsFlags elements() const {
160 return elements_;
161 }
162
167 void set_elements(MeshElementsFlags x) {
168 elements_ = x;
169 }
170
177 void set_element(MeshElementsFlags x) {
178 elements_ = MeshElementsFlags(elements_ | x);
179 }
180
187 void reset_element(MeshElementsFlags x) {
188 elements_ = MeshElementsFlags(elements_ & ~x);
189 }
190
199 bool has_element(MeshElementsFlags x) const {
200 return (elements_ & x) != 0;
201 }
202
210 void set_texture_filename(const std::string& x) {
211 texture_filename_ = x;
212 }
213
219 const std::string& get_texture_filename() const {
220 return texture_filename_;
221 }
222
223 private:
224 coord_index_t dimension_;
225 MeshAttributesFlags attributes_;
226 MeshElementsFlags elements_;
227 std::string texture_filename_;
228 };
229
230
246 bool GEOGRAM_API mesh_load(
247 const std::string& filename, Mesh& M,
248 const MeshIOFlags& ioflags = MeshIOFlags()
249 );
250
263 bool GEOGRAM_API mesh_load(
264 InputGeoFile& geofile, Mesh& M,
265 const MeshIOFlags& ioflags = MeshIOFlags()
266 );
267
268
282 bool GEOGRAM_API mesh_save(
283 const Mesh& M, const std::string& filename,
284 const MeshIOFlags& ioflags = MeshIOFlags()
285 );
286
298 bool GEOGRAM_API mesh_save(
299 const Mesh& M, OutputGeoFile& geofile,
300 const MeshIOFlags& ioflags = MeshIOFlags()
301 );
302
303
304 /*************************************************************************/
305
329 class GEOGRAM_API MeshIOHandler : public Counted {
330 public:
342 static MeshIOHandler* create(const std::string& format);
343
354 static MeshIOHandler* get_handler(const std::string& filename);
355
363 virtual bool load(
364 const std::string& filename, Mesh& M,
365 const MeshIOFlags& ioflags = MeshIOFlags()
366 ) = 0;
367
376 virtual bool save(
377 const Mesh& M, const std::string& filename,
378 const MeshIOFlags& ioflags = MeshIOFlags()
379 ) = 0;
380
381 protected:
386 }
387
391 ~MeshIOHandler() override;
392
393 virtual void bind_attributes(
394 const Mesh& M, const MeshIOFlags& flags, bool create
395 );
396 virtual void unbind_attributes();
397
398 protected:
399 Attribute<index_t> vertex_region_;
400 Attribute<index_t> edge_region_;
401 Attribute<index_t> facet_region_;
402 Attribute<index_t> cell_region_;
403 };
404
410
422
428#define geo_register_MeshIOHandler_creator(type, name) \
429 geo_register_creator(GEO::MeshIOHandlerFactory, type, name)
430
431
432 void GEOGRAM_API mesh_io_initialize() ;
433}
434
435#endif
436
Generic mechanism for attributes.
Common include file, providing basic definitions. Should be included before anything else by all head...
Manages an attribute attached to a set of object.
Base class for reference-counted objects.
Definition counted.h:71
Factory for types without constructor arguments.
Definition factory.h:292
Used to read a structured binary file.
Definition geofile.h:667
Mesh load/save flags.
Definition mesh_io.h:83
void set_element(MeshElementsFlags x)
Sets a mesh element.
Definition mesh_io.h:177
bool has_element(MeshElementsFlags x) const
Tests whether a mesh element is set.
Definition mesh_io.h:199
void set_attribute(MeshAttributesFlags x)
Sets a mesh attribute.
Definition mesh_io.h:130
void reset_element(MeshElementsFlags x)
Resets a mesh element.
Definition mesh_io.h:187
void reset_attribute(MeshAttributesFlags &x)
Resets a mesh attribute..
Definition mesh_io.h:139
MeshAttributesFlags attributes() const
Gets the attributes that should be loaded or saved.
Definition mesh_io.h:113
MeshIOFlags()
Constructs a new MeshIOFlags with default attributes.
void set_dimension(coord_index_t x)
Sets the dimension of the mesh (number of coordinates of the vertices).
Definition mesh_io.h:105
void set_elements(MeshElementsFlags x)
Sets the set of mesh elements that should be loaded or stored.
Definition mesh_io.h:167
void set_attributes(MeshAttributesFlags x)
Sets the attributes that should be loaded or stored.
Definition mesh_io.h:121
bool has_attribute(MeshAttributesFlags x) const
Tests whether a mesh attribute is set.
Definition mesh_io.h:151
const std::string & get_texture_filename() const
Gets the name of the texture image file.
Definition mesh_io.h:219
void set_texture_filename(const std::string &x)
Sets the name of the texture image file associated with this mesh.
Definition mesh_io.h:210
MeshElementsFlags elements() const
Gets the set of mesh elements that should be loaded or stored.
Definition mesh_io.h:159
coord_index_t dimension() const
Gets the dimension of the mesh (number of coordinates of the vertices).
Definition mesh_io.h:96
Mesh loader and saver.
Definition mesh_io.h:329
virtual bool load(const std::string &filename, Mesh &M, const MeshIOFlags &ioflags=MeshIOFlags())=0
Loads a double precision mesh from a file.
SmartPointer< MeshIOHandler > MeshIOHandler_var
A smart pointer that contains a MeshIOHandler object.
Definition mesh_io.h:409
MeshIOHandler()
MeshIOHandler default constructor.
Definition mesh_io.h:385
static MeshIOHandler * create(const std::string &format)
Creates a MeshIOHandler.
~MeshIOHandler() override
MeshIOHandler destructor.
virtual bool save(const Mesh &M, const std::string &filename, const MeshIOFlags &ioflags=MeshIOFlags())=0
Saves a mesh to a file.
Factory0< MeshIOHandler > MeshIOHandlerFactory
MeshIOHandler Factory.
Definition mesh_io.h:421
static MeshIOHandler * get_handler(const std::string &filename)
Gets the MeshIOHandler for a file.
Represents a mesh.
Definition mesh.h:2648
Used to write a structured binary file.
Definition geofile.h:771
A smart pointer with reference-counted copy semantics.
Generic factory mechanism.
The class that represents a mesh.
Global Vorpaline namespace.
Definition algorithm.h:64
bool mesh_save(const Mesh &M, const std::string &filename, const MeshIOFlags &ioflags=MeshIOFlags())
Saves a mesh to a file.
MeshAttributesFlags
Indicates the attributes stored in a mesh and attached to the mesh elements (vertices,...
Definition mesh_io.h:66
bool mesh_load(const std::string &filename, Mesh &M, const MeshIOFlags &ioflags=MeshIOFlags())
Loads a mesh from a file.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:321
Types and functions for numbers manipulation.