mi32/bintoreg.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * \file mi32/bintoreg.h
00004  * \brief A Binary raster to region converer class
00005  *
00006  * \if NODOC
00007  * $Log: bintoreg.h_v $
00008  * Revision 1.4  2005/03/09 22:56:20  mju
00009  * Eliminate most virtual overrides, now all goes through ProcessLine.
00010  *
00011  * Revision 1.3  2004/09/24 15:01:17  mju
00012  * Add isPointOnSpan.
00013  *
00014  * Revision 1.2  2004/07/02 17:38:29  dwilliss
00015  * Added AddSpansFromBytes
00016  *
00017  * Revision 1.1  2003/12/15 17:26:58  dwilliss
00018  * Initial revision
00019  * \endif
00020 **/
00021 
00022 #ifndef INC_MI32_BINTOREG_H
00023 #define INC_MI32_BINTOREG_H
00024 
00025 #ifndef INC_MI32_SIMPLEAR_H
00026 #include <mi32/simplear.h>
00027 #endif
00028 
00029 #ifndef INC_MI32_POLYLINE_H
00030 #include <mi32/polyline.h>
00031 #endif
00032 
00033 #ifndef INC_MI32_REGION2D_H
00034 #include <mi32/region2d.h>
00035 #endif
00036 
00037 
00038 
00039 //! Class for converting a binary raster to a region.
00040 //!
00041 //! This is a generic base class which can be extended to create any sort of
00042 //! region: REGION2D, X region or Windows Region.
00043 class BINARYTOREGIONINTERFACE {
00044    public:
00045 
00046       //! Add a span to the region.
00047       //! This is used to transfer the binary object (whatever the source)
00048       //! into a format that this class can use.
00049       //! Note, this method makes sure that the spans are kept in order and
00050       //! combines spans which overlap. 
00051       //! If you know you're adding spans in top-to-bottom, left-to-right order,
00052       //! call AddSpanFast() instead.
00053       ERRVALUE AddSpan (
00054          INT32 x1,
00055          INT32 x2,
00056          INT32 y
00057          );
00058 
00059       //! Add a span to the region.
00060       //! This is used to transfer the binary object (whatever the source)
00061       //! into a format that this class can use.
00062       //! Note, no attempt is made to keep the spans sorted or make sure the 
00063       //! span does not overlap any existing spans.  If you know you're adding
00064       //! spans in top-to-bottom, left-to-right order, you can use this method
00065       //! and it will be much faster than AddSpan()
00066       ERRVALUE AddSpanFast (
00067          INT32 x1,
00068          INT32 x2,
00069          INT32 y
00070          );
00071 
00072       //! Add spans to the region from a buffer of UINT8s
00073       //!
00074       //! This function takes an array of UINT8s representing a raster line
00075       //! and adds spans for all of the non-zero runs.
00076       //! The buffer is treated as one byte per pixel with 0 being false and
00077       //! non-zero being true.
00078       //! 
00079       //! The bFast parameter tells the function whether or not you're procssing
00080       //! lines in a top-down order without back-tracking.  If you are, pass
00081       //! true and it can add the spans without having to keep them sorted.
00082       ERRVALUE AddSpansFromBytes (
00083          INT32 lin,
00084          INT32 col,
00085          INT32 len,
00086          const UINT8* buf,
00087          bool bFast = false
00088          );
00089 
00090       //! Clear any existing spans.
00091       void Clear (
00092          );
00093 
00094       //! Determine if specified point is on existing span.
00095       bool IsPointOnSpan (
00096          INT32 x,
00097          INT32 y
00098          ) const;
00099 
00100       //! Process the spans that have been set.
00101       ERRVALUE ProcessSpans (
00102          );
00103 
00104    protected:
00105 
00106       BINARYTOREGIONINTERFACE ();
00107 
00108       virtual ~BINARYTOREGIONINTERFACE ();
00109 
00110    private:
00111 
00112       #ifndef GENERATING_DOXYGEN_OUTPUT
00113 
00114       struct SPAN {
00115          INT32 start;
00116          INT32 end;
00117          };
00118 
00119       typedef SIMPLE_ARRAY<SPAN> SPANARRAY;
00120 
00121       SIMPLE_ARRAY<SPANARRAY*> m_Spans;
00122 
00123       void FillSpan (
00124          INT32 x1,
00125          INT32 x2,
00126          INT32 y
00127          );
00128 
00129       static int TraceTest (
00130          INT32 x,
00131          INT32 y,
00132          void* cbdata
00133          );
00134 
00135       static int FillSpan (
00136          INT32 x1,
00137          INT32 x2,
00138          INT32 y,
00139          void* cbdata
00140          );
00141 
00142       #endif   // GENERATING_DOXYGEN_OUTPUT
00143 
00144       // Overridables
00145 
00146       //! Clear the current region.
00147       //! Will be called by the Clear() method, which also gets called by
00148       //! the destructor.
00149       virtual void v_Clear ();
00150 
00151       //! Add or remove a line from the region.
00152       //! Note that the points array passed in is not const for a reason. 
00153       //! The method is allowed to modify the points in the buffer before 
00154       //! adding them to the region.  Just don't free the buffer.
00155       virtual ERRVALUE v_ProcessLine (
00156          LPOINT2D* points,
00157          int numpts
00158          ) = 0;
00159 
00160    };
00161 
00162 
00163 // An in implementation of BINARYTOREGIONINTERFACE which converts to a
00164 // REGION2D
00165 class BINARYTOREGION2D : public BINARYTOREGIONINTERFACE {
00166    public:
00167       BINARYTOREGION2D() {}
00168       ~BINARYTOREGION2D() {}
00169 
00170       // Get the region.
00171       // You must setup the spans and call ProcessSpans first.
00172       const REGION2D& GetRegion() {
00173          return m_region;
00174          }
00175 
00176    private:
00177       #ifndef GENERATING_DOXYGEN_OUTPUT
00178       void v_Clear();
00179 
00180       virtual ERRVALUE v_ProcessLine (
00181          LPOINT2D* points,
00182          int numpts
00183          );
00184 
00185       REGION2D m_region;
00186       #endif   // GENERATING_DOXYGEN_OUTPUT
00187    };
00188 
00189 
00190 #ifdef X_NATIVE
00191 
00192 #include <X11/Intrinsic.h>
00193 
00194 // An in implementation of BINARYTOREGIONINTERFACE which converts to an X
00195 // Region.
00196 class BINARYTOXREGION : public BINARYTOREGIONINTERFACE {
00197    public:
00198       BINARYTOXREGION() :
00199          m_region(0)
00200          {}
00201 
00202       ~BINARYTOXREGION() {}
00203 
00204       Region GetRegion() {
00205          return m_region;
00206          }
00207 
00208    private:
00209       #ifndef GENERATING_DOXYGEN_OUTPUT
00210       void v_Clear();
00211 
00212       virtual ERRVALUE v_ProcessLine (
00213          LPOINT2D* points,
00214          int numpts
00215          );
00216 
00217       Region m_region;
00218       #endif   // GENERATING_DOXYGEN_OUTPUT
00219    };
00220 
00221 
00222 #endif
00223 
00224 
00225 
00226 
00227 
00228 
00229 #endif // INC_MI32_BINTOREG_H

Generated on Thu Apr 26 04:44:52 2007 for TNTsdk by  doxygen 1.5.2