homogeneoussplines.h revision fbc6bde0fc903b3982812d69c4f3ca2bfad690ee
/* This file is part of the libdepixelize project
Copyright (C) 2013 VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com>
GNU Lesser General Public License Usage
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
GNU General Public License Usage
Alternatively, this library may be used under the terms of the GNU General
Public License as published by the Free Software Foundation, either version
2 of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public License along with
this library. If not, see <http://www.gnu.org/licenses/>.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#include "simplifiedvoronoi.h"
#include "point.h"
#include <algorithm>
#include <utility>
{
struct Polygon
{
Polygon() {}
{
for ( int i = 0 ; i != 4 ; ++i )
}
/**
* It may be benefited from C++11 move references.
*/
};
// Iterators
{
}
const_iterator begin() const
{
}
{
}
const_iterator end() const
{
}
{
}
int width() const
{
return _width;
}
int height() const
{
return _height;
}
struct CommonEdge
{
bool ok; //< share an edge
// the interval is closed on both ends
// different from [begin, end) STL style
};
struct SelfCommonEdge
{
bool ok; //< share an edge
// Greater range. The one that should be erased from the vector.
// Smaller range. The one that should be used to create a new vector.
};
/**
* Return ok == true if they share an edge (more than one point).
*/
/**
* Return ok == true if they share an edge (more than one point).
*
* - [dst_begin, dst_end) will contain the hole polygon
* - [src_begin, src_end) will contain the range to be erased
*
* It's required to do the search in backward order.
*/
/*!
* Add polygon represented by \p common_edge.src to \p common_edge.dst.
*/
/**
* Weird recursive function created to solve the complex problem to fill
* polygons holes without the need to store temporaries on the heap nor
* changing requirements to some data type that don't invalidate iterators
* that point before the current element (maybe I'll write some poetry about
* the problem someday).
*/
int _width;
int _height;
};
{
//if (!voronoi.size())
// return;
// Identify visible edges (group polygons with the same color)
bool found = false;
if ( common_edge.ok ) {
found = true;
if ( common_edge2.ok ) {
break;
}
}
}
break;
}
}
}
if ( !found ) {
}
}
// Find polygons with holes and fix them
// This iteration runs such complex time-consuming algorithm, but each
// results and the only waste would be a join at the end of the for.
}
}
}
// it can infinite loop if points of both entities are equal,
// but this shouldn't happen if user has only access to Kopf2011 interface
{
// It's an edge, then the points are closer together. After we find the
// first point, there is no need for check against all points of the src
// a second time
continue;
// iterate until find the beginning of the common edge range
while ( *dst_common_edge_begin == *src_common_edge_end ) {
if ( dst_common_edge_begin == dst_begin )
else
if ( src_common_edge_end == src_end )
}
// fix {dst_begin, src_end} range
if ( dst_common_edge_begin == dst_end )
if ( src_common_edge_end == src_begin )
else
// find the end of the common edge range
while ( *dst_common_edge_end == *src_common_edge_begin ) {
if ( dst_common_edge_end == dst_end )
if ( src_common_edge_begin == src_begin )
else
}
// fix {dst_end, src_begin} range
if ( dst_common_edge_end == dst_begin )
else
if ( src_common_edge_begin == src_end )
// if only one point in common
if ( dst_common_edge_begin == dst_common_edge_end )
continue;
return ret;
}
return ret;
}
{
continue;
}
return ret;
}
return ret;
}
{
// the rotated cell must be inserted before (dst.begin() + index)
// first, we remove the common edge in dst
// common edge is in the middle of dst
} else {
// common edge cross the end of dst
}
// second, we copy src points to polygon
// common edge is in the middle of src
} else {
// common edge cross the end of src
}
}
// The following piece of code is so evil that you could end up invoking an
// ancient beast if you proceed to read it, but I'll be able to explain it in
// the form of some video (text is not so representative as an image).
{
// the exact location might not always be back and iterators will be
// invalidated after some insertions, then the index is required
if ( res == region_end )
continue;
it);
region_begin = res;
do {
++it;
--res;
it = region_begin;
}
region_end - 1);
}
} // namespace Tracer
#endif // LIBDEPIXELIZE_TRACER_HOMOGENEOUSSPLINES_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:encoding=utf-8:textwidth=99 :