clipping.hpp
Go to the documentation of this file.
00001 
00063 #ifndef COB_3D_CLIPPING_HPP
00064 #define COB_3D_CLIPPING_HPP
00065 
00066 namespace cob_3d_mapping
00067 {
00068   bool CohenSutherLandClipping::clip(const Eigen::Vector3f& p0,
00069                                      const Eigen::Vector3f& p1,
00070                                      Eigen::Vector3f& q0,
00071                                      Eigen::Vector3f& q1)
00072   {
00073     int code0 = computeCode(p0(0),p0(1),p0(2));
00074     int code1 = computeCode(p1(0),p1(1),p1(2));
00075     bool accept = false;
00076 
00077     if( !(code0 | code1) ) // trivial accept
00078     {
00079       accept = true;
00080       q0 = p0;
00081       q1 = p1;
00082     }
00083     else if( !(code0 & code1) )
00084     {
00085       /* Line:  q = (p1 - p0) * d + p0
00086        * Plane: (q - c).dot(n)           c: point on plane, n: normal of plane
00087        *
00088        *           (p0 - c).dot(n)
00089        * => d =  ------------------
00090        *          (p1 - p0).dot(n)
00091        */
00092       float x, y, z, d;
00093       int outcode;
00094       Eigen::Vector3f *pnew;
00095       const Eigen::Vector3f *pold;
00096       if(code0)
00097       { // check which point lies outside
00098         outcode = code0;
00099         pnew = &q0;
00100         pold = &p1;
00101       }
00102       else
00103       {
00104         outcode = code1;
00105         pold = &p0;
00106         pnew = &q1;
00107       }
00108 
00109       if(outcode & FAR)
00110       {
00111         d = (zmax - p0(2)) / (p1(2) - p0(2));
00112         (*pnew)(0) = (p1(0) - p0(0)) * d + p0(0);
00113         (*pnew)(1) = (p1(1) - p0(1)) * d + p0(1);
00114         (*pnew)(2) = zmax;
00115       }
00116       else if(outcode & NEAR)
00117       {
00118         d = (zmin - p0(2)) / (p1(2) - p0(2));
00119         (*pnew)(0) = (p1(0) - p0(0)) * d + p0(0);
00120         (*pnew)(1) = (p1(1) - p0(1)) * d + p0(1);
00121         (*pnew)(2) = zmin;
00122       }
00123       else if(outcode & BOTTOM)
00124       {
00125         d = (ymax - p0(1)) / (p1(1) - p0(1));
00126         (*pnew)(0) = (p1(0) - p0(0)) * d + p0(0);
00127         (*pnew)(1) = ymax;
00128         (*pnew)(2) = (p1(2) - p0(2)) * d + p0(2);
00129       }
00130       else if(outcode & TOP)
00131       {
00132         d = (ymin - p0(1)) / (p1(1) - p0(1));
00133         (*pnew)(0) = (p1(0) - p0(0)) * d + p0(0);
00134         (*pnew)(1) = ymin;
00135         (*pnew)(2) = (p1(2) - p0(2)) * d + p0(2);
00136       }
00137       else if(outcode & RIGHT)
00138       {
00139         d = (xmax - p0(0)) / (p1(0) - p0(0));
00140         (*pnew)(0) = xmax;
00141         (*pnew)(1) = (p1(1) - p0(1)) * d + p0(1);
00142         (*pnew)(2) = (p1(2) - p0(2)) * d + p0(2);
00143       }
00144       else /*(outcode & LEFT)*/
00145       {
00146         d = (xmin - p0(0)) / (p1(0) - p0(0));
00147         (*pnew)(0) = xmin;
00148         (*pnew)(1) = (p1(1) - p0(1)) * d + p0(1);
00149         (*pnew)(2) = (p1(2) - p0(2)) * d + p0(2);
00150       }
00151       accept = clip(*pold,*pnew,q0,q1);
00152     }
00153 
00154     return accept;
00155   }
00156 }


cob_3d_fov_segmentation
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:19