00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00125
00126 ThrowError("DrawSegment3D with antialiasing is not implemented yet");
00127 }
00128 }
00129 #endif// _Draw_hxx