OpenWalnut  1.5.0dev
WEEGChannelInfo.cpp
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 #include <cstddef>
26 #include <memory>
27 #include <sstream>
28 #include <string>
29 
30 
31 #include "../common/exceptions/WOutOfBounds.h"
32 #include "../common/math/linearAlgebra/WPosition.h"
33 #include "WEEGChannelInfo.h"
34 #include "WEEGPositionsLibrary.h"
35 #include "exceptions/WDHException.h"
36 #include "io/WPagerEEG.h"
37 
38 
39 WEEGChannelInfo::WEEGChannelInfo( std::size_t channelID,
40  std::shared_ptr< WPagerEEG > pager,
41  std::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
42 {
43  if( !pager )
44  {
45  throw WDHException( std::string( "Couldn't construct new EEG channel info: pager invalid" ) );
46  }
47 
48  if( !positionsLibrary )
49  {
50  throw WDHException( std::string( "Couldn't construct new EEG channel info: positions library invalid" ) );
51  }
52 
53  if( channelID >= pager->getNumberOfChannels() )
54  {
55  std::ostringstream stream;
56  stream << "The EEG has no channel number " << channelID;
57  throw WOutOfBounds( stream.str() );
58  }
59 
60  m_unit = pager->getChannelUnit( channelID );
61  m_label = pager->getChannelLabel( channelID );
62 
63  try
64  {
65  m_position = positionsLibrary->getPosition( m_label );
66  m_hasPosition = true;
67  }
68  catch( const WOutOfBounds& )
69  {
70  m_hasPosition = false;
71  }
72 }
73 
74 std::string WEEGChannelInfo::getUnit() const
75 {
76  return m_unit;
77 }
78 
79 std::string WEEGChannelInfo::getLabel() const
80 {
81  return m_label;
82 }
83 
85 {
86  if( m_hasPosition )
87  {
88  return m_position;
89  }
90  else
91  {
92  throw WDHException( std::string( "The position of this electrode is unknown." ) );
93  }
94 }
General purpose exception and therefore base class for all DataHandler related exceptions.
Definition: WDHException.h:40
std::string m_label
label of the channel
WPosition m_position
position of the electrode
WPosition getPosition() const
Get the position of the electrode.
std::string m_unit
unit used by the recording of the channel
std::string getLabel() const
Get the label of the channel.
bool m_hasPosition
whether there is a valid position for this electrode
WEEGChannelInfo(std::size_t channelID, std::shared_ptr< WPagerEEG > pager, std::shared_ptr< WEEGPositionsLibrary > positionsLibrary)
Constructor.
std::string getUnit() const
Get the unit used by the recording of the channel.
Indicates invalid element access of a container.
Definition: WOutOfBounds.h:37
This only is a 3d double vector.