Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2115)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2119)
@@ -2,39 +2,26 @@
 #define __ObjReader_H__
 
-//#include <stdlib>
 #include <string>
 #include <vector>
 #include <Ogre.h>
 #include "Containers.h"
-/*#include "ObjNode.h"
-#include "ObjMeshData.h"
-#include "ObjManualMeshLoader.h"
-*/
 
-
-namespace GtpVisibilityPreprocessor {
-
-struct Triangle3;
-
-}
-
-//typedef std::vector<GtpVisibilityPreprocessor::Triangle3 *> TriangleContainer;
 
 class __declspec(dllexport) ObjReader
 {
 public:
-	ObjReader();
+	ObjReader(Ogre::SceneManager *sceneManager);
 	~ObjReader();
 
-	bool LoadFile(const std::string &filename,
-				  GtpVisibilityPreprocessor::ObjectContainer &objects) const;
+	bool LoadFile(const string &sceneName, 
+				  const string &visibilitySolution,
+				  Ogre::SceneNode *root);
 	
-	const std::vector<Ogre::Entity *> &GetObjects() const;
-	
-	Ogre::Entity *CreateEntity(const std::string &name);
+	Ogre::Entity *CreateEntity(const std::string &name,
+							   GtpVisibilityPreprocessor::Intersectable *object);
 
 protected:
 
-	std::vector<Ogre::Entity *> mObjects;
+	Ogre::SceneManager *mSceneManager;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2112)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2119)
@@ -73,5 +73,5 @@
 				Name="VCCLCompilerTool"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include;..\..\..\Preprocessing\src"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE1"
 				RuntimeLibrary="2"
 				UsePrecompiledHeader="0"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2115)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2119)
@@ -3,7 +3,14 @@
 #include "Triangle3.h"
 #include "IntersectableWrapper.h"
+#include "BvHierarchy.h"
+#include "Preprocessor.h"
+#include "OgreEntity.h"
+#include "PreprocessorFactory.h"
+#include "OgreLogManager.h"
 
 
-ObjReader::ObjReader()
+
+ObjReader::ObjReader(Ogre::SceneManager *sceneManager):
+mSceneManager(sceneManager)
 {}
 
@@ -13,67 +20,81 @@
 
 
-bool ObjReader::LoadFile(const string &filename,
-						 GtpVisibilityPreprocessor::ObjectContainer &objects) const
+bool ObjReader::LoadFile(const string &sceneName, 
+						 const string &visibilitySolution,
+						 Ogre::SceneNode *root)
 {
-	igzstream samplesIn(filename.c_str());
-	
-	if (!samplesIn.is_open())
+	GtpVisibilityPreprocessor::Debug.open("debug.log");
+	// HACK: get any preprocessor to load file
+	GtpVisibilityPreprocessor::Preprocessor *preprocessor = 
+		GtpVisibilityPreprocessor::PreprocessorFactory::CreatePreprocessor("vss");
+
+	// hack
+	preprocessor->mLoadMeshes = false;
+	GtpVisibilityPreprocessor::ObjectContainer pvsObjects;
+
+	Ogre::LogManager::getSingleton().logMessage("loading obj scene!!");
+
+	if (preprocessor->LoadScene(sceneName))
+	{
+		Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects");
+		// form objects from the scene triangles
+		if (!preprocessor->LoadObjects(visibilitySolution, pvsObjects, preprocessor->mObjects))
+		{
+			Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded");
+			return false;
+		}
+	}
+	else
+	{
+		Ogre::LogManager::getSingleton().logMessage("scene cannot be loaded");
 		return false;
-	
-	// read in triangle size
-	int numTriangles;
+	}
 
-	samplesIn.read(reinterpret_cast<char *>(&numTriangles), sizeof(int));
-	objects.reserve(numTriangles);
-	
-	while (1)
-	{
-		GtpVisibilityPreprocessor::Triangle3 tri;
-		
-		samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 0), 
-					   sizeof(GtpVisibilityPreprocessor::Vector3));
-		samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 1), 
-					   sizeof(GtpVisibilityPreprocessor::Vector3));
-		samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 2), 
-					   sizeof(GtpVisibilityPreprocessor::Vector3));
+	std::stringstream d; 
+	d << "successfully loaded " << pvsObjects.size() << " objects";
 
-		// end of file reached
-		if (samplesIn.eof())
-			break;
+	Ogre::LogManager::getSingleton().logMessage(d.str());
 
-		GtpVisibilityPreprocessor::TriangleIntersectable *obj = 
-			new GtpVisibilityPreprocessor::TriangleIntersectable(tri);
-		objects.push_back(obj);
+	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = pvsObjects.end();
+
+	int i = 0;
+	for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i)
+	{Ogre::LogManager::getSingleton().logMessage("r");
+		const Ogre::String entname = "Object" + i;
+
+		Ogre::Entity *ent = CreateEntity(entname, *oit);
+
+		const Ogre::String nodeName = entname + "/Node";
+		root->createChildSceneNode(nodeName);
 	}
-	
-	return true;
+
+	delete preprocessor;
+
+	return false;
 }
 
 
-const std::vector<Ogre::Entity *> &ObjReader::GetObjects() const
-{
-	return mObjects;
-}
-
-
-Ogre::Entity *ObjReader::CreateEntity(const std::string &name)
-//									  ObjMeshData *mData, 
-//									  Ogre::Vector3 *translation)
+Ogre::Entity *ObjReader::CreateEntity(const std::string &name,
+									  GtpVisibilityPreprocessor::Intersectable *object)
 {
 	using namespace Ogre;
+	//using namespace GtpVisibilityPreprocessor;
+
 	Entity *entity;
 
-	
-	std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh";
+	GtpVisibilityPreprocessor::BvhLeaf *bvhObj = 
+		static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object);
+
+	std::string meshName = name + "/Mesh";
 	std::string entityName = name + "/Entity";
 
 	MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup");
 	SubMesh* submesh = mesh->createSubMesh();
-int nbVertices = 99992;
+
 	// We must create the vertex data, indicating how many vertices there will be
 	submesh->useSharedVertices = false;
 	submesh->vertexData = new VertexData();
 	submesh->vertexData->vertexStart = 0;
-	submesh->vertexData->vertexCount = nbVertices;
+	submesh->vertexData->vertexCount = (int)bvhObj->mObjects.size() * 3;
 
 	static const unsigned short source = 0;
@@ -82,5 +103,5 @@
 	VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
 
-	offset += declaration->addElement(source,offset,VET_FLOAT3,VES_POSITION).getSize();
+	offset += declaration->addElement(source, offset, VET_FLOAT3,VES_POSITION).getSize();
 	//	offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize();
 	//	offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize();
@@ -89,36 +110,34 @@
 	int numVertices = 0;
 
-	HardwareVertexBufferSharedPtr vbuffer = 
-		HardwareBufferManager::getSingleton().createVertexBuffer(declaration->getVertexSize(source), // size of one whole vertex
-		submesh->vertexData->vertexCount, // number of vertices
-		HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage
-		false); // no shadow buffer
+	HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton().
+		createVertexBuffer(declaration->getVertexSize(source),
+						   submesh->vertexData->vertexCount,
+						   HardwareBuffer::HBU_STATIC_WRITE_ONLY,
+						   false);
 
-
-	// No we get access to the buffer to fill it.  During so we record the bounding box.
+    // No we get access to the buffer to fill it.  During so we record the bounding box.
 	AxisAlignedBox aabox;
 
 	float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD));
 
-	for (size_t i = 0; i < nbVertices; ++ i)
+	GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end();
+
+	for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit)
 	{
-		// Position
-		Vector3 position;// = 20.0f*positions[i];
-		*vdata++ = position.x;
-		*vdata++ = position.y;
-		*vdata++ = position.z;
-		aabox.merge(position);
-		// Normal
-		Vector3 normal = position.normalisedCopy();
-		*vdata++ = normal.x;
-		*vdata++ = normal.y;
-		*vdata++ = normal.z;
+		GtpVisibilityPreprocessor::TriangleIntersectable *tObj = 
+			static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit);
+		
+		GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem();
 
-		// Texture coordinate
-		Vector2 tcoordinate;// = tcoordinates[i];
-		*vdata ++ = tcoordinate.x;
+		for (int i = 0; i < 3; ++ i)
+		{
+			Vector3 vtx(tri.mVertices[i]);
 
-		*vdata ++ = tcoordinate.y;
+			*vdata ++ = vtx.x;
+			*vdata ++ = vtx.y;
+			*vdata ++ = vtx.z;
 
+			aabox.merge(vtx);
+		}
 	}
 
@@ -126,12 +145,11 @@
 
 	// We must indicate the bounding box
-	//mesh->_setBounds(aabox); 
+	mesh->_setBounds(aabox); 
 
-	//mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 
-
+	mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 
 	mesh->load();
 	
 	// Create an entity with the mesh
-	//entity = mSceneManager->createEntity(meshName, entityName);
+	entity = mSceneManager->createEntity(meshName, entityName);
 
 	return entity;
