OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 <vector>
31 #include "WRecording.h"
32 #include "../common/WPrototyped.h"
33 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
34 #include "WExportDataHandler.h"
35 
36 /**
37  * An incomplete implementation to store information about electrodes of EEG data
38  */
40 {
41 public:
42  /**
43  * Contructor taking the position of the elctrode.
44  * \param position The position of the electrode in world space.
45  */
46  explicit WEEGElectrodeObject( WPosition position );
47 
48  /**
49  * Returns the position of the electrode.
50  * \return The position of the electrode.
51  */
52  WPosition getPosition() const;
53 protected:
54 private:
55  WPosition m_position; //!< Position of the electrode in space
56 };
57 
58 typedef std::vector< double > WEEGElectrode;
59 typedef std::vector< WEEGElectrode > WEEGSegment;
60 typedef std::vector< WEEGSegment > WEEGSegmentArray;
61 
62 typedef std::vector< WEEGElectrodeObject > WEEGElectrodeLibrary;
63 typedef std::vector< std::pair< std::string, std::string > > WEEGChannelLabels;
64 /**
65  * Contains EEG recording data.
66  * \ingroup dataHandler
67  */
68 class OWDATAHANDLER_EXPORT WEEG : public WRecording // NOLINT
69 {
70 public:
71 
72 
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  /**
161  * The prototype as singleton.
162  */
163  static boost::shared_ptr< WPrototyped > m_prototype;
164 
165 private:
166  /**
167  * We have only on sampling rate for all channels.
168  */
170  /**
171  * Description of electrodes
172  */
173  std::map< std::string, size_t > m_electrodeDescriptions;
174 
175  /**
176  * Information about the electrodes.
177  */
178  WEEGElectrodeLibrary m_electrodeLibrary;
179 
180  /**
181  * Contains the EEG data as an arry of segements
182  * of data which consist of an array of electrodes
183  * which again consist of an array of samples over time.
184  */
185  WEEGSegmentArray m_segments;
186 
187  /**
188  * Label for each channel.
189  */
190  WEEGChannelLabels m_channelLabels;
191 
192  /**
193  * Is the channel enabled?
194  */
195  std::vector< bool > m_channelEnabled;
196 };
197 
198 inline const double& WEEG::operator()( size_t segment, size_t signal, size_t sample ) const
199 {
200  return m_segments[segment][signal][sample];
201 }
202 
203 inline size_t WEEG::getNumberOfSamples( size_t segmentId ) const
204 {
205  return m_segments[segmentId][0].size();
206 }
207 
208 inline size_t WEEG::getNumberOfChannels() const
209 {
210  return m_segments[0].size();
211 }
212 
213 inline size_t WEEG::getNumberOfSegments() const
214 {
215  return m_segments.size();
216 }
217 
218 inline std::string WEEG::getChannelLabel( size_t channelId ) const
219 {
220  // TODO(wiebel): what is done with the second string of the label?
221  return m_channelLabels[channelId].first;
222 }
223 
224 inline WPosition WEEG::getChannelPosition( size_t channelId ) const
225 {
226  return m_electrodeLibrary[channelId].getPosition();
227 }
228 
229 #endif // WEEG_H