OpenWalnut  1.4.0
WEEG.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WEEG_H
26 #define WEEG_H
27 
28 #include <map>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include "../common/math/linearAlgebra/WPosition.h"
34 #include "../common/WPrototyped.h"
35 
36 #include "WRecording.h"
37 
38 /**
39  * An incomplete implementation to store information about electrodes of EEG data
40  */
41 class WEEGElectrodeObject // NOLINT
42 {
43 public:
44  /**
45  * Contructor taking the position of the elctrode.
46  * \param position The position of the electrode in world space.
47  */
48  explicit WEEGElectrodeObject( WPosition position );
49 
50  /**
51  * Returns the position of the electrode.
52  * \return The position of the electrode.
53  */
54  WPosition getPosition() const;
55 protected:
56 private:
57  WPosition m_position; //!< Position of the electrode in space
58 };
59 
60 typedef std::vector< double > WEEGElectrode;
61 typedef std::vector< WEEGElectrode > WEEGSegment;
62 typedef std::vector< WEEGSegment > WEEGSegmentArray;
63 
64 typedef std::vector< WEEGElectrodeObject > WEEGElectrodeLibrary;
65 typedef std::vector< std::pair< std::string, std::string > > WEEGChannelLabels;
66 /**
67  * Contains EEG recording data.
68  * \ingroup dataHandler
69  */
70 class WEEG : public WRecording // NOLINT
71 {
72 public:
73  /**
74  * Constructs a WEEG object from the give infos.
75  * \param data Array of segments
76  * \param electrodeLib Information about the electrodes
77  * \param channelLabels The names of the channels.
78  */
79  explicit WEEG( const WEEGSegmentArray& data,
80  const WEEGElectrodeLibrary& electrodeLib,
81  const WEEGChannelLabels& channelLabels );
82 
83  /**
84  * Constructor creating a quite unusable instance. Useful for prototype mechanism.
85  */
86  WEEG();
87 
88  /**
89  * Access operator for single samples.
90  * \param segment id of segment to access
91  * \param signal id of signal to access
92  * \param sample id of sample to access
93  * \return The data sample at the given location
94  */
95  const double& operator()( size_t segment, size_t signal, size_t sample ) const;
96 
97  /**
98  * Returns number of samples of a given segment.
99  * \param segmentId id of segment beeing inspected.
100  * \return Number of samples of segment with segmentId.
101  */
102  size_t getNumberOfSamples( size_t segmentId ) const;
103 
104  /**
105  * Return the number of channels this EEG has.
106  * \return Number of channels.
107  */
108  size_t getNumberOfChannels() const;
109 
110  /**
111  * Return the number of segments this EEG consists of.
112  * \return Number of segments.
113  */
114  size_t getNumberOfSegments() const;
115 
116  /**
117  * Return the label of a certain channel.
118  * \param channelId id of channel beeing inspected.
119  * \return Name of channel with channelId
120  */
121  std::string getChannelLabel( size_t channelId ) const;
122 
123  /**
124  * Return the position of the sensor for a certain channel.
125  * \param channelId id of channel beeing inspected.
126  * \return Position of sensor of channel channelId
127  */
128  WPosition getChannelPosition( size_t channelId ) const;
129 
130  /**
131  * Determines whether this dataset can be used as a texture.
132  *
133  * \return true if usable as texture.
134  */
135  virtual bool isTexture() const;
136 
137  /**
138  * Gets the name of this prototype.
139  *
140  * \return the name.
141  */
142  virtual const std::string getName() const;
143 
144  /**
145  * Gets the description for this prototype.
146  *
147  * \return the description
148  */
149  virtual const std::string getDescription() const;
150 
151  /**
152  * Returns a prototype instantiated with the true type of the deriving class.
153  *
154  * \return the prototype.
155  */
156  static boost::shared_ptr< WPrototyped > getPrototype();
157 
158 protected:
159  /**
160  * The prototype as singleton.
161  */
162  static boost::shared_ptr< WPrototyped > m_prototype;
163 
164 private:
165  /**
166  * We have only on sampling rate for all channels.
167  */
169  /**
170  * Description of electrodes
171  */
172  std::map< std::string, size_t > m_electrodeDescriptions;
173 
174  /**
175  * Information about the electrodes.
176  */
177  WEEGElectrodeLibrary m_electrodeLibrary;
178 
179  /**
180  * Contains the EEG data as an arry of segements
181  * of data which consist of an array of electrodes
182  * which again consist of an array of samples over time.
183  */
184  WEEGSegmentArray m_segments;
185 
186  /**
187  * Label for each channel.
188  */
189  WEEGChannelLabels m_channelLabels;
190 
191  /**
192  * Is the channel enabled?
193  */
194  std::vector< bool > m_channelEnabled;
195 };
196 
197 inline const double& WEEG::operator()( size_t segment, size_t signal, size_t sample ) const
198 {
199  return m_segments[segment][signal][sample];
200 }
201 
202 inline size_t WEEG::getNumberOfSamples( size_t segmentId ) const
203 {
204  return m_segments[segmentId][0].size();
205 }
206 
207 inline size_t WEEG::getNumberOfChannels() const
208 {
209  return m_segments[0].size();
210 }
211 
212 inline size_t WEEG::getNumberOfSegments() const
213 {
214  return m_segments.size();
215 }
216 
217 inline std::string WEEG::getChannelLabel( size_t channelId ) const
218 {
219  // TODO(wiebel): what is done with the second string of the label?
220  return m_channelLabels[channelId].first;
221 }
222 
223 inline WPosition WEEG::getChannelPosition( size_t channelId ) const
224 {
225  return m_electrodeLibrary[channelId].getPosition();
226 }
227 
228 #endif // WEEG_H