28 #include "WDataCreatorSphere.h"
29 #include "core/common/WAssert.h"
30 #include "core/common/WLimits.h"
36 m_center =
m_properties->addProperty(
"Center",
"The center point in relative coordinates, where 0.5 is the center. At this point, "
37 "the value in the scalar field will be zero.",
39 m_radius =
m_properties->addProperty(
"Radius",
"The radius in relative coordinates, where 0.5 creates a sphere in the size of the grid.",
43 m_lowerClamp =
m_properties->addProperty(
"Lower Clamp Threshold",
"Defines a threshold which allows all values below this value to be set to 0."
44 "This can be handy to create spheres which are 0 in the inside.",
47 m_upperClamp =
m_properties->addProperty(
"Upper Clamp Threshold",
"Defines a threshold which allows all values above this value to be set to 0."
48 "This can be handy to create an empty field around the sphere",
65 WAssert( ( order == 0 ) && ( dimension == 1 ),
"The sphere data creator only supports scalar data." );
68 typedef double ValueType;
72 std::shared_ptr< std::vector< ValueType > > data(
new std::vector< ValueType > );
74 data->resize( grid->size() );
76 double originX =
m_center->get().x();
77 double originY =
m_center->get().y();
78 double originZ =
m_center->get().z();
81 double radius = 2.0 *
m_radius->get();
93 for(
size_t x = 0; x < grid->getNbCoordsX(); ++x )
95 xRel =
static_cast< double >( x ) /
static_cast< double >( grid->getNbCoordsX() - 1 );
99 for(
size_t y = 0; y < grid->getNbCoordsY(); ++y )
101 yRel =
static_cast< double >( y ) /
static_cast< double >( grid->getNbCoordsY() - 1 );
105 for(
size_t z = 0; z < grid->getNbCoordsZ(); ++z )
107 zRel =
static_cast< double >( z ) /
static_cast< double >( grid->getNbCoordsZ() - 1 );
111 ValueType val =
static_cast< ValueType
>( ( 1.0 / ( radius * radius ) ) *
117 data->operator[]( grid->getVoxelNum( x, y, z ) ) = val < lowClamp ? lowClampValue : ( val > upClamp ? upClampValue : val );
121 progress->increment( grid->getNbCoordsZ() );
127 return ValueSetType::SPtr(
new ValueSetType( 0, 1, data ) );
WPropDouble m_lowerClampValue
To which value should be clamped?
WPropDouble m_upperClampValue
To which value should be clamped?
virtual ~WDataCreatorSphere()
Destructor.
WPropDouble m_upperClamp
Clamp to 0 for all values above.
WPropDouble m_lowerClamp
Clamp to 0 for all values below this one.
WDataCreatorSphere()
Default constructor.
WPropDouble m_radius
The radius of the sphere in relative coordinates.
WPropPosition m_center
Relative center coordinates.
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).
WProperties::SPtr m_properties
the properties of the object.
This only is a 3d double vector.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
std::shared_ptr< WValueSetBase > SPtr
Shared pointer to an instance of this class.
Base Class for all value set types.
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...
const double MAX_DOUBLE
Maximum double value.