Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/freestyle/style_modules/anisotropic_diffusion.py49
-rw-r--r--release/scripts/freestyle/style_modules/curvature2d.py30
-rw-r--r--release/scripts/freestyle/style_modules/parameter_editor.py158
-rw-r--r--release/scripts/freestyle/style_modules/shaders.py234
-rw-r--r--release/scripts/freestyle/style_modules/sketchy_topology_broken.py61
-rw-r--r--release/scripts/freestyle/style_modules/thickness_fof_depth_discontinuity.py36
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.cpp62
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.h2
-rw-r--r--source/blender/freestyle/intern/python/BPy_Interface0D.cpp2
-rw-r--r--source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp484
-rw-r--r--source/blender/freestyle/intern/python/BPy_StrokeAttribute.h1
-rw-r--r--source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp343
-rw-r--r--source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h4
13 files changed, 615 insertions, 851 deletions
diff --git a/release/scripts/freestyle/style_modules/anisotropic_diffusion.py b/release/scripts/freestyle/style_modules/anisotropic_diffusion.py
index 7e7ebf647bd..83cc9991d8b 100644
--- a/release/scripts/freestyle/style_modules/anisotropic_diffusion.py
+++ b/release/scripts/freestyle/style_modules/anisotropic_diffusion.py
@@ -27,48 +27,21 @@
from freestyle_init import *
from logical_operators import *
-from PredicatesB1D import *
from shaders import *
-from PredicatesU0D import *
-from math import *
-## thickness modifiers
-
-normalInfo=Normal2DF0D()
-curvatureInfo=Curvature2DAngleF0D()
-
-def edgestopping(x, sigma):
- return exp(- x*x/(2*sigma*sigma))
-
-class pyDiffusion2Shader(StrokeShader):
- def __init__(self, lambda1, nbIter):
- StrokeShader.__init__(self)
- self._lambda = lambda1
- self._nbIter = nbIter
- def getName(self):
- return "pyDiffusionShader"
- def shade(self, stroke):
- for i in range (1, self._nbIter):
- it = stroke.strokeVerticesBegin()
- while it.isEnd() == 0:
- v=it.getObject()
- p1 = v.getPoint()
- p2 = normalInfo(it.castToInterface0DIterator())*self._lambda*curvatureInfo(it.castToInterface0DIterator())
- v.setPoint(p1+p2)
- it.increment()
+# pyDiffusion2Shader parameters
+offset = 0.25
+nbIter = 30
upred = AndUP1D(QuantitativeInvisibilityUP1D(0), ExternalContourUP1D())
Operators.select( upred )
-bpred = TrueBP1D();
+bpred = TrueBP1D()
Operators.bidirectionalChain(ChainPredicateIterator(upred, bpred), NotUP1D(upred) )
-shaders_list = [
- ConstantThicknessShader(4),
- StrokeTextureShader("smoothAlpha.bmp", Stroke.OPAQUE_MEDIUM, 0),
- SamplingShader(2),
- pyDiffusion2Shader(-0.03, 30),
- IncreasingColorShader(1.0,0.0,0.0,1, 0, 1, 0, 1)
- ]
+shaders_list = [
+ ConstantThicknessShader(4),
+ StrokeTextureShader("smoothAlpha.bmp", Stroke.OPAQUE_MEDIUM, 0),
+ SamplingShader(2),
+ pyDiffusion2Shader(offset, nbIter),
+ IncreasingColorShader(1, 0, 0, 1, 0, 1, 0, 1)
+ ]
Operators.create(TrueUP1D(), shaders_list)
-
-
-
diff --git a/release/scripts/freestyle/style_modules/curvature2d.py b/release/scripts/freestyle/style_modules/curvature2d.py
index fc2bcab4946..0c013997a16 100644
--- a/release/scripts/freestyle/style_modules/curvature2d.py
+++ b/release/scripts/freestyle/style_modules/curvature2d.py
@@ -28,33 +28,13 @@
from freestyle_init import *
from logical_operators import *
-from PredicatesB1D import *
from shaders import *
-class py2DCurvatureColorShader(StrokeShader):
- def getName(self):
- return "py2DCurvatureColorShader"
-
- def shade(self, stroke):
- it = stroke.strokeVerticesBegin()
- it_end = stroke.strokeVerticesEnd()
- func = Curvature2DAngleF0D()
- while it.isEnd() == 0:
- it0D = it.castToInterface0DIterator()
- sv = it.getObject()
- att = sv.attribute()
- c = func(it0D)
- if (c<0):
- print("negative 2D curvature")
- color = 10.0 * c/3.1415
- att.setColor(color,color,color);
- it.increment()
-
Operators.select(QuantitativeInvisibilityUP1D(0))
Operators.bidirectionalChain(ChainSilhouetteIterator(), NotUP1D(QuantitativeInvisibilityUP1D(0)))
-shaders_list = [
- StrokeTextureShader("smoothAlpha.bmp", Stroke.OPAQUE_MEDIUM, 0),
- ConstantThicknessShader(5),
- py2DCurvatureColorShader()
- ]
+shaders_list = [
+ StrokeTextureShader("smoothAlpha.bmp", Stroke.OPAQUE_MEDIUM, 0),
+ ConstantThicknessShader(5),
+ py2DCurvatureColorShader()
+ ]
Operators.create(TrueUP1D(), shaders_list)
diff --git a/release/scripts/freestyle/style_modules/parameter_editor.py b/release/scripts/freestyle/style_modules/parameter_editor.py
index 76ca49adaa6..1cec55fc4d4 100644
--- a/release/scripts/freestyle/style_modules/parameter_editor.py
+++ b/release/scripts/freestyle/style_modules/parameter_editor.py
@@ -109,7 +109,7 @@ class ThicknessModifierMixIn:
outer, inner = inner, outer
else:
outer = inner = (outer + inner) / 2
- sv.attribute().setThickness(outer, inner)
+ sv.attribute.thickness = (outer, inner)
class ThicknessBlenderMixIn(ThicknessModifierMixIn):
def __init__(self, position, ratio):
@@ -171,7 +171,7 @@ def iter_t2d_along_stroke(stroke):
distance = 0.0
it = stroke.strokeVerticesBegin()
while not it.isEnd():
- p = it.getObject().getPoint()
+ p = it.getObject().point
if not it.isBegin():
distance += (prev - p).length
prev = p
@@ -184,22 +184,20 @@ class ColorAlongStrokeShader(ColorRampModifier):
return "ColorAlongStrokeShader"
def shade(self, stroke):
for it, t in iter_t2d_along_stroke(stroke):
- attr = it.getObject().attribute()
- a = attr.getColorRGB()
+ sv = it.getObject()
+ a = sv.attribute.color
b = self.evaluate(t)
- c = self.blend_ramp(a, b)
- attr.setColor(c)
+ sv.attribute.color = self.blend_ramp(a, b)
class AlphaAlongStrokeShader(CurveMappingModifier):
def getName(self):
return "AlphaAlongStrokeShader"
def shade(self, stroke):
for it, t in iter_t2d_along_stroke(stroke):
- attr = it.getObject().attribute()
- a = attr.getAlpha()
+ sv = it.getObject()
+ a = sv.attribute.alpha
b = self.evaluate(t)
- c = self.blend(a, b)
- attr.setAlpha(c)
+ sv.attribute.alpha = self.blend(a, b)
class ThicknessAlongStrokeShader(ThicknessBlenderMixIn, CurveMappingModifier):
def __init__(self, thickness_position, thickness_ratio,
@@ -213,7 +211,7 @@ class ThicknessAlongStrokeShader(ThicknessBlenderMixIn, CurveMappingModifier):
def shade(self, stroke):
for it, t in iter_t2d_along_stroke(stroke):
sv = it.getObject()
- a = sv.attribute().getThicknessRL()
+ a = sv.attribute.thickness
b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
c = self.blend_thickness(a[0], a[1], b)
self.set_thickness(sv, c[0], c[1])
@@ -244,11 +242,10 @@ class ColorDistanceFromCameraShader(ColorRampModifier):
return "ColorDistanceFromCameraShader"
def shade(self, stroke):
for it, t in iter_distance_from_camera(stroke, self.__range_min, self.__range_max):
- attr = it.getObject().attribute()
- a = attr.getColorRGB()
+ sv = it.getObject()
+ a = sv.attribute.color
b = self.evaluate(t)
- c = self.blend_ramp(a, b)
- attr.setColor(c)
+ sv.attribute.color = self.blend_ramp(a, b)
class AlphaDistanceFromCameraShader(CurveMappingModifier):
def __init__(self, blend, influence, mapping, invert, curve, range_min, range_max):
@@ -259,11 +256,10 @@ class AlphaDistanceFromCameraShader(CurveMappingModifier):
return "AlphaDistanceFromCameraShader"
def shade(self, stroke):
for it, t in iter_distance_from_camera(stroke, self.__range_min, self.__range_max):
- attr = it.getObject().attribute()
- a = attr.getAlpha()
+ sv = it.getObject()
+ a = sv.attribute.alpha
b = self.evaluate(t)
- c = self.blend(a, b)
- attr.setAlpha(c)
+ sv.attribute.alpha = self.blend(a, b)
class ThicknessDistanceFromCameraShader(ThicknessBlenderMixIn, CurveMappingModifier):
def __init__(self, thickness_position, thickness_ratio,
@@ -279,7 +275,7 @@ class ThicknessDistanceFromCameraShader(ThicknessBlenderMixIn, CurveMappingModif
def shade(self, stroke):
for it, t in iter_distance_from_camera(stroke, self.__range_min, self.__range_max):
sv = it.getObject()
- a = sv.attribute().getThicknessRL()
+ a = sv.attribute.thickness
b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
c = self.blend_thickness(a[0], a[1], b)
self.set_thickness(sv, c[0], c[1])
@@ -317,11 +313,10 @@ class ColorDistanceFromObjectShader(ColorRampModifier):
if self.__target is None:
return
for it, t in iter_distance_from_object(stroke, self.__target, self.__range_min, self.__range_max):
- attr = it.getObject().attribute()
- a = attr.getColorRGB()
+ sv = it.getObject()
+ a = sv.attribute.color
b = self.evaluate(t)
- c = self.blend_ramp(a, b)
- attr.setColor(c)
+ sv.attribute.color = self.blend_ramp(a, b)
class AlphaDistanceFromObjectShader(CurveMappingModifier):
def __init__(self, blend, influence, mapping, invert, curve, target, range_min, range_max):
@@ -335,11 +330,10 @@ class AlphaDistanceFromObjectShader(CurveMappingModifier):
if self.__target is None:
return
for it, t in iter_distance_from_object(stroke, self.__target, self.__range_min, self.__range_max):
- attr = it.getObject().attribute()
- a = attr.getAlpha()
+ sv = it.getObject()
+ a = sv.attribute.alpha
b = self.evaluate(t)
- c = self.blend(a, b)
- attr.setAlpha(c)
+ sv.attribute.alpha = self.blend(a, b)
class ThicknessDistanceFromObjectShader(ThicknessBlenderMixIn, CurveMappingModifier):
def __init__(self, thickness_position, thickness_ratio,
@@ -358,7 +352,7 @@ class ThicknessDistanceFromObjectShader(ThicknessBlenderMixIn, CurveMappingModif
return
for it, t in iter_distance_from_object(stroke, self.__target, self.__range_min, self.__range_max):
sv = it.getObject()
- a = sv.attribute().getThicknessRL()
+ a = sv.attribute.thickness
b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
c = self.blend_thickness(a[0], a[1], b)
self.set_thickness(sv, c[0], c[1])
@@ -429,17 +423,15 @@ class ColorMaterialShader(ColorRampModifier):
def shade(self, stroke):
if self.__material_attr in ["DIFF", "SPEC"] and not self.__use_ramp:
for it, b in iter_material_color(stroke, self.__material_attr):
- attr = it.getObject().attribute()
- a = attr.getColorRGB()
- c = self.blend_ramp(a, b)
- attr.setColor(c)
+ sv = it.getObject()
+ a = sv.attribute.color
+ sv.attribute.color = self.blend_ramp(a, b)
else:
for it, t in iter_material_value(stroke, self.__material_attr):
- attr = it.getObject().attribute()
- a = attr.getColorRGB()
+ sv = it.getObject()
+ a = sv.attribute.color
b = self.evaluate(t)
- c = self.blend_ramp(a, b)
- attr.setColor(c)
+ sv.attribute.color = self.blend_ramp(a, b)
class AlphaMaterialShader(CurveMappingModifier):
def __init__(self, blend, influence, mapping, invert, curve, material_attr):
@@ -449,11 +441,10 @@ class AlphaMaterialShader(CurveMappingModifier):
return "AlphaMaterialShader"
def shade(self, stroke):
for it, t in iter_material_value(stroke, self.__material_attr):
- attr = it.getObject().attribute()
- a = attr.getAlpha()
+ sv = it.getObject()
+ a = sv.attribute.alpha
b = self.evaluate(t)
- c = self.blend(a, b)
- attr.setAlpha(c)
+ sv.attribute.alpha = self.blend(a, b)
class ThicknessMaterialShader(ThicknessBlenderMixIn, CurveMappingModifier):
def __init__(self, thickness_position, thickness_ratio,
@@ -468,7 +459,7 @@ class ThicknessMaterialShader(ThicknessBlenderMixIn, CurveMappingModifier):
def shade(self, stroke):
for it, t in iter_material_value(stroke, self.__material_attr):
sv = it.getObject()
- a = sv.attribute().getThicknessRL()
+ a = sv.attribute.thickness
b = self.__value_min + self.evaluate(t) * (self.__value_max - self.__value_min)
c = self.blend_thickness(a[0], a[1], b)
self.set_thickness(sv, c[0], c[1])
@@ -492,7 +483,7 @@ class CalligraphicThicknessShader(ThicknessBlenderMixIn, ScalarBlendModifier):
orthDir.normalize()
fac = abs(orthDir * self.__orientation)
sv = it.getObject()
- a = sv.attribute().getThicknessRL()
+ a = sv.attribute.thickness
b = self.__min_thickness + fac * (self.__max_thickness - self.__min_thickness)
b = max(b, 0.0)
c = self.blend_thickness(a[0], a[1], b)
@@ -505,7 +496,7 @@ def iter_distance_along_stroke(stroke):
distance = 0.0
it = stroke.strokeVerticesBegin()
while not it.isEnd():
- p = it.getObject().getPoint()
+ p = it.getObject().point
if not it.isBegin():
distance += (prev - p).length
prev = p
@@ -525,10 +516,8 @@ class SinusDisplacementShader(StrokeShader):
for it, distance in iter_distance_along_stroke(stroke):
v = it.getObject()
n = self._getNormal(it.castToInterface0DIterator())
- p = v.getPoint()
- u = v.u()
n = n * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase)
- v.setPoint(p + n)
+ v.point = v.point + n
stroke.UpdateLength()
class PerlinNoise1DShader(StrokeShader):
@@ -546,8 +535,8 @@ class PerlinNoise1DShader(StrokeShader):
it = stroke.strokeVerticesBegin()
while not it.isEnd():
v = it.getObject()
- nres = self.__noise.turbulence1(length * v.u(), self.__freq, self.__amp, self.__oct)
- v.setPoint(v.getPoint() + nres * self.__dir)
+ nres = self.__noise.turbulence1(length * v.u, self.__freq, self.__amp, self.__oct)
+ v.point = v.point + nres * self.__dir
it.increment()
stroke.UpdateLength()
@@ -565,9 +554,9 @@ class PerlinNoise2DShader(StrokeShader):
it = stroke.strokeVerticesBegin()
while not it.isEnd():
v = it.getObject()
- vec = Vector([v.getProjectedX(), v.getProjectedY()])
+ vec = Vector([v.getProjectedX(), v.getProjectedY()]) # FIXME
nres = self.__noise.turbulence2(vec, self.__freq, self.__amp, self.__oct)
- v.setPoint(v.getPoint() + nres * self.__dir)
+ v.point = v.point + nres * self.__dir
it.increment()
stroke.UpdateLength()
@@ -584,12 +573,11 @@ class Offset2DShader(StrokeShader):
it = stroke.strokeVerticesBegin()
while not it.isEnd():
v = it.getObject()
- u = v.u()
+ u = v.u
a = self.__start + u * (self.__end - self.__start)
n = self.__getNormal(it.castToInterface0DIterator())
n = n * a
- p = v.getPoint()
- v.setPoint(p + n + self.__xy)
+ v.point = v.point + n + self.__xy
it.increment()
stroke.UpdateLength()
@@ -609,19 +597,19 @@ class Transform2DShader(StrokeShader):
# determine the pivot of scaling and rotation operations
if self.__pivot == "START":
it = stroke.strokeVerticesBegin()
- pivot = it.getObject().getPoint()
+ pivot = it.getObject().point
elif self.__pivot == "END":
it = stroke.strokeVerticesEnd()
it.decrement()
- pivot = it.getObject().getPoint()
+ pivot = it.getObject().point
elif self.__pivot == "PARAM":
p = None
it = stroke.strokeVerticesBegin()
while not it.isEnd():
prev = p
v = it.getObject()
- p = v.getPoint()
- u = v.u()
+ p = v.point
+ u = v.u
if self.__pivot_u < u:
break
it.increment()
@@ -635,7 +623,7 @@ class Transform2DShader(StrokeShader):
n = 0
it = stroke.strokeVerticesBegin()
while not it.isEnd():
- p = it.getObject().getPoint()
+ p = it.getObject().point
pivot = pivot + p
n = n + 1
it.increment()
@@ -649,13 +637,13 @@ class Transform2DShader(StrokeShader):
it = stroke.strokeVerticesBegin()
while not it.isEnd():
v = it.getObject()
- p = v.getPoint()
+ p = v.point
p = p - pivot
x = p.x * self.__scale_x
y = p.y * self.__scale_y
p.x = x * cos_theta - y * sin_theta
p.y = x * sin_theta + y * cos_theta
- v.setPoint(p + pivot)
+ v.point = p + pivot
it.increment()
stroke.UpdateLength()
@@ -701,7 +689,7 @@ def iter_stroke_vertices(stroke):
prev_p = None
while not it.isEnd():
sv = it.getObject()
- p = sv.getPoint()
+ p = sv.point
if prev_p is None or (prev_p - p).length > 1e-6:
yield sv
prev_p = p
@@ -715,15 +703,15 @@ class RoundCapShader(StrokeShader):
# save the location and attribute of stroke vertices
buffer = []
for sv in iter_stroke_vertices(stroke):
- buffer.append((sv.getPoint(), sv.attribute()))
+ buffer.append((Vector(sv.point), StrokeAttribute(sv.attribute)))
nverts = len(buffer)
if nverts < 2:
return
# calculate the number of additional vertices to form caps
- R, L = stroke[0].attribute().getThicknessRL()
+ R, L = stroke[0].attribute.thickness
caplen_beg = (R + L) / 2.0
nverts_beg = max(5, int(R + L))
- R, L = stroke[-1].attribute().getThicknessRL()
+ R, L = stroke[-1].attribute.thickness
caplen_end = (R + L) / 2.0
nverts_end = max(5, int(R + L))
# adjust the total number of stroke vertices
@@ -731,34 +719,34 @@ class RoundCapShader(StrokeShader):
# restore the location and attribute of the original vertices
for i in range(nverts):
p, attr = buffer[i]
- stroke[nverts_beg + i].setPoint(p)
- stroke[nverts_beg + i].setAttribute(attr)
+ stroke[nverts_beg + i].point = p
+ stroke[nverts_beg + i].attribute = attr
# reshape the cap at the beginning of the stroke
q, attr = buffer[1]
p, attr = buffer[0]
d = p - q
d = d / d.length * caplen_beg
n = 1.0 / nverts_beg
- R, L = attr.getThicknessRL()
+ R, L = attr.thickness
for i in range(nverts_beg):
t = (nverts_beg - i) * n
- stroke[i].setPoint(p + d * t)
+ stroke[i].point = p + d * t
r = self.round_cap_thickness((nverts_beg - i + 1) * n)
- stroke[i].setAttribute(attr)
- stroke[i].attribute().setThickness(R * r, L * r)
+ stroke[i].attribute = attr
+ stroke[i].attribute.thickness = (R * r, L * r)
# reshape the cap at the end of the stroke
q, attr = buffer[-2]
p, attr = buffer[-1]
d = p - q
d = d / d.length * caplen_end
n = 1.0 / nverts_end
- R, L = attr.getThicknessRL()
+ R, L = attr.thickness
for i in range(nverts_end):
t = (nverts_end - i) * n
- stroke[-i-1].setPoint(p + d * t)
+ stroke[-i-1].point = p + d * t
r = self.round_cap_thickness((nverts_end - i + 1) * n)
- stroke[-i-1].setAttribute(attr)
- stroke[-i-1].attribute().setThickness(R * r, L * r)
+ stroke[-i-1].attribute = attr
+ stroke[-i-1].attribute.thickness = (R * r, L * r)
# update the curvilinear 2D length of each vertex
stroke.UpdateLength()
@@ -767,15 +755,15 @@ class SquareCapShader(StrokeShader):
# save the location and attribute of stroke vertices
buffer = []
for sv in iter_stroke_vertices(stroke):
- buffer.append((sv.getPoint(), sv.attribute()))
+ buffer.append((Vector(sv.point), StrokeAttribute(sv.attribute)))
nverts = len(buffer)
if nverts < 2:
return
# calculate the number of additional vertices to form caps
- R, L = stroke[0].attribute().getThicknessRL()
+ R, L = stroke[0].attribute.thickness
caplen_beg = (R + L) / 2.0
nverts_beg = 1
- R, L = stroke[-1].attribute().getThicknessRL()
+ R, L = stroke[-1].attribute.thickness
caplen_end = (R + L) / 2.0
nverts_end = 1
# adjust the total number of stroke vertices
@@ -783,20 +771,20 @@ class SquareCapShader(StrokeShader):
# restore the location and attribute of the original vertices
for i in range(nverts):
p, attr = buffer[i]
- stroke[nverts_beg + i].setPoint(p)
- stroke[nverts_beg + i].setAttribute(attr)
+ stroke[nverts_beg + i].point = p
+ stroke[nverts_beg + i].attribute = attr
# reshape the cap at the beginning of the stroke
q, attr = buffer[1]
p, attr = buffer[0]
d = p - q
- stroke[0].setPoint(p + d / d.length * caplen_beg)
- stroke[0].setAttribute(attr)
+ stroke[0].point = p + d / d.length * caplen_beg
+ stroke[0].attribute = attr
# reshape the cap at the end of the stroke
q, attr = buffer[-2]
p, attr = buffer[-1]
d = p - q
- stroke[-1].setPoint(p + d / d.length * caplen_beg)
- stroke[-1].setAttribute(attr)
+ stroke[-1].point = p + d / d.length * caplen_beg
+ stroke[-1].attribute = attr
# update the curvilinear 2D length of each vertex
stroke.UpdateLength()
@@ -872,7 +860,7 @@ class DashedLineShader(StrokeShader):
if index == len(self._pattern):
index = 0
visible = not visible
- it.getObject().attribute().setVisible(visible)
+ it.getObject().attribute.visible = visible
it.increment()
# predicates for chaining
diff --git a/release/scripts/freestyle/style_modules/shaders.py b/release/scripts/freestyle/style_modules/shaders.py
index f05042f8332..85ba2da0e25 100644
--- a/release/scripts/freestyle/style_modules/shaders.py
+++ b/release/scripts/freestyle/style_modules/shaders.py
@@ -28,7 +28,7 @@ class pyDepthDiscontinuityThicknessShader(StrokeShader):
while it.isEnd() == 0:
z = self.__func(it.castToInterface0DIterator())
thickness = a*z+b
- it.getObject().attribute().setThickness(thickness, thickness)
+ it.getObject().attribute.thickness = (thickness, thickness)
it.increment()
class pyConstantThicknessShader(StrokeShader):
@@ -42,9 +42,8 @@ class pyConstantThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
t = self._thickness/2.0
- att.setThickness(t, t)
+ it.getObject().attribute.thickness = (t, t)
it.increment()
class pyFXSThicknessShader(StrokeShader):
@@ -58,9 +57,8 @@ class pyFXSThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
t = self._thickness/2.0
- att.setThickness(t, t)
+ it.getObject().attribute.thickness = (t, t)
it.increment()
class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
@@ -81,7 +79,6 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
it_end = stroke.strokeVerticesEnd()
func = DensityF0D(self.wsize)
while it.isEnd() == 0:
- att = it.getObject().attribute()
toto = it.castToInterface0DIterator()
c= func(toto)
if (c < self.threshold_min ):
@@ -90,9 +87,10 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
c = self.threshold_max
## t = (c - self.threshold_min)/(self.threshold_max - self.threshold_min)*(self._thicknessMax-self._thicknessMin) + self._thicknessMin
t = (self.threshold_max - c )/(self.threshold_max - self.threshold_min)*(self._thicknessMax-self._thicknessMin) + self._thicknessMin
- att.setThickness(t/2.0, t/2.0)
+ it.getObject().attribute.thickness = (t/2.0, t/2.0)
i = i+1
it.increment()
+
class pyIncreasingThicknessShader(StrokeShader):
def __init__(self, thicknessMin, thicknessMax):
StrokeShader.__init__(self)
@@ -107,13 +105,12 @@ class pyIncreasingThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
c = float(i)/float(n)
if(i < float(n)/2.0):
t = (1.0 - c)*self._thicknessMin + c * self._thicknessMax
else:
t = (1.0 - c)*self._thicknessMax + c * self._thicknessMin
- att.setThickness(t/2.0, t/2.0)
+ it.getObject().attribute.thickness = (t/2.0, t/2.0)
i = i+1
it.increment()
@@ -139,15 +136,15 @@ class pyConstrainedIncreasingThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
+ att = it.getObject().attribute
c = float(i)/float(n)
if(i < float(n)/2.0):
t = (1.0 - c)*self._thicknessMin + c * maxT
else:
t = (1.0 - c)*maxT + c * self._thicknessMin
- att.setThickness(t/2.0, t/2.0)
+ att.thickness = (t/2.0, t/2.0)
if(i == n-1):
- att.setThickness(self._thicknessMin/2.0, self._thicknessMin/2.0)
+ att.thickness = (self._thicknessMin/2.0, self._thicknessMin/2.0)
i = i+1
it.increment()
@@ -172,10 +169,9 @@ class pyDecreasingThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
c = float(i)/float(n)
t = (1.0 - c)*tMax +c*tMin
- att.setThickness(t/2.0, t/2.0)
+ it.getObject().attribute.thickness = (t/2.0, t/2.0)
i = i+1
it.increment()
@@ -198,14 +194,13 @@ class pyNonLinearVaryingThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
if(i < float(n)/2.0):
c = float(i)/float(n)
else:
c = float(n-i)/float(n)
c = smoothC(c, self._exponent)
t = (1.0 - c)*self._thicknessMax + c * self._thicknessMin
- att.setThickness(t/2.0, t/2.0)
+ it.getObject().attribute.thickness = (t/2.0, t/2.0)
i = i+1
it.increment()
@@ -231,13 +226,12 @@ class pySLERPThicknessShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
c = float(i)/float(n)
if(i < float(n)/2.0):
t = sin((1-c)*self._omega)/sinh(self._omega)*self._thicknessMin + sin(c*self._omega)/sinh(self._omega) * maxT
else:
t = sin((1-c)*self._omega)/sinh(self._omega)*maxT + sin(c*self._omega)/sinh(self._omega) * self._thicknessMin
- att.setThickness(t/2.0, t/2.0)
+ it.getObject().attribute.thickness = (t/2.0, t/2.0)
i = i+1
it.increment()
@@ -266,33 +260,30 @@ class pyTVertexThickenerShader(StrokeShader): ## FIXME
it3 = StrokeVertexIterator(it)
count = 0
while (it3.isEnd() == 0 and count < n):
- att = it3.getObject().attribute()
- tr = att.getThicknessR();
- tl = att.getThicknessL();
+ att = it3.getObject().attribute
+ (tr, tl) = att.thickness
r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
#r = (1.0-a)/float(n-1)*count + a
- att.setThickness(r*tr, r*tl)
+ att.thickness = (r*tr, r*tl)
it3.increment()
count = count + 1
if(it2.isEnd()):
it4 = StrokeVertexIterator(it)
count = 0
while (it4.isBegin() == 0 and count < n):
- att = it4.getObject().attribute()
- tr = att.getThicknessR();
- tl = att.getThicknessL();
+ att = it4.getObject().attribute
+ (tr, tl) = att.thickness
r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
#r = (1.0-a)/float(n-1)*count + a
- att.setThickness(r*tr, r*tl)
+ att.thickness = (r*tr, r*tl)
it4.decrement()
count = count + 1
if ((it4.isBegin() == 1)):
- att = it4.getObject().attribute()
- tr = att.getThicknessR();
- tl = att.getThicknessL();
+ att = it4.getObject().attribute
+ (tr, tl) = att.thickness
r = (a-1.0)/float(n-1)*(float(n)/float(count+1) - 1) + 1
#r = (1.0-a)/float(n-1)*count + a
- att.setThickness(r*tr, r*tl)
+ att.thickness = (r*tr, r*tl)
it.increment()
class pyImportance2DThicknessShader(StrokeShader):
@@ -317,10 +308,9 @@ class pyImportance2DThicknessShader(StrokeShader):
k = self._kmin
else:
k = (self._kmax*(self._w-d) + self._kmin*d)/self._w
- att = v.attribute()
- tr = att.getThicknessR()
- tl = att.getThicknessL()
- att.setThickness(k*tr/2.0, k*tl/2.0)
+ att = v.attribute
+ (tr, tl) = att.thickness
+ att.thickness = (k*tr/2.0, k*tl/2.0)
it.increment()
class pyImportance3DThicknessShader(StrokeShader):
@@ -346,10 +336,9 @@ class pyImportance3DThicknessShader(StrokeShader):
k = self._kmin
else:
k = (self._kmax*(self._w-d) + self._kmin*d)/self._w
- att = v.attribute()
- tr = att.getThicknessR()
- tl = att.getThicknessL()
- att.setThickness(k*tr/2.0, k*tl/2.0)
+ att = v.attribute
+ (tr, tl) = att.thickness
+ att.thickness = (k*tr/2.0, k*tl/2.0)
it.increment()
class pyZDependingThicknessShader(StrokeShader):
@@ -376,7 +365,7 @@ class pyZDependingThicknessShader(StrokeShader):
while it.isEnd() == 0:
z = (self.__func(it.castToInterface0DIterator()) - z_min) * z_diff
thickness = (1 - z) * self.__max + z * self.__min
- it.getObject().attribute().setThickness(thickness, thickness)
+ it.getObject().attribute.thickness = (thickness, thickness)
it.increment()
@@ -396,9 +385,9 @@ class pyConstantColorShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
- att.setColor(self._r, self._g, self._b)
- att.setAlpha(self._a)
+ att = it.getObject().attribute
+ att.color = (self._r, self._g, self._b)
+ att.alpha = self._a
it.increment()
#c1->c2
@@ -415,13 +404,13 @@ class pyIncreasingColorShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
+ att = it.getObject().attribute
c = float(inc)/float(n)
- att.setColor( (1-c)*self._c1[0] + c*self._c2[0],
- (1-c)*self._c1[1] + c*self._c2[1],
- (1-c)*self._c1[2] + c*self._c2[2],)
- att.setAlpha((1-c)*self._c1[3] + c*self._c2[3],)
+ att.color = ((1-c)*self._c1[0] + c*self._c2[0],
+ (1-c)*self._c1[1] + c*self._c2[1],
+ (1-c)*self._c1[2] + c*self._c2[2])
+ att.alpha = (1-c)*self._c1[3] + c*self._c2[3]
inc = inc+1
it.increment()
@@ -439,13 +428,13 @@ class pyInterpolateColorShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
+ att = it.getObject().attribute
u = float(inc)/float(n)
c = 1-2*(fabs(u-0.5))
- att.setColor( (1-c)*self._c1[0] + c*self._c2[0],
- (1-c)*self._c1[1] + c*self._c2[1],
- (1-c)*self._c1[2] + c*self._c2[2],)
- att.setAlpha((1-c)*self._c1[3] + c*self._c2[3],)
+ att.color = ((1-c)*self._c1[0] + c*self._c2[0],
+ (1-c)*self._c1[1] + c*self._c2[1],
+ (1-c)*self._c1[2] + c*self._c2[2])
+ att.alpha = (1-c)*self._c1[3] + c*self._c2[3]
inc = inc+1
it.increment()
@@ -511,8 +500,7 @@ class pyMaterialColorShader(StrokeShader):
g = max(0,g)
b = max(0,b)
- att = it.getObject().attribute()
- att.setColor(r, g, b)
+ it.getObject().attribute.color = (r, g, b)
it.increment()
class pyRandomColorShader(StrokeShader):
@@ -529,7 +517,7 @@ class pyRandomColorShader(StrokeShader):
print(c0, c1, c2)
it = stroke.strokeVerticesBegin()
while(it.isEnd() == 0):
- it.getObject().attribute().setColor(c0,c1,c2)
+ it.getObject().attribute.color = (c0,c1,c2)
it.increment()
class py2DCurvatureColorShader(StrokeShader):
@@ -538,18 +526,13 @@ class py2DCurvatureColorShader(StrokeShader):
def shade(self, stroke):
it = stroke.strokeVerticesBegin()
- it_end = stroke.strokeVerticesEnd()
func = Curvature2DAngleF0D()
while it.isEnd() == 0:
- toto = it.castToInterface0DIterator()
- sv = it.getObject()
- att = sv.attribute()
- c = func(toto)
- if (c<0):
+ c = func(it.castToInterface0DIterator())
+ if c < 0:
print("negative 2D curvature")
color = 10.0 * c/3.1415
- print(color)
- att.setColor(color,color,color);
+ it.getObject().attribute.color = (color, color, color)
it.increment()
class pyTimeColorShader(StrokeShader):
@@ -562,8 +545,7 @@ class pyTimeColorShader(StrokeShader):
it = stroke.strokeVerticesBegin()
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
- att = it.getObject().attribute()
- att.setColor(c,c,c)
+ it.getObject().attribute.color = (c,c,c)
it.increment()
self._t = self._t+self._step
@@ -607,8 +589,8 @@ class pyBackboneStretcherShader(StrokeShader):
dn.normalize()
newFirst = p0+d1*float(self._l)
newLast = pn+dn*float(self._l)
- v0.setPoint(newFirst)
- vn.setPoint(newLast)
+ v0.point = newFirst
+ vn.point = newLast
stroke.UpdateLength()
class pyLengthDependingBackboneStretcherShader(StrokeShader):
@@ -641,8 +623,8 @@ class pyLengthDependingBackboneStretcherShader(StrokeShader):
dn.normalize()
newFirst = p0+d1*float(stretch)
newLast = pn+dn*float(stretch)
- v0.setPoint(newFirst)
- vn.setPoint(newLast)
+ v0.point = newFirst
+ vn.point = newLast
stroke.UpdateLength()
@@ -655,23 +637,23 @@ class pyGuidingLineShader(StrokeShader):
it = stroke.strokeVerticesBegin() ## get the first vertex
itlast = stroke.strokeVerticesEnd() ##
itlast.decrement() ## get the last one
- t = itlast.getObject().getPoint() - it.getObject().getPoint() ## tangent direction
+ t = itlast.getObject().point - it.getObject().point ## tangent direction
itmiddle = StrokeVertexIterator(it) ##
- while(itmiddle.getObject().u()<0.5): ## look for the stroke middle vertex
+ while(itmiddle.getObject().u<0.5): ## look for the stroke middle vertex
itmiddle.increment() ##
it = StrokeVertexIterator(itmiddle)
it.increment()
while(it.isEnd() == 0): ## position all the vertices along the tangent for the right part
- it.getObject().setPoint(itmiddle.getObject().getPoint() \
- +t*(it.getObject().u()-itmiddle.getObject().u()))
+ it.getObject().point = itmiddle.getObject().point \
+ +t*(it.getObject().u-itmiddle.getObject().u)
it.increment()
it = StrokeVertexIterator(itmiddle)
it.decrement()
while(it.isBegin() == 0): ## position all the vertices along the tangent for the left part
- it.getObject().setPoint(itmiddle.getObject().getPoint() \
- -t*(itmiddle.getObject().u()-it.getObject().u()))
+ it.getObject().point = itmiddle.getObject().point \
+ -t*(itmiddle.getObject().u-it.getObject().u)
it.decrement()
- it.getObject().setPoint(itmiddle.getObject().getPoint()-t*(itmiddle.getObject().u())) ## first vertex
+ it.getObject().point = itmiddle.getObject().point-t*itmiddle.getObject().u ## first vertex
stroke.UpdateLength()
@@ -692,30 +674,28 @@ class pyBackboneStretcherNoCuspShader(StrokeShader):
v0 = it0.getObject()
v1 = it1.getObject()
if((v0.getNature() & Nature.CUSP == 0) and (v1.getNature() & Nature.CUSP == 0)):
- p0 = v0.getPoint()
- p1 = v1.getPoint()
+ p0 = v0.point
+ p1 = v1.point
d1 = p0-p1
d1.normalize()
newFirst = p0+d1*float(self._l)
- v0.setPoint(newFirst)
+ v0.point = newFirst
vn_1 = itn_1.getObject()
vn = itn.getObject()
if((vn.getNature() & Nature.CUSP == 0) and (vn_1.getNature() & Nature.CUSP == 0)):
- pn = vn.getPoint()
- pn_1 = vn_1.getPoint()
+ pn = vn.point
+ pn_1 = vn_1.point
dn = pn-pn_1
dn.normalize()
newLast = pn+dn*float(self._l)
- vn.setPoint(newLast)
+ vn.point = newLast
stroke.UpdateLength()
-normalInfo=Normal2DF0D()
-curvatureInfo=Curvature2DAngleF0D()
-
-def edgestopping(x, sigma):
- return exp(- x*x/(2*sigma*sigma))
-
class pyDiffusion2Shader(StrokeShader):
+ """This shader iteratively adds an offset to the position of each
+ stroke vertex in the direction perpendicular to the stroke direction
+ at the point. The offset is scaled by the 2D curvature (i.e., how
+ quickly the stroke curve is) at the point."""
def __init__(self, lambda1, nbIter):
StrokeShader.__init__(self)
self._lambda = lambda1
@@ -729,9 +709,9 @@ class pyDiffusion2Shader(StrokeShader):
it = stroke.strokeVerticesBegin()
while it.isEnd() == 0:
v=it.getObject()
- p1 = v.getPoint()
+ p1 = v.point
p2 = self._normalInfo(it.castToInterface0DIterator())*self._lambda*self._curvatureInfo(it.castToInterface0DIterator())
- v.setPoint(p1+p2)
+ v.point = p1+p2
it.increment()
stroke.UpdateLength()
@@ -750,14 +730,15 @@ class pyTipRemoverShader(StrokeShader):
it = stroke.strokeVerticesBegin()
while(it.isEnd() == 0):
v = it.getObject()
- if((v.curvilinearAbscissa() < self._l) or (v.strokeLength()-v.curvilinearAbscissa() < self._l)):
+ if((v.curvilinear_abscissa < self._l) or (v.stroke_length-v.curvilinear_abscissa < self._l)):
verticesToRemove.append(v)
- oldAttributes.append(StrokeAttribute(v.attribute()))
+ oldAttributes.append(StrokeAttribute(v.attribute))
it.increment()
if(originalSize-len(verticesToRemove) < 2):
return
for sv in verticesToRemove:
stroke.RemoveVertex(sv)
+ stroke.UpdateLength()
stroke.Resample(originalSize)
if(stroke.strokeVerticesSize() != originalSize):
print("pyTipRemover: Warning: resampling problem")
@@ -765,8 +746,7 @@ class pyTipRemoverShader(StrokeShader):
for a in oldAttributes:
if(it.isEnd() == 1):
break
- v = it.getObject()
- v.setAttribute(a)
+ it.getObject().attribute = a
it.increment()
stroke.UpdateLength()
@@ -827,7 +807,7 @@ class pyHLRShader(StrokeShader):
else:
invisible = 0
if(invisible == 1):
- v.attribute().setVisible(0)
+ v.attribute.visible = False
it.increment()
it2.increment()
@@ -871,7 +851,7 @@ class pyTVertexOrientationShader(StrokeShader):
if(tv != None):
dir = self.findOrientation(tv, ve)
#print(dir.x, dir.y)
- v.attribute().setAttributeVec2f("orientation", dir)
+ v.attribute.setAttributeVec2f("orientation", dir)
while(it2.isEnd() == 0):
vprevious = it.getObject()
v = it2.getObject()
@@ -881,7 +861,7 @@ class pyTVertexOrientationShader(StrokeShader):
if(tv != None):
dir = self.findOrientation(tv, ve)
#print(dir.x, dir.y)
- v.attribute().setAttributeVec2f("orientation", dir)
+ v.attribute.setAttributeVec2f("orientation", dir)
it.increment()
it2.increment()
## case where the last vertex is a TVertex
@@ -894,7 +874,7 @@ class pyTVertexOrientationShader(StrokeShader):
if(tv != None):
dir = self.findOrientation(tv, ve)
#print(dir.x, dir.y)
- v.attribute().setAttributeVec2f("orientation", dir)
+ v.attribute.setAttributeVec2f("orientation", dir)
class pySinusDisplacementShader(StrokeShader):
def __init__(self, f, a):
@@ -911,13 +891,13 @@ class pySinusDisplacementShader(StrokeShader):
v = it.getObject()
#print(self._getNormal.getName())
n = self._getNormal(it.castToInterface0DIterator())
- p = v.getPoint()
- u = v.u()
+ p = v.point
+ u = v.u
a = self._a*(1-2*(fabs(u-0.5)))
n = n*a*cos(self._f*u*6.28)
#print(n.x, n.y)
- v.setPoint(p+n)
- #v.setPoint(v.getPoint()+n*a*cos(f*v.u()))
+ v.point = p+n
+ #v.point = v.point+n*a*cos(f*v.u)
it.increment()
stroke.UpdateLength()
@@ -936,7 +916,7 @@ class pyPerlinNoise1DShader(StrokeShader):
v = it.getObject()
i = v.getProjectedX() + v.getProjectedY()
nres = self.__noise.turbulence1(i, self.__freq, self.__amp, self.__oct)
- v.setPoint(v.getProjectedX() + nres, v.getProjectedY() + nres)
+ v.point = (v.getProjectedX() + nres, v.getProjectedY() + nres)
it.increment()
stroke.UpdateLength()
@@ -955,7 +935,7 @@ class pyPerlinNoise2DShader(StrokeShader):
v = it.getObject()
vec = Vector([v.getProjectedX(), v.getProjectedY()])
nres = self.__noise.turbulence2(vec, self.__freq, self.__amp, self.__oct)
- v.setPoint(v.getProjectedX() + nres, v.getProjectedY() + nres)
+ v.point = (v.getProjectedX() + nres, v.getProjectedY() + nres)
it.increment()
stroke.UpdateLength()
@@ -971,10 +951,10 @@ class pyBluePrintCirclesShader(StrokeShader):
it = stroke.strokeVerticesBegin()
if it.isEnd():
return
- p_min = it.getObject().getPoint()
- p_max = it.getObject().getPoint()
+ p_min = Vector(it.getObject().point)
+ p_max = Vector(it.getObject().point)
while it.isEnd() == 0:
- p = it.getObject().getPoint()
+ p = it.getObject().point
if (p.x < p_min.x):
p_min.x = p.x
if (p.x > p_max.x):
@@ -1011,7 +991,7 @@ class pyBluePrintCirclesShader(StrokeShader):
c = prev_center + (center - prev_center) * t
p_new.x = c.x + r * cos(2 * pi * t)
p_new.y = c.y + r * sin(2 * pi * t)
- it.getObject().setPoint(p_new)
+ it.getObject().point = p_new
i = i + 1
it.increment()
i = 1
@@ -1035,10 +1015,10 @@ class pyBluePrintEllipsesShader(StrokeShader):
it = stroke.strokeVerticesBegin()
if it.isEnd():
return
- p_min = it.getObject().getPoint()
- p_max = it.getObject().getPoint()
+ p_min = Vector(it.getObject().point)
+ p_max = Vector(it.getObject().point)
while it.isEnd() == 0:
- p = it.getObject().getPoint()
+ p = it.getObject().point
if (p.x < p_min.x):
p_min.x = p.x
if (p.x > p_max.x):
@@ -1070,7 +1050,7 @@ class pyBluePrintEllipsesShader(StrokeShader):
c = prev_center + (center - prev_center) * t
p_new.x = c.x + r.x * cos(2 * pi * t)
p_new.y = c.y + r.y * sin(2 * pi * t)
- it.getObject().setPoint(p_new)
+ it.getObject().point = p_new
i = i + 1
it.increment()
i = 1
@@ -1097,10 +1077,10 @@ class pyBluePrintSquaresShader(StrokeShader):
it = stroke.strokeVerticesBegin()
if it.isEnd():
return
- p_min = it.getObject().getPoint()
- p_max = it.getObject().getPoint()
+ p_min = Vector(it.getObject().point)
+ p_max = Vector(it.getObject().point)
while it.isEnd() == 0:
- p = it.getObject().getPoint()
+ p = it.getObject().point
if (p.x < p_min.x):
p_min.x = p.x
if (p.x > p_max.x):
@@ -1168,8 +1148,8 @@ class pyBluePrintSquaresShader(StrokeShader):
if visible == 0:
visible = 1
continue
- it.getObject().setPoint(p_new)
- it.getObject().attribute().setVisible(visible)
+ it.getObject().point = p_new
+ it.getObject().attribute.visible = visible
if visible == 0:
visible = 1
i = i + 1
@@ -1196,7 +1176,7 @@ class pyBluePrintDirectedSquaresShader(StrokeShader):
p_mean = Vector([0, 0])
it = stroke.strokeVerticesBegin()
while it.isEnd() == 0:
- p = it.getObject().getPoint()
+ p = it.getObject().point
p_mean = p_mean + p
it.increment()
sv_nb = stroke.strokeVerticesSize()
@@ -1206,7 +1186,7 @@ class pyBluePrintDirectedSquaresShader(StrokeShader):
p_var_xy = 0
it = stroke.strokeVerticesBegin()
while it.isEnd() == 0:
- p = it.getObject().getPoint()
+ p = it.getObject().point
p_var_xx = p_var_xx + pow(p.x - p_mean.x, 2)
p_var_yy = p_var_yy + pow(p.y - p_mean.y, 2)
p_var_xy = p_var_xy + (p.x - p_mean.x) * (p.y - p_mean.y)
@@ -1267,8 +1247,8 @@ class pyBluePrintDirectedSquaresShader(StrokeShader):
p_new = p_fourth + vec_fourth * float(i - third)/float(fourth - third - 1)
if i == fourth - 1:
visible = 0
- it.getObject().setPoint(p_new)
- it.getObject().attribute().setVisible(visible)
+ it.getObject().point = p_new
+ it.getObject().attribute.visible = visible
if visible == 0:
visible = 1
i = i + 1
@@ -1291,14 +1271,14 @@ class pyModulateAlphaShader(StrokeShader):
def shade(self, stroke):
it = stroke.strokeVerticesBegin()
while it.isEnd() == 0:
- alpha = it.getObject().attribute().getAlpha()
- p = it.getObject().getPoint()
+ alpha = it.getObject().attribute.alpha
+ p = it.getObject().point
alpha = alpha * p.y / 400
if alpha < self.__min:
alpha = self.__min
elif alpha > self.__max:
alpha = self.__max
- it.getObject().attribute().setAlpha(alpha)
+ it.getObject().attribute.alpha = alpha
it.increment()
@@ -1311,9 +1291,9 @@ class pyDummyShader(StrokeShader):
it_end = stroke.strokeVerticesEnd()
while it.isEnd() == 0:
toto = it.castToInterface0DIterator()
- att = it.getObject().attribute()
- att.setColor(0.3, 0.4, 0.4)
- att.setThickness(0, 5)
+ att = it.getObject().attribute
+ att.color = (0.3, 0.4, 0.4)
+ att.thickness = (0, 5)
it.increment()
class pyDebugShader(StrokeShader):
diff --git a/release/scripts/freestyle/style_modules/sketchy_topology_broken.py b/release/scripts/freestyle/style_modules/sketchy_topology_broken.py
index 9ec0cffcfec..e51acb93fbc 100644
--- a/release/scripts/freestyle/style_modules/sketchy_topology_broken.py
+++ b/release/scripts/freestyle/style_modules/sketchy_topology_broken.py
@@ -32,58 +32,19 @@ from logical_operators import *
from ChainingIterators import *
from shaders import *
-## Backbone stretcher that leaves cusps intact to avoid cracks
-class pyBackboneStretcherNoCuspShader(StrokeShader):
- def __init__(self, l):
- StrokeShader.__init__(self)
- self._l = l
- def getName(self):
- return "pyBackboneStretcherNoCuspShader"
- def shade(self, stroke):
- it0 = stroke.strokeVerticesBegin()
- it1 = StrokeVertexIterator(it0)
- it1.increment()
- itn = stroke.strokeVerticesEnd()
- itn.decrement()
- itn_1 = StrokeVertexIterator(itn)
- itn_1.decrement()
- v0 = it0.getObject()
- v1 = it1.getObject()
- if((v0.getNature() & Nature.CUSP == 0) and (v1.getNature() & Nature.CUSP == 0)):
- p0 = v0.getPoint()
- p1 = v1.getPoint()
- d1 = p0-p1
- d1.normalize()
- newFirst = p0+d1*float(self._l)
- v0.setPoint(newFirst)
- else:
- print("got a v0 cusp")
- vn_1 = itn_1.getObject()
- vn = itn.getObject()
- if((vn.getNature() & Nature.CUSP == 0) and (vn_1.getNature() & Nature.CUSP == 0)):
- pn = vn.getPoint()
- pn_1 = vn_1.getPoint()
- dn = pn-pn_1
- dn.normalize()
- newLast = pn+dn*float(self._l)
- vn.setPoint(newLast)
- else:
- print("got a vn cusp")
-
-
Operators.select(QuantitativeInvisibilityUP1D(0))
## Chain 3 times each ViewEdge indpendantly from the
## initial objects topology
Operators.bidirectionalChain(pySketchyChainingIterator(3))
-shaders_list = [
- SamplingShader(4),
- SpatialNoiseShader(6, 120, 2, 1, 1),
- IncreasingThicknessShader(4, 10),
- SmoothingShader(100, 0.1, 0, 0.2, 0, 0, 0, 1),
- pyBackboneStretcherNoCuspShader(20),
- #ConstantColorShader(0.0,0.0,0.0)
- IncreasingColorShader(0.2,0.2,0.2,1,0.5,0.5,0.5,1),
- #IncreasingColorShader(1,0,0,1,0,1,0,1),
- TextureAssignerShader(4)
- ]
+shaders_list = [
+ SamplingShader(4),
+ SpatialNoiseShader(6, 120, 2, 1, 1),
+ IncreasingThicknessShader(4, 10),
+ SmoothingShader(100, 0.1, 0, 0.2, 0, 0, 0, 1),
+ pyBackboneStretcherNoCuspShader(20),
+ #ConstantColorShader(0.0,0.0,0.0)
+ IncreasingColorShader(0.2,0.2,0.2,1,0.5,0.5,0.5,1),
+ #IncreasingColorShader(1,0,0,1,0,1,0,1),
+ TextureAssignerShader(4)
+ ]
Operators.create(TrueUP1D(), shaders_list)
diff --git a/release/scripts/freestyle/style_modules/thickness_fof_depth_discontinuity.py b/release/scripts/freestyle/style_modules/thickness_fof_depth_discontinuity.py
index 21f6c7bdf35..8394aa1bde4 100644
--- a/release/scripts/freestyle/style_modules/thickness_fof_depth_discontinuity.py
+++ b/release/scripts/freestyle/style_modules/thickness_fof_depth_discontinuity.py
@@ -27,36 +27,14 @@
from freestyle_init import *
from logical_operators import *
-from ChainingIterators import *
from shaders import *
-class pyDepthDiscontinuityThicknessShader(StrokeShader):
- def __init__(self, min, max):
- StrokeShader.__init__(self)
- self.__min = float(min)
- self.__max = float(max)
- self.__func = ZDiscontinuityF0D()
- def getName(self):
- return "pyDepthDiscontinuityThicknessShader"
- def shade(self, stroke):
- it = stroke.strokeVerticesBegin()
- z_min=0.0
- z_max=1.0
- a = (self.__max - self.__min)/(z_max-z_min)
- b = (self.__min*z_max-self.__max*z_min)/(z_max-z_min)
- it = stroke.strokeVerticesBegin()
- while it.isEnd() == 0:
- z = self.__func(it.castToInterface0DIterator())
- thickness = a*z+b
- it.getObject().attribute().setThickness(thickness, thickness)
- it.increment()
-
Operators.select(QuantitativeInvisibilityUP1D(0))
Operators.bidirectionalChain(ChainSilhouetteIterator(), NotUP1D(QuantitativeInvisibilityUP1D(0)))
-shaders_list = [
- SamplingShader(1),
- ConstantThicknessShader(3),
- ConstantColorShader(0.0,0.0,0.0),
- pyDepthDiscontinuityThicknessShader(0.8, 6)
- ]
-Operators.create(TrueUP1D(), shaders_list) \ No newline at end of file
+shaders_list = [
+ SamplingShader(1),
+ ConstantThicknessShader(3),
+ ConstantColorShader(0.0, 0.0, 0.0),
+ pyDepthDiscontinuityThicknessShader(0.8, 6)
+ ]
+Operators.create(TrueUP1D(), shaders_list)
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index 01567b18142..87f7c3a6beb 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -483,6 +483,8 @@ Vec3f * Vec3f_ptr_from_PyObject( PyObject* obj ) {
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 )) )
@@ -494,6 +496,8 @@ Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ) {
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 )) )
@@ -502,53 +506,49 @@ Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ) {
}
Vec2f * Vec2f_ptr_from_Vector( PyObject* obj ) {
- PyObject *v;
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
return NULL;
- v = PyObject_GetAttrString(obj,"x");
- float x = PyFloat_AsDouble( v );
- Py_DECREF( v );
- v = PyObject_GetAttrString(obj,"y");
- float y = PyFloat_AsDouble( v );
- Py_DECREF( v );
-
- return new Vec2f(x,y);
+ float x = ((VectorObject *)obj)->vec[0];
+ float y = ((VectorObject *)obj)->vec[1];
+ return new Vec2f(x, y);
}
Vec3f * Vec3f_ptr_from_Vector( PyObject* obj ) {
- PyObject *v;
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
return NULL;
- v = PyObject_GetAttrString(obj,"x");
- float x = PyFloat_AsDouble( v );
- Py_DECREF( v );
- v = PyObject_GetAttrString(obj,"y");
- float y = PyFloat_AsDouble( v );
- Py_DECREF( v );
- v = PyObject_GetAttrString(obj,"z");
- float z = PyFloat_AsDouble( v );
- Py_DECREF( v );
-
+ float x = ((VectorObject *)obj)->vec[0];
+ float y = ((VectorObject *)obj)->vec[1];
+ float z = ((VectorObject *)obj)->vec[2];
return new Vec3f(x,y,z);
}
Vec3r * Vec3r_ptr_from_Vector( PyObject* obj ) {
- PyObject *v;
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
return NULL;
- v = PyObject_GetAttrString(obj,"x");
- double x = PyFloat_AsDouble( v );
- Py_DECREF( v );
- v = PyObject_GetAttrString(obj,"y");
- double y = PyFloat_AsDouble( v );
- Py_DECREF( v );
- v = PyObject_GetAttrString(obj,"z");
- double z = PyFloat_AsDouble( v );
- Py_DECREF( v );
-
+ real x = ((VectorObject *)obj)->vec[0];
+ real y = ((VectorObject *)obj)->vec[1];
+ real z = ((VectorObject *)obj)->vec[2];
return new Vec3r(x,y,z);
}
+Vec3f * Vec3f_ptr_from_Color( PyObject* obj ) {
+ 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);
+}
+
+Vec3r * Vec3r_ptr_from_Color( PyObject* obj ) {
+ 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);
+}
+
Vec2f * Vec2f_ptr_from_PyList( PyObject* obj ) {
if( !PyList_Check(obj) || PyList_Size(obj) != 2 )
return NULL;
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h
index ef5a64bde3f..178301262ff 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.h
+++ b/source/blender/freestyle/intern/python/BPy_Convert.h
@@ -128,6 +128,8 @@ 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 );
diff --git a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
index 11af30439cf..be8b87cd1bc 100644
--- a/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Interface0D.cpp
@@ -57,6 +57,8 @@ int Interface0D_Init( PyObject *module )
Py_INCREF( &TVertex_Type );
PyModule_AddObject(module, "TVertex", (PyObject *)&TVertex_Type);
+ StrokeVertex_mathutils_register_callback();
+
return 0;
}
diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
index 9e723d4236b..c1937bdf5f0 100644
--- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
+++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
@@ -18,6 +18,8 @@ int StrokeAttribute_Init( PyObject *module )
return -1;
Py_INCREF( &StrokeAttribute_Type );
PyModule_AddObject(module, "StrokeAttribute", (PyObject *)&StrokeAttribute_Type);
+
+ StrokeAttribute_mathutils_register_callback();
return 0;
}
@@ -132,122 +134,6 @@ static PyObject * StrokeAttribute___repr__(BPy_StrokeAttribute* self)
return PyUnicode_FromString( repr.str().c_str() );
}
-
-static char StrokeAttribute_getColorR___doc__[] =
-".. method:: getColorR()\n"
-"\n"
-" Returns the red component of the stroke color.\n"
-"\n"
-" :return: Red component of the stroke color.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getColorR( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getColorR() );
-}
-
-static char StrokeAttribute_getColorG___doc__[] =
-".. method:: getColorG()\n"
-"\n"
-" Returns the green component of the stroke color.\n"
-"\n"
-" :return: Green component of the stroke color.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getColorG( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getColorG() );
-}
-
-static char StrokeAttribute_getColorB___doc__[] =
-".. method:: getColorB()\n"
-"\n"
-" Returns the blue component of the stroke color.\n"
-"\n"
-" :return: Blue component of the stroke color.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getColorB( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getColorB() );
-}
-
-static char StrokeAttribute_getColorRGB___doc__[] =
-".. method:: getColorRGB()\n"
-"\n"
-" Returns the RGB components of the stroke color.\n"
-"\n"
-" :return: RGB components of the stroke color.\n"
-" :rtype: :class:`mathutils.Vector`\n";
-
-static PyObject *StrokeAttribute_getColorRGB( BPy_StrokeAttribute *self ) {
- Vec3f v( self->sa->getColorRGB() );
- return Vector_from_Vec3f( v );
-}
-
-static char StrokeAttribute_getAlpha___doc__[] =
-".. method:: getAlpha()\n"
-"\n"
-" Returns the alpha component of the stroke color.\n"
-"\n"
-" :return: Alpha component of the stroke color.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getAlpha( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getAlpha() );
-}
-
-static char StrokeAttribute_getThicknessR___doc__[] =
-".. method:: getThicknessR()\n"
-"\n"
-" Returns the thickness on the right of the vertex when following\n"
-" the stroke.\n"
-"\n"
-" :return: The thickness on the right of the vertex.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getThicknessR( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getThicknessR() );
-}
-
-static char StrokeAttribute_getThicknessL___doc__[] =
-".. method:: getThicknessL()\n"
-"\n"
-" Returns the thickness on the left of the vertex when following\n"
-" the stroke.\n"
-"\n"
-" :return: The thickness on the left of the vertex.\n"
-" :rtype: float\n";
-
-static PyObject *StrokeAttribute_getThicknessL( BPy_StrokeAttribute *self ) {
- return PyFloat_FromDouble( self->sa->getThicknessL() );
-}
-
-static char StrokeAttribute_getThicknessRL___doc__[] =
-".. method:: getThicknessRL()\n"
-"\n"
-" Returns the thickness on the right and on the left of the vertex\n"
-" when following the stroke.\n"
-"\n"
-" :return: A two-dimensional vector. The first value is the\n"
-" thickness on the right of the vertex when following the stroke,\n"
-" and the second one is the thickness on the left.\n"
-" :rtype: :class:`mathutils.Vector`\n";
-
-static PyObject *StrokeAttribute_getThicknessRL( BPy_StrokeAttribute *self ) {
- Vec2f v( self->sa->getThicknessRL() );
- return Vector_from_Vec2f( v );
-}
-
-static char StrokeAttribute_isVisible___doc__[] =
-".. method:: isVisible()\n"
-"\n"
-" Returns true if the StrokeVertex is visible, false otherwise.\n"
-"\n"
-" :return: True if the StrokeVertex is visible, false otherwise.\n"
-" :rtype: bool\n";
-
-static PyObject *StrokeAttribute_isVisible( BPy_StrokeAttribute *self ) {
- return PyBool_from_bool( self->sa->isVisible() );
-}
-
static char StrokeAttribute_getAttributeReal___doc__[] =
".. method:: getAttributeReal(iName)\n"
"\n"
@@ -367,142 +253,6 @@ static PyObject *StrokeAttribute_isAttributeAvailableVec3f( BPy_StrokeAttribute
return PyBool_from_bool( self->sa->isAttributeAvailableVec3f( attr ) );
}
-
-static char StrokeAttribute_setColor___doc__[] =
-".. method:: setColor(r, g, b)\n"
-"\n"
-" Sets the stroke color.\n"
-"\n"
-" :arg r: Red component of the stroke color.\n"
-" :type r: float\n"
-" :arg g: Green component of the stroke color.\n"
-" :type g: float\n"
-" :arg b: Blue component of the stroke color.\n"
-" :type b: float\n"
-"\n"
-".. method:: setColor(iRGB)\n"
-"\n"
-" Sets the stroke color.\n"
-"\n"
-" :arg iRGB: The new RGB values.\n"
-" :type iRGB: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n";
-
-static PyObject * StrokeAttribute_setColor( BPy_StrokeAttribute *self, PyObject *args ) {
- PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0 ;
-
- if(!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
- return NULL;
-
- if( obj1 && !obj2 && !obj3 ){
-
- Vec3f *v = Vec3f_ptr_from_PyObject(obj1);
- if( !v ) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)");
- return NULL;
- }
- self->sa->setColor( *v );
- delete v;
-
- } else if( obj1 && obj2 && obj3 ){
-
- self->sa->setColor( PyFloat_AsDouble(obj1),
- PyFloat_AsDouble(obj2),
- PyFloat_AsDouble(obj3) );
-
- } else {
- PyErr_SetString(PyExc_TypeError, "invalid arguments");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static char StrokeAttribute_setAlpha___doc__[] =
-".. method:: setAlpha(alpha)\n"
-"\n"
-" Sets the alpha component of the stroke color.\n"
-"\n"
-" :arg alpha: The new alpha value.\n"
-" :type alpha: float\n";
-
-static PyObject * StrokeAttribute_setAlpha( BPy_StrokeAttribute *self, PyObject *args ){
- float f = 0;
-
- if(!( PyArg_ParseTuple(args, "f", &f) ))
- return NULL;
-
- self->sa->setAlpha( f );
- Py_RETURN_NONE;
-}
-
-static char StrokeAttribute_setThickness___doc__[] =
-".. method:: setThickness(tr, tl)\n"
-"\n"
-" Sets the stroke thickness.\n"
-"\n"
-" :arg tr: The thickness on the right of the vertex when following\n"
-" the stroke.\n"
-" :type tr: float\n"
-" :arg tl: The thickness on the left of the vertex when following\n"
-" the stroke.\n"
-" :type tl: float\n"
-"\n"
-".. method:: setThickness(tRL)\n"
-"\n"
-" Sets the stroke thickness.\n"
-"\n"
-" :arg tRL: The thickness on the right and on the left of the vertex\n"
-" when following the stroke.\n"
-" :type tRL: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n";
-
-static PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *args ) {
- PyObject *obj1 = 0, *obj2 = 0;
-
- if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) ))
- return NULL;
-
- if( obj1 && !obj2 ){
-
- Vec2f *v = Vec2f_ptr_from_PyObject(obj1);
- if( !v ) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)");
- return NULL;
- }
- self->sa->setThickness( *v );
- delete v;
-
- } else if( obj1 && obj2 ){
-
- self->sa->setThickness( PyFloat_AsDouble(obj1),
- PyFloat_AsDouble(obj2) );
-
- } else {
- PyErr_SetString(PyExc_TypeError, "invalid arguments");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static char StrokeAttribute_setVisible___doc__[] =
-".. method:: setVisible(iVisible)\n"
-"\n"
-" Sets the visibility flag. True means the StrokeVertex is visible.\n"
-"\n"
-" :arg iVisible: True if the StrokeVertex is visible.\n"
-" :type iVisible: bool\n";
-
-static PyObject * StrokeAttribute_setVisible( BPy_StrokeAttribute *self, PyObject *args ) {
- PyObject *py_b;
-
- if(!( PyArg_ParseTuple(args, "O", &py_b) ))
- return NULL;
-
- self->sa->setVisible( bool_from_PyBool(py_b) );
-
- Py_RETURN_NONE;
-}
-
static char StrokeAttribute_setAttributeReal___doc__[] =
".. method:: setAttributeReal(iName, att)\n"
"\n"
@@ -586,31 +336,233 @@ static PyObject * StrokeAttribute_setAttributeVec3f( BPy_StrokeAttribute *self,
/*----------------------StrokeAttribute instance definitions ----------------------------*/
static PyMethodDef BPy_StrokeAttribute_methods[] = {
- {"getColorR", ( PyCFunction ) StrokeAttribute_getColorR, METH_NOARGS, StrokeAttribute_getColorR___doc__},
- {"getColorG", ( PyCFunction ) StrokeAttribute_getColorG, METH_NOARGS, StrokeAttribute_getColorG___doc__},
- {"getColorB", ( PyCFunction ) StrokeAttribute_getColorB, METH_NOARGS, StrokeAttribute_getColorB___doc__},
- {"getColorRGB", ( PyCFunction ) StrokeAttribute_getColorRGB, METH_NOARGS, StrokeAttribute_getColorRGB___doc__},
- {"getAlpha", ( PyCFunction ) StrokeAttribute_getAlpha, METH_NOARGS, StrokeAttribute_getAlpha___doc__},
- {"getThicknessR", ( PyCFunction ) StrokeAttribute_getThicknessR, METH_NOARGS, StrokeAttribute_getThicknessR___doc__},
- {"getThicknessL", ( PyCFunction ) StrokeAttribute_getThicknessL, METH_NOARGS, StrokeAttribute_getThicknessL___doc__},
- {"getThicknessRL", ( PyCFunction ) StrokeAttribute_getThicknessRL, METH_NOARGS, StrokeAttribute_getThicknessRL___doc__},
- {"isVisible", ( PyCFunction ) StrokeAttribute_isVisible, METH_NOARGS, StrokeAttribute_isVisible___doc__},
{"getAttributeReal", ( PyCFunction ) StrokeAttribute_getAttributeReal, METH_VARARGS, StrokeAttribute_getAttributeReal___doc__},
{"getAttributeVec2f", ( PyCFunction ) StrokeAttribute_getAttributeVec2f, METH_VARARGS, StrokeAttribute_getAttributeVec2f___doc__},
{"getAttributeVec3f", ( PyCFunction ) StrokeAttribute_getAttributeVec3f, METH_VARARGS, StrokeAttribute_getAttributeVec3f___doc__},
{"isAttributeAvailableReal", ( PyCFunction ) StrokeAttribute_isAttributeAvailableReal, METH_VARARGS, StrokeAttribute_isAttributeAvailableReal___doc__},
{"isAttributeAvailableVec2f", ( PyCFunction ) StrokeAttribute_isAttributeAvailableVec2f, METH_VARARGS, StrokeAttribute_isAttributeAvailableVec2f___doc__},
{"isAttributeAvailableVec3f", ( PyCFunction ) StrokeAttribute_isAttributeAvailableVec3f, METH_VARARGS, StrokeAttribute_isAttributeAvailableVec3f___doc__},
- {"setColor", ( PyCFunction ) StrokeAttribute_setColor, METH_VARARGS, StrokeAttribute_setColor___doc__},
- {"setAlpha", ( PyCFunction ) StrokeAttribute_setAlpha, METH_VARARGS, StrokeAttribute_setAlpha___doc__},
- {"setThickness", ( PyCFunction ) StrokeAttribute_setThickness, METH_VARARGS, StrokeAttribute_setThickness___doc__},
- {"setVisible", ( PyCFunction ) StrokeAttribute_setVisible, METH_VARARGS, StrokeAttribute_setVisible___doc__},
{"setAttributeReal", ( PyCFunction ) StrokeAttribute_setAttributeReal, METH_VARARGS, StrokeAttribute_setAttributeReal___doc__},
{"setAttributeVec2f", ( PyCFunction ) StrokeAttribute_setAttributeVec2f, METH_VARARGS, StrokeAttribute_setAttributeVec2f___doc__},
{"setAttributeVec3f", ( PyCFunction ) StrokeAttribute_setAttributeVec3f, METH_VARARGS, StrokeAttribute_setAttributeVec3f___doc__},
{NULL, NULL, 0, NULL}
};
+/*----------------------mathutils callbacks ----------------------------*/
+
+/* subtype */
+#define MATHUTILS_SUBTYPE_COLOR 1
+#define MATHUTILS_SUBTYPE_THICKNESS 2
+
+static int StrokeAttribute_mathutils_check(BaseMathObject *bmo)
+{
+ if (!BPy_StrokeAttribute_Check(bmo->cb_user))
+ return -1;
+ return 0;
+}
+
+static int StrokeAttribute_mathutils_get(BaseMathObject *bmo, int subtype)
+{
+ BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user;
+ switch (subtype) {
+ case MATHUTILS_SUBTYPE_COLOR:
+ bmo->data[0] = self->sa->getColorR();
+ bmo->data[1] = self->sa->getColorG();
+ bmo->data[2] = self->sa->getColorB();
+ break;
+ case MATHUTILS_SUBTYPE_THICKNESS:
+ bmo->data[0] = self->sa->getThicknessR();
+ bmo->data[1] = self->sa->getThicknessL();
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int StrokeAttribute_mathutils_set(BaseMathObject *bmo, int subtype)
+{
+ BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user;
+ switch (subtype) {
+ case MATHUTILS_SUBTYPE_COLOR:
+ self->sa->setColor(bmo->data[0], bmo->data[1], bmo->data[1]);
+ break;
+ case MATHUTILS_SUBTYPE_THICKNESS:
+ self->sa->setThickness(bmo->data[0], bmo->data[1]);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int StrokeAttribute_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
+{
+ BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user;
+ switch (subtype) {
+ case MATHUTILS_SUBTYPE_COLOR:
+ switch (index) {
+ case 0: bmo->data[0] = self->sa->getColorR(); break;
+ case 1: bmo->data[1] = self->sa->getColorG(); break;
+ case 2: bmo->data[2] = self->sa->getColorB(); break;
+ default:
+ return -1;
+ }
+ break;
+ case MATHUTILS_SUBTYPE_THICKNESS:
+ switch (index) {
+ case 0: bmo->data[0] = self->sa->getThicknessR(); break;
+ case 1: bmo->data[1] = self->sa->getThicknessL(); break;
+ default:
+ return -1;
+ }
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int StrokeAttribute_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
+{
+ BPy_StrokeAttribute *self = (BPy_StrokeAttribute *)bmo->cb_user;
+ switch (subtype) {
+ case MATHUTILS_SUBTYPE_COLOR:
+ {
+ float r = (index == 0) ? bmo->data[0] : self->sa->getColorR();
+ float g = (index == 1) ? bmo->data[1] : self->sa->getColorG();
+ float b = (index == 2) ? bmo->data[2] : self->sa->getColorB();
+ self->sa->setColor(r, g, b);
+ }
+ break;
+ case MATHUTILS_SUBTYPE_THICKNESS:
+ {
+ float tr = (index == 0) ? bmo->data[0] : self->sa->getThicknessR();
+ float tl = (index == 1) ? bmo->data[1] : self->sa->getThicknessL();
+ self->sa->setThickness(tr, tl);
+ }
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static Mathutils_Callback StrokeAttribute_mathutils_cb = {
+ StrokeAttribute_mathutils_check,
+ StrokeAttribute_mathutils_get,
+ StrokeAttribute_mathutils_set,
+ StrokeAttribute_mathutils_get_index,
+ StrokeAttribute_mathutils_set_index
+};
+
+static unsigned char StrokeAttribute_mathutils_cb_index = -1;
+
+void StrokeAttribute_mathutils_register_callback()
+{
+ StrokeAttribute_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeAttribute_mathutils_cb);
+}
+
+/*----------------------StrokeAttribute get/setters ----------------------------*/
+
+PyDoc_STRVAR(StrokeAttribute_alpha_doc,
+"Alpha component of the stroke color.\n"
+"\n"
+":type: float"
+);
+
+static PyObject *StrokeAttribute_alpha_get(BPy_StrokeAttribute *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->sa->getAlpha());
+}
+
+static int StrokeAttribute_alpha_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
+ PyErr_SetString(PyExc_TypeError, "value must be a number");
+ return -1;
+ }
+ self->sa->setAlpha(scalar);
+ return 0;
+}
+
+PyDoc_STRVAR(StrokeAttribute_color_doc,
+"RGB components of the stroke color.\n"
+"\n"
+":type: mathutils.Color"
+);
+
+static PyObject *StrokeAttribute_color_get(BPy_StrokeAttribute *self, void *UNUSED(closure))
+{
+ return Color_CreatePyObject_cb((PyObject *)self, StrokeAttribute_mathutils_cb_index, MATHUTILS_SUBTYPE_COLOR);
+}
+
+static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
+{
+ Vec3f *v = Vec3f_ptr_from_PyObject(value);
+ if (!v) {
+ PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
+ return -1;
+ }
+ self->sa->setColor(v->x(), v->y(), v->z());
+ return 0;
+}
+
+PyDoc_STRVAR(StrokeAttribute_thickness_doc,
+"Right and left components of the stroke thickness.\n"
+"The right (left) component is the thickness on the right (left) of the vertex\n"
+"when following the stroke.\n"
+"\n"
+":type: mathutils.Vector"
+);
+
+static PyObject *StrokeAttribute_thickness_get(BPy_StrokeAttribute *self, void *UNUSED(closure))
+{
+ return Vector_CreatePyObject_cb((PyObject *)self, 2, StrokeAttribute_mathutils_cb_index, MATHUTILS_SUBTYPE_THICKNESS);
+}
+
+static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
+{
+ Vec2f *v = Vec2f_ptr_from_PyObject(value);
+ if (!v) {
+ PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
+ return -1;
+ }
+ self->sa->setThickness(v->x(), v->y());
+ return 0;
+}
+
+PyDoc_STRVAR(StrokeAttribute_visible_doc,
+"visible component of the stroke color.\n"
+"\n"
+":type: float"
+);
+
+static PyObject *StrokeAttribute_visible_get(BPy_StrokeAttribute *self, void *UNUSED(closure))
+{
+ return PyBool_from_bool(self->sa->isVisible());
+}
+
+static int StrokeAttribute_visible_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
+ PyErr_SetString(PyExc_TypeError, "value must be a number");
+ return -1;
+ }
+ self->sa->setVisible(scalar);
+ return 0;
+}
+
+static PyGetSetDef BPy_StrokeAttribute_getseters[] = {
+ {(char *)"alpha", (getter)StrokeAttribute_alpha_get, (setter)StrokeAttribute_alpha_set, (char *)StrokeAttribute_alpha_doc, NULL},
+ {(char *)"color", (getter)StrokeAttribute_color_get, (setter)StrokeAttribute_color_set, (char *)StrokeAttribute_color_doc, NULL},
+ {(char *)"thickness", (getter)StrokeAttribute_thickness_get, (setter)StrokeAttribute_thickness_set, (char *)StrokeAttribute_thickness_doc, NULL},
+ {(char *)"visible", (getter)StrokeAttribute_visible_get, (setter)StrokeAttribute_visible_set, (char *)StrokeAttribute_visible_doc, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
/*-----------------------BPy_StrokeAttribute type definition ------------------------------*/
PyTypeObject StrokeAttribute_Type = {
@@ -643,7 +595,7 @@ PyTypeObject StrokeAttribute_Type = {
0, /* tp_iternext */
BPy_StrokeAttribute_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ BPy_StrokeAttribute_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h
index 51e18c0a96f..c108ed7bf04 100644
--- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h
+++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.h
@@ -25,6 +25,7 @@ typedef struct {
/*---------------------------Python BPy_StrokeAttribute visible prototypes-----------*/
int StrokeAttribute_Init( PyObject *module );
+void StrokeAttribute_mathutils_register_callback();
///////////////////////////////////////////////////////////////////////////////////////////
diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
index 80b9defd95e..3d7a29a540d 100644
--- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
+++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
@@ -1,5 +1,6 @@
#include "BPy_StrokeVertex.h"
+#include "../../BPy_Freestyle.h"
#include "../../BPy_Convert.h"
#include "../../BPy_StrokeAttribute.h"
#include "../../Interface0D/BPy_SVertex.h"
@@ -8,6 +9,8 @@
extern "C" {
#endif
+#include "../../../python/mathutils/mathutils.h" /* for Vector callbacks */
+
///////////////////////////////////////////////////////////////////////////////////////////
//------------------------INSTANCE METHODS ----------------------------------
@@ -108,247 +111,187 @@ static int StrokeVertex___init__(BPy_StrokeVertex *self, PyObject *args, PyObjec
return 0;
}
-static char StrokeVertex_x___doc__[] =
-".. method:: x()\n"
-"\n"
-" Returns the 2D point X coordinate.\n"
-"\n"
-" :return: The X coordinate.\n"
-" :rtype: float\n";
-
-static PyObject * StrokeVertex_x( BPy_StrokeVertex *self ) {
- return PyFloat_FromDouble( self->sv->x() );
-}
-
-static char StrokeVertex_y___doc__[] =
-".. method:: y()\n"
-"\n"
-" Returns the 2D point Y coordinate.\n"
-"\n"
-" :return: The Y coordinate.\n"
-" :rtype: float\n";
+// real operator[] (const int i) const
+// real & operator[] (const int i)
-static PyObject * StrokeVertex_y( BPy_StrokeVertex *self ) {
- return PyFloat_FromDouble( self->sv->y() );
-}
+/*----------------------StrokeVertex instance definitions ----------------------------*/
+static PyMethodDef BPy_StrokeVertex_methods[] = {
+ {NULL, NULL, 0, NULL}
+};
-static char StrokeVertex_getPoint___doc__[] =
-".. method:: getPoint()\n"
-"\n"
-" Returns the 2D point coordinates as a two-dimensional vector.\n"
-"\n"
-" :return: The 2D coordinates.\n"
-" :rtype: :class:`mathutils.Vector`\n";
+/*----------------------mathutils callbacks ----------------------------*/
-static PyObject * StrokeVertex_getPoint( BPy_StrokeVertex *self ) {
- Vec2f v( self->sv->getPoint() );
- return Vector_from_Vec2f( v );
+static int StrokeVertex_mathutils_check(BaseMathObject *bmo)
+{
+ if (!BPy_StrokeVertex_Check(bmo->cb_user))
+ return -1;
+ return 0;
}
-static char StrokeVertex_attribute___doc__[] =
-".. method:: attribute()\n"
-"\n"
-" Returns the StrokeAttribute for this StrokeVertex.\n"
-"\n"
-" :return: The StrokeAttribute object.\n"
-" :rtype: :class:`StrokeAttribute`\n";
-
-static PyObject * StrokeVertex_attribute( BPy_StrokeVertex *self ) {
- return BPy_StrokeAttribute_from_StrokeAttribute( self->sv->attribute() );
+static int StrokeVertex_mathutils_get(BaseMathObject *bmo, int subtype)
+{
+ BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
+ bmo->data[0] = (float)self->sv->x();
+ bmo->data[1] = (float)self->sv->y();
+ return 0;
}
-static char StrokeVertex_curvilinearAbscissa___doc__[] =
-".. method:: curvilinearAbscissa()\n"
-"\n"
-" Returns the curvilinear abscissa.\n"
-"\n"
-" :return: The curvilinear abscissa.\n"
-" :rtype: float\n";
-
-static PyObject * StrokeVertex_curvilinearAbscissa( BPy_StrokeVertex *self ) {
- return PyFloat_FromDouble( self->sv->curvilinearAbscissa() );
+static int StrokeVertex_mathutils_set(BaseMathObject *bmo, int subtype)
+{
+ BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
+ self->sv->setX((real)bmo->data[0]);
+ self->sv->setY((real)bmo->data[1]);
+ return 0;
}
-static char StrokeVertex_strokeLength___doc__[] =
-".. method:: strokeLength()\n"
-"\n"
-" Returns the length of the Stroke to which this StrokeVertex belongs\n"
-"\n"
-" :return: The stroke length.\n"
-" :rtype: float\n";
-
-static PyObject * StrokeVertex_strokeLength( BPy_StrokeVertex *self ) {
- return PyFloat_FromDouble( self->sv->strokeLength() );
+static int StrokeVertex_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
+{
+ BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
+ switch (index) {
+ case 0: bmo->data[0] = (float)self->sv->x(); break;
+ case 1: bmo->data[1] = (float)self->sv->y(); break;
+ default:
+ return -1;
+ }
+ return 0;
}
-static char StrokeVertex_u___doc__[] =
-".. method:: u()\n"
-"\n"
-" Returns the curvilinear abscissa of this StrokeVertex in the Stroke\n"
-"\n"
-" :return: The curvilinear abscissa.\n"
-" :rtype: float\n";
-
-static PyObject * StrokeVertex_u( BPy_StrokeVertex *self ) {
- return PyFloat_FromDouble( self->sv->u() );
+static int StrokeVertex_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
+{
+ BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
+ switch (index) {
+ case 0: self->sv->setX((real)bmo->data[0]); break;
+ case 1: self->sv->setY((real)bmo->data[1]); break;
+ default:
+ return -1;
+ }
+ return 0;
}
-static char StrokeVertex_setX___doc__[] =
-".. method:: setX(x)\n"
-"\n"
-" Sets the 2D point X coordinate.\n"
-"\n"
-" :arg x: The X coordinate.\n"
-" :type x: float\n";
-
-static PyObject *StrokeVertex_setX( BPy_StrokeVertex *self , PyObject *args) {
- double r;
-
- if(!( PyArg_ParseTuple(args, "d", &r) ))
- return NULL;
+static Mathutils_Callback StrokeVertex_mathutils_cb = {
+ StrokeVertex_mathutils_check,
+ StrokeVertex_mathutils_get,
+ StrokeVertex_mathutils_set,
+ StrokeVertex_mathutils_get_index,
+ StrokeVertex_mathutils_set_index
+};
- self->sv->setX( r );
+static unsigned char StrokeVertex_mathutils_cb_index = -1;
- Py_RETURN_NONE;
+void StrokeVertex_mathutils_register_callback()
+{
+ StrokeVertex_mathutils_cb_index = Mathutils_RegisterCallback(&StrokeVertex_mathutils_cb);
}
-static char StrokeVertex_setY___doc__[] =
-".. method:: setY(y)\n"
-"\n"
-" Sets the 2D point Y coordinate.\n"
-"\n"
-" :arg y: The Y coordinate.\n"
-" :type y: float\n";
-
-static PyObject *StrokeVertex_setY( BPy_StrokeVertex *self , PyObject *args) {
- double r;
+/*----------------------StrokeVertex get/setters ----------------------------*/
- if(!( PyArg_ParseTuple(args, "d", &r) ))
- return NULL;
+PyDoc_STRVAR(StrokeVertex_attribute_doc,
+"StrokeAttribute for this StrokeVertex.\n"
+"\n"
+":type: StrokeAttribute"
+);
- self->sv->setY( r );
+static PyObject *StrokeVertex_attribute_get(BPy_StrokeVertex *self, void *UNUSED(closure))
+{
+ return BPy_StrokeAttribute_from_StrokeAttribute(self->sv->attribute());
+}
- Py_RETURN_NONE;
+static int StrokeVertex_attribute_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
+{
+ if (!BPy_StrokeAttribute_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "value must be a StrokeAttribute object");
+ return -1;
+ }
+ self->sv->setAttribute(*(((BPy_StrokeAttribute *)value)->sa));
+ return 0;
}
-static char StrokeVertex_setPoint___doc__[] =
-".. method:: setPoint(x, y)\n"
-"\n"
-" Sets the 2D point X and Y coordinates.\n"
-"\n"
-" :arg x: The X coordinate.\n"
-" :type x: float\n"
-" :arg y: The Y coordinate.\n"
-" :type y: float\n"
+PyDoc_STRVAR(StrokeVertex_curvilinear_abscissa_doc,
+"Curvilinear abscissa of this StrokeVertex in the Stroke.\n"
"\n"
-".. method:: setPoint(p)\n"
-"\n"
-" Sets the 2D point X and Y coordinates.\n"
-"\n"
-" :arg p: A two-dimensional vector.\n"
-" :type p: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n";
+":type: float"
+);
-static PyObject *StrokeVertex_setPoint( BPy_StrokeVertex *self , PyObject *args) {
- PyObject *obj1 = 0, *obj2 = 0;
+static PyObject *StrokeVertex_curvilinear_abscissa_get(BPy_StrokeVertex *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->sv->curvilinearAbscissa());
+}
- if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) ))
- return NULL;
-
- if( obj1 && !obj2 ){
- Vec2f *v = Vec2f_ptr_from_PyObject(obj1);
- if( !v ) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)");
- return NULL;
- }
- self->sv->setPoint( *v );
- delete v;
- } else if( PyFloat_Check(obj1) && obj2 && PyFloat_Check(obj2) ){
- self->sv->setPoint( PyFloat_AsDouble(obj1), PyFloat_AsDouble(obj2) );
- } else {
- PyErr_SetString(PyExc_TypeError, "invalid arguments");
- return NULL;
+static int StrokeVertex_curvilinear_abscissa_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
+ PyErr_SetString(PyExc_TypeError, "value must be a number");
+ return -1;
}
-
- Py_RETURN_NONE;
+ self->sv->setCurvilinearAbscissa(scalar);
+ return 0;
}
-static char StrokeVertex_setAttribute___doc__[] =
-".. method:: setAttribute(iAttribute)\n"
-"\n"
-" Sets the attribute.\n"
+PyDoc_STRVAR(StrokeVertex_point_doc,
+"2D point coordinates.\n"
"\n"
-" :arg iAttribute: A StrokeAttribute object.\n"
-" :type iAttribute: :class:`StrokeAttribute`\n";
-
-static PyObject *StrokeVertex_setAttribute( BPy_StrokeVertex *self , PyObject *args) {
- PyObject *py_sa;
-
- if(!( PyArg_ParseTuple(args, "O!", &StrokeAttribute_Type, &py_sa) ))
- return NULL;
+":type: mathutils.Vector"
+);
- self->sv->setAttribute(*( ((BPy_StrokeAttribute *) py_sa)->sa ));
+static PyObject *StrokeVertex_point_get(BPy_StrokeVertex *self, void *UNUSED(closure))
+{
+ return Vector_CreatePyObject_cb((PyObject *)self, 2, StrokeVertex_mathutils_cb_index, 0);
+}
- Py_RETURN_NONE;
+static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
+{
+ Vec2f *v = Vec2f_ptr_from_PyObject(value);
+ if (!v) {
+ PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
+ return -1;
+ }
+ self->sv->setX(v->x());
+ self->sv->setY(v->y());
+ return 0;
}
-static char StrokeVertex_setCurvilinearAbscissa___doc__[] =
-".. method:: setCurvilinearAbscissa(iAbscissa)\n"
-"\n"
-" Sets the curvilinear abscissa of this StrokeVertex in the Stroke\n"
+PyDoc_STRVAR(StrokeVertex_stroke_length_doc,
+"Stroke length (it is only a value retained by the StrokeVertex,\n"
+"and it won't change the real stroke length).\n"
"\n"
-" :arg iAbscissa: The curvilinear abscissa.\n"
-" :type iAbscissa: float\n";
+":type: float"
+);
-static PyObject *StrokeVertex_setCurvilinearAbscissa( BPy_StrokeVertex *self , PyObject *args) {
- double r;
-
- if(!( PyArg_ParseTuple(args, "d", &r) ))
- return NULL;
-
- self->sv->setCurvilinearAbscissa( r );
+static PyObject *StrokeVertex_stroke_length_get(BPy_StrokeVertex *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->sv->strokeLength());
+}
- Py_RETURN_NONE;
+static int StrokeVertex_stroke_length_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
+ PyErr_SetString(PyExc_TypeError, "value must be a number");
+ return -1;
+ }
+ self->sv->setStrokeLength(scalar);
+ return 0;
}
-static char StrokeVertex_setStrokeLength___doc__[] =
-".. method:: setStrokeLength(iLength)\n"
+PyDoc_STRVAR(StrokeVertex_u_doc,
+"Curvilinear abscissa of this StrokeVertex in the Stroke.\n"
"\n"
-" Sets the stroke length (it is only a value retained by the\n"
-" StrokeVertex, and it won't change the real stroke length).\n"
-"\n"
-" :arg iLength: The stroke length.\n"
-" :type iLength: float\n";
-
-static PyObject *StrokeVertex_setStrokeLength( BPy_StrokeVertex *self , PyObject *args) {
- double r;
+":type: float"
+);
- if(!( PyArg_ParseTuple(args, "d", &r) ))
- return NULL;
-
- self->sv->setStrokeLength( r );
-
- Py_RETURN_NONE;
+static PyObject *StrokeVertex_u_get(BPy_StrokeVertex *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->sv->u());
}
-// real operator[] (const int i) const
-// real & operator[] (const int i)
-
-/*----------------------StrokeVertex instance definitions ----------------------------*/
-static PyMethodDef BPy_StrokeVertex_methods[] = {
- {"x", ( PyCFunction ) StrokeVertex_x, METH_NOARGS, StrokeVertex_x___doc__},
- {"y", ( PyCFunction ) StrokeVertex_y, METH_NOARGS, StrokeVertex_y___doc__},
- {"getPoint", ( PyCFunction ) StrokeVertex_getPoint, METH_NOARGS, StrokeVertex_getPoint___doc__},
- {"attribute", ( PyCFunction ) StrokeVertex_attribute, METH_NOARGS, StrokeVertex_attribute___doc__},
- {"curvilinearAbscissa", ( PyCFunction ) StrokeVertex_curvilinearAbscissa, METH_NOARGS, StrokeVertex_curvilinearAbscissa___doc__},
- {"strokeLength", ( PyCFunction ) StrokeVertex_strokeLength, METH_NOARGS, StrokeVertex_strokeLength___doc__},
- {"u", ( PyCFunction ) StrokeVertex_u, METH_NOARGS, StrokeVertex_u___doc__},
- {"setX", ( PyCFunction ) StrokeVertex_setX, METH_VARARGS, StrokeVertex_setX___doc__},
- {"setY", ( PyCFunction ) StrokeVertex_setY, METH_VARARGS, StrokeVertex_setY___doc__},
- {"setPoint", ( PyCFunction ) StrokeVertex_setPoint, METH_VARARGS, StrokeVertex_setPoint___doc__},
- {"setAttribute", ( PyCFunction ) StrokeVertex_setAttribute, METH_VARARGS, StrokeVertex_setAttribute___doc__},
- {"setCurvilinearAbscissa", ( PyCFunction ) StrokeVertex_setCurvilinearAbscissa, METH_VARARGS, StrokeVertex_setCurvilinearAbscissa___doc__},
- {"setStrokeLength", ( PyCFunction ) StrokeVertex_setStrokeLength, METH_VARARGS, StrokeVertex_setStrokeLength___doc__},
- {NULL, NULL, 0, NULL}
+static PyGetSetDef BPy_StrokeVertex_getseters[] = {
+ {(char *)"attribute", (getter)StrokeVertex_attribute_get, (setter)StrokeVertex_attribute_set, (char *)StrokeVertex_attribute_doc, NULL},
+ {(char *)"curvilinear_abscissa", (getter)StrokeVertex_curvilinear_abscissa_get, (setter)StrokeVertex_curvilinear_abscissa_set, (char *)StrokeVertex_curvilinear_abscissa_doc, NULL},
+ {(char *)"point", (getter)StrokeVertex_point_get, (setter)StrokeVertex_point_set, (char *)StrokeVertex_point_doc, NULL},
+ {(char *)"stroke_length", (getter)StrokeVertex_stroke_length_get, (setter)StrokeVertex_stroke_length_set, (char *)StrokeVertex_stroke_length_doc, NULL},
+ {(char *)"u", (getter)StrokeVertex_u_get, (setter)NULL, (char *)StrokeVertex_u_doc, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
/*-----------------------BPy_StrokeVertex type definition ------------------------------*/
@@ -382,7 +325,7 @@ PyTypeObject StrokeVertex_Type = {
0, /* tp_iternext */
BPy_StrokeVertex_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ BPy_StrokeVertex_getseters, /* tp_getset */
&CurvePoint_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h
index 2a84e2480f0..a1cf3e80662 100644
--- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h
+++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h
@@ -22,6 +22,10 @@ typedef struct {
StrokeVertex *sv;
} BPy_StrokeVertex;
+/*---------------------------Python BPy_StrokeVertex visible prototypes-----------*/
+
+void StrokeVertex_mathutils_register_callback();
+
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus