Commit b18e7413 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents ada27463 1a319ff7
......@@ -96,19 +96,20 @@ protected:
*/
WObjectNDIP( std::string name, std::string description, const char** icon = NULL );
WProperties::SPtr m_properties; //!< the properties of the object.
private:
std::string m_name; //!< the name
std::string m_description; //!< the description
const char** m_icon; //!< the icon
WProperties::SPtr m_properties; //!< the properties of the object.
};
template< typename T >
WObjectNDIP< T >::WObjectNDIP( std::string name, std::string description, const char** icon ):
m_properties( new WProperties( name, description ) ),
m_name( name ),
m_description( description ),
m_icon( icon ),
m_properties( new WProperties( name, description ) )
m_icon( icon )
{
// init
}
......
......@@ -31,6 +31,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "WLogger.h"
#include "WItemSelection.h"
#include "WItemSelector.h"
#include "WSharedSequenceContainer.h"
......@@ -268,6 +269,7 @@ void WStrategyHelper< StrategyType >::addStrategy( typename StrategyType::SPtr s
// add strategy to selector:
m_possibleSelections->addItem( strategy->getName(), strategy->getDescription(), strategy->getIcon() );
m_properties->addProperty( strategy->getProperties() );
// we can safely unlock m_strategies now. This is needed since an update in m_possibleSelectionProp requests a read lock and will deadlock if
// w was not unlocked.
......
......@@ -222,9 +222,9 @@ std::string WModule::deprecated() const
return "";
}
WModuleMetaInformation WModule::getMetaInformation() const
WModuleMetaInformation::ConstSPtr WModule::getMetaInformation() const
{
return WModuleMetaInformation( getName() );
return m_meta;
}
void WModule::initialize()
......@@ -239,6 +239,9 @@ void WModule::initialize()
// set the module name as default runtime name
m_runtimeName->set( getName() );
// initialize module meta information
m_meta = WModuleMetaInformation::SPtr( new WModuleMetaInformation( shared_from_this() ) );
// initialize connectors and properties
requirements();
connectors();
......
......@@ -52,6 +52,7 @@
#include "WModuleConnectorSignals.h"
#include "WModuleSignals.h"
#include "WModuleTypes.h"
#include "WModuleMetaInformation.h"
class WModuleConnector;
class WModuleContainer;
......@@ -59,7 +60,6 @@ class WModuleFactory;
class WModuleLoader;
class WModuleInputConnector;
class WModuleOutputConnector;
class WModuleMetaInformation;
template < typename T > class WModuleInputData;
template < typename T > class WModuleInputForwardData;
template < typename T > class WModuleOutputData;
......@@ -252,8 +252,8 @@ public:
boost::shared_ptr< WModuleContainer > getAssociatedContainer() const;
/**
* 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.
* Due to the prototype design pattern used to build modules, this method returns a new instance of this module. NOTE: it
* should never be initialized or modified in some other way.
*
* \return the prototype used to create every module in OpenWalnut.
*/
......@@ -424,7 +424,7 @@ protected:
*
* \return the meta info object for this module.
*/
virtual WModuleMetaInformation getMetaInformation() const;
virtual WModuleMetaInformation::ConstSPtr getMetaInformation() const;
/**
* Manages connector initialization. Gets called by module container.
......@@ -692,6 +692,11 @@ private:
*/
// boost::shared_mutex m_outputConnectorsLock;
/**
* Module meta information. Set by the factory creating the module instance.
*/
WModuleMetaInformation::SPtr m_meta;
/**
* Signal fired whenever a module main thread is ready.
*/
......
......@@ -27,25 +27,37 @@
#include "../common/WException.h"
#include "../common/WLogger.h"
#include "../common/WStructuredTextParser.h"
#include "WModule.h"
#include "WModuleMetaInformation.h"
WModuleMetaInformation::WModuleMetaInformation( std::string name ):
m_name( name )
m_name( name ),
m_loaded( false )
{
// initialize members
}
WModuleMetaInformation::WModuleMetaInformation( std::string name, boost::filesystem::path metafile ):
m_name( name )
WModuleMetaInformation::WModuleMetaInformation( boost::shared_ptr< WModule > module ):
m_name( module->getName() ),
m_loaded( false )
{
// check whether file exists
boost::filesystem::path metafile = module->getLocalPath() / "META";
if( !boost::filesystem::exists( metafile ) )
{
return;
}
// try loading it
try
{
m_metaData = WStructuredTextParser::StructuredValueTree( metafile );
m_loaded = true;
}
catch( const WException& e )
{
wlog::error( "Module (" + name + ")" ) << "Meta file load failed. Message: " << e.what();
wlog::error( "Module (" + m_name + ")" ) << "Meta file load failed. Message: " << e.what();
}
}
......
......@@ -32,7 +32,7 @@
#include "../common/WStructuredTextParser.h"
#include "WModule.h"
class WModule;
/**
* A class abstracting module meta information. It encapsulates module name, description, icon, author lists, help resources, online resources
......@@ -61,13 +61,12 @@ public:
explicit WModuleMetaInformation( std::string name );
/**
* Construct a meta info object that loads all information from the specified file. If the file does not exist or could not be parsed, only
* Construct a meta info object that loads all information from the specified file. If the file exist and could not be parsed, only
* an error log is printed. No exception is thrown.
*
* \param name the module name
* \param metafile the path to the module's meta file. Usually, this is somewhere in WModule::m_localPath.
* \param module The module to load the meta file for.
*/
WModuleMetaInformation( std::string name, boost::filesystem::path metafile );
explicit WModuleMetaInformation( boost::shared_ptr< WModule > module );
/**
* Destructor. Cleans internal list.
......@@ -84,6 +83,12 @@ private:
* The tree representing the data
*/
WStructuredTextParser::StructuredValueTree m_metaData;
/**
* If true, m_metaData should be queried in all getters. If false, you can query m_meta but it will only tell you that the desired value
* could not be found.
*/
bool m_loaded;
};
#endif // WMODULEMETAINFORMATION_H
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <ctime>
#include <cstdlib>
#include <vector>
#include "core/common/WLogger.h"
......@@ -32,10 +33,10 @@
#include "WDataCreatorRandom.h"
WDataCreatorRandom::WDataCreatorRandom():
WObjectNDIP< WMDataCreatorScalar::DataCreatorInterface >( "Random", "Creates a noise volume." ),
m_rand( std::time( 0 ) ),
m_values01( 0.0, 1.0 )
WObjectNDIP< WMDataCreatorScalar::DataCreatorInterface >( "Random", "Creates a noise volume." )
{
m_rangeMin = m_properties->addProperty( "Range Min", "The minimum value in the data.", 0.0 );
m_rangeMax = m_properties->addProperty( "Range Max", "The maximum value in the data.", 1.0 );
}
WDataCreatorRandom::~WDataCreatorRandom()
......@@ -44,6 +45,8 @@ WDataCreatorRandom::~WDataCreatorRandom()
WValueSetBase::SPtr WDataCreatorRandom::operator()( WGridRegular3D::ConstSPtr grid, dataType /* type */ )
{
std::srand( time( 0 ) );
// currently, the type is fixed. This will come soon.
typedef double ValueType;
typedef WValueSet< ValueType > ValueSetType;
......@@ -56,7 +59,9 @@ WValueSetBase::SPtr WDataCreatorRandom::operator()( WGridRegular3D::ConstSPtr gr
// iterate the data and fill in some random values
for( size_t i = 0; i < grid->size(); ++i )
{
data->push_back( m_values01( m_rand ) );
// NOLINT: because we do not want to use rand_r.
double randD = static_cast< double >( std::rand() ) / static_cast< double >( RAND_MAX ); // NOLINT
data->push_back( static_cast< ValueType >( m_rangeMin->get() + ( m_rangeMax->get() * randD ) ) );
}
// finally, create the value set and return it
......
......@@ -25,8 +25,6 @@
#ifndef WDATACREATORRANDOM_H
#define WDATACREATORRANDOM_H
#include <boost/random.hpp>
#include "core/common/WObjectNDIP.h"
#include "WMDataCreatorScalar.h"
......@@ -59,14 +57,14 @@ public:
protected:
private:
/**
* Random number generator.
* Minimum value in the dataset.
*/
boost::random::mt19937 m_rand;
WPropDouble m_rangeMin;
/**
* A distribution. This one creates random numbers in [0, 1)
* Maximum value in the dataset.
*/
boost::random::uniform_real_distribution<> m_values01;
WPropDouble m_rangeMax;
};
#endif // WDATACREATORRANDOM_H
......
......@@ -29,6 +29,13 @@
WDataCreatorSphere::WDataCreatorSphere():
WObjectNDIP< WMDataCreatorScalar::DataCreatorInterface >( "Spherical", "Creates a spherical volume." )
{
// add some properties
m_center = m_properties->addProperty( "Center", "The center point in relative coordinates, where 0.5 is the center. At this point, "
"the value in the scalar field will be zero.",
WPosition( 0.5, 0.5, 0.5 ) );
m_radius = m_properties->addProperty( "Radius", "The radius in relative coordinates, where 0.5 creates a sphere in the size of the grid.",
0.5 );
m_radius->setMin( 0.0 );
}
WDataCreatorSphere::~WDataCreatorSphere()
......@@ -46,14 +53,39 @@ WValueSetBase::SPtr WDataCreatorSphere::operator()( WGridRegular3D::ConstSPtr gr
// for scalar data we need only as much space as we have voxels
data->resize( grid->size() );
double originX = m_center->get().x();
double originY = m_center->get().y();
double originZ = m_center->get().z();
// the formular below calculates the stuff in -1,1 interval. The radius is meant to be used in -0.5 to 0.5 -> so scale up
double radius = 2.0 * m_radius->get();
// iterate the data and fill in some values
double xRel = 0.0;
double yRel = 0.0;
double zRel = 0.0;
for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
{
xRel = static_cast< double >( x ) / static_cast< double >( grid->getNbCoordsX() - 1 );
xRel -= originX;
xRel *= 2.0;
for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
{
yRel = static_cast< double >( y ) / static_cast< double >( grid->getNbCoordsY() - 1 );
yRel -= originY;
yRel *= 2.0;
for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
{
data->operator[]( grid->getVoxelNum( x, y, z ) ) = x*x + y*y + z*z;
zRel = static_cast< double >( z ) / static_cast< double >( grid->getNbCoordsZ() - 1 );
zRel -= originZ;
zRel *= 2.0;
data->operator[]( grid->getVoxelNum( x, y, z ) ) = static_cast< ValueType >( ( 1.0 / ( radius * radius ) ) *
( ( xRel * xRel ) +
( yRel * yRel ) +
( zRel * zRel ) ) );
}
}
}
......
......@@ -57,6 +57,15 @@ public:
protected:
private:
/**
* Relative center coordinates
*/
WPropPosition m_center;
/**
* The radius of the sphere in relative coordinates.
*/
WPropDouble m_radius;
};
#endif // WDATACREATORSPHERE_H
......
......@@ -358,13 +358,13 @@ void WMProbTractDisplaySP::checkProbabilityRanges( std::vector< boost::shared_pt
size_t i = 0;
for( std::vector< boost::shared_ptr< const WDataSetScalar > >::const_iterator p = probTracts.begin(); p != probTracts.end(); ++p, ++i )
{
if( ( *p )->getMax() > 10 ) // Note: same check is made in the builder, later when colors are deterimined and alpha values depending on prob
if( ( *p )->getMax() > 1 ) // Note: same check is made in the builder, later when colors are deterimined and alpha values depending on prob
{
ss << ( *p )->getFilename() << " ";
otherRange = true;
}
}
ss << "which have probabilites > 10 may be invalid => range 0..255 assumed instead";
ss << "which have probabilites > 1 are normalized by its maximum value. As the seed point should have the maximum value it is converted to 1.0 then.";
if( otherRange )
{
warnLog() << ss.str();
......
......@@ -131,9 +131,9 @@ WColor WSPSliceBuilder::lookUpColor( const WPosition& pos, size_t tractID ) cons
WColor c = colorMap( tractID );
bool success = false;
double probability = m_probTracts.at( tractID )->interpolate( pos, &success );
if( m_probTracts.at( tractID )->getMax() > 10 )
if( m_probTracts.at( tractID )->getMax() > 1 )
{
probability /= 255.0;
probability /= static_cast< double >( m_probTracts.at( tractID )->getMax() );
}
if( c[3] != 0.0 )
{
......
......@@ -136,7 +136,7 @@ osg::ref_ptr< WGEGroupNode > WSPSliceBuilderVectors::generateSlice( const unsign
if( tractColor[3] > m_probThreshold->get() )
{
// determine density of line stipples 1 => 10 samples. 0 => 0 samples
size_t numSamples = static_cast< size_t >( tractColor[3] * 10 + 1 ); // / m_spacing->get() );
size_t numSamples = static_cast< size_t >( tractColor[3] * 9 + 1 ); // / m_spacing->get() );
for( size_t sample = 0; sample < numSamples; ++sample )
{
double s = 1.0 * m_spacing->get(); // jitter scaling
......
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