OpenMEEG
Loading...
Searching...
No Matches
GeometryIO.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 <map>
11#include <string>
12
13#include <geometry.h>
14#include <matrix.h>
15#include <filenames.h>
16
17namespace OpenMEEG {
18
19 // Geometry IO class
20
21 class OPENMEEG_EXPORT GeometryIO {
22 public:
23
24 static GeometryIO* create(const std::string& filename) {
25 const std::string& extension = tolower(getFilenameExtension(filename));
26 try {
27 return registery.at(extension)->clone(filename);
28 } catch(std::out_of_range&) {
29 throw UnknownFileSuffix(extension);
30 }
31 }
32
33 virtual const char* name() const = 0;
34
35 void load(Geometry& geometry) {
36 load_meshes(geometry);
37 load_domains(geometry);
38 }
39
40 void load(Geometry& geometry,Matrix& matrix) {
41 load(geometry);
42 matrix = load_data();
43 }
44
45 void save(const Geometry& geometry) {
46 save_geom(geometry);
47 write();
48 }
49
50 void save(const Geometry& geometry,const Matrix& matrix) {
51 save_geom(geometry);
52 save_data(geometry,matrix);
53 write();
54 }
55
56 virtual ~GeometryIO() = default;
57
58 protected:
59
60 virtual void load_meshes(Geometry& geometry) = 0;
61 virtual void load_domains(Geometry&) { }
62 virtual Matrix load_data() const = 0;
63
64 virtual void save_geom(const Geometry& geometry) = 0;
65 virtual void save_data(const Geometry& geometry,const Matrix& matrix) const = 0;
66 virtual void write() const = 0;
67
68 virtual GeometryIO* clone(const std::string& filename) const = 0;
69
70 typedef std::map<std::string,GeometryIO*> Registery;
71
73
74 GeometryIO(const std::string& filename,const char* name): fname(filename) { registery.insert({ name, this }); }
75
76 std::string fname;
77 };
78}
static GeometryIO * create(const std::string &filename)
Definition: GeometryIO.h:24
virtual void load_meshes(Geometry &geometry)=0
virtual void write() const =0
virtual void save_data(const Geometry &geometry, const Matrix &matrix) const =0
GeometryIO(const std::string &filename, const char *name)
Definition: GeometryIO.h:74
std::map< std::string, GeometryIO * > Registery
Definition: GeometryIO.h:70
virtual const char * name() const =0
virtual void save_geom(const Geometry &geometry)=0
void load(Geometry &geometry)
Definition: GeometryIO.h:35
std::string fname
Definition: GeometryIO.h:76
virtual GeometryIO * clone(const std::string &filename) const =0
virtual ~GeometryIO()=default
void load(Geometry &geometry, Matrix &matrix)
Definition: GeometryIO.h:40
void save(const Geometry &geometry, const Matrix &matrix)
Definition: GeometryIO.h:50
virtual void load_domains(Geometry &)
Definition: GeometryIO.h:61
void save(const Geometry &geometry)
Definition: GeometryIO.h:45
virtual Matrix load_data() const =0
static Registery registery
Definition: GeometryIO.h:72
Geometry contains the electrophysiological model Vertices, meshes and domains are stored in this geom...
Definition: geometry.h:31
Matrix class Matrix class.
Definition: matrix.h:28
std::string tolower(const std::string &s)
Definition: filenames.h:26
std::string getFilenameExtension(const std::string &name)
Definition: filenames.h:18