Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Lightfield/raycaster.cpp

Go to the documentation of this file.
00001 #include "Scanner.h"
00002 #include <stdio.h>
00003 #include "vuMisc/vuCommandLineTool.h"
00004 #include <GL/glut.h>
00005 
00006 /* 
00007    Usage: raycaster OPTIONS input.vud lightfield.vul
00008 
00009    OPTIONS: --views=100 --width=200 --height=200 [--tfunc=file.tf] [--show]
00010 */
00011 
00012 Scanner *g_Scanner   = NULL;
00013 vuString g_ErrorMsg;
00014 vuString g_TFuncFile;
00015 vuString g_OutputFile;
00016 vuString g_InputFile;
00017 int      g_Views     = -1;
00018 int      g_Width     = -1;
00019 int      g_Height    = -1;
00020 bool     g_Visualize = false;
00021 
00022 void init(void) {
00023   g_Scanner = new Scanner(g_InputFile.c_str(), g_Width, g_Height, g_Views);
00024   if (!g_TFuncFile.isEmpty()) {
00025     g_Scanner->loadTFuncFromFile(g_TFuncFile.c_str());
00026   }
00027 }
00028 
00029 void destroy(void) {
00030   delete g_Scanner;
00031 }
00032 
00033 //*****************************************//
00034 //**** The glut stuff                  ****//
00035 //*****************************************//
00036 
00037 void display(void)
00038 {
00039   g_Scanner->lazyCalculateAndDisplay(g_OutputFile);
00040 }
00041 
00042 void keyboard(unsigned char key, int x, int y)
00043 {
00044   switch(key)
00045     {
00046     case 27:
00047     case 'q':
00048     case 'Q':
00049       destroy();
00050       exit(0);
00051       break;
00052     default:
00053       break;
00054     }
00055   glutPostRedisplay();
00056 }
00057 
00058 void reshape(int width, int height)
00059 {
00060 
00061   glViewport(0, 0, width, height);
00062 
00063   glMatrixMode(GL_PROJECTION);
00064   glLoadIdentity();
00065   gluPerspective(60.0f, 1.0f, 0.1f, 10.0f);
00066   glMatrixMode(GL_MODELVIEW);
00067   glLoadIdentity();
00068   glPixelZoom((float)width/g_Width,(float)height/g_Height);
00069   glTranslated(0.0, 0.0, -2.5);
00070 }
00071 
00072 vuString _helpString(vuCommandLineTool &tool)
00073 {
00074   vuString str;
00075 
00076 
00077   str += "Creating spherical RGB lightfields for vuVolume using a raycaster.\n\n";
00078   str += "Usage: ";
00079   str += tool.toolName();
00080   str += " mandatory_options [additional_options] inputFile outputFile\n";
00081   str += "\nmandatory_options:\n";
00082   str += "  --views=nnn    number of views,              e.g. --views=100\n";
00083   str += "  --width=www    width of each view in pixel,  e.g. --width=200\n";
00084   str += "  --height=hhh   height of each view in pixel, e.g. --height=200\n";
00085   str += "\nadditional_options:\n";
00086   str += "  --tfunc=fff    transfer function file,       e.g.";
00087   str += " --tfunc=engine.tf\n";  
00088   str += "  --show         shows the views in a window,  e.g. --show\n";
00089   str += "\ninputFile:\n";
00090   str += "  a regular 3D vuVolume data file,             e.g. engine.vud\n";
00091   str += "\noutputFile:\n";
00092   str += "  a vuVolume spherical RGB lightfield file,    e.g.";
00093   str += " engine_200x200_100.vul\n";
00094  
00095   return str;
00096 }
00097 
00098 bool _parseParameters(int argc, const char **argv)
00099 {
00100   bool isOk = true;
00101   vuCommandLineTool tool(argc, argv);
00102 
00103   if (tool.hasParameter("--help")) {
00104     g_ErrorMsg += _helpString(tool);
00105     return false;
00106   }
00107 
00108   g_TFuncFile = tool.stringForParameter("--tfunc");
00109   g_Views     = tool.intForParameter   ("--views");
00110   g_Width     = tool.intForParameter   ("--width");
00111   g_Height    = tool.intForParameter   ("--height");
00112   g_Visualize = tool.hasParameter      ("--show");
00113 
00114   g_ErrorMsg += "Following error(s) occured:\n";
00115   if (tool.hasParameter("--tfunc")) {
00116     if (!tool.fileExists(g_TFuncFile)) {
00117       g_ErrorMsg += "  - Could not load transfer function from '";
00118       g_ErrorMsg += g_TFuncFile + "'.\n";
00119       isOk = false;
00120     }
00121   }
00122 
00123   if (!tool.hasParameter("--views")) {
00124     g_ErrorMsg += "  - Number of views not set (use '--views=100').\n";
00125     isOk = false;
00126   }
00127   else if (g_Views < 1 || g_Views > 10000) {
00128     g_ErrorMsg += "  - Number of views not properly set. ";
00129     g_ErrorMsg += "(Must be between 1 and 10000)\n";
00130     isOk = false;
00131   }
00132 
00133   if (!tool.hasParameter("--width")) {
00134     g_ErrorMsg += "  - Width not set (use '--width=250').\n";
00135     isOk = false;
00136   }
00137   else if (g_Width < 1 || g_Width > 2048) {
00138     g_ErrorMsg += "  - Width not properly set. ";
00139     g_ErrorMsg += "(Must be between 1 and 2048)\n";
00140     isOk = false;
00141   }
00142 
00143   if (!tool.hasParameter("--height")) {
00144     g_ErrorMsg += "  - Height not set (use '--height=250').\n";
00145     isOk = false;
00146   }
00147   else if (g_Height < 1 || g_Height > 2048) {
00148     g_ErrorMsg += "  - Height not properly set. ";
00149     g_ErrorMsg += "(Must be between 1 and 2048)\n";
00150     isOk = false;
00151   }
00152 
00153   bool isValid;
00154   word fileCount = tool.numberOfNonParameters(isValid);
00155 
00156   if (fileCount == 0) {
00157     g_ErrorMsg += "  - Neither an input nor an output file is specified.\n";
00158     isOk = false;
00159   }
00160   else if (fileCount == 1)  {
00161     g_ErrorMsg += "  - No output file specified.\n";
00162     isOk = false;
00163   }
00164   else if (fileCount == 2 && isValid)  {
00165     g_InputFile  = tool.getArgument(argc-2);
00166     g_OutputFile = tool.getArgument(argc-1);
00167     if (!tool.fileExists(g_InputFile)) {
00168       g_ErrorMsg += "  - InputFile does not exist ('";
00169       g_ErrorMsg += g_InputFile + "').\n";
00170       isOk = false;
00171     }
00172     if (g_OutputFile.isEmpty()) {
00173       g_ErrorMsg += "  - No output file specified.\n";
00174       isOk = false;
00175     }
00176   }
00177   else if (fileCount > 2)  {
00178     g_ErrorMsg += "  - More than one input and one output file specified.\n";
00179     isOk = false;
00180   }
00181   else {
00182     g_ErrorMsg += "  - The input and output file are expected to be at the ";
00183     g_ErrorMsg += " end of the line.\n";
00184     isOk = false;
00185   }
00186 
00187   g_ErrorMsg += "\nType '" + tool.toolName() + " --help' for more information!\n";
00188 
00189   if (isOk) g_ErrorMsg = "";
00190 
00191   return isOk;
00192 }
00193 
00194 int main(int argc, const char **argv)
00195 {
00196   if (!_parseParameters(argc, argv)) {
00197     cerr << g_ErrorMsg << endl;
00198     exit(0);
00199   }
00200 
00201   init();
00202 
00203   if (g_Visualize) {
00204     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
00205     glutInitWindowSize(g_Width, g_Height);
00206     glutInitWindowPosition(0, 0);
00207 
00208     glutCreateWindow("raycaster");
00209 
00210     glutDisplayFunc(display);
00211     glutKeyboardFunc(keyboard);
00212     glutReshapeFunc(reshape);
00213     glutMainLoop();
00214   }
00215   else {
00216     g_Scanner->lazyCalculateAndLog(g_OutputFile);
00217   }
00218 
00219   destroy();
00220   return 0;
00221 }

Generated on Wed Dec 15 21:20:30 2004 for vuVolume by  doxygen 1.3.9.1