diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/export_png.cc | 27 | ||||
-rw-r--r-- | src/linalg.h | 13 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/export_png.cc b/src/export_png.cc index 96e30fa..25e99a0 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -3,7 +3,9 @@ #include "OffscreenView.h" #include "CsgInfo.h" #include <stdio.h> - +#include "CGALRenderer.h" +#include "CGAL_renderer.h" +#include "cgal.h" #ifdef ENABLE_CGAL void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) @@ -14,6 +16,29 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) } catch (int error) { fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error); } + CGALRenderer cgalRenderer(*root_N); + + BoundingBox bbox; + if (cgalRenderer.polyhedron) { + CGAL::Bbox_3 cgalbbox = cgalRenderer.polyhedron->bbox(); + bbox = BoundingBox(Vector3d(cgalbbox.xmin(), cgalbbox.ymin(), cgalbbox.zmin()), + Vector3d(cgalbbox.xmax(), cgalbbox.ymax(), cgalbbox.zmax())); + } + else if (cgalRenderer.polyset) { + bbox = cgalRenderer.polyset->getBoundingBox(); + } + + Vector3d center = getBoundingCenter(bbox); + double radius = getBoundingRadius(bbox); + + Vector3d cameradir(1, 1, -0.5); + Vector3d camerapos = center - radius*2*cameradir; +/* + csgInfo.glview->setCamera(camerapos, center); + csgInfo.glview->setRenderer(&cgalRenderer); + csgInfo.glview->paintGL(); + csgInfo.glview->save(outfile); +*/ output << "solid OpenSCAD_Model\n"; output << "endsolid OpenSCAD_Model\n"; } diff --git a/src/linalg.h b/src/linalg.h index 48960b7..129ed3f 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -23,6 +23,19 @@ bool matrix_contains_nan( const Transform3d &m ); BoundingBox operator*(const Transform3d &m, const BoundingBox &box); +Vector3d getBoundingCenter(BoundingBox bbox) +{ + Vector3d center = (bbox.min() + bbox.max()) / 2; + return center; // Vector3d(0,0,0); +} + +double getBoundingRadius(BoundingBox bbox) +{ + double radius = (bbox.max() - bbox.min()).norm() / 2; + return radius; // 0; +} + + class Color4f : public Eigen::Vector4f { public: |