1 #pragma once
2 
3 #include "NodeVisitor.h"
4 #include "enums.h"
5 #include "memory.h"
6 #include "Geometry.h"
7 
8 #include <utility>
9 #include <list>
10 #include <vector>
11 #include <map>
12 
13 class GeometryEvaluator : public NodeVisitor
14 {
15 public:
16 	GeometryEvaluator(const class Tree &tree);
~GeometryEvaluator()17 	~GeometryEvaluator() {}
18 
19 	shared_ptr<const Geometry> evaluateGeometry(const AbstractNode &node, bool allownef);
20 
21 	Response visit(State &state, const AbstractNode &node) override;
22 	Response visit(State &state, const AbstractIntersectionNode &node) override;
23 	Response visit(State &state, const AbstractPolyNode &node) override;
24 	Response visit(State &state, const LinearExtrudeNode &node) override;
25 	Response visit(State &state, const RotateExtrudeNode &node) override;
26 	Response visit(State &state, const ListNode &node) override;
27 	Response visit(State &state, const GroupNode &node) override;
28 	Response visit(State &state, const RootNode &node) override;
29 	Response visit(State &state, const LeafNode &node) override;
30 	Response visit(State &state, const TransformNode &node) override;
31 	Response visit(State &state, const CsgOpNode &node) override;
32 	Response visit(State &state, const CgaladvNode &node) override;
33 	Response visit(State &state, const ProjectionNode &node) override;
34 	Response visit(State &state, const RenderNode &node) override;
35 	Response visit(State &state, const TextNode &node) override;
36 	Response visit(State &state, const OffsetNode &node) override;
37 
getTree()38 	const Tree &getTree() const { return this->tree; }
39 
40 private:
41 	class ResultObject {
42 	public:
43 		// Default constructor with nullptr can be used to represent empty geometry,
44 		// for example union() with no children, etc.
ResultObject()45 		ResultObject() : is_const(true) {}
ResultObject(const Geometry * g)46 		ResultObject(const Geometry *g) : is_const(true), const_pointer(g) {}
ResultObject(shared_ptr<const Geometry> & g)47 		ResultObject(shared_ptr<const Geometry> &g) : is_const(true), const_pointer(g) {}
ResultObject(Geometry * g)48 		ResultObject(Geometry *g) : is_const(false), pointer(g) {}
ResultObject(shared_ptr<Geometry> & g)49 		ResultObject(shared_ptr<Geometry> &g) : is_const(false), pointer(g) {}
isConst()50 		bool isConst() const { return is_const; }
ptr()51 		shared_ptr<Geometry> ptr() { assert(!is_const); return pointer; }
constptr()52 		shared_ptr<const Geometry> constptr() const {
53 			return is_const ? const_pointer : static_pointer_cast<const Geometry>(pointer);
54 		}
55 	private:
56 		bool is_const;
57 		shared_ptr<Geometry> pointer;
58 		shared_ptr<const Geometry> const_pointer;
59 	};
60 
61 	void smartCacheInsert(const AbstractNode &node, const shared_ptr<const Geometry> &geom);
62 	shared_ptr<const Geometry> smartCacheGet(const AbstractNode &node, bool preferNef);
63 	bool isSmartCached(const AbstractNode &node);
64 	bool isValidDim(const Geometry::GeometryItem &item, unsigned int &dim) const;
65 	std::vector<const class Polygon2d *> collectChildren2D(const AbstractNode &node);
66 	Geometry::Geometries collectChildren3D(const AbstractNode &node);
67 	Polygon2d *applyMinkowski2D(const AbstractNode &node);
68 	Polygon2d *applyHull2D(const AbstractNode &node);
69 	Geometry *applyHull3D(const AbstractNode &node);
70 	void applyResize3D(class CGAL_Nef_polyhedron &N, const Vector3d &newsize, const Eigen::Matrix<bool,3,1> &autosize);
71 	Polygon2d *applyToChildren2D(const AbstractNode &node, OpenSCADOperator op);
72 	ResultObject applyToChildren3D(const AbstractNode &node, OpenSCADOperator op);
73 	ResultObject applyToChildren(const AbstractNode &node, OpenSCADOperator op);
74 	void addToParent(const State &state, const AbstractNode &node, const shared_ptr<const Geometry> &geom);
75 	Response lazyEvaluateRootNode(State &state, const AbstractNode& node);
76 
77 	std::map<int, Geometry::Geometries> visitedchildren;
78 	const Tree &tree;
79 	shared_ptr<const Geometry> root;
80 
81 public:
82 };
83