OpenWalnut  1.5.0dev
WDataCreatorFiberParallel.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 "WDataCreatorFiberParallel.h"
28 
30  WObjectNDIP< WDataSetFibersCreatorInterface >( "Parallel", "Create parallel fibers." )
31 {
32  m_direction = m_properties->addProperty( "Direction", "The direction of the parallel fibers", WPosition( 1.0, 0.0, 0.0 ) );
33 }
34 
36 {
37  // cleanup
38 }
39 
41  WProgress::SPtr progress,
42  const WColor& color,
43  size_t numFibers,
44  size_t numVertsPerFiber,
45  const WPosition& origin,
46  const WPosition& size,
50  WDataSetFibers::IndexArray fibIdxVertexMap,
52 {
53  WAssert( length2( m_direction->get() ) != 0, "The direction should not be (0, 0, 0)!" );
54 
55  std::uniform_real_distribution< double > unif( 0.0, 1.0 );
56  std::default_random_engine re;
57  re.seed( seed );
58 
59  WVector3d dir = m_direction->get();
60 
61  for( size_t fidx = 0; fidx < numFibers; ++fidx )
62  {
63  double x = unif( re ) * size.x();
64  double y = unif( re ) * size.y();
65  double z = unif( re ) * size.z();
66 
67  // parameter of ray to calculate the intersection points
68  double tmin, tmax, tymin, tymax, tzmin, tzmax;
69  tmin = ( 0.0 * size.x() - x ) / dir.x();
70  tmax = ( 1.0 * size.x() - x ) / dir.x();
71  tymin = ( 0.0 * size.y() - y ) / dir.y();
72  tymax = ( 1.0 * size.y() - y ) / dir.y();
73  tzmin = ( 0.0 * size.z() - z ) / dir.z();
74  tzmax = ( 1.0 * size.z() - z ) / dir.z();
75  tmin = fmax( fmax( tmin, tymin ), tzmin );
76  tmax = fmin( fmin( tmax, tymax ), tzmax );
77 
78  WVector3d pos( x, y, z ); // start position of the ray
79  WVector3d min = pos + ( dir * tmin ); // first intersection
80  WVector3d max = pos + ( dir * tmax ); // second intersection
81  WVector3d ray = ( max - min ) / numVertsPerFiber; // Build new ray between start and end so that all vertices can fit in between
82 
83  fibIdx->push_back( fidx * numVertsPerFiber );
84  lengths->push_back( numVertsPerFiber );
85 
86  for( size_t vidx = 0; vidx < numVertsPerFiber; ++vidx )
87  {
88  WVector3d vec = ray * vidx;
89 
90  vertices->push_back( origin.x() + min.x() + vec.x() );
91  vertices->push_back( origin.y() + min.y() + vec.y() );
92  vertices->push_back( origin.z() + min.z() + vec.z() );
93 
94  colors->push_back( color.x() );
95  colors->push_back( color.y() );
96  colors->push_back( color.z() );
97  fibIdxVertexMap->push_back( fidx );
98  }
99 
100  ++( *progress );
101  }
102 }
WPropPosition m_direction
The direction of the parallel lines.
WDataCreatorFiberParallel()
Default constructor.
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.
virtual ~WDataCreatorFiberParallel()
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
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:99
This only is a 3d double vector.
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48