//==========Functions============= void readFile(char *fname) { char filename[1024]; //holds filename FILE *SceneFile; //points to the file char cmd[512]; // holds a command char Buff[2048]; int line=1; //keep track of line #s GLdouble x, y, z, angle, ni; char axis; //Initialize number of lights & objects numLights = 0; numObjs = 0; //Start reading scene with identity transform loadIdentityTransform(¤tTransform[curGroupLevel]); //Open the file if ((SceneFile = fopen(fname, "r")) == NULL) { printf("Error opening scene file \n"); exit(1); } fscanf(SceneFile, "%s", cmd); //stores first word into cmd //Loop to read contents of the file while (!feof(SceneFile)) { if (!strcmp(cmd, "view")) //compares string to view { fscanf(SceneFile, "%d", &view.size); //printf("View size: %d\n", view.size); fscanf(SceneFile, "%lf", &view.d); //printf("View distance to corner of image plane: %f\n", view.d); } else if (!strncmp(cmd, "#", 1)) { /* Comment, let's ignore! */ fgets(Buff, 2048, SceneFile); //takes in till \n is found } else if (!strcmp(cmd, "group")) { ++curGroupLevel; //printf("Current group level: %d\n", curGroupLevel); // get transform for previous group level currentTransform[curGroupLevel] = currentTransform[curGroupLevel-1]; } else if (!strcmp(cmd, "groupend")) { --curGroupLevel; //printf("Current group level: %d\n", curGroupLevel); } else if (!strcmp(cmd, "background")) { fscanf(SceneFile, "%lf", &backgroundColor.red); fscanf(SceneFile, "%lf", &backgroundColor.green); fscanf(SceneFile, "%lf", &backgroundColor.blue); } else if (!strcmp(cmd, "ambient")) { fscanf(SceneFile, "%lf", &ambient_light.red); fscanf(SceneFile, "%lf", &ambient_light.green); fscanf(SceneFile, "%lf", &ambient_light.blue); } else if (!strcmp(cmd, "light")) { if (numLights>=MAX_LIGHTS) { fprintf(stderr, "Error: max number of lights exceeded in description file\n"); fprintf(stderr, "Line %d\n", line); exit(-1); } fscanf(SceneFile,"%lf", &lightSources[numLights].color.red); fscanf(SceneFile,"%lf", &lightSources[numLights].color.green); fscanf(SceneFile,"%lf", &lightSources[numLights].color.blue); fscanf(SceneFile,"%lf", &lightSources[numLights].position.x); fscanf(SceneFile,"%lf", &lightSources[numLights].position.y); fscanf(SceneFile,"%lf", &lightSources[numLights].position.z); //printf("Color red: %lf\n", lightSources[numLights].color.red); //printf("Color green: %lf\n", lightSources[numLights].color.green); //printf("Color blue: %lf\n", lightSources[numLights].color.blue); //printf("Position x: %lf\n", lightSources[numLights].position.x); //printf("Position y: %lf\n", lightSources[numLights].position.y); //printf("Position z: %lf\n", lightSources[numLights].position.z); numLights++; } else if (!strcmp(cmd, "sphere")) { objects[numObjs].transform = currentTransform[curGroupLevel]; objects[numObjs].material = currentMaterial; numObjs++; if (numObjs>MAX_OBJECTS) { fprintf(stderr, "Error: max number of objects exceeded in description file\n"); fprintf(stderr, "Line %d\n", line); exit(-1); } } else if (!strcmp(cmd, "material")) { fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.red); fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.green); fscanf(SceneFile, "%lf", ¤tMaterial.diffuse.blue); fscanf(SceneFile, "%lf", ¤tMaterial.specular.red); fscanf(SceneFile, "%lf", ¤tMaterial.specular.green); fscanf(SceneFile, "%lf", ¤tMaterial.specular.blue); fscanf(SceneFile, "%lf", ¤tMaterial.shininess); // What do I do with this? // you need to put this into the object } else if (!strcmp(cmd, "refraction")) { //needs to be setup later } else if (!strcmp(cmd, "move")) { fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform[curGroupLevel]; //set current matrix to identity (loadIdentityTransoform b/c // we can't send in our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in move to identity. so that it's first (reversing //order) applyTransform(translateTransform(x,y,z),¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else if (!strcmp(cmd, "scale")) { //printf("Scale\n"); fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform [curGroupLevel]; //set current matrix to identity (loadIdentTransform b/c we can't send in //our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in scale to identity. so that it's first (reversing //order) applyTransform( scaleTransform(x, y, z), ¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else if (!strcmp(cmd, "rotate")) { fscanf(SceneFile, "%lf", &angle); fscanf(SceneFile, "%lf", &x); fscanf(SceneFile, "%lf", &y); fscanf(SceneFile, "%lf", &z); //save current matrix off to the side tempSave = currentTransform[curGroupLevel]; //set current matrix to identity (loadIdentTransform b/c we can't send in //our current matrix) loadIdentityTransform(¤tTransform[curGroupLevel]); //apply passed in rotate to identity. so that it's first (reversing //order) applyTransform(rotateTransform(angle,x,y,z), ¤tTransform[curGroupLevel]); //now put save matrix on to transform passed in. (reversing order) applyTransform( tempSave, ¤tTransform[curGroupLevel]); } else { fprintf(stderr, "Error: Unknown cmd '%s' in description file\n", cmd); fprintf(stderr, "Line %d\n", line); exit(-1); } fscanf(SceneFile, "%s", cmd); //get next command line++; } fclose(SceneFile); //close the scene file }
//-------------------------------------------------------------------------------------------------- /// Create display model, /// or at least empty scenes as frames that is delivered to the viewer /// The real geometry generation is done inside RivReservoirViewGeometry and friends //-------------------------------------------------------------------------------------------------- void RimGeoMechView::createDisplayModel() { if (m_viewer.isNull()) return; if (!(m_geomechCase && m_geomechCase->geoMechData() && m_geomechCase->geoMechData()->femParts())) return; int partCount = m_geomechCase->geoMechData()->femParts()->partCount(); if (partCount <= 0) return; // Remove all existing animation frames from the viewer. // The parts are still cached in the RivReservoir geometry and friends m_viewer->removeAllFrames(); if (isTimeStepDependentDataVisible()) { // Create empty frames in the viewer int frameCount = geoMechCase()->geoMechData()->femPartResults()->frameCount(); for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { cvf::ref<cvf::Scene> scene = new cvf::Scene; scene->addModel(new cvf::ModelBasicList); m_viewer->addFrame(scene.p()); } } // Set the Main scene in the viewer. Used when the animation is in "Stopped" state cvf::ref<cvf::Scene> mainScene = new cvf::Scene; m_viewer->setMainScene(mainScene.p()); // Grid model cvf::ref<cvf::ModelBasicList> mainSceneGridVizModel = new cvf::ModelBasicList; mainSceneGridVizModel->setName("GridModel"); m_vizLogic->appendNoAnimPartsToModel(mainSceneGridVizModel.p()); mainSceneGridVizModel->updateBoundingBoxesRecursive(); mainScene->addModel(mainSceneGridVizModel.p()); // Well path model double characteristicCellSize = geoMechCase()->geoMechData()->femParts()->characteristicElementSize(); cvf::BoundingBox femBBox = geoMechCase()->geoMechData()->femParts()->boundingBox(); m_wellPathPipeVizModel->removeAllParts(); addWellPathsToModel(m_wellPathPipeVizModel.p(), cvf::Vec3d(0, 0, 0), characteristicCellSize, femBBox, scaleTransform()); m_viewer->addStaticModelOnce(m_wellPathPipeVizModel.p()); // Cross sections m_crossSectionVizModel->removeAllParts(); crossSectionCollection->appendPartsToModel(m_crossSectionVizModel.p(), scaleTransform()); m_viewer->addStaticModelOnce(m_crossSectionVizModel.p()); // If the animation was active before recreating everything, make viewer view current frame if (isTimeStepDependentDataVisible()) { m_viewer->animationControl()->setCurrentFrameOnly(m_currentTimeStep); m_viewer->setCurrentFrame(m_currentTimeStep); } else { updateLegends(); m_vizLogic->updateStaticCellColors(-1); m_overlayInfoConfig()->update3DInfo(); } }
Transform identityTransform(void) { return scaleTransform(1, 1, 1); }