Blender V4.3
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
12#include <string>
13
14#include "AdvancedFunctions1D.h"
15
16#include "../system/TimeStamp.h"
17
20
21#ifdef WITH_CXX_GUARDEDALLOC
22# include "MEM_guardedalloc.h"
23#endif
24
25namespace Freestyle {
26
27//
28// UnaryPredicate1D (base class for predicates in 1D)
29//
31
39 public:
40 bool result;
41 void *py_up1D;
42
45 {
46 py_up1D = nullptr;
47 }
48
50 virtual ~UnaryPredicate1D() {}
51
53 virtual string getName() const
54 {
55 return "UnaryPredicate1D";
56 }
57
63 virtual int operator()(Interface1D &inter);
64
65#ifdef WITH_CXX_GUARDEDALLOC
66 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate1D")
67#endif
68};
69
70//
71// BinaryPredicate1D (base class for predicates in 1D)
72//
74
81 public:
82 bool result;
83 void *py_bp1D;
84
87 {
88 py_bp1D = nullptr;
89 }
90
92 virtual ~BinaryPredicate1D() {}
93
95 virtual string getName() const
96 {
97 return "BinaryPredicate1D";
98 }
99
108 virtual int operator()(Interface1D &inter1, Interface1D &inter2);
109
110#ifdef WITH_CXX_GUARDEDALLOC
111 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D")
112#endif
113};
114
115//
116// Predicates definitions
117//
119
120namespace Predicates1D {
121
122// TrueUP1D
125 public:
128
130 string getName() const
131 {
132 return "TrueUP1D";
133 }
134
137 {
138 result = true;
139 return 0;
140 }
141};
142
143// FalseUP1D
146 public:
149
151 string getName() const
152 {
153 return "FalseUP1D";
154 }
155
158 {
159 result = false;
160 return 0;
161 }
162};
163
164// QuantitativeInvisibilityUP1D
169 public:
175
177 string getName() const
178 {
179 return "QuantitativeInvisibilityUP1D";
180 }
181
184 {
186 if (func(inter) < 0) {
187 return -1;
188 }
189 result = (func.result == _qi);
190 return 0;
191 }
192
193 private:
194 uint _qi;
195};
196
197// ContourUP1D
202 private:
204
205 public:
207 string getName() const
208 {
209 return "ContourUP1D";
210 }
211
214 {
215 if (_getNature(inter) < 0) {
216 return -1;
217 }
218 if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
220 for (; !it.isEnd(); ++it) {
222 result = true;
223 return 0;
224 }
225 }
226 }
227 result = false;
228 return 0;
229 }
230};
231
232// ExternalContourUP1D
237 private:
239
240 public:
242 string getName() const
243 {
244 return "ExternalContourUP1D";
245 }
246
249 {
250 if (_getNature(inter) < 0) {
251 return -1;
252 }
253 if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
254 set<ViewShape *> occluded;
255 Functions1D::getOccludeeF1D(inter, occluded);
256 for (set<ViewShape *>::iterator os = occluded.begin(), osend = occluded.end(); os != osend;
257 ++os)
258 {
259 if ((*os) == 0) {
260 result = true;
261 return 0;
262 }
263 }
264 }
265 result = false;
266 return 0;
267 }
268};
269
270// EqualToTimeStampUP1D
273 protected:
275
276 public:
281
283 string getName() const
284 {
285 return "EqualToTimeStampUP1D";
286 }
287
290 {
291 result = (inter.getTimeStamp() == _timeStamp);
292 return 0;
293 }
294};
295
296// EqualToChainingTimeStampUP1D
299 protected:
301
302 public:
307
309 string getName() const
310 {
311 return "EqualToChainingTimeStampUP1D";
312 }
313
316 {
317 ViewEdge *edge = dynamic_cast<ViewEdge *>(&inter);
318 if (!edge) {
319 result = false;
320 return 0;
321 }
322 result = (edge->getChainingTimeStamp() >= _timeStamp);
323 return 0;
324 }
325};
326
327// ShapeUP1D
331 private:
332 Id _id;
333
334 public:
341 ShapeUP1D(uint idFirst, uint idSecond = 0) : UnaryPredicate1D()
342 {
343 _id = Id(idFirst, idSecond);
344 }
345
347 string getName() const
348 {
349 return "ShapeUP1D";
350 }
351
354 {
355 set<ViewShape *> shapes;
356 Functions1D::getShapeF1D(inter, shapes);
357 for (set<ViewShape *>::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) {
358 if ((*s)->getId() == _id) {
359 result = true;
360 return 0;
361 }
362 }
363 result = false;
364 return 0;
365 }
366};
367
368// WithinImageBoundaryUP1D
371 private:
372 real _xmin, _ymin, _xmax, _ymax;
373
374 public:
385 WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
386 : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax)
387 {
388 }
389
391 string getName() const
392 {
393 return "WithinImageBoundaryUP1D";
394 }
395
398 {
399 // 1st pass: check if a point is within the image boundary.
400 Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
401 for (; it != itend; ++it) {
402 real x = (*it).getProjectedX();
403 real y = (*it).getProjectedY();
404 if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) {
405 result = true;
406 return 0;
407 }
408 }
409 // 2nd pass: check if a line segment intersects with the image boundary.
410 it = inter.verticesBegin();
411 if (it != itend) {
412 Vec2r pmin(_xmin, _ymin);
413 Vec2r pmax(_xmax, _ymax);
414 Vec2r prev((*it).getPoint2D());
415 ++it;
416 for (; it != itend; ++it) {
417 Vec2r p((*it).getPoint2D());
418 if (GeomUtils::intersect2dSeg2dArea(pmin, pmax, prev, p)) {
419 result = true;
420 return 0;
421 }
422 prev = p;
423 }
424 }
425 result = false;
426 return 0;
427 }
428};
429
430//
431// Binary Predicates definitions
432//
434
435// TrueBP1D
438 public:
440 string getName() const
441 {
442 return "TrueBP1D";
443 }
444
446 int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
447 {
448 result = true;
449 return 0;
450 }
451};
452
453// FalseBP1D
456 public:
458 string getName() const
459 {
460 return "FalseBP1D";
461 }
462
464 int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
465 {
466 result = false;
467 return 0;
468 }
469};
470
471// Length2DBP1D
475 public:
477 string getName() const
478 {
479 return "Length2DBP1D";
480 }
481
484 {
485 result = (i1.getLength2D() > i2.getLength2D());
486 return 0;
487 }
488};
489
490// SameShapeIdBP1D
493 public:
495 string getName() const
496 {
497 return "SameShapeIdBP1D";
498 }
499
502 {
503 set<ViewShape *> shapes1;
504 Functions1D::getShapeF1D(i1, shapes1);
505 set<ViewShape *> shapes2;
506 Functions1D::getShapeF1D(i2, shapes2);
507 // FIXME:// n2 algo, can do better...
508 for (set<ViewShape *>::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) {
509 Id current = (*s)->getId();
510 for (set<ViewShape *>::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end;
511 ++s2)
512 {
513 if ((*s2)->getId() == current) {
514 result = true;
515 return 0;
516 }
517 }
518 }
519 result = false;
520 return 0;
521 }
522};
523
524// ViewMapGradientNormBP1D
528 private:
530
531 public:
532 ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0)
533 : BinaryPredicate1D(), _func(level, iType, sampling)
534 {
535 }
536
538 string getName() const
539 {
540 return "ViewMapGradientNormBP1D";
541 }
542
545 {
546 if (_func(i1) < 0) {
547 return -1;
548 }
549 real n1 = _func.result;
550 if (_func(i2) < 0) {
551 return -1;
552 }
553 real n2 = _func.result;
554 result = (n1 > n2);
555 return 0;
556 }
557};
558
559} // end of namespace Predicates1D
560
561} /* 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 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
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
static const EdgeNature BORDER
Definition Nature.h:42
static const EdgeNature SILHOUETTE
Definition Nature.h:40
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14