Commit 4f757aa7 authored by Mathias Goldau's avatar Mathias Goldau

[MERGE]

parents 5175ea4b a77c8faf
//---------------------------------------------------------------------------
//
// 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 <ctime>
#include <cstdlib>
#include <vector>
#include "core/common/WLogger.h"
#include "core/dataHandler/WDataHandlerEnums.h"
#include "core/dataHandler/WValueSet.h"
#include "WDataCreatorConstant.h"
WDataCreatorConstant::WDataCreatorConstant():
WObjectNDIP< WDataSetSingleCreatorInterface >( "Constant", "Creates a volume containing only one value." )
{
m_value = m_properties->addProperty( "Value", "The value in the data.", 0.0 );
}
WDataCreatorConstant::~WDataCreatorConstant()
{
}
WValueSetBase::SPtr WDataCreatorConstant::operator()( WProgress::SPtr progress,
WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
dataType /*type*/ )
{
std::srand( time( 0 ) );
// currently, the type is fixed. This will come soon.
typedef double ValueType;
typedef WValueSet< ValueType > ValueSetType;
ValueType val = m_value->get( true );
// create some memory for the data
boost::shared_ptr< std::vector< ValueType > > data( new std::vector< ValueType > );
// for scalar data we need only as much space as we have voxels
size_t valuesPerVoxel = ValueSetType::getRequiredRawSizePerVoxel( order, dimension );
data->resize( valuesPerVoxel * grid->size() );
// iterate the data and fill in some conatnt values
for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
{
for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
{
for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
{
// each voxels might need multiple values
for( size_t v = 0; v < valuesPerVoxel; ++v )
{
data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + v ) =
static_cast< ValueType >( val );
}
}
// updating progress for each voxel is not needed. It is enough to update each slice
progress->increment( grid->getNbCoordsZ() );
}
}
// finally, create the value set and return it
// We have scalar data (order = 0 ) in 3D
return ValueSetType::SPtr( new ValueSetType( order, dimension , data ) );
}
//---------------------------------------------------------------------------
//
// 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 WDATACREATORCONSTANT_H
#define WDATACREATORCONSTANT_H
#include "core/common/WObjectNDIP.h"
#include "WDataSetSingleCreatorInterface.h"
#include "WMDataCreatorScalar.h"
/**
* Creates constant values inside a given grid. This works for all kinds of datasets using WValueSetBase.
*/
class WDataCreatorConstant: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorConstant();
/**
* Destructor.
*/
virtual ~WDataCreatorConstant();
/**
* Create the dataset. This needs to be implemented by all the creators you write. This method is designed to be applicable to all kinds of
* WDataSetSingle that use WValueSetBase. Your implementation does not need to support all types. If you do not support any order/dimension
* combination, throw an exception (like by using WAssert).
*
* \param order the tensor order of the values stored in this WValueSet
* \param dimension the tensor dimension of the values stored in this WValueSet
* \param progress the progress instance you should increment each time you fill the value for one voxel.
* \param grid the grid on which the value set has to be build
* \param type the value type in the value set
*
* \return the value set for the given grid
*/
virtual WValueSetBase::SPtr operator()( WProgress::SPtr progress,
WGridRegular3D::ConstSPtr grid, unsigned char order = 0, unsigned char dimension = 1,
dataType type = W_DT_FLOAT );
protected:
private:
/**
* The value in the dataset.
*/
WPropDouble m_value;
};
#endif // WDATACREATORCONSTANT_H
......@@ -33,6 +33,7 @@
#include "core/kernel/WKernel.h"
#include "WDataCreatorBreyzel5.h"
#include "WDataCreatorConstant.h"
#include "WDataCreatorLinearAscent.h"
#include "WDataCreatorRandom.h"
#include "WDataCreatorSphere.h"
......@@ -49,9 +50,10 @@ WMDataCreatorScalar::WMDataCreatorScalar():
// add some strategies here
m_strategy.addStrategy( WDataCreatorRandom::SPtr( new WDataCreatorRandom() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorSphere() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorTangle() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorBreyzel5() ) );
m_strategy.addStrategy( WDataCreatorTangle::SPtr( new WDataCreatorTangle() ) );
m_strategy.addStrategy( WDataCreatorBreyzel5::SPtr( new WDataCreatorBreyzel5() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorLinearAscent() ) );
m_strategy.addStrategy( WDataCreatorConstant::SPtr( new WDataCreatorConstant() ) );
}
WMDataCreatorScalar::~WMDataCreatorScalar()
......
......@@ -69,14 +69,14 @@ const char** WMDataTypeConversion::getXPMIcon() const
const std::string WMDataTypeConversion::getName() const
{
return "Data Type Conversion (to float)";
return "Data Type Conversion";
}
const std::string WMDataTypeConversion::getDescription() const
{
return "This module is intended for development use only. Modules for general use should not depend on it.<br><br> "
"Allows one to change the data type of the provided WDataSetSingle to another type. "
"E.g., double to float. At the moment only conversion to float is supported.";
"E.g., double to float.";
}
/**
......@@ -132,6 +132,10 @@ void WMDataTypeConversion::moduleMain()
// loop until the module container requests the module to quit
while( !m_shutdownFlag() )
{
// 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();
// acquire data from the input connector
m_dataSet = m_input->getData();
if( !m_dataSet )
......@@ -139,7 +143,6 @@ void WMDataTypeConversion::moduleMain()
// 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;
}
......@@ -210,10 +213,6 @@ void WMDataTypeConversion::moduleMain()
// we have the valueset -> create dataset
m_dataSet = boost::shared_ptr<WDataSetScalar>( new WDataSetScalar( valueSet, m_dataSet->getGrid() ) );
m_output->updateData( m_dataSet );
// 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();
}
}
......
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