Commit ca36cf6f authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] new data creator function

parent 41b51ad5
//---------------------------------------------------------------------------
//
// 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 <memory>
#include <vector>
#include "WDataCreatorTwoBlobs.h"
#include "core/common/WAssert.h"
WDataCreatorTwoBlobs::WDataCreatorTwoBlobs():
WObjectNDIP< WDataSetSingleCreatorInterface >( "Two Blobs", "Creates a volume containing two blobs." )
{
}
WDataCreatorTwoBlobs::~WDataCreatorTwoBlobs()
{
}
WValueSetBase::SPtr WDataCreatorTwoBlobs::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
std::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() );
const WVector3d p = WVector3d( -1, 0, 0 );
const WVector3d q = WVector3d( 1, 0, 0 );
// iterate the data and fill in some 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 )
{
const WVector3d s = grid->getPosition( x, y, z );
data->operator[]( grid->getVoxelNum( x, y, z ) ) = static_cast< ValueType >( distance( p, s ) * distance( q, s ) );
}
// 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 2022 OpenWalnut Community
// 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 WDATACREATORTWOBLOBS_H
#define WDATACREATORTWOBLOBS_H
#include <core/common/WObjectNDIP.h>
#include "WDataSetSingleCreatorInterface.h"
/**
* Creates two blobs inside a given grid. Only works on scalar fields.
* https://doi.org/10.1109/TVCG.2012.249
*/
class WDataCreatorTwoBlobs: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorTwoBlobs();
/**
* Destructor.
*/
virtual ~WDataCreatorTwoBlobs();
/**
* 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 // WDATACREATORTWOBLOBS_H
......@@ -35,6 +35,7 @@
#include "WDataCreatorSphere.h"
#include "WDataCreatorTangle.h"
#include "WDataCreatorTuring.h"
#include "WDataCreatorTwoBlobs.h"
#include "WMDataCreatorScalar.h"
#include "core/common/WAssert.h"
#include "core/common/WProgress.h"
......@@ -56,6 +57,7 @@ WMDataCreatorScalar::WMDataCreatorScalar():
m_strategy.addStrategy( WDataCreatorSphere::SPtr( new WDataCreatorLinearAscent() ) );
m_strategy.addStrategy( WDataCreatorConstant::SPtr( new WDataCreatorConstant() ) );
m_strategy.addStrategy( WDataCreatorConstant::SPtr( new WDataCreatorTuring() ) );
m_strategy.addStrategy( WDataCreatorTwoBlobs::SPtr( new WDataCreatorTwoBlobs() ) );
}
WMDataCreatorScalar::~WMDataCreatorScalar()
......
......@@ -37,4 +37,8 @@ th, td {
<td>Turing</td>
<td>Turing pattern, see <a href="https://en.wikipedia.org/wiki/Turing_pattern">Wikipedia</a>.</td>
</tr>
<tr>
<td>Two Blobs</td>
<td>Field increasing around two centers. For details see <a href="https://doi.org/10.1109/TVCG.2012.249">DOI</a>.</td>
</tr>
</table>
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