OpenWalnut  1.4.0
WROIArbitrary.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 WROIARBITRARY_H
00026 #define WROIARBITRARY_H
00027 
00028 #include <string>
00029 #include <utility>
00030 #include <vector>
00031 
00032 #include <boost/thread.hpp>
00033 
00034 #include "../common/math/WMatrix.h"
00035 #include "../common/WColor.h"
00036 #include "WPickHandler.h"
00037 #include "WGEViewer.h"
00038 
00039 #include "WTriangleMesh.h"
00040 
00041 #include "WROI.h"
00042 
00043 
00044 class WDataSetScalar;
00045 
00046 /**
00047  * A box containing information on an arbitrarily shaped a region of interest.
00048  */
00049 class WROIArbitrary : public WROI
00050 {
00051 public:
00052     /**
00053      * constructor
00054      * \param nbCoordsX number of vertices in X direction
00055      * \param nbCoordsY number of vertices in Y direction
00056      * \param nbCoordsZ number of vertices in Z direction
00057      * \param mat the matrix transforming the vertices from canonical space
00058      * \param vals the values at the vertices
00059      * \param triMesh
00060      * \param threshold
00061      * \param maxThreshold The maximum of the values.
00062      * \param color the color to use for the ROI.
00063      */
00064     WROIArbitrary( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ,
00065                    const WMatrix< double >& mat,
00066                    const std::vector< float >& vals,
00067                    boost::shared_ptr< WTriangleMesh > triMesh,
00068                    float threshold,
00069                    float maxThreshold,
00070                    WColor color );
00071 
00072     /**
00073      * constructor
00074      * \param nbCoordsX number of vertices in X direction
00075      * \param nbCoordsY number of vertices in Y direction
00076      * \param nbCoordsZ number of vertices in Z direction
00077      * \param mat the matrix transforming the vertices from canonical space
00078      * \param vals the values at the vertices
00079      * \param maxThreshold The maximum of the values.
00080      * \param color the color to use for the ROI.
00081      */
00082     WROIArbitrary( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ,
00083                    const WMatrix< double >& mat,
00084                    const std::vector< float >& vals,
00085                    float maxThreshold,
00086                    WColor color );
00087 
00088 
00089     /**
00090      * destructor
00091      */
00092     virtual ~WROIArbitrary();
00093 
00094     /**
00095      * initalizes the properties
00096      */
00097     void properties();
00098 
00099     /**
00100      * Used as callback to mark a change in the ROI
00101      */
00102     void propertyChanged();
00103 
00104     /**
00105      * setter
00106      * \param threshold
00107      */
00108     void setThreshold( double threshold );
00109 
00110     /**
00111      * getter
00112      *
00113      * \return The threshold on the data in box which leads to the arbitrary ROI
00114      */
00115     double getThreshold();
00116 
00117     /**
00118      * Get the number of vertices in the three coordinate directions
00119      *
00120      * \return A vector containing the numbers of vertices
00121      */
00122     std::vector< size_t > getCoordDimensions();
00123 
00124     /**
00125      * Get the vertex offsets in the three coordinate directions
00126      *
00127      * \return The offsets between point in each of the three coordinate directions
00128      */
00129     std::vector< double > getCoordOffsets();
00130 
00131     /**
00132      * Get the i-th value of the data defining the ROI
00133      * \param i the index of the value
00134      *
00135      * \return The value at the given index.
00136      */
00137     float getValue( size_t i );
00138 
00139     /**
00140      *  updates the graphics
00141      */
00142     virtual void updateGFX();
00143 
00144 protected:
00145 private:
00146     std::vector< size_t > m_nbCoordsVec; //!< The data's number of vertices in X, Y and Z direction.
00147 
00148     WMatrix< double > m_matrix; //!< The 4x4 transformation matrix for the vertices.
00149 
00150     const std::vector< float > m_vals; //!< The data at the vertices.
00151 
00152     boost::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
00153 
00154     WPropDouble m_threshold; //!< the threshold
00155 
00156     /**
00157      * The ROI color
00158      */
00159     WColor m_color;
00160 
00161     /**
00162      * Node callback to handle updates properly
00163      */
00164     class ROIArbNodeCallback : public osg::NodeCallback
00165     {
00166     public: // NOLINT
00167         /**
00168          * operator ()
00169          *
00170          * \param node the osg node
00171          * \param nv the node visitor
00172          */
00173         virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
00174         {
00175             osg::ref_ptr< WROIArbitrary > module = static_cast< WROIArbitrary* > ( node->getUserData() );
00176             if( module )
00177             {
00178                 module->updateGFX();
00179             }
00180             traverse( node, nv );
00181         }
00182     };
00183 };
00184 
00185 #endif  // WROIARBITRARY_H