44 #include <GeometryExceptions.H>
79 const char c0 = name[0];
80 if ( c0 ==
'/' || c0 ==
'\\' ) {
83 const char c1 = name[1];
84 const char c2 = name[2];
85 return !( std::isalpha(c0) && c1 ==
':' && ( c2 ==
'/' || c2 ==
'\\' ) );
117 std::ifstream ifs(geometry.c_str());
119 if ( !ifs.is_open() ) {
120 throw OpenMEEG::OpenError(geometry);
126 ifs >> io_utils::match(
"# Domain Description ") >> version[0] >> io_utils::match(
".") >> version[1];
129 throw OpenMEEG::WrongFileFormat(geometry);
136 std::cerr <<
"(DEPRECATED) Please consider updating your geometry file to the new format 1.1 (see data/README.rst): "
137 << geometry << std::endl;
144 std::cerr <<
"Domain Description version not available !" << std::endl;
145 throw OpenMEEG::WrongFileFormat(geometry);
149 const std::string::size_type pos = geometry.find_last_of(this->
PathSeparator);
150 const std::string path = (pos == std::string::npos) ?
"" : geometry.substr(0, pos+1);
157 bool Is_MeshFile, Is_Meshes;
158 ifs >> io_utils::skip_comments(
"#") >> io_utils::match_optional(
"MeshFile", Is_MeshFile);
159 ifs >> io_utils::skip_comments(
"#") >> io_utils::match_optional(
"Meshes", Is_Meshes);
162 ifs >> io_utils::skip_comments(
"#") >> io_utils::filename(name,
'"',
false);
165 }
else if ( Is_Meshes ) {
168 std::vector<std::string> meshname(nb_meshes);
169 std::vector<std::string> filename(nb_meshes);
170 std::vector<std::string> fullname(nb_meshes);
172 for (
unsigned i = 0; i < nb_meshes; ++i ) {
174 ifs >> io_utils::skip_comments(
"#") >> io_utils::match_optional(
"Mesh:", unnamed);
176 ifs >> io_utils::filename(filename[i],
'"',
false);
177 std::stringstream defaultname;
179 meshname[i] = defaultname.str();
181 ifs >> io_utils::match(
"Mesh")
182 >> io_utils::token(meshname[i],
':')
183 >> io_utils::filename(filename[i],
'"',
false);
187 meshes[i].load(fullname[i],
false);
188 meshes[i].name() = meshname[i];
196 unsigned nb_interfaces;
198 ifs >> io_utils::skip_comments(
'#')
199 >> io_utils::match(
"Interfaces") >> nb_interfaces >> io_utils::match_optional(
"Mesh", trash);
202 throw OpenMEEG::WrongFileFormat(geometry);
211 std::vector<std::string> interfacename(nb_interfaces);
212 std::vector<std::string> filename(nb_interfaces);
213 std::vector<std::string> fullname(nb_interfaces);
217 unsigned nb_vertices = 0;
218 for (
unsigned i = 0; i < nb_interfaces; ++i ) {
220 ifs >> io_utils::skip_comments(
"#") >> io_utils::match_optional(
"Interface:", unnamed);
222 ifs >> io_utils::filename(filename[i],
'"',
false);
223 std::stringstream defaultname;
225 interfacename[i] = defaultname.str();
227 std::stringstream defaultname;
229 interfacename[i] = defaultname.str();
230 ifs >> io_utils::filename(filename[i],
'"',
false);
232 ifs >> io_utils::match(
"Interface")
233 >> io_utils::token(interfacename[i],
':')
234 >> io_utils::filename(filename[i],
'"',
false);
238 nb_vertices += m.
load(fullname[i],
false,
false);
242 for (
unsigned i = 0; i < nb_interfaces; ++i ) {
245 interfaces.push_back(
Interface(interfacename[i]) );
249 std::string interfacename;
250 for (
unsigned i = 0; i < nb_interfaces; ++i ) {
253 ifs >> io_utils::skip_comments(
"#");
254 std::getline(ifs, line);
255 std::istringstream iss(line);
256 iss >> io_utils::match_optional(
"Interface:", unnamed);
258 std::stringstream defaultname;
260 interfacename = defaultname.str();
262 iss >> io_utils::match(
"Interface")
263 >> io_utils::token(interfacename,
':');
265 interfaces.push_back( interfacename );
266 while ( iss >>
id ) {
267 bool oriented =
true;
268 if ( (
id[0] ==
'-' ) || (
id[0] ==
'+' ) ) {
269 oriented = (
id[0] ==
'+' );
270 id =
id.substr(1,
id.size());
279 unsigned num_domains;
280 ifs >> io_utils::skip_comments(
'#') >> io_utils::match(
"Domains") >> num_domains;
283 throw OpenMEEG::WrongFileFormat(geometry);
290 ifs >> io_utils::skip_comments(
'#') >> io_utils::match(
"Domain") >> dit->name();
292 ifs >> io_utils::skip_comments(
'#') >> io_utils::match(
"Domain") >> io_utils::token(dit->name(),
':');
295 std::istringstream iss(line);
296 while ( iss >>
id ) {
299 if ( (
id[0] ==
'-' ) || (
id[0] ==
'+' ) ) {
300 inside = (
id[0] ==
'-' );
301 id =
id.substr(1,
id.size());
302 }
else if (
id ==
"shared" ) {
303 std::cerr <<
"(DEPRECATED) Keyword shared is useless. Please consider updating your geometry file to the new format 1.1 (see data/README.rst): " << geometry << std::endl;
306 for ( Interfaces::iterator iit = interfaces.begin(); iit != interfaces.end() ; ++iit) {
307 if ( iit->name() == id ) {
309 if ( !iit->check() ) {
310 std::cerr <<
"Interface \"" << iit->name() <<
"\" is not closed !" << std::endl;
311 std::cerr <<
"Please correct a mesh orientation when defining the interface in the geometry file." << std::endl;
318 throw OpenMEEG::NonExistingDomain<std::string>(dit->name(),
id);
326 Domains::iterator dit_out;
329 for ( Domain::iterator hit = dit->begin(); hit != dit->end(); ++hit)
330 outer = outer && !(hit->inside());
334 dit_out->outermost() =
true;
335 for (Domain::iterator hit = dit_out->begin(); hit != dit_out->end(); ++hit) {
336 hit->interface().set_to_outermost();
349 unsigned out_interface = 0;
350 if ( dit != dit_out ) {
351 for ( Domain::const_iterator hit = dit->begin(); hit != dit->end(); ++hit) {
352 if ( !hit->inside() ) {
357 if ( out_interface >= 2 ) {
365 unsigned m_oriented = 0;
367 for ( Domain::const_iterator hit = dit->begin(); hit != dit->end(); ++hit) {
368 for ( Interface::const_iterator iit = hit->first.begin(); iit != hit->first.end(); ++iit) {
369 if ( iit->mesh() == *mit ) {
370 m_oriented += (iit->orientation());
375 if ( m_oriented == 0 ) {
384 throw OpenMEEG::WrongFileFormat(geometry);
393 typedef Utils::Properties::Named<std::string, Conductivity<double> > HeadProperties;
394 HeadProperties properties(condFileName.c_str());
402 }
catch(
const Utils::Properties::UnknownProperty<HeadProperties::Id>& e) {
403 throw OpenMEEG::BadDomain(dit->name());
A class to read geometry and cond file.
static const char PathSeparator
GeometryReader(Geometry &g)
bool is_relative_path(const std::string &name)
void read_geom(const std::string &)
read a geometry file
void read_cond(const std::string &)
read a cond file
Geometry contains the electrophysiological model Here are stored the vertices, meshes and domains.
void import_meshes(const Meshes &m)
imports meshes from a list of meshes
Domains::iterator domain_begin()
iterator begin()
Iterators.
const Mesh & mesh(const std::string &id) const
void load_vtp(const std::string &filename)
Domains::iterator domain_end()
Meshes::const_iterator const_iterator
VersionId version_id
Members.
a HalfSpace is a pair of Interface and boolean A simple domain (HalfSpace) is given by an interface (...
Interface class An interface is a closed-shape composed of oriented meshes (here pointer to meshes)
unsigned load(const std::string &filename, const bool &verbose=true, const bool &read_all=true)
Read mesh from file.
An Oriented Mesh is a mesh associated with a boolean stating if it is well oriented.
std::vector< Mesh > Meshes
A vector of Mesh is called Meshes.
std::vector< Interface > Interfaces
A vector of Interface is called Interfaces.