forked from openscad/openscad
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCSGTreeEvaluator.h
More file actions
70 lines (60 loc) · 2.53 KB
/
CSGTreeEvaluator.h
File metadata and controls
70 lines (60 loc) · 2.53 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include <cstddef>
#include <list>
#include <map>
#include <memory>
#include <vector>
#include "core/BaseVisitable.h"
#include "core/CSGNode.h"
#include "core/ModuleInstantiation.h"
#include "core/NodeVisitor.h"
#include "core/enums.h"
#include "core/node.h"
#include "geometry/Geometry.h"
class CSGNode;
class GeometryEvaluator;
class Tree;
class CSGTreeEvaluator : public NodeVisitor
{
public:
CSGTreeEvaluator(const Tree& tree, GeometryEvaluator *geomevaluator = nullptr)
: tree(tree), geomevaluator(geomevaluator)
{
}
Response visit(State& state, const AbstractNode& node) override;
Response visit(State& state, const AbstractIntersectionNode& node) override;
Response visit(State& state, const AbstractPolyNode& node) override;
Response visit(State& state, const ListNode& node) override;
Response visit(State& state, const CsgOpNode& node) override;
Response visit(State& state, const TransformNode& node) override;
Response visit(State& state, const ColorNode& node) override;
Response visit(State& state, const RenderNode& node) override;
Response visit(State& state, const CgalAdvNode& node) override;
std::shared_ptr<CSGNode> buildCSGTree(const AbstractNode& node);
[[nodiscard]] const std::shared_ptr<CSGNode>& getRootNode() const { return this->rootNode; }
[[nodiscard]] const std::vector<std::shared_ptr<CSGNode>>& getHighlightNodes() const
{
return this->highlightNodes;
}
[[nodiscard]] const std::vector<std::shared_ptr<CSGNode>>& getBackgroundNodes() const
{
return this->backgroundNodes;
}
private:
void addToParent(const State& state, const AbstractNode& node);
void applyToChildren(State& state, const AbstractNode& node, OpenSCADOperator op);
std::shared_ptr<CSGNode> evaluateCSGNodeFromGeometry(State& state,
const std::shared_ptr<const Geometry>& geom,
const ModuleInstantiation *modinst,
const AbstractNode& node);
void applyBackgroundAndHighlight(State& state, const AbstractNode& node);
using ChildList = std::list<std::shared_ptr<const AbstractNode>>;
std::map<int, ChildList> visitedchildren;
protected:
const Tree& tree;
GeometryEvaluator *geomevaluator;
std::shared_ptr<CSGNode> rootNode;
std::vector<std::shared_ptr<CSGNode>> highlightNodes;
std::vector<std::shared_ptr<CSGNode>> backgroundNodes;
std::map<int, std::shared_ptr<CSGNode>> stored_term; // The term evaluated from each node index
};