2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class gathering stroke creation algorithms
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2009-03-21 04:51:51 +00:00
|
|
|
#include <stdexcept>
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "Canvas.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "CurveIterators.h"
|
|
|
|
|
#include "Operators.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "Stroke.h"
|
2014-05-25 16:16:00 +09:00
|
|
|
#include "StrokeIterators.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2022-10-26 18:58:04 +02:00
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2013-01-03 23:27:20 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2014-04-17 14:19:10 +09:00
|
|
|
Operators::I1DContainer Operators::_current_view_edges_set;
|
|
|
|
|
Operators::I1DContainer Operators::_current_chains_set;
|
2020-11-06 17:49:09 +01:00
|
|
|
Operators::I1DContainer *Operators::_current_set = nullptr;
|
2014-04-17 14:19:10 +09:00
|
|
|
Operators::StrokesContainer Operators::_current_strokes_set;
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
int Operators::select(UnaryPredicate1D &pred)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_set) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (_current_set->empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
I1DContainer new_set;
|
|
|
|
|
I1DContainer rejected;
|
|
|
|
|
Functions1D::ChainingTimeStampF1D cts;
|
|
|
|
|
Functions1D::TimeStampF1D ts;
|
|
|
|
|
I1DContainer::iterator it = _current_set->begin();
|
|
|
|
|
I1DContainer::iterator itbegin = it;
|
|
|
|
|
while (it != _current_set->end()) {
|
|
|
|
|
Interface1D *i1d = *it;
|
|
|
|
|
cts(*i1d); // mark everyone's chaining time stamp anyway
|
|
|
|
|
if (pred(*i1d) < 0) {
|
|
|
|
|
new_set.clear();
|
|
|
|
|
rejected.clear();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
|
|
|
|
new_set.push_back(i1d);
|
|
|
|
|
ts(*i1d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rejected.push_back(i1d);
|
|
|
|
|
}
|
|
|
|
|
++it;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if ((*itbegin)->getExactTypeName() != "ViewEdge") {
|
2019-05-31 22:51:19 +10:00
|
|
|
for (it = rejected.begin(); it != rejected.end(); ++it) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete *it;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
rejected.clear();
|
|
|
|
|
_current_set->clear();
|
|
|
|
|
*_current_set = new_set;
|
|
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
UnaryFunction1D_void &modifier)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewEdge *edge;
|
|
|
|
|
I1DContainer new_chains_set;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
|
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
2014-04-01 11:34:00 +11:00
|
|
|
while (true) {
|
2012-12-28 20:21:05 +00:00
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
if (modifier(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (it.isEnd()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (pred(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
new_chains_set.push_back(new_chain);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!new_chains_set.empty()) {
|
|
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
|
|
|
|
_current_chains_set.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
|
|
|
|
_current_set = &_current_chains_set;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
2011-02-26 22:11:40 +00:00
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete (*it);
|
2011-02-26 22:11:40 +00:00
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
Functions1D::IncrementChainingTimeStampF1D ts;
|
|
|
|
|
Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1);
|
|
|
|
|
ViewEdge *edge;
|
|
|
|
|
I1DContainer new_chains_set;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
|
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred_ts(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred_ts.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
2014-04-01 11:34:00 +11:00
|
|
|
while (true) {
|
2012-12-28 20:21:05 +00:00
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
++it;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (it.isEnd()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (pred(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (pred_ts(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred_ts.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
new_chains_set.push_back(new_chain);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!new_chains_set.empty()) {
|
|
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
|
|
|
|
_current_chains_set.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
|
|
|
|
_current_set = &_current_chains_set;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
2011-02-26 22:11:40 +00:00
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete (*it);
|
2011-02-26 22:11:40 +00:00
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
void Operators::bidirectionalChain(ViewEdgeIterator &it,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
UnaryFunction1D_void &modifier)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2019-05-31 23:21:16 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 12:51:50 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewEdge *edge;
|
|
|
|
|
Chain *new_chain;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
2023-08-09 10:47:43 +10:00
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 23:21:16 +10:00
|
|
|
if (pred(**it_edge)) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
2012-12-28 20:21:05 +00:00
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
|
|
|
|
# if 0 // FIXME
|
|
|
|
|
ViewEdgeIterator it_back(it);
|
|
|
|
|
--it_back;
|
|
|
|
|
# endif
|
|
|
|
|
do {
|
|
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
modifier(**it);
|
|
|
|
|
++it;
|
|
|
|
|
} while (!it.isEnd() && !pred(**it));
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
--it;
|
|
|
|
|
while (!it.isEnd() && !pred(**it)) {
|
|
|
|
|
new_chain->push_viewedge_front(*it, it.getOrientation());
|
|
|
|
|
modifier(**it);
|
|
|
|
|
--it;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set.push_back(new_chain);
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 23:21:16 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
void Operators::bidirectionalChain(ViewEdgeIterator &it, UnaryPredicate1D &pred)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2019-05-31 23:21:16 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 12:51:50 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
Functions1D::IncrementChainingTimeStampF1D ts;
|
|
|
|
|
Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewEdge *edge;
|
|
|
|
|
Chain *new_chain;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
2023-08-09 10:47:43 +10:00
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 23:21:16 +10:00
|
|
|
if (pred(**it_edge) || pred_ts(**it_edge)) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
2012-12-28 20:21:05 +00:00
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
2019-04-30 17:50:57 +10:00
|
|
|
# if 0 // FIXME
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewEdgeIterator it_back(it);
|
|
|
|
|
--it_back;
|
|
|
|
|
# endif
|
|
|
|
|
do {
|
|
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
++it;
|
|
|
|
|
} while (!it.isEnd() && !pred(**it) && !pred_ts(**it));
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
--it;
|
|
|
|
|
while (!it.isEnd() && !pred(**it) && !pred_ts(**it)) {
|
|
|
|
|
new_chain->push_viewedge_front(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
--it;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set.push_back(new_chain);
|
2011-02-26 22:11:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 23:21:16 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int Operators::bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
Functions1D::IncrementChainingTimeStampF1D ts;
|
|
|
|
|
Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1);
|
|
|
|
|
ViewEdge *edge;
|
|
|
|
|
I1DContainer new_chains_set;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
|
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred_ts(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred_ts.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
|
|
|
|
// re-init iterator
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
it.setOrientation(true);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (it.init() < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
|
|
|
|
#if 0 // FIXME
|
|
|
|
|
ViewEdgeIterator it_back(it);
|
|
|
|
|
--it_back;
|
|
|
|
|
#endif
|
2014-04-01 11:34:00 +11:00
|
|
|
while (true) {
|
2012-12-28 20:21:05 +00:00
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
if (it.increment() < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (it.isEnd()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (pred(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
it.setOrientation(true);
|
|
|
|
|
if (it.decrement() < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
while (!it.isEnd()) {
|
|
|
|
|
if (pred(**it) < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
new_chain->push_viewedge_front(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
if (it.decrement() < 0) {
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.push_back(new_chain);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!new_chains_set.empty()) {
|
|
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
|
|
|
|
_current_chains_set.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
|
|
|
|
_current_set = &_current_chains_set;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
2011-02-26 22:11:40 +00:00
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
2012-12-28 20:21:05 +00:00
|
|
|
delete (*it);
|
2011-02-26 22:11:40 +00:00
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Operators::bidirectionalChain(ChainingIterator &it)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_current_view_edges_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-26 10:04:44 +10:00
|
|
|
uint id = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
Functions1D::IncrementChainingTimeStampF1D ts;
|
|
|
|
|
Predicates1D::EqualToChainingTimeStampUP1D pred_ts(TimeStamp::instance()->getTimeStamp() + 1);
|
|
|
|
|
ViewEdge *edge;
|
|
|
|
|
I1DContainer new_chains_set;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
|
|
|
|
|
it_edge != _current_view_edges_set.end();
|
|
|
|
|
++it_edge)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred_ts(**it_edge) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (pred_ts.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
edge = dynamic_cast<ViewEdge *>(*it_edge);
|
|
|
|
|
// re-init iterator
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
it.setOrientation(true);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (it.init() < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_chain = new Chain(id);
|
|
|
|
|
++id;
|
|
|
|
|
#if 0 // FIXME
|
|
|
|
|
ViewEdgeIterator it_back(it);
|
|
|
|
|
--it_back;
|
|
|
|
|
#endif
|
|
|
|
|
do {
|
|
|
|
|
new_chain->push_viewedge_back(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
if (it.increment() < 0) { // FIXME
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} while (!it.isEnd());
|
|
|
|
|
it.setBegin(edge);
|
|
|
|
|
it.setCurrentEdge(edge);
|
|
|
|
|
it.setOrientation(true);
|
|
|
|
|
if (it.decrement() < 0) { // FIXME
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
while (!it.isEnd()) {
|
|
|
|
|
new_chain->push_viewedge_front(*it, it.getOrientation());
|
|
|
|
|
ts(**it);
|
|
|
|
|
if (it.decrement() < 0) { // FIXME
|
|
|
|
|
delete new_chain;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.push_back(new_chain);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!new_chains_set.empty()) {
|
|
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
|
|
|
|
_current_chains_set.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
|
|
|
|
_current_set = &_current_chains_set;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-02-26 22:11:40 +00:00
|
|
|
|
|
|
|
|
error:
|
2012-12-28 20:21:05 +00:00
|
|
|
for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
|
|
|
|
|
delete (*it);
|
|
|
|
|
}
|
|
|
|
|
new_chains_set.clear();
|
|
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::sequentialSplit(UnaryPredicate0D &pred, float sampling)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (_current_chains_set.empty()) {
|
|
|
|
|
cerr << "Warning: current set empty" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
CurvePoint *point;
|
|
|
|
|
Chain *new_curve;
|
|
|
|
|
I1DContainer splitted_chains;
|
|
|
|
|
Interface0DIterator first;
|
|
|
|
|
Interface0DIterator end;
|
|
|
|
|
Interface0DIterator last;
|
|
|
|
|
Interface0DIterator it;
|
|
|
|
|
I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
Id currentId = (*cit)->getId();
|
|
|
|
|
new_curve = new Chain(currentId);
|
|
|
|
|
first = (*cit)->pointsBegin(sampling);
|
|
|
|
|
end = (*cit)->pointsEnd(sampling);
|
|
|
|
|
last = end;
|
|
|
|
|
--last;
|
|
|
|
|
it = first;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
point = dynamic_cast<CurvePoint *>(&(*it));
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
++it;
|
2013-03-11 06:56:51 +00:00
|
|
|
for (; it != end; ++it) {
|
2012-12-28 20:21:05 +00:00
|
|
|
point = dynamic_cast<CurvePoint *>(&(*it));
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
if (pred(it) < 0) {
|
|
|
|
|
delete new_curve;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (pred.result && (it != last)) {
|
|
|
|
|
splitted_chains.push_back(new_curve);
|
|
|
|
|
currentId.setSecond(currentId.getSecond() + 1);
|
|
|
|
|
new_curve = new Chain(currentId);
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (new_curve->nSegments() == 0) {
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
delete new_curve;
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
splitted_chains.push_back(new_curve);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// Update the current set of chains:
|
|
|
|
|
cit = _current_chains_set.begin();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.clear();
|
2011-02-22 01:39:56 +00:00
|
|
|
#if 0
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set = splitted_chains;
|
2011-02-22 01:39:56 +00:00
|
|
|
#else
|
2012-12-28 20:21:05 +00:00
|
|
|
for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
|
|
|
|
|
if ((*cit)->getLength2D() < M_EPSILON) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.push_back(*cit);
|
2011-02-22 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-28 20:21:05 +00:00
|
|
|
splitted_chains.clear();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
|
|
|
|
|
error:
|
2012-12-28 20:21:05 +00:00
|
|
|
cit = splitted_chains.begin();
|
|
|
|
|
citend = splitted_chains.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
}
|
|
|
|
|
splitted_chains.clear();
|
|
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::sequentialSplit(UnaryPredicate0D &startingPred,
|
|
|
|
|
UnaryPredicate0D &stoppingPred,
|
|
|
|
|
float sampling)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (_current_chains_set.empty()) {
|
|
|
|
|
cerr << "Warning: current set empty" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
CurvePoint *point;
|
|
|
|
|
Chain *new_curve;
|
|
|
|
|
I1DContainer splitted_chains;
|
|
|
|
|
Interface0DIterator first;
|
|
|
|
|
Interface0DIterator end;
|
|
|
|
|
Interface0DIterator last;
|
|
|
|
|
Interface0DIterator itStart;
|
|
|
|
|
Interface0DIterator itStop;
|
|
|
|
|
I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
Id currentId = (*cit)->getId();
|
|
|
|
|
first = (*cit)->pointsBegin(sampling);
|
|
|
|
|
end = (*cit)->pointsEnd(sampling);
|
|
|
|
|
last = end;
|
|
|
|
|
--last;
|
|
|
|
|
itStart = first;
|
|
|
|
|
do {
|
|
|
|
|
itStop = itStart;
|
|
|
|
|
++itStop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
new_curve = new Chain(currentId);
|
|
|
|
|
currentId.setSecond(currentId.getSecond() + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
point = dynamic_cast<CurvePoint *>(&(*itStart));
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
do {
|
|
|
|
|
point = dynamic_cast<CurvePoint *>(&(*itStop));
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
++itStop;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (itStop == end) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (stoppingPred(itStop) < 0) {
|
|
|
|
|
delete new_curve;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} while (!stoppingPred.result);
|
|
|
|
|
if (itStop != end) {
|
|
|
|
|
point = dynamic_cast<CurvePoint *>(&(*itStop));
|
|
|
|
|
new_curve->push_vertex_back(point);
|
|
|
|
|
}
|
|
|
|
|
if (new_curve->nSegments() == 0) {
|
|
|
|
|
delete new_curve;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
splitted_chains.push_back(new_curve);
|
|
|
|
|
}
|
|
|
|
|
// find next start
|
2013-03-11 06:56:51 +00:00
|
|
|
do {
|
2012-12-28 20:21:05 +00:00
|
|
|
++itStart;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (itStart == end) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (startingPred(itStart) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
} while (!startingPred.result);
|
2020-11-06 12:30:59 +11:00
|
|
|
} while (!ELEM(itStart, end, last));
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// Update the current set of chains:
|
|
|
|
|
cit = _current_chains_set.begin();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.clear();
|
2011-02-22 01:39:56 +00:00
|
|
|
#if 0
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set = splitted_chains;
|
2011-02-22 01:39:56 +00:00
|
|
|
#else
|
2012-12-28 20:21:05 +00:00
|
|
|
for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
|
|
|
|
|
if ((*cit)->getLength2D() < M_EPSILON) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.push_back(*cit);
|
2011-02-22 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-28 20:21:05 +00:00
|
|
|
splitted_chains.clear();
|
|
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
|
|
|
|
|
error:
|
2012-12-28 20:21:05 +00:00
|
|
|
cit = splitted_chains.begin();
|
|
|
|
|
citend = splitted_chains.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
}
|
|
|
|
|
splitted_chains.clear();
|
|
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Internal function
|
2012-12-08 22:24:41 +00:00
|
|
|
static int __recursiveSplit(Chain *_curve,
|
|
|
|
|
UnaryFunction0D<double> &func,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
float sampling,
|
|
|
|
|
Operators::I1DContainer &newChains,
|
|
|
|
|
Operators::I1DContainer &splitted_chains)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) {
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling);
|
|
|
|
|
CurveInternal::CurvePointIterator second = first;
|
|
|
|
|
++second;
|
|
|
|
|
CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling);
|
|
|
|
|
CurveInternal::CurvePointIterator it = second;
|
|
|
|
|
CurveInternal::CurvePointIterator split = second;
|
|
|
|
|
Interface0DIterator it0d = it.castToInterface0DIterator();
|
|
|
|
|
real _min = FLT_MAX; // func(it0d);
|
|
|
|
|
++it;
|
|
|
|
|
CurveInternal::CurvePointIterator next = it;
|
|
|
|
|
++next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool bsplit = false;
|
|
|
|
|
for (; ((it != end) && (next != end)); ++it, ++next) {
|
|
|
|
|
it0d = it.castToInterface0DIterator();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (func(it0d) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (func.result < _min) {
|
|
|
|
|
_min = func.result;
|
|
|
|
|
split = it;
|
|
|
|
|
bsplit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!bsplit) { // we didn't find any minimum
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// retrieves the current splitting id
|
|
|
|
|
Id *newId = _curve->getSplittingId();
|
2020-11-06 17:49:09 +01:00
|
|
|
if (newId == nullptr) {
|
2012-12-28 20:21:05 +00:00
|
|
|
newId = new Id(_curve->getId());
|
|
|
|
|
_curve->setSplittingId(newId);
|
2018-06-17 17:05:14 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_curve_a = new Chain(*newId);
|
|
|
|
|
newId->setSecond(newId->getSecond() + 1);
|
|
|
|
|
new_curve_a->setSplittingId(newId);
|
|
|
|
|
Chain *new_curve_b = new Chain(*newId);
|
|
|
|
|
newId->setSecond(newId->getSecond() + 1);
|
|
|
|
|
new_curve_b->setSplittingId(newId);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(),
|
|
|
|
|
vitend = _curve->curveVerticesEnd();
|
|
|
|
|
CurveInternal::CurvePointIterator vnext = vit;
|
|
|
|
|
++vnext;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (; (vit != vitend) && (vnext != vitend) &&
|
|
|
|
|
(vnext._CurvilinearLength < split._CurvilinearLength);
|
|
|
|
|
++vit, ++vnext)
|
|
|
|
|
{
|
|
|
|
|
new_curve_a->push_vertex_back(&(*vit));
|
|
|
|
|
}
|
|
|
|
|
if ((vit == vitend) || (vnext == vitend)) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "The split takes place in bad location" << endl;
|
|
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// build the two resulting chains
|
|
|
|
|
new_curve_a->push_vertex_back(&(*vit));
|
|
|
|
|
new_curve_a->push_vertex_back(&(*split));
|
|
|
|
|
new_curve_b->push_vertex_back(&(*split));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
for (vit = vnext; vit != vitend; ++vit) {
|
2012-12-28 20:21:05 +00:00
|
|
|
new_curve_b->push_vertex_back(&(*vit));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// let's check whether one or two of the two new curves satisfy the stopping condition or not.
|
|
|
|
|
// (if one of them satisfies it, we don't split)
|
|
|
|
|
if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) {
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
|
|
|
|
// we don't actually create these two chains
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// here we know we'll split _curve:
|
|
|
|
|
splitted_chains.push_back(_curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
__recursiveSplit(new_curve_a, func, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
__recursiveSplit(new_curve_b, func, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
int Operators::recursiveSplit(UnaryFunction0D<double> &func,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
float sampling)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (_current_chains_set.empty()) {
|
|
|
|
|
cerr << "Warning: current set empty" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
Chain *currentChain = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
I1DContainer splitted_chains;
|
|
|
|
|
I1DContainer newChains;
|
|
|
|
|
I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
currentChain = dynamic_cast<Chain *>(*cit);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!currentChain) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
// let's check the first one:
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(*currentChain) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!pred.result) {
|
|
|
|
|
__recursiveSplit(currentChain, func, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
newChains.push_back(currentChain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Update the current set of chains:
|
|
|
|
|
if (!splitted_chains.empty()) {
|
|
|
|
|
for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
2018-06-17 17:05:14 +02:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
splitted_chains.clear();
|
2018-06-17 17:05:14 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set.clear();
|
2011-02-22 01:39:56 +00:00
|
|
|
#if 0
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set = newChains;
|
2011-02-22 01:39:56 +00:00
|
|
|
#else
|
2012-12-28 20:21:05 +00:00
|
|
|
for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) {
|
|
|
|
|
if ((*cit)->getLength2D() < M_EPSILON) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.push_back(*cit);
|
2011-02-22 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-28 20:21:05 +00:00
|
|
|
newChains.clear();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// recursive split with pred 0D
|
2012-12-28 20:21:05 +00:00
|
|
|
static int __recursiveSplit(Chain *_curve,
|
|
|
|
|
UnaryFunction0D<double> &func,
|
|
|
|
|
UnaryPredicate0D &pred0d,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
float sampling,
|
2012-12-08 22:24:41 +00:00
|
|
|
Operators::I1DContainer &newChains,
|
|
|
|
|
Operators::I1DContainer &splitted_chains)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (((_curve->nSegments() == 1) && (sampling == 0)) || (_curve->getLength2D() <= sampling)) {
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
CurveInternal::CurvePointIterator first = _curve->curvePointsBegin(sampling);
|
|
|
|
|
CurveInternal::CurvePointIterator second = first;
|
|
|
|
|
++second;
|
|
|
|
|
CurveInternal::CurvePointIterator end = _curve->curvePointsEnd(sampling);
|
|
|
|
|
CurveInternal::CurvePointIterator it = second;
|
|
|
|
|
CurveInternal::CurvePointIterator split = second;
|
|
|
|
|
Interface0DIterator it0d = it.castToInterface0DIterator();
|
|
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
real _min = func(it0d);
|
2012-12-28 20:21:05 +00:00
|
|
|
++it;
|
|
|
|
|
#endif
|
|
|
|
|
real _min = FLT_MAX;
|
|
|
|
|
++it;
|
2021-12-28 21:53:41 -05:00
|
|
|
// real mean = 0.0f;
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc unused - real variance = 0.0f;
|
2023-01-19 17:07:29 +11:00
|
|
|
// uint count = 0;
|
2012-12-28 20:21:05 +00:00
|
|
|
CurveInternal::CurvePointIterator next = it;
|
|
|
|
|
++next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool bsplit = false;
|
|
|
|
|
for (; ((it != end) && (next != end)); ++it, ++next) {
|
2023-01-19 17:07:29 +11:00
|
|
|
// ++count;
|
2012-12-28 20:21:05 +00:00
|
|
|
it0d = it.castToInterface0DIterator();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred0d(it0d) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (!pred0d.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (func(it0d) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2021-12-28 21:53:41 -05:00
|
|
|
// mean += func.result;
|
2012-12-28 20:21:05 +00:00
|
|
|
if (func.result < _min) {
|
|
|
|
|
_min = func.result;
|
|
|
|
|
split = it;
|
|
|
|
|
bsplit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-25 12:51:50 +10:00
|
|
|
// mean /= float(count);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// if ((!bsplit) || (mean - _min > mean)) { // we didn't find any minimum
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!bsplit) { // we didn't find any minimum
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// retrieves the current splitting id
|
|
|
|
|
Id *newId = _curve->getSplittingId();
|
2020-11-06 17:49:09 +01:00
|
|
|
if (newId == nullptr) {
|
2012-12-28 20:21:05 +00:00
|
|
|
newId = new Id(_curve->getId());
|
|
|
|
|
_curve->setSplittingId(newId);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Chain *new_curve_a = new Chain(*newId);
|
|
|
|
|
newId->setSecond(newId->getSecond() + 1);
|
|
|
|
|
new_curve_a->setSplittingId(newId);
|
|
|
|
|
Chain *new_curve_b = new Chain(*newId);
|
|
|
|
|
newId->setSecond(newId->getSecond() + 1);
|
|
|
|
|
new_curve_b->setSplittingId(newId);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
CurveInternal::CurvePointIterator vit = _curve->curveVerticesBegin(),
|
|
|
|
|
vitend = _curve->curveVerticesEnd();
|
|
|
|
|
CurveInternal::CurvePointIterator vnext = vit;
|
|
|
|
|
++vnext;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (; (vit != vitend) && (vnext != vitend) &&
|
|
|
|
|
(vnext._CurvilinearLength < split._CurvilinearLength);
|
|
|
|
|
++vit, ++vnext)
|
|
|
|
|
{
|
|
|
|
|
new_curve_a->push_vertex_back(&(*vit));
|
|
|
|
|
}
|
|
|
|
|
if ((vit == vitend) || (vnext == vitend)) {
|
2013-01-03 23:27:20 +00:00
|
|
|
if (G.debug & G_DEBUG_FREESTYLE) {
|
|
|
|
|
cout << "The split takes place in bad location" << endl;
|
|
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// build the two resulting chains
|
|
|
|
|
new_curve_a->push_vertex_back(&(*vit));
|
|
|
|
|
new_curve_a->push_vertex_back(&(*split));
|
|
|
|
|
new_curve_b->push_vertex_back(&(*split));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
for (vit = vnext; vit != vitend; ++vit) {
|
2012-12-28 20:21:05 +00:00
|
|
|
new_curve_b->push_vertex_back(&(*vit));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// let's check whether one or two of the two new curves satisfy the stopping condition or not.
|
|
|
|
|
// (if one of them satisfies it, we don't split)
|
|
|
|
|
if (pred(*new_curve_a) < 0 || (!pred.result && pred(*new_curve_b) < 0)) {
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (pred.result) {
|
|
|
|
|
// we don't actually create these two chains
|
|
|
|
|
newChains.push_back(_curve);
|
|
|
|
|
delete new_curve_a;
|
|
|
|
|
delete new_curve_b;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// here we know we'll split _curve:
|
|
|
|
|
splitted_chains.push_back(_curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
__recursiveSplit(new_curve_a, func, pred0d, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
__recursiveSplit(new_curve_b, func, pred0d, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::recursiveSplit(UnaryFunction0D<double> &func,
|
|
|
|
|
UnaryPredicate0D &pred0d,
|
|
|
|
|
UnaryPredicate1D &pred,
|
|
|
|
|
float sampling)
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
if (_current_chains_set.empty()) {
|
|
|
|
|
cerr << "Warning: current set empty" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
Chain *currentChain = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
I1DContainer splitted_chains;
|
|
|
|
|
I1DContainer newChains;
|
|
|
|
|
I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
|
|
|
|
|
for (; cit != citend; ++cit) {
|
|
|
|
|
currentChain = dynamic_cast<Chain *>(*cit);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!currentChain) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
// let's check the first one:
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(*currentChain) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!pred.result) {
|
|
|
|
|
__recursiveSplit(currentChain, func, pred0d, pred, sampling, newChains, splitted_chains);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
newChains.push_back(currentChain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Update the current set of chains:
|
|
|
|
|
if (!splitted_chains.empty()) {
|
|
|
|
|
for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
}
|
|
|
|
|
splitted_chains.clear();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set.clear();
|
2011-02-22 01:39:56 +00:00
|
|
|
#if 0
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set = newChains;
|
2011-02-22 01:39:56 +00:00
|
|
|
#else
|
2012-12-28 20:21:05 +00:00
|
|
|
for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) {
|
|
|
|
|
if ((*cit)->getLength2D() < M_EPSILON) {
|
|
|
|
|
delete (*cit);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_current_chains_set.push_back(*cit);
|
2011-02-22 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2012-12-28 20:21:05 +00:00
|
|
|
newChains.clear();
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_chains_set.empty()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_set = &_current_chains_set;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
// Internal class
|
|
|
|
|
class PredicateWrapper {
|
|
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
inline PredicateWrapper(BinaryPredicate1D &pred)
|
|
|
|
|
{
|
|
|
|
|
_pred = &pred;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline bool operator()(Interface1D *i1, Interface1D *i2)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (i1 == i2) {
|
2015-10-28 23:09:10 +09:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if ((*_pred)(*i1, *i2) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
throw std::runtime_error("comparison failed");
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return _pred->result;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
private:
|
2012-12-28 20:21:05 +00:00
|
|
|
BinaryPredicate1D *_pred;
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::sort(BinaryPredicate1D &pred)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_current_set) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
PredicateWrapper wrapper(pred);
|
|
|
|
|
try {
|
|
|
|
|
std::sort(_current_set->begin(), _current_set->end(), wrapper);
|
|
|
|
|
}
|
|
|
|
|
catch (std::runtime_error &e) {
|
|
|
|
|
cerr << "Warning: Operator.sort(): " << e.what() << endl;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
static Stroke *createStroke(Interface1D &inter)
|
|
|
|
|
{
|
|
|
|
|
Stroke *stroke = new Stroke;
|
|
|
|
|
stroke->setId(inter.getId());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
float currentCurvilignAbscissa = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
|
|
|
|
|
Interface0DIterator itfirst = it;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Vec2r current(it->getPoint2D());
|
|
|
|
|
Vec2r previous = current;
|
|
|
|
|
SVertex *sv;
|
|
|
|
|
CurvePoint *cp;
|
2020-11-06 17:49:09 +01:00
|
|
|
StrokeVertex *stroke_vertex = nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
bool hasSingularity = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
do {
|
|
|
|
|
cp = dynamic_cast<CurvePoint *>(&(*it));
|
|
|
|
|
if (!cp) {
|
|
|
|
|
sv = dynamic_cast<SVertex *>(&(*it));
|
|
|
|
|
if (!sv) {
|
|
|
|
|
cerr << "Warning: unexpected Vertex type" << endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
stroke_vertex = new StrokeVertex(sv);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stroke_vertex = new StrokeVertex(cp);
|
|
|
|
|
}
|
|
|
|
|
current = stroke_vertex->getPoint2D();
|
|
|
|
|
Vec2r vec_tmp(current - previous);
|
|
|
|
|
real dist = vec_tmp.norm();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (dist < 1.0e-6) {
|
2012-12-28 20:21:05 +00:00
|
|
|
hasSingularity = true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
currentCurvilignAbscissa += dist;
|
|
|
|
|
stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa);
|
|
|
|
|
stroke->push_back(stroke_vertex);
|
|
|
|
|
previous = current;
|
|
|
|
|
++it;
|
2020-11-06 12:30:59 +11:00
|
|
|
} while (!ELEM(it, itend, itfirst));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (it == itfirst) {
|
|
|
|
|
// Add last vertex:
|
|
|
|
|
cp = dynamic_cast<CurvePoint *>(&(*it));
|
|
|
|
|
if (!cp) {
|
|
|
|
|
sv = dynamic_cast<SVertex *>(&(*it));
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!sv) {
|
2012-12-28 20:21:05 +00:00
|
|
|
cerr << "Warning: unexpected Vertex type" << endl;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-28 20:21:05 +00:00
|
|
|
stroke_vertex = new StrokeVertex(sv);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stroke_vertex = new StrokeVertex(cp);
|
|
|
|
|
}
|
|
|
|
|
current = stroke_vertex->getPoint2D();
|
|
|
|
|
Vec2r vec_tmp(current - previous);
|
|
|
|
|
real dist = vec_tmp.norm();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (dist < 1.0e-6) {
|
2012-12-28 20:21:05 +00:00
|
|
|
hasSingularity = true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
currentCurvilignAbscissa += dist;
|
|
|
|
|
stroke_vertex->setCurvilinearAbscissa(currentCurvilignAbscissa);
|
|
|
|
|
stroke->push_back(stroke_vertex);
|
|
|
|
|
}
|
|
|
|
|
// Discard the stroke if the number of stroke vertices is less than two
|
|
|
|
|
if (stroke->strokeVerticesSize() < 2) {
|
|
|
|
|
delete stroke;
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
stroke->setLength(currentCurvilignAbscissa);
|
|
|
|
|
if (hasSingularity) {
|
|
|
|
|
// Try to address singular points such that the distance between two subsequent vertices
|
|
|
|
|
// are smaller than epsilon.
|
2014-05-25 16:16:00 +09:00
|
|
|
StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin();
|
|
|
|
|
StrokeInternal::StrokeVertexIterator vnext = v;
|
2012-12-28 20:21:05 +00:00
|
|
|
++vnext;
|
2014-05-25 16:16:00 +09:00
|
|
|
Vec2r next((*v).getPoint());
|
2012-12-28 20:21:05 +00:00
|
|
|
while (!vnext.isEnd()) {
|
|
|
|
|
current = next;
|
2014-05-25 16:16:00 +09:00
|
|
|
next = (*vnext).getPoint();
|
2012-12-28 20:21:05 +00:00
|
|
|
if ((next - current).norm() < 1.0e-6) {
|
2014-05-25 16:16:00 +09:00
|
|
|
StrokeInternal::StrokeVertexIterator vprevious = v;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!vprevious.isBegin()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
--vprevious;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-16 22:39:39 +00:00
|
|
|
// collect a set of overlapping vertices
|
2014-05-25 16:16:00 +09:00
|
|
|
std::vector<StrokeVertex *> overlapping_vertices;
|
2013-03-16 22:39:39 +00:00
|
|
|
overlapping_vertices.push_back(&(*v));
|
2012-12-28 20:21:05 +00:00
|
|
|
do {
|
|
|
|
|
overlapping_vertices.push_back(&(*vnext));
|
|
|
|
|
current = next;
|
|
|
|
|
++v;
|
|
|
|
|
++vnext;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (vnext.isEnd()) {
|
2012-12-28 20:21:05 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2014-05-25 16:16:00 +09:00
|
|
|
next = (*vnext).getPoint();
|
2012-12-28 20:21:05 +00:00
|
|
|
} while ((next - current).norm() < 1.0e-6);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Vec2r target;
|
|
|
|
|
bool reverse;
|
|
|
|
|
if (!vnext.isEnd()) {
|
2014-05-25 16:16:00 +09:00
|
|
|
target = (*vnext).getPoint();
|
2012-12-28 20:21:05 +00:00
|
|
|
reverse = false;
|
|
|
|
|
}
|
|
|
|
|
else if (!vprevious.isBegin()) {
|
2014-05-25 16:16:00 +09:00
|
|
|
target = (*vprevious).getPoint();
|
2012-12-28 20:21:05 +00:00
|
|
|
reverse = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Discard the stroke because all stroke vertices are overlapping
|
|
|
|
|
delete stroke;
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2014-05-25 16:16:00 +09:00
|
|
|
current = overlapping_vertices.front()->getPoint();
|
2012-12-28 20:21:05 +00:00
|
|
|
Vec2r dir(target - current);
|
|
|
|
|
real dist = dir.norm();
|
|
|
|
|
real len = 1.0e-3; // default offset length
|
|
|
|
|
int nvert = overlapping_vertices.size();
|
|
|
|
|
if (dist < len * nvert) {
|
2013-03-16 22:39:39 +00:00
|
|
|
len = dist / nvert;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
dir.normalize();
|
|
|
|
|
Vec2r offset(dir * len);
|
|
|
|
|
// add the offset to the overlapping vertices
|
|
|
|
|
StrokeVertex *sv;
|
2014-05-25 16:16:00 +09:00
|
|
|
std::vector<StrokeVertex *>::iterator it = overlapping_vertices.begin();
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!reverse) {
|
2014-05-26 10:53:42 +09:00
|
|
|
for (int n = 0; n < nvert; n++) {
|
2014-05-25 16:16:00 +09:00
|
|
|
sv = (*it);
|
2014-05-26 10:53:42 +09:00
|
|
|
sv->setPoint(sv->getPoint() + offset * (n + 1));
|
2013-03-16 22:39:39 +00:00
|
|
|
++it;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-05-26 10:53:42 +09:00
|
|
|
for (int n = 0; n < nvert; n++) {
|
2014-05-25 16:16:00 +09:00
|
|
|
sv = (*it);
|
2014-05-26 10:53:42 +09:00
|
|
|
sv->setPoint(sv->getPoint() + offset * (nvert - n));
|
2013-03-16 22:39:39 +00:00
|
|
|
++it;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (vnext.isEnd()) {
|
2013-03-16 22:39:39 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
++v;
|
|
|
|
|
++vnext;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
// Check if the stroke no longer contains singular points
|
|
|
|
|
Interface0DIterator v = stroke->verticesBegin();
|
|
|
|
|
Interface0DIterator vnext = v;
|
|
|
|
|
++vnext;
|
|
|
|
|
Vec2r next((*v).getPoint2D());
|
|
|
|
|
bool warning = false;
|
|
|
|
|
while (!vnext.isEnd()) {
|
|
|
|
|
current = next;
|
|
|
|
|
next = (*vnext).getPoint2D();
|
|
|
|
|
if ((next - current).norm() < 1.0e-6) {
|
|
|
|
|
warning = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++v;
|
|
|
|
|
++vnext;
|
|
|
|
|
}
|
2013-01-03 23:27:20 +00:00
|
|
|
if (warning && G.debug & G_DEBUG_FREESTYLE) {
|
2012-12-28 20:21:05 +00:00
|
|
|
printf("Warning: stroke contains singular points.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stroke;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
inline int applyShading(Stroke &stroke, vector<StrokeShader *> &shaders)
|
|
|
|
|
{
|
|
|
|
|
for (vector<StrokeShader *>::iterator it = shaders.begin(); it != shaders.end(); ++it) {
|
|
|
|
|
if ((*it)->shade(stroke) < 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
Made changes to the C++ API in order to allow for proper error
propagation up to the toplevel error handler in BPY_txt_do_python_Text().
Before these changes were made, the operator() methods of predicates
and functions, for example, returned a value of various types such as
bool, double and Vec2f. These returned values were not capable to
represent an error state in many cases.
Now the operator() methods always return 0 on normal exit and -1 on
error. The original returned values are stored in the "result" member
variables of the predicate/function classes.
This means that if we have a code fragment like below:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter)) {
/* do something */
}
then we have to rewrite it as follows:
UnaryPredicate1D& pred;
Interface1D& inter;
if (pred(inter) < 0)
return -1; /* an error in pred() is propagated */
if (pred.result) {
/* do something */
}
Suppose that pred is a user-defined predicate in Python, i.e. the predicate
is likely error-prone (especially when debugging the predicate). The first
code fragment shown above prevents the proper error propagation because
the boolean return value of UnaryPredicate1D::operator() cannot inform the
occurrence of an error to the caller; the second code fragment can.
In addition to the operator() methods of predicates and functions, similar
improvements have been made to all other C++ API functions and methods that
are involved in the execution of user-defined Python code snippets. Changes
in the signatures of functions and methods are summarized as follows (note
that all subclasses of listed classes are also subject to the changes).
Old signatures:
virtual void Iterator::increment();
virtual void Iterator::decrement();
virtual void ChainingIterator::init();
virtual ViewEdge * ChainingIterator::traverse(const AdjacencyIterator &it);
static void Operators::select(UnaryPredicate1D& pred);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static void Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static void Operators::bidirectionalChain(ChainingIterator& it);
static void Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static void Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static void Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static void Operators::sort(BinaryPredicate1D& pred);
static void Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual bool UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual bool BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual bool UnaryPredicate1D::operator()(Interface1D& inter);
virtual bool BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual void StrokeShader::shade(Stroke& ioStroke) const;
virtual T UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual T UnaryFunction1D::operator()(Interface1D& inter);
New signatures:
virtual int Iterator::increment();
virtual int Iterator::decrement();
virtual int ChainingIterator::init();
virtual int ChainingIterator::traverse(const AdjacencyIterator &it);
static int Operators::select(UnaryPredicate1D& pred);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred, UnaryFunction1D_void& modifier);
static int Operators::chain(ViewEdgeInternal::ViewEdgeIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it,
UnaryPredicate1D& pred);
static int Operators::bidirectionalChain(ChainingIterator& it);
static int Operators::sequentialSplit(UnaryPredicate0D& startingPred,
UnaryPredicate0D& stoppingPred, float sampling = 0);
static int Operators::sequentialSplit(UnaryPredicate0D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate1D& pred, float sampling = 0);
static int Operators::recursiveSplit(UnaryFunction0D<double>& func,
UnaryPredicate0D& pred0d, UnaryPredicate1D& pred, float sampling = 0);
static int Operators::sort(BinaryPredicate1D& pred);
static int Operators::create(UnaryPredicate1D& pred, vector<StrokeShader*> shaders);
virtual int UnaryPredicate0D::operator()(Interface0DIterator& it);
virtual int BinaryPredicate0D::operator()(Interface0D& inter1, Interface0D& inter2);
virtual int UnaryPredicate1D::operator()(Interface1D& inter);
virtual int BinaryPredicate1D::operator()(Interface1D& inter1, Interface1D& inter2);
virtual int StrokeShader::shade(Stroke& ioStroke) const;
virtual int UnaryFunction0D::operator()(Interface0DIterator& iter);
virtual int UnaryFunction1D::operator()(Interface1D& inter);
2009-03-20 22:55:07 +00:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
return 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
int Operators::create(UnaryPredicate1D &pred, vector<StrokeShader *> shaders)
|
|
|
|
|
{
|
2019-04-30 17:50:57 +10:00
|
|
|
// Canvas* canvas = Canvas::getInstance();
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_current_set) {
|
|
|
|
|
cerr << "Warning: current set empty" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
StrokesContainer new_strokes_set;
|
|
|
|
|
for (Operators::I1DContainer::iterator it = _current_set->begin(); it != _current_set->end();
|
2024-01-02 18:12:54 +01:00
|
|
|
++it)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (pred(**it) < 0) {
|
2012-12-28 20:21:05 +00:00
|
|
|
goto error;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
if (!pred.result) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Stroke *stroke = createStroke(**it);
|
|
|
|
|
if (stroke) {
|
|
|
|
|
if (applyShading(*stroke, shaders) < 0) {
|
|
|
|
|
delete stroke;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2019-04-30 17:50:57 +10:00
|
|
|
// canvas->RenderStroke(stroke);
|
2012-12-28 20:21:05 +00:00
|
|
|
new_strokes_set.push_back(stroke);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
_current_strokes_set.push_back(*it);
|
|
|
|
|
}
|
|
|
|
|
new_strokes_set.clear();
|
|
|
|
|
return 0;
|
2011-02-26 22:11:40 +00:00
|
|
|
|
|
|
|
|
error:
|
2012-12-28 20:21:05 +00:00
|
|
|
for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
delete (*it);
|
|
|
|
|
}
|
|
|
|
|
new_strokes_set.clear();
|
|
|
|
|
return -1;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-28 11:05:19 +09:00
|
|
|
void Operators::reset(bool removeStrokes)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
|
|
|
|
ViewMap *vm = ViewMap::getInstance();
|
|
|
|
|
if (!vm) {
|
|
|
|
|
cerr << "Error: no ViewMap computed yet" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_current_view_edges_set.clear();
|
|
|
|
|
for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end();
|
2019-05-31 22:51:19 +10:00
|
|
|
++it)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
delete *it;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_chains_set.clear();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewMap::viewedges_container &vedges = vm->ViewEdges();
|
|
|
|
|
ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end();
|
|
|
|
|
for (; ve != veend; ++ve) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if ((*ve)->getLength2D() < M_EPSILON) {
|
2012-12-28 20:21:05 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_current_view_edges_set.push_back(*ve);
|
|
|
|
|
}
|
|
|
|
|
_current_set = &_current_view_edges_set;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (removeStrokes) {
|
2014-09-28 11:05:19 +09:00
|
|
|
_current_strokes_set.clear();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|