Home | Hierarchy | Members | Alphabetical | Related Pages |
Scene scene;
scene.load("myfile.wrl");
for (unsigned int i=0;i<scene.nodes.size();++i) { cout<<"top node "<<i<<" is a "<<scene.nodes[i]->typeName()<<endl; }
#include <xdkwrl/scene.h> #include <iostream> #include <stdexcept> #include <string> using namespace std; int main(int char** argv) { string fileName(argv[1]); // should do better checks!! try { wrl::Scene scene; scene.load(fileName); cout<<fileName<<" can be parsed correctly"<<endl; } catch (runtime_error& e) { cerr<<fileName<<" *cannot* be parsed correctly\n" <<e.what()<<endl; } }
The second flag is more involved. It indicates which flavor of the parser to use. There exists two implementations of the parser: one is generated by ANTLR from the grammar and is therefore trustworthy. However, it is a bit slow and is therefore referred to as the "slow" flavor. The second implementations overidde some of the functions of the first parser in order to achieve faster parsing (and is therefore refered to as the "fast" flavor"). It has been thoroughly tested and works fine. So you probably want to use that one in general and this is why the default value for the fast flag is true. However, if you encounter a file for which the fast parsing fails, and for which you are pretty sure the file is a valid VRML one, you can use the slow version to try to still parse the file. If it fails too, then you can send me an e-mail with the file so I can fix the parser.
Below is a complete example of a program that can accept different command line arguments to perform the different combinations of flags and parsing. It uses the argstream tool bundled with the library for command line parsing.
#include <xdkwrl/scene.h> #include <xdkwrl/tools/argstream.h> #include <iostream> #include <stdexcept> using namespace std; int main(int argc,char** argv) { bool verbose; bool slow; string file; argstream as(argc,argv); as>>option('v',"verbose",verbose,"") >>option('s',"slow",slow,"") >>values<string>(&file),"files to parse",1) >>help(); as.defaultErrorHandling(); try { wrl::Scene scene; scene.load(file,verbose,!slow); cout<<fileName<<" can be parsed correctly"<<endl; } } catch (runtime_error& e) { cerr<<fileName<<" *cannot* be parsed correctly\n" <<e.what()<<endl; } }
Generated on 24 Feb 2005 with
![]() |
|