From 3105a734ed04764d61a7aef48b96a1fe3423a971 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 27 Nov 2015 23:05:30 +0100 Subject: [PATCH] [DEBUG] correct display bug of ordering segment before weight and reject double point position in a single line --- esvg/render/Segment.cpp | 4 ++-- esvg/render/Segment.h | 2 +- esvg/render/SegmentList.cpp | 8 +++---- esvg/render/Weight.cpp | 43 +++++++++++++++++++++++++++---------- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/esvg/render/Segment.cpp b/esvg/render/Segment.cpp index ce5a35a..5f999fa 100644 --- a/esvg/render/Segment.cpp +++ b/esvg/render/Segment.cpp @@ -17,11 +17,11 @@ esvg::render::Segment::Segment(const vec2& _p0, const vec2& _p1) { if (_p0.y() < _p1.y()) { p0 = _p0; p1 = _p1; - direction = 1.0f; // direction like clock + direction = 1; // direction like clock } else { p0 = _p1; p1 = _p0; - direction = -1.0f; // direction like anti-clock + direction = -1; // direction like anti-clock } } diff --git a/esvg/render/Segment.h b/esvg/render/Segment.h index eecb0cb..cd8cef8 100644 --- a/esvg/render/Segment.h +++ b/esvg/render/Segment.h @@ -19,7 +19,7 @@ namespace esvg { Segment(const vec2& _p0, const vec2& _p1); vec2 p0; vec2 p1; - float direction; + int32_t direction; }; } } diff --git a/esvg/render/SegmentList.cpp b/esvg/render/SegmentList.cpp index 660e720..6d42404 100644 --- a/esvg/render/SegmentList.cpp +++ b/esvg/render/SegmentList.cpp @@ -41,8 +41,8 @@ void esvg::render::SegmentList::createSegmentList(const esvg::render::PointList& addSegment(it[jjj], it[iii]); } } - // TODO : Check if it is really usefull ... - std::sort(m_data.begin(), m_data.end(), sortSegmentFunction); + // TODO : Check if it is really usefull ... ==> really bad, create parsing bug in weighter ... + //std::sort(m_data.begin(), m_data.end(), sortSegmentFunction); } static vec2 getIntersect(const vec2& _point1, @@ -211,8 +211,8 @@ void esvg::render::SegmentList::createSegmentListStroke(esvg::render::PointList& } } } - // TODO : Check if it is really usefull ... - std::sort(m_data.begin(), m_data.end(), sortSegmentFunction); + // TODO : Check if it is really usefull ... ==> really bad, create parsing bug in weighter ... + //std::sort(m_data.begin(), m_data.end(), sortSegmentFunction); } diff --git a/esvg/render/Weight.cpp b/esvg/render/Weight.cpp index 91e6d40..5fe8e9a 100644 --- a/esvg/render/Weight.cpp +++ b/esvg/render/Weight.cpp @@ -97,17 +97,23 @@ void esvg::render::Weight::generate(ivec2 _size, int32_t _subSamplingCount, cons resize(_size); // for each lines: for (int32_t yyy=0; yyy<_size.y(); ++yyy) { + SVG_VERBOSE("Weighting ... " << yyy << " / " << _size.y()); // Reduce the number of lines in the subsampling parsing: std::vector availlableSegmentPixel; for (auto &it : _listSegment.m_data) { - if ( it.p0.y() <= float(yyy+1) - && it.p1.y() >= float(yyy)) { + if ( it.p0.y() < float(yyy+1) + && it.p1.y() > float(yyy)) { availlableSegmentPixel.push_back(it); } } + if (availlableSegmentPixel.size() == 0) { + continue; + } + SVG_VERBOSE(" Find Basic segments " << availlableSegmentPixel.size()); // This represent the pondaration on the subSampling float deltaSize = 1.0f/_subSamplingCount; for (int32_t kkk=0; kkk<_subSamplingCount ; ++kkk) { + SVG_VERBOSE(" Scanline ... " << kkk << " / " << _subSamplingCount); Scanline scanline(_size.x()); //find all the segment that cross the middle of the line of the center of the pixel line: float subSamplingCenterPos = yyy + deltaSize*0.5f + deltaSize*kkk; @@ -116,23 +122,38 @@ void esvg::render::Weight::generate(ivec2 _size, int32_t _subSamplingCount, cons for (auto &it : availlableSegmentPixel) { if ( it.p0.y() <= subSamplingCenterPos && it.p1.y() >= subSamplingCenterPos) { - availlableSegment.push_back(it); + // check if we not get 2 identical lines: + if ( availlableSegment.size() > 0 + && availlableSegment.back().p1 == it.p0 + && availlableSegment.back().direction == it.direction) { + // we not add this point in this case to prevent double count of the same point. + } else { + availlableSegment.push_back(it); + } } } + SVG_VERBOSE(" Availlable Segment " << availlableSegment.size()); + if (availlableSegment.size() == 0) { + continue; + } + for (auto &it : availlableSegment) { + SVG_VERBOSE(" Availlable Segment " << it.p0 << " -> " << it.p1 << " dir=" << it.direction); + } // x position, angle - std::vector> listPosition; + std::vector> listPosition; for (auto &it : availlableSegment) { vec2 delta = it.p0 - it.p1; // x = coefficent*y+bbb; float coefficient = delta.x()/delta.y(); float bbb = it.p0.x() - coefficient*it.p0.y(); float xpos = coefficient * subSamplingCenterPos + bbb; - listPosition.push_back(std::pair(xpos, it.direction)); + listPosition.push_back(std::pair(xpos, it.direction)); } + SVG_VERBOSE(" List position " << listPosition.size()); // now we order position of the xPosition: std::sort(listPosition.begin(), listPosition.end(), sortXPosFunction); // move through all element in the point: - float lastState = 0.0f; + int32_t lastState = 0; float currentValue = 0.0f; int32_t lastPos = -1; int32_t currentPos = -1; @@ -144,20 +165,20 @@ void esvg::render::Weight::generate(ivec2 _size, int32_t _subSamplingCount, cons for (auto &it : listPosition) { if (currentPos != int32_t(it.first)) { // fill to the new pos -1: - float endValue = std::min(1.0f,std::abs(lastState)) * deltaSize; + float endValue = float(std::min(1,std::abs(lastState))) * deltaSize; for (int32_t iii=currentPos+1; iii fill if to the end with full value ... 2.0 - if (lastState != 0.0f) { + if (lastState != 0) { // just past the last state to the end of the image ... SVG_ERROR("end of Path whith no end ... " << currentPos << " -> " << _size.x()); for (int32_t xxx=currentPos; xxx<_size.x(); ++xxx) {