Blender V5.0
Predicates1D.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11
12#include <string>
13
14#include "AdvancedFunctions1D.h"
15
16#include "../system/TimeStamp.h"
17
20
21#include "MEM_guardedalloc.h"
22
23namespace Freestyle {
24
25//
26// UnaryPredicate1D (base class for predicates in 1D)
27//
29
37 public:
38 bool result;
39 void *py_up1D;
40
43 {
44 py_up1D = nullptr;
45 }
46
48 virtual ~UnaryPredicate1D() {}
49
51 virtual string getName() const
52 {
53 return "UnaryPredicate1D";
54 }
55
61 virtual int operator()(Interface1D &inter);
62
63 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate1D")
64};
65
66//
67// BinaryPredicate1D (base class for predicates in 1D)
68//
70
77 public:
78 bool result;
79 void *py_bp1D;
80
83 {
84 py_bp1D = nullptr;
85 }
86
88 virtual ~BinaryPredicate1D() {}
89
91 virtual string getName() const
92 {
93 return "BinaryPredicate1D";
94 }
95
104 virtual int operator()(Interface1D &inter1, Interface1D &inter2);
105
106 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D")
107};
108
109//
110// Predicates definitions
111//
113
114namespace Predicates1D {
115
116// TrueUP1D
119 public:
122
124 string getName() const
125 {
126 return "TrueUP1D";
127 }
128
131 {
132 result = true;
133 return 0;
134 }
135};
136
137// FalseUP1D
140 public:
143
145 string getName() const
146 {
147 return "FalseUP1D";
148 }
149
152 {
153 result = false;
154 return 0;
155 }
156};
157
158// QuantitativeInvisibilityUP1D
163 public:
169
171 string getName() const
172 {
173 return "QuantitativeInvisibilityUP1D";
174 }
175
178 {
180 if (func(inter) < 0) {
181 return -1;
182 }
183 result = (func.result == _qi);
184 return 0;
185 }
186
187 private:
188 uint _qi;
189};
190
191// ContourUP1D
196 private:
198
199 public:
201 string getName() const
202 {
203 return "ContourUP1D";
204 }
205
208 {
209 if (_getNature(inter) < 0) {
210 return -1;
211 }
212 if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
214 for (; !it.isEnd(); ++it) {
216 result = true;
217 return 0;
218 }
219 }
220 }
221 result = false;
222 return 0;
223 }
224};
225
226// ExternalContourUP1D
231 private:
233
234 public:
236 string getName() const
237 {
238 return "ExternalContourUP1D";
239 }
240
243 {
244 if (_getNature(inter) < 0) {
245 return -1;
246 }
247 if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
248 set<ViewShape *> occluded;
249 Functions1D::getOccludeeF1D(inter, occluded);
250 for (set<ViewShape *>::iterator os = occluded.begin(), osend = occluded.end(); os != osend;
251 ++os)
252 {
253 if ((*os) == 0) {
254 result = true;
255 return 0;
256 }
257 }
258 }
259 result = false;
260 return 0;
261 }
262};
263
264// EqualToTimeStampUP1D
267 protected:
269
270 public:
275
277 string getName() const
278 {
279 return "EqualToTimeStampUP1D";
280 }
281
284 {
285 result = (inter.getTimeStamp() == _timeStamp);
286 return 0;
287 }
288};
289
290// EqualToChainingTimeStampUP1D
293 protected:
295
296 public:
301
303 string getName() const
304 {
305 return "EqualToChainingTimeStampUP1D";
306 }
307
310 {
311 ViewEdge *edge = dynamic_cast<ViewEdge *>(&inter);
312 if (!edge) {
313 result = false;
314 return 0;
315 }
317 return 0;
318 }
319};
320
321// ShapeUP1D
325 private:
326 Id _id;
327
328 public:
335 ShapeUP1D(uint idFirst, uint idSecond = 0) : UnaryPredicate1D()
336 {
337 _id = Id(idFirst, idSecond);
338 }
339
341 string getName() const
342 {
343 return "ShapeUP1D";
344 }
345
348 {
349 set<ViewShape *> shapes;
350 Functions1D::getShapeF1D(inter, shapes);
351 for (set<ViewShape *>::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) {
352 if ((*s)->getId() == _id) {
353 result = true;
354 return 0;
355 }
356 }
357 result = false;
358 return 0;
359 }
360};
361
362// WithinImageBoundaryUP1D
365 private:
366 real _xmin, _ymin, _xmax, _ymax;
367
368 public:
379 WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
380 : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax)
381 {
382 }
383
385 string getName() const
386 {
387 return "WithinImageBoundaryUP1D";
388 }
389
392 {
393 // 1st pass: check if a point is within the image boundary.
394 Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
395 for (; it != itend; ++it) {
396 real x = (*it).getProjectedX();
397 real y = (*it).getProjectedY();
398 if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) {
399 result = true;
400 return 0;
401 }
402 }
403 // 2nd pass: check if a line segment intersects with the image boundary.
404 it = inter.verticesBegin();
405 if (it != itend) {
406 Vec2r pmin(_xmin, _ymin);
407 Vec2r pmax(_xmax, _ymax);
408 Vec2r prev((*it).getPoint2D());
409 ++it;
410 for (; it != itend; ++it) {
411 Vec2r p((*it).getPoint2D());
412 if (GeomUtils::intersect2dSeg2dArea(pmin, pmax, prev, p)) {
413 result = true;
414 return 0;
415 }
416 prev = p;
417 }
418 }
419 result = false;
420 return 0;
421 }
422};
423
424//
425// Binary Predicates definitions
426//
428
429// TrueBP1D
432 public:
434 string getName() const
435 {
436 return "TrueBP1D";
437 }
438
440 int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
441 {
442 result = true;
443 return 0;
444 }
445};
446
447// FalseBP1D
450 public:
452 string getName() const
453 {
454 return "FalseBP1D";
455 }
456
458 int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
459 {
460 result = false;
461 return 0;
462 }
463};
464
465// Length2DBP1D
469 public:
471 string getName() const
472 {
473 return "Length2DBP1D";
474 }
475
478 {
479 result = (i1.getLength2D() > i2.getLength2D());
480 return 0;
481 }
482};
483
484// SameShapeIdBP1D
487 public:
489 string getName() const
490 {
491 return "SameShapeIdBP1D";
492 }
493
496 {
497 set<ViewShape *> shapes1;
498 Functions1D::getShapeF1D(i1, shapes1);
499 set<ViewShape *> shapes2;
500 Functions1D::getShapeF1D(i2, shapes2);
501 // FIXME:// n2 algo, can do better...
502 for (set<ViewShape *>::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) {
503 Id current = (*s)->getId();
504 for (set<ViewShape *>::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end;
505 ++s2)
506 {
507 if ((*s2)->getId() == current) {
508 result = true;
509 return 0;
510 }
511 }
512 }
513 result = false;
514 return 0;
515 }
516};
517
518// ViewMapGradientNormBP1D
522 private:
524
525 public:
526 ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0)
527 : BinaryPredicate1D(), _func(level, iType, sampling)
528 {
529 }
530
532 string getName() const
533 {
534 return "ViewMapGradientNormBP1D";
535 }
536
539 {
540 if (_func(i1) < 0) {
541 return -1;
542 }
543 real n1 = _func.result;
544 if (_func(i2) < 0) {
545 return -1;
546 }
547 real n2 = _func.result;
548 result = (n1 > n2);
549 return 0;
550 }
551};
552
553} // end of namespace Predicates1D
554
555} /* namespace Freestyle */
Functions taking 1D input.
unsigned int uint
Functions taking 1D input.
Interface 1D and related tools definitions.
Read Guarded memory(de)allocation.
Class defining a singleton used as timestamp.
virtual string getName() const
virtual int operator()(Interface1D &inter1, Interface1D &inter2)
virtual bool isEnd() const
virtual Interface0DIterator verticesEnd()
virtual Interface0DIterator verticesBegin()
virtual uint getTimeStamp() const
virtual real getLength2D() const
int operator()(Interface1D &inter)
int operator()(Interface1D &, Interface1D &)
int operator()(Interface1D &i1, Interface1D &i2)
int operator()(Interface1D &i1, Interface1D &i2)
int operator()(Interface1D &inter)
ShapeUP1D(uint idFirst, uint idSecond=0)
int operator()(Interface1D &, Interface1D &)
int operator()(Interface1D &i1, Interface1D &i2)
ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0)
WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
virtual int operator()(Interface1D &inter)
virtual string getName() const
uint getChainingTimeStamp()
Definition ViewMap.h:1102
ViewShape * getShapeF0D(Interface0DIterator &it)
ViewShape * getOccludeeF0D(Interface0DIterator &it)
void getOccludeeF1D(Interface1D &inter, set< ViewShape * > &oShapes)
void getShapeF1D(Interface1D &inter, set< ViewShape * > &oShapes)
bool intersect2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B)
Definition GeomUtils.cpp:19
VecMat::Vec2< real > Vec2r
Definition Geom.h:24
static const EdgeNature BORDER
Definition Nature.h:42
static const EdgeNature SILHOUETTE
Definition Nature.h:40
inherits from class Rep
Definition AppCanvas.cpp:20
static uint x[3]
Definition RandGen.cpp:77
double real
Definition Precision.h:14