summaryrefslogtreecommitdiff
path: root/test-code/CSGTextRenderer.h
blob: 84f3d30c5f9489c872b140fec62a16a9c3137149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef CSGTEXTRENDERER_H_
#define CSGTEXTRENDERER_H_

#include <string>
#include <map>
#include <list>
#include "visitor.h"
#include "nodecache.h"

using std::string;
using std::map;
using std::list;
using std::pair;

class CSGTextRenderer : public Visitor
{
public:
	enum CsgOp {UNION, INTERSECTION, DIFFERENCE, MINKOWSKI};
	CSGTextRenderer(const NodeCache<string> &dumpcache) : root(NULL), dumpcache(dumpcache) {}
  virtual ~CSGTextRenderer() {}

  virtual Response visit(const State &state, const AbstractNode &node);
	virtual Response visit(const State &state, const AbstractIntersectionNode &node);
	virtual Response visit(const State &state, const CsgNode &node);
	virtual Response visit(const State &state, const TransformNode &node);
	virtual Response visit(const State &state, const AbstractPolyNode &node);

	string getCGALMesh() const;
// 	CGAL_Nef_polyhedron getCGALMesh() const;
private:
  void addToParent(const State &state, const AbstractNode &node);
  bool isCached(const AbstractNode &node);
	QString mk_cache_id(const AbstractNode &node) const;
	void process(string &target, const string &src, CSGTextRenderer::CsgOp op);
	void applyToChildren(const AbstractNode &node, CSGTextRenderer::CsgOp op);

  string currindent;
  const AbstractNode *root;
  typedef list<pair<const AbstractNode *, QString> > ChildList;
  map<int, ChildList> visitedchildren;
//	hashmap<string, CGAL_Nef_polyhedron> cache;

  // For now use strings instead of Nef polyhedrons for testing caching
	QHash<QString, string> cache;
	const NodeCache<string> &dumpcache;
};

#endif
contact: Jan Huwald // Impressum