Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Draw.hxx

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00020 #ifndef _Draw_hxx
00021 #define _Draw_hxx
00022 
00024 template <class ImageType>
00025 void
00026 IP3D::DrawSegment3D(const ImageType& src, const Segment3D& segment , const Pen<typename ImageType::value_type> &pen,ImageType& res0)
00027 {
00028     ImageProcessorArgs<ImageType> args(ImArgs(src),ImageArg<ImageType>(res0, IMARG_INPLACE));
00029     args.SameSize();
00030     ImageType &res=args.GetDest();
00031 
00032     if(!pen.Antialias())
00033     {
00034         // draw line without antialiasing
00035         RectZone3Di cube(0,0,0,res.Width(), res.Height(), res.Depth());
00036         Vect3Di pos = floor(segment.p0);
00037         int dx = (int)segment.p1.x - (int)segment.p0.x;
00038         int dy = (int)segment.p1.y - (int)segment.p0.y;
00039         int dz = (int)segment.p1.z - (int)segment.p0.z;
00040         int xInc = (dx < 0) ? -1 : 1;
00041         int l = abs(dx);
00042         int yInc = (dy < 0) ? -1 : 1;
00043         int m = abs(dy);
00044         int zInc = (dz < 0) ? -1 : 1;
00045         int n = abs(dz);
00046         int dx2 = l << 1;
00047         int dy2 = m << 1;
00048         int dz2 = n << 1;
00049     
00050         int err1, err2;
00051         if ((l >=m) && (l >=n))
00052         {
00053             err1 = dy2 - l;
00054             err2 = dz2 - l;
00055             for (int i=0; i< l; i++)
00056             {
00057                 if (cube.IsInside(pos))
00058                 res(pos) = pen.Color();
00059                 if (err1 > 0)
00060                 {
00061                     pos.y += yInc;
00062                     err1 -= dx2;
00063                 }
00064                 if (err2 > 0)
00065                 {
00066                     pos.z += zInc;
00067                     err2 -= dx2;
00068                 }
00069                 err1 += dy2;
00070                 err2 += dz2;
00071                 pos.x += xInc;
00072             }
00073         }
00074         else if ((m >= l) && (m >= n))
00075         {
00076             err1 = dx2 - m;
00077             err2 = dz2 - m;
00078             for (int i=0; i < m; i++)
00079             {
00080                 if (cube.IsInside(pos))
00081                 res(pos) = pen.Color();
00082                 if (err1 > 0)
00083                 {
00084                     pos.x += xInc;
00085                     err1 -= dy2;
00086                 }
00087                 if (err2 > 0)
00088                 {
00089                     pos.z += zInc;
00090                     err2 -= dy2;
00091                 }
00092                 err1 += dx2;
00093                 err2 += dz2;
00094                 pos.y += yInc;
00095             }
00096         }
00097         else 
00098         {
00099             err1 = dy2 - n;
00100             err2 = dx2 - n;
00101             for (int i=0; i < n; i++)
00102             {
00103                 if (cube.IsInside(pos))
00104                 res(pos) = pen.Color();
00105                 if (err1 > 0)
00106                 {
00107                     pos.y += yInc;
00108                     err1 -= dz2;
00109                 }
00110                 if (err2 > 0)
00111                 {
00112                     pos.x += xInc;
00113                     err2 -= dz2;
00114                 }
00115                 err1 += dy2;
00116                 err2 += dx2;
00117                 pos.z += zInc;
00118             }
00119         }
00120         if (cube.IsInside(pos)){res(pos) = pen.Color();}
00121     }
00122     else
00123     {
00124         // draw line using antialiasing
00125         // segment is actually a cylinder ... argh this was more complicated than initially thought
00126         ThrowError("DrawSegment3D with antialiasing is not implemented yet");
00127     }
00128 }
00129 #endif// _Draw_hxx

Generated on Fri Jun 17 13:36:00 2005 for ImLib3D by  doxygen 1.4.2