OpenWalnut
1.4.0
|
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 #include <vector> 00026 00027 #include "WDataSetDipoles.h" 00028 00029 // prototype instance as singleton 00030 boost::shared_ptr< WPrototyped > WDataSetDipoles::m_prototype = boost::shared_ptr< WPrototyped >(); 00031 00032 00033 WDataSetDipoles::WDataSetDipoles() : 00034 m_maxMagnitude( 0.0f ) 00035 { 00036 } 00037 00038 WDataSetDipoles::WDataSetDipoles( WPosition dipPos, std::vector<float> mags, std::vector<float> times, 00039 size_t firstTimeStep, size_t lastTimeStep ) : 00040 m_maxMagnitude( 0.0f ) 00041 { 00042 WAssert( mags.size() == times.size(), "There has to be a magnitude for every time and vice versa." ); 00043 for( size_t id = 0; id < times.size() - 1; ++id ) 00044 { 00045 WAssert( times[id] < times[id+1], "Times need to be ascending." ); 00046 } 00047 addDipole( dipPos, mags, times, firstTimeStep, lastTimeStep ); 00048 } 00049 00050 WDataSetDipoles::~WDataSetDipoles() 00051 { 00052 } 00053 00054 boost::shared_ptr< WPrototyped > WDataSetDipoles::getPrototype() 00055 { 00056 if( !m_prototype ) 00057 { 00058 m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetDipoles() ); 00059 } 00060 00061 return m_prototype; 00062 } 00063 00064 size_t WDataSetDipoles::addDipole( WPosition dipPos, std::vector<float> mags, std::vector<float> times, 00065 size_t firstTimeStep, size_t lastTimeStep ) 00066 { 00067 Dipole dipole; 00068 dipole.m_dipolePosition = dipPos; 00069 dipole.m_magnitudes = mags; 00070 dipole.m_times = times; 00071 dipole.m_firstTimeStep = firstTimeStep; 00072 dipole.m_lastTimeStep = lastTimeStep; 00073 m_dipoles.push_back( dipole ); 00074 00075 for( size_t id = 0u; id < mags.size(); ++id ) 00076 { 00077 if( mags[id] > m_maxMagnitude ) 00078 { 00079 m_maxMagnitude = mags[id]; 00080 } 00081 } 00082 00083 return m_dipoles.size() - 1; 00084 } 00085 00086 WPosition WDataSetDipoles::getPosition( size_t dipoleId ) 00087 { 00088 return m_dipoles[dipoleId].m_dipolePosition; 00089 } 00090 00091 float WDataSetDipoles::getStartTime( size_t dipoleId ) const 00092 { 00093 return m_dipoles[dipoleId].m_times[m_dipoles[dipoleId].m_firstTimeStep]; 00094 } 00095 00096 float WDataSetDipoles::getEndTime( size_t dipoleId ) const 00097 { 00098 return m_dipoles[dipoleId].m_times[m_dipoles[dipoleId].m_lastTimeStep]; 00099 } 00100 00101 std::vector<float> WDataSetDipoles::getTimes( size_t dipoleId ) const 00102 { 00103 const Dipole& dipole = m_dipoles[dipoleId]; 00104 const std::vector<float>::const_iterator& begin = dipole.m_times.begin(); 00105 00106 return std::vector<float>( begin + dipole.m_firstTimeStep, begin + ( dipole.m_lastTimeStep + 1u ) ); 00107 } 00108 00109 std::vector<float> WDataSetDipoles::getMagnitudes( size_t dipoleId ) const 00110 { 00111 const Dipole& dipole = m_dipoles[dipoleId]; 00112 const std::vector<float>::const_iterator& begin = dipole.m_magnitudes.begin(); 00113 00114 return std::vector<float>( begin + dipole.m_firstTimeStep, begin + ( dipole.m_lastTimeStep + 1u ) ); 00115 } 00116 00117 size_t WDataSetDipoles::getNumberOfDipoles() 00118 { 00119 return m_dipoles.size(); 00120 } 00121 00122 float WDataSetDipoles::getMaxMagnitude() const 00123 { 00124 return m_maxMagnitude; 00125 } 00126 00127 float WDataSetDipoles::getMagnitude( float time, size_t dipoleId ) 00128 { 00129 std::vector<float>& times = m_dipoles[dipoleId].m_times; 00130 std::vector<float>& magnitudes = m_dipoles[dipoleId].m_magnitudes; 00131 00132 if( time < times[0] || time > times.back() ) 00133 { 00134 return 0; 00135 } 00136 else 00137 { 00138 size_t upperBoundId = 1u; 00139 for( ; upperBoundId < times.size() - 1u; ++upperBoundId ) 00140 { 00141 if( time < times[upperBoundId] ) 00142 { 00143 break; 00144 } 00145 } 00146 float scale = ( time - times[upperBoundId-1] ) / ( times[upperBoundId] - times[upperBoundId-1] ); 00147 float magnitude = magnitudes[upperBoundId-1] + scale * ( magnitudes[upperBoundId] - magnitudes[upperBoundId-1] ); 00148 return magnitude; 00149 } 00150 }