1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
25
#include <boost/shared_ptr.hpp>
27
#include "core/dataHandler/WGridRegular3D.h"
28
#include "core/common/math/WLine.h"
29
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
30
#include "WBresenhamDBL.h"
32
WBresenhamDBL::WBresenhamDBL( boost::shared_ptr< WGridRegular3D > grid, bool antialiased )
33
: WBresenham( grid, antialiased )
37
WBresenhamDBL::~WBresenhamDBL()
41
void WBresenhamDBL::rasterSegment( const WPosition& start, const WPosition& end )
44
WValue< int > gridStartPos = m_grid->getVoxelCoord( start );
45
WValue< int > gridEndPos = m_grid->getVoxelCoord( end );
46
int dx = gridEndPos[0] - gridStartPos[0];
47
int dy = gridEndPos[1] - gridStartPos[1];
48
int dz = gridEndPos[2] - gridStartPos[2];
49
int l = std::abs( dx );
50
int m = std::abs( dy );
51
int n = std::abs( dz );
52
int x_inc = ( dx < 0 ) ? -1 : 1;
53
int y_inc = ( dy < 0 ) ? -1 : 1;
54
int z_inc = ( dz < 0 ) ? -1 : 1;
59
WValue< int > voxel = gridStartPos;
60
WPosition gridOffset( 0, 0, 0 );
61
gridOffset[0] = start[0] - gridStartPos[0];
62
gridOffset[1] = start[1] - gridStartPos[1];
63
gridOffset[2] = start[2] - gridStartPos[2];
65
if( ( l >= m ) && ( l >= n ) )
67
err_1 = dy2 - l + gridOffset[1];
68
err_2 = dz2 - l + gridOffset[2];
69
for( i = 0; i < l; i++ )
71
markVoxel( voxel, 0, start, end );
82
// end of antialiased if-else
88
else if( ( m >= l ) && ( m >= n ) )
90
err_1 = dx2 - m + gridOffset[0];
91
err_2 = dz2 - m + gridOffset[2];
92
for( i = 0; i < m; i++ )
94
markVoxel( voxel, 1, start, end );
112
err_1 = dy2 - n + gridOffset[1];
113
err_2 = dx2 - n + gridOffset[0];
114
for( i = 0; i < n; i++ )
116
markVoxel( voxel, 2, start, end );
132
markVoxel( voxel, -1, start, end );