OpenWalnut  1.5.0dev
WMArbitraryROIs.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 WMARBITRARYROIS_H
26 #define WMARBITRARYROIS_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <osg/Geode>
33 
34 #include "core/graphicsEngine/WGEGroupNode.h"
35 #include "core/graphicsEngine/WROI.h"
36 #include "core/graphicsEngine/WTriangleMesh.h"
37 #include "core/kernel/WModule.h"
38 #include "core/kernel/WModuleInputData.h"
39 #include "core/kernel/WModuleOutputData.h"
40 
41 class WROIArbitrary;
42 class WROIBox;
43 class WDataSetScalar;
44 
45 /**
46  * Create non uniformly shaped ROIs for fiber selection.
47  *
48  * \ingroup modules
49  */
50 class WMArbitraryROIs: public WModule
51 {
52 public:
53  /**
54  *
55  */
57 
58  /**
59  *
60  */
61  virtual ~WMArbitraryROIs();
62 
63  /**
64  * Gives back the name of this module.
65  * \return the module's name.
66  */
67  virtual const std::string getName() const;
68 
69  /**
70  * Gives back a description of this module.
71  * \return description to module.
72  */
73  virtual const std::string getDescription() const;
74 
75  /**
76  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
77  * should never be initialized or modified in some other way. A simple new instance is required.
78  *
79  * \return the prototype used to create every module in OpenWalnut.
80  */
81  virtual std::shared_ptr< WModule > factory() const;
82 
83  /**
84  * Get the icon for this module in XPM format.
85  * \return The icon.
86  */
87  virtual const char** getXPMIcon() const;
88 
89 protected:
90  /**
91  * Entry point after loading the module. Runs in separate thread.
92  */
93  virtual void moduleMain();
94 
95  /**
96  * Initialize the connectors this module is using.
97  */
98  virtual void connectors();
99 
100  /**
101  * Initialize the properties for this module.
102  */
103  virtual void properties();
104 
105  /**
106  * Callback for m_active. Overwrite this in your modules to handle m_active changes separately.
107  */
108  virtual void activate();
109 
110 private:
111  /**
112  * create a selection box to mark the area in a dataset which will provide the data for a new ROI
113  */
114  void initSelectionROI();
115 
116  /**
117  * creates a new dataset
118  */
119  void createCutDataset();
120 
121  /**
122  * renders the temporary ROI
123  */
124  void renderMesh();
125 
126  /**
127  * creates a ROI and adds it to the ROI manager
128  */
129  void finalizeROI();
130 
131  /**
132  * Removes the ROI and cleans up the scene.
133  */
134  void cleanup();
135 
136  /**
137  * copies the data from the input dataset which is marked by the selection box, otherwise data is zero
138  *
139  * \param inGrid The grid from which the area will be cut
140  * \param vals The values on the original grid
141  *
142  * \return Data in the selected box
143  */
144  template< typename T > std::shared_ptr< std::vector< float > > cutArea( std::shared_ptr< WGrid > inGrid,
145  std::shared_ptr< WValueSet< T > > vals );
146 
147  /**
148  * This condition denotes whether we need to recompute the surface
149  */
150  std::shared_ptr< WCondition > m_recompute;
151 
152  std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input; //!< Input connector required by this module.
153 
154  std::shared_ptr< const WDataSetScalar > m_dataSet; //!< pointer to dataSet to be able to access it throughout the whole module.
155 
156  std::shared_ptr< WValueSet< float > > m_newValueSet; //!< pointer to the created cut valueSet
157 
158  osg::ref_ptr< WROIBox > m_selectionROI; //!< stores a pointer to the cutting tool ROI
159 
160  /**
161  * A condition used to notify about changes in several properties.
162  */
163  std::shared_ptr< WCondition > m_propCondition;
164 
165  /**
166  * A trigger which can be used to trigger some kind of operation.
167  */
168  WPropTrigger m_finalizeTrigger;
169 
170  WPropDouble m_threshold; //!< the threshold for the ROI
171 
172  WPropColor m_surfaceColor; //!< Property determining the color for the surface
173 
174  osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node. We need it to be able to update it when callback is invoked.
175 
176  osg::ref_ptr< osg::Geode > m_outputGeode; //!< Pointer to geode containing the glpyhs
177 
178  std::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
179 
180  bool m_showSelector; //!< flag indication if the temporary ROI should be shown;
181 
182  WPosition m_lastMinPos; //!< the last know min position of the ROI if there was any
183  WPosition m_lastMaxPos; //!< the last know max position of the ROI if there was any
184 };
185 
186 #endif // WMARBITRARYROIS_H
This data set type contains scalars as values.
Create non uniformly shaped ROIs for fiber selection.
virtual void activate()
Callback for m_active.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
Input connector required by this module.
void initSelectionROI()
create a selection box to mark the area in a dataset which will provide the data for a new ROI
void finalizeROI()
creates a ROI and adds it to the ROI manager
virtual void moduleMain()
Entry point after loading the module.
virtual const std::string getDescription() const
Gives back a description of this module.
osg::ref_ptr< WROIBox > m_selectionROI
stores a pointer to the cutting tool ROI
std::shared_ptr< WCondition > m_recompute
This condition denotes whether we need to recompute the surface.
WPosition m_lastMaxPos
the last know max position of the ROI if there was any
virtual const std::string getName() const
Gives back the name of this module.
osg::ref_ptr< osg::Geode > m_outputGeode
Pointer to geode containing the glpyhs.
void renderMesh()
renders the temporary ROI
virtual void connectors()
Initialize the connectors this module is using.
WPropColor m_surfaceColor
Property determining the color for the surface.
void cleanup()
Removes the ROI and cleans up the scene.
WPropDouble m_threshold
the threshold for the ROI
std::shared_ptr< const WDataSetScalar > m_dataSet
pointer to dataSet to be able to access it throughout the whole module.
WPropTrigger m_finalizeTrigger
A trigger which can be used to trigger some kind of operation.
osg::ref_ptr< WGEGroupNode > m_moduleNode
Pointer to the modules group node. We need it to be able to update it when callback is invoked.
std::shared_ptr< WValueSet< float > > m_newValueSet
pointer to the created cut valueSet
void createCutDataset()
creates a new dataset
WPosition m_lastMinPos
the last know min position of the ROI if there was any
std::shared_ptr< WTriangleMesh > m_triMesh
This triangle mesh is provided as output through the connector.
std::shared_ptr< std::vector< float > > cutArea(std::shared_ptr< WGrid > inGrid, std::shared_ptr< WValueSet< T > > vals)
copies the data from the input dataset which is marked by the selection box, otherwise data is zero
bool m_showSelector
flag indication if the temporary ROI should be shown;
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void properties()
Initialize the properties for this module.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
This only is a 3d double vector.
A box containing information on an arbitrarily shaped a region of interest.
Definition: WROIArbitrary.h:49
A box representing a region of interest.
Definition: WROIBox.h:49
Base Class for all value set types.
Definition: WValueSet.h:47