Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_span_interpolator_trans.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry (AGG) - Version 2.5
00003 // A high quality rendering engine for C++
00004 // Copyright (C) 2002-2006 Maxim Shemanarev
00005 // Contact: mcseem@antigrain.com
00006 //          mcseemagg@yahoo.com
00007 //          http://antigrain.com
00008 // 
00009 // AGG is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // AGG is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU General Public License
00020 // along with AGG; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00022 // MA 02110-1301, USA.
00023 //----------------------------------------------------------------------------
00024 //
00025 // Horizontal span interpolator for use with an arbitrary transformer
00026 // The efficiency highly depends on the operations done in the transformer
00027 //
00028 //----------------------------------------------------------------------------
00029 
00030 #ifndef AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED
00031 #define AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED
00032 
00033 #include "agg_basics.h"
00034 
00035 namespace agg
00036 {
00037     //=================================================span_interpolator_trans
00038     template<class Transformer, unsigned SubpixelShift = 8> 
00039     class span_interpolator_trans
00040     {
00041     public:
00042         typedef Transformer trans_type;
00043         enum subpixel_scale_e
00044         {
00045             subpixel_shift = SubpixelShift,
00046             subpixel_scale = 1 << subpixel_shift
00047         };
00048 
00049         //--------------------------------------------------------------------
00050         span_interpolator_trans() {}
00051         span_interpolator_trans(const trans_type& trans) : m_trans(&trans) {}
00052         span_interpolator_trans(const trans_type& trans,
00053                                 double x, double y, unsigned) :
00054             m_trans(&trans)
00055         {
00056             begin(x, y, 0);
00057         }
00058 
00059         //----------------------------------------------------------------
00060         const trans_type& transformer() const { return *m_trans; }
00061         void transformer(const trans_type& trans) { m_trans = &trans; }
00062 
00063         //----------------------------------------------------------------
00064         void begin(double x, double y, unsigned)
00065         {
00066             m_x = x;
00067             m_y = y;
00068             m_trans->transform(&x, &y);
00069             m_ix = iround(x * subpixel_scale);
00070             m_iy = iround(y * subpixel_scale);
00071         }
00072 
00073         //----------------------------------------------------------------
00074         void operator++()
00075         {
00076             m_x += 1.0;
00077             double x = m_x;
00078             double y = m_y;
00079             m_trans->transform(&x, &y);
00080             m_ix = iround(x * subpixel_scale);
00081             m_iy = iround(y * subpixel_scale);
00082         }
00083 
00084         //----------------------------------------------------------------
00085         void coordinates(int* x, int* y) const
00086         {
00087             *x = m_ix;
00088             *y = m_iy;
00089         }
00090 
00091     private:
00092         const trans_type* m_trans;
00093         double            m_x;
00094         double            m_y;
00095         int               m_ix;
00096         int               m_iy;
00097     };
00098 
00099 }
00100 
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines