Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r391 - in trunk: Core/Math Engine/PixelSamplers SwigInterface
- Date: Thu, 16 Jun 2005 17:08:00 -0600 (MDT)
Author: bigler
Date: Thu Jun 16 17:08:00 2005
New Revision: 391
Removed:
trunk/Core/Math/CheapRNG.cc
Modified:
trunk/Core/Math/CheapRNG.h
trunk/Engine/PixelSamplers/JitterSampler.cc
trunk/Engine/PixelSamplers/JitterSampler.h
trunk/SwigInterface/manta.i
trunk/SwigInterface/runmanta.py
Log:
Core/Math/CheapRNG.cc
Removed, since all the code is now in the header file.
Core/Math/CheapRNG.h
It now compiles. ;) MantaTypes.h is used to determine the type
for Real. There is no longer any float or double function.
Make sure uint32 is a 32 bit unsigned integer with a typedef.
No crazy floats generated with bit masks. Default constructor
now doesn't take a seed parameter. Use seed() after creation
instead. Since functions are typed agains Real, you no longer
need fancy templated functions.
Engine/PixelSamplers/JitterSampler.cc
Engine/PixelSamplers/JitterSampler.h
Use CheapRNG random number generator by default. You can get
MT_RNG by specifying -nocheap as an argument.
SwigInterface/manta.i
Added some support for exceptions. Still a work in progress.
Exceptions are caught for the engine, but non of the Model
stuff. Special code to catch UnknownColor thrown by
ColorDB::getNamedColor().
SwigInterface/runmanta.py
Put default scene creation in its own function to make sure
that all the pointers get setup correctly. Added a commented
out jittersample setup.
Modified: trunk/Core/Math/CheapRNG.h
==============================================================================
--- trunk/Core/Math/CheapRNG.h (original)
+++ trunk/Core/Math/CheapRNG.h Thu Jun 16 17:08:00 2005
@@ -24,70 +24,49 @@
// bit integer, because the computation relies on the overflow
// properties of integer multiplication.
+// For the Real type
+#include <MantaTypes.h>
+
namespace Manta {
class CheapRNG {
- u_int32_t val;
+ public:
+ // You need to make sure that this is 32 bits or you are in
+ // trouble. It also needs to be public to initialize the static
+ // members.
+ typedef unsigned int uint32;
+ protected:
- // These are used to play some fancy bit twiddling to "create" a
- // floating point number from the int. It kills 9 of the bits that
- // you could have otherwised used, so the period is only 2^23
- // (8,388,608).
- enum {
- float1 0x3f800000,
- mantissa_mask 0x7fffff
- };
-
- // These are for computation help. They make the interval
- // returned [0,1].
- static float inv_maxf;
- static double inv_maxd;
-
- // [0..1]
- inline float genfloat() {
- return genuint()*inv_maxf;
+ uint32 val;
+
+ public:
+ // Your seed value is upto the fates. You should call seed.
+ CheapRNG() {}
+
+ inline void seed(uint32 seed_val) {
+ val = seed_val;
}
- // [0..1]
- // See comment above for the enum.
- inline float genfloatFast() {
- float fval;
- *(u_int32_t*)(&fval) = (genuint() & mantissa_mask) | float1;
- return fval - 1;
+ inline uint32 randInt() {
+ val = 1664525*val + 1013904223;
+ return val;
}
// [0..1]
- inline double gendouble() {
- return genuint()*inv_maxd;
- }
- public:
- CheapRNG(u_int32_t seed_val = 0) {
- seed(seed_val);
- }
-
- inline void seed(u_int32_t seed_val) {
- val = seed_val;
+ inline Real rand() {
+ return Real(randInt())*Real(1./4294967295.);
}
- // Default to returning a double. In actuallity this should never
- // be used.
- template<class T>
- inline T genRealRand() { return static_cast<T>(gendouble()); }
+ // real number in [0,1)
+ inline Real randExc() {
+ return Real(randInt())*Real(1./4294967296.);
+ }
- inline u_int32_t genuint() {
- val = 1664525*val + 1013904223;
- return val;
+ // real number in (0,1)
+ inline Real randDblExc() {
+ return ( Real(randInt()) + Real(0.5) ) * Real(1./4294967296.);
}
+
}; // end class CheapRNG
-
- template<>
- inline float CheapRNG::genRealRand<float>() {
- return genfloat();
- }
-
- template<>
- inline double CheapRNG::genRealRand<double>() {
- return gendouble();
- }
}
Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Thu Jun 16 17:08:00 2005
@@ -7,6 +7,7 @@
#include <Interface/RayPacket.h>
#include <Interface/Renderer.h>
+#include <Core/Math/CheapRNG.h>
#include <Engine/PixelSamplers/Sample.h>
#include <stdio.h>
@@ -24,9 +25,9 @@
return new JitterSampler(args);
}
-JitterSampler::JitterSampler(const vector<string>& args)
+JitterSampler::JitterSampler(const vector<string>& args):
+ num_samples(4), use_cheaprng(true)
{
- num_samples = 4;
int argc = static_cast<int>(args.size());
for(int i = 0; i<argc;i++){
string arg = args[i];
@@ -36,6 +37,8 @@
if (num_samples < 1)
throw IllegalArgument("-numberOfSamples must be greater than 0",
i, args);
+ } else if (arg == "-nocheap") {
+ use_cheaprng = false;
}
else {
@@ -154,9 +157,13 @@
int consecutivex_flag = fragment.getFlags() & Fragment::ConsecutiveX;
+ CheapRNG rng;
if (consecutivex_flag) {
Fragment::Element& fe = fragment.get(0);
- random[thd_num].seed_rng(fe.x*ci.xres+fe.y);
+ if (use_cheaprng)
+ rng.seed(fe.x*ci.xres+fe.y);
+ else
+ random[thd_num].seed_rng(fe.x*ci.xres+fe.y);
}
int depth = 0;
@@ -175,7 +182,10 @@
Fragment::Element& fe0 = fragment.get(frag_index);
if (!consecutivex_flag) {
- random[thd_num].seed_rng(fe0.x*ci.xres+fe0.y);
+ if (use_cheaprng)
+ rng.seed(fe0.x*ci.xres+fe0.y);
+ else
+ random[thd_num].seed_rng(fe0.x*ci.xres+fe0.y);
}
// For each fragment start filling up the RayPacket with samples.
@@ -184,8 +194,14 @@
for(int xs = 0; xs < nx; xs++)
for(int ys = 0; ys < ny; ys++)
{
- Real x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
- Real y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
+ Real x_sample, y_sample;
+ if (use_cheaprng) {
+ x_sample = (xs + rng.rand()) * inx;
+ y_sample = (ys + rng.rand()) * iny;
+ } else {
+ x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
+ y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
+ }
px = (fe0.x+(x_sample))*ci.xscale+ci.xoffset;
py = (fe0.y+(y_sample))*ci.yscale+ci.yoffset;
rays.setPixel(next_slot, 0, px, py, &sample_color[next_slot]);
Modified: trunk/Engine/PixelSamplers/JitterSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.h (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.h Thu Jun 16 17:08:00 2005
@@ -37,6 +37,7 @@
int num_samples;
// nx*ny == num_samples where nx~=ny (or as close as you can get it).
int nx, ny;
+ bool use_cheaprng;
struct ChannelInfo {
Real xscale;
Modified: trunk/SwigInterface/manta.i
==============================================================================
--- trunk/SwigInterface/manta.i (original)
+++ trunk/SwigInterface/manta.i Thu Jun 16 17:08:00 2005
@@ -2,6 +2,7 @@
%module manta
%include "std_string.i"
%include "std_vector.i"
+%include "exception.i"
%{
#include <MantaTypes.h>
@@ -16,6 +17,41 @@
}
%{
+#include <Core/Exceptions/Exception.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/BadPrimitive.h>
+%}
+
+%include <Core/Exceptions/Exception.h>
+%include <Core/Exceptions/IllegalArgument.h>
+%include <Core/Exceptions/BadPrimitive.h>
+
+%exception create {
+ try {
+ $action
+ } catch(Manta::IllegalArgument& e) {
+ SWIG_exception(SWIG_ValueError, e.message());
+ } catch(...) {
+ SWIG_exception(SWIG_RuntimeError, "Unknown exception");
+ }
+}
+
+%exception {
+ try {
+ $action
+ } catch(Manta::IllegalArgument& e) {
+ SWIG_exception(SWIG_ValueError, e.message());
+ } catch(Manta::BadPrimitive& e) {
+ static char exception_message[1024];
+ sprintf(exception_message, "BadPrimitive: \"%s\"", e.message());
+ SWIG_exception(SWIG_ValueError, exception_message);
+ } catch(...) {
+ SWIG_exception(SWIG_RuntimeError, "Unknown exception");
+ }
+}
+
+
+%{
#include <Interface/RTRTInterface.h>
#include <Interface/UserInterface.h>
#include <Interface/RenderParameters.h>
@@ -52,10 +88,31 @@
%include <Interface/RTRTInterface.h>
+%exception;
+
/////////////////////////////////////////////////
// Model stuff
%{
+#include <Core/Exceptions/UnknownColor.h>
+%}
+
+%include <Core/Exceptions/UnknownColor.h>
+
+%exception Manta::ColorDB::getNamedColor {
+ try {
+ $action
+ } catch(Manta::UnknownColor& e) {
+ static char exception_message[1024];
+ sprintf(exception_message, "Unknown color: \"%s\"", e.message());
+ SWIG_exception(SWIG_ValueError, exception_message);
+ } catch(...) {
+ SWIG_exception(SWIG_RuntimeError, "Unknown exception");
+ }
+}
+
+
+%{
#include <MantaTypes.h>
#include <Core/Color/RGBColor.h>
#include <Core/Color/RGBTraits.h>
@@ -74,6 +131,7 @@
%include <Core/Color/ColorSpace.h>
%include <Core/Color/ColorSpace_fancy.h>
%include <Core/Color/ColorDB.h>
+
namespace Manta {
// typedef ColorSpace<RGBTraits> Color;
Modified: trunk/SwigInterface/runmanta.py
==============================================================================
--- trunk/SwigInterface/runmanta.py (original)
+++ trunk/SwigInterface/runmanta.py Thu Jun 16 17:08:00 2005
@@ -1,11 +1,48 @@
from manta import *
+def createDefaultScenePython():
+ scene = manta_new(Scene())
+
scene.setBackground(manta_new(ConstantBackground(ColorDB.getNamedColor("SkyBlue3").scaled(0.5))))
+ red = manta_new(Phong(Color(RGBColor(0.6, 0, 0)),
+ Color(RGBColor(0.6,0.6,0.6)),
+ 32, 0.4))
+ checker1 = manta_new(CheckerTexture_Color(Color(RGBColor(.6,.6,.6)),
+ Color(RGBColor(0,0,0)),
+ Vector(1,0,0),
+ Vector(0,1,0)))
+ constant_color1 = manta_new(Constant_Color(Color(RGBColor(.6,.6,.6))))
+ checker2 = manta_new(CheckerTexture_Real(0.2, 0.5, Vector(1,0,0),
+ Vector(0,1,0)))
+ plane_matl = manta_new(Phong(checker1, constant_color1, 32, checker2))
+
+ world = manta_new(Group())
+ floor = manta_new(Parallelogram(plane_matl, Point(-20,-20,0),
+ Vector(40,0,0), Vector(0,40,0)))
+ uniformmap = manta_new(UniformMapper())
+ floor.setTexCoordMapper(uniformmap)
+ world.add(floor)
+ world.add(manta_new(Sphere(red, Point(0,0,1.2), 1.0)))
+ scene.setObject(world)
+
+ lights = manta_new(LightSet())
+ lights.add(manta_new(PointLight(Point(0,5,8),
Color(RGBColor(.6,.1,.1)))))
+ lights.add(manta_new(PointLight(Point(5,0,8),
Color(RGBColor(.1,.6,.1)))))
+ lights.add(manta_new(PointLight(Point(5,5,2),
Color(RGBColor(.2,.2,.2)))))
+ lights.setAmbientLight(manta_new(ConstantAmbient(Color.black())))
+ print lights
+
+ scene.setLights(lights)
+ scene.getRenderParameters().maxDepth = 5
+ return scene
+
+
engine = createRTRT()
engine.changeNumWorkers(1)
engine.selectImageType("rgba8")
engine.selectLoadBalancer("workqueue")
engine.selectImageTraverser("tiled")
engine.selectPixelSampler("singlesample")
+#engine.selectPixelSampler("jittersample(-numberOfSamples 4)")
engine.selectRenderer("raytracer")
engine.selectShadowAlgorithm("hard")
currentCamera = engine.createCamera("pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up
0 0 1 -fov 60)")
@@ -15,41 +52,9 @@
xinterface.startup()
engine.createChannel("opengl", currentCamera, False, xres, yres)
-scene = Scene()
-bg = ConstantBackground(ColorDB.getNamedColor("SkyBlue3").scaled(0.5))
-#bg = ConstantBackground(ColorDB.getNamedColor("green"))
-scene.setBackground(bg)
-red = Phong(Color(RGBColor(0.6, 0, 0)), Color(RGBColor(0.6,0.6,0.6)), 32,
0.4)
-checker1 = CheckerTexture_Color(Color(RGBColor(.6,.6,.6)),
- Color(RGBColor(0,0,0)),
- Vector(1,0,0),
- Vector(0,1,0))
-constant_color1 = Constant_Color(Color(RGBColor(.6,.6,.6)))
-checker2 = CheckerTexture_Real(0.2, 0.5, Vector(1,0,0), Vector(0,1,0))
-plane_matl = Phong(checker1, constant_color1, 32, checker2)
-
-world = Group()
-floor = Parallelogram(plane_matl, Point(-20,-20,0),
- Vector(40,0,0), Vector(0,40,0))
-uniformmap = UniformMapper()
-floor.setTexCoordMapper(uniformmap)
-world.add(floor)
-world.add(manta_new(Sphere(red, Point(0,0,1.2), 1.0)))
-scene.setObject(world)
-
-lights = LightSet()
-lights.add(manta_new(PointLight(Point(0,5,8), Color(RGBColor(.6,.1,.1)))))
-lights.add(manta_new(PointLight(Point(5,0,8), Color(RGBColor(.1,.6,.1)))))
-lights.add(manta_new(PointLight(Point(5,5,2), Color(RGBColor(.2,.2,.2)))))
-lights.setAmbientLight(manta_new(ConstantAmbient(Color.black())))
-print lights
-
-scene.setLights(lights);
-scene.getRenderParameters().maxDepth = 5;
-
#engine.setScene(createDefaultScene())
-engine.setScene(scene)
+engine.setScene(createDefaultScenePython())
# if __name__ == "__main__":
- [MANTA] r391 - in trunk: Core/Math Engine/PixelSamplers SwigInterface, bigler, 06/16/2005
Archive powered by MHonArc 2.6.16.