From 290425c1c9ee8672adc04db5f0b2515e35429693 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Wed, 31 Dec 2008 00:23:40 +0000 Subject: [PATCH] switch nr-filter to 2geom --- src/display/nr-filter-units.cpp | 73 ++++++++++++++++++--------------- src/display/nr-filter-units.h | 32 +++++++-------- src/display/nr-filter.cpp | 4 +- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/display/nr-filter-units.cpp b/src/display/nr-filter-units.cpp index 6836e39af..c26d56ad6 100644 --- a/src/display/nr-filter-units.cpp +++ b/src/display/nr-filter-units.cpp @@ -20,6 +20,7 @@ #include "libnr/nr-rect-l.h" #include "libnr/nr-scale.h" #include "sp-filter-units.h" +#include <2geom/transforms.h> namespace NR { @@ -36,7 +37,7 @@ FilterUnits::FilterUnits(SPFilterUnits const filterUnits, SPFilterUnits const pr paraller_axis(false), automatic_resolution(true) {} -void FilterUnits::set_ctm(Matrix const &ctm) { +void FilterUnits::set_ctm(Geom::Matrix const &ctm) { this->ctm = ctm; } @@ -48,11 +49,11 @@ void FilterUnits::set_resolution(double const x_res, double const y_res) { resolution_y = y_res; } -void FilterUnits::set_item_bbox(Rect const &bbox) { +void FilterUnits::set_item_bbox(Geom::OptRect const &bbox) { item_bbox = bbox; } -void FilterUnits::set_filter_area(Rect const &area) { +void FilterUnits::set_filter_area(Geom::OptRect const &area) { filter_area = area; } @@ -64,17 +65,18 @@ void FilterUnits::set_automatic_resolution(bool const automatic) { automatic_resolution = automatic; } -Matrix FilterUnits::get_matrix_user2pb() const { +Geom::Matrix FilterUnits::get_matrix_user2pb() const { g_assert(resolution_x > 0); g_assert(resolution_y > 0); + g_assert(filter_area); - Matrix u2pb = ctm; + Geom::Matrix u2pb = ctm; if (paraller_axis || !automatic_resolution) { - u2pb[0] = resolution_x / (filter_area.max()[X] - filter_area.min()[X]); + u2pb[0] = resolution_x / (filter_area->max()[X] - filter_area->min()[X]); u2pb[1] = 0; u2pb[2] = 0; - u2pb[3] = resolution_y / (filter_area.max()[Y] - filter_area.min()[Y]); + u2pb[3] = resolution_y / (filter_area->max()[Y] - filter_area->min()[Y]); u2pb[4] = ctm[4]; u2pb[5] = ctm[5]; } @@ -82,14 +84,14 @@ Matrix FilterUnits::get_matrix_user2pb() const { return u2pb; } -Matrix FilterUnits::get_matrix_units2pb(SPFilterUnits units) const { - if (units == SP_FILTER_UNITS_OBJECTBOUNDINGBOX) { - Matrix u2pb = get_matrix_user2pb(); - Point origo(item_bbox.min()); +Geom::Matrix FilterUnits::get_matrix_units2pb(SPFilterUnits units) const { + if ( item_bbox && (units == SP_FILTER_UNITS_OBJECTBOUNDINGBOX) ) { + Geom::Matrix u2pb = get_matrix_user2pb(); + Geom::Point origo(item_bbox->min()); origo *= u2pb; - Point i_end(item_bbox.max()[X], item_bbox.min()[Y]); + Geom::Point i_end(item_bbox->max()[X], item_bbox->min()[Y]); i_end *= u2pb; - Point j_end(item_bbox.min()[X], item_bbox.max()[Y]); + Geom::Point j_end(item_bbox->min()[X], item_bbox->max()[Y]); j_end *= u2pb; double len_i = sqrt((origo[X] - i_end[X]) * (origo[X] - i_end[X]) @@ -99,70 +101,73 @@ Matrix FilterUnits::get_matrix_units2pb(SPFilterUnits units) const { /* TODO: make sure that user coordinate system (0,0) is in correct * place in pixblock coordinates */ - scale scaling(1.0 / len_i, 1.0 / len_j); + Geom::Scale scaling(1.0 / len_i, 1.0 / len_j); u2pb *= scaling; return u2pb; } else if (units == SP_FILTER_UNITS_USERSPACEONUSE) { return get_matrix_user2pb(); } else { g_warning("Error in NR::FilterUnits::get_matrix_units2pb: unrecognized unit type (%d)", units); - return Matrix(); + return Geom::Matrix(); } } -Matrix FilterUnits::get_matrix_filterunits2pb() const { +Geom::Matrix FilterUnits::get_matrix_filterunits2pb() const { return get_matrix_units2pb(filterUnits); } -Matrix FilterUnits::get_matrix_primitiveunits2pb() const { +Geom::Matrix FilterUnits::get_matrix_primitiveunits2pb() const { return get_matrix_units2pb(primitiveUnits); } -Matrix FilterUnits::get_matrix_display2pb() const { - Matrix d2pb = ctm.inverse(); +Geom::Matrix FilterUnits::get_matrix_display2pb() const { + Geom::Matrix d2pb = ctm.inverse(); d2pb *= get_matrix_user2pb(); return d2pb; } -Matrix FilterUnits::get_matrix_pb2display() const { - Matrix pb2d = get_matrix_user2pb().inverse(); +Geom::Matrix FilterUnits::get_matrix_pb2display() const { + Geom::Matrix pb2d = get_matrix_user2pb().inverse(); pb2d *= ctm; return pb2d; } -Matrix FilterUnits::get_matrix_user2units(SPFilterUnits units) const { - if (units == SP_FILTER_UNITS_OBJECTBOUNDINGBOX) { +Geom::Matrix FilterUnits::get_matrix_user2units(SPFilterUnits units) const { + if (item_bbox && units == SP_FILTER_UNITS_OBJECTBOUNDINGBOX) { /* No need to worry about rotations: bounding box coordinates * always have base vectors paraller with userspace coordinates */ - Point min(item_bbox.min()); - Point max(item_bbox.max()); + Point min(item_bbox->min()); + Point max(item_bbox->max()); double scale_x = 1.0 / (max[X] - min[X]); double scale_y = 1.0 / (max[Y] - min[Y]); - return Matrix(scale_x, 0, - 0, scale_y, - min[X] * scale_x, min[Y] * scale_y); + //return Geom::Translate(min) * Geom::Scale(scale_x,scale_y); ? + return Geom::Matrix(scale_x, 0, + 0, scale_y, + min[X] * scale_x, min[Y] * scale_y); } else if (units == SP_FILTER_UNITS_USERSPACEONUSE) { - return identity(); + return Geom::identity(); } else { g_warning("Error in NR::FilterUnits::get_matrix_user2units: unrecognized unit type (%d)", units); - return Matrix(); + return Geom::Matrix(); } } -Matrix FilterUnits::get_matrix_user2filterunits() const { +Geom::Matrix FilterUnits::get_matrix_user2filterunits() const { return get_matrix_user2units(filterUnits); } -Matrix FilterUnits::get_matrix_user2primitiveunits() const { +Geom::Matrix FilterUnits::get_matrix_user2primitiveunits() const { return get_matrix_user2units(primitiveUnits); } IRect FilterUnits::get_pixblock_filterarea_paraller() const { + g_assert(filter_area); + int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; - Matrix u2pb = get_matrix_user2pb(); + Geom::Matrix u2pb = get_matrix_user2pb(); for (int i = 0 ; i < 4 ; i++) { - Point p = filter_area.corner(i); + Geom::Point p = filter_area->corner(i); p *= u2pb; if (p[X] < min_x) min_x = (int)std::floor(p[X]); if (p[X] > max_x) max_x = (int)std::ceil(p[X]); diff --git a/src/display/nr-filter-units.h b/src/display/nr-filter-units.h index a24e0682f..d11df621f 100644 --- a/src/display/nr-filter-units.h +++ b/src/display/nr-filter-units.h @@ -14,9 +14,9 @@ #include "sp-filter-units.h" #include "libnr/nr-matrix.h" -#include <2geom/matrix.h> #include "libnr/nr-rect.h" #include "libnr/nr-rect-l.h" +#include <2geom/matrix.h> #include <2geom/rect.h> namespace NR { @@ -30,7 +30,7 @@ public: * Sets the current transformation matrix, i.e. transformation matrix * from object's user coordinates to screen coordinates */ - void set_ctm(Matrix const &ctm); + void set_ctm(Geom::Matrix const &ctm); /** * Sets the resolution, the filter should be rendered with. @@ -40,12 +40,12 @@ public: /** * Sets the item bounding box in user coordinates */ - void set_item_bbox(Rect const &bbox); + void set_item_bbox(Geom::OptRect const &bbox); /** * Sets the filter effects area in user coordinates */ - void set_filter_area(Rect const &area); + void set_filter_area(Geom::OptRect const &area); /** * Sets, if x and y axis in pixblock coordinates should be paraller @@ -63,39 +63,39 @@ public: /** * Gets the user coordinates to pixblock coordinates transformation matrix. */ - Matrix get_matrix_user2pb() const; + Geom::Matrix get_matrix_user2pb() const; /** * Gets the filterUnits to pixblock coordinates transformation matrix. */ - Matrix get_matrix_filterunits2pb() const; + Geom::Matrix get_matrix_filterunits2pb() const; /** * Gets the primitiveUnits to pixblock coordinates transformation matrix. */ - Matrix get_matrix_primitiveunits2pb() const; + Geom::Matrix get_matrix_primitiveunits2pb() const; /** * Gets the display coordinates to pixblock coordinates transformation * matrix. */ - Matrix get_matrix_display2pb() const; + Geom::Matrix get_matrix_display2pb() const; /** * Gets the pixblock coordinates to display coordinates transformation * matrix */ - Matrix get_matrix_pb2display() const; + Geom::Matrix get_matrix_pb2display() const; /** * Gets the user coordinates to filterUnits transformation matrix. */ - Matrix get_matrix_user2filterunits() const; + Geom::Matrix get_matrix_user2filterunits() const; /** * Gets the user coordinates to primitiveUnits transformation matrix. */ - Matrix get_matrix_user2primitiveunits() const; + Geom::Matrix get_matrix_user2primitiveunits() const; /** * Returns the filter area in pixblock coordinates. @@ -107,16 +107,16 @@ public: FilterUnits& operator=(FilterUnits const &other); private: - Matrix get_matrix_units2pb(SPFilterUnits units) const; - Matrix get_matrix_user2units(SPFilterUnits units) const; + Geom::Matrix get_matrix_units2pb(SPFilterUnits units) const; + Geom::Matrix get_matrix_user2units(SPFilterUnits units) const; SPFilterUnits filterUnits, primitiveUnits; double resolution_x, resolution_y; bool paraller_axis; bool automatic_resolution; - Matrix ctm; - Rect item_bbox; - Rect filter_area; + Geom::Matrix ctm; + Geom::OptRect item_bbox; + Geom::OptRect filter_area; }; diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index 2f437ba6c..36ba3704e 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -157,8 +157,8 @@ int Filter::render(NRArenaItem const *item, NRPixBlock *pb) FilterUnits units(_filter_units, _primitive_units); units.set_ctm(trans); - units.set_item_bbox(from_2geom(item_bbox)); - units.set_filter_area(from_2geom(filter_area)); + units.set_item_bbox(item_bbox); + units.set_filter_area(filter_area); // TODO: with filterRes of 0x0 should return an empty image std::pair resolution -- 2.30.2