Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2370 - trunk/scenes


Chronological Thread 
  • From: "Andrew Kensler" < >
  • To:
  • Subject: [Manta] r2370 - trunk/scenes
  • Date: Wed, 4 Feb 2009 12:48:23 -0700 (MST)

Author: aek
Date: Wed Feb  4 12:48:21 2009
New Revision: 2370

Modified:
   trunk/scenes/triangleSceneViewer.cc
Log:
Adding support for on-the-fly decompression of .iw.bz2, .iw.gz, .m.bz2, and
.m.gz files on *nix-like systems.  Sets up a named pipe and invokes bzip2
or gzip as a subprocess.  This makes it transparent to any model reader
that streams in a model in a single pass.  Doesn't work for OBJ files since
the OBJ reader library makes two passes through the file using rewind().



Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Wed Feb  4 12:48:21 2009
@@ -46,6 +46,40 @@
 using namespace Manta;
 using namespace std;
 
+#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+class Decompress {
+  char *fifo_name;
+  pid_t proc_id;
+public:
+  Decompress(string &model, char const *args[]) {
+    fifo_name = static_cast<char *>(malloc(model.size() + 7));
+    strcpy(fifo_name, model.c_str());
+    strcat(fifo_name, "XXXXXX");
+    mktemp(fifo_name);
+    mkfifo(fifo_name, 0666);
+    proc_id = fork();
+    if (proc_id == 0) {
+      int file_des = open(fifo_name, O_WRONLY, 0666);
+      dup2(file_des, 1);
+      close(file_des);
+      execvp(args[0], const_cast<char* const*>(args));
+    }
+  }
+  const char *get_fifo() {
+    return fifo_name;
+  }
+  ~Decompress() {
+    waitpid(proc_id, 0, 0);
+    unlink(fifo_name);
+    free(fifo_name);
+  }
+};
+#endif
+
 void argumentError(int i, const vector<string>& args) {
   cerr << "Valid options for scene meshViewer:\n";
   cerr << " -BSP   - use BSP acceleration structure\n";
@@ -70,7 +104,7 @@
   cerr << " -overrideMatl       - Force to use a material.\n"
        << "                       flat, eyelight, lambertian, phong, 
ambientocclusion\n.";
   cerr << " -lightPosition      - Location of light.\n";
-  throw IllegalArgument("scene primtest", i, args);
+  throw IllegalArgument("scene triangleSceneViewer", i, args);
 }
 
 Mesh* LoadModel(std::string modelName, Material* defaultMatl, Material 
*overrideMatl,
@@ -94,15 +128,41 @@
       }
     }
   }
-  else if  (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
+  else if (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
     frame = new ObjGroup(modelName.c_str(), defaultMatl, triangleType);
   }
-  else if  (!strncmp(modelName.c_str()+modelName.length()-3, ".iw", 3)) {
+  else if (!strncmp(modelName.c_str()+modelName.length()-3, ".iw", 3)) {
     frame = readIW(modelName, triangleType);
   }
   else if  (!strncmp(modelName.c_str()+modelName.length()-2, ".m", 2)) {
     frame = readM(modelName, defaultMatl, triangleType);
   }
+#ifndef _WIN32
+  // NOTE(aek): Don't bother trying this with OBJ files.  The OBJ reader
+  // library that we use makes two passes through the file using rewind(),
+  // which doesn't play well with pipes.  Any readers that stream in a
+  // single pass should work, however.
+  else if (!strncmp(modelName.c_str()+modelName.length()-7, ".iw.bz2", 7)) {
+    char const *args[] = {"bzip2", "-dc", modelName.c_str(), 0};
+    Decompress decomp(modelName, args);
+    frame = readIW(decomp.get_fifo(), triangleType);
+  }
+  else if (!strncmp(modelName.c_str()+modelName.length()-6, ".iw.gz", 6)) {
+    char const *args[] = {"gzip", "-dc", modelName.c_str(), 0};
+    Decompress decomp(modelName, args);
+    frame = readIW(decomp.get_fifo(), triangleType);
+  }
+  else if (!strncmp(modelName.c_str()+modelName.length()-7, ".m.bz2", 7)) {
+    char const *args[] = {"bzip2", "-dc", modelName.c_str(), 0};
+    Decompress decomp(modelName, args);
+    frame = readM(decomp.get_fifo(), defaultMatl, triangleType);
+  }
+  else if (!strncmp(modelName.c_str()+modelName.length()-6, ".m.gz", 6)) {
+    char const *args[] = {"gzip", "-dc", modelName.c_str(), 0};
+    Decompress decomp(modelName, args);
+    frame = readM(decomp.get_fifo(), defaultMatl, triangleType);
+  }
+#endif
 
   if (overrideMatl) {
     frame->materials[0] = overrideMatl;


  • [Manta] r2370 - trunk/scenes, Andrew Kensler, 02/04/2009

Archive powered by MHonArc 2.6.16.

Top of page