Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

agg_span_interpolator_linear.h

00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry - Version 2.2
00003 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
00004 //
00005 // Permission to copy, use, modify, sell and distribute this software 
00006 // is granted provided this copyright notice appears in all copies. 
00007 // This software is provided "as is" without express or implied
00008 // warranty, and with no claim as to its suitability for any purpose.
00009 //
00010 //----------------------------------------------------------------------------
00011 // Contact: mcseem@antigrain.com
00012 //          mcseemagg@yahoo.com
00013 //          http://www.antigrain.com
00014 //----------------------------------------------------------------------------
00015 
00016 #ifndef AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
00017 #define AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
00018 
00019 #include "agg_basics.h"
00020 #include "agg_dda_line.h"
00021 #include "agg_trans_affine.h"
00022 
00023 namespace agg
00024 {
00025 
00026     //================================================span_interpolator_linear
00027     template<class Transformer = trans_affine, unsigned SubpixelShift = 8> 
00028     class span_interpolator_linear
00029     {
00030     public:
00031         typedef Transformer trans_type;
00032 
00033         enum
00034         {
00035             subpixel_shift = SubpixelShift,
00036             subpixel_size  = 1 << subpixel_shift
00037         };
00038 
00039         //--------------------------------------------------------------------
00040         span_interpolator_linear() {}
00041         span_interpolator_linear(const trans_type& trans) : m_trans(&trans) {}
00042         span_interpolator_linear(const trans_type& trans,
00043                                  double x, double y, unsigned len) :
00044             m_trans(&trans)
00045         {
00046             begin(x, y, len);
00047         }
00048 
00049         //----------------------------------------------------------------
00050         const trans_type& transformer() const { return *m_trans; }
00051         void transformer(const trans_type& trans) { m_trans = &trans; }
00052 
00053         //----------------------------------------------------------------
00054         void begin(double x, double y, unsigned len)
00055         {
00056             double tx;
00057             double ty;
00058 
00059             tx = x;
00060             ty = y;
00061             m_trans->transform(&tx, &ty);
00062             int x1 = int(tx * subpixel_size);
00063             int y1 = int(ty * subpixel_size);
00064 
00065             tx = x + len;
00066             ty = y;
00067             m_trans->transform(&tx, &ty);
00068             int x2 = int(tx * subpixel_size);
00069             int y2 = int(ty * subpixel_size);
00070 
00071             m_li_x = dda2_line_interpolator(x1, x2, len);
00072             m_li_y = dda2_line_interpolator(y1, y2, len);
00073         }
00074 
00075         //----------------------------------------------------------------
00076         void operator++()
00077         {
00078             ++m_li_x;
00079             ++m_li_y;
00080         }
00081 
00082         //----------------------------------------------------------------
00083         void coordinates(int* x, int* y) const
00084         {
00085             *x = m_li_x.y();
00086             *y = m_li_y.y();
00087         }
00088 
00089     private:
00090         const trans_type* m_trans;
00091         dda2_line_interpolator m_li_x;
00092         dda2_line_interpolator m_li_y;
00093     };
00094 
00095 }
00096 
00097 
00098 
00099 #endif
00100 
00101 

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0