30 #include <osg/Geometry>
31 #include <osg/LightModel>
32 #include <osg/Material>
33 #include <osg/PolygonMode>
34 #include <osg/StateAttribute>
35 #include <osg/StateSet>
37 #include "WMArbitraryROIs.h"
38 #include "WMArbitraryROIs.xpm"
39 #include "core/common/WAssert.h"
40 #include "core/common/algorithms/WMarchingLegoAlgorithm.h"
41 #include "core/dataHandler/WDataSetScalar.h"
42 #include "core/graphicsEngine/WROIArbitrary.h"
43 #include "core/graphicsEngine/WROIBox.h"
44 #include "core/kernel/WKernel.h"
45 #include "core/kernel/WROIManager.h"
46 #include "core/kernel/WSelectionManager.h"
51 WMArbitraryROIs::WMArbitraryROIs():
56 m_showSelector( true )
60 WMArbitraryROIs::~WMArbitraryROIs()
73 return arbitraryROI_xpm;
79 return "Arbitrary ROIs";
84 return "Create non uniformly shaped ROIs for fiber selection. The ROI "
85 "is what is enclosed by a surface created as isosurface from "
86 "the data within a ROI box.";
92 m_input = std::shared_ptr< WModuleInputData < WDataSetScalar > >(
203 std::shared_ptr< WValueSetBase > newValueSet;
205 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
207 size_t order = ( *m_dataSet ).getValueSet()->order();
208 size_t vDim = ( *m_dataSet ).getValueSet()->dimension();
211 std::shared_ptr< std::vector< float > > data(
new std::vector< float >() );
213 switch( ( *m_dataSet ).getValueSet()->getDataType() )
215 case W_DT_UNSIGNED_CHAR:
217 std::shared_ptr< WValueSet< unsigned char > > vals;
218 vals = std::dynamic_pointer_cast< WValueSet< unsigned char > >( ( *m_dataSet ).getValueSet() );
219 WAssert( vals,
"Data type and data type indicator must fit." );
220 data =
cutArea( ( *m_dataSet ).getGrid(), vals );
225 std::shared_ptr< WValueSet< int16_t > > vals;
226 vals = std::dynamic_pointer_cast< WValueSet< int16_t > >( ( *m_dataSet ).getValueSet() );
227 WAssert( vals,
"Data type and data type indicator must fit." );
228 data =
cutArea( ( *m_dataSet ).getGrid(), vals );
231 case W_DT_SIGNED_INT:
233 std::shared_ptr< WValueSet< int32_t > > vals;
234 vals = std::dynamic_pointer_cast< WValueSet< int32_t > >( ( *m_dataSet ).getValueSet() );
235 WAssert( vals,
"Data type and data type indicator must fit." );
236 cutArea( ( *m_dataSet ).getGrid(), vals );
237 data =
cutArea( ( *m_dataSet ).getGrid(), vals );
242 std::shared_ptr< WValueSet< float > > vals;
243 vals = std::dynamic_pointer_cast< WValueSet< float > >( ( *m_dataSet ).getValueSet() );
244 WAssert( vals,
"Data type and data type indicator must fit." );
245 data =
cutArea( ( *m_dataSet ).getGrid(), vals );
250 std::shared_ptr< WValueSet< double > > vals;
251 vals = std::dynamic_pointer_cast< WValueSet< double > >( ( *m_dataSet ).getValueSet() );
252 WAssert( vals,
"Data type and data type indicator must fit." );
253 data =
cutArea( ( *m_dataSet ).getGrid(), vals );
257 WAssert(
false,
"Unknown data type in ArbitraryROIs module" );
261 m_triMesh = mlAlgo.generateSurface( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(),
262 grid->getTransformationMatrix(),
267 template<
typename T >
270 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( inGrid );
272 size_t nx = grid->getNbCoordsX();
273 size_t ny = grid->getNbCoordsY();
274 size_t nz = grid->getNbCoordsZ();
276 double dx = grid->getOffsetX();
277 double dy = grid->getOffsetY();
278 double dz = grid->getOffsetZ();
280 size_t xMin =
static_cast<size_t>(
m_selectionROI->getMinPos()[0] / dx );
281 size_t yMin =
static_cast<size_t>(
m_selectionROI->getMinPos()[1] / dy );
282 size_t zMin =
static_cast<size_t>(
m_selectionROI->getMinPos()[2] / dz );
283 size_t xMax =
static_cast<size_t>(
m_selectionROI->getMaxPos()[0] / dx );
284 size_t yMax =
static_cast<size_t>(
m_selectionROI->getMaxPos()[1] / dy );
285 size_t zMax =
static_cast<size_t>(
m_selectionROI->getMaxPos()[2] / dz );
287 std::shared_ptr< std::vector< float > > newVals(
new std::vector< float >( nx * ny * nz, 0 ) );
290 for( z = 0; z < nz; ++z )
292 for( y = 0 ; y < ny; ++y )
294 for( x = 0 ; x < nx; ++x )
296 if( ( x > xMin ) && ( x < xMax ) && ( y > yMin ) && ( y < yMax ) && ( z > zMin ) && ( z < zMax ) )
298 ( *newVals )[ x + nx * y + nx * ny * z ] =
static_cast< float >( vals->getScalar( x + nx * y + nx * ny * z ) );
312 osg::Geometry* surfaceGeometry =
new osg::Geometry();
313 m_outputGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
317 surfaceGeometry->setVertexArray(
m_triMesh->getVertexArray() );
321 surfaceGeometry->setNormalArray(
m_triMesh->getVertexNormalArray() );
322 surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
326 osg::Vec4Array* colors =
new osg::Vec4Array;
327 colors->push_back( osg::Vec4( 0.2f, 1.0f, 0.2f, 1.0f ) );
328 surfaceGeometry->setColorArray( colors );
329 surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
331 osg::DrawElementsUInt* surfaceElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
333 std::vector< size_t >tris =
m_triMesh->getTriangles();
334 surfaceElement->reserve( tris.size() );
336 for(
unsigned int vertId = 0; vertId < tris.size(); ++vertId )
338 surfaceElement->push_back( tris[vertId] );
340 surfaceGeometry->addPrimitiveSet( surfaceElement );
344 osg::ref_ptr<osg::LightModel> lightModel =
new osg::LightModel();
345 lightModel->setTwoSided(
true );
346 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
347 state->setMode( GL_BLEND, osg::StateAttribute::ON );
371 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
372 osg::ref_ptr< WROI > newROI = osg::ref_ptr< WROI >(
new WROIArbitrary( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(),
373 grid->getTransformationMatrix(),
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
std::shared_ptr< WSelectionManager > getSelectionManager()
get for selection manager
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WROIManager > getRoiManager()
get for roi manager
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
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.
Creates a non interpolated triangulation of an isosurface.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
virtual void activate()
Callback for m_active.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
This only is a 3d double vector.
A box containing information on an arbitrarily shaped a region of interest.
A box representing a region of interest.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)