Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2123)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2124)
@@ -9,4 +9,5 @@
 namespace  GtpVisibilityPreprocessor {
 class Intersectable;
+class Preprocessor;
 }
 
@@ -31,4 +32,5 @@
 	Ogre::SceneManager *mSceneManager;
 	GtpVisibilityPreprocessor::ObjectContainer mPvsObjects;
+	GtpVisibilityPreprocessor::Preprocessor *mPreprocessor;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjNode.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjNode.h	(revision 2111)
+++ 	(revision )
@@ -1,59 +1,0 @@
-#ifndef __ObjNode_H__
-#define __ObjNode_H__
-
-
-#include <string.h>
-#include <Ogre.h>
-
-enum ObjType
-{
-	IV_INVALID = -1,
-	IV_STRING = 0,
-	IV_INT = 1,
-	IV_REAL = 2
-};
-
-
-class ObjField
-{
-public:
-	ObjField();
-	~ObjField();
-
-	char *name;
-	void *value;
-	ObjType typ;
-	int cnt;
-	ObjField *next;
-};
-
-class __declspec(dllexport) ObjNode
-{
-	public:
-		ObjNode();
-		ObjNode(const char *s);
-		~ObjNode();
-
-		void print(int ident=0);
-		void attachNode(ObjNode *child);
-		void addField(const char *name, char *value);
-		void addField(const char *name, void *value, int cnt, ObjType typ);
-
-		ObjNode *getParent() { return parent; }
-		char *getName() { return name; }
-		ObjNode *getNodeRecursive(const char *name);
-		ObjNode *getNextChildNode(bool reset = false);
-		ObjField *getField(const char *name);
-		void *getField(const char *name, ObjType *typ, int *cnt);
-
-	private:
-		char *name;
-		ObjField *fields;
-		ObjNode *parent;
-		ObjNode *children;
-		ObjNode *next;
-
-		ObjNode *actual;
-};
-
-#endif
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjMeshData.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjMeshData.h	(revision 2111)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#ifndef __ObjMeshData_H__
-#define __ObjMeshData_H__
-
-
-#include <Ogre.h>
-
-enum ObjReaderOpType
-{
-	IV_ROT_INVALID = -1,
-	IV_ROT_TRIANGLE_STRIP = 1,
-	IV_ROT_TRIANGLE_LIST = 3,
-	IV_ROT_FACE_SET = 4,
-};
-
-class __declspec(dllexport) ObjMeshData
-{
-	public:	
-		ObjMeshData();
-		~ObjMeshData();
-
-		ObjMeshData *expand();
-
-		void collapse();
-		
-		Ogre::Real *vertices, *normals, *texCoords, *indices, *normalIndices, *texCoordIndices;
-		int vcnt, ncnt, tcnt, icnt, nicnt, ticnt;
-		ObjReaderOpType roType;
-		Ogre::AxisAlignedBox *boundingBox;
-
-	private:
-		int getSeparatorCnt(Ogre::Real *data, int end);
-
-		Ogre::Real *expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut);
-		Ogre::Real *expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut);
-
-		int getNextFaceSize(int start);
-
-		Ogre::AxisAlignedBox *calcBoundingBox();
-
-
-};
-
-#endif
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2123)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2124)
@@ -13,6 +13,7 @@
 
 ObjReader::ObjReader(Ogre::SceneManager *sceneManager):
-mSceneManager(sceneManager)
-{}
+mSceneManager(sceneManager), mPreprocessor(NULL)
+{
+}
 
 
@@ -20,4 +21,6 @@
 {
 	CLEAR_CONTAINER(mPvsObjects);
+	
+	DEL_PTR(mPreprocessor);
 }
 
@@ -29,17 +32,19 @@
 	GtpVisibilityPreprocessor::Debug.open("debug.log");
 	// HACK: get any preprocessor to load file
-	GtpVisibilityPreprocessor::Preprocessor *preprocessor = 
+	// note should be preserved to allow manual mesh reloading,
+	// but then geometry has to be stored two times
+	mPreprocessor = 
 		GtpVisibilityPreprocessor::PreprocessorFactory::CreatePreprocessor("vss");
 
 	// hack
-	preprocessor->mLoadMeshes = false;
+	mPreprocessor->mLoadMeshes = false;
 
 	Ogre::LogManager::getSingleton().logMessage("loading obj scene");
 
-	if (preprocessor->LoadScene(sceneName))
+	if (mPreprocessor->LoadScene(sceneName))
 	{
 		Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects");
 		// form objects from the scene triangles
-		if (!preprocessor->LoadObjects(visibilitySolution, mPvsObjects, preprocessor->mObjects))
+		if (!mPreprocessor->LoadObjects(visibilitySolution, mPvsObjects, mPreprocessor->mObjects))
 		{
 			Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded");
@@ -54,5 +59,6 @@
 
 	std::stringstream d; 
-	d << "successfully loaded " << mPvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects";
+	d << "successfully loaded " << (int)mPvsObjects.size() 
+	  << " objects from " << (int)mPreprocessor->mObjects.size() << " preprocessor objects";
 
 	Ogre::LogManager::getSingleton().logMessage(d.str());
@@ -65,5 +71,6 @@
 		if (i % 5000 == 4999)
 		{
-			d << i << " objects created" << endl;
+			d << i << " objects created";
+			Ogre::LogManager::getSingleton().logMessage(d.str());
 		}
 	
@@ -84,5 +91,5 @@
 	}
 
-	delete preprocessor;
+	//delete preprocessor;
 
 	return true;
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjNode.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjNode.cpp	(revision 2111)
+++ 	(revision )
@@ -1,215 +1,0 @@
-#include "ObjNode.h"
-#include "ObjReader.h"
-
-ObjField::ObjField()
-{
-	next = NULL;
-	typ = IV_STRING;
-}
-
-
-ObjField::~ObjField()
-{
-	if (value != NULL) free(value);
-	if (name != NULL) delete [] name;
-//	if (next != NULL) delete next;
-}
-
-
-ObjNode::ObjNode()
-{
-	parent = children = next = actual = NULL; 
-	name = NULL;
-	fields = NULL;
-}
-
-
-ObjNode::ObjNode(const char *s)
-{
-	name = new char[strlen(s)+1];
-	strcpy(name, s);
-	parent = children = next = actual = NULL;
-	fields = NULL;	
-}
-
-ObjNode::~ObjNode()
-{
-	if (name != NULL) delete[] name;
-	if (fields != NULL) 
-	{
-		ObjField *help = fields, *delme = NULL;
-		while (help->next != NULL)
-		{
-			delme = help; help = help->next; delete delme;
-		}
-		delete help;
-	}
-	if (children != NULL) 
-	{
-		ObjNode *help = children, *delme = NULL;
-		while (help->next != NULL)
-		{
-			delme = help; help = help->next; delete delme;
-		}
-		delete help;
-	}
-//	if (next != NULL) delete next;
-}
-
-
-
-
-void ObjNode::attachNode(ObjNode *child)
-{
-	if (children == NULL) children = child;
-	else 
-	{
-		ObjNode *help = children;
-		while (help->next != NULL) help = help->next;
-		help->next = child;
-	}
-	child->parent = this;
-}
-
-
-void ObjNode::print(int ident)
-{
-	if (IVReader::IVLog != NULL)
-	{
-		std::string msg = ""; 
-
-//		for (int i=0; i < ident; i++) fprintf(stdout, " ");
-		for (int i=0; i < ident; i++) msg = msg + " ";
-//		fprintf(stdout, "%s:\n", name);
-		msg = msg + name + ":";
-		IVReader::IVLog->logMessage(msg);
-
-		ObjField *help = fields;
-		while (help != NULL)
-		{
-//			for (int i=0; i < ident; i++) fprintf(stdout, " ");
-			msg = "";
-			for (int i=0; i < ident; i++) msg = msg + " ";
-			
-			if (help->typ == IV_STRING)
-			{
-//				fprintf(stdout, "- %s: %s\n", help->name, (char *)help->value);
-				msg = msg + "- " + help->name + ": " + (char *)help->value;
-				IVReader::IVLog->logMessage(msg);
-			}
-			if (help->typ == IV_INT)
-			{
-//				fprintf(stdout, "- %s (%d): ", help->name, help->cnt);
-				msg = msg + "- " + help->name + "(" + IVReader::intToStr(help->cnt) + "): ";
-//				for (int i=0; i < help->cnt; i++) fprintf(stdout, " %d", ((int *)help->value)[i]);
-				for (int i=0; i < help->cnt; i++) msg = msg + " " + IVReader::realToStr(((float *)help->value)[i]);
-//				fprintf(stdout, "\n");
-				IVReader::IVLog->logMessage(msg);
-			}
-			if (help->typ == IV_REAL)
-			{
-//				fprintf(stdout, "- %s (%d):\n", help->name, help->cnt);
-				msg = msg + "- " + help->name + "(" + IVReader::intToStr(help->cnt) + "): ";
-				for (int i=0; i < help->cnt; i++) 
-				{				
-//					fprintf(stdout, " %.3f", ((float *)help->value)[i]);
-					msg = msg + " " + IVReader::realToStr(((float *)help->value)[i]);
-//					if (i % 3 == 2) fprintf(stdout, "\n");
-					if (i % 3 == 2) msg = msg + "\n";
-				}
-//				fprintf(stdout, "\n");
-				IVReader::IVLog->logMessage(msg);
-			}
-			help = help->next;
-		}	
-		if (children != NULL) { children->print(ident+3); }
-		if (next != NULL) next->print(ident);
-	}
-}
-
-void ObjNode::addField(const char *name, void *value, int cnt, ObjType typ)
-{
-	ObjField *newone = new ObjField();
-	newone->name = new char[strlen(name)+1];
-	strcpy(newone->name, name);
-/*
-	if (typ == IV_STRING)
-	{
-		newone->value = new char[strlen((char *)value)+1];
-		strcpy((char *)newone->value, (char *)value);
-	} else
-	if ((typ == IV_INT) || (typ == IV_REAL))
-	{
-		newone->value = new Ogre::Real[cnt];
-		memcpy(newone->value, value, cnt*sizeof(Ogre::Real));
-	}
-*/
-	newone->value = value;
-	newone->typ = typ;
-	newone->cnt = cnt;
-	newone->next = NULL;
-
-	if (fields == NULL) fields = newone;
-	else
-	{
-		ObjField *help = fields;
-		while (help->next != NULL) help = help->next;
-		help->next = newone;
-	}
-}
-
-
-void ObjNode::addField(const char *name, char *value)
-{
-	addField(name, value, 1, IV_STRING);
-}
-
-
-ObjNode *ObjNode::getNodeRecursive(const char *name)
-{
-	if (strcmp(name, this->name) == 0) return this;
-	if (this->children != NULL)
-	{
-		ObjNode *help = this->children->getNodeRecursive(name);
-		if (help != NULL) return help;
-	}
-	if (this->next != NULL) return this->next->getNodeRecursive(name); else return NULL;
-}
-
-
-ObjNode *ObjNode::getNextChildNode(bool reset)
-{
-	if (reset) actual = this->children;
-	else if (actual == NULL) actual = this->children; else actual = actual->next;
-	return actual;	
-}
-
-
-ObjField *ObjNode::getField(const char *name)
-{
-	ObjField *help = fields;
-	while (help != NULL)
-	{
-		if (strcmp(name, help->name) == 0) return help;
-		help = help->next;
-	}
-	return NULL;
-}
-
-void *ObjNode::getField(const char *name, ObjType *typ, int *cnt)
-{
-	ObjField *help = fields;
-	while (help != NULL)
-	{
-		if (strcmp(name, help->name) == 0) 
-		{
-			*typ = help->typ;
-			*cnt = help->cnt;
-			return help->value;
-		}
-		help = help->next;
-	}
-	*typ = IV_INVALID;
-	*cnt = 0;
-	return NULL;
-}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjMeshData.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjMeshData.cpp	(revision 2111)
+++ 	(revision )
@@ -1,268 +1,0 @@
-#include "ObjMeshData.h"
-#include "ObjReader.h"
-
-
-ObjMeshData::ObjMeshData()
-{ 
-	vertices = normals = texCoords = indices = normalIndices = texCoordIndices = NULL; 
-	vcnt = ncnt = tcnt = icnt = nicnt = ticnt = 0;
-	roType = IV_ROT_INVALID;
-	boundingBox = NULL;
-}
-
-ObjMeshData::~ObjMeshData()
-{ 
-}
-
-void ObjMeshData::collapse()
-{
-	if (indices != NULL)	delete [] indices;
-	if (vertices != NULL)	delete [] vertices;
-	if (normals != NULL)	delete [] normals;
-	if (texCoords != NULL)	delete [] texCoords;
-	if (normalIndices != NULL) delete [] normalIndices;
-	if (texCoordIndices != NULL) delete [] texCoordIndices;
-	if (boundingBox != NULL) delete boundingBox;
-	indices = vertices = normals = texCoords = normalIndices = texCoords = NULL;
-	boundingBox = NULL;
-}
-
-int ObjMeshData::getSeparatorCnt(Ogre::Real *data, int end)
-{
-	int cnt = 0;
-	for (int i=0; i < end; i++) if (data[i] < 0.f) cnt++; 
-	return cnt;
-}
-
-Ogre::AxisAlignedBox *ObjMeshData::calcBoundingBox()
-{
-	if ((vertices == NULL) || (vcnt <=0)) 
-		return new Ogre::AxisAlignedBox(0, 0, 0, 0, 0, 0);
-
-	Ogre::Real x, y, z, minX, minY, minZ, maxX, maxY, maxZ;
-	minX = minY = minZ = 999999;
-	maxX = maxY = maxZ = -999999;
-	
-	for (int i=0; i<vcnt/3; i++) 
-	{
-		x = vertices[i*3];
-		if (minX > x) minX = x;	if (maxX < x) maxX = x;
-		y = vertices[i*3+1];
-		if (minY > y) minY = y;	if (maxY < y) maxY = y;
-		z = vertices[i*3+2];
-		if (minZ > z) minZ = z;	if (maxZ < z) maxZ = z;
-	}
-	
-	return new Ogre::AxisAlignedBox(minX, minY, minZ, maxX, maxY, maxZ);
-}
-
-
-Ogre::Real *ObjMeshData::expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut)
-{
-	if (indices[icnt-1] >= 0.0)
-		*icntOut = (icnt+1 - 3*(getSeparatorCnt(indices, icnt)+1))*3;
-	else
-		*icntOut = (icnt - 3*getSeparatorCnt(indices, icnt))*3;
-
-	Ogre::Real *indOut = new Ogre::Real[*icntOut];
-
-	int triangleCnt = 0, tc = 0;
-	for (int i=2; i < icnt; i++)
-	{
-		if (indices[i] >= 0)
-		{
-			if (tc % 2 == 0)
-			{
-				indOut[triangleCnt*3]   = indices[i-2]; 
-				indOut[triangleCnt*3+1] = indices[i-1];
-				indOut[triangleCnt*3+2] = indices[i];
-			}
-			else
-			{
-				indOut[triangleCnt*3]   = indices[i]; 
-				indOut[triangleCnt*3+1] = indices[i-1];
-				indOut[triangleCnt*3+2] = indices[i-2];
-			}
-			triangleCnt++; tc++;
-		}
-		else
-		{
-			i += 2; tc = 0;
-		}
-	}
-	return indOut;
-}	
-
-
-int ObjMeshData::getNextFaceSize(int start)
-{
-	for (int i=start; i < icnt; i++) 
-	{
-		if (indices[i] < 0.f) return i - start;
-	}
-	return icnt - start;
-}
-
-
-Ogre::Real *ObjMeshData::expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut)
-{
-	if (indices[icnt-1] >= 0.0)
-		*icntOut = (icnt+1 - 3*(getSeparatorCnt(indices, icnt)+1))*3;
-	else
-		*icntOut = (icnt - 3*getSeparatorCnt(indices, icnt))*3;
-	Ogre::Real *indOut = new Ogre::Real[*icntOut];
-
-	int index = 0, size = 0;
-	for (int i=0; i < icnt; i++)
-	{
-		if ((size = getNextFaceSize(i)) < 3) break;
-		for (int j=0; j < size-2; j++)
-		{
-			indOut[index] = indices[i]; index++;
-			indOut[index] = indices[i+1+j]; index++;
-			indOut[index] = indices[i+2+j]; index++;
-		}
-		i = i + size; 
-	}
-	return indOut;
-}
-
-ObjMeshData *ObjMeshData::expand()
-{
-	using namespace Ogre;
-
-	ObjMeshData *mDataOut = new ObjMeshData();
-
-	mDataOut->boundingBox = calcBoundingBox();
-	if ((vertices == NULL) || (vcnt <= 0) || (indices == NULL) || (icnt <= 0))
-	{
-		if (IVReader::IVLog != NULL)
-		{
-			std::string message = "Expand-Error: ((vertices == NULL) || (vcnt <= 0) || (indices == NULL) || (icnt <= 0))";
-			IVReader::IVLog->logMessage(message);
-		}
-	
-		return mDataOut;
-	}
-	bool nOk, tOk, niOk, tiOk, nperv, tperv;
-	nOk = ((normals != NULL) && (ncnt > 0));
-	tOk = ((texCoords != NULL) && (tcnt > 0));
-	nperv = (ncnt == vcnt) && (nicnt != icnt);
-	tperv = (tcnt*3 == vcnt*2) && (ticnt != icnt);
-
-	if ((nOk && !nperv) || (tOk && !tperv)) 
-	{
-		niOk = ((normalIndices != NULL) && (nicnt == icnt));
-		tiOk = ((texCoordIndices != NULL) && (ticnt == icnt));
-
-		if (!nperv && nOk && !niOk) nOk = false;
-		if (!tperv && tOk && !tiOk) tOk = false;
-
-		int sepcnt = getSeparatorCnt(indices, icnt);
-		mDataOut->icnt = icnt;
-		mDataOut->vcnt = (icnt - sepcnt)*3;
-		mDataOut->vertices = new Real[mDataOut->vcnt];
-
-		if (nOk) 
-		{
-			mDataOut->ncnt = mDataOut->vcnt;
-			mDataOut->normals = new Real[mDataOut->ncnt];
-		}
-		if (tOk)
-		{
-			mDataOut->tcnt = (icnt - sepcnt)*2;
-			mDataOut->texCoords = new Real[mDataOut->tcnt];
-		}
-		mDataOut->indices = new Real[mDataOut->icnt];
-
-		int index = 0;
-		for (int i=0; i < icnt; i++)
-		{
-			if (indices[i] >= 0.f)
-			{
-				mDataOut->vertices[index*3]   = vertices[(int)indices[i]*3];
-				mDataOut->vertices[index*3+1] = vertices[(int)indices[i]*3+1];
-				mDataOut->vertices[index*3+2] = vertices[(int)indices[i]*3+2];
-
-				if (nOk)
-				{
-					if (nperv)
-					{
-						mDataOut->normals[index*3]   = normals[(int)indices[i]*3];
-						mDataOut->normals[index*3+1] = normals[(int)indices[i]*3+1];
-						mDataOut->normals[index*3+2] = normals[(int)indices[i]*3+2];
-					}
-					else
-					{
-						mDataOut->normals[index*3]   = normals[(int)normalIndices[i]*3];
-						mDataOut->normals[index*3+1] = normals[(int)normalIndices[i]*3+1];
-						mDataOut->normals[index*3+2] = normals[(int)normalIndices[i]*3+2];
-					}
-				}
-				if (tOk)
-				{
-					if (tperv)
-					{
-						mDataOut->texCoords[index*2]   = texCoords[(int)indices[i]*2];
-						mDataOut->texCoords[index*2+1] = texCoords[(int)indices[i]*2+1];
-					}
-					else
-					{
-						mDataOut->texCoords[index*2]   = texCoords[(int)texCoordIndices[i]*2];
-						mDataOut->texCoords[index*2+1] = texCoords[(int)texCoordIndices[i]*2+1];
-					}
-				}
-
-				mDataOut->indices[i] = index;
-				index++;
-			}
-			else mDataOut->indices[i] = indices[i];
-		}
-	}
-	else
-	{
-		mDataOut->icnt = icnt;
-		mDataOut->indices = new Real[mDataOut->icnt];
-		memcpy(mDataOut->indices, indices, mDataOut->icnt*sizeof(Real));
-
-		mDataOut->vcnt = vcnt;
-		mDataOut->vertices = new Real[mDataOut->vcnt];
-		memcpy(mDataOut->vertices, vertices, mDataOut->vcnt*sizeof(Real));
-
-		if (nOk)
-		{
-			mDataOut->ncnt = ncnt;
-			mDataOut->normals = new Real[mDataOut->ncnt];
-			memcpy(mDataOut->normals, normals, mDataOut->ncnt*sizeof(Real));
-		}
-		if (tOk)
-		{
-			mDataOut->tcnt = tcnt;
-			mDataOut->texCoords = new Real[mDataOut->tcnt];
-			memcpy(mDataOut->texCoords, texCoords, mDataOut->tcnt*sizeof(Real));
-		}
-
-	}
-
-	int icntNew = 0;
-	Real *indicesNew = NULL;
-	mDataOut->roType = roType;
-
-	if (mDataOut->roType == IV_ROT_TRIANGLE_STRIP)	
-	{	
-		indicesNew = expandTriangleStripIndices(mDataOut->indices, mDataOut->icnt, &icntNew);
-	}
-	else if (mDataOut->roType == IV_ROT_FACE_SET)
-	{
-		indicesNew = expandFaceSetIndices(mDataOut->indices, mDataOut->icnt, &icntNew);
-	}
-	else 
-	{
-		return mDataOut;
-	}
-	delete [] mDataOut->indices;
-	mDataOut->indices = indicesNew;
-	mDataOut->icnt = icntNew;
-
-	return mDataOut;
-}
