summaryrefslogtreecommitdiff
path: root/src/OpenCSGRenderer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/OpenCSGRenderer.cc')
-rw-r--r--src/OpenCSGRenderer.cc57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc
index eb66687..e4ed928 100644
--- a/src/OpenCSGRenderer.cc
+++ b/src/OpenCSGRenderer.cc
@@ -38,7 +38,7 @@ class OpenCSGPrim : public OpenCSG::Primitive
public:
OpenCSGPrim(OpenCSG::Operation operation, unsigned int convexity) :
OpenCSG::Primitive(operation, convexity) { }
- shared_ptr<PolySet> ps;
+ boost::shared_ptr<PolySet> ps;
Transform3d m;
PolySet::csgmode_e csgmode;
virtual void render() {
@@ -71,6 +71,10 @@ void OpenCSGRenderer::draw(bool /*showfaces*/, bool showedges) const
}
}
+#include "CGALEvaluator.h"
+#include "CSGTermEvaluator.h"
+#include "csgtermnormalizer.h"
+
void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
bool highlight, bool background) const
{
@@ -129,3 +133,54 @@ 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;
+}
contact: Jan Huwald // Impressum