VisualSensorSharedPtr parseVisualSensor(TiXmlElement *g) { VisualSensorSharedPtr visual_sensor; // get sensor type TiXmlElement *sensor_xml; if (g->FirstChildElement("camera")) { Camera *camera = new Camera(); visual_sensor.reset(camera); sensor_xml = g->FirstChildElement("camera"); if (!parseCamera(*camera, sensor_xml)) visual_sensor.reset(); } else if (g->FirstChildElement("ray")) { Ray *ray = new Ray(); visual_sensor.reset(ray); sensor_xml = g->FirstChildElement("ray"); if (!parseRay(*ray, sensor_xml)) visual_sensor.reset(); } else { logError("No know sensor types [camera|ray] defined in <sensor> block"); } return visual_sensor; }
boost::shared_ptr<VisualSensor> parseVisualSensor(TiXmlElement *g) { boost::shared_ptr<VisualSensor> visual_sensor; // get sensor type TiXmlElement *sensor_xml; if (g->FirstChildElement("camera")) { Camera *camera = new Camera(); visual_sensor.reset(camera); sensor_xml = g->FirstChildElement("camera"); if (!parseCamera(*camera, sensor_xml)) visual_sensor.reset(); } else if (g->FirstChildElement("ray")) { Ray *ray = new Ray(); visual_sensor.reset(ray); sensor_xml = g->FirstChildElement("ray"); if (!parseRay(*ray, sensor_xml)) visual_sensor.reset(); } else { printf("No know sensor types [camera|ray] defined in <sensor> block \n"); } return visual_sensor; }
void octreeVizNode::draw( M3dView & view, const MDagPath & /*path*/, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { MDagPath camera; view = M3dView::active3dView(); view.getCamera(camera); MATRIX44F mat; double clipNear, clipFar, fov; int ispersp; parseCamera(camera, mat, clipNear, clipFar, fov, ispersp); view.beginGL(); glPushAttrib(GL_ALL_ATTRIB_BITS); glShadeModel(GL_SMOOTH); glPointSize(3); if(m_pTex) { XYZ ori(0,0,0); m_pTex->setProjection(mat, fov, ispersp); int port[4]; glGetIntegerv(GL_VIEWPORT, port); m_pTex->setPortWidth(port[2]); m_pTex->drawCube(); m_pTex->testRaster(ori); } glPopAttrib(); view.endGL(); }
void scene::parse(const char *filename) { //some default values in case parsing fails myObjGroup = NULL; bgColor = Vec3f(0.5,0.5,0.5); ambLight = Vec3f(0.5,0.5,0.5); eye = Vec3f(0,0,0); lookAt = Vec3f(0,0,-1); up = Vec3f(0,1,0); fovy = 45; file = NULL; curline = 1; //the file-extension needs to be "ray" assert(filename != NULL); const char *ext = &filename[strlen(filename)-4]; assert(!strcmp(ext,".ray")); fopen_s(&file, filename, "r"); assert(file != NULL); char token[MAX_PARSER_TOKEN_LENGTH]; //prime the parser pipe parse_char = fgetc(file); while (getToken(token)) { if(!strcmp(token, "Background")) parseBackground(); else if(!strcmp(token, "Camera")) parseCamera(); else if(!strcmp(token, "Materials")) parseMaterials(); else if(!strcmp(token, "Group")) myObjGroup = parseGroup(); else if(!strcmp(token, "Lights")) parseLights(); else { cout<<"Unknown token in parseFile: '"<<token<< "' at input line "<<curline<<"\n"; exit(-1); } } }
void Scene::parseScene(string sceneText){ char buffer[300]; FILE *fp; cout <<" yar:"<< sceneText << endl; fflush(stdout); fp = fopen(sceneText.c_str(), "r"); my_assert(fp, "can't open spec"); cout << "END HERE " << endl; fflush(stdout); while(!feof(fp)){ fgets(buffer, 300, fp); //Used to suppress warning of fgets //Used to suppress warning of len printf("read line: %s\n", buffer); switch (buffer[0]) { case '#': printf("NOPE \n"); break; case '1': case '2': case '3': case '4': case '5': case '6': //read in the cubei printf("READING SHAPE\n"); parseObject(buffer); break; //etc case 'l': parseLight(buffer); break; case 'c': parseCamera(buffer); break; default: break; } } }
void SceneParser::parse() { nsUtil::Timer timer = nsUtil::Timer(); TiXmlDocument scene(_fileName); if (!scene.LoadFile()) { cerr << "error while loading" << endl; cerr << "error #" << scene.ErrorId() << " : " << scene.ErrorDesc() << endl; exit(-1); } else { //Timer Start timer.start(); TiXmlHandle hdl(&scene); TiXmlElement *elem = hdl.FirstChildElement().FirstChildElement().Element(); if (!elem) { cerr << "The node to reach does not exist" << endl; exit(-1); } //Browse every node while (elem) { if ((std::string) elem->Value() == "screenSetup") { screenSetup(elem); } else if ((std::string) elem->Value() == "shape") { Shape *s = parseShape(elem); _shapes.add(s); } else if ((std::string) elem->Value() == "light") { parseLight(elem); } else if ((std::string) elem->Value() == "camera") { parseCamera(elem); } else { cerr << "Invalid description: " << (std::string) elem->Value() << " does not exist.\nPlease, check the spelling and try again." << endl; exit(-1); } elem = elem->NextSiblingElement(); } int time = timer.getTicks(); cout << "\nParsing time: " << time/1000.0 << "s\n" << endl; parsingInfo(); } }
void Bundler::parseBundlerOut(void) { std::cout<<"1.Start to parse bundler.out file..."<<std::endl; try { std::string bundlerName = mBundlerDir + "/bundle.rd.out"; ifstream f1(bundlerName.c_str()); if ( f1.is_open()) { parseMeta(f1); parseCamera(f1); } else cout<<"File open failed!"; f1.close(); } catch (exception e) { cerr<<e.what()<<endl; //getchar(); exit(1); } std::cout<<"2.Parse bundler.out file successfully!"<<std::endl; }
bool Importer::parseLibraryCameras( const Asset& asset_parent, xmlNodePtr lib_cameras_node ) { Logger log = getLogger( "Scene.XML.parseLibraryCameras" ); if( !assertNode( lib_cameras_node, "library_cameras" ) ) { return false; } xmlNodePtr n = lib_cameras_node->children; if( n!=NULL && xmlStrEqual( n->name, BAD_CAST "asset" ) ) { Asset asset; if( parseAsset( asset, n ) ) { m_database.library<Camera>().setAsset( asset ); } else { SCENELOG_ERROR( log, "Failed to parse <asset>" ); return false; } n = n->next; } else { m_database.library<Camera>().setAsset( asset_parent ); } while( n!= NULL && xmlStrEqual( n->name, BAD_CAST "camera" ) ) { if( !parseCamera( m_database.library<Camera>().asset(), n ) ) { SCENELOG_ERROR( log, "Failed to parse <camera>" ); return false; } n = n->next; } ignoreExtraNodes( log, n ); nagAboutRemainingNodes( log, n ); return true; }
Scene parseFile( std::string filename ) { Scene scene; int maxSpheres = 1000; int maxTriangles = 1000; int maxPlanes = 1000; int maxPointLights = 10; scene.numPointLights = 0; scene.numSpheres = 0; scene.numTriangles = 0; scene.numPlanes = 0; scene.spheres = (Sphere *)malloc( sizeof(Sphere) * maxSpheres ); scene.triangles = (Triangle *)malloc( sizeof(Triangle) * maxTriangles ); scene.planes = (Plane *)malloc( sizeof(Plane) * maxSpheres ); scene.pointLights = (PointLight *)malloc( sizeof(PointLight) * maxPointLights ); //Open file for writing FILE *file = fopen(filename.c_str(), "r"); if(file == NULL) { printf("Error Occured opening file\n"); exit(EXIT_FAILURE); } while(1) { //starting off eating all whitespace char cur = ' '; while( isspace(cur) ) { if( fscanf( file, "%c", &cur ) == EOF ) { printf("End of File reached\n"); return scene; } } //check for comment if(cur == '/') { while(cur != '\n') { if( fscanf( file, "%c", &cur ) == EOF ) { printf("Error Occured reading file\n"); exit(EXIT_FAILURE); } } } else if( cur == 'c' || cur == 'C' ) { scene.camera = parseCamera( file ); } else if( cur == 'l' || cur == 'L' ) { PointLight light = parsePointLight( file ); if( scene.numPointLights + 1 >= maxPointLights ) { maxPointLights = maxPointLights*10; scene.pointLights = (PointLight *)realloc( scene.pointLights, sizeof(PointLight)*maxPointLights ); } scene.pointLights[scene.numPointLights] = light; scene.numPointLights++; } else if( cur == 's' || cur == 'S' ) { if( scene.numSpheres+1 >= maxSpheres ) { maxSpheres = maxSpheres*1000; scene.spheres = (Sphere *) realloc( scene.spheres, sizeof(Sphere) * maxSpheres ); } scene.spheres[scene.numSpheres] = parseSphere(file); scene.numSpheres++; } else if( cur == 'p' || cur == 'P' ) { if( scene.numPlanes+1 >= maxPlanes ) { maxPlanes = maxPlanes*1000; scene.planes = (Plane *) realloc( scene.planes, maxPlanes * sizeof(Plane) ); } scene.planes[scene.numPlanes] = parsePlane(file); scene.numPlanes++; } else if( cur == 't' || cur == 'T' ) { if( scene.numTriangles+1 >= maxTriangles ) { maxTriangles = maxTriangles*1000; scene.triangles = (Triangle *) realloc( scene.triangles, maxTriangles * sizeof(Triangle) ); } scene.triangles[scene.numTriangles] = parseTriangle(file); scene.numTriangles++; } else { printf("Unknown Keyword Failure char was |%c|\n", cur); exit(EXIT_FAILURE); } } }
bool Scene::parse(const string &filename) { QFile* file = new QFile(filename.c_str()); if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(0, "FermaRenderer", "Couldn't open the selected scene file.", QMessageBox::Ok); return false; } QXmlStreamReader xml(file); while(!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); if(token == QXmlStreamReader::StartDocument) { continue; } if(token == QXmlStreamReader::StartElement) { // parse different parts if(xml.name() == "material") { materials.push_back(parseMaterial(xml)); } if(xml.name() == "shape") { shapes.push_back(parseShape(xml)); } if(xml.name() == "object") { objects.push_back(parseObject(xml)); } if(xml.name() == "config") { config = parseConfigurations(xml); } if(xml.name() == "camera") { camera = parseCamera(xml); } } } if(xml.hasError()) { QMessageBox::critical(0, "FermaRenderer", xml.errorString(), QMessageBox::Ok); return false; } xml.clear(); cout << "done parsing." << endl; return true; }
void SceneParser::parseConfig(void) { if(currentToken == Scanner::StreamDone) return; else{ while(errorFlag == false && currentToken != Scanner::StreamDone) { if(currentToken == Scanner::Separator) return; acceptToken(Scanner::Id); string tokenText = scanner.tokenText(); if(tokenText == "width"){ parseNumber(config.width); } else if(tokenText == "height"){ parseNumber(config.height); } else if(tokenText == "mode"){ parseToken(Scanner::Id); string m = scanner.tokenText(); if(m == "standard") config.mode = Config::STANDARD; else if(m == "photon") config.mode = Config::PHOTON; else error("invalid mode"); } else if(tokenText == "gamma"){ float num; parseNumber(num); config.gamma = num; } else if(tokenText == "ambient"){ parseNumber(config.ambient); } else if(tokenText == "background"){ parseVector(config.backColor); } else if(tokenText == "depth"){ float depth; parseNumber(depth); config.reflectionDepth = depth; } else if(tokenText == "glossyReflectSampling"){ int sampling; parseNumber(sampling); config.glossyReflectSampling = sampling; } else if(tokenText == "glossyRefractSampling"){ int sampling; parseNumber(sampling); config.glossyRefractSampling = sampling; } else if(tokenText == "uniform"){ int level; parseNumber(level); config.sampler = new uniformSampler(raytracer, config, level); } else if(tokenText == "jitter"){ int level; parseNumber(level); config.sampler = new jitterSampler(raytracer, config, level); } else if(tokenText == "adaptive"){ int level; parseNumber(level); Vector3 threshold; parseVector(threshold); config.sampler = new adaptiveSampler(raytracer, config, level, threshold); } else if(tokenText == "camera"){ parseCamera(); } else if(tokenText == "photon"){ parsePhoton(); } else{ return; } advance(); } } }