// OiStream.cpp #include "OiStream.h" #include #include "Inventor/SoDB.h" #include "Inventor/nodes/SoSeparator.h" #include "Inventor/nodes/SoMaterial.h" #include "Inventor/actions/SoWriteAction.h" #include "OiSurface.h" #include "trfobj/VisColor.h" using std::cerr; using std::endl; //********************************************************************** // Local functions. //********************************************************************** namespace { // Fetch a new root separator. // Initialize open inventor if this is the first root. SoSeparator* get_new_root() { static bool initialized = false; if ( ! initialized ) { initialized = true; SoDB::init(); } return new SoSeparator; } } // end unnamed namespace //********************************************************************** // Member functions. //********************************************************************** // Constructor. OiStream::OiStream() : _proot( get_new_root() ) { } //********************************************************************** // Destructor. OiStream::~OiStream() { } //********************************************************************** // Define the color. void OiStream::set_color(const VisColor& col) { SoMaterial* pmat = new SoMaterial; pmat->diffuseColor.setValue(col.red(),col.green(),col.blue()); _proot->addChild(pmat); } //********************************************************************** // Create a substream. VisStream& OiStream::add_child() { OiStream* pchild = new OiStream; _children.push_back( OiStreamPtr(pchild) ); _proot->addChild( pchild->_proot ); return *pchild; } //********************************************************************** // Write to a file. void OiStream::write(string filename) { SoWriteAction writer; writer.getOutput()->openFile(filename.c_str()); writer.getOutput()->setBinary(FALSE); writer.apply(_proot); writer.getOutput()->closeFile(); } //**********************************************************************