35 #include <osg/Geometry>
37 #include "WBresenham.h"
38 #include "WBresenhamDBL.h"
39 #include "WCenterlineParameterization.h"
40 #include "WIntegrationParameterization.h"
41 #include "WMVoxelizer.h"
42 #include "WRasterAlgorithm.h"
43 #include "core/common/WColor.h"
44 #include "core/common/WLogger.h"
45 #include "core/common/WPropertyHelper.h"
46 #include "core/common/datastructures/WFiber.h"
47 #include "core/dataHandler/WDataSetFiberVector.h"
48 #include "core/dataHandler/WDataSetScalar.h"
49 #include "core/dataHandler/WGridTransformOrtho.h"
50 #include "core/dataHandler/WSubject.h"
51 #include "core/dataHandler/datastructures/WFiberCluster.h"
52 #include "core/graphicsEngine/WGEColormapping.h"
53 #include "core/graphicsEngine/WGEGeodeUtils.h"
54 #include "core/graphicsEngine/WGEGeometryUtils.h"
55 #include "core/graphicsEngine/WGEManagedGroupNode.h"
56 #include "core/graphicsEngine/WGEUtils.h"
57 #include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
58 #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
59 #include "core/graphicsEngine/shaders/WGEShaderDefineOptions.h"
60 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefine.h"
61 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
62 #include "core/kernel/WKernel.h"
63 #include "core/kernel/WModuleInputData.h"
80 return std::shared_ptr< WModule >(
new WMVoxelizer() );
86 m_voxelsPerUnit =
m_properties->addProperty(
"Voxels per Unit",
"Specified the number of voxels per unit in the coordinate system. This "
87 "is useful to increase the resolution of the grid", 1.0,
m_fullUpdate );
94 m_paramAlgoSelections->addItem(
"By Longest Line",
"Use the longest line and parameterize the bundle along it." );
95 m_paramAlgoSelections->addItem(
"By Centerline",
"Use the centerline and parameterize the bundle along it." );
103 std::shared_ptr< WItemSelection > rasterAlgos(
new WItemSelection() );
104 rasterAlgos->addItem(
"Bresenham",
"Voxelization with 3D Bresenham" );
105 m_rasterAlgo =
m_properties->addProperty(
"Rasterization",
"Which method for rasterizing the tracts", rasterAlgos->getSelectorFirst(),
110 m_phongShading =
m_properties->addProperty(
"Phong shading",
"If enabled, Phong shading gets applied on a per-pixel basis.",
true );
111 m_colorMapping =
m_properties->addProperty(
"Colormapping",
"If enabled, colormapping gets applied on a per-pixel basis.",
false );
122 "The parameter field for the voxelized fibers." );
165 bool selectionPresent = (
m_clusterIC->getData() != NULL );
172 size_t numTracts = ( selectionPresent ?
m_clusterIC->getData()->size() :
m_tractIC->getData()->size() );
174 infoLog() <<
"Start voxelization with: " << numTracts <<
" tracts";
178 if( !result.empty() )
181 if( result.size() == 2 )
204 std::shared_ptr< const WFiberCluster > cluster )
const
209 bb = cluster->getBoundingBox();
213 bb = tracts->getBoundingBox();
221 size_t nbPosX = std::ceil( bb.xMax() - bb.xMin() ) + 1;
222 size_t nbPosY = std::ceil( bb.yMax() - bb.yMin() ) + 1;
223 size_t nbPosZ = std::ceil( bb.zMax() - bb.zMin() ) + 1;
227 mat( 0, 0 ) = mat( 1, 1 ) = mat( 2, 2 ) = 1.0 / nbVoxelsPerUnit;
228 mat( 0, 3 ) = bb.
getMin()[ 0 ];
229 mat( 1, 3 ) = bb.
getMin()[ 1 ];
230 mat( 2, 3 ) = bb.
getMin()[ 2 ];
234 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( nbVoxelsPerUnit * nbPosX,
235 nbVoxelsPerUnit * nbPosY,
236 nbVoxelsPerUnit * nbPosZ,
238 debugLog() <<
"Created grid of size: " << grid->size();
243 std::shared_ptr< const WDataSetFibers > tracts,
244 std::shared_ptr< const WFiberCluster > cluster )
const
246 boost::array< std::shared_ptr< WDataSetScalar >, 2 > result;
253 std::shared_ptr< WGridRegular3D > grid =
constructGrid( tracts, cluster );
255 std::shared_ptr< WRasterAlgorithm > rasterAlgo;
256 std::string rasterName =
m_rasterAlgo->get().at( 0 )->getName();
257 if( rasterName ==
"Bresenham" )
263 errorLog() <<
"Invalid rasterization algorithm selected: " << rasterName <<
" aborting.";
268 std::shared_ptr< WRasterParameterization > paramAlgo;
269 std::string paramName =
m_parameterAlgo->get(
true ).at( 0 )->getName();
270 if( paramName ==
"By Longest Line" )
274 else if( paramName ==
"By Centerline" )
278 else if( paramName ==
"By Integration" )
282 debugLog() << paramName <<
" as parameterization method selected.";
286 rasterAlgo->addParameterizationAlgorithm( paramAlgo );
289 raster( rasterAlgo, tracts, cluster );
291 result[0] = rasterAlgo->generateDataSet();
295 result[1] = paramAlgo->getDataSet();
302 std::shared_ptr< const WFiberCluster > cluster )
const
306 return cluster->getLongestLine();
312 std::shared_ptr< const WFiberCluster > cluster )
const
316 return cluster->getCenterLine();
321 void WMVoxelizer::raster( std::shared_ptr< WRasterAlgorithm > algo, std::shared_ptr< const WDataSetFibers > tracts,
322 std::shared_ptr< const WFiberCluster > cluster )
const
328 std::shared_ptr< const WDataSetFiberVector > clusterTracts = cluster->getDataSetReference();
329 const std::list< size_t >& tractIDs = cluster->getIndices();
330 std::list< size_t >::const_iterator cit = tractIDs.begin();
331 for( cit = tractIDs.begin(); cit != tractIDs.end(); ++cit )
333 algo->raster( clusterTracts->at( *cit ) );
341 algo->raster( *cit );
354 errorLog() <<
"The dataset grid is not regular.";
355 return new osg::Node;
357 WPosition size( grid->getOffsetX(), grid->getOffsetY(), grid->getOffsetZ() );
360 osg::ref_ptr< osg::Geode > geode(
new osg::Geode );
362 std::shared_ptr< WValueSet< double > > valueset = std::dynamic_pointer_cast< WValueSet< double > >( dataset->getValueSet() );
365 errorLog() <<
"The dataset does not contain a double valueset";
366 return new osg::Node;
370 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry );
371 const std::vector< double >& values = *valueset->rawDataVectorPointer();
372 for(
size_t i = 0; i < values.size(); ++i )
374 if( values[i] != 0.0 )
378 double transparency = ( values[i] <= 1.0 ? values[i] : 1.0 );
379 WColor color( 1.0, 0.0, 0.0, transparency );
387 geode->addDrawable( geometry );
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
Implements basic Bresenham algorithm for rasterization.
Stores the direction if a line in a separate dataset for each voxel.
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.
Represents a simple set of WFibers.
static void apply(osg::ref_ptr< osg::Node > node, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
Apply the colormapping to the specified node.
This class adds some convenience methods to WGEGroupNode.
This class enables you to add arbitrary nodes that get post-processed in screen space.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
This is a WGEShaderDefineOptions class which additionally uses a property to automatically control th...
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
A grid that has parallelepiped cells which all have the same proportion.
std::shared_ptr< WGridRegular3DTemplate > SPtr
Convenience typedef for a std::shared_ptr< WGridRegular3DTemplate >.
Stores the direction if a line in a separate dataset for each voxel.
A class containing a list of named items.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Traces a given set of deterministic tracts as given by a dataset of deterministic tracts (optionally ...
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...
WPropBool m_antialiased
Enable/disable anti-aliased rasterization of voxels.
WPropBool m_colorMapping
add colormapping
WMVoxelizer()
Default Constructor.
WPropDouble m_voxelsPerUnit
The number of voxels per unit in the coordinate system.
WPropBool m_phongShading
Add lighting to the scene.
WPropSelection m_rasterAlgo
List for selecting the rasterization method.
void raster(std::shared_ptr< WRasterAlgorithm > algo, std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Performs rasterization with the given algorithm on either all tracts or only a subset if given.
std::shared_ptr< WModuleInputData< const WFiberCluster > > m_clusterIC
Input connector for an optional selection of some fibers in the fiber dataset via a cluster.
WPropSelection m_parameterAlgo
The actually selected parameterization algorithm.
std::shared_ptr< WFiber > longestLine(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster=std::shared_ptr< const WFiberCluster >()) const
Finds and returns a copy of the longest line (in term of #points) in the dataset, or in a subset of i...
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_paramOC
Output providing parameterization to other algorithms.
std::shared_ptr< WGridRegular3D > constructGrid(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Constructs a grid out of the current tract dataset or out of a subset (selection) of this dataset.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
OSG root node for this module.
std::shared_ptr< WItemSelection > m_paramAlgoSelections
The available parameterization algorithms.
osg::ref_ptr< osg::Node > genDataSetGeode(std::shared_ptr< WDataSetScalar > dataset) const
Builds an OSG geode where all voxels inside the dataSet which are not zero are drawn as cuboids.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_voxelizedOC
Output connector for a voxelized cluster.
WPropBool m_renderingActive
Enable/disable rendering of voxels.
virtual ~WMVoxelizer()
Default Destructor.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WCondition > m_fullUpdate
module is performing an expensive update
virtual void connectors()
Initialize the connectors this module is using.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WFiber > centerLine(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster=std::shared_ptr< const WFiberCluster >()) const
Finds and returns a copy of the center line in the dataset, or in a subset of it specified by the giv...
boost::array< std::shared_ptr< WDataSetScalar >, 2 > generateDatasets(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Generates a intensity dataset where each tract is rasterized into.
std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_tractIC
Input connector for a fiber dataset.
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
vector_type::const_iterator const_iterator
Compares to std::vector type.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this out data connector with proper type and add it to...
Class representing a single module of OpenWalnut.
boost::filesystem::path m_localPath
The path where the module binary resides in.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
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.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
WPropBool m_active
True whenever the module should be active.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
This only is a 3d double vector.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
void createCube(osg::ref_ptr< osg::Geometry > geometry, const WPosition &position, const WPosition &size, const WColor &color)
Create an arbitrary cube and insert it into the given geometry.