Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
David Cazier
CGoGN
Commits
43b1b8e7
Commit
43b1b8e7
authored
Feb 20, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add svg out option in text3D
parent
15beca88
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
19 deletions
+157
-19
Apps/Tuto/tuto5.cpp
Apps/Tuto/tuto5.cpp
+3
-0
include/Utils/svg.h
include/Utils/svg.h
+37
-3
include/Utils/text3d.h
include/Utils/text3d.h
+5
-1
src/Utils/svg.cpp
src/Utils/svg.cpp
+100
-13
src/Utils/text3d.cpp
src/Utils/text3d.cpp
+12
-2
No files found.
Apps/Tuto/tuto5.cpp
View file @
43b1b8e7
...
...
@@ -249,8 +249,11 @@ void MyQT::cb_keyPress(int code)
svg
.
setWidth
(
1.0
f
);
svg
.
setColor
(
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
0.5
f
));
Algo
::
Render
::
SVG
::
renderEdges
<
PFP
>
(
svg
,
myMap
,
position
);
svg
.
setColor
(
Geom
::
Vec3f
(
0.0
f
,
0.8
f
,
0.0
f
));
svg
.
setWidth
(
5.0
f
);
Algo
::
Render
::
SVG
::
renderVertices
<
PFP
>
(
svg
,
myMap
,
position
);
svg
.
setColor
(
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
0.0
f
));
m_strings
->
toSVG
(
svg
);
//svg destruction close the file
}
if
(
code
==
't'
)
...
...
include/Utils/svg.h
View file @
43b1b8e7
...
...
@@ -28,6 +28,7 @@
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include "Geometry/vector_gen.h"
...
...
@@ -65,6 +66,7 @@ class SvgObj
protected:
std
::
vector
<
Geom
::
Vec3f
>
m_vertices
;
std
::
vector
<
Geom
::
Vec3f
>
m_colors
;
std
::
vector
<
std
::
string
>
m_strings
;
std
::
vector
<
Geom
::
Vec3f
>
m_vertices3D
;
Geom
::
Vec3f
m_color
;
float
m_width
;
...
...
@@ -79,6 +81,10 @@ public:
void
addVertex3D
(
const
Geom
::
Vec3f
&
v
,
const
Geom
::
Vec3f
&
C
);
void
addString
(
const
Geom
::
Vec3f
&
v
,
const
std
::
string
&
str
);
void
addString
(
const
Geom
::
Vec3f
&
v
,
const
std
::
string
&
str
,
const
Geom
::
Vec3f
&
C
);
void
setColor
(
const
Geom
::
Vec3f
&
c
);
void
setWidth
(
float
w
);
...
...
@@ -87,7 +93,7 @@ public:
virtual
void
save
(
std
::
ofstream
&
out
)
const
=
0
;
virtual
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
)
const
=
0
;
virtual
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
,
unsigned
int
bbl
=
0
)
const
=
0
;
unsigned
int
nbv
()
const
;
...
...
@@ -107,7 +113,7 @@ class SvgPoints: public SvgObj
{
public:
void
save
(
std
::
ofstream
&
out
)
const
;
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
)
const
;
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
,
unsigned
int
bbl
=
0
)
const
;
unsigned
int
nbPrimtives
()
const
;
void
fillDS
(
std
::
vector
<
DepthSort
>&
vds
,
unsigned
int
idObj
)
const
;
};
...
...
@@ -116,7 +122,20 @@ class SvgLines: public SvgObj
{
public:
void
save
(
std
::
ofstream
&
out
)
const
;
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
)
const
;
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
,
unsigned
int
bbl
=
0
)
const
;
unsigned
int
nbPrimtives
()
const
;
void
fillDS
(
std
::
vector
<
DepthSort
>&
vds
,
unsigned
int
idObj
)
const
;
};
class
SvgStrings
:
public
SvgObj
{
protected:
float
m_sf
;
public:
SvgStrings
(
float
scalefactor
=
1.0
f
)
:
m_sf
(
scalefactor
)
{}
void
save
(
std
::
ofstream
&
out
)
const
;
void
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
,
unsigned
int
bbl
=
0
)
const
;
unsigned
int
nbPrimtives
()
const
;
void
fillDS
(
std
::
vector
<
DepthSort
>&
vds
,
unsigned
int
idObj
)
const
;
};
...
...
@@ -154,6 +173,14 @@ protected:
std
::
vector
<
SvgObj
*>
m_objs
;
SvgObj
*
m_current
;
unsigned
int
m_bbX0
;
unsigned
int
m_bbY0
;
unsigned
int
m_bbX1
;
unsigned
int
m_bbY1
;
protected:
void
computeBB
(
unsigned
int
&
a
,
unsigned
int
&
b
,
unsigned
int
&
c
,
unsigned
&
d
);
...
...
@@ -190,6 +217,13 @@ public:
void
addLine
(
const
Geom
::
Vec3f
&
P
,
const
Geom
::
Vec3f
&
P2
);
void
addLine
(
const
Geom
::
Vec3f
&
P
,
const
Geom
::
Vec3f
&
P2
,
const
Geom
::
Vec3f
&
C
);
void
beginStrings
(
float
scalefactor
=
1.0
f
);
void
endStrings
();
void
addString
(
const
Geom
::
Vec3f
&
P
,
const
std
::
string
&
str
);
void
addString
(
const
Geom
::
Vec3f
&
P
,
const
Geom
::
Vec3f
&
Q
,
const
std
::
string
&
str
);
void
addString
(
const
Geom
::
Vec3f
&
P
,
const
std
::
string
&
str
,
const
Geom
::
Vec3f
&
C
);
void
sortSimpleDepth
(
std
::
vector
<
DepthSort
>&
vds
);
};
...
...
include/Utils/text3d.h
View file @
43b1b8e7
...
...
@@ -28,10 +28,10 @@
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
namespace
CGoGN
{
namespace
Utils
{
namespace
SVG
{
class
SVGOut
;
}
}
}
namespace
CGoGN
{
namespace
Utils
{
...
...
@@ -67,6 +67,8 @@ protected:
Utils
::
VBO
*
m_vbo1
;
float
m_scale
;
unsigned
int
sendOneStringToVBO
(
const
std
::
string
&
str
,
float
**
buffer
);
GLuint
m_uniform_texture
;
...
...
@@ -137,6 +139,8 @@ public:
*/
void
setScale
(
float
scale
);
void
toSVG
(
Utils
::
SVG
::
SVGOut
&
svg
);
};
}
// namespace Utils
...
...
src/Utils/svg.cpp
View file @
43b1b8e7
...
...
@@ -70,6 +70,21 @@ void SvgObj::addVertex3D(const Geom::Vec3f& v, const Geom::Vec3f& c)
}
void SvgObj::addString(const Geom::Vec3f& v, const std::string& str)
{
m_vertices.push_back(v);
m_strings.push_back(str);
m_colors.push_back(m_color);
}
void SvgObj::addString(const Geom::Vec3f& v, const std::string& str, const Geom::Vec3f& c)
{
m_vertices.push_back(v);
m_strings.push_back(str);
m_colors.push_back(c);
}
void SvgObj::setWidth(float w)
{
m_width=w;
...
...
@@ -146,7 +161,7 @@ void SvgPoints::save(std::ofstream& out) const
}
void
SvgPoints
::
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
)
const
void SvgPoints::saveOne(std::ofstream& out, unsigned int i
, unsigned int bbl
) const
{
std::stringstream ss;
...
...
@@ -212,7 +227,7 @@ void SvgLines::save(std::ofstream& out) const
}
}
void
SvgLines
::
saveOne
(
std
::
ofstream
&
out
,
unsigned
int
i
)
const
void SvgLines::saveOne(std::ofstream& out, unsigned int i
, unsigned int bbl
) const
{
std::stringstream ss;
...
...
@@ -249,6 +264,59 @@ void SvgLines::fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const
}
void SvgStrings::save(std::ofstream& out) const
{
unsigned int nb = m_vertices.size();
for (unsigned int i=0; i<nb; ++i)
{
saveOne(out,i);
}
}
void SvgStrings::saveOne(std::ofstream& out, unsigned int i, unsigned int bbl) const
{
float scale = m_sf * sqrt(1.0f - m_vertices[i][2])*0.007f*float(bbl);
out << "<text style=\"font-size:24px;";
out << "font-family:Bitstream Vera Sans\" ";
out << "transform=\"scale(" << scale <<"," << scale <<")\""<< std::endl;
out << "x=\""<< (m_vertices[i][0])/scale << "\" y=\""<< (m_vertices[i][1])/scale<< "\">";
out << "<tspan style=\"fill:#";
out << std::hex;
unsigned int wp = out.width(2);
char prev = out.fill('0');
out << int(m_colors[i][0]*255);
out.width(2); out.fill('0');
out<< int(m_colors[i][1]*255);
out.width(2); out.fill('0');
out << int(m_colors[i][2]*255)<<std::dec;
out.fill(prev);
out.width(wp);
out <<"\">"<< m_strings[i]<< "</tspan></text>"<< std::endl;
}
unsigned int SvgStrings::nbPrimtives() const
{
return m_vertices.size();
}
void SvgStrings::fillDS(std::vector<DepthSort>& vds, unsigned int idObj) const
{
for (unsigned int i = 0; i< m_vertices.size(); ++i)
{
vds.push_back(DepthSort(idObj,i,m_vertices[i][2]));
}
}
//void SvgPolyline::save(std::ofstream& out)
//{
// std::stringstream ss;
...
...
@@ -368,17 +436,12 @@ void SVGOut::setWidth(float w)
void SVGOut::closeFile()
{
unsigned
int
a
=
0
;
unsigned
int
b
=
0
;
unsigned
int
c
=
1024
;
unsigned
int
d
=
1024
;
computeBB
(
a
,
b
,
c
,
d
);
computeBB(m_bbX0, m_bbY0, m_bbX1, m_bbY1);
*m_out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"<< std::endl;
*m_out << "<svg xmlns=\"http://www.w3.org/2000/svg\""<< std::endl;
*m_out << " xmlns:xlink=\"http://www.w3.org/1999/xlink\""<< std::endl;
// *m_out << " width=\""<<m_viewport[2]<<"px\" height=\""<<m_viewport[3]<<"px\" viewBox=\"0 0 "<<m_viewport[2]<<" "<<m_viewport[3]<<"\">"<< std::endl;
*
m_out
<<
"viewBox=
\"
"
<<
a
<<
" "
<<
b
<<
" "
<<
c
-
a
<<
" "
<<
d
-
b
<<
"
\"
>"
<<
std
::
endl
;
*m_out << "viewBox=\""<< m_bbX0 <<" "<< m_bbY0 <<" "<< m_bbX1-m_bbX0 << " " << m_bbY1-m_bbY0 <<"\">"<< std::endl;
*m_out << "<title>test</title>"<< std::endl;
*m_out << "<desc>"<< std::endl;
*m_out << "Rendered from CGoGN"<< std::endl;
...
...
@@ -395,7 +458,7 @@ void SVGOut::closeFile()
for (std::vector<DepthSort>::iterator it = vds.begin(); it != vds.end(); ++it)
{
m_objs
[
it
->
obj
]
->
saveOne
(
*
m_out
,
it
->
id
);
m_objs[it->obj]->saveOne(*m_out,it->id
, m_bbX1-m_bbX0
);
}
// for (std::vector<SvgObj*>::iterator it = m_objs.begin(); it != m_objs.end(); ++it)
...
...
@@ -446,9 +509,6 @@ void SVGOut::computeBB(unsigned int& a, unsigned int& b, unsigned int& c, unsign
void SVGOut::beginPoints()
{
// glm::i32vec4 viewport;
// glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
m_current = new SvgPoints();
m_current->setColor(global_color);
m_current->setWidth(global_width);
...
...
@@ -528,6 +588,33 @@ void SVGOut::addLine(const Geom::Vec3f& P, const Geom::Vec3f& P2, const Geom::Ve
}
void SVGOut::beginStrings(float scalefactor)
{
m_current = new SvgStrings(scalefactor);
m_current->setColor(global_color);
m_current->setWidth(global_width);
}
void SVGOut::endStrings()
{
m_objs.push_back(m_current);
m_current = NULL;
}
void SVGOut::addString(const Geom::Vec3f& P, const std::string& str)
{
glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport);
m_current->addString(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])), str);
}
void SVGOut::addString(const Geom::Vec3f& P, const std::string& str, const Geom::Vec3f& C)
{
glm::vec3 Q = glm::project(glm::vec3(P[0],P[1],P[2]),m_model,m_proj,m_viewport);
m_current->addString(Geom::Vec3f(float(Q[0]),float(m_viewport[3])-float(Q[1]),float(Q[2])), str, C);
}
void SVGOut::sortSimpleDepth(std::vector<DepthSort>& vds)
{
unsigned int nb=0;
...
...
src/Utils/text3d.cpp
View file @
43b1b8e7
...
...
@@ -23,8 +23,8 @@
*******************************************************************************/
#include "Utils/text3d.h"
#include "Utils/vbo.h"
#include "Utils/svg.h"
namespace
CGoGN
{
...
...
@@ -43,7 +43,7 @@ std::string Strings3D::fragmentShaderText2 =
GLuint
Strings3D
::
m_idTexture
=
0xffffffff
;
Strings3D
::
Strings3D
(
bool
withBackground
,
const
Geom
::
Vec3f
&
bgc
)
:
m_nbChars
(
0
)
Strings3D
::
Strings3D
(
bool
withBackground
,
const
Geom
::
Vec3f
&
bgc
)
:
m_nbChars
(
0
)
,
m_scale
(
1.0
f
)
{
if
(
m_idTexture
==
0xffffffff
)
{
...
...
@@ -101,6 +101,7 @@ void Strings3D::setScale(float scale)
{
bind
();
glUniform1f
(
m_uniform_scale
,
scale
);
m_scale
=
scale
;
unbind
();
}
...
...
@@ -246,6 +247,15 @@ void Strings3D::drawAll(const Geom::Vec3f& color)
postdraw
();
}
void
Strings3D
::
toSVG
(
Utils
::
SVG
::
SVGOut
&
svg
)
{
svg
.
beginStrings
(
m_scale
);
unsigned
int
nb
=
m_strings
.
size
();
for
(
unsigned
int
i
=
0
;
i
<
nb
;
++
i
)
svg
.
addString
(
m_strTranslate
[
i
],
m_strings
[
i
]);
svg
.
endStrings
();
}
}
// namespace Utils
}
// namespace CGoGN
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment