Blender  V3.3
Predicates1D.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <string>
11 
12 #include "AdvancedFunctions1D.h"
13 
14 #include "../system/TimeStamp.h"
15 
16 #include "../view_map/Functions1D.h"
17 #include "../view_map/Interface1D.h"
18 
19 #ifdef WITH_CXX_GUARDEDALLOC
20 # include "MEM_guardedalloc.h"
21 #endif
22 
23 namespace 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 = NULL;
45  }
46 
49  {
50  }
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 = NULL;
89  }
90 
93  {
94  }
95 
97  virtual string getName() const
98  {
99  return "BinaryPredicate1D";
100  }
101 
110  virtual int operator()(Interface1D &inter1, Interface1D &inter2);
111 
112 #ifdef WITH_CXX_GUARDEDALLOC
113  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D")
114 #endif
115 };
116 
117 //
118 // Predicates definitions
119 //
121 
122 namespace Predicates1D {
123 
124 // TrueUP1D
126 class TrueUP1D : public UnaryPredicate1D {
127  public:
130  {
131  }
132 
134  string getName() const
135  {
136  return "TrueUP1D";
137  }
138 
141  {
142  result = true;
143  return 0;
144  }
145 };
146 
147 // FalseUP1D
149 class FalseUP1D : public UnaryPredicate1D {
150  public:
153  {
154  }
155 
157  string getName() const
158  {
159  return "FalseUP1D";
160  }
161 
164  {
165  result = false;
166  return 0;
167  }
168 };
169 
170 // QuantitativeInvisibilityUP1D
175  public:
180  QuantitativeInvisibilityUP1D(unsigned qi = 0) : _qi(qi)
181  {
182  }
183 
185  string getName() const
186  {
187  return "QuantitativeInvisibilityUP1D";
188  }
189 
192  {
194  if (func(inter) < 0) {
195  return -1;
196  }
197  result = (func.result == _qi);
198  return 0;
199  }
200 
201  private:
202  unsigned _qi;
203 };
204 
205 // ContourUP1D
210  private:
211  Functions1D::CurveNatureF1D _getNature;
212 
213  public:
215  string getName() const
216  {
217  return "ContourUP1D";
218  }
219 
222  {
223  if (_getNature(inter) < 0) {
224  return -1;
225  }
226  if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
227  Interface0DIterator it = inter.verticesBegin();
228  for (; !it.isEnd(); ++it) {
230  result = true;
231  return 0;
232  }
233  }
234  }
235  result = false;
236  return 0;
237  }
238 };
239 
240 // ExternalContourUP1D
245  private:
246  Functions1D::CurveNatureF1D _getNature;
247 
248  public:
250  string getName() const
251  {
252  return "ExternalContourUP1D";
253  }
254 
257  {
258  if (_getNature(inter) < 0) {
259  return -1;
260  }
261  if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
262  set<ViewShape *> occluded;
263  Functions1D::getOccludeeF1D(inter, occluded);
264  for (set<ViewShape *>::iterator os = occluded.begin(), osend = occluded.end(); os != osend;
265  ++os) {
266  if ((*os) == 0) {
267  result = true;
268  return 0;
269  }
270  }
271  }
272  result = false;
273  return 0;
274  }
275 };
276 
277 // EqualToTimeStampUP1D
280  protected:
281  unsigned _timeStamp;
282 
283  public:
285  {
286  _timeStamp = ts;
287  }
288 
290  string getName() const
291  {
292  return "EqualToTimeStampUP1D";
293  }
294 
297  {
298  result = (inter.getTimeStamp() == _timeStamp);
299  return 0;
300  }
301 };
302 
303 // EqualToChainingTimeStampUP1D
306  protected:
307  unsigned _timeStamp;
308 
309  public:
311  {
312  _timeStamp = ts;
313  }
314 
316  string getName() const
317  {
318  return "EqualToChainingTimeStampUP1D";
319  }
320 
323  {
324  ViewEdge *edge = dynamic_cast<ViewEdge *>(&inter);
325  if (!edge) {
326  result = false;
327  return 0;
328  }
329  result = (edge->getChainingTimeStamp() >= _timeStamp);
330  return 0;
331  }
332 };
333 
334 // ShapeUP1D
337 class ShapeUP1D : public UnaryPredicate1D {
338  private:
339  Id _id;
340 
341  public:
348  ShapeUP1D(unsigned idFirst, unsigned idSecond = 0) : UnaryPredicate1D()
349  {
350  _id = Id(idFirst, idSecond);
351  }
352 
354  string getName() const
355  {
356  return "ShapeUP1D";
357  }
358 
361  {
362  set<ViewShape *> shapes;
363  Functions1D::getShapeF1D(inter, shapes);
364  for (set<ViewShape *>::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) {
365  if ((*s)->getId() == _id) {
366  result = true;
367  return 0;
368  }
369  }
370  result = false;
371  return 0;
372  }
373 };
374 
375 // WithinImageBoundaryUP1D
378  private:
379  real _xmin, _ymin, _xmax, _ymax;
380 
381  public:
392  WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
393  : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax)
394  {
395  }
396 
398  string getName() const
399  {
400  return "WithinImageBoundaryUP1D";
401  }
402 
405  {
406  // 1st pass: check if a point is within the image boundary.
407  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
408  for (; it != itend; ++it) {
409  real x = (*it).getProjectedX();
410  real y = (*it).getProjectedY();
411  if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) {
412  result = true;
413  return 0;
414  }
415  }
416  // 2nd pass: check if a line segment intersects with the image boundary.
417  it = inter.verticesBegin();
418  if (it != itend) {
419  Vec2r pmin(_xmin, _ymin);
420  Vec2r pmax(_xmax, _ymax);
421  Vec2r prev((*it).getPoint2D());
422  ++it;
423  for (; it != itend; ++it) {
424  Vec2r p((*it).getPoint2D());
425  if (GeomUtils::intersect2dSeg2dArea(pmin, pmax, prev, p)) {
426  result = true;
427  return 0;
428  }
429  prev = p;
430  }
431  }
432  result = false;
433  return 0;
434  }
435 };
436 
437 //
438 // Binary Predicates definitions
439 //
441 
442 // TrueBP1D
444 class TrueBP1D : public BinaryPredicate1D {
445  public:
447  string getName() const
448  {
449  return "TrueBP1D";
450  }
451 
453  int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
454  {
455  result = true;
456  return 0;
457  }
458 };
459 
460 // FalseBP1D
462 class FalseBP1D : public BinaryPredicate1D {
463  public:
465  string getName() const
466  {
467  return "FalseBP1D";
468  }
469 
471  int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
472  {
473  result = false;
474  return 0;
475  }
476 };
477 
478 // Length2DBP1D
482  public:
484  string getName() const
485  {
486  return "Length2DBP1D";
487  }
488 
491  {
492  result = (i1.getLength2D() > i2.getLength2D());
493  return 0;
494  }
495 };
496 
497 // SameShapeIdBP1D
500  public:
502  string getName() const
503  {
504  return "SameShapeIdBP1D";
505  }
506 
509  {
510  set<ViewShape *> shapes1;
511  Functions1D::getShapeF1D(i1, shapes1);
512  set<ViewShape *> shapes2;
513  Functions1D::getShapeF1D(i2, shapes2);
514  // FIXME:// n2 algo, can do better...
515  for (set<ViewShape *>::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) {
516  Id current = (*s)->getId();
517  for (set<ViewShape *>::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end;
518  ++s2) {
519  if ((*s2)->getId() == current) {
520  result = true;
521  return 0;
522  }
523  }
524  }
525  result = false;
526  return 0;
527  }
528 };
529 
530 // ViewMapGradientNormBP1D
534  private:
536 
537  public:
538  ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0)
539  : BinaryPredicate1D(), _func(level, iType, sampling)
540  {
541  }
542 
544  string getName() const
545  {
546  return "ViewMapGradientNormBP1D";
547  }
548 
551  {
552  if (_func(i1) < 0) {
553  return -1;
554  }
555  real n1 = _func.result;
556  if (_func(i2) < 0) {
557  return -1;
558  }
559  real n2 = _func.result;
560  result = (n1 > n2);
561  return 0;
562  }
563 };
564 
565 } // end of namespace Predicates1D
566 
567 } /* namespace Freestyle */
Functions taking 1D input.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1
Read Guarded memory(de)allocation.
virtual string getName() const
Definition: Predicates1D.h:97
virtual int operator()(Interface1D &inter1, Interface1D &inter2)
virtual bool isEnd() const
Definition: Interface0D.h:282
virtual Interface0DIterator verticesEnd()
Definition: Interface1D.cpp:21
virtual unsigned getTimeStamp() const
Definition: Interface1D.h:186
virtual Interface0DIterator verticesBegin()
Definition: Interface1D.cpp:15
virtual real getLength2D() const
Definition: Interface1D.cpp:39
int operator()(Interface1D &inter)
Definition: Predicates1D.h:221
int operator()(Interface1D &, Interface1D &)
Definition: Predicates1D.h:471
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:490
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:508
int operator()(Interface1D &inter)
Definition: Predicates1D.h:360
ShapeUP1D(unsigned idFirst, unsigned idSecond=0)
Definition: Predicates1D.h:348
int operator()(Interface1D &, Interface1D &)
Definition: Predicates1D.h:453
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:550
ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0)
Definition: Predicates1D.h:538
WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
Definition: Predicates1D.h:392
virtual int operator()(Interface1D &inter)
virtual string getName() const
Definition: Predicates1D.h:53
ViewShape * getShapeF0D(Interface0DIterator &it)
Definition: Functions0D.cpp:93
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:15
static const EdgeNature BORDER
Definition: Nature.h:38
static const EdgeNature SILHOUETTE
Definition: Nature.h:36
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
double real
Definition: Precision.h:12
SymEdge< T > * prev(const SymEdge< T > *se)
Definition: delaunay_2d.cc:105