Commit Graph

129 Commits

Author SHA1 Message Date
2d1bc90eed Added Python wrappers for the following Operators static methods:
- getViewEdgeFromIndex()
- getChainFromIndex()
- getStrokeFromIndex()
2010-12-23 09:21:41 +00:00
d8b2d1945a Documentation updates: Added a class hierarchy that shows
inheritance relationships among the classes defined in the
Freestyle module.
2010-08-28 13:52:49 +00:00
f510faed6c Python API documentation updates: a description of class hierarchy
was added to the docstrings of most Python extension types.
2010-08-12 12:17:47 +00:00
a99a466fee * Made the Parameter Editor mode much more functional. Edge selection
criteria, as well as the color/alpha/thickness Along Stroke modifiers
now work.

* Added more curve blend types.  The default is set to "MIX".
2010-07-28 00:43:45 +00:00
1813324544 Added helper functions to the Freestyle module:
* evaluateColorRamp() to evaluate a color ramp at a given point in
the interval 0 to 1.

* evaluateCurveMappingF() to evaluate a curve mapping at a given
point in the interval 0 to 1.
2010-07-26 23:50:32 +00:00
db158b42de Documentation updates: Replaced "string" with "str". 2010-05-28 18:42:11 +00:00
d15f2b562e Fixed the __call__ method of UnaryFunction0DVectorViewShape and
UnaryFunction1DVectorViewShape.  The __call__ method now returns
a list whose elements are either a ViewShape or None.
2010-05-27 21:12:09 +00:00
96e79172a0 Made object names accessible from within style modules.
ViewShape objects in the view map, as well as SShape objects
that can be retrieved with ViewShape::sshape(), now have a
getName() method that returns the name of the object from
which each shape is created.  For instance, visible feature
edges of specific mesh objects (e.g., Cube.001 and Cube.002)
can be selected using custom predicate ObjectNamesUP1D as
follows:

class ObjectNamesUP1D(UnaryPredicate1D):
    def __init__(self, names):
        UnaryPredicate1D.__init__(self)
        self._names = names
    def getName(self):
        return "ObjectNamesUP1D"
    def __call__(self, viewEdge):
        return viewEdge.viewShape().getName() in self._names

upred = AndUP1D(QuantitativeInvisibilityUP1D(0),
                ObjectNamesUP1D(["Cube.001", "Cube.002"]))
Operators.select(upred)
2010-05-23 17:11:44 +00:00
2212564f18 Fixed invalid use of PyUnicode_FromFormat() where PyUnicode_FromString()
should have been used.
2010-05-23 12:10:31 +00:00
02a4dbeff0 Docstring update for Nature::MATERIAL_BOUNDARY (cf. revision 28919). 2010-05-23 00:09:56 +00:00
b85985535d New option for detecting feature edges at material boundaries.
A checkbox "Material Boundaries" has been added to the Freestyle
options in the Layers tab of the Render buttons.  By enabling the
option, any edge between two faces with different materials is
detected as a feature edge.  In style modules, edges at material
boundaries can be tested with pyNatureUP1D(Nature.MATERIAL_BOUNDARY).
2010-05-22 22:21:15 +00:00
f76c3aa376 * Fix for a crash in StrokeVertexIterator::getObject().
* Minor docstring fixes.
2010-05-21 21:27:32 +00:00
bc993fcd55 Minor docstring fixes. 2010-05-14 21:29:13 +00:00
867419b290 Removed partial implementations of the __copy__ method of some Python
extension classes.  Copy constructors should be used to duplicate
objects.
2010-05-09 18:21:36 +00:00
2385c51360 Renamed FrsCurve, FrsNoise and FrsMaterial Python extension types
to those names without the "Frs" prefix.  These types are part of
the Freestyle module, so that there is no need to make their names
globally unique.
2010-05-09 18:05:33 +00:00
dfe2f8dc03 Merged changes in the trunk up to revision 28247. 2010-04-18 02:03:19 +00:00
d7e08f2d33 Major documentation updates. The original Freestyle API reference
(http://freestyle.sourceforge.net/doc/html/index.html) has been
incorporated into the Blender/Freestyle Python API implementation
in the form of Sphinx-based embedded docstrings.  Some C++-specific
descriptions of classes and functions were revised so that they are
suitable for Python programmers.  Missing docstrings were filled,
and sparse descriptions were extended.  By means of the new
documentation system for Blender, an up-to-date Freestyle Python
API reference will be part of the Blender 2.5 documentation.
2010-04-17 23:47:47 +00:00
7a4a3ec626 Removed duplicated definitions of verticesBegin(), verticesEnd(),
pointsBegin(), and pointsEnd().  All these methods are inherited
from the Interface1D class.
2010-04-10 14:46:02 +00:00
67ca348be3 Missing update in the last commit. 2010-04-08 01:42:39 +00:00
d131a8db48 Replaced PyObject_HEAD_INIT(NULL) with PyVarObject_HEAD_INIT(NULL, 0)
in the definitions of Python wrappers.
2010-04-08 01:13:54 +00:00
7ed7524c91 Got rid of a number of compiler warnings with regard to redefinitions
of _POSIX_C_SOURCE and _XOPEN_SOURCE.  There are no functional changes.
Tested with GCC 4.4.1 on Ubuntu 9.10 (karmic).
2010-04-07 23:28:29 +00:00
128f9730f2 Added Freestyle.getCurrentScene() to give access to the current scene
from within style modules.  Calling this function is only valid within
style modules.  Calling it from the Python Interactive Console results
in an error as follows:

>>> import Freestyle
>>> Freestyle.getCurrentScene()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: current scene not available
>>>
2009-12-06 22:01:04 +00:00
6d88769cc2 Improved error checks in the Freestyle.Nature class. 2009-10-18 17:57:33 +00:00
211e7be580 Fixed a bug in the Freestyle.Nature class that instances are always
considered True even if their integer values are 0.
2009-10-18 17:28:15 +00:00
94711098e4 * Fixed compiler warnings concerning the lack of a newline at the
end of a file.

* Fixed compiler warnings due to an invalid argument to PyList_New().
NULL was used instead of 0 to create an empty list.
2009-10-15 19:38:45 +00:00
069d21dddf Made the Freestyle Python API compatible with Python 3. 2009-09-27 00:32:20 +00:00
a1d560fc89 Fixed refcount issues in the Python API. 2009-08-08 16:28:10 +00:00
56c76ba21c Added missing #include <typeinfo> to BPy_Convert.h. 2009-08-08 11:18:40 +00:00
ff110c17f7 Fixed argument checking in __init__ methods of Interface1D, Predicates,
Functions, and StrokeShader types.
2009-08-03 15:19:51 +00:00
d4ff63fe20 * Fixed uninitialized pointers in "__init__" methods of UnaryFunction1D types.
There was a known issue for a long time that we occasionally encountered
strange "TypeError: an integer is required" and "RuntimeWarning: tp_compare
didn't return -1 or -2 for exception", as shown in the following unit test
log.  The source of the former error was PyInt_AsLong(obj) being used by
IntegrationType_from_BPy_IntegrationType(obj), where "obj" was not properly
initialized in "__init__" before the converter was called.  The TypeError
was left unattended for a while and showed up when a comparison occurred
and the TypeError was detected, which resulted in the latter warning.

> runTest (__main__.UnaryFunction1DDoubleInitTestCase) ...
> .\blender:211: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
> ERROR
> 
> ======================================================================
> ERROR: runTest (__main__.UnaryFunction1DDoubleInitTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "init_tests.py", line 211, in runTest
> TypeError: an integer is required
> 
> ----------------------------------------------------------------------

* Also removed unnecessary error messages in "__init__" methods of
UnaryFunction1D types.
2009-08-03 14:38:15 +00:00
e2eb4d567c Fixed the handling of constructor arguments in the following Python
types: Interface0D, SVertex, ViewVertex, StrokeVertex, NonTVertex,
and TVertex.
2009-08-02 22:39:21 +00:00
74027eafcb SWIG/directors dependency removal (cont'd)
Removed all castToSomething() methods from Interface0D's subclasses.
These methods are useless, because introspection-based automatic type
conversion takes place whenever it is applicable.

If you need to rewrite old style modules that rely on the cast methods,
apply the following rewriting rules:

- SVertex.castToSVertex()
- TVertex.castToViewVertex()
- TVertex.castToTVertex()
- NonTVertex.castToViewVertex()
- NonTVertex.castToNonTVertex()

  These 5 methods return an object itself, so just removing a method
  call will suffice.  If you need to handle objects in a different way
  depending on their types, then you can use Python's type checking
  idioms such as "type(obj) is T" and "isinstance(obj, T)".  Example:

    [Original]
    v = it.getObject()
    # try to convert v into a TVertex object
    vertex = v.castToTVertex()
    if vertex != None:
	... # do something on the TVertex object
    # try to convert v into a NonTVertex object
    vertex = v.castToNonTVertex()
    if vertex != None:
	... # do something on the NonTVertex object

    [Rewritten]
    vertex = it.getObject()
    if type(vertex) is TVertex:
	... # do something on the TVertex object
    elif type(vertex) is NonTVertex:
	... # do something on the NonTVertex object

- SVertex.castToViewVertex()
- SVertex.castToTVertex()
- SVertex.castToNonTVertex()

  Use SVertex.viewvertex() instead.  You don't need to care about
  which cast method is appropriate.  SVertex.viewvertex() does, if
  necessary, introspection-based automatic type conversion for you.

- NonTVertex.castToSVertex()

  Use NonTVertex.svertex() instead.

- CurvePoint.castToSVertex()

  Let cp be a CurvePoint object, then this method can be expressed as
  follows:

    if cp.t2d() == 0.0:
	return cp.A() # returns an SVertex
    elif cp.t2d() == 1.0:
	return cp.B() # returns an SVertex
    return None

- CurvePoint.castToViewVertex()
- CurvePoint.castToTVertex()
- CurvePoint.castToNonVertex()

  Similarly, these 3 methods can be expressed as follows:

    if cp.t2d() == 0.0:
	return cp.A().viewvertex()
    elif cp.t2d() == 1.0:
	return cp.B().viewvertex()
    return None
2009-08-02 19:36:18 +00:00
0ea01da4ba Fixed the argument parsing in CurvePoint.__init__(). 2009-08-02 18:25:26 +00:00
cc19c8e270 * Fixed __init__() method so as to corecttly handle arguments.
* Fixed refcount issues in diffuse(), specular(), ambient() and
emission() methods.  Also changed the type of their returned values
from list to tuple.
2009-08-02 17:38:51 +00:00
acf97994bc SWIG/directors dependency removal (cont'd)
* Added to python/BPy_Convert.{cpp,h} 4 utility converters below for
better introspection-based automatic type conversion.

  PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D );
  PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D );
  PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe );
  PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );

There are 4 corresponding converters without the "Any_" prefix.  All
calls of them in the code base were replaced with these new converters
so that the introspection-based automatic conversion would take place
universally.

* python/BPy_Convert.{cpp,h}: Those C++ to Python converters having
had a "_ptr" suffix were renamed to a name without the suffix, and
their arguments were changed so as to take a reference (e.g.,
ViewVertex&) instead of a pointer (e.g., ViewVertex *).  The changed
converters and their new function prototypes are listed below.  These
converters now return a Python wrapper object that retains the passed
reference, instead of retaining a newly created C++ object by the
converters.

  // Interface0D converters
  PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
  PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp );
  PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv );
  PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
  PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
  PyObject * BPy_TVertex_from_TVertex( TVertex& tv );
  PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv );
  // Interface1D converters
  PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
  PyObject * BPy_Chain_from_Chain( Chain& c );
  PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
  PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes );
  PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes );
  PyObject * BPy_Stroke_from_Stroke( Stroke& s );
  PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve );
  PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve );
  // some other converters
  PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs );
  PyObject * BPy_SShape_from_SShape( SShape& ss );
  PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
  PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa );

* Added a "borrowed" flag to the definitions of Python types being
used to wrap C++ components of Freestyle's internal data structures.
The flag indicates whether or not a Python wrapper object has a
reference to a C++ object that comprises the internal data structures.
The deallocation routines of the Python types check this flag and
release a wrapped C++ object only when it is not part of the internal
data structures.  The following files were modified:

  python/BPy_FrsMaterial.{cpp,h}
  python/BPy_Interface0D.{cpp,h}
  python/BPy_Interface1D.{cpp,h}
  python/BPy_SShape.{cpp,h}
  python/BPy_StrokeAttribute.{cpp,h}
  python/BPy_ViewShape.{cpp,h}
  python/Interface0D/BPy_CurvePoint.cpp
  python/Interface0D/BPy_SVertex.cpp
  python/Interface0D/BPy_ViewVertex.cpp
  python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
  python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
  python/Interface0D/ViewVertex/BPy_TVertex.cpp
  python/Interface1D/BPy_FEdge.cpp
  python/Interface1D/BPy_FrsCurve.cpp
  python/Interface1D/BPy_Stroke.cpp
  python/Interface1D/BPy_ViewEdge.cpp
  python/Interface1D/Curve/BPy_Chain.cpp
  python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
  python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp

* view_map/Interface[01]D.h, python/BPy_Interface[01]D.cpp: Removed
from the Interface0D and Interface1D C++ classes a back pointer to a
Python wrapper object and all "director" calls.  These classes (and
their subclasses) are used to build Freestyle's main data structures
(such as a view map and strokes) and their class hierarchy is static.
Python wrappers of these C++ classes are only used to access the data
structures from the Python layer, and not intended to extend the data
structures by subclassing the Python wrappers.  Without the necessity
of subclassing in the Python layer, the back pointer to a wrapping
Python object and "director" calls would be useless (actually they
were not used at all), so they were all removed.

* python/Director.{cpp,h}: Removed the definitions of directors that
were no longer used.

* stroke/Stroke.{cpp,h}: Removed an (unused) back pointer to a Python
wrapper object.

* python/BPy_ViewMap.cpp: Fixed a possible null pointer reference.

* python/Interface1D/BPy_FEdge.cpp: Fixed parameter checking in
FEdge___init__().
2009-08-02 16:23:18 +00:00
6d1ad351f3 Changed the type of returned value of BPy_directedViewEdge_from_directedViewEdge()
from list to tuple.
2009-08-01 18:03:43 +00:00
2c829e9bd3 Disabled the Python wrapper of ViewVertex::edgesEnd(), since the
method returns a non-functional orientedViewEdgeIterator instance.
The iteration from the end to the beginning of the sequence relies
on orientedViewEdgeIterator::decrement() which is not actually
implemented in the C++ class.  As a quick fix, the edgesEnd method
now raises a NotImplementedError.
2009-07-31 23:49:12 +00:00
631df8cc01 Added boundary checking to Iterator::increment() and Iterator::decrement()
to avoid an immediate crash.  Now these methods raise a RuntimeError when
the iteration is already at the end.
2009-07-31 23:16:38 +00:00
ba9943e4a7 * Implemented Python's iterator protocol in Interface0DIterator and
orientedViewEdgeIterator.

* Simplified Python-related error handling in C++ class definitions.
The definitions of the following C++ methods were simplified and most
code segments using the C/Python API were moved to Director.cpp.

  ChainingIterator::init()
  ChainingIterator::traverse()
  UnaryPredicate0D::operator()()
  UnaryPredicate1D::operator()()
  BinaryPredicate0D::operator()()
  BinaryPredicate1D::operator()()
  UnaryFunction0D::operator()()
  UnaryFunction1D::operator()()
  StrokeShader.shade()

* Moved part of the introspection-based automatic type conversion code
from BPy_Interface0DIterator.cpp and Director.cpp to BPy_Convert.cpp
for the sake of better code organization.

* Fixed an uninitialized member in StrokeVertexIterator___init__().
2009-07-31 22:13:48 +00:00
6134a41270 Fixed typoes in error messages. 2009-07-31 21:44:59 +00:00
d62f844b12 Fixed typoes in error messages. 2009-07-31 21:44:02 +00:00
4e78dff629 Added Python error handling to StrokeShader::shade(). Also made
a measure to avoid an infinite loop due to non-proper overriding
of the shade method.
2009-07-31 21:03:22 +00:00
3771d648d0 Added minor changes. 2009-07-29 18:49:03 +00:00
7600037924 Added changes to the AdjacencyIterator type to support Python's
iterator protocol.  Now the following code in the conventional
SWIG-based syntax:

    it = AdjacencyIterator(iter)
    while not it.isEnd():
        ve = it.getObject()
        ...
        it.increment()

can be written using the iterator protocol as follows:

    for ve in AdjacencyIterator(iter):
        ...
2009-07-29 00:18:13 +00:00
8eb1064f41 Implemented a measure to avoid an infinite loop triggered when
ChainingIterator::init() and ChainingIterator::traverse() were
not properly overloaded in a subclass.
2009-07-29 00:11:41 +00:00
bf0365ceb0 * BPy_IntegrationType.cpp: Added a Python wrapper of integrate function.
* Fixed uninitialized fields in the "__init__" methods of UnaryFunction0D
types.  Also added missing argument validation codes to some of the types,
and removed redundant validation error messages.
2009-07-28 00:29:30 +00:00
fe5b6a556c * Fixed compiler errors in UnaryFunction0DVectorViewShape::__call__()
and UnaryFunction1DVectorViewShape::__call__().

* Added a Python wrapper of ViewEdge::qi().
2009-07-27 19:34:52 +00:00
52f639277b Second attempt to fix a null pointer reference in deallocators of
built-in types (the first was in revision 21877).  When an exception
has raised within from the __init__ method of a user-defined class
derived from a built-in type (e.g., UnaryPredicate0D and
BinaryPredicate1D), some member variables of the base type are
left uninitialized, leading to a null pointer reference in the
"__dealloc__" function in the base type.  To avoid this, pointer
checking was added in the deallocators of those built-in types that
can be used to define a subclass by a user.
2009-07-26 20:20:25 +00:00
69853d3e40 Reverted the change in revision 21877 in Interface0D___dealloc__(). 2009-07-26 17:29:25 +00:00
730fb1021c Made predicate and function types callable in the sense that
callable(I, T) returns True when I is an object of a type T or
of a subtype of T.  Also implemented a measure to avoid an
infinite loop when user-defined predicate and function classes
do not properly overload the __call__ method (including the
cases of directly instantiating the base classes such as
UnaryPredicate0D and BinaryPredicate1D).
2009-07-26 16:15:28 +00:00