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. | |||||
| b = ((u >= self._m) and (u <= self._M)) | b = ((u >= self._m) and (u <= self._M)) | ||||
| return (b and b1) | return (b and b1) | ||||
| # -- 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) | ||||
kjym3: I guess you meant `len(predicates)` at the end of the error message. | |||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return not self.__pred(inter) | return not self.__pred(inter) | ||||
| class ObjectNamesUP1D(UnaryPredicate1D): | class ObjectNamesUP1D(UnaryPredicate1D): | ||||
| def __init__(self, names, negative=False): | def __init__(self, names, negative=False): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| Context not available. | |||||
| found = viewEdge.viewshape.name in self._names | found = viewEdge.viewshape.name in self._names | ||||
| return found if not self._negative else not found | return found if not self._negative else not found | ||||
| class QuantitativeInvisibilityRangeUP1D(UnaryPredicate1D): | class QuantitativeInvisibilityRangeUP1D(UnaryPredicate1D): | ||||
| def __init__(self, qi_start, qi_end): | def __init__(self, qi_start, qi_end): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| Context not available. | |||||
| qi = self.__getQI(inter) | qi = self.__getQI(inter) | ||||
| return (self.__qi_start <= qi <= self.__qi_end) | return (self.__qi_start <= qi <= self.__qi_end) | ||||
| class pyNFirstUP1D(UnaryPredicate1D): | class pyNFirstUP1D(UnaryPredicate1D): | ||||
| def __init__(self, n): | def __init__(self, n): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| Context not available. | |||||
| return (self.__count <= self.__n) | return (self.__count <= self.__n) | ||||
| class pyHigherLengthUP1D(UnaryPredicate1D): | class pyHigherLengthUP1D(UnaryPredicate1D): | ||||
| def __init__(self, l): | def __init__(self, l): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| 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 | |||||
| class pyDensityUP1D(UnaryPredicate1D): | class pyDensityUP1D(UnaryPredicate1D): | ||||
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… | |||||
| 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): | ||||
| 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. | |||||
| def __call__(self, i1, i2): | def __call__(self, i1, i2): | ||||
| return all(pred(i1, i2) for pred in self._predicates) | return all(pred(i1, i2) for pred in self._predicates) | ||||
| class OrBP1D(BinaryPredicate1D): | class OrBP1D(BinaryPredicate1D): | ||||
| def __init__(self, *predicates): | def __init__(self, *predicates): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| 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)) | ||||
| No newline at end of file | |||||
| Context not available. | |||||
I guess you meant len(predicates) at the end of the error message.