"Fossies" - the Fresh Open Source Software Archive

Member "veusz-3.1/veusz/helpers/src/qtloops/qtloops.sip" (29 May 2018, 7389 Bytes) of package /linux/privat/veusz-3.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "qtloops.sip": 2.2.2_vs_3.0.

    1 //    Copyright (C) 2009 Jeremy S. Sanders
    2 //    Email: Jeremy Sanders <jeremy@jeremysanders.net>
    3 //
    4 //    This program is free software; you can redistribute it and/or modify
    5 //    it under the terms of the GNU General Public License as published by
    6 //    the Free Software Foundation; either version 2 of the License, or
    7 //    (at your option) any later version.
    8 //
    9 //    This program is distributed in the hope that it will be useful,
   10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 //    GNU General Public License for more details.
   13 //
   14 //    You should have received a copy of the GNU General Public License along
   15 //    with this program; if not, write to the Free Software Foundation, Inc.,
   16 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   17 /////////////////////////////////////////////////////////////////////////////
   18 
   19 %Module(name=qtloops)
   20 
   21 %Import(name=QtCore/QtCoremod.sip)
   22 %Import(name=QtGui/QtGuimod.sip)
   23 
   24 %ModuleHeaderCode
   25 #include <qtloops_helpers.h>
   26 %End
   27 
   28 %PostInitialisationCode
   29 do_numpy_init_package();
   30 %End
   31 
   32 class QtLoops
   33  {
   34 
   35 %TypeHeaderCode
   36 #include <qtloops.h>
   37 #include <polygonclip.h>
   38 #include <polylineclip.h>
   39 #include <beziers_qtwrap.h>
   40 #include <numpyfuncs.h>
   41 %End
   42 
   43 public:
   44    QtLoops();
   45 };
   46 
   47 void addNumpyToPolygonF(QPolygonF&, ...);
   48 %MethodCode
   49    {
   50    try
   51      {
   52        Tuple2Ptrs t(a1);
   53        addNumpyToPolygonF(*a0, t);
   54      }
   55    catch( const char *msg )
   56      {
   57        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
   58      }
   59    }
   60 %End
   61 
   62 void addNumpyPolygonToPath(QPainterPath&, const QRectF*, ...);
   63 %MethodCode
   64    {
   65    try
   66      {
   67        Tuple2Ptrs t(a2);
   68        addNumpyPolygonToPath(*a0, t, a1);
   69      }
   70    catch( const char *msg )
   71      {
   72        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
   73      }
   74    }
   75 %End
   76 
   77 
   78 void plotPathsToPainter(QPainter&, QPainterPath&, SIP_PYOBJECT, SIP_PYOBJECT,
   79 			SIP_PYOBJECT,
   80 			const QRectF* clip=0,
   81 			const QImage* colorimg=0,
   82 			bool scaleline=false);
   83 %MethodCode
   84 {
   85   Numpy1DObj* scaling = 0;
   86   
   87   try
   88     {
   89       // x and y coordinates
   90       Numpy1DObj x(a2);
   91       Numpy1DObj y(a3);
   92       
   93       // a4 is scaling or None
   94       if (a4 != Py_None) {
   95 	scaling = new Numpy1DObj(a4);
   96       }
   97       
   98       plotPathsToPainter(*a0, *a1, x, y, scaling, a5, a6, a7);
   99     }
  100   catch( const char *msg )
  101     {
  102       sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  103     }
  104   
  105   delete scaling;
  106 }
  107 %End
  108 
  109 void plotLinesToPainter(QPainter& painter,
  110 			SIP_PYOBJECT, SIP_PYOBJECT,
  111 			SIP_PYOBJECT, SIP_PYOBJECT,
  112 			const QRectF* clip = 0,
  113 			bool autoexpand = true);
  114 %MethodCode
  115    {
  116    try
  117      {
  118        Numpy1DObj x1(a1);
  119        Numpy1DObj y1(a2);
  120        Numpy1DObj x2(a3);
  121        Numpy1DObj y2(a4);
  122        plotLinesToPainter(*a0, x1, y1, x2, y2, a5, a6);
  123      }
  124    catch( const char *msg )
  125      {
  126        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  127      }
  128    }
  129 %End
  130 
  131 void plotBoxesToPainter(QPainter& painter,
  132 			SIP_PYOBJECT, SIP_PYOBJECT,
  133 			SIP_PYOBJECT, SIP_PYOBJECT,
  134 			const QRectF* clip = 0,
  135 			bool autoexpand = true);
  136 %MethodCode
  137    {
  138    try
  139      {
  140        Numpy1DObj x1(a1);
  141        Numpy1DObj y1(a2);
  142        Numpy1DObj x2(a3);
  143        Numpy1DObj y2(a4);
  144        plotBoxesToPainter(*a0, x1, y1, x2, y2, a5, a6);
  145      }
  146    catch( const char *msg )
  147      {
  148        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  149      }
  150    }
  151 %End
  152 
  153 void addCubicsToPainterPath(QPainterPath& path, const QPolygonF& poly);
  154 
  155 QImage numpyToQImage(SIP_PYOBJECT, SIP_PYOBJECT, bool forcetrans = false);
  156 %MethodCode
  157   {
  158    try
  159      {
  160        Numpy2DObj data(a0);
  161        Numpy2DIntObj colors(a1);
  162        QImage *img = new QImage( numpyToQImage(data, colors, a2) );
  163        sipRes = img;
  164      }
  165    catch( const char *msg )
  166      {
  167        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  168      }
  169   }
  170 %End
  171 
  172 void applyImageTransparancy(QImage& img, SIP_PYOBJECT);
  173 %MethodCode
  174   {
  175    try
  176      {
  177        Numpy2DObj data(a1);
  178        applyImageTransparancy(*a0, data);
  179      }
  180    catch( const char *msg )
  181      {
  182        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  183      }
  184   }
  185 %End
  186 
  187 QImage resampleLinearImage(QImage& img, SIP_PYOBJECT, SIP_PYOBJECT);
  188 %MethodCode
  189    {
  190    try
  191      {
  192        Numpy1DObj xpts(a1);
  193        Numpy1DObj ypts(a2);
  194 
  195        QImage *oimg = new QImage( resampleLinearImage(*a0, xpts, ypts) );
  196        sipRes = oimg;
  197      }
  198    catch( const char *msg )
  199      {
  200        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  201      }
  202    }
  203 %End
  204 
  205 void polygonClip(const QPolygonF& inpoly,
  206 		 const QRectF& cliprect,
  207 		 QPolygonF& outpoly);
  208 
  209 void plotClippedPolygon(QPainter& painter,
  210 			QRectF rect,
  211 			const QPolygonF& inpoly,
  212 			bool autoexpand = true);
  213 
  214 // polyline clipping code
  215 
  216 void plotClippedPolyline(QPainter& painter,
  217 			 QRectF clip,
  218 			 const QPolygonF& poly,
  219 			 bool autoexpand = true);
  220 
  221 // clip polyline to rectangle and return polylines
  222 QVector<QPolygonF> clipPolyline(QRectF clip, const QPolygonF& poly);
  223 
  224 // Do the polygons intersect?
  225 bool doPolygonsIntersect(const QPolygonF& a, const QPolygonF& b);
  226 
  227 
  228 // storing rotated rectangles
  229 
  230 struct RotatedRectangle
  231 {
  232   %TypeHeaderCode
  233 #include <polylineclip.h>
  234   %End
  235 
  236   RotatedRectangle(double _cx, double _cy,
  237 		   double _xw, double _yw, double _angle);
  238 
  239   bool isValid() const;
  240   void rotate(double dtheta);
  241   void rotateAboutOrigin(double dtheta);
  242   void translate(double dx, double dy);
  243 
  244   QPolygonF makePolygon() const;
  245 
  246   double cx;
  247   double cy;
  248   double xw;
  249   double yw;
  250   double angle;
  251 };
  252 
  253 // for labelling of sets of contour lines
  254 class LineLabeller
  255 {
  256   %TypeHeaderCode
  257 #include <polylineclip.h>
  258   %End
  259 
  260 public:
  261   LineLabeller(QRectF cliprect, bool rotatelabels);
  262   virtual ~LineLabeller();
  263 
  264   // override this to receive the label to draw
  265   virtual void drawAt(int idx, RotatedRectangle r);
  266 
  267   void addLine(const QPolygonF& poly, QSizeF textsize);
  268 
  269   void process();
  270 
  271   int getNumPolySets() const;
  272   QVector<QPolygonF> getPolySet(int i) const;
  273 };
  274 
  275 class RectangleOverlapTester
  276 {
  277   %TypeHeaderCode
  278 #include <polylineclip.h>
  279   %End
  280 
  281 public:
  282   RectangleOverlapTester();
  283   bool willOverlap(const RotatedRectangle& rect) const;
  284   void addRect(const RotatedRectangle& rect);
  285   void reset();
  286   void debug(QPainter& painter) const;
  287 };
  288 
  289 
  290 // bezier functions
  291 
  292 QPolygonF bezier_fit_cubic_single(const QPolygonF& data, double error);
  293 
  294 QPolygonF bezier_fit_cubic_multi(const QPolygonF& data, double error,
  295 				 unsigned max_beziers);
  296 
  297 SIP_PYOBJECT binData(SIP_PYOBJECT data, int binning, bool average);
  298 %MethodCode
  299    try
  300      {
  301        Numpy1DObj d(a0);
  302        double* data;
  303        int numelem;
  304        binData(d, a1, a2, &numelem, &data);
  305        sipRes = doubleArrayToNumpy(data, numelem);
  306        delete[] data;
  307      }
  308    catch( const char *msg )
  309      {
  310        sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  311      }
  312 %End
  313 
  314 SIP_PYOBJECT rollingAverage(SIP_PYOBJECT data, SIP_PYOBJECT weights,
  315 			    int width);
  316 %MethodCode
  317 {
  318   Numpy1DObj* weightarray = 0;
  319   try
  320     {
  321       Numpy1DObj d(a0);
  322       if( a1 != Py_None ) {
  323 	weightarray = new Numpy1DObj(a1);
  324       }
  325       double* data;
  326       int numelem;
  327       rollingAverage(d, weightarray, a2, &numelem, &data);
  328       sipRes = doubleArrayToNumpy(data, numelem);
  329       delete[] data;
  330     }
  331   catch( const char *msg )
  332     {
  333       sipIsErr = 1; PyErr_SetString(PyExc_TypeError, msg);
  334     }
  335   delete weightarray;
  336 }
  337 %End