~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/live_effects/lpe-perspective_path.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 * @brief LPE perspective path effect implementation.
 
3
 */
 
4
/* Authors:
 
5
 *   Maximilian Albert <maximilian.albert@gmail.com>
 
6
 *   Johan Engelen <j.b.c.engelen@utwente.nl>
 
7
 *
 
8
 * Copyright (C) 2007-2008 Authors
 
9
 *
 
10
 * Released under GNU GPL, read the file 'COPYING' for more information
 
11
 */
 
12
 
 
13
#include "persp3d.h"
 
14
//#include "transf_mat_3x4.h"
 
15
#include "document.h"
 
16
 
 
17
#include "live_effects/lpe-perspective_path.h"
 
18
#include "sp-item-group.h"
 
19
 
 
20
#include "inkscape.h"
 
21
 
 
22
#include <2geom/path.h>
 
23
 
 
24
namespace Inkscape {
 
25
namespace LivePathEffect {
 
26
 
 
27
namespace PP {
 
28
 
 
29
class KnotHolderEntityOffset : public LPEKnotHolderEntity
 
30
{
 
31
public:
 
32
    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 
33
    virtual Geom::Point knot_get();
 
34
};
 
35
 
 
36
} // namespace PP
 
37
 
 
38
LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) :
 
39
    Effect(lpeobject),
 
40
    // initialise your parameters here:
 
41
    scalex(_("Scale x"), _("Scale factor in x direction"), "scalex", &wr, this, 1.0),
 
42
    scaley(_("Scale y"), _("Scale factor in y direction"), "scaley", &wr, this, 1.0),
 
43
    offsetx(_("Offset x"), _("Offset in x direction"), "offsetx", &wr, this, 0.0),
 
44
    offsety(_("Offset y"), _("Offset in y direction"), "offsety", &wr, this, 0.0),
 
45
    uses_plane_xy(_("Uses XY plane?"), _("If true, put the path on the left side of an imaginary box, otherwise on the right side"), "uses_plane_xy", &wr, this, true)
 
46
{
 
47
    // register all your parameters here, so Inkscape knows which parameters this effect has:
 
48
    registerParameter( dynamic_cast<Parameter *>(&scalex) );
 
49
    registerParameter( dynamic_cast<Parameter *>(&scaley) );
 
50
    registerParameter( dynamic_cast<Parameter *>(&offsetx) );
 
51
    registerParameter( dynamic_cast<Parameter *>(&offsety) );
 
52
    registerParameter( dynamic_cast<Parameter *>(&uses_plane_xy) );
 
53
 
 
54
    registerKnotHolderHandle(new PP::KnotHolderEntityOffset(), _("Adjust the origin"));
 
55
 
 
56
    concatenate_before_pwd2 = true; // don't split the path into its subpaths
 
57
 
 
58
    Persp3D *persp = persp3d_document_first_persp(inkscape_active_document());
 
59
 
 
60
    Proj::TransfMat3x4 pmat = persp->tmat;
 
61
 
 
62
    pmat.copy_tmat(tmat);
 
63
}
 
64
 
 
65
LPEPerspectivePath::~LPEPerspectivePath()
 
66
{
 
67
 
 
68
}
 
69
 
 
70
void
 
71
LPEPerspectivePath::doBeforeEffect (SPLPEItem *lpeitem)
 
72
{
 
73
    original_bbox(lpeitem, true);
 
74
}
 
75
 
 
76
Geom::Piecewise<Geom::D2<Geom::SBasis> >
 
77
LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
 
78
{
 
79
    using namespace Geom;
 
80
 
 
81
    Piecewise<D2<SBasis> > path_a_pw = pwd2_in;
 
82
 
 
83
    // FIXME: the minus sign is there because the SVG coordinate system goes down;
 
84
    //        remove this once we have unified coordinate systems
 
85
    path_a_pw = path_a_pw + Geom::Point(offsetx, -offsety);
 
86
 
 
87
    D2<Piecewise<SBasis> > B = make_cuts_independent(path_a_pw);
 
88
    Piecewise<SBasis> preimage[4];
 
89
 
 
90
    //Geom::Point orig = Geom::Point(bounds_X.min(), bounds_Y.middle());
 
91
    //orig = Geom::Point(orig[X], sp_document_height(inkscape_active_document()) - orig[Y]);
 
92
 
 
93
    //double offset = uses_plane_xy ? boundingbox_X.extent() : 0.0;
 
94
 
 
95
    orig = Point(uses_plane_xy ? boundingbox_X.max() : boundingbox_X.min(), boundingbox_Y.middle());
 
96
 
 
97
    /**
 
98
    g_print ("Orig: (%8.2f, %8.2f)\n", orig[X], orig[Y]);
 
99
 
 
100
    g_print ("B[1] - orig[1]: %8.2f\n", (B[1] - orig[1])[0].valueAt(0));
 
101
    g_print ("B[0] - orig[0]: %8.2f\n", (B[0] - orig[0])[0].valueAt(0));
 
102
    **/
 
103
 
 
104
    if (uses_plane_xy) {
 
105
        preimage[0] =  (-B[0] + orig[0]) * scalex / 200.0;
 
106
        preimage[1] =  ( B[1] - orig[1]) * scaley / 400.0;
 
107
        preimage[2] =  B[0] - B[0]; // hack!
 
108
    } else {
 
109
        preimage[0] =  B[0] - B[0]; // hack!
 
110
        preimage[1] =  (B[1] - orig[1]) * scaley / 400.0;
 
111
        preimage[2] =  (B[0] - orig[0]) * scalex / 200.0;
 
112
    }
 
113
 
 
114
    /* set perspective origin to first point of path */
 
115
    tmat[0][3] = orig[0];
 
116
    tmat[1][3] = orig[1];
 
117
 
 
118
    /**
 
119
    g_print ("preimage[1]: %8.2f\n", preimage[1][0].valueAt(0));
 
120
    g_print ("preimage[2]: %8.2f\n", preimage[2][0].valueAt(0));
 
121
    **/
 
122
 
 
123
    Piecewise<SBasis> res[3];
 
124
    for (int j = 0; j < 3; ++j) {
 
125
        res[j] =
 
126
              preimage[0] * tmat[j][0]
 
127
            + preimage[1] * tmat[j][1]
 
128
            + preimage[2] * tmat[j][2]
 
129
            +               tmat[j][3];
 
130
    }
 
131
    D2<Piecewise<SBasis> > result(divide(res[0],res[2], 3),
 
132
                                  divide(res[1],res[2], 3));
 
133
 
 
134
    Piecewise<D2<SBasis> > output = sectionize(result);
 
135
 
 
136
    return output;
 
137
}
 
138
 
 
139
namespace PP {
 
140
 
 
141
// TODO: make this more generic
 
142
static LPEPerspectivePath *
 
143
get_effect(SPItem *item)
 
144
{
 
145
    Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
 
146
    if (effect->effectType() != PERSPECTIVE_PATH) {
 
147
        g_print ("Warning: Effect is not of type LPEPerspectivePath!\n");
 
148
        return NULL;
 
149
    }
 
150
    return static_cast<LPEPerspectivePath *>(effect);
 
151
}
 
152
 
 
153
void
 
154
KnotHolderEntityOffset::knot_set(Geom::Point const &p, Geom::Point const &origin, guint /*state*/)
 
155
{
 
156
    using namespace Geom;
 
157
 
 
158
    LPEPerspectivePath* lpe = get_effect(item);
 
159
 
 
160
    Geom::Point const s = snap_knot_position(p);
 
161
 
 
162
    lpe->offsetx.param_set_value((s - origin)[Geom::X]);
 
163
    lpe->offsety.param_set_value(-(s - origin)[Geom::Y]); // additional minus sign is due to coordinate system flipping
 
164
 
 
165
    // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
 
166
    sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
 
167
}
 
168
 
 
169
Geom::Point
 
170
KnotHolderEntityOffset::knot_get()
 
171
{
 
172
    LPEPerspectivePath* lpe = get_effect(item);
 
173
    return lpe->orig + Geom::Point(lpe->offsetx, -lpe->offsety);
 
174
}
 
175
 
 
176
} // namespace PP
 
177
 
 
178
} //namespace LivePathEffect
 
179
} /* namespace Inkscape */
 
180
 
 
181
/*
 
182
  Local Variables:
 
183
  mode:c++
 
184
  c-file-style:"stroustrup"
 
185
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
186
  indent-tabs-mode:nil
 
187
  fill-column:99
 
188
  End:
 
189
*/
 
190
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :