Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_PLANE_BOX_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_PLANE_BOX_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_aabb.h>
00013 #include <OpenTissue/core/geometry/geometry_plane.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace geometry
00018 {
00019
00083 template<typename math_types>
00084 class PlaneBox
00085 {
00086 public:
00087
00088 typedef typename math_types::value_traits value_traits;
00089 typedef typename math_types::vector3_type vector3_type;
00090 typedef typename math_types::real_type real_type;
00091 typedef Plane<math_types> plane_type;
00092
00093 protected:
00094
00095 typedef AABB<math_types> aabb_type;
00096
00097 aabb_type m_box;
00098 plane_type m_plane;
00099 int m_max_tick;
00100 int m_cur_tick;
00101 int m_axis;
00102
00103
00104 vector3_type m_p[4][3];
00105 vector3_type m_n[3];
00106
00107 public:
00108
00109 plane_type const & plane() const { return m_plane; }
00110 aabb_type const & box() const { return m_box; }
00111 vector3_type const & p0() const { return m_p[0][m_axis];}
00112 vector3_type const & p1() const { return m_p[1][m_axis];}
00113 vector3_type const & p2() const { return m_p[2][m_axis];}
00114 vector3_type const & p3() const { return m_p[3][m_axis];}
00115 vector3_type const & n() const { return m_n[m_axis]; }
00116
00117 public:
00118
00119 PlaneBox()
00120 : m_max_tick(100)
00121 , m_cur_tick(50)
00122 , m_axis(0)
00123 {
00124 m_n[0] = vector3_type(1,0,0);
00125 m_n[1] = vector3_type(0,1,0);
00126 m_n[2] = vector3_type(0,0,1);
00127 }
00128
00129 void init( vector3_type const & min_coord, vector3_type const & max_coord )
00130 {
00131 m_box.set(min_coord, max_coord);
00132 m_cur_tick = m_max_tick/2;
00133 update();
00134 }
00135
00136 void increment()
00137 {
00138 ++m_cur_tick;
00139 if(m_cur_tick>m_max_tick)
00140 m_cur_tick = m_max_tick;
00141 update();
00142 }
00143
00144 void decrement()
00145 {
00146 --m_cur_tick;
00147 if(m_cur_tick<0)
00148 m_cur_tick = 0;
00149 update();
00150 }
00151
00152 void set_x_axis(){ m_axis = 0; update(); }
00153 void set_y_axis(){ m_axis = 1; update(); }
00154 void set_z_axis(){ m_axis = 2; update(); }
00155
00156 protected:
00157
00158 void update()
00159 {
00160 real_type fraction = (value_traits::one()*m_cur_tick / m_max_tick);
00161
00162
00163 m_p[0][0] = m_box.min();
00164 m_p[1][0] = m_box.min() + vector3_type( value_traits::zero(), m_box.h(), value_traits::zero() );
00165 m_p[2][0] = m_box.min() + vector3_type( value_traits::zero(), m_box.h(), m_box.d() );
00166 m_p[3][0] = m_box.min() + vector3_type( value_traits::zero(), value_traits::zero(), m_box.d() );
00167
00168
00169 m_p[0][1] = m_box.min();
00170 m_p[1][1] = m_box.min() + vector3_type( value_traits::zero(), value_traits::zero(), m_box.d() );
00171 m_p[2][1] = m_box.min() + vector3_type( m_box.w(), value_traits::zero(), m_box.d() );
00172 m_p[3][1] = m_box.min() + vector3_type( m_box.w(), value_traits::zero(), value_traits::zero() );
00173
00174
00175 m_p[0][2] = m_box.min();
00176 m_p[1][2] = m_box.min() + vector3_type( m_box.w(), value_traits::zero(), value_traits::zero() );
00177 m_p[2][2] = m_box.min() + vector3_type( m_box.w(), m_box.h(), value_traits::zero() );
00178 m_p[3][2] = m_box.min() + vector3_type( value_traits::zero(), m_box.h(), value_traits::zero() );
00179
00180 m_p[0][0](0) += m_box.w()*fraction;
00181 m_p[1][0](0) += m_box.w()*fraction;
00182 m_p[2][0](0) += m_box.w()*fraction;
00183 m_p[3][0](0) += m_box.w()*fraction;
00184
00185 m_p[0][1](1) += m_box.h()*fraction;
00186 m_p[1][1](1) += m_box.h()*fraction;
00187 m_p[2][1](1) += m_box.h()*fraction;
00188 m_p[3][1](1) += m_box.h()*fraction;
00189
00190 m_p[0][2](2) += m_box.d()*fraction;
00191 m_p[1][2](2) += m_box.d()*fraction;
00192 m_p[2][2](2) += m_box.d()*fraction;
00193 m_p[3][2](2) += m_box.d()*fraction;
00194
00195 m_plane.set( m_n[m_axis], m_p[0][m_axis]);
00196
00197 }
00198
00199 };
00200
00201 }
00202 }
00203
00204
00205 #endif
00206
00207
00208