OpenWalnut  1.4.0
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 
27 #include <sstream>
28 #include <string>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "../common/exceptions/WOutOfBounds.h"
33 #include "../common/math/linearAlgebra/WPosition.h"
34 #include "WEEGPositionsLibrary.h"
35 #include "WEEGChannelInfo.h"
36 #include "exceptions/WDHException.h"
37 #include "io/WPagerEEG.h"
38 
39 
40 WEEGChannelInfo::WEEGChannelInfo( std::size_t channelID,
41  boost::shared_ptr< WPagerEEG > pager,
42  boost::shared_ptr< WEEGPositionsLibrary > positionsLibrary )
43 {
44  if( !pager )
45  {
46  throw WDHException( std::string( "Couldn't construct new EEG channel info: pager invalid" ) );
47  }
48 
49  if( !positionsLibrary )
50  {
51  throw WDHException( std::string( "Couldn't construct new EEG channel info: positions library invalid" ) );
52  }
53 
54  if( channelID >= pager->getNumberOfChannels() )
55  {
56  std::ostringstream stream;
57  stream << "The EEG has no channel number " << channelID;
58  throw WOutOfBounds( stream.str() );
59  }
60 
61  m_unit = pager->getChannelUnit( channelID );
62  m_label = pager->getChannelLabel( channelID );
63 
64  try
65  {
66  m_position = positionsLibrary->getPosition( m_label );
67  m_hasPosition = true;
68  }
69  catch( const WOutOfBounds& )
70  {
71  m_hasPosition = false;
72  }
73 }
74 
75 std::string WEEGChannelInfo::getUnit() const
76 {
77  return m_unit;
78 }
79 
80 std::string WEEGChannelInfo::getLabel() const
81 {
82  return m_label;
83 }
84 
86 {
87  if( m_hasPosition )
88  {
89  return m_position;
90  }
91  else
92  {
93  throw WDHException( std::string( "The position of this electrode is unknown." ) );
94  }
95 }