[DEV] try to have a line generator

This commit is contained in:
Edouard DUPIN 2016-08-21 22:50:29 +02:00
parent a9297c4cb1
commit 68e67dfde3
22 changed files with 426 additions and 120 deletions

View File

@ -430,3 +430,12 @@ void esvg::Base::setId(const std::string& _newId) {
m_id = _newId;
}
void esvg::Base::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
}

View File

@ -17,6 +17,7 @@
#include <etk/math/Vector2D.h>
#include <etk/math/Matrix2.h>
#include <etk/Color.h>
#include <esvg/render/Path.h>
#include <exml/exml.h>
#include <esvg/Renderer.h>
@ -65,8 +66,26 @@ namespace esvg {
* @return true if no problem arrived
*/
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
/**
* @brief Draw the form in the renderer
* @param[in] _myRenderer Renderer engine
* @param[in] _basicTrans Parant transformation of the environement
* @param[in] _level Level of the tree
*/
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level=1);
/**
* @brief Draw rhe shape with all points
* @param[in] _out where the lines are added
* @param[in] _recurtionMax interpolation recurtion max
* @param[in] _threshold threshold to stop recurtion
* @param[in] _basicTrans Parant transformation of the environement
* @param[in] _level Level of the tree
*/
virtual void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1);
virtual void display(int32_t _spacing) { };
void parseTransform(const exml::Element& _element);

View File

@ -59,6 +59,30 @@ void esvg::Circle::display(int32_t _spacing) {
ESVG_DEBUG(spacingDist(_spacing) << "Circle " << m_position << " radius=" << m_radius);
}
esvg::render::Path esvg::Circle::createPath() {
esvg::render::Path out;
out.clear();
out.moveTo(false, m_position + vec2(m_radius, 0.0f));
out.curveTo(false,
m_position + vec2(m_radius, m_radius*esvg::kappa90),
m_position + vec2(m_radius*esvg::kappa90, m_radius),
m_position + vec2(0.0f, m_radius));
out.curveTo(false,
m_position + vec2(-m_radius*esvg::kappa90, m_radius),
m_position + vec2(-m_radius, m_radius*esvg::kappa90),
m_position + vec2(-m_radius, 0.0f));
out.curveTo(false,
m_position + vec2(-m_radius, -m_radius*esvg::kappa90),
m_position + vec2(-m_radius*esvg::kappa90, -m_radius),
m_position + vec2(0.0f, -m_radius));
out.curveTo(false,
m_position + vec2(m_radius*esvg::kappa90, -m_radius),
m_position + vec2(m_radius, -m_radius*esvg::kappa90),
m_position + vec2(m_radius, 0.0f));
out.close();
return out;
}
void esvg::Circle::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Circle");
@ -66,26 +90,7 @@ void esvg::Circle::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
ESVG_VERBOSE(spacingDist(_level+1) << "Too small radius" << m_radius);
return;
}
esvg::render::Path listElement;
listElement.clear();
listElement.moveTo(false, m_position + vec2(m_radius, 0.0f));
listElement.curveTo(false,
m_position + vec2(m_radius, m_radius*esvg::kappa90),
m_position + vec2(m_radius*esvg::kappa90, m_radius),
m_position + vec2(0.0f, m_radius));
listElement.curveTo(false,
m_position + vec2(-m_radius*esvg::kappa90, m_radius),
m_position + vec2(-m_radius, m_radius*esvg::kappa90),
m_position + vec2(-m_radius, 0.0f));
listElement.curveTo(false,
m_position + vec2(-m_radius, -m_radius*esvg::kappa90),
m_position + vec2(-m_radius*esvg::kappa90, -m_radius),
m_position + vec2(0.0f, -m_radius));
listElement.curveTo(false,
m_position + vec2(m_radius*esvg::kappa90, -m_radius),
m_position + vec2(m_radius, -m_radius*esvg::kappa90),
m_position + vec2(m_radius, 0.0f));
listElement.close();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -140,3 +145,23 @@ void esvg::Circle::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
#endif
}
void esvg::Circle::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Circle");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -17,9 +17,16 @@ namespace esvg {
public:
Circle(PaintState _parentPaintState);
~Circle();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -64,6 +64,30 @@ void esvg::Ellipse::display(int32_t _spacing) {
}
esvg::render::Path esvg::Ellipse::createPath() {
esvg::render::Path out;
out.clear();
out.moveTo(false, m_c + vec2(m_r.x(), 0.0f));
out.curveTo(false,
m_c + vec2(m_r.x(), m_r.y()*esvg::kappa90),
m_c + vec2(m_r.x()*esvg::kappa90, m_r.y()),
m_c + vec2(0.0f, m_r.y()));
out.curveTo(false,
m_c + vec2(-m_r.x()*esvg::kappa90, m_r.y()),
m_c + vec2(-m_r.x(), m_r.y()*esvg::kappa90),
m_c + vec2(-m_r.x(), 0.0f));
out.curveTo(false,
m_c + vec2(-m_r.x(), -m_r.y()*esvg::kappa90),
m_c + vec2(-m_r.x()*esvg::kappa90, -m_r.y()),
m_c + vec2(0.0f, -m_r.y()));
out.curveTo(false,
m_c + vec2(m_r.x()*esvg::kappa90, -m_r.y()),
m_c + vec2(m_r.x(), -m_r.y()*esvg::kappa90),
m_c + vec2(m_r.x(), 0.0f));
out.close();
return out;
}
void esvg::Ellipse::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Ellipse");
if ( m_r.x()<=0.0f
@ -71,26 +95,7 @@ void esvg::Ellipse::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
ESVG_VERBOSE(spacingDist(_level+1) << "Too small radius" << m_r);
return;
}
esvg::render::Path listElement;
listElement.clear();
listElement.moveTo(false, m_c + vec2(m_r.x(), 0.0f));
listElement.curveTo(false,
m_c + vec2(m_r.x(), m_r.y()*esvg::kappa90),
m_c + vec2(m_r.x()*esvg::kappa90, m_r.y()),
m_c + vec2(0.0f, m_r.y()));
listElement.curveTo(false,
m_c + vec2(-m_r.x()*esvg::kappa90, m_r.y()),
m_c + vec2(-m_r.x(), m_r.y()*esvg::kappa90),
m_c + vec2(-m_r.x(), 0.0f));
listElement.curveTo(false,
m_c + vec2(-m_r.x(), -m_r.y()*esvg::kappa90),
m_c + vec2(-m_r.x()*esvg::kappa90, -m_r.y()),
m_c + vec2(0.0f, -m_r.y()));
listElement.curveTo(false,
m_c + vec2(m_r.x()*esvg::kappa90, -m_r.y()),
m_c + vec2(m_r.x(), -m_r.y()*esvg::kappa90),
m_c + vec2(m_r.x(), 0.0f));
listElement.close();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -146,3 +151,23 @@ void esvg::Ellipse::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
}
void esvg::Ellipse::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Ellipse");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -17,9 +17,16 @@ namespace esvg {
public:
Ellipse(PaintState _parentPaintState);
~Ellipse();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -99,9 +99,9 @@ void esvg::Group::display(int32_t _spacing) {
ESVG_DEBUG(spacingDist(_spacing) << "Group (START) fill=" << m_paint.fill.first << "/" << m_paint.fill.second
<< " stroke=" << m_paint.stroke.first << "/" << m_paint.stroke.second
<< " stroke-width=" << m_paint.strokeWidth );
for (size_t iii=0; iii<m_subElementList.size(); ++iii) {
if (m_subElementList[iii] != nullptr) {
m_subElementList[iii]->display(_spacing+1);
for (auto &it : m_subElementList) {
if (it != nullptr) {
it->display(_spacing+1);
}
}
ESVG_DEBUG(spacingDist(_spacing) << "Group (STOP)");
@ -109,9 +109,22 @@ void esvg::Group::display(int32_t _spacing) {
void esvg::Group::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::group");
for (size_t iii=0; iii<m_subElementList.size(); ++iii) {
if (m_subElementList[iii] != nullptr) {
m_subElementList[iii]->draw(_myRenderer, _basicTrans, _level+1);
for (auto &it : m_subElementList) {
if (it != nullptr) {
it->draw(_myRenderer, _basicTrans, _level+1);
}
}
}
void esvg::Group::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW shape esvg::group");
for (auto &it : m_subElementList) {
if (it != nullptr) {
it->drawShapePoints(_out, _recurtionMax, _threshold, _basicTrans, _level+1);
}
}
}

View File

@ -17,9 +17,14 @@ namespace esvg {
public:
Group(PaintState _parentPaintState);
~Group();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
};
}

View File

@ -57,14 +57,19 @@ void esvg::Line::display(int32_t _spacing) {
ESVG_DEBUG(spacingDist(_spacing) << "Line " << m_startPos << " to " << m_stopPos);
}
esvg::render::Path esvg::Line::createPath() {
esvg::render::Path out;
out.clear();
out.moveTo(false, m_startPos);
out.lineTo(false, m_stopPos);
out.stop();
return out;
}
void esvg::Line::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Line");
esvg::render::Path listElement;
listElement.clear();
listElement.moveTo(false, m_startPos);
listElement.lineTo(false, m_stopPos);
listElement.stop();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -113,3 +118,23 @@ void esvg::Line::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _l
}
void esvg::Line::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Line");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -17,9 +17,16 @@ namespace esvg {
public:
Line(PaintState _parentPaintState);
~Line();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -326,3 +326,27 @@ void esvg::Path::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _l
#endif
}
void esvg::Path::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Path");
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = m_listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
ESVG_CRITICAL("add list... " << it.size() << " / " << m_listElement.m_listElement.size());
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -17,9 +17,14 @@ namespace esvg {
public:
Path(PaintState _parentPaintState);
~Path();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
};
}

View File

@ -63,15 +63,20 @@ void esvg::Polygon::display(int32_t _spacing) {
ESVG_DEBUG(spacingDist(_spacing) << "Polygon nbPoint=" << m_listPoint.size());
}
esvg::render::Path esvg::Polygon::createPath() {
esvg::render::Path out;
out.moveTo(false, m_listPoint[0]);
for( int32_t iii=1; iii< m_listPoint.size(); iii++) {
out.lineTo(false, m_listPoint[iii]);
}
out.close();
return out;
}
void esvg::Polygon::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Polygon");
esvg::render::Path listElement;
listElement.moveTo(false, m_listPoint[0]);
for( int32_t iii=1; iii< m_listPoint.size(); iii++) {
listElement.lineTo(false, m_listPoint[iii]);
}
listElement.close();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -126,3 +131,24 @@ void esvg::Polygon::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t
#endif
}
void esvg::Polygon::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Polygon");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -24,9 +24,16 @@ namespace esvg {
public:
Polygon(PaintState parentPaintState);
~Polygon();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -59,16 +59,21 @@ void esvg::Polyline::display(int32_t _spacing) {
}
esvg::render::Path esvg::Polyline::createPath() {
esvg::render::Path out;
out.clear();
out.moveTo(false, m_listPoint[0]);
for( int32_t iii=1; iii< m_listPoint.size(); iii++) {
out.lineTo(false, m_listPoint[iii]);
}
out.stop();
return out;
}
void esvg::Polyline::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Polyline");
esvg::render::Path listElement;
listElement.clear();
listElement.moveTo(false, m_listPoint[0]);
for( int32_t iii=1; iii< m_listPoint.size(); iii++) {
listElement.lineTo(false, m_listPoint[iii]);
}
listElement.stop();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -124,3 +129,22 @@ void esvg::Polyline::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_
}
void esvg::Polyline::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Polyline");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -17,9 +17,16 @@ namespace esvg {
public:
Polyline(PaintState _parentPaintState);
~Polyline();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -54,38 +54,43 @@ void esvg::Rectangle::display(int32_t _spacing) {
ESVG_DEBUG(spacingDist(_spacing) << "Rectangle : pos=" << m_position << " size=" << m_size << " corner=" << m_roundedCorner);
}
esvg::render::Path esvg::Rectangle::createPath() {
esvg::render::Path out;
out.clear();
if ( m_roundedCorner.x() == 0.0f
|| m_roundedCorner.y() == 0.0f) {
out.moveTo(false, m_position);
out.lineToH(true, m_size.x());
out.lineToV(true, m_size.y());
out.lineToH(true, -m_size.x());
} else {
// Rounded rectangle
out.moveTo(false, m_position + vec2(m_roundedCorner.x(), 0.0f));
out.lineToH(true, m_size.x()-m_roundedCorner.x()*2.0f);
out.curveTo(true, vec2(m_roundedCorner.x()*esvg::kappa90, 0.0f),
vec2(m_roundedCorner.x(), m_roundedCorner.y() * (1.0f - esvg::kappa90)),
vec2(m_roundedCorner.x(), m_roundedCorner.y()) );
out.lineToV(true, m_size.y()-m_roundedCorner.y()*2.0f);
out.curveTo(true, vec2(0.0f, m_roundedCorner.y() * esvg::kappa90),
vec2(-m_roundedCorner.x()* (1.0f - esvg::kappa90), m_roundedCorner.y()),
vec2(-m_roundedCorner.x(), m_roundedCorner.y()) );
out.lineToH(true, -(m_size.x()-m_roundedCorner.x()*2.0f));
out.curveTo(true, vec2(-m_roundedCorner.x()*esvg::kappa90, 0.0f),
vec2(-m_roundedCorner.x(), -m_roundedCorner.y() * (1.0f - esvg::kappa90)),
vec2(-m_roundedCorner.x(), -m_roundedCorner.y()) );
out.lineToV(true, -(m_size.y()-m_roundedCorner.y()*2.0f));
out.curveTo(true, vec2(0.0f, -m_roundedCorner.y() * esvg::kappa90),
vec2(m_roundedCorner.x()* (1.0f - esvg::kappa90), -m_roundedCorner.y()),
vec2(m_roundedCorner.x(), -m_roundedCorner.y()) );
}
out.close();
return out;
}
void esvg::Rectangle::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::Rectangle: fill=" << m_paint.fill.first << "/" << m_paint.fill.second
<< " stroke=" << m_paint.stroke.first << "/" << m_paint.stroke.second);
esvg::render::Path listElement;
listElement.clear();
if ( m_roundedCorner.x() == 0.0f
|| m_roundedCorner.y() == 0.0f) {
listElement.moveTo(false, m_position);
listElement.lineToH(true, m_size.x());
listElement.lineToV(true, m_size.y());
listElement.lineToH(true, -m_size.x());
} else {
// Rounded rectangle
listElement.moveTo(false, m_position + vec2(m_roundedCorner.x(), 0.0f));
listElement.lineToH(true, m_size.x()-m_roundedCorner.x()*2.0f);
listElement.curveTo(true, vec2(m_roundedCorner.x()*esvg::kappa90, 0.0f),
vec2(m_roundedCorner.x(), m_roundedCorner.y() * (1.0f - esvg::kappa90)),
vec2(m_roundedCorner.x(), m_roundedCorner.y()) );
listElement.lineToV(true, m_size.y()-m_roundedCorner.y()*2.0f);
listElement.curveTo(true, vec2(0.0f, m_roundedCorner.y() * esvg::kappa90),
vec2(-m_roundedCorner.x()* (1.0f - esvg::kappa90), m_roundedCorner.y()),
vec2(-m_roundedCorner.x(), m_roundedCorner.y()) );
listElement.lineToH(true, -(m_size.x()-m_roundedCorner.x()*2.0f));
listElement.curveTo(true, vec2(-m_roundedCorner.x()*esvg::kappa90, 0.0f),
vec2(-m_roundedCorner.x(), -m_roundedCorner.y() * (1.0f - esvg::kappa90)),
vec2(-m_roundedCorner.x(), -m_roundedCorner.y()) );
listElement.lineToV(true, -(m_size.y()-m_roundedCorner.y()*2.0f));
listElement.curveTo(true, vec2(0.0f, -m_roundedCorner.y() * esvg::kappa90),
vec2(m_roundedCorner.x()* (1.0f - esvg::kappa90), -m_roundedCorner.y()),
vec2(m_roundedCorner.x(), -m_roundedCorner.y()) );
}
listElement.close();
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
@ -140,3 +145,23 @@ void esvg::Rectangle::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32
#endif
}
void esvg::Rectangle::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW Shape esvg::Rectangle");
esvg::render::Path listElement = createPath();
mat2 mtx = m_transformMatrix;
mtx *= _basicTrans;
esvg::render::PointList listPoints;
listPoints = listElement.generateListPoints(_level, _recurtionMax, _threshold);
for (auto &it : listPoints.m_data) {
std::vector<vec2> listPoint;
for (auto &itDot : it) {
listPoint.push_back(itDot.m_pos);
}
_out.push_back(listPoint);
}
}

View File

@ -18,9 +18,16 @@ namespace esvg {
public:
Rectangle(PaintState _parentPaintState);
~Rectangle();
virtual bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
bool parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) override;
void display(int32_t _spacing) override;
void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) override;
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
private:
esvg::render::Path createPath();
};
}

View File

@ -14,8 +14,8 @@ namespace esvg {
public:
Text(PaintState _parentPaintState);
~Text();
virtual bool parse(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
bool parse(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax);
void display(int32_t _spacing) override;
};
}

View File

@ -370,4 +370,32 @@ ememory::SharedPtr<esvg::Base> esvg::Document::getReference(const std::string& _
return nullptr;
}
std::vector<std::vector<vec2>> esvg::Document::getLines(vec2 _size) {
std::vector<std::vector<vec2>> out;
if (_size.x() <= 0) {
_size.setX(m_size.x());
}
if (_size.y() <= 0) {
_size.setY(m_size.y());
}
ESVG_DEBUG("lineification size " << _size);
// create the first element matrix modification ...
mat2 basicTrans;
basicTrans *= etk::mat2Scale(vec2(_size.x()/m_size.x(), _size.y()/m_size.y()));
drawShapePoints(out, 10, 0.25f, basicTrans);
return out;
}
void esvg::Document::drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level) {
ESVG_VERBOSE(spacingDist(_level) << "DRAW shape esvg::Document");
for (auto &it : m_subElementList) {
if (it != nullptr) {
it->drawShapePoints(_out, _recurtionMax, _threshold, _basicTrans, _level+1);
}
}
}

View File

@ -85,6 +85,7 @@ namespace esvg {
std::vector<etk::Color<uint8_t,4>> renderImageU8RGBA(ivec2& _size);
//! @previous
std::vector<etk::Color<uint8_t,3>> renderImageU8RGB(ivec2& _size);
std::vector<std::vector<vec2>> getLines(vec2 _size=vec2(256,256));
protected:
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level=0);
public:
@ -92,6 +93,12 @@ namespace esvg {
return m_size;
};
ememory::SharedPtr<esvg::Base> getReference(const std::string& _name);
protected:
void drawShapePoints(std::vector<std::vector<vec2>>& _out,
int32_t _recurtionMax,
int32_t _threshold,
mat2& _basicTrans,
int32_t _level=1) override;
};
}

View File

@ -509,6 +509,10 @@ esvg::render::PointList esvg::render::Path::generateListPoints(int32_t _level, i
out.addList(tmpListPoint);
tmpListPoint.clear();
}
ESVG_VERBOSE(spacingDist(_level) << " ==> " << out.m_data.size());
for (auto &it : out.m_data) {
ESVG_VERBOSE(spacingDist(_level) << " " << it.size());
}
out.display();
return out;
}