Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 833)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 850)
@@ -109,5 +109,5 @@
 				LinkIncremental="1"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\support\xercesc\lib\;..\..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\..\NonGTP\zlib\lib;..\..\..\..\..\..\..\NonGTP\Devil\lib;&quot;$(QTDIR)\lib&quot;;&quot;$(CG_LIB_PATH)&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\support\xercesc\lib\;..\..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\..\NonGTP\zlib\lib;..\..\..\..\..\..\..\NonGTP\Devil\lib;&quot;$(QTDIR)\lib&quot;;&quot;$(CG_LIB_PATH)&quot;;..\..\..\Preprocessing\src\GL"
 				ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def"
 				GenerateDebugInformation="TRUE"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 697)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 850)
@@ -91,5 +91,5 @@
     if ( (value >=mMin[axis]) && (value <= mMax[axis]) )
       if (right)
-				mMin[axis] = value;
+		mMin[axis] = value;
       else
         mMax[axis] = value;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 844)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 850)
@@ -48,6 +48,16 @@
 };
 
-/**
-	Manages different higher order operations on the view cells.
+
+struct IndexedBoundingBox: public std::pair<int, AxisAlignedBox3>
+{
+	typedef std::pair<int, AxisAlignedBox3> IndexedBoundingBoxParent;
+
+	IndexedBoundingBox(int idx, const AxisAlignedBox3 &box): IndexedBoundingBoxParent(idx, box)
+	{
+
+	}
+};
+
+/**	Manages different higher order operations on the view cells.
 */
 class ViewCellsManager
@@ -416,4 +426,7 @@
 	bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
 
+	/** Load the bounding boxes into the container.
+	*/
+	bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 844)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 850)
@@ -1328,5 +1328,4 @@
 					"view_cells_export_bounding_boxes=",
 					"true");
-
 	
 	RegisterOption("ViewCells.boxesFilename",
@@ -1334,5 +1333,4 @@
 					"view_cells_boxes_filename=",
 					"boxes.out");
-
 
 	RegisterOption("ViewCells.PostProcess.emptyViewCellsMerge",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 837)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 850)
@@ -46,38 +46,35 @@
 
 
+    virtual AxisAlignedBox3 GetBox() = 0;
+	virtual int CastRay(Ray &ray) = 0;
 	
-  virtual AxisAlignedBox3 GetBox() = 0;
+	virtual bool IsConvex() = 0;
+	virtual bool IsWatertight() = 0;
+	virtual float IntersectionComplexity() = 0;
   
-  virtual int CastRay(Ray &ray) = 0;
+	virtual int NumberOfFaces() const = 0;
+	virtual int Type() const = 0;
+
+	virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
+
+	virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
+											 Vector3 &normal,
+											 const Vector3 &viewpoint,
+											 const int maxTries) = 0;
   
-  virtual bool IsConvex() = 0;
-  virtual bool IsWatertight() = 0;
-  virtual float IntersectionComplexity() = 0;
-  
-  virtual int NumberOfFaces() const = 0;
+	virtual ostream &Describe(ostream &s) = 0;
+	
+	virtual int GenerateSilhouetteRays(const int nrays,
+									   const AxisAlignedBox3 &originBox,
+									   const AxisAlignedBox3 &directionBox, VssRayContainer &rays) 
+	{
+		return 0;
+	}
 
-  virtual int Type() const = 0;
-  
-  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
-  
-  virtual int
-  GetRandomVisibleSurfacePoint(Vector3 &point,
-							   Vector3 &normal,
-							   const Vector3 &viewpoint,
-							   const int maxTries
-							   ) = 0;
-  
-  virtual ostream &Describe(ostream &s) = 0;
-  
-  virtual int GenerateSilhouetteRays(const int nrays,
-									 const AxisAlignedBox3 &originBox,
-									 const AxisAlignedBox3 &directionBox,
-									 VssRayContainer &rays
-									 ) {return 0;}
-
-  static bool GreaterCounter(const Intersectable *a,
-							 const Intersectable *b) {
-	return a->mCounter > b->mCounter;
-  }
+	static bool GreaterCounter(const Intersectable *a,
+							 const Intersectable *b) 
+	{
+		return a->mCounter > b->mCounter;
+	}
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 810)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 850)
@@ -14,4 +14,6 @@
 class Ray;
 class Mesh;
+
+struct IndexedBoundingBox;
 
 struct VisibilityPoint;
@@ -52,4 +54,6 @@
 typedef vector<VisibilityPoint *> VisibilityPointsContainer;
 
+typedef vector<IndexedBoundingBox> IndexedBoundingBoxContainer;
+
 #endif // _Container_H__
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 844)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 850)
@@ -187,4 +187,8 @@
 	Debug << "filter width: " << mFilterWidth << endl;
 	Debug << "sample after subdivision: " << SAMPLE_AFTER_SUBDIVISION << endl;
+
+	Debug << "export bounding boxes: " << mExportBboxesForPvs << endl;
+	Debug << "export pvs for view cells: " << mExportPvs << endl;
+
 	Debug << endl;
 }
@@ -1896,5 +1900,7 @@
 			Vector3 bmin = box.Min();
 			Vector3 bmax = box.Max();
-
+			int id = mi->GetId();
+
+			boxesOut.write(reinterpret_cast<char *>(&id), sizeof(int));
 			boxesOut.write(reinterpret_cast<char *>(&bmin), sizeof(Vector3));
 			boxesOut.write(reinterpret_cast<char *>(&bmax), sizeof(Vector3));
@@ -1909,99 +1915,71 @@
 
 
-// use ascii format to store rays
-#define USE_ASCII 0
-
-
-inline bool ilt(Intersectable *obj1, Intersectable *obj2)
-{
-	return obj1->mId < obj2->mId;
-}
-
-/*
-bool Preprocessor::LoadBoundingBoxes(const string filename, 
-									 const ObjectContainer &objects) const
-{
-	std::stable_sort(objects.begin(), objects.end(), ilt);
-	char fileName[100];
-	environment->GetStringValue("Preprocessor.samplesFilename", fileName);
-	
-    Vector3 origin, termination;
+bool ViewCellsManager::LoadBoundingBoxes(const string filename, 
+										 IndexedBoundingBoxContainer &boxes) const
+{
 	// HACK: needed only for lower_bound algorithm to find the 
 	// intersected objects
-	MeshInstance sObj(NULL);
-	MeshInstance tObj(NULL);
-
-#if USE_ASCII
-	ifstream samplesIn(fileName);
-	if (!samplesIn.is_open())
-		return false;
-
-	string buf;
-	while (!(getline(samplesIn, buf)).eof())
-	{
-		sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d", 
-			   &origin.x, &origin.y, &origin.z,
-			   &termination.x, &termination.y, &termination.z, 
-			   &(sObj.mId), &(tObj.mId));
+
+	Vector3 bmin, bmax;
+	int id;
+
+	if (USE_ASCII)
+	{
+		ifstream boxesIn(filename.c_str());
 		
-		Intersectable *sourceObj = NULL;
-		Intersectable *termObj = NULL;
+		if (!boxesIn.is_open())
+		{
+			cout << "failed to open file " << filename << endl;
+			return false;
+		}
+
+		string buf;
+		while (!(getline(boxesIn, buf)).eof())
+		{
+			sscanf(buf.c_str(), "%d %f %f %f %f %f %f", 
+				   &id, &bmin.x, &bmin.y, &bmin.z,
+				   &bmax.x, &bmax.y, &bmax.z);
 		
-		if (sObj.mId >= 0)
-		{
-			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &sObj, ilt);
-			sourceObj = *oit;
-		}
-		
-		if (tObj.mId >= 0)
-		{
-			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &tObj, ilt);
-			termObj = *oit;
-		}
-
-		samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
-	}
-#else
-	ifstream samplesIn(fileName, ios::binary);
-	if (!samplesIn.is_open())
-		return false;
-
-	while (1)
-	{
-		 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3));
-		 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3));
-		 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int));
-		 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int));
-		
-		 if (samplesIn.eof())
-			break;
-
-		Intersectable *sourceObj = NULL;
-		Intersectable *termObj = NULL;
-		
-		if (sObj.mId >= 0)
-		{
-			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &sObj, ilt);
-			sourceObj = *oit;
-		}
-		
-		if (tObj.mId >= 0)
-		{
-			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &tObj, ilt);
-			termObj = *oit;
-		}
-
-		samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
-	}
-
-#endif
-	samplesIn.close();
+			AxisAlignedBox3 box(bmin, bmax);
+			//	MeshInstance *mi = new MeshInstance();
+			// HACK: set bounding box to new box
+			//mi->mBox = box;
+
+			boxes.push_back(IndexedBoundingBox(id, box));
+		}
+
+		boxesIn.close();
+	}
+	else
+	{
+		ifstream boxesIn(filename.c_str(), ios::binary);
+
+		if (!boxesIn.is_open())
+			return false;
+
+		while (1)
+		{
+			boxesIn.read(reinterpret_cast<char *>(&id), sizeof(Vector3));
+			boxesIn.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3));
+			boxesIn.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3));
+			
+			if (boxesIn.eof())
+				break;
+
+			
+			AxisAlignedBox3 box(bmin, bmax);
+			MeshInstance *mi = new MeshInstance(NULL);
+
+			// HACK: set bounding box to new box
+			//mi->mBox = box;
+			//boxes.push_back(mi);
+			boxes.push_back(IndexedBoundingBox(id, box));
+		}
+
+		boxesIn.close();
+	}
 
 	return true;
-}*/
+}
 
 /**********************************************************************/
@@ -3686,8 +3664,4 @@
 		// compute tree by merging the nodes based on cost heuristics
 		mViewCellsTree->ConstructMergeTree(rays, objects);
-
-        //cout << "here344" << endl;
-		//ObjectPvs pvs;
-		//UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs);
 	}
 	else
@@ -3971,5 +3945,25 @@
 		char filename[100];
 		environment->GetStringValue("ViewCells.boxesFilename", filename);
+	
 		ExportBoundingBoxes(filename, objects);
+/*
+		IndexedBoundingBoxContainer boxes;
+		LoadBoundingBoxes(filename, boxes);
+
+		IndexedBoundingBoxContainer::const_iterator it, it_end = boxes.end();
+
+		for (it = boxes.begin(); it != it_end; ++ it)
+		{
+			IndexedBoundingBox ibox = *it;
+			AxisAlignedBox3 box = ibox.second;
+
+			Debug << ibox.first << " " 
+				  << box.Min().x << " " 
+				  << box.Min().y << " " 
+				  << box.Min().z << " " 
+				  << box.Max().x << " " 
+				  << box.Max().y << " " 
+                  << box.Max().z << endl;	
+		}*/
 	}
 
Index: GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln
===================================================================
--- GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 833)
+++ GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 850)
@@ -26,4 +26,5 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestPreprocessor", "..\..\Preprocessing\scripts\TestPreprocessor.vcproj", "{69BC58F0-C7EB-4B43-B782-B6F047EF0528}"
 	ProjectSection(ProjectDependencies) = postProject
+		{EABCE292-D598-4600-A1C9-2591E7D62FDA} = {EABCE292-D598-4600-A1C9-2591E7D62FDA}
 	EndProjectSection
 EndProject
