Blender  V2.93
Predicates1D.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <string>
25 
26 #include "AdvancedFunctions1D.h"
27 
28 #include "../system/TimeStamp.h"
29 
30 #include "../view_map/Functions1D.h"
31 #include "../view_map/Interface1D.h"
32 
33 #ifdef WITH_CXX_GUARDEDALLOC
34 # include "MEM_guardedalloc.h"
35 #endif
36 
37 namespace Freestyle {
38 
39 //
40 // UnaryPredicate1D (base class for predicates in 1D)
41 //
43 
51  public:
52  bool result;
53  void *py_up1D;
54 
57  {
58  py_up1D = NULL;
59  }
60 
63  {
64  }
65 
67  virtual string getName() const
68  {
69  return "UnaryPredicate1D";
70  }
71 
77  virtual int operator()(Interface1D &inter);
78 
79 #ifdef WITH_CXX_GUARDEDALLOC
80  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryPredicate1D")
81 #endif
82 };
83 
84 //
85 // BinaryPredicate1D (base class for predicates in 1D)
86 //
88 
95  public:
96  bool result;
97  void *py_bp1D;
98 
101  {
102  py_bp1D = NULL;
103  }
104 
107  {
108  }
109 
111  virtual string getName() const
112  {
113  return "BinaryPredicate1D";
114  }
115 
124  virtual int operator()(Interface1D &inter1, Interface1D &inter2);
125 
126 #ifdef WITH_CXX_GUARDEDALLOC
127  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BinaryPredicate1D")
128 #endif
129 };
130 
131 //
132 // Predicates definitions
133 //
135 
136 namespace Predicates1D {
137 
138 // TrueUP1D
140 class TrueUP1D : public UnaryPredicate1D {
141  public:
144  {
145  }
146 
148  string getName() const
149  {
150  return "TrueUP1D";
151  }
152 
155  {
156  result = true;
157  return 0;
158  }
159 };
160 
161 // FalseUP1D
163 class FalseUP1D : public UnaryPredicate1D {
164  public:
167  {
168  }
169 
171  string getName() const
172  {
173  return "FalseUP1D";
174  }
175 
178  {
179  result = false;
180  return 0;
181  }
182 };
183 
184 // QuantitativeInvisibilityUP1D
189  public:
194  QuantitativeInvisibilityUP1D(unsigned qi = 0) : _qi(qi)
195  {
196  }
197 
199  string getName() const
200  {
201  return "QuantitativeInvisibilityUP1D";
202  }
203 
206  {
208  if (func(inter) < 0) {
209  return -1;
210  }
211  result = (func.result == _qi);
212  return 0;
213  }
214 
215  private:
216  unsigned _qi;
217 };
218 
219 // ContourUP1D
224  private:
225  Functions1D::CurveNatureF1D _getNature;
226 
227  public:
229  string getName() const
230  {
231  return "ContourUP1D";
232  }
233 
236  {
237  if (_getNature(inter) < 0) {
238  return -1;
239  }
240  if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
241  Interface0DIterator it = inter.verticesBegin();
242  for (; !it.isEnd(); ++it) {
244  result = true;
245  return 0;
246  }
247  }
248  }
249  result = false;
250  return 0;
251  }
252 };
253 
254 // ExternalContourUP1D
259  private:
260  Functions1D::CurveNatureF1D _getNature;
261 
262  public:
264  string getName() const
265  {
266  return "ExternalContourUP1D";
267  }
268 
271  {
272  if (_getNature(inter) < 0) {
273  return -1;
274  }
275  if ((_getNature.result & Nature::SILHOUETTE) || (_getNature.result & Nature::BORDER)) {
276  set<ViewShape *> occluded;
277  Functions1D::getOccludeeF1D(inter, occluded);
278  for (set<ViewShape *>::iterator os = occluded.begin(), osend = occluded.end(); os != osend;
279  ++os) {
280  if ((*os) == 0) {
281  result = true;
282  return 0;
283  }
284  }
285  }
286  result = false;
287  return 0;
288  }
289 };
290 
291 // EqualToTimeStampUP1D
294  protected:
295  unsigned _timeStamp;
296 
297  public:
299  {
300  _timeStamp = ts;
301  }
302 
304  string getName() const
305  {
306  return "EqualToTimeStampUP1D";
307  }
308 
311  {
312  result = (inter.getTimeStamp() == _timeStamp);
313  return 0;
314  }
315 };
316 
317 // EqualToChainingTimeStampUP1D
320  protected:
321  unsigned _timeStamp;
322 
323  public:
325  {
326  _timeStamp = ts;
327  }
328 
330  string getName() const
331  {
332  return "EqualToChainingTimeStampUP1D";
333  }
334 
337  {
338  ViewEdge *edge = dynamic_cast<ViewEdge *>(&inter);
339  if (!edge) {
340  result = false;
341  return 0;
342  }
343  result = (edge->getChainingTimeStamp() >= _timeStamp);
344  return 0;
345  }
346 };
347 
348 // ShapeUP1D
351 class ShapeUP1D : public UnaryPredicate1D {
352  private:
353  Id _id;
354 
355  public:
362  ShapeUP1D(unsigned idFirst, unsigned idSecond = 0) : UnaryPredicate1D()
363  {
364  _id = Id(idFirst, idSecond);
365  }
366 
368  string getName() const
369  {
370  return "ShapeUP1D";
371  }
372 
375  {
376  set<ViewShape *> shapes;
377  Functions1D::getShapeF1D(inter, shapes);
378  for (set<ViewShape *>::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) {
379  if ((*s)->getId() == _id) {
380  result = true;
381  return 0;
382  }
383  }
384  result = false;
385  return 0;
386  }
387 };
388 
389 // WithinImageBoundaryUP1D
392  private:
393  real _xmin, _ymin, _xmax, _ymax;
394 
395  public:
406  WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
407  : _xmin(xmin), _ymin(ymin), _xmax(xmax), _ymax(ymax)
408  {
409  }
410 
412  string getName() const
413  {
414  return "WithinImageBoundaryUP1D";
415  }
416 
419  {
420  // 1st pass: check if a point is within the image boundary.
421  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
422  for (; it != itend; ++it) {
423  real x = (*it).getProjectedX();
424  real y = (*it).getProjectedY();
425  if (_xmin <= x && x <= _xmax && _ymin <= y && y <= _ymax) {
426  result = true;
427  return 0;
428  }
429  }
430  // 2nd pass: check if a line segment intersects with the image boundary.
431  it = inter.verticesBegin();
432  if (it != itend) {
433  Vec2r pmin(_xmin, _ymin);
434  Vec2r pmax(_xmax, _ymax);
435  Vec2r prev((*it).getPoint2D());
436  ++it;
437  for (; it != itend; ++it) {
438  Vec2r p((*it).getPoint2D());
439  if (GeomUtils::intersect2dSeg2dArea(pmin, pmax, prev, p)) {
440  result = true;
441  return 0;
442  }
443  prev = p;
444  }
445  }
446  result = false;
447  return 0;
448  }
449 };
450 
451 //
452 // Binary Predicates definitions
453 //
455 
456 // TrueBP1D
458 class TrueBP1D : public BinaryPredicate1D {
459  public:
461  string getName() const
462  {
463  return "TrueBP1D";
464  }
465 
467  int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
468  {
469  result = true;
470  return 0;
471  }
472 };
473 
474 // FalseBP1D
476 class FalseBP1D : public BinaryPredicate1D {
477  public:
479  string getName() const
480  {
481  return "FalseBP1D";
482  }
483 
485  int operator()(Interface1D & /*i1*/, Interface1D & /*i2*/)
486  {
487  result = false;
488  return 0;
489  }
490 };
491 
492 // Length2DBP1D
496  public:
498  string getName() const
499  {
500  return "Length2DBP1D";
501  }
502 
505  {
506  result = (i1.getLength2D() > i2.getLength2D());
507  return 0;
508  }
509 };
510 
511 // SameShapeIdBP1D
514  public:
516  string getName() const
517  {
518  return "SameShapeIdBP1D";
519  }
520 
523  {
524  set<ViewShape *> shapes1;
525  Functions1D::getShapeF1D(i1, shapes1);
526  set<ViewShape *> shapes2;
527  Functions1D::getShapeF1D(i2, shapes2);
528  // FIXME:// n2 algo, can do better...
529  for (set<ViewShape *>::iterator s = shapes1.begin(), send = shapes1.end(); s != send; ++s) {
530  Id current = (*s)->getId();
531  for (set<ViewShape *>::iterator s2 = shapes2.begin(), s2end = shapes2.end(); s2 != s2end;
532  ++s2) {
533  if ((*s2)->getId() == current) {
534  result = true;
535  return 0;
536  }
537  }
538  }
539  result = false;
540  return 0;
541  }
542 };
543 
544 // ViewMapGradientNormBP1D
548  private:
550 
551  public:
552  ViewMapGradientNormBP1D(int level, IntegrationType iType = MEAN, float sampling = 2.0)
553  : BinaryPredicate1D(), _func(level, iType, sampling)
554  {
555  }
556 
558  string getName() const
559  {
560  return "ViewMapGradientNormBP1D";
561  }
562 
565  {
566  if (_func(i1) < 0) {
567  return -1;
568  }
569  real n1 = _func.result;
570  if (_func(i2) < 0) {
571  return -1;
572  }
573  real n2 = _func.result;
574  result = (n1 > n2);
575  return 0;
576  }
577 };
578 
579 } // end of namespace Predicates1D
580 
581 } /* 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 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
_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
Read Guarded memory(de)allocation.
virtual string getName() const
Definition: Predicates1D.h:111
virtual int operator()(Interface1D &inter1, Interface1D &inter2)
virtual bool isEnd() const
Definition: Interface0D.h:296
virtual Interface0DIterator verticesEnd()
Definition: Interface1D.cpp:35
virtual unsigned getTimeStamp() const
Definition: Interface1D.h:185
virtual Interface0DIterator verticesBegin()
Definition: Interface1D.cpp:29
virtual real getLength2D() const
Definition: Interface1D.cpp:53
int operator()(Interface1D &inter)
Definition: Predicates1D.h:235
int operator()(Interface1D &, Interface1D &)
Definition: Predicates1D.h:485
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:504
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:522
int operator()(Interface1D &inter)
Definition: Predicates1D.h:374
ShapeUP1D(unsigned idFirst, unsigned idSecond=0)
Definition: Predicates1D.h:362
int operator()(Interface1D &, Interface1D &)
Definition: Predicates1D.h:467
int operator()(Interface1D &i1, Interface1D &i2)
Definition: Predicates1D.h:564
ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0)
Definition: Predicates1D.h:552
WithinImageBoundaryUP1D(const real xmin, const real ymin, const real xmax, const real ymax)
Definition: Predicates1D.h:406
virtual int operator()(Interface1D &inter)
virtual string getName() const
Definition: Predicates1D.h:67
unsigned getChainingTimeStamp()
Definition: ViewMap.h:1124
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:29
static const EdgeNature BORDER
Definition: Nature.h:52
static const EdgeNature SILHOUETTE
Definition: Nature.h:50
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
double real
Definition: Precision.h:26