Commit f4d01413 authored by André Reichenbach's avatar André Reichenbach
Browse files

[ADD] added a strategy for vector data creation, copies a single vector to all voxels

parent 55bbb9a3
//---------------------------------------------------------------------------
//
// 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 "WDataCreatorSingleDirection.h"
WDataCreatorSingleDirection::WDataCreatorSingleDirection():
WObjectNDIP< WDataSetSingleCreatorInterface >( "Single direction.", "Creates a volume with a single direction for all vectors." )
{
m_vector = m_properties->addProperty( "Direction", "The direction for all vectors in the dataset.", WPosition( 0.0, 0.0, 0.0 ) );
}
WDataCreatorSingleDirection::~WDataCreatorSingleDirection()
{
}
WValueSetBase::SPtr WDataCreatorSingleDirection::operator()( WProgress::SPtr progress,
WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
dataType /*type*/ )
{
typedef double ValueType;
typedef WValueSet< ValueType > ValueSetType;
if( order != 1 || dimension != 3 )
{
return ValueSetType::SPtr();
}
boost::shared_ptr< std::vector< ValueType > > data( new std::vector< ValueType > );
size_t valuesPerVoxel = ValueSetType::getRequiredRawSizePerVoxel( order, dimension );
data->resize( valuesPerVoxel * grid->size() );
WPosition dir = m_vector->get( true );
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 )
{
data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 0 ) = dir[ 0 ];
data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 1 ) = dir[ 1 ];
data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 2 ) = dir[ 2 ];
}
progress->increment( grid->getNbCoordsZ() );
}
}
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 WDATACREATORSINGLEDIRECTION_H
#define WDATACREATORSINGLEDIRECTION_H
#include "core/common/WObjectNDIP.h"
#include "WDataSetSingleCreatorInterface.h"
#include "WMDataCreatorScalar.h"
/**
* Sets all voxels to the same vector.
*/
class WDataCreatorSingleDirection: public WObjectNDIP< WDataSetSingleCreatorInterface >
{
public:
/**
* Default constructor.
*/
WDataCreatorSingleDirection();
/**
* Destructor.
*/
virtual ~WDataCreatorSingleDirection();
/**
* Create the dataset.
*
* \param order the tensor order of the values stored in this WValueSet, must equal 1
* \param dimension the tensor dimension of the values stored in this WValueSet, must equal 3
* \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 = 1, unsigned char dimension = 3,
dataType type = W_DT_FLOAT );
protected:
private:
//! The vector to copy to the voxels.
WPropPosition m_vector;
};
#endif // WDATACREATORSINGLEDIRECTION_H
......@@ -34,6 +34,7 @@
#include "WDataCreatorSphere.h"
#include "WDataCreatorRandom.h"
#include "WDataCreatorSingleDirection.h"
#include "WMDataCreatorVector.xpm"
#include "WMDataCreatorVector.h"
......@@ -45,6 +46,7 @@ WMDataCreatorVector::WMDataCreatorVector():
{
// add some strategies here
m_strategy.addStrategy( WDataCreatorRandom::SPtr( new WDataCreatorRandom() ) );
m_strategy.addStrategy( WDataCreatorSingleDirection::SPtr( new WDataCreatorSingleDirection() ) );
// NOTE: the sphere strategy does not support vectors -> if you want them, create a scalar sphere and derive from it.
}
......
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