diff options
author | Marius Kintel <marius@kintel.net> | 2012-01-04 22:07:32 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-01-04 22:07:32 (GMT) |
commit | fdce8d15fc4a927d1a6a257783dde5054d9f3e7b (patch) | |
tree | 6a779b50ef65474af9c539ad7d42268f7e760ae8 /src/csgterm.cc | |
parent | cbabbaed700536b3a1f513fd5a07d25382cb137f (diff) | |
parent | ba8aa515d14cf270c9d0fdf50b4c7c55b3c416a8 (diff) |
Merge branch 'master' into boost_filesystem
Conflicts:
boost.pri
src/lexer.l
tests/CMakeLists.txt
Diffstat (limited to 'src/csgterm.cc')
-rw-r--r-- | src/csgterm.cc | 128 |
1 files changed, 3 insertions, 125 deletions
diff --git a/src/csgterm.cc b/src/csgterm.cc index 56fcbb5..4e6912b 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -89,10 +89,9 @@ shared_ptr<CSGTerm> CSGTerm::createCSGTerm(type_e type, CSGTerm *left, CSGTerm * return createCSGTerm(type, shared_ptr<CSGTerm>(left), shared_ptr<CSGTerm>(right)); } -CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const double color[4], const std::string &label) - : type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix) +CSGTerm::CSGTerm(const shared_ptr<PolySet> &polyset, const Transform3d &matrix, const Color4f &color, const std::string &label) + : type(TYPE_PRIMITIVE), polyset(polyset), label(label), m(matrix), color(color) { - for (int i = 0; i < 4; i++) this->color[i] = color[i]; initBoundingBox(); } @@ -140,127 +139,6 @@ void CSGTerm::initBoundingBox() } } -shared_ptr<CSGTerm> CSGTerm::normalize(shared_ptr<CSGTerm> term) -{ - // This function implements the CSG normalization - // Reference: - // Goldfeather, J., Molnar, S., Turk, G., and Fuchs, H. Near - // Realtime CSG Rendering Using Tree Normalization and Geometric - // Pruning. IEEE Computer Graphics and Applications, 9(3):20-28, - // 1989. - // http://www.cc.gatech.edu/~turk/my_papers/pxpl_csg.pdf - - if (term->type == TYPE_PRIMITIVE) { - return term; - } - - do { - while (term && normalize_tail(term)) { } - if (!term || term->type == TYPE_PRIMITIVE) return term; - term->left = normalize(term->left); - } while (term->type != TYPE_UNION && - (term->right->type != TYPE_PRIMITIVE || term->left->type == TYPE_UNION)); - term->right = normalize(term->right); - - // FIXME: Do we need to take into account any transformation of item here? - if (!term->right) { - if (term->type == TYPE_UNION || term->type == TYPE_DIFFERENCE) return term->left; - else return term->right; - } - if (!term->left) { - if (term->type == TYPE_UNION) return term->right; - else return term->left; - } - - return term; -} - -bool CSGTerm::normalize_tail(shared_ptr<CSGTerm> &term) -{ - if (term->type == TYPE_UNION || term->type == TYPE_PRIMITIVE) return false; - - // Part A: The 'x . (y . z)' expressions - - shared_ptr<CSGTerm> x = term->left; - shared_ptr<CSGTerm> y = term->right->left; - shared_ptr<CSGTerm> z = term->right->right; - - shared_ptr<CSGTerm> result = term; - - // 1. x - (y + z) -> (x - y) - z - if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_UNION) { - term = createCSGTerm(TYPE_DIFFERENCE, - createCSGTerm(TYPE_DIFFERENCE, x, y), - z); - return true; - } - // 2. x * (y + z) -> (x * y) + (x * z) - else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_UNION) { - term = createCSGTerm(TYPE_UNION, - createCSGTerm(TYPE_INTERSECTION, x, y), - createCSGTerm(TYPE_INTERSECTION, x, z)); - return true; - } - // 3. x - (y * z) -> (x - y) + (x - z) - else if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_INTERSECTION) { - term = createCSGTerm(TYPE_UNION, - createCSGTerm(TYPE_DIFFERENCE, x, y), - createCSGTerm(TYPE_DIFFERENCE, x, z)); - return true; - } - // 4. x * (y * z) -> (x * y) * z - else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_INTERSECTION) { - term = createCSGTerm(TYPE_INTERSECTION, - createCSGTerm(TYPE_INTERSECTION, x, y), - z); - return true; - } - // 5. x - (y - z) -> (x - y) + (x * z) - else if (term->type == TYPE_DIFFERENCE && term->right->type == TYPE_DIFFERENCE) { - term = createCSGTerm(TYPE_UNION, - createCSGTerm(TYPE_DIFFERENCE, x, y), - createCSGTerm(TYPE_INTERSECTION, x, z)); - return true; - } - // 6. x * (y - z) -> (x * y) - z - else if (term->type == TYPE_INTERSECTION && term->right->type == TYPE_DIFFERENCE) { - term = createCSGTerm(TYPE_DIFFERENCE, - createCSGTerm(TYPE_INTERSECTION, x, y), - z); - return true; - } - - // Part B: The '(x . y) . z' expressions - - x = term->left->left; - y = term->left->right; - z = term->right; - - // 7. (x - y) * z -> (x * z) - y - if (term->left->type == TYPE_DIFFERENCE && term->type == TYPE_INTERSECTION) { - term = createCSGTerm(TYPE_DIFFERENCE, - createCSGTerm(TYPE_INTERSECTION, x, z), - y); - return true; - } - // 8. (x + y) - z -> (x - z) + (y - z) - else if (term->left->type == TYPE_UNION && term->type == TYPE_DIFFERENCE) { - term = createCSGTerm(TYPE_UNION, - createCSGTerm(TYPE_DIFFERENCE, x, z), - createCSGTerm(TYPE_DIFFERENCE, y, z)); - return true; - } - // 9. (x + y) * z -> (x * z) + (y * z) - else if (term->left->type == TYPE_UNION && term->type == TYPE_INTERSECTION) { - term = createCSGTerm(TYPE_UNION, - createCSGTerm(TYPE_INTERSECTION, x, z), - createCSGTerm(TYPE_INTERSECTION, y, z)); - return true; - } - - return false; -} - std::string CSGTerm::dump() { std::stringstream dump; @@ -281,7 +159,7 @@ CSGChain::CSGChain() { } -void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, double *color, CSGTerm::type_e type, std::string label) +void CSGChain::add(const shared_ptr<PolySet> &polyset, const Transform3d &m, const Color4f &color, CSGTerm::type_e type, std::string label) { polysets.push_back(polyset); matrices.push_back(m); |