Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r336 - in branches/itanium2: Core/Geometry Interface Model Model/Intersections Model/Materials Model/Primitives
- Date: Mon, 23 May 2005 17:51:28 -0600 (MDT)
Author: abe
Date: Mon May 23 17:51:21 2005
New Revision: 336
Added:
branches/itanium2/Model/Materials/NormalMaterial.cc
branches/itanium2/Model/Materials/NormalMaterial.h
Removed:
branches/itanium2/Model/Intersections/AxisAlignedBox.cc~
branches/itanium2/Model/Intersections/AxisAlignedBox.h~
Modified:
branches/itanium2/Core/Geometry/BBox.h
branches/itanium2/Core/Geometry/PointVector.h
branches/itanium2/Interface/HitInfo.h
branches/itanium2/Interface/RayPacket.h
branches/itanium2/Model/CMakeLists.txt
branches/itanium2/Model/Materials/CMakeLists.txt
branches/itanium2/Model/Primitives/Cube.cc
branches/itanium2/Model/Primitives/Cube.h
Log:
other changes associated with bbox.
Modified: branches/itanium2/Core/Geometry/BBox.h
==============================================================================
--- branches/itanium2/Core/Geometry/BBox.h (original)
+++ branches/itanium2/Core/Geometry/BBox.h Mon May 23 17:51:21 2005
@@ -2,55 +2,61 @@
#ifndef Manta_Core_BBox_h
#define Manta_Core_BBox_h
+#include <SCIRun/Core/Math/MiscMath.h>
+
namespace Manta {
class BBox {
public:
- BBox(const Point& min, const Point& max)
- : min(min), max(max) {
- }
- BBox() {
- }
- ~BBox() {
+ BBox(const Point& min_, const Point& max_ ) {
+ bounds[0] = min_;
+ bounds[1] = max_;
}
+ BBox() { }
+ ~BBox() { }
Vector diagonal() const {
- return max-min;
+ return bounds[1] - bounds[0];
}
Point center() const {
- return Interpolate(min, max, 0.5);
+ // return SCIRun::Interpolate(bounds[0], bounds[1],
(Point::ScalarType)0.5);
+ return Point(Vector(bounds[1]-bounds[0])*0.5);
}
void extendByPoint(const Point& p) {
- min = Min(min, p);
- max = Max(max, p);
+ bounds[0] = Min(bounds[0], p);
+ bounds[1] = Max(bounds[1], p);
}
void extendBySphere(const Point& p, Real radius) {
- min = Min(min, p-Vector(radius, radius, radius));
- max = Max(max, p+Vector(radius, radius, radius));
+ bounds[0] = Min(bounds[0], p-Vector(radius, radius, radius));
+ bounds[1] = Max(bounds[1], p+Vector(radius, radius, radius));
}
void extendByDisc(const Point& p, const Vector& n, Real radius) {
Vector v(sqrt(1-p.x()*p.x()), sqrt(1-p.y()*p.y()),
sqrt(1-p.z()*p.z()));
- min = Min(min, p-v*radius);
- max = Max(max, p+v*radius);
+ bounds[0] = Min(bounds[0], p-v*radius);
+ bounds[1] = Max(bounds[1], p+v*radius);
}
const Point& getMin() const {
- return min;
+ return bounds[0];
}
const Point& getMax() const {
- return max;
+ return bounds[1];
}
Point getCorner(int i) const {
- return Point(i&4?min.x():max.x(),
- i&2?min.y():max.y(),
- i&1?min.z():max.z());
+ return Point(i&4?bounds[0].x():bounds[1].x(),
+ i&2?bounds[0].y():bounds[1].y(),
+ i&1?bounds[0].z():bounds[1].z());
}
+
+ inline Point &operator[] (int i) { return bounds[i]; }
+ inline const Point &operator[] (int i) const { return bounds[i]; }
+
private:
BBox(const BBox&);
BBox& operator=(const BBox&);
- Point min, max;
+ Point bounds[2];
};
}
Modified: branches/itanium2/Core/Geometry/PointVector.h
==============================================================================
--- branches/itanium2/Core/Geometry/PointVector.h (original)
+++ branches/itanium2/Core/Geometry/PointVector.h Mon May 23 17:51:21
2005
@@ -13,6 +13,8 @@
template<typename T, int Dim>
class VectorT {
public:
+ typedef T ScalarType;
+
VectorT() {
}
VectorT(T x, T y) {
@@ -218,6 +220,8 @@
template<typename T, int Dim>
class PointT {
public:
+ typedef T ScalarType;
+
PointT() {
}
Modified: branches/itanium2/Interface/HitInfo.h
==============================================================================
--- branches/itanium2/Interface/HitInfo.h (original)
+++ branches/itanium2/Interface/HitInfo.h Mon May 23 17:51:21 2005
@@ -75,7 +75,7 @@
const TexCoordMapper* hitTexCoordMapper() const {
return hitTex;
}
- double minT() const {
+ Real minT() const {
return min_t;
}
void scaleT(double scale) {
@@ -89,13 +89,13 @@
bool hit(double t, const Material* matl, const Primitive* prim,
const TexCoordMapper* tex) {
if(t<T_EPSILON)
- return false;
+ return false;
if(t < min_t){
- min_t=t;
- hitMatl = matl;
- hitPrim = prim;
- hitTex = tex;
- return true;
+ min_t=t;
+ hitMatl = matl;
+ hitPrim = prim;
+ hitTex = tex;
+ return true;
} else {
return false;
}
@@ -126,7 +126,7 @@
const Primitive* hitPrim;
const Material* hitMatl;
const TexCoordMapper* hitTex;
- double min_t;
+ Real min_t;
char scratchpad_data[MaxScratchpadSize];
};
}
Modified: branches/itanium2/Interface/RayPacket.h
==============================================================================
--- branches/itanium2/Interface/RayPacket.h (original)
+++ branches/itanium2/Interface/RayPacket.h Mon May 23 17:51:21 2005
@@ -13,26 +13,30 @@
class RenderContext;
class RayPacket {
public:
- static const int MaxSize = 32;
+ enum {
+ MaxSize = 32,
- static const int ConstantOrigin = 0x01;
- static const int ConstantEye = 0x02;
- static const int HaveImageCoordinates = 0x04;
- static const int NormalizedDirections = 0x08;
- static const int HaveHitPositions = 0x10;
- static const int HaveHitRecords = 0x20;
- static const int HaveTexture3 = 0x40;
- static const int HaveTexture2 = 0x80;
- //static const int HaveFrame = 0x100;
- static const int HaveNormals = 0x200;
- static const int HaveUnitNormals = 0x300;
- static const int HaveInverseDirections = 0x800;
- inline RayPacket(RayPacketData& data, int size, int depth, int flags);
+ // Flags.
+ ConstantOrigin = 0x001,
+ ConstantEye = 0x002,
+ HaveImageCoordinates = 0x004,
+ NormalizedDirections = 0x008,
+ HaveHitPositions = 0x010,
+ HaveHitRecords = 0x020,
+ HaveTexture3 = 0x040,
+ HaveTexture2 = 0x080,
+ // HaveFrame = 0x100,
+ HaveNormals = 0x200,
+ HaveUnitNormals = 0x300,
+ HaveInverseDirections = 0x800 };
+
+ inline RayPacket(RayPacketData& data, int size, int depth, int flags);
+
// Create a subset of another raypacket
RayPacket(RayPacket& parent, int start, int end)
: data(parent.data+start), size(end-start), depth(parent.depth),
- flags(parent.flags)
+ flags(parent.flags)
{
}
@@ -54,7 +58,7 @@
}
void resetHit() {
for(int i=0;i<size;i++)
- data[i].hitInfo.reset();
+ data[i].hitInfo.reset();
flags |= HaveHitRecords;
}
@@ -64,21 +68,23 @@
}
struct Element {
- Color localColor;
- Color* color;
- double imageX;
- double imageY;
- int whichEye;
- Ray ray;
+ Color localColor;
+ Color* color;
+ double imageX;
+ double imageY;
+ Ray ray;
HitInfo hitInfo;
- Vector normal;
- Point hitPosition;
- Point texCoords;
- Vector inverseDirection;
+ Vector normal;
+ Point hitPosition;
+ Point texCoords;
+ Vector inverseDirection;
+
+ Color ambientLight;
+ Color light;
- Color ambientLight;
int shadowBegin, shadowEnd;
- Color light;
+ int whichEye;
+ int sign_mask[3]; // This is set at the same time as inverse direction.
};
const Element& get(int which) const {
@@ -110,15 +116,16 @@
void normalizeDirections()
{
if(flags & NormalizedDirections)
- return;
+ return;
+
if(flags & HaveHitRecords){
- for(int i=0;i<size;i++){
- double length = data[i].ray.normalizeDirection();
- data[i].hitInfo.scaleT(length);
- }
+ for(int i=0;i<size;i++){
+ double length = data[i].ray.normalizeDirection();
+ data[i].hitInfo.scaleT(length);
+ }
} else {
- for(int i=0;i<size;i++)
- data[i].ray.normalizeDirection();
+ for(int i=0;i<size;i++)
+ data[i].ray.normalizeDirection();
}
flags |= NormalizedDirections;
flags &= ~HaveInverseDirections;
@@ -126,25 +133,31 @@
void computeHitPositions()
{
if(flags & HaveHitPositions)
- return;
+ return;
for(int i=0;i<size;i++)
- data[i].hitPosition = data[i].ray.origin() + data[i].ray.direction()
* data[i].hitInfo.minT();
+ data[i].hitPosition = data[i].ray.origin() + data[i].ray.direction()
* data[i].hitInfo.minT();
flags |= HaveHitPositions;
}
void computeInverseDirections()
{
if(flags & HaveInverseDirections)
- return;
- for(int i=0;i<size;i++)
- data[i].inverseDirection = Vector(1./data[i].ray.direction().x(),
+ return;
+ for(int i=0;i<size;i++) {
+ data[i].inverseDirection = Vector(1./data[i].ray.direction().x(),
1./data[i].ray.direction().y(),
1./data[i].ray.direction().z());
+
+ // Set the sign mask at the same time.
+ data[i].sign_mask[0] = (data[i].inverseDirection[0] < 0.0);
+ data[i].sign_mask[1] = (data[i].inverseDirection[1] < 0.0);
+ data[i].sign_mask[2] = (data[i].inverseDirection[2] < 0.0);
+ }
flags |= HaveInverseDirections;
}
void computeTextureCoordinates2(const RenderContext& context)
{
if(flags & (HaveTexture2|HaveTexture3))
- return;
+ return;
Element& e0 = data[0];
const TexCoordMapper* tex = e0.hitInfo.hitTexCoordMapper();
tex->computeTexCoords2(context, *this);
@@ -153,7 +166,7 @@
void computeTextureCoordinates3(const RenderContext& context)
{
if(flags & HaveTexture3)
- return;
+ return;
Element& e0 = data[0];
const TexCoordMapper* tex = e0.hitInfo.hitTexCoordMapper();
tex->computeTexCoords3(context, *this);
@@ -174,18 +187,29 @@
void computeNormals(const RenderContext& context)
{
if(flags & HaveNormals)
- return;
+ return;
+
+ int end;
+ int i = 0;
+
// Compute normals
- for(int i=0;i<size;){
- RayPacket::Element& e = data[i];
- const Primitive* prim = e.hitInfo.hitPrimitive();
- int end = i+1;
- while(end < size && data[end].hitInfo.hitPrimitive() == prim)
- end++;
- RayPacket subPacket(*this, i, end);
- prim->computeNormal(context, subPacket);
- i=end;
+ while (i<size) {
+
+ RayPacket::Element& e = data[i];
+ const Primitive* prim = e.hitInfo.hitPrimitive();
+
+ end = i+1;
+
+ while(end < size && data[end].hitInfo.hitPrimitive() == prim)
+ end++;
+
+ RayPacket subPacket(*this, i, end);
+ prim->computeNormal(context, subPacket);
+
+
+ i=end;
}
+
flags |= HaveNormals;
}
Modified: branches/itanium2/Model/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/CMakeLists.txt (original)
+++ branches/itanium2/Model/CMakeLists.txt Mon May 23 17:51:21 2005
@@ -10,6 +10,7 @@
INCLUDE (Instances/CMakeLists.txt)
INCLUDE (MiscObjects/CMakeLists.txt)
INCLUDE (Readers/CMakeLists.txt)
+INCLUDE (Intersections/CMakeLists.txt)
SET(BUILD_SCALAR_VOLUME CACHE BOOL false)
IF(BUILD_SCALAR_VOLUME)
@@ -24,11 +25,12 @@
${Manta_Lights_SRCS}
${Manta_Materials_SRCS}
${Manta_Primitives_SRCS}
- ${Manta_Primitives_Volume_SRCS}
+ ${Manta_Primitives_Volume_SRCS}
${Manta_TexCoordMappers_SRCS}
${Manta_Instances_SRCS}
${Manta_MiscObjects_SRCS}
- ${Manta_Readers_SRCS}
+ ${Manta_Readers_SRCS}
+ ${Manta_Intersections_SRCS}
)
TARGET_LINK_LIBRARIES(Manta_Model Manta_Interface Manta_Core)
Modified: branches/itanium2/Model/Materials/CMakeLists.txt
==============================================================================
--- branches/itanium2/Model/Materials/CMakeLists.txt (original)
+++ branches/itanium2/Model/Materials/CMakeLists.txt Mon May 23 17:51:21
2005
@@ -9,4 +9,5 @@
Materials/LitMaterial.cc
Materials/MetalMaterial.cc
Materials/Phong.cc
+ Materials/NormalMaterial.cc # Shade the material using it's normal.
)
Added: branches/itanium2/Model/Materials/NormalMaterial.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Model/Materials/NormalMaterial.cc Mon May 23 17:51:21
2005
@@ -0,0 +1,24 @@
+
+#include <Model/Materials/NormalMaterial.h>
+#include <Interface/RayPacket.h>
+
+using namespace Manta;
+
+void NormalMaterial::shade( const RenderContext &context, RayPacket &rays)
const {
+
+ // Compute the normal for each ray.
+ rays.computeNormals( context );
+
+ // Iterate over the packet and set the colors.
+ for (int i=0;i<rays.getSize();++i) {
+
+ Vector normal = rays.get(i).normal;
+
+ RGBColor rgb( normal[0]*0.5 + 0.5,
+
normal[1]*0.5 + 0.5,
+
normal[2]*0.5 + 0.5 );
+
+ rays.setResult( i, Color(rgb) );
+ }
+}
+
Added: branches/itanium2/Model/Materials/NormalMaterial.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Model/Materials/NormalMaterial.h Mon May 23 17:51:21
2005
@@ -0,0 +1,18 @@
+
+#ifndef Manta_Model_NormalMaterial_h
+#define Manta_Model_NormalMaterial_h
+
+#include <Model/Materials/LitMaterial.h>
+#include <Core/Color/Color.h>
+#include <Interface/Texture.h>
+
+namespace Manta {
+ class NormalMaterial : public LitMaterial {
+public:
+ NormalMaterial() { };
+ ~NormalMaterial() { };
+ void shade( const RenderContext &context, RayPacket &rays) const;
+ };
+};
+
+#endif
\ No newline at end of file
Modified: branches/itanium2/Model/Primitives/Cube.cc
==============================================================================
--- branches/itanium2/Model/Primitives/Cube.cc (original)
+++ branches/itanium2/Model/Primitives/Cube.cc Mon May 23 17:51:21 2005
@@ -4,30 +4,73 @@
#include <Core/Math/MiscMath.h>
#include <Core/Math/MinMax.h>
+#include <Model/Intersections/AxisAlignedBox.h>
+
using namespace Manta;
using namespace std;
using SCIRun::Abs;
Cube::Cube(Material* mat, const Point& anch, double w, double h, double d)
- : PrimitiveCommon(mat), anchor(anch), w(w), h(h), d(d)
+ : PrimitiveCommon(mat)
{
+
+ bbox[0] = anch;
+ bbox[1] = anch + Vector(w,h,d);
+#if 0
xmin = anchor.x(); xmax = xmin + w;
ymin = anchor.y(); ymax = ymin + h;
zmin = anchor.z(); zmax = zmin + d;
+#endif
}
Cube::~Cube()
{
}
-void Cube::computeBounds(const PreprocessContext&, BBox& bbox) const
+void Cube::computeBounds(const PreprocessContext&, BBox& bbox_) const
{
- bbox.extendByPoint(Point(xmin, ymin, zmin));
- bbox.extendByPoint(Point(xmax, ymax, zmax));
+ // bbox.extendByPoint(Point(xmin, ymin, zmin));
+ // bbox.extendByPoint(Point(xmax, ymax, zmax));
+ bbox_.extendByPoint( bbox[0] );
+ bbox_.extendByPoint( bbox[1] );
}
void Cube::intersect(const RenderContext&, RayPacket& rays) const
-{
+{
+
+ // Intersection algorithm requires inverse directions computed.
+ rays.computeInverseDirections();
+
+ // Iterate over each ray.
+ for (int i=0;i<rays.getSize();++i) {
+
+ RayPacket::Element &e = rays.get(i);
+
+ Real tmin, tmax;
+
+ // Check for an intersection.
+ if (Intersection::intersect_box( bbox,
+ tmin,
+ tmax,
+ e.ray,
+ e.sign_mask,
+ e.inverseDirection/*,
+
e.hitInfo.minT()*/)) {
+
+ // Check to see if we are inside the box.
+ if (tmin > 0.0) {
+ e.hitInfo.hit( tmin, material, this, tex );
+ }
+
+ // And use the max intersection if we are.
+ else
+ e.hitInfo.hit( tmax, material, this, tex );
+ }
+
+ }
+
+
+#if 0
using SCIRun::Max;
using SCIRun::Min;
rays.computeInverseDirections();
@@ -114,6 +157,8 @@
e.hitInfo.hit(tnear, material, this, tex);
}
}
+
+#endif
}
@@ -121,17 +166,24 @@
{
rays.computeHitPositions();
for(int i=0; i<rays.getSize(); i++) {
+
RayPacket::Element& e = rays.get(i);
- if (Abs(e.hitPosition.x() - xmin) < 0.0001)
+
+ if (Abs(e.hitPosition.x() - bbox[0][0]) < 0.0001)
e.normal = Vector(-1, 0, 0 );
- else if (Abs(e.hitPosition.x() - xmax) < 0.0001)
+
+ else if (Abs(e.hitPosition.x() - bbox[1][0]) < 0.0001)
e.normal = Vector( 1, 0, 0 );
- else if (Abs(e.hitPosition.y() - ymin) < 0.0001)
+
+ else if (Abs(e.hitPosition.y() - bbox[0][1]) < 0.0001)
e.normal = Vector( 0,-1, 0 );
- else if (Abs(e.hitPosition.y() - ymax) < 0.0001)
+
+ else if (Abs(e.hitPosition.y() - bbox[1][1]) < 0.0001)
e.normal = Vector( 0, 1, 0 );
- else if (Abs(e.hitPosition.z() - ymin) < 0.0001)
+
+ else if (Abs(e.hitPosition.z() - bbox[0][2]) < 0.0001)
e.normal = Vector( 0, 0,-1 );
+
else
e.normal = Vector( 0, 0, 1 );
}
Modified: branches/itanium2/Model/Primitives/Cube.h
==============================================================================
--- branches/itanium2/Model/Primitives/Cube.h (original)
+++ branches/itanium2/Model/Primitives/Cube.h Mon May 23 17:51:21 2005
@@ -4,6 +4,7 @@
#include <Model/Primitives/PrimitiveCommon.h>
#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/BBox.h>
namespace Manta
{
@@ -11,6 +12,8 @@
class Cube : public PrimitiveCommon {
public:
Cube(Material* mat, const Point& anch, double w, double h, double d);
+ Cube(Material *mat, const Point &min_, const Point &max_ ) :
+ PrimitiveCommon( mat ), bbox( min_, max_ ) { }
~Cube();
virtual void computeBounds(const PreprocessContext& context,
@@ -19,11 +22,14 @@
virtual void computeNormal(const RenderContext& context, RayPacket
&rays) const;
private:
+ BBox bbox;
+#if 0
Point anchor;
double w,h,d;
double xmin, xmax;
double ymin, ymax;
double zmin, zmax;
+#endif
};
}
- [MANTA] r336 - in branches/itanium2: Core/Geometry Interface Model Model/Intersections Model/Materials Model/Primitives, abe, 05/23/2005
Archive powered by MHonArc 2.6.16.