OpenWalnut  1.5.0dev
WDataCreatorSingleDirection.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <cstdlib>
26 #include <ctime>
27 #include <memory>
28 #include <vector>
29 
30 #include "WDataCreatorSingleDirection.h"
31 #include "core/common/WLogger.h"
32 #include "core/dataHandler/WDataHandlerEnums.h"
33 #include "core/dataHandler/WValueSet.h"
34 
36  WObjectNDIP< WDataSetSingleCreatorInterface >( "Single direction.", "Creates a volume with a single direction for all vectors." )
37 {
38  m_vector = m_properties->addProperty( "Direction", "The direction for all vectors in the dataset.", WPosition( 0.0, 0.0, 0.0 ) );
39 }
40 
42 {
43 }
44 
46  WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
47  dataType /*type*/ )
48 {
49  typedef double ValueType;
50  typedef WValueSet< ValueType > ValueSetType;
51 
52  if( order != 1 || dimension != 3 )
53  {
54  return ValueSetType::SPtr();
55  }
56 
57  std::shared_ptr< std::vector< ValueType > > data( new std::vector< ValueType > );
58 
59  size_t valuesPerVoxel = ValueSetType::getRequiredRawSizePerVoxel( order, dimension );
60  data->resize( valuesPerVoxel * grid->size() );
61 
62  WPosition dir = m_vector->get( true );
63 
64  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
65  {
66  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
67  {
68  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
69  {
70  data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 0 ) = dir[ 0 ];
71  data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 1 ) = dir[ 1 ];
72  data->operator[]( ( valuesPerVoxel * grid->getVoxelNum( x, y, z ) ) + 2 ) = dir[ 2 ];
73  }
74 
75  progress->increment( grid->getNbCoordsZ() );
76  }
77  }
78 
79  return ValueSetType::SPtr( new ValueSetType( order, dimension, data ) );
80 }
WDataCreatorSingleDirection()
Default constructor.
virtual ~WDataCreatorSingleDirection()
Destructor.
WPropPosition m_vector
The vector to copy to the voxels.
virtual WValueSetBase::SPtr operator()(WProgress::SPtr progress, WGridRegular3D::ConstSPtr grid, unsigned char order=1, unsigned char dimension=3, dataType type=W_DT_FLOAT)
Create the dataset.
Define the interface which is injected into an WObjectNDIP.
std::shared_ptr< const WGridRegular3DTemplate > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGridRegular3DTemplate >.
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP).
Definition: WObjectNDIP.h:42
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:99
This only is a 3d double vector.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48
std::shared_ptr< WValueSetBase > SPtr
Shared pointer to an instance of this class.
Definition: WValueSetBase.h:65
Base Class for all value set types.
Definition: WValueSet.h:47
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...