Welcome to mirror list, hosted at ThFree Co, Russian Federation.

predicates.py « freestyle « modules « freestyle « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54656e450d9c3fac277f42cbb8f09d30a7287865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

"""
This module contains predicates operating on vertices (0D elements)
and polylines (1D elements).  It is also intended to be a collection
of examples for predicate definition in Python.

User-defined predicates inherit one of the following base classes,
depending on the object type (0D or 1D) to operate on and the arity
(unary or binary):

- :class:`freestyle.types.BinaryPredicate0D`
- :class:`freestyle.types.BinaryPredicate1D`
- :class:`freestyle.types.UnaryPredicate0D`
- :class:`freestyle.types.UnaryPredicate1D`
"""

__all__ = (
    "AndBP1D",
    "AndUP1D",
    "ContourUP1D",
    "DensityLowerThanUP1D",
    "EqualToChainingTimeStampUP1D",
    "EqualToTimeStampUP1D",
    "ExternalContourUP1D",
    "FalseBP1D",
    "FalseUP0D",
    "FalseUP1D",
    "Length2DBP1D",
    "NotBP1D",
    "NotUP1D",
    "ObjectNamesUP1D",
    "OrBP1D",
    "OrUP1D",
    "QuantitativeInvisibilityRangeUP1D",
    "QuantitativeInvisibilityUP1D",
    "SameShapeIdBP1D",
    "ShapeUP1D",
    "TrueBP1D",
    "TrueUP0D",
    "TrueUP1D",
    "ViewMapGradientNormBP1D",
    "WithinImageBoundaryUP1D",
    "pyBackTVertexUP0D",
    "pyClosedCurveUP1D",
    "pyDensityFunctorUP1D",
    "pyDensityUP1D",
    "pyDensityVariableSigmaUP1D",
    "pyHighDensityAnisotropyUP1D",
    "pyHighDirectionalViewMapDensityUP1D",
    "pyHighSteerableViewMapDensityUP1D",
    "pyHighViewMapDensityUP1D",
    "pyHighViewMapGradientNormUP1D",
    "pyHigherCurvature2DAngleUP0D",
    "pyHigherLengthUP1D",
    "pyHigherNumberOfTurnsUP1D",
    "pyIsInOccludersListUP1D",
    "pyIsOccludedByIdListUP1D",
    "pyIsOccludedByItselfUP1D",
    "pyIsOccludedByUP1D",
    "pyLengthBP1D",
    "pyLowDirectionalViewMapDensityUP1D",
    "pyLowSteerableViewMapDensityUP1D",
    "pyNFirstUP1D",
    "pyNatureBP1D",
    "pyNatureUP1D",
    "pyParameterUP0D",
    "pyParameterUP0DGoodOne",
    "pyProjectedXBP1D",
    "pyProjectedYBP1D",
    "pyShapeIdListUP1D",
    "pyShapeIdUP1D",
    "pyShuffleBP1D",
    "pySilhouetteFirstBP1D",
    "pyUEqualsUP0D",
    "pyVertexNatureUP0D",
    "pyViewMapGradientNormBP1D",
    "pyZBP1D",
    "pyZDiscontinuityBP1D",
    "pyZSmallerUP1D",
    )


# module members
from _freestyle import (
    ContourUP1D,
    DensityLowerThanUP1D,
    EqualToChainingTimeStampUP1D,
    EqualToTimeStampUP1D,
    ExternalContourUP1D,
    FalseBP1D,
    FalseUP0D,
    FalseUP1D,
    Length2DBP1D,
    QuantitativeInvisibilityUP1D,
    SameShapeIdBP1D,
    ShapeUP1D,
    TrueBP1D,
    TrueUP0D,
    TrueUP1D,
    ViewMapGradientNormBP1D,
    WithinImageBoundaryUP1D,
    )

# constructs for predicate definition in Python
from freestyle.types import (
    BinaryPredicate1D,
    Id,
    IntegrationType,
    Interface0DIterator,
    Nature,
    TVertex,
    UnaryPredicate0D,
    UnaryPredicate1D,
    )
from freestyle.functions import (
    Curvature2DAngleF0D,
    CurveNatureF1D,
    DensityF1D,
    GetCompleteViewMapDensityF1D,
    GetCurvilinearAbscissaF0D,
    GetDirectionalViewMapDensityF1D,
    GetOccludersF1D,
    GetProjectedXF1D,
    GetProjectedYF1D,
    GetProjectedZF1D,
    GetShapeF1D,
    GetSteerableViewMapDensityF1D,
    GetZF1D,
    QuantitativeInvisibilityF0D,
    ZDiscontinuityF1D,
    pyCurvilinearLengthF0D,
    pyDensityAnisotropyF1D,
    pyViewMapGradientNormF1D,
    )

import random


# -- Unary predicates for 0D elements (vertices) -- #


class pyHigherCurvature2DAngleUP0D(UnaryPredicate0D):
    def __init__(self, a):
        UnaryPredicate0D.__init__(self)
        self._a = a
        self.func = Curvature2DAngleF0D()

    def __call__(self, inter):
        return (self.func(inter) > self._a)


class pyUEqualsUP0D(UnaryPredicate0D):
    def __init__(self, u, w):
        UnaryPredicate0D.__init__(self)
        self._u = u
        self._w = w
        self._func = pyCurvilinearLengthF0D()

    def __call__(self, inter):
        u = self._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):
        return bool(inter.object.nature & self._nature)


class pyBackTVertexUP0D(UnaryPredicate0D):
    """
    Check whether an Interface0DIterator references a TVertex and is
    the one that is hidden (inferred from the context).
    """
    def __init__(self):
        UnaryPredicate0D.__init__(self)
        self._getQI = QuantitativeInvisibilityF0D()

    def __call__(self, iter):
        if not (iter.object.nature & Nature.T_VERTEX) or iter.is_end:
            return False
        return self._getQI(iter) != 0


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
        self._func = Curvature2DAngleF0D()

    def __call__(self, inter):
        c = self._func(inter)
        b1 = (c > 0.1)
        u = inter.u
        b = ((u >= self._m) and (u <= self._M))
        return (b and b1)


# -- Unary predicates for 1D elements (curves) -- #

class AndUP1D(UnaryPredicate1D):
    def __init__(self, *predicates):
        UnaryPredicate1D.__init__(self)
        self.predicates = predicates
        # there are cases in which only one predicate is supplied (in the parameter editor)
        if len(self.predicates) < 1:
            raise ValueError("Expected one or more UnaryPredicate1D, got ", len(predicates))

    def __call__(self, inter):
        return all(pred(inter) for pred in self.predicates)


class OrUP1D(UnaryPredicate1D):
    def __init__(self, *predicates):
        UnaryPredicate1D.__init__(self)
        self.predicates = predicates
        # there are cases in which only one predicate is supplied (in the parameter editor)
        if len(self.predicates) < 1:
            raise ValueError("Expected one or more UnaryPredicate1D, got ", len(predicates))

    def __call__(self, inter):
        return any(pred(inter) for pred in self.predicates)


class NotUP1D(UnaryPredicate1D):
    def __init__(self, pred):
        UnaryPredicate1D.__init__(self)
        self.__pred = pred

    def __call__(self, 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):
    def __init__(self, n):
        UnaryPredicate1D.__init__(self)
        self.__n = n
        self.__count = 0

    def __call__(self, inter):
        self.__count += 1
        return (self.__count <= self.__n)


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):
        return bool(self._getNature(inter) & self._nature)


class pyHigherNumberOfTurnsUP1D(UnaryPredicate1D):
    def __init__(self, n, a):
        UnaryPredicate1D.__init__(self)
        self._n = n
        self._a = a
        self.func = Curvature2DAngleF0D()

    def __call__(self, inter):
        it = Interface0DIterator(inter)
        # sum the turns, check against 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):
    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):
        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):
        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):
        UnaryPredicate1D.__init__(self)
        self._threshold = threshold
        self._func = GetSteerableViewMapDensityF1D(level, 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):
        UnaryPredicate1D.__init__(self)
        self._threshold = threshold
        self._func = GetDirectionalViewMapDensityF1D(orientation, level, integration, sampling)

    def __call__(self, inter):
        return (self.func(inter) > self._threshold)


class pyHighViewMapDensityUP1D(UnaryPredicate1D):
    def __init__(self, threshold, level, integration=IntegrationType.MEAN, sampling=2.0):
        UnaryPredicate1D.__init__(self)
        self._threshold = threshold
        self._func = GetCompleteViewMapDensityF1D(level, integration, sampling)

    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):
        UnaryPredicate1D.__init__(self)
        self._threshold = float(threshold)
        self._functor = functor
        self._funcmin = float(funcmin)
        self._funcmax = float(funcmax)
        self._func = DensityF1D(wsize, integration)

    def __call__(self, inter):
        res = self._functor(inter)
        k = (res - self._funcmin) / (self._funcmax - self._funcmin)
        return (func(inter) < (self._threshold * k))


class pyZSmallerUP1D(UnaryPredicate1D):
    def __init__(self, z, integration=IntegrationType.MEAN):
        UnaryPredicate1D.__init__(self)
        self._z = z
        self.func = GetProjectedZF1D(integration)

    def __call__(self, inter):
        return (self.func(inter) < self._z)


class pyIsOccludedByUP1D(UnaryPredicate1D):
    def __init__(self, id):
        UnaryPredicate1D.__init__(self)
        if not isinstance(id, Id):
            raise TypeError("pyIsOccludedByUP1D expected freestyle.types.Id, not " + type(id).__name__)
        self._id = id

    def __call__(self, inter):
        shapes = GetShapeF1D()(inter)
        if any(s.id == self._id for s in shapes):
            return False

        # construct iterators
        it = inter.vertices_begin()
        itlast = inter.vertices_end()
        itlast.decrement()

        vertex = next(it)
        if type(vertex) is TVertex:
            eit = vertex.edges_begin()
            if any(ve.id == self._id for (ve, incoming) in eit):
                return True

        vertex = next(itlast)
        if type(vertex) is TVertex:
            eit = tvertex.edges_begin()
            if any(ve.id == self._id for (ve, incoming) in eit):
                return True
        return False


class pyIsInOccludersListUP1D(UnaryPredicate1D):
    def __init__(self, id):
        UnaryPredicate1D.__init__(self)
        self._id = id

    def __call__(self, inter):
        occluders = GetOccludersF1D()(inter)
        return any(a.id == self._id for a in occluders)


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)
        return any(vs1.id == vs2.id for vs1 in lst1 for vs2 in lst2)


class pyIsOccludedByIdListUP1D(UnaryPredicate1D):
    def __init__(self, idlist):
        UnaryPredicate1D.__init__(self)
        self._idlist = idlist
        self.__func1 = GetOccludersF1D()

    def __call__(self, inter):
        lst1 = self.__func1(inter.object)
        return any(vs1.id == _id for vs1 in lst1 for _id in self._idlist)


class pyShapeIdListUP1D(UnaryPredicate1D):
    def __init__(self, idlist):
        UnaryPredicate1D.__init__(self)
        self._funcs = tuple(ShapeUP1D(_id, 0) for _id in idlist)

    def __call__(self, inter):
        return any(func(inter) for func in self._funcs)


# DEPRECATED
class pyShapeIdUP1D(UnaryPredicate1D):
    def __init__(self, _id):
        UnaryPredicate1D.__init__(self)
        self._id = _id

    def __call__(self, inter):
        shapes = GetShapeF1D()(inter)
        return any(a.id == self._id for a in shapes)


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)
        return (gn > self._threshold)


class pyDensityVariableSigmaUP1D(UnaryPredicate1D):
    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)
        self._sigmaMax = float(sigmaMax)
        self._lmin = float(lmin)
        self._lmax = float(lmax)
        self._tmin = tmin
        self._tmax = tmax
        self._integration = integration
        self._sampling = sampling

    def __call__(self, inter):
        result = self._functor(inter) - self._lmin
        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)
        self._func = DensityF1D(sigma, self._integration, self._sampling)
        return (self._func(inter) < t)


class pyClosedCurveUP1D(UnaryPredicate1D):
    def __call__(self, inter):
        it = inter.vertices_begin()
        itlast = inter.vertices_end()
        itlast.decrement()
        return (next(it).id == next(itlast).id)


# -- Binary predicates for 1D elements (curves) -- #

class AndBP1D(BinaryPredicate1D):
    def __init__(self, *predicates):
        BinaryPredicate1D.__init__(self)
        self._predicates = predicates
        if len(self.predicates) < 2:
            raise ValueError("Expected two or more BinaryPredicate1D, got ", len(predictates))

    def __call__(self, i1, i2):
        return all(pred(i1, i2) for pred in self._predicates)


class OrBP1D(BinaryPredicate1D):
    def __init__(self, *predicates):
        BinaryPredicate1D.__init__(self)
        self._predicates = predicates
        if len(self.predicates) < 2:
            raise ValueError("Expected two or more BinaryPredicate1D, got ", len(predictates))

    def __call__(self, i1, i2):
        return any(pred(i1, i2) for pred in self._predicates)


class NotBP1D(BinaryPredicate1D):
    def __init__(self, predicate):
        BinaryPredicate1D.__init__(self)
        self._predicate = predicate

    def __call__(self, i1, i2):
        return (not self._predicate(i1, i2))


class pyZBP1D(BinaryPredicate1D):
    def __init__(self, iType=IntegrationType.MEAN):
        BinaryPredicate1D.__init__(self)
        self.func = GetZF1D(iType)

    def __call__(self, i1, i2):
        return (self.func(i1) > self.func(i2))


class pyProjectedXBP1D(BinaryPredicate1D):
    def __init__(self, iType=IntegrationType.MEAN):
        BinaryPredicate1D.__init__(self)
        self.func = GetProjectedXF1D(iType)

    def __call__(self, i1, i2):
        return (self.func(i1) > self.func(i2))


class pyProjectedYBP1D(BinaryPredicate1D):
    def __init__(self, iType=IntegrationType.MEAN):
        BinaryPredicate1D.__init__(self)
        self.func = GetProjectedYF1D(iType)

    def __call__(self, i1, i2):
        return (self.func(i1) > self.func(i2))


class pyZDiscontinuityBP1D(BinaryPredicate1D):
    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()
        if (not bpred(inter1, inter2)):
            return False
        if (inter1.nature & Nature.SILHOUETTE):
            return bool(inter2.nature & Nature.SILHOUETTE)
        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):
        return (self._GetGradient(i1) > self._GetGradient(i2))


class pyShuffleBP1D(BinaryPredicate1D):
    def __init__(self):
        BinaryPredicate1D.__init__(self)
        random.seed = 1

    def __call__(self, inter1, inter2):
        return (random.uniform(0, 1) < random.uniform(0, 1))