Text archives Help
- From: cgribble@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1203 - in trunk: Core Core/Util Engine/Control Engine/Factory Engine/Renderers Interface
- Date: Wed, 4 Oct 2006 12:51:41 -0600 (MDT)
Author: cgribble
Date: Wed Oct 4 12:51:38 2006
New Revision: 1203
Added:
trunk/Core/Util/RayTree.cc
trunk/Core/Util/RayTree.h
trunk/Engine/Renderers/Raydumper.cc
trunk/Engine/Renderers/Raydumper.h
Modified:
trunk/Core/CMakeLists.txt
trunk/Engine/Control/RTRT.cc
trunk/Engine/Control/RTRT.h
trunk/Engine/Factory/RegisterKnownComponents.cc
trunk/Engine/Renderers/CMakeLists.txt
trunk/Interface/MantaInterface.h
Log:
Second attmept at adding preliminary code to dump ray trees using Solomon's
PABST
format. Doesn't do quite what I'd like, but we should be getting all of the
rays
with some depth information, which should be good enough for my and Andrew's
purposes. Had to modify RTRT (added get/set functions for Renderer and
ShadowAlgorithm). Hopefully Abe won't kill me...
Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt (original)
+++ trunk/Core/CMakeLists.txt Wed Oct 4 12:51:38 2006
@@ -58,6 +58,8 @@
Util/Endian.h
Util/LargeFile.h
Util/LargeFile.cc
+ Util/RayTree.h
+ Util/RayTree.cc
Util/Stat.h
Util/ThreadStorage.h
Util/ThreadStorage.cc)
Added: trunk/Core/Util/RayTree.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Util/RayTree.cc Wed Oct 4 12:51:38 2006
@@ -0,0 +1,146 @@
+
+#include <Core/Util/RayTree.h>
+
+#include <cstdio>
+#include <cstdlib>
+
+using namespace Manta;
+
+// TODO: replace the fwrite, fread with EndianSafe versions
+
+RayForest::~RayForest()
+{
+ // printf("RayForest::~RayForest - deleting trees\n");
+ for (size_t i = 0; i < trees.size(); i++ )
+ delete trees[i];
+}
+
+void RayForest::addChild(RayTree* t)
+{
+ trees.push_back(t);
+}
+
+bool RayForest::writeToFile(FILE* output) const
+{
+ // printf("RayForest::writeToFile() -- %d Children\n", int(trees.size()));
+ // write out the number of trees then
+ // call writeToFile recursively
+ size_t num_trees = trees.size();
+ size_t result = fwrite((const void*)&num_trees, sizeof(size_t), (size_t)1,
output);
+ if (result != 1)
+ {
+ return false;
+ }
+
+ for (size_t i = 0; i < num_trees; i++ )
+ {
+ // printf("RayForest::writeToFile() -- Writing Tree #%d\n", int(i));
+ if (!trees[i]->writeToFile(output))
+ return false;
+ }
+ return true;
+}
+
+bool RayForest::readFromFile(FILE* input)
+{
+ size_t num_trees = 0;
+ size_t result = fread((void*)&num_trees, sizeof(size_t), (size_t)1, input);
+ if (result != 1)
+ return false;
+
+ trees.resize(num_trees);
+ for (size_t i = 0; i < num_trees; i++ )
+ {
+ trees[i] = new RayTree;
+ if (!trees[i]->readFromFile(input))
+ return false;
+ }
+ return true;
+}
+
+RayTree::~RayTree()
+{
+ // printf("RayTree::~RayTree - deleting children\n");
+ for (size_t i = 0; i < children.size(); i++ )
+ delete children[i];
+}
+
+bool RayTree::writeToFile(FILE* output) const
+{
+ // printf("RayTree::writeToFile() -- %d Children\n", int(children.size()));
+ node.writeToFile(output);
+ // write out the number of children then
+ // call writeToFile recursively
+ size_t num_children = children.size();
+ size_t result = fwrite((const void*)&num_children, sizeof(size_t),
(size_t)1, output);
+ if (result != 1)
+ {
+ fprintf(stderr, "Failed to write number of children\n");
+ return false;
+ }
+
+ for (size_t i = 0; i < num_children; i++)
+ {
+ // printf("RayTree::writeToFile() -- Writing Child %d\n", int(i));
+ if (!children[i]->writeToFile(output))
+ return false;
+ }
+
+ return true;
+}
+
+bool RayTree::readFromFile(FILE* input)
+{
+ node.readFromFile(input);
+
+ size_t num_children = 0;
+ size_t result = fread((void*)&num_children, sizeof(size_t), (size_t)1,
input);
+ if (result != 1)
+ {
+ fprintf(stderr, "Failed to read number of children\n");
+ return false;
+ }
+
+ children.resize(num_children);
+
+ for (size_t i = 0; i < num_children; i++ )
+ {
+ children[i] = new RayTree;
+ if (!children[i]->readFromFile(input))
+ return false;
+ }
+ return true;
+}
+
+void RayTree::addChild(RayTree* t)
+{
+ children.push_back(t);
+}
+
+bool RayInfo::writeToFile(FILE* output) const
+{
+ // printf("RayInfo::writeToFile() -- Writing 4 Byte Values\n");
+ size_t result = fwrite((const void*)origin, (size_t)4,
(size_t)RayInfo::Num4Byte, output);
+ if (result != Num4Byte)
+ return false;
+
+ // printf("RayInfo::writeToFile() -- Writing %d Byte Values\n",
int(sizeof(long long int)));
+ result = fwrite((const void*)&ray_id, (size_t)8,
(size_t)RayInfo::Num8Byte, output);
+ if (result != Num8Byte)
+ return false;
+
+ return true;
+}
+
+bool RayInfo::readFromFile(FILE* input)
+{
+ size_t result = fread((void*)origin, (size_t)4, (size_t)RayInfo::Num4Byte,
input);
+ if (result != Num4Byte)
+ return false;
+
+ result = fread((void*)&ray_id, sizeof(long long int),
(size_t)RayInfo::Num8Byte, input);
+ if (result != Num8Byte)
+ return false;
+
+ return true;
+}
Added: trunk/Core/Util/RayTree.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/RayTree.h Wed Oct 4 12:51:38 2006
@@ -0,0 +1,133 @@
+
+#ifndef Manta_Core_RayTree_h
+#define Manta_Core_RayTree_h
+
+#include <cstdio>
+#include <vector>
+
+namespace Manta {
+ class RayInfo {
+ public:
+ RayInfo(){}
+
+ enum RayType {
+ PrimaryRay = 0,
+ ShadowRay,
+ ReflectionRay,
+ RefractionRay,
+ DiffuseRay,
+ UnknownRay
+ };
+
+ // 4 byte entries
+ float origin[3]; // ray origin
+ float direction[3]; // ray direction
+ float time; // motion blur time [0,1)
+ float HitParameter; // ray t_value at hitpoint
+ int object_id; // object you hit, -1 for background
+ int material_id; // material of object, -1 for background
+ float s,t; // surface parameterization
+ // normal? ONB?
+ int depth; // bounce depth for reconstructing trees
+ RayType type;
+
+ // 8 byte entries
+ long long int ray_id; // unique ray identifier
+ long long int parent_id; // -1 for root
+
+ static const int Num4Byte = 14;
+ static const int Num8Byte = 2;
+
+ bool writeToFile(FILE* output) const;
+ bool readFromFile(FILE* input);
+
+ void setOrigin(float x, float y, float z)
+ {
+ origin[0] = x;
+ origin[1] = y;
+ origin[2] = z;
+ }
+
+ void setDirection(float x, float y, float z)
+ {
+ direction[0] = x;
+ direction[1] = y;
+ direction[2] = z;
+ }
+
+ void setTime(float t)
+ {
+ time = t;
+ }
+
+ void setHit(float t)
+ {
+ HitParameter = t;
+ }
+
+ void setObjectID(int i)
+ {
+ object_id = i;
+ }
+
+ void setMaterialID(int i)
+ {
+ material_id = i;
+ }
+
+ void setSurfaceParams(float u, float v)
+ {
+ s = u;
+ t = v;
+ }
+
+ void setDepth(int d)
+ {
+ depth = d;
+ }
+
+ void setType(RayType t)
+ {
+ type = t;
+ }
+
+ void setRayID(long long int id)
+ {
+ ray_id = id;
+ }
+
+ void setParentID(long long int id)
+ {
+ parent_id = id;
+ }
+ };
+
+ class RayTree {
+ public:
+ RayTree() {}
+ RayTree(const RayInfo& r) : node(r) {}
+ ~RayTree();
+
+ void addChild(RayTree* t);
+ bool writeToFile(FILE* output) const;
+ bool readFromFile(FILE* input);
+
+ RayInfo node;
+ std::vector<RayTree*> children;
+ };
+
+ // a forest is a collection of Trees ;)
+ class RayForest {
+ public:
+ RayForest() {}
+ ~RayForest();
+
+ void addChild(RayTree* t);
+ bool writeToFile(FILE* output=0) const;
+ bool readFromFile(FILE* input=0);
+
+ std::vector<RayTree*> trees;
+ };
+}
+
+#endif // Manta_Core_RayTree_h
Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc (original)
+++ trunk/Engine/Control/RTRT.cc Wed Oct 4 12:51:38 2006
@@ -1180,6 +1180,11 @@
currentRenderer = renderer_;
}
+Renderer* RTRT::getRenderer(void)
+{
+ return currentRenderer;
+}
+
bool RTRT::selectRenderer(const string& spec)
{
string name;
@@ -1236,6 +1241,16 @@
iter != idleModes.end(); iter++)
list.push_back(iter->first);
return list;
+}
+
+void RTRT::setShadowAlgorithm(ShadowAlgorithm* shadows)
+{
+ currentShadowAlgorithm = shadows;
+}
+
+ShadowAlgorithm* RTRT::getShadowAlgorithm(void)
+{
+ return currentShadowAlgorithm;
}
bool RTRT::selectShadowAlgorithm(const string& spec)
Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Wed Oct 4 12:51:38 2006
@@ -74,11 +74,14 @@
// Renderers
virtual void setRenderer( Renderer *renderer_ );
+ virtual Renderer* getRenderer();
virtual bool selectRenderer(const string& spec);
virtual void registerComponent(const string& name, RendererCreator
creator);
virtual listType listRenderers() const;
// Shadow Algorithms
+ virtual void setShadowAlgorithm(ShadowAlgorithm* shadows);
+ virtual ShadowAlgorithm* getShadowAlgorithm();
virtual bool selectShadowAlgorithm(const string& spec);
virtual void registerComponent(const string& name,
ShadowAlgorithmCreator creator);
virtual listType listShadowAlgorithms() const;
Modified: trunk/Engine/Factory/RegisterKnownComponents.cc
==============================================================================
--- trunk/Engine/Factory/RegisterKnownComponents.cc (original)
+++ trunk/Engine/Factory/RegisterKnownComponents.cc Wed Oct 4 12:51:38
2006
@@ -19,6 +19,7 @@
#include <Engine/PixelSamplers/JitterSampler.h>
#include <Engine/Renderers/Moire.h>
#include <Engine/Renderers/NullRenderer.h>
+#include <Engine/Renderers/Raydumper.h>
#include <Engine/Renderers/RayGen.h>
#include <Engine/Renderers/Raytracer.h>
#include <Engine/Shadows/BeamShadows.h>
@@ -84,6 +85,7 @@
engine->registerComponent("raygen", &RayGen::create);
engine->registerComponent("moire", &Moire::create);
engine->registerComponent("raytracer", &Raytracer::create);
+ engine->registerComponent("raydumper", &Raydumper::create);
// Register cameras
//engine->registerComponent("environment", &EnvironmentCamera::create);
Modified: trunk/Engine/Renderers/CMakeLists.txt
==============================================================================
--- trunk/Engine/Renderers/CMakeLists.txt (original)
+++ trunk/Engine/Renderers/CMakeLists.txt Wed Oct 4 12:51:38 2006
@@ -4,6 +4,8 @@
Renderers/Moire.cc
Renderers/NullRenderer.h
Renderers/NullRenderer.cc
+ Renderers/Raydumper.h
+ Renderers/Raydumper.cc
Renderers/RayGen.h
Renderers/RayGen.cc
Renderers/Raytracer.h
Added: trunk/Engine/Renderers/Raydumper.cc
==============================================================================
--- (empty file)
+++ trunk/Engine/Renderers/Raydumper.cc Wed Oct 4 12:51:38 2006
@@ -0,0 +1,158 @@
+
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Exceptions/IllegalValue.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/OutputError.h>
+#include <Core/Util/Args.h>
+#include <Engine/Renderers/Raydumper.h>
+#include <Interface/Context.h>
+
+using namespace Manta;
+using namespace SCIRun;
+
+// TODO: Allow multi-threaded rendering
+// Construct actual ray trees
+
+Renderer* Raydumper::create(const vector<string>& args)
+{
+ return new Raydumper(args);
+}
+
+Raydumper::Raydumper(const vector<string>& args) :
+ renderer_string("raytracer"), shadow_string("hard"), ray_id(0)
+{
+ // Parse arguments
+ string fname = "raydump.out";
+ int argc = static_cast<int>(args.size());
+ for(int i=0; i< argc; i++){
+ string arg = args[i];
+ if (arg == "-fname") {
+ if (!getArg(i, args, fname))
+ throw IllegalArgument("Raydumper -fname", i, args);
+ } else if (arg == "-renderer") {
+ if (!getArg(i, args, renderer_string))
+ throw IllegalArgument("Raydumper -renderer", i, args);
+ } else if (arg == "-shadows") {
+ if (!getArg(i, args, shadow_string))
+ throw IllegalArgument("Raydumper -shadows", i, args);
+ } else {
+ throw IllegalArgument("Raydumper", i, args);
+ cerr<<"Valid options are:\n";
+ cerr<<" -fname <string> output ray trees to specified file\n";
+ cerr<<" -renderer <string> use specified renderer\n";
+ cerr<<" -shadows <string> use specified shadow algorithm\n";
+ }
+ }
+
+ // Open output file
+ fp = fopen(fname.c_str(), "wb");
+ if (!fp)
+ throw OutputError("Failed to open \"" + fname + "\" for writing");
+ cerr<<"Writing ray trees to \""<<fname<<"\"\n";
+}
+
+Raydumper::~Raydumper()
+{
+ delete renderer;
+ delete shadows;
+}
+
+void Raydumper::setupBegin(const SetupContext& context, int integer)
+{
+ rtrt = context.rtrt_int;
+
+ // Force single-threaded rendering
+ if (rtrt->numWorkers() > 1)
+ throw IllegalValue<int>("Raydumper does not yet support multi-threaded
rendering",
+ rtrt->numWorkers());
+
+ // Hi-jack RTRT's Renderer
+ if (!rtrt->selectRenderer(renderer_string))
+ throw InternalError("renderer not found", __FILE__, __LINE__ );
+ renderer = rtrt->getRenderer();
+ rtrt->setRenderer(this);
+
+ // Hi-jack RTRT's ShadowAlgorithm
+ if (!rtrt->selectShadowAlgorithm(shadow_string))
+ throw InternalError("shadow algorithm not found", __FILE__, __LINE__ );
+ shadows = rtrt->getShadowAlgorithm();
+ rtrt->setShadowAlgorithm(this);
+
+ // Quit after rendering a single frame
+ rtrt->addOneShotCallback(MantaInterface::Absolute, 1,
+ Callback::create(this, &Raydumper::quit));
+
+ // Continue with setup
+ renderer->setupBegin(context, integer);
+}
+
+void Raydumper::setupDisplayChannel(SetupContext& context)
+{
+ renderer->setupDisplayChannel(context);
+}
+
+void Raydumper::setupFrame(const RenderContext& context)
+{
+ renderer->setupFrame(context);
+}
+
+void Raydumper::traceEyeRays(const RenderContext& context, RayPacket& rays)
+{
+ renderer->traceEyeRays(context, rays);
+ logRays(rays, RayInfo::PrimaryRay);
+}
+
+void Raydumper::traceRays(const RenderContext& context, RayPacket& rays)
+{
+ renderer->traceRays(context, rays);
+ logRays(rays, RayInfo::UnknownRay);
+}
+
+bool Raydumper::computeShadows(const RenderContext& context,
+ const LightSet* lights,
+ RayPacket& sourceRays,
+ RayPacket& shadowRays,
+ bool firstTime,
+ StateBuffer& stateBuffer)
+{
+ shadows->computeShadows(context, lights, sourceRays, shadowRays, firstTime,
+ stateBuffer);
+ logRays(shadowRays, RayInfo::ShadowRay);
+}
+
+string Raydumper::getName() const
+{
+ return shadows->getName();
+}
+
+string Raydumper::getSpecs() const
+{
+ return shadows->getSpecs();
+}
+
+void Raydumper::logRays(const RayPacket& rays, RayInfo::RayType type)
+{
+ int depth=rays.getDepth();
+ for (int i = rays.begin(); i < rays.end(); ++i) {
+ Vector o = rays.getOrigin(i);
+ Vector d = rays.getDirection(i);
+
+ RayInfo ray;
+ ray.setRayID(ray_id++);
+ // ray.setParentID(parent_id);
+ ray.setDepth(depth);
+ ray.setType(type);
+ ray.setOrigin(o.x(), o.y(), o.z());
+ ray.setDirection(d.x(), d.y(), d.z());
+
+ forest.addChild(new RayTree(ray));
+ }
+}
+
+void Raydumper::quit(int, int)
+{
+ forest.writeToFile(fp);
+ fclose(fp);
+
+ rtrt->finish();
+}
Added: trunk/Engine/Renderers/Raydumper.h
==============================================================================
--- (empty file)
+++ trunk/Engine/Renderers/Raydumper.h Wed Oct 4 12:51:38 2006
@@ -0,0 +1,62 @@
+
+#ifndef Manta_Engine_Raydumper_h
+#define Manta_Engine_Raydumper_h
+
+#include <Core/Util/RayTree.h>
+#include <Interface/MantaInterface.h>
+#include <Interface/RayPacket.h>
+#include <Interface/Renderer.h>
+#include <Interface/ShadowAlgorithm.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
+namespace Manta {
+ using namespace std;
+
+ class Raydumper : public Renderer, public ShadowAlgorithm {
+ public:
+ Raydumper(const vector<string>& args);
+ virtual ~Raydumper();
+
+ // Renderer
+ virtual void setupBegin(const SetupContext&, int numChannels);
+ virtual void setupDisplayChannel(SetupContext&);
+ virtual void setupFrame(const RenderContext& context);
+
+ virtual void traceEyeRays(const RenderContext&, RayPacket& rays);
+ virtual void traceRays(const RenderContext&, RayPacket& rays);
+
+ static Renderer* create(const vector<string>& args);
+
+ // Shadow algorithm
+ virtual bool computeShadows(const RenderContext& context,
+ const LightSet* lights, RayPacket& source,
+ RayPacket& shadowRays, bool firstTime,
+ StateBuffer& stateBuffer);
+
+ string getName() const;
+ string getSpecs() const;
+
+ private:
+ Raydumper(const Raydumper&);
+ Raydumper& operator=(const Raydumper&);
+
+ void logRays(const RayPacket& rays, RayInfo::RayType type);
+ void quit(int, int);
+
+ string renderer_string;
+ string shadow_string;
+
+ MantaInterface* rtrt;
+ Renderer* renderer;
+ ShadowAlgorithm* shadows;
+
+ RayForest forest;
+ unsigned long long ray_id;
+ FILE* fp;
+ };
+}
+
+#endif
Modified: trunk/Interface/MantaInterface.h
==============================================================================
--- trunk/Interface/MantaInterface.h (original)
+++ trunk/Interface/MantaInterface.h Wed Oct 4 12:51:38 2006
@@ -92,12 +92,15 @@
// Renderers
typedef Renderer* (*RendererCreator)(const vector<string>& args);
virtual void setRenderer( Renderer *renderer_ ) = 0;
+ virtual Renderer* getRenderer(void) = 0;
virtual bool selectRenderer(const string& spec) = 0;
virtual void registerComponent(const string& name, RendererCreator
creator) = 0;
virtual listType listRenderers() const = 0;
// Shadow Algorithms
typedef ShadowAlgorithm* (*ShadowAlgorithmCreator)(const vector<string>&
args);
+ virtual void setShadowAlgorithm(ShadowAlgorithm* shadows) = 0;
+ virtual ShadowAlgorithm* getShadowAlgorithm(void) = 0;
virtual bool selectShadowAlgorithm(const string& spec) = 0;
virtual void registerComponent(const string& name,
ShadowAlgorithmCreator creator) = 0;
virtual listType listShadowAlgorithms() const = 0;
- [MANTA] r1203 - in trunk: Core Core/Util Engine/Control Engine/Factory Engine/Renderers Interface, cgribble, 10/04/2006
Archive powered by MHonArc 2.6.16.