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

[ADD #162] - added some other data creators i have coded for FAnToM some years...

[ADD #162] - added some other data creators i have coded for FAnToM some years ago. It is very simple to port them to our WDataCreator scheme
parent 3e3ffcc1
//---------------------------------------------------------------------------
//
// 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 <vector>
#include "core/common/WAssert.h"
#include "WDataCreatorBreyzel5.h"
WDataCreatorBreyzel5::WDataCreatorBreyzel5():
WObjectNDIP< WDataSetSingleCreatorInterface >( "Breyzel5", "Creates a volume with some nice shape." )
{
// add some properties
m_scale = m_properties->addProperty( "Scale", "Scale the value domain.", 1.0 );
m_scale->setMin( 0.0 );
m_scale->setMax( 10 );
}
WDataCreatorBreyzel5::~WDataCreatorBreyzel5()
{
}
WValueSetBase::SPtr WDataCreatorBreyzel5::operator()( WProgress::SPtr progress,
WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
dataType /*type*/ )
{
// this creator only supports valuesets for scalar data.
WAssert( ( order == 0 ) && ( dimension == 1 ), "The data creator only supports scalar data." );
// 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
data->resize( grid->size() );
// iterate the data and fill in some values
double xRel = 0.0;
double yRel = 0.0;
double zRel = 0.0;
double scale = m_scale->get();
for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
{
xRel = static_cast< double >( x ) / static_cast< double >( grid->getNbCoordsX() - 1 );
xRel -= 0.5;
xRel *= scale * 2.0;
for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
{
yRel = static_cast< double >( y ) / static_cast< double >( grid->getNbCoordsY() - 1 );
yRel -= 0.5;
yRel *= scale * 2.0;
for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
{
zRel = static_cast< double >( z ) / static_cast< double >( grid->getNbCoordsZ() - 1 );
zRel -= 0.5;
zRel *= scale * 2.0;
double x2 = xRel * xRel;
double y2 = yRel * yRel;
double z2 = zRel * zRel;
double s = ( x2 + 0.25 * y2 - 1.0 ) * ( 0.25 * x2 + y2 - 1.0 );
data->operator[]( grid->getVoxelNum( x, y, z ) ) = static_cast< ValueType >( s * s + z2 - 0.1 );
}
// 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( 0, 1, 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 WDATACREATORBREYZEL5_H
#define WDATACREATORBREYZEL5_H
#include <core/common/WObjectNDIP.h>
#include "WDataSetSingleCreatorInterface.h"
/**
* Creates a breyzel5 inside a given grid. Only works on scalar fields.
*/
class WDataCreatorBreyzel5: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorBreyzel5();
/**
* Destructor.
*/
virtual ~WDataCreatorBreyzel5();
/**
* 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:
/**
* Scale the value domain.
*/
WPropDouble m_scale;
};
#endif // WDATACREATORBREYZEL5_H
//---------------------------------------------------------------------------
//
// 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 <vector>
#include "core/common/WAssert.h"
#include "WDataCreatorTangle.h"
WDataCreatorTangle::WDataCreatorTangle():
WObjectNDIP< WDataSetSingleCreatorInterface >( "Tangle", "Creates a volume using the tangle equation." )
{
// add some properties
m_scale = m_properties->addProperty( "Scale", "Scale the value domain.", 1.0 );
m_scale->setMin( 0.0 );
m_scale->setMax( 10 );
}
WDataCreatorTangle::~WDataCreatorTangle()
{
}
WValueSetBase::SPtr WDataCreatorTangle::operator()( WProgress::SPtr progress,
WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
dataType /*type*/ )
{
// this creator only supports valuesets for scalar data.
WAssert( ( order == 0 ) && ( dimension == 1 ), "The data creator only supports scalar data." );
// 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
data->resize( grid->size() );
// iterate the data and fill in some values
double xRel = 0.0;
double yRel = 0.0;
double zRel = 0.0;
double scale = m_scale->get();
for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
{
xRel = static_cast< double >( x ) / static_cast< double >( grid->getNbCoordsX() - 1 );
xRel -= 0.5;
xRel *= scale * 2.0;
for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
{
yRel = static_cast< double >( y ) / static_cast< double >( grid->getNbCoordsY() - 1 );
yRel -= 0.5;
yRel *= scale * 2.0;
for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
{
zRel = static_cast< double >( z ) / static_cast< double >( grid->getNbCoordsZ() - 1 );
zRel -= 0.5;
zRel *= scale * 2.0;
// set value
double x2 = xRel * xRel;
double y2 = yRel * yRel;
double z2 = zRel * zRel;
data->operator[]( grid->getVoxelNum( x, y, z ) ) = static_cast< ValueType >(
x2 - 5.0 * x2 + y2 - 5.0 * y2 + z2 * z2 - 5.0 * z2 + 11.8 + 0.25
);
}
// 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( 0, 1, 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 WDATACREATORTANGLE_H
#define WDATACREATORTANGLE_H
#include <core/common/WObjectNDIP.h>
#include "WDataSetSingleCreatorInterface.h"
/**
* Creates a tangle inside a given grid. Only works on scalar fields.
*/
class WDataCreatorTangle: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorTangle();
/**
* Destructor.
*/
virtual ~WDataCreatorTangle();
/**
* 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:
/**
* Scale the value domain.
*/
WPropDouble m_scale;
};
#endif // WDATACREATORTANGLE_H
......@@ -33,6 +33,8 @@
#include "core/kernel/WKernel.h"
#include "WDataCreatorSphere.h"
#include "WDataCreatorBreyzel5.h"
#include "WDataCreatorTangle.h"
#include "WDataCreatorRandom.h"
#include "WMDataCreator.xpm"
......@@ -44,8 +46,10 @@ WMDataCreatorScalar::WMDataCreatorScalar():
"Creator", "A list of all known creators." )
{
// add some strategies here
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorSphere() ) );
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() ) );
}
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