bugfix: background and highlight was broken after refactoring

stl_dim
Marius Kintel 2011-08-06 01:08:11 +02:00
parent b9608dd2f8
commit cfea2f8934
3 changed files with 34 additions and 31 deletions

View File

@ -22,12 +22,14 @@
with OpenCSG. with OpenCSG.
*/ */
CSGTerm *CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node, CSGTerm *CSGTermEvaluator::evaluateCSGTerm(const AbstractNode &node,
vector<CSGTerm*> *highlights, std::vector<CSGTerm*> &highlights,
vector<CSGTerm*> *background) std::vector<CSGTerm*> &background)
{ {
Traverser evaluate(*this, node, Traverser::PRE_AND_POSTFIX); Traverser evaluate(*this, node, Traverser::PRE_AND_POSTFIX);
evaluate.execute(); evaluate.execute();
highlights = this->highlights;
background = this->background;
return this->stored_term[node.index()]; return this->stored_term[node.index()];
} }
@ -52,11 +54,11 @@ void CSGTermEvaluator::applyToChildren(const AbstractNode &node, CSGTermEvaluato
} }
} }
} }
if (t1 && node.modinst->tag_highlight && this->highlights) { if (t1 && node.modinst->tag_highlight) {
this->highlights->push_back(t1->link()); this->highlights.push_back(t1->link());
} }
if (t1 && node.modinst->tag_background && this->background) { if (t1 && node.modinst->tag_background) {
this->background->push_back(t1); this->background.push_back(t1);
t1 = NULL; // don't propagate background tagged nodes t1 = NULL; // don't propagate background tagged nodes
} }
this->stored_term[node.index()] = t1; this->stored_term[node.index()] = t1;
@ -81,17 +83,17 @@ Response CSGTermEvaluator::visit(State &state, const AbstractIntersectionNode &n
} }
static CSGTerm *evaluate_csg_term_from_ps(const double m[20], static CSGTerm *evaluate_csg_term_from_ps(const double m[20],
vector<CSGTerm*> *highlights, vector<CSGTerm*> &highlights,
vector<CSGTerm*> *background, vector<CSGTerm*> &background,
PolySet *ps, PolySet *ps,
const ModuleInstantiation *modinst, const ModuleInstantiation *modinst,
const AbstractPolyNode &node) const AbstractPolyNode &node)
{ {
CSGTerm *t = new CSGTerm(ps, m, QString("%1%2").arg(node.name().c_str()).arg(node.index())); CSGTerm *t = new CSGTerm(ps, m, QString("%1%2").arg(node.name().c_str()).arg(node.index()));
if (modinst->tag_highlight && highlights) if (modinst->tag_highlight)
highlights->push_back(t->link()); highlights.push_back(t->link());
if (modinst->tag_background && background) { if (modinst->tag_background) {
background->push_back(t); background.push_back(t);
return NULL; return NULL;
} }
return t; return t;
@ -190,7 +192,7 @@ void CSGTermEvaluator::addToParent(const State &state, const AbstractNode &node)
// FIXME: #ifdef ENABLE_CGAL // FIXME: #ifdef ENABLE_CGAL
#if 0 #if 0
CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> &highlights, QVector<CSGTerm*> &background) const
{ {
if (type == MINKOWSKI) if (type == MINKOWSKI)
return evaluate_csg_term_from_nef(m, highlights, background, "minkowski", this->convexity); return evaluate_csg_term_from_nef(m, highlights, background, "minkowski", this->convexity);
@ -209,7 +211,7 @@ CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlig
#else // ENABLE_CGAL #else // ENABLE_CGAL
CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> &highlights, QVector<CSGTerm*> &background) const
{ {
PRINT("WARNING: Found minkowski(), glide(), subdiv() or hull() statement but compiled without CGAL support!"); PRINT("WARNING: Found minkowski(), glide(), subdiv() or hull() statement but compiled without CGAL support!");
return NULL; return NULL;
@ -221,7 +223,7 @@ CSGTerm *CgaladvNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlig
// FIXME: #ifdef ENABLE_CGAL // FIXME: #ifdef ENABLE_CGAL
#if 0 #if 0
CSGTerm *AbstractNode::evaluate_csg_term_from_nef(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, const char *statement, int convexity) const CSGTerm *AbstractNode::evaluate_csg_term_from_nef(double m[20], QVector<CSGTerm*> &highlights, QVector<CSGTerm*> &background, const char *statement, int convexity) const
{ {
QString key = mk_cache_id(); QString key = mk_cache_id();
if (PolySet::ps_cache.contains(key)) { if (PolySet::ps_cache.contains(key)) {
@ -302,10 +304,10 @@ CSGTerm *AbstractNode::evaluate_csg_term_from_nef(double m[20], QVector<CSGTerm*
PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link())); PolySet::ps_cache.insert(key, new PolySet::ps_cache_entry(ps->link()));
CSGTerm *term = new CSGTerm(ps, m, QString("n%1").arg(idx)); CSGTerm *term = new CSGTerm(ps, m, QString("n%1").arg(idx));
if (modinst->tag_highlight && highlights) if (modinst->tag_highlight)
highlights->push_back(term->link()); highlights.push_back(term->link());
if (modinst->tag_background && background) { if (modinst->tag_background) {
background->push_back(term); background.push_back(term);
return NULL; return NULL;
} }
return term; return term;
@ -315,14 +317,14 @@ CSGTerm *AbstractNode::evaluate_csg_term_from_nef(double m[20], QVector<CSGTerm*
return NULL; return NULL;
} }
CSGTerm *RenderNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const CSGTerm *RenderNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> &highlights, QVector<CSGTerm*> &background) const
{ {
return evaluate_csg_term_from_nef(m, highlights, background, "render", this->convexity); return evaluate_csg_term_from_nef(m, highlights, background, "render", this->convexity);
} }
#else #else
CSGTerm *RenderNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const CSGTerm *RenderNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> &highlights, QVector<CSGTerm*> &background) const
{ {
CSGTerm *t1 = NULL; CSGTerm *t1 = NULL;
PRINT("WARNING: Found render() statement but compiled without CGAL support!"); PRINT("WARNING: Found render() statement but compiled without CGAL support!");
@ -334,10 +336,10 @@ CSGTerm *RenderNode::evaluate_csg_term(double m[20], QVector<CSGTerm*> *highligh
t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2); t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
} }
} }
if (modinst->tag_highlight && highlights) if (modinst->tag_highlight)
highlights->push_back(t1->link()); highlights.push_back(t1->link());
if (t1 && modinst->tag_background && background) { if (t1 && modinst->tag_background) {
background->push_back(t1); background.push_back(t1);
return NULL; return NULL;
} }
return t1; return t1;

View File

@ -18,7 +18,7 @@ class CSGTermEvaluator : public Visitor
{ {
public: public:
CSGTermEvaluator(const Tree &tree, class PolySetEvaluator *psevaluator = NULL) CSGTermEvaluator(const Tree &tree, class PolySetEvaluator *psevaluator = NULL)
: highlights(NULL), background(NULL), tree(tree), psevaluator(psevaluator) { : tree(tree), psevaluator(psevaluator) {
} }
virtual ~CSGTermEvaluator() {} virtual ~CSGTermEvaluator() {}
@ -30,7 +30,8 @@ public:
virtual Response visit(State &state, const RenderNode &node); virtual Response visit(State &state, const RenderNode &node);
class CSGTerm *evaluateCSGTerm(const AbstractNode &node, class CSGTerm *evaluateCSGTerm(const AbstractNode &node,
vector<CSGTerm*> *highlights, vector<CSGTerm*> *background); vector<CSGTerm*> &highlights,
vector<CSGTerm*> &background);
private: private:
enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI}; enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI};
@ -44,8 +45,8 @@ private:
public: public:
map<int, class CSGTerm*> stored_term; // The term evaluated from each node index map<int, class CSGTerm*> stored_term; // The term evaluated from each node index
vector<CSGTerm*> *highlights; vector<CSGTerm*> highlights;
vector<CSGTerm*> *background; vector<CSGTerm*> background;
const Tree &tree; const Tree &tree;
class PolySetEvaluator *psevaluator; class PolySetEvaluator *psevaluator;
}; };

View File

@ -779,7 +779,7 @@ void MainWindow::compileCSG(bool procevents)
CGALEvaluator cgalevaluator(cache, this->tree); CGALEvaluator cgalevaluator(cache, this->tree);
PolySetCGALEvaluator psevaluator(cgalevaluator); PolySetCGALEvaluator psevaluator(cgalevaluator);
CSGTermEvaluator csgrenderer(this->tree, &psevaluator); CSGTermEvaluator csgrenderer(this->tree, &psevaluator);
root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, &highlight_terms, &background_terms); root_raw_term = csgrenderer.evaluateCSGTerm(*root_node, highlight_terms, background_terms);
if (!root_raw_term) { if (!root_raw_term) {
PRINT("ERROR: CSG generation failed! (no top level object found)"); PRINT("ERROR: CSG generation failed! (no top level object found)");
if (procevents) if (procevents)