Commit 8429bb78 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[FIX] Removed OSG_BIND_PER_PRIMITIVE usages in this module.

parent 9db2e499
../../src/edgeBundling/resources/WMEdgeBundling.png
\ No newline at end of file
../../src/gaussProcesses/gpView/WMGpView.png
\ No newline at end of file
......@@ -32,16 +32,13 @@
#include "detTractClustering/WMDetTractClustering.h"
#include "detTractCulling/WMDetTractCulling.h"
#include "directionHistogram/WMDirectionHistogram.h"
#include "edgeBundling/WMEdgeBundling.h"
#include "fiberColoring/WMFiberColoring.h"
#include "gaussProcesses/detTract2GPConvert/WMDetTract2GPConvert.h"
#include "gaussProcesses/detTractClusteringGP/WMDetTractClusteringGP.h"
#include "gaussProcesses/gpView/WMGpView.h"
#include "loadClusters/WMLoadClusters.h"
#include "lineGuidedSlice/WMLineGuidedSlice.h"
#include "matrixWriter/WMMatrixWriter.h"
#include "writeClusters/WMWriteClusters.h"
//#include "bundleParamView/WMBundleParamView.h"
#include "WToolkit.h"
// This file's purpose is to provide a list of modules as entry point for OpenWalnut's module loader.
......@@ -56,9 +53,7 @@ extern "C" void WLoadModule( WModuleList& m ) // NOLINT
m.push_back( WModule::SPtr( new WMDetTractClusteringGP ) );
m.push_back( WModule::SPtr( new WMDetTractCulling ) );
m.push_back( WModule::SPtr( new WMDirectionHistogram ) );
m.push_back( WModule::SPtr( new WMEdgeBundling ) );
m.push_back( WModule::SPtr( new WMFiberColoring ) );
m.push_back( WModule::SPtr( new WMGpView ) );
m.push_back( WModule::SPtr( new WMLineGuidedSlice ) );
m.push_back( WModule::SPtr( new WMLoadClusters ) );
m.push_back( WModule::SPtr( new WMMatrixWriter ) );
......
......@@ -31,7 +31,7 @@
#include <utility>
#include <vector>
#include <osg/Geometry>
#include <osg/ShapeDrawable>
#include "core/common/datastructures/WColoredVertices.h"
#include "core/common/math/WPlane.h"
......@@ -415,42 +415,16 @@ template< class Container > inline osg::ref_ptr< osg::Geode > WMClusterSlicer::g
double size,
const WColor& color ) const
{
osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
osg::ref_ptr< osg::Vec3Array > normals = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
for( typename Container::const_iterator point = points->begin(); point != points->end(); ++point )
{
const WPosition& pos = *point;
std::vector< WPosition > corners;
corners.reserve( 8 );
double halfSize = size / 2.0;
corners.push_back( WPosition( pos[0] - halfSize, pos[1] - halfSize, pos[2] - halfSize ) );
corners.push_back( WPosition( pos[0] + halfSize, pos[1] - halfSize, pos[2] - halfSize ) );
corners.push_back( WPosition( pos[0] + halfSize, pos[1] - halfSize, pos[2] + halfSize ) );
corners.push_back( WPosition( pos[0] - halfSize, pos[1] - halfSize, pos[2] + halfSize ) );
corners.push_back( WPosition( pos[0] - halfSize, pos[1] + halfSize, pos[2] - halfSize ) );
corners.push_back( WPosition( pos[0] + halfSize, pos[1] + halfSize, pos[2] - halfSize ) );
corners.push_back( WPosition( pos[0] + halfSize, pos[1] + halfSize, pos[2] + halfSize ) );
corners.push_back( WPosition( pos[0] - halfSize, pos[1] + halfSize, pos[2] + halfSize ) );
osg::ref_ptr< osg::Vec3Array > ver = wge::generateCuboidQuads( corners ); // do not use. use osg::Shape for boxes
vertices->insert( vertices->end(), ver->begin(), ver->end() );
osg::ref_ptr< osg::Vec3Array > nor = wge::generateCuboidQuadNormals( corners );
normals->insert( normals->end(), nor->begin(), nor->end() );
geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, vertices->size() - ver->size(), ver->size() ) );
osg::Box* box = new osg::Box( *point, size / 2.0 );
osg::ShapeDrawable* boxDrawable = new osg::ShapeDrawable(box);
boxDrawable->setColor( color );
geode->addDrawable( boxDrawable );
}
geometry->setVertexArray( vertices );
colors->push_back( color );
geometry->setColorArray( colors );
geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
geometry->setNormalArray( normals );
geometry->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE ); // this will not compile on OSG 3.2. Please use osg::Shape for creating
// boxes
osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
geode->addDrawable( geometry );
return geode;
}
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <vector>
#include "WBundlerCPU.h"
WBundlerCPU::WBundlerCPU()
: WObjectNDIP< WEdgeBundlingInterface >( "Edge Bundler CPU", "Bundles edges of fibers (CPU implementation)" )
{
m_stiffness = m_properties->addProperty( "Stiffness", "Variability of fiber sample points", 0.5 );
m_stiffness->setMin( 0.0 );
m_stiffness->setMax( 1.0 );
m_fixedEndings = m_properties->addProperty( "Fixed Ending", "If true, endings of fibers will not change positions", true );
m_maxCurvature = m_properties->addProperty( "Max curvature", "Curvature Threshold as constraint for moving positions", 1.0 );
m_maxCurvature->setMin( 0.0 );
m_maxCurvature->setMax( 1.0 );
m_curveSegments = m_properties->addProperty( "Curvature Segments", "How many segments used for Max Curvature threshold", 1 );
m_curveSegments->setMin( 0 );
m_minDistance = m_properties->addProperty( "Min Point Distance", "How close may edges packed", 0.0 );
m_minDistance->setMin( 0.0 );
m_minDistance->setMax( 1.0 );
m_maxExtension = m_properties->addProperty( "Max Extension", "Percentage how much fibers may be elongated", 100.0 );
m_maxExtension->setMin( 0.0 );
m_maxContraction = m_properties->addProperty( "Max Contraction", "Percentage how much fibers may be shortened", 50.0 );
m_maxContraction->setMin( 0.0 );
m_maxContraction->setMax( 100.0 );
m_maxRadius = m_properties->addProperty( "Attraction Radius", "Only segments within this radius will contribute to attraction", 0.0 );
m_maxRadius->setMin( 0.0 );
m_maxIter = m_properties->addProperty( "Max Iterations", "Only this number of iterations are performed", 0 );
m_maxIter->setMin( 0 );
}
WBundlerCPU::~WBundlerCPU()
{
}
WDataSetFibers::SPtr WBundlerCPU::operator()( WProgress::SPtr progress, WBoolFlag const & shutdown, WDataSetFibers::SPtr fibers,
WDataSetScalar::SPtr mask )
{
if( !fibers )
{
wlog::debug( "WBundlerCPU" ) << "Got an invalid fiber dataset, no bundling performed";
return fibers;
}
// Assume that there is a valid dataset
WDataSetFibers::IndexArray fibStart = fibers->getLineStartIndexes();
WDataSetFibers::LengthArray fibLen = fibers->getLineLengths();
WDataSetFibers::VertexArray fibVerts = fibers->getVertices();
WDataSetFibers::IndexArray newStarts( new std::vector< size_t > );
WDataSetFibers::LengthArray newLen( new std::vector< size_t > );
WDataSetFibers::VertexArray newVerts( new std::vector< float > );
WDataSetFibers::IndexArray newReverseMap( new std::vector< size_t > );
for( size_t fidx = 0; fidx < fibStart->size(); ++fidx ) // iterate over fibers
{
if( shutdown )
{
wlog::info( "WBundlerCPU" ) << "Abort bundling due to shutdown request.";
break;
}
++*progress;
size_t firstPointIdx = fibStart->at( fidx );
size_t lastPointIdx = fibStart->at( fidx ) + 3 * ( fibLen->at( fidx ) - 1 );
newStarts->push_back( newVerts->size() / 3 );
newVerts->push_back( fibVerts->at( firstPointIdx ) );
newVerts->push_back( fibVerts->at( firstPointIdx + 1 ) );
newVerts->push_back( fibVerts->at( firstPointIdx + 2 ) );
newVerts->push_back( fibVerts->at( lastPointIdx ) );
newVerts->push_back( fibVerts->at( lastPointIdx + 1 ) );
newVerts->push_back( fibVerts->at( lastPointIdx + 2 ) );
newLen->push_back( 2 );
newReverseMap->push_back( fidx );
newReverseMap->push_back( fidx );
}
return WDataSetFibers::SPtr( new WDataSetFibers( newVerts, newStarts, newLen, newReverseMap ) );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WBUNDLERCPU_H
#define WBUNDLERCPU_H
#include <core/common/WObjectNDIP.h>
#include <core/common/WProperties.h>
#include "WEdgeBundlingInterface.h"
/**
* Implementation of edge bundling for 3D fibers on CPU.
*/
class WBundlerCPU : public WObjectNDIP< WEdgeBundlingInterface >
{
public:
/**
* Constructor.
*/
WBundlerCPU();
/**
* Destructor.
*/
virtual ~WBundlerCPU();
/**
* Implements edge bundling on CPU.
*
* \copydetails WEdgeBundlingInterface::operator()()
*/
virtual WDataSetFibers::SPtr operator()( WProgress::SPtr progress, WBoolFlag const &shutdown, WDataSetFibers::SPtr fibers,
WDataSetScalar::SPtr mask );
protected:
private:
/**
* Stiffness, 0 means all points of a fiber may change position, 1 means all points of a fiber may not change position.
*/
WPropDouble m_stiffness;
/**
* If true, end points of fibers may not change position, even if stiffness would allow this.
*/
WPropBool m_fixedEndings;
/**
* Maximal allowed curvature between a number of segments. 0 means, only straight segments are allowed, 1 means every possb. cuvature is allowed.
*/
WPropDouble m_maxCurvature;
/**
* Number of segements used for curvature computation. 0 disables curvature threshold, 1 means: last segment and
* current segment is used, 2 means: the last two segments and current segments contributes to curvature and so on.
*/
WPropInt m_curveSegments;
/**
* There should be a minimal distance between points. 0 means, two points may have exact the same position.
*/
WPropDouble m_minDistance;
/**
* Percentage up to which a fiber may be elongated. 0 percent means, length must be conserved. 100 percent means length may be doubled.
*/
WPropDouble m_maxExtension;
/**
* Percentage up to which a fiber may be shrunk. 0 percent means, length must be conserved. 50 percent means length may be halved.
*/
WPropDouble m_maxContraction;
/**
* Only segments within this radius should contribute to attraction computation. 0 disables this feature and all segments may contribute.
*/
WPropDouble m_maxRadius;
/**
* Strength of angle based attraction.
*/
WPropDouble m_angleBasedAttraction;
/**
* Maximum number of iterations for computing the force directed layout. 0 means disabled and another criteria must be implemented to abort computation.
*/
WPropInt m_maxIter;
};
#endif // WBUNDLERCPU_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WEdgeBundlingInterface.h"
WEdgeBundlingInterface::~WEdgeBundlingInterface()
{
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WEDGEBUNDLINGINTERFACE_H
#define WEDGEBUNDLINGINTERFACE_H
#include <core/common/WProgress.h>
#include <core/common/WFlag.h>
#include <core/dataHandler/WDataSetFibers.h>
#include <core/dataHandler/WDataSetScalar.h>
/**
* Interface all edge bundling algorithms for 3D fibers should follow.
*/
class WEdgeBundlingInterface
{
public:
/**
* Applies edge bundling on the given fibers.
*
* \param progress This will indicate bundling progress.
* \param shutdown While computing bundling, it should abort also in case of shutdown.
* \param fibers The fibers which should be bundled.
* \param mask Optional mask defining allowed space within segments may be shifted.
*
* \return Bundled fibers
*/
virtual WDataSetFibers::SPtr operator()( WProgress::SPtr progress, WBoolFlag const &shutdown, WDataSetFibers::SPtr fibers,
WDataSetScalar::SPtr mask ) = 0;
/**
* Destructor.
*/
virtual ~WEdgeBundlingInterface();
protected:
private:
};
#endif // WEDGEBUNDLINGINTERFACE_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include <core/common/WStrategyHelper.h>
#include <core/dataHandler/WDataSetFibers.h>
#include <core/dataHandler/WDataSetScalar.h>
#include <core/kernel/WKernel.h>
#include <core/kernel/WModuleInputData.h>
// For now we will implement a CPU version first and later do OpenCL implementation
// #include "WOpenCLCode.h"
#include "WMEdgeBundling.h"
#include "WBundlerCPU.h"
WMEdgeBundling::WMEdgeBundling():
WModule(),
m_strategy( "Edge Bundling Algorithms", "Select one algorithm to bundle fibers via edge bundling", NULL,
"Bundler", "A list of all known bundling strategies" )
{
m_strategy.addStrategy( WBundlerCPU::SPtr( new WBundlerCPU() ) );
}
WMEdgeBundling::~WMEdgeBundling()
{
}
boost::shared_ptr< WModule > WMEdgeBundling::factory() const
{
return boost::shared_ptr< WModule >( new WMEdgeBundling() );
}
const std::string WMEdgeBundling::getName() const
{
return "Edge Bundling";
}
const std::string WMEdgeBundling::getDescription() const
{
return "Performs edge bundling on line data.";
}
void WMEdgeBundling::connectors()
{
m_fibersIC = WModuleInputData< WDataSetFibers >::createAndAdd( shared_from_this(), "fibers", "The line data to bundle." );
m_maskIC = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "mask", "Optional mask, specifies valid space for segments" );
m_fibersOC = WModuleOutputData< WDataSetFibers >::createAndAdd( shared_from_this(), "bundledFibers", "The bundled line data." );
WModule::connectors();
}
void WMEdgeBundling::properties()
{
m_properties->addProperty( m_strategy.getProperties() );
WModule::properties();
}
void WMEdgeBundling::requirements()
{
}
void WMEdgeBundling::moduleMain()
{
// get notified about data changes
m_moduleState.setResetable( true, true );
m_moduleState.add( m_fibersIC->getDataChangedCondition() );
m_moduleState.add( m_maskIC->getDataChangedCondition() );
m_moduleState.add( m_strategy.getProperties()->getUpdateCondition() );
ready();
// main loop
while( !m_shutdownFlag() )
{
infoLog() << "Waiting ...";
m_moduleState.wait();
// woke up since the module is requested to finish?
if( m_shutdownFlag() )
{
break;
}
WDataSetScalar::SPtr mask = m_maskIC->getData();
WDataSetFibers::SPtr fibers = m_fibersIC->getData();
if( !fibers )
{
continue;
}
WProgress::SPtr progress( new WProgress( "Bundling Edges", fibers->size() ) );
m_progress->addSubProgress( progress );
debugLog() << "Starting bundling edges";
m_fibersOC->updateData( m_strategy()->operator()( progress, m_shutdownFlag, fibers, mask ) );
progress->finish();
m_progress->removeSubProgress( progress );
debugLog() << "Finished bundling edges";
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMEDGEBUNDLING_H
#define WMEDGEBUNDLING_H
#include <string>
#include <core/common/WStrategyHelper.h>
#include <core/common/WObjectNDIP.h>
#include <core/kernel/WModule.h>
template< class T > class WModuleInputData;
template< class T > class WModuleOutputData;
class WDataSetFibers;
class WDataSetScalar;
#include "WEdgeBundlingInterface.h"
/**
* Bundles lines (aka fibers, tracts, streamlines, etc) using a force directed edge bundling method.
* \ingroup modules
*/
class WMEdgeBundling: public WModule
{
public:
/**
* Creates a edge bundling module for fiber datasets.
*/
WMEdgeBundling();
/**
* Cleans up!
*/
virtual ~WMEdgeBundling();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;