Commit 83ace5f8 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] new module showing as simple bounding box for a dataset with a grid

parent 64e85ea5
......@@ -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