TSeparatorKit* ComponentHeliostatField::OpenHeliostatComponent( QString fileName ) { if ( fileName.isEmpty() ) return 0; SoInput componentInput; if ( !componentInput.openFile( fileName.toLatin1().constData() ) ) { QMessageBox::warning( 0, QString( "Scene Graph Structure" ), QString( "Cannot open file %1:\n." ).arg( fileName ) ); return 0; } SoSeparator* componentSeparator = SoDB::readAll( &componentInput ); componentInput.closeFile(); if ( !componentSeparator ) { QMessageBox::warning( 0, QString( "Scene Graph Structure" ), QString( "Error reading file %1:\n%2." ) .arg( fileName ) ); return 0; } TSeparatorKit* componentRoot = static_cast< TSeparatorKit* >( componentSeparator->getChild(0) ); componentRoot->ref(); return componentRoot; }
/*! \brief Add a new object in the scene graph \param iv_filename : name of.iv file to load \param fMo : position of the object wrt the reference frame */ void vpSimulator::load(const char * iv_filename,const vpHomogeneousMatrix &fMo) { SoInput in; SoSeparator * newObject; if (! in.openFile (iv_filename)) { vpERROR_TRACE ("Erreur lors de la lecture du fichier %s.", iv_filename); } newObject = SoDB::readAll (&in); if (NULL == newObject) { vpERROR_TRACE ("Problem reading data for file <%s>.", iv_filename); } try { this->addObject (newObject, fMo) ; } catch(...) { vpERROR_TRACE("Error adding object from file <%s> ",iv_filename) ; throw ; } }
SoSeparator *ReadScene(const char *Dir, const char *filename) { FILE *filePtr = NULL; SoSeparator *root; SoInput in; in.addDirectoryLast(Dir); if (!in.openFile(filename)) { cerr << "Error opening file " << filename << " from Directory " << Dir << endl; exit(1); } root = SoDB::readAll(&in); if (root == NULL) cerr << "Error reading file " << filename << " from Directory " << Dir << endl; else { #ifdef DEBUG cerr << "Scene (" << filename << ") read!\n"; #endif root->ref(); } in.closeFile(); return root; }
// Read file and convert to OSG osgDB::ReaderWriter::ReadResult ReaderWriterIV::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { // Accept extension std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; // Find file std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // Notify OSG_NOTICE << "osgDB::ReaderWriterIV::readNode() Reading file " << fileName.data() << std::endl; OSG_INFO << "osgDB::ReaderWriterIV::readNode() Inventor version: " << SoDB::getVersion() << std::endl; // Open the file SoInput input; if (!input.openFile(fileName.data())) { OSG_WARN << "osgDB::ReaderWriterIV::readIVFile() " << "Cannot open file " << fileName << std::endl; return ReadResult::ERROR_IN_READING_FILE; } // Perform reading from SoInput return readNodeFromSoInput(input, fileName, options); }
//!loading the virtual scene void vpSimulator::load(const char *file_name) { SoInput input; if (!input.openFile(file_name)) { vpERROR_TRACE("Erreur cannot open file %s",file_name); } SoSeparator *newscene=SoDB::readAll(&input); newscene->ref() ; if (newscene==NULL) { vpERROR_TRACE("Error while reading %s",file_name); } SoScale *taille = new SoScale; taille->scaleFactor.setValue (zoomFactor, zoomFactor, zoomFactor); // newscene->addChild(taille); // std::cout << "this->scene->getNumChildren() = " << this->scene->getNumChildren() << std::endl; this->scene->addChild(taille); this->scene->addChild(newscene); newscene->unref() ; }
SoSeparator * SceneFileObj::readSceneFile(void) { SoInput input; SoSeparator *s; FILE *f = NULL; if (_sceneFileName[0] == '<') { char *p = _sceneFileName+1; while (*p) { if (! isdigit(*p)) break; p++; } if (*p == '\0') { int fd = atoi(_sceneFileName+1); if ((f = fdopen(fd, "r")) == NULL) { return (NULL); } input.setFilePointer(f); } } if (f == NULL) { if (!input.openFile(_sceneFileName)) return NULL; } s = SoDB::readAll(&input); input.closeFile(); return s; }
void DragDropHandlerP::dropEvent(QDropEvent * event) { const QMimeData * mimedata = event->mimeData(); SoSeparator * root; SoInput in; QByteArray bytes; if (mimedata->hasUrls()) { QUrl url = mimedata->urls().takeFirst(); if (url.scheme().isEmpty() || url.scheme().toLower() == QString("file") ) { // attempt to open file if (!in.openFile(url.toLocalFile().toLatin1().constData())) return; } } else if (mimedata->hasText()) { /* FIXME 2007-11-09 preng: dropping text buffer does not work on Windows Vista. */ bytes = mimedata->text().toUtf8(); in.setBuffer((void *) bytes.constData(), bytes.size()); if (!in.isValidBuffer()) return; } // attempt to import it root = SoDB::readAll(&in); if (root == NULL) return; // set new scenegraph this->quarterwidget->setSceneGraph(root); this->quarterwidget->viewport()->update(); }
SoSeparator* loadModel(const char* fileName) { SoSeparator *root = new SoSeparator; SoInput myScene; //try to open the file if (!myScene.openFile(fileName)) { printf("Could not open %s\n",fileName) ; return NULL; } //check if the file is valid if (!myScene.isValidFile()) { printf("%s is not a valid Inventor file\n",fileName) ; return NULL; } //try to read the file root = SoDB::readAll(&myScene) ; if (root == NULL) { printf("Problem reading %s\n",fileName) ; myScene.closeFile() ; return NULL; } //close the file myScene.closeFile() ; return root ; }
/*! * Reads the scene saved on the file with given \a filename and return a pointer to the scene. * * Returns null on any error. */ TSceneKit* Document::GetSceneKitFromFile( const QString& fileName ) { SoInput sceneInput; if ( !sceneInput.openFile( fileName.toLatin1().constData() ) ) { QString message = QString( "Cannot open file %1." ).arg( fileName ); emit Warning( message ); return 0; } if( !sceneInput.isValidFile() ) { QString message = QString( "Error reading file %1.\n" ).arg( fileName ); emit Warning( message ); return 0; } SoSeparator* graphSeparator = SoDB::readAll( &sceneInput ); sceneInput.closeFile(); if ( !graphSeparator ) { QString message = QString( "Error reading file %1.\n" ).arg( fileName ); emit Warning( message ); return 0; } return static_cast< TSceneKit* >( graphSeparator->getChild(0) ); return 0; }
bool QCtkXipSGWidget::loadIvFile(const QString& ivFileName) { if(!QFile::exists(ivFileName)) { QString pwd = QDir::currentPath(); return false; } std::string ivFileNameStr(ivFileName.toStdString()); const char *ivStr = (const char*) ivFileNameStr.c_str(); SoInput in; in.openFile(ivStr); // file SoSeparator *topNode = SoDB::readAll(&in); if (topNode) { if(mRoot) { mRoot->removeAllChildren(); mRoot->addChild(topNode); return true; } } return false; }
SbBool SoTexture2::readImage(const SbString& fname, int &w, int &h, int &nc, unsigned char *&bytes) // //////////////////////////////////////////////////////////////////////// { w = h = nc = 0; bytes = NULL; // Empty file means an empty image... if (fname.getString()[0] == '\0') return TRUE; SoInput in; if (!in.openFile(fname.getString(), TRUE)) { return FALSE; } #ifdef DEBUG SoDebugError::postInfo("SoTexture2::readImage", "Reading texture image %s", fname.getString()); #endif if (ReadSGIImage(in, w, h, nc, bytes)) return TRUE; // fiopen() closes the file even if it can't read the data, so // reopen it in.closeFile(); if (!in.openFile(fname.getString(), TRUE)) return FALSE; if (ReadGIFImage(in, w, h, nc, bytes)) return TRUE; if (ReadJPEGImage(in, w, h, nc, bytes)) return TRUE; return FALSE; }
void SoXtMaterialList::selectionCallback(// private int materialid) { materialid--; // get index SoXtMaterialDirectory * data = common->getMaterialDirectory(); assert(materialid >= 0 && materialid < data->groups[data->current]->numMaterials); const char * materialdata = data->groups[data->current]->materials[materialid]->data; SoInput reader; if (data->flags & SOXT_BUILTIN_MATERIALS) { reader.setBuffer((void *) materialdata, strlen(materialdata)); } else { if (! reader.openFile(materialdata, FALSE)) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "could not open file: \"%s\"", materialdata); return; } } SoNode * material = NULL; if (! SoDB::read(&reader, material)) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "failed to read material"); return; } if (! material) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "read returned no data"); return; } material->ref(); if (! material->isOfType(SoMaterial::getClassTypeId())) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "not a material node!"); material->unref(); return; } common->invokeCallbacks((SoMaterial *) material); material->unref(); } // selectionCallback()
SoSeparator* QilexDoc::readFile(const char *filename, int &tipus) { // Open the input file SoInput mySceneInput; if (!mySceneInput.openFile(filename)) { fprintf(stderr, "Cannot open file %s\n", filename); return NULL; } // Read the whole file into the database SoSeparator *myGraph = SoDB::readAll(&mySceneInput); tipus = (int)mySceneInput.isFileVRML2(); if (myGraph == NULL) { fprintf(stderr, "Problem reading file\n"); return NULL; } mySceneInput.closeFile(); return myGraph; }
bool InventorViewer::loadModel(const std::string& filename) { if (!initialized) { ROS_ERROR("InventorViewer not initialized."); return false; } SoInput in; SoNode *model = NULL; if (!in.openFile(filename.c_str())) return false; if (!SoDB::read(&in, model) || model == NULL) /*model = SoDB::readAll(&in); if (!model)*/ return false; root->addChild(model); in.closeFile(); return true; }
void SoFile::nameChangedCB(void *data, SoSensor *) // //////////////////////////////////////////////////////////////////////// { SoFile *f = (SoFile *)data; f->children.truncate(0); SoInput in; const char *filename = f->name.getValue().getString(); // Open file f->readOK = TRUE; if (! in.openFile(filename, TRUE)) { f->readOK = FALSE; SoReadError::post(&in, "Can't open included file \"%s\" in File node", filename); } if (f->readOK) { SoNode *node; // Read children from opened file. while (TRUE) { if (SoDB::read(&in, node)) { if (node != NULL) f->children.append(node); else break; } else f->readOK = FALSE; } in.closeFile(); } // Note: if there is an error reading one of the children, the // other children will still be added properly... }
void SoFileSubgraph::readFile(const char *fileName){ // open the input file SoInput sceneInput; if (!sceneInput.openFile(fileName)) { SoDebugError::post("SoFileSubgraph::readFile()", "Cannot open file '%s'", fileName); return; } if (!sceneInput.isValidFile()){ SoDebugError::post("SoFileSubgraph::readFile()", "file '%s' is not a valid Inventor file", fileName); return; } else{ SoDebugError::postInfo("SoFileSubgraph::readFile()", "file '%s' read successfully", fileName); } // read the whole file into the database SoSeparator *subgraph=SoDB::readAll(&sceneInput); subgraph->ref(); if (subgraph ==NULL) { SoDebugError::post("SoFileSubgraph::readFile()", "problem reading contents of file '%s'", fileName); return; } SoSeparator *graphRoot=SO_GET_ANY_PART(this,"root",SoSeparator); graphRoot->addChild(subgraph); sceneInput.closeFile(); }
/*! Tries to load the shape primitives file for the grasped object. It uses the same file name as the current object, but looks in the primitives folder within the objects directory. If the primitives are not found, it uses the original geometry of the object, the \a IVGeomRoot. */ void grasp_manager::loadPrimitives() { SoInput myInput; char prDir[256]; QString directory = QString(getenv("GRASPIT"))+ QString("/models/objects/primitives/"); QString filename = my_body->getFilename().section('/',-1); //make sure the extension is iv, as this is how primitives //are stored for now filename = filename.section('.',-2,-2) + ".iv"; QString path = directory + filename; printf("Loading primitive %s.\n",path.latin1()); if (!(myInput.openFile(path.latin1()))) { pr_error("could not open primitives file!"); primitives = my_body->getIVGeomRoot(); printf ("%s\n",prDir); printf("Setting primitive root node to original object.\n"); } else { primitives = SoDB::readAll(&myInput); myInput.closeFile(); if (primitives == NULL) { printf("Load Primitive didnt work, although file seems to exist.\n"); printf("Setting primitive root node to original object.\n"); primitives = my_body->getIVGeomRoot(); } else { primitives->ref(); } } }
main(int argc, char **argv) // ////////////////////////////////////////////////////////////// { Options options; SoSeparator *root; Display *display; Window window; float asisTime, ptsTime, invisTime, freezeTime, noMatTime, noTexTime, noLitTime, noXformTime, noClearTime, oneTexTime; // Init Inventor SoInteraction::init(); // Parse arguments if (! parseArgs(argc, argv, options)) { printUsage(argv[0]); return 1; } // Open scene graphs SoInput sceneInput; if (! sceneInput.openFile(options.inputFileName)) { fprintf(stderr, "Cannot open %s\n", options.inputFileName); return 1; } SbViewportRegion vpr(options.windowX, options.windowY); root = setUpGraph(vpr, &sceneInput, options); // Create and initialize window openWindow(display, window, options.windowX, options.windowY, argv[0]); // Timing tests printf("\t\t\tseconds/frame\tframes/second\n"); // as is rendering asisTime = timeRendering(options, vpr, root); printf("As-Is rendering:\t%10.3f\t%10.2f\n", asisTime, 1.0/asisTime); // time for rendering without clear options.noClear = TRUE; noClearTime = timeRendering(options, vpr, root); options.noClear = FALSE; printf("No Clear:\t\t%10.3f\t%10.2f\n", noClearTime, 1.0/noClearTime); // time for rendering without materials options.noMaterials = TRUE; noMatTime = timeRendering(options, vpr, root); options.noMaterials = FALSE; printf("No Materials:\t\t%10.3f\t%10.2f\n", noMatTime, 1.0/noMatTime); // time for rendering without xforms options.noXforms = TRUE; noXformTime = timeRendering(options, vpr, root); options.noXforms = FALSE; printf("No Transforms:\t\t%10.3f\t%10.2f\n", noXformTime, 1.0/noXformTime); if (options.hasTextures) { // do tests only if scene has textures // time for rendering without any textures options.noTextures = TRUE; noTexTime = timeRendering(options, vpr, root); options.noTextures = FALSE; printf("No Textures:\t\t%10.3f\t%10.2f\n", noTexTime, 1.0/noTexTime); // time for rendering without only one texture options.oneTexture = TRUE; oneTexTime = timeRendering(options, vpr, root); options.oneTexture = FALSE; printf("One Texture:\t\t%10.3f\t%10.2f\n", oneTexTime, 1.0/oneTexTime); } else noTexTime = oneTexTime = asisTime; // time for rendering without fill options.noFill = TRUE; ptsTime = timeRendering(options, vpr, root); options.noFill = FALSE; printf("No Fills:\t\t%10.3f\t%10.2f\n", ptsTime, 1.0/ptsTime); if (options.hasLights) { // do test only if scene has lights // time for rendering with lights turned off options.noLights = TRUE; noLitTime = timeRendering(options, vpr, root); options.noLights = FALSE; printf("No Lights:\t\t%10.3f\t%10.2f\n", noLitTime, 1.0/noLitTime); } else noLitTime = asisTime; printf("\n"); // time for rendering without vertex xforms options.noVtxXforms = TRUE; invisTime = timeRendering(options, vpr, root); options.noVtxXforms = FALSE; printf("Time taken by vertex transformations:\t%10.3f seconds/frame\n", ptsTime-invisTime); // time for rendering with scene graph frozen options.freeze = TRUE; freezeTime = timeRendering(options, vpr, root); options.freeze = FALSE; printf("Time taken to traverse scene graph:\t%10.3f seconds/frame\n\n", asisTime-freezeTime); // kill window XEvent event; XUnmapWindow(display, window); XIfEvent(display, &event, waitForNotify, (char *) window); // draw timing bars if (options.showBars) drawBar(asisTime, noClearTime, noMatTime, noXformTime, noTexTime, oneTexTime, noLitTime, ptsTime, invisTime, freezeTime); return 0; }
void Scene::load(const ::std::string& filename, const bool& doBoundingBoxPoints, const bool& doPoints) { ::rl::xml::DomParser parser; ::rl::xml::Document doc = parser.readFile(filename, "", XML_PARSE_NOENT | XML_PARSE_XINCLUDE); doc.substitute(XML_PARSE_NOENT | XML_PARSE_XINCLUDE); ::rl::xml::Path path(doc); ::rl::xml::Object scenes = path.eval("//scene"); for (int i = 0; i < ::std::min(1, scenes.getNodeNr()); ++i) { SoInput input; if (!input.openFile(scenes.getNodeTab(i).getLocalPath(scenes.getNodeTab(i).getAttribute("href").getValue()).c_str() ,true)) { throw Exception("::rl::sg::Scene::load() - failed to open file"); } SoVRMLGroup* root = SoDB::readAllVRML(&input); if (NULL == root) { throw Exception("::rl::sg::Scene::load() - failed to read file"); } SbViewportRegion viewportRegion; root->ref(); // model ::rl::xml::Object models = path.eval("model", scenes.getNodeTab(i)); for (int j = 0; j < models.getNodeNr(); ++j) { SoSearchAction modelSearchAction; modelSearchAction.setName(models.getNodeTab(j).getAttribute("name").getValue().c_str()); modelSearchAction.apply(root); if (NULL == modelSearchAction.getPath()) { continue; } Model* model = this->create(); model->setName(models.getNodeTab(j).getAttribute("name").getValue()); // body ::rl::xml::Object bodies = path.eval("body", models.getNodeTab(j)); for (int k = 0; k < bodies.getNodeNr(); ++k) { SoSearchAction bodySearchAction; bodySearchAction.setName(bodies.getNodeTab(k).getAttribute("name").getValue().c_str()); bodySearchAction.apply(static_cast< SoFullPath* >(modelSearchAction.getPath())->getTail()); if (NULL == bodySearchAction.getPath()) { continue; } Body* body = model->create(); body->setName(bodies.getNodeTab(k).getAttribute("name").getValue()); SoSearchAction pathSearchAction; pathSearchAction.setNode(static_cast< SoFullPath* >(bodySearchAction.getPath())->getTail()); pathSearchAction.apply(root); SoGetMatrixAction bodyGetMatrixAction(viewportRegion); bodyGetMatrixAction.apply(static_cast< SoFullPath* >(pathSearchAction.getPath())); SbMatrix bodyMatrix = bodyGetMatrixAction.getMatrix(); if (!this->isScalingSupported) { SbVec3f bodyTranslation; SbRotation bodyRotation; SbVec3f bodyScaleFactor; SbRotation bodyScaleOrientation; SbVec3f bodyCenter; bodyMatrix.getTransform(bodyTranslation, bodyRotation, bodyScaleFactor, bodyScaleOrientation, bodyCenter); for (int l = 0; l < 3; ++l) { if (::std::abs(bodyScaleFactor[l] - 1.0f) > 1.0e-6f) { throw Exception("::rl::sg::Scene::load() - bodyScaleFactor not supported"); } } } ::rl::math::Transform frame; for (int m = 0; m < 4; ++m) { for (int n = 0; n < 4; ++n) { frame(m, n) = bodyMatrix[n][m]; } } body->setFrame(frame); if (static_cast< SoFullPath* >(bodySearchAction.getPath())->getTail()->isOfType(SoVRMLTransform::getClassTypeId())) { SoVRMLTransform* bodyVrmlTransform = static_cast< SoVRMLTransform* >(static_cast< SoFullPath* >(bodySearchAction.getPath())->getTail()); for (int l = 0; l < 3; ++l) { body->center(l) = bodyVrmlTransform->center.getValue()[l]; } } SoPathList pathList; // shape SoSearchAction shapeSearchAction; shapeSearchAction.setInterest(SoSearchAction::ALL); shapeSearchAction.setType(SoVRMLShape::getClassTypeId()); shapeSearchAction.apply(static_cast< SoFullPath* >(bodySearchAction.getPath())->getTail()); for (int l = 0; l < shapeSearchAction.getPaths().getLength(); ++l) { SoFullPath* path = static_cast< SoFullPath* >(shapeSearchAction.getPaths()[l]); if (path->getLength() > 1) { path = static_cast< SoFullPath* >(shapeSearchAction.getPaths()[l]->copy(1, static_cast< SoFullPath* >(shapeSearchAction.getPaths()[l])->getLength() - 1)); } pathList.append(path); SoGetMatrixAction shapeGetMatrixAction(viewportRegion); shapeGetMatrixAction.apply(path); SbMatrix shapeMatrix = shapeGetMatrixAction.getMatrix(); if (!this->isScalingSupported) { SbVec3f shapeTranslation; SbRotation shapeRotation; SbVec3f shapeScaleFactor; SbRotation shapeScaleOrientation; SbVec3f shapeCenter; shapeMatrix.getTransform(shapeTranslation, shapeRotation, shapeScaleFactor, shapeScaleOrientation, shapeCenter); for (int m = 0; m < 3; ++m) { if (::std::abs(shapeScaleFactor[m] - 1.0f) > 1.0e-6f) { throw Exception("::rl::sg::Scene::load() - shapeScaleFactor not supported"); } } } SoVRMLShape* shapeVrmlShape = static_cast< SoVRMLShape* >(static_cast< SoFullPath* >(shapeSearchAction.getPaths()[l])->getTail()); Shape* shape = body->create(shapeVrmlShape); shape->setName(shapeVrmlShape->getName().getString()); ::rl::math::Transform transform; for (int m = 0; m < 4; ++m) { for (int n = 0; n < 4; ++n) { transform(m, n) = shapeMatrix[n][m]; } } shape->setTransform(transform); } // bounding box if (doBoundingBoxPoints) { SoGetBoundingBoxAction getBoundingBoxAction(viewportRegion); getBoundingBoxAction.apply(pathList); SbBox3f boundingBox = getBoundingBoxAction.getBoundingBox(); for (int l = 0; l < 3; ++l) { body->max(l) = boundingBox.getMax()[l]; body->min(l) = boundingBox.getMin()[l]; } } // convex hull if (doPoints) { SoCallbackAction callbackAction; callbackAction.addTriangleCallback(SoVRMLGeometry::getClassTypeId(), Scene::triangleCallback, &body->points); callbackAction.apply(pathList); } } } root->unref(); } }
int main(int argc, char ** argv) { fprintf(stderr, "ivcp v0.1\n"); SoDB::init(); SoNodeKit::init(); SoInteraction::init(); if (argc != 3 ) { fprintf(stdout, "Usage: %s infile outfile\n", argv[0]); return 0; } SoInput * in = new SoInput; if (!in->openFile(argv[1])) { fprintf(stderr, "error: could not open file '%s'\n", argv[1]); delete in; SoDB::cleanup(); return -1; } SoNode * scene = SoDB::readAll(in); if (!scene) { fprintf(stderr, "error: could not read file '%s'\n", argv[1]); delete in; SoDB::cleanup(); return -1; } FileType inputFileType; if (in->isFileVRML1()) inputFileType = VRML1; else if (in->isFileVRML2()) inputFileType = VRML2; else inputFileType = INVENTOR; delete in; scene->ref(); SoNode * firstChild = static_cast<SoSeparator*>(scene)->getNumChildren()? static_cast<SoSeparator*>(scene)->getChild(0) :NULL; if (firstChild && firstChild->isOfType(SoForeignFileKit::getClassTypeId())) { SoForeignFileKit * kit = (SoForeignFileKit *) firstChild; if (kit->canWriteScene() ) { SoNode * subscene = NULL; kit->writeScene(subscene); if (!subscene ) { return -1; } subscene->ref(); scene->unref(); scene = subscene; } } SoOutput * out = new SoOutput; if (!out->openFile(argv[2])) { fprintf(stderr, "error: could not open file '%s' for writing\n"); scene->unref(); delete out; SoDB::cleanup(); return -1; } switch (inputFileType) { case VRML1: out->setHeaderString("#VRML V1.0 ascii"); break; case VRML2: out->setHeaderString("#VRML V2.0 utf8"); } SoWriteAction wa(out); wa.apply(scene); out->closeFile(); delete out; scene->unref(); // with actions on the stack, cleanup can't be called... // SoDB::cleanup(); return 0; }
IVElement::IVElement(string ivfile, KthReal sc) { for(int i=0;i<3;i++){ position[i]= 0.0f; orientation[i]=0.0f; } orientation[2]=1.0f; orientation[3]=0.0f; scale=sc; trans= new SoTranslation; rot = new SoRotation; sca = new SoScale(); color = new SoMaterial; posVec = new SoSFVec3f; trans->translation.connectFrom(posVec); posVec->setValue((float)position[0],(float)position[1],(float)position[2]); rotVec = new SoSFRotation; rotVec->setValue(SbVec3f((float)orientation[0],(float)orientation[1], (float)orientation[2]),(float)orientation[3]); rot->rotation.connectFrom(rotVec); scaVec= new SoSFVec3f; scaVec->setValue((float)scale,(float)scale,(float)scale); sca->scaleFactor.connectFrom(scaVec); SoInput input; ivmodel = new SoSeparator; ivmodel->ref(); ivmodel->addChild(sca); if(input.openFile(ivfile.c_str())) ivmodel->addChild(SoDB::readAll(&input)); else { //ivmodel->addChild(new SoSphere()); static const char *str[] = { "#VRML V1.0 ascii\n", "DEF pointgoal Separator {\n", " Separator {\n", " MaterialBinding { value PER_PART }\n", " Coordinate3 {\n", " point [\n", " 0.0 0.0 0.0\n", " ]\n", " }\n", " DrawStyle { pointSize 5 }\n", " PointSet { }\n", " }\n", "}\n", NULL }; input.setStringArray(str); SoSeparator *sep = SoDB::readAll(&input); sep->ref(); while (sep->getNumChildren() > 0) { ivmodel->addChild(sep->getChild(0)); sep->removeChild(0); } sep->unref(); } ivmodel->ref(); }
int main(int argc, char ** argv) { if ( argc != 3 ) { fprintf(stderr, "Usage: %s <infile.iv> <outfile.iv>\n", argv[0]); return -1; } SoDB::init(); SoNodeKit::init(); SoInteraction::init(); SoGenerateSceneGraphAction::initClass(); SoTweakAction::initClass(); SoInput in; SoNode * scene, * graph; if ( !in.openFile(argv[1]) ) { fprintf(stderr, "%s: error opening \"%s\" for reading.\n", argv[0], argv[1]); return -1; } scene = SoDB::readAll(&in); if ( scene == NULL ) { fprintf(stderr, "%s: error parsing \"%s\"\n", argv[0], argv[1]); return -1; } scene->ref(); SoGenerateSceneGraphAction action; // action.setDropTypeIfNameEnabled(TRUE); action.apply(scene); graph = action.getGraph(); if ( graph == NULL ) { fprintf(stderr, "%s: error generating scene graph\n", argv[0]); return -1; } graph->ref(); scene->unref(); scene = NULL; // figure out camera settings and needed rendering canvas size SoGetBoundingBoxAction bbaction(SbViewportRegion(64,64)); // just something bbaction.apply(graph); SbBox3f bbox = bbaction.getBoundingBox(); SbVec3f min = bbox.getMin(); SbVec3f max = bbox.getMax(); float bwidth = max[0] - min[0]; float bheight = max[1] - min[1]; // fprintf(stdout, "min: %g %g %g\n", min[0], min[1], min[2]); // fprintf(stdout, "max: %g %g %g\n", max[0], max[1], max[2]); // place camera SoSearchAction search; search.setType(SoCamera::getClassTypeId()); search.setInterest(SoSearchAction::FIRST); search.apply(graph); SoPath * campath = search.getPath(); SoOrthographicCamera * cam = (SoOrthographicCamera *) campath->getTail(); assert(cam != NULL); SbVec3f pos = cam->position.getValue(); cam->position.setValue(SbVec3f(min[0] + ((max[0]-min[0])/2.0), min[1] + ((max[1]-min[1])/2.0), pos[2])); cam->height.setValue(bheight); if ( TRUE ) { // FIXME: only write .iv-scene if asked SoOutput out; if ( !out.openFile(argv[2]) ) { fprintf(stderr, "%s: error opening \"%s\" for writing.\n", argv[0], argv[2]); return -1; } SoWriteAction writer(&out); // writer.setCoinFormattingEnabled(TRUE); writer.apply(graph); } int width = (int) ceil(bwidth * 150.0) + 2; int height = (int) ceil(bheight * 150.0); fprintf(stderr, "image: %d x %d\n", width, height); if ( TRUE ) { // FIXME: only write image if asked SoOffscreenRenderer renderer(SbViewportRegion(width, height)); SoGLRenderAction * glra = renderer.getGLRenderAction(); glra->setNumPasses(9); // FIXME: auto-crop image afterwards? seems like it's a perfect fit right now renderer.setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY); renderer.setBackgroundColor(SbColor(1.0,1.0,1.0)); renderer.render(graph); // FIXME: support command line option filename // FIXME: also support .eps renderer.writeToFile("output.png", "png"); } graph->unref(); return 0; }