OpenWalnut 1.2.5

WDataSetSegmentation.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 WDATASETSEGMENTATION_H
00026 #define WDATASETSEGMENTATION_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #include "../kernel/WModuleInputData.h"
00034 #include "WDataSet.h"
00035 #include "WDataSetScalar.h"
00036 #include "WDataSetSingle.h"
00037 
00038 
00039 /**
00040  * A dataset that stores the segmentation of the brain into CSF, white and gray matter.
00041  *
00042  * It also offers some convenience functions for this task.
00043  *
00044  * \ingroup dataHandler
00045  */
00046 class WDataSetSegmentation : public WDataSetSingle
00047 {
00048 public:
00049 
00050     /**
00051      * Constructs an instance out of a value set and a grid.
00052      *
00053      * \param segmentation the value set to use
00054      * \param grid the grid which maps world space to the value set
00055      */
00056     WDataSetSegmentation( boost::shared_ptr< WValueSetBase > segmentation, boost::shared_ptr< WGrid > grid );
00057 
00058     /**
00059      * Constructs an instance out of three WDataSetScalar.
00060      *
00061      * \param whiteMatter the value set to use
00062      * \param grayMatter the value set to use
00063      * \param cerebrospinalFluid the value set to use
00064      */
00065     WDataSetSegmentation( boost::shared_ptr< WDataSetScalar > whiteMatter,
00066                           boost::shared_ptr< WDataSetScalar > grayMatter,
00067                           boost::shared_ptr< WDataSetScalar > cerebrospinalFluid );
00068     /**
00069      * Construct an empty and unusable instance. This is useful for prototypes.
00070      */
00071     WDataSetSegmentation();
00072 
00073     /**
00074      * Destroys this DataSet instance
00075      */
00076     virtual ~WDataSetSegmentation();
00077 
00078     /**
00079      * Returns the white matter probability for the given cell.
00080      *
00081      * \param x, y, z The coordinates in grid space.
00082      *
00083      * \return white matter probability.
00084      */
00085     float getWMProbability( int x, int y, int z ) const;
00086 
00087     /**
00088      * Returns the gray matter probability for the given cell.
00089      *
00090      * \param x, y, z The coordinates in grid space.
00091      *
00092      * \return gray matter probability.
00093      */
00094     float getGMProbability( int x, int y, int z ) const;
00095 
00096     /**
00097      * Returns the cerebrospinal fluid probability for the given cell.
00098      *
00099      * \param x, y, z The coordinates in grid space.
00100      *
00101      * \return cerebrospinal fluid probability.
00102      */
00103     float getCSFProbability( int x, int y, int z ) const;
00104 
00105     // template < typename T > T getWMValueAt( int x, int y, int z ) const;
00106 
00107     // template < typename T > T getGMValueAt( int x, int y, int z ) const;
00108 
00109     // template < typename T > T getCSFValueAt( int x, int y, int z ) const;
00110 
00111     /**
00112      * Gets the name of this prototype.
00113      *
00114      * \return the name.
00115      */
00116     virtual const std::string getName() const;
00117 
00118     /**
00119      * Gets the description for this prototype.
00120      *
00121      * \return the description
00122      */
00123     virtual const std::string getDescription() const;
00124 
00125     /**
00126      * Creates a copy (clone) of this instance but allows to change the valueset. Unlike copy construction, this is a very useful function if you
00127      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00128      *
00129      * \param newValueSet the new valueset.
00130      *
00131      * \return the clone
00132      */
00133     virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WValueSetBase > newValueSet ) const;
00134 
00135     /**
00136      * Creates a copy (clone) of this instance but allows to change the grid. Unlike copy construction, this is a very useful function if you
00137      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00138      *
00139      * \param newGrid the new grid.
00140      *
00141      * \return the clone
00142      */
00143     virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WGrid > newGrid ) const;
00144 
00145     /**
00146      * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
00147      * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
00148      *
00149      * \return the clone
00150      */
00151     virtual WDataSetSingle::SPtr clone() const;
00152 
00153     /**
00154      * Returns a prototype instantiated with the true type of the deriving class.
00155      *
00156      * \return the prototype.
00157      */
00158     static boost::shared_ptr< WPrototyped > getPrototype();
00159 
00160     /**
00161      * Enumerator for the three different classification types.
00162      */
00163     enum matterType
00164     {
00165       whiteMatter = 0,
00166       grayMatter = 1,
00167       csf = 2
00168     };
00169 
00170     // double getValueAt( int x, int y, int z );
00171 
00172     // void countVoxel() const;
00173 
00174 protected:
00175     /**
00176      * The prototype as singleton.
00177      */
00178     static boost::shared_ptr< WPrototyped > m_prototype;
00179 
00180 private:
00181     /**
00182      * This helper function converts the probabilities given by three seperate WDataSetScalars to one WValueSetBase.
00183      *
00184      * \param whiteMatter the probabilities for white matter.
00185      * \param grayMatter the probabilities for gray matter.
00186      * \param cerebrospinalFluid the probabilities for cerebrospinal fluid.
00187      *
00188      * \return The probabilities in one value set.
00189      */
00190     static boost::shared_ptr< WValueSetBase > convert( boost::shared_ptr< WDataSetScalar > whiteMatter,
00191                                                        boost::shared_ptr< WDataSetScalar > grayMatter,
00192                                                        boost::shared_ptr< WDataSetScalar > cerebrospinalFluid );
00193 
00194     /**
00195      * This helper function copies the content of several WDataSetScalars to one std::vector.
00196      *
00197      * \param dataSets the std::vector of data WDataSetScalars.
00198      *
00199      * \return The WDataSetScalars merged to a std::vector.
00200      */
00201     template< typename T > static std::vector< T > copyDataSetsToArray( const std::vector< boost::shared_ptr< WDataSetScalar > > &dataSets );
00202 };
00203 
00204 template< typename T > std::vector< T >
00205 WDataSetSegmentation::copyDataSetsToArray( const std::vector< boost::shared_ptr< WDataSetScalar > > &dataSets )
00206 {
00207     const size_t voxelDim = dataSets.size();
00208     size_t countVoxels = 0;
00209     if ( !dataSets.empty() ) countVoxels = ( *dataSets.begin() )->getValueSet()->size();
00210 
00211     std::vector< T > data( countVoxels * voxelDim );
00212 
00213     // loop over images
00214     size_t dimIndex = 0;
00215     for ( std::vector< boost::shared_ptr< WDataSetScalar > >::const_iterator it = dataSets.begin(); it != dataSets.end(); it++ )
00216     {
00217       for( size_t voxelNumber = 0; voxelNumber < countVoxels; voxelNumber++ )
00218       {
00219         data[ voxelNumber * voxelDim + dimIndex ] =  ( boost::shared_static_cast< WDataSetSingle > ( *it ) )->getValueAt< T >( voxelNumber );
00220       }
00221       dimIndex++;
00222     }
00223     return data;
00224 }
00225 
00226 
00227 // template < typename T > T WDataSetSegmentation::getValueAt( int x, int y, int z )
00228 // {
00229 //     boost::shared_ptr< WValueSet< T > > vs = boost::shared_dynamic_cast< WValueSet< T > >( m_valueSet );
00230 //     boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
00231 //
00232 //     size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
00233 //
00234 //     T v = vs->getScalar( id );
00235 //     return v;
00236 // }
00237 
00238 
00239 #endif  // WDATASETSEGMENTATION_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends