summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CsgInfo.h70
-rw-r--r--src/GLView.h4
-rw-r--r--src/OpenCSGRenderer.cc51
-rw-r--r--src/OpenCSGRenderer.h5
-rw-r--r--src/Preferences.cc2
-rw-r--r--src/export_png.cc27
-rw-r--r--src/rendersettings.cc3
-rw-r--r--src/rendersettings.h2
8 files changed, 78 insertions, 86 deletions
diff --git a/src/CsgInfo.h b/src/CsgInfo.h
index 4107b1a..816071f 100644
--- a/src/CsgInfo.h
+++ b/src/CsgInfo.h
@@ -2,38 +2,78 @@
#define __CSGINFO_H__
#include "OffscreenView.h"
-
-class CsgInfo
-{
-public:
- CsgInfo() { glview = NULL; }
- OffscreenView *glview;
-};
-
-
-#ifdef ENABLE_OPENCSG
-
#include "csgterm.h"
+#include "Tree.h"
+#include "CGALEvaluator.h"
+#include "CSGTermEvaluator.h"
+#include "csgtermnormalizer.h"
+#include "rendersettings.h"
-class CsgInfo_OpenCSG : public CsgInfo
+class CsgInfo
{
public:
- CsgInfo_OpenCSG()
+ CsgInfo()
{
root_chain = NULL;
highlights_chain = NULL;
background_chain = NULL;
glview = NULL;
}
+ OffscreenView *glview;
shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
class CSGChain *root_chain;
std::vector<shared_ptr<CSGTerm> > highlight_terms;
CSGChain *highlights_chain;
std::vector<shared_ptr<CSGTerm> > background_terms;
CSGChain *background_chain;
-};
-#endif // ENABLE_OPENCSG
+ bool prep_chains( const Tree &tree )
+ {
+ const AbstractNode *root_node = tree.root();
+ CGALEvaluator cgalevaluator(tree);
+ CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator);
+ boost::shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm( *root_node, this->highlight_terms, this->background_terms );
+
+ if (!root_raw_term) {
+ fprintf(stderr, "Error: CSG generation failed! (no top level object found)\n");
+ return false;
+ }
+
+ // CSG normalization
+ CSGTermNormalizer normalizer( RenderSettings::inst()->openCSGTermLimit );
+ this->root_norm_term = normalizer.normalize(root_raw_term);
+ if (this->root_norm_term) {
+ this->root_chain = new CSGChain();
+ this->root_chain->import(this->root_norm_term);
+ fprintf(stderr, "Normalized CSG tree has %d elements\n", int(this->root_chain->polysets.size()));
+ }
+ else {
+ this->root_chain = NULL;
+ fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n");
+ }
+
+ if (this->highlight_terms.size() > 0) {
+ std::cerr << "Compiling highlights (" << this->highlight_terms.size() << " CSG Trees)...\n";
+
+ this->highlights_chain = new CSGChain();
+ for (unsigned int i = 0; i < this->highlight_terms.size(); i++) {
+ this->highlight_terms[i] = normalizer.normalize(this->highlight_terms[i]);
+ this->highlights_chain->import(this->highlight_terms[i]);
+ }
+ }
+
+ if (this->background_terms.size() > 0) {
+ std::cerr << "Compiling background (" << this->background_terms.size() << " CSG Trees)...\n";
+
+ this->background_chain = new CSGChain();
+ for (unsigned int i = 0; i < this->background_terms.size(); i++) {
+ this->background_terms[i] = normalizer.normalize(this->background_terms[i]);
+ this->background_chain->import(this->background_terms[i]);
+ }
+ }
+ return true;
+ }
+};
#endif
diff --git a/src/GLView.h b/src/GLView.h
index 5d52e05..30d3c03 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -14,8 +14,8 @@ There are two different types of cameras
*Vector camera - uses 'eye', 'center', and 'up' vectors
Currently, the two cameras are not kept in sync and they are not easily
-interchangable in code QGLView uses GimbalCamera while OffscreenView can
-use both (but defaults to Vector)
+interchangable. QGLView uses GimbalCamera while OffscreenView can
+use either (defaulting to Vector).
*/
diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc
index e4ed928..8e4aba9 100644
--- a/src/OpenCSGRenderer.cc
+++ b/src/OpenCSGRenderer.cc
@@ -133,54 +133,3 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
}
std::for_each(primitives.begin(), primitives.end(), del_fun<OpenCSG::Primitive>());
}
-
-// miscellaneous code to prep OpenCSG render.
-// returns 0 on success, 1 on failure
-// csgInfo gets modified
-int opencsg_prep( const Tree &tree, const AbstractNode *root_node, CsgInfo_OpenCSG &csgInfo )
-{
- CGALEvaluator cgalevaluator(tree);
- CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator);
- boost::shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm(*root_node,
- csgInfo.highlight_terms,
- csgInfo.background_terms);
-
- if (!root_raw_term) {
- std::cerr << "Error: CSG generation failed! (no top level object found)\n";
- return 1;
- }
-
- // CSG normalization
- CSGTermNormalizer normalizer(5000);
- csgInfo.root_norm_term = normalizer.normalize(root_raw_term);
- if (csgInfo.root_norm_term) {
- csgInfo.root_chain = new CSGChain();
- csgInfo.root_chain->import(csgInfo.root_norm_term);
- fprintf(stderr, "Normalized CSG tree has %d elements\n", int(csgInfo.root_chain->polysets.size()));
- }
- else {
- csgInfo.root_chain = NULL;
- fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n");
- }
-
- if (csgInfo.highlight_terms.size() > 0) {
- std::cerr << "Compiling highlights (" << csgInfo.highlight_terms.size() << " CSG Trees)...\n";
-
- csgInfo.highlights_chain = new CSGChain();
- for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) {
- csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]);
- csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]);
- }
- }
-
- if (csgInfo.background_terms.size() > 0) {
- std::cerr << "Compiling background (" << csgInfo.background_terms.size() << " CSG Trees)...\n";
-
- csgInfo.background_chain = new CSGChain();
- for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) {
- csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]);
- csgInfo.background_chain->import(csgInfo.background_terms[i]);
- }
- }
- return 0;
-}
diff --git a/src/OpenCSGRenderer.h b/src/OpenCSGRenderer.h
index 9a24c1c..e6091aa 100644
--- a/src/OpenCSGRenderer.h
+++ b/src/OpenCSGRenderer.h
@@ -20,9 +20,4 @@ private:
GLint *shaderinfo;
};
-#include "Tree.h"
-#include "CsgInfo.h"
-// should we refactor this into the renderer class?
-int opencsg_prep( const Tree &tree, const AbstractNode *root_node, CsgInfo_OpenCSG &csgInfo );
-
#endif
diff --git a/src/Preferences.cc b/src/Preferences.cc
index 7c7aee4..0f3115e 100644
--- a/src/Preferences.cc
+++ b/src/Preferences.cc
@@ -83,7 +83,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
#ifdef ENABLE_CGAL
this->defaultmap["advanced/cgalCacheSize"] = uint(CGALCache::instance()->maxSize());
#endif
- this->defaultmap["advanced/openCSGLimit"] = 2000;
+ this->defaultmap["advanced/openCSGLimit"] = RenderSettings::inst()->openCSGTermLimit;
this->defaultmap["advanced/forceGoldfeather"] = false;
diff --git a/src/export_png.cc b/src/export_png.cc
index 3e618e5..8a6dd1d 100644
--- a/src/export_png.cc
+++ b/src/export_png.cc
@@ -4,6 +4,7 @@
#include "CsgInfo.h"
#include <stdio.h>
#include "polyset.h"
+#include "rendersettings.h"
#ifdef ENABLE_CGAL
#include "CGALRenderer.h"
@@ -12,9 +13,11 @@
void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream &output)
{
- CsgInfo csgInfo;
+ OffscreenView *glview;
+ int w = RenderSettings::inst()->img_width;
+ int h = RenderSettings::inst()->img_height;
try {
- csgInfo.glview = new OffscreenView(512,512);
+ glview = new OffscreenView( w, h );
} catch (int error) {
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error);
return;
@@ -44,10 +47,10 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream
//std::cerr << center << "\n";
//std::cerr << radius << "\n";
- csgInfo.glview->setCamera( cam );
- csgInfo.glview->setRenderer(&cgalRenderer);
- csgInfo.glview->paintGL();
- csgInfo.glview->save(output);
+ glview->setCamera( cam );
+ glview->setRenderer(&cgalRenderer);
+ glview->paintGL();
+ glview->save(output);
}
#ifdef ENABLE_OPENCSG
@@ -58,16 +61,16 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream
void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output)
{
#ifdef ENABLE_OPENCSG
- CsgInfo_OpenCSG csgInfo = CsgInfo_OpenCSG();
- AbstractNode const *root_node = tree.root();
- int result = opencsg_prep( tree, root_node, csgInfo );
- if ( result == 1 ) {
+ CsgInfo csgInfo = CsgInfo();
+ if ( !csgInfo.prep_chains( tree ) ) {
+ fprintf(stderr,"Couldn't initialize OpenCSG chains\n");
return;
- fprintf(stderr,"Couldn't init OpenCSG chainsn");
}
+ int w = RenderSettings::inst()->img_width;
+ int h = RenderSettings::inst()->img_height;
try {
- csgInfo.glview = new OffscreenView(512,512);
+ csgInfo.glview = new OffscreenView( w, h );
} catch (int error) {
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error);
return;
diff --git a/src/rendersettings.cc b/src/rendersettings.cc
index 195f2d8..0777324 100644
--- a/src/rendersettings.cc
+++ b/src/rendersettings.cc
@@ -12,6 +12,9 @@ RenderSettings *RenderSettings::inst(bool erase)
RenderSettings::RenderSettings()
{
+ openCSGTermLimit = 2000;
+ img_width = 512;
+ img_height = 512;
this->colors[BACKGROUND_COLOR] = Color4f(0xff, 0xff, 0xe5);
this->colors[OPENCSG_FACE_FRONT_COLOR] = Color4f(0xf9, 0xd7, 0x2c);
this->colors[OPENCSG_FACE_BACK_COLOR] = Color4f(0x9d, 0xcb, 0x51);
diff --git a/src/rendersettings.h b/src/rendersettings.h
index 15a0746..cb33981 100644
--- a/src/rendersettings.h
+++ b/src/rendersettings.h
@@ -25,6 +25,8 @@ public:
void setColors(const std::map<RenderColor, Color4f> &colors);
Color4f color(RenderColor idx);
+ unsigned int openCSGTermLimit, img_width, img_height;
+
private:
RenderSettings();
~RenderSettings() {}
contact: Jan Huwald // Impressum