diff options
author | Marius Kintel <marius@kintel.net> | 2011-12-27 13:46:10 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-12-27 13:46:10 (GMT) |
commit | bac92dbd0ecb7b9535b9acbcd019c88ff9981b4a (patch) | |
tree | 3e02392a80d53d54e289328d478922328e32fb4e /src/csgterm.cc | |
parent | e502fab71d998c0bd025512c0c3884a1117479d1 (diff) | |
parent | 546ed1690486443e6780c1509626de8758a73498 (diff) |
Merge branch 'master' into color-priority
Diffstat (limited to 'src/csgterm.cc')
-rw-r--r-- | src/csgterm.cc | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/src/csgterm.cc b/src/csgterm.cc index 890b0c9..4e6912b 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -139,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; |