GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Geometry/ThreeDDDA.h
00001 #ifndef __GEOMETRY_THREEDDDA_H
00002 #define __GEOMETRY_THREEDDDA_H
00003 
00004 #ifdef _MSC_VER 
00005 typedef __int64 Integer64Bits;
00006 #else
00007 typedef int64_t Integer64Bits;
00008 #endif
00009 
00010 
00011 #include "CGLA/Vec3f.h"
00012 #include "CGLA/Vec3i.h"
00013 
00014 namespace Geometry
00015 {
00016 
00017 
00054         class ThreeDDDA
00055         {
00058                 const int PRECISION;
00059 
00061                 const CGLA::Vec3i sgn;
00062 
00064                 const CGLA::Vec3i p0_int;
00065 
00066                 // Fine grid position where the ray ends.
00067                 const CGLA::Vec3i p1_int;
00068 
00070                 const CGLA::Vec3i dir;
00071 
00073                 const CGLA::Vec3i first_cell;
00074 
00076                 const CGLA::Vec3i last_cell;
00077 
00080                 const int no_steps; 
00081 
00085                 const CGLA::Vec3i dir_pre_mul;
00086 
00092                 Integer64Bits disc[3][3];
00093 
00096                 CGLA::Vec3i cell;
00097 
00098 
00104                 const CGLA::Vec3i grid_pos(const CGLA::Vec3f& v) const;
00105         
00107                 CGLA::Vec3i get_cell(const CGLA::Vec3i& v) const;
00108         
00110                 CGLA::Vec3i mirror(const CGLA::Vec3i& v) const;
00111 
00112 
00113         public:
00114 
00117                 ThreeDDDA(const CGLA::Vec3f& p0, const CGLA::Vec3f& p1, 
00118                                                         int _PRECISION = 0x100);
00119         
00121                 int get_no_steps() const
00122                 {
00123                         return no_steps;
00124                 }
00125 
00127                 const CGLA::Vec3i& get_current_cell() const
00128                 {
00129                         return cell;
00130                 }
00131 
00133                 const CGLA::Vec3i& get_first_cell() const
00134                 {
00135                         return first_cell;
00136                 }
00137 
00139                 const CGLA::Vec3i& get_last_cell() const
00140                 {
00141                         return last_cell;
00142                 }
00143 
00145                 const CGLA::Vec3f get_first_point() const
00146                 {
00147                         return (CGLA::Vec3f(p0_int)+CGLA::Vec3f(0.5))/PRECISION;
00148                 }
00149 
00150 
00152                 const CGLA::Vec3f get_last_point() const
00153                 {
00154                         return (CGLA::Vec3f(p1_int)+CGLA::Vec3f(0.5))/PRECISION;
00155                 }
00156         
00158                 bool at_end() const
00159                 {
00160                         return cell == last_cell;
00161                 }
00162 
00164                 void operator++()
00165                 {
00166                         int step_dir;
00167                         if(disc[1][0] > disc[0][1])
00168                                 if(disc[2][0] > disc[0][2])
00169                                         step_dir = 0;
00170                                 else
00171                                         step_dir = 2;
00172                         else
00173                                 if(disc[2][1] > disc[1][2])
00174                                         step_dir = 1;
00175                                 else
00176                                         step_dir = 2;
00177                                 
00178                         const int k1 = (step_dir + 1) % 3;
00179                         const int k2 = (step_dir + 2) % 3;
00180                         cell[step_dir] += sgn[step_dir];
00181                         disc[step_dir][k1] += dir_pre_mul[k1];
00182                         disc[step_dir][k2] += dir_pre_mul[k2];
00183                 }
00184 
00186                         const CGLA::Vec3f step();
00187 
00188 
00189         };
00190 }
00191 
00192 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations