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

Functions0D.h « view_map « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb88eb29b4c8c1044aa2d850aec254f7d94b52f9 (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
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

/** \file
 * \ingroup freestyle
 * \brief Functions taking 0D input
 */

#include <set>
#include <vector>

#include "Interface0D.h"

#include "../geometry/Geom.h"

#include "../python/Director.h"

#include "../scene_graph/FrsMaterial.h"

#include "../system/Exception.h"
#include "../system/Precision.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

namespace Freestyle {

class FEdge;
class ViewEdge;
class SShape;

using namespace Geometry;

//
// UnaryFunction0D (base class for functions in 0D)
//
///////////////////////////////////////////////////////////

/** Base class for Unary Functions (functors) working on Interface0DIterator.
 *  A unary function will be used by calling its operator() on an Interface0DIterator.
 * \attention In the scripting language, there exists several prototypes depending on the returned
 * value type. For example, you would inherit from a UnaryFunction0DDouble if you wish to define a
 * function that returns a double. The different existing prototypes are:
 *    - UnaryFunction0DDouble
 *    - UnaryFunction0DEdgeNature
 *    - UnaryFunction0DFloat
 *    - UnaryFunction0DId
 *    - UnaryFunction0DMaterial
 *    - UnaryFunction0DUnsigned
 *    - UnaryFunction0DVec2f
 *    - UnaryFunction0DVec3f
 *    - UnaryFunction0DVectorViewShape
 *    - UnaryFunction0DViewShape
 *    - UnaryFunction0DVoid
 */
template<class T> class UnaryFunction0D {
 public:
  T result;
  void *py_uf0D;

  /** The type of the value returned by the functor. */
  typedef T ReturnedValueType;

  /** Default constructor. */
  UnaryFunction0D()
  {
    py_uf0D = NULL;
  }

  /** Destructor; */
  virtual ~UnaryFunction0D()
  {
  }

  /** Returns the string "UnaryFunction0D" */
  virtual string getName() const
  {
    return "UnaryFunction0D";
  }

  /** The operator ().
   *  \param iter:
   *    An Interface0DIterator pointing onto the point at which we wish to evaluate the function.
   *  \return the result of the function of type T.
   */
  /* FIXME move the implementation to Functions0D.cpp */
  virtual int operator()(Interface0DIterator &iter)
  {
    return Director_BPy_UnaryFunction0D___call__(this, py_uf0D, iter);
  }

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:UnaryFunction0D")
#endif
};

#ifdef SWIG
%feature("director")  UnaryFunction0D<void>;
%feature("director")  UnaryFunction0D<unsigned>;
%feature("director")  UnaryFunction0D<float>;
%feature("director")  UnaryFunction0D<double>;
%feature("director")  UnaryFunction0D<Vec2f>;
%feature("director")  UnaryFunction0D<Vec3f>;
%feature("director")  UnaryFunction0D<Id>;

%template(UnaryFunction0DVoid)             UnaryFunction0D<void>;
%template(UnaryFunction0DUnsigned)         UnaryFunction0D<unsigned>;
%template(UnaryFunction0DFloat)            UnaryFunction0D<float>;
%template(UnaryFunction0DDouble)           UnaryFunction0D<double>;
%template(UnaryFunction0DVec2f)            UnaryFunction0D<Vec2f>;
%template(UnaryFunction0DVec3f)            UnaryFunction0D<Vec3f>;
%template(UnaryFunction0DId)               UnaryFunction0D<Id>;
%template(UnaryFunction0DViewShape)        UnaryFunction0D<ViewShape*>;
%template(UnaryFunction0DVectorViewShape)  UnaryFunction0D<std::vector<ViewShape*> >;
#endif  // SWIG

//
// Functions definitions
//
///////////////////////////////////////////////////////////
class ViewShape;

namespace Functions0D {

// GetXF0D
/** Returns the X 3D coordinate of an Interface0D. */
class GetXF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetXF0D" */
  string getName() const
  {
    return "GetXF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getX();
    return 0;
  }
};

// GetYF0D
/** Returns the Y 3D coordinate of an Interface0D. */
class GetYF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetYF0D" */
  string getName() const
  {
    return "GetYF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getY();
    return 0;
  }
};

// GetZF0D
/** Returns the Z 3D coordinate of an Interface0D. */
class GetZF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetZF0D" */
  string getName() const
  {
    return "GetZF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getZ();
    return 0;
  }
};

// GetProjectedXF0D
/** Returns the X 3D projected coordinate of an Interface0D. */
class GetProjectedXF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetProjectedXF0D" */
  string getName() const
  {
    return "GetProjectedXF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getProjectedX();
    return 0;
  }
};

// GetProjectedYF0D
/** Returns the Y projected 3D coordinate of an Interface0D. */
class GetProjectedYF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetProjectedYF0D" */
  string getName() const
  {
    return "GetProjectedYF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getProjectedY();
    return 0;
  }
};

// GetProjectedZF0D
/** Returns the Z projected 3D coordinate of an Interface0D. */
class GetProjectedZF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "GetProjectedZF0D" */
  string getName() const
  {
    return "GetProjectedZF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter->getProjectedZ();
    return 0;
  }
};

// GetCurvilinearAbscissaF0D
/** Returns the curvilinear abscissa of an Interface0D in the context of its 1D element. */
class GetCurvilinearAbscissaF0D : public UnaryFunction0D<float> {
 public:
  /** Returns the string "GetCurvilinearAbscissaF0D" */
  string getName() const
  {
    return "GetCurvilinearAbscissaF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter.t();
    return 0;
  }
};

// GetParameterF0D
/** Returns the parameter of an Interface0D in the context of its 1D element. */
class GetParameterF0D : public UnaryFunction0D<float> {
 public:
  /** Returns the string "GetCurvilinearAbscissaF0D" */
  string getName() const
  {
    return "GetParameterF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter)
  {
    result = iter.u();
    return 0;
  }
};

// VertexOrientation2DF0D
/** Returns a Vec2r giving the 2D oriented tangent to the 1D element to which the
 * Interface0DIterator& belongs to and evaluated at the Interface0D pointed by this
 * Interface0DIterator&.
 */
class VertexOrientation2DF0D : public UnaryFunction0D<Vec2f> {
 public:
  /** Returns the string "VertexOrientation2DF0D" */
  string getName() const
  {
    return "VertexOrientation2DF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// VertexOrientation3DF0D
/** Returns a Vec3r giving the 3D oriented tangent to the 1D element to which the
 * Interface0DIterator& belongs to and evaluated at the Interface0D pointed by this
 * Interface0DIterator&.
 */
class VertexOrientation3DF0D : public UnaryFunction0D<Vec3f> {
 public:
  /** Returns the string "VertexOrientation3DF0D" */
  string getName() const
  {
    return "VertexOrientation3DF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// Curvature2DAngleF0D
/** Returns a real giving the 2D curvature (as an angle) of the 1D element to which the
 * Interface0DIterator& belongs to and evaluated at the Interface0D pointed by this
 * Interface0DIterator&.
 */
class Curvature2DAngleF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "Curvature2DAngleF0D" */
  string getName() const
  {
    return "Curvature2DAngleF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// ZDiscontinuity
/** Returns a real giving the distance between and Interface0D and the shape that lies behind
 * (occludee). This distance is evaluated in the camera space and normalized between 0 and 1.
 * Therefore, if no object is occluded by the shape to which the Interface0D belongs to, 1 is
 * returned.
 */
class ZDiscontinuityF0D : public UnaryFunction0D<double> {
 public:
  /** Returns the string "ZDiscontinuityF0D" */
  string getName() const
  {
    return "ZDiscontinuityF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// Normal2DF0D
/** Returns a Vec2f giving the normalized 2D normal to the 1D element to which the
 * Interface0DIterator& belongs to and evaluated at the Interface0D pointed by this
 * Interface0DIterator&.
 */
class Normal2DF0D : public UnaryFunction0D<Vec2f> {
 public:
  /** Returns the string "Normal2DF0D" */
  string getName() const
  {
    return "Normal2DF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// MaterialF0D
/** Returns the material of the object evaluated at the Interface0D.
 *  This evaluation can be ambiguous (in the case of a TVertex for example.
 *  This functor tries to remove this ambiguity using the context offered by the 1D element to
 * which the Interface0DIterator& belongs to and by arbitrary choosing the material of the face
 * that lies on its left when following the 1D element if there are two different materials on each
 * side of the point. However, there still can be problematic cases, and the user willing to deal
 * with this cases in a specific way should implement its own getMaterial functor.
 */
class MaterialF0D : public UnaryFunction0D<FrsMaterial> {
 public:
  /** Returns the string "MaterialF0D" */
  string getName() const
  {
    return "MaterialF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// ShapeIdF0D
/** Returns the Id of the Shape the Interface0D belongs to.
 *  This evaluation can be ambiguous (in the case of a TVertex for example).
 *  This functor tries to remove this ambiguity using the context offered by the 1D element to
 * which the Interface0DIterator& belongs to. However, there still can be problematic cases, and
 * the user willing to deal with this cases in a specific way should implement its own
 * getShapeIdF0D functor.
 */
class ShapeIdF0D : public UnaryFunction0D<Id> {
 public:
  /** Returns the string "ShapeIdF0D" */
  string getName() const
  {
    return "ShapeIdF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// QiF0D
/** Returns the quantitative invisibility of this Interface0D.
 *  This evaluation can be ambiguous (in the case of a TVertex for example).
 *  This functor tries to remove this ambiguity using the context offered by the 1D element to
 * which the Interface0DIterator& belongs to. However, there still can be problematic cases, and
 * the user willing to deal with this cases in a specific way should implement its own getQIF0D
 * functor.
 */
class QuantitativeInvisibilityF0D : public UnaryFunction0D<unsigned int> {
 public:
  /** Returns the string "QuantitativeInvisibilityF0D" */
  string getName() const
  {
    return "QuantitativeInvisibilityF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// CurveNatureF0D
/** Returns the Nature::EdgeNature of the 1D element the Interface0DIterator& belongs to. */
class CurveNatureF0D : public UnaryFunction0D<Nature::EdgeNature> {
 public:
  /** Returns the string "QuantitativeInvisibilityF0D" */
  string getName() const
  {
    return "CurveNatureF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// GetShapeF0D
/** Returns the ViewShape* containing the Interface0D */
class GetShapeF0D : public UnaryFunction0D<ViewShape *> {
 public:
  /** Returns the string "GetShapeF0D" */
  string getName() const
  {
    return "GetShapeF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// GetOccludersF0D
/** Returns a vector containing the ViewShape* occluding the Interface0D */
class GetOccludersF0D : public UnaryFunction0D<std::vector<ViewShape *>> {
 public:
  /** Returns the string "GetOccludersF0D" */
  string getName() const
  {
    return "GetOccludersF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

// GetOccludeeF0D
/** Returns the ViewShape* "occluded" by the Interface0D */
class GetOccludeeF0D : public UnaryFunction0D<ViewShape *> {
 public:
  /** Returns the string "GetOccludeeF0D" */
  string getName() const
  {
    return "GetOccludeeF0D";
  }

  /** the () operator. */
  int operator()(Interface0DIterator &iter);
};

/////////////////////////// Internal ////////////////////////////

// getFEdge
FEdge *getFEdge(Interface0D &it1, Interface0D &it2);

// getFEdges
void getFEdges(Interface0DIterator &it, FEdge *&fe1, FEdge *&fe2);

// getViewEdges
void getViewEdges(Interface0DIterator &it, ViewEdge *&ve1, ViewEdge *&ve2);

// getShapeF0D
ViewShape *getShapeF0D(Interface0DIterator &it);

// getOccludersF0D
void getOccludersF0D(Interface0DIterator &it, std::set<ViewShape *> &oOccluders);

// getOccludeeF0D
ViewShape *getOccludeeF0D(Interface0DIterator &it);

}  // end of namespace Functions0D

} /* namespace Freestyle */