Text archives Help
- From:
- To:
- Subject: [Manta] r2323 - trunk/scenes
- Date: Fri, 12 Sep 2008 17:23:22 -0600 (MDT)
Author: aek
Date: Fri Sep 12 17:23:22 2008
New Revision: 2323
Added:
trunk/scenes/cubeWorld.cc
Modified:
trunk/scenes/CMakeLists.txt
Log:
Adding a new test scene, cubeWorld. This scene simply populates a DynBVH
with a set of oriented boxes described in a given text file. Each box is
given as nine floats, three each for the center, lengths, and orientation
(pitch, roll, yaw). Because the boxes are indivisible, this can be useful
for testing some aspects of acceleration structures.
Using this scene is similar to triangleSceneViewer. It only recognizes the
-model and -lightPosition arguments, however.
The following is a simple python script that can generate the two different
test scenes, room-of-dice and pickup-sticks suggested by Eric Haines in RTN
(
http://tog.acm.org/resources/RTNews/html/rtnv20n1.html#art8):
# ----------------------------------------
from random import *
from math import *
class vector:
def __init__( self, x, y, z ):
self.x = x
self.y = y
self.z = z
def __add__( self, other ):
return vector( self.x + other.x,
self.y + other.y,
self.z + other.z )
def __sub__( self, other ):
return vector( self.x - other.x,
self.y - other.y,
self.z - other.z )
def __mul__( self, other ):
return vector( self.x * other,
self.y * other,
self.z * other )
def dot( self, other ):
return ( self.x * other.x +
self.y * other.y +
self.z * other.z )
def box( center, length, angle ):
print "%g %g %g %g %g %g 0 0 %g" % ( center.x, center.y, center.z,
length.x, length.y, length.z,
angle )
def dice():
room = 56
half = room * 0.5
box( vector( 0, 0, half + 0.5 ), vector( room + 2, room + 2, room + 2 ),
0 )
positions = []
while len( positions ) < 1023:
center = vector( random() * room - half, random() * room - half, 0 )
for position in positions:
offset = center - position
if offset.dot( offset ) < 2:
break
else:
positions.append( center )
box( center, vector( 1, 1, 1 ), random() * 360 )
def sticks():
half = 250
for index in range( -half, half + 1 ):
box( vector( index, 0, 0 ), vector( 0.25, half * 2, 0.25 ), 0 )
box( vector( 0, index, 0 ), vector( half * 2, 0.25, 0.25 ), 0 )
dice()
# sticks()
# ----------------------------------------
Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Fri Sep 12 17:23:22 2008
@@ -154,3 +154,10 @@
ADD_LIBRARY(scene_externalObject externalObject.cc)
TARGET_LINK_LIBRARIES(scene_externalObject ${MANTA_SCENE_LINK})
ENDIF(SCENE_EXTERNAL_OBJECT)
+
+# Loads oriented boxes to test acceleration structures (box are indivisible)
+SET(SCENE_CUBE_WORLD TRUE CACHE BOOL "Loads sets of oriented boxes")
+IF(SCENE_CUBE_WORLD)
+ ADD_LIBRARY(scene_cubeWorld cubeWorld.cc)
+ TARGET_LINK_LIBRARIES(scene_cubeWorld ${MANTA_SCENE_LINK})
+ENDIF(SCENE_CUBE_WORLD)
Added: trunk/scenes/cubeWorld.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/cubeWorld.cc Fri Sep 12 17:23:22 2008
@@ -0,0 +1,113 @@
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/UnknownColor.h>
+#include <Core/Util/Args.h>
+#include <Core/Util/Preprocessor.h>
+#include <Interface/Context.h>
+#include <Interface/LightSet.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ArcAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Groups/DynBVH.h>
+#include <Model/Instances/Instance.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Primitives/Cube.h>
+
+#include <string>
+#include <vector>
+#include <fstream>
+#include <iostream>
+
+using namespace Manta;
+using namespace std;
+
+void argumentError(
+ int i,
+ vector< string > const &arguments )
+{
+ cerr << "Valid options for scene cubeWorld:" << endl
+ << " -model - Required. The file to load each line of the
model has 9 floats:" << endl
+ << " <center> <lengths> pitch roll yaw." << endl
+ << " -lightPosition - Location of light." << endl;
+ throw IllegalArgument("scene cubeWorld", i, arguments );
+}
+
+MANTA_PLUGINEXPORT
+Scene* make_scene(
+ ReadContext const &/*context*/,
+ vector< string > const &arguments )
+{
+
+ cout << "Make_scene arguments: " << arguments.size() << endl;
+ string file_name;
+ Vector light_position;
+ bool file_set = false;
+ bool light_set = false;
+
+ for( size_t index = 0; index < arguments.size(); ++index )
+ {
+ string arg = arguments[ index ];
+ if( arg == "-model" )
+ {
+ if( !getStringArg( index, arguments, file_name ) )
+ throw IllegalArgument( "scene cubeWorld -model", index,
arguments );
+ file_set = true;
+ }
+ else if (arg == "-lightPosition")
+ {
+ if ( !getVectorArg( index, arguments, light_position ) )
+ throw IllegalArgument( "scene cubeWorld -lightPosition",
index, arguments );
+ light_set = true;
+ }
+ else
+ argumentError( index, arguments );
+ }
+ if ( arguments.empty() || !file_set )
+ argumentError( 0, arguments );
+
+ Group* group = new Group();
+ Material *flat = new Lambertian( Color::white() * 0.8 );
+ ifstream input( file_name.c_str() );
+ while( input )
+ {
+ Vector center, length, rotations;
+ input >> center >> length >> rotations;
+ length *= 0.5;
+ if ( rotations != Vector( 0.0, 0.0, 0.0 ) )
+ {
+ AffineTransform transform;
+ transform.initWithIdentity();
+ transform.rotate( Vector( 1.0, 0.0, 0.0 ), rotations.x() * M_PI
/ 180.0 );
+ transform.rotate( Vector( 0.0, 1.0, 0.0 ), rotations.y() * M_PI
/ 180.0 );
+ transform.rotate( Vector( 0.0, 0.0, 1.0 ), rotations.z() * M_PI
/ 180.0 );
+ transform.translate( center );
+ group->add( new Instance( new Cube( flat, -length, length ),
transform ) );
+ }
+ else
+ group->add( new Cube( flat, center - length, center + length ) );
+ }
+
+ LightSet* lights = new LightSet();
+ if ( !light_set )
+ {
+ BBox bbox;
+ PreprocessContext dummy_context;
+ group->computeBounds( dummy_context, bbox );
+ light_position = bbox[ 1 ] + bbox.diagonal() * 0.3;
+ }
+ lights->add( new PointLight( light_position, Color::white() ) );
+ lights->setAmbientLight( new ArcAmbient( Color( RGB( 0.2, 0.2, 0.3 ) ),
+ Color( RGB( 0.2, 0.1, 0.1 ) ),
+ Vector( 0.0, 0.0, 1.0 ) ) );
+
+ AccelerationStructure *world = new DynBVH();
+ world->setGroup( group );
+ world->rebuild();
+ Scene* scene = new Scene();
+ scene->setBackground( new ConstantBackground( Color::white() * 0.1 ) );
+ scene->setObject( world );
+ scene->setLights( lights );
+
+ return scene;
+
+}
- [Manta] r2323 - trunk/scenes, aek, 09/12/2008
Archive powered by MHonArc 2.6.16.