diff options
Diffstat (limited to 'tests/csgtestcore.cc')
-rw-r--r-- | tests/csgtestcore.cc | 118 |
1 files changed, 52 insertions, 66 deletions
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 29f92e4..a4a036d 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -32,6 +32,8 @@ #include <boost/program_options.hpp> #include <boost/filesystem.hpp> +#include "CsgInfo.h" + namespace po = boost::program_options; namespace fs = boost::filesystem; #include "boosty.h" @@ -45,26 +47,6 @@ std::string commandline_commands; //#define DEBUG -class CsgInfo -{ -public: - CsgInfo(); - 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; - OffscreenView *glview; -}; - -CsgInfo::CsgInfo() { - root_chain = NULL; - highlights_chain = NULL; - background_chain = NULL; - glview = NULL; -} - string info_dump(OffscreenView *glview) { assert(glview); @@ -123,8 +105,53 @@ po::variables_map parse_options(int argc, char *argv[]) return vm; } -// glview->shaderinfo[9] = glview->width; -// glview->shaderinfo[10] = glview->height; +int opencsg_prep( Tree &tree, AbstractNode *root_node, CsgInfo_OpenCSG &csgInfo ) +{ + CGALEvaluator cgalevaluator(tree); + CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator); + shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm(*root_node, + csgInfo.highlight_terms, + csgInfo.background_terms); + + if (!root_raw_term) { + cerr << "Error: CSG generation failed! (no top level object found)\n"; + return 1; + } + + // CSG normalization + CSGTermNormalizer normalizer(5000); + csgInfo.root_norm_term = normalizer.normalize(root_raw_term); + if (csgInfo.root_norm_term) { + csgInfo.root_chain = new CSGChain(); + csgInfo.root_chain->import(csgInfo.root_norm_term); + fprintf(stderr, "Normalized CSG tree has %d elements\n", int(csgInfo.root_chain->polysets.size())); + } + else { + csgInfo.root_chain = NULL; + fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n"); + } + + if (csgInfo.highlight_terms.size() > 0) { + cerr << "Compiling highlights (" << csgInfo.highlight_terms.size() << " CSG Trees)...\n"; + + csgInfo.highlights_chain = new CSGChain(); + for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) { + csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]); + csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]); + } + } + + if (csgInfo.background_terms.size() > 0) { + cerr << "Compiling background (" << csgInfo.background_terms.size() << " CSG Trees)...\n"; + + csgInfo.background_chain = new CSGChain(); + for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) { + csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]); + csgInfo.background_chain->import(csgInfo.background_terms[i]); + } + } + return 0; +} int csgtestcore(int argc, char *argv[], test_type_e test_type) { @@ -187,51 +214,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) Tree tree(root_node); - CsgInfo csgInfo = CsgInfo(); - CGALEvaluator cgalevaluator(tree); - CSGTermEvaluator evaluator(tree, &cgalevaluator.psevaluator); - shared_ptr<CSGTerm> root_raw_term = evaluator.evaluateCSGTerm(*root_node, - csgInfo.highlight_terms, - csgInfo.background_terms); - - if (!root_raw_term) { - cerr << "Error: CSG generation failed! (no top level object found)\n"; - return 1; - } - - // CSG normalization - CSGTermNormalizer normalizer(5000); - csgInfo.root_norm_term = normalizer.normalize(root_raw_term); - if (csgInfo.root_norm_term) { - csgInfo.root_chain = new CSGChain(); - csgInfo.root_chain->import(csgInfo.root_norm_term); - fprintf(stderr, "Normalized CSG tree has %d elements\n", int(csgInfo.root_chain->polysets.size())); - } - else { - csgInfo.root_chain = NULL; - fprintf(stderr, "WARNING: CSG normalization resulted in an empty tree\n"); - } + CsgInfo_OpenCSG csgInfo = CsgInfo_OpenCSG(); + int result = opencsg_prep( tree, root_node, csgInfo ); + if ( result == 1 ) return result; - if (csgInfo.highlight_terms.size() > 0) { - cerr << "Compiling highlights (" << csgInfo.highlight_terms.size() << " CSG Trees)...\n"; - - csgInfo.highlights_chain = new CSGChain(); - for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) { - csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]); - csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]); - } - } - - if (csgInfo.background_terms.size() > 0) { - cerr << "Compiling background (" << csgInfo.background_terms.size() << " CSG Trees)...\n"; - - csgInfo.background_chain = new CSGChain(); - for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) { - csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]); - csgInfo.background_chain->import(csgInfo.background_terms[i]); - } - } - fs::current_path(original_path); try { |