OpenMEEG
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sensors.h
Go to the documentation of this file.
1 /*
2 Project Name : OpenMEEG
3 
4 © INRIA and ENPC (contributors: Geoffray ADDE, Maureen CLERC, Alexandre
5 GRAMFORT, Renaud KERIVEN, Jan KYBIC, Perrine LANDREAU, Théodore PAPADOPOULO,
6 Emmanuel OLIVI
7 Maureen.Clerc.AT.inria.fr, keriven.AT.certis.enpc.fr,
8 kybic.AT.fel.cvut.cz, papadop.AT.inria.fr)
9 
10 The OpenMEEG software is a C++ package for solving the forward/inverse
11 problems of electroencephalography and magnetoencephalography.
12 
13 This software is governed by the CeCILL-B license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL-B
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's authors, the holders of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL-B license and that you accept its terms.
38 */
39 
40 #pragma once
41 
42 #include <fstream>
43 #include <sstream>
44 #include <stdlib.h>
45 #include <string>
46 #include <vector>
47 
48 #include <IOUtils.H>
49 #include <vector.h>
50 #include <matrix.h>
51 #include <geometry.h>
52 #include <om_common.h>
53 
54 #include <OpenMEEG_Export.h>
55 
56 namespace OpenMEEG {
57 
92  class OPENMEEG_EXPORT Sensors {
93 
94  public:
95  Sensors(): m_nb(0), m_geo(NULL) {}
96  Sensors(const Geometry& g): m_nb(0), m_geo(&g) {}
97  Sensors(const char* filename): m_geo(NULL) { this->load(filename,'t'); }
98  Sensors(const char* filename, const Geometry& g): m_geo(&g) { this->load(filename,'t'); };
100  Sensors(const Strings &labels, const Matrix& positions, const Matrix& orientations, const Vector &weights, const Vector &radii);
101  Sensors(const Strings &labels, const Matrix& positions, const Matrix& orientations, const Vector &weights, const Vector &radii, const Geometry &g);
102 
103  void load(const char* filename, char filetype = 't' );
104  void load(std::istream &in);
105  void save(const char* filename);
106 
107  size_t getNumberOfSensors() const { return m_nb; }
108  size_t getNumberOfPositions() const { return m_positions.nlin(); }
110  Matrix& getPositions() { return m_positions ; }
111  Matrix getPositions() const { return m_positions ; }
113  Matrix& getOrientations() {return m_orientations ; }
114  Matrix getOrientations() const {return m_orientations ; }
116  Strings& getNames() {return m_names ; }
117  Strings getNames() const {return m_names ; }
119  bool hasRadii() const { return m_radii.nlin() > 0 ;}
120  bool hasOrientations() const { return m_orientations.nlin() > 0 ;}
121  bool hasNames() const { return m_names.size() == m_nb ;}
122  Vector getPosition(size_t idx) const;
123  Vector getOrientation(size_t idx) const;
124  std::string getName(size_t idx) const{ om_assert(idx < m_names.size()); return m_names[idx]; }
125  void setPosition(size_t idx, Vector& pos);
126  void setOrientation(size_t idx, Vector& orient);
128  bool hasSensor(std::string name) const;
129  size_t getSensorIdx(std::string name) const;
130  Triangles getInjectionTriangles(size_t idx) const { om_assert(idx < m_triangles.size()); return m_triangles[idx]; }
132  Vector getRadii() const { return m_radii; }
133  Vector getWeights() const { return m_weights; }
134 
135  SparseMatrix getWeightsMatrix() const;
136 
137  bool isEmpty() { if(m_nb == 0) return true; else return false; }
138  void info() const;
140  private:
141  size_t m_nb;
147  std::vector<Triangles> m_triangles;
148  const Geometry * m_geo;
149  std::vector<size_t> m_pointSensorIdx;
150  void findInjectionTriangles();
151  };
152 
153  inline Vector Sensors::getPosition(size_t idx) const {
154  return m_positions.getlin(idx);
155  }
156 
157  inline Vector Sensors::getOrientation(size_t idx) const {
158  return m_orientations.getlin(idx);
159  }
160 
161  inline void Sensors::setPosition(size_t idx, Vector& pos) {
162  return m_positions.setlin(idx,pos);
163  }
164 
165  inline void Sensors::setOrientation(size_t idx, Vector& orient) {
166  return m_orientations.setlin(idx,orient);
167  }
168 
169  inline Sensors::Sensors(const Strings &labels, const Matrix& positions, const Matrix& orientations, const Vector &weights, const Vector &radii) :
170  m_nb(labels.size()), m_names(labels), m_positions(positions), m_orientations(orientations),m_weights(weights), m_radii(radii)
171  {
172  std::cout << "const" << labels.size() << std::endl;
173  m_pointSensorIdx = std::vector<size_t>(labels.size());
174  for ( std::size_t i = 0; i < labels.size(); ++i) {
176  }
177  }
178 
179  inline Sensors::Sensors(const Strings &labels, const Matrix& positions, const Matrix& orientations, const Vector &weights, const Vector &radii, const Geometry &g) :
180  m_nb(labels.size()), m_names(labels), m_positions(positions), m_orientations(orientations),m_weights(weights), m_radii(radii), m_geo(&g)
181  {
182  // find triangles on which to inject the currents and compute weights
184 
185  m_pointSensorIdx = std::vector<size_t>(labels.size());
186  for ( std::size_t i = 0; i < labels.size(); ++i) {
188  }
189  }
190 
191 }
void setOrientation(size_t idx, Vector &orient)
Definition: sensors.h:165
Geometry contains the electrophysiological model Here are stored the vertices, meshes and domains...
Definition: geometry.h:61
Vector getWeights() const
Definition: sensors.h:133
Strings getNames() const
Definition: sensors.h:117
std::string getName(size_t idx) const
Definition: sensors.h:124
bool hasOrientations() const
Definition: sensors.h:120
std::vector< std::string > Strings
Definition: om_common.h:52
std::vector< Triangle > Triangles
Definition: triangle.h:176
void findInjectionTriangles()
Matrix m_orientations
Definition: sensors.h:144
bool hasNames() const
Definition: sensors.h:121
const Geometry * m_geo
Definition: sensors.h:148
void setPosition(size_t idx, Vector &pos)
Definition: sensors.h:161
std::vector< size_t > m_pointSensorIdx
Definition: sensors.h:149
Vector m_radii
Definition: sensors.h:146
Vector m_weights
Definition: sensors.h:145
bool hasRadii() const
Definition: sensors.h:119
Sensors(const char *filename)
Definition: sensors.h:97
Matrix & getOrientations()
Definition: sensors.h:113
Sensors(const char *filename, const Geometry &g)
Definition: sensors.h:98
Vector getRadii() const
Definition: sensors.h:132
Vector getOrientation(size_t idx) const
Definition: sensors.h:157
size_t getNumberOfPositions() const
Definition: sensors.h:108
Matrix & getPositions()
Definition: sensors.h:110
Triangles getInjectionTriangles(size_t idx) const
Definition: sensors.h:130
Vector getlin(size_t i) const
Definition: matrix.h:256
Matrix m_positions
Definition: sensors.h:143
Strings & getNames()
Definition: sensors.h:116
Matrix getPositions() const
Definition: sensors.h:111
Matrix getOrientations() const
Definition: sensors.h:114
bool isEmpty()
Definition: sensors.h:137
Strings m_names
Definition: sensors.h:142
size_t getSensorIdx(std::string name) const
Vector getPosition(size_t idx) const
Definition: sensors.h:153
Sensors(const Geometry &g)
Definition: sensors.h:96
std::vector< Triangles > m_triangles
Definition: sensors.h:147
Matrix class.
Definition: matrix.h:61
size_t getNumberOfSensors() const
Definition: sensors.h:107
void setlin(size_t i, const Vector &v)
Definition: matrix.h:276