2012-12-28 20:21:05 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#ifndef __FREESTYLE_PREDICATES_0D_H__
|
|
|
|
|
#define __FREESTYLE_PREDICATES_0D_H__
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
/** \file blender/freestyle/intern/stroke/Predicates0D.h
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class gathering stroke creation algorithms
|
|
|
|
|
* \author Stephane Grabli
|
|
|
|
|
* \author Emmanuel Turquin
|
|
|
|
|
* \date 01/07/2003
|
|
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#include "../view_map/Functions0D.h"
|
2008-07-31 08:50:12 +00:00
|
|
|
|
2013-05-13 22:58:27 +00:00
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
//
|
|
|
|
|
// UnaryPredicate0D (base class for predicates in 0D)
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
/*! Base class for Unary Predicates that work on Interface0DIterator.
|
|
|
|
|
* A UnaryPredicate0D is a functor that evaluates a condition on a Interface0DIterator and returns
|
|
|
|
|
* true or false depending on whether this condition is satisfied or not.
|
2008-04-30 15:41:54 +00:00
|
|
|
* The UnaryPredicate0D is used by calling its () operator.
|
|
|
|
|
* Any inherited class must overload the () operator.
|
|
|
|
|
*/
|
|
|
|
|
class UnaryPredicate0D
|
|
|
|
|
{
|
|
|
|
|
public:
|
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
|
|
|
bool result;
|
2014-04-17 12:37:08 +09:00
|
|
|
void *py_up0D;
|
2008-07-31 08:50:12 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
/*! Default constructor. */
|
|
|
|
|
UnaryPredicate0D()
|
|
|
|
|
{
|
|
|
|
|
py_up0D = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Destructor. */
|
|
|
|
|
virtual ~UnaryPredicate0D() {}
|
|
|
|
|
|
|
|
|
|
/*! Returns the string of the name of the UnaryPredicate0D. */
|
|
|
|
|
virtual string getName() const
|
|
|
|
|
{
|
|
|
|
|
return "UnaryPredicate0D";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! The () operator. Must be overload by inherited classes.
|
|
|
|
|
* \param it
|
|
|
|
|
* The Interface0DIterator pointing onto the Interface0D at which we wish to evaluate the predicate.
|
|
|
|
|
* \return true if the condition is satisfied, false otherwise.
|
|
|
|
|
*/
|
2014-04-17 12:37:08 +09:00
|
|
|
virtual int operator()(Interface0DIterator& it);
|
2013-05-13 22:58:27 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate0D")
|
|
|
|
|
#endif
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// BinaryPredicate0D (base class for predicates in 0D)
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
/*! Base class for Binary Predicates working on Interface0D.
|
2012-12-28 20:21:05 +00:00
|
|
|
* A BinaryPredicate0D is typically an ordering relation between two Interface0D.
|
|
|
|
|
* It evaluates a relation between 2 Interface0D and returns true or false.
|
2008-04-30 15:41:54 +00:00
|
|
|
* It is used by calling the () operator.
|
|
|
|
|
*/
|
|
|
|
|
class BinaryPredicate0D
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
bool result;
|
2014-04-17 12:37:08 +09:00
|
|
|
void *py_bp0D;
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
/*! Default constructor. */
|
|
|
|
|
BinaryPredicate0D()
|
|
|
|
|
{
|
|
|
|
|
py_bp0D = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Destructor. */
|
|
|
|
|
virtual ~BinaryPredicate0D() {}
|
|
|
|
|
|
|
|
|
|
/*! Returns the string of the name of the binary predicate. */
|
|
|
|
|
virtual string getName() const
|
|
|
|
|
{
|
|
|
|
|
return "BinaryPredicate0D";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! The () operator. Must be overload by inherited classes.
|
|
|
|
|
* It evaluates a relation between 2 Interface0D.
|
|
|
|
|
* \param inter1
|
|
|
|
|
* The first Interface0D.
|
|
|
|
|
* \param inter2
|
|
|
|
|
* The second Interface0D.
|
|
|
|
|
* \return true or false.
|
|
|
|
|
*/
|
2014-04-17 12:37:08 +09:00
|
|
|
virtual int operator()(Interface0D& inter1, Interface0D& inter2);
|
2013-05-13 22:58:27 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate0D")
|
|
|
|
|
#endif
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Predicates definitions
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
namespace Predicates0D {
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// TrueUP0D
|
|
|
|
|
/*! Returns true any time */
|
|
|
|
|
class TrueUP0D : public UnaryPredicate0D
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*! Default constructor. */
|
|
|
|
|
TrueUP0D() {}
|
|
|
|
|
|
|
|
|
|
/*! Returns the string "TrueUP0D"*/
|
|
|
|
|
string getName() const
|
|
|
|
|
{
|
|
|
|
|
return "TrueUP0D";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! The () operator. */
|
|
|
|
|
int operator()(Interface0DIterator&)
|
|
|
|
|
{
|
|
|
|
|
result = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// FalseUP0D
|
|
|
|
|
/*! Returns false any time */
|
|
|
|
|
class FalseUP0D : public UnaryPredicate0D
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*! Default constructor. */
|
|
|
|
|
FalseUP0D() {}
|
|
|
|
|
|
|
|
|
|
/*! Returns the string "FalseUP0D"*/
|
|
|
|
|
string getName() const
|
|
|
|
|
{
|
|
|
|
|
return "FalseUP0D";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! The () operator. */
|
|
|
|
|
int operator()(Interface0DIterator&)
|
|
|
|
|
{
|
|
|
|
|
result = false;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
} // end of namespace Predicates0D
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
#endif // __FREESTYLE_PREDICATES_0D_H__
|