OpenWalnut  1.4.0
WEEG.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WEEG_H
00026 #define WEEG_H
00027 
00028 #include <map>
00029 #include <string>
00030 #include <utility>
00031 #include <vector>
00032 
00033 #include "../common/math/linearAlgebra/WPosition.h"
00034 #include "../common/WPrototyped.h"
00035 
00036 #include "WRecording.h"
00037 
00038 /**
00039  * An incomplete implementation to store information about electrodes of EEG data
00040  */
00041 class WEEGElectrodeObject // NOLINT
00042 {
00043 public:
00044     /**
00045      * Contructor taking the position of the elctrode.
00046      * \param position The position of the electrode in world space.
00047      */
00048     explicit WEEGElectrodeObject( WPosition position );
00049 
00050     /**
00051      * Returns the position of the electrode.
00052      * \return The position of the electrode.
00053      */
00054     WPosition getPosition() const;
00055 protected:
00056 private:
00057     WPosition m_position; //!< Position of the electrode in space
00058 };
00059 
00060 typedef std::vector< double > WEEGElectrode;
00061 typedef std::vector< WEEGElectrode > WEEGSegment;
00062 typedef std::vector< WEEGSegment > WEEGSegmentArray;
00063 
00064 typedef std::vector< WEEGElectrodeObject > WEEGElectrodeLibrary;
00065 typedef std::vector< std::pair< std::string, std::string > > WEEGChannelLabels;
00066 /**
00067  * Contains EEG recording data.
00068  * \ingroup dataHandler
00069  */
00070 class WEEG : public WRecording // NOLINT
00071 {
00072 public:
00073     /**
00074      * Constructs a WEEG object from the give infos.
00075      * \param data Array of segments
00076      * \param electrodeLib Information about the electrodes
00077      * \param channelLabels The names of the channels.
00078      */
00079     explicit WEEG( const WEEGSegmentArray& data,
00080                    const WEEGElectrodeLibrary& electrodeLib,
00081                    const WEEGChannelLabels& channelLabels );
00082 
00083     /**
00084      * Constructor creating a quite unusable instance. Useful for prototype mechanism.
00085      */
00086     WEEG();
00087 
00088     /**
00089      * Access operator for single samples.
00090      * \param segment id of segment to access
00091      * \param signal id of signal to access
00092      * \param sample id of sample to access
00093      * \return The data sample at the given location
00094      */
00095     const double& operator()( size_t segment, size_t signal, size_t sample ) const;
00096 
00097     /**
00098      * Returns number of samples of a given segment.
00099      * \param segmentId id of segment beeing inspected.
00100      * \return Number of samples of segment with segmentId.
00101      */
00102     size_t getNumberOfSamples( size_t segmentId ) const;
00103 
00104     /**
00105      * Return the number of channels this EEG has.
00106      * \return Number of channels.
00107      */
00108     size_t getNumberOfChannels() const;
00109 
00110     /**
00111      * Return the number of segments this EEG consists of.
00112      * \return Number of segments.
00113      */
00114     size_t getNumberOfSegments() const;
00115 
00116     /**
00117      * Return the label of a certain channel.
00118      * \param channelId id of channel beeing inspected.
00119      * \return Name of channel with channelId
00120      */
00121     std::string getChannelLabel( size_t channelId ) const;
00122 
00123     /**
00124      * Return the position of the sensor for a certain channel.
00125      * \param channelId id of channel beeing inspected.
00126      * \return Position of sensor of channel channelId
00127      */
00128     WPosition getChannelPosition( size_t channelId ) const;
00129 
00130     /**
00131      * Determines whether this dataset can be used as a texture.
00132      *
00133      * \return true if usable as texture.
00134      */
00135     virtual bool isTexture() const;
00136 
00137     /**
00138      * Gets the name of this prototype.
00139      *
00140      * \return the name.
00141      */
00142     virtual const std::string getName() const;
00143 
00144     /**
00145      * Gets the description for this prototype.
00146      *
00147      * \return the description
00148      */
00149     virtual const std::string getDescription() const;
00150 
00151     /**
00152      * Returns a prototype instantiated with the true type of the deriving class.
00153      *
00154      * \return the prototype.
00155      */
00156     static boost::shared_ptr< WPrototyped > getPrototype();
00157 
00158 protected:
00159     /**
00160      * The prototype as singleton.
00161      */
00162     static boost::shared_ptr< WPrototyped > m_prototype;
00163 
00164 private:
00165     /**
00166      * We have only on sampling rate for all channels.
00167      */
00168     double m_samplingRate;
00169     /**
00170      * Description of electrodes
00171      */
00172     std::map< std::string, size_t > m_electrodeDescriptions;
00173 
00174     /**
00175      * Information about the electrodes.
00176      */
00177     WEEGElectrodeLibrary m_electrodeLibrary;
00178 
00179     /**
00180      * Contains the EEG data as an arry of segements
00181      * of data which consist of an array of electrodes
00182      * which again consist of an array of samples over time.
00183      */
00184     WEEGSegmentArray m_segments;
00185 
00186     /**
00187      * Label for each channel.
00188      */
00189     WEEGChannelLabels m_channelLabels;
00190 
00191     /**
00192      * Is the channel enabled?
00193      */
00194     std::vector< bool > m_channelEnabled;
00195 };
00196 
00197 inline const double& WEEG::operator()( size_t segment, size_t signal, size_t sample ) const
00198 {
00199     return m_segments[segment][signal][sample];
00200 }
00201 
00202 inline size_t WEEG::getNumberOfSamples( size_t segmentId ) const
00203 {
00204     return m_segments[segmentId][0].size();
00205 }
00206 
00207 inline size_t WEEG::getNumberOfChannels() const
00208 {
00209     return m_segments[0].size();
00210 }
00211 
00212 inline size_t WEEG::getNumberOfSegments() const
00213 {
00214     return m_segments.size();
00215 }
00216 
00217 inline std::string WEEG::getChannelLabel( size_t channelId ) const
00218 {
00219     // TODO(wiebel): what is done with the second string of the label?
00220     return  m_channelLabels[channelId].first;
00221 }
00222 
00223 inline WPosition WEEG::getChannelPosition( size_t channelId ) const
00224 {
00225     return  m_electrodeLibrary[channelId].getPosition();
00226 }
00227 
00228 #endif  // WEEG_H