28 #include <shared_mutex>
32 #include "WBresenham.h"
33 #include "core/common/WAssert.h"
34 #include "core/common/WLogger.h"
35 #include "core/common/math/WLine.h"
36 #include "core/common/math/linearAlgebra/WPosition.h"
37 #include "core/common/math/linearAlgebra/WVectorFixed.h"
38 #include "core/dataHandler/WGridRegular3D.h"
42 m_antialiased( antialiased )
53 boost::shared_lock< std::shared_mutex > lock = boost::shared_lock< std::shared_mutex >(
m_parameterizationsLock );
59 wlog::debug(
"WBresenham" ) <<
"Tried to raster an empty line!, skipped.";
61 for(
size_t i = 1; i < line.
size(); ++i )
75 int dx = gridEndPos[0] - gridStartPos[0];
76 int dy = gridEndPos[1] - gridStartPos[1];
77 int dz = gridEndPos[2] - gridStartPos[2];
78 int l = std::abs( dx );
79 int m = std::abs( dy );
80 int n = std::abs( dz );
81 int x_inc = ( dx < 0 ) ? -1 : 1;
82 int y_inc = ( dy < 0 ) ? -1 : 1;
83 int z_inc = ( dz < 0 ) ? -1 : 1;
90 if( ( l >= m ) && ( l >= n ) )
94 for( i = 0; i < l; i++ )
113 else if( ( m >= l ) && ( m >= n ) )
117 for( i = 0; i < m; i++ )
139 for( i = 0; i < n; i++ )
167 std::vector< WPosition > x;
169 x.push_back(
m_grid->getPosition( voxelNum ) - start );
170 x.push_back(
m_grid->getPosition( voxelNum + 1 ) - start );
171 x.push_back(
m_grid->getPosition( voxelNum - 1 ) - start );
172 x.push_back(
m_grid->getPosition( voxelNum +
m_grid->getNbCoordsX() ) - start );
173 x.push_back(
m_grid->getPosition( voxelNum -
m_grid->getNbCoordsX() ) - start );
174 x.push_back(
m_grid->getPosition( voxelNum +
m_grid->getNbCoordsX() *
m_grid->getNbCoordsY() ) - start );
175 x.push_back(
m_grid->getPosition( voxelNum -
m_grid->getNbCoordsX() *
m_grid->getNbCoordsY() ) - start );
177 std::vector< double > result;
181 for(
size_t i = 0; i < x.size(); ++i )
184 result.push_back( std::abs( length( x[i] - lot ) ) );
191 return std::max( newValue, existingValue );
197 size_t nbX =
m_grid->getNbCoordsX();
198 size_t nbXY =
m_grid->getNbCoordsX() *
m_grid->getNbCoordsY();
202 size_t idx = x + y * nbX + z * nbXY;
203 std::vector< double > distances;
223 int nbXInt =
m_grid->getNbCoordsX();
224 int nbYInt =
m_grid->getNbCoordsY();
225 int nbZInt =
m_grid->getNbCoordsZ();
226 if( voxel[0] < margin || voxel[0] >= nbXInt - 1 ||
227 voxel[1] < margin || voxel[1] >= nbYInt - 1 ||
228 voxel[2] < margin || voxel[2] >= nbZInt - 1
239 WAssert( distances.size() == 7,
"There is an invalid number of precomputed antialiased voxels" );
277 default : WAssert( 0,
"Invalid axis selected for marking a voxel" );
283 WAssert( distance >= 0,
"Negative distances are forbidden" );
288 size_t bucket = std::floor( distance * 10 );
289 double tableData[] = { 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1 };
290 std::vector< double > lookUpTable( tableData, tableData +
sizeof( tableData ) /
sizeof(
double ) );
291 return lookUpTable.at( bucket );
virtual void raster(const WLine &line)
Rasterize the given line into the grid of dataset.
WBresenham(std::shared_ptr< WGridRegular3D > grid, bool antialiased=true)
Initializes new raster algo.
virtual double filter(const double distance) const
Returns the value to mark the hit voxels with, depending on their distance to the line.
bool m_antialiased
If true also some supporting voxels are marked.
virtual void markVoxel(const WVector3i &voxel, const int axis, const WPosition &start, const WPosition &end)
Marks the given voxel as a hit.
double composeValue(double newValue, double existingValue) const
Compose the new value for a voxel out of a new computed value and the already existing marking.
virtual ~WBresenham()
Finishes this raster algo.
std::vector< double > computeDistances(const size_t voxelNum, const WPosition &start, const WPosition &end) const
Computes the distances for a voxel to the real line segment and also for its supporting voxels.
virtual void rasterSegment(const WPosition &start, const WPosition &end)
Scans a line segment for voxels which are hit.
A line is an ordered sequence of WPositions.
A fixed size matrix class.
size_type size() const
Wrapper around std::vector member function.
This only is a 3d double vector.
Base class for all rasterization algorithms.
std::shared_ptr< WGridRegular3D > m_grid
The grid is used for the following purposes:
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.
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.
WStreamedLogger debug(const std::string &source)
Logging a debug message.