OpenWalnut  1.5.0dev
WDataCreatorFiberStar.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 <random>
26 
27 #include "WDataCreatorFiberStar.h"
28 
30  WObjectNDIP< WDataSetFibersCreatorInterface >( "Star", "Create a star of fibers." )
31 {
32 }
33 
35 {
36  // cleanup
37 }
38 
40  WProgress::SPtr progress,
41  const WColor& color,
42  size_t numFibers,
43  size_t numVertsPerFiber,
44  const WPosition& origin,
45  const WPosition& size,
49  WDataSetFibers::IndexArray fibIdxVertexMap,
51 {
52  std::uniform_real_distribution< double > unif( -0.5, 0.5 );
53  std::default_random_engine re;
54  re.seed( seed );
55 
56  for( size_t fidx = 0; fidx < numFibers; ++fidx )
57  {
58  WVector3d dir( unif( re ), unif( re ), unif( re ) );
59  dir = normalize( dir );
60 
61  WVector3d ray( dir.x() * ( size.x() / 2.0 ), dir.y() * ( size.y() / 2.0 ), dir.z() * ( size.z() / 2.0 ) );
62  ray /= numVertsPerFiber;
63 
64  fibIdx->push_back( fidx * numVertsPerFiber );
65  lengths->push_back( numVertsPerFiber );
66 
67  for( size_t vidx = 0; vidx < numVertsPerFiber; ++vidx )
68  {
69  WVector3d vec = ray * vidx;
70 
71  vertices->push_back( origin.x() + vec.x() + size.x() / 2.0 );
72  vertices->push_back( origin.y() + vec.y() + size.y() / 2.0 );
73  vertices->push_back( origin.z() + vec.z() + size.z() / 2.0 );
74 
75  colors->push_back( color.x() );
76  colors->push_back( color.y() );
77  colors->push_back( color.z() );
78  fibIdxVertexMap->push_back( fidx );
79  }
80 
81  ++( *progress );
82  }
83 }
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.
WDataCreatorFiberStar()
Default constructor.
virtual ~WDataCreatorFiberStar()
Destructor.
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.
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).
Definition: WObjectNDIP.h:42
This only is a 3d double vector.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48