summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2010-09-07 00:02:22 (GMT)
committerMarius Kintel <marius@kintel.net>2010-10-31 00:42:39 (GMT)
commitfdcbb4cf9744151f901d6dba9f04a29c2ea75c92 (patch)
tree24330f1bedf104a15a1b5e11786f742af12ba495
parent3f66c23731f0711dd1158f2cded7f0bf313617d4 (diff)
Improved CSGTermRenderer to a testable point
-rw-r--r--src/CSGTermRenderer.cc10
-rw-r--r--src/CSGTermRenderer.h6
-rw-r--r--src/MainWindow.h5
-rw-r--r--src/Tree.h4
-rw-r--r--src/mainwin.cc34
-rw-r--r--src/node.h5
6 files changed, 38 insertions, 26 deletions
diff --git a/src/CSGTermRenderer.cc b/src/CSGTermRenderer.cc
index 412f09f..e59df1c 100644
--- a/src/CSGTermRenderer.cc
+++ b/src/CSGTermRenderer.cc
@@ -22,6 +22,16 @@
with OpenCSG.
*/
+CSGTerm *CSGTermRenderer::renderCSGTerm(const AbstractNode &node,
+ vector<CSGTerm*> *highlights,
+ vector<CSGTerm*> *background)
+{
+ CSGTermRenderer renderer;
+ Traverser render(renderer, node, Traverser::PRE_AND_POSTFIX);
+ render.execute();
+ return renderer.stored_term[node.index()];
+}
+
void CSGTermRenderer::applyToChildren(const AbstractNode &node, CSGTermRenderer::CsgOp op)
{
CSGTerm *t1 = NULL;
diff --git a/src/CSGTermRenderer.h b/src/CSGTermRenderer.h
index 462ece2..d992b76 100644
--- a/src/CSGTermRenderer.h
+++ b/src/CSGTermRenderer.h
@@ -16,7 +16,8 @@ using std::vector;
class CSGTermRenderer : public Visitor
{
public:
- CSGTermRenderer() {}
+ CSGTermRenderer() : highlights(NULL), background(NULL) {
+ }
virtual ~CSGTermRenderer() {}
virtual Response visit(State &state, const AbstractNode &node);
@@ -26,6 +27,9 @@ public:
virtual Response visit(State &state, const TransformNode &node);
virtual Response visit(State &state, const RenderNode &node);
+ class CSGTerm *renderCSGTerm(const AbstractNode &node,
+ vector<CSGTerm*> *highlights, vector<CSGTerm*> *background);
+
private:
enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI};
void addToParent(const State &state, const AbstractNode &node);
diff --git a/src/MainWindow.h b/src/MainWindow.h
index 132035a..f555906 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -9,6 +9,7 @@
#include "polyset.h"
#include "Tree.h"
#include <QPointer>
+#include <vector>
class MainWindow : public QMainWindow, public Ui::MainWindow
{
@@ -45,9 +46,9 @@ public:
PolySet *cgal_ogl_ps;
#endif
- QVector<CSGTerm*> highlight_terms;
+ std::vector<CSGTerm*> highlight_terms;
CSGChain *highlights_chain;
- QVector<CSGTerm*> background_terms;
+ std::vector<CSGTerm*> background_terms;
CSGChain *background_chain;
QString last_compiled_doc;
bool enableOpenCSG;
diff --git a/src/Tree.h b/src/Tree.h
index fec4464..88c55cb 100644
--- a/src/Tree.h
+++ b/src/Tree.h
@@ -8,9 +8,7 @@ using std::string;
class Tree
{
public:
- Tree() {
- this->root_node = NULL;
- }
+ Tree(const AbstractNode *root = NULL) : root_node(root) {}
~Tree() {}
void setRoot(const AbstractNode *root) { this->root_node = root; }
diff --git a/src/mainwin.cc b/src/mainwin.cc
index f885cd4..88b7d40 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -40,6 +40,7 @@
#include "progress.h"
#ifdef ENABLE_OPENCSG
#include "render-opencsg.h"
+#include "CSGTermRenderer.h"
#endif
#ifdef USE_PROGRESSWIDGET
#include "ProgressWidget.h"
@@ -74,6 +75,11 @@
#include "qlanguagefactory.h"
#endif
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+using namespace boost::lambda;
+
//for chdir
#include <unistd.h>
@@ -572,22 +578,19 @@ void MainWindow::compile(bool procevents)
this->root_chain = NULL;
}
- foreach(CSGTerm *v, this->highlight_terms) {
- v->unlink();
- }
+ std::for_each(this->highlight_terms.begin(), this->highlight_terms.end(),
+ bind(&CSGTerm::unlink, _1));
+
this->highlight_terms.clear();
- if (this->highlights_chain) {
- delete this->highlights_chain;
- this->highlights_chain = NULL;
- }
- foreach(CSGTerm *v, this->background_terms) {
- v->unlink();
- }
+ delete this->highlights_chain;
+ this->highlights_chain = NULL;
+
+ std::for_each(this->background_terms.begin(), this->background_terms.end(),
+ bind(&CSGTerm::unlink, _1));
this->background_terms.clear();
- if (this->background_chain) {
- delete this->background_chain;
- this->background_chain = NULL;
- }
+ delete this->background_chain;
+ this->background_chain = NULL;
+
this->root_node = NULL;
this->enableOpenCSG = false;
@@ -727,7 +730,8 @@ void MainWindow::compileCSG(bool procevents)
progress_report_prep(root_node, report_func, pd);
try {
- root_raw_term = root_node->render_csg_term(m, &highlight_terms, &background_terms);
+ CSGTermRenderer renderer;
+ root_raw_term = renderer.renderCSGTerm(*root_node, &highlight_terms, &background_terms);
if (!root_raw_term) {
PRINT("ERROR: CSG generation failed! (no top level object found)");
if (procevents)
diff --git a/src/node.h b/src/node.h
index db1f8e2..9127ae1 100644
--- a/src/node.h
+++ b/src/node.h
@@ -54,11 +54,6 @@ public:
void progress_report() const;
int idx; // Node index (unique per tree)
-
- // FIXME: Rewrite to visitor
-#ifdef ENABLE_CGAL
- class CSGTerm *render_csg_term_from_nef(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, const char *statement, int convexity) const;
-#endif
};
class AbstractIntersectionNode : public AbstractNode
contact: Jan Huwald // Impressum