From 858a1a2d5395cca9f26b32c305d8c7d1dcd3c9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Sat, 5 Oct 2013 23:09:30 -0300 Subject: Bumping a new release of libdepixelize (bzr r12663) --- ...PLEASE DON'T MAKE CHANGES IN THESE FILES.README | 9 + src/libdepixelize/kopftracer2011.cpp | 54 +-- src/libdepixelize/kopftracer2011.h | 10 +- src/libdepixelize/priv/simplifiedvoronoi.h | 391 ++++++++++++++------- src/libdepixelize/priv/splines-kopf2011.h | 10 +- src/libdepixelize/splines.h | 6 +- 6 files changed, 299 insertions(+), 181 deletions(-) create mode 100644 src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README (limited to 'src/libdepixelize') diff --git a/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README b/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README new file mode 100644 index 000000000..df63435d6 --- /dev/null +++ b/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README @@ -0,0 +1,9 @@ +All code files in this directory are *direct* copies of the files in +libdepixelize's BZR repo. +If you want to change the code, please change it in libdepixelize, then copy the +files here. +Otherwise, I will probably miss that you changed something in Inkscape's copy, +and destroy your changes by copying libdepixelize's files over it during the +next time I update Inkscape's copy of libdepixelize. + +libdepixelize's BZR repo = lp:libdepixelize diff --git a/src/libdepixelize/kopftracer2011.cpp b/src/libdepixelize/kopftracer2011.cpp index 5e6e26048..95f91fdcb 100644 --- a/src/libdepixelize/kopftracer2011.cpp +++ b/src/libdepixelize/kopftracer2011.cpp @@ -86,7 +86,7 @@ Splines Kopf2011::to_voronoi(const std::string &filename, Splines Kopf2011::to_voronoi(const Glib::RefPtr &buf, const Options &options) { - return Splines(_voronoi(buf, options)); + return Splines(_voronoi(buf, options)); } Splines Kopf2011::to_splines(const std::string &filename, @@ -98,13 +98,15 @@ Splines Kopf2011::to_splines(const std::string &filename, Splines Kopf2011::to_splines(const Glib::RefPtr &buf, const Options &options) { - HomogeneousSplines splines(_voronoi(buf, options)); + HomogeneousSplines splines(_voronoi + (buf, options)); return Splines(splines, options.optimize, options.nthreads); } -template -SimplifiedVoronoi Kopf2011::_voronoi(const Glib::RefPtr &buf, - const Options &options) +template +SimplifiedVoronoi +Kopf2011::_voronoi(const Glib::RefPtr &buf, + const Options &options) { PixelGraph graph(buf); @@ -146,13 +148,7 @@ SimplifiedVoronoi Kopf2011::_voronoi(const Glib::RefPtr &b graph.checkConsistency(); #endif - _remove_puzzle_pattern(graph); - -#ifndef NDEBUG - graph.checkConsistency(); -#endif - - return SimplifiedVoronoi(graph); + return SimplifiedVoronoi(graph); } // TODO: move this function (plus connectAllNeighbors) to PixelGraph constructor @@ -315,40 +311,6 @@ void Kopf2011::_remove_crossing_edges_unsafe(PixelGraph &graph, } } -inline -void Kopf2011::_remove_puzzle_pattern(PixelGraph &graph) -{ - if ( graph.width() < 2 || graph.height() < 2 ) - return; - - PixelGraph::iterator it = graph.begin(); - for ( int i = 0 ; i + 1 != graph.height() ; ++i ) { - PixelGraph::iterator it2 = it; - for ( int j = 0 ; j + 1 != graph.width() ; ++j ) { - // Evil pattern currently not handled correctly in SimplifiedVoronoi - if ( it2->adj.right + it2->adj.bottom - + graph.nodeBottomRight(it2)->adj.left - + graph.nodeBottomRight(it2)->adj.top == 3 ) { - // We fake a new connection =) - it2->adj.right = true; - graph.nodeRight(it2)->adj.left = true; - - it2->adj.bottom = true; - graph.nodeBottom(it2)->adj.top = true; - - graph.nodeBottomRight(it2)->adj.left = true; - graph.nodeBottom(it2)->adj.right = true; - - graph.nodeBottomRight(it2)->adj.top = true; - graph.nodeRight(it2)->adj.bottom = true; - } - - it2 = graph.nodeRight(it2); - } - it = graph.nodeBottom(it); - } -} - inline int Heuristics::curves(const PixelGraph &graph, PixelGraph::const_iterator a, PixelGraph::const_iterator b) diff --git a/src/libdepixelize/kopftracer2011.h b/src/libdepixelize/kopftracer2011.h index aff39d3d8..c224abe9a 100644 --- a/src/libdepixelize/kopftracer2011.h +++ b/src/libdepixelize/kopftracer2011.h @@ -35,8 +35,6 @@ namespace Tracer { class PixelGraph; -template class SimplifiedVoronoi; -template class HomogeneousSplines; class Kopf2011 { @@ -102,15 +100,15 @@ public: private: typedef Geom::Coord Precision; - template - static SimplifiedVoronoi _voronoi(const Glib::RefPtr &buf, - const Options &options); + template + static SimplifiedVoronoi + _voronoi(const Glib::RefPtr &buf, + const Options &options); static void _disconnect_neighbors_with_dissimilar_colors(PixelGraph &graph); static void _remove_crossing_edges_safe(PixelGraph &graph); static void _remove_crossing_edges_unsafe(PixelGraph &graph, const Options &options); - static void _remove_puzzle_pattern(PixelGraph &graph); }; } // namespace Tracer diff --git a/src/libdepixelize/priv/simplifiedvoronoi.h b/src/libdepixelize/priv/simplifiedvoronoi.h index d5ebc36e5..8a25bc626 100644 --- a/src/libdepixelize/priv/simplifiedvoronoi.h +++ b/src/libdepixelize/priv/simplifiedvoronoi.h @@ -32,7 +32,7 @@ namespace Tracer { -template +template class SimplifiedVoronoi { public: @@ -121,8 +121,10 @@ public: } private: +#ifdef LIBDEPIXELIZE_VERY_TYPE_SAFE typedef void (*PointTransform)(Point &p, T dx, T dy); typedef bool (*NodeTransform)(PixelGraph::const_iterator); +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE /** * Output is translated by -.5 in each axis. This function fixes this error. @@ -221,6 +223,9 @@ private: * indirection, except for the problem of too many layers of indirection." * -- David J. Wheeler */ +#ifndef LIBDEPIXELIZE_VERY_TYPE_SAFE + template +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE void _genericComplexBottomRight(PixelGraph::const_iterator a_it, PixelGraph::const_iterator b_it, PixelGraph::const_iterator c_it, @@ -241,8 +246,9 @@ private: std::vector _cells; }; -template -SimplifiedVoronoi::SimplifiedVoronoi(const PixelGraph &graph) : +template +SimplifiedVoronoi +::SimplifiedVoronoi(const PixelGraph &graph) : _width(graph.width()), _height(graph.height()), _cells(graph.size()) @@ -481,10 +487,11 @@ SimplifiedVoronoi::SimplifiedVoronoi(const PixelGraph &graph) : } } -template void -SimplifiedVoronoi::_complexTopLeft(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template void +SimplifiedVoronoi +::_complexTopLeft(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeLeft(graph_it), @@ -502,10 +509,11 @@ SimplifiedVoronoi::_complexTopLeft(const PixelGraph &graph, &SimplifiedVoronoi::_complexTopLeftTransformTopLeft); } -template void -SimplifiedVoronoi::_complexTopRight(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template void +SimplifiedVoronoi +::_complexTopRight(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeTop(graph_it), @@ -523,10 +531,11 @@ SimplifiedVoronoi::_complexTopRight(const PixelGraph &graph, &SimplifiedVoronoi::_complexTopRightTransformTopLeft); } -template void -SimplifiedVoronoi::_complexBottomRight(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template void +SimplifiedVoronoi +::_complexBottomRight(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeRight(graph_it), @@ -544,10 +553,11 @@ SimplifiedVoronoi::_complexBottomRight(const PixelGraph &graph, &SimplifiedVoronoi::_complexBottomRightTransformTopLeft); } -template void -SimplifiedVoronoi::_complexBottomLeft(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template void +SimplifiedVoronoi +::_complexBottomLeft(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeBottom(graph_it), @@ -565,229 +575,268 @@ SimplifiedVoronoi::_complexBottomLeft(const PixelGraph &graph, &SimplifiedVoronoi::_complexBottomLeftTransformTopLeft); } -template void -SimplifiedVoronoi::_complexTopLeftTransform(Point &p, T dx, T dy) +template void +SimplifiedVoronoi +::_complexTopLeftTransform(Point &p, T dx, T dy) { p.x -= dx; p.y -= dy; } -template void -SimplifiedVoronoi::_complexTopRightTransform(Point &p, T dx, T dy) +template void +SimplifiedVoronoi +::_complexTopRightTransform(Point &p, T dx, T dy) { p.x += dy; p.y -= dx; } -template void -SimplifiedVoronoi::_complexBottomRightTransform(Point &p, T dx, T dy) +template void +SimplifiedVoronoi +::_complexBottomRightTransform(Point &p, T dx, T dy) { p.x += dx; p.y += dy; } -template void -SimplifiedVoronoi::_complexBottomLeftTransform(Point &p, T dx, T dy) +template void +SimplifiedVoronoi +::_complexBottomLeftTransform(Point &p, T dx, T dy) { p.x -= dy; p.y += dx; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformTop(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformTopRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformBottomRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformBottom(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template -bool SimplifiedVoronoi::_complexTopLeftTransformTopLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopLeftTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template -bool SimplifiedVoronoi::_complexTopRightTransformTop(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template -bool SimplifiedVoronoi::_complexTopRightTransformTopRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template -bool SimplifiedVoronoi::_complexTopRightTransformRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template -bool SimplifiedVoronoi::_complexTopRightTransformBottomRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template -bool SimplifiedVoronoi::_complexTopRightTransformBottom(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template -bool SimplifiedVoronoi::_complexTopRightTransformBottomLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template -bool SimplifiedVoronoi::_complexTopRightTransformLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template -bool SimplifiedVoronoi::_complexTopRightTransformTopLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexTopRightTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformTop(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformTopRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformBottomRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformBottom(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformBottomLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template -bool SimplifiedVoronoi::_complexBottomRightTransformTopLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomRightTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformTop(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformTopRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformBottomRight(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformBottom(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template -bool SimplifiedVoronoi::_complexBottomLeftTransformTopLeft(PixelGraph::const_iterator graph_it) +template +bool SimplifiedVoronoi +::_complexBottomLeftTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template +template +#ifndef LIBDEPIXELIZE_VERY_TYPE_SAFE +template +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE void -SimplifiedVoronoi +SimplifiedVoronoi ::_genericComplexBottomRight(PixelGraph::const_iterator a_it, PixelGraph::const_iterator b_it, PixelGraph::const_iterator c_it, @@ -817,8 +866,12 @@ SimplifiedVoronoi // this and bottom-right are connected bool smooth[2] = { - same_color(a_it->rgba, d_it->rgba) || right(a_it), - same_color(a_it->rgba, d_it->rgba) || bottom(a_it) + ( same_color(a_it->rgba, d_it->rgba) + || same_color(a_it->rgba, b_it->rgba) + || same_color(b_it->rgba, d_it->rgba) ), + ( same_color(a_it->rgba, d_it->rgba) + || same_color(a_it->rgba, c_it->rgba) + || same_color(c_it->rgba, d_it->rgba) ) }; Point borderMid = initial; @@ -836,7 +889,7 @@ SimplifiedVoronoi vertices[1] = _adjust(midpoint(borderMid, vertices[1]), smooth[1]); } - if ( !smooth[0] ) { + if ( !smooth[0] && adjust_splines ) { cells_it->vertices.push_back(vertices[0].invisible()); { Point another = vertices[0]; @@ -885,7 +938,7 @@ SimplifiedVoronoi cells_it->vertices.push_back(vertices[0]); - if ( !smooth[1] ) { + if ( !smooth[1] && adjust_splines ) { { Point another = vertices[1]; transform(another, @@ -954,7 +1007,7 @@ SimplifiedVoronoi vertex = _adjust(midpoint(initial, vertex)); // compute smoothness - if ( right(a_it) ) { + if ( right(a_it) && adjust_splines ) { // this and right are connected if ( !right(c_it) && !( bottom(a_it) && bottom(b_it) ) ) { @@ -1006,11 +1059,65 @@ SimplifiedVoronoi * 0.03125 ); transform(vertex, amount, amount); } + } else if ( !same_color(a_it->rgba, b_it->rgba) ) { + vertex.smooth = false; + // This is the same code of the if ( special ) + // I REALLY NEED lambdas to improve this code without + // creating yet another interface that takes a million + // of function parameters and keep code locality + { + Point another = vertex; + T amount = 0.03125; + transform(another, + amount + * ( topleft(c_it) - topright(d_it) + + bottomleft(a_it) - bottomright(b_it) ), + // y + - amount + * ( topleft(c_it) + topright(d_it) + - bottomleft(a_it) - bottomright(b_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point another = vertex; + T amount = 0.0625; + transform(another, + 0.25 - amount + * ( topright(d_it) + bottomright(b_it) ), + // y + - amount + * ( topright(d_it) - bottomright(b_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point another = vertex; + T amount = 0.0625; + transform(another, + - ( 0.25 - amount + * ( topleft(c_it) + bottomleft(a_it) ) ), + // y + - amount + * ( topleft(c_it) - bottomleft(a_it) )); + another.smooth = true; + cells_it->vertices.push_back(another); + } + { + Point another = vertex; + T amount = 0.1875; + transform(another, + - ( 0.75 - amount + * ( topleft(c_it) + bottomleft(a_it) ) ), + // y + - amount + * ( topleft(c_it) - bottomleft(a_it) )); + cells_it->vertices.push_back(another.invisible()); + } + vertex.visible = false; } } else { // {this, right} is the pair with the angle // closest to 180 degrees - vertex.smooth = true; + vertex.smooth = same_color(a_it->rgba, b_it->rgba); } } else { // there might be 2-color, then vertex.smooth = true @@ -1018,17 +1125,12 @@ SimplifiedVoronoi // or it might be 1-color and doesn't matter, // because the current node will disappear vertex.smooth - = !( bottom(a_it) ^ bottom(b_it) ); - - if ( vertex.smooth ) { - vertex.smooth - = same_color(a_it->rgba, b_it->rgba) - + same_color(a_it->rgba, c_it->rgba) - + same_color(d_it->rgba, b_it->rgba) - + same_color(d_it->rgba, c_it->rgba) == 2; - } + = same_color(a_it->rgba, b_it->rgba) + + same_color(a_it->rgba, c_it->rgba) + + same_color(d_it->rgba, b_it->rgba) + + same_color(d_it->rgba, c_it->rgba) == 2; } - } else if ( bottom(a_it) ) { + } else if ( bottom(a_it) && adjust_splines ) { // this and bottom are connected if ( !bottom(b_it) && !( right(a_it) && right(c_it) ) ) { @@ -1079,28 +1181,75 @@ SimplifiedVoronoi * 0.03125 ); transform(vertex, amount, amount); } + } else if ( !same_color(a_it->rgba, c_it->rgba) ) { + vertex.smooth = false; + // This is the same code of the if ( special ) + // I REALLY NEED lambdas to improve this code without + // creating yet another interface that takes a million + // of function parameters and keep code locality + cells_it->vertices.push_back(vertex.invisible()); + { + Point another = vertex; + T amount = 0.1875; + transform(another, + - ( topleft(b_it) - topright(a_it) ) * amount, + // y + - ( 0.75 + - ( topleft(b_it) + topright(a_it) ) + * amount )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point another = vertex; + T amount = 0.0625; + transform(another, + - ( topleft(b_it) - topright(a_it) ) * amount, + // y + - ( 0.25 + - ( topleft(b_it) + topright(a_it) ) + * amount )); + another.smooth = true; + cells_it->vertices.push_back(another); + } + { + Point another = vertex; + T amount = 0.0625; + transform(another, - amount + * ( bottomleft(d_it) - bottomright(c_it) ), + // y + 0.25 - amount + * ( bottomleft(d_it) + bottomright(c_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + transform(vertex, + - ( topleft(b_it) + bottomleft(d_it) + - topright(a_it) - bottomright(c_it) ) + * 0.03125, + // y + ( topleft(b_it) - bottomleft(d_it) + + topright(a_it) - bottomright(c_it) ) + * 0.03125); + vertex.visible = false; + } } } else { // {this, bottom} is the pair with the angle // closest to 180 degrees - vertex.smooth = true; + vertex.smooth = same_color(a_it->rgba, c_it->rgba); } } else { // there might be 2-color, then vertex.smooth = true // or it might be 1-color and doesn't matter, // because the current node will disappear - vertex.smooth = !( right(a_it) ^ right(c_it) ); - - if ( vertex.smooth ) { - vertex.smooth - = same_color(a_it->rgba, c_it->rgba) - + same_color(a_it->rgba, b_it->rgba) - + same_color(d_it->rgba, b_it->rgba) - + same_color(d_it->rgba, c_it->rgba) == 2; - } + vertex.smooth + = same_color(a_it->rgba, c_it->rgba) + + same_color(a_it->rgba, b_it->rgba) + + same_color(d_it->rgba, b_it->rgba) + + same_color(d_it->rgba, c_it->rgba) == 2; } - } else if ( bottom(b_it) ) { + } else if ( bottom(b_it) && adjust_splines ) { // right and bottom-right are connected bool special = false; @@ -1205,7 +1354,7 @@ SimplifiedVoronoi vertex.visible = false; } } - } else if ( right(c_it) ) { + } else if ( right(c_it) && adjust_splines ) { // bottom and bottom-right are connected bool special = false; diff --git a/src/libdepixelize/priv/splines-kopf2011.h b/src/libdepixelize/priv/splines-kopf2011.h index eb84c3bfb..fb4f8ba1e 100644 --- a/src/libdepixelize/priv/splines-kopf2011.h +++ b/src/libdepixelize/priv/splines-kopf2011.h @@ -107,22 +107,22 @@ void worker(const typename HomogeneousSplines::Polygon &source, } } -template -Splines::Splines(const SimplifiedVoronoi &diagram) : +template +Splines::Splines(const SimplifiedVoronoi &diagram) : _width(diagram.width()), _height(diagram.height()) { _paths.reserve(diagram.size()); - for ( typename SimplifiedVoronoi::const_iterator it = diagram.begin() - , end = diagram.end() ; it != end ; ++it ) { + for ( typename SimplifiedVoronoi::const_iterator + it = diagram.begin() , end = diagram.end() ; it != end ; ++it ) { Path path; path.pathVector .push_back(Geom::Path(to_geom_point(it->vertices.front()))); for ( typename std::vector< Point >::const_iterator - it2 = it->vertices.begin(), end2 = it->vertices.end() + it2 = ++it->vertices.begin(), end2 = it->vertices.end() ; it2 != end2 ; ++it2 ) { path.pathVector.back() .appendNew(Geom::Point(it2->x, it2->y)); diff --git a/src/libdepixelize/splines.h b/src/libdepixelize/splines.h index c4b455aae..b06ba8ba9 100644 --- a/src/libdepixelize/splines.h +++ b/src/libdepixelize/splines.h @@ -30,7 +30,7 @@ namespace Tracer { -template +template class SimplifiedVoronoi; template @@ -54,8 +54,8 @@ public: Splines() /* = default */ {} - template - Splines(const SimplifiedVoronoi &simplifiedVoronoi); + template + Splines(const SimplifiedVoronoi &simplifiedVoronoi); /** * There are two levels of optimization. The first level only removes -- cgit v1.2.3