[DEV] REwork methode to be simple

This commit is contained in:
Edouard DUPIN 2015-11-17 22:34:12 +01:00
parent 402b29ca36
commit a66e8ff9ff
2 changed files with 435 additions and 353 deletions

View File

@ -484,399 +484,485 @@ class PointRender {
m_type(_type) { m_type(_type) {
// nothing to do ... // nothing to do ...
} }
void setEndPath() {
if (m_type == typePoint_interpolation) {
SVG_WARNING("Request stop path of an interpolate Point");
m_type = typePoint_stop;
return;
}
if (m_type == typePoint_stop) {
SVG_WARNING("Request stop path of an STOP Point");
return;
}
if (m_type == typePoint_start) {
m_type = typePoint_single;
return;
}
m_type = typePoint_stop;
}
void normalize(const vec2& _nextPoint) { void normalize(const vec2& _nextPoint) {
m_delta = _nextPoint - m_pos; m_delta = _nextPoint - m_pos;
m_len = m_delta.length(); m_len = m_delta.length();
} }
}; };
class Transformation { void diplayRenderPoints(const std::vector<PointRender>& listPoints) {
public: SVG_VERBOSE(" Display list of points : size=" << listPoints.size());
std::vector<PointRender> m_listPoints; for (int32_t iii=0;
std::vector<Segment> m_listSegment; iii < listPoints.size();
float m_threshold; ++iii) {
int32_t m_recursionMax; switch (listPoints[iii].m_type) {
int32_t m_subSamplingCount; case PointRender::typePoint_single:
public: SVG_VERBOSE(" [" << iii << "] Find Single " << listPoints[iii].m_pos);
Transformation() : break;
m_threshold(0.25f), case PointRender::typePoint_start:
m_recursionMax(10), SVG_VERBOSE(" [" << iii << "] Find Start " << listPoints[iii].m_pos);
m_subSamplingCount(8) { break;
case PointRender::typePoint_stop:
SVG_VERBOSE(" [" << iii << "] Find Stop " << listPoints[iii].m_pos);
break;
case PointRender::typePoint_interpolation:
SVG_VERBOSE(" [" << iii << "] Find interpolation " << listPoints[iii].m_pos);
break;
case PointRender::typePoint_join:
SVG_VERBOSE(" [" << iii << "] Find Join " << listPoints[iii].m_pos);
break;
} }
}
void addSegment(const PointRender& _pos0, const PointRender& _pos1) { }
// Skip horizontal Segments
if (_pos0.m_pos.y() == _pos1.m_pos.y()) { void interpolateCubicBezier(std::vector<PointRender>& _listPoint,
// remove /0 operation int32_t _recurtionMax,
return; float _threshold,
vec2 _pos1,
vec2 _pos2,
vec2 _pos3,
vec2 _pos4,
int32_t _level,
enum PointRender::typePoint _type) {
if (_level > _recurtionMax) {
return;
}
vec2 pos12 = (_pos1+_pos2)*0.5f;
vec2 pos23 = (_pos2+_pos3)*0.5f;
vec2 pos34 = (_pos3+_pos4)*0.5f;
vec2 delta = _pos4 - _pos1;
float distance2 = std::abs(((_pos2.x() - _pos4.x()) * delta.y() - (_pos2.y() - _pos4.y()) * delta.x() ));
float distance3 = std::abs(((_pos3.x() - _pos4.x()) * delta.y() - (_pos3.y() - _pos4.y()) * delta.x() ));
if ((distance2 + distance3)*(distance2 + distance3) < _threshold * delta.length2()) {
_listPoint.push_back(PointRender(_pos4, _type) );
return;
}
vec2 pos123 = (pos12+pos23)*0.5f;
vec2 pos234 = (pos23+pos34)*0.5f;
vec2 pos1234 = (pos123+pos234)*0.5f;
interpolateCubicBezier(_listPoint, _recurtionMax, _threshold, _pos1, pos12, pos123, pos1234, _level+1, PointRender::typePoint_interpolation);
interpolateCubicBezier(_listPoint, _recurtionMax, _threshold, pos1234, pos234, pos34, _pos4, _level+1, _type);
}
void addSegment(std::vector<Segment>& _seg, const PointRender& _pos0, const PointRender& _pos1) {
// Skip horizontal Segments
if (_pos0.m_pos.y() == _pos1.m_pos.y()) {
// remove /0 operation
return;
}
_seg.push_back(Segment(_pos0.m_pos, _pos1.m_pos));
}
std::vector<Segment> createSegmentList(const std::vector<PointRender>& _listPoint) {
std::vector<Segment> out;
// Build Segments
for (int32_t iii=0, jjj=_listPoint.size()-1;
iii < _listPoint.size();
jjj = iii++) {
addSegment(out, _listPoint[jjj], _listPoint[iii]);
}
// TODO : Check if it is really usefull ...
std::sort(out.begin(), out.end(), sortSegmentFunction);
return out;
}
std::vector<Segment> createSegmentListStroke(std::vector<PointRender>& _listPoint) {
std::vector<Segment> out;
// generate for every point all the orthogonal elements
// normal edge * end path
// * | * * * * * * * * * * * * * *
// * |<--*----this | *
// * | * this -->| *
// * * * | *
// * . | . * . . . . . . . . * *
// * . | . * | *
// * A . | . B * | *
// . * . | *
// . * * . * * * * * * * * * * * * *
// * *
// * *
// TODO : Start and stop of the path ...
for (int32_t idPevious=-1, idCurrent=0, idNext=1;
idCurrent < _listPoint.size();
idPevious++, idCurrent++, idNext++) {
if ( _listPoint[idCurrent].m_type == PointRender::typePoint_join
|| _listPoint[idCurrent].m_type == PointRender::typePoint_interpolation) {
if (idPevious < 0 ) {
SVG_ERROR("an error occure a previous ID is < 0.... ");
continue;
} }
m_listSegment.push_back(Segment(_pos0.m_pos, _pos1.m_pos)); if (idNext >= _listPoint.size()) {
SVG_ERROR("an error occure a next ID is >= nbPoint len .... ");
continue;
}
vec2 vecA = _listPoint[idCurrent].m_pos - _listPoint[idPevious].m_pos;
vecA.safeNormalize();
vec2 vecB = _listPoint[idNext].m_pos - _listPoint[idCurrent].m_pos;
vecB.safeNormalize();
vec2 vecC = vecA - vecB;
if (vecC == vec2(0,0)) {
// special case: 1 line ...
_listPoint[idCurrent].m_miterAxe = vec2(vecA.y(), vecA.x());
} else {
vecC.safeNormalize();
_listPoint[idCurrent].m_miterAxe = vecC;
}
} else if (_listPoint[idCurrent].m_type == PointRender::typePoint_start) {
vec2 vecB = _listPoint[idNext].m_pos - _listPoint[idCurrent].m_pos;
vecB.safeNormalize();
_listPoint[idCurrent].m_miterAxe = vec2(vecB.y(), vecB.x());
} else if (_listPoint[idCurrent].m_type == PointRender::typePoint_stop) {
if (idPevious < 0 ) {
SVG_ERROR("an error occure a previous ID is < 0.... ");
continue;
}
vec2 vecA = _listPoint[idCurrent].m_pos - _listPoint[idPevious].m_pos;
vecA.safeNormalize();
_listPoint[idCurrent].m_miterAxe = vec2(vecA.y(), vecA.x());
} else {
SVG_TODO("lklklklklkl");
} }
}
void flattenCubicBez(vec2 _pos1, float lineWidth = 5.0f;
vec2 _pos2, // create segment list:
vec2 _pos3, bool haveStartLine;
vec2 _pos4, vec2 leftPoint;
int32_t _level, vec2 rightPoint;
enum PointRender::typePoint _type) { for (int32_t iii=0;
if (_level > m_recursionMax) { iii < _listPoint.size();
return; ++iii) {
} switch (_listPoint[iii].m_type) {
vec2 pos12 = (_pos1+_pos2)*0.5f; case PointRender::typePoint_single:
vec2 pos23 = (_pos2+_pos3)*0.5f; // just do nothing ....
vec2 pos34 = (_pos3+_pos4)*0.5f; SVG_VERBOSE("[" << iii << "] Find Single " << _listPoint[iii].m_pos);
break;
vec2 delta = _pos4 - _pos1; case PointRender::typePoint_start:
float distance2 = std::abs(((_pos2.x() - _pos4.x()) * delta.y() - (_pos2.y() - _pos4.y()) * delta.x() )); {
float distance3 = std::abs(((_pos3.x() - _pos4.x()) * delta.y() - (_pos3.y() - _pos4.y()) * delta.x() )); SVG_VERBOSE("[" << iii << "] Find Start " << _listPoint[iii].m_pos);
if (haveStartLine == true) {
if ((distance2 + distance3)*(distance2 + distance3) < m_threshold * delta.length2()) { // close previous :
m_listPoints.push_back(PointRender(_pos4, _type) ); SVG_WARNING(" find a non close path ...");
return; addSegment(out, leftPoint, rightPoint);
} }
vec2 pos123 = (pos12+pos23)*0.5f; haveStartLine = true;
vec2 pos234 = (pos23+pos34)*0.5f; // TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 pos1234 = (pos123+pos234)*0.5f; leftPoint = _listPoint[iii].m_pos
+ _listPoint[iii].m_miterAxe*lineWidth*0.5f;
flattenCubicBez(_pos1, pos12, pos123, pos1234, _level+1, PointRender::typePoint_interpolation); rightPoint = _listPoint[iii].m_pos
flattenCubicBez(pos1234, pos234, pos34, _pos4, _level+1, _type); - _listPoint[iii].m_miterAxe*lineWidth*0.5f;
addSegment(out, leftPoint, rightPoint);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << rightPoint);
}
break;
case PointRender::typePoint_stop:
{
SVG_VERBOSE("[" << iii << "] Find Stop " << _listPoint[iii].m_pos);
if (haveStartLine == true) {
SVG_WARNING("find close path without start part ...");
break;
}
haveStartLine = false;
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = _listPoint[iii].m_pos
+ _listPoint[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = _listPoint[iii].m_pos
- _listPoint[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(out, leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(out, right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
// end line ...
addSegment(out, rightPoint, leftPoint);
SVG_VERBOSE(" segment :" << rightPoint << " -> " << leftPoint);
}
break;
case PointRender::typePoint_interpolation:
{
SVG_VERBOSE("[" << iii << "] Find interpolation " << _listPoint[iii].m_pos);
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = _listPoint[iii].m_pos
+ _listPoint[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = _listPoint[iii].m_pos
- _listPoint[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(out, leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(out, right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
}
break;
case PointRender::typePoint_join:
{
SVG_VERBOSE("[" << iii << "] Find Join " << _listPoint[iii].m_pos);
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = _listPoint[iii].m_pos
+ _listPoint[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = _listPoint[iii].m_pos
- _listPoint[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(out, leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(out, right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
}
break;
} }
}
void flattenShape(const esvg::RenderPath& _path, const mat2& _matrix) { // TODO : Check if it is really usefull ...
// Flatten path std::sort(out.begin(), out.end(), sortSegmentFunction);
m_listPoints.push_back(PointRender(_path.m_points[0], PointRender::typePoint_join)); return out;
for (int32_t iii=0; }
iii<_path.m_points.size()-1;
iii+=3) {
flattenCubicBez(_path.m_points[iii+0], _path.m_points[iii+1], _path.m_points[iii+2], _path.m_points[iii+3], 0, PointRender::typePoint_interpolation); Weighter createWeighter(ivec2 _size, int32_t _subSamplingCount, const std::vector<Segment>& _listSegment) {
} Weighter out(_size);
// Close path (all time in a background element) // for each lines:
m_listPoints.push_back(PointRender(_path.m_points[0], PointRender::typePoint_join)); for (int32_t yyy=0; yyy<_size.y(); ++yyy) {
// Build Segments // Reduce the number of lines in the subsampling parsing:
for (int32_t iii=0, jjj=m_listPoints.size()-1; std::vector<Segment> availlableSegmentPixel;
iii < m_listPoints.size(); for (auto &it : _listSegment) {
jjj = iii++) { if ( it.p0.y() <= float(yyy+1)
addSegment(m_listPoints[jjj], m_listPoints[iii]); && it.p1.y() >= float(yyy)) {
availlableSegmentPixel.push_back(it);
} }
} }
// This represent the pondaration on the subSampling
void flattenShapeStroke(const esvg::RenderPath& _path, const mat2& _matrix) { float deltaSize = 1.0f/_subSamplingCount;
// Flatten path for (int32_t kkk=0; kkk<_subSamplingCount ; ++kkk) {
m_listPoints.push_back(PointRender(_path.m_points[0], PointRender::typePoint_start)); Scanline scanline(_size.x());
for (int32_t iii=0; //find all the segment that cross the middle of the line of the center of the pixel line:
iii<_path.m_points.size()-1; float subSamplingCenterPos = yyy + deltaSize*0.5f + deltaSize*kkk;
iii+=3) { std::vector<Segment> availlableSegment;
flattenCubicBez(_path.m_points[iii+0], _path.m_points[iii+1], _path.m_points[iii+2], _path.m_points[iii+3], 0, PointRender::typePoint_join); // find in the subList ...
for (auto &it : availlableSegmentPixel) {
if ( it.p0.y() <= subSamplingCenterPos
&& it.p1.y() >= subSamplingCenterPos) {
availlableSegment.push_back(it);
}
} }
// When we stroke , We need to have a minimum of 2 points: // x position, angle
if (_path.m_points.size() < 2) { std::vector<std::pair<float, float>> listPosition;
// no stroke ... for (auto &it : availlableSegment) {
return; 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<float,float>(xpos, it.direction));
} }
// generate for every point all the orthogonal elements // now we order position of the xPosition:
// normal edge * end path std::sort(listPosition.begin(), listPosition.end(), sortXPosFunction);
// * | * * * * * * * * * * * * * * // move through all element in the point:
// * |<--*----this | * float lastState = 0.0f;
// * | * this -->| * float currentValue = 0.0f;
// * * * | * int32_t lastPos = -1;
// * . | . * . . . . . . . . * * int32_t currentPos = -1;
// * . | . * | * float lastX = 0.0f;
// * A . | . B * | * // * | \---------------/ |
// . * . | * // * current pos
// . * * . * * * * * * * * * * * * * // * pos ...
// * * // TODO : Code the Odd/even and non-zero ...
// * * for (auto &it : listPosition) {
// TODO : Start and stop of the path ... if (currentPos != int32_t(it.first)) {
for (int32_t idPevious=-1, idCurrent=0, idNext=1; // fill to the new pos -1:
idCurrent < m_listPoints.size(); float endValue = std::min(1.0f,std::abs(lastState)) * deltaSize;
idPevious++, idCurrent++, idNext++) { for (int32_t iii=currentPos+1; iii<int32_t(it.first); ++iii) {
if ( m_listPoints[idCurrent].m_type == PointRender::typePoint_join scanline.set(iii, endValue);
|| m_listPoints[idCurrent].m_type == PointRender::typePoint_interpolation) {
if (idPevious < 0 ) {
SVG_ERROR("an error occure a previous ID is < 0.... ");
continue;
} }
if (idNext >= m_listPoints.size()) { currentPos = int32_t(it.first);
SVG_ERROR("an error occure a next ID is >= nbPoint len .... "); currentValue = endValue;
continue; }
} float oldState = lastState;
vec2 vecA = m_listPoints[idCurrent].m_pos - m_listPoints[idPevious].m_pos; lastState += it.second;
vecA.safeNormalize(); if (oldState == 0.0f) {
vec2 vecB = m_listPoints[idNext].m_pos - m_listPoints[idCurrent].m_pos; // nothing to draw before ...
vecB.safeNormalize(); float ratio = 1.0f - (it.first - float(int32_t(it.first)));
vec2 vecC = vecA - vecB; currentValue += ratio * deltaSize;
if (vecC == vec2(0,0)) { } else if (lastState == 0.0f) {
// special case: 1 line ... // something new to draw ...
m_listPoints[idCurrent].m_miterAxe = vec2(vecA.y(), vecA.x()); float ratio = 1.0f - (it.first - float(int32_t(it.first)));
} else { currentValue -= ratio * deltaSize;
vecC.safeNormalize();
m_listPoints[idCurrent].m_miterAxe = vecC;
}
} else if (m_listPoints[idCurrent].m_type == PointRender::typePoint_start) {
vec2 vecB = m_listPoints[idNext].m_pos - m_listPoints[idCurrent].m_pos;
vecB.safeNormalize();
m_listPoints[idCurrent].m_miterAxe = vec2(vecB.y(), vecB.x());
} else if (m_listPoints[idCurrent].m_type == PointRender::typePoint_stop) {
if (idPevious < 0 ) {
SVG_ERROR("an error occure a previous ID is < 0.... ");
continue;
}
vec2 vecA = m_listPoints[idCurrent].m_pos - m_listPoints[idPevious].m_pos;
vecA.safeNormalize();
m_listPoints[idCurrent].m_miterAxe = vec2(vecA.y(), vecA.x());
} else { } else {
SVG_TODO("lklklklklkl"); // nothing to do ...
} }
}
float lineWidth = 5.0f; if (currentPos == int32_t(it.first)) {
// create segment list: scanline.set(currentPos, currentValue);
bool haveStartLine;
vec2 leftPoint;
vec2 rightPoint;
for (int32_t iii=0;
iii < m_listPoints.size();
++iii) {
switch (m_listPoints[iii].m_type) {
case PointRender::typePoint_single:
// just do nothing ....
SVG_VERBOSE("[" << iii << "] Find Single " << m_listPoints[iii].m_pos);
break;
case PointRender::typePoint_start:
{
SVG_VERBOSE("[" << iii << "] Find Start " << m_listPoints[iii].m_pos);
if (haveStartLine == true) {
// close previous :
SVG_WARNING(" find a non close path ...");
addSegment(leftPoint, rightPoint);
}
haveStartLine = true;
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
leftPoint = m_listPoints[iii].m_pos
+ m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
rightPoint = m_listPoints[iii].m_pos
- m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
addSegment(leftPoint, rightPoint);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << rightPoint);
}
break;
case PointRender::typePoint_stop:
{
SVG_VERBOSE("[" << iii << "] Find Stop " << m_listPoints[iii].m_pos);
if (haveStartLine == true) {
SVG_WARNING("find close path without start part ...");
break;
}
haveStartLine = false;
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = m_listPoints[iii].m_pos
+ m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = m_listPoints[iii].m_pos
- m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
// end line ...
addSegment(rightPoint, leftPoint);
SVG_VERBOSE(" segment :" << rightPoint << " -> " << leftPoint);
}
break;
case PointRender::typePoint_interpolation:
{
SVG_VERBOSE("[" << iii << "] Find interpolation " << m_listPoints[iii].m_pos);
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = m_listPoints[iii].m_pos
+ m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = m_listPoints[iii].m_pos
- m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
}
break;
case PointRender::typePoint_join:
{
SVG_VERBOSE("[" << iii << "] Find Join " << m_listPoints[iii].m_pos);
// TODO : Calculate intersection ... (now we do a simple fast test of path display ...)
vec2 left = m_listPoints[iii].m_pos
+ m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
vec2 right = m_listPoints[iii].m_pos
- m_listPoints[iii].m_miterAxe*lineWidth*0.5f;
//Draw from previous point:
addSegment(leftPoint, left);
SVG_VERBOSE(" segment :" << leftPoint << " -> " << left);
addSegment(right, rightPoint);
SVG_VERBOSE(" segment :" << right << " -> " << rightPoint);
leftPoint = left;
rightPoint = right;
}
break;
} }
} }
out.append(yyy, scanline);
} }
}
void sortSegment() { return out;
std::sort(m_listSegment.begin(), m_listSegment.end(), sortSegmentFunction); }
}
Weighter createWeighter(ivec2 _size) {
Weighter out(_size);
// for each lines:
for (int32_t yyy=0; yyy<_size.y(); ++yyy) {
// Reduce the number of lines in the subsampling parsing:
std::vector<Segment> availlableSegmentPixel;
for (auto &it : m_listSegment) {
if ( it.p0.y() <= float(yyy+1)
&& it.p1.y() >= float(yyy)) {
availlableSegmentPixel.push_back(it);
}
}
// This represent the pondaration on the subSampling
float deltaSize = 1.0f/m_subSamplingCount;
for (int32_t kkk=0; kkk<m_subSamplingCount ; ++kkk) {
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;
std::vector<Segment> availlableSegment;
// find in the subList ...
for (auto &it : availlableSegmentPixel) {
if ( it.p0.y() <= subSamplingCenterPos
&& it.p1.y() >= subSamplingCenterPos) {
availlableSegment.push_back(it);
}
}
// x position, angle
std::vector<std::pair<float, float>> 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<float,float>(xpos, it.direction));
}
// 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;
float currentValue = 0.0f;
int32_t lastPos = -1;
int32_t currentPos = -1;
float lastX = 0.0f;
// * | \---------------/ |
// * current pos
// * pos ...
// TODO : Code the Odd/even and non-zero ...
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;
for (int32_t iii=currentPos+1; iii<int32_t(it.first); ++iii) {
scanline.set(iii, endValue);
}
currentPos = int32_t(it.first);
currentValue = endValue;
}
float oldState = lastState;
lastState += it.second;
if (oldState == 0.0f) {
// nothing to draw before ...
float ratio = 1.0f - (it.first - float(int32_t(it.first)));
currentValue += ratio * deltaSize;
} else if (lastState == 0.0f) {
// something new to draw ...
float ratio = 1.0f - (it.first - float(int32_t(it.first)));
currentValue -= ratio * deltaSize;
} else {
// nothing to do ...
}
if (currentPos == int32_t(it.first)) {
scanline.set(currentPos, currentValue);
}
}
out.append(yyy, scanline);
}
}
return out;
}
};
void esvg::Path::aggDraw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) { void esvg::Path::aggDraw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
SVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Path"); SVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Path");
esvg::RenderPath path; vec2 lastPosition(0.0f, 0.0f);
path.clear(); std::vector<PointRender> listPoints;
int32_t lastPointId = -1;
bool PathStart = false;
int32_t recurtionMax = 10;
float threshold = 0.25f;
// Foreach element, we move in the path:
for(int32_t iii=0; iii<m_listElement.size(); iii++) { for(int32_t iii=0; iii<m_listElement.size(); iii++) {
switch (m_listElement[iii].m_cmd) { switch (m_listElement[iii].m_cmd) {
case esvg::path_stop: case esvg::path_stop:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_stop"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_stop");
path.stop(); // TODO : Check if the z value mean that the path will cycle ...
if (listPoints.size() != 0) {
if (PathStart == false) {
SVG_WARNING(spacingDist(_level+1) << "[" << iii << "] Request path stop of not starting path ...");
} else {
listPoints.back().setEndPath();
PathStart = false;
}
}
// nothing alse to do ...
break; break;
case esvg::path_moveTo: case esvg::path_moveTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_moveTo"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_moveTo");
path.moveTo(m_listElement[iii].m_relative, // stop last path
vec2(m_listElement[iii].m_element[0], if (listPoints.size() != 0) {
m_listElement[iii].m_element[1]) ); if (PathStart == true) {
listPoints.back().setEndPath();
PathStart = false;
}
}
PathStart = true;
// create a new one
if (m_listElement[iii].m_relative == false) {
lastPosition = vec2(0.0f, 0.0f);
}
lastPosition += vec2(m_listElement[iii].m_element[0], m_listElement[iii].m_element[1]);
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_start));
break; break;
case esvg::path_lineTo: case esvg::path_lineTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_lineTo"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_lineTo");
path.lineTo(m_listElement[iii].m_relative, // If no previous point, we need to create the last point has start ...
vec2(m_listElement[iii].m_element[0], if (PathStart == false) {
m_listElement[iii].m_element[1]) ); listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_join));
PathStart = true;
}
if (m_listElement[iii].m_relative == false) {
lastPosition = vec2(0.0f, 0.0f);
}
lastPosition += vec2(m_listElement[iii].m_element[0], m_listElement[iii].m_element[1]);
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_start));
break; break;
case esvg::path_lineToH: case esvg::path_lineToH:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_lineToH"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_lineToH");
path.lineTo(m_listElement[iii].m_relative, // If no previous point, we need to create the last point has start ...
vec2(m_listElement[iii].m_element[0], 0.0f) ); if (PathStart == false) {
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_join));
PathStart = true;
}
if (m_listElement[iii].m_relative == false) {
lastPosition = vec2(0.0f, 0.0f);
}
lastPosition += vec2(m_listElement[iii].m_element[0], 0.0f);
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_start));
break; break;
case esvg::path_lineToV: case esvg::path_lineToV:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_lineToV"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_lineToV");
path.lineTo(m_listElement[iii].m_relative, // If no previous point, we need to create the last point has start ...
vec2(0.0f, m_listElement[iii].m_element[0]) ); if (PathStart == false) {
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_join));
PathStart = true;
}
if (m_listElement[iii].m_relative == false) {
lastPosition = vec2(0.0f, 0.0f);
}
lastPosition += vec2(0.0, m_listElement[iii].m_element[1]);
listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_start));
break; break;
case esvg::path_curveTo: case esvg::path_curveTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_curveTo"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_curveTo");
path.curve4To(m_listElement[iii].m_relative, // If no previous point, we need to create the last point has start ...
vec2(m_listElement[iii].m_element[0], if (PathStart == false) {
m_listElement[iii].m_element[1]), listPoints.push_back(PointRender(lastPosition, PointRender::typePoint_join));
vec2(m_listElement[iii].m_element[2], PathStart = true;
m_listElement[iii].m_element[3]), }
vec2(m_listElement[iii].m_element[4], {
m_listElement[iii].m_element[5]) ); vec2 lastPosStore(lastPosition);
if (m_listElement[iii].m_relative == false) {
lastPosition = vec2(0.0f, 0.0f);
}
vec2 pos1 = lastPosition + vec2(m_listElement[iii].m_element[0], m_listElement[iii].m_element[1]);
vec2 pos2 = lastPosition + vec2(m_listElement[iii].m_element[2], m_listElement[iii].m_element[3]);
vec2 pos = lastPosition + vec2(m_listElement[iii].m_element[4], m_listElement[iii].m_element[5]);
interpolateCubicBezier(listPoints,
recurtionMax,
threshold,
lastPosStore,
pos1,
pos2,
pos,
0,
PointRender::typePoint_join);
lastPosition = pos;
}
break; break;
case esvg::path_smothCurveTo: case esvg::path_smothCurveTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_smothCurveTo"); SVG_TODO(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_smothCurveTo");
/*
path.curve4SmoothTo(m_listElement[iii].m_relative, path.curve4SmoothTo(m_listElement[iii].m_relative,
vec2(m_listElement[iii].m_element[0], vec2(m_listElement[iii].m_element[0],
m_listElement[iii].m_element[1]), m_listElement[iii].m_element[1]),
vec2(m_listElement[iii].m_element[2], vec2(m_listElement[iii].m_element[2],
m_listElement[iii].m_element[3]) ); m_listElement[iii].m_element[3]) );
*/
break; break;
case esvg::path_bezierCurveTo: case esvg::path_bezierCurveTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_bezierCurveTo"); SVG_TODO(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_bezierCurveTo");
/*
path.curve3To(m_listElement[iii].m_relative, path.curve3To(m_listElement[iii].m_relative,
vec2(m_listElement[iii].m_element[0], vec2(m_listElement[iii].m_element[0],
m_listElement[iii].m_element[1]), m_listElement[iii].m_element[1]),
vec2(m_listElement[iii].m_element[2], vec2(m_listElement[iii].m_element[2],
m_listElement[iii].m_element[3]) ); m_listElement[iii].m_element[3]) );
*/
break; break;
case esvg::path_bezierSmothCurveTo: case esvg::path_bezierSmothCurveTo:
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_bezierSmothCurveTo"); SVG_TODO(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_bezierSmothCurveTo");
/*
path.curve3SmoothTo(m_listElement[iii].m_relative, path.curve3SmoothTo(m_listElement[iii].m_relative,
vec2(m_listElement[iii].m_element[0], vec2(m_listElement[iii].m_element[0],
m_listElement[iii].m_element[1]) ); m_listElement[iii].m_element[1]) );
*/
break; break;
case esvg::path_elliptic: case esvg::path_elliptic:
/* /*
SVG_VERBOSE(spacingDist(_level+1) << "Draw : esvg::path_elliptic"); SVG_VERBOSE(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_elliptic");
path.ellipticTo(m_listElement[iii].m_relative, path.ellipticTo(m_listElement[iii].m_relative,
m_listElement[iii].m_element[0], m_listElement[iii].m_element[0],
m_listElement[iii].m_element[1], m_listElement[iii].m_element[1],
@ -886,38 +972,33 @@ void esvg::Path::aggDraw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
m_listElement[iii].m_element[5], m_listElement[iii].m_element[5],
m_listElement[iii].m_element[6] ); m_listElement[iii].m_element[6] );
*/ */
SVG_TODO(spacingDist(_level+1) << "Draw : esvg::path_elliptic"); SVG_TODO(spacingDist(_level+1) << "[" << iii << "] Draw : esvg::path_elliptic");
break; break;
default: default:
SVG_ERROR("Unknow PATH commant (internal error)"); SVG_ERROR(spacingDist(_level+1) << "[" << iii << "] Unknow PATH commant (internal error)");
break; break;
} }
} }
diplayRenderPoints(listPoints);
mat2 mtx = m_transformMatrix; mat2 mtx = m_transformMatrix;
mtx *= _basicTrans; mtx *= _basicTrans;
path.display();
Weighter tmpFill; Weighter tmpFill;
Weighter tmpStroke; Weighter tmpStroke;
//agg::conv_curve<esvg::RenderPath> curve(path);
// Check if we need to display background // Check if we need to display background
int32_t nbSubScanLine = 8;
if (m_paint.fill.a() != 0x00) { if (m_paint.fill.a() != 0x00) {
Transformation ttt;
ttt.flattenShape(path, mtx); std::vector<Segment> listSegment = createSegmentList(listPoints);
// Rasterize Segments
ttt.sortSegment();
// now, traverse the scanlines and find the intersections on each scanline, use non-zero rule // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
tmpFill = ttt.createWeighter(ivec2(128,128)); tmpFill = createWeighter(ivec2(128,128), nbSubScanLine, listSegment);
} }
// check if we need to display stroke: // check if we need to display stroke:
if ( m_paint.strokeWidth > 0 if ( m_paint.strokeWidth > 0
&& m_paint.stroke.a() != 0x00) { && m_paint.stroke.a() != 0x00) {
Transformation ttt; std::vector<Segment> listSegment = createSegmentListStroke(listPoints);
ttt.flattenShapeStroke(path, mtx);
// Rasterize Segments
ttt.sortSegment();
// now, traverse the scanlines and find the intersections on each scanline, use non-zero rule // now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
tmpStroke = ttt.createWeighter(ivec2(128,128)); tmpStroke = createWeighter(ivec2(128,128), nbSubScanLine, listSegment);
} }
// add on images: // add on images:
for (int32_t yyy=0; yyy<_myRenderer.m_size.y(); ++yyy) { for (int32_t yyy=0; yyy<_myRenderer.m_size.y(); ++yyy) {

View File

@ -11,21 +11,22 @@
TEST(TestPath, basicTest) { TEST(TestPath, basicTest) {
esvg::Document doc; esvg::Document doc;
/* #if 0
doc.parse( "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" doc.parse( "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg width='64' height='64'>" "<svg width='64' height='64'>"
" <g transform='matrix(1.2,0,0,1.2,-579.7336,-567.9832)'>" " <g transform='matrix(1.2,0,0,1.2,-579.7336,-567.9832)'>"
" <path d='m 50,50 c -12.426,0 -22.5,10.072 -22.5,22.5 0,12.426 10.074,22.5 22.5,22.5 12.428,0 22.5,-10.074 22.5,-22.5 0,-12.427 -10.072,-22.5 -22.5,-22.5 z'" " <path d='m 50,50 c -12.426,0 -22.5,10.072 -22.5,22.5 0,12.426 10.074,22.5 22.5,22.5 12.428,0 22.5,-10.074 22.5,-22.5 0,-12.427 -10.072,-22.5 -22.5,-22.5 z'"
" style='fill:#333333;fill-rule:evenodd' />" " style='fill:#F00;fill-rule:evenodd;stroke:#0000' />"
" </g>" " </g>"
"</svg>"); "</svg>");
*/ #else
doc.parse( "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" doc.parse( "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
"<svg width='64' height='64'>" "<svg width='64' height='64'>"
" <g transform='matrix(1.2,0,0,1.2,-579.7336,-567.9832)'>" " <g transform='matrix(1.2,0,0,1.2,-579.7336,-567.9832)'>"
" <path d='m 50,50 c -12.426,0 -22.5,10.072 -22.5,22.5 0,12.426 10.074,22.5 22.5,22.5 12.428,0 22.5,-10.074 22.5,-22.5 0,-12.427 -10.072,-22.5 -22.5,-22.5 z'" " <path d='m 50,50 c -12.426,0 -22.5,10.072 -22.5,22.5 0,12.426 10.074,22.5 22.5,22.5 12.428,0 22.5,-10.074 22.5,-22.5 0,-12.427 -10.072,-22.5 -22.5,-22.5 z'"
" style='stroke:#00F;stroke-width:5;fill-rule:evenodd' />" " style='fill:#000;stroke:#00F;stroke-width:5;fill-rule:evenodd' />"
" </g>" " </g>"
"</svg>"); "</svg>");
#endif
doc.generateAnImage(128, 128); doc.generateAnImage(128, 128);
} }