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