OpenWalnut  1.5.0dev
WRasterAlgorithm.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 <shared_mutex>
27 #include <vector>
28 
29 
30 #include "WRasterAlgorithm.h"
31 #include "core/common/WLogger.h"
32 #include "core/common/math/linearAlgebra/WVectorFixed.h"
33 #include "core/dataHandler/WDataSetScalar.h"
34 #include "core/dataHandler/WGridRegular3D.h"
35 
36 WRasterAlgorithm::WRasterAlgorithm( std::shared_ptr< WGridRegular3D > grid )
37  : m_grid( grid ),
38  m_values( grid->size(), 0.0 )
39 {
40  // NOTE: I assume the Voxelizer class is only used by the WMVoxelizer module, hence the
41  // source is "Voxelizer".
42  wlog::debug( "Voxelizer" ) << "WRasterAlogrithm created " << m_values.size() << " values.";
43 }
44 
46 {
47 }
48 
49 std::shared_ptr< WDataSetScalar > WRasterAlgorithm::generateDataSet() const
50 {
51  std::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0,
52  1,
53  std::shared_ptr< std::vector< double > >(
54  new std::vector< double >( m_values ) ),
55  W_DT_DOUBLE ) );
56  return std::shared_ptr< WDataSetScalar >( new WDataSetScalar( valueSet, m_grid ) );
57 }
58 
59 void WRasterAlgorithm::addParameterizationAlgorithm( std::shared_ptr< WRasterParameterization > algorithm )
60 {
61  std::unique_lock< std::shared_mutex > lock = std::unique_lock< std::shared_mutex >( m_parameterizationsLock );
62  m_parameterizations.push_back( algorithm );
63  lock.unlock();
64 }
65 
66 void WRasterAlgorithm::newLine( const WLine& line )
67 {
68  // NOTE: the list already is locked (in raster method, hopefully)
69  for( size_t i = 0; i < m_parameterizations.size(); ++i )
70  {
71  m_parameterizations[ i ]->newLine( line );
72  }
73 }
74 
75 void WRasterAlgorithm::newSegment( const WPosition& start, const WPosition& end )
76 {
77  // NOTE: the list already is locked (in raster method, hopefully)
78  for( size_t i = 0; i < m_parameterizations.size(); ++i )
79  {
80  m_parameterizations[ i ]->newSegment( start, end );
81  }
82 }
83 
84 void WRasterAlgorithm::parameterizeVoxel( const WVector3i& voxel, size_t voxelIdx, const int axis, const double value,
85  const WPosition& start,
86  const WPosition& end )
87 {
88  // NOTE: the list already is locked (in raster method, hopefully)
89  for( size_t i = 0; i < m_parameterizations.size(); ++i )
90  {
91  m_parameterizations[ i ]->parameterizeVoxel( voxel, voxelIdx, axis, value, start, end );
92  }
93 }
94 
96 {
97  // lock the parameterization list for reading
98  boost::shared_lock< std::shared_mutex > lock = boost::shared_lock< std::shared_mutex >( m_parameterizationsLock );
99 
100  // NOTE: the list already is locked (in raster method, hopefully)
101  for( size_t i = 0; i < m_parameterizations.size(); ++i )
102  {
103  m_parameterizations[ i ]->finished();
104  }
105 
106  lock.unlock();
107 }
108 
This data set type contains scalars as values.
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.
std::shared_ptr< WDataSetScalar > generateDataSet() const
Computes a dataset out of our voxel values and the previously given grid.
void addParameterizationAlgorithm(std::shared_ptr< WRasterParameterization > algorithm)
This method allows the user of the raster algorithm to add arbitrary parameterizations.
std::shared_ptr< WGridRegular3D > m_grid
The grid is used for the following purposes:
std::vector< std::shared_ptr< WRasterParameterization > > m_parameterizations
All the parameterization algorithms to apply while rasterizing a line.
virtual void finished()
Called whenever all lines have been rasterized.
virtual void parameterizeVoxel(const WVector3i &voxel, size_t voxelIdx, const int axis, const double value, const WPosition &start, const WPosition &end)
This method allows all registered parameterization algorithms to update.
WRasterAlgorithm(std::shared_ptr< WGridRegular3D > grid)
Creates new raster algorithm within the given grid.
std::shared_mutex m_parameterizationsLock
The mutex used to lock access to m_parameterizations.
std::vector< double > m_values
Stores the value of each voxel.
virtual void newLine(const WLine &line)
Distribute a new line getting rasterized to all parameterize algorithms.
virtual void newSegment(const WPosition &start, const WPosition &end)
Distribute a new segment of a line to all parameterization algorithms.
virtual ~WRasterAlgorithm()
Dispose a this raster algorithm.
Base Class for all value set types.
Definition: WValueSet.h:47
WStreamedLogger debug(const std::string &source)
Logging a debug message.
Definition: WLogger.h:331