summaryrefslogtreecommitdiff
path: root/src/svg.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-03-11 02:35:30 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-03-11 02:35:30 (GMT)
commit5559ae9a6af459021c5b7ab4a823f491dce822a0 (patch)
treeccea074154b71c24ab0aee3150d4b07eef896a05 /src/svg.cc
parent33a54b52f2c54c4ac66881d63b852b472f5589f1 (diff)
move transform from CGALEvaluator to Nef_polyhedron - reuse in resize(). also
move ZRemover code to cgalutils, also cleanup SVG code
Diffstat (limited to 'src/svg.cc')
-rw-r--r--src/svg.cc106
1 files changed, 61 insertions, 45 deletions
diff --git a/src/svg.cc b/src/svg.cc
index 66e5797..c1231a5 100644
--- a/src/svg.cc
+++ b/src/svg.cc
@@ -2,13 +2,13 @@
#include "cgalutils.h"
#include "svg.h"
#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
#include <map>
namespace OpenSCAD {
// SVG code
// currently for debugging, not necessarily pretty or useful for users. (yet)
-int svg_cursor_py = 0;
int svg_px_width = SVG_PXW;
int svg_px_height = SVG_PXH;
@@ -27,6 +27,26 @@ std::string svg_label(std::string s)
return out.str();
}
+std::string svg_styleblock(std::string strokewidth)
+{
+ std::stringstream out;
+ // halfedge: f1/f0 = face mark, b1/b0 = body or hole, m1/m0 = halfedge mark
+ out << "\
+ <style type='text/css'>\n\
+ .halfedge_f0_b1_m0 { stroke: gold; stroke-width: __STROKEW__px } \n\
+ .halfedge_f0_b1_m1 { stroke: gold; stroke-width: __STROKEW__px } \n\
+ .halfedge_f0_b0_m0 { stroke: green; stroke-width: __STROKEW__px } \n\
+ .halfedge_f0_b0_m1 { stroke: green; stroke-width: __STROKEW__px } \n\
+ .halfedge_f1_b1_m0 { stroke: gold; stroke-width: __STROKEW__px } \n\
+ .halfedge_f1_b1_m1 { stroke: gold; stroke-width: __STROKEW__px } \n\
+ .halfedge_f1_b0_m0 { stroke: green; stroke-width: __STROKEW__px } \n\
+ .halfedge_f1_b0_m1 { stroke: green; stroke-width: __STROKEW__px } \n\
+ </style>";
+ std::string tmp = out.str();
+ boost::replace_all( tmp, "__STROKEW__", strokewidth );
+ return tmp;
+}
+
std::string svg_border()
{
std::stringstream out;
@@ -93,36 +113,27 @@ std::string dump_cgal_nef_polyhedron2_face_svg(
CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1,
CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2,
CGAL_Nef_polyhedron2::Explorer explorer,
- std::string color,
- bool mark,
- CGAL_Iso_rectangle_2e bbox )
+ bool facemark, bool body )
{
+ std::stringstream style;
+ style << "halfedge_f" << facemark << "_b" << body << "_m";
+ std::string styleclass = style.str();
+
std::stringstream out;
CGAL_For_all(c1, c2) {
if ( explorer.is_standard( explorer.target(c1) ) ) {
CGAL_Point_2e source = explorer.point( explorer.source( c1 ) );
CGAL_Point_2e target = explorer.point( explorer.target( c1 ) );
- CGAL_Point_2e tp1 = project_svg_2to2( source, bbox );
- CGAL_Point_2e tp2 = project_svg_2to2( target, bbox );
- double mod=0;
- if (color=="green") mod=10;
- out << " <!-- Halfedge. Mark: " << c1->mark() << " -->\n";
- out << " <line"
- << " x1='" << CGAL::to_double(tp1.x()) + mod << "'"
- << " y1='" << CGAL::to_double(tp1.y()) - mod << "'"
- << " x2='" << CGAL::to_double(tp2.x()) + mod << "'"
- << " y2='" << CGAL::to_double(tp2.y()) - mod << "'"
- << " stroke='" << color << "'";
- if (!mark) out << " stroke-dasharray='4 4' />\n";
- else out << " />\n";
- // crude "arrowhead" to indicate directionality
- out << " <circle"
- << " cx='" << CGAL::to_double(tp1.x()+ (tp2.x()-tp1.x())* 7/8) + mod << "'"
- << " cy='" << CGAL::to_double(tp1.y()+ (tp2.y()-tp1.y())* 7/8) - mod << "'"
- << " r='2'"
- << " fill='" << color << "' stroke='" << color << "' />\n";
+ out << " <!-- Halfedge. Mark: " << c1->mark() << " -->\n";
+ std::string he_mark = boost::lexical_cast<std::string>(c1->mark());
+ out << " <line"
+ << " x1='" << CGAL::to_double(source.x()) << "'"
+ << " y1='" << CGAL::to_double(source.y()) << "'"
+ << " x2='" << CGAL::to_double(target.x()) << "'"
+ << " y2='" << CGAL::to_double(target.y()) << "'"
+ << " class='" << styleclass + he_mark << "' />\n";
} else {
- out << " <!-- 2d Nef Rays - not implemented -->\n";
+ out << " <!-- 2d Nef Rays - not implemented -->\n";
}
}
return out.str();
@@ -132,27 +143,27 @@ std::string dump_svg( const CGAL_Nef_polyhedron2 &N )
{
std::stringstream out;
CGAL_Nef_polyhedron2::Explorer explorer = N.explorer();
-
CGAL_Iso_rectangle_2e bbox = bounding_box( N );
-
CGAL_Nef_polyhedron2::Explorer::Face_const_iterator i;
- out << " <svg y='" << svg_cursor_py << "' width='" << svg_px_width
- << "' height='" << svg_px_height
- << "' xmlns='http://www.w3.org/2000/svg' version='1.1'>\n";
- out << svg_border() << "\n" << svg_axes() << "\n";
- svg_cursor_py += svg_px_height;
+
+ std::string linewidth = "0.05";
+
+ out << "<!--CGAL_Nef_polyhedron2 dump begin-->\n";
+ out << svg_header() << "\n" << svg_styleblock( linewidth ) << "\n";
for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) {
out << " <!-- face begin. mark: " << i->mark() << " -->\n";
+ out << " <!-- body begin -->\n";
CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1
= explorer.face_cycle( i ), c2 ( c1 );
- out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, "red", i->mark(), bbox );
+ out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, i->mark(), true );
+ out << " <!-- body end -->\n";
CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j;
for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) {
out << " <!-- hole begin. mark: " << j->mark() << " -->\n";
CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 );
- out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", j->mark(), bbox );
+ out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", j->mark() );
out << " <!-- hole end -->\n";
}
out << " <!-- face end -->\n";
@@ -182,13 +193,13 @@ public:
void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet )
{
int contour_count = 0;
- out << " <!-- Halffacet. Mark: " << (*hfacet).mark() << " -->\n";
+ out << " <!-- Halffacet visit. Mark: " << (*hfacet).mark() << " -->\n";
std::string color = "gold";
if (!(*hfacet).mark()) color = "green";
CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator i;
CGAL_forall_facet_cycles_of( i, hfacet ) {
CGAL_Nef_polyhedron3::SHalfloop_const_handle shl_handle;
- out << " <!-- Halffacet cycle: -->\n";
+ out << " <!-- Halffacet cycle begin: -->\n";
if ( contour_count == 0 ) {
out << " <!-- Body contour:--> \n";
} else {
@@ -196,13 +207,15 @@ public:
}
CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(i), c2(c1);
CGAL_For_all( c1, c2 ) {
- out << " <line";
// don't know why we use source()->source(), except thats what CGAL does internally
CGAL_Point_3 source = c1->source()->source()->point();
CGAL_Point_3 target = c1->source()->target()->point();
CGAL_Point_2e tp1 = project_svg_3to2 ( source, bbox );
CGAL_Point_2e tp2 = project_svg_3to2 ( target, bbox );
- out << " "
+ out << " <!-- " << CGAL::to_double(source.x()) << ","
+ << CGAL::to_double(source.y()) << ","
+ << CGAL::to_double(source.z()) << " -->\n";
+ out << " <line "
<< "x1='" << CGAL::to_double(tp1.x()) << "' "
<< "y1='" << CGAL::to_double(tp1.y()) << "' "
<< "x2='" << CGAL::to_double(tp2.x()) << "' "
@@ -212,31 +225,34 @@ public:
else out << " />\n";
}
contour_count++;
- } // next facet cycle (i.e. next contour)
- } // visit()
-
+ out << " <!-- Halffacet cycle end -->\n";
+ }
+ out << " <!-- Halffacet visit end -->\n";
+ }
};
std::string dump_svg( const CGAL_Nef_polyhedron3 &N )
{
std::stringstream out;
- out << svg_header() << "\n" << svg_border() << "\n" << svg_axes() << "\n";
+ std::string linewidth = "0.05";
out << "<!--CGAL_Nef_polyhedron3 dump begin-->\n";
+ out << svg_header() << "\n" << svg_border() << "\n";
+ out << svg_styleblock( linewidth ) << "\n" << svg_axes() << "\n";
CGAL_Nef_polyhedron3::Volume_const_iterator c;
CGAL_forall_volumes(c,N) {
- out << " <!--Processing volume...-->\n";
+ out << " <!--Volume begin-->\n";
out << " <!--Mark: " << (*c).mark() << "-->\n";
CGAL_Nef_polyhedron3::Shell_entry_const_iterator it;
CGAL_forall_shells_of(it,c) {
- out << " <!--Processing shell...-->\n";
+ out << " <!--Shell begin-->\n";
NefPoly3_dumper_svg dumper_svg(N);
N.visit_shell_objects(CGAL_Nef_polyhedron3::SFace_const_handle(it), dumper_svg );
out << dumper_svg.out.str();
- out << " <!--Processing shell end-->\n";
+ out << " <!--Shell end-->\n";
}
- out << " <!--Processing volume end-->\n";
+ out << " <!--Volume end-->\n";
}
out << "<!--CGAL_Nef_polyhedron3 dump end-->\n";
out << "</svg>";
contact: Jan Huwald // Impressum