summaryrefslogtreecommitdiff
path: root/src/csgterm.h
blob: 94878e5fceb77a9ce5e56840dba523e53c3e1e9e (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef CSGTERM_H_
#define CSGTERM_H_

#include <string>
#include <vector>
#include "memory.h"
#include "linalg.h"

class PolySet;

class CSGTerm
{
public:
	enum type_e {
		TYPE_PRIMITIVE,
		TYPE_UNION,
		TYPE_INTERSECTION,
		TYPE_DIFFERENCE
	};

	enum Flag {
		FLAG_NONE = 0x00,
		FLAG_BACKGROUND = 0x01,
		FLAG_HIGHLIGHT = 0x03
	};

	static shared_ptr<CSGTerm> createCSGTerm(type_e type, shared_ptr<CSGTerm> left, shared_ptr<CSGTerm> right);
	static shared_ptr<CSGTerm> createCSGTerm(type_e type, CSGTerm *left, CSGTerm *right);

	type_e type;
	shared_ptr<PolySet> polyset;
	std::string label;
	shared_ptr<CSGTerm> left;
	shared_ptr<CSGTerm> right;
	BoundingBox bbox;
	Flag flag;

	CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label);
	~CSGTerm();

	const BoundingBox &getBoundingBox() const { return this->bbox; }

	std::string dump();
private:
	CSGTerm(type_e type, shared_ptr<CSGTerm> left, shared_ptr<CSGTerm> right);
	CSGTerm(type_e type, CSGTerm *left, CSGTerm *right);

	void initBoundingBox();

	Transform3d m;
	Color4f color;

	friend class CSGChain;
};

class CSGChainObject
{
public:
	CSGChainObject(shared_ptr<PolySet> polyset,
								 const Transform3d &matrix,
								 const Color4f &color,
								 CSGTerm::type_e type,
								 const std::string &label,
								 CSGTerm::Flag flag = CSGTerm::FLAG_NONE)
		: polyset(polyset), matrix(matrix), color(color), type(type), label(label), flag(flag) {}

	shared_ptr<PolySet> polyset;
	Transform3d matrix;
	Color4f color;
	CSGTerm::type_e type;
	std::string label;
	CSGTerm::Flag flag;
};

class CSGChain
{
public:
	std::vector<CSGChainObject> objects;

	CSGChain() {};

	void import(shared_ptr<CSGTerm> term, CSGTerm::type_e type = CSGTerm::TYPE_UNION,
							CSGTerm::Flag flag = CSGTerm::FLAG_NONE);
	std::string dump(bool full = false);

	BoundingBox getBoundingBox() const;
};

#endif
contact: Jan Huwald // Impressum