diff options
Diffstat (limited to 'source/blender/freestyle')
29 files changed, 235 insertions, 186 deletions
diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index c61f72295d2..81034c1502c 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -204,7 +204,6 @@ void Controller::setPassZ(float *buf, int width, int height) void Controller::setContext(bContext *C) { PythonInterpreter *py_inter = dynamic_cast<PythonInterpreter*>(_inter); - assert(py_inter != 0); py_inter->setContext(C); } diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index a1368f1ea21..070bee047a9 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -261,7 +261,7 @@ public: /*! inserts a convex polygon occluder * This method is quite coarse insofar as it adds all cells intersecting the polygon bounding box * convex_poly - * The list of 3D points constituing a convex polygon + * The list of 3D points constituting a convex polygon */ void insertOccluder(Polygon3r *convex_poly); diff --git a/source/blender/freestyle/intern/geometry/Noise.cpp b/source/blender/freestyle/intern/geometry/Noise.cpp index b21ded9dd95..8ec56e84f95 100644 --- a/source/blender/freestyle/intern/geometry/Noise.cpp +++ b/source/blender/freestyle/intern/geometry/Noise.cpp @@ -62,10 +62,10 @@ namespace Freestyle { #define SETUP(i, b0, b1, r0, r1) \ { \ (t) = (i) + (N); \ - (b0) = ((int)(t)) & BM; \ - (b1) = ((b0) + 1) & BM; \ - (r0) = (t) - (int)(t); \ + (r0) = modff((t), &(u)); \ (r1) = (r0) - 1.0; \ + (b0) = ((int)(u)) & BM; \ + (b1) = ((b0) + 1) & BM; \ } (void)0 static void normalize2(float v[2]) diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 3b1232c51af..56c096a1eae 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -512,93 +512,100 @@ Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj) return static_cast<Nature::EdgeNature>(PyLong_AsLong(obj)); } -Vec2f *Vec2f_ptr_from_PyObject(PyObject *obj) -{ - Vec2f *v; - if ((v = Vec2f_ptr_from_Vector(obj))) - return v; - if ((v = Vec2f_ptr_from_PyList(obj))) - return v; - if ((v = Vec2f_ptr_from_PyTuple(obj))) - return v; - return NULL; +bool Vec2f_ptr_from_PyObject(PyObject *obj, Vec2f *vec) +{ + if (Vec2f_ptr_from_Vector(obj, vec)) + return true; + if (Vec2f_ptr_from_PyList(obj, vec)) + return true; + if (Vec2f_ptr_from_PyTuple(obj, vec)) + return true; + return false; } -Vec3f *Vec3f_ptr_from_PyObject(PyObject *obj) +bool Vec3f_ptr_from_PyObject(PyObject *obj, Vec3f *vec) { - Vec3f *v; - if ((v = Vec3f_ptr_from_Vector(obj))) - return v; - if ((v = Vec3f_ptr_from_Color(obj))) - return v; - if ((v = Vec3f_ptr_from_PyList(obj))) - return v; - if ((v = Vec3f_ptr_from_PyTuple(obj))) - return v; - return NULL; + if (Vec3f_ptr_from_Vector(obj, vec)) + return true; + if (Vec3f_ptr_from_Color(obj, vec)) + return true; + if (Vec3f_ptr_from_PyList(obj, vec)) + return true; + if (Vec3f_ptr_from_PyTuple(obj, vec)) + return true; + return false; } -Vec3r *Vec3r_ptr_from_PyObject(PyObject *obj) +bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r *vec) { - Vec3r *v; - if ((v = Vec3r_ptr_from_Vector(obj))) - return v; - if ((v = Vec3r_ptr_from_Color(obj))) - return v; - if ((v = Vec3r_ptr_from_PyList(obj))) - return v; - if ((v = Vec3r_ptr_from_PyTuple(obj))) - return v; - return NULL; + if (Vec3r_ptr_from_Vector(obj, vec)) + return true; + if (Vec3r_ptr_from_Color(obj, vec)) + return true; + if (Vec3r_ptr_from_PyList(obj, vec)) + return true; + if (Vec3r_ptr_from_PyTuple(obj, vec)) + return true; + return false; } -Vec2f *Vec2f_ptr_from_Vector(PyObject *obj) +bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f *vec) { if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) - return NULL; - float x = ((VectorObject *)obj)->vec[0]; - float y = ((VectorObject *)obj)->vec[1]; - return new Vec2f(x, y); + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + return true; } -Vec3f *Vec3f_ptr_from_Vector(PyObject *obj) +bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f *vec) { if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) - return NULL; - float x = ((VectorObject *)obj)->vec[0]; - float y = ((VectorObject *)obj)->vec[1]; - float z = ((VectorObject *)obj)->vec[2]; - return new Vec3f(x, y, z); + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + vec[2] = ((VectorObject *)obj)->vec[2]; + return true; } -Vec3r *Vec3r_ptr_from_Vector(PyObject *obj) +bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r *vec) { if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) - return NULL; - real x = ((VectorObject *)obj)->vec[0]; - real y = ((VectorObject *)obj)->vec[1]; - real z = ((VectorObject *)obj)->vec[2]; - return new Vec3r(x, y, z); + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((VectorObject *)obj)->vec[0]; + vec[1] = ((VectorObject *)obj)->vec[1]; + vec[2] = ((VectorObject *)obj)->vec[2]; + return true; } -Vec3f *Vec3f_ptr_from_Color(PyObject *obj) +bool Vec3f_ptr_from_Color(PyObject *obj, Vec3f *vec) { if (!ColorObject_Check(obj)) - return NULL; - float r = ((ColorObject *)obj)->col[0]; - float g = ((ColorObject *)obj)->col[1]; - float b = ((ColorObject *)obj)->col[2]; - return new Vec3f(r, g, b); + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((ColorObject *)obj)->col[0]; + vec[1] = ((ColorObject *)obj)->col[1]; + vec[2] = ((ColorObject *)obj)->col[2]; + return true; } -Vec3r *Vec3r_ptr_from_Color(PyObject *obj) +bool Vec3r_ptr_from_Color(PyObject *obj, Vec3r *vec) { if (!ColorObject_Check(obj)) - return NULL; - real r = ((ColorObject *)obj)->col[0]; - real g = ((ColorObject *)obj)->col[1]; - real b = ((ColorObject *)obj)->col[2]; - return new Vec3r(r, g, b); + return false; + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return false; + vec[0] = ((ColorObject *)obj)->col[0]; + vec[1] = ((ColorObject *)obj)->col[1]; + vec[2] = ((ColorObject *)obj)->col[2]; + return true; } static int float_array_from_PyList(PyObject *obj, float *v, int n) @@ -613,37 +620,45 @@ static int float_array_from_PyList(PyObject *obj, float *v, int n) return 1; } -Vec2f *Vec2f_ptr_from_PyList(PyObject *obj) +bool Vec2f_ptr_from_PyList(PyObject *obj, Vec2f *vec) { float v[2]; if (!PyList_Check(obj) || PyList_Size(obj) != 2) - return NULL; + return false; if (!float_array_from_PyList(obj, v, 2)) - return NULL; - return new Vec2f(v[0], v[1]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + return true; } -Vec3f *Vec3f_ptr_from_PyList(PyObject *obj) +bool Vec3f_ptr_from_PyList(PyObject *obj, Vec3f *vec) { float v[3]; if (!PyList_Check(obj) || PyList_Size(obj) != 3) - return NULL; + return false; if (!float_array_from_PyList(obj, v, 3)) - return NULL; - return new Vec3f(v[0], v[1], v[2]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } -Vec3r *Vec3r_ptr_from_PyList(PyObject *obj) +bool Vec3r_ptr_from_PyList(PyObject *obj, Vec3r *vec) { float v[3]; if (!PyList_Check(obj) || PyList_Size(obj) != 3) - return NULL; + return false; if (!float_array_from_PyList(obj, v, 3)) - return NULL; - return new Vec3r(v[0], v[1], v[2]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } static int float_array_from_PyTuple(PyObject *obj, float *v, int n) @@ -658,37 +673,45 @@ static int float_array_from_PyTuple(PyObject *obj, float *v, int n) return 1; } -Vec2f *Vec2f_ptr_from_PyTuple(PyObject *obj) +bool Vec2f_ptr_from_PyTuple(PyObject *obj, Vec2f *vec) { float v[2]; if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2) - return NULL; + return false; if (!float_array_from_PyTuple(obj, v, 2)) - return NULL; - return new Vec2f(v[0], v[1]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + return true; } -Vec3f *Vec3f_ptr_from_PyTuple(PyObject *obj) +bool Vec3f_ptr_from_PyTuple(PyObject *obj, Vec3f *vec) { float v[3]; if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3) - return NULL; + return false; if (!float_array_from_PyTuple(obj, v, 3)) - return NULL; - return new Vec3f(v[0], v[1], v[2]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } -Vec3r *Vec3r_ptr_from_PyTuple(PyObject *obj) +bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r *vec) { float v[3]; if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3) - return NULL; + return false; if (!float_array_from_PyTuple(obj, v, 3)) - return NULL; - return new Vec3r(v[0], v[1], v[2]); + return false; + vec[0] = v[0]; + vec[1] = v[1]; + vec[2] = v[2]; + return true; } // helper for argument parsing @@ -696,10 +719,19 @@ Vec3r *Vec3r_ptr_from_PyTuple(PyObject *obj) int float_array_from_PyObject(PyObject *obj, float *v, int n) { if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) { + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return 0; for (int i = 0; i < n; i++) v[i] = ((VectorObject *)obj)->vec[i]; return 1; } + else if (ColorObject_Check(obj) && n == 3) { + if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) + return 0; + for (int i = 0; i < n; i++) + v[i] = ((ColorObject *)obj)->col[i]; + return 1; + } else if (PyList_Check(obj) && PyList_Size(obj) == n) { return float_array_from_PyList(obj, v, n); } diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h index 1df4901757b..a8bc7eaa306 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.h +++ b/source/blender/freestyle/intern/python/BPy_Convert.h @@ -150,20 +150,20 @@ bool bool_from_PyBool(PyObject *b); IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj); Stroke::MediumType MediumType_from_BPy_MediumType(PyObject *obj); Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj); -Vec2f * Vec2f_ptr_from_PyObject(PyObject *obj); -Vec3f * Vec3f_ptr_from_PyObject(PyObject *obj); -Vec3r * Vec3r_ptr_from_PyObject(PyObject *obj); -Vec2f * Vec2f_ptr_from_Vector(PyObject *obj); -Vec3f * Vec3f_ptr_from_Vector(PyObject *obj); -Vec3r * Vec3r_ptr_from_Vector(PyObject *obj); -Vec3f * Vec3f_ptr_from_Color(PyObject *obj); -Vec3r * Vec3r_ptr_from_Color(PyObject *obj); -Vec2f * Vec2f_ptr_from_PyList(PyObject *obj); -Vec3f * Vec3f_ptr_from_PyList(PyObject *obj); -Vec3r * Vec3r_ptr_from_PyList(PyObject *obj); -Vec2f * Vec2f_ptr_from_PyTuple(PyObject *obj); -Vec3f * Vec3f_ptr_from_PyTuple(PyObject *obj); -Vec3r * Vec3r_ptr_from_PyTuple(PyObject *obj); +bool Vec2f_ptr_from_PyObject(PyObject *obj, Vec2f *vec); +bool Vec3f_ptr_from_PyObject(PyObject *obj, Vec3f *vec); +bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r *vec); +bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f *vec); +bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f *vec); +bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r *vec); +bool Vec3f_ptr_from_Color(PyObject *obj, Vec3f *vec); +bool Vec3r_ptr_from_Color(PyObject *obj, Vec3r *vec); +bool Vec2f_ptr_from_PyList(PyObject *obj, Vec2f *vec); +bool Vec3f_ptr_from_PyList(PyObject *obj, Vec3f *vec); +bool Vec3r_ptr_from_PyList(PyObject *obj, Vec3r *vec); +bool Vec2f_ptr_from_PyTuple(PyObject *obj, Vec2f *vec); +bool Vec3f_ptr_from_PyTuple(PyObject *obj, Vec3f *vec); +bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r *vec); int float_array_from_PyObject(PyObject *obj, float *v, int n); diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index 680f399cc77..fb678d7ea66 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -101,8 +101,8 @@ static int ramp_blend_type(const char *type) if (!strcmp(type, "SATURATION")) return MA_RAMP_SAT; if (!strcmp(type, "VALUE")) return MA_RAMP_VAL; if (!strcmp(type, "COLOR")) return MA_RAMP_COLOR; - if (!strcmp(type, "SOFT LIGHT")) return MA_RAMP_SOFT; - if (!strcmp(type, "LINEAR LIGHT")) return MA_RAMP_LINEAR; + if (!strcmp(type, "SOFT_LIGHT")) return MA_RAMP_SOFT; + if (!strcmp(type, "LINEAR_LIGHT")) return MA_RAMP_LINEAR; return -1; } @@ -129,7 +129,6 @@ static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args) PyObject *obj1, *obj2; char *s; int type; - Vec3f *v1 = NULL, *v2 = NULL; float a[3], fac, b[3]; if (!PyArg_ParseTuple(args, "sOfO", &s, &obj1, &fac, &obj2)) @@ -137,32 +136,20 @@ static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args) type = ramp_blend_type(s); if (type < 0) { PyErr_SetString(PyExc_TypeError, "argument 1 is an unknown ramp blend type"); - goto error; + return NULL; } - v1 = Vec3f_ptr_from_PyObject(obj1); - if (!v1) { + if (!float_array_from_PyObject(obj1, a, 3)) { PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a tuple/list of 3 elements or Vector)"); - goto error; + return NULL; } - v2 = Vec3f_ptr_from_PyObject(obj2); - if (!v2) { + if (!float_array_from_PyObject(obj2, b, 3)) { PyErr_SetString(PyExc_TypeError, "argument 4 must be a 3D vector (either a tuple/list of 3 elements or Vector)"); - goto error; + return NULL; } - a[0] = v1->x(); b[0] = v2->x(); - a[1] = v1->y(); b[1] = v2->y(); - a[2] = v1->z(); b[2] = v2->z(); ramp_blend(type, a, fac, b); - delete v1; - delete v2; return Vector_CreatePyObject(a, 3, Py_NEW, NULL); - -error: - if (v1) delete v1; - if (v2) delete v2; - return NULL; } #include "BKE_texture.h" /* do_colorband() */ diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp index abdcbaff6e1..2575b16b27a 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -132,16 +132,15 @@ static PyObject *FrsNoise_turbulence2(BPy_FrsNoise *self, PyObject *args, PyObje PyObject *obj1; float f2, f3; unsigned int i = 4; + Vec2f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) return NULL; - Vec2f *v = Vec2f_ptr_from_PyObject(obj1); - if (!v) { + if (!Vec2f_ptr_from_PyObject(obj1, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - float t = self->n->turbulence2(*v, f2, f3, i); - delete v; + float t = self->n->turbulence2(vec, f2, f3, i); return PyFloat_FromDouble(t); } @@ -167,16 +166,15 @@ static PyObject *FrsNoise_turbulence3(BPy_FrsNoise *self, PyObject *args, PyObje PyObject *obj1; float f2, f3; unsigned int i = 4; + Vec3f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "Off|I", (char **)kwlist, &obj1, &f2, &f3, &i)) return NULL; - Vec3f *v = Vec3f_ptr_from_PyObject(obj1); - if (!v) { + if (!Vec3f_ptr_from_PyObject(obj1, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - float t = self->n->turbulence3(*v, f2, f3, i); - delete v; + float t = self->n->turbulence3(vec, f2, f3, i); return PyFloat_FromDouble(t); } @@ -214,16 +212,15 @@ static PyObject *FrsNoise_smoothNoise2(BPy_FrsNoise *self, PyObject *args, PyObj { static const char *kwlist[] = {"v", NULL}; PyObject *obj; + Vec2f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) return NULL; - Vec2f *v = Vec2f_ptr_from_PyObject(obj); - if (!v) { + if (!Vec2f_ptr_from_PyObject(obj, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - float t = self->n->smoothNoise2(*v); - delete v; + float t = self->n->smoothNoise2(vec); return PyFloat_FromDouble(t); } @@ -241,16 +238,15 @@ static PyObject *FrsNoise_smoothNoise3(BPy_FrsNoise *self, PyObject *args, PyObj { static const char *kwlist[] = {"v", NULL}; PyObject *obj; + Vec3f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) return NULL; - Vec3f *v = Vec3f_ptr_from_PyObject(obj); - if (!v) { + if (!Vec3f_ptr_from_PyObject(obj, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - float t = self->n->smoothNoise3(*v); - delete v; + float t = self->n->smoothNoise3(vec); return PyFloat_FromDouble(t); } diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index e17f16a2fa7..b08fcfa8dba 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -311,16 +311,15 @@ static PyObject * StrokeAttribute_set_attribute_vec2(BPy_StrokeAttribute *self, static const char *kwlist[] = {"name", "value", NULL}; char *s; PyObject *obj = 0; + Vec2f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) return NULL; - Vec2f *v = Vec2f_ptr_from_PyObject(obj); - if (!v) { + if (!Vec2f_ptr_from_PyObject(obj, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 2 must be a 2D vector (either a list of 2 elements or Vector)"); return NULL; } - self->sa->setAttributeVec2f(s, *v); - delete v; + self->sa->setAttributeVec2f(s, vec); Py_RETURN_NONE; } @@ -341,16 +340,15 @@ static PyObject * StrokeAttribute_set_attribute_vec3(BPy_StrokeAttribute *self, static const char *kwlist[] = {"name", "value", NULL}; char *s; PyObject *obj = 0; + Vec3f vec; if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", (char **)kwlist, &s, &obj)) return NULL; - Vec3f *v = Vec3f_ptr_from_PyObject(obj); - if (!v) { + if (!Vec3f_ptr_from_PyObject(obj, &vec)) { PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - self->sa->setAttributeVec3f(s, *v); - delete v; + self->sa->setAttributeVec3f(s, vec); Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index cd6f9da3e05..011609bb343 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -251,14 +251,16 @@ int Director_BPy_UnaryFunction0D___call__(void *uf0D, PyObject *obj, Interface0D ((UnaryFunction0D<unsigned> *)uf0D)->result = PyLong_AsLong(result); } else if (BPy_UnaryFunction0DVec2f_Check(obj)) { - Vec2f *v = Vec2f_ptr_from_Vector(result); - ((UnaryFunction0D<Vec2f> *)uf0D)->result = *v; - delete v; + Vec2f vec; + if (!Vec2f_ptr_from_Vector(result, &vec)) + return -1; + ((UnaryFunction0D<Vec2f> *)uf0D)->result = vec; } else if (BPy_UnaryFunction0DVec3f_Check(obj)) { - Vec3f *v = Vec3f_ptr_from_Vector(result); - ((UnaryFunction0D<Vec3f> *)uf0D)->result = *v; - delete v; + Vec3f vec; + if (!Vec3f_ptr_from_Vector(result, &vec)) + return -1; + ((UnaryFunction0D<Vec3f> *)uf0D)->result = vec; } else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) { vector<ViewShape*> vec; @@ -301,14 +303,16 @@ int Director_BPy_UnaryFunction1D___call__(void *uf1D, PyObject *obj, Interface1D ((UnaryFunction1D<unsigned> *)uf1D)->result = PyLong_AsLong(result); } else if (BPy_UnaryFunction1DVec2f_Check(obj)) { - Vec2f *v = Vec2f_ptr_from_Vector(result); - ((UnaryFunction1D<Vec2f> *)uf1D)->result = *v; - delete v; + Vec2f vec; + if (!Vec2f_ptr_from_Vector(result, &vec)) + return -1; + ((UnaryFunction1D<Vec2f> *)uf1D)->result = vec; } else if (BPy_UnaryFunction1DVec3f_Check(obj)) { - Vec3f *v = Vec3f_ptr_from_Vector(result); - ((UnaryFunction1D<Vec3f> *)uf1D)->result = *v; - delete v; + Vec3f vec; + if (!Vec3f_ptr_from_Vector(result, &vec)) + return -1; + ((UnaryFunction1D<Vec3f> *)uf1D)->result = vec; } else if (BPy_UnaryFunction1DVectorViewShape_Check(obj)) { vector<ViewShape*> vec; diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 3205a3a3d7e..d2dd1657770 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -107,17 +107,15 @@ static PyObject *SVertex_add_normal(BPy_SVertex *self, PyObject *args, PyObject { static const char *kwlist[] = {"normal", NULL}; PyObject *py_normal; + Vec3r n; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &py_normal)) return NULL; - Vec3r *n = Vec3r_ptr_from_PyObject(py_normal); - if (!n) { + if (!Vec3r_ptr_from_PyObject(py_normal, &n)) { PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - self->sv->AddNormal(*n); - delete n; - + self->sv->AddNormal(n); Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index 50d54df2ead..9bbb0405e49 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -167,7 +167,7 @@ static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure) } PyDoc_STRVAR(FrsCurve_segments_size_doc, -"The number of segments in the polyline constituing the Curve.\n" +"The number of segments in the polyline constituting the Curve.\n" "\n" ":type: int"); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index 3e4e7e3aef3..80765e794fb 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -283,7 +283,7 @@ static PyObject *Stroke_stroke_vertices_end(BPy_Stroke *self) PyDoc_STRVAR(Stroke_stroke_vertices_size_doc, ".. method:: stroke_vertices_size()\n" "\n" -" Returns the number of StrokeVertex constituing the Stroke.\n" +" Returns the number of StrokeVertex constituting the Stroke.\n" "\n" " :return: The number of stroke vertices.\n" " :rtype: int"); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 510875ebb2f..292729782ec 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -115,6 +115,10 @@ PyDoc_STRVAR(AdjacencyIterator_object_doc, static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->a_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); @@ -129,6 +133,10 @@ PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return PyBool_from_bool(self->a_it->isIncoming()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index 2b8b4eec4dd..99ac72db028 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -104,7 +104,7 @@ PyDoc_STRVAR(ChainPredicateIterator_doc, static int check_begin(PyObject *obj, void *v) { - if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) return 0; *((PyObject **)v) = obj; return 1; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index b723631f365..1a082ac93bb 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -74,7 +74,7 @@ PyDoc_STRVAR(ChainSilhouetteIterator_doc, static int check_begin(PyObject *obj, void *v) { - if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) return 0; *((PyObject **)v) = obj; return 1; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index 3e2f0102dc3..1dadfbced03 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -75,7 +75,7 @@ PyDoc_STRVAR(ChainingIterator_doc, static int check_begin(PyObject *obj, void *v) { - if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) return 0; *((PyObject **)v) = obj; return 1; @@ -175,6 +175,10 @@ PyDoc_STRVAR(ChainingIterator_object_doc, static PyObject *ChainingIterator_object_get(BPy_ChainingIterator *self, void *UNUSED(closure)) { + if (self->c_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->c_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index 3e45ef17c1b..0329aa99acc 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -97,6 +97,10 @@ PyDoc_STRVAR(CurvePointIterator_object_doc, static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { + if (self->cp_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 3a537eb672a..3a246263efa 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -123,6 +123,10 @@ PyDoc_STRVAR(Interface0DIterator_object_doc, static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { + if (self->if0D_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index d493b6c158b..ccf52c64757 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -115,6 +115,10 @@ PyDoc_STRVAR(SVertexIterator_object_doc, static PyObject *SVertexIterator_object_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } SVertex *sv = self->sv_it->operator->(); if (sv) return BPy_SVertex_from_SVertex(*sv); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 3174980b7d9..8287e280186 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -109,8 +109,10 @@ PyDoc_STRVAR(StrokeVertexIterator_object_doc, static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - if (!self->reversed && self->sv_it->isEnd()) - Py_RETURN_NONE; + if (!self->reversed && self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } StrokeVertex *sv = self->sv_it->operator->(); if (sv) return BPy_StrokeVertex_from_StrokeVertex(*sv); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index f30621f01e3..4a45be8caa5 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -65,7 +65,7 @@ PyDoc_STRVAR(ViewEdgeIterator_doc, static int check_begin(PyObject *obj, void *v) { - if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) return 0; *((PyObject **)v) = obj; return 1; @@ -122,6 +122,10 @@ PyDoc_STRVAR(ViewEdgeIterator_object_doc, static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { + if (!self->ve_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->ve_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); @@ -138,7 +142,8 @@ static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, v ViewEdge *ve = self->ve_it->getCurrentEdge(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE;} + Py_RETURN_NONE; +} static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) { diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index f2b0e604c22..12ca3d6cc4a 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -103,6 +103,10 @@ PyDoc_STRVAR(orientedViewEdgeIterator_object_doc, static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure)) { + if (self->ove_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); } diff --git a/source/blender/freestyle/intern/stroke/Curve.h b/source/blender/freestyle/intern/stroke/Curve.h index 68da744d7b3..7e3b6732bff 100644 --- a/source/blender/freestyle/intern/stroke/Curve.h +++ b/source/blender/freestyle/intern/stroke/Curve.h @@ -491,7 +491,7 @@ public: return _Id; } - /*! Returns the number of segments in the polyline constituing the Curve. */ + /*! Returns the number of segments in the polyline constituting the Curve. */ inline unsigned int nSegments() const { return _nSegments; diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index e7a75728985..d116edc6ace 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -774,7 +774,7 @@ public: const_vertex_iterator vertices_end() const; vertex_iterator vertices_end(); - /*! Returns a StrokeVertexIterator pointing on the first StrokeVertex of the Stroke. One can specifly a sampling + /*! Returns a StrokeVertexIterator pointing on the first StrokeVertex of the Stroke. One can specify a sampling * value to resample the Stroke on the fly if needed. * \param t * The resampling value with which we want our Stroke to be resampled. @@ -785,7 +785,7 @@ public: /*! Returns a StrokeVertexIterator pointing after the last StrokeVertex of the Stroke. */ StrokeInternal::StrokeVertexIterator strokeVerticesEnd(); - /*! Returns the number of StrokeVertex constituing the Stroke. */ + /*! Returns the number of StrokeVertex constituting the Stroke. */ inline unsigned int strokeVerticesSize() const { return _Vertices.size(); diff --git a/source/blender/freestyle/intern/system/Id.h b/source/blender/freestyle/intern/system/Id.h index 9cd45646f1c..8b028cdb3da 100644 --- a/source/blender/freestyle/intern/system/Id.h +++ b/source/blender/freestyle/intern/system/Id.h @@ -92,13 +92,13 @@ public: return _second; } - /*! Sets the first number constituing the Id */ + /*! Sets the first number constituting the Id */ void setFirst(id_type first) { _first = first; } - /*! Sets the second number constituing the Id */ + /*! Sets the second number constituting the Id */ void setSecond(id_type second) { _second = second; diff --git a/source/blender/freestyle/intern/system/TimeUtils.h b/source/blender/freestyle/intern/system/TimeUtils.h index bbf4c5a1edb..6fe8b0e7431 100644 --- a/source/blender/freestyle/intern/system/TimeUtils.h +++ b/source/blender/freestyle/intern/system/TimeUtils.h @@ -23,7 +23,7 @@ /** \file blender/freestyle/intern/system/TimeUtils.h * \ingroup freestyle - * \brief Class to measure ellapsed time + * \brief Class to measure elapsed time * \author Stephane Grabli * \date 10/04/2002 */ diff --git a/source/blender/freestyle/intern/view_map/SteerableViewMap.h b/source/blender/freestyle/intern/view_map/SteerableViewMap.h index 581155fa6e8..d6af7384fb8 100644 --- a/source/blender/freestyle/intern/view_map/SteerableViewMap.h +++ b/source/blender/freestyle/intern/view_map/SteerableViewMap.h @@ -95,7 +95,7 @@ public: /*! Builds _nbOrientations+1 pyramids of images from the _nbOrientations+1 base images of the steerable viewmap. * \param steerableBases - * The _nbOrientations+1 images constituing the basis for the steerable pyramid. + * The _nbOrientations+1 images constituting the basis for the steerable pyramid. * \param copy * If false, the data is not duplicated, and Canvas deals with the memory management of these * _nbOrientations+1 images. If true, data is copied, and it's up to the caller to delete the images. diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp index 91d077278fb..b5d73640c11 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp @@ -39,7 +39,7 @@ namespace Freestyle { void ViewEdgeXBuilder::Init(ViewShape *oVShape) { - if (0 == oVShape) + if (NULL == oVShape) return; // for design conveniance, we store the current SShape. @@ -527,7 +527,7 @@ FEdge *ViewEdgeXBuilder::BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer& bool ViewEdgeXBuilder::stopSmoothViewEdge(WXFaceLayer *iFaceLayer) { - if (0 == iFaceLayer) + if (NULL == iFaceLayer) return true; if (iFaceLayer->userdata == 0) return false; @@ -698,7 +698,7 @@ FEdge *ViewEdgeXBuilder::BuildSharpFEdge(FEdge *feprevious, const OWXEdge& iwe) bool ViewEdgeXBuilder::stopSharpViewEdge(WXEdge *iEdge) { - if (0 == iEdge) + if (NULL == iEdge) return true; if (iEdge->userdata == 0) return false; diff --git a/source/blender/freestyle/intern/view_map/ViewMap.h b/source/blender/freestyle/intern/view_map/ViewMap.h index 0ab089b7d7a..2c9672be53b 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.h +++ b/source/blender/freestyle/intern/view_map/ViewMap.h @@ -1352,12 +1352,12 @@ public: vertex_iterator vertices_end(); // Iterator access (Interface1D) - /*! Returns an Interface0DIterator to iterate over the SVertex constituing the embedding of this ViewEdge. + /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. * The returned Interface0DIterator points to the first SVertex of the ViewEdge. */ virtual Interface0DIterator verticesBegin(); - /*! Returns an Interface0DIterator to iterate over the SVertex constituing the embedding of this ViewEdge. + /*! Returns an Interface0DIterator to iterate over the SVertex constituting the embedding of this ViewEdge. * The returned Interface0DIterator points after the last SVertex of the ViewEdge. */ virtual Interface0DIterator verticesEnd(); |