Changeset View
Standalone View
release/scripts/freestyle/modules/freestyle/predicates.py
| Context not available. | |||||
| TVertex, | TVertex, | ||||
| UnaryPredicate0D, | UnaryPredicate0D, | ||||
| UnaryPredicate1D, | UnaryPredicate1D, | ||||
| Id, | |||||
| ) | ) | ||||
| from freestyle.functions import ( | from freestyle.functions import ( | ||||
| Curvature2DAngleF0D, | Curvature2DAngleF0D, | ||||
| Context not available. | |||||
| pyDensityAnisotropyF1D, | pyDensityAnisotropyF1D, | ||||
| pyViewMapGradientNormF1D, | pyViewMapGradientNormF1D, | ||||
| ) | ) | ||||
| import random | import random | ||||
| ## Unary predicates for 0D elements (vertices) | # -- Unary predicates for 0D elements (vertices) -- # | ||||
| ############################################## | |||||
| class pyHigherCurvature2DAngleUP0D(UnaryPredicate0D): | class pyHigherCurvature2DAngleUP0D(UnaryPredicate0D): | ||||
| def __init__(self,a): | def __init__(self, a): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._a = a | self._a = a | ||||
| Context not available. | |||||
| class pyUEqualsUP0D(UnaryPredicate0D): | class pyUEqualsUP0D(UnaryPredicate0D): | ||||
| def __init__(self,u, w): | def __init__(self, u, w): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._u = u | self._u = u | ||||
| self._w = w | self._w = w | ||||
| self._func = pyCurvilinearLengthF0D() | |||||
kjym3: We could create the functor object in `__init__()` (e.g., self._getLength) and reuse it in… | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = pyCurvilinearLengthF0D() | u = self._func(inter) | ||||
| u = func(inter) | return (u > (self._u - self._w)) and (u < (self._u + self._w)) | ||||
| return (u > (self._u-self._w)) and (u < (self._u+self._w)) | |||||
| class pyVertexNatureUP0D(UnaryPredicate0D): | class pyVertexNatureUP0D(UnaryPredicate0D): | ||||
| Context not available. | |||||
| self._nature = nature | self._nature = nature | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| v = inter.object | return bool(inter.object.nature & self._nature) | ||||
| return (v.nature & self._nature) != 0 | |||||
| ## check whether an Interface0DIterator | |||||
| ## is a TVertex and is the one that is | |||||
| ## hidden (inferred from the context) | |||||
| class pyBackTVertexUP0D(UnaryPredicate0D): | class pyBackTVertexUP0D(UnaryPredicate0D): | ||||
| """ | |||||
| Check whether an Interface0DIterator | |||||
| references a TVertex and is the one that is | |||||
| hidden (inferred from the context) | |||||
| """ | |||||
| def __init__(self): | def __init__(self): | ||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._getQI = QuantitativeInvisibilityF0D() | self._getQI = QuantitativeInvisibilityF0D() | ||||
| def __call__(self, iter): | def __call__(self, iter): | ||||
| if (iter.object.nature & Nature.T_VERTEX) == 0: | if not (iter.object.nature & Nature.T_VERTEX) or iter.is_end: | ||||
| return False | return False | ||||
| if iter.is_end: | return self._getQI(iter) != 0 | ||||
Not Done Inline ActionsThe original notation qi != 0 seems more logical. kjym3: The original notation `qi != 0` seems more logical. | |||||
| return False | |||||
| if self._getQI(iter) != 0: | |||||
| return True | |||||
| return False | |||||
| class pyParameterUP0DGoodOne(UnaryPredicate0D): | class pyParameterUP0DGoodOne(UnaryPredicate0D): | ||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| u = inter.u | u = inter.u | ||||
| return ((u>=self._m) and (u<=self._M)) | return ((u >= self._m) and (u <= self._M)) | ||||
| class pyParameterUP0D(UnaryPredicate0D): | class pyParameterUP0D(UnaryPredicate0D): | ||||
| Context not available. | |||||
| UnaryPredicate0D.__init__(self) | UnaryPredicate0D.__init__(self) | ||||
| self._m = pmin | self._m = pmin | ||||
| self._M = pmax | self._M = pmax | ||||
| self._func = Curvature2DAngleF0D() | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = Curvature2DAngleF0D() | c = self._func(inter) | ||||
| c = func(inter) | b1 = (c > 0.1) | ||||
Not Done Inline ActionsSame as the previous comment in line 98. kjym3: Same as the previous comment in line 98. | |||||
| b1 = (c>0.1) | |||||
| u = inter.u | u = inter.u | ||||
| 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, pred1, pred2): | def __init__(self, *predicates): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self.__pred1 = pred1 | self.predicates = predicates | ||||
| self.__pred2 = pred2 | if len(self.predicates) < 2: | ||||
| raise ValueError("Expected two or more UnaryPredicate1D") | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return self.__pred1(inter) and self.__pred2(inter) | return all(pred(inter) for pred in self.predicates) | ||||
Not Done Inline ActionsThis if block seems wrong. How about adding an argument check in __init__() to make sure the self.predicates have two or more predicates, and raise a ValueError if that is not the case? kjym3: This `if` block seems wrong. How about adding an argument check in `__init__()` to make sure… | |||||
| class OrUP1D(UnaryPredicate1D): | class OrUP1D(UnaryPredicate1D): | ||||
| def __init__(self, pred1, pred2): | def __init__(self, *predicates): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self.__pred1 = pred1 | self.predicates = predicates | ||||
| self.__pred2 = pred2 | if len(self.predicates) < 2: | ||||
| raise ValueError("Expected two or more UnaryPredicate1D") | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return self.__pred1(inter) or self.__pred2(inter) | return any(pred(inter) for pred in self.predicates) | ||||
Not Done Inline ActionsSame as the previous comment in line 165. kjym3: Same as the previous comment in line 165. | |||||
| class NotUP1D(UnaryPredicate1D): | class NotUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return not self.__pred(inter) | return not self.__pred(inter) | ||||
| class ObjectNamesUP1D(UnaryPredicate1D): | |||||
| def __init__(self, names, negative=False): | |||||
| UnaryPredicate1D.__init__(self) | |||||
| self._names = names | |||||
| self._negative = negative | |||||
| def __call__(self, viewEdge): | |||||
| found = viewEdge.viewshape.name in self._names | |||||
| return found if not self._negative else not found | |||||
| class QuantitativeInvisibilityRangeUP1D(UnaryPredicate1D): | |||||
| def __init__(self, qi_start, qi_end): | |||||
| UnaryPredicate1D.__init__(self) | |||||
| self.__getQI = QuantitativeInvisibilityF1D() | |||||
| self.__qi_start = qi_start | |||||
| self.__qi_end = qi_end | |||||
| def __call__(self, inter): | |||||
| qi = self.__getQI(inter) | |||||
| return (self.__qi_start <= qi <= self.__qi_end) | |||||
| class pyNFirstUP1D(UnaryPredicate1D): | class pyNFirstUP1D(UnaryPredicate1D): | ||||
| def __init__(self, n): | def __init__(self, n): | ||||
| Context not available. | |||||
| self.__count = 0 | self.__count = 0 | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| self.__count = self.__count + 1 | self.__count += 1 | ||||
| if self.__count <= self.__n: | return (self.__count <= self.__n) | ||||
| return True | |||||
| return False | |||||
| class pyHigherLengthUP1D(UnaryPredicate1D): | class pyHigherLengthUP1D(UnaryPredicate1D): | ||||
| def __init__(self,l): | def __init__(self, l): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._l = l | self._l = l | ||||
| Context not available. | |||||
| self._getNature = CurveNatureF1D() | self._getNature = CurveNatureF1D() | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| if(self._getNature(inter) & self._nature): | return bool(self._getNature(inter) & self._nature) | ||||
| return True | |||||
| return False | |||||
| class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D): | class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D): | ||||
| def __init__(self,n,a): | def __init__(self, n, a): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._n = n | self._n = n | ||||
| self._a = a | self._a = a | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| count = 0 | |||||
| func = Curvature2DAngleF0D() | func = Curvature2DAngleF0D() | ||||
| it = inter.vertices_begin() | it = inter.vertices_begin() | ||||
Not Done Inline ActionsI liked the expression sum(1 for ve in it if func(it) > self._a) in a previous revision. Is there any reason the new form is preferable? kjym3: I liked the expression `sum(1 for ve in it if func(it) > self._a)` in a previous revision. Is… | |||||
| while not it.is_end: | # sum the turns, check against n | ||||
| if func(it) > self._a: | return sum(1 for ve in it if func(it) > self._a) > self._n | ||||
| count = count+1 | |||||
| if count > self._n: | |||||
| return True | |||||
| it.increment() | |||||
| return False | |||||
| class pyDensityUP1D(UnaryPredicate1D): | class pyDensityUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| def __init__(self, threshold, level, integration=IntegrationType.MEAN): | def __init__(self, threshold, level, integration=IntegrationType.MEAN): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._threshold = threshold | self._threshold = threshold | ||||
| self._level = level | self._func = GetSteerableViewMapDensityF1D(level, integration) | ||||
| self._integration = integration | |||||
| self._func = GetSteerableViewMapDensityF1D(self._level, self._integration) | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return (self._func(inter) > self._threshold) | return (self._func(inter) > self._threshold) | ||||
| Context not available. | |||||
| 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) | UnaryPredicate1D.__init__(self) | ||||
| self._threshold = threshold | self._threshold = threshold | ||||
| self._orientation = orientation | self._func = GetDirectionalViewMapDensityF1D(orientation, level, integration, sampling) | ||||
| self._level = level | |||||
| self._integration = integration | |||||
| self._sampling = sampling | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetDirectionalViewMapDensityF1D(self._orientation, self._level, self._integration, self._sampling) | return (self.func(inter) > self._threshold) | ||||
| return (func(inter) > self._threshold) | |||||
| class pyHighViewMapDensityUP1D(UnaryPredicate1D): | 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) | UnaryPredicate1D.__init__(self) | ||||
| self._threshold = threshold | self._threshold = threshold | ||||
| self._level = level | self._func = GetCompleteViewMapDensityF1D(level, integration, sampling) | ||||
| self._integration = integration | |||||
| self._sampling = sampling | |||||
| self._func = GetCompleteViewMapDensityF1D(self._level, self._integration, self._sampling) # 2.0 is the smpling | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| return (self._func(inter) > self._threshold) | return (self._func(inter) > self._threshold) | ||||
Not Done Inline ActionsIs inter.object correct? (cf. the original code) kjym3: Is `inter.object` correct? (cf. the original code) | |||||
Not Done Inline Actionsit is not correct. probably forgot that while testing. using self._func(inter) will however result in an infinite loop printing "this viewmap does not exist", alike most, if not all, ...Viewmap...-methods. because of this i've ommited it from my tests. flokkievids: it is not correct. probably forgot that while testing. using self._func(inter) will however… | |||||
| Context not available. | |||||
| class pyDensityFunctorUP1D(UnaryPredicate1D): | 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) | UnaryPredicate1D.__init__(self) | ||||
| self._wsize = wsize | |||||
| self._threshold = float(threshold) | self._threshold = float(threshold) | ||||
| self._functor = functor | self._functor = functor | ||||
| self._funcmin = float(funcmin) | self._funcmin = float(funcmin) | ||||
| self._funcmax = float(funcmax) | self._funcmax = float(funcmax) | ||||
| self._integration = integration | self._func = DensityF1D(wsize, integration) | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = DensityF1D(self._wsize, self._integration) | |||||
| res = self._functor(inter) | res = self._functor(inter) | ||||
| k = (res-self._funcmin)/(self._funcmax-self._funcmin) | k = (res - self._funcmin) / (self._funcmax - self._funcmin) | ||||
| return (func(inter) < (self._threshold * k)) | return (func(inter) < (self._threshold * k)) | ||||
| class pyZSmallerUP1D(UnaryPredicate1D): | class pyZSmallerUP1D(UnaryPredicate1D): | ||||
| def __init__(self,z, integration=IntegrationType.MEAN): | def __init__(self, z, integration=IntegrationType.MEAN): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._z = z | self._z = z | ||||
| self._integration = integration | self.func = GetProjectedZF1D(integration) | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetProjectedZF1D(self._integration) | return (self.func(inter) < self._z) | ||||
| return (func(inter) < self._z) | |||||
| 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): | |||||
| raise TypeError("pyIsOccludedByUP1D expected freestyle.types.Id, not " + type(id).__name__) | |||||
| self._id = id | self._id = id | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetShapeF1D() | shapes = GetShapeF1D()(inter) | ||||
| shapes = func(inter) | if any(s.id == self._id for s in shapes): | ||||
| for s in shapes: | return False | ||||
| if(s.id == self._id): | |||||
| return False | # construct iterators | ||||
| it = inter.vertices_begin() | it = inter.vertices_begin() | ||||
| itlast = inter.vertices_end() | itlast = inter.vertices_end() | ||||
| itlast.decrement() | itlast.decrement() | ||||
| v = it.object | |||||
| vlast = itlast.object | vertex = next(it) | ||||
Not Done Inline ActionsComparing the original and modified code, is next(it) the same as it.object.viewvertex? kjym3: Comparing the original and modified code, is `next(it)` the same as `it.object.viewvertex`? | |||||
Not Done Inline ActionsAgain, unable to test, executing this function enters an infinite loop printing "this steerable viewmap level does not exist" flokkievids: Again, unable to test, executing this function enters an infinite loop printing "this steerable… | |||||
| tvertex = v.viewvertex | if type(vertex) is TVertex: | ||||
| if type(tvertex) is TVertex: | eit = vertex.edges_begin() | ||||
| #print("TVertex: [ ", tvertex.id.first, ",", tvertex.id.second," ]") | if any(ve.id == self._id for (ve, incoming) in eit): | ||||
| eit = tvertex.edges_begin() | return True | ||||
| while not eit.is_end: | |||||
| ve, incoming = eit.object | vertex = next(itlast) | ||||
Not Done Inline ActionsSame question as in line 360. kjym3: Same question as in line 360. | |||||
| if ve.id == self._id: | if type(vertex) is TVertex: | ||||
| return True | |||||
| #print("-------", ve.id.first, "-", ve.id.second) | |||||
| eit.increment() | |||||
| tvertex = vlast.viewvertex | |||||
| if type(tvertex) is TVertex: | |||||
| #print("TVertex: [ ", tvertex.id.first, ",", tvertex.id.second," ]") | |||||
| eit = tvertex.edges_begin() | eit = tvertex.edges_begin() | ||||
| while not eit.is_end: | if any(ve.id == self._id for (ve, incoming) in eit): | ||||
| ve, incoming = eit.object | return True | ||||
| if ve.id == self._id: | |||||
| return True | |||||
| #print("-------", ve.id.first, "-", ve.id.second) | |||||
| eit.increment() | |||||
| return False | return False | ||||
| Context not available. | |||||
| self._id = id | self._id = id | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetOccludersF1D() | occluders = GetOccludersF1D()(inter) | ||||
| occluders = func(inter) | return any(a.id == self._id for a in occluders) | ||||
| for a in occluders: | |||||
| if a.id == self._id: | |||||
| return True | |||||
| return False | |||||
| class pyIsOccludedByItselfUP1D(UnaryPredicate1D): | class pyIsOccludedByItselfUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| lst1 = self.__func1(inter) | lst1 = self.__func1(inter) | ||||
| lst2 = self.__func2(inter) | lst2 = self.__func2(inter) | ||||
| for vs1 in lst1: | return any(vs1.id == vs2.id for vs1 in lst1 for vs2 in lst2) | ||||
| for vs2 in lst2: | |||||
| if vs1.id == vs2.id: | |||||
| return True | |||||
| return False | |||||
| class pyIsOccludedByIdListUP1D(UnaryPredicate1D): | class pyIsOccludedByIdListUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| self.__func1 = GetOccludersF1D() | self.__func1 = GetOccludersF1D() | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| lst1 = self.__func1(inter) | lst1 = self.__func1(inter.object) | ||||
| for vs1 in lst1: | return any(vs1.id == _id for vs1 in lst1 for _id in self._idlist) | ||||
| for _id in self._idlist: | |||||
| if vs1.id == _id: | |||||
| return True | |||||
| return False | |||||
| class pyShapeIdListUP1D(UnaryPredicate1D): | class pyShapeIdListUP1D(UnaryPredicate1D): | ||||
| def __init__(self,idlist): | def __init__(self,idlist): | ||||
| UnaryPredicate1D.__init__(self) | UnaryPredicate1D.__init__(self) | ||||
| self._idlist = idlist | self._funcs = tuple(ShapeUP1D(_id, 0) for _id in idlist) | ||||
| self._funcs = [] | |||||
| for _id in idlist: | |||||
| self._funcs.append(ShapeUP1D(_id.first, _id.second)) | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| for func in self._funcs: | return any(func(inter) for func in self._funcs) | ||||
| if func(inter) == 1: | |||||
| return True | |||||
| return False | |||||
| ## deprecated | ## deprecated | ||||
| Context not available. | |||||
| self._id = _id | self._id = _id | ||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| func = GetShapeF1D() | shapes = GetShapeF1D()(inter) | ||||
| shapes = func(inter) | return any(a.id == self._id for a in shapes) | ||||
| for a in shapes: | |||||
| if a.id == self._id: | |||||
| return True | |||||
| return False | |||||
| class pyHighDensityAnisotropyUP1D(UnaryPredicate1D): | class pyHighDensityAnisotropyUP1D(UnaryPredicate1D): | ||||
| Context not available. | |||||
| def __call__(self, inter): | def __call__(self, inter): | ||||
| gn = self._GetGradient(inter) | gn = self._GetGradient(inter) | ||||
| #print(gn) | |||||
| return (gn > self._threshold) | return (gn > self._threshold) | ||||
| Context not available. | |||||
| it = inter.vertices_begin() | it = inter.vertices_begin() | ||||
| itlast = inter.vertices_end() | itlast = inter.vertices_end() | ||||
| itlast.decrement() | itlast.decrement() | ||||
| vlast = itlast.object | return (next(it).id == next(itlast).id) | ||||
| v = it.object | |||||
| #print(v.id.first, v.id.second) | |||||
| #print(vlast.id.first, vlast.id.second) | |||||
| if v.id == vlast.id: | |||||
| return True | |||||
| return False | |||||
| ## Binary predicates for 1D elements (curves) | # -- Binary predicates for 1D elements (curves) -- # | ||||
| ############################################# | |||||
| class AndBP1D(BinaryPredicate1D): | class AndBP1D(BinaryPredicate1D): | ||||
| def __init__(self, pred1, pred2): | def __init__(self, *predicates): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
Not Done Inline ActionsShould be if not self._predicates:. kjym3: Should be `if not self._predicates:`. | |||||
Not Done Inline Actions"Expected two or more BinaryPredicate1D" kjym3: "Expected two or more BinaryPredicate1D" | |||||
| self.__pred1 = pred1 | self._predicates = predicates | ||||
| self.__pred2 = pred2 | if len(self.predicates) < 2: | ||||
| raise ValueError("Expected two or more BinaryPredicate1D") | |||||
| def __call__(self, inter1, inter2): | |||||
| return self.__pred1(inter1, inter2) and self.__pred2(inter1, inter2) | |||||
| def __call__(self, i1, i2): | |||||
Not Done Inline ActionsSame comment here as in AndUP1D. kjym3: Same comment here as in AndUP1D. | |||||
| return all(pred(i1, i2) for pred in self._predicates) | |||||
| class OrBP1D(BinaryPredicate1D): | class OrBP1D(BinaryPredicate1D): | ||||
| def __init__(self, pred1, pred2): | def __init__(self, *predicates): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
Not Done Inline ActionsSame as the comment in line 482. kjym3: Same as the comment in line 482. | |||||
Not Done Inline Actions"Expected two or more BinaryPredicate1D" kjym3: "Expected two or more BinaryPredicate1D" | |||||
| self.__pred1 = pred1 | self._predicates = predicates | ||||
| self.__pred2 = pred2 | if len(self.predicates) < 2: | ||||
| raise ValueError("Expected two or more BinaryPredicate1D") | |||||
| def __call__(self, inter1, inter2): | def __call__(self, i1, i2): | ||||
Not Done Inline ActionsSame comment here as in OrUP1D. kjym3: Same comment here as in OrUP1D. | |||||
| return self.__pred1(inter1, inter2) or self.__pred2(inter1, inter2) | return any(pred(i1, i2) for pred in self._predicates) | ||||
| class NotBP1D(BinaryPredicate1D): | class NotBP1D(BinaryPredicate1D): | ||||
| def __init__(self, pred): | def __init__(self, predicate): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| self.__pred = pred | self._predicate = predicate | ||||
| def __call__(self, inter1, inter2): | def __call__(self, i1, i2): | ||||
| return not self.__pred(inter1, inter2) | return (not self._precicate(i1, i2)) | ||||
| class pyZBP1D(BinaryPredicate1D): | class pyZBP1D(BinaryPredicate1D): | ||||
| def __init__(self, iType=IntegrationType.MEAN): | def __init__(self, iType=IntegrationType.MEAN): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| self._GetZ = GetZF1D(iType) | self.func = GetZF1D(iType) | ||||
| def __call__(self, i1, i2): | def __call__(self, i1, i2): | ||||
| return (self._GetZ(i1) > self._GetZ(i2)) | return (self.func(i1) > self.func(i2)) | ||||
| class pyZDiscontinuityBP1D(BinaryPredicate1D): | class pyZDiscontinuityBP1D(BinaryPredicate1D): | ||||
| Context not available. | |||||
| class pySilhouetteFirstBP1D(BinaryPredicate1D): | class pySilhouetteFirstBP1D(BinaryPredicate1D): | ||||
| def __call__(self, inter1, inter2): | def __call__(self, inter1, inter2): | ||||
| bpred = SameShapeIdBP1D() | bpred = SameShapeIdBP1D() | ||||
| if (bpred(inter1, inter2) != 1): | if (not bpred(inter1, inter2)): | ||||
| return False | return False | ||||
| if (inter1.nature & Nature.SILHOUETTE): | if (inter1.nature & Nature.SILHOUETTE): | ||||
Not Done Inline ActionsThis comment is not always true, since pyNatureBP1D is mostly meant to be used as an argument of an API function that takes a 1D binary predicate. kjym3: This comment is not always true, since pyNatureBP1D is mostly meant to be used as an argument… | |||||
| return (inter2.nature & Nature.SILHOUETTE) != 0 | return bool(inter2.nature & Nature.SILHOUETTE) | ||||
| return (inter1.nature == inter2.nature) | return (inter1.nature == inter2.nature) | ||||
| Context not available. | |||||
| self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | self._GetGradient = pyViewMapGradientNormF1D(l, IntegrationType.MEAN) | ||||
| def __call__(self, i1,i2): | def __call__(self, i1,i2): | ||||
| #print("compare gradient") | |||||
| return (self._GetGradient(i1) > self._GetGradient(i2)) | return (self._GetGradient(i1) > self._GetGradient(i2)) | ||||
| class pyShuffleBP1D(BinaryPredicate1D): | class pyShuffleBP1D(BinaryPredicate1D): | ||||
| def __init__(self): | def __init__(self): | ||||
| BinaryPredicate1D.__init__(self) | BinaryPredicate1D.__init__(self) | ||||
| random.seed(1) | random.seed = 1 | ||||
| def __call__(self, inter1, inter2): | def __call__(self, inter1, inter2): | ||||
| r1 = random.uniform(0,1) | return (random.uniform(0,1) < random.uniform(0,1)) | ||||
| r2 = random.uniform(0,1) | No newline at end of file | ||||
| return (r1<r2) | |||||
| Context not available. | |||||
We could create the functor object in __init__() (e.g., self._getLength) and reuse it in __call__. That should be faster than instantiating the functor at every 0D element.