Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r978 - in trunk: Core/Geometry Model/Groups scenes
- Date: Tue, 7 Mar 2006 17:07:14 -0700 (MST)
Author: bigler
Date: Tue Mar 7 17:07:12 2006
New Revision: 978
Added:
trunk/Model/Groups/KDTreeLoaderIW.cc
trunk/Model/Groups/KDTreeLoaderIW.h
Modified:
trunk/Core/Geometry/VectorT.h
trunk/Model/Groups/CMakeLists.txt
trunk/Model/Groups/KDTree.h
trunk/Model/Groups/KDTreeLoader.cc
trunk/scenes/boeing777.cc
Log:
Core/Geometry/VectorT.h
Added constructor that takes an array pointer.
Model/Groups/CMakeLists.txt
Added KDTreeLoaderIM.{cc,h}
Model/Groups/KDTree.h
Added loadIW() as friend to KDTreeData.
Model/Groups/KDTreeLoader.cc
Missed a return 0 when there was a problem opening a file.
Model/Groups/KDTreeLoaderIW.cc
Model/Groups/KDTreeLoaderIW.h
Loader for IW format data and BSPs. Only loads data right now.
Doesn't actually load the BSP stuff.
scenes/boeing777.cc
Added -iwfile <geom file> <bsp file> argument that would load in IW
format data.
Modified: trunk/Core/Geometry/VectorT.h
==============================================================================
--- trunk/Core/Geometry/VectorT.h (original)
+++ trunk/Core/Geometry/VectorT.h Tue Mar 7 17:07:12 2006
@@ -86,6 +86,11 @@
data[i] = copy[i];
}
+ VectorT(const T* data_in) {
+ for(int i=0;i<Dim;i++)
+ data[i] = data_in[i];
+ }
+
#ifndef SWIG
VectorT<T, Dim>& operator=(const VectorT<T, Dim>& copy) {
for(int i=0;i<Dim;i++)
Modified: trunk/Model/Groups/CMakeLists.txt
==============================================================================
--- trunk/Model/Groups/CMakeLists.txt (original)
+++ trunk/Model/Groups/CMakeLists.txt Tue Mar 7 17:07:12 2006
@@ -20,6 +20,8 @@
Groups/KDTree.h
Groups/KDTreeLoader.cc
Groups/KDTreeLoader.h
+ Groups/KDTreeLoaderIW.cc
+ Groups/KDTreeLoaderIW.h
Groups/PsiGammaTable.cc
Groups/PsiGammaTable.h
Groups/RealisticBvh.cc
Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Tue Mar 7 17:07:12 2006
@@ -41,6 +41,7 @@
#include <Interface/Texture.h>
#include <Model/Groups/KDTreeLoader.h>
+#include <Model/Groups/KDTreeLoaderIW.h>
#include <Model/Groups/varray.h>
#include <Model/Readers/V3C1.h>
@@ -225,6 +226,10 @@
// The Kdtree::load(...) function is used to load data into the kdtree.
friend int Manta::Kdtree::load( KDTreeData *kdtree, const char
*filename,
int np );
+ friend int Manta::Kdtree::loadIW( KDTreeData* kdtree,
+ const char* geom_filename,
+ const char* bsp_filename,
+ int np );
/////////////////////////////////////////////////////////////////////////
// SCRATCH PAD
Modified: trunk/Model/Groups/KDTreeLoader.cc
==============================================================================
--- trunk/Model/Groups/KDTreeLoader.cc (original)
+++ trunk/Model/Groups/KDTreeLoader.cc Tue Mar 7 17:07:12 2006
@@ -291,7 +291,7 @@
}
/////////////////////////////////////////////////////////////////////////////
-
/////////////////////////////////////////////////////////////////////////////
+
/////////////////////////////////////////////////////////////////////////////
// Allocate triangles.
*tris = new VArray<Triangle> (nTris);
(*tris)->setLen(nTris);
@@ -533,8 +533,8 @@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-// LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD
LOAD
-////////////////////////////////////////////////////////////////////////////////
+// LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD LOAD
LOAD
+///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Given a file name, and a number of workers, load the specified file.
@@ -571,6 +571,7 @@
FILE *f = fopen(filename, "rb");
if (! f) {
fprintf(stderr, "Error: cannot open %s for loading\n",
filename);
+ return 0;
}
fseek(f, 0, SEEK_END);
Added: trunk/Model/Groups/KDTreeLoaderIW.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Groups/KDTreeLoaderIW.cc Tue Mar 7 17:07:12 2006
@@ -0,0 +1,153 @@
+/*
+ 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/Groups/KDTree.h>
+#include <Model/Groups/KDTreeLoaderIW.h>
+#include <stdio.h>
+
+using namespace Manta;
+using namespace Kdtree;
+
+// Load the specified file (and associated kdtree files) using the
+// given number of processors. The geometry should be found in
+// geom_filename and the bsp data should be found in bsp_filename.
+int Manta::Kdtree::loadIW( KDTreeData* kdtree, const char* geom_filename,
+ const char* bsp_filename, int np )
+{
+ // Attempt to open the two files
+ FILE* geomf = fopen(geom_filename, "r");
+ if (!geomf) {
+ fprintf(stderr, "Error: cannot open %s for loading\n",
geom_filename);
+ return LoadingProblem;
+ }
+ FILE* bspf = fopen(bsp_filename, "r");
+ if (!bspf) {
+ fprintf(stderr, "Error: cannot open %s for loading\n",
bsp_filename);
+ fclose(bspf);
+ return LoadingProblem;
+ }
+
+ // Start loading in the geometry
+#define LINE_WIDTH 100
+
+ char line[LINE_WIDTH];
+ fgets(line, LINE_WIDTH, geomf);
+ char token[LINE_WIDTH];
+ sscanf(line, "%s %*\n", token);
+ // Check to see if the token matches newobject
+ if (strcmp(token, "newobject")) {
+ fprintf(stderr, "First string (%s) is not newobject\n", token);
+ fclose(geomf); fclose(geomf);
+ return LoadingProblem;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ // Load the vertices
+ fgets(line, LINE_WIDTH, geomf);
+ unsigned int num_vertices;
+ sscanf(line, "%s %u", token, &num_vertices);
+ // Check to see if the token matches vertices
+ if (strcmp(token, "vertices:")) {
+ fprintf(stderr, "Token (%s) not equal to vertices:\n", token);
+ fclose(geomf); fclose(geomf);
+ return LoadingProblem;
+ }
+ float* vertices = (float*)(malloc(num_vertices*sizeof(float)*3));
+ float* vp = vertices;
+ for(unsigned int vi = 0; vi < num_vertices; ++vi) {
+ fscanf(geomf, "\t%f %f %f\n", vp, vp+1, vp+2);
+ vp+=3;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ // Load the vertex normals
+ fgets(line, LINE_WIDTH, geomf);
+ unsigned int num_vtxnormals;
+ sscanf(line, "%s %u", token, &num_vtxnormals);
+ // Check to see if the token matches vtxnormals
+ if (strcmp(token, "vtxnormals:")) {
+ fprintf(stderr, "Token (%s) not equal to vtxnormals:\n", token);
+ fclose(geomf); fclose(geomf); free(vertices);
+ return LoadingProblem;
+ }
+
+ float* vtxnormals = (float*)(malloc(num_vtxnormals*sizeof(float)*3));
+ vp = vtxnormals;
+ for(unsigned int vi = 0; vi < num_vtxnormals; ++vi) {
+ fscanf(geomf, "\t%f %f %f\n", vp, vp+1, vp+2);
+ vp+=3;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ // Load the triangles
+ fgets(line, LINE_WIDTH, geomf);
+ unsigned int num_tris;
+ sscanf(line, "%s %u", token, &num_tris);
+ // Check to see if the token matches triangles
+ if (strcmp(token, "triangles:")) {
+ fprintf(stderr, "Token (%s) not equal to triangles:\n", token);
+ fclose(geomf); fclose(geomf); free(vertices); free(vtxnormals);
+ return LoadingProblem;
+ }
+
+ // Allocate space for the triangles and read them in:
+ kdtree->tris = new VArray<Triangle>(num_tris);
+ kdtree->tris->setLen(num_tris);
+ kdtree->normals = reinterpret_cast<TriangleNormal*>(new
char[sizeof(TriangleNormal)*num_tris]);
+ kdtree->triToGroupMap = new VArray<int>(num_tris);
+ kdtree->triToGroupMap->setLen(num_tris);
+
+ for(unsigned int ti = 0; ti < num_tris; ++ti) {
+ unsigned int a,b,c,group;
+ fscanf(geomf, "\t%u %u %u %u\n", &a, &b, &c, &group);
+ Triangle& t = kdtree->tris->get(ti);
+ t.v = Vectorf(vertices+(a*3));
+ t.edge1 = Vectorf(vertices+(b*3)) - t.v;
+ t.edge2 = Vectorf(vertices+(c*3)) - t.v;
+ kdtree->triToGroupMap->get(ti) = group;
+ }
+
+ // Here you should parse out the shaders, but we skip this for now
+
+ Color all_color(RGBColor(1,0,0));
+ for(unsigned int ti = 0; ti < num_tris; ++ti) {
+ Triangle& t = kdtree->tris->get(ti);
+ // int group = kdtree->triToGroupMap.get(ti);
+ t.payload = all_color;
+ }
+
+ fprintf(stderr, "vertices :%20u\n", num_vertices);
+ fprintf(stderr, "vertex normals:%20u\n", num_vtxnormals);
+ fprintf(stderr, "triangles :%20u\n", num_tris);
+
+ // Cleanup memory
+ free(vertices);
+ free(vtxnormals);
+
+} // int loadIW()
+
Added: trunk/Model/Groups/KDTreeLoaderIW.h
==============================================================================
--- (empty file)
+++ trunk/Model/Groups/KDTreeLoaderIW.h Tue Mar 7 17:07:12 2006
@@ -0,0 +1,53 @@
+/*
+ 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_Groups_KDTreeLoaderIW_H
+#define Manta_Groups_KDTreeLoaderIW_H
+
+namespace Manta {
+ namespace Kdtree {
+
+ class KDTreeData;
+ // The KDTreeLoader returns 0 when there was a problem, which is
+ // kind of weird, since most return codes use 0 for success.
+ // These macros will allow the option of changing them later.
+ enum {
+ LoadingProblem = 0,
+ LoadedOK = 1
+ };
+
+ // Load the specified file (and associated kdtree files) using the
+ // given number of processors. The geometry should be found in
+ // geom_filename and the bsp data should be found in bsp_filename.
+ int loadIW( KDTreeData* kdtree, const char* geom_filename,
+ const char* bsp_filename, int np );
+
+ };
+};
+
+#endif // Manta_Groups_KDTreeLoaderIW_H
Modified: trunk/scenes/boeing777.cc
==============================================================================
--- trunk/scenes/boeing777.cc (original)
+++ trunk/scenes/boeing777.cc Tue Mar 7 17:07:12 2006
@@ -95,6 +95,7 @@
Scene* make_scene(const ReadContext& context, const vector<string>& args) {
string file_name;
+ string bsp_name;
Vector plane_point;
Vector plane_normal;
@@ -128,9 +129,15 @@
if (!getIntArg(i, args, workers_np ))
throw IllegalArgument("boeing777 -np <num
build workers>", i, args);
}
+ else if (args[i] == "-iwfile") {
+ if (!getStringArg(i, args, file_name ) ||
+ !getStringArg(i, args, bsp_name))
+ throw IllegalArgument("boeing777 -iwfile
<geom file> <bsp file>",
+ i, args);
+ }
else if (args[i] == "-alpha") {
-
- // Note this just specifies that a TransparentKDTree should be created
as well.
+ // Note this just specifies that a TransparentKDTree should be
+ // created as well.
use_transparency = true;
if (!getArg<Real>(i, args, alpha ))
throw IllegalArgument("boeing777 -alpha
<alpha>", i, args);
@@ -243,7 +250,12 @@
double start_time = Time::currentSeconds();
KDTreeData *kdtree_data = new KDTreeData();
- Kdtree::load( kdtree_data, file_name.c_str(), workers_np );
+ if (bsp_name.length() == 0) {
+ Kdtree::load( kdtree_data, file_name.c_str(), workers_np );
+ } else {
+ Kdtree::loadIW( kdtree_data, file_name.c_str(), bsp_name.c_str(),
+ workers_np );
+ }
double end_time = Time::currentSeconds();
- [MANTA] r978 - in trunk: Core/Geometry Model/Groups scenes, bigler, 03/07/2006
Archive powered by MHonArc 2.6.16.