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