diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-09-12 05:42:38 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-09-12 05:42:38 (GMT) |
commit | 4e1b1900ed22962add76357f0248decb71a9e4ac (patch) | |
tree | 0342fea8801b684d82ca6514603898fe7b789ba9 /src | |
parent | 6af6c311a12a0211545e29666c92f1806ca0c7e8 (diff) |
remove redundant code
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 4 | ||||
-rw-r--r-- | src/export_png.cc | 65 |
2 files changed, 29 insertions, 40 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index adaec4a..09070d5 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -216,7 +216,7 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) bbox_size.push_back( bb.ymax()-bb.ymin() ); bbox_size.push_back( bb.zmax()-bb.zmin() ); int newsizemax_index = 0; - for (int i=0;i<3;i++) { + for (int i=0;i<N.dim;i++) { if (node.newsize[i]) { if (bbox_size[i]==NT3(0)) { PRINT("WARNING: Resize in direction normal to flat object is not implemented"); @@ -230,7 +230,7 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) } } NT3 autoscale = NT3( node.newsize[ newsizemax_index ] ) / bbox_size[ newsizemax_index ]; - for (int i=0;i<3;i++) { + for (int i=0;i<N.dim;i++) { if (node.autosize[i] && node.newsize[i]==0) scale[i] = autoscale; } diff --git a/src/export_png.cc b/src/export_png.cc index fcc64fc..07c4398 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -50,17 +50,19 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream glview->save(output); } +enum Previewer { OPENCSG, THROWN } previewer; + #ifdef ENABLE_OPENCSG #include "OpenCSGRenderer.h" #include <opencsg.h> #endif +#include "ThrownTogetherRenderer.h" -void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) +void export_png_preview_common( Tree &tree, Camera &cam, std::ostream &output, Previewer previewer = OPENCSG ) { -#ifdef ENABLE_OPENCSG CsgInfo csgInfo = CsgInfo(); if ( !csgInfo.compile_chains( tree ) ) { - fprintf(stderr,"Couldn't initialize OpenCSG chains\n"); + fprintf(stderr,"Couldn't initialize CSG chains\n"); return; } @@ -71,7 +73,16 @@ void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) return; } - OpenCSGRenderer opencsgRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo); + Renderer *renderer; + if ( previewer == OPENCSG) { +#ifdef ENABLE_OPENCSG + OpenCSGRenderer openCSGRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo); + renderer = &openCSGRenderer; +#endif + } else { + ThrownTogetherRenderer thrownTogetherRenderer( csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain ); + renderer = &thrownTogetherRenderer; + } if (cam.type == Camera::NONE) { cam.type = Camera::VECTOR; @@ -86,51 +97,29 @@ void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) } csgInfo.glview->setCamera( cam ); - csgInfo.glview->setRenderer(&opencsgRenderer); +#ifdef ENABLE_OPENCSG + csgInfo.glview->setRenderer(renderer); OpenCSG::setContext(0); OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject); +#else + csgInfo.glview->setRenderer(renderer); +#endif csgInfo.glview->paintGL(); csgInfo.glview->save(output); +} + +void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) +{ +#ifdef ENABLE_OPENCSG + export_png_preview_common( tree, cam, output, OPENCSG ); #else fprintf(stderr,"This openscad was built without OpenCSG support\n"); #endif } -#include "ThrownTogetherRenderer.h" void export_png_with_throwntogether(Tree &tree, Camera &cam, std::ostream &output) { - CsgInfo csgInfo = CsgInfo(); - if ( !csgInfo.compile_chains( tree ) ) { - fprintf(stderr,"Couldn't initialize OpenCSG chains\n"); - return; - } - - try { - csgInfo.glview = new OffscreenView( cam.pixel_width, cam.pixel_height ); - } catch (int error) { - fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error); - return; - } - - ThrownTogetherRenderer thrownTogetherRenderer( csgInfo.root_chain, - csgInfo.highlights_chain, csgInfo.background_chain ); - - if (cam.type == Camera::NONE) { - cam.type = Camera::VECTOR; - double radius = 1.0; - if (csgInfo.root_chain) { - BoundingBox bbox = csgInfo.root_chain->getBoundingBox(); - cam.center = (bbox.min() + bbox.max()) / 2; - radius = (bbox.max() - bbox.min()).norm() / 2; - } - Vector3d cameradir(1, 1, -0.5); - cam.eye = cam.center - radius*1.8*cameradir; - } - - csgInfo.glview->setCamera( cam ); - csgInfo.glview->setRenderer(&thrownTogetherRenderer); - csgInfo.glview->paintGL(); - csgInfo.glview->save(output); + export_png_preview_common( tree, cam, output, THROWN ); } |