Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/freestyle/modules/freestyle/predicates.py
| Context not available. | |||||
| UnaryPredicate0D, | UnaryPredicate0D, | ||||
| UnaryPredicate1D, | UnaryPredicate1D, | ||||
| Id, | Id, | ||||
| Interface0DIterator, | |||||
| ) | ) | ||||
| from freestyle.functions import ( | from freestyle.functions import ( | ||||
| Curvature2DAngleF0D, | Curvature2DAngleF0D, | ||||
| Context not available. | |||||
| def __init__(self, a): | def __init__(self, a): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._a = a | self._a = a | ||||
| self.func = Curvature2DAngleF0D() | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = Curvature2DAngleF0D() | return (self.func(inter) > self._a) | ||||
| a = func(inter) | |||||
| return (a > self._a) | |||||
| class pyUEqualsUP0D(UnaryPredicate0D): | class pyUEqualsUP0D(UnaryPredicate0D): | ||||
| Context not available. | |||||
| class pyVertexNatureUP0D(UnaryPredicate0D): | class pyVertexNatureUP0D(UnaryPredicate0D): | ||||
| def __init__(self,nature): | def __init__(self, nature): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._nature = nature | self._nature = nature | ||||
| Context not available. | |||||
| class pyParameterUP0DGoodOne(UnaryPredicate0D): | class pyParameterUP0DGoodOne(UnaryPredicate0D): | ||||
| def __init__(self,pmin,pmax): | def __init__(self, pmin, pmax): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._m = pmin | self._m = pmin | ||||
| self._M = pmax | self._M = pmax | ||||
| Context not available. | |||||
| class pyParameterUP0D(UnaryPredicate0D): | class pyParameterUP0D(UnaryPredicate0D): | ||||
| def __init__(self,pmin,pmax): | def __init__(self, pmin, pmax): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._m = pmin | self._m = pmin | ||||
| self._M = pmax | self._M = pmax | ||||
| Context not available. | |||||
| # -- Unary predicates for 1D elements (curves) -- # | # -- Unary predicates for 1D elements (curves) -- # | ||||
| class AndUP1D(UnaryPredicate1D): | class AndUP1D(UnaryPredicate1D): | ||||
| def __init__(self, *predicates): | def __init__(self, *predicates): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self.predicates = predicates | self.predicates = predicates | ||||
| if len(self.predicates) < 2: | # there are cases in which only one predicate is supplied (in the parameter editor) | ||||
| raise ValueError("Expected two or more UnaryPredicate1D") | if len(self.predicates) < 1: | ||||
| raise ValueError("Expected two or more UnaryPredicate1D, got" + str(predicates)) | |||||
kjym3: I guess you meant `len(predicates)` at the end of the error message. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return all(pred(inter) for pred in self.predicates) | return all(pred(inter) for pred in self.predicates) | ||||
| Context not available. | |||||
| def __init__(self, *predicates): | def __init__(self, *predicates): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self.predicates = predicates | self.predicates = predicates | ||||
| if len(self.predicates) < 2: | # there are cases in which only one predicate is supplied (in the parameter editor) | ||||
| raise ValueError("Expected two or more UnaryPredicate1D") | if len(self.predicates) < 1: | ||||
| raise ValueError("Expected two or more UnaryPredicate1D, got" + str(predicates)) | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return any(pred(inter) for pred in self.predicates) | return any(pred(inter) for pred in self.predicates) | ||||
| Context not available. | |||||
| class pyNatureUP1D(UnaryPredicate1D): | class pyNatureUP1D(UnaryPredicate1D): | ||||
| def __init__(self,nature): | def __init__(self, nature): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._nature = nature | self._nature = nature | ||||
| self._getNature = CurveNatureF1D() | self._getNature = CurveNatureF1D() | ||||
| Context not available. | |||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._n = n | self._n = n | ||||
| self._a = a | self._a = a | ||||
| self.func = Curvature2DAngleF0D() | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = Curvature2DAngleF0D() | it = Interface0DIterator(inter) | ||||
| it = inter.vertices_begin() | |||||
| # sum the turns, check against n | # sum the turns, check against n | ||||
| return sum(1 for ve in it if func(it) > self._a) > self._n | return sum(1 for _ in it if self.func(it) > self._a) > self._n | ||||
| # interesting fact, the line above is 70% faster than: | |||||
| # return sum(self.func(it) > self._a for _ in it) > self._n | |||||
kjym3Unsubmitted Not Done Inline ActionsConcerning the comment, I guess sum(1 for ... if ...) is faster because summation only takes place for those items that hold the condition (i.e., the smaller the number of items for which the condition is true is, the faster the new expression is). kjym3: Concerning the comment, I guess `sum(1 for ... if ...)` is faster because summation only takes… | |||||
| class pyDensityUP1D(UnaryPredicate1D): | class pyDensityUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| class pyIsOccludedByUP1D(UnaryPredicate1D): | class pyIsOccludedByUP1D(UnaryPredicate1D): | ||||
| def __init__(self,id): | def __init__(self, id): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| if not isinstance(id, Id): | if not isinstance(id, Id): | ||||
| raise TypeError("pyIsOccludedByUP1D expected freestyle.types.Id, not " + type(id).__name__) | raise TypeError("pyIsOccludedByUP1D expected freestyle.types.Id, not " + type(id).__name__) | ||||
| Context not available. | |||||
| class pyIsInOccludersListUP1D(UnaryPredicate1D): | class pyIsInOccludersListUP1D(UnaryPredicate1D): | ||||
| def __init__(self,id): | def __init__(self, id): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._id = id | self._id = id | ||||
| Context not available. | |||||
| class pyShapeIdListUP1D(UnaryPredicate1D): | class pyShapeIdListUP1D(UnaryPredicate1D): | ||||
| def __init__(self,idlist): | def __init__(self, idlist): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._funcs = tuple(ShapeUP1D(_id, 0) for _id in idlist) | self._funcs = tuple(ShapeUP1D(_id, 0) for _id in idlist) | ||||
| Context not available. | |||||
| return any(func(inter) for func in self._funcs) | return any(func(inter) for func in self._funcs) | ||||
| ## deprecated | # DEPRECATED | ||||
| class pyShapeIdUP1D(UnaryPredicate1D): | class pyShapeIdUP1D(UnaryPredicate1D): | ||||
| def __init__(self, _id): | def __init__(self, _id): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| Context not available. | |||||
| class pyHighDensityAnisotropyUP1D(UnaryPredicate1D): | class pyHighDensityAnisotropyUP1D(UnaryPredicate1D): | ||||
| def __init__(self,threshold, level, sampling=2.0): | def __init__(self, threshold, level, sampling=2.0): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._l = threshold | self._l = threshold | ||||
| self.func = pyDensityAnisotropyF1D(level, IntegrationType.MEAN, sampling) | self.func = pyDensityAnisotropyF1D(level, IntegrationType.MEAN, sampling) | ||||
| Context not available. | |||||
| class pyHighViewMapGradientNormUP1D(UnaryPredicate1D): | class pyHighViewMapGradientNormUP1D(UnaryPredicate1D): | ||||
| def __init__(self,threshold, l, sampling=2.0): | def __init__(self, threshold, l, sampling=2.0): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._threshold = threshold | self._threshold = threshold | ||||
| self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | ||||
| Context not available. | |||||
| self._sampling = sampling | self._sampling = sampling | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| sigma = (self._sigmaMax-self._sigmaMin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._sigmaMin | result = self._functor(inter) - self._lmin | ||||
| t = (self._tmax-self._tmin)/(self._lmax-self._lmin)*(self._functor(inter)-self._lmin) + self._tmin | sigma = (self._sigmaMax - self._sigmaMin) / (self._lmax - self._lmin) * result + self._sigmaMin | ||||
| t = (self._tmax - self._tmin) / (self._lmax - self._lmin) * result + self._tmin | |||||
| sigma = max(sigma, self._sigmaMin) | sigma = max(sigma, self._sigmaMin) | ||||
| self._func = DensityF1D(sigma, self._integration, self._sampling) | self._func = DensityF1D(sigma, self._integration, self._sampling) | ||||
| return (self._func(inter) < t) | return (self._func(inter) < t) | ||||
| Context not available. | |||||
| # -- Binary predicates for 1D elements (curves) -- # | # -- Binary predicates for 1D elements (curves) -- # | ||||
| class AndBP1D(BinaryPredicate1D): | class AndBP1D(BinaryPredicate1D): | ||||
| def __init__(self, *predicates): | def __init__(self, *predicates): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| Context not available. | |||||
| class pyViewMapGradientNormBP1D(BinaryPredicate1D): | class pyViewMapGradientNormBP1D(BinaryPredicate1D): | ||||
| def __init__(self,l, sampling=2.0): | def __init__(self, l, sampling=2.0): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | ||||
| def __call__(self, i1,i2): | def __call__(self, i1, i2): | ||||
| return (self._GetGradient(i1) > self._GetGradient(i2)) | return (self._GetGradient(i1) > self._GetGradient(i2)) | ||||
| Context not available. | |||||
| random.seed = 1 | random.seed = 1 | ||||
| def __call__(self, inter1, inter2): | def __call__(self, inter1, inter2): | ||||
| return (random.uniform(0,1) < random.uniform(0,1)) | return (random.uniform(0, 1) < random.uniform(0, 1)) | ||||
| Context not available. | |||||
I guess you meant len(predicates) at the end of the error message.