Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r866 - trunk/Model/Textures
- Date: Tue, 24 Jan 2006 19:56:08 -0700 (MST)
Author: abe
Date: Tue Jan 24 19:56:08 2006
New Revision: 866
Added:
trunk/Model/Textures/NormalTexture.cc
trunk/Model/Textures/NormalTexture.h
Log:
Whoops, forgot to add those new textures to svn
Added: trunk/Model/Textures/NormalTexture.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/NormalTexture.cc Tue Jan 24 19:56:08 2006
@@ -0,0 +1,178 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ 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 <Model/Textures/NormalTexture.h>
+
+#include <Interface/RayPacket.h>
+
+#include <Core/Color/Color.h>
+
+#include <Model/Primitives/HeavyTriangle.h>
+#include <Model/Groups/KDTree.h>
+#include <Model/Textures/Constant.h>
+
+using namespace Manta;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// NORMAL NORMAL NORMAL NORMAL NORMAL NORMAL NORMAL NORMAL NORMAL
NORM
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void NormalTexture::mapValues(const RenderContext&context, RayPacket& rays,
Color results[]) const {
+
+ // Compute the normal for each ray.
+ rays.computeNormals( context );
+
+ // Iterate over the packet and set the colors.
+ for (int i=rays.begin();i<rays.end();++i) {
+
+ // Copy the normal out.
+ Vector normal = rays.getNormal(i);
+
+ normal = (normal *(Real)0.5) + Vector( 0.5, 0.5, 0.5 );
+
+ results[i] = Color( RGB( (ColorComponent)normal[0],
+ (ColorComponent)normal[1],
+ (ColorComponent)normal[2] ));
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// RAY SIGNS RAY SIGNS RAY SIGNS RAY SIGNS RAY SIGNS RAY SIGNS RAY
SIGNS
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void RaySignTexture::mapValues(const RenderContext&, RayPacket& rays, Color
results[]) const {
+
+ // Compute the directions for each ray.
+ rays.computeInverseDirections();
+ rays.computeSigns();
+
+ // Iterate over the packet and set the colors.
+ for (int i=rays.begin();i<rays.end();++i) {
+
+ // Copy the normal out.
+ VectorT<int,3> sign = rays.getSigns( i );
+
+ ColorComponent scale = 0.5;
+ if (rays.getFlag( RayPacket::ConstantSigns )) {
+ scale = 1.0;
+ }
+
+ results[i] = Color( RGB( (scale*sign[0])*0.5+0.5,
+ (scale*sign[1])*0.5+0.5,
+ (scale*sign[2])*0.5+0.5 ));
+
+
+ }
+
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// WIREFRAME WIREFRAME WIREFRAME WIREFRAME WIREFRAME WIREFRAME
WIREFRAME
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+template<class ScratchPadInfo>
+WireframeTexture<ScratchPadInfo>::WireframeTexture( const Color &color_ ) {
+
+ texture = new Constant<Color>( color_ );
+}
+
+template<>
+void WireframeTexture<HeavyTriangle::TriangleHit>::getBarycentricCoords(
RayPacket &rays, int which, Real &a, Real &b, Real &c ) const {
+
+ HeavyTriangle::TriangleHit &th =
+ rays.scratchpad<HeavyTriangle::TriangleHit>(which);
+
+ a = th.a;
+ b = th.b;
+ c = ((Real)1.0 - th.a - th.b);
+}
+
+template<>
+void WireframeTexture<Kdtree::KDTree::ScratchPadInfo>::
+getBarycentricCoords( RayPacket &rays, int which, Real &a, Real &b, Real &c
) const {
+
+ Kdtree::KDTree::ScratchPadInfo &info =
+ rays.scratchpad<Kdtree::KDTree::ScratchPadInfo>(which);
+
+ a = info.a;
+ b = info.b;
+ c = ((Real)1.0 - info.a - info.b);
+}
+
+template<class ScratchPadInfo>
+void WireframeTexture<ScratchPadInfo>::mapValues(const RenderContext
&context, RayPacket& rays, Color results[]) const {
+
+ // Compute the normal for each ray.
+ rays.computeNormals( context );
+
+ // Lookup dependent texture values.
+ Color texture_values[RayPacket::MaxSize];
+ texture->mapValues( context, rays, texture_values );
+
+ // Iterate over the packet and set the colors.
+ for (int i=rays.begin();i<rays.end();++i) {
+
+ // Lookup barycentric coordinates.
+ Real a, b, c;
+ getBarycentricCoords( rays, i, a, b, c );
+
+ // Add a wireframe.
+#if 0
+ if ((a > 0.9) && (b < 0.1) && (c < 0.1)) {
+ results[i] = Color( RGB( normal[0],normal[1], normal[2] ));
+ }
+ else if ((b > 0.9) && (c < 0.1) && (a < 0.1)) {
+ results[i] = Color( RGB( normal[0],normal[1], normal[2] ));
+ }
+ else if ((c > 0.9) && (a < 0.1) && (b < 0.1)) {
+ results[i] = Color( RGB( normal[0],normal[1], normal[2] ));
+ }
+ else
+#endif
+
+ if ((a < 0.05) || (b < 0.05) || (c < 0.05)) {
+ results[i] = Color(RGB(0.0,0.0,0.0));
+ }
+ else {
+ results[i] = texture_values[i];
+ }
+
+ }
+}
+
+template class WireframeTexture<HeavyTriangle::TriangleHit>;
+template class WireframeTexture<Kdtree::KDTree::ScratchPadInfo>;
Added: trunk/Model/Textures/NormalTexture.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/NormalTexture.h Tue Jan 24 19:56:08 2006
@@ -0,0 +1,81 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ 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.
+*/
+
+#ifndef Manta_Model_NormalTexture_h
+#define Manta_Model_NormalTexture_h
+
+#include <Interface/Texture.h>
+#include <Interface/RayPacket.h>
+
+// Abe Stephens
+
+namespace Manta {
+
+ class RayPacket;
+ class RenderContext;
+
+ class NormalTexture : public Texture<Color> {
+ public:
+ NormalTexture() { }
+ virtual ~NormalTexture() { }
+
+ virtual void mapValues(const RenderContext&, RayPacket& rays, Color
results[]) const;
+ };
+
+ class RaySignTexture : public Texture<Color> {
+ public:
+ RaySignTexture() { }
+ virtual ~RaySignTexture() { }
+
+ virtual void mapValues(const RenderContext&, RayPacket& rays, Color
results[]) const;
+ };
+
+ template<class ScratchPadInfo>
+ class WireframeTexture : public Texture<Color> {
+ public:
+ WireframeTexture( Texture<Color> *texture_ ) :
+ texture( texture_ ) { };
+ WireframeTexture( const Color &color_ );
+ virtual ~WireframeTexture() { }
+
+ virtual void mapValues(const RenderContext&, RayPacket& rays, Color
results[]) const;
+ private:
+
+
///////////////////////////////////////////////////////////////////////////
+ // Note: This method must be implemented for each possible template
parameter
+ // type explicitly. It is responsible for copying the coordinates out of
the
+ // ray packet scratch pad.
+ void getBarycentricCoords( RayPacket &rays, int which,
+ Real &a, Real &b, Real &c ) const;
+ Texture<Color> *texture;
+ };
+
+};
+
+#endif
- [MANTA] r866 - trunk/Model/Textures, abe, 01/24/2006
Archive powered by MHonArc 2.6.16.