Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_TETRAHEDRON_Z_SLICER_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_TETRAHEDRON_Z_SLICER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace geometry
00015 {
00024 template<typename vector3_type_>
00025 class ZTetrahedronSlicer
00026 {
00027 public:
00028
00029 typedef vector3_type_ vector3_type;
00030 typedef typename vector3_type::value_type real_type;
00031
00032 protected:
00033
00034 vector3_type m_p[4];
00035
00036 public:
00037
00038 ZTetrahedronSlicer(
00039 vector3_type const & p0
00040 , vector3_type const & p1
00041 , vector3_type const & p2
00042 , vector3_type const & p3
00043 )
00044 {
00045 m_p[0] = p0;
00046 m_p[1] = p1;
00047 m_p[2] = p2;
00048 m_p[3] = p3;
00049
00050
00051
00052 while(swap(0,1)||swap(1,2)||swap(2,3));
00053 };
00054
00055 protected:
00056
00065 bool swap(int i,int j)
00066 {
00067 if(m_p[j](2)< m_p[i](2))
00068 {
00069 vector3_type tmp = m_p[j];
00070 m_p[j] = m_p[i];
00071 m_p[i] = tmp;
00072 return true;
00073 }
00074 return false;
00075 };
00076
00085 void intersect(real_type const & z, int i, int j, vector3_type & p) const
00086 {
00087 p = m_p[i];
00088 vector3_type dir = m_p[j] - m_p[i];
00089 real_type s = (z-m_p[i](2))/(m_p[j](2)-m_p[i](2));
00090 p += s * dir;
00091 };
00092
00093 public:
00094
00103 unsigned int intersect(real_type const & z, vector3_type slice[4]) const
00104 {
00105 if( z < m_p[0](2) || z > m_p[3](2) )
00106 return 0;
00107 if( z<m_p[1](2) )
00108 {
00109 intersect(z,0,3, slice[0]);
00110 intersect(z,0,1, slice[1]);
00111 intersect(z,0,2, slice[2]);
00112 return 3;
00113 }
00114 else if( z<m_p[2](2) )
00115 {
00116 intersect(z,0,3, slice[0]);
00117 intersect(z,1,3, slice[1]);
00118 intersect(z,1,2, slice[2]);
00119 intersect(z,0,2, slice[3]);
00120 return 4;
00121 }
00122 else
00123 {
00124 intersect(z,0,3, slice[0]);
00125 intersect(z,1,3, slice[1]);
00126 intersect(z,2,3, slice[2]);
00127 return 3;
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 };
00160
00161 }
00162 }
00163
00164
00165 #endif