Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-filter-units.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Utilities for handling coordinate system transformations in filters
4 *
5 * Author:
6 * Niko Kiirala <niko@kiirala.com>
7 *
8 * Copyright (C) 2007 Niko Kiirala
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <glib.h>
14
17#include <2geom/transforms.h>
18
19using Geom::X;
20using Geom::Y;
21
22namespace Inkscape {
23namespace Filters {
24
27 primitiveUnits(SP_FILTER_UNITS_USERSPACEONUSE),
28 resolution_x(-1), resolution_y(-1),
29 paraller_axis(false), automatic_resolution(true)
30{}
31
32FilterUnits::FilterUnits(SPFilterUnits const filterUnits, SPFilterUnits const primitiveUnits) :
33 filterUnits(filterUnits), primitiveUnits(primitiveUnits),
34 resolution_x(-1), resolution_y(-1),
35 paraller_axis(false), automatic_resolution(true)
36{}
37
39 this->ctm = ctm;
40}
41
42void FilterUnits::set_resolution(double const x_res, double const y_res) {
43 g_assert(x_res > 0);
44 g_assert(y_res > 0);
45
46 resolution_x = x_res;
47 resolution_y = y_res;
48}
49
51 item_bbox = bbox;
52}
53
55 filter_area = area;
56}
57
58void FilterUnits::set_paraller(bool const paraller) {
59 paraller_axis = paraller;
60}
61
62void FilterUnits::set_automatic_resolution(bool const automatic) {
63 automatic_resolution = automatic;
64}
65
67 g_assert(resolution_x > 0);
68 g_assert(resolution_y > 0);
69 g_assert(filter_area);
70
71 Geom::Affine u2pb = ctm;
72
74 u2pb[0] = resolution_x / filter_area->width();
75 u2pb[1] = 0;
76 u2pb[2] = 0;
77 u2pb[3] = resolution_y / filter_area->height();
78 u2pb[4] = ctm[4];
79 u2pb[5] = ctm[5];
80 }
81
82 return u2pb;
83}
84
86 if ( item_bbox && (units == SP_FILTER_UNITS_OBJECTBOUNDINGBOX) ) {
87
89
90 /* TODO: make sure that user coordinate system (0,0) is in correct
91 * place in pixblock coordinates */
92 Geom::Scale scaling(item_bbox->width(), item_bbox->height());
93 u2pb *= scaling;
94 return u2pb;
95
96 } else if (units == SP_FILTER_UNITS_USERSPACEONUSE) {
97 return get_matrix_user2pb();
98 } else {
99 g_warning("Error in Inkscape::Filters::FilterUnits::get_matrix_units2pb: unrecognized unit type (%d)", units);
100 return Geom::Affine();
101 }
102}
103
107
111
113 Geom::Affine d2pb = ctm.inverse();
114 d2pb *= get_matrix_user2pb();
115 return d2pb;
116}
117
120 pb2d *= ctm;
121 return pb2d;
122}
123
126 /* No need to worry about rotations: bounding box coordinates
127 * always have base vectors paraller with userspace coordinates */
128 Geom::Point min(item_bbox->min());
129 Geom::Point max(item_bbox->max());
130 double scale_x = 1.0 / (max[X] - min[X]);
131 double scale_y = 1.0 / (max[Y] - min[Y]);
132 //return Geom::Translate(min) * Geom::Scale(scale_x,scale_y); ?
133 return Geom::Affine(scale_x, 0,
134 0, scale_y,
135 min[X] * scale_x, min[Y] * scale_y);
136 } else if (units == SP_FILTER_UNITS_USERSPACEONUSE) {
137 return Geom::identity();
138 } else {
139 g_warning("Error in Inkscape::Filters::FilterUnits::get_matrix_user2units: unrecognized unit type (%d)", units);
140 return Geom::Affine();
141 }
142}
143
147
151
153 g_assert(filter_area);
154
156 Geom::Rect r = *filter_area * u2pb;
158 return ir;
159}
160
161FilterUnits& FilterUnits::operator=(FilterUnits const &other) = default;
162
163} /* namespace Filters */
164} /* namespace Inkscape */
165
166
167/*
168 Local Variables:
169 mode:c++
170 c-file-style:"stroustrup"
171 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172 indent-tabs-mode:nil
173 fill-column:99
174 End:
175*/
176// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
Affine inverse() const
Compute the inverse matrix.
Definition affine.cpp:388
Axis aligned, non-empty, generic rectangle.
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
IntRect roundOutwards() const
Return the smallest integer rectangle which contains this one.
Definition rect.h:141
Scaling from the origin.
Definition transforms.h:150
Geom::Affine get_matrix_user2primitiveunits() const
Gets the user coordinates to primitiveUnits transformation matrix.
void set_automatic_resolution(bool const automatic)
Sets, if filter resolution is automatic.
Geom::Affine get_matrix_user2filterunits() const
Gets the user coordinates to filterUnits transformation matrix.
Geom::Affine get_matrix_primitiveunits2pb() const
Gets the primitiveUnits to pixblock coordinates transformation matrix.
Geom::Affine get_matrix_display2pb() const
Gets the display coordinates to pixblock coordinates transformation matrix.
Geom::Affine get_matrix_units2pb(SPFilterUnits units) const
Geom::Affine get_matrix_pb2display() const
Gets the pixblock coordinates to display coordinates transformation matrix.
void set_paraller(bool const paraller)
Sets, if x and y axis in pixblock coordinates should be paraller to x and y of user coordinates.
FilterUnits & operator=(FilterUnits const &other)
void set_filter_area(Geom::OptRect const &area)
Sets the filter effects area in user coordinates.
void set_item_bbox(Geom::OptRect const &bbox)
Sets the item bounding box in user coordinates.
void set_ctm(Geom::Affine const &ctm)
Sets the current transformation matrix, i.e.
Geom::Affine get_matrix_user2pb() const
Gets the user coordinates to pixblock coordinates transformation matrix.
Geom::IntRect get_pixblock_filterarea_paraller() const
Returns the filter area in pixblock coordinates.
void set_resolution(double const x_res, double const y_res)
Sets the resolution, the filter should be rendered with.
Geom::Affine get_matrix_filterunits2pb() const
Gets the filterUnits to pixblock coordinates transformation matrix.
Geom::Affine get_matrix_user2units(SPFilterUnits units) const
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
Affine identity()
Create an identity matrix.
Definition affine.h:210
Helper class to stream background task notifications as a series of messages.
TODO: insert short description here.
SPFilterUnits
@ SP_FILTER_UNITS_USERSPACEONUSE
@ SP_FILTER_UNITS_OBJECTBOUNDINGBOX
Affine transformation classes.