diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-28 19:16:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-28 19:20:59 +0400 |
commit | a283b099b13a24b0361f9c063caa9426a70de1e4 (patch) | |
tree | 54fbe71e5d7837a4fc782e83e0bfb3aa95efd38a /release | |
parent | deab0d10402b59652ec5e19836856eb238af863e (diff) |
Code cleanup: pep8
Diffstat (limited to 'release')
8 files changed, 221 insertions, 42 deletions
diff --git a/release/scripts/freestyle/modules/freestyle/chainingiterators.py b/release/scripts/freestyle/modules/freestyle/chainingiterators.py index aad82d16bd2..4b2cc9a832c 100644 --- a/release/scripts/freestyle/modules/freestyle/chainingiterators.py +++ b/release/scripts/freestyle/modules/freestyle/chainingiterators.py @@ -54,8 +54,10 @@ class pyChainSilhouetteIterator(ChainingIterator): """ def __init__(self, stayInSelection=True): ChainingIterator.__init__(self, stayInSelection, True, None, True) + def init(self): pass + def traverse(self, iter): winner = None it = AdjacencyIterator(iter) @@ -110,8 +112,10 @@ class pyChainSilhouetteGenericIterator(ChainingIterator): def __init__(self, stayInSelection=True, stayInUnvisited=True): ChainingIterator.__init__(self, stayInSelection, stayInUnvisited, None, True) + def init(self): pass + def traverse(self, iter): winner = None it = AdjacencyIterator(iter) @@ -161,9 +165,11 @@ class pyExternalContourChainingIterator(ChainingIterator): def __init__(self): ChainingIterator.__init__(self, False, True, None, True) self._isExternalContour = ExternalContourUP1D() + def init(self): self._nEdges = 0 self._isInSelection = 1 + def checkViewEdge(self, ve, orientation): if orientation != 0: vertex = ve.second_svertex() @@ -178,6 +184,7 @@ class pyExternalContourChainingIterator(ChainingIterator): if bpy.app.debug_freestyle: print("pyExternalContourChainingIterator : didn't find next edge") return False + def traverse(self, iter): winner = None it = AdjacencyIterator(iter) @@ -218,8 +225,10 @@ class pySketchyChainSilhouetteIterator(ChainingIterator): ChainingIterator.__init__(self, stayInSelection, False, None, True) self._timeStamp = CF.get_time_stamp()+nRounds self._nRounds = nRounds + def init(self): self._timeStamp = CF.get_time_stamp()+self._nRounds + def traverse(self, iter): winner = None it = AdjacencyIterator(iter) @@ -277,8 +286,10 @@ class pySketchyChainingIterator(ChainingIterator): ChainingIterator.__init__(self, stayInSelection, False, None, True) self._timeStamp = CF.get_time_stamp()+nRounds self._nRounds = nRounds + def init(self): self._timeStamp = CF.get_time_stamp()+self._nRounds + def traverse(self, iter): winner = None found = False @@ -316,10 +327,12 @@ class pyFillOcclusionsRelativeChainingIterator(ChainingIterator): ChainingIterator.__init__(self, False, True, None, True) self._length = 0 self._percent = float(percent) + def init(self): # A chain's length should preferably be evaluated only once. # Therefore, the chain length is reset here. self._length = 0 + def traverse(self, iter): winner = None @@ -414,8 +427,10 @@ class pyFillOcclusionsAbsoluteChainingIterator(ChainingIterator): def __init__(self, length): ChainingIterator.__init__(self, False, True, None, True) self._length = float(length) + def init(self): pass + def traverse(self, iter): winner = None winnerOrientation = False @@ -481,11 +496,13 @@ class pyFillOcclusionsAbsoluteAndRelativeChainingIterator(ChainingIterator): self._length = 0 self._absLength = l self._percent = float(percent) + def init(self): # each time we're evaluating a chain length # we try to do it once. Thus we reinit # the chain length here: self._length = 0 + def traverse(self, iter): winner = None winnerOrientation = False @@ -581,10 +598,12 @@ class pyFillQi0AbsoluteAndRelativeChainingIterator(ChainingIterator): self._length = 0 self._absLength = l self._percent = float(percent) + def init(self): # A chain's length should preverably be evaluated only once. # Therefore, the chain length is reset here. self._length = 0 + def traverse(self, iter): winner = None winnerOrientation = False @@ -682,8 +701,10 @@ class pyNoIdChainSilhouetteIterator(ChainingIterator): def __init__(self, stayInSelection=True): ChainingIterator.__init__(self, stayInSelection, True, None, True) + def init(self): pass + def traverse(self, iter): winner = None it = AdjacencyIterator(iter) diff --git a/release/scripts/freestyle/modules/freestyle/functions.py b/release/scripts/freestyle/modules/freestyle/functions.py index 686dce6615f..379e933862c 100644 --- a/release/scripts/freestyle/modules/freestyle/functions.py +++ b/release/scripts/freestyle/modules/freestyle/functions.py @@ -94,6 +94,7 @@ from mathutils import Vector ## Functions for 0D elements (vertices) ####################################### + class CurveMaterialF0D(UnaryFunction0DMaterial): """ A replacement of the built-in MaterialF0D for stroke creation. @@ -106,18 +107,21 @@ class CurveMaterialF0D(UnaryFunction0DMaterial): assert(fe is not None) return fe.material if fe.is_smooth else fe.material_left + class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble): def __call__(self, inter): func = Curvature2DAngleF0D() c = func(inter) return (3.1415 - c) + class pyCurvilinearLengthF0D(UnaryFunction0DDouble): def __call__(self, inter): cp = inter.object assert(isinstance(cp, CurvePoint)) return cp.t2d + class pyDensityAnisotropyF0D(UnaryFunction0DDouble): """Estimates the anisotropy of density""" def __init__(self,level): @@ -127,6 +131,7 @@ class pyDensityAnisotropyF0D(UnaryFunction0DDouble): self.d1Density = ReadSteerableViewMapPixelF0D(1, level) self.d2Density = ReadSteerableViewMapPixelF0D(2, level) self.d3Density = ReadSteerableViewMapPixelF0D(3, level) + def __call__(self, inter): c_iso = self.IsoDensity(inter) c_0 = self.d0Density(inter) @@ -141,6 +146,7 @@ class pyDensityAnisotropyF0D(UnaryFunction0DDouble): v = (cMax-cMin)/c_iso return v + class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): """Returns the gradient vector for a pixel @@ -151,6 +157,7 @@ class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): UnaryFunction0DVec2f.__init__(self) self._l = level self._step = pow(2, self._l) + def __call__(self, iter): p = iter.object.point_2d gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step), int(p.y)) - \ @@ -159,11 +166,13 @@ class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f): CF.read_complete_view_map_pixel(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 __call__(self, iter): p = iter.object.point_2d gx = CF.read_complete_view_map_pixel(self._l, int(p.x+self._step), int(p.y)) - \ @@ -176,34 +185,40 @@ class pyViewMapGradientNormF0D(UnaryFunction0DDouble): ## Functions for 1D elements (curves) ##################################### + class pyGetInverseProjectedZF1D(UnaryFunction1DDouble): def __call__(self, inter): func = GetProjectedZF1D() z = func(inter) return (1.0 - z) + class pyGetSquareInverseProjectedZF1D(UnaryFunction1DDouble): def __call__(self, inter): func = GetProjectedZF1D() z = func(inter) return (1.0 - z*z) + class pyDensityAnisotropyF1D(UnaryFunction1DDouble): def __init__(self,level, integrationType=IntegrationType.MEAN, sampling=2.0): UnaryFunction1DDouble.__init__(self, integrationType) self._func = pyDensityAnisotropyF0D(level) self._integration = integrationType self._sampling = sampling + def __call__(self, inter): v = integrate(self._func, inter.points_begin(self._sampling), inter.points_end(self._sampling), self._integration) return v + class pyViewMapGradientNormF1D(UnaryFunction1DDouble): def __init__(self,l, integrationType, sampling=2.0): UnaryFunction1DDouble.__init__(self, integrationType) self._func = pyViewMapGradientNormF0D(l) self._integration = integrationType self._sampling = sampling + def __call__(self, inter): v = integrate(self._func, inter.points_begin(self._sampling), inter.points_end(self._sampling), self._integration) return v diff --git a/release/scripts/freestyle/modules/freestyle/predicates.py b/release/scripts/freestyle/modules/freestyle/predicates.py index ab702f1c290..08017953c35 100644 --- a/release/scripts/freestyle/modules/freestyle/predicates.py +++ b/release/scripts/freestyle/modules/freestyle/predicates.py @@ -80,29 +80,35 @@ class pyHigherCurvature2DAngleUP0D(UnaryPredicate0D): def __init__(self,a): UnaryPredicate0D.__init__(self) self._a = a + def __call__(self, inter): func = Curvature2DAngleF0D() a = func(inter) return (a > self._a) + class pyUEqualsUP0D(UnaryPredicate0D): def __init__(self,u, w): UnaryPredicate0D.__init__(self) self._u = u self._w = w + def __call__(self, inter): func = pyCurvilinearLengthF0D() u = func(inter) return (u > (self._u-self._w)) and (u < (self._u+self._w)) + class pyVertexNatureUP0D(UnaryPredicate0D): def __init__(self,nature): UnaryPredicate0D.__init__(self) self._nature = nature + def __call__(self, inter): v = inter.object return (v.nature & self._nature) != 0 + ## check whether an Interface0DIterator ## is a TVertex and is the one that is ## hidden (inferred from the context) @@ -110,6 +116,7 @@ class pyBackTVertexUP0D(UnaryPredicate0D): def __init__(self): UnaryPredicate0D.__init__(self) self._getQI = QuantitativeInvisibilityF0D() + def __call__(self, iter): if (iter.object.nature & Nature.T_VERTEX) == 0: return False @@ -119,20 +126,24 @@ class pyBackTVertexUP0D(UnaryPredicate0D): return True return False + class pyParameterUP0DGoodOne(UnaryPredicate0D): def __init__(self,pmin,pmax): UnaryPredicate0D.__init__(self) self._m = pmin self._M = pmax + def __call__(self, inter): u = inter.u return ((u>=self._m) and (u<=self._M)) + class pyParameterUP0D(UnaryPredicate0D): def __init__(self,pmin,pmax): UnaryPredicate0D.__init__(self) self._m = pmin self._M = pmax + def __call__(self, inter): func = Curvature2DAngleF0D() c = func(inter) @@ -144,62 +155,76 @@ class pyParameterUP0D(UnaryPredicate0D): ## Unary predicates for 1D elements (curves) ############################################ + class AndUP1D(UnaryPredicate1D): def __init__(self, pred1, pred2): UnaryPredicate1D.__init__(self) self.__pred1 = pred1 self.__pred2 = pred2 + def __call__(self, inter): return self.__pred1(inter) and self.__pred2(inter) + class OrUP1D(UnaryPredicate1D): def __init__(self, pred1, pred2): UnaryPredicate1D.__init__(self) self.__pred1 = pred1 self.__pred2 = pred2 + def __call__(self, inter): return self.__pred1(inter) or self.__pred2(inter) + class NotUP1D(UnaryPredicate1D): def __init__(self, pred): UnaryPredicate1D.__init__(self) self.__pred = pred + def __call__(self, inter): return not self.__pred(inter) + class pyNFirstUP1D(UnaryPredicate1D): def __init__(self, n): UnaryPredicate1D.__init__(self) self.__n = n self.__count = 0 + def __call__(self, inter): self.__count = self.__count + 1 if self.__count <= self.__n: return True return False + class pyHigherLengthUP1D(UnaryPredicate1D): def __init__(self,l): UnaryPredicate1D.__init__(self) self._l = l + def __call__(self, inter): return (inter.length_2d > self._l) + class pyNatureUP1D(UnaryPredicate1D): def __init__(self,nature): UnaryPredicate1D.__init__(self) self._nature = nature self._getNature = CurveNatureF1D() + def __call__(self, inter): if(self._getNature(inter) & self._nature): return True return False + class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D): def __init__(self,n,a): UnaryPredicate1D.__init__(self) self._n = n self._a = a + def __call__(self, inter): count = 0 func = Curvature2DAngleF0D() @@ -212,72 +237,85 @@ class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D): it.increment() return False + class pyDensityUP1D(UnaryPredicate1D): - def __init__(self,wsize,threshold, integration = IntegrationType.MEAN, sampling=2.0): + def __init__(self, wsize, threshold, integration=IntegrationType.MEAN, sampling=2.0): UnaryPredicate1D.__init__(self) self._wsize = wsize self._threshold = threshold self._integration = integration self._func = DensityF1D(self._wsize, self._integration, sampling) + def __call__(self, inter): return (self._func(inter) < self._threshold) + class pyLowSteerableViewMapDensityUP1D(UnaryPredicate1D): - def __init__(self,threshold, level,integration = IntegrationType.MEAN): + def __init__(self, threshold, level, integration=IntegrationType.MEAN): UnaryPredicate1D.__init__(self) self._threshold = threshold self._level = level self._integration = integration + def __call__(self, inter): func = GetSteerableViewMapDensityF1D(self._level, self._integration) return (func(inter) < self._threshold) + class pyLowDirectionalViewMapDensityUP1D(UnaryPredicate1D): - def __init__(self,threshold, orientation, level,integration = IntegrationType.MEAN): + def __init__(self, threshold, orientation, level, integration=IntegrationType.MEAN): UnaryPredicate1D.__init__(self) self._threshold = threshold self._orientation = orientation self._level = level self._integration = integration + def __call__(self, inter): func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration) return (func(inter) < self._threshold) + class pyHighSteerableViewMapDensityUP1D(UnaryPredicate1D): - def __init__(self,threshold, level,integration = IntegrationType.MEAN): + def __init__(self, threshold, level, integration=IntegrationType.MEAN): UnaryPredicate1D.__init__(self) self._threshold = threshold self._level = level self._integration = integration self._func = GetSteerableViewMapDensityF1D(self._level, self._integration) + def __call__(self, inter): return (self._func(inter) > self._threshold) + class pyHighDirectionalViewMapDensityUP1D(UnaryPredicate1D): - def __init__(self,threshold, orientation, level,integration = IntegrationType.MEAN, sampling=2.0): + def __init__(self, threshold, orientation, level, integration=IntegrationType.MEAN, sampling=2.0): UnaryPredicate1D.__init__(self) self._threshold = threshold self._orientation = orientation self._level = level self._integration = integration self._sampling = sampling + def __call__(self, inter): func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration, self._sampling) return (func(inter) > self._threshold) + class pyHighViewMapDensityUP1D(UnaryPredicate1D): - def __init__(self,threshold, level,integration = IntegrationType.MEAN, sampling=2.0): + def __init__(self, threshold, level, integration=IntegrationType.MEAN, sampling=2.0): UnaryPredicate1D.__init__(self) self._threshold = threshold self._level = level self._integration = integration self._sampling = sampling self._func = GetCompleteViewMapDensityF1D(self._level, self._integration, self._sampling) # 2.0 is the smpling + def __call__(self, inter): return (self._func(inter) > self._threshold) + class pyDensityFunctorUP1D(UnaryPredicate1D): - def __init__(self,wsize,threshold, functor, funcmin=0.0, funcmax=1.0, integration = IntegrationType.MEAN): + def __init__(self, wsize, threshold, functor, funcmin=0.0, funcmax=1.0, integration=IntegrationType.MEAN): UnaryPredicate1D.__init__(self) self._wsize = wsize self._threshold = float(threshold) @@ -285,6 +323,7 @@ class pyDensityFunctorUP1D(UnaryPredicate1D): self._funcmin = float(funcmin) self._funcmax = float(funcmax) self._integration = integration + def __call__(self, inter): func = DensityF1D(self._wsize, self._integration) res = self._functor(inter) @@ -297,14 +336,17 @@ class pyZSmallerUP1D(UnaryPredicate1D): UnaryPredicate1D.__init__(self) self._z = z self._integration = integration + def __call__(self, inter): func = GetProjectedZF1D(self._integration) return (func(inter) < self._z) + class pyIsOccludedByUP1D(UnaryPredicate1D): def __init__(self,id): UnaryPredicate1D.__init__(self) self._id = id + def __call__(self, inter): func = GetShapeF1D() shapes = func(inter) @@ -314,7 +356,7 @@ class pyIsOccludedByUP1D(UnaryPredicate1D): it = inter.vertices_begin() itlast = inter.vertices_end() itlast.decrement() - v = it.object + v = it.object vlast = itlast.object tvertex = v.viewvertex if type(tvertex) is TVertex: @@ -338,10 +380,12 @@ class pyIsOccludedByUP1D(UnaryPredicate1D): eit.increment() return False + class pyIsInOccludersListUP1D(UnaryPredicate1D): def __init__(self,id): UnaryPredicate1D.__init__(self) self._id = id + def __call__(self, inter): func = GetOccludersF1D() occluders = func(inter) @@ -350,11 +394,13 @@ class pyIsInOccludersListUP1D(UnaryPredicate1D): return True return False + class pyIsOccludedByItselfUP1D(UnaryPredicate1D): def __init__(self): UnaryPredicate1D.__init__(self) self.__func1 = GetOccludersF1D() self.__func2 = GetShapeF1D() + def __call__(self, inter): lst1 = self.__func1(inter) lst2 = self.__func2(inter) @@ -364,11 +410,13 @@ class pyIsOccludedByItselfUP1D(UnaryPredicate1D): return True return False + class pyIsOccludedByIdListUP1D(UnaryPredicate1D): def __init__(self, idlist): UnaryPredicate1D.__init__(self) self._idlist = idlist self.__func1 = GetOccludersF1D() + def __call__(self, inter): lst1 = self.__func1(inter) for vs1 in lst1: @@ -377,24 +425,28 @@ class pyIsOccludedByIdListUP1D(UnaryPredicate1D): return True return False + class pyShapeIdListUP1D(UnaryPredicate1D): def __init__(self,idlist): UnaryPredicate1D.__init__(self) self._idlist = idlist self._funcs = [] - for _id in idlist : + for _id in idlist: self._funcs.append(ShapeUP1D(_id.first, _id.second)) + def __call__(self, inter): for func in self._funcs: if func(inter) == 1: return True return False + ## deprecated class pyShapeIdUP1D(UnaryPredicate1D): def __init__(self, _id): UnaryPredicate1D.__init__(self) self._id = _id + def __call__(self, inter): func = GetShapeF1D() shapes = func(inter) @@ -403,26 +455,31 @@ class pyShapeIdUP1D(UnaryPredicate1D): return True return False + class pyHighDensityAnisotropyUP1D(UnaryPredicate1D): def __init__(self,threshold, level, sampling=2.0): UnaryPredicate1D.__init__(self) self._l = threshold self.func = pyDensityAnisotropyF1D(level, IntegrationType.MEAN, sampling) + def __call__(self, inter): return (self.func(inter) > self._l) + class pyHighViewMapGradientNormUP1D(UnaryPredicate1D): def __init__(self,threshold, l, sampling=2.0): UnaryPredicate1D.__init__(self) self._threshold = threshold self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) + def __call__(self, inter): gn = self._GetGradient(inter) #print(gn) return (gn > self._threshold) + class pyDensityVariableSigmaUP1D(UnaryPredicate1D): - def __init__(self,functor, sigmaMin,sigmaMax, lmin, lmax, tmin, tmax, integration = IntegrationType.MEAN, sampling=2.0): + def __init__(self, functor, sigmaMin, sigmaMax, lmin, lmax, tmin, tmax, integration=IntegrationType.MEAN, sampling=2.0): UnaryPredicate1D.__init__(self) self._functor = functor self._sigmaMin = float(sigmaMin) @@ -433,6 +490,7 @@ class pyDensityVariableSigmaUP1D(UnaryPredicate1D): self._tmax = tmax self._integration = integration self._sampling = sampling + def __call__(self, inter): sigma = (self._sigmaMax-self._sigmaMin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._sigmaMin t = (self._tmax-self._tmin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._tmin @@ -440,6 +498,7 @@ class pyDensityVariableSigmaUP1D(UnaryPredicate1D): self._func = DensityF1D(sigma, self._integration, self._sampling) return (self._func(inter) < t) + class pyClosedCurveUP1D(UnaryPredicate1D): def __call__(self, inter): it = inter.vertices_begin() @@ -456,22 +515,27 @@ class pyClosedCurveUP1D(UnaryPredicate1D): ## Binary predicates for 1D elements (curves) ############################################# + class pyZBP1D(BinaryPredicate1D): def __call__(self, i1, i2): func = GetZF1D() return (func(i1) > func(i2)) + class pyZDiscontinuityBP1D(BinaryPredicate1D): - def __init__(self, iType = IntegrationType.MEAN): + def __init__(self, iType=IntegrationType.MEAN): BinaryPredicate1D.__init__(self) self._GetZDiscontinuity = ZDiscontinuityF1D(iType) + def __call__(self, i1, i2): return (self._GetZDiscontinuity(i1) > self._GetZDiscontinuity(i2)) + class pyLengthBP1D(BinaryPredicate1D): def __call__(self, i1, i2): return (i1.length_2d > i2.length_2d) + class pySilhouetteFirstBP1D(BinaryPredicate1D): def __call__(self, inter1, inter2): bpred = SameShapeIdBP1D() @@ -481,22 +545,27 @@ class pySilhouetteFirstBP1D(BinaryPredicate1D): return (inter2.nature & Nature.SILHOUETTE) != 0 return (inter1.nature == inter2.nature) + class pyNatureBP1D(BinaryPredicate1D): def __call__(self, inter1, inter2): return (inter1.nature & inter2.nature) + class pyViewMapGradientNormBP1D(BinaryPredicate1D): def __init__(self,l, sampling=2.0): BinaryPredicate1D.__init__(self) self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) + def __call__(self, i1,i2): #print("compare gradient") return (self._GetGradient(i1) > self._GetGradient(i2)) + class pyShuffleBP1D(BinaryPredicate1D): def __init__(self): BinaryPredicate1D.__init__(self) random.seed(1) + def __call__(self, inter1, inter2): r1 = random.uniform(0,1) r2 = random.uniform(0,1) diff --git a/release/scripts/freestyle/modules/freestyle/shaders.py b/release/scripts/freestyle/modules/freestyle/shaders.py index f4ff5e75b3d..a6ff61653be 100644 --- a/release/scripts/freestyle/modules/freestyle/shaders.py +++ b/release/scripts/freestyle/modules/freestyle/shaders.py @@ -93,6 +93,7 @@ class pyDepthDiscontinuityThicknessShader(StrokeShader): self.__min = float(min) self.__max = float(max) self.__func = ZDiscontinuityF0D() + def shade(self, stroke): z_min=0.0 z_max=1.0 @@ -105,6 +106,7 @@ class pyDepthDiscontinuityThicknessShader(StrokeShader): it.object.attribute.thickness = (thickness, thickness) it.increment() + class pyConstantThicknessShader(StrokeShader): """ Assigns a constant thickness along the stroke @@ -112,6 +114,7 @@ class pyConstantThicknessShader(StrokeShader): def __init__(self, thickness): StrokeShader.__init__(self) self._thickness = thickness + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -119,6 +122,7 @@ class pyConstantThicknessShader(StrokeShader): it.object.attribute.thickness = (t, t) it.increment() + class pyFXSVaryingThicknessWithDensityShader(StrokeShader): """ Assings thickness to a stroke based on the density of the diffuse map @@ -130,6 +134,7 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader): self.threshold_max= threshold_max self._thicknessMin = thicknessMin self._thicknessMax = thicknessMax + def shade(self, stroke): n = stroke.stroke_vertices_size() i = 0 @@ -147,6 +152,7 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader): i = i+1 it.increment() + class pyIncreasingThicknessShader(StrokeShader): """ Increasingly thickens the stroke @@ -155,6 +161,7 @@ class pyIncreasingThicknessShader(StrokeShader): StrokeShader.__init__(self) self._thicknessMin = thicknessMin self._thicknessMax = thicknessMax + def shade(self, stroke): n = stroke.stroke_vertices_size() i = 0 @@ -169,6 +176,7 @@ class pyIncreasingThicknessShader(StrokeShader): i = i+1 it.increment() + class pyConstrainedIncreasingThicknessShader(StrokeShader): """ Increasingly thickens the stroke, constrained by a ratio of the @@ -179,6 +187,7 @@ class pyConstrainedIncreasingThicknessShader(StrokeShader): self._thicknessMin = thicknessMin self._thicknessMax = thicknessMax self._ratio = ratio + def shade(self, stroke): slength = stroke.length_2d tmp = self._ratio*slength @@ -203,6 +212,7 @@ class pyConstrainedIncreasingThicknessShader(StrokeShader): i = i+1 it.increment() + class pyDecreasingThicknessShader(StrokeShader): """ Inverse of pyIncreasingThicknessShader, decreasingly thickens the stroke @@ -211,6 +221,7 @@ class pyDecreasingThicknessShader(StrokeShader): StrokeShader.__init__(self) self._thicknessMin = thicknessMin self._thicknessMax = thicknessMax + def shade(self, stroke): l = stroke.length_2d tMax = self._thicknessMax @@ -229,6 +240,7 @@ class pyDecreasingThicknessShader(StrokeShader): i = i+1 it.increment() + class pyNonLinearVaryingThicknessShader(StrokeShader): """ Assigns thickness to a stroke based on an exponential function @@ -238,6 +250,7 @@ class pyNonLinearVaryingThicknessShader(StrokeShader): self._thicknessMin = thicknessMiddle self._thicknessMax = thicknessExtremity self._exponent = exponent + def shade(self, stroke): n = stroke.stroke_vertices_size() i = 0 @@ -252,9 +265,11 @@ class pyNonLinearVaryingThicknessShader(StrokeShader): it.object.attribute.thickness = (t/2.0, t/2.0) i = i+1 it.increment() + def smoothC(self, a, exp): return pow(float(a), exp) * pow(2.0, exp) + class pySLERPThicknessShader(StrokeShader): """ Assigns thickness to a stroke based on spherical linear interpolation @@ -264,6 +279,7 @@ class pySLERPThicknessShader(StrokeShader): self._thicknessMin = thicknessMin self._thicknessMax = thicknessMax self._omega = omega + def shade(self, stroke): slength = stroke.length_2d tmp = 0.33*slength @@ -283,6 +299,7 @@ class pySLERPThicknessShader(StrokeShader): i = i+1 it.increment() + class pyTVertexThickenerShader(StrokeShader): ## FIXME """ Thickens TVertices (visual intersections between two edges) @@ -291,6 +308,7 @@ class pyTVertexThickenerShader(StrokeShader): ## FIXME StrokeShader.__init__(self) self._a = a self._n = n + def shade(self, stroke): it = stroke.stroke_vertices_begin() predTVertex = pyVertexNatureUP0D(Nature.T_VERTEX) @@ -333,6 +351,7 @@ class pyTVertexThickenerShader(StrokeShader): ## FIXME att.thickness = (r*tr, r*tl) it.increment() + class pyImportance2DThicknessShader(StrokeShader): """ Assigns thickness based on distance to a given point in 2D space. @@ -346,6 +365,7 @@ class pyImportance2DThicknessShader(StrokeShader): self._w = float(w) self._kmin = float(kmin) self._kmax = float(kmax) + def shade(self, stroke): origin = Vector((self._x, self._y)) it = stroke.stroke_vertices_begin() @@ -361,6 +381,7 @@ class pyImportance2DThicknessShader(StrokeShader): att.thickness = (k*tr/2.0, k*tl/2.0) it.increment() + class pyImportance3DThicknessShader(StrokeShader): """ Assigns thickness based on distance to a given point in 3D space @@ -373,6 +394,7 @@ class pyImportance3DThicknessShader(StrokeShader): self._w = float(w) self._kmin = float(kmin) self._kmax = float(kmax) + def shade(self, stroke): origin = Vector((self._x, self._y, self._z)) it = stroke.stroke_vertices_begin() @@ -389,6 +411,7 @@ class pyImportance3DThicknessShader(StrokeShader): att.thickness = (k*tr/2.0, k*tl/2.0) it.increment() + class pyZDependingThicknessShader(StrokeShader): """ Assigns thickness based on an object's local Z depth (point @@ -399,6 +422,7 @@ class pyZDependingThicknessShader(StrokeShader): self.__min = min self.__max = max self.__func = GetProjectedZF0D() + def shade(self, stroke): it = stroke.stroke_vertices_begin() z_min = 1 @@ -426,12 +450,13 @@ class pyConstantColorShader(StrokeShader): """ Assigns a constant color to the stroke """ - def __init__(self,r,g,b, a = 1): + def __init__(self, r, g, b, a=1): StrokeShader.__init__(self) self._r = r self._g = g self._b = b self._a = a + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -449,19 +474,20 @@ class pyIncreasingColorShader(StrokeShader): StrokeShader.__init__(self) self._c1 = [r1,g1,b1,a1] self._c2 = [r2,g2,b2,a2] + def shade(self, stroke): n = stroke.stroke_vertices_size() - 1 inc = 0 it = stroke.stroke_vertices_begin() while not it.is_end: att = it.object.attribute - c = float(inc)/float(n) + c = float(inc) / float(n) - 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 + att.color = ((1.0 - c) * self._c1[0] + c * self._c2[0], + (1.0 - c) * self._c1[1] + c * self._c2[1], + (1.0 - c) * self._c1[2] + c * self._c2[2]) + att.alpha = (1.0 - c) * self._c1[3] + c * self._c2[3] + inc = inc + 1 it.increment() @@ -473,21 +499,23 @@ class pyInterpolateColorShader(StrokeShader): StrokeShader.__init__(self) self._c1 = [r1,g1,b1,a1] self._c2 = [r2,g2,b2,a2] + def shade(self, stroke): n = stroke.stroke_vertices_size() - 1 inc = 0 it = stroke.stroke_vertices_begin() while not it.is_end: att = it.object.attribute - u = float(inc)/float(n) - c = 1 - 2 * abs(u - 0.5) - 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] + u = float(inc) / float(n) + c = 1.0 - 2.0 * abs(u - 0.5) + att.color = ((1.0 - c) * self._c1[0] + c * self._c2[0], + (1.0 - c) * self._c1[1] + c * self._c2[1], + (1.0 - c) * self._c1[2] + c * self._c2[2]) + att.alpha = (1.0-c) * self._c1[3] + c * self._c2[3] inc = inc+1 it.increment() + class pyMaterialColorShader(StrokeShader): """ Assigns the color of the underlying material to the stroke @@ -495,6 +523,7 @@ class pyMaterialColorShader(StrokeShader): def __init__(self, threshold=50): StrokeShader.__init__(self) self._threshold = threshold + def shade(self, stroke): it = stroke.stroke_vertices_begin() func = MaterialF0D() @@ -536,8 +565,8 @@ class pyMaterialColorShader(StrokeShader): v = V / (13. * L) + vn Y = Yn * pow(((L+16.)/116.), 3.) - X = -9. * Y * u / ((u - 4.)* v - u * v) - Z = (9. * Y - 15*v*Y - v*X) /( 3. * v) + X = -9.0 * Y * u / ((u - 4.0) * v - u * v) + Z = (9.0 * Y - 15.0 * v * Y - v * X) / (3.0 * v) r = 3.240479 * X - 1.53715 * Y - 0.498535 * Z g = -0.969256 * X + 1.875991 * Y + 0.041556 * Z @@ -550,6 +579,7 @@ class pyMaterialColorShader(StrokeShader): it.object.attribute.color = (r, g, b) it.increment() + class pyRandomColorShader(StrokeShader): """ Assigns a color to the stroke based on given seed @@ -557,6 +587,7 @@ class pyRandomColorShader(StrokeShader): def __init__(self, s=1): StrokeShader.__init__(self) random.seed(s) + def shade(self, stroke): ## pick a random color c0 = float(random.uniform(15,75))/100.0 @@ -568,6 +599,7 @@ class pyRandomColorShader(StrokeShader): it.object.attribute.color = (c0,c1,c2) it.increment() + class py2DCurvatureColorShader(StrokeShader): """ Assigns a color (greyscale) to the stroke based on the curvature. @@ -584,6 +616,7 @@ class py2DCurvatureColorShader(StrokeShader): it.object.attribute.color = (color, color, color) it.increment() + class pyTimeColorShader(StrokeShader): """ Assigns a greyscale value that increases for every vertex. @@ -592,6 +625,7 @@ class pyTimeColorShader(StrokeShader): def __init__(self, step=0.01): StrokeShader.__init__(self) self._step = step + def shade(self, stroke): for i, svert in enumerate(iter(stroke)): c = i * self._step @@ -599,6 +633,7 @@ class pyTimeColorShader(StrokeShader): ## geometry modifiers + class pySamplingShader(StrokeShader): """ Resamples the stroke, which gives the stroke the ammount of @@ -607,10 +642,12 @@ class pySamplingShader(StrokeShader): def __init__(self, sampling): StrokeShader.__init__(self) self._sampling = sampling + def shade(self, stroke): stroke.resample(float(self._sampling)) stroke.update_length() + class pyBackboneStretcherShader(StrokeShader): """ Stretches the stroke's backbone by a given length (in pixels) @@ -618,6 +655,7 @@ class pyBackboneStretcherShader(StrokeShader): def __init__(self, l): StrokeShader.__init__(self) self._l = l + def shade(self, stroke): it0 = stroke.stroke_vertices_begin() it1 = StrokeVertexIterator(it0) @@ -642,6 +680,7 @@ class pyBackboneStretcherShader(StrokeShader): vn.point = newLast stroke.update_length() + class pyLengthDependingBackboneStretcherShader(StrokeShader): """ Stretches the stroke's backbone proportional to the stroke's length @@ -649,6 +688,7 @@ class pyLengthDependingBackboneStretcherShader(StrokeShader): def __init__(self, l): StrokeShader.__init__(self) self._l = l + def shade(self, stroke): l = stroke.length_2d stretch = self._l*l @@ -710,6 +750,7 @@ class pyBackboneStretcherNoCuspShader(StrokeShader): def __init__(self, l): StrokeShader.__init__(self) self._l = l + def shade(self, stroke): it0 = stroke.stroke_vertices_begin() it1 = StrokeVertexIterator(it0) @@ -732,6 +773,7 @@ class pyBackboneStretcherNoCuspShader(StrokeShader): vn.point = newLast stroke.update_length() + class pyDiffusion2Shader(StrokeShader): """ Iteratively adds an offset to the position of each stroke vertex @@ -745,6 +787,7 @@ class pyDiffusion2Shader(StrokeShader): self._nbIter = nbIter self._normalInfo = Normal2DF0D() self._curvatureInfo = Curvature2DAngleF0D() + def shade(self, stroke): for i in range (1, self._nbIter): it = stroke.stroke_vertices_begin() @@ -756,6 +799,7 @@ class pyDiffusion2Shader(StrokeShader): it.increment() stroke.update_length() + class pyTipRemoverShader(StrokeShader): """ Removes the tips of the stroke @@ -763,6 +807,7 @@ class pyTipRemoverShader(StrokeShader): def __init__(self, l): StrokeShader.__init__(self) self._l = l + def shade(self, stroke): originalSize = stroke.stroke_vertices_size() if originalSize < 4: @@ -792,6 +837,7 @@ class pyTipRemoverShader(StrokeShader): it.increment() stroke.update_length() + class pyTVertexRemoverShader(StrokeShader): """ Removes t-vertices from the stroke @@ -809,6 +855,7 @@ class pyTVertexRemoverShader(StrokeShader): stroke.remove_vertex(itlast.object) stroke.update_length() + #class pyExtremitiesOrientationShader(StrokeShader): # def __init__(self, x1,y1,x2=0,y2=0): # StrokeShader.__init__(self) @@ -819,6 +866,7 @@ class pyTVertexRemoverShader(StrokeShader): # stroke.setBeginningOrientation(self._v1.x,self._v1.y) # stroke.setEndingOrientation(self._v2.x,self._v2.y) + class pyHLRShader(StrokeShader): """ Controlls visibility based upon the quantative invisibility (QI) @@ -850,9 +898,11 @@ class pyHLRShader(StrokeShader): v.attribute.visible = False it.increment() it2.increment() + def get_fedge(self, it1, it2): return it1.get_fedge(it2) + # broken and a mess class pyTVertexOrientationShader(StrokeShader): def __init__(self): @@ -860,6 +910,7 @@ class pyTVertexOrientationShader(StrokeShader): self._Get2dDirection = Orientation2DF1D() ## finds the TVertex orientation from the TVertex and ## the previous or next edge + def findOrientation(self, tv, ve): mateVE = tv.get_mate(ve) if ve.qi != 0 or mateVE.qi != 0: @@ -881,12 +932,14 @@ class pyTVertexOrientationShader(StrokeShader): direction = self._Get2dDirection(winner.first_fedge) return direction return None + def castToTVertex(self, cp): if cp.t2d() == 0.0: return cp.first_svertex.viewvertex elif cp.t2d() == 1.0: return cp.second_svertex.viewvertex return None + def shade(self, stroke): it = stroke.stroke_vertices_begin() it2 = StrokeVertexIterator(it) @@ -926,9 +979,11 @@ class pyTVertexOrientationShader(StrokeShader): if dir is not None: #print(dir.x, dir.y) v.attribute.set_attribute_vec2("orientation", dir) + def get_fedge(self, it1, it2): return it1.get_fedge(it2) + class pySinusDisplacementShader(StrokeShader): """ Displaces the stroke in the shape of a sine wave @@ -938,6 +993,7 @@ class pySinusDisplacementShader(StrokeShader): self._f = f self._a = a self._getNormal = Normal2DF0D() + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -954,18 +1010,20 @@ class pySinusDisplacementShader(StrokeShader): it.increment() stroke.update_length() + class pyPerlinNoise1DShader(StrokeShader): """ Displaces the stroke using the curvilinear abscissa. This means that lines with the same length and sampling interval will be identically distorded """ - def __init__(self, freq = 10, amp = 10, oct = 4, seed = -1): + def __init__(self, freq=10, amp=10, oct=4, seed=-1): StrokeShader.__init__(self) self.__noise = Noise(seed) self.__freq = freq self.__amp = amp self.__oct = oct + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -976,6 +1034,7 @@ class pyPerlinNoise1DShader(StrokeShader): it.increment() stroke.update_length() + class pyPerlinNoise2DShader(StrokeShader): """ Displaces the stroke using the strokes coordinates. This means @@ -984,12 +1043,13 @@ class pyPerlinNoise2DShader(StrokeShader): More information on the noise shaders can be found at freestyleintegration.wordpress.com/2011/09/25/development-updates-on-september-25/ """ - def __init__(self, freq = 10, amp = 10, oct = 4, seed = -1): + def __init__(self, freq=10, amp=10, oct=4, seed=-1): StrokeShader.__init__(self) self.__noise = Noise(seed) self.__freq = freq self.__amp = amp self.__oct = oct + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -999,15 +1059,17 @@ class pyPerlinNoise2DShader(StrokeShader): it.increment() stroke.update_length() + class pyBluePrintCirclesShader(StrokeShader): """ Draws the silhouette of the object as a circle """ - def __init__(self, turns = 1, random_radius = 3, random_center = 5): + def __init__(self, turns=1, random_radius=3, random_center=5): StrokeShader.__init__(self) self.__turns = turns self.__random_center = random_center self.__random_radius = random_radius + def shade(self, stroke): it = stroke.stroke_vertices_begin() if it.is_end: @@ -1035,7 +1097,7 @@ class pyBluePrintCirclesShader(StrokeShader): sv_nb = sv_nb // self.__turns center = (p_min + p_max) / 2 radius = (center.x - p_min.x + center.y - p_min.y) / 2 - p_new = Vector((0,0)) + p_new = Vector((0.0, 0.0)) ####################################################### R = self.__random_radius C = self.__random_center @@ -1064,15 +1126,17 @@ class pyBluePrintCirclesShader(StrokeShader): stroke.remove_vertex(sv) stroke.update_length() + class pyBluePrintEllipsesShader(StrokeShader): """ Draws the silhouette of the object as an ellips """ - def __init__(self, turns = 1, random_radius = 3, random_center = 5): + def __init__(self, turns=1, random_radius=3, random_center=5): StrokeShader.__init__(self) self.__turns = turns self.__random_center = random_center self.__random_radius = random_radius + def shade(self, stroke): it = stroke.stroke_vertices_begin() if it.is_end: @@ -1095,7 +1159,7 @@ class pyBluePrintEllipsesShader(StrokeShader): sv_nb = sv_nb // self.__turns center = (p_min + p_max) / 2 radius = center - p_min - p_new = Vector((0,0)) + p_new = Vector((0.0, 0.0)) ####################################################### R = self.__random_radius C = self.__random_center @@ -1129,11 +1193,12 @@ class pyBluePrintSquaresShader(StrokeShader): """ Draws the silhouette of the object as a square """ - def __init__(self, turns = 1, bb_len = 10, bb_rand = 0): + def __init__(self, turns=1, bb_len=10, bb_rand=0): StrokeShader.__init__(self) self.__turns = turns self.__bb_len = bb_len self.__bb_rand = bb_rand + def shade(self, stroke): it = stroke.stroke_vertices_begin() if it.is_end: @@ -1203,7 +1268,7 @@ class pyBluePrintSquaresShader(StrokeShader): p_new = p_fourth + vec_fourth * float(i - third)/float(fourth - third - 1) if i == fourth - 1: visible = False - if it.object == None: + if it.object is None: i = i + 1 it.increment() if not visible: @@ -1223,16 +1288,18 @@ class pyBluePrintSquaresShader(StrokeShader): stroke.remove_vertex(sv) stroke.update_length() + # needs a docstring class pyBluePrintDirectedSquaresShader(StrokeShader): - def __init__(self, turns = 1, bb_len = 10, mult = 1): + def __init__(self, turns=1, bb_len=10, mult=1): StrokeShader.__init__(self) self.__mult = mult self.__turns = turns self.__bb_len = 1 + float(bb_len) / 100 + def shade(self, stroke): stroke.resample(32 * self.__turns) - p_mean = Vector((0, 0)) + p_mean = Vector((0.0, 0.0)) it = stroke.stroke_vertices_begin() while not it.is_end: p = it.object.point @@ -1264,7 +1331,7 @@ class pyBluePrintDirectedSquaresShader(StrokeShader): ## print(theta) if p_var_yy > p_var_xx: e1 = Vector((cos(theta + pi / 2), sin(theta + pi / 2))) * sqrt(lambda1) * self.__mult - e2 = Vector((cos(theta + pi), sin(theta + pi))) * sqrt(lambda2) * self.__mult + e2 = Vector((cos(theta + pi), sin(theta + pi))) * sqrt(lambda2) * self.__mult else: e1 = Vector((cos(theta), sin(theta))) * sqrt(lambda1) * self.__mult e2 = Vector((cos(theta + pi / 2), sin(theta + pi / 2))) * sqrt(lambda2) * self.__mult @@ -1320,14 +1387,16 @@ class pyBluePrintDirectedSquaresShader(StrokeShader): stroke.remove_vertex(sv) stroke.update_length() + class pyModulateAlphaShader(StrokeShader): """ Limits the stroke's alpha between a min and max value """ - def __init__(self, min = 0, max = 1): + def __init__(self, min=0, max=1): StrokeShader.__init__(self) self.__min = min self.__max = max + def shade(self, stroke): it = stroke.stroke_vertices_begin() while not it.is_end: @@ -1341,6 +1410,7 @@ class pyModulateAlphaShader(StrokeShader): it.object.attribute.alpha = alpha it.increment() + ## various class pyDummyShader(StrokeShader): def shade(self, stroke): @@ -1352,6 +1422,7 @@ class pyDummyShader(StrokeShader): att.thickness = (0, 5) it.increment() + class pyDebugShader(StrokeShader): def shade(self, stroke): fe = CF.get_selected_fedge() diff --git a/release/scripts/freestyle/modules/parameter_editor.py b/release/scripts/freestyle/modules/parameter_editor.py index 80a8740145f..f3dd66b78cc 100644 --- a/release/scripts/freestyle/modules/parameter_editor.py +++ b/release/scripts/freestyle/modules/parameter_editor.py @@ -1133,9 +1133,11 @@ def iter_three_segments(stroke): it3.increment() it4.increment() + def is_tvertex(svertex): return type(svertex.viewvertex) is TVertex + class StrokeCleaner(StrokeShader): def shade(self, stroke): for sv1, sv2, sv3, sv4 in iter_three_segments(stroke): diff --git a/release/scripts/freestyle/styles/apriori_density.py b/release/scripts/freestyle/styles/apriori_density.py index 22f924d8e98..b52bcfbeb4e 100644 --- a/release/scripts/freestyle/styles/apriori_density.py +++ b/release/scripts/freestyle/styles/apriori_density.py @@ -42,7 +42,7 @@ bpred = TrueBP1D() upred = AndUP1D(QuantitativeInvisibilityUP1D(0), pyHighViewMapDensityUP1D(0.0007,5)) Operators.bidirectional_chain(ChainPredicateIterator(upred, bpred), NotUP1D(QuantitativeInvisibilityUP1D(0))) shaders_list = [ - ConstantThicknessShader(2), - ConstantColorShader(0.0, 0.0, 0.0,1) - ] + ConstantThicknessShader(2), + ConstantColorShader(0.0, 0.0, 0.0, 1.0) + ] Operators.create(TrueUP1D(), shaders_list) diff --git a/release/scripts/freestyle/styles/long_anisotropically_dense.py b/release/scripts/freestyle/styles/long_anisotropically_dense.py index 890696d7779..50bec4f1a79 100644 --- a/release/scripts/freestyle/styles/long_anisotropically_dense.py +++ b/release/scripts/freestyle/styles/long_anisotropically_dense.py @@ -55,6 +55,7 @@ class pyDensityUP1D(UnaryPredicate1D): self._integration = integration self._func = DensityF1D(self._wsize, self._integration, sampling) self._func2 = DensityF1D(self._wsize, IntegrationType.MAX, sampling) + def __call__(self, inter): c = self._func(inter) m = self._func2(inter) diff --git a/release/scripts/freestyle/styles/multiple_parameterization.py b/release/scripts/freestyle/styles/multiple_parameterization.py index 482d8bd94f7..bf0691f2ce1 100644 --- a/release/scripts/freestyle/styles/multiple_parameterization.py +++ b/release/scripts/freestyle/styles/multiple_parameterization.py @@ -53,6 +53,6 @@ shaders_list = [ ConstantColorShader(0.0, 0.0, 0.0), IncreasingColorShader(1, 0, 0, 1, 0, 1, 0, 1), TextureAssignerShader(-1), - pyHLRShader(), ## this shader draws only visible portions + pyHLRShader(), ## this shader draws only visible portions ] Operators.create(TrueUP1D(), shaders_list) |