35 if (_current_set->empty()) {
42 I1DContainer::iterator it = _current_set->begin();
43 I1DContainer::iterator itbegin = it;
44 while (it != _current_set->end()) {
53 new_set.push_back(i1d);
57 rejected.push_back(i1d);
61 if ((*itbegin)->getExactTypeName() !=
"ViewEdge") {
62 for (it = rejected.begin(); it != rejected.end(); ++it) {
67 _current_set->clear();
68 *_current_set = new_set;
76 if (_current_view_edges_set.empty()) {
84 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
85 it_edge != _current_view_edges_set.end();
88 if (pred(**it_edge) < 0) {
95 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
103 if (modifier(**it) < 0) {
111 if (pred(**it) < 0) {
119 new_chains_set.push_back(new_chain);
122 if (!new_chains_set.empty()) {
123 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
124 _current_chains_set.push_back(*it);
126 new_chains_set.clear();
127 _current_set = &_current_chains_set;
132 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
135 new_chains_set.clear();
141 if (_current_view_edges_set.empty()) {
151 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
152 it_edge != _current_view_edges_set.end();
155 if (pred(**it_edge) < 0) {
161 if (pred_ts(**it_edge) < 0) {
168 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
181 if (pred(**it) < 0) {
188 if (pred_ts(**it) < 0) {
196 new_chains_set.push_back(new_chain);
199 if (!new_chains_set.empty()) {
200 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
201 _current_chains_set.push_back(*it);
203 new_chains_set.clear();
204 _current_set = &_current_chains_set;
209 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
212 new_chains_set.clear();
221 if (_current_view_edges_set.empty()) {
229 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
230 it_edge != _current_view_edges_set.end();
233 if (pred(**it_edge)) {
237 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
239 it.setCurrentEdge(edge);
241 Chain *new_chain =
new Chain(
id);
244 ViewEdgeIterator it_back(it);
248 new_chain->push_viewedge_back(*it, it.getOrientation());
251 }
while (!it.isEnd() && !pred(**it));
253 it.setCurrentEdge(edge);
255 while (!it.isEnd() && !pred(**it)) {
256 new_chain->push_viewedge_front(*it, it.getOrientation());
261 _current_chains_set.push_back(new_chain);
264 if (!_current_chains_set.empty()) {
265 _current_set = &_current_chains_set;
271 if (_current_view_edges_set.empty()) {
276 Functions1D::IncrementChainingTimeStampF1D ts;
277 Predicates1D::EqualToChainingTimeStampUP1D pred_ts(
TimeStamp::instance()->getTimeStamp() + 1);
282 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
283 it_edge != _current_view_edges_set.end();
286 if (pred(**it_edge) || pred_ts(**it_edge)) {
290 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
292 it.setCurrentEdge(edge);
294 Chain *new_chain =
new Chain(
id);
297 ViewEdgeIterator it_back(it);
301 new_chain->push_viewedge_back(*it, it.getOrientation());
304 }
while (!it.isEnd() && !pred(**it) && !pred_ts(**it));
306 it.setCurrentEdge(edge);
308 while (!it.isEnd() && !pred(**it) && !pred_ts(**it)) {
309 new_chain->push_viewedge_front(*it, it.getOrientation());
314 _current_chains_set.push_back(new_chain);
317 if (!_current_chains_set.empty()) {
318 _current_set = &_current_chains_set;
325 if (_current_view_edges_set.empty()) {
335 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
336 it_edge != _current_view_edges_set.end();
339 if (pred(**it_edge) < 0) {
345 if (pred_ts(**it_edge) < 0) {
352 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
364 ViewEdgeIterator it_back(it);
377 if (pred(**it) < 0) {
392 while (!it.
isEnd()) {
393 if (pred(**it) < 0) {
407 new_chains_set.push_back(new_chain);
410 if (!new_chains_set.empty()) {
411 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
412 _current_chains_set.push_back(*it);
414 new_chains_set.clear();
415 _current_set = &_current_chains_set;
420 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
423 new_chains_set.clear();
429 if (_current_view_edges_set.empty()) {
439 for (I1DContainer::iterator it_edge = _current_view_edges_set.begin();
440 it_edge != _current_view_edges_set.end();
443 if (pred_ts(**it_edge) < 0) {
450 edge =
dynamic_cast<ViewEdge *
>(*it_edge);
462 ViewEdgeIterator it_back(it);
472 }
while (!it.
isEnd());
480 while (!it.
isEnd()) {
488 new_chains_set.push_back(new_chain);
491 if (!new_chains_set.empty()) {
492 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
493 _current_chains_set.push_back(*it);
495 new_chains_set.clear();
496 _current_set = &_current_chains_set;
501 for (I1DContainer::iterator it = new_chains_set.begin(); it != new_chains_set.end(); ++it) {
504 new_chains_set.clear();
510 if (_current_chains_set.empty()) {
511 cerr <<
"Warning: current set empty" << endl;
521 I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
522 for (; cit != citend; ++cit) {
523 Id currentId = (*cit)->getId();
524 new_curve =
new Chain(currentId);
525 first = (*cit)->pointsBegin(sampling);
526 end = (*cit)->pointsEnd(sampling);
534 for (; it != end; ++it) {
541 if (pred.
result && (it != last)) {
542 splitted_chains.push_back(new_curve);
544 new_curve =
new Chain(currentId);
553 splitted_chains.push_back(new_curve);
557 cit = _current_chains_set.begin();
558 for (; cit != citend; ++cit) {
561 _current_chains_set.clear();
563 _current_chains_set = splitted_chains;
565 for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
570 _current_chains_set.push_back(*cit);
573 splitted_chains.clear();
575 if (!_current_chains_set.empty()) {
576 _current_set = &_current_chains_set;
581 cit = splitted_chains.begin();
582 citend = splitted_chains.end();
583 for (; cit != citend; ++cit) {
586 splitted_chains.clear();
594 if (_current_chains_set.empty()) {
595 cerr <<
"Warning: current set empty" << endl;
606 I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
607 for (; cit != citend; ++cit) {
608 Id currentId = (*cit)->getId();
609 first = (*cit)->pointsBegin(sampling);
610 end = (*cit)->pointsEnd(sampling);
618 new_curve =
new Chain(currentId);
621 point =
dynamic_cast<CurvePoint *
>(&(*itStart));
624 point =
dynamic_cast<CurvePoint *
>(&(*itStop));
630 if (stoppingPred(itStop) < 0) {
634 }
while (!stoppingPred.
result);
636 point =
dynamic_cast<CurvePoint *
>(&(*itStop));
643 splitted_chains.push_back(new_curve);
648 if (itStart == end) {
651 if (startingPred(itStart) < 0) {
654 }
while (!startingPred.
result);
655 }
while (!
ELEM(itStart, end, last));
659 cit = _current_chains_set.begin();
660 for (; cit != citend; ++cit) {
663 _current_chains_set.clear();
665 _current_chains_set = splitted_chains;
667 for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
672 _current_chains_set.push_back(*cit);
675 splitted_chains.clear();
677 if (!_current_chains_set.empty()) {
678 _current_set = &_current_chains_set;
683 cit = splitted_chains.begin();
684 citend = splitted_chains.end();
685 for (; cit != citend; ++cit) {
688 splitted_chains.clear();
701 newChains.push_back(_curve);
718 for (; ((it != end) && (
next != end)); ++it, ++
next) {
720 if (func(it0d) < 0) {
731 newChains.push_back(_curve);
737 if (newId ==
nullptr) {
738 newId =
new Id(_curve->
getId());
754 for (; (vit != vitend) && (vnext != vitend) &&
760 if ((vit == vitend) || (vnext == vitend)) {
762 cout <<
"The split takes place in bad location" << endl;
764 newChains.push_back(_curve);
775 for (vit = vnext; vit != vitend; ++vit) {
781 if (pred(*new_curve_a) < 0 || (!pred.
result && pred(*new_curve_b) < 0)) {
788 newChains.push_back(_curve);
794 splitted_chains.push_back(_curve);
796 __recursiveSplit(new_curve_a, func, pred, sampling, newChains, splitted_chains);
797 __recursiveSplit(new_curve_b, func, pred, sampling, newChains, splitted_chains);
805 if (_current_chains_set.empty()) {
806 cerr <<
"Warning: current set empty" << endl;
810 Chain *currentChain =
nullptr;
813 I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
814 for (; cit != citend; ++cit) {
815 currentChain =
dynamic_cast<Chain *
>(*cit);
820 if (pred(*currentChain) < 0) {
824 __recursiveSplit(currentChain, func, pred, sampling, newChains, splitted_chains);
827 newChains.push_back(currentChain);
831 if (!splitted_chains.empty()) {
832 for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
835 splitted_chains.clear();
838 _current_chains_set.clear();
840 _current_chains_set = newChains;
842 for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) {
847 _current_chains_set.push_back(*cit);
852 if (!_current_chains_set.empty()) {
853 _current_set = &_current_chains_set;
868 newChains.push_back(_curve);
880 real _min = func(it0d);
892 for (; ((it != end) && (
next != end)); ++it, ++
next) {
895 if (pred0d(it0d) < 0) {
901 if (func(it0d) < 0) {
915 newChains.push_back(_curve);
921 if (newId ==
nullptr) {
922 newId =
new Id(_curve->
getId());
938 for (; (vit != vitend) && (vnext != vitend) &&
944 if ((vit == vitend) || (vnext == vitend)) {
946 cout <<
"The split takes place in bad location" << endl;
948 newChains.push_back(_curve);
959 for (vit = vnext; vit != vitend; ++vit) {
965 if (pred(*new_curve_a) < 0 || (!pred.
result && pred(*new_curve_b) < 0)) {
972 newChains.push_back(_curve);
978 splitted_chains.push_back(_curve);
980 __recursiveSplit(new_curve_a, func, pred0d, pred, sampling, newChains, splitted_chains);
981 __recursiveSplit(new_curve_b, func, pred0d, pred, sampling, newChains, splitted_chains);
990 if (_current_chains_set.empty()) {
991 cerr <<
"Warning: current set empty" << endl;
995 Chain *currentChain =
nullptr;
998 I1DContainer::iterator cit = _current_chains_set.begin(), citend = _current_chains_set.end();
999 for (; cit != citend; ++cit) {
1000 currentChain =
dynamic_cast<Chain *
>(*cit);
1001 if (!currentChain) {
1005 if (pred(*currentChain) < 0) {
1009 __recursiveSplit(currentChain, func, pred0d, pred, sampling, newChains, splitted_chains);
1012 newChains.push_back(currentChain);
1016 if (!splitted_chains.empty()) {
1017 for (cit = splitted_chains.begin(), citend = splitted_chains.end(); cit != citend; ++cit) {
1020 splitted_chains.clear();
1023 _current_chains_set.clear();
1025 _current_chains_set = newChains;
1027 for (cit = newChains.begin(), citend = newChains.end(); cit != citend; ++cit) {
1028 if ((*cit)->getLength2D() <
M_EPSILON) {
1032 _current_chains_set.push_back(*cit);
1037 if (!_current_chains_set.empty()) {
1038 _current_set = &_current_chains_set;
1056 if ((*_pred)(*i1, *i2) < 0) {
1057 throw std::runtime_error(
"comparison failed");
1059 return _pred->result;
1068 if (!_current_set) {
1073 std::sort(_current_set->begin(), _current_set->end(), wrapper);
1075 catch (std::runtime_error &
e) {
1076 cerr <<
"Warning: Operator.sort(): " <<
e.what() << endl;
1087 float currentCurvilignAbscissa = 0.0f;
1093 Vec2r previous = current;
1097 bool hasSingularity =
false;
1102 sv =
dynamic_cast<SVertex *
>(&(*it));
1104 cerr <<
"Warning: unexpected Vertex type" << endl;
1113 Vec2r vec_tmp(current - previous);
1115 if (dist < 1.0e-6) {
1116 hasSingularity =
true;
1118 currentCurvilignAbscissa += dist;
1123 }
while (!
ELEM(it, itend, itfirst));
1125 if (it == itfirst) {
1129 sv =
dynamic_cast<SVertex *
>(&(*it));
1131 cerr <<
"Warning: unexpected Vertex type" << endl;
1141 Vec2r vec_tmp(current - previous);
1143 if (dist < 1.0e-6) {
1144 hasSingularity =
true;
1146 currentCurvilignAbscissa += dist;
1155 stroke->
setLength(currentCurvilignAbscissa);
1156 if (hasSingularity) {
1163 while (!vnext.
isEnd()) {
1165 next = (*vnext).getPoint();
1166 if ((
next - current).
norm() < 1.0e-6) {
1173 std::vector<StrokeVertex *> overlapping_vertices;
1174 overlapping_vertices.push_back(&(*
v));
1176 overlapping_vertices.push_back(&(*vnext));
1180 if (vnext.
isEnd()) {
1183 next = (*vnext).getPoint();
1184 }
while ((
next - current).
norm() < 1.0e-6);
1188 if (!vnext.
isEnd()) {
1189 target = (*vnext).getPoint();
1192 else if (!vprevious.
isBegin()) {
1193 target = (*vprevious).getPoint();
1201 current = overlapping_vertices.front()->getPoint();
1202 Vec2r dir(target - current);
1205 int nvert = overlapping_vertices.size();
1206 if (dist <
len * nvert) {
1213 std::vector<StrokeVertex *>::iterator it = overlapping_vertices.begin();
1215 for (
int n = 0; n < nvert; n++) {
1222 for (
int n = 0; n < nvert; n++) {
1229 if (vnext.
isEnd()) {
1243 bool warning =
false;
1244 while (!vnext.
isEnd()) {
1246 next = (*vnext).getPoint2D();
1247 if ((
next - current).
norm() < 1.0e-6) {
1255 printf(
"Warning: stroke contains singular points.\n");
1263 for (vector<StrokeShader *>::iterator it = shaders.begin(); it != shaders.end(); ++it) {
1264 if ((*it)->shade(stroke) < 0) {
1274 if (!_current_set) {
1275 cerr <<
"Warning: current set empty" << endl;
1279 for (Operators::I1DContainer::iterator it = _current_set->begin(); it != _current_set->end();
1282 if (pred(**it) < 0) {
1296 new_strokes_set.push_back(stroke);
1300 for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it)
1302 _current_strokes_set.push_back(*it);
1304 new_strokes_set.clear();
1308 for (StrokesContainer::iterator it = new_strokes_set.begin(); it != new_strokes_set.end(); ++it)
1312 new_strokes_set.clear();
1320 cerr <<
"Error: no ViewMap computed yet" << endl;
1323 _current_view_edges_set.clear();
1324 for (I1DContainer::iterator it = _current_chains_set.begin(); it != _current_chains_set.end();
1329 _current_chains_set.clear();
1332 ViewMap::viewedges_container::iterator ve = vedges.begin(), veend = vedges.end();
1333 for (; ve != veend; ++ve) {
1337 _current_view_edges_set.push_back(*ve);
1339 _current_set = &_current_view_edges_set;
1340 if (removeStrokes) {
1341 _current_strokes_set.clear();
Class to define a canvas designed to draw style modules.
Iterators used to iterate over the elements of the Curve.
static void split(const char *text, const char *seps, char ***str, int *count)
Class gathering stroke creation algorithms.
Iterators used to iterate over the elements of the Stroke.
Classes to define a stroke.
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
void push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
void push_viewedge_back(ViewEdge *iViewEdge, bool orientation)
void setSplittingId(Id *sid)
Interface0DIterator castToInterface0DIterator() const
virtual Vec2r getPoint2D() const
void push_vertex_back(Vertex *iVertex)
CurveInternal::CurvePointIterator curvePointsBegin(float t=0.0f)
CurveInternal::CurvePointIterator curveVerticesBegin()
CurveInternal::CurvePointIterator curveVerticesEnd()
CurveInternal::CurvePointIterator curvePointsEnd(float t=0.0f)
id_type getSecond() const
void setSecond(id_type second)
virtual bool isEnd() const
virtual Geometry::Vec2r getPoint2D() const
virtual Interface0DIterator verticesEnd()
virtual Interface0DIterator verticesBegin()
static int sort(BinaryPredicate1D &pred)
static int select(UnaryPredicate1D &pred)
static int chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred, UnaryFunction1D_void &modifier)
static void reset(bool removeStrokes=true)
vector< Interface1D * > I1DContainer
static int sequentialSplit(UnaryPredicate0D &startingPred, UnaryPredicate0D &stoppingPred, float sampling=0.0f)
static int recursiveSplit(UnaryFunction0D< double > &func, UnaryPredicate1D &pred, float sampling=0)
static int bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred)
static int create(UnaryPredicate1D &pred, vector< StrokeShader * > shaders)
vector< Stroke * > StrokesContainer
bool operator()(Interface1D *i1, Interface1D *i2)
PredicateWrapper(BinaryPredicate1D &pred)
void setCurvilinearAbscissa(float iAbscissa)
void setPoint(real x, real y)
void push_back(StrokeVertex *iVertex)
virtual Interface0DIterator verticesBegin()
uint strokeVerticesSize() const
void setLength(float iLength)
StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t=0.0f)
static TimeStamp * instance()
Vec< T, N > & normalize()
bool getOrientation() const
void setOrientation(bool orientation)
void setBegin(ViewEdge *begin)
virtual bool isEnd() const
void setCurrentEdge(ViewEdge *edge)
vector< ViewEdge * > viewedges_container
static ViewMap * getInstance()
viewedges_container & ViewEdges()
static void error(const char *str)
VecMat::Vec2< real > Vec2r
static const real M_EPSILON
static int __recursiveSplit(Chain *_curve, UnaryFunction0D< double > &func, UnaryPredicate1D &pred, float sampling, Operators::I1DContainer &newChains, Operators::I1DContainer &splitted_chains)
static Stroke * createStroke(Interface1D &inter)
int applyShading(Stroke &stroke, vector< StrokeShader * > &shaders)