Code

add missing files
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 30 May 2008 20:46:01 +0000 (20:46 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 30 May 2008 20:46:01 +0000 (20:46 +0000)
src/live_effects/lpe-lattice.cpp [new file with mode: 0644]
src/live_effects/lpe-lattice.h [new file with mode: 0644]

diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp
new file mode 100644 (file)
index 0000000..001aa6b
--- /dev/null
@@ -0,0 +1,253 @@
+#define INKSCAPE_LPE_LATTICE_CPP\r
+/** \file\r
+ * LPE <lattice> implementation\r
\r
+ */\r
+/*\r
+ * Authors:\r
+ *   Johan Engelen <j.b.c.engelen@utwente.nl>\r
+ *   Steren Giannini\r
+ *   Noé Falzon\r
+ *   Victor Navez\r
+*\r
+* Copyright (C) 2007-2008 Authors \r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/lpe-lattice.h"\r
+\r
+#include "sp-shape.h"\r
+#include "sp-item.h"\r
+#include "sp-path.h"\r
+#include "display/curve.h"\r
+#include "libnr/n-art-bpath-2geom.h"\r
+#include "svg/svg.h"\r
+\r
+#include <2geom/sbasis.h>\r
+#include <2geom/sbasis-2d.h>\r
+#include <2geom/sbasis-geometric.h>\r
+#include <2geom/bezier-to-sbasis.h>\r
+#include <2geom/sbasis-to-bezier.h>\r
+#include <2geom/d2.h>\r
+#include <2geom/piecewise.h>\r
+#include <2geom/transforms.h>\r
+\r
+using namespace Geom;\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+LPELattice::LPELattice(LivePathEffectObject *lpeobject) :\r
+    Effect(lpeobject),\r
+    \r
+    // initialise your parameters here:\r
+    grid_point0(_("Control handle 0"), _("Tadah"), "gridpoint0", &wr, this),\r
+    grid_point1(_("Control handle 1"), _("Tadah"), "gridpoint1", &wr, this),\r
+    grid_point2(_("Control handle 2"), _("Tadah"), "gridpoint2", &wr, this),\r
+    grid_point3(_("Control handle 3"), _("Tadah"), "gridpoint3", &wr, this),\r
+    grid_point4(_("Control handle 4"), _("Tadah"), "gridpoint4", &wr, this),\r
+    grid_point5(_("Control handle 5"), _("Tadah"), "gridpoint5", &wr, this),\r
+    grid_point6(_("Control handle 6"), _("Tadah"), "gridpoint6", &wr, this),\r
+    grid_point7(_("Control handle 7"), _("Tadah"), "gridpoint7", &wr, this),\r
+    grid_point8(_("Control handle 8"), _("Tadah"), "gridpoint8", &wr, this),\r
+    grid_point9(_("Control handle 9"), _("Tadah"), "gridpoint9", &wr, this),\r
+    grid_point10(_("Control handle 10"), _("Tadah"), "gridpoint10", &wr, this),\r
+    grid_point11(_("Control handle 11"), _("Tadah"), "gridpoint11", &wr, this),\r
+    grid_point12(_("Control handle 12"), _("Tadah"), "gridpoint12", &wr, this),\r
+    grid_point13(_("Control handle 13"), _("Tadah"), "gridpoint13", &wr, this),\r
+    grid_point14(_("Control handle 14"), _("Tadah"), "gridpoint14", &wr, this),\r
+    grid_point15(_("Control handle 15"), _("Tadah"), "gridpoint15", &wr, this)\r
+    \r
+{\r
+    // register all your parameters here, so Inkscape knows which parameters this effect has:\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point0) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point1) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point2) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point3) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point4) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point5) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point6) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point7) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point8) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point9) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point10) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point11) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point12) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point13) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point14) );\r
+    registerParameter( dynamic_cast<Parameter *>(&grid_point15) );\r
+\r
+    \r
+}\r
+\r
+LPELattice::~LPELattice()\r
+{\r
+\r
+}\r
+\r
+\r
+Geom::Piecewise<Geom::D2<Geom::SBasis> >\r
+LPELattice::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)\r
+{\r
+    D2<SBasis2d> sb2;\r
+    \r
+    //Initialisation of the sb2\r
+    for(unsigned dim = 0; dim < 2; dim++) {\r
+        sb2[dim].us = 2;\r
+        sb2[dim].vs = 2;\r
+        const int depth = sb2[dim].us*sb2[dim].vs;\r
+        sb2[dim].resize(depth, Linear2d(0));\r
+    }\r
+\r
+    //Grouping the point params in a convenient vector\r
+    std::vector<Geom::Point *> handles(16);\r
+    \r
+    handles[0] = &grid_point0;\r
+    handles[1] = &grid_point1;\r
+    handles[2] = &grid_point2;\r
+    handles[3] = &grid_point3;\r
+    handles[4] = &grid_point4;\r
+    handles[5] = &grid_point5;\r
+    handles[6] = &grid_point6;\r
+    handles[7] = &grid_point7;\r
+    handles[8] = &grid_point8;\r
+    handles[9] = &grid_point9;\r
+    handles[10] = &grid_point10;\r
+    handles[11] = &grid_point11;\r
+    handles[12] = &grid_point12;\r
+    handles[13] = &grid_point13;\r
+    handles[14] = &grid_point14;\r
+    handles[15] = &grid_point15;\r
+\r
+    Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min());\r
+      \r
+    double width = boundingbox_X.extent();\r
+    double height = boundingbox_Y.extent();\r
+\r
+    //numbering is based on 4 rectangles.\r
+    for(unsigned dim = 0; dim < 2; dim++) {\r
+        Geom::Point dir(0,0);\r
+        dir[dim] = 1;\r
+        for(unsigned vi = 0; vi < sb2[dim].vs; vi++) {\r
+            for(unsigned ui = 0; ui < sb2[dim].us; ui++) {\r
+                for(unsigned iv = 0; iv < 2; iv++) {\r
+                    for(unsigned iu = 0; iu < 2; iu++) {\r
+                        unsigned corner = iu + 2*iv;\r
+                        unsigned i = ui + vi*sb2[dim].us;\r
+                        \r
+                        //This is the offset from the Upperleft point\r
+                        Geom::Point base(   (ui + iu*(3-2*ui))*width/3.,\r
+                                            (vi + iv*(3-2*vi))*height/3.);\r
+                       \r
+                        //Special action for corners\r
+                        if(vi == 0 && ui == 0) {\r
+                            base = Geom::Point(0,0);\r
+                        }\r
+                        \r
+                        // i = Upperleft corner of the considerated rectangle\r
+                        // corner = actual corner of the rectangle\r
+                        // origin = Upperleft point\r
+                        double dl = dot((*handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir);\r
+                        sb2[dim][i][corner] = dl/( dim ? height : width )*pow(4.0,ui+vi);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+   \r
+    Piecewise<D2<SBasis> >  output;\r
+    output.push_cut(0.);\r
+    for(unsigned i = 0; i < pwd2_in.size(); i++) {\r
+        D2<SBasis> B = pwd2_in[i];\r
+        B -= origin;   \r
+        B*= 1/width;\r
+        //Here comes the magic\r
+        D2<SBasis> tB = compose_each(sb2,B);\r
+        tB = tB * width + origin;\r
+\r
+        output.push(tB,i+1);\r
+    }\r
+\r
+    return output;\r
+}\r
+\r
+void\r
+LPELattice::doBeforeEffect (SPLPEItem *lpeitem)\r
+{\r
+    original_bbox(lpeitem);\r
+}\r
+\r
+void\r
+LPELattice::resetDefaults(SPItem * item)\r
+{\r
+    original_bbox(SP_LPE_ITEM(item), false);\r
+    \r
+    // place the 16 control points\r
+    grid_point0[Geom::X] = boundingbox_X.min();\r
+    grid_point0[Geom::Y] = boundingbox_Y.min();\r
+    \r
+    grid_point1[Geom::X] = boundingbox_X.max();\r
+    grid_point1[Geom::Y] = boundingbox_Y.min();\r
+    \r
+    grid_point2[Geom::X] = boundingbox_X.min();\r
+    grid_point2[Geom::Y] = boundingbox_Y.max();\r
+    \r
+    grid_point3[Geom::X] = boundingbox_X.max();\r
+    grid_point3[Geom::Y] = boundingbox_Y.max();\r
+    \r
+    grid_point4[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();\r
+    grid_point4[Geom::Y] = boundingbox_Y.min();\r
+    \r
+    grid_point5[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();\r
+    grid_point5[Geom::Y] = boundingbox_Y.min();\r
+    \r
+    grid_point6[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();\r
+    grid_point6[Geom::Y] = boundingbox_Y.max();\r
+    \r
+    grid_point7[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();\r
+    grid_point7[Geom::Y] = boundingbox_Y.max();\r
+    \r
+    grid_point8[Geom::X] = boundingbox_X.min();\r
+    grid_point8[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();     \r
+\r
+    grid_point9[Geom::X] = boundingbox_X.max();\r
+    grid_point9[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();\r
+        \r
+    grid_point10[Geom::X] = boundingbox_X.min();\r
+    grid_point10[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();  \r
+    \r
+    grid_point11[Geom::X] = boundingbox_X.max();\r
+    grid_point11[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();  \r
+    \r
+    grid_point12[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();\r
+    grid_point12[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();\r
+    \r
+    grid_point13[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();\r
+    grid_point13[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();\r
+    \r
+    grid_point14[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();\r
+    grid_point14[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();\r
+    \r
+    grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();\r
+    grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();\r
+\r
+\r
+    \r
+}\r
+\r
+/* ######################## */\r
+\r
+} //namespace LivePathEffect\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/live_effects/lpe-lattice.h b/src/live_effects/lpe-lattice.h
new file mode 100644 (file)
index 0000000..ad82e27
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef INKSCAPE_LPE_LATTICE_H\r
+#define INKSCAPE_LPE_LATTICE_H\r
+\r
+/** \file\r
+ * LPE <lattice> implementation, see lpe-lattice.cpp.\r
+ */\r
+\r
+/*\r
+ * Authors:\r
+ *   Johan Engelen\r
+ *   Steren Giannini\r
+ *   Noé Falzon\r
+ *   Victor Navez\r
+*\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/effect.h"\r
+#include "live_effects/parameter/point.h"\r
+#include "live_effects/parameter/enum.h"\r
+#include "live_effects/parameter/bool.h"\r
+\r
+#include "live_effects/lpegroupbbox.h"\r
+\r
+namespace Inkscape {\r
+namespace LivePathEffect {\r
+\r
+class LPELattice : public Effect, GroupBBoxEffect {\r
+public:\r
+\r
+    LPELattice(LivePathEffectObject *lpeobject);\r
+    virtual ~LPELattice();\r
+\r
+    virtual void doBeforeEffect (SPLPEItem *lpeitem);\r
+\r
+    virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);\r
+    \r
+    virtual void resetDefaults(SPItem * item);\r
+\r
+\r
+\r
+private:\r
+    PointParam grid_point0;\r
+    PointParam grid_point1;\r
+    PointParam grid_point2;\r
+    PointParam grid_point3;\r
+    PointParam grid_point4;\r
+    PointParam grid_point5;\r
+    PointParam grid_point6;\r
+    PointParam grid_point7;\r
+    PointParam grid_point8;\r
+    PointParam grid_point9;\r
+    PointParam grid_point10;\r
+    PointParam grid_point11;\r
+    PointParam grid_point12;\r
+    PointParam grid_point13;\r
+    PointParam grid_point14;\r
+    PointParam grid_point15;\r
+    \r
+    LPELattice(const LPELattice&);\r
+    LPELattice& operator=(const LPELattice&);\r
+};\r
+\r
+} //namespace LivePathEffect\r
+} //namespace Inkscape\r
+\r
+#endif\r