Ejemplo n.º 1
0
//-------------------------------------------------------------------
// FileName::dir_copy
//-------------------------------------------------------------------
void FileName::dir_copy(const String &strDest, bool bCreateDir, mode_t modeDir, uid_t uid, gid_t gid) throw( Exception )
{
  FileName fnDst;

  // Create destination path
  fnDst.set(strDest);
  fnDst.mkdir(modeDir, uid, gid);

  if( bCreateDir )
  {
    // Create source directory name inside destination path
    fnDst.set(strDest + dir_name() + SEP_PATH);
    fnDst.mkdir(modeDir, uid, gid);
  }

  if( !fnDst.is_path_name() )
    throw BadPathException(PSZ(String::str_format(ERR_BAD_DEST_PATH, PSZ(fnDst.full_name()))),
                           "FileName::dir_copy");

  // Recursively copying sub-directories
  FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR);
  while( dirEnum.find() )
    dirEnum.dir_copy(fnDst.path(), true, modeDir, uid, gid);

  // Copying directory files
  FileEnum fileEnum(full_name(), FileEnum::ENUM_FILE);
  while( fileEnum.find() )
    // Copy with metadata
    fileEnum.copy(fnDst.path(), true);
}
Ejemplo n.º 2
0
/* main function in embree namespace */
int main(int argc, char** argv)
{
    /* for best performance set FTZ and DAZ flags in MXCSR control and status register */
    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
    _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

    /* create stream for parsing */
    Ref<ParseStream> stream = new ParseStream(new CommandLineStream(argc, argv));

    /* parse command line */
    parseCommandLine(stream, FileName());

    /* load default scene if none specified */
    if (filename.ext() == "") {
        FileName file = FileName::executableFolder() + FileName("models/cornell_box.ecs");
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
    }

    /* configure number of threads */
    if (g_numThreads)
        g_rtcore += ",threads=" + std::to_string((long long)g_numThreads);
    if (g_numBenchmarkFrames)
        g_rtcore += ",benchmark=1";

    g_rtcore += g_subdiv_mode;

    /* load scene */
    if (strlwr(filename.ext()) == std::string("obj")) {
        g_scene->add(loadOBJ(filename,g_subdiv_mode != ""));
    }
    else if (strlwr(filename.ext()) == std::string("xml")) {
        g_scene->add(loadXML(filename,one));
    }
    else if (filename.ext() != "")
        THROW_RUNTIME_ERROR("invalid scene type: "+strlwr(filename.ext()));

    /* initialize ray tracing core */
    init(g_rtcore.c_str());

    /* send model */
    g_obj_scene.add(g_scene.dynamicCast<SceneGraph::Node>(),g_instancing_mode);
    g_scene = nullptr;
    set_scene(&g_obj_scene);

    /* benchmark mode */
    if (g_numBenchmarkFrames)
        renderBenchmark(outFilename);

    /* render to disk */
    if (outFilename.str() != "")
        renderToFile(outFilename);

    /* interactive mode */
    if (g_interactive) {
        initWindowState(argc,argv,tutorialName, g_width, g_height, g_fullscreen);
        enterWindowRunLoop(g_anim_mode);
    }

    return 0;
}
Ejemplo n.º 3
0
 /* opens a shared library */
 lib_t openLibrary(const std::string& file)
 {
   std::string fullName = file+".dll";
   FileName executable = getExecutableFileName();
   HANDLE handle = LoadLibrary((executable.path() + fullName).c_str());
   return lib_t(handle);
 }
Ejemplo n.º 4
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }

      /* load OBJ model*/
      else if (tag == "-i") {
        filename = path + cin->getFileName();
      }

      /* ambient light source */
      else if (tag == "-ambientlight") {
        g_ambientLightIntensity = cin->getVector3f();
      }

      /* point light source */
      else if (tag == "-pointlight") {
        g_pointLightPosition  = cin->getVector3f();
        g_pointLightIntensity = cin->getVector3f();
      }

      /* parse camera parameters */
      else if (tag == "-vp") g_camera.from = cin->getVector3f();
      else if (tag == "-vi") g_camera.to = cin->getVector3f();
      else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVector3f();
      else if (tag == "-vu") g_camera.up = cin->getVector3f();
      else if (tag == "-fov") g_camera.fov = cin->getFloat();

      /* frame buffer size */
      else if (tag == "-size") {
        g_width = cin->getInt();
        g_height = cin->getInt();
      }

      /* full screen mode */
      else if (tag == "-fullscreen") 
        g_fullscreen = true;
      
      /*! enable verbose output mode */
      else if (tag == "-verbose") {
        g_verbose = 1;
      }

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
Ejemplo n.º 5
0
 void postParseCommandLine() 
 {
   /* load default scene if none specified */
   if (scene->size() == 0 && sceneFilename.ext() == "") {
     FileName file = FileName::executableFolder() + FileName("models/cornell_box.ecs");
     parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
   }
 }
Ejemplo n.º 6
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      else if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }

      /* load OBJ model*/
      else if (tag == "-i") {
        filename = path + cin->getFileName();
      }

      /* parse camera parameters */
      else if (tag == "-vp") g_camera.from = cin->getVec3fa();
      else if (tag == "-vi") g_camera.to = cin->getVec3fa();
      else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();
      else if (tag == "-vu") g_camera.up = cin->getVec3fa();
      else if (tag == "-fov") g_camera.fov = cin->getFloat();

      /* frame buffer size */
      else if (tag == "-size") {
        g_width = cin->getInt();
        g_height = cin->getInt();
      }

      /* full screen mode */
      else if (tag == "-fullscreen") 
        g_fullscreen = true;

      /* rtcore configuration */
      else if (tag == "-rtcore")
        g_rtcore = cin->getString();

      /* number of threads to use */
      else if (tag == "-threads")
        g_numThreads = cin->getInt();

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
Ejemplo n.º 7
0
  /* opens a shared library */
  lib_t openLibrary(const std::string& file)
  {
#if defined(__MACOSX__)
    std::string fullName = "lib"+file+".dylib";
#else
    std::string fullName = "lib"+file+".so";
#endif
    void* lib = dlopen(fullName.c_str(), RTLD_NOW);
    if (lib) return lib_t(lib);
    FileName executable = getExecutableFileName();
    lib = dlopen((executable.path() + fullName).c_str(),RTLD_NOW);
    if (lib == NULL) THROW_RUNTIME_ERROR(dlerror());
    return lib_t(lib);
  }
Ejemplo n.º 8
0
  void loadKeyFrameAnimation(FileName &fileName)
  {
    PRINT(fileName);
    std::ifstream cin;
    cin.open(fileName.c_str());
    if (!cin.is_open()) {
      std::cerr << "cannot open " << fileName.str() << std::endl;
      return;
    }
    
    FileName path;
    path = fileName.path();

    char line[10000];
    memset(line, 0, sizeof(line));

    int cur = 0;
    while (cin.peek() != -1)
    {
      /* load next multiline */
      char* pline = line;
      while (true) {
        cin.getline(pline, sizeof(line) - (pline - line) - 16, '\n');
        ssize_t last = strlen(pline) - 1;
        if (last < 0 || pline[last] != '\\') break;
        pline += last;
        *pline++ = ' ';
      }
      OBJScene *scene = new OBJScene;
      FileName keyframe = path + FileName(line);
      loadOBJ(keyframe,one,*scene,true);	
      PRINT(keyframe);
      if (g_obj_scene.subdiv.size() != scene->subdiv.size())
	FATAL("#subdiv meshes differ");
      for (size_t i=0;i<g_obj_scene.subdiv.size();i++)
	if (g_obj_scene.subdiv[i]->positions.size() != scene->subdiv[i]->positions.size())
	  FATAL("#positions differ");

      g_keyframes.push_back(scene);
    } 
    cin.close();

    
  }
Ejemplo n.º 9
0
  CoronaLoader::CoronaLoader(const FileName& fileName, const AffineSpace3fa& space)
  {
    path = fileName.path();
    Ref<XML> xml = parseXML(fileName,"/.-",false);
    if (xml->name == "scene") 
    {
      Ref<SceneGraph::GroupNode> group = new SceneGraph::GroupNode;
      for (size_t i=0; i<xml->children.size(); i++) { 
        group->add(loadNode(xml->children[i]));
      }
      root = group.cast<SceneGraph::Node>();
    }
    else 
      THROW_RUNTIME_ERROR(xml->loc.str()+": invalid scene tag");

    if (space == AffineSpace3fa(one)) 
      return;
    
    root = new SceneGraph::TransformNode(space,root);
  }
Ejemplo n.º 10
0
void IsisMain() {

    //Get user parameters
    UserInterface &ui = Application::GetUserInterface();
    FileName inFile = ui.GetFileName("FROM");
    int numberOfLines = ui.GetInteger("NL");
    int lineOverlap   = ui.GetInteger("OVERLAP");

    //Throws exception if user is dumb
    if(lineOverlap >= numberOfLines) {
        throw IException(IException::User, "The Line Overlap (OVERLAP) must be less than the Number of Lines (LN).", _FILEINFO_);
    }

    //Opens the cube
    Cube cube;
    cube.open(inFile.expanded());

    //Loops through, cropping as desired
    int cropNum = 1;
    int startLine = 1;
    bool hasReachedEndOfCube = false;
    while(startLine <= cube.lineCount()  &&  not hasReachedEndOfCube) {
        //! Sets up the proper paramaters for running the crop program
        QString parameters = "FROM=" + inFile.expanded() +
                             " TO=" + inFile.path() + "/" + inFile.baseName() + ".segment" + toString(cropNum) + ".cub"
                             + " LINE=" + toString(startLine) + " NLINES=";

        if(startLine + numberOfLines > cube.lineCount()) {
            parameters += toString(cube.lineCount() - (startLine - 1));
            hasReachedEndOfCube = true;
        }
        else {
            parameters += toString(numberOfLines);
        }
        ProgramLauncher::RunIsisProgram("crop", parameters);
        //The starting line for next crop
        startLine = 1 + cropNum * (numberOfLines - lineOverlap);
        cropNum++;
    }
}
Ejemplo n.º 11
0
  FileName FileName::createTempFile(FileName templateFileName) {
    QString preppedFileName = QString("%1/%2XXXXXX.%3").arg(templateFileName.path())
        .arg(templateFileName.baseName()).arg(templateFileName.extension());
    QTemporaryFile tempFile(preppedFileName);
    tempFile.setAutoRemove(false);

    if (!tempFile.open()) {
      throw IException(IException::Io,
          QObject::tr("Could not create a unique temporary file name based on [%1]")
            .arg(templateFileName.original()),
          _FILEINFO_);
    }

    // We want to set the 'original' path as correctly as possible. So let's use the input original
    //   path with the output temp file's file name in our result.
    FileName result;
    QString newTempFileNameStr = templateFileName.originalPath() + "/" +
        QFileInfo(tempFile.fileName()).fileName();
    result = FileName(newTempFileNameStr);

    return result;
  }
Ejemplo n.º 12
0
  SceneLoadingTutorialApplication::SceneLoadingTutorialApplication (const std::string& tutorialName, int features)

    : TutorialApplication(tutorialName, features),
      scene(new SceneGraph::GroupNode),
      convert_tris_to_quads(false),
      convert_tris_to_quads_prop(inf),
      convert_bezier_to_lines(false),
      convert_hair_to_curves(false),
      convert_bezier_to_bspline(false),
      convert_bspline_to_bezier(false),
      remove_mblur(false),
      remove_non_mblur(false),
      sceneFilename(""),
      instancing_mode(SceneGraph::INSTANCING_NONE),
      print_scene_cameras(false)
  {
    registerOption("i", [this] (Ref<ParseStream> cin, const FileName& path) {
        sceneFilename = path + cin->getFileName();
      }, "-i <filename>: parses scene from <filename>");

    registerOption("animlist", [this] (Ref<ParseStream> cin, const FileName& path) {
        FileName listFilename = path + cin->getFileName();

        std::ifstream listFile;
        listFile.open(listFilename.c_str());
        if (!listFile.is_open()) {
          THROW_RUNTIME_ERROR("cannot open " + listFilename.str());
        }
        else
        {
          while (!listFile.eof())
          {
            std::string line;
            listFile >> line;
            if (line != "")
              keyFramesFilenames.push_back(listFilename.path() + line);
          }
        }
      }, "-animlist <filename>: parses a sequence of .obj/.xml files listed in <filename> and adds them to the scene");
Ejemplo n.º 13
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      else if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }

      /* load OBJ model*/
      else if (tag == "-i") {
        filename = path + cin->getFileName();
      }

      /* parse camera parameters */
      else if (tag == "-vp") g_camera.from = cin->getVec3fa();
      else if (tag == "-vi") g_camera.to = cin->getVec3fa();
      else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();
      else if (tag == "-vu") g_camera.up = cin->getVec3fa();
      else if (tag == "-fov") g_camera.fov = cin->getFloat();

      /* frame buffer size */
      else if (tag == "-size") {
        g_width = cin->getInt();
        g_height = cin->getInt();
      }

      /* full screen mode */
      else if (tag == "-fullscreen") 
        g_fullscreen = true;

      /* output filename */
      else if (tag == "-o") {
        outFilename = cin->getFileName();
	g_interactive = false;
      }

      /* number of frames to render in benchmark mode */
      else if (tag == "-benchmark") {
        g_skipBenchmarkFrames = cin->getInt();
        g_numBenchmarkFrames  = cin->getInt();
	g_interactive = false;
      }

      /* rtcore configuration */
      else if (tag == "-rtcore")
        g_rtcore = cin->getString();

      /* number of threads to use */
      else if (tag == "-threads")
        g_numThreads = cin->getInt();

       /* ambient light source */
      else if (tag == "-ambientlight") 
      {
        const Vec3fa L = cin->getVec3fa();
        g_obj_scene.ambientLights.push_back(OBJScene::AmbientLight(L));
      }

      /* point light source */
      else if (tag == "-pointlight") 
      {
        const Vec3fa P = cin->getVec3fa();
        const Vec3fa I = cin->getVec3fa();
        g_obj_scene.pointLights.push_back(OBJScene::PointLight(P,I));
      }

      /* directional light source */
      else if (tag == "-directionallight" || tag == "-dirlight") 
      {
        const Vec3fa D = cin->getVec3fa();
        const Vec3fa E = cin->getVec3fa();
        g_obj_scene.directionalLights.push_back(OBJScene::DirectionalLight(D,E));
      }

      /* distant light source */
      else if (tag == "-distantlight") 
      {
        const Vec3fa D = cin->getVec3fa();
        const Vec3fa L = cin->getVec3fa();
        const float halfAngle = cin->getFloat();
        g_obj_scene.distantLights.push_back(OBJScene::DistantLight(D,L,halfAngle));
      }

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
Ejemplo n.º 14
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName &path) {

    for (std::string term = cin->getString() ; term != "" ; term = cin->getString()) {

      /*! Command line parameters from a file. */
      if (term == "-c") { FileName file = path + cin->getFileName();  parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path()); }

      /* load OBJ model*/
      else if (term == "-i") {
        filename = path + cin->getFileName();
      }

      /*! Camera field of view. */
      else if (term == "-fov") g_camera.fov = cin->getFloat();

      /*! Full screen mode. */
      else if (term == "-fullscreen") g_fullscreen = true;

      /* output filename */
	  else if (term == "-o") {
		  g_interactive = false;
		  outFilename = cin->getFileName();
	  }
      
      /*! Embree configuration. */
      else if (term == "-rtcore") g_rtcore = cin->getString();

      /*! Window size. */
      else if (term == "-size") { g_width = cin->getInt();  g_height = cin->getInt(); }

      /*! Thread count. */
      else if (term == "-threads") { g_numThreads = cin->getInt(); }

      /*! Camera view direction. */
      else if (term == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();

      /*! Camera look point. */
      else if (term == "-vi") g_camera.to = cin->getVec3fa();

      /*! Camera position. */
      else if (term == "-vp") g_camera.from = cin->getVec3fa();

      /*! Camera up vector. */
      else if (term == "-vu") g_camera.up = cin->getVec3fa();

      else if (term == "-cache") 
	g_subdiv_mode = ",subdiv_accel=bvh4.subdivpatch1cached";

      else if (term == "-lazy") 
	g_subdiv_mode = ",subdiv_accel=bvh4.grid.lazy";

      else if (term == "-pregenerate") 
	g_subdiv_mode = ",subdiv_accel=bvh4.grid.eager";

      /*! Skip unknown command line parameters. */
      else std::cerr << "Unknown command line parameter: " << getParameterString(cin, term) << std::endl;

    }

  }
Ejemplo n.º 15
0
  TutorialApplication::TutorialApplication (const std::string& tutorialName, int features)

    : Application(features),
      tutorialName(tutorialName),

      shader(SHADER_DEFAULT),

      width(512),
      height(512),
      pixels(nullptr),

      outputImageFilename(""),

      skipBenchmarkFrames(0),
      numBenchmarkFrames(0),
      numBenchmarkRepetitions(1),

      interactive(true),
      fullscreen(false),

      window_width(512),
      window_height(512),
      windowID(0),

      time0(getSeconds()),
      debug_int0(0),
      debug_int1(0),

      mouseMode(0),
      clickX(0), clickY(0),
      speed(1.0f),
      moveDelta(zero),
      command_line_camera(false),
      print_frame_rate(false),
      avg_render_time(64,1.0),
      avg_frame_time(64,1.0),
      avg_mrayps(64,1.0),
      print_camera(false),

      debug0(0),
      debug1(0),
      debug2(0),
      debug3(0),

      iflags_coherent(RTC_INTERSECT_COHERENT),
      iflags_incoherent(RTC_INTERSECT_INCOHERENT)
  {
    /* only a single instance of this class is supported */
    assert(instance == nullptr);
    instance = this;

    /* for best performance set FTZ and DAZ flags in MXCSR control and status register */
    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
    _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

    registerOption("c", [this] (Ref<ParseStream> cin, const FileName& path) {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }, "-c <filename>: parses command line option from <filename>");

    registerOption("o", [this] (Ref<ParseStream> cin, const FileName& path) {
        outputImageFilename = cin->getFileName();
        interactive = false;
      }, "-o <filename>: output image filename");

    /* camera settings */
    registerOption("vp", [this] (Ref<ParseStream> cin, const FileName& path) {
        camera.from = cin->getVec3fa();
        command_line_camera = true;
      }, "--vp <float> <float> <float>: camera position");

    registerOption("vi", [this] (Ref<ParseStream> cin, const FileName& path) {
        camera.to = cin->getVec3fa();
        command_line_camera = true;
      }, "--vi <float> <float> <float>: camera lookat position");

    registerOption("vd", [this] (Ref<ParseStream> cin, const FileName& path) {
        camera.to = camera.from + cin->getVec3fa();
        command_line_camera = true;
      }, "--vd <float> <float> <float>: camera direction vector");

    registerOption("vu", [this] (Ref<ParseStream> cin, const FileName& path) {
        camera.up = cin->getVec3fa();
        command_line_camera = true;
      }, "--vu <float> <float> <float>: camera up vector");

    registerOption("fov", [this] (Ref<ParseStream> cin, const FileName& path) {
        camera.fov = cin->getFloat();
        command_line_camera = true;
      }, "--fov <float>: vertical field of view");

    /* framebuffer settings */
    registerOption("size", [this] (Ref<ParseStream> cin, const FileName& path) {
        width = cin->getInt();
        height = cin->getInt();
      }, "--size <width> <height>: sets image size");

    registerOption("fullscreen", [this] (Ref<ParseStream> cin, const FileName& path) {
        fullscreen = true;
      }, "--fullscreen: starts in fullscreen mode");

    registerOption("benchmark", [this] (Ref<ParseStream> cin, const FileName& path) {
        skipBenchmarkFrames = cin->getInt();
        numBenchmarkFrames  = cin->getInt();
        if (cin->peek() != "" && cin->peek()[0] != '-')
          numBenchmarkRepetitions = cin->getInt();
        interactive = false;
        rtcore += ",benchmark=1,start_threads=1";
      }, "--benchmark <N> <M> <R>: enabled benchmark mode, builds scene, skips N frames, renders M frames, and repeats this R times");

    registerOption("nodisplay", [this] (Ref<ParseStream> cin, const FileName& path) {
        skipBenchmarkFrames = 0;
        numBenchmarkFrames  = 2048;
        interactive = false;
      }, "--nodisplay: enabled benchmark mode, continously renders frames");

    registerOption("print-frame-rate", [this] (Ref<ParseStream> cin, const FileName& path) {
        print_frame_rate = true;
      }, "--print-frame-rate: prints framerate for each frame on console");

     registerOption("print-camera", [this] (Ref<ParseStream> cin, const FileName& path) {
         print_camera = true;
      }, "--print-camera: prints camera for each frame on console");

     registerOption("debug0", [this] (Ref<ParseStream> cin, const FileName& path) {
         debug0 = cin->getInt();
       }, "--debug0: sets internal debugging value");

     registerOption("debug1", [this] (Ref<ParseStream> cin, const FileName& path) {
         debug1 = cin->getInt();
       }, "--debug1: sets internal debugging value");

     registerOption("debug2", [this] (Ref<ParseStream> cin, const FileName& path) {
         debug2 = cin->getInt();
       }, "--debug2: sets internal debugging value");

     registerOption("debug3", [this] (Ref<ParseStream> cin, const FileName& path) {
         debug3 = cin->getInt();
       }, "--debug3: sets internal debugging value");

    /* output filename */
    registerOption("shader", [this] (Ref<ParseStream> cin, const FileName& path) {
        std::string mode = cin->getString();
        if      (mode == "default" ) shader = SHADER_DEFAULT;
        else if (mode == "eyelight") shader = SHADER_EYELIGHT;
        else if (mode == "occlusion") shader = SHADER_OCCLUSION;
        else if (mode == "uv"      ) shader = SHADER_UV;
        else if (mode == "texcoords") shader = SHADER_TEXCOORDS;
        else if (mode == "texcoords-grid") shader = SHADER_TEXCOORDS_GRID;
        else if (mode == "Ng"      ) shader = SHADER_NG;
        else if (mode == "cycles"  ) { shader = SHADER_CYCLES; scale = cin->getFloat(); }
        else if (mode == "geomID"  ) shader = SHADER_GEOMID;
        else if (mode == "primID"  ) shader = SHADER_GEOMID_PRIMID;
        else if (mode == "ao"      ) shader = SHADER_AMBIENT_OCCLUSION;
        else throw std::runtime_error("invalid shader:" +mode);
      },
      "--shader <string>: sets shader to use at startup\n"
      "  default: default tutorial shader\n"
      "  eyelight: eyelight shading\n"
      "  occlusion: occlusion shading\n"
      "  uv: uv debug shader\n"
      "  texcoords: texture coordinate debug shader\n"
      "  texcoords-grid: grid texture debug shader\n"
      "  Ng: visualization of shading normal\n"
      "  cycles <float>: CPU cycle visualization\n"
      "  geomID: visualization of geometry ID\n"
      "  primID: visualization of geometry and primitive ID\n"
      "  ao: ambient occlusion shader");

    if (features & FEATURE_STREAM)
    {
      /* register parsing of stream mode */
      registerOption("mode", [] (Ref<ParseStream> cin, const FileName& path) {
          std::string mode = cin->getString();
          if      (mode == "normal") g_mode = MODE_NORMAL;
          else if (mode == "stream") g_mode = MODE_STREAM;
          else throw std::runtime_error("invalid mode:" +mode);
        },
        "--mode: sets rendering mode\n"
        "  normal  : normal mode\n"
        "  stream  : stream mode\n");
    }

    registerOption("coherent", [this] (Ref<ParseStream> cin, const FileName& path) {
        g_iflags_coherent   = iflags_coherent   = RTC_INTERSECT_COHERENT;
        g_iflags_incoherent = iflags_incoherent = RTC_INTERSECT_COHERENT;
      }, "--coherent: force using RTC_INTERSECT_COHERENT hint when tracing rays");

    registerOption("incoherent", [this] (Ref<ParseStream> cin, const FileName& path) {
        g_iflags_coherent   = iflags_coherent   = RTC_INTERSECT_INCOHERENT;
        g_iflags_incoherent = iflags_incoherent = RTC_INTERSECT_INCOHERENT;
      }, "--incoherent: force using RTC_INTERSECT_INCOHERENT hint when tracing rays");
  }
Ejemplo n.º 16
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      else if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }

      /* load OBJ model*/
      else if (tag == "-i") {
        filename = path + cin->getFileName();
      }

      /* parse camera parameters */
      else if (tag == "-vp") g_camera.from = cin->getVec3fa();
      else if (tag == "-vi") g_camera.to = cin->getVec3fa();
      else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();
      else if (tag == "-vu") g_camera.up = cin->getVec3fa();
      else if (tag == "-fov") g_camera.fov = cin->getFloat();

      /* frame buffer size */
      else if (tag == "-size") {
        g_width = cin->getInt();
        g_height = cin->getInt();
      }

      /* full screen mode */
      else if (tag == "-fullscreen") 
        g_fullscreen = true;

      /* output filename */
      else if (tag == "-o") {
        outFilename = cin->getFileName();
	g_interactive = false;
      }

      else if (tag == "-objlist") {
        keyframeList = cin->getFileName();
      }

      /* subdivision mode */
      else if (tag == "-cache") 
	g_subdiv_mode = ",subdiv_accel=bvh4.subdivpatch1cached";

      else if (tag == "-lazy") 
	g_subdiv_mode = ",subdiv_accel=bvh4.grid.lazy";

      else if (tag == "-pregenerate") 
	g_subdiv_mode = ",subdiv_accel=bvh4.grid.eager";
      
      else if (tag == "-loop") 
	g_loop_mode = true;

      else if (tag == "-anim") 
	g_anim_mode = true;

      else if (tag == "-shader") {
        std::string mode = cin->getString();
        if      (mode == "default" ) g_shader = SHADER_DEFAULT;
        else if (mode == "eyelight") g_shader = SHADER_EYELIGHT;
        else if (mode == "uv"      ) g_shader = SHADER_UV;
        else if (mode == "Ng"      ) g_shader = SHADER_NG;
        else if (mode == "geomID"  ) g_shader = SHADER_GEOMID;
        else if (mode == "primID"  ) g_shader = SHADER_GEOMID_PRIMID;
        else throw std::runtime_error("invalid shader:" +mode);
      }

      /* number of frames to render in benchmark mode */
      else if (tag == "-benchmark") {
        g_skipBenchmarkFrames = cin->getInt();
        g_numBenchmarkFrames  = cin->getInt();
	g_interactive = false;
      }

      /* rtcore configuration */
      else if (tag == "-rtcore")
        g_rtcore = cin->getString();

      /* number of threads to use */
      else if (tag == "-threads")
        g_numThreads = cin->getInt();

      /* ambient light source */
      else if (tag == "-ambientlight") 
      {
        const Vec3fa L = cin->getVec3fa();
        g_obj_scene.ambientLights.push_back(OBJScene::AmbientLight(L));
      }

      /* point light source */
      else if (tag == "-pointlight") 
      {
        const Vec3fa P = cin->getVec3fa();
        const Vec3fa I = cin->getVec3fa();
        g_obj_scene.pointLights.push_back(OBJScene::PointLight(P,I));
      }

      /* directional light source */
      else if (tag == "-directionallight" || tag == "-dirlight") 
      {
        const Vec3fa D = cin->getVec3fa();
        const Vec3fa E = cin->getVec3fa();
        g_obj_scene.directionalLights.push_back(OBJScene::DirectionalLight(D,E));
      }

      /* distant light source */
      else if (tag == "-distantlight") 
      {
        const Vec3fa D = cin->getVec3fa();
        const Vec3fa L = cin->getVec3fa();
        const float halfAngle = cin->getFloat();
        g_obj_scene.distantLights.push_back(OBJScene::DistantLight(D,L,halfAngle));
      }

      /* converts triangle meshes into subdiv meshes */
      else if (tag == "-subdiv") {
	g_only_subdivs = true;
      }

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
Ejemplo n.º 17
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      else if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
      }

      /* load model */
      else if (tag == "-i") {
        g_scene->add(SceneGraph::load(path + cin->getFileName()));
      }

      /* convert triangles to quads */
      else if (tag == "-convert-triangles-to-quads") {
        g_scene->triangles_to_quads();
      }

      /* convert to subdivs */
      else if (tag == "-convert-to-subdivs") {
        g_scene->triangles_to_quads();
        g_scene->quads_to_subdivs();
      }

      /* convert bezier to lines */
      else if (tag == "-convert-bezier-to-lines") {
        g_scene->bezier_to_lines();
      }

      /* load terrain */
      else if (tag == "-terrain") 
      {
        Ref<Image> tex = loadImage(path + cin->getFileName());
        const Vec3fa lower = cin->getVec3fa();
        const Vec3fa upper = cin->getVec3fa();
        g_height_field = new HeightField(tex,BBox3fa(lower,upper));
        g_scene->add(g_height_field->geometry());
      }

      /* distribute model */
      else if (tag == "-distribute") {
        Ref<SceneGraph::Node> object = SceneGraph::load(path + cin->getFileName());
        Ref<Image> distribution = loadImage(path + cin->getFileName());
        const float minDistance = cin->getFloat();
        const size_t N = cin->getInt();
        Ref<Instantiator> instantiator = new Instantiator(g_height_field,object,distribution,minDistance,N);
        instantiator->instantiate(g_scene);
      }

      /* instantiate model a single time */
      else if (tag == "-instantiate") {
        Ref<SceneGraph::Node> object = SceneGraph::load(path + cin->getFileName());
        const float px = cin->getFloat();
        const float py = cin->getFloat();
        const Vec2f p(px,py);
        const float angle = cin->getFloat()/180.0f*float(pi);
        const AffineSpace3fa space = g_height_field->get(p)*AffineSpace3fa::rotate(Vec3fa(0,1,0),angle);
        g_scene->add(new SceneGraph::TransformNode(space,object));
      }

      /* enable texture embedding */
      else if (tag == "-embed-textures") {
        embedTextures = true;
      }

      /* enable texture referencing */
      else if (tag == "-reference-textures") {
        embedTextures = false;
      }

      /* output filename */
      else if (tag == "-o") {
        SceneGraph::store(g_scene.dynamicCast<SceneGraph::Node>(),path + cin->getFileName(),embedTextures);
      }

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
  OBJLoader::OBJLoader(const FileName &fileName, const bool subdivMode) 
    : path(fileName.path()), group(new SceneGraph::GroupNode), subdivMode(subdivMode)
  {
    /* open file */
    std::ifstream cin;
    cin.open(fileName.c_str());
    if (!cin.is_open()) {
      THROW_RUNTIME_ERROR("cannot open " + fileName.str());
      return;
    }

    /* generate default material */
    Material objmtl; new (&objmtl) OBJMaterial;
    Ref<SceneGraph::MaterialNode> defaultMaterial = new SceneGraph::MaterialNode(objmtl);
    curMaterial = defaultMaterial;

    char line[10000];
    memset(line, 0, sizeof(line));

    while (cin.peek() != -1)
    {
      /* load next multiline */
      char* pline = line;
      while (true) {
        cin.getline(pline, sizeof(line) - (pline - line) - 16, '\n');
        ssize_t last = strlen(pline) - 1;
        if (last < 0 || pline[last] != '\\') break;
        pline += last;
        *pline++ = ' ';
      }

      const char* token = trimEnd(line + strspn(line, " \t"));
      if (token[0] == 0) continue;

      /*! parse position */
      if (token[0] == 'v' && isSep(token[1])) { 
        v.push_back(getVec3f(token += 2)); continue;
      }

      /* parse normal */
      if (token[0] == 'v' && token[1] == 'n' && isSep(token[2])) { 
        vn.push_back(getVec3f(token += 3)); 
        continue; 
      }

      /* parse texcoord */
      if (token[0] == 'v' && token[1] == 't' && isSep(token[2])) { vt.push_back(getVec2f(token += 3)); continue; }

      /*! parse face */
      if (token[0] == 'f' && isSep(token[1]))
      {
        parseSep(token += 1);

        std::vector<Vertex> face;
        while (token[0]) {
	  Vertex vtx = getInt3(token);
          face.push_back(vtx);
          parseSepOpt(token);
        }
        curGroup.push_back(face);
        continue;
      }

      /*! parse edge crease */
      if (token[0] == 'e' && token[1] == 'c' && isSep(token[2]))
      {
	parseSep(token += 2);
	float w = getFloat(token);
	parseSepOpt(token);
	int a = fix_v(getInt(token));
	parseSepOpt(token);
	int b = fix_v(getInt(token));
	parseSepOpt(token);
	ec.push_back(Crease(w, a, b));
	continue;
      }

      /*! use material */
      if (!strncmp(token, "usemtl", 6) && isSep(token[6]))
      {
        flushFaceGroup();
        std::string name(parseSep(token += 6));
        if (material.find(name) == material.end()) curMaterial = defaultMaterial;
        else curMaterial = material[name];
        continue;
      }

      /* load material library */
      if (!strncmp(token, "mtllib", 6) && isSep(token[6])) {
        loadMTL(path + std::string(parseSep(token += 6)));
        continue;
      }

      // ignore unknown stuff
    }
    flushFaceGroup();

    cin.close();
  }
Ejemplo n.º 19
0
    void importOBJ(const std::shared_ptr<Node> &world, const FileName &fileName)
    {
      tinyobj::attrib_t attrib;
      std::vector<tinyobj::shape_t> shapes;
      std::vector<tinyobj::material_t> materials;

      std::string err;
      const std::string containingPath = fileName.path();

      std::cout << "parsing OBJ input file... \n";
      bool ret = tinyobj::LoadObj(&attrib,
                                  &shapes,
                                  &materials,
                                  &err,
                                  fileName.c_str(),
                                  containingPath.c_str());

#if 0 // NOTE(jda) - enable if you want to see warnings from TinyOBJ
      if (!err.empty())
        std::cerr << "#ospsg: obj parsing warning(s)...\n" << err << std::endl;
#endif

      if (!ret) {
        std::cerr << "#ospsg: FATAL error parsing obj file, no geometry added"
                  << " to the scene!" << std::endl;
        return;
      }

      auto sgMaterials = createSgMaterials(materials, containingPath);

      std::string base_name = fileName.name() + '_';
      int shapeId           = 0;

      std::cout << "...adding found triangle groups to the scene...\n";

      size_t shapeCounter = 0;
      size_t numShapes    = shapes.size();
      size_t increment    = numShapes / size_t(10);
      int    incrementer  = 0;

#if !USE_INSTANCES
      auto objInstance = createNode("instance", "Instance");
      world->add(objInstance);
#endif
      for (auto &shape : shapes) {
        for (int numVertsInFace : shape.mesh.num_face_vertices) {
          if (numVertsInFace != 3) {
            std::cerr << "Warning: more thant 3 verts in face!";
            PRINT(numVertsInFace);
          }
        }

        if (shapeCounter++ > (increment * incrementer + 1))
          std::cout << incrementer++ * 10 << "%\n";

        auto name = base_name + std::to_string(shapeId++) + '_' + shape.name;
        auto mesh = createNode(name, "TriangleMesh")->nodeAs<TriangleMesh>();

        auto v = createNode("vertex", "DataVector3f")->nodeAs<DataVector3f>();
        auto numSrcIndices = shape.mesh.indices.size();
        v->v.reserve(numSrcIndices);

        auto vi = createNode("index", "DataVector3i")->nodeAs<DataVector3i>();
        vi->v.reserve(numSrcIndices / 3);

        auto vn = createNode("normal", "DataVector3f")->nodeAs<DataVector3f>();
        vn->v.reserve(numSrcIndices);

        auto vt =
            createNode("texcoord", "DataVector2f")->nodeAs<DataVector2f>();
        vt->v.reserve(numSrcIndices);

        for (size_t i = 0; i < shape.mesh.indices.size(); i += 3) {
          auto idx0 = shape.mesh.indices[i + 0];
          auto idx1 = shape.mesh.indices[i + 1];
          auto idx2 = shape.mesh.indices[i + 2];

          auto prim = vec3i(i + 0, i + 1, i + 2);
          vi->push_back(prim);

          v->push_back(vec3f(attrib.vertices[idx0.vertex_index * 3 + 0],
                             attrib.vertices[idx0.vertex_index * 3 + 1],
                             attrib.vertices[idx0.vertex_index * 3 + 2]));
          v->push_back(vec3f(attrib.vertices[idx1.vertex_index * 3 + 0],
                             attrib.vertices[idx1.vertex_index * 3 + 1],
                             attrib.vertices[idx1.vertex_index * 3 + 2]));
          v->push_back(vec3f(attrib.vertices[idx2.vertex_index * 3 + 0],
                             attrib.vertices[idx2.vertex_index * 3 + 1],
                             attrib.vertices[idx2.vertex_index * 3 + 2]));

          // TODO create missing normals&texcoords if only some faces have them
          if (!attrib.normals.empty() && idx0.normal_index != -1) {
            vn->push_back(vec3f(attrib.normals[idx0.normal_index * 3 + 0],
                                attrib.normals[idx0.normal_index * 3 + 1],
                                attrib.normals[idx0.normal_index * 3 + 2]));
            vn->push_back(vec3f(attrib.normals[idx1.normal_index * 3 + 0],
                                attrib.normals[idx1.normal_index * 3 + 1],
                                attrib.normals[idx1.normal_index * 3 + 2]));
            vn->push_back(vec3f(attrib.normals[idx2.normal_index * 3 + 0],
                                attrib.normals[idx2.normal_index * 3 + 1],
                                attrib.normals[idx2.normal_index * 3 + 2]));
          }

          if (!attrib.texcoords.empty() && idx0.texcoord_index != -1) {
            vt->push_back(vec2f(attrib.texcoords[idx0.texcoord_index * 2 + 0],
                                attrib.texcoords[idx0.texcoord_index * 2 + 1]));
            vt->push_back(vec2f(attrib.texcoords[idx1.texcoord_index * 2 + 0],
                                attrib.texcoords[idx1.texcoord_index * 2 + 1]));
            vt->push_back(vec2f(attrib.texcoords[idx2.texcoord_index * 2 + 0],
                                attrib.texcoords[idx2.texcoord_index * 2 + 1]));
          }
        }

        mesh->add(v);
        mesh->add(vi);
        if (!vn->empty())
          mesh->add(vn);
        if (!vt->empty())
          mesh->add(vt);

        auto pmids = createNode("prim.materialID",
                                "DataVector1i")->nodeAs<DataVector1i>();

        auto numMatIds = shape.mesh.material_ids.size();
        pmids->v.reserve(numMatIds);

        for (auto id : shape.mesh.material_ids)
          pmids->v.push_back(id);

        mesh->add(pmids);
        mesh->add(sgMaterials);

        auto model = createNode(name + "_model", "Model");
        model->add(mesh);

        // TODO: Large .obj models with lots of groups run much slower with each
        //       group put in a separate instance. In the future, we want to
        //       support letting the user (ospExampleViewer, for starters)
        //       specify if each group should be placed in an instance or not.
#if USE_INSTANCES
        auto instance = createNode(name + "_instance", "Instance");
        instance->setChild("model", model);
        model->setParent(instance);

        world->add(instance);
#else
        (*objInstance)["model"].add(mesh);
#endif

      }

      std::cout << "...finished import!\n";
    }
Ejemplo n.º 20
0
  /* main function in embree namespace */
  int main(int argc, char** argv) 
  {
    /* for best performance set FTZ and DAZ flags in MXCSR control and status register */
    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
    _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

    /* create stream for parsing */
    Ref<ParseStream> stream = new ParseStream(new CommandLineStream(argc, argv));

    /* parse command line */  
    parseCommandLine(stream, FileName());

    /* load default scene if none specified */
    if (filename.ext() == "") {
      FileName file = FileName::executableFolder() + FileName("models/cornell_box.ecs");
      parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
    }

    /* configure number of threads */
    if (g_numThreads) 
      g_rtcore += ",threads=" + std::to_string((long long)g_numThreads);
    if (g_numBenchmarkFrames)
      g_rtcore += ",benchmark=1";

    g_rtcore += g_subdiv_mode;

    /* load scene */
    if (strlwr(filename.ext()) == std::string("obj"))
    {
      if (g_subdiv_mode != "") {
        std::cout << "enabling subdiv mode" << std::endl;
        loadOBJ(filename,one,g_obj_scene,true);	
      }
      else
        loadOBJ(filename,one,g_obj_scene);
    }
    else if (strlwr(filename.ext()) == std::string("xml"))
      loadXML(filename,one,g_obj_scene);
    else if (filename.ext() != "")
      THROW_RUNTIME_ERROR("invalid scene type: "+strlwr(filename.ext()));
    
    /* load keyframes */
    if (keyframeList.str() != "")
      loadKeyFrameAnimation(keyframeList);
    
    /* initialize ray tracing core */
    init(g_rtcore.c_str());

    /* set shader mode */
    switch (g_shader) {
    case SHADER_EYELIGHT: key_pressed(GLUT_KEY_F2); break;
    case SHADER_UV      : key_pressed(GLUT_KEY_F4); break;
    case SHADER_NG      : key_pressed(GLUT_KEY_F5); break;
    case SHADER_GEOMID  : key_pressed(GLUT_KEY_F6); break;
    case SHADER_GEOMID_PRIMID: key_pressed(GLUT_KEY_F7); break;
    };
    
    /* convert triangle meshes to subdiv meshes */
    if (g_only_subdivs)
      g_obj_scene.convert_to_subdiv();

    /* send model */
    set_scene(&g_obj_scene);
    
    /* send keyframes */
    if (g_keyframes.size())
      set_scene_keyframes(&*g_keyframes.begin(),g_keyframes.size());

    /* benchmark mode */
    if (g_numBenchmarkFrames)
      renderBenchmark(outFilename);
    
    /* render to disk */
    if (outFilename.str() != "")
      renderToFile(outFilename);
    
    /* interactive mode */
    if (g_interactive) {
      initWindowState(argc,argv,tutorialName, g_width, g_height, g_fullscreen);
      enterWindowRunLoop(g_anim_mode);

    }

    return 0;
  }
Ejemplo n.º 21
0
  static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
  {
    while (true)
    {
      std::string tag = cin->getString();
      if (tag == "") return;

      /* parse command line parameters from a file */
      if (tag == "-c") {
        FileName file = path + cin->getFileName();
        parseCommandLine(new ParseStream(new LineCommentFilter(file,"#")),file.path());
      }

      /* read model from file */
      else if (tag == "-i")
        *g_scene += load(path+cin->getFileName());

      /* triangulated sphere */
      else if (tag == "-trisphere")
      {
        Ref<Device::RTShape> sphere = g_device->rtNewShape("sphere");
        sphere->rtSetFloat3("P",cin->getVec3f());
        sphere->rtSetFloat1("r",cin->getFloat());
        sphere->rtSetInt1("numTheta",cin->getInt());
        sphere->rtSetInt1("numPhi",cin->getInt());
        sphere->rtCommit();

        Ref<Device::RTMaterial> material = g_device->rtNewMaterial("matte");
        material->rtSetFloat3("reflection",Col3f(1.0f,0.0f,0.0f));
        material->rtCommit();

        *g_scene += new ShapeNode(sphere,material);
      }

      /* ambient light source */
      else if (tag == "-ambientlight") {
        Ref<Device::RTLight> light = g_device->rtNewLight("ambientlight");
        light->rtSetFloat3("L",cin->getVec3f());
        light->rtCommit();
        *g_scene += new LightNode(light);
      }

      /* point light source */
      else if (tag == "-pointlight") {
		Vec3f P = cin->getVec3f();
		Vec3f I = cin->getVec3f();
		std::cout << " P " << P.x << " :  " << P.y << " : " << P.z << std::endl;
		std::cout << " I " << I.x << " : " << I.y << " : " << I.z << std::endl;
        Ref<Device::RTLight> light = g_device->rtNewLight("pointlight");
        light->rtSetFloat3("P",P);
        light->rtSetFloat3("I",I);
        light->rtCommit();
        *g_scene += new LightNode(light);
      }

      /* distant light source */
      else if (tag == "-distantlight") {
        Ref<Device::RTLight> light = g_device->rtNewLight("distantlight");
        light->rtSetFloat3("D",cin->getVec3f());
        light->rtSetFloat3("L",cin->getVec3f());
        light->rtSetFloat1("halfAngle",cin->getFloat());
        light->rtCommit();
        *g_scene += new LightNode(light);
      }
      /* triangular light source */
      else if (tag == "-trianglelight") {
        Vec3f P = cin->getVec3f();
        Vec3f U = cin->getVec3f();
        Vec3f V = cin->getVec3f();
        Vec3f L = cin->getVec3f();
        Ref<Device::RTLight> light = g_device->rtNewLight("trianglelight");
        light->rtSetFloat3("v0",P);
        light->rtSetFloat3("v1",P+U);
        light->rtSetFloat3("v2",P+V);
        light->rtSetFloat3("L" ,L);
        light->rtCommit();
        *g_scene += new LightNode(light);
      }
      /* quad light source */
      else if (tag == "-quadlight")
      {
        Vec3f P = cin->getVec3f();
        Vec3f U = cin->getVec3f();
        Vec3f V = cin->getVec3f();
        Vec3f L = cin->getVec3f();

        Ref<Device::RTLight> light0 = g_device->rtNewLight("trianglelight");
        light0->rtSetFloat3("v0",P);
        light0->rtSetFloat3("v1",P+U);
        light0->rtSetFloat3("v2",P+U+V);
        light0->rtSetFloat3("L" ,L);
        light0->rtCommit();
        *g_scene += new LightNode(light0);

        Ref<Device::RTLight> light1 = g_device->rtNewLight("trianglelight");
        light1->rtSetFloat3("v0",P+U+V);
        light1->rtSetFloat3("v1",P+V);
        light1->rtSetFloat3("v2",P);
        light1->rtSetFloat3("L" ,L);
        light1->rtCommit();
        *g_scene += new LightNode(light1);
      }

      /* HDRI light source */
      else if (tag == "-hdrilight")
      {
        Ref<Device::RTLight> light = g_device->rtNewLight("hdrilight");
        light->rtSetFloat3("L",cin->getVec3f());
        light->rtSetImage("image",loadRTImage(path + cin->getFileName()));
        light->rtCommit();
        *g_scene += new LightNode(light);
      }

      /* parse camera parameters */
      else if (tag == "-vp")     g_camPos    = Vec3f(cin->getVec3f());
      else if (tag == "-vi")     g_camLookAt = Vec3f(cin->getVec3f());
      else if (tag == "-vd")     g_camLookAt = g_camPos+cin->getVec3f();
      else if (tag == "-vu")     g_camUp     = cin->getVec3f();
      else if (tag == "-angle")  g_camAngle  = cin->getFloat();
      else if (tag == "-fov")    g_camAngle  = cin->getFloat();
      else if (tag == "-radius") g_camRadius = cin->getFloat();

      /* frame buffer size */
      else if (tag == "-size") {
        g_width = cin->getInt();
        g_height = cin->getInt();
        g_frameBuffer = g_device->rtNewFrameBuffer("RGB_FLOAT32", g_width, g_height);
      }

       /* full screen mode */
      else if (tag == "-fullscreen") {
        g_fullscreen = true;
      }

      /* refine rendering when not moving */
      else if (tag == "-refine") g_refine = true;
      else if (tag == "-norefine") g_refine = false;

      /* acceleration structure to use */
      else if (tag == "-accel") g_accel = cin->getString();

      /* set renderer */
      else if (tag == "-renderer")
      {
        std::string renderer = cin->getString();
        if      (renderer == "debug"     ) g_renderer = parseDebugRenderer(cin,path);
        else if (renderer == "pt"        ) g_renderer = parsePathTracer(cin,path);
        else if (renderer == "pathtracer") g_renderer = parsePathTracer(cin,path);
        else if (renderer == "material"  ) g_renderer = parseMaterialRenderer(cin,path);
				else if (renderer == "opengl"  ) g_renderer = parseOpenGLRenderer(cin);
        else throw std::runtime_error("unknown renderer: "+renderer);
      }

      /* set gamma */
      else if (tag == "-gamma") {
        g_renderer->rtSetFloat1("gamma",g_gamma = cin->getFloat());
        g_renderer->rtCommit();
      }

      /* set recursion depth */
      else if (tag == "-depth") {
        g_renderer->rtSetInt1("maxDepth",g_depth = cin->getInt());
        g_renderer->rtCommit();
      }

      /* set samples per pixel */
      else if (tag == "-spp") {
        g_renderer->rtSetInt1("sampler.spp",g_spp = cin->getInt());
        g_renderer->rtCommit();
      }

      /* set the backplate */
      else if (tag == "-backplate") {
        g_renderer->rtSetImage("backplate",g_backplate = loadRTImage(path + cin->getFileName()));
        g_renderer->rtCommit();
      }

      /* render frame */
      else if (tag == "-o")
        outputMode(path + cin->getFileName());

      /* display image */
      else if (tag == "-display")
        displayMode();

      /* regression testing */
      else if (tag == "-regression")
      {
        g_refine = false;
        g_regression = true;
        GLUTDisplay(OrthonormalSpace::lookAtPoint(g_camPos,g_camLookAt,g_camUp),0.01f);
      }

      else if (tag == "-version") {
        std::cout << "embree renderer version 1.0" << std::endl;
        exit(1);
      }

      else if (tag == "-h" || tag == "-?" || tag == "-help" || tag == "--help")
      {
        std::cout << std::endl;
        std::cout << "Embree Version 1.0" << std::endl;
        std::cout << std::endl;
        std::cout << "  usage: embree -i model.obj -renderer debug -display" << std::endl;
        std::cout << "         embree -i model.obj -renderer pathtracer -o out.tga" << std::endl;
        std::cout << "         embree -c model.ecs -display" << std::endl;
        std::cout << std::endl;
        std::cout << "-renderer [debug,pathtracer]" << std::endl;
        std::cout << "  Sets the renderer to use." << std::endl;
        std::cout << std::endl;
        std::cout << "-c file" << std::endl;
        std::cout << "  Parses command line parameters from file." << std::endl;
        std::cout << std::endl;
        std::cout << "-i file" << std::endl;
        std::cout << "  Loads a scene from file." << std::endl;
        std::cout << std::endl;
        std::cout << "-o file" << std::endl;
        std::cout << "  Renders and outputs the image to the file." << std::endl;
        std::cout << std::endl;
        std::cout << "-display" << std::endl;
        std::cout << "  Interactively displays the rendering into a window." << std::endl;
        std::cout << std::endl;
        std::cout << "-vp x y z" << std::endl;
        std::cout << "  Sets camera position to the location (x,y,z)." << std::endl;
        std::cout << std::endl;
        std::cout << "-vi x y z" << std::endl;
        std::cout << "  Sets camera lookat point to the location (x,y,z)." << std::endl;
        std::cout << std::endl;
        std::cout << "-vd x y z" << std::endl;
        std::cout << "  Sets camera viewing direction to (x,y,z)." << std::endl;
        std::cout << std::endl;
        std::cout << "-vu x y z" << std::endl;
        std::cout << "  Sets camera up direction to (x,y,z)." << std::endl;
        std::cout << std::endl;
        std::cout << "-fov angle" << std::endl;
        std::cout << "  Sets camera field of view in y direction to angle." << std::endl;
        std::cout << std::endl;
        std::cout << "-size width height" << std::endl;
        std::cout << "  Sets the width and height of image to render." << std::endl;
        std::cout << std::endl;
        std::cout << "-fullscreen" << std::endl;
        std::cout << "  Enables full screen display mode." << std::endl;
        std::cout << std::endl;
        std::cout << "-accel [bvh2,bvh4,bvh4.spatial]" << std::endl;
        std::cout << "  Sets the spatial index structure to use." << std::endl;
        std::cout << std::endl;
        std::cout << "-gamma v" << std::endl;
        std::cout << "  Sets gamma correction to v (only pathtracer)." << std::endl;
        std::cout << std::endl;
        std::cout << "-depth i" << std::endl;
        std::cout << "  Sets the recursion depth to i (default 16)" << std::endl;
        std::cout << std::endl;
        std::cout << "-spp i" << std::endl;
        std::cout << "  Sets the number of samples per pixel to i (default 1) (only pathtracer)." << std::endl;
        std::cout << std::endl;
        std::cout << "-backplate" << std::endl;
        std::cout << "  Sets a high resolution back ground image. (default none) (only pathtracer)." << std::endl;
        std::cout << std::endl;

        std::cout << "-ambientlight r g b" << std::endl;
        std::cout << "  Creates an ambient light with intensity (r,g,b)." << std::endl;
        std::cout << std::endl;
        std::cout << "-pointlight px py pz r g b" << std::endl;
        std::cout << "  Creates a point light with intensity (r,g,b) at position (px,py,pz)." << std::endl;
        std::cout << std::endl;
        std::cout << "-distantlight dx dy dz r g b halfAngle" << std::endl;
        std::cout << "  Creates a distant sun light with intensity (r,g,b) shining into " << std::endl;
        std::cout << "  direction (dx,dy,dz) from the cone spanned by halfAngle." << std::endl;
        std::cout << std::endl;
        std::cout << "-trianglelight px py pz ux uy uz vx vy vz r g b" << std::endl;
        std::cout << "  Creates a triangle-light with intensity (r,g,b) spanned by the point " << std::endl;
        std::cout << "  (px,py,pz) and the vectors (vx,vy,vz) and (ux,uy,uz)." << std::endl;
        std::cout << std::endl;
        std::cout << "-quadlight px py pz ux uy uz vx vy vz r g b" << std::endl;
        std::cout << "  Creates a quad-light with intensity (r,g,b) spanned by the point " << std::endl;
        std::cout << "  (px,py,pz) and the vectors (vx,vy,vz) and (ux,uy,uz)." << std::endl;
        std::cout << std::endl;
        std::cout << "-hdrilight r g b file" << std::endl;
        std::cout << "  Creates a high dynamic range environment light from the image " << std::endl;
        std::cout << "  file. The intensities are multiplies by (r,g,b)." << std::endl;
        std::cout << std::endl;
        std::cout << "-trisphere px py pz r theta phi" << std::endl;
        std::cout << "  Creates a triangulated sphere with radius r at location (px,py,pz) " << std::endl;
        std::cout << "  and triangulation rates theta and phi." << std::endl;
        std::cout << std::endl;
        std::cout << "-[no]refine" << std::endl;
        std::cout << "  Enables (default) or disables the refinement display mode." << std::endl;
        std::cout << std::endl;
        std::cout << "-regression" << std::endl;
        std::cout << "  Runs a stress test of the system." << std::endl;
        std::cout << std::endl;
        std::cout << "-version" << std::endl;
        std::cout << "  Prints version number." << std::endl;
        std::cout << std::endl;
        std::cout << "-h, -?, -help, --help" << std::endl;
        std::cout << "  Prints this help." << std::endl;
        exit(1);
      }

      /* skip unknown command line parameter */
      else {
        std::cerr << "unknown command line parameter: " << tag << " ";
        while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
        std::cerr << std::endl;
      }
    }
  }
Ejemplo n.º 22
0
static void parseCommandLine(Ref<ParseStream> cin, const FileName& path)
{
    while (true)
    {
        std::string tag = cin->getString();
        if (tag == "") return;

        /* parse command line parameters from a file */
        else if (tag == "-c") {
            FileName file = path + cin->getFileName();
            parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path());
        }

        /* load OBJ model*/
        else if (tag == "-i") {
            filename = path + cin->getFileName();
        }

        /* parse camera parameters */
        else if (tag == "-vp") g_camera.from = cin->getVec3fa();
        else if (tag == "-vi") g_camera.to = cin->getVec3fa();
        else if (tag == "-vd") g_camera.to = g_camera.from + cin->getVec3fa();
        else if (tag == "-vu") g_camera.up = cin->getVec3fa();
        else if (tag == "-fov") g_camera.fov = cin->getFloat();

        /* frame buffer size */
        else if (tag == "-size") {
            g_width = cin->getInt();
            g_height = cin->getInt();
        }

        /* full screen mode */
        else if (tag == "-fullscreen")
            g_fullscreen = true;

        /* output filename */
        else if (tag == "-o") {
            outFilename = cin->getFileName();
            g_interactive = false;
        }

        else if (tag == "-objlist") {
            keyframeList = cin->getFileName();
        }

        /* subdivision mode */
        else if (tag == "-cache")
            g_subdiv_mode = ",subdiv_accel=bvh4.subdivpatch1cached";

        else if (tag == "-pregenerate")
            g_subdiv_mode = ",subdiv_accel=bvh4.grid.eager";

        else if (tag == "-anim")
            g_anim_mode = true;

        else if (tag == "-instancing") {
            std::string mode = cin->getString();
            if      (mode == "none"    ) g_instancing_mode = 0;
            else if (mode == "geometry") g_instancing_mode = 1;
            else if (mode == "scene"   ) g_instancing_mode = 2;
            else throw std::runtime_error("unknown instancing mode: "+mode);
        }

        /* number of frames to render in benchmark mode */
        else if (tag == "-benchmark") {
            g_skipBenchmarkFrames = cin->getInt();
            g_numBenchmarkFrames  = cin->getInt();
            g_interactive = false;
        }

        /* rtcore configuration */
        else if (tag == "-rtcore")
            g_rtcore = cin->getString();

        /* number of threads to use */
        else if (tag == "-threads")
            g_numThreads = cin->getInt();

        /* ambient light source */
        else if (tag == "-ambientlight")
        {
            const Vec3fa L = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<AmbientLight>(AmbientLight(L)));
        }

        /* point light source */
        else if (tag == "-pointlight")
        {
            const Vec3fa P = cin->getVec3fa();
            const Vec3fa I = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<PointLight>(PointLight(P,I)));
        }

        /* directional light source */
        else if (tag == "-directionallight" || tag == "-dirlight")
        {
            const Vec3fa D = cin->getVec3fa();
            const Vec3fa E = cin->getVec3fa();
            g_scene->add(new SceneGraph::LightNode<DirectionalLight>(DirectionalLight(D,E)));
        }

        /* distant light source */
        else if (tag == "-distantlight")
        {
            const Vec3fa D = cin->getVec3fa();
            const Vec3fa L = cin->getVec3fa();
            const float halfAngle = cin->getFloat();
            g_scene->add(new SceneGraph::LightNode<DistantLight>(DistantLight(D,L,halfAngle)));
        }

        /* skip unknown command line parameter */
        else {
            std::cerr << "unknown command line parameter: " << tag << " ";
            while (cin->peek() != "" && cin->peek()[0] != '-') std::cerr << cin->getString() << " ";
            std::cerr << std::endl;
        }
    }
}