Blender  V3.3
Curve.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 #include <cstdio> /* printf */
9 
10 #include "Curve.h"
11 #include "CurveAdvancedIterators.h"
12 #include "CurveIterators.h"
13 
14 #include "BKE_global.h"
15 #include "BLI_utildefines.h"
16 
17 namespace Freestyle {
18 
19 /**********************************/
20 /* */
21 /* */
22 /* CurvePoint */
23 /* */
24 /* */
25 /**********************************/
26 
28 {
29  __A = nullptr;
30  __B = nullptr;
31  _t2d = 0;
32 }
33 
35 {
36  __A = iA;
37  __B = iB;
38  _t2d = t;
39  if ((iA == nullptr) && (t == 1.0f)) {
40  _Point2d = __B->point2d();
41  _Point3d = __B->point3d();
42  }
43  else if ((iB == nullptr) && (t == 0.0f)) {
44  _Point2d = __A->point2d();
45  _Point3d = __A->point3d();
46  }
47  else {
48  _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d());
49  _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d());
50  }
51 }
52 
54 {
55  __A = nullptr;
56  __B = nullptr;
57  float t1 = iA->t2d();
58  float t2 = iB->t2d();
59  if ((iA->A() == iB->A()) && (iA->B() == iB->B()) && (iA->A() != nullptr) &&
60  (iA->B() != nullptr) && (iB->A() != nullptr) && (iB->B() != nullptr)) {
61  __A = iA->A();
62  __B = iB->B();
63  _t2d = t1 + t2 * t3 - t1 * t3;
64  }
65  else if ((iA->B() == nullptr) && (iB->B() == nullptr)) {
66  __A = iA->A();
67  __B = iB->A();
68  _t2d = t3;
69  }
70  else if ((iA->t2d() == 0) && (iB->t2d() == 0)) {
71  __A = iA->A();
72  __B = iB->A();
73  _t2d = t3;
74  }
75  else if (iA->A() == iB->A()) {
76  iA_A_eq_iB_A:
77  if (iA->t2d() == 0) {
78  __A = iB->A();
79  __B = iB->B();
80  _t2d = t3;
81  }
82  else if (iB->t2d() == 0) {
83  __A = iA->A();
84  __B = iA->B();
85  _t2d = t3;
86  }
87  }
88  else if (iA->B() == iB->B()) {
89  iA_B_eq_iB_B:
90  if (iA->t2d() == 1) {
91  __A = iB->A();
92  __B = iB->B();
93  _t2d = t3;
94  }
95  else if (iB->t2d() == 1) {
96  __A = iA->A();
97  __B = iA->B();
98  _t2d = t3;
99  }
100  }
101  else if (iA->B() == iB->A()) {
102  iA_B_eq_iB_A:
103  if ((iA->t2d() != 1.0f) && (iB->t2d() == 0.0f)) {
104  __A = iA->A();
105  __B = iA->B();
106  _t2d = t1 + t3 - t1 * t3;
107  //_t2d = t3;
108  }
109  else if ((iA->t2d() == 1.0f) && (iB->t2d() != 0.0f)) {
110  __A = iB->A();
111  __B = iB->B();
112  //_t2d = t3;
113  _t2d = t2 * t3;
114  }
115  else if ((iA->getPoint2D() - iB->getPoint2D()).norm() < 1.0e-6) {
116  __A = iB->A();
117  __B = iB->B();
118  //_t2d = t3;
119  _t2d = t2 * t3;
120  }
121  }
122  else if (iA->A() != nullptr && iB->A() != nullptr &&
123  (iA->A()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) {
124  goto iA_A_eq_iB_A;
125  }
126  else if (iA->B() != nullptr && iB->B() != nullptr &&
127  (iA->B()->point3d() - iB->B()->point3d()).norm() < 1.0e-6) {
128  goto iA_B_eq_iB_B;
129  }
130  else if (iA->B() != nullptr && iB->A() != nullptr &&
131  (iA->B()->point3d() - iB->A()->point3d()).norm() < 1.0e-6) {
132  goto iA_B_eq_iB_A;
133  }
134 
135  if (!__A || !__B) {
136  if (G.debug & G_DEBUG_FREESTYLE) {
137  printf(
138  "iA A 0x%p p (%f, %f)\n", iA->A(), iA->A()->getPoint2D().x(), iA->A()->getPoint2D().y());
139  printf(
140  "iA B 0x%p p (%f, %f)\n", iA->B(), iA->B()->getPoint2D().x(), iA->B()->getPoint2D().y());
141  printf(
142  "iB A 0x%p p (%f, %f)\n", iB->A(), iB->A()->getPoint2D().x(), iB->A()->getPoint2D().y());
143  printf(
144  "iB B 0x%p p (%f, %f)\n", iB->B(), iB->B()->getPoint2D().x(), iB->B()->getPoint2D().y());
145  printf("iA t2d %f p (%f, %f)\n", iA->t2d(), iA->getPoint2D().x(), iA->getPoint2D().y());
146  printf("iB t2d %f p (%f, %f)\n", iB->t2d(), iB->getPoint2D().x(), iB->getPoint2D().y());
147  }
148  cerr << "Fatal error in CurvePoint::CurvePoint(CurvePoint *iA, CurvePoint *iB, float t3)"
149  << endl;
150  }
151  BLI_assert(__A != nullptr && __B != nullptr);
152 
153 #if 0
154  _Point2d = __A->point2d() + _t2d * (__B->point2d() - __A->point2d());
155  _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d());
156 #endif
157 
158  _Point2d = iA->point2d() + t3 * (iB->point2d() - iA->point2d());
159  _Point3d = __A->point3d() + _t2d * (__B->point3d() - __A->point3d());
160 }
161 
163 {
164  __A = iBrother.__A;
165  __B = iBrother.__B;
166  _t2d = iBrother._t2d;
167  _Point2d = iBrother._Point2d;
168  _Point3d = iBrother._Point3d;
169 }
170 
172 {
173  __A = iBrother.__A;
174  __B = iBrother.__B;
175  _t2d = iBrother._t2d;
176  _Point2d = iBrother._Point2d;
177  _Point3d = iBrother._Point3d;
178  return *this;
179 }
180 
182 {
183  if (getNature() & Nature::T_VERTEX) {
184  return nullptr;
185  }
186  return __A->fedge();
187 }
188 
190 {
191  CurvePoint *iVertexB = dynamic_cast<CurvePoint *>(&inter);
192  if (!iVertexB) {
193  cerr << "Warning: CurvePoint::getFEdge() failed to cast the given 0D element to CurvePoint."
194  << endl;
195  return nullptr;
196  }
197  if (((__A == iVertexB->__A) && (__B == iVertexB->__B)) ||
198  ((__A == iVertexB->__B) && (__B == iVertexB->__A))) {
199  return __A->getFEdge(*__B);
200  }
201  if (__B == nullptr) {
202  if (iVertexB->__B == nullptr) {
203  return __A->getFEdge(*(iVertexB->__A));
204  }
205  if (iVertexB->__A == __A) {
206  return __A->getFEdge(*(iVertexB->__B));
207  }
208  if (iVertexB->__B == __A) {
209  return __A->getFEdge(*(iVertexB->__A));
210  }
211  }
212  if (iVertexB->__B == nullptr) {
213  if (iVertexB->__A == __A) {
214  return __B->getFEdge(*(iVertexB->__A));
215  }
216  if (iVertexB->__A == __B) {
217  return __A->getFEdge(*(iVertexB->__A));
218  }
219  }
220  if (__B == iVertexB->__A) {
221  if ((_t2d != 1) && (iVertexB->_t2d == 0)) {
222  return __A->getFEdge(*__B);
223  }
224  if ((_t2d == 1) && (iVertexB->_t2d != 0)) {
225  return iVertexB->__A->getFEdge(*(iVertexB->__B));
226  }
227  }
228  if (__B == iVertexB->__B) {
229  if ((_t2d != 1) && (iVertexB->_t2d == 1)) {
230  return __A->getFEdge(*__B);
231  }
232  if ((_t2d == 1) && (iVertexB->_t2d != 1)) {
233  return iVertexB->__A->getFEdge(*(iVertexB->__B));
234  }
235  }
236  if (__A == iVertexB->__A) {
237  if ((_t2d == 0) && (iVertexB->_t2d != 0)) {
238  return iVertexB->__A->getFEdge(*(iVertexB->__B));
239  }
240  if ((_t2d != 0) && (iVertexB->_t2d == 0)) {
241  return __A->getFEdge(*__B);
242  }
243  }
244  if (__A == iVertexB->__B) {
245  if ((_t2d == 0) && (iVertexB->_t2d != 1)) {
246  return iVertexB->__A->getFEdge(*(iVertexB->__B));
247  }
248  if ((_t2d != 0) && (iVertexB->_t2d == 1)) {
249  return __A->getFEdge(*__B);
250  }
251  }
252 #if 0
253  if (G.debug & G_DEBUG_FREESTYLE) {
254  printf("__A 0x%p p (%f, %f)\n", __A, __A->getPoint2D().x(), __A->getPoint2D().y());
255  printf("__B 0x%p p (%f, %f)\n", __B, __B->getPoint2D().x(), __B->getPoint2D().y());
256  printf("iVertexB->A() 0x%p p (%f, %f)\n",
257  iVertexB->A(),
258  iVertexB->A()->getPoint2D().x(),
259  iVertexB->A()->getPoint2D().y());
260  printf("iVertexB->B() 0x%p p (%f, %f)\n",
261  iVertexB->B(),
262  iVertexB->B()->getPoint2D().x(),
263  iVertexB->B()->getPoint2D().y());
264  printf("_t2d %f p (%f, %f)\n", _t2d, getPoint2D().x(), getPoint2D().y());
265  printf("iVertexB->t2d() %f p (%f, %f)\n",
266  iVertexB->t2d(),
267  iVertexB->getPoint2D().x(),
268  iVertexB->getPoint2D().y());
269  }
270 #endif
271  cerr << "Warning: CurvePoint::getFEdge() failed." << endl;
272 
273  return nullptr;
274 }
275 
277 {
278  if (__B == nullptr) {
279  return __A->normal();
280  }
281  if (__A == nullptr) {
282  return __B->normal();
283  }
284  Vec3r Na = __A->normal();
285  if (Exception::getException()) {
286  Na = Vec3r(0, 0, 0);
287  }
288  Vec3r Nb = __B->normal();
289  if (Exception::getException()) {
290  Nb = Vec3r(0, 0, 0);
291  }
292  // compute t3d:
294  return ((1 - t3d) * Na + t3d * Nb);
295 }
296 
297 #if 0
299 {
300  if (__A == 0) {
301  return __B->material();
302  }
303  return __A->material();
304 }
305 
306 Id CurvePoint::shape_id() const
307 {
308  if (__A == 0) {
309  return __B->shape_id();
310  }
311  return __A->shape_id();
312 }
313 #endif
314 
315 const SShape *CurvePoint::shape() const
316 {
317  if (__A == nullptr) {
318  return __B->shape();
319  }
320  return __A->shape();
321 }
322 
323 #if 0
324 float CurvePoint::shape_importance() const
325 {
326  if (__A == 0) {
327  return __B->shape_importance();
328  }
329  return __A->shape_importance();
330 }
331 
332 const unsigned CurvePoint::qi() const
333 {
334  if (__A == 0) {
335  return __B->qi();
336  }
337  if (__B == 0) {
338  return __A->qi();
339  }
340  return __A->getFEdge(*__B)->qi();
341 }
342 #endif
343 
344 occluder_container::const_iterator CurvePoint::occluders_begin() const
345 {
346  if (__A == nullptr) {
347  return __B->occluders_begin();
348  }
349  if (__B == nullptr) {
350  return __A->occluders_begin();
351  }
352  return __A->getFEdge(*__B)->occluders_begin();
353 }
354 
355 occluder_container::const_iterator CurvePoint::occluders_end() const
356 {
357  if (__A == nullptr) {
358  return __B->occluders_end();
359  }
360  if (__B == nullptr) {
361  return __A->occluders_end();
362  }
363  return __A->getFEdge(*__B)->occluders_end();
364 }
365 
367 {
368  if (__A == nullptr) {
369  return __B->occluders_empty();
370  }
371  if (__B == nullptr) {
372  return __A->occluders_empty();
373  }
374  return __A->getFEdge(*__B)->occluders_empty();
375 }
376 
378 {
379  if (__A == nullptr) {
380  return __B->occluders_size();
381  }
382  if (__B == nullptr) {
383  return __A->occluders_size();
384  }
385  return __A->getFEdge(*__B)->occluders_size();
386 }
387 
389 {
390  if (__A == nullptr) {
391  return __B->occluded_shape();
392  }
393  if (__B == nullptr) {
394  return __A->occluded_shape();
395  }
396  return __A->getFEdge(*__B)->occluded_shape();
397 }
398 
400 {
401  if (__A == nullptr) {
402  return __B->occludee();
403  }
404  if (__B == nullptr) {
405  return __A->occludee();
406  }
407  return __A->getFEdge(*__B)->occludee();
408 }
409 
411 {
412  if (__A == nullptr) {
413  return __B->occludee_empty();
414  }
415  if (__B == nullptr) {
416  return __A->occludee_empty();
417  }
418  return __A->getFEdge(*__B)->occludee_empty();
419 }
420 
422 {
423  if (__A == nullptr) {
424  return __B->z_discontinuity();
425  }
426  if (__B == nullptr) {
427  return __A->z_discontinuity();
428  }
429  if (__A->getFEdge(*__B) == nullptr) {
430  return 0.0;
431  }
432 
433  return __A->getFEdge(*__B)->z_discontinuity();
434 }
435 
436 #if 0
437 float CurvePoint::local_average_depth() const
438 {
439  return local_average_depth_function<CurvePoint>(this);
440 }
441 
442 float CurvePoint::local_depth_variance() const
443 {
444  return local_depth_variance_function<CurvePoint>(this);
445 }
446 
447 real CurvePoint::local_average_density(float sigma) const
448 {
449  //return local_average_density<CurvePoint >(this);
450  return density_function<CurvePoint>(this);
451 }
452 
453 Vec3r shaded_color() const;
454 
455 Vec3r CurvePoint::orientation2d() const
456 {
457  if (__A == 0) {
458  return __B->orientation2d();
459  }
460  if (__B == 0) {
461  return __A->orientation2d();
462  }
463  return __B->point2d() - __A->point2d();
464 }
465 
466 Vec3r CurvePoint::orientation3d() const
467 {
468  if (__A == 0) {
469  return __B->orientation3d();
470  }
471  if (__B == 0) {
472  return __A->orientation3d();
473  }
474  return __B->point3d() - __A->point3d();
475 }
476 
477 real curvature2d() const
478 {
479  return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0);
480 }
481 
482 Vec3r CurvePoint::curvature2d_as_vector() const
483 {
484 # if 0
485  Vec3r edgeA = (_FEdges[0])->orientation2d().normalize();
486  Vec3r edgeB = (_FEdges[1])->orientation2d().normalize();
487  return edgeA + edgeB;
488 # endif
489  if (__A == 0) {
490  return __B->curvature2d_as_vector();
491  }
492  if (__B == 0) {
493  return __A->curvature2d_as_vector();
494  }
495  return ((1 - _t2d) * __A->curvature2d_as_vector() + _t2d * __B->curvature2d_as_vector());
496 }
497 
498 real CurvePoint::curvature2d_as_angle() const
499 {
500 # if 0
501  Vec3r edgeA = (_FEdges[0])->orientation2d();
502  Vec3r edgeB = (_FEdges[1])->orientation2d();
503  Vec2d N1(-edgeA.y(), edgeA.x());
504  N1.normalize();
505  Vec2d N2(-edgeB.y(), edgeB.x());
506  N2.normalize();
507  return acos((N1 * N2));
508 # endif
509  if (__A == 0) {
510  return __B->curvature2d_as_angle();
511  }
512  if (__B == 0) {
513  return __A->curvature2d_as_angle();
514  }
515  return ((1 - _t2d) * __A->curvature2d_as_angle() + _t2d * __B->curvature2d_as_angle());
516 }
517 
518 real CurvePoint::curvatureFredo() const
519 {
520  if (__A == 0) {
521  return __B->curvatureFredo();
522  }
523  if (__B == 0) {
524  return __A->curvatureFredo();
525  }
526  return ((1 - _t2d) * __A->curvatureFredo() + _t2d * __B->curvatureFredo());
527 }
528 
529 Vec2d CurvePoint::directionFredo() const
530 {
531  if (__A == 0) {
532  return __B->directionFredo();
533  }
534  if (__B == 0) {
535  return __A->directionFredo();
536  }
537  return ((1 - _t2d) * __A->directionFredo() + _t2d * __B->directionFredo());
538 }
539 #endif
540 
541 /**********************************/
542 /* */
543 /* */
544 /* Curve */
545 /* */
546 /* */
547 /**********************************/
548 
549 /* for functions */
550 
552 {
553  if (!_Vertices.empty()) {
554  for (vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); it != itend;
555  ++it) {
556  delete (*it);
557  }
558  _Vertices.clear();
559  }
560 }
561 
564 {
565  vertex_container::iterator second = _Vertices.begin();
566  ++second;
567  return point_iterator(
568  _Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), _nSegments, step, 0.0f, 0.0f);
569  // return point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f);
570 }
571 
573 {
574  vertex_container::const_iterator second = _Vertices.begin();
575  ++second;
576  return const_point_iterator(
577  _Vertices.begin(), second, _Vertices.begin(), _Vertices.end(), _nSegments, step, 0.0f, 0.0f);
578  // return const_point_iterator(_Vertices.begin(), second, _nSegments, step, 0.0f, 0.0f);
579 }
580 
582 {
583  return point_iterator(_Vertices.end(),
584  _Vertices.end(),
585  _Vertices.begin(),
586  _Vertices.end(),
587  _nSegments,
588  step,
589  1.0f,
590  _Length);
591  // return point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f, _Length);
592 }
593 
595 {
596  return const_point_iterator(_Vertices.end(),
597  _Vertices.end(),
598  _Vertices.begin(),
599  _Vertices.end(),
600  _nSegments,
601  step,
602  1.0f,
603  _Length);
604  // return const_point_iterator(_Vertices.end(), _Vertices.end(), _nSegments, step, 1.0f,
605  // _Length);
606 }
607 
608 // Adavnced Iterators access
610 {
611  return points_begin(0);
612 }
613 
615 {
616  return points_begin(0);
617 }
618 
620 {
621  return points_end(0);
622 }
623 
625 {
626  return points_end(0);
627 }
628 
629 // specialized iterators access
631 {
632  vertex_container::iterator second = _Vertices.begin();
633  ++second;
635  second,
636  _Vertices.begin(),
637  _Vertices.end(),
638  0,
639  _nSegments,
640  _Length,
641  t,
642  0.0f,
643  0.0f);
644 }
645 
647 {
648  vertex_container::iterator last = _Vertices.end();
649  --last;
651  _Vertices.end(),
652  _Vertices.begin(),
653  _Vertices.end(),
654  _nSegments,
655  _nSegments,
656  _Length,
657  t,
658  0.0f,
659  _Length);
660 }
661 
663 {
664  return curvePointsBegin(0);
665 }
666 
668 {
669  return curvePointsEnd(0);
670 }
671 
673 {
674  vertex_container::iterator second = _Vertices.begin();
675  ++second;
677  second,
678  _Vertices.begin(),
679  _Vertices.end(),
680  0,
681  _nSegments,
682  _Length,
683  t,
684  0.0f,
685  0.0f));
686  return ret;
687 }
688 
690 {
691  vertex_container::iterator last = _Vertices.end();
692  --last;
694  _Vertices.end(),
695  _Vertices.begin(),
696  _Vertices.end(),
697  _nSegments,
698  _nSegments,
699  _Length,
700  t,
701  0.0f,
702  _Length));
703  return ret;
704 }
705 
707 {
708  return pointsBegin(0);
709 }
710 
712 {
713  return pointsEnd(0);
714 }
715 
716 #if 0
717 Vec3r shaded_color(int iCombination = 0) const;
718 
719 Vec3r Curve::orientation2d(point_iterator it) const
720 {
721  return (*it)->orientation2d();
722 }
723 
724 template<class BaseVertex> Vec3r Curve::orientation2d(int iCombination) const
725 {
726  return edge_orientation2d_function<Curve>(this, iCombination);
727 }
728 
729 Vec3r Curve::orientation3d(point_iterator it) const
730 {
731  return (*it)->orientation3d();
732 }
733 
734 Vec3r Curve::orientation3d(int iCombination) const
735 {
736  return edge_orientation3d_function<Curve>(this, iCombination);
737 }
738 
739 real curvature2d(point_iterator it) const
740 {
741  return (*it)->curvature2d();
742 }
743 
744 real curvature2d(int iCombination = 0) const;
745 
747 {
749  const Material &mat = (*v)->material();
750  for (; v != vend; ++v) {
751  if ((*v)->material() != mat) {
753  }
754  }
755  return mat;
756 }
757 
758 int Curve::qi() const
759 {
761  int qi_ = (*v)->qi();
762  for (; v != vend; ++v) {
763  if ((*v)->qi() != qi_) {
765  }
766  }
767  return qi_;
768 }
769 
770 occluder_container::const_iterator occluders_begin() const
771 {
772  return _FEdgeA->occluders().begin();
773 }
774 
775 occluder_container::const_iterator occluders_end() const
776 {
777  return _FEdgeA->occluders().end();
778 }
779 
780 int Curve::occluders_size() const
781 {
782  return qi();
783 }
784 
785 bool Curve::occluders_empty() const
786 {
788  bool empty = (*v)->occluders_empty();
789  for (; v != vend; ++v) {
790  if ((*v)->occluders_empty() != empty) {
792  }
793  }
794  return empty;
795 }
796 
797 const Polygon3r &occludee() const
798 {
799  return *(_FEdgeA->aFace());
800 }
801 
802 const SShape *Curve::occluded_shape() const
803 {
805  const SShape *sshape = (*v)->occluded_shape();
806  for (; v != vend; ++v) {
807  if ((*v)->occluded_shape() != sshape) {
809  }
810  }
811  return sshape;
812 }
813 
814 const bool Curve::occludee_empty() const
815 {
817  bool empty = (*v)->occludee_empty();
818  for (; v != vend; ++v) {
819  if ((*v)->occludee_empty() != empty) {
821  }
822  }
823  return empty;
824 }
825 real Curve::z_discontinuity(int iCombination) const
826 {
827  return z_discontinuity_edge_function<Curve>(this, iCombination);
828 }
829 
830 int Curve::shape_id() const
831 {
833  Id id = (*v)->shape_id();
834  for (; v != vend; ++v) {
835  if ((*v)->shape_id() != id) {
837  }
838  }
839  return id.first;
840 }
841 
842 const SShape *Curve::shape() const
843 {
845  const SShape *sshape = (*v)->shape();
846  for (; v != vend; ++v) {
847  if ((*v)->shape() != sshape) {
849  }
850  }
851  return sshape;
852 }
853 
854 occluder_container::const_iterator Curve::occluders_begin() const
855 {
857  return (*v)->occluders_begin();
858 }
859 
860 occluder_container::const_iterator Curve::occluders_end() const
861 {
863  return (*v)->occluders_end();
864 }
865 
866 Vec3r Curve::curvature2d_as_vector(int iCombination) const
867 {
868  return curvature2d_as_vector_edge_function<Curve>(this, iCombination);
869 }
870 
871 real Curve::curvature2d_as_angle(int iCombination) const
872 {
873  return curvature2d_as_angle_edge_function<Curve>(this, iCombination);
874 }
875 
876 float Curve::shape_importance(int iCombination) const
877 {
878  return shape_importance_edge_function<Curve>(this, iCombination);
879 }
880 
881 float Curve::local_average_depth(int iCombination) const
882 {
883  return local_average_depth_edge_function<Curve>(this, iCombination);
884 }
885 
886 float Curve::local_depth_variance(int iCombination) const
887 {
888  return local_depth_variance_edge_function<Curve>(this, iCombination);
889 # if 0
890  local_depth_variance_functor<Point> functor;
891  float result;
892  Evaluate<float, local_depth_variance_functor<Point> >(&functor, iCombination, result);
893  return result;
894 # endif
895 }
896 
897 real Curve::local_average_density(float sigma, int iCombination) const
898 {
899  return density_edge_function<Curve>(this, iCombination);
900 # if 0
901  density_functor<Point> functor;
902  real result;
903  Evaluate<real, density_functor<Point> >(&functor, iCombination, result);
904  return result;
905 # endif
906 }
907 
908 /* UNUSED */
909 // #define EPS_CURVA_DIR 0.01
910 
911 void Curve::computeCurvatureAndOrientation()
912 {
913  const_vertex_iterator v = vertices_begin(), vend = vertices_end(), v2, prevV, v0;
914  Vec2d p0, p1, p2;
915  Vec3r p;
916 
917  p = (*v)->point2d();
918  p0 = Vec2d(p[0], p[1]);
919  prevV = v;
920  ++v;
921  p = (*v)->point2d();
922  p1 = Vec2d(p[0], p[1]);
923  Vec2d prevDir(p1 - p0);
924 
925  for (; v ! = vend; ++v) {
926  v2 = v;
927  ++v2;
928  if (v2 == vend) {
929  break;
930  }
931  Vec3r p2 = (*v2)->point2d();
932 
933  Vec2d BA = p0 - p1;
934  Vec2d BC = p2 - p1;
935  real lba = BA.norm(), lbc = BC.norm();
936  BA.normalizeSafe();
937  BC.normalizeSafe();
938  Vec2d normalCurvature = BA + BC;
939  Vec2d dir = Vec2d(BC - BA);
940  Vec2d normal = Vec2d(-dir[1], dir[0]);
941 
942  normal.normalizeSafe();
943  real curvature = normalCurvature * normal;
944  if (lba + lbc > MY_EPSILON) {
945  curvature /= (0.5 * lba + lbc);
946  }
947  if (dir.norm() < MY_EPSILON) {
948  dir = 0.1 * prevDir;
949  }
950  (*v)->setCurvatureFredo(curvature);
951  (*v)->setDirectionFredo(dir);
952 
953  prevV = v;
954  p0 = p1;
955  p1 = p2;
956  prevDir = dir;
957  prevDir.normalize();
958  }
959  (*v)->setCurvatureFredo((*prevV)->curvatureFredo());
960  (*v)->setDirectionFredo((*v)->point2d() - (*prevV)->point2d());
961  v0 = vertices_begin();
962  v2 = v0;
963  ++v2;
964  (*v0)->setCurvatureFredo((*v2)->curvatureFredo());
965  (*v0)->setDirectionFredo((*v2)->point2d() - (*v0)->point2d());
966 
967  //closed curve case one day...
968 
969  //
970  return;
971 
972  //numerical degeneracy verification... we'll see later
973  const_vertex_iterator vLastReliable = vertices_begin();
974 
975  v = vertices_begin();
976  p = (*v)->point2d();
977  p0 = Vec2d(p[0], p[1]);
978  prevV = v;
979  ++v;
980  p = (*v)->point2d();
981  p1 = Vec2d(p[0], p[1]);
982  bool isReliable = false;
983  if ((p1 - p0).norm > EPS_CURVA) {
984  vLastReliable = v;
985  isReliable = true;
986  }
987 
988  for (; v != vend; ++v) {
989  v2 = v;
990  ++v2;
991  if (v2 == vend) {
992  break;
993  }
994  Vec3r p2 = (*v2)->point2d();
995 
996  Vec2d BA = p0 - p1;
997  Vec2d BC = p2 - p1;
998  real lba = BA.norm(), lbc = BC.norm();
999 
1000  if ((lba + lbc) < EPS_CURVA) {
1001  isReliable = false;
1002  cerr << "/";
1003  }
1004  else {
1005  if (!isReliable) { //previous points were not reliable
1006  const_vertex_iterator vfix = vLastReliable;
1007  ++vfix;
1008  for (; vfix != v; ++vfix) {
1009  (*vfix)->setCurvatureFredo((*v)->curvatureFredo());
1010  (*vfix)->setDirectionFredo((*v)->directionFredo());
1011  }
1012  }
1013  isReliable = true;
1014  vLastReliable = v;
1015  }
1016  prevV = v;
1017  p0 = p1;
1018  p1 = p2;
1019  }
1020 }
1021 #endif
1022 
1023 } /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:181
#define BLI_assert(a)
Definition: BLI_assert.h:46
Iterators used to iterate over the elements of the Curve. Can't be used in python.
Iterators used to iterate over the elements of the Curve.
Class to define a container for curves.
_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 GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
SVertex * __B
Definition: Curve.h:186
const Vec3r & point2d() const
Definition: Curve.h:289
virtual FEdge * getFEdge(Interface0D &inter)
Definition: Curve.cpp:189
int occluders_size() const
Definition: Curve.cpp:377
real z_discontinuity() const
Definition: Curve.cpp:421
CurvePoint & operator=(const CurvePoint &iBrother)
Definition: Curve.cpp:171
bool occluders_empty() const
Definition: Curve.cpp:366
occluder_container::const_iterator occluders_begin() const
Definition: Curve.cpp:344
const SShape * occluded_shape() const
Definition: Curve.cpp:388
float t2d() const
Definition: Curve.h:247
SVertex * B()
Definition: Curve.h:241
virtual Nature::VertexNature getNature() const
Definition: Curve.h:121
SVertex * A()
Definition: Curve.h:235
SVertex * __A
Definition: Curve.h:185
Vec3r normal() const
Definition: Curve.cpp:276
bool occludee_empty() const
Definition: Curve.cpp:410
virtual Vec2r getPoint2D() const
Definition: Curve.h:100
occluder_container::const_iterator occluders_end() const
Definition: Curve.cpp:355
const Polygon3r & occludee() const
Definition: Curve.cpp:399
const SShape * shape() const
Definition: Curve.cpp:315
point_iterator vertices_end()
Definition: Curve.cpp:619
vertex_container _Vertices
Definition: Curve.h:379
CurveInternal::__point_iterator< CurveInternal::CurvePoint_nonconst_traits > point_iterator
Definition: Curve.h:372
unsigned _nSegments
Definition: Curve.h:382
virtual Interface0DIterator verticesBegin()
Definition: Curve.cpp:706
virtual Interface0DIterator verticesEnd()
Definition: Curve.cpp:711
point_iterator points_end(float step=0)
Definition: Curve.cpp:581
CurveInternal::__point_iterator< CurveInternal::CurvePoint_const_traits > const_point_iterator
Definition: Curve.h:374
virtual ~Curve()
Definition: Curve.cpp:551
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition: Curve.cpp:672
CurveInternal::CurvePointIterator curvePointsBegin(float t=0.0f)
Definition: Curve.cpp:630
CurveInternal::CurvePointIterator curveVerticesBegin()
Definition: Curve.cpp:662
bool empty() const
Definition: Curve.h:473
CurveInternal::CurvePointIterator curveVerticesEnd()
Definition: Curve.cpp:667
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition: Curve.cpp:689
double _Length
Definition: Curve.h:380
point_iterator vertices_begin()
Definition: Curve.cpp:609
point_iterator points_begin(float step=0)
Definition: Curve.cpp:563
const_point_iterator const_vertex_iterator
Definition: Curve.h:376
CurveInternal::CurvePointIterator curvePointsEnd(float t=0.0f)
Definition: Curve.cpp:646
static int getException()
Definition: Exception.h:23
static int raiseException(exception_type exception=UNDEFINED)
Definition: Exception.h:30
const int qi() const
Definition: Silhouette.h:872
bool occluders_empty() const
Definition: Silhouette.cpp:254
int occluders_size() const
Definition: Silhouette.cpp:259
occluder_container::const_iterator occluders_end() const
Definition: Silhouette.cpp:249
occluder_container::const_iterator occluders_begin() const
Definition: Silhouette.cpp:244
const SShape * occluded_shape() const
Definition: Silhouette.cpp:225
const Polygon3r & occludee() const
Definition: Silhouette.h:882
real z_discontinuity() const
Definition: Silhouette.cpp:279
bool occludee_empty() const
Definition: Silhouette.cpp:264
SShape * shape()
Definition: Silhouette.h:263
const SShape * occluded_shape() const
Definition: Silhouette.cpp:120
virtual FEdge * getFEdge(Interface0D &)
Definition: Silhouette.cpp:152
const Vec3r & point2d() const
Definition: Silhouette.h:395
int qi() const
Definition: Silhouette.cpp:72
Vec3r normal() const
Definition: Silhouette.h:405
real z_discontinuity() const
Definition: Silhouette.cpp:136
occluder_container::const_iterator occluders_begin() const
Definition: Silhouette.cpp:80
bool occluders_empty() const
Definition: Silhouette.cpp:96
Id shape_id() const
Definition: Silhouette.cpp:62
virtual Vec2r getPoint2D() const
Definition: Silhouette.h:108
occluder_container::const_iterator occluders_end() const
Definition: Silhouette.cpp:88
int occluders_size() const
Definition: Silhouette.cpp:104
const Polygon3r & occludee() const
Definition: Silhouette.cpp:112
const Vec3r & point3d() const
Definition: Silhouette.h:400
bool occludee_empty() const
Definition: Silhouette.cpp:128
float shape_importance() const
Definition: Silhouette.cpp:50
static real ImageToWorldParameter(FEdge *fe, real t)
value_type x() const
Definition: VecMat.h:305
value_type y() const
Definition: VecMat.h:315
Vec< T, N > & normalize()
Definition: VecMat.h:105
Material material
IconTextureDrawCall normal
#define G(x, y, z)
VecMat::Vec2< double > Vec2d
Definition: Geom.h:21
VecMat::Vec3< real > Vec3r
Definition: Geom.h:28
static const VertexNature T_VERTEX
Definition: Nature.h:28
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
double real
Definition: Precision.h:12
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition: rall1d.h:399
return ret