Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1240 - in trunk: CMake scenes scenes/galileo
- Date: Fri, 1 Dec 2006 19:15:06 -0700 (MST)
Author: bigler
Date: Fri Dec 1 19:15:05 2006
New Revision: 1240
Added:
trunk/CMake/FindParsers.cmake
trunk/scenes/galileo/
trunk/scenes/galileo/CMakeLists.txt
trunk/scenes/galileo/galileo.cc
trunk/scenes/galileo/grlex.l
trunk/scenes/galileo/grparse.y
Modified:
trunk/scenes/CMakeLists.txt
Log:
First crack at a galileo scene parser.
CMake/FindParsers.cmake
This will find flex and bison and setup a macro to build the parsing
files.
scenes/CMakeLists.txt
Go into galileo subdirectory.
scenes/galileo
scenes/galileo/CMakeLists.txt
scenes/galileo/galileo.cc
scenes/galileo/grlex.l
scenes/galileo/grparse.y
Build the scene based on a galileo scene file. Currently supports
Parallelograms, Contant<Color> textures, and Lambertian materials.
Added: trunk/CMake/FindParsers.cmake
==============================================================================
--- (empty file)
+++ trunk/CMake/FindParsers.cmake Fri Dec 1 19:15:05 2006
@@ -0,0 +1,89 @@
+SET(PARSERS_FOUND FOOBAR)
+FIND_PROGRAM(BISON_EXECUTABLE
+ NAMES bison
+ PATHS ${BISON_DIR} )
+
+FIND_PROGRAM(FLEX_EXECUTABLE
+ NAMES flex
+ PATHS ${FLEX_DIR} )
+
+IF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
+ SET(PARSERS_FOUND 1)
+ELSE(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
+ SET(PARSERS_FOUND 0)
+ENDIF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
+
+# You need at least version 2.4 for this to work.
+IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4)
+ MESSAGE("You need at least version 2.4 for generating flex and bison
parsers. Go get it from
http://www.cmake.org/HTML/Download.html")
+ SET(PARSERS_FOUND 0)
+ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4)
+
+# These are helper functions for parsers.
+
+# parser is the parser file name like parser.y
+# lexer is like lexer.l
+
+# The names of the output files will be based on the input names.
+# BF_SOURCES will be parser.cc, parser.h and lexer.cc.
+
+MACRO(GENERATE_BISON_FLEX_SOURCES parser parser_args
+ lexer lexer_args)
+ GET_FILENAME_COMPONENT(parser_base "${parser}" NAME_WE)
+
+ SET(BISON_TAB_C "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.c")
+ SET(BISON_TAB_H "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.h")
+ SET(BISON_CC "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.cc")
+ SET(BISON_H "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.h")
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${BISON_TAB_C} ${BISON_TAB_H}
+ COMMAND ${BISON_EXECUTABLE}
+ ARGS "${parser}" ${parser_args} "--defines"
+ DEPENDS "${parser}"
+ COMMENT "Generating ${BISON_TAB_C} ${BISON_TAB_H} from ${parser}"
+ )
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${BISON_CC}
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${BISON_TAB_C} ${BISON_CC}
+ DEPENDS ${BISON_TAB_C}
+ COMMENT "Copying ${BISON_TAB_C} to ${BISON_CC}"
+ )
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${BISON_H}
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${BISON_TAB_H} ${BISON_H}
+ DEPENDS ${BISON_TAB_H}
+ COMMENT "Copying ${BISON_TAB_H} to ${BISON_H}"
+ )
+
+ GET_FILENAME_COMPONENT(lexer_base "${lexer}" NAME_WE)
+ SET(FLEX_C "${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c")
+ SET(FLEX_CC "${CMAKE_CURRENT_BINARY_DIR}/${lexer_base}.cc")
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${FLEX_C}
+ COMMAND ${FLEX_EXECUTABLE}
+ ARGS "${lexer}" ${lexer_args}
+ DEPENDS "${lexer}" ${BISON_H}
+ COMMENT "Generating ${FLEX_C} from ${lexer}"
+ )
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${FLEX_CC}
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${FLEX_C} ${FLEX_CC}
+ DEPENDS ${FLEX_C}
+ COMMENT "Copying ${FLEX_C} to ${FLEX_CC}"
+ )
+
+ SET(BF_SOURCES ${BISON_CC} ${BISON_H} ${FLEX_CC})
+
+ENDMACRO(GENERATE_BISON_FLEX_SOURCES)
+
+
+
+
Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Fri Dec 1 19:15:05 2006
@@ -111,3 +111,6 @@
ADD_LIBRARY(scene_dynlt dynlt.cc)
TARGET_LINK_LIBRARIES(scene_dynlt Manta_DynLT ${MANTA_SCENE_LINK})
ENDIF(BUILD_DYNLT)
+
+# Recurse into galileo directory
+SUBDIRS(galileo)
Added: trunk/scenes/galileo/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/scenes/galileo/CMakeLists.txt Fri Dec 1 19:15:05 2006
@@ -0,0 +1,20 @@
+
+SET(SCENE_GALILEO 0 CACHE BOOL "Galileo scene reader")
+
+IF(SCENE_GALILEO)
+ INCLUDE(${CMAKE_SOURCE_DIR}/CMake/FindParsers.cmake)
+ENDIF(SCENE_GALILEO)
+
+GENERATE_BISON_FLEX_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/grparse.y ""
+ ${CMAKE_CURRENT_SOURCE_DIR}/grlex.l "")
+MESSAGE("BF_SOURCES = ${BF_SOURCES}")
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
+
+IF(SCENE_GALILEO AND PARSERS_FOUND)
+ ADD_LIBRARY(scene_galileo galileo.cc ${BF_SOURCES})
+ TARGET_LINK_LIBRARIES(scene_galileo ${MANTA_SCENE_LINK})
+ENDIF(SCENE_GALILEO AND PARSERS_FOUND)
+
Added: trunk/scenes/galileo/galileo.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/galileo/galileo.cc Fri Dec 1 19:15:05 2006
@@ -0,0 +1,79 @@
+#include <Core/Geometry/Vector.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Util/Args.h>
+#include <Interface/Context.h>
+#include <Interface/LightSet.h>
+#include <Interface/MantaInterface.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/AmbientLights/ArcAmbient.h>
+#include <Model/Backgrounds/LinearBackground.h>
+#include <Model/Groups/Group.h>
+#include <Model/Groups/GriddedGroup.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Materials/MetalMaterial.h>
+#include <Model/Primitives/Parallelogram.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Textures/CheckerTexture.h>
+#include <Core/Geometry/AffineTransform.h>
+#include <Core/Util/NotFinished.h>
+
+#include <Engine/Factory/Factory.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+#include <math.h>
+#include <string.h>
+
+using namespace std;
+using namespace Manta;
+
+extern FILE* yyin;
+extern int yyparse(void);
+extern Group* world;
+
+extern "C"
+Scene* make_scene(const ReadContext& context, const vector<string>& args)
+{
+// Group* world = new Group();
+
+// Material* matl0=new Lambertian(Color(RGBColor(.4,.4,.4)));
+// world->add(new Sphere(matl0, Vector(1, 1, 1), 1.0f));
+
+ cerr << "args[0] = "<<args[0]<<"\n";
+
+ yyin = fopen(args[0].c_str(), "r");
+ if (!yyin) {
+ perror("Can't open file");
+ return NULL;
+ }
+ if (!yyparse()) {
+ perror("Error parsing");
+ }
+ fclose(yyin);
+
+ Scene* scene = new Scene();
+ scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
+ Color::black(),
+ Vector(0,0,1)));
+ scene->setObject(world);
+
+ scene->addBookmark("default view",
+ /* eye */ Vector(10, 10, 10),
+ /* lookat */ Vector(1,1,1),
+ /* up */ Vector(0,0,1),
+ /* fov */ 28.2);
+
+ LightSet* lights = new LightSet();
+ lights->add(new PointLight(Vector(5,-3,3), Color(RGB(1,1,.8))*2));
+ Color cup(RGB(0.1, 0.3, 0.8));
+ Color cdown(RGB(0.82, 0.62, 0.62));
+ Vector up(0,0,1);
+ // lights->setAmbientLight(new ArcAmbient(cup, cdown, up));
+ lights->setAmbientLight(new ConstantAmbient(Color(RGBColor(1,1,1))));
+ scene->setLights(lights);
+ return scene;
+}
Added: trunk/scenes/galileo/grlex.l
==============================================================================
--- (empty file)
+++ trunk/scenes/galileo/grlex.l Fri Dec 1 19:15:05 2006
@@ -0,0 +1,145 @@
+
+%{
+
+/*****************************************************************************\
+ *
*
+ * filename : lexrib.l
*
+ * author : R. Keith Morley
*
+ *
*
+ * flex file for generating a Galileo lexer.
*
+ *
*
+\*****************************************************************************/
+
+#include <grparse.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define MAX_INCLUDE_DEPTH 10
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+int include_stack_ptr = 0;
+
+int line_num = 1;
+int col_num = 1;
+
+%}
+
+wspace [\t ]+
+nl \n
+num [0-9]
+alpha [a-zA-Z]
+alphanum [a-zA-Z0-9]
+ident [a-zA-Z_][a-zA-Z0-9_]*
+decimal
[-+]?([0-9]+|(([0-9]+)|([0-9]+\.[0-9]*)|(\.[0-9]+))([eE][-+]?[0-9]+)?)
+comment #[^\n]*\n
+eatline [^\n]*\n
+qstring \"[^\"\n]*\"
+larraybracket \[
+rarraybracket \]
+
+%x INCLUDEMODE
+
+%%
+
+{wspace} { ; /* ignore whitespace */ }
+{nl} { line_num++; }
+{comment} { line_num++; }
+{qstring} {
+ strcpy(yylval.string, &yytext[1]);
+ yylval.string[yyleng-2] = '\0';
+ return STRING;
+ }
+{decimal} {
+ yylval.num = atof(yytext);
+ return NUM;
+ }
+{larraybracket} { return LBRACKET; }
+{rarraybracket} { return RBRACKET; }
+
+Include { BEGIN(INCLUDEMODE); }
+<INCLUDEMODE>[ \t]* /* eat whitespace */
+<INCLUDEMODE>\"[^\"\n]*\" {
+ if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
+ {
+ fprintf(stderr, "Includes nested too deeply\n");
+ exit(1);
+ }
+ include_stack[include_stack_ptr++] =
+ YY_CURRENT_BUFFER;
+ strcpy(yylval.string, &yytext[1]);
+ yylval.string[yyleng-2] = '\0';
+ yyin = fopen(yylval.string, "r");
+
+ if ( !yyin )
+ {
+ fprintf(stderr, "Failed to open file %s\n", yylval.string);
+ exit(-1);
+ }
+
+ yy_switch_to_buffer(
+ yy_create_buffer(yyin, YY_BUF_SIZE) );
+
+ BEGIN(INITIAL);
+}
+
+<<EOF>> {
+ if ( --include_stack_ptr < 0 )
+ {
+ yyterminate();
+ }
+ else
+ {
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+ yy_switch_to_buffer(include_stack[include_stack_ptr]);
+ }
+}
+
+ /* Interface commands */
+Accel { return ACCEL; }
+AreaLight { return AREALIGHT; }
+AttributeBegin { return ATTRIBUTEBEGIN; }
+AttributeEnd { return ATTRIBUTEND; }
+Camera { return CAMERA; }
+Clipping { return CLIPPING; }
+ConcatTransform { return CONCATTRANSFORM; }
+Displacement { return DISPLACEMENT; }
+Environment { return ENVIRONMENT; }
+FrameBegin { return FRAMEBEGIN; }
+FrameEnd { return FRAMEEND; }
+Identity { return IDENTITY; }
+Image { return IMAGE; }
+Instance { return INSTANCE; }
+Light { return LIGHT; }
+LightShader { return LIGHTSHADER; }
+LookAt { return LOOKAT; }
+MaxDepth { return MAXDEPTH; }
+ObjectBegin { return OBJECTBEGIN; }
+ObjectEnd { return OBJECTEND; }
+PixelSamples { return PIXELSAMPLES; }
+Renderer { return RENDERER; }
+Rotate { return ROTATE; }
+Sampler { return SAMPLER; }
+Scale { return SCALE; }
+Spectral { return SPECTRAL; }
+Surface { return SURFACE; }
+SurfaceShader { return SURFACESHADER; }
+Texture { return TEXTURE; }
+ToneMap { return TONEMAP; }
+Transform { return TRANSFORM; }
+TransformBegin { return TRANSFORMBEGIN; }
+TransformEnd { return TRANSFORMEND; }
+Translate { return TRANSLATE; }
+WorldBegin { return WORLDBEGIN; }
+WorldEnd { return WORLDEND; }
+
+
+{ident} {
+ strcpy(yylval.string, yytext);
+ return UNKNOWN;
+ }
+
+%%
+int yywrap(void)
+{
+ return 1;
+}
+
Added: trunk/scenes/galileo/grparse.y
==============================================================================
--- (empty file)
+++ trunk/scenes/galileo/grparse.y Fri Dec 1 19:15:05 2006
@@ -0,0 +1,897 @@
+
+%{
+/*****************************************************************************\
+ *
*
+ * filename : grparse.y
*
+ * author : R. Keith Morley
*
+ * last mod : 04/12/04
*
+ *
*
+ * bison file used to create Pixar RIB parser.
*
+ *
*
+\*****************************************************************************/
+
+/* #include <core/api.h> */
+/* #include <utilities/rgb.h> */
+/* #include <utilities/DynArray.h> */
+/* #include <math/Vector3.h> */
+/* #include <parser/Params.h> */
+/* #include <utilities/config.h> */
+
+ #include <Model/Groups/Group.h>
+ #include <Model/Primitives/Parallelogram.h>
+ #include <Model/Materials/Lambertian.h>
+ #include <Model/Textures/Constant.h>
+
+#include <Core/Geometry/Vector.h>
+
+#ifdef USE_DEP_HEADERS
+#include <stdlib.h>
+#include <stdio.h>
+#else
+#include <cstdlib>
+#include <cstdio>
+#endif
+
+#define MAX_PARAMS 100 /* maximum number of allowed params of a
+ single type in a single statement */
+
+#define MAX_NAME_LENGTH 256 /* max length of parameter name */
+
+extern FILE* yyin; /* */
+extern int yylex(); /* these are needed to make bison */
+extern int yyerror(char*); /* play well with C++ compilers */
+extern int yytext; /* */
+
+extern int line_num;
+
+/* dynamic arrays to push paramlist values onto as they are parsed */
+#include <vector>
+#include <map>
+#include <string>
+
+ using namespace std;
+ using namespace Manta;
+
+std::vector<float> current_floats;
+std::vector<std::string> current_strings;
+ Material* current_material = new Lambertian(Color(RGBColor(0.2, 0.2, 0.9)));
+
+ map<string, Material*> materials;
+ map<string, Texture<Color>*> rgb_textures;
+
+ // These will be accessed externally
+ Group* world = new Group();
+
+
+ struct Params {
+ Params()
+ {
+ }
+
+ void clear() {
+ floats.clear();
+ vectors.clear();
+ rgb_textures.clear();
+ rgb_colors.clear();
+ }
+
+ void addFloat(string name, vector<float>& value) {
+ floats[name] = value;
+ }
+
+ void addVector(string name, vector<Vector>& value) {
+ vectors[name] = value;
+ }
+
+ void addRGBTexture(string name, vector<Texture<Color>*>& value) {
+ rgb_textures[name] = value;
+ }
+
+ void addRGB(string name, vector<RGBColor>& value) {
+ rgb_colors[name] = value;
+ }
+
+ map<string, vector<float> > floats;
+ map<string, vector<Vector> > vectors;
+ map<string, vector<Texture<Color>*> > rgb_textures;
+ map<string, vector<RGBColor> > rgb_colors;
+ };
+
+Params params;
+
+%}
+
+
+%union
+{
+ char string[256];
+ float num;
+}
+
+%token <string> UNKNOWN
+%token <string> STRING
+%token <num> NUM
+%token NUMARRAY
+%token STRINGARRAY
+%token LBRACKET
+%token RBRACKET
+
+%token ACCEL
+%token AREALIGHT
+%token ATTRIBUTEBEGIN
+%token ATTRIBUTEND
+%token CAMERA
+%token CLIPPING
+%token CONCATTRANSFORM
+%token DISPLACEMENT
+%token ENVIRONMENT
+%token FRAMEBEGIN
+%token FRAMEEND
+%token IDENTITY
+%token IMAGE
+%token INSTANCE
+%token LIGHT
+%token LIGHTSHADER
+%token MAXDEPTH
+%token LOOKAT
+%token OBJECTBEGIN
+%token OBJECTEND
+%token PIXELSAMPLES
+%token RENDERER
+%token ROTATE
+%token SAMPLER
+%token SCALE
+%token SPECTRAL
+%token SURFACE
+%token SURFACESHADER
+%token TEXTURE
+%token TONEMAP
+%token TRANSFORM
+%token TRANSFORMBEGIN
+%token TRANSFORMEND
+%token TRANSLATE
+%token WORLDBEGIN
+%token WORLDEND
+
+%token HIGH_PRECEDENCE
+
+%%
+
+start: statement_list
+;
+
+init_arrays: %prec HIGH_PRECEDENCE
+{
+ current_floats.clear();
+ current_strings.clear();
+}
+;
+
+array: init_arrays string_array
+{
+}
+| init_arrays num_array
+{
+}
+;
+
+string_array: LBRACKET string_list RBRACKET
+{
+}
+;
+
+string_list: string_list string_list_entry
+{
+}
+| string_list_entry
+{
+}
+;
+
+string_list_entry: STRING
+{
+ current_strings.push_back(std::string($1));
+}
+;
+
+num_array: LBRACKET num_list RBRACKET
+{
+}
+;
+
+num_list: num_list num_list_entry
+{
+}
+| num_list_entry
+{
+}
+;
+
+num_list_entry: NUM
+{
+ current_floats.push_back($1);
+}
+;
+
+param_list: init_param_list param_lists
+{
+}
+;
+
+init_param_list: %prec HIGH_PRECEDENCE
+{
+ params.clear();
+}
+;
+
+param_lists: param_list_entry param_lists
+{
+}
+|
+{
+}
+;
+
+param_list_entry: STRING array
+{
+ // add the param token/value to the global paramset here
+
+ char type[128];
+ char name[128];
+
+ // parse the param declaration for type and name
+ int num_tokens = sscanf($1, "%s %s", type, name);
+ if (num_tokens != 2)
+ {
+ fprintf(stderr, "grparse: ERROR - Param declaration not in form ");
+ fprintf(stderr, "\"type name\": line %i\n",
+ line_num);
+ exit(0);
+ }
+
+ // add the param to params based on the type
+ if (false)
+ {
+ }
+#if 0
+ else if (strcmp(type, "int") == 0)
+ {
+ size_t count = current_floats.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - int array declared \'%s\'",
$1);
+ fprintf(stderr, " current_floats empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ int* int_array = new int[count];
+ for (size_t i = 0; i < count; ++i)
+ int_array[i] = (int)current_floats[i];
+
+ params.addInt(name, int_array, count);
+ delete [] int_array;
+ }
+ else if (strcmp(type, "bool") == 0)
+ {
+ size_t count = current_floats.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - bool array declared \'%s\'",
$1);
+ fprintf(stderr, " current_floats empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ int* int_array = new int[count];
+ for (size_t i = 0; i < count; i++)
+ int_array[i] = (int)current_floats[i];
+
+ params.addBool(name, int_array, count);
+ delete []int_array;
+ }
+#endif
+ else if (strcmp(type, "float") == 0)
+ {
+ size_t count = current_floats.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - float array declared \'%s\'",
$1);
+ fprintf(stderr, " current_floats empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ params.addFloat(name, current_floats);
+ }
+#if 0
+ else if (strcmp(type, "string") == 0)
+ {
+ size_t count = current_strings.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - stringarray declared \'%s\'",
$1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ std::string* string_array = new std::string[count];
+ for (size_t i = 0; i < count; i++)
+ string_array[i] = current_strings[i];
+
+ params.addString(name, string_array, count);
+ delete [] string_array;
+ }
+#endif
+ else if (strcmp(type, "rgb_texture") == 0)
+ {
+ size_t count = current_strings.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - RGBtex array declared \'%s\'",
$1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ vector<Texture<Color>*> tex_array(count);
+ for (size_t i = 0; i < count; i++) {
+ map<string, Texture<Color>*>::iterator rgb_texture =
rgb_textures.find(current_strings[i]);
+ if (rgb_texture != rgb_textures.end()) {
+ tex_array[i] = (*rgb_texture).second;
+ } else {
+ fprintf(stderr, " grparse: ERROR - rgbtexture \'%s\' not found",
+ current_strings[i].c_str());
+ fprintf(stderr, ": line %i\n", line_num);
+ exit(2);
+ }
+ }
+ params.addRGBTexture(name, tex_array);
+ }
+#if 0
+ else if (strcmp(type, "float_texture") == 0)
+ {
+ size_t count = current_strings.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - floatex array \'%s\'", $1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ FloatTexture** tex_array = new FloatTexture*[count];
+ for (size_t i = 0; i < count; i++)
+ {
+ FloatTexture* tex =
grGetFloatTexture(current_strings[i].c_str());
+ if (tex == NULL)
+ {
+ fprintf(stderr, " grparse: ERROR - floattex \'%s\' not
found",
+ current_strings[i].c_str());
+ fprintf(stderr, ": line %i\n", line_num);
+ exit(0);
+ }
+ else
+ tex_array[i] = tex;
+ }
+ params.addFloatTexture(name, tex_array, count);
+ delete [] tex_array;
+ }
+ else if (strcmp(type, "image") == 0)
+ {
+ size_t count = current_strings.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - image array declared \'%s\'",
$1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ Image** image_array = new Image*[count];
+ for (size_t i = 0; i < count; i++)
+ {
+ Image* image = grGetImage(current_strings[i].c_str());
+ if (image == NULL)
+ {
+ GRError("grparse: image \'%s\' not found, line %i\n",
+ current_strings[i].c_str(), line_num);
+ }
+ else
+ image_array[i] = image;
+ }
+ params.addImage(name, image_array, count);
+ delete [] image_array;
+ }
+ else if (strcmp(type, "object") == 0)
+ {
+ size_t count = current_strings.length();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - object declared \'%s\'", $1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ Surface** object_array = new Surface*[count];
+ for (size_t i = 0; i < count; i++)
+ {
+ Surface* object = grGetObject(current_strings[i].c_str());
+ if (object == NULL)
+ {
+ GRError("grparse: object\'%s\' not found, line %i\n",
+ current_strings[i].c_str(), line_num);
+ }
+ else
+ object_array[i] = object;
+ }
+ params.addSurface(name, object_array, count);
+ delete [] object_array;
+ }
+ else if (strcmp(type, "lshader") == 0)
+ {
+ size_t count = current_strings.length();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR-shader array declared \'%s\'",
$1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ LightShader** shader_array = new LightShader*[count];
+ for (size_t i = 0; i < count; i++)
+ {
+ LightShader* shader = grGetLShader(current_strings[i].c_str());
+ if (shader == NULL)
+ {
+ fprintf(stderr, " grparse: ERROR - lshader\'%s\' not found",
+ current_strings[i].c_str());
+ fprintf(stderr, ": line %i\n", line_num);
+ exit(0);
+ }
+ else
+ shader_array[i] = shader;
+ }
+ params.addLShader(name, shader_array, count);
+ delete [] shader_array;
+ }
+ else if (strcmp(type, "sshader") == 0)
+ {
+ size_t count = current_strings.length();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR-shader array declared \'%s\'",
$1);
+ fprintf(stderr, " current_strings empty: line %i\n", line_num);
+ exit(0);
+ }
+
+ SurfaceShader** shader_array = new SurfaceShader*[count];
+ for (size_t i = 0; i < count; i++)
+ {
+ SurfaceShader* shader = grGetSShader(current_strings[i].c_str());
+ if (shader == NULL)
+ {
+ fprintf(stderr, " grparse: ERROR - sshader\'%s\' not found",
+ current_strings[i].c_str());
+ fprintf(stderr, ": line %i\n", line_num);
+ exit(0);
+ }
+ else
+ shader_array[i] = shader;
+ }
+ params.addSShader(name, shader_array, count);
+ delete [] shader_array;
+ }
+#endif
+ else if (strcmp(type, "vector") == 0)
+ {
+ size_t count = current_floats.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - vec array declared \'%s\'",
$1);
+ fprintf(stderr, " current_floats empty: line %i\n", line_num);
+ exit(0);
+ }
+ if (count%3 != 0)
+ {
+ fprintf(stderr, "grparse: ERROR - vec array declared \'%s\'",
$1);
+ fprintf(stderr, " but array length not multiple of 3 : line
%i\n",
+ line_num);
+ exit(0);
+ }
+
+ count = count / 3;
+ vector<Vector> vec_array(count);
+ for (size_t i = 0; i < count; i++)
+ {
+ int index = i*3;
+ vec_array[i] = Vector(current_floats[index+0],
+ current_floats[index+1],
+ current_floats[index+2]);
+ }
+
+ params.addVector(name, vec_array);
+ }
+ else if (strcmp(type, "rgb") == 0)
+ {
+ size_t count = current_floats.size();
+ if (count == 0)
+ {
+ fprintf(stderr, "grparse: ERROR - vec array declared \'%s\'",
$1);
+ fprintf(stderr, " current_floats empty: line %i\n", line_num);
+ exit(2);
+ }
+ if (count%3 != 0)
+ {
+ fprintf(stderr, "grparse: ERROR - rgb array declared \'%s\'",
$1);
+ fprintf(stderr, " but array length not multiple of 3 : line
%i\n",
+ line_num);
+ exit(2);
+ }
+
+ count = count / 3;
+ vector<RGBColor> rgb_array(count);
+ for (size_t i = 0; i < count; i++)
+ {
+ int index = i*3;
+ rgb_array[i] = RGBColor(current_floats[index+0],
+ current_floats[index+1],
+ current_floats[index+2]);
+ }
+
+ params.addRGB(name, rgb_array);
+ }
+ else
+ {
+ fprintf(stderr,
+ "grparse: - unknown param type \'%s\' at line %i\n",
+ type, line_num);
+ }
+}
+;
+
+statement_list: statement_list statement
+{
+}
+| statement
+{
+}
+;
+
+statement: ACCEL STRING param_list
+{
+
+#if 0
+ grAccel($2, params);
+#endif
+}
+| AREALIGHT
+{
+#if 0
+ grAreaLight();
+#endif
+}
+| ATTRIBUTEBEGIN
+{
+#if 0
+ grAttributeBegin();
+#endif
+}
+| ATTRIBUTEND
+{
+#if 0
+ grAttributeEnd();
+#endif
+}
+| CAMERA STRING param_list
+{
+
+#if 0
+ grCamera($2, params);
+#endif
+}
+| CLIPPING NUM NUM
+{
+#if 0
+ grClipping($2, $3);
+#endif
+}
+| CONCATTRANSFORM NUM NUM NUM NUM
+ NUM NUM NUM NUM
+ NUM NUM NUM NUM
+ NUM NUM NUM NUM
+{
+ float trans[16] = { $2, $3, $4, $5,
+ $6, $7, $8, $9,
+ $10, $11, $12, $13,
+ $14, $15, $16, $17};
+#if 0
+ grConcatTransform(trans);
+#endif
+}
+| DISPLACEMENT STRING STRING param_list
+{
+
+#if 0
+ grDisplacement($2, $3, params);
+#endif
+}
+| ENVIRONMENT STRING param_list
+{
+#if 0
+ grEnvironment($2, params);
+#endif
+}
+| FRAMEBEGIN
+{
+#if 0
+ grFrameBegin();
+#endif
+}
+| FRAMEEND
+{
+#if 0
+ grFrameEnd();
+#endif
+}
+| IDENTITY
+{
+#if 0
+ grIdentity();
+#endif
+}
+| IMAGE STRING NUM NUM
+{
+#if 0
+ grImage($2, (int)$3, (int)$4);
+#endif
+}
+| INSTANCE STRING
+{
+#if 0
+ grInstance($2);
+#endif
+}
+| LIGHT STRING
+{
+#if 0
+ grLight($2);
+#endif
+}
+| LIGHTSHADER STRING STRING param_list
+{
+#if 0
+ grLightShader($2, $3, params);
+#endif
+}
+| LOOKAT NUM NUM NUM
+ NUM NUM NUM
+ NUM NUM NUM
+{
+#if 0
+ grLookAt($2, $3, $4,
+ $5, $6, $7,
+ $8, $9, $10);
+#endif
+}
+| MAXDEPTH NUM
+{
+#if 0
+ grMaxDepth((int)$2);
+#endif
+}
+| OBJECTBEGIN STRING
+{
+#if 0
+ grObjectBegin($2);
+#endif
+}
+| OBJECTEND
+{
+#if 0
+ grObjectEnd();
+#endif
+}
+| PIXELSAMPLES NUM
+{
+#if 0
+ grPixelSamples((int)$2);
+#endif
+}
+| RENDERER STRING param_list
+{
+#if 0
+ grRenderer($2, params);
+#endif
+}
+| ROTATE NUM NUM NUM NUM
+{
+#if 0
+ grRotate($2, $3, $4, $5);
+#endif
+}
+| SAMPLER STRING param_list
+{
+#if 0
+ grSampler($2, params);
+#endif
+}
+| SCALE NUM NUM NUM
+{
+#if 0
+ grScale($2, $3, $4);
+#endif
+}
+| SPECTRAL STRING
+{
+#if 0
+ if (strcmp($2, "false") == 0)
+ {
+ grSpectral(false);
+ }
+ else if (strcmp($2, "true") == 0)
+ {
+ grSpectral(true);
+ }
+ else
+ {
+ GRWarning("grparse: Unknown Spectral flag \'%s\' line: %i", $2,
+ line_num);
+ }
+#endif
+}
+| SURFACE STRING param_list
+{
+ if (strcmp($2, "Parallelogram") == 0) {
+ Vector anchor, v1, v2;
+ map<string, vector<Vector> >::iterator found =
params.vectors.find("base");
+ if (found == params.vectors.end()) {
+ // woot woot
+ fprintf(stderr, "vector base not found for Parallelogram\n");
+ exit(2);
+ } else {
+ size_t num_vectors = (*found).second.size();
+ if (num_vectors == 1) {
+ anchor = (*found).second[0];
+ } else {
+ fprintf(stderr, "Got wrong number of base vectors (got %llu) \n",
+ (unsigned long long)num_vectors);
+ }
+ }
+
+ found = params.vectors.find("v");
+ if (found == params.vectors.end()) {
+ // woot woot
+ fprintf(stderr, "vector v not found for Parallelogram\n");
+ exit(2);
+ } else {
+ size_t num_vectors = (*found).second.size();
+ if (num_vectors == 1) {
+ v1 = (*found).second[0];
+ } else {
+ fprintf(stderr, "Got wrong number of v vectors (got %llu) \n",
+ (unsigned long long)num_vectors);
+ }
+ }
+
+ found = params.vectors.find("u");
+ if (found == params.vectors.end()) {
+ // woot woot
+ fprintf(stderr, "vector u not found for Parallelogram\n");
+ exit(2);
+ } else {
+ size_t num_vectors = (*found).second.size();
+ if (num_vectors == 1) {
+ v2 = (*found).second[0];
+ } else {
+ fprintf(stderr, "Got wrong number of u vectors (got %llu) \n",
+ (unsigned long long)num_vectors);
+ }
+ }
+
+ world->add(new Parallelogram(/* material */ current_material,
+ /* anchor */ anchor,
+ /* v1 */ v1,
+ /* v2 */ v2));
+ } else {
+ fprintf(stderr, "Unknown surface object (%s)\n", $2);
+ }
+}
+| SURFACESHADER STRING
+{
+ // Lookup named shader
+ map<string, Material*>::iterator material = materials.find(string($2));
+ if (material != materials.end()) {
+ current_material = (*material).second;
+ } else {
+ fprintf(stderr, "Can't find named material s()", $2);
+ exit(2);
+ }
+}
+| SURFACESHADER STRING STRING param_list
+{
+ // Create new named shared
+ if (strcmp($3, "LambertianShader") == 0) {
+ map<string, vector<Texture<Color>*> >::iterator rgb_texture =
params.rgb_textures.find("Kd");
+ if (rgb_texture != params.rgb_textures.end()) {
+ Material* material = new Lambertian((*rgb_texture).second[0]);
+ materials[string($2)] = material;
+ current_material = material;
+ }
+ } else {
+ fprintf(stderr, "Unknown surface shader (%s)\n", $3);
+ }
+}
+| TEXTURE STRING STRING STRING param_list
+{
+ if (strcmp($3, "ConstantTexture") == 0) {
+ if (strcmp($4, "rgb") == 0) {
+ map<string, vector<RGBColor> >::iterator rgb =
params.rgb_colors.find("value");
+ if (rgb != params.rgb_colors.end()) {
+ rgb_textures[$2] = new Constant<Color>(Color((*rgb).second[0]));
+ } else {
+ fprintf(stderr, "Didn't find value\n");
+ exit(2);
+ }
+ } else {
+ fprintf(stderr, "Unknown texture type (%s)\n", $4);
+ }
+ } else {
+ fprintf(stderr, "Unknown texture (%s)\n", $3);
+ }
+}
+| TONEMAP STRING param_list
+{
+#if 0
+ grToneMap($2, params);
+#endif
+}
+| TRANSFORM NUM NUM NUM NUM
+ NUM NUM NUM NUM
+ NUM NUM NUM NUM
+ NUM NUM NUM NUM
+{
+ float trans[16] = { $2, $3, $4, $5,
+ $6, $7, $8, $9,
+ $10, $11, $12, $13,
+ $14, $15, $16, $17};
+#if 0
+ grTransform(trans);
+#endif
+}
+| TRANSFORMBEGIN
+{
+#if 0
+ grTransformBegin();
+#endif
+}
+| TRANSFORMEND
+{
+#if 0
+ grTransformEnd();
+#endif
+}
+| TRANSLATE NUM NUM NUM
+{
+#if 0
+ grTranslate($2, $3, $4);
+#endif
+}
+| WORLDBEGIN
+{
+#if 0
+ grWorldBegin();
+#endif
+}
+| WORLDEND
+{
+ params.clear();
+#if 0
+ grWorldEnd();
+#endif
+}
+;
+
+%%
+
+int yyerror(char* s)
+{
+ fprintf(stderr, "\n%s at line: %i\n", s, line_num );
+ return 0;
+}
+
+
- [MANTA] r1240 - in trunk: CMake scenes scenes/galileo, bigler, 12/01/2006
Archive powered by MHonArc 2.6.16.