Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 574)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 575)
@@ -13,7 +13,7 @@
 #;../data/vienna/vienna-plane.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
-#	filename ../data/atlanta/atlanta2.x3d
+	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
-	filename ../data/soda/soda5.dat
+#	filename ../data/soda/soda5.dat
 }
 
@@ -23,7 +23,7 @@
 	useGlRenderer false
 #	type sampling
-	type vss
-#	type rss
-	detectEmptyViewSpace true
+#	type vss
+	type rss
+	detectEmptyViewSpace false
 }
 
@@ -303,5 +303,5 @@
 	Termination {
 		# parameters used for autopartition
-		minRays 		300
+		minRays 		150
 		minPolygons 		-1
 		maxDepth		30
@@ -309,10 +309,10 @@
 		#minProbability		0.0001
 		minProbability 		-1
-		maxRayContribution	0.1
+		maxRayContribution	0.3
 		maxCostRatio		0.9
 		missTolerance		3
 		#maxAccRayLength	100
 		
-		maxViewCells		5000
+		maxViewCells		50000
 		
 		# used for pvs criterium
@@ -335,5 +335,5 @@
 	PostProcess {
 		maxCostRatio 0.1
-		minViewCells 110
+		minViewCells 5000
 		useRaysForMerge false
 		exportMergeStats false
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.h	(revision 508)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.h	(revision 575)
@@ -15,6 +15,5 @@
   //bool ParseFile(const string filename, ViewCellsManager &viewCells);
   bool ParseFile(const string filename, 
-				 VspBspTree *tree, 
-				 ViewCellsManager *viewCells,
+				 ViewCellsManager **viewCells,
 				 ObjectContainer *objects);
 };
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 574)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 575)
@@ -356,4 +356,6 @@
 class BspTree 
 {
+	friend class ViewCellsParseHandlers;
+
 public:
 	
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 574)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 575)
@@ -688,3 +688,13 @@
 };
 
+
+class ViewCellsManagerFactory
+{
+
+public:
+
+	ViewCellsManager *Create(const string mName);
+
+};
+
 #endif
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 574)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 575)
@@ -194,46 +194,5 @@
 	environment->GetStringValue("ViewCells.type", viewCellsStr);
 
-	int initialSamples = 0;
-	
-	if (strcmp(viewCellsStr, "kdTree") == 0)
-	{
-		mViewCellsManager = new KdViewCellsManager(mKdTree);
-	}
-	else if (strcmp(viewCellsStr, "bspTree") == 0)
-	{
-		mBspTree = new BspTree();
-
-		Debug << "view cell type: Bsp" << endl;
-
-		mViewCellsManager = new BspViewCellsManager(mBspTree);
-	}
-	else if (strcmp(viewCellsStr, "vspBspTree") == 0)
-	{
-		mVspBspTree = new VspBspTree();
-
-		Debug << "view cell type: VspBsp" << endl;
-
-		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
-	}
-	else if (strcmp(viewCellsStr, "vspKdTree") == 0)
-	{
-		mVspKdTree = new VspKdTree();		
-	
-		mViewCellsManager = new VspKdViewCellsManager(mVspKdTree);
-	}
-	else if (strcmp(viewCellsStr, "sceneDependent") == 0)
-	{
-		//TODO
-		mBspTree = new BspTree();
-
-		Debug << "view cell type: Bsp" << endl;
-		
-		mViewCellsManager = new BspViewCellsManager(mBspTree);
-	}
-	else
-	{
-		cerr<<"Wrong view cells type" << viewCellsStr << endl;
-		exit(1);
-	}
+	mViewCellsManager = CreateViewCellsManager(viewCellsStr);
 
 	float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0;
@@ -272,4 +231,51 @@
 
 	return true;
+}
+
+
+ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name)
+{
+	if (strcmp(name, "kdTree") == 0)
+	{
+		mViewCellsManager = new KdViewCellsManager(mKdTree);
+	}
+	else if (strcmp(name, "bspTree") == 0)
+	{
+		mBspTree = new BspTree();
+
+		Debug << "view cell type: Bsp" << endl;
+
+		mViewCellsManager = new BspViewCellsManager(mBspTree);
+	}
+	else if (strcmp(name, "vspBspTree") == 0)
+	{
+		mVspBspTree = new VspBspTree();
+
+		Debug << "view cell type: VspBsp" << endl;
+
+		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
+	}
+	else if (strcmp(name, "vspKdTree") == 0)
+	{
+		mVspKdTree = new VspKdTree();		
+	
+		mViewCellsManager = new VspKdViewCellsManager(mVspKdTree);
+	}
+	else if (strcmp(name, "sceneDependent") == 0)
+	{
+		//TODO
+		mBspTree = new BspTree();
+
+		Debug << "view cell type: Bsp" << endl;
+		
+		mViewCellsManager = new BspViewCellsManager(mBspTree);
+	}
+	else
+	{
+		cerr<<"Wrong view cells type" << name << endl;
+		exit(1);
+	}
+
+	return mViewCellsManager;
 }
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParserXerces.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParserXerces.h	(revision 508)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParserXerces.h	(revision 575)
@@ -14,4 +14,5 @@
 
 class VspBspTree;
+class BspTree;
 class ViewCellsManager;
 
@@ -22,6 +23,5 @@
   //  Constructors and Destructor
   // -----------------------------------------------------------------------
-  ViewCellsParseHandlers(VspBspTree *tree, 
-						 ViewCellsManager *viewCellsManager,
+  ViewCellsParseHandlers(ViewCellsManager **viewCellsManager,
 						 ObjectContainer *objects);
   ~ViewCellsParseHandlers();
@@ -61,5 +61,10 @@
   void resetDocument();
 
+  void CreateViewCellsManager(const char *name);
+
+
   VspBspTree *mVspBspTree;
+  BspTree *mBspTree;
+  
   BspNode *mCurrentNode;
   ViewCellContainer mViewCells;
@@ -68,11 +73,14 @@
 
   // Handlers for X3D
-  void StartLeaf(AttributeList& attributes);
-  void StartInterior(AttributeList& attributes);
-  void EndInterior();
+  void StartBspLeaf(AttributeList& attributes);
+  void StartBspInterior(AttributeList& attributes);
+  void EndBspInterior();
  
   void StartViewCell(AttributeList&  attributes);
   void EndViewCells();
 
+  void StartHierarchy(AttributeList& attributes);
+
+  void startBspElement(string element, AttributeList& attributes);
   // -----------------------------------------------------------------------
   //  Handlers for the SAX ErrorHandler interface
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 573)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 575)
@@ -121,4 +121,6 @@
 	  VssRayContainer &vssRays) {};
 
+  ViewCellsManager *CreateViewCellsManager(const char *name);
+
   /// scene graph loaded from file
   SceneGraph *mSceneGraph;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.cpp	(revision 556)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.cpp	(revision 575)
@@ -61,6 +61,5 @@
 //  StdInParseHandlers: Constructors and Destructor
 // ---------------------------------------------------------------------------
-ViewCellsParseHandlers::ViewCellsParseHandlers(VspBspTree *tree,
-											   ViewCellsManager *viewCells,
+ViewCellsParseHandlers::ViewCellsParseHandlers(ViewCellsManager **viewCells,
 											   ObjectContainer *objects):
   mElementCount(0)
@@ -69,9 +68,9 @@
   , mSpaceCount(0)
 {
-	mVspBspTree = tree;
-	mCurrentNode = tree->GetRoot();
-	mViewCellsManager = viewCells;
 	mObjects = objects;
-}
+	viewCells = &mViewCellsManager;
+	//mPreprocessor = preprocessor;
+}
+
 
 ViewCellsParseHandlers::~ViewCellsParseHandlers()
@@ -90,5 +89,5 @@
   string element(lname.LocalForm());
   if (element == "Interior")
-	  EndInterior();
+	  EndBspInterior();
   if (element == "ViewCells")
 	  EndViewCells();
@@ -96,5 +95,5 @@
 
 
-void ViewCellsParseHandlers::EndInterior()
+void ViewCellsParseHandlers::EndBspInterior()
 {
 	// go one up in the tree
@@ -114,6 +113,49 @@
 void ViewCellsParseHandlers::EndViewCells()
 {
-	// sort view cells for easily finding id
+	// sort view cells to help associating view cells according to their id
 	stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
+}
+
+
+
+void ViewCellsParseHandlers::StartHierarchy(AttributeList&  attributes)
+{
+	int len = attributes.getLength();
+  
+	for (int i = 0; i < len; ++ i) 
+	{
+		string attrName(StrX(attributes.getName(i)).LocalForm());
+		
+		if (attrName == "name") 
+		{
+			StrX attrValue(attributes.getValue(i));
+			
+			const char *ptr = attrValue.LocalForm();
+			
+			CreateViewCellsManager(ptr);
+		}
+	}
+}
+
+
+void ViewCellsParseHandlers::startBspElement(string element,
+											 AttributeList& attributes)
+{
+	if (element == "ViewCell")
+	{
+		cout << "v";
+		StartViewCell(attributes);
+	}
+
+	if (element == "Interior") 
+	{
+		cout << "[";
+		StartBspInterior(attributes);
+	}
+
+	if (element == "Leaf") 
+	{
+		StartBspLeaf(attributes);
+	}
 }
 
@@ -125,21 +167,23 @@
 	string element(lname.LocalForm());
 	
-	if (element == "ViewCell")
-	{
-		cout << "v";
-		StartViewCell(attributes);
-	}
-
-	if (element == "Interior") 
-	{
-		cout << "[";
-		StartInterior(attributes);
-	}
-
-	if (element == "Leaf") 
-	{
-		StartLeaf(attributes);
-	}
-
+	if (element == "Hierarchy")
+	{
+		cout << "h";
+		StartHierarchy(attributes);
+	}
+
+	switch (mViewCellsManager->GetType())
+	{
+	case ViewCellsManager::BSP:
+	case ViewCellsManager::VSP_BSP:
+		startBspElement(element, attributes);
+		break;
+	
+	default:
+		Debug << "not implemented" << endl;
+		break;
+
+	}
+	
 	++ mElementCount;
 	mAttrCount += attributes.getLength();
@@ -228,5 +272,5 @@
 
 
-void ViewCellsParseHandlers::StartLeaf(AttributeList& attributes)
+void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes)
 {
 	BspLeaf * leaf = 
@@ -239,5 +283,8 @@
 	else
 	{
-		mVspBspTree->mRoot = leaf;
+		if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
+			mBspTree->mRoot = leaf;
+		else
+			mVspBspTree->mRoot = leaf;
 	}
 
@@ -282,12 +329,15 @@
 	else
 	{
-		leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
-		leaf->SetTreeValid(false);
-		mVspBspTree->PropagateUpValidity(leaf);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartInterior(AttributeList& attributes)
+		if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
+		{
+			leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
+			leaf->SetTreeValid(false);
+			mVspBspTree->PropagateUpValidity(leaf);
+		}
+	}
+}
+
+
+void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes)
 {
 	Plane3 plane;
@@ -318,8 +368,48 @@
 	else
 	{
-		mVspBspTree->mRoot = interior;
+		if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
+			mBspTree->mRoot = interior;
+		else
+			mVspBspTree->mRoot = interior;
 	}
 
 	mCurrentNode = interior;
+}
+
+
+
+void ViewCellsParseHandlers::CreateViewCellsManager(const char *name)
+{
+	
+	if (strcmp(name, "bspTree") == 0)
+	{
+		mBspTree = new BspTree();
+
+		Debug << "view cell type: Bsp" << endl;
+
+		mCurrentNode = mBspTree->GetRoot();
+
+		mViewCellsManager = new BspViewCellsManager(mBspTree);
+	}
+	else if (strcmp(name, "vspBspTree") == 0)
+	{
+		mVspBspTree = new VspBspTree();
+
+		Debug << "view cell type: VspBsp" << endl;
+		mCurrentNode = mVspBspTree->GetRoot();
+
+		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
+	}
+	/*else if (strcmp(name, "vspKdTree") == 0)
+	{
+		mVspKdTree = new VspKdTree();		
+	
+		mViewCellsManager = VspKdViewCellsManager(mVspKdTree);
+	}*/
+	else
+	{
+		cerr<<"Wrong view cells type" << name << endl;
+		exit(1);
+	}
 }
 
@@ -380,6 +470,5 @@
 
 bool ViewCellsParser::ParseFile(const string filename, 
-								VspBspTree *tree,
-								ViewCellsManager *viewCells,
+								ViewCellsManager **viewCells,
 								ObjectContainer *objects)
 {
@@ -414,5 +503,5 @@
   //  to do.
   //
-  ViewCellsParseHandlers handler(tree, viewCells, objects);
+  ViewCellsParseHandlers handler(viewCells, objects);
   parser->setDocumentHandler(&handler);
   parser->setErrorHandler(&handler);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 574)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 575)
@@ -126,6 +126,6 @@
 	//-- construction rays => we use uniform samples for this
 	CastPassSamples(mInitialSamples, 
-					Preprocessor::DIRECTION_BASED_DISTRIBUTION,
-					//Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
+					//Preprocessor::DIRECTION_BASED_DISTRIBUTION,
+					Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
 					initialSamples);
 	
@@ -157,5 +157,5 @@
 				 		Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION;
 
-		dirSamples = !dirSamples; // toggle sampling
+		dirSamples = !dirSamples; // toggle sampling method
 		numSamples += CastPassSamples(mSamplesPerPass, 
 									  samplingType,
@@ -2679,5 +2679,5 @@
 	mVspBspTree = new VspBspTree();
 
-	bool success = parser.ParseFile(filename, mVspBspTree, this, objects);
+	bool success ;//= parser.ParseFile(filename, &this, objects);
 	mVspBspTree->RepairViewCellsLeafLists();
 	mVspBspTree->mBox = GetViewSpaceBox();
@@ -2764,2 +2764,10 @@
 	viewCell->SetArea(area);
 }
+
+
+
+ViewCellsManager *ViewCellsManagerFactory::Create(const string mName)
+{
+	//TODO
+	return NULL;// new VspBspViewCellsManager();
+}
