-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
CsgInfo.h
88 lines (80 loc) · 2.68 KB
/
CsgInfo.h
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
#pragma once
#include "OffscreenView.h"
#include "csgterm.h"
#include "Tree.h"
#include "GeometryEvaluator.h"
#include "CSGTermEvaluator.h"
#include "csgtermnormalizer.h"
#include "rendersettings.h"
#include "printutils.h"
class CsgInfo
{
public:
CsgInfo()
{
root_chain = NULL;
highlights_chain = NULL;
background_chain = NULL;
glview = NULL;
progress_function = NULL;
normalizelimit = RenderSettings::inst()->openCSGTermLimit;
}
OffscreenView *glview;
shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
class CSGChain *root_chain;
std::vector<shared_ptr<CSGTerm> > highlight_terms;
CSGChain *highlights_chain;
std::vector<shared_ptr<CSGTerm> > background_terms;
CSGChain *background_chain;
int normalizelimit;
void (*progress_function)();
void call_progress_function()
{
if (progress_function) progress_function();
}
bool compile_chains( const Tree &tree )
{
const AbstractNode *root_node = tree.root();
GeometryEvaluator geomevaluator(tree);
CSGTermEvaluator evaluator(tree, &geomevaluator);
boost::shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm( *root_node, this->highlight_terms, this->background_terms );
if (!root_raw_term) {
PRINT("Error: CSG generation failed! (no top level object found)");
call_progress_function();
return false;
}
PRINT("Compiling design (CSG Products normalization)...");
call_progress_function();
CSGTermNormalizer normalizer( normalizelimit );
this->root_norm_term = normalizer.normalize(root_raw_term);
if (this->root_norm_term) {
this->root_chain = new CSGChain();
this->root_chain->import(this->root_norm_term);
PRINTB("Normalized CSG tree has %d elements", int(this->root_chain->objects.size()));
}
else {
this->root_chain = NULL;
PRINT("WARNING: CSG normalization resulted in an empty tree");
call_progress_function();
}
if (this->highlight_terms.size() > 0) {
PRINTB("Compiling highlights (%i CSG Trees)...", this->highlight_terms.size() );
call_progress_function();
this->highlights_chain = new CSGChain();
for (unsigned int i = 0; i < this->highlight_terms.size(); i++) {
this->highlight_terms[i] = normalizer.normalize(this->highlight_terms[i]);
this->highlights_chain->import(this->highlight_terms[i]);
}
}
if (this->background_terms.size() > 0) {
PRINTB("Compiling background (%i CSG Trees)...", this->background_terms.size());
call_progress_function();
this->background_chain = new CSGChain();
for (unsigned int i = 0; i < this->background_terms.size(); i++) {
this->background_terms[i] = normalizer.normalize(this->background_terms[i]);
this->background_chain->import(this->background_terms[i]);
}
}
return true;
}
};