OpenMEEG
Toggle main menu visibility
Loading...
Searching...
No Matches
OpenMEEG
include
MeshIO.h
Go to the documentation of this file.
1
// Project Name: OpenMEEG (http://openmeeg.github.io)
2
// © INRIA and ENPC under the French open source license CeCILL-B.
3
// See full copyright notice in the file LICENSE.txt
4
// If you make a copy of this file, you must either:
5
// - provide also LICENSE.txt and modify this header to refer to it.
6
// - replace this header by the LICENSE.txt content.
7
8
#pragma once
9
10
#include <fstream>
11
#include <map>
12
#include <string>
13
14
#include <
triangle.h
>
15
#include <
mesh.h
>
16
#include <
geometry.h
>
17
#include <
filenames.h
>
18
#include <OMExceptions.H>
19
20
namespace
OpenMEEG
{
21
22
// Mesh class
23
// \brief Mesh is a collection of triangles associated to a geometry containing the points
24
// on which triangles are based.
25
26
class
OPENMEEG_EXPORT
MeshIO
{
27
public
:
28
29
virtual
~MeshIO
() { }
30
31
static
MeshIO
*
create
(
const
std::string& filename) {
32
const
std::string& extension =
tolower
(
getFilenameExtension
(filename));
33
return
registery
.at(extension)->clone(filename);
34
}
35
36
virtual
const
char
*
name
()
const
= 0;
37
38
void
open
(
const
std::ios_base::openmode mode=std::ios_base::in) {
39
fs
.open(
fname
,(
binary
()) ? mode|std::ios_base::binary : mode);
40
if
(!
fs
.is_open())
41
throw
OpenMEEG::OpenError(
name
());
42
}
43
44
virtual
void
load_points
(
Geometry
& geom) = 0;
45
virtual
void
load_triangles
(
Mesh
& m) = 0;
46
47
virtual
void
load
(
Mesh
& m) {
48
open
(std::ios_base::in);
49
load_points
(m.
geometry
());
50
// TODO
51
load_triangles
(m);
52
fs
.close();
53
m.
update
(
true
);
54
}
55
56
virtual
void
save
(
const
Mesh
& mesh,std::ostream& os)
const
= 0;
57
58
virtual
void
save
(
const
Mesh
& mesh) {
59
open
(std::ios_base::out);
60
save
(mesh,
fs
);
61
fs
.close();
62
}
63
64
protected
:
65
66
typedef
std::map<std::string,MeshIO*>
Registery
;
67
68
class
VertexIndices
{
69
public
:
70
71
VertexIndices
(
const
Mesh
& mesh) {
72
unsigned
i = 0;
73
for
(
const
auto
& vertex : mesh.
vertices
())
74
vmap[vertex] = i++;
75
}
76
77
unsigned
operator()
(
const
Triangle
& triangle,
const
unsigned
ind)
const
{
78
return
vmap.at(&(triangle.
vertex
(ind)));
79
}
80
81
private
:
82
83
std::map<const Vertex*,unsigned> vmap;
84
};
85
86
virtual
MeshIO
*
clone
(
const
std::string& filename)
const
= 0;
87
virtual
bool
binary
()
const
{
return
false
; }
88
89
void
reference_vertices
(
Mesh
& mesh)
const
{ mesh.reference_vertices(
indmap
); }
90
91
static
Registery
registery
;
92
93
MeshIO
(
const
std::string& filename,
const
char
*
name
):
fname
(filename) {
registery
.insert({
name
,
this
}); }
94
95
std::string
fname
;
96
std::fstream
fs
;
97
IndexMap
indmap
;
98
};
99
}
OpenMEEG::Geometry
Geometry contains the electrophysiological model Vertices, meshes and domains are stored in this geom...
Definition
geometry.h:31
OpenMEEG::MeshIO::VertexIndices::operator()
unsigned operator()(const Triangle &triangle, const unsigned ind) const
Definition
MeshIO.h:77
OpenMEEG::MeshIO::VertexIndices::VertexIndices
VertexIndices(const Mesh &mesh)
Definition
MeshIO.h:71
OpenMEEG::MeshIO::fname
std::string fname
Definition
MeshIO.h:95
OpenMEEG::MeshIO::open
void open(const std::ios_base::openmode mode=std::ios_base::in)
Definition
MeshIO.h:38
OpenMEEG::MeshIO::Registery
std::map< std::string, MeshIO * > Registery
Definition
MeshIO.h:66
OpenMEEG::MeshIO::fs
std::fstream fs
Definition
MeshIO.h:96
OpenMEEG::MeshIO::create
static MeshIO * create(const std::string &filename)
Definition
MeshIO.h:31
OpenMEEG::MeshIO::registery
static Registery registery
Definition
MeshIO.h:91
OpenMEEG::MeshIO::load_points
virtual void load_points(Geometry &geom)=0
OpenMEEG::MeshIO::name
virtual const char * name() const =0
OpenMEEG::MeshIO::binary
virtual bool binary() const
Definition
MeshIO.h:87
OpenMEEG::MeshIO::load_triangles
virtual void load_triangles(Mesh &m)=0
OpenMEEG::MeshIO::indmap
IndexMap indmap
Definition
MeshIO.h:97
OpenMEEG::MeshIO::clone
virtual MeshIO * clone(const std::string &filename) const =0
OpenMEEG::MeshIO::save
virtual void save(const Mesh &mesh)
Definition
MeshIO.h:58
OpenMEEG::MeshIO::MeshIO
MeshIO(const std::string &filename, const char *name)
Definition
MeshIO.h:93
OpenMEEG::MeshIO::load
virtual void load(Mesh &m)
Definition
MeshIO.h:47
OpenMEEG::MeshIO::reference_vertices
void reference_vertices(Mesh &mesh) const
Definition
MeshIO.h:89
OpenMEEG::MeshIO::~MeshIO
virtual ~MeshIO()
Definition
MeshIO.h:29
OpenMEEG::MeshIO::save
virtual void save(const Mesh &mesh, std::ostream &os) const =0
OpenMEEG::Mesh
Definition
mesh.h:34
OpenMEEG::Mesh::geometry
Geometry & geometry() const
Definition
mesh.h:87
OpenMEEG::Mesh::update
void update(const bool topology_changed)
Recompute triangles normals, area, and vertex triangles.
OpenMEEG::Mesh::vertices
VerticesRefs & vertices()
Definition
mesh.h:84
OpenMEEG::Triangle
Triangle Triangle class.
Definition
triangle.h:45
OpenMEEG::Triangle::vertex
Vertex & vertex(const unsigned &vindex)
Definition
triangle.h:83
filenames.h
geometry.h
mesh.h
OpenMEEG
Definition
analytics.h:14
OpenMEEG::tolower
std::string tolower(const std::string &s)
Definition
filenames.h:26
OpenMEEG::IndexMap
std::map< unsigned, unsigned > IndexMap
Definition
triangle.h:148
OpenMEEG::getFilenameExtension
std::string getFilenameExtension(const std::string &name)
Definition
filenames.h:18
triangle.h
Generated by
1.17.0