Commit cdbf531b by Mathias Goldau

[ADD] New scalar data create scheme. Linear increasing values from bottom (x) to top (z).

parent e9530d17
//---------------------------------------------------------------------------
//
// 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 "WDataCreatorLinearAscent.h"
WDataCreatorLinearAscent::WDataCreatorLinearAscent():
WObjectNDIP< WDataSetSingleCreatorInterface >( "LinearAscent", "Creates a linear increasing values starting from the bottom (x,y,z)." )
{
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 );
}
WDataCreatorLinearAscent::~WDataCreatorLinearAscent()
{
}
WValueSetBase::SPtr WDataCreatorLinearAscent::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;
// 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 LinearAscent values
for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
{
for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
{
for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
{
// each voxels might need multiple values
for( size_t v = 0; v < valuesPerVoxel; ++v )
{
double val = static_cast< double >( grid->getVoxelNum( x, y, z ) ) / grid->size();
data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + v ) =
static_cast< ValueType >( m_rangeMin->get() + ( std::abs( m_rangeMin->get() - m_rangeMax->get() ) * val ) );
}
}
// updating progress for each voxel is not needed. It is enough to update each slice
progress->increment( grid->getNbCoordsX() );
}
}
// 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 WDATACREATORLINEARASCENT_H
#define WDATACREATORLINEARASCENT_H
#include "core/common/WObjectNDIP.h"
#include "WDataSetSingleCreatorInterface.h"
#include "WMDataCreatorScalar.h"
/**
* Creates linear increasing values inside a given grid. This works for all kinds of datasets using WValueSetBase.
*/
class WDataCreatorLinearAscent: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorLinearAscent();
/**
* Destructor.
*/
virtual ~WDataCreatorLinearAscent();
/**
* 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:
/**
* Minimum value in the dataset.
*/
WPropDouble m_rangeMin;
/**
* Maximum value in the dataset.
*/
WPropDouble m_rangeMax;
};
#endif // WDATACREATORLINEARASCENT_H
......@@ -28,14 +28,15 @@
#include "core/common/WAssert.h"
#include "core/common/WProgress.h"
#include "core/common/WStrategyHelper.h"
#include "core/dataHandler/WGridRegular3D.h"
#include "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WGridRegular3D.h"
#include "core/kernel/WKernel.h"
#include "WDataCreatorSphere.h"
#include "WDataCreatorBreyzel5.h"
#include "WDataCreatorTangle.h"
#include "WDataCreatorLinearAscent.h"
#include "WDataCreatorRandom.h"
#include "WDataCreatorSphere.h"
#include "WDataCreatorTangle.h"
#include "WMDataCreator.xpm"
#include "WMDataCreatorScalar.h"
......@@ -50,6 +51,7 @@ WMDataCreatorScalar::WMDataCreatorScalar():
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorSphere() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorTangle() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorBreyzel5() ) );
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorLinearAscent() ) );
}
WMDataCreatorScalar::~WMDataCreatorScalar()
......
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