OpenWalnut  1.5.0dev
WIntegrationParameterization.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 <memory>
26 #include <vector>
27 
28 #include "WIntegrationParameterization.h"
29 #include "core/common/math/linearAlgebra/WVectorFixed.h"
30 
31 WIntegrationParameterization::WIntegrationParameterization( std::shared_ptr< WGridRegular3D > grid ):
33  m_lengthValues( grid->size(), 0.0 ),
34  m_curLength( 0.0 )
35 {
36  // initialize members
37 }
38 
40 {
41  // cleanup
42 }
43 
44 std::shared_ptr< WDataSetScalar > WIntegrationParameterization::getDataSet()
45 {
46  std::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0,
47  1,
48  std::shared_ptr< std::vector< double > >(
49  new std::vector< double >( m_lengthValues ) ),
50  W_DT_DOUBLE ) );
51  return std::shared_ptr< WDataSetScalar >( new WDataSetScalar( valueSet, m_grid ) );
52 }
53 
54 namespace wip //WIntegrationParameterization
55 {
56  size_t index( int x, int y, int z, std::shared_ptr< WGridRegular3D > grid )
57  {
58  // check validity of voxel
59  x = x < 0 ? 0 : x;
60  y = y < 0 ? 0 : y;
61  z = z < 0 ? 0 : z;
62  x = x >= static_cast< int >( grid->getNbCoordsX() ) ? static_cast< int >( grid->getNbCoordsX() ) - 1 : x;
63  y = y >= static_cast< int >( grid->getNbCoordsY() ) ? static_cast< int >( grid->getNbCoordsY() ) - 1 : y;
64  z = z >= static_cast< int >( grid->getNbCoordsZ() ) ? static_cast< int >( grid->getNbCoordsZ() ) - 1 : z;
65 
66  // calculate the index inside the grid
67  size_t nbX = grid->getNbCoordsX();
68  size_t nbXY = grid->getNbCoordsX() * grid->getNbCoordsY();
69  return x + y * nbX + z * nbXY;
70  }
71 }
72 
73 void WIntegrationParameterization::parameterizeVoxel( const WVector3i& voxel, size_t /*voxelIdx*/, const int /*axis*/,
74  const double /*value*/,
75  const WPosition& /*start*/,
76  const WPosition& /*end*/ )
77 {
78  // ok, this looks ugly but setting the whole 27-neighborhood produces better results
79  m_lengthValues[ wip::index( voxel[0], voxel[1]+1, voxel[2]+1, m_grid ) ] = m_curLength;
80  m_lengthValues[ wip::index( voxel[0], voxel[1]+1, voxel[2]-1, m_grid ) ] = m_curLength;
81  m_lengthValues[ wip::index( voxel[0], voxel[1]+1, voxel[2], m_grid ) ] = m_curLength;
82  m_lengthValues[ wip::index( voxel[0], voxel[1]-1, voxel[2]+1, m_grid ) ] = m_curLength;
83  m_lengthValues[ wip::index( voxel[0], voxel[1]-1, voxel[2]-1, m_grid ) ] = m_curLength;
84  m_lengthValues[ wip::index( voxel[0], voxel[1]-1, voxel[2], m_grid ) ] = m_curLength;
85  m_lengthValues[ wip::index( voxel[0], voxel[1], voxel[2]+1, m_grid ) ] = m_curLength;
86  m_lengthValues[ wip::index( voxel[0], voxel[1], voxel[2]-1, m_grid ) ] = m_curLength;
87  m_lengthValues[ wip::index( voxel[0], voxel[1], voxel[2], m_grid ) ] = m_curLength;
88 
89  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]+1, voxel[2]+1, m_grid ) ] = m_curLength;
90  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]+1, voxel[2]-1, m_grid ) ] = m_curLength;
91  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]+1, voxel[2], m_grid ) ] = m_curLength;
92  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]-1, voxel[2]+1, m_grid ) ] = m_curLength;
93  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]-1, voxel[2]-1, m_grid ) ] = m_curLength;
94  m_lengthValues[ wip::index( voxel[0]+1, voxel[1]-1, voxel[2], m_grid ) ] = m_curLength;
95  m_lengthValues[ wip::index( voxel[0]+1, voxel[1], voxel[2]+1, m_grid ) ] = m_curLength;
96  m_lengthValues[ wip::index( voxel[0]+1, voxel[1], voxel[2]-1, m_grid ) ] = m_curLength;
97  m_lengthValues[ wip::index( voxel[0]+1, voxel[1], voxel[2], m_grid ) ] = m_curLength;
98 
99  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]+1, voxel[2]+1, m_grid ) ] = m_curLength;
100  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]+1, voxel[2]-1, m_grid ) ] = m_curLength;
101  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]+1, voxel[2], m_grid ) ] = m_curLength;
102  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]-1, voxel[2]+1, m_grid ) ] = m_curLength;
103  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]-1, voxel[2]-1, m_grid ) ] = m_curLength;
104  m_lengthValues[ wip::index( voxel[0]-1, voxel[1]-1, voxel[2], m_grid ) ] = m_curLength;
105  m_lengthValues[ wip::index( voxel[0]-1, voxel[1], voxel[2]+1, m_grid ) ] = m_curLength;
106  m_lengthValues[ wip::index( voxel[0]-1, voxel[1], voxel[2]-1, m_grid ) ] = m_curLength;
107  m_lengthValues[ wip::index( voxel[0]-1, voxel[1], voxel[2], m_grid ) ] = m_curLength;
108 }
109 
111 {
112  // new line -> reset length
113  m_curLength = 0.0;
114 }
115 
117 {
118  // add this segments length
119  m_curLength += length2( start - end );
120 }
121 
This data set type contains scalars as values.
virtual void parameterizeVoxel(const WVector3i &voxel, size_t voxelIdx, const int axis, const double value, const WPosition &start, const WPosition &end)
This method allows this parameterization to update.
double m_curLength
The current length of a line.
std::vector< double > m_lengthValues
Stores the current length of the fiber at each voxel.
WIntegrationParameterization(std::shared_ptr< WGridRegular3D > grid)
Default constructor.
virtual void newSegment(const WPosition &start, const WPosition &end)
Gets called for each new line segment getting rasterized, as one segment can have multiple voxels.
virtual std::shared_ptr< WDataSetScalar > getDataSet()
Gets the dataset representing the parameterization.
virtual void newLine(const WLine &line)
Gets called for each new line getting rasterized.
A line is an ordered sequence of WPositions.
Definition: WLine.h:42
A fixed size matrix class.
Definition: WMatrixFixed.h:150
This only is a 3d double vector.
This class is the base for all specific parameterization algorithms.
std::shared_ptr< WGridRegular3D > m_grid
The grid, which needs to be used for the created dataset and to which the parameterizeVoxel method is...
Base Class for all value set types.
Definition: WValueSet.h:47