OpenWalnut  1.3.1
WROIArbitrary.h
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 #ifndef WROIARBITRARY_H
26 #define WROIARBITRARY_H
27 
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include <boost/thread.hpp>
33 
34 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
35 #include "../common/math/WMatrix.h"
36 #include "../common/WColor.h"
37 #include "WPickHandler.h"
38 #include "WGEViewer.h"
39 
40 #include "WTriangleMesh.h"
41 
42 #include "WROI.h"
43 
44 
45 class WDataSetScalar;
46 
47 /**
48  * A box containing information on an arbitrarily shaped a region of interest.
49  */
50 class WROIArbitrary : public WROI
51 {
52 public:
53  /**
54  * constructor
55  * \param nbCoordsX number of vertices in X direction
56  * \param nbCoordsY number of vertices in Y direction
57  * \param nbCoordsZ number of vertices in Z direction
58  * \param mat the matrix transforming the vertices from canonical space
59  * \param vals the values at the vertices
60  * \param triMesh
61  * \param threshold
62  * \param maxThreshold The maximum of the values.
63  * \param color the color to use for the ROI.
64  */
65  WROIArbitrary( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ,
66  const WMatrix< double >& mat,
67  const std::vector< float >& vals,
68  boost::shared_ptr< WTriangleMesh > triMesh,
69  float threshold,
70  float maxThreshold,
71  WColor color );
72 
73  /**
74  * constructor
75  * \param nbCoordsX number of vertices in X direction
76  * \param nbCoordsY number of vertices in Y direction
77  * \param nbCoordsZ number of vertices in Z direction
78  * \param mat the matrix transforming the vertices from canonical space
79  * \param vals the values at the vertices
80  * \param maxThreshold The maximum of the values.
81  * \param color the color to use for the ROI.
82  */
83  WROIArbitrary( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ,
84  const WMatrix< double >& mat,
85  const std::vector< float >& vals,
86  float maxThreshold,
87  WColor color );
88 
89 
90  /**
91  * destructor
92  */
93  virtual ~WROIArbitrary();
94 
95  /**
96  * initalizes the properties
97  */
98  void properties();
99 
100  /**
101  *
102  */
103  void propertyChanged();
104 
105  /**
106  * setter
107  * \param threshold
108  */
109  void setThreshold( double threshold );
110 
111  /**
112  * getter
113  *
114  * \return The threshold on the data in box which leads to the arbitrary ROI
115  */
116  double getThreshold();
117 
118  /**
119  * Get the number of vertices in the three coordinate directions
120  *
121  * \return A vector containing the numbers of vertices
122  */
123  std::vector< size_t > getCoordDimensions();
124 
125  /**
126  * Get the vertex offsets in the three coordinate directions
127  *
128  * \return The offsets between point in each of the three coordinate directions
129  */
130  std::vector< double > getCoordOffsets();
131 
132  /**
133  * Get the i-th value of the data defining the ROI
134  * \param i the index of the value
135  *
136  * \return The value at the given index.
137  */
138  float getValue( size_t i );
139 
140  /**
141  * updates the graphics
142  */
143  virtual void updateGFX();
144 
145 protected:
146 private:
147  std::vector< size_t > m_nbCoordsVec; //!< The data's number of vertices in X, Y and Z direction.
148 
149  WMatrix< double > m_matrix; //!< The 4x4 transformation matrix for the vertices.
150 
151  const std::vector< float > m_vals; //!< The data at the vertices.
152 
153  boost::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
154 
155  WPropDouble m_threshold; //!< the threshold
156 
157  /**
158  * The ROI color
159  */
160  WColor m_color;
161 
162  /**
163  * Node callback to handle updates properly
164  */
165  class ROIArbNodeCallback : public osg::NodeCallback
166  {
167  public: // NOLINT
168  /**
169  * operator ()
170  *
171  * \param node the osg node
172  * \param nv the node visitor
173  */
174  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
175  {
176  osg::ref_ptr< WROIArbitrary > module = static_cast< WROIArbitrary* > ( node->getUserData() );
177  if( module )
178  {
179  module->updateGFX();
180  }
181  traverse( node, nv );
182  }
183  };
184 };
185 
186 #endif // WROIARBITRARY_H