Commit 94caaae8 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 27615638 83ace5f8
......@@ -26,6 +26,9 @@
#define WGRID_H
#include <cstddef>
#include <utility>
#include "../math/WPosition.h"
/**
* Base class to all grid types, e.g. a regular grid.
......@@ -53,6 +56,11 @@ public:
*/
size_t size() const;
/**
* Returns the two positions representing the bounding box of the grid.
*/
virtual std::pair< wmath::WPosition, wmath::WPosition > getBoundingBox() const = 0;
protected:
private:
......
......@@ -26,6 +26,7 @@
#define WGRIDREGULAR3D_H
#include <vector>
#include <utility>
#include <boost/shared_ptr.hpp>
......@@ -193,6 +194,11 @@ public:
*/
wmath::WPosition getOrigin() const;
/**
* Returns the two positions representing the bounding box of the grid.
*/
std::pair< wmath::WPosition, wmath::WPosition > getBoundingBox() const;
/**
* Returns the i-th position on the grid.
* \param i id of position to be obtained
......@@ -423,5 +429,11 @@ inline wmath::WPosition WGridRegular3D::getOrigin() const
return m_origin;
}
inline std::pair< wmath::WPosition, wmath::WPosition > WGridRegular3D::getBoundingBox() const
{
return std::make_pair( getOrigin(),
getOrigin() + getDirectionX() * getNbCoordsX() + getDirectionY() * getNbCoordsY() + getDirectionZ() * getNbCoordsZ() );
}
#endif // WGRIDREGULAR3D_H
......@@ -32,6 +32,7 @@
#include "../WDataSetSingle.h"
#include "../WValueSet.h"
#include "../WGrid.h"
#include "../WGridRegular3D.h"
#include "../WDataHandlerEnums.h"
/**
......@@ -49,7 +50,7 @@ public:
void setUp( void )
{
// create dummies, since they are needed in almost every test
gridDummy = boost::shared_ptr< WGrid >( new WGrid( 1 ) );
gridDummy = boost::shared_ptr< WGrid >( new WGridRegular3D( 1, 1, 1, 1, 1, 1 ) );
std::vector< int8_t > data( 1, 1 );
valueSetDummy = boost::shared_ptr< WValueSet< int8_t > >( new WValueSet< int8_t >( 0, 1, data, W_DT_INT8 ) );
}
......@@ -80,7 +81,7 @@ public:
*/
void testGetGrid( void )
{
boost::shared_ptr< WGrid > other = boost::shared_ptr< WGrid >( new WGrid( 1 ) );
boost::shared_ptr< WGrid > other = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 1, 1, 1, 1, 1, 1 ) );
WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
TS_ASSERT_EQUALS( dataSetSingle.getGrid(), gridDummy );
TS_ASSERT_DIFFERS( dataSetSingle.getGrid(), other );
......
......@@ -25,10 +25,34 @@
#ifndef WGRID_TEST_H
#define WGRID_TEST_H
#include <utility>
#include <cxxtest/TestSuite.h>
#include "../WGrid.h"
/**
* Dummy class for testing the abstract class WGrid
*/
class Dummy : public WGrid
{
friend class WGridTest;
public:
/**
* Standard constructor of Dummy class.
*/
explicit Dummy( size_t size )
: WGrid( size )
{
}
virtual std::pair< wmath::WPosition, wmath::WPosition > getBoundingBox() const
{
return std::make_pair( wmath::WPosition( 0, 0, 0 ), wmath::WPosition( 1, 1, 1 ) );
}
};
/**
* Tests the WGrid class.
*/
......@@ -36,19 +60,19 @@ class WGridTest : public CxxTest::TestSuite
{
public:
/**
* Ensure that nothing is thrown when an instance is created.
* Checks if the Dummy is instanceable.
*/
void testInstantiation( void )
{
TS_ASSERT_THROWS_NOTHING( WGrid grid( 1 ) );
TS_ASSERT_THROWS_NOTHING( Dummy d( 1 ) );
}
/**
* After instantiation there should be no positions.
* After instantiation there should be only 1 positions.
*/
void testSize( void )
{
WGrid grid( 1 );
Dummy grid( 1 );
TS_ASSERT_EQUALS( grid.size(), 1 );
}
};
......
......@@ -29,6 +29,7 @@
#include "../common/WLogger.h"
#include "../modules/coordinateSystem/WMCoordinateSystem.h"
#include "../modules/boundingBox/WMBoundingBox.h"
#include "../modules/data/WMData.h"
#include "../modules/distanceMap/WMDistanceMap.h"
#include "../modules/eegView/WMEEGView.h"
......@@ -69,6 +70,7 @@ void WModuleFactory::load()
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_prototypesLock );
// currently the prototypes are added by hand. This will be done automatically later.
m_prototypes.insert( boost::shared_ptr< WModule >( new WMBoundingBox() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMData() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMNavSlices() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMFiberDisplay() ) );
......
//---------------------------------------------------------------------------
//
// 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 <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#include "../../common/WStringUtils.h"
#include "../../dataHandler/WGridRegular3D.h"
#include "../../kernel/WKernel.h"
#include "../../math/WPosition.h"
#include "../../math/WVector3D.h"
#include "../data/WMData.h"
#include "WMBoundingBox.h"
WMBoundingBox::WMBoundingBox():
WModule()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
}
WMBoundingBox::~WMBoundingBox()
{
// cleanup
removeConnectors();
}
boost::shared_ptr< WModule > WMBoundingBox::factory() const
{
return boost::shared_ptr< WModule >( new WMBoundingBox() );
}
const std::string WMBoundingBox::getName() const
{
return "Bounding Box";
}
const std::string WMBoundingBox::getDescription() const
{
return "Shows the bounding box of a data set.";
}
void WMBoundingBox::moduleMain()
{
// use the m_input "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() );
// signal ready state
ready();
// loop until the module container requests the module to quit
while ( !m_shutdownFlag() )
{
sleep( 3 ); // TODO(wiebel): remove this
// acquire data from the input connector
m_dataSet = m_input->getData();
if ( !m_dataSet )
{
// ok, the output has not yet sent data
// NOTE: see comment at the end of this while loop for m_moduleState
debugLog() << "Waiting for data ...";
m_moduleState.wait();
continue;
}
assert( m_dataSet );
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_dataSet->getGrid() );
assert( grid && "Seems that grid is of wrong type." );
std::pair< wmath::WPosition, wmath::WPosition > bb = grid->getBoundingBox();
m_bBoxNode = osg::ref_ptr< WGEGroupNode >( new WGEGroupNode );
m_bBoxNode->insert( wge::generateBoundingBoxGeode( bb.first, bb.second, WColor( 0.3, 0.3, 0.3, 1 ) ) );
WGraphicsEngine::getGraphicsEngine()->getScene()->insert( m_bBoxNode );
// this waits for m_moduleState to fire. By default, this is only the m_shutdownFlag condition.
// NOTE: you can add your own conditions to m_moduleState using m_moduleState.add( ... )
m_moduleState.wait();
}
}
void WMBoundingBox::connectors()
{
// initialize connectors
m_input = boost::shared_ptr< WModuleInputData < WDataSetSingle > >(
new WModuleInputData< WDataSetSingle >( shared_from_this(),
"in", "The dataset to filter" )
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_input );
// call WModules initialization
WModule::connectors();
}
void WMBoundingBox::properties()
{
// ( m_properties->addInt( "Thickness", 1 ) )->connect( boost::bind( &WMBoundingBox::slotPropertyChanged, this, _1 ) );
}
void WMBoundingBox::slotPropertyChanged( std::string propertyName )
{
// if( propertyName == "Filter Size" )
// {
// // TODO(wiebel): need code here
// }
// else
{
std::cout << propertyName << std::endl;
assert( 0 && "This property name is not supported by this function yet." );
}
}
//---------------------------------------------------------------------------
//
// 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 WMBOUNDINGBOX_H
#define WMBOUNDINGBOX_H
#include <map>
#include <string>
#include <vector>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Uniform>
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../math/WVector3D.h"
class WPickHandler;
/**
* Show the bounding box of a WDataSetSingle
* \ingroup modules
*/
class WMBoundingBox : public WModule
{
public:
/**
* Standard constructor.
*/
WMBoundingBox();
/**
* Destructor.
*/
~WMBoundingBox();
/**
* 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 of module.
*/
virtual const std::string getDescription() const;
/**
* Determine what to do if a property was changed.
* \param propertyName Name of the property.
*/
void slotPropertyChanged( std::string propertyName );
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual boost::shared_ptr< WModule > factory() const;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
private:
osg::ref_ptr< WGEGroupNode > m_bBoxNode; //!< OSG root node for this module
boost::shared_ptr< WModuleInputData< WDataSetSingle > > m_input; //!< Input connector required by this module.
boost::shared_ptr< WDataSetSingle > m_dataSet; //!< Pointer providing access to the treated data set in the whole module.
};
#endif // WMBOUNDINGBOX_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment