25 #ifndef WDATACREATORTORUS_H
26 #define WDATACREATORTORUS_H
30 #include "core/common/math/WMath.h"
31 #include "core/common/WLimits.h"
32 #include "core/common/WObjectNDIP.h"
34 #include "WDataSetFibersCreatorInterface.h"
35 #include "WDataSetPointsCreatorInterface.h"
47 typedef std::shared_ptr< WDataCreatorTorus< T > >
SPtr;
52 typedef std::shared_ptr< const WDataCreatorTorus< T > >
ConstSPtr;
84 size_t numVertsPerFiber,
168 WObjectNDIP< T >(
"Torus",
"Create data in a torus shape." )
200 osg::Matrixd::scale( size.x() / 2.0, size.y() / 2.0, size.z() / 2.0 ) *
201 osg::Matrixd::rotate(
202 m_rotateX->get(), osg::Vec3d( 1, 0, 0 ), m_rotateY->get(), osg::Vec3d( 0, 1, 0 ), m_rotateZ->get(), osg::Vec3d( 0, 0, 1 ) )
209 double radCache = ( torusRadius + ringRadius * cos( ringAngle ) );
210 double x = radCache * cos( torusAngle );
211 double y = radCache * sin( torusAngle );
212 double z = ( ringRadius * sin( ringAngle ) );
223 size_t numVertsPerFiber,
232 double innerRadius = m_innerRadius->get() / 2.0;
234 std::uniform_real_distribution< double > unifRadius( 0.01, innerRadius );
235 std::uniform_real_distribution< double > unifAngle( 0.0, pi() * 2.0 );
236 std::default_random_engine re;
239 WMatrix4d transform = calculateTransform( origin, size );
241 float lowX, lowY, lowZ;
244 for(
size_t fidx = 0; fidx < numFibers; ++fidx )
246 double irad = m_generateInner->get() ? unifRadius( re ) : innerRadius;
247 double iangle = unifAngle( re );
249 double angleParam = pi() * 2.0 / numVertsPerFiber;
251 fibIdx->push_back( fidx * numVertsPerFiber );
252 lengths->push_back( numVertsPerFiber );
254 for(
size_t vidx = 0; vidx < numVertsPerFiber; ++vidx )
256 WVector4d vec = calculateTorusVertex( 1.0 - innerRadius, irad, angleParam * vidx, iangle );
257 vec = transform * vec;
258 vec =
WVector4d( vec.
x() + origin.x() + size.x() / 2.0,
259 vec.
y() + origin.y() + size.y() / 2.0,
260 vec.
z() + origin.z() + size.z() / 2.0, 1.0 );
262 lowX = fmin( lowX, vec.
x() );
263 lowY = fmin( lowY, vec.
y() );
264 lowZ = fmin( lowZ, vec.
z() );
266 vertices->push_back( vec.
x() );
267 vertices->push_back( vec.
y() );
268 vertices->push_back( vec.
z() );
270 colors->push_back( color.x() );
271 colors->push_back( color.y() );
272 colors->push_back( color.z() );
273 fibIdxVertexMap->push_back( fidx );
279 for(
size_t vidx = 0; vidx < vertices->size(); vidx += 3 )
281 vertices->at( vidx + 0 ) -= lowX;
282 vertices->at( vidx + 1 ) -= lowY;
283 vertices->at( vidx + 2 ) -= lowZ;
297 double innerRadius = m_innerRadius->get() / 2.0;
299 std::uniform_real_distribution< double > unifRadius( 0.01, innerRadius );
300 std::uniform_real_distribution< double > unifAngle( 0.0, pi() * 2.0 );
301 std::default_random_engine re;
304 WMatrix4d transform = calculateTransform( origin, size );
306 float lowX, lowY, lowZ;
309 for(
size_t pidx = 0; pidx < numPoints; ++pidx )
311 double irad = m_generateInner->get() ? unifRadius( re ) : innerRadius;
312 double iangle = unifAngle( re );
313 double iangle2 = unifAngle( re );
315 WVector4d vec = calculateTorusVertex( 1.0 - innerRadius, irad, iangle2, iangle );
316 vec = transform * vec;
317 vec =
WVector4d( vec.
x() + origin.x() + size.x() / 2.0,
318 vec.
y() + origin.y() + size.y() / 2.0,
319 vec.
z() + origin.z() + size.z() / 2.0, 1.0 );
321 lowX = fmin( lowX, vec.
x() );
322 lowY = fmin( lowY, vec.
y() );
323 lowZ = fmin( lowZ, vec.
z() );
325 vertices->push_back( vec.
x() );
326 vertices->push_back( vec.
y() );
327 vertices->push_back( vec.
z() );
329 colors->push_back( color.x() );
330 colors->push_back( color.y() );
331 colors->push_back( color.z() );
336 for(
size_t vidx = 0; vidx < vertices->size(); vidx += 3 )
338 vertices->at( vidx + 0 ) -= lowX;
339 vertices->at( vidx + 1 ) -= lowY;
340 vertices->at( vidx + 2 ) -= lowZ;
virtual ~WDataCreatorTorus()
Destructor.
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 fiber dataset.
WPropDouble m_rotateY
The rotation angle for the x axis.
std::shared_ptr< const WDataCreatorTorus< T > > ConstSPtr
Abbreviate const shared_ptr.
std::shared_ptr< WDataCreatorTorus< T > > SPtr
Abbreviate shared_ptr.
WPropDouble m_rotateZ
The rotation angle for the x axis.
WVector4d calculateTorusVertex(double torusRadius, double ringRadius, double torusAngle, double ringAngle)
Calculates a vertex on a torus.
WDataCreatorTorus()
Default constructor.
WPropBool m_generateInner
Property whether inner fibers should be created.
WPropDouble m_innerRadius
The inner radius of the torus.
WMatrix4d calculateTransform(const WPosition &origin, const WPosition &size)
Calculates the transformation matrix.
WPropDouble m_rotateX
The rotation angle for the x axis.
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.
std::shared_ptr< std::vector< float > > ColorArray
Colors for each vertex in VertexArray.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
ValueT & z()
Access z element of vector.
ValueT & y()
Access y element of vector.
ValueT & x()
Access x element of vector.
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP).
This only is a 3d double vector.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
const float MAX_FLOAT
Maximum float value.