mi32/fillpoly.h

Go to the documentation of this file.
00001 /**
00002  * \file fillpoly.h <mi32/fillpoly.h>
00003  * \brief Definitions for FILLPOLYGON class
00004  *
00005  * \if NODOC
00006  * $Id: fillpoly.h_v 1.3 2003/09/15 13:49:56 fileserver!dwilliss Exp $
00007  *
00008  * $Log: fillpoly.h_v $
00009  * Revision 1.3  2003/09/15 13:49:56  fileserver!dwilliss
00010  * Doxygen
00011  *
00012  * Revision 1.2  2002/08/22 15:41:08  vdronov
00013  * const_cast was used in operator=
00014  *
00015  * Revision 1.1  2002/08/21 14:25:31  vdronov
00016  * Initial revision
00017  *
00018  * \endif
00019 **/
00020 
00021 
00022 #ifndef  INC_MI32_FILLPOLY_H
00023 #define  INC_MI32_FILLPOLY_H
00024 
00025 #include <mi32/polyline.h>
00026 
00027 //! FILLPOLYGON class provides MakeScans method
00028 class FILLPOLYGON {
00029    public:
00030 
00031    //! An interface that deal with result of fill polygon
00032    class SPAN {
00033       public:
00034          void Process(const double x1, const double x2, const double y) {VProcess(x1,x2,y);}; 
00035       private:
00036          virtual void VProcess(const double x1, const double x2, const double y) = 0; 
00037       };
00038 
00039    //! MakeScans method creates set of scans of polygon "points" depends on "origin" and "step"
00040    //! and call method "Process" of "span" for each scan.
00041    static ERRVALUE MakeScans (
00042       const POLYLINE& polyline,
00043       SPAN& span,
00044       const double origin = 0.0,
00045       const double step = 1.0
00046       );
00047 
00048    private:
00049       #ifndef GENERATING_DOXYGEN_OUTPUT
00050 
00051       class EDGE {
00052          public:
00053 
00054          EDGE (
00055             const DPOINT2D& p1,           
00056             const DPOINT2D& p2            
00057             ) :
00058             m_YMin(MIN(p1.y,p2.y)),
00059             m_YMax(MAX(p1.y,p2.y)),
00060             m_DX((p1.y != p2.y) ? (p2.x - p1.x) / (p2.y - p1.y) : 0.0),
00061             m_X((p1.y < p2.y) ? p1.x : p2.x)
00062             {
00063             }
00064 
00065          EDGE& operator= (
00066             const EDGE& rhs
00067             ) {
00068             if (this != &rhs) {
00069                const_cast<double&>(m_YMin) = rhs.m_YMin;
00070                const_cast<double&>(m_YMax) = rhs.m_YMax;
00071                const_cast<double&>(m_DX) = rhs.m_DX;
00072                m_X = rhs.m_X;
00073                }
00074             return (*this);
00075             }
00076 
00077          bool IsHorizontal (
00078             ) const {
00079             return (m_YMin == m_YMax);
00080             }
00081 
00082          void SetX (
00083             const double y
00084             ) {
00085             m_X += m_DX * (y - m_YMin);
00086             return;
00087             }
00088 
00089          double GetX (
00090             ) {
00091             return m_X;
00092             }
00093 
00094          void UpdateX (
00095             ) {
00096             m_X += m_DX;
00097             return;
00098             }
00099 
00100          const double m_YMin;
00101          const double m_YMax;
00102          const double m_DX;
00103 
00104          private:
00105 
00106          double m_X;
00107          };
00108 
00109    static int DoubleLessCompare (
00110       const void *p1,
00111       const void *p2
00112       ) {
00113       const double *d1 = static_cast<const double*>(p1);
00114       const double *d2 = static_cast<const double*>(p2);
00115 
00116       if (*d1 > *d2) return 1;
00117       if (*d1 < *d2) return -1;
00118       return 0;
00119       };
00120 
00121    static int EdgeYMinGreaterCompare (
00122       const void *p1,
00123       const void *p2
00124       ) {
00125       const EDGE *d1 = static_cast<const EDGE*>(p1);
00126       const EDGE *d2 = static_cast<const EDGE*>(p2);
00127 
00128       if (d1->m_YMin < d2->m_YMin) return 1;
00129       if (d1->m_YMin > d2->m_YMin) return -1;
00130       return 0;
00131       };
00132 
00133       //! Not implemented
00134       FILLPOLYGON();
00135       ~FILLPOLYGON();
00136       FILLPOLYGON(const FILLPOLYGON&);
00137       #endif // GENERATING_DOXYGEN_OUTPUT
00138 
00139    };
00140 
00141 #endif   //!< INC_MI32_FILLPOLY_H
00142 

Generated on Thu Aug 12 06:18:32 2004 for TNTsdk by doxygen 1.3.4-20031026