OpenWalnut  1.5.0dev
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
WBresenham Class Reference

Implements basic Bresenham algorithm for rasterization. More...

#include <WBresenham.h>

+ Inheritance diagram for WBresenham:
+ Collaboration diagram for WBresenham:

Public Member Functions

 WBresenham (std::shared_ptr< WGridRegular3D > grid, bool antialiased=true)
 Initializes new raster algo. More...
 
virtual ~WBresenham ()
 Finishes this raster algo. More...
 
virtual void raster (const WLine &line)
 Rasterize the given line into the grid of dataset. More...
 
- Public Member Functions inherited from WRasterAlgorithm
 WRasterAlgorithm (std::shared_ptr< WGridRegular3D > grid)
 Creates new raster algorithm within the given grid. More...
 
virtual ~WRasterAlgorithm ()
 Dispose a this raster algorithm. More...
 
std::shared_ptr< WDataSetScalargenerateDataSet () const
 Computes a dataset out of our voxel values and the previously given grid. More...
 
void addParameterizationAlgorithm (std::shared_ptr< WRasterParameterization > algorithm)
 This method allows the user of the raster algorithm to add arbitrary parameterizations. More...
 
virtual void finished ()
 Called whenever all lines have been rasterized. More...
 

Protected Member Functions

virtual void rasterSegment (const WPosition &start, const WPosition &end)
 Scans a line segment for voxels which are hit. More...
 
virtual void markVoxel (const WVector3i &voxel, const int axis, const WPosition &start, const WPosition &end)
 Marks the given voxel as a hit. More...
 
virtual double filter (const double distance) const
 Returns the value to mark the hit voxels with, depending on their distance to the line. More...
 
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. More...
 
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. More...
 
- Protected Member Functions inherited from WRasterAlgorithm
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. More...
 
virtual void newLine (const WLine &line)
 Distribute a new line getting rasterized to all parameterize algorithms. More...
 
virtual void newSegment (const WPosition &start, const WPosition &end)
 Distribute a new segment of a line to all parameterization algorithms. More...
 

Protected Attributes

bool m_antialiased
 If true also some supporting voxels are marked. More...
 
- Protected Attributes inherited from WRasterAlgorithm
std::vector< std::shared_ptr< WRasterParameterization > > m_parameterizations
 All the parameterization algorithms to apply while rasterizing a line. More...
 
std::shared_mutex m_parameterizationsLock
 The mutex used to lock access to m_parameterizations. More...
 
std::shared_ptr< WGridRegular3Dm_grid
 The grid is used for the following purposes: More...
 
std::vector< double > m_values
 Stores the value of each voxel. More...
 

Friends

class WBresenhamTest
 Only UnitTests may be friends. More...
 

Detailed Description

Implements basic Bresenham algorithm for rasterization.

Definition at line 42 of file WBresenham.h.

Constructor & Destructor Documentation

◆ WBresenham()

WBresenham::WBresenham ( std::shared_ptr< WGridRegular3D grid,
bool  antialiased = true 
)

Initializes new raster algo.

Parameters
gridThe grid which defines the voxels which should be marked.
antialiasedIf true then all voxels of a line are supported with anti-aliasing voxels around

Definition at line 40 of file WBresenham.cpp.

◆ ~WBresenham()

WBresenham::~WBresenham ( )
virtual

Finishes this raster algo.

Definition at line 46 of file WBresenham.cpp.

Member Function Documentation

◆ composeValue()

double WBresenham::composeValue ( double  newValue,
double  existingValue 
) const
protected

Compose the new value for a voxel out of a new computed value and the already existing marking.

Parameters
newValueNewly computed value
existingValueThe mark already existing for the voxel (aka previous mark or markSoFar)
Returns
The new mark for that voxel

Definition at line 189 of file WBresenham.cpp.

Referenced by markVoxel().

+ Here is the caller graph for this function:

◆ computeDistances()

std::vector< double > WBresenham::computeDistances ( const size_t  voxelNum,
const WPosition start,
const WPosition end 
) const
protected

Computes the distances for a voxel to the real line segment and also for its supporting voxels.

Parameters
voxelNumThe voxel number
startStart point of the line segment
endEnd point of the line segment
Returns
A vector of distances where first distance is the distance of the voxel itself, then x+1, x-1 supporting voxel, then y+1 and y-1 and at last z+1 and z-1.

Definition at line 160 of file WBresenham.cpp.

References WRasterAlgorithm::m_grid.

Referenced by markVoxel().

+ Here is the caller graph for this function:

◆ filter()

double WBresenham::filter ( const double  distance) const
protectedvirtual

Returns the value to mark the hit voxels with, depending on their distance to the line.

Parameters
distanceDistance of the voxel to the line.
Returns
Value which is used for marking a voxel.

Definition at line 281 of file WBresenham.cpp.

Referenced by markVoxel().

+ Here is the caller graph for this function:

◆ markVoxel()

void WBresenham::markVoxel ( const WVector3i voxel,
const int  axis,
const WPosition start,
const WPosition end 
)
protectedvirtual

Marks the given voxel as a hit.

If anti-aliasing is enabled also some supporting voxels nearby are marked. The value for marking the voxel depends on the distance from its center point to the real line.

Parameters
voxelThe voxel to mark
axisAlong which axis the traversal takes place. Since when walking in e.g. X-direction there are not supporting voxels in the same direction.
startStart point of the line segment (used to computed the distance)
endEnd point of the line segment (used to computed the distance)

Definition at line 195 of file WBresenham.cpp.

References composeValue(), computeDistances(), filter(), m_antialiased, WRasterAlgorithm::m_grid, WRasterAlgorithm::m_values, and WRasterAlgorithm::parameterizeVoxel().

Referenced by rasterSegment(), and WBresenhamDBL::rasterSegment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raster()

void WBresenham::raster ( const WLine line)
virtual

Rasterize the given line into the grid of dataset.

The value of the voxel which will be hit changes its value.

Parameters
linePolyline which is about to be rastered.

Implements WRasterAlgorithm.

Definition at line 50 of file WBresenham.cpp.

References wlog::debug(), WRasterAlgorithm::m_parameterizationsLock, WRasterAlgorithm::newLine(), WRasterAlgorithm::newSegment(), rasterSegment(), and WMixinVector< ValueT >::size().

+ Here is the call graph for this function:

◆ rasterSegment()

void WBresenham::rasterSegment ( const WPosition start,
const WPosition end 
)
protectedvirtual

Scans a line segment for voxels which are hit.

Warning
Not every voxel which is hit by the segment will be marked but at least so many voxels so that the segment is represented by those voxels.
Every line starting in voxel A and ending in voxel B is rastered the same way as the line from the middlepoint of A to the middlepoint of B.
Note
This algorithm is fast since using only integer operations. This is the real Bresenham
Parameters
startStart point of the line segment
endEnd point of the line segment

Reimplemented in WBresenhamDBL.

Definition at line 70 of file WBresenham.cpp.

References WRasterAlgorithm::m_grid, and markVoxel().

Referenced by raster().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WBresenhamTest

friend class WBresenhamTest
friend

Only UnitTests may be friends.

Definition at line 47 of file WBresenham.h.

Member Data Documentation

◆ m_antialiased

bool WBresenham::m_antialiased
protected

If true also some supporting voxels are marked.

Definition at line 140 of file WBresenham.h.

Referenced by markVoxel().


The documentation for this class was generated from the following files: