OpenWalnut  1.5.0dev
WDataCreatorTangle.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 <memory>
26 #include <vector>
27 
28 #include "WDataCreatorTangle.h"
29 #include "core/common/WAssert.h"
30 
32  WObjectNDIP< WDataSetSingleCreatorInterface >( "Tangle", "Creates a volume using the tangle equation." )
33 {
34  // add some properties
35  m_scale = m_properties->addProperty( "Scale", "Scale the value domain.", 1.0 );
36  m_scale->setMin( 0.0 );
37  m_scale->setMax( 10 );
38 }
39 
41 {
42 }
43 
45  WGridRegular3D::ConstSPtr grid, unsigned char order, unsigned char dimension,
46  dataType /*type*/ )
47 {
48  // this creator only supports valuesets for scalar data.
49  WAssert( ( order == 0 ) && ( dimension == 1 ), "The data creator only supports scalar data." );
50 
51  // currently, the type is fixed. This will come soon.
52  typedef double ValueType;
53  typedef WValueSet< ValueType > ValueSetType;
54 
55  // create some memory for the data
56  std::shared_ptr< std::vector< ValueType > > data( new std::vector< ValueType > );
57  // for scalar data we need only as much space as we have voxels
58  data->resize( grid->size() );
59 
60  // iterate the data and fill in some values
61  double xRel = 0.0;
62  double yRel = 0.0;
63  double zRel = 0.0;
64  double scale = m_scale->get();
65  for( size_t x = 0; x < grid->getNbCoordsX(); ++x )
66  {
67  xRel = static_cast< double >( x ) / static_cast< double >( grid->getNbCoordsX() - 1 );
68  xRel -= 0.5;
69  xRel *= scale * 2.0;
70 
71  for( size_t y = 0; y < grid->getNbCoordsY(); ++y )
72  {
73  yRel = static_cast< double >( y ) / static_cast< double >( grid->getNbCoordsY() - 1 );
74  yRel -= 0.5;
75  yRel *= scale * 2.0;
76 
77  for( size_t z = 0; z < grid->getNbCoordsZ(); ++z )
78  {
79  zRel = static_cast< double >( z ) / static_cast< double >( grid->getNbCoordsZ() - 1 );
80  zRel -= 0.5;
81  zRel *= scale * 2.0;
82 
83  // set value
84  double x2 = xRel * xRel;
85  double y2 = yRel * yRel;
86  double z2 = zRel * zRel;
87  data->operator[]( grid->getVoxelNum( x, y, z ) ) = static_cast< ValueType >(
88  x2 - 5.0 * x2 + y2 - 5.0 * y2 + z2 * z2 - 5.0 * z2 + 11.8 + 0.25
89  );
90  }
91 
92  // updating progress for each voxel is not needed. It is enough to update each slice
93  progress->increment( grid->getNbCoordsZ() );
94  }
95  }
96 
97  // finally, create the value set and return it
98  // We have scalar data (order = 0 ) in 3d
99  return ValueSetType::SPtr( new ValueSetType( 0, 1, data ) );
100 }
virtual ~WDataCreatorTangle()
Destructor.
WDataCreatorTangle()
Default constructor.
WPropDouble m_scale
Scale the value domain.
virtual WValueSetBase::SPtr operator()(WProgress::SPtr progress, WGridRegular3D::ConstSPtr grid, unsigned char order=0, unsigned char dimension=1, 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
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...