Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CGoGN
CGoGN
Commits
f29d13fe
Commit
f29d13fe
authored
Feb 17, 2012
by
Sylvain Thery
Browse files
svg output from drawer
parent
5579ce2f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/show_traversors.cpp
View file @
f29d13fe
...
...
@@ -106,6 +106,15 @@ void MyQT::cb_combo6(int x)
CGoGNerr
<<
"undefined traversor"
<<
CGoGNendl
;
}
void
MyQT
::
cb_explode
(
int
x
)
{
m_expl
=
float
(
x
)
/
100.0
f
;
if
(
m_last
==
2
)
traverse2
();
if
(
m_last
==
3
)
traverse3
();
}
void
MyQT
::
cb_initGL
()
{
...
...
@@ -154,6 +163,13 @@ void MyQT::cb_mousePress(int button, int x, int y)
}
void
MyQT
::
cb_Save
()
{
std
::
string
filename
=
selectFileSave
(
"Export SVG file "
,
"."
,
"(*.svg)"
);
Utils
::
SVG
::
SVGOut
svg
(
filename
,
modelViewMatrix
(),
projectionMatrix
());
m_drawer
.
toSVG
(
svg
);
}
void
MyQT
::
colorizeCell
(
Dart
d
,
unsigned
int
orbit
,
float
r
,
float
g
,
float
b
)
{
TraversorDartsOfOrbit
<
PFP
::
MAP
>
doo
(
myMap
,
orbit
,
d
);
...
...
@@ -166,37 +182,37 @@ void MyQT::traverse2()
{
if
(
m_selected
==
NIL
)
return
;
m_last
=
2
;
// int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
SelectorDartNoBoundary
<
PFP
::
MAP
>
nb
(
myMap
);
m_drawer
.
newList
(
GL_COMPILE
);
m_drawer
.
lineWidth
(
3.0
f
);
m_drawer
.
pointSize
(
7.0
f
);
m_drawer
.
color3f
(
1
.0
f
,
1.0
f
,
0.0
f
);
m_drawer
.
color3f
(
0
.0
f
,
0.7
f
,
0.0
f
);
m_affDarts
.
clear
();
if
(
m_ajd_or_inci2
==
0
)
// incident
{
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_second2
,
m_drawer
,
myMap
,
m_selected
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_second2
,
m_drawer
,
myMap
,
m_selected
,
position
,
m_expl
);
m_drawer
.
color3f
(
1.0
f
,
0.0
f
,
0.0
f
);
Traversor2
<
PFP
::
MAP
>*
tra
=
Traversor2
<
PFP
::
MAP
>::
createIncident
(
myMap
,
m_selected
,
VERTEX
+
m_second2
,
VERTEX
+
m_first2
);
for
(
Dart
d
=
tra
->
begin
();
d
!=
tra
->
end
();
d
=
tra
->
next
())
m_affDarts
.
push_back
(
d
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
m_expl
);
}
else
// adjacent
{
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_selected
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_selected
,
position
,
m_expl
);
m_drawer
.
color3f
(
1.0
f
,
0.0
f
,
0.0
f
);
Traversor2
<
PFP
::
MAP
>*
tra
=
Traversor2
<
PFP
::
MAP
>::
createAdjacent
(
myMap
,
m_selected
,
VERTEX
+
m_first2
,
VERTEX
+
m_second2
);
for
(
Dart
d
=
tra
->
begin
();
d
!=
tra
->
end
();
d
=
tra
->
next
())
m_affDarts
.
push_back
(
d
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first2
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
m_expl
);
}
m_drawer
.
endList
();
...
...
@@ -207,35 +223,36 @@ void MyQT::traverse2()
void
MyQT
::
traverse3
()
{
// int code = (m_ajd_or_inci3)*100+m_first3*10+m_second3;
// std::cout << "CODE="<< code << std::endl;
if
(
m_selected
==
NIL
)
return
;
m_last
=
3
;
SelectorDartNoBoundary
<
PFP
::
MAP
>
nb
(
myMap
);
m_affDarts
.
clear
();
m_drawer
.
newList
(
GL_COMPILE
);
m_drawer
.
lineWidth
(
3.0
f
);
m_drawer
.
pointSize
(
7.0
f
);
m_drawer
.
color3f
(
1
.0
f
,
1.0
f
,
0.0
f
);
m_drawer
.
color3f
(
0
.0
f
,
0.7
f
,
0.0
f
);
if
(
m_ajd_or_inci3
==
0
)
// incident
{
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_second3
,
m_drawer
,
myMap
,
m_selected
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_second3
,
m_drawer
,
myMap
,
m_selected
,
position
,
m_expl
);
m_drawer
.
color3f
(
1.0
f
,
0.0
f
,
0.0
f
);
Traversor3XY
<
PFP
::
MAP
>
tra
(
myMap
,
m_selected
,
VERTEX
+
m_second3
,
VERTEX
+
m_first3
);
for
(
Dart
d
=
tra
.
begin
();
d
!=
tra
.
end
();
d
=
tra
.
next
())
m_affDarts
.
push_back
(
d
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
m_expl
);
}
else
// adjacent
{
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_selected
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCell
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_selected
,
position
,
m_expl
);
m_drawer
.
color3f
(
1.0
f
,
0.0
f
,
0.0
f
);
Traversor3XXaY
<
PFP
::
MAP
>
tra
(
myMap
,
m_selected
,
VERTEX
+
m_first3
,
VERTEX
+
m_second3
);
for
(
Dart
d
=
tra
.
begin
();
d
!=
tra
.
end
();
d
=
tra
.
next
())
m_affDarts
.
push_back
(
d
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
0.7
f
);
Algo
::
Render
::
drawerCells
<
PFP
>
(
VERTEX
+
m_first3
,
m_drawer
,
myMap
,
m_affDarts
,
position
,
m_expl
);
}
m_drawer
.
endList
();
...
...
@@ -280,6 +297,7 @@ int main(int argc, char **argv)
sqt
.
setCallBack
(
dock
.
combo4
,
SIGNAL
(
activated
(
int
)),
SLOT
(
cb_combo4
(
int
))
);
sqt
.
setCallBack
(
dock
.
combo5
,
SIGNAL
(
activated
(
int
)),
SLOT
(
cb_combo5
(
int
))
);
sqt
.
setCallBack
(
dock
.
combo6
,
SIGNAL
(
activated
(
int
)),
SLOT
(
cb_combo6
(
int
))
);
sqt
.
setCallBack
(
dock
.
explodeSlider
,
SIGNAL
(
valueChanged
(
int
)),
SLOT
(
cb_explode
(
int
))
);
sqt
.
setCallBack
(
dock
.
checkTopo
,
SIGNAL
(
clicked
(
bool
)),
SLOT
(
cb_checkTopo
(
bool
))
);
...
...
Apps/Tuto/show_traversors.h
View file @
f29d13fe
...
...
@@ -96,6 +96,8 @@ class MyQT: public Utils::QT::SimpleQT
unsigned
int
m_first2
;
unsigned
int
m_ajd_or_inci2
;
unsigned
int
m_second2
;
float
m_expl
;
unsigned
int
m_last
;
public:
MyQT
()
:
m_render_topo
(
NULL
),
...
...
@@ -106,6 +108,8 @@ public:
m_first2
(
0
),
m_ajd_or_inci2
(
0
),
m_second2
(
1
),
m_expl
(
0.8
f
),
m_last
(
2
),
m_selected
(
NIL
)
{}
...
...
@@ -122,6 +126,8 @@ protected:
void
cb_initGL
();
void
cb_Save
();
void
cb_mousePress
(
int
button
,
int
x
,
int
y
);
void
colorizeCell
(
Dart
d
,
unsigned
int
orbit
,
float
r
,
float
g
,
float
b
);
...
...
@@ -139,6 +145,8 @@ public slots:
void
cb_combo5
(
int
x
);
void
cb_combo6
(
int
x
);
void
cb_checkTopo
(
bool
b
);
void
cb_explode
(
int
x
);
};
#endif
Apps/Tuto/show_traversors.ui
View file @
f29d13fe
...
...
@@ -210,6 +210,29 @@
</property>
</widget>
</item>
<item>
<widget
class=
"QSlider"
name=
"explodeSlider"
>
<property
name=
"minimum"
>
<number>
1
</number>
</property>
<property
name=
"maximum"
>
<number>
100
</number>
</property>
<property
name=
"sliderPosition"
>
<number>
80
</number>
</property>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item>
<widget
class=
"Line"
name=
"line_3"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"checkTopo"
>
<property
name=
"focusPolicy"
>
...
...
include/Utils/drawer.h
View file @
f29d13fe
...
...
@@ -31,6 +31,7 @@
namespace
CGoGN
{
namespace
Utils
{
class
VBO
;
}
}
namespace
CGoGN
{
namespace
Utils
{
class
ShaderColorPerVertex
;
}
}
namespace
CGoGN
{
namespace
Utils
{
namespace
SVG
{
class
SVGOut
;
}
}
}
namespace
CGoGN
{
...
...
@@ -137,6 +138,11 @@ public:
* usr as glPointSize
*/
void
pointSize
(
float
ps
);
/**
* rendering in svg struct
*/
void
toSVG
(
Utils
::
SVG
::
SVGOut
&
svg
);
};
}
// namespace Utils
...
...
include/Utils/svg.h
View file @
f29d13fe
...
...
@@ -81,6 +81,8 @@ public:
Geom
::
Vec3f
normal
();
const
std
::
vector
<
Geom
::
Vec3f
>&
vertices
()
const
;
};
class
SvgPoints
:
public
SvgObj
...
...
@@ -127,6 +129,9 @@ protected:
std
::
vector
<
SvgObj
*>
m_objs
;
SvgObj
*
m_current
;
protected:
void
computeBB
(
unsigned
int
&
a
,
unsigned
int
&
b
,
unsigned
int
&
c
,
unsigned
&
d
);
public:
/**
...
...
src/Utils/drawer.cpp
View file @
f29d13fe
...
...
@@ -22,10 +22,12 @@
* *
*******************************************************************************/
#include
"GL/glew.h"
#include
"Utils/drawer.h"
#include
"Utils/Shaders/shaderColorPerVertex.h"
#include
"Utils/vbo.h"
#include
"Utils/svg.h"
namespace
CGoGN
{
...
...
@@ -167,6 +169,73 @@ void Drawer::callList()
m_shader
->
disableVertexAttribs
();
}
void
Drawer
::
toSVG
(
Utils
::
SVG
::
SVGOut
&
svg
)
{
const
Geom
::
Vec3f
*
ptrP
=
reinterpret_cast
<
Geom
::
Vec3f
*>
(
m_vboPos
->
lockPtr
());
const
Geom
::
Vec3f
*
ptrC
=
reinterpret_cast
<
Geom
::
Vec3f
*>
(
m_vboCol
->
lockPtr
());
for
(
std
::
vector
<
PrimParam
>::
iterator
pp
=
m_begins
.
begin
();
pp
!=
m_begins
.
end
();
++
pp
)
{
svg
.
setWidth
(
pp
->
width
);
if
(
pp
->
mode
==
GL_POINTS
)
{
unsigned
int
end
=
pp
->
begin
+
pp
->
nb
;
svg
.
beginPoints
();
for
(
unsigned
int
i
=
pp
->
begin
;
i
<
end
;
++
i
)
svg
.
addPoint
(
ptrP
[
i
],
ptrC
[
i
]);
svg
.
endPoints
();
}
if
(
pp
->
mode
==
GL_LINES
)
{
unsigned
int
end
=
pp
->
begin
+
pp
->
nb
;
svg
.
beginLines
();
for
(
unsigned
int
i
=
pp
->
begin
;
i
<
end
;
i
+=
2
)
svg
.
addLine
(
ptrP
[
i
],
ptrP
[
i
+
1
],
ptrC
[
i
]);
svg
.
endLines
();
}
if
((
pp
->
mode
==
GL_LINE_LOOP
)
||
(
pp
->
mode
==
GL_POLYGON
))
{
unsigned
int
end
=
pp
->
begin
+
pp
->
nb
-
1
;
svg
.
beginLines
();
for
(
unsigned
int
i
=
pp
->
begin
;
i
<=
end
;
++
i
)
svg
.
addLine
(
ptrP
[
i
],
ptrP
[
i
+
1
],
ptrC
[
i
]);
svg
.
addLine
(
ptrP
[
end
],
ptrP
[
pp
->
begin
],
ptrC
[
end
]);
svg
.
endLines
();
}
if
(
pp
->
mode
==
GL_TRIANGLES
)
{
unsigned
int
end
=
pp
->
begin
+
pp
->
nb
;
svg
.
beginLines
();
for
(
unsigned
int
i
=
pp
->
begin
;
i
<
end
;
i
+=
3
)
{
svg
.
addLine
(
ptrP
[
i
],
ptrP
[
i
+
1
],
ptrC
[
i
]);
svg
.
addLine
(
ptrP
[
i
+
1
],
ptrP
[
i
+
2
],
ptrC
[
i
+
1
]);
svg
.
addLine
(
ptrP
[
i
+
2
],
ptrP
[
i
],
ptrC
[
i
+
2
]);
}
svg
.
endLines
();
}
if
(
pp
->
mode
==
GL_QUADS
)
{
unsigned
int
end
=
pp
->
begin
+
pp
->
nb
;
svg
.
beginLines
();
for
(
unsigned
int
i
=
pp
->
begin
;
i
<
end
;
i
+=
4
)
{
svg
.
addLine
(
ptrP
[
i
],
ptrP
[
i
+
1
],
ptrC
[
i
]);
svg
.
addLine
(
ptrP
[
i
+
1
],
ptrP
[
i
+
2
],
ptrC
[
i
+
1
]);
svg
.
addLine
(
ptrP
[
i
+
2
],
ptrP
[
i
+
3
],
ptrC
[
i
+
2
]);
svg
.
addLine
(
ptrP
[
i
+
3
],
ptrP
[
i
],
ptrC
[
i
+
3
]);
}
svg
.
endLines
();
}
}
m_vboPos
->
releasePtr
();
m_vboCol
->
releasePtr
();
}
}
// namespace Utils
}
// namespace CGoGN
src/Utils/svg.cpp
View file @
f29d13fe
...
...
@@ -37,6 +37,11 @@ namespace SVG
{
const
std
::
vector
<
Geom
::
Vec3f
>&
SvgObj
::
vertices
()
const
{
return
m_vertices
;
}
void
SvgObj
::
addVertex
(
const
Geom
::
Vec3f
&
v
)
{
m_vertices
.
push_back
(
v
);
...
...
@@ -248,19 +253,19 @@ SVGOut::SVGOut(const std::string& filename, const glm::mat4& model, const glm::m
}
glGetIntegerv
(
GL_VIEWPORT
,
&
(
m_viewport
[
0
]));
*
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
<<
"<title>test</title>"
<<
std
::
endl
;
*
m_out
<<
"<desc>"
<<
std
::
endl
;
*
m_out
<<
"Rendered from CGoGN"
<<
std
::
endl
;
*
m_out
<<
"</desc>"
<<
std
::
endl
;
*
m_out
<<
"<defs>"
<<
std
::
endl
;
*
m_out
<<
"</defs>"
<<
std
::
endl
;
*
m_out
<<
"<g shape-rendering=
\"
crispEdges
\"
>"
<<
std
::
endl
;
//
//
*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 << "<title>test</title>"<< std::endl;
//
*m_out << "<desc>"<< std::endl;
//
*m_out << "Rendered from CGoGN"<< std::endl;
//
//
*m_out << "</desc>"<< std::endl;
//
*m_out << "<defs>"<< std::endl;
//
*m_out << "</defs>"<< std::endl;
//
*m_out << "<g shape-rendering=\"crispEdges\">" << std::endl;
}
SVGOut
::~
SVGOut
()
...
...
@@ -287,6 +292,26 @@ 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
);
*
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
<<
"<title>test</title>"
<<
std
::
endl
;
*
m_out
<<
"<desc>"
<<
std
::
endl
;
*
m_out
<<
"Rendered from CGoGN"
<<
std
::
endl
;
*
m_out
<<
"</desc>"
<<
std
::
endl
;
*
m_out
<<
"<defs>"
<<
std
::
endl
;
*
m_out
<<
"</defs>"
<<
std
::
endl
;
*
m_out
<<
"<g shape-rendering=
\"
crispEdges
\"
>"
<<
std
::
endl
;
// here do the sort in necessary
for
(
std
::
vector
<
SvgObj
*>::
iterator
it
=
m_objs
.
begin
();
it
!=
m_objs
.
end
();
++
it
)
...
...
@@ -300,6 +325,40 @@ void SVGOut::closeFile()
}
void
SVGOut
::
computeBB
(
unsigned
int
&
a
,
unsigned
int
&
b
,
unsigned
int
&
c
,
unsigned
&
d
)
{
// here do the sort in necessary
a
=
100000
;
b
=
100000
;
c
=
0
;
d
=
0
;
for
(
std
::
vector
<
SvgObj
*>::
iterator
it
=
m_objs
.
begin
();
it
!=
m_objs
.
end
();
++
it
)
{
const
std
::
vector
<
Geom
::
Vec3f
>&
vert
=
(
*
it
)
->
vertices
();
for
(
std
::
vector
<
Geom
::
Vec3f
>::
const_iterator
j
=
vert
.
begin
();
j
!=
vert
.
end
();
++
j
)
{
const
Geom
::
Vec3f
&
P
=
*
j
;
if
(
P
[
0
]
<
a
)
a
=
(
unsigned
int
)(
P
[
0
]);
if
(
P
[
1
]
<
b
)
b
=
(
unsigned
int
)(
P
[
1
]);
if
(
P
[
0
]
>
c
)
c
=
(
unsigned
int
)(
P
[
0
]);
if
(
P
[
1
]
>
d
)
d
=
(
unsigned
int
)(
P
[
1
]);
}
if
(
a
>
10
)
a
-=
10
;
if
(
b
>
10
)
b
-=
10
;
c
+=
10
;
d
+=
10
;
}
}
void
SVGOut
::
beginPoints
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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