Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1457 - in trunk: Core/Math Engine/ImageTraversers Engine/PixelSamplers Interface Model/Materials Model/Textures
- Date: Mon, 9 Jul 2007 16:56:28 -0600 (MDT)
Author: bigler
Date: Mon Jul 9 16:56:27 2007
New Revision: 1457
Added:
trunk/Interface/RandomNumberGenerator.cc
trunk/Interface/RandomNumberGenerator.h
Modified:
trunk/Core/Math/CheapRNG.h
trunk/Core/Math/MT_RNG.cc
trunk/Core/Math/MT_RNG.h
trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc
trunk/Engine/PixelSamplers/JitterSampler.cc
trunk/Interface/CMakeLists.txt
trunk/Model/Materials/AmbientOcclusion.cc
trunk/Model/Textures/NormalTexture.h
Log:
Core/Math/CheapRNG.h
Now inherit from and implement the RandomNumberGenerator interface.
Core/Math/MT_RNG.cc
Core/Math/MT_RNG.h
Now inherit from and implement the RandomNumberGenerator interface.
I'm not sure why we were using unsigned longs when we should be
using unsigned ints.
Engine/ImageTraversers/DissolveTiledImageTraverser.cc
Engine/PixelSamplers/JitterSampler.cc
Updates for new RandomNumberGenerator interface.
Interface/CMakeLists.txt
Add RandomNumberGenerator.
Alphabetize file list.
Interface/RandomNumberGenerator.cc
Interface/RandomNumberGenerator.h
Model/Materials/AmbientOcclusion.cc
New random number generator interface.
Model/Textures/NormalTexture.h
Reorder member variables to quiet GCC warning.
Modified: trunk/Core/Math/CheapRNG.h
==============================================================================
--- trunk/Core/Math/CheapRNG.h (original)
+++ trunk/Core/Math/CheapRNG.h Mon Jul 9 16:56:27 2007
@@ -54,10 +54,11 @@
// For the Real type
#include <MantaTypes.h>
+#include <Interface/RandomNumberGenerator.h>
namespace Manta {
- class CheapRNG {
+ class CheapRNG: public RandomNumberGenerator {
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
@@ -71,30 +72,14 @@
// Your seed value is upto the fates. You should call seed.
CheapRNG() {}
- inline void seed(uint32 seed_val) {
+ virtual void seed(unsigned int seed_val) {
val = seed_val;
}
- inline uint32 randInt() {
+ virtual unsigned int nextInt() {
val = 1664525*val + 1013904223;
return val;
}
-
- // [0..1]
- inline Real rand() {
- return Real(randInt())*Real(1./4294967295.);
- }
-
- // real number in [0,1)
- inline Real randExc() {
- return Real(randInt())*Real(1./4294967296.);
- }
-
- // real number in (0,1)
- inline Real randDblExc() {
- return ( Real(randInt()) + Real(0.5) ) * Real(1./4294967296.);
- }
-
}; // end class CheapRNG
}
Modified: trunk/Core/Math/MT_RNG.cc
==============================================================================
--- trunk/Core/Math/MT_RNG.cc (original)
+++ trunk/Core/Math/MT_RNG.cc Mon Jul 9 16:56:27 2007
@@ -48,28 +48,28 @@
/* initializing the array with a NONZERO seed */
-void MT_RNG::seed_rng(unsigned long seed)
+void MT_RNG::seed(unsigned int seed)
{
/* setting initial seeds to mt[MT_RNG_N] using */
/* the generator Line 25 of Table 1 in */
/* [KNUTH 1981, The Art of Computer Programming */
/* Vol. 2 (2nd Ed.), pp102] */
- mt[0]= seed & 0xffffffff;
+ mt[0]= seed;
for (mti=1; mti<MT_RNG_N; mti++)
- mt[mti] = (69069 * mt[mti-1]) & 0xffffffff;
+ mt[mti] = (69069 * mt[mti-1]);
}
-unsigned long MT_RNG::genrand()
+unsigned int MT_RNG::nextInt()
{
- unsigned long y;
- static unsigned long mag01[2]={0x0, MATRIX_A};
+ unsigned int y;
+ static unsigned int mag01[2]={0x0, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= MT_RNG_N) { /* generate MT_RNG_N words at one time */
int kk;
- if (mti == MT_RNG_N+1) /* if seed_rng() has not been called, */
- seed_rng(4357); /* a default initial seed is used */
+ if (mti == MT_RNG_N+1) /* if seed() has not been called, */
+ seed(4357); /* a default initial seed is used */
for (kk=0;kk<MT_RNG_N-MT_RNG_M;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
@@ -94,35 +94,13 @@
return y;
}
-double MT_RNG::gendrand() {
- return ( (double)genrand() / 4.294967295e+09 );
- // return ( (double)genrand() / (unsigned long)0xffffffff );
-}
-
-float MT_RNG::genfrand() {
- return ( (float)genrand() / (unsigned long)0xffffffff );
-}
-
void MT_RNG::test_print() {
int j;
- seed_rng(4357); // any nonzero integer can be used as a seed
+ seed(4357); // any nonzero integer can be used as a seed
for (j=0; j<1000; j++) {
- printf("%5f ", gendrand());
+ printf("%5f ", nextDouble());
if (j%8==7) printf("\n");
}
printf("\n");
}
-
-template<>
-float MT_RNG::genRealRand<float>()
-{
- return genfrand();
-}
-
-template<>
-double MT_RNG::genRealRand<double>()
-{
- return gendrand();
-}
-
Modified: trunk/Core/Math/MT_RNG.h
==============================================================================
--- trunk/Core/Math/MT_RNG.h (original)
+++ trunk/Core/Math/MT_RNG.h Mon Jul 9 16:56:27 2007
@@ -31,36 +31,24 @@
#ifndef __MT19937_H__
#define __MT19937_H__
+#include <Interface/RandomNumberGenerator.h>
+
namespace Manta {
// Period parameters
#define MT_RNG_N 624
#define MT_RNG_M 397
-class MT_RNG {
- unsigned long mt[MT_RNG_N]; // the array for the state vector
+class MT_RNG : public RandomNumberGenerator {
+ unsigned int mt[MT_RNG_N]; // the array for the state vector
int mti; // mti==MT_RNG_N+1 means mt[MT_RNG_N] is not initialized
public:
MT_RNG(): mti(MT_RNG_N+1) {}
- void seed_rng(unsigned long seed);
- unsigned long genrand();
- double gendrand();
- float genfrand();
-
- // Default to returning a double. In actuallity this should never
- // be used.
- template<class T>
- T genRealRand() { return static_cast<T>(gendrand()); }
-
+ void seed(unsigned int seed);
+ virtual unsigned int nextInt();
void test_print(); // prints some random numbers to the console
};
-
-template<>
-float MT_RNG::genRealRand<float>();
-
-template<>
-double MT_RNG::genRealRand<double>();
} // end namespace Manta
Modified: trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc (original)
+++ trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc Mon Jul 9
16:56:27 2007
@@ -123,7 +123,7 @@
// Inialize the random number stuff. Since we are using the
// modulous we need to add 1 to get the range from [0,numTiles-1]
// to [1,numTiles].
- cdata.next_tile = rng.randInt()%cdata.numTiles + 1;
+ cdata.next_tile = rng.nextInt()%cdata.numTiles + 1;
// Figure out the mask
int num_bits = numBinaryDigits(cdata.numTiles);
if (num_bits > 32)
Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Mon Jul 9 16:56:27 2007
@@ -140,7 +140,7 @@
if (use_cheaprng)
rng.seed(fragment.getX(b)*ci.xres+fragment.getY(b));
else
- random[thd_num].seed_rng(fragment.getX(b)*ci.xres+fragment.getY(b));
+ random[thd_num].seed(fragment.getX(b)*ci.xres+fragment.getY(b));
}
int depth = 0;
@@ -166,7 +166,7 @@
if (use_cheaprng)
rng.seed(fragment.getX(frag_index)*ci.xres+fragment.getY(frag_index));
else
-
random[thd_num].seed_rng(fragment.getX(frag_index)*ci.xres+fragment.getY(frag_index));
+
random[thd_num].seed(fragment.getX(frag_index)*ci.xres+fragment.getY(frag_index));
}
// For each fragment start filling up the RayPacket with samples.
@@ -179,11 +179,15 @@
{
Real x_sample, y_sample;
if (use_cheaprng) {
- x_sample = (xs + rng.rand()) * inx;
- y_sample = (ys + rng.rand()) * iny;
+ // I'm using the float version, because it seems to make a
+ // differnce in performance. This is likely due the
+ // compiler's ability to inline all the necessary
+ // functions which using next<Real> prevents.
+ x_sample = (xs + rng.nextFloat()) * inx;
+ y_sample = (ys + rng.nextFloat()) * iny;
} else {
- x_sample = (xs + random[thd_num].genRealRand<Real>()) * inx;
- y_sample = (ys + random[thd_num].genRealRand<Real>()) * iny;
+ x_sample = (xs + random[thd_num].next<Real>()) * inx;
+ y_sample = (ys + random[thd_num].next<Real>()) * iny;
}
px = (fx+x_sample)*ci.xscale+ci.xoffset;
py = (fy+y_sample)*ci.yscale+ci.yoffset;
Modified: trunk/Interface/CMakeLists.txt
==============================================================================
--- trunk/Interface/CMakeLists.txt (original)
+++ trunk/Interface/CMakeLists.txt Mon Jul 9 16:56:27 2007
@@ -1,64 +1,66 @@
## Create the Interface library.
ADD_LIBRARY(Manta_Interface
- AmbientLight.h
- AmbientLight.cc
+ CallbackHandle.h
+ CameraPath.cc
+ CameraPath.h
AccelerationStructure.h
- Background.h
+ AmbientLight.cc
+ AmbientLight.h
Background.cc
- Camera.h
+ Background.h
+ Callback.h
+ CallbackHelpers.h
Camera.cc
- CameraPath.h
- CameraPath.cc
+ Camera.h
Clonable.h
Context.h
Fragment.h
- IdleMode.h
IdleMode.cc
- Image.h
+ IdleMode.h
Image.cc
- ImageDisplay.h
+ Image.h
ImageDisplay.cc
- ImageTraverser.h
+ ImageDisplay.h
ImageTraverser.cc
+ ImageTraverser.h
Interpolable.h
- Light.h
Light.cc
- LightSet.h
+ Light.h
LightSet.cc
- LoadBalancer.h
+ LightSet.h
LoadBalancer.cc
- MantaInterface.h
+ LoadBalancer.h
MantaInterface.cc
- Material.h
+ MantaInterface.h
Material.cc
- Object.h
+ Material.h
Object.cc
- PixelSampler.h
+ Object.h
PixelSampler.cc
- Primitive.h
+ PixelSampler.h
Primitive.cc
- RayPacket.h
+ Primitive.h
+ RandomNumberGenerator.cc
+ RandomNumberGenerator.h
RayPacket.cc
- Renderer.h
- Renderer.cc
+ RayPacket.h
RenderParameters.h
- SetupCallback.h
- SetupCallback.cc
- Scene.h
+ Renderer.cc
+ Renderer.h
Scene.cc
- ShadowAlgorithm.h
+ Scene.h
+ SetupCallback.cc
+ SetupCallback.h
ShadowAlgorithm.cc
- TexCoordMapper.h
+ ShadowAlgorithm.h
TexCoordMapper.cc
+ TexCoordMapper.h
Texture.h
- Transaction.h
Transaction.cc
- UserInterface.h
+ Transaction.h
UserInterface.cc
+ UserInterface.h
XWindow.h
- Callback.h
- CallbackHelpers.h
- CallbackHandle.h
)
TARGET_LINK_LIBRARIES(Manta_Interface Manta_Core SCIRun_Core )
Added: trunk/Interface/RandomNumberGenerator.cc
==============================================================================
--- (empty file)
+++ trunk/Interface/RandomNumberGenerator.cc Mon Jul 9 16:56:27 2007
@@ -0,0 +1,19 @@
+#include <Interface/RandomNumberGenerator.h>
+
+namespace Manta {
+
+ // Don't put these in the header, or you will get multiply defined
+ // symbols.
+ template<>
+ float RandomNumberGenerator::next<float>()
+ {
+ return nextFloat();
+ }
+
+ template<>
+ double RandomNumberGenerator::next<double>()
+ {
+ return nextDouble();
+ }
+
+} // end namespace Manta
Added: trunk/Interface/RandomNumberGenerator.h
==============================================================================
--- (empty file)
+++ trunk/Interface/RandomNumberGenerator.h Mon Jul 9 16:56:27 2007
@@ -0,0 +1,74 @@
+#ifndef Manta_Interface_RandomNumberGenerator_h
+#define Manta_Interface_RandomNumberGenerator_h
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2003-2005
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+/*
+ */
+
+#include <MantaSSE.h>
+
+namespace Manta {
+ class RandomNumberGenerator {
+ public:
+ virtual ~RandomNumberGenerator() {}
+
+ virtual void seed(unsigned int val) = 0;
+
+ // result = [0, 4294967295(UINT_MAX)]
+ virtual unsigned int nextInt() = 0;
+
+ // All the floating point interface return numbers in the range of
+ // [0, 1).
+
+ // This function can't be virtual, since it is a template member
+ // function.
+ template<class T>
+ T next() { return 0; }
+
+ virtual double nextDouble() {
+ return ( (double)nextInt() * (1./4294967296.) );
+ }
+
+ virtual float nextFloat() {
+ return ( (float)nextInt() * (float)((1./4294967296.)) );
+ }
+ };
+
+ // Don't put the implementations here, because you will get multiply
+ // defined symbols.
+ template<>
+ float RandomNumberGenerator::next<float>();
+
+ template<>
+ double RandomNumberGenerator::next<double>();
+
+} // end namespace Manta
+
+#endif // #ifndef Manta_Interface_RandomNumberGenerator_h
Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc Mon Jul 9 16:56:27 2007
@@ -43,8 +43,8 @@
// generate cosine weighted directions
for ( int i = 0; i < num_directions; i++ )
{
- double r1 = rng.genRealRand<double>();
- double r2 = rng.genRealRand<double>();
+ double r1 = rng.next<double>();
+ double r2 = rng.next<double>();
double phi = 2.0 * Pi * r1;
double r = sqrt(r2);
Modified: trunk/Model/Textures/NormalTexture.h
==============================================================================
--- trunk/Model/Textures/NormalTexture.h (original)
+++ trunk/Model/Textures/NormalTexture.h Mon Jul 9 16:56:27 2007
@@ -92,8 +92,8 @@
void getBarycentricCoords( RayPacket &rays, int which,
Real &a, Real &b, Real &c ) const;
- ValueType wire_value;
Texture<ValueType> *texture;
+ ValueType wire_value;
};
// Specialized versions of functions
- [MANTA] r1457 - in trunk: Core/Math Engine/ImageTraversers Engine/PixelSamplers Interface Model/Materials Model/Textures, bigler, 07/09/2007
Archive powered by MHonArc 2.6.16.