
This allows users to test the types of those objects that are returned by API functions, by means of usual Python idioms such as "type(I) is T" and "isinstance(I, T)". * Removed all occurrences of ViewVertex::castToTVertex() in the following modules and rewrote the code segments using it by means of the "type(I) is T" idiom mentioned above: ChainingIterators.py PredicatesU1D.py * Replaced all occurrences of vector.Vec2, vector.Vec3, Vec2f and Vec3f by Blender.Mathutils.Vector in the following modules: anisotropic_diffusion.py Functions0D.py shaders.py sketchy_topology_broken.py * shaders.py: Fixed NameError's concerning math.pow(). * shaders.py: Added a Python equivalent of getFEdge function, defined in source\blender\freestyle\intern\view_map\Functions0D.cpp as follows: FEdge* Functions0D::getFEdge(Interface0D& it1, Interface0D& it2) { return it1.getFEdge(it2); } * shaders.py: Replaced fe.qi() by fe.viewedge().qi(). * contour.py: Fixed the import statement for freestyle_init.py.
82 lines
2.7 KiB
Python
Executable File
82 lines
2.7 KiB
Python
Executable File
from freestyle_init import *
|
|
|
|
|
|
class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble):
|
|
def getName(self):
|
|
return "InverseCurvature2DAngleF0D"
|
|
|
|
def __call__(self, inter):
|
|
func = Curvature2DAngleF0D()
|
|
c = func(inter)
|
|
return (3.1415 - c)
|
|
|
|
class pyCurvilinearLengthF0D(UnaryFunction0DDouble):
|
|
def getName(self):
|
|
return "CurvilinearLengthF0D"
|
|
|
|
def __call__(self, inter):
|
|
i0d = inter.getObject()
|
|
s = i0d.getExactTypeName()
|
|
if (string.find(s, "CurvePoint") == -1):
|
|
print "CurvilinearLengthF0D: not implemented yet for %s" % (s)
|
|
return -1
|
|
cp = castToCurvePoint(i0d)
|
|
return cp.t2d()
|
|
|
|
## estimate anisotropy of density
|
|
class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
|
|
def __init__(self,level):
|
|
UnaryFunction0DDouble.__init__(self)
|
|
self.IsoDensity = ReadCompleteViewMapPixelF0D(level)
|
|
self.d0Density = ReadSteerableViewMapPixelF0D(0, level)
|
|
self.d1Density = ReadSteerableViewMapPixelF0D(1, level)
|
|
self.d2Density = ReadSteerableViewMapPixelF0D(2, level)
|
|
self.d3Density = ReadSteerableViewMapPixelF0D(3, level)
|
|
def getName(self):
|
|
return "pyDensityAnisotropyF0D"
|
|
def __call__(self, inter):
|
|
c_iso = self.IsoDensity(inter)
|
|
c_0 = self.d0Density(inter)
|
|
c_1 = self.d1Density(inter)
|
|
c_2 = self.d2Density(inter)
|
|
c_3 = self.d3Density(inter)
|
|
cMax = max( max(c_0,c_1), max(c_2,c_3))
|
|
cMin = min( min(c_0,c_1), min(c_2,c_3))
|
|
if ( c_iso == 0 ):
|
|
v = 0
|
|
else:
|
|
v = (cMax-cMin)/c_iso
|
|
return (v)
|
|
|
|
## Returns the gradient vector for a pixel
|
|
## l
|
|
## the level at which one wants to compute the gradient
|
|
class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
|
|
def __init__(self, l):
|
|
UnaryFunction0DVec2f.__init__(self)
|
|
self._l = l
|
|
self._step = pow(2,self._l)
|
|
def getName(self):
|
|
return "pyViewMapGradientVectorF0D"
|
|
def __call__(self, iter):
|
|
p = iter.getObject().getPoint2D()
|
|
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x()+self._step), int(p.y()))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
|
|
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
|
|
return Vector(gx, gy)
|
|
|
|
class pyViewMapGradientNormF0D(UnaryFunction0DDouble):
|
|
def __init__(self, l):
|
|
UnaryFunction0DDouble.__init__(self)
|
|
self._l = l
|
|
self._step = pow(2,self._l)
|
|
def getName(self):
|
|
return "pyViewMapGradientNormF0D"
|
|
def __call__(self, iter):
|
|
p = iter.getObject().getPoint2D()
|
|
gx = ReadCompleteViewMapPixelCF(self._l, int(p.x()+self._step), int(p.y()))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
|
|
gy = ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()+self._step))- ReadCompleteViewMapPixelCF(self._l, int(p.x()), int(p.y()))
|
|
grad = Vector(gx, gy)
|
|
return grad.length
|
|
|
|
|