OpenWalnut  1.4.0
WDataSetRawHARDI.cpp
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 <string>
00026 #include <vector>
00027 
00028 #include "../common/WAssert.h"
00029 #include "WDataSetSingle.h"
00030 
00031 #include "WDataSetRawHARDI.h"
00032 
00033 // prototype instance as singleton
00034 boost::shared_ptr< WPrototyped > WDataSetRawHARDI::m_prototype = boost::shared_ptr< WPrototyped >();
00035 
00036 WDataSetRawHARDI::WDataSetRawHARDI( boost::shared_ptr< WValueSetBase > newValueSet,
00037                                     boost::shared_ptr< WGrid > newGrid,
00038                                     boost::shared_ptr< std::vector< WVector3d > > newGradients,
00039                                     double diffusionBValue )
00040     : WDataSetSingle( newValueSet, newGrid ), m_gradients( newGradients ), m_diffusionBValue( diffusionBValue )
00041 {
00042     WAssert( newValueSet, "No value set given." );
00043     WAssert( newGrid, "No grid given." );
00044     WAssert( newGradients, "No gradients given." );
00045     WAssert( newValueSet->size() == newGrid->size(), "Number of voxel entries unequal number of positions in grid." );
00046     WAssert( newValueSet->order() != newGradients->size(), "Number of gradients unequal number of entries in value set." );
00047     buildGradientIndexes();
00048 }
00049 
00050 void WDataSetRawHARDI::buildGradientIndexes()
00051 {
00052     std::vector< size_t > validIndices;
00053     for( size_t i = 0; i < m_gradients->size(); ++i )
00054     {
00055         const WVector3d& grad = ( *m_gradients )[ i ];
00056         if( ( grad[ 0 ] != 0.0 ) || ( grad[ 1 ] != 0.0 ) || ( grad[ 2 ] != 0.0 ) )
00057         {
00058             m_nonZeroGradientIndexes.push_back( i );
00059         }
00060         else
00061         {
00062             m_zeroGradientIndexes.push_back( i );
00063         }
00064     }
00065 }
00066 
00067 WDataSetRawHARDI::WDataSetRawHARDI()
00068     : WDataSetSingle()
00069 {
00070 }
00071 
00072 WDataSetRawHARDI::~WDataSetRawHARDI()
00073 {
00074 }
00075 
00076 WDataSetSingle::SPtr WDataSetRawHARDI::clone( boost::shared_ptr< WValueSetBase > newValueSet ) const
00077 {
00078     return WDataSetSingle::SPtr( new WDataSetRawHARDI( newValueSet, getGrid(), m_gradients, getDiffusionBValue() ) );
00079 }
00080 
00081 WDataSetSingle::SPtr WDataSetRawHARDI::clone( boost::shared_ptr< WGrid > newGrid ) const
00082 {
00083     return WDataSetSingle::SPtr( new WDataSetRawHARDI( getValueSet(), newGrid, m_gradients, getDiffusionBValue() ) );
00084 }
00085 
00086 WDataSetSingle::SPtr WDataSetRawHARDI::clone() const
00087 {
00088     return WDataSetSingle::SPtr( new WDataSetRawHARDI( getValueSet(), getGrid(), m_gradients, getDiffusionBValue() ) );
00089 }
00090 
00091 boost::shared_ptr< WPrototyped > WDataSetRawHARDI::getPrototype()
00092 {
00093     if( !m_prototype )
00094     {
00095         m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetRawHARDI() );
00096     }
00097 
00098     return m_prototype;
00099 }
00100 
00101 const WVector3d& WDataSetRawHARDI::getGradient( size_t index ) const
00102 {
00103 #ifdef DEBUG
00104   return m_gradients->at( index );
00105 #else
00106   return (*m_gradients)[ index ];
00107 #endif
00108 }
00109 
00110 std::vector< WVector3d > const& WDataSetRawHARDI::getOrientations() const
00111 {
00112     return *m_gradients;
00113 }
00114 
00115 double WDataSetRawHARDI::getDiffusionBValue() const
00116 {
00117   return m_diffusionBValue;
00118 }
00119 
00120 std::size_t WDataSetRawHARDI::getNumberOfMeasurements() const
00121 {
00122   return m_gradients->size();
00123 }
00124 
00125 const std::string WDataSetRawHARDI::getName() const
00126 {
00127     return "WDataSetRawHARDI";
00128 }
00129 
00130 const std::string WDataSetRawHARDI::getDescription() const
00131 {
00132     return "Contains HARDI measurements.";
00133 }