27 #include "core/common/math/WMath.h"
29 #include "WDataCreatorFiberSpiral.h"
52 size_t numVertsPerFiber,
63 WPosition originOffset = origin + size / 2.0;
64 originOffset.z() = origin.z();
65 double spiralRadius = std::min( size.x(), size.y() ) / 2.0;
67 double height = size.z();
69 WColor fibColor = color;
72 for(
size_t fidx = 0; fidx < numFibers; ++fidx )
74 size_t vertOffset = fidx * numVertsPerFiber;
75 fibIdx->push_back( vertOffset );
76 lengths->push_back( numVertsPerFiber );
78 double a1 =
static_cast< double >( std::rand() % 255 ) / 255.0;
79 double a2 =
static_cast< double >( std::rand() % 255 ) / 255.0;
81 double seedX = cos( 2.0 * pi() * a1 ) * tubeRadius;
82 double seedY = sin( 2.0 * pi() * a2 ) * tubeRadius;
83 double seedZ = sqrt( tubeRadius - ( seedX * seedX ) - ( seedY * seedY ) );
87 for(
size_t vidx = 0; vidx < numVertsPerFiber; ++vidx )
89 double v =
static_cast< double >( vidx ) /
static_cast< double >( numVertsPerFiber - 1 );
90 double degree = v * 2.0 * pi() * numRotations;
92 double X = seed.x() + cos( degree ) * v * spiralRadius;
93 double Y = seed.y() + sin( degree ) * v * spiralRadius;
94 double Z = seed.z() + ( v * height );
96 vertices->push_back( originOffset.x() + X );
97 vertices->push_back( originOffset.y() + Y );
98 vertices->push_back( originOffset.z() + Z );
100 colors->push_back( fibColor.x() );
101 colors->push_back( fibColor.y() );
102 colors->push_back( fibColor.z() );
103 fibIdxVertexMap->push_back( fidx );
WPropDouble m_tubeRadius
The radius of a tube (consisting of multiple fibers.
virtual void operator()(int seed, WProgress::SPtr progress, const WColor &color, size_t numFibers, size_t numVertsPerFiber, const WPosition &origin, const WPosition &size, WDataSetFibers::VertexArray vertices, WDataSetFibers::IndexArray fibIdx, WDataSetFibers::LengthArray lengths, WDataSetFibers::IndexArray fibIdxVertexMap, WDataSetFibers::ColorArray colors)
Create the dataset.
WDataCreatorFiberSpiral()
Default constructor.
virtual ~WDataCreatorFiberSpiral()
Destructor.
WPropInt m_numRotations
Number of rotations to do.
Define the interface which is injected into an WObjectNDIP.
std::shared_ptr< std::vector< size_t > > IndexArray
Index list indexing fibers in VertexArray in terms of vertex numbers.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
std::shared_ptr< std::vector< size_t > > LengthArray
Lengths of fibers in terms of vertices.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
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.