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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
CGoGN
CGoGN
Commits
a8c72c7c
Commit
a8c72c7c
authored
May 05, 2011
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modif svg
parent
614b1ff0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
196 additions
and
17 deletions
+196
-17
Apps/Tuto/tuto5.cpp
Apps/Tuto/tuto5.cpp
+1
-1
include/Algo/Render/SVG/mapSVGRender.h
include/Algo/Render/SVG/mapSVGRender.h
+33
-13
include/Algo/Render/SVG/mapSVGRender.hpp
include/Algo/Render/SVG/mapSVGRender.hpp
+1
-1
src/Algo/Render/mapSVGRender.cpp
src/Algo/Render/mapSVGRender.cpp
+161
-2
No files found.
Apps/Tuto/tuto5.cpp
View file @
a8c72c7c
...
...
@@ -249,7 +249,7 @@ void MyQT::cb_keyPress(int code)
std
::
string
filename
=
selectFileSave
(
"Export SVG file "
);
CGoGNout
<<
"Exporting "
<<
filename
<<
CGoGNendl
;
Algo
::
Render
::
SVG
::
SVGOut
svg
(
filename
,
modelViewMatrix
(),
projectionMatrix
());
svg
.
renderLinesToSVG
<
PFP
>
(
myMap
,
position
);
//
svg.renderLinesToSVG<PFP>(myMap,position);
svg
.
setColor
(
Geom
::
Vec3f
(
1.
,
0.
,
0.
));
svg
.
renderFacesToSVG
<
PFP
>
(
myMap
,
position
,
0.8
f
);
//svg destruction close the file
...
...
include/Algo/Render/SVG/mapSVGRender.h
View file @
a8c72c7c
...
...
@@ -62,38 +62,49 @@ namespace SVG
class
SvgObj
{
protected:
std
::
vector
<
Geom
::
Vec3f
>
m_vertices
;
Geom
::
Vec3f
m_color
;
float
m_width
;
public:
void
addVertex
(
const
Geom
::
Vec3f
&
v
);
void
setColor
(
const
Geom
::
Vec3f
&
c
);
void
setWidth
(
float
w
)
{
m_width
=
w
;}
void
close
();
virtual
void
save
(
std
::
ofstream
&
out
)
=
0
;
unsigned
int
nbv
()
const
{
return
m_vertices
.
size
();}
const
Geom
::
Vec3f
&
P
(
unsigned
int
i
)
const
{
return
m_vertices
[
i
];}
Geom
::
Vec3f
normal
();
};
class
SvgPolyline
:
public
SvgObj
{
protected:
std
::
vector
<
Geom
::
Vec3f
>
m_vertices
;
float
m_width
;
public:
void
addVertex
(
const
Geom
::
Vec3f
&
v
);
void
close
();
void
setColor
(
const
Geom
::
Vec3f
&
c
)
{
m_color
=
c
;}
void
setWidth
(
float
w
)
{
m_width
=
w
;}
public:
void
save
(
std
::
ofstream
&
out
);
};
class
Svg
_
Polygon
:
public
SvgObj
class
SvgPolygon
:
public
SvgObj
{
protected:
std
::
vector
<
Geom
::
Vec3f
>
m_vertices
;
Geom
::
Vec3f
m_colorFill
;
public:
void
addVertex
(
const
Geom
::
Vec3f
&
v
)
{}
void
close
()
{}
void
save
(
std
::
ofstream
&
out
)
{}
void
setColorFill
(
const
Geom
::
Vec3f
&
c
);
void
save
(
std
::
ofstream
&
out
);
};
...
...
@@ -142,6 +153,15 @@ public:
};
struct
compSvgObj
{
int
points_plane
(
SvgPolygon
*
pol_points
,
SvgPolygon
*
pol_plane
);
bool
operator
()
(
SvgObj
*
a
,
SvgObj
*
b
);
};
void
bubble_sort
(
std
::
vector
<
SvgObj
*>&
table
,
compSvgObj
&
cmp
);
}
// namespace SVG
}
// namespace Render
...
...
include/Algo/Render/SVG/mapSVGRender.hpp
View file @
a8c72c7c
...
...
@@ -79,7 +79,7 @@ void SVGOut::renderFacesToSVG(typename PFP::MAP& map, const typename PFP::TVEC3&
if
(
!
m
.
isMarked
(
d
)
&&
good
(
d
))
{
typename
PFP
::
VEC3
center
=
Algo
::
Geometry
::
faceCentroid
<
PFP
>
(
map
,
d
,
position
);
SvgPoly
line
*
pol
=
new
SvgPolyline
();
SvgPoly
gon
*
pol
=
new
SvgPolygon
();
Dart
dd
=
d
;
do
{
...
...
src/Algo/Render/mapSVGRender.cpp
View file @
a8c72c7c
...
...
@@ -22,6 +22,8 @@
* *
*******************************************************************************/
#include "Algo/Render/SVG/mapSVGRender.h"
#include <algorithm>
#include <typeinfo>
/**
* A set of functions that allow the creation of rendering
...
...
@@ -41,16 +43,43 @@ namespace Render
namespace
SVG
{
void
Svg
Polyline
::
addVertex
(
const
Geom
::
Vec3f
&
v
)
void
Svg
Obj
::
addVertex
(
const
Geom
::
Vec3f
&
v
)
{
m_vertices
.
push_back
(
v
);
}
void
SvgPolyline
::
close
()
void
SvgObj
::
setColor
(
const
Geom
::
Vec3f
&
c
)
{
m_color
=
c
;
}
void
SvgObj
::
close
()
{
m_vertices
.
push_back
(
m_vertices
.
front
());
}
Geom
::
Vec3f
SvgObj
::
normal
()
{
if
(
m_vertices
.
size
()
<
3
)
{
CGoGNerr
<<
"Error SVG normal computing (not enough points)"
<<
CGoGNendl
;
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
0.0
f
);
}
Geom
::
Vec3f
U
=
m_vertices
[
2
]
-
m_vertices
[
1
];
Geom
::
Vec3f
V
=
m_vertices
[
0
]
-
m_vertices
[
1
];
Geom
::
Vec3f
N
=
U
^
V
;
N
.
normalize
();
// TO DO verify that is necessary
return
N
;
}
void
SvgPolyline
::
save
(
std
::
ofstream
&
out
)
{
std
::
stringstream
ss
;
...
...
@@ -75,6 +104,46 @@ void SvgPolyline::save(std::ofstream& out)
}
void
SvgPolygon
::
setColorFill
(
const
Geom
::
Vec3f
&
c
)
{
m_colorFill
=
c
;
}
void
SvgPolygon
::
save
(
std
::
ofstream
&
out
)
{
std
::
stringstream
ss
;
out
<<
"<polyline fill=
\"
"
;
out
<<
std
::
hex
;
unsigned
int
wp
=
out
.
width
(
2
);
char
prev
=
out
.
fill
(
'0'
);
out
<<
int
(
m_colorFill
[
0
]
*
255
);
out
.
width
(
2
);
out
.
fill
(
'0'
);
out
<<
int
(
m_colorFill
[
1
]
*
255
);
out
.
width
(
2
);
out
.
fill
(
'0'
);
out
<<
int
(
m_colorFill
[
2
]
*
255
);
out
<<
"none
\"
stroke=
\"
#"
;
wp
=
out
.
width
(
2
);
prev
=
out
.
fill
(
'0'
);
out
<<
int
(
m_color
[
0
]
*
255
);
out
.
width
(
2
);
out
.
fill
(
'0'
);
out
<<
int
(
m_color
[
1
]
*
255
);
out
.
width
(
2
);
out
.
fill
(
'0'
);
out
<<
int
(
m_color
[
2
]
*
255
)
<<
std
::
dec
;
out
<<
"
\"
stroke-width=
\"
"
<<
m_width
<<
"
\"
points=
\"
"
;
out
.
fill
(
prev
);
out
.
width
(
wp
);
for
(
std
::
vector
<
Geom
::
Vec3f
>::
iterator
it
=
m_vertices
.
begin
();
it
!=
m_vertices
.
end
();
++
it
)
{
out
<<
(
*
it
)[
0
]
<<
","
<<
(
*
it
)[
1
]
<<
" "
;
}
out
<<
"
\"
/>"
<<
std
::
endl
;
}
...
...
@@ -132,6 +201,10 @@ void SVGOut::setWidth(float w)
void
SVGOut
::
closeFile
()
{
// here do the sort in necessary
compSvgObj
cmp
;
// std::sort(m_objs.begin(),m_objs.end(),cmp);
bubble_sort
(
m_objs
,
cmp
);
for
(
std
::
vector
<
SvgObj
*>::
iterator
it
=
m_objs
.
begin
();
it
!=
m_objs
.
end
();
++
it
)
{
(
*
it
)
->
save
(
*
m_out
);
...
...
@@ -144,6 +217,92 @@ void SVGOut::closeFile()
// all points behind the plane +
// all points before the plane -
// all points colinear to the plane 0
int
compSvgObj
::
points_plane
(
SvgPolygon
*
pol_points
,
SvgPolygon
*
pol_plane
)
{
Geom
::
Vec3f
N
=
pol_plane
->
normal
();
if
(
N
[
2
]
>
0.0
f
)
N
=
-
1.0
f
*
N
;
unsigned
int
nb
=
pol_points
->
nbv
();
unsigned
int
nbback
=
0
;
unsigned
int
nbfront
=
0
;
unsigned
int
nb_col
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
nb
;
++
i
)
{
Geom
::
Vec3f
U
=
pol_points
->
P
(
i
)
-
pol_plane
->
P
(
0
);
float
ps
=
U
*
N
;
if
(
fabs
(
ps
)
<
0.0001
f
)
nb_col
++
;
else
{
if
(
ps
<
0
)
nbback
++
;
else
nbfront
++
;
}
}
if
(
nbfront
==
0
)
return
1
;
if
(
nbback
==
0
)
return
-
1
;
return
0
;
}
bool
compSvgObj
::
operator
()
(
SvgObj
*
a
,
SvgObj
*
b
)
{
// std::cout << typeid(*a).name()<< " / "<< typeid(*b).name()<< std::endl;
SvgPolygon
*
p_a
=
dynamic_cast
<
SvgPolygon
*>
(
a
);
SvgPolygon
*
p_b
=
dynamic_cast
<
SvgPolygon
*>
(
b
);
if
((
p_a
!=
NULL
)
&&
(
p_b
!=
NULL
))
// first case polygon/polygon
{
if
(
points_plane
(
p_a
,
p_b
)
>
0
)
return
true
;
if
(
points_plane
(
p_b
,
p_a
)
<
0
)
return
true
;
return
false
;
}
std
::
cout
<<
"Cas non traite !!"
<<
std
::
endl
;
return
false
;
}
void
bubble_sort
(
std
::
vector
<
SvgObj
*>&
table
,
compSvgObj
&
cmp
)
{
unsigned
int
nb
=
table
.
size
()
-
1
;
unsigned
int
nbswap
=
1
;
while
(
nbswap
>
0
)
{
nbswap
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
nb
;
++
i
)
{
if
(
cmp
(
table
[
i
+
1
],
table
[
i
]))
{
SvgObj
*
tempo
=
table
[
i
];
table
[
i
]
=
table
[
i
+
1
];
table
[
i
+
1
]
=
tempo
;
nbswap
++
;
std
::
cout
<<
"SWAP "
<<
i
<<
" / "
<<
i
+
1
<<
std
::
endl
;
}
}
std
::
cout
<<
"NB SWAP = "
<<
nbswap
<<
std
::
endl
;
}
}
}
// namespace SVG
}
// namespace Render
}
// namespace Algo
...
...
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