Text archives Help
- From: boulos@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r974 - in trunk: Model/Primitives scenes
- Date: Tue, 7 Mar 2006 02:04:25 -0700 (MST)
Author: boulos
Date: Tue Mar 7 02:04:25 2006
New Revision: 974
Added:
trunk/Model/Primitives/WaldTriangle.cc
trunk/Model/Primitives/WaldTriangle.h
Modified:
trunk/Model/Primitives/CMakeLists.txt
trunk/scenes/perf.cc
Log:
Committing a new WaldTriangle primitive based
on Ingo's thesis and the DynRT codebase. The
code currently doesn't work (committing to work
on my laptop).
Modified: trunk/Model/Primitives/CMakeLists.txt
==============================================================================
--- trunk/Model/Primitives/CMakeLists.txt (original)
+++ trunk/Model/Primitives/CMakeLists.txt Tue Mar 7 02:04:25 2006
@@ -37,5 +37,7 @@
Primitives/Triangle.h
Primitives/VertexColoredTriangle.cc
Primitives/VertexColoredTriangle.h
+ Primitives/WaldTriangle.h
+ Primitives/WaldTriangle.cc
)
Added: trunk/Model/Primitives/WaldTriangle.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/WaldTriangle.cc Tue Mar 7 02:04:25 2006
@@ -0,0 +1,65 @@
+#include <Model/Primitives/WaldTriangle.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/BBox.h>
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+using namespace Manta;
+using namespace std;
+
+WaldTriangle::WaldTriangle(Material* mat,
+ const Vector& _p1, const Vector& _p2, const
Vector& _p3) : PrimitiveCommon(mat)
+{
+ box.reset();
+ box.extendByPoint(_p1);
+ box.extendByPoint(_p2);
+ box.extendByPoint(_p3);
+
+ Vector normal = Cross(_p3-_p1, _p2-_p1);
+ normal.normalize();
+
+ unsigned int n, u, v;
+
+ n = 0;
+ if ( fabsf(normal[1]) > fabsf(normal[n]) ) n = 1;
+ if ( fabsf(normal[2]) > fabsf(normal[n]) ) n = 2;
+
+ switch ( n )
+ {
+ case 0: u = 1; v = 2; break;
+ case 1: u = 2; v = 0; break;
+ default: u = 0; v = 1; break;
+ };
+
+ // copy to struct
+ k = n;
+ n_u = normal[u] / normal[k];
+ n_v = normal[v] / normal[k];
+ n_d = _p1[u] * n_u + _p1[v] * n_v + _p1[k];
+
+ float s;
+
+ c_nu = + _p2[v] - _p1[v];
+ c_nv = - _p2[u] + _p1[u];
+ c_d = - _p1[u] * c_nu + _p1[v] * c_nv;
+
+ s = 1.f / ( _p3[u] * c_nu + _p3[v] * c_nv + c_d );
+
+ c_nu *= s;
+ c_nv *= s;
+ c_d *= s;
+
+ b_nu = + _p3[v] - _p1[v];
+ b_nv = - _p3[u] + _p1[u];
+ b_d = - _p1[u] * b_nu + _p1[v] * b_nv;
+
+ s = 1.f / ( _p2[u] * b_nu + _p2[v] * b_nv + b_d );
+
+ b_nu *= s;
+ b_nv *= s;
+ b_d *= s;
+
+ n_k = normal[k];
+ cout << "Finished triangle" << endl;
+}
Added: trunk/Model/Primitives/WaldTriangle.h
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/WaldTriangle.h Tue Mar 7 02:04:25 2006
@@ -0,0 +1,124 @@
+
+#ifndef Manta_Model_WaldTriangle_h
+#define Manta_Model_WaldTriangle_h
+
+#include <Model/Primitives/PrimitiveCommon.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/Vector.h>
+#include <Core/Geometry/Ray.h>
+#include <Core/Geometry/BBox.h>
+
+namespace Manta
+{
+ class WaldTriangle : public PrimitiveCommon {
+ public:
+
+ WaldTriangle() { };
+ WaldTriangle(Material* mat,
+ const Vector& _p1, const Vector& _p2, const Vector& _p3);
+
+ void computeBounds(const PreprocessContext& context,
+ BBox& bbox) const
+ {
+ bbox = box;
+ }
+
+ void intersect(const RenderContext& context, RayPacket& rays) const
+ {
+ const int axis = k;
+ const int ku = (k==2)?0:k+1;
+ const int kv = (k==0)?2:k-1;
+
+ // what qualifiers go here?
+ RayPacketData* data = rays.data;
+
+ const float* const dir_k = data->direction[axis];
+ const float* const dir_ku = data->direction[ku];
+ const float* const dir_kv = data->direction[kv];
+
+ float org_k, org_ku, org_kv, f0;
+
+ const int begin = rays.begin();
+ const int end = rays.end();
+ const bool RaysConstantOrigin = rays.getAllFlags() &
RayPacket::ConstantOrigin;
+
+ if (RaysConstantOrigin)
+ {
+ org_k = data->origin[axis][begin];
+ org_ku = data->origin[ku][begin];
+ org_kv = data->origin[kv][begin];
+ f0 = n_d - (org_k + n_u * org_ku + n_v * org_kv);
+ }
+
+ for (int i = begin; i < end; i++ )
+ {
+ const float nd0 = n_u * dir_ku[i] + n_v * dir_kv[i] + dir_k[i];
+ const float nd = 1.f/nd0;
+
+ if (!RaysConstantOrigin)
+ {
+ org_k = data->origin[axis][i];
+ org_ku = data->origin[ku][i];
+ org_kv = data->origin[kv][i];
+
+ f0 = n_d - (org_k + n_u * org_ku + n_v * org_kv);
+ }
+
+ const float f = f0 * nd;
+ // plane test
+ if ( f < T_EPSILON || f > data->minT[i] )
+ continue;
+
+ const float hu = org_ku + f*dir_ku[i];
+ const float hv = org_kv + f*dir_kv[i];
+ const float lambda = b_d + hu*b_nu + hv * b_nv;
+
+ // barycentric test
+ if ( lambda < 0.f )
+ continue;
+
+ const float mue = c_d + hu * c_nu + hv * c_nv;
+ if ( mue < 0.f || mue + lambda > 1.f )
+ continue;
+
+ rays.hit(i, f, getMaterial(), this, getTexCoordMapper());
+ }
+ }
+
+ void computeNormal(const RenderContext& context, RayPacket &rays) const
+ {
+ const int axis = k;
+ const int ku = (k==2)?0:k+1;
+ const int kv = (k==0)?2:k-1;
+
+ const float mult = n_k;
+ RayPacketData* data = rays.data;
+ for ( int ray = rays.begin(); ray < rays.end(); ray++ )
+ {
+ data->normal[axis][ray] = mult;
+ data->normal[ku][ray] = mult * n_u;
+ data->normal[kv][ray] = mult * n_v;
+ }
+
+ }
+
+
+ float n_u;
+ float n_v;
+ float n_d;
+ unsigned int k;
+
+ float b_nu;
+ float b_nv;
+ float b_d;
+ float n_k;
+
+ float c_nu;
+ float c_nv;
+ float c_d;
+
+ BBox box; // for bounds
+ };
+}
+
+#endif
Modified: trunk/scenes/perf.cc
==============================================================================
--- trunk/scenes/perf.cc (original)
+++ trunk/scenes/perf.cc Tue Mar 7 02:04:25 2006
@@ -44,6 +44,7 @@
#include <Model/Materials/Flat.h>
#include <Model/Primitives/Sphere.h>
#include <Model/Primitives/Triangle.h>
+#include <Model/Primitives/WaldTriangle.h>
#include <Model/Textures/CheckerTexture.h>
#include <Model/Textures/NormalTexture.h>
#include <Core/Geometry/AffineTransform.h>
@@ -71,8 +72,12 @@
// Add a simple sphere to the scene
world->add(new Sphere( matte_yellow, Vector(0, 0, 0), 1.0 ) );
- world->add(new Triangle(matte_blue,
Vector(-1,-1,-1),Vector(-1,-1,1),Vector(1,-1,1)));
- world->add(new Triangle(matte_blue,
Vector(1,-1,1),Vector(-1,-1,-1),Vector(1,-1,-1)));
+
+ //world->add(new Triangle(matte_blue,
Vector(-1,-1,-1),Vector(-1,-1,1),Vector(1,-1,1)));
+ //world->add(new Triangle(matte_blue,
Vector(1,-1,1),Vector(-1,-1,-1),Vector(1,-1,-1)));
+
+ world->add(new WaldTriangle(matte_blue,
Vector(-1,-1,-1),Vector(-1,-1,1),Vector(1,-1,1)));
+ world->add(new WaldTriangle(matte_blue,
Vector(1,-1,1),Vector(-1,-1,-1),Vector(1,-1,-1)));
Scene* scene = new Scene();
scene->setBackground(new
ConstantBackground(ColorDB::getNamedColor("SkyBlue3")));
scene->setObject(world);
- [MANTA] r974 - in trunk: Model/Primitives scenes, boulos, 03/07/2006
Archive powered by MHonArc 2.6.16.