Text archives Help
- From: thiago@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1298 - in trunk: Model/Textures scenes
- Date: Mon, 12 Mar 2007 19:34:40 -0700 (MST)
Author: thiago
Date: Mon Mar 12 19:34:39 2007
New Revision: 1298
Added:
trunk/Model/Textures/HeightColorMap.cc
trunk/Model/Textures/HeightColorMap.h
trunk/scenes/vorpal.cc
Modified:
trunk/Model/Textures/CMakeLists.txt
trunk/scenes/CMakeLists.txt
Log:
scenes/vorpal.cc
scenes/CMakeLists.txt:
scene file for loading the VORPAL data.
Model/Textures/HeightColorMap.cc
Model/Textures/HeightColorMap.h
Model/Textures/CMakeLists.txt:
Makes a rainbow colormap based on the z value of the hitpoint and a
min/max z range.
Modified: trunk/Model/Textures/CMakeLists.txt
==============================================================================
--- trunk/Model/Textures/CMakeLists.txt (original)
+++ trunk/Model/Textures/CMakeLists.txt Mon Mar 12 19:34:39 2007
@@ -7,6 +7,8 @@
Textures/Constant.h
Textures/ImageTexture.cc
Textures/ImageTexture.h
+ Textures/HeightColorMap.cc
+ Textures/HeightColorMap.h
Textures/MarbleTexture.cc
Textures/MarbleTexture.h
Textures/NormalTexture.cc
Added: trunk/Model/Textures/HeightColorMap.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/HeightColorMap.cc Mon Mar 12 19:34:39 2007
@@ -0,0 +1,107 @@
+
+/*
+ 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/HeightColorMap.h>
+#include <Interface/RayPacket.h>
+#include <Core/Color/Color.h>
+
+using namespace Manta;
+
+
+void hsv_to_rgb(float H, float &R, float &G, float &B)
+{
+ float S = 1;
+ float V = 1;
+
+ H *= 6.0;
+ float i = floor(H);
+ float f = H - i;
+
+ float p = V * (1.0 - S);
+ float q = V * (1.0 - S * f);
+ float t = V * (1.0 - S * (1 - f));
+
+ if (i == 0.0)
+ {
+ R = V;
+ G = t;
+ B = p;
+ }
+ else if (i == 1.0)
+ {
+ R = q;
+ G = V;
+ B = p;
+ }
+ else if (i == 2.0)
+ {
+ R = p;
+ G = V;
+ B = t;
+ }
+ else if (i == 3.0)
+ {
+ R = p;
+ G = q;
+ B = V;
+ }
+ else if (i == 4.0)
+ {
+ R = t;
+ G = p;
+ B = V;
+ }
+ else
+ {
+ // i == 5.0
+ R = V;
+ G = p;
+ B = q;
+ }
+}
+
+
+void HeightColorMap::mapValues(Packet<Color>& results,
+ const RenderContext& context,
+ RayPacket& rays) const
+{
+
+ for (int i=rays.begin();i<rays.end();++i) {
+ rays.computeHitPositions();
+ Real height = rays.getHitPosition(i).z() - min_height;
+ Real normalized_height = height * inv_range;
+ float r, g, b;
+ hsv_to_rgb(normalized_height, r, g, b);
+
+ results.set(i, Color( RGB( (ColorComponent)r,
+ (ColorComponent)g,
+ (ColorComponent)b )));
+
+ }
+}
Added: trunk/Model/Textures/HeightColorMap.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/HeightColorMap.h Mon Mar 12 19:34:39 2007
@@ -0,0 +1,60 @@
+
+/*
+ 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_HeightColorMap_h
+#define Manta_Model_HeightColorMap_h
+
+#include <Interface/Texture.h>
+#include <Interface/RayPacket.h>
+#include <Model/Textures/Constant.h>
+
+namespace Manta {
+
+ class RayPacket;
+ class RenderContext;
+
+ class HeightColorMap : public Texture<Color> {
+ public:
+ HeightColorMap(Real min_height, Real max_height) :
+ min_height(min_height), max_height(max_height)
+ {
+ inv_range = 1.0 / (max_height - min_height);
+ }
+ virtual ~HeightColorMap() { }
+
+ virtual void mapValues(Packet<Color>& results,
+ const RenderContext&,
+ RayPacket& rays) const;
+ private:
+ Real min_height, max_height;
+ Real inv_range;
+ };
+};
+
+#endif
Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Mon Mar 12 19:34:39 2007
@@ -114,3 +114,9 @@
# Recurse into galileo directory
SUBDIRS(galileo)
+
+SET(SCENE_VORPAL 0 CACHE BOOL "VORPAL fusion datasets")
+IF(SCENE_VORPAL)
+ ADD_LIBRARY(scene_vorpal vorpal.cc)
+ TARGET_LINK_LIBRARIES(scene_vorpal ${MANTA_SCENE_LINK})
+ENDIF(SCENE_VORPAL)
Added: trunk/scenes/vorpal.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/vorpal.cc Mon Mar 12 19:34:39 2007
@@ -0,0 +1,108 @@
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Util/Args.h>
+#include <Interface/LightSet.h>
+#include <Interface/Context.h>
+#include <Interface/Scene.h>
+#include <Model/Textures/HeightColorMap.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/AmbientLights/ArcAmbient.h>
+#include <Model/Backgrounds/LinearBackground.h>
+#include <Model/Groups/Group.h>
+#include <Model/Groups/DynBVH.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Primitives/Heightfield.h>
+#include <Core/Math/MinMax.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <sgi_stl_warnings_on.h>
+
+using namespace Manta;
+using namespace std;
+
+extern "C"
+Scene* make_scene(const ReadContext&, const vector<string>& args)
+{
+ std::cout << "Make_scene args: " << args.size() << std::endl;
+
+ string heightfield_filename, particles_filename;
+ int argc = static_cast<int>(args.size());
+ for(int i=0;i<argc;i++){
+ string arg = args[i];
+ if(arg == "-heightfield"){
+ if(!getStringArg(i, args, heightfield_filename))
+ throw IllegalArgument("scene vorpal -heightfield", i, args);
+ }
+ else if(arg == "-particles"){
+ if(!getStringArg(i, args, particles_filename))
+ throw IllegalArgument("scene vorpal -particles", i, args);
+ } else {
+ if(arg[0] == '-') {
+ cerr << "Valid options for scene vorpal:\n";
+ cerr << "-heightfield <filename>\n";
+ cerr << "-particles <filename>\n";
+ throw IllegalArgument("scene vorpal", i, args);
+ }
+ }
+ }
+
+ Group* group = new Group();
+
+ ifstream in(particles_filename.c_str());
+ if(!in){
+ cerr << "Error opening " << particles_filename << "\n";
+ exit(1);
+ }
+ int nparticles;
+ float min_x, min_y, max_x, max_y;
+ in >> nparticles >> min_x >> min_y >> max_x >> max_y;
+ in.get();
+ float *data = new float[nparticles*3];
+ in.read(reinterpret_cast<char*>(data), sizeof(float)*(nparticles*3));
+ if(!in){
+ cerr << "Error reading data from " << particles_filename << "\n";
+ exit(1);
+ }
+
+ float max_dim = std::max(max_x-min_x, max_y-min_y)/8;
+
+ Vector minBound(0, 0, 0);
+ Vector maxBound( (max_x-min_x)/max_dim, (max_y-min_y)/max_dim, 1);
+
+ Heightfield* heightfield = new Heightfield(NULL,
heightfield_filename.c_str(), minBound, maxBound);
+ BBox bbox;
+ PreprocessContext preprocessContext;
+ heightfield->computeBounds(preprocessContext, bbox);
+ heightfield->setMaterial(new Lambertian(new
HeightColorMap(bbox.getMin().z(), bbox.getMax().z())));
+// if ( mapr )
+// prim->setTexCoordMapper( mapr );
+
+ Group *particles = new DynBVH;
+ Material *particle_matl = new Lambertian(Color(RGB(.2,.6,.2)));
+ for (int i = 0; i < nparticles; ++i) {
+ Vector center( (data[i*3 + 0]-min_x)/max_dim,
+ (data[i*3 + 1]-min_y)/max_dim,
+ data[i*3 + 2]*4);
+ particles->add(new Sphere(particle_matl, center, .03));
+ }
+ group->add(particles);
+ group->add(heightfield);
+
+
+ Scene* scene = new Scene();
+ scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
+ Color(RGB(0.0,0.0,0.0)),
+ Vector(0,1,0)));
+ scene->setObject(group);
+
+ LightSet* lights = new LightSet();
+ lights->add(new PointLight(Vector(0,0,1000), Color(RGB(1,1,1))*2));
+ Color cup(RGB(0.1, 0.3, 0.8));
+ Color cdown(RGB(0.82, 0.62, 0.62));
+ Vector up(0,1,0);
+ lights->setAmbientLight(new ArcAmbient(cup, cdown, up));
+ scene->setLights(lights);
+ return scene;
+}
- [MANTA] r1298 - in trunk: Model/Textures scenes, thiago, 03/12/2007
Archive powered by MHonArc 2.6.16.