summaryrefslogtreecommitdiffstats
path: root/src/display/nr-filter-units.h
blob: 432e6817323a134feb56affdeb326d6eaa9a4781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_NR_FILTER_UNITS_H
#define SEEN_NR_FILTER_UNITS_H

/*
 * Utilities for handling coordinate system transformations in filters
 *
 * Author:
 *   Niko Kiirala <niko@kiirala.com>
 *
 * Copyright (C) 2007 Niko Kiirala
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "object/sp-filter-units.h"
#include <2geom/affine.h>
#include <2geom/rect.h>

namespace Inkscape {
namespace Filters {

/* Notes:
 * - "filter units" is a coordinate system where the filter region is contained
 *   between (0,0) and (1,1). Do not confuse this with the filterUnits property
 * - "primitive units" is the coordinate system in which all lengths and distances
 *   in the filter definition should be interpreted. They are affected by the value
 *   of the primitiveUnits attribute
 * - "pb" is the coordinate system in which filter rendering happens.
 *   It might be aligned with user or screen coordinates depending on
 *   the filter primitives used in the filter.
 * - "display" are world coordinates of the canvas - pixel grid coordinates
 *   of the drawing area translated so that (0,0) corresponds to the document origin
 */
class FilterUnits {
public:
    FilterUnits();
    FilterUnits(SPFilterUnits const filterUnits, SPFilterUnits const primitiveUnits);

    /**
     * Sets the current transformation matrix, i.e. transformation matrix
     * from object's user coordinates to screen coordinates
     */
    void set_ctm(Geom::Affine const &ctm);

    /**
     * Sets the resolution, the filter should be rendered with.
     */
    void set_resolution(double const x_res, double const y_res);

    /**
     * Sets the item bounding box in user coordinates
     */
    void set_item_bbox(Geom::OptRect const &bbox);

    /**
     * Sets the filter effects area in user coordinates
     */
    void set_filter_area(Geom::OptRect const &area);

    /**
     * Sets, if x and y axis in pixblock coordinates should be paraller
     * to x and y of user coordinates.
     */
    void set_paraller(bool const paraller);

    /**
     * Sets, if filter resolution is automatic.
     * NOTE: even if resolution is automatic, it must be set with
     * set_resolution. This only tells, if the set value is automatic.
     */
    void set_automatic_resolution(bool const automatic);

    /**
     * Gets the item bounding box in user coordinates
     */
    Geom::OptRect get_item_bbox() const { return item_bbox; };

    /**
     * Gets the filter effects area in user coordinates
     */
    Geom::OptRect get_filter_area() const { return filter_area; };

    /**
     * Gets Filter Units (userSpaceOnUse or objectBoundingBox)
     */
    SPFilterUnits get_filter_units() const { return filterUnits; };

    /**
     * Gets Primitive Units (userSpaceOnUse or objectBoundingBox)
     */
    SPFilterUnits get_primitive_units() const { return primitiveUnits; };

    /**
     * Gets the user coordinates to pixblock coordinates transformation matrix.
     */
    Geom::Affine get_matrix_user2pb() const;

    /**
     * Gets the filterUnits to pixblock coordinates transformation matrix.
     */
    Geom::Affine get_matrix_filterunits2pb() const;

    /**
     * Gets the primitiveUnits to pixblock coordinates transformation matrix.
     */
    Geom::Affine get_matrix_primitiveunits2pb() const;

    /**
     * Gets the display coordinates to pixblock coordinates transformation
     * matrix.
     */
    Geom::Affine get_matrix_display2pb() const;

    /**
     * Gets the pixblock coordinates to display coordinates transformation
     * matrix
     */
    Geom::Affine get_matrix_pb2display() const;

    /**
     * Gets the user coordinates to filterUnits transformation matrix.
     */
    Geom::Affine get_matrix_user2filterunits() const;

    /**
     * Gets the user coordinates to primitiveUnits transformation matrix.
     */
    Geom::Affine get_matrix_user2primitiveunits() const;

    /**
     * Returns the filter area in pixblock coordinates.
     * NOTE: use only in filters, that define TRAIT_PARALLER in
     * get_input_traits. The filter effects area may not be representable
     * by simple rectangle otherwise. */
    Geom::IntRect get_pixblock_filterarea_paraller() const;

    FilterUnits& operator=(FilterUnits const &other);

private:
    Geom::Affine get_matrix_units2pb(SPFilterUnits units) const;
    Geom::Affine get_matrix_user2units(SPFilterUnits units) const;

    SPFilterUnits filterUnits, primitiveUnits;
    double resolution_x, resolution_y;
    bool paraller_axis;
    bool automatic_resolution;
    Geom::Affine ctm;
    Geom::OptRect item_bbox;
    Geom::OptRect filter_area;

};


} /* namespace Filters */
} /* namespace Inkscape */


#endif /* __NR_FILTER_UNITS_H__ */
/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :