diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-03-03 15:22:36 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-03-03 15:22:36 (GMT) |
commit | 0f6b76cf2125828ce11ec9f6f47cfc26860d3571 (patch) | |
tree | 62e30a3bbcacfcf1a22134f6ffad6aaefcc295b6 /src/CsgInfo.h | |
parent | eb1f73de0393bd890c9648932ae2e04de2c65ba3 (diff) |
move csg chain prep code to CsgInfo.h, move defaults to rendersettings.h
Diffstat (limited to 'src/CsgInfo.h')
-rw-r--r-- | src/CsgInfo.h | 70 |
1 files changed, 55 insertions, 15 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 |