Index: Damkjer/Damkjer_Research.sln
===================================================================
--- Damkjer/Damkjer_Research.sln	(revision 9)
+++ Damkjer/Damkjer_Research.sln	(revision 9)
@@ -0,0 +1,103 @@
+﻿
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Util", "Util", "{27DB8DBD-623B-4593-80F3-9F25F07BBA1A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SpatialIndexing", "SpatialIndexing", "{3411130C-FC3A-47AD-9277-EEA9BDA15D28}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VpTreeAPI", "Util\SpatialIndexing\VpTree\VpTreeAPI.vcxproj", "{2738EE40-D034-9113-3C3F-2AD5946B372D}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Util", "Util\Util.vcxproj", "{20FE2624-C64F-D61A-BD8F-1725A8E68A42}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3093F2E8-7C3B-4B90-8E92-C0C235FB979A}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_TestCase", "Util\UnitTest\test\TestUnitTest.vcxproj", "{72785A79-5BD2-AAE4-6386-93F74C7E248D}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_Exception", "Util\Exception\test\TestException.vcxproj", "{75486221-5693-30A9-18E4-ECC307F92A68}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_Metrics", "Util\SpatialIndexing\Metrics\test\TestMetrics.vcxproj", "{FF08AA20-7D15-AEAB-9915-1FA343E8C993}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		OpenMP|Win32 = OpenMP|Win32
+		OpenMP|x64 = OpenMP|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Debug|Win32.ActiveCfg = Debug|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Debug|Win32.Build.0 = Debug|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Debug|x64.ActiveCfg = Debug|x64
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Debug|x64.Build.0 = Debug|x64
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.OpenMP|Win32.ActiveCfg = OpenMP|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.OpenMP|Win32.Build.0 = OpenMP|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.OpenMP|x64.ActiveCfg = OpenMP|x64
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.OpenMP|x64.Build.0 = OpenMP|x64
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Release|Win32.ActiveCfg = Release|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Release|Win32.Build.0 = Release|Win32
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Release|x64.ActiveCfg = Release|x64
+		{2738EE40-D034-9113-3C3F-2AD5946B372D}.Release|x64.Build.0 = Release|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Debug|Win32.ActiveCfg = Debug|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Debug|Win32.Build.0 = Debug|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Debug|x64.ActiveCfg = Debug|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Debug|x64.Build.0 = Debug|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.OpenMP|Win32.ActiveCfg = OpenMP|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.OpenMP|Win32.Build.0 = OpenMP|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.OpenMP|x64.ActiveCfg = OpenMP|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.OpenMP|x64.Build.0 = OpenMP|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Release|Win32.ActiveCfg = Release|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Release|Win32.Build.0 = Release|Win32
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Release|x64.ActiveCfg = Release|x64
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42}.Release|x64.Build.0 = Release|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Debug|Win32.ActiveCfg = Debug|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Debug|Win32.Build.0 = Debug|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Debug|x64.ActiveCfg = Debug|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Debug|x64.Build.0 = Debug|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.OpenMP|Win32.ActiveCfg = OpenMP|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.OpenMP|Win32.Build.0 = OpenMP|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.OpenMP|x64.ActiveCfg = OpenMP|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.OpenMP|x64.Build.0 = OpenMP|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Release|Win32.ActiveCfg = Release|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Release|Win32.Build.0 = Release|Win32
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Release|x64.ActiveCfg = Release|x64
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D}.Release|x64.Build.0 = Release|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Debug|Win32.ActiveCfg = Debug|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Debug|Win32.Build.0 = Debug|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Debug|x64.ActiveCfg = Debug|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Debug|x64.Build.0 = Debug|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.OpenMP|Win32.ActiveCfg = OpenMP|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.OpenMP|Win32.Build.0 = OpenMP|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.OpenMP|x64.ActiveCfg = OpenMP|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.OpenMP|x64.Build.0 = OpenMP|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Release|Win32.ActiveCfg = Release|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Release|Win32.Build.0 = Release|Win32
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Release|x64.ActiveCfg = Release|x64
+		{75486221-5693-30A9-18E4-ECC307F92A68}.Release|x64.Build.0 = Release|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Debug|Win32.ActiveCfg = Debug|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Debug|Win32.Build.0 = Debug|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Debug|x64.ActiveCfg = Debug|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Debug|x64.Build.0 = Debug|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.OpenMP|Win32.ActiveCfg = OpenMP|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.OpenMP|Win32.Build.0 = OpenMP|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.OpenMP|x64.ActiveCfg = OpenMP|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.OpenMP|x64.Build.0 = OpenMP|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Release|Win32.ActiveCfg = Release|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Release|Win32.Build.0 = Release|Win32
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Release|x64.ActiveCfg = Release|x64
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(NestedProjects) = preSolution
+		{3411130C-FC3A-47AD-9277-EEA9BDA15D28} = {27DB8DBD-623B-4593-80F3-9F25F07BBA1A}
+		{3093F2E8-7C3B-4B90-8E92-C0C235FB979A} = {27DB8DBD-623B-4593-80F3-9F25F07BBA1A}
+		{20FE2624-C64F-D61A-BD8F-1725A8E68A42} = {27DB8DBD-623B-4593-80F3-9F25F07BBA1A}
+		{2738EE40-D034-9113-3C3F-2AD5946B372D} = {3411130C-FC3A-47AD-9277-EEA9BDA15D28}
+		{72785A79-5BD2-AAE4-6386-93F74C7E248D} = {3093F2E8-7C3B-4B90-8E92-C0C235FB979A}
+		{75486221-5693-30A9-18E4-ECC307F92A68} = {3093F2E8-7C3B-4B90-8E92-C0C235FB979A}
+		{FF08AA20-7D15-AEAB-9915-1FA343E8C993} = {3093F2E8-7C3B-4B90-8E92-C0C235FB979A}
+	EndGlobalSection
+EndGlobal
Index: Damkjer/PointProcessing/SpatialAnalyzer/spanalyze.m
===================================================================
--- Damkjer/PointProcessing/SpatialAnalyzer/spanalyze.m	(revision 7)
+++ Damkjer/PointProcessing/SpatialAnalyzer/spanalyze.m	(revision 9)
@@ -17,6 +17,4 @@
 userParams = parseInputs(varargin{:});
 
-% disp(userParams);
-
 dimensions=size(QUERIES, 1);
 elements=size(QUERIES, 2);
@@ -33,8 +31,7 @@
 h = timebar(1, elements, msg, tstart);
 
+%step=8192;
 step=1000;
 tic;
-
-% maxnbrs = 0;
 
 for elem=1:step:elements
@@ -77,12 +74,5 @@
          cells{n}=QUERIES(:,NN{n})';
       end
- 
-%      covs=cell(1,length(cells));
-%      
-%      parfor n=1:length(cells)
-%         covs{n}=cov(cells{n}');
-%      end
-      
-%      [covs,bias,inty]=fastcov(cellfun(@(x) QUERIES(:,x)',NN,'UniformOutput',false));
+
       [covs,bias,inty]=fastcov(cells);
    elseif (~isempty(userParams.counts))
@@ -95,8 +85,17 @@
       
       for c=1:length(userParams.counts)
-         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cellfun(@(x) QUERIES(:,x(1:userParams.counts(c)))',NN,'UniformOutput',false));
+         cells=cell(1,length(NN));
+         
+         for n=1:length(NN)
+            cells{n}=QUERIES(:,NN{n}(1:userParams.counts(c)))';
+         end
+         
+         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cells);
+         
+%         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cellfun(@(x) QUERIES(:,x(1:userParams.counts(c)))',NN,'UniformOutput',false));
 
          for nbr=1:size(NN,1)
-            [~,D]=eig(tempcovs{c}{nbr});
+%            [~,D]=eig(tempcovs{c}{nbr});
+            [~,D]=par_eig(tempcovs{c}{nbr});
             tempfeats(:,nbr)=sort(diag(D),'descend');
          end
@@ -128,29 +127,23 @@
       
       for c=1:length(userParams.steps)
-%          disp('userParams.steps(c)');
-%          disp(userParams.steps(c));
-
-%          disp('NN');
-%          disp(NN);
-         
-%          disp('DISTS');
-%          disp(DISTS);
-         
-%          disp('DISTS <= userParams.steps(c)');
-%          cellfun(@(x) disp(x <= userParams.steps(c))',DISTS,'UniformOutput',false);
-
-         nbrs=cellfun(@(x) sum(x <= userParams.steps(c))',DISTS,'UniformOutput',false);
-         
-%          disp('NN(DISTS <= userParams.steps(c))');
-%          cellfun(@(x,y) disp(x(y <= userParams.steps(c))'),NN,DISTS,'UniformOutput',false)
-         
-%          disp('QUERIES(:,NN(DISTS <= userParams.steps(c)))');
-%          cellfun(@(x,y) disp(QUERIES(:,x(y <= userParams.steps(c)))'),NN,DISTS,'UniformOutput',false)
-
-         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cellfun(@(x,y) QUERIES(:,x(y <= userParams.steps(c)))',NN,DISTS,'UniformOutput',false));
-
-%          disp('tempcovs{c}');
-%          cellfun(@(x) disp(x), tempcovs{c});
-         
+
+         nbrs=cell(1,length(DISTS));
+         
+         for n=1:length(DISTS)
+            nbrs{n}=sum(DISTS{n} <= userParams.steps(c))';
+         end
+         
+%         nbrs=cellfun(@(x) sum(x <= userParams.steps(c))',DISTS,'UniformOutput',false);
+
+         cells=cell(1,length(NN));
+         
+         for n=1:length(NN)
+            cells{n}=QUERIES(:,NN{n}(DISTS{n} <= userParams.steps(c)))';
+         end
+
+%         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cellfun(@(x,y) QUERIES(:,x(y <= userParams.steps(c)))',NN,DISTS,'UniformOutput',false));
+
+         [tempcovs{c},tempbias{c},tempinty{c}]=fastcov(cells);
+
          for nbr=1:size(NN,1)
             if (nbrs{nbr}<5)
@@ -158,10 +151,8 @@
             end
 
-            [~,D]=eig(tempcovs{c}{nbr});
+%            [~,D]=eig(tempcovs{c}{nbr});
+            [~,D]=par_eig(tempcovs{c}{nbr});
             tempfeats(:,nbr)=sort(diag(D),'descend');
          end
-
-%          disp('tempfeats');
-%          disp(tempfeats);
 
          % Compute dimensional degree
@@ -180,7 +171,4 @@
          tempde(c,:)=-sum(tempalpha.*log(tempalpha))./log(dimensions);
       end
-
-%       disp('tempde');
-%       disp(tempde);
 
       [~,ind]=nanmin(tempde);
Index: Damkjer/Util/Exception/Exception.cpp
===================================================================
--- Damkjer/Util/Exception/Exception.cpp	(revision 9)
+++ Damkjer/Util/Exception/Exception.cpp	(revision 9)
@@ -0,0 +1,325 @@
+//*****************************************************************************
+// FILE:        Exception.cpp
+//
+//    Copyright (C)  2012 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-27  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include <iostream>
+#include <sstream>
+
+#include "Exception.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// Exception::~Exception
+//*****************************************************************************
+Util_API Exception::~Exception() throw()
+{
+}
+
+//*****************************************************************************
+// Exception::what
+//*****************************************************************************
+Util_API const char* Exception::what() const throw()
+{
+   if (theMsg.empty())
+   {
+      std::ostringstream oss;
+      message(oss);
+      theMsg = oss.str();
+   }
+
+   return theMsg.c_str();
+}
+
+//*****************************************************************************
+// Exception::message
+//*****************************************************************************
+Util_API std::ostream& Exception::message(std::ostream& os) const
+{
+   os << "-- " << type() << " --\n";
+
+   insertReason(os);
+
+   os << "\n(" << who()
+      << ", \"" << file() << "\""
+      << ", line " << line() << ")\n";
+
+   return os;
+}
+
+//*****************************************************************************
+// Exception::push
+//*****************************************************************************
+Util_API void Exception::push(const std::string& who,
+                     const std::string& file,
+                     const int          line) const
+{
+   std::ostringstream os;
+   os << who << " (\"" << file << "\"" << ", line " << line << ")";
+   theStack.push_back(os.str());
+}
+ 
+//*****************************************************************************
+// Exception::stackTrace
+//*****************************************************************************
+Util_API std::ostream& Exception::stackTrace(std::ostream& os) const
+{
+   if (theStack.empty()) return os;
+
+   os << "\nStack Trace:";
+//   os << "\nStack Trace:";
+
+//   BlockIndent block(79, os);
+//   block.indentBy(3);
+
+   for (std::vector<std::string>::const_iterator vsi = theStack.begin();
+        vsi != theStack.end();
+        ++vsi)
+   {
+//      block << "\n" << *vsi;
+      os << "\n" << *vsi;
+   }
+
+//   block << "\n";
+   os << "\n";
+
+   return os;
+}
+
+//*****************************************************************************
+// Exception::Exception
+//*****************************************************************************
+Util_API Exception::Exception(const std::string& why,
+                     const std::string& who,
+                     const std::string& file,
+                     int                line)
+   : theWhy(why)
+   , theWho(who)
+   , theFile(file)
+   , theLine(line)
+{
+}
+
+//*****************************************************************************
+// Exception::insertReason
+//*****************************************************************************
+Util_API std::ostream& Exception::insertReason(std::ostream& os) const
+{
+   return os << "\n" << theWhy << "\n";
+}
+
+//*****************************************************************************
+// LogicError::LogicError
+//*****************************************************************************
+LogicError::LogicError(const std::string& why,
+                       const std::string& who,
+                       const std::string& file,
+                       int                line)
+   : Exception(why, who, file, line)
+   , std::logic_error("")
+{
+}
+
+//*****************************************************************************
+// LogicError::what
+//*****************************************************************************
+const char* LogicError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// DomainError::DomainError
+//*****************************************************************************
+DomainError::DomainError(const std::string& why,
+                         const std::string& who,
+                         const std::string& file,
+                         int                line)
+   : LogicError(why, who, file, line)
+   , std::domain_error("")
+{
+}
+
+//*****************************************************************************
+// DomainError::what
+//*****************************************************************************
+const char* DomainError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// InvalidArgument::InvalidArgument
+//*****************************************************************************
+InvalidArgument::InvalidArgument(const std::string& why,
+                                 const std::string& who,
+                                 const std::string& file,
+                                 int                line)
+   : LogicError(why, who, file, line)
+   , std::invalid_argument("")
+{
+}
+
+//*****************************************************************************
+// InvalidArgument::what
+//*****************************************************************************
+const char* InvalidArgument::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// LengthError::LengthError
+//*****************************************************************************
+LengthError::LengthError(const std::string& why,
+                         const std::string& who,
+                         const std::string& file,
+                         int                line)
+   : LogicError(why, who, file, line)
+   , std::length_error("")
+{
+}
+
+//*****************************************************************************
+// LengthError::what
+//*****************************************************************************
+const char* LengthError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// OutOfRange::OutOfRange
+//*****************************************************************************
+OutOfRange::OutOfRange(const std::string& why,
+                       const std::string& who,
+                       const std::string& file,
+                       int                line)
+   : LogicError(why, who, file, line)
+   , std::out_of_range("")
+{
+}
+
+//*****************************************************************************
+// OutOfRange::what
+//*****************************************************************************
+const char* OutOfRange::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// RethrowError::RethrowError
+//*****************************************************************************
+RethrowError::RethrowError(const std::exception& thrown,
+                                    const std::string& who,
+                                    const std::string& file,
+                                    int line)
+   : DomainError((*thrown.what() != '\0' ? thrown.what()
+                                         : typeid(thrown).name()),
+                 who, file, line)
+{
+}
+
+//*****************************************************************************
+// RuntimeError::RuntimeError
+//*****************************************************************************
+RuntimeError::RuntimeError(const std::string& why,
+                           const std::string& who,
+                           const std::string& file,
+                           int                line)
+   : Exception(why, who, file, line)
+   , std::runtime_error("")
+{
+}
+
+//*****************************************************************************
+// RuntimeError::what
+//*****************************************************************************
+const char* RuntimeError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// RangeError::RangeError
+//*****************************************************************************
+RangeError::RangeError(const std::string& why,
+                       const std::string& who,
+                       const std::string& file,
+                       int                line)
+   : RuntimeError(why, who, file, line)
+   , std::range_error("")
+{
+}
+
+//*****************************************************************************
+// RangeError::what
+//*****************************************************************************
+const char* RangeError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// OverflowError::OverflowError
+//*****************************************************************************
+OverflowError::OverflowError(const std::string& why,
+                             const std::string& who,
+                             const std::string& file,
+                             int                line)
+   : RuntimeError(why, who, file, line)
+   , std::overflow_error("")
+{
+}
+
+//*****************************************************************************
+// OverflowError::what
+//*****************************************************************************
+const char* OverflowError::what() const throw()
+{
+   return Exception::what();
+}
+
+//*****************************************************************************
+// UnderflowError::UnderflowError
+//*****************************************************************************
+UnderflowError::UnderflowError(const std::string& why,
+                               const std::string& who,
+                               const std::string& file,
+                               int                line)
+   : RuntimeError(why, who, file, line)
+   , std::underflow_error("")
+{
+}
+
+//*****************************************************************************
+// UnderflowError::what
+//*****************************************************************************
+const char* UnderflowError::what() const throw()
+{
+   return Exception::what();
+}
+
+}
+
+//*****************************************************************************
+// ::operator<<
+//*****************************************************************************
+//Util_API std::ostream& operator<<(std::ostream& os,
+//                                  const Damkjer::Exception& e)
+//{
+//   return os << e.what();
+//}
Index: Damkjer/Util/Exception/Exception.h
===================================================================
--- Damkjer/Util/Exception/Exception.h	(revision 9)
+++ Damkjer/Util/Exception/Exception.h	(revision 9)
@@ -0,0 +1,456 @@
+//*****************************************************************************
+// FILE:        Exception.h
+//
+//    Copyright (C)  2012 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-27  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef Exception_HEADER
+#define Exception_HEADER
+
+#include <typeinfo>
+#include <exception>
+#include <stdexcept>
+#include <vector>
+#include <string>
+
+#include "Util/UtilAPI.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// CLASS: Exception
+//> Exception objects allow for detailed, robust handling of errors and
+//  exceptional circumstances encountered in programs. This class, and its
+//  derivatives, intnentionally mirror the C++ Standard Library exception
+//  classes. They also provide for standardized message formatting and stack
+//  trace aggregation through convenience macros.
+//
+//  The implemented exceptions that parallel the C++ Standard Library are:
+//
+//- Exception                ->     std::exception
+//-    LogicError            ->        std::logic_error
+//-       DomainError        ->           std::domain_error
+//-       InvalidArgument    ->           std::invalid_argument
+//-       LengthError        ->           std::length_error
+//-       OutOfRange         ->           std::out_of_range
+//-    RuntimeError          ->        std::runtime_error
+//-       RangeError         ->           std::range_error
+//-       OverflowError      ->           std::overflow_error
+//-       UnderflowError     ->           std::underflow_error
+//<
+//*****************************************************************************
+class Exception
+{
+public:
+   Util_API virtual ~Exception() throw();
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw() = 0;
+      //>
+      //<
+
+   Util_API virtual std::ostream& message(std::ostream&) const;
+      //>
+      //<
+
+   Util_API void push(const std::string&,
+             const std::string&,
+             const int) const;
+      //>
+      //<
+
+   Util_API std::ostream& stackTrace(std::ostream&) const;
+      //>
+      //<
+
+   Util_API const std::string& type() const {
+      if (theTypeID.empty())
+      {
+         theTypeID = typeid(*this).name();
+      }
+      return theTypeID;
+   }
+   Util_API const std::string& why()  const { return theWhy; }
+   Util_API const std::string& who()  const { return theWho; }
+   Util_API const std::string& file() const { return theFile; }
+   Util_API const int          line() const { return theLine; }
+
+protected:
+   Util_API Exception(const std::string&,
+             const std::string&,
+             const std::string&,
+             int);
+      //>
+      //<
+
+   Util_API virtual std::ostream& insertReason(std::ostream&) const;
+      //>
+      //<
+
+private:
+   mutable std::string theTypeID;
+   std::string theWhy;
+   std::string theWho;
+   std::string theFile;
+   int         theLine;
+
+   mutable std::string theMsg;
+
+   mutable std::vector<std::string> theStack;
+};
+
+//*****************************************************************************
+// CLASS: LogicError
+//> 
+//<
+//*****************************************************************************
+class LogicError : public Exception,
+                   public std::logic_error
+{
+public:
+   Util_API LogicError(const std::string&,
+              const std::string&,
+              const std::string&,
+              int);
+      //>
+      //<
+
+   Util_API virtual ~LogicError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: DomainError
+//>
+//<
+//*****************************************************************************
+class DomainError : public LogicError,
+                    public std::domain_error
+{
+public:
+   Util_API DomainError(const std::string&,
+               const std::string&,
+               const std::string&,
+               int);
+      //>
+      //<
+
+   Util_API virtual ~DomainError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: InvalidArgument
+//>
+//<
+//*****************************************************************************
+class InvalidArgument : public LogicError,
+                                 public std::invalid_argument
+{
+public:
+   Util_API InvalidArgument(const std::string&,
+                   const std::string&,
+                   const std::string&,
+                   int);
+      //>
+      //<
+
+   Util_API virtual ~InvalidArgument() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: LengthError
+//>
+//<
+//*****************************************************************************
+class LengthError : public LogicError,
+                             public std::length_error
+{
+public:
+   Util_API LengthError(const std::string&,
+               const std::string&,
+               const std::string&,
+               int);
+      //>
+      //<
+
+   Util_API virtual ~LengthError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: OutOfRange
+//>
+//<
+//*****************************************************************************
+class OutOfRange : public LogicError,
+                            public std::out_of_range
+{
+public:
+   Util_API OutOfRange(const std::string&,
+              const std::string&,
+              const std::string&,
+              int);
+      //>
+      //<
+
+   Util_API virtual ~OutOfRange() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: RethrowError
+//>
+//<
+//*****************************************************************************
+class RethrowError : public DomainError
+{
+public:
+   Util_API RethrowError(const std::exception&,
+                const std::string&,
+                const std::string&,
+                int);
+      //> This constructor is used to wrap a std::exception as a
+      //  Damkjer::Exception for the purpose of rethrowing. The what()
+      //  portion of the std::exception is reported in the what()
+      //  of the RethrowError.
+      //<
+
+   Util_API RethrowError(const Damkjer::Exception& thrown,
+                const std::string&        extraReason,
+                const std::string&        who,
+                const std::string&        file,
+                int                       line)
+      : DomainError(thrown.why() + " " + extraReason, who, file, line)
+   {
+   }
+      //> This constructor is used to add an extra reason to a
+      //  Damkjer::Exception for the purpose of rethrowing.
+      //<
+
+   Util_API RethrowError(const std::string& why,
+                const std::string& who,
+                const std::string& file,
+                int                line)
+      : DomainError(why, who, file, line)
+   {
+   }
+      //> This constructor is used to wrap a string as a
+      //  Damkjer::Exception for the purpose of rethrowing. The what()
+      //  portion of the std::exception is reported in the what()
+      //  of the RethrowError.
+      //<
+
+   Util_API RethrowError(const std::string& who,
+                const std::string& file,
+                int                line)
+      : DomainError("Unknown error", who, file, line)
+   {
+   }
+      //> This constructor is used to wrap an unknown exception as a
+      //  Damkjer::Exception for the purpose of rethrowing. The message
+      //  "Unknown error" is reported in the what() of the RethrowError.
+      //<
+};
+
+//*****************************************************************************
+// CLASS: RuntimeError
+//>
+//<
+//*****************************************************************************
+class RuntimeError : public Exception,
+                              public std::runtime_error
+{
+public:
+   Util_API RuntimeError(const std::string&,
+                const std::string&,
+                const std::string&,
+                int);
+      //>
+      //<
+
+   Util_API virtual ~RuntimeError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: RangeError
+//>
+//<
+//*****************************************************************************
+class RangeError : public RuntimeError,
+                            public std::range_error
+{
+public:
+   Util_API RangeError(const std::string&,
+              const std::string&,
+              const std::string&,
+              int);
+      //>
+      //<
+
+   Util_API virtual ~RangeError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: OverflowError
+//>
+//<
+//*****************************************************************************
+class OverflowError : public RuntimeError,
+                               public std::overflow_error
+{
+public:
+   Util_API OverflowError(const std::string&,
+                 const std::string&,
+                 const std::string&,
+                 int);
+      //>
+      //<
+
+   Util_API virtual ~OverflowError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CLASS: UnderflowError
+//>
+//<
+//*****************************************************************************
+class UnderflowError : public RuntimeError,
+                                public std::underflow_error
+{
+public:
+   Util_API UnderflowError(const std::string&,
+                  const std::string&,
+                  const std::string&,
+                  int);
+      //>
+      //<
+
+   Util_API virtual ~UnderflowError() throw() {}
+      //>
+      //<
+
+   Util_API virtual const char* what() const throw();
+      //>
+      //<
+};
+
+}
+
+Util_API inline std::ostream& operator<<(std::ostream& os, const Damkjer::Exception& e)
+{
+   return os << e.what();
+}
+
+//*****************************************************************************
+// MACRO: EXCEPTION_TRY
+//>
+//<
+//*****************************************************************************
+#define EXCEPTION_TRY(MODULE_NAME) \
+static const char* const MODULE = MODULE_NAME; \
+try \
+{
+
+//*****************************************************************************
+// MACRO: EXCEPTION_RETHROW
+//>
+//<
+//*****************************************************************************
+#define EXCEPTION_RETHROW \
+} \
+catch (const Damkjer::Exception& e) \
+{ \
+   e.push(MODULE, __FILE__, __LINE__); \
+   throw; \
+} \
+catch (const std::exception& e) \
+{ \
+   throw RethrowError(e, MODULE, __FILE__, __LINE__); \
+} \
+catch (...) \
+{ \
+   throw RethrowError(MODULE, __FILE__, __LINE__); \
+}
+
+//*****************************************************************************
+// MACRO: EXCEPTION_CATCHALL
+//>
+//<
+//*****************************************************************************
+#define EXCEPTION_CATCHALL \
+} \
+catch (const Damkjer::Exception& e) \
+{ \
+   e.push(MODULE, __FILE__, __LINE__); \
+   std::cerr << e; \
+   e.stackTrace(std::cerr); \
+   return EXIT_FAILURE; \
+} \
+catch (const std::exception& e) \
+{ \
+   std::cerr << e.what() << std::endl; \
+   return EXIT_FAILURE; \
+} \
+catch (...) \
+{ \
+   std::cerr << "Unknown exception" << std::endl; \
+   return EXIT_FAILURE; \
+}
+
+#endif
Index: Damkjer/Util/Exception/test/TestException.cpp
===================================================================
--- Damkjer/Util/Exception/test/TestException.cpp	(revision 9)
+++ Damkjer/Util/Exception/test/TestException.cpp	(revision 9)
@@ -0,0 +1,197 @@
+//*****************************************************************************
+// FILE:        TestException.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: TestException
+//
+//    See TestTestCase header for detailed description.
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include <sstream>
+
+#include <vector>
+#include <typeinfo>
+
+#include "damkjerConfig.h"
+#include "TestException.h"
+#include "Util/Streams/BlockIndent.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// FUNCTOR: throwTest
+//*****************************************************************************
+template <typename Type, typename DType=Type>
+class throwTest : public TestCase::TestStep
+{
+public:
+   throwTest(const DType& expected)
+      : TestCase::TestStep(typeid(Type).name())
+      , theExpected(expected)
+   {
+   }
+      //> 
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::throwTest::operator(TestCase&)");
+
+      try
+      {
+         throw theExpected;
+
+         test.report() << "Did not catch an exception!\n";
+
+         // If we get here, we didn't throw: failed test.
+         return false;
+      }
+      catch (const Type& e)
+      {
+         test.report() << "Caught expected exception:\n";
+
+         test.report() << blockIndent() << e.what() << endBlock;
+
+         // If we get here, we threw the correct exception: successful test.
+         return true;
+      }
+      catch (...)
+      {
+         test.report() << "Caught unexpected exception.\n";
+
+         // If we get here, we threw something unexpected: failed test.
+         return false;
+      }
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   DType theExpected;
+      //>
+      //<
+};
+
+//*****************************************************************************
+// CONSTRUCTOR: TestException::TestException(int, char**)
+//*****************************************************************************
+TestException::TestException(int argc, char** argv)
+   : TestCase(argc, argv,
+              "Exception: Basic Functionality",
+              "Exception_01",
+              "This test case tests basic Exception functionality.")
+{
+   EXCEPTION_TRY("Damkjer::TestException::TestException(int, char**)");
+
+   DomainError     dde("Function not defined for provided input. (undefined "
+                       "behavior)",
+                       MODULE,__FILE__,__LINE__);
+   InvalidArgument dia("Argument cannot be interpretted in the context of the "
+                       "function. (e.g., bitset initialized with char other "
+                       "than '0' or '1')",
+                       MODULE,__FILE__,__LINE__);
+   LengthError     dle("Action exceeded a maximum allowable size.",
+                       MODULE,__FILE__,__LINE__);
+   OutOfRange      dor("Parameter outside of permitted range. (e.g., bad "
+                       "index)",
+                       MODULE,__FILE__,__LINE__);
+   RangeError      dre("Error in internal computation. (result cannot be "
+                       "represented)",
+                       MODULE,__FILE__,__LINE__);
+   OverflowError   doe("Detected arithmetic overflow. (result is larger "
+                       "than type can represent)",
+                       MODULE,__FILE__,__LINE__);
+   UnderflowError  due("Detected arithmetic underflow. (result is smaller "
+                       "than type can represent)",
+                       MODULE,__FILE__,__LINE__);
+   std::domain_error     sde("Function not defined for provided input. "
+                             "(undefined behavior)");
+   std::invalid_argument sia("Argument cannot be interpretted in the context "
+                             "of the function. (e.g., bitset initialized with "
+                             "char other than '0' or '1')");
+   std::length_error     sle("Action exceeded a maximum allowable size.");
+   std::out_of_range     sor("Parameter outside of permitted range. (e.g., "
+                             "bad index)");
+   std::range_error      sre("Error in internal computation. (result cannot "
+                             "be represented)");
+   std::overflow_error   soe("Detected arithmetic overflow. (result is larger "
+                             "than type can represent)");
+   std::underflow_error  sue("Detected arithmetic underflow. (result is "
+                             "smaller than type can represent)");
+   std::bad_alloc        sba("Unable to allocate requested memory.");
+   std::bad_cast         sbc("Failure to dynamic cast. Cast relationship is "
+                             "defined, but results in an incomplete object of"
+                             "the destination type");
+   std::bad_exception    sbe("Exception thrown that wasn't listed in the "
+                             "function dynamic exception specifier.");
+   std::bad_typeid       sbt("typeid operator applied to dereferenced null "
+                             "pointer.");
+
+   registerStep(new throwTest<std::domain_error>(sde));
+   registerStep(new throwTest<std::invalid_argument>(sia));
+   registerStep(new throwTest<std::length_error>(sle));
+   registerStep(new throwTest<std::out_of_range>(sor));
+   registerStep(new throwTest<std::range_error>(sre));
+   registerStep(new throwTest<std::overflow_error>(soe));
+   registerStep(new throwTest<std::underflow_error>(sue));
+   registerStep(new throwTest<std::bad_alloc>(sba));
+   registerStep(new throwTest<std::bad_cast>(sbc));
+   registerStep(new throwTest<std::bad_exception>(sbe));
+   registerStep(new throwTest<std::bad_typeid>(sbt));
+   registerStep(new throwTest<std::logic_error>(sde));
+   registerStep(new throwTest<std::logic_error>(sia));
+   registerStep(new throwTest<std::logic_error>(sle));
+   registerStep(new throwTest<std::logic_error>(sor));
+   registerStep(new throwTest<std::runtime_error>(sre));
+   registerStep(new throwTest<std::runtime_error>(soe));
+   registerStep(new throwTest<std::runtime_error>(sue));
+   registerStep(new throwTest<std::exception>(sde));
+   registerStep(new throwTest<std::exception>(sia));
+   registerStep(new throwTest<std::exception>(sle));
+   registerStep(new throwTest<std::exception>(sor));
+   registerStep(new throwTest<std::exception>(sre));
+   registerStep(new throwTest<std::exception>(soe));
+   registerStep(new throwTest<std::exception>(sue));
+   registerStep(new throwTest<std::exception>(sba));
+   registerStep(new throwTest<std::exception>(sbc));
+   registerStep(new throwTest<std::exception>(sbe));
+   registerStep(new throwTest<std::exception>(sbt));
+   registerStep(new throwTest<DomainError>(dde));
+   registerStep(new throwTest<InvalidArgument>(dia));
+   registerStep(new throwTest<LengthError>(dle));
+   registerStep(new throwTest<OutOfRange>(dor));
+   registerStep(new throwTest<RangeError>(dre));
+   registerStep(new throwTest<OverflowError>(doe));
+   registerStep(new throwTest<UnderflowError>(due));
+   registerStep(new throwTest<LogicError>(dde));
+   registerStep(new throwTest<LogicError>(dia));
+   registerStep(new throwTest<LogicError>(dle));
+   registerStep(new throwTest<LogicError>(dor));
+   registerStep(new throwTest<RuntimeError>(dre));
+   registerStep(new throwTest<RuntimeError>(doe));
+   registerStep(new throwTest<RuntimeError>(due));
+   registerStep(new throwTest<Exception, DomainError>(dde));
+   registerStep(new throwTest<Exception, InvalidArgument>(dia));
+   registerStep(new throwTest<Exception, LengthError>(dle));
+   registerStep(new throwTest<Exception, OutOfRange>(dor));
+   registerStep(new throwTest<Exception, RangeError>(dre));
+   registerStep(new throwTest<Exception, OverflowError>(doe));
+   registerStep(new throwTest<Exception, UnderflowError>(due));
+
+   EXCEPTION_RETHROW;
+}
+
+}
Index: Damkjer/Util/Exception/test/TestException.h
===================================================================
--- Damkjer/Util/Exception/test/TestException.h	(revision 9)
+++ Damkjer/Util/Exception/test/TestException.h	(revision 9)
@@ -0,0 +1,35 @@
+//*****************************************************************************
+// FILE:        TestException.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef TestException_HEADER
+#define TestException_HEADER
+
+#include "Util/UtilAPI.h"
+#include "Util/UnitTest/TestCase.h"
+
+namespace Damkjer
+{
+
+class TestException : public TestCase
+{
+public:
+   TestException(int, char**);
+      //>
+      //<
+};
+
+}
+
+#endif
Index: Damkjer/Util/Exception/test/TestException.vcxproj
===================================================================
--- Damkjer/Util/Exception/test/TestException.vcxproj	(revision 9)
+++ Damkjer/Util/Exception/test/TestException.vcxproj	(revision 9)
@@ -0,0 +1,266 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|Win32">
+      <Configuration>OpenMP</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|x64">
+      <Configuration>OpenMP</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\Util.vcxproj">
+      <Project>{20fe2624-c64f-d61a-bd8f-1725a8e68a42}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestException.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="TestException.cpp" />
+    <ClCompile Include="test_Exception.cpp" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>test_Exception</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
Index: Damkjer/Util/Exception/test/TestException.vcxproj.filters
===================================================================
--- Damkjer/Util/Exception/test/TestException.vcxproj.filters	(revision 9)
+++ Damkjer/Util/Exception/test/TestException.vcxproj.filters	(revision 9)
@@ -0,0 +1,26 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4010ed24-e68d-4e6e-97b0-8b8bb335aa86}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{0c039d31-de79-478b-9dc5-c3378145e52a}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestException.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="test_Exception.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="TestException.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
Index: Damkjer/Util/Exception/test/test_Exception.cpp
===================================================================
--- Damkjer/Util/Exception/test/test_Exception.cpp	(revision 9)
+++ Damkjer/Util/Exception/test/test_Exception.cpp	(revision 9)
@@ -0,0 +1,33 @@
+//*****************************************************************************
+// FILE:        test_Exception.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-26  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "damkjerConfig.h"
+#include "TestException.h"
+
+using namespace Damkjer;
+
+//*****************************************************************************
+// main
+//*****************************************************************************
+int main(int argc, char** argv)
+{
+   EXCEPTION_TRY("main(int, char**)");
+
+   TestException driver(argc, argv);
+
+   return driver.execute();
+
+   EXCEPTION_CATCHALL;
+}
Index: mkjer/Util/MATLAB/ClassHandle.cpp
===================================================================
--- Damkjer/Util/MATLAB/ClassHandle.cpp	(revision 7)
+++ 	(revision )
@@ -1,70 +1,0 @@
-//*****************************************************************************
-// FILE:        ClassHandle.cpp
-//
-//    Copyright (C)  2012 Kristian Damkjer.
-//
-// DESCRIPTION: This class is intended to be used to wrap C++ objects for
-//              transport across mex function calls in MATLAB.
-//
-// LIMITATIONS: To preserve the lifetime guarantees of the pointer, default
-//              construction, copy construction and assignment are
-//              explicitly disallowed.
-//
-//              The class handle owns the pointer it contains. Thus, when
-//              the class handle is destroyed, the pointer is deleted.
-//
-//              Class handles are forced to be allocated on the heap by
-//              using the named constructor idiom. Class handles should be
-//              destroyed using the destroyHandleTo template function.
-//
-// SOFTWARE HISTORY:
-//> 2012-OCT-08  K. Damkjer
-//               Initial Coding.
-//<
-//*****************************************************************************
-
-#include "ClassHandle.h"
-
-#include <typeinfo>
-
-namespace Damkjer
-{
-
-#define CLASS_HANDLE_SIGNATURE 0xfacade01
-
-//*****************************************************************************
-// ClassHandle::ClassHandle
-//*****************************************************************************
-template<typename BASE>
-inline ClassHandle<BASE>::ClassHandle(BASE* pointer)
-   : thePointer(pointer)
-   , theName(typeid(BASE).name())
-   , theSignature(CLASS_HANDLE_SIGNATURE)
-{
-   mexLock();
-}
-
-//*****************************************************************************
-// ClassHandle::~ClassHandle
-//*****************************************************************************
-template<typename BASE>
-inline ClassHandle<BASE>::~ClassHandle()
-{
-   delete thePointer;
-   thePointer = 0;
-   theSignature = 0;
-
-   mexUnlock();
-}
-
-//*****************************************************************************
-// ClassHandle::isValid
-//*****************************************************************************
-template<typename BASE>
-inline bool ClassHandle<BASE>::isValid() const
-{
-   return (theSignature == CLASS_HANDLE_SIGNATURE &&
-           theName == typeid(BASE).name());
-}
-
-}
Index: Damkjer/Util/MATLAB/ClassHandle.h
===================================================================
--- Damkjer/Util/MATLAB/ClassHandle.h	(revision 7)
+++ Damkjer/Util/MATLAB/ClassHandle.h	(revision 9)
@@ -28,21 +28,17 @@
 #define ClassHandle_HEADER
 
-#ifndef EXPORT
-   #if defined(MAKE_DEPENDING) || defined(TEMPLATE_INCLUSION)
-      #define EXPORT
-   #else
-      #define EXPORT export
+#include <string>
+
+#include "damkjerConfig.h"
+
+// Fix "wide char" definition for older versions of MATLAB. This must be placed
+// after other includes and before the mex.h include.
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
    #endif
 #endif
 
-#include <string>
-
-// Fix "wide char" definition for older versions of MATLAB. This must be placed
-// after other includes and before the mex.h include.
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
-#endif
-
-#include "mex.h"
+#include "matrix.h"
 
 namespace Damkjer
@@ -175,6 +171,6 @@
 }
 
-#if defined(MAKE_DEPENDING) || defined(TEMPLATE_INCLUSION)
-#include "ClassHandle.cpp"
+#if MAKE_DEPENDING || TEMPLATE_INCLUSION
+#include "ClassHandle.hpp"
 #endif
 
Index: Damkjer/Util/MATLAB/ClassHandle.hpp
===================================================================
--- Damkjer/Util/MATLAB/ClassHandle.hpp	(revision 9)
+++ Damkjer/Util/MATLAB/ClassHandle.hpp	(revision 9)
@@ -0,0 +1,70 @@
+//*****************************************************************************
+// FILE:        ClassHandle.cpp
+//
+//    Copyright (C)  2012 Kristian Damkjer.
+//
+// DESCRIPTION: This class is intended to be used to wrap C++ objects for
+//              transport across mex function calls in MATLAB.
+//
+// LIMITATIONS: To preserve the lifetime guarantees of the pointer, default
+//              construction, copy construction and assignment are
+//              explicitly disallowed.
+//
+//              The class handle owns the pointer it contains. Thus, when
+//              the class handle is destroyed, the pointer is deleted.
+//
+//              Class handles are forced to be allocated on the heap by
+//              using the named constructor idiom. Class handles should be
+//              destroyed using the destroyHandleTo template function.
+//
+// SOFTWARE HISTORY:
+//> 2012-OCT-08  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "ClassHandle.h"
+
+#include <typeinfo>
+
+namespace Damkjer
+{
+
+#define CLASS_HANDLE_SIGNATURE 0xfacade01
+
+//*****************************************************************************
+// ClassHandle::ClassHandle
+//*****************************************************************************
+template<typename BASE>
+inline ClassHandle<BASE>::ClassHandle(BASE* pointer)
+   : thePointer(pointer)
+   , theName(typeid(BASE).name())
+   , theSignature(CLASS_HANDLE_SIGNATURE)
+{
+   mexLock();
+}
+
+//*****************************************************************************
+// ClassHandle::~ClassHandle
+//*****************************************************************************
+template<typename BASE>
+inline ClassHandle<BASE>::~ClassHandle()
+{
+   delete thePointer;
+   thePointer = 0;
+   theSignature = 0;
+
+   mexUnlock();
+}
+
+//*****************************************************************************
+// ClassHandle::isValid
+//*****************************************************************************
+template<typename BASE>
+inline bool ClassHandle<BASE>::isValid() const
+{
+   return (theSignature == CLASS_HANDLE_SIGNATURE &&
+           theName == typeid(BASE).name());
+}
+
+}
Index: Damkjer/Util/Math/fastcenter.cpp
===================================================================
--- Damkjer/Util/Math/fastcenter.cpp	(revision 7)
+++ Damkjer/Util/Math/fastcenter.cpp	(revision 9)
@@ -21,6 +21,8 @@
 #include <vector>
 
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
+   #endif
 #endif
 
Index: Damkjer/Util/Math/fastcoeffvar.cpp
===================================================================
--- Damkjer/Util/Math/fastcoeffvar.cpp	(revision 7)
+++ Damkjer/Util/Math/fastcoeffvar.cpp	(revision 9)
@@ -21,6 +21,8 @@
 #include <vector>
 
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
+   #endif
 #endif
 
Index: Damkjer/Util/Math/fastcov.cpp
===================================================================
--- Damkjer/Util/Math/fastcov.cpp	(revision 7)
+++ Damkjer/Util/Math/fastcov.cpp	(revision 9)
@@ -22,6 +22,8 @@
 #include <sstream>
 
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
+   #endif
 #endif
 
Index: Damkjer/Util/Math/par_eig.cpp
===================================================================
--- Damkjer/Util/Math/par_eig.cpp	(revision 8)
+++ Damkjer/Util/Math/par_eig.cpp	(revision 9)
@@ -22,6 +22,8 @@
 #include <sstream>
 
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
+   #endif
 #endif
 
Index: mkjer/Util/SpatialIndexing/FRANN.m
===================================================================
--- Damkjer/Util/SpatialIndexing/FRANN.m	(revision 0)
+++ 	(revision )
@@ -1,482 +1,0 @@
-function [NN] = FRANN(varargin)
-%%
-% FRANN    short description probably needs a better name now that I'm
-%            not always performing a convolution.
-%
-%   NN = FRANN(X) ...
-%
-%   NN = FRANN(P, X) ...
-%
-%   NN = FRANN(I, X) ...
-%
-%   IDX = FRANN(..., Property, Value)
-%   Calls FRANN with the indicated parameters set. Property names can be
-%   supplied as just the first letters of the property name if this is
-%   unambiguous, e.g. PSFCONV(..., 'sig', [1 1 0.15]) is equivalent to
-%   PSFCONV(..., 'Sigmas', [1 1 0.15]). Properties are case insensitive,
-%   and are as follows:
-%      Property:                         Value:
-%      ---------                         ------
-%      PointWeights                      ...
-%      Sigmas                            ...
-%      Mode                              {'count', 'intensity', 'noise'},
-%                                        default: 'noise'
-%            FRANN(..., 'Mode', M) computes 'density' according to the
-%            requested mode. 'count' simply provides a raw count of
-%            adjacent pixels in the local neighborhood defined by the PSF 
-%            SDV reach. 'intensity' provides an estimate of signal strength
-%            by convolving the detections with the PSF. 'noise' provides an
-%            estimate of noise likelihood using a Bayesian analysis of the
-%            detection population and PSF.
-%      TODO: Add SDVs or CI
-%      TODO: Add SNR or SignalProb
-%
-%   Example:
-%
-%   See also 
-
-%% Default parameters
-userParams.radius = 1;
-
-%% Parse inputs
-[P, X, isNotSubset, userParams] = parseinputs(userParams, varargin{:});
-
-% userParams.Radius=userParams.Radius*userParams.sdvs
-
-% %% First scale into SDV space
-% sigmaScale=diag(1./userParams.Sigmas);
-% X=sigmaScale*X;
-% P=sigmaScale*P;
-
-%% Establish the bucket origin and dimensions
-origin=min(X,[],2);
-extent=max(X,[],2);
-cover=extent-origin;
-lengths=ceil(cover/userParams.radius)+2; % plus 2*reach is better... if we use reach
-
-spacing=userParams.radius*ones(1,length(lengths));
-
-rsq=userParams.radius*userParams.radius;
-
-[dimensions,population]=size(X);
-estimates=size(P,2);
-
-% gaussConst=1/((2*pi())^(dimensions/2));
-% dConst=-0.5;
-
-%% Compute n-dimensional bin offsets for adjacency checks
-tic;
-reach=1;
-
-offsets=zeros(dimensions,power(2*reach+1,dimensions));
-
-for dimension=1:dimensions
-    reps=power(2*reach+1,dimensions-dimension);
-    cycles=power(2*reach+1,dimension-1);
-
-    offset=1;
-    for cycle=1:cycles
-        for value=-reach:reach
-            for rep=1:reps
-                offsets(dimension,offset)=value;
-                offset=offset+1;
-            end
-        end
-    end
-end
-
-offidxs=offsets(1,:);
-
-for dimension=2:dimensions
-    offidxs=offidxs+prod(lengths(1:dimension-1))*offsets(dimension,:);
-end
-
-clear offsets;
-
-disp(['Time to compute offsets: ' num2str(toc) 's']);
-
-%% Compute bin subscripts for requested points and population
-tic;
-
-xsubs=zeros(size(X));
-psubs=zeros(size(P));
-
-for dimension=1:dimensions
-    xsubs(dimension,:)=ceil((X(dimension,:)-origin(dimension))/...
-                                                spacing(dimension))+1;
-    psubs(dimension,:)=ceil((P(dimension,:)-origin(dimension))/...
-                                                spacing(dimension))+1;
-end
-
-disp(['Time to compute subscripts: ' num2str(toc) 's']);
-
-%% Convert subscripts to linear indices for fast indexing
-tic;
-
-xidxs=xsubs(1,:);
-pidxs=psubs(1,:);
-
-for dimension=2:dimensions
-    xidxs=xidxs+prod(lengths(1:dimension-1))*(xsubs(dimension,:)-1);
-    pidxs=pidxs+prod(lengths(1:dimension-1))*(psubs(dimension,:)-1);
-end
-
-bidxs=unique(xidxs); % bin indices
-vidxs=unique(pidxs); % visitation indices
-
-clear xsubs;
-clear psubs;
-
-disp(['Time to identify unique indices: ' num2str(toc) 's']);
-
-%% Make sure we visit all of the necessary bins when processing a subset
-tic;
-
-baks=[vidxs' ones(length(vidxs),1)] *...
-     [ones(1,length(offidxs(:,offidxs<0)));offidxs(:,offidxs<0)];
-
-% NOTE: We only need to visit populated bins
-vidxs=intersect(bidxs,unique([baks(:)' vidxs]));
-
-disp(['Time to identify back-adjacent cells: ' num2str(toc) 's']);
-
-%% Map hash indices to linear indices (sparsely)
-%  NOTE: we only need to map observations that contribute to estimates
-blu=sparse(vidxs,ones(1,length(vidxs)),1:length(vidxs),prod(lengths),1);
-
-%% Only keep positive offsets since we have verified that we can safely
-% propagate a wavefront in one direction per dimension.
-offidxs=offidxs(:,offidxs>0);
-
-%%
-%%% Bin points for faster searching (O(n+k) vs O(n*n))
-
-%% Determine the size of each populated bin and contained observations
-tic;
-
-bsz=zeros(1,length(vidxs),'int32');
-bpt=zeros(1,population,'int32');
-
-msg='Determining Observation Bin Vital Statistics...';
-tstart=tic;
-h = timebar(1, population, msg, tstart);
-
-for point=1:population
-    if (toc>1)
-        tic;
-        h = timebar(point, population, msg, tstart, h);
-    end
-    
-    bin=blu(xidxs(point));
-    
-    if (bin ~= 0)
-        bsz(bin)=bsz(bin)+1;
-        bpt(point)=bsz(bin);
-    end
-end
-
-if (all(ishghandle(h, 'figure')))
-    close(h);
-end
-
-disp(['Time to determine observation bin statistics: '...
-    num2str(toc(tstart)) 's']);
-
-%% Determine the size of each populated bin and contained observation
-if (isNotSubset)
-    tic;
-
-    vsz=zeros(1,length(vidxs),'int32');
-    vpt=zeros(1,estimates,'int32');
-    
-    msg='Determining Estimate Bin Vital Statistics...';
-    tstart=tic;
-    h = timebar(1, estimates, msg, tstart);
-    
-    for point=1:estimates
-        if (toc>1)
-            tic;
-            h = timebar(point, estimates, msg, tstart, h);
-        end
-        
-        bin=blu(pidxs(point));
-        
-        if (bin ~= 0)
-            vsz(bin)=vsz(bin)+1;
-            vpt(point)=vsz(bin);
-        end
-    end
-    
-    if (all(ishghandle(h, 'figure')))
-        close(h);
-    end
-    
-    disp(['Time to determine estimate bin statistics: '...
-        num2str(toc(tstart)) 's']);
-end
-
-%% Allocate space for the binned data
-tic;
-
-obins=cell(1,length(vidxs));
-
-for bin=1:numel(obins)
-    obins{bin}=zeros(1,bsz(bin),'int32');
-end
-
-clear bsz;
-
-if (isNotSubset)
-    ebins=cell(1,length(vidxs));
-    
-    for bin=1:numel(ebins)
-        ebins{bin}=zeros(1,vsz(bin),'int32');
-    end
-    
-    clear vsz;
-end
-
-disp(['Time to allocate bins: ' num2str(toc) 's']);
-
-%% Populate the bins
-msg='Populating observation bins...';
-tstart=tic;
-h = timebar(1, population, msg, tstart);
-
-for point=1:population;
-    if (toc>1)
-        tic;
-        h = timebar(point, population, msg, tstart, h);
-    end
-
-    bin=blu(xidxs(point));
-    
-    if (bin>0)
-        obins{bin}(bpt(point))=point;
-    end
-end
-
-if (all(ishghandle(h, 'figure')))
-    close(h);
-end
-
-clear bpt;
-
-if (isNotSubset)
-    msg='Populating estimation bins...';
-    tstarte=tic;
-    h = timebar(1, estimates, msg, tstarte);
-    
-    for point=1:estimates;
-        if (toc>1)
-            tic;
-            h = timebar(point, estimates, msg, tstarte, h);
-        end
-        
-        bin=blu(pidxs(point));
-        
-        if (bin>0)
-            ebins{bin}(vpt(point))=point;
-        end
-    end
-    
-    if (all(ishghandle(h, 'figure')))
-        close(h);
-    end
-    
-    clear vpt;
-end
-
-disp(['Time to populate bins: ' num2str(toc(tstart)) 's']);
-
-%% Compute densities
-
-if (isNotSubset)
-    NN=cell(1,estimates);
-%      NN=zeros(1,estimates);
-else
-    NN=cell(1,population);
-%      NN=zeros(1,population);
-end
-
-msg='Computing Neighbors...';
-tstart=tic;
-h = timebar(1, length(vidxs), msg, tstart);
-
-for bin=1:length(vidxs)
-    if (toc>1)
-        tic;
-        h = timebar(bin, length(vidxs), msg, tstart, h);
-    end
-
-    % Local indices for observations
-    loidxs=[obins{blu(vidxs(bin))}];
-    lopts=X(:,loidxs);
-
-    % Local indices for requested point estimates (copy-paste code since
-    % there's no way to create an alias in MATLAB that I'm aware of)
-    if (isNotSubset)
-        leidxs=[ebins{blu(vidxs(bin))}];
-        lepts=P(:,leidxs);
- 
-        % Compute weight for local cell contributions
-        locd=bsxfun(@plus,dot(lepts,lepts,1)',dot(lopts,lopts,1))-...
-            2*(lepts'*lopts);
-        
-        mapping=repmat(loidxs,length(leidxs),1);
-        mapping(locd>rsq)=0;
-        
-        for i=1:size(mapping,1)
-            neighbors=mapping(i,:);
-            NN{leidxs(i)}=[NN{leidxs(i)} neighbors(neighbors>0)];
-        end
-        
-    else
-        % Compute weight for local cell contributions
-        locd=bsxfun(@plus,dot(lopts,lopts,1)',dot(lopts,lopts,1))-...
-            2*(lopts'*lopts);
-        
-        mapping=repmat(loidxs,length(loidxs),1);
-        mapping(locd>rsq)=0;
-        
-        for i=1:size(mapping,1)
-            neighbors=mapping(i,:);
-            NN{loidxs(i)}=[NN{loidxs(i)} neighbors(neighbors>0)];
-        end
-    end
-
-    % Compute weight for forward-adjacent cell contributions
-    offs=offidxs+vidxs(bin);
-    offs=offs(blu(offs)~=0);
-
-    if (~isempty(offs))
-        % Adjacent indices for observations
-        aoidxs=[obins{blu(offs)}];
-        aopts=X(:,aoidxs);
-        
-        % Adjacent indices for requested point estimates (copy-paste code
-        % since there's no way to create an alias in MATLAB that I'm aware
-        % of)
-        if (isNotSubset)
-            aeidxs=[ebins{blu(offs)}];
-            aepts=X(:,aeidxs);
-            
-            % Calculate influence of adjacent observations on local estimates
-            led=bsxfun(@plus,dot(lepts,lepts,1)',dot(aopts,aopts,1))-...
-                2*(lepts'*aopts);
-            
-            % Calculate influence of local observations on adjacent estimates
-            aed=bsxfun(@plus,dot(aepts,aepts,1)',dot(lopts,lopts,1))-...
-                2*(aepts'*lopts);
-        
-            % Remove contributors outside reach
-%             wl(led>rsq)=0;
-%             wa(aed>rsq)=0;
-        else
-            % Calculate influence of adjacent observations on local estimates
-            ed=bsxfun(@plus,dot(lopts,lopts,1)',dot(aopts,aopts,1))-2*(lopts'*aopts);
-            
-            % Remove contributors outside reach
-            mappingla=repmat(aoidxs,length(loidxs),1);
-            mappingal=repmat(loidxs,length(aoidxs),1);
-            mappingla(ed>rsq)=0;
-            mappingal(ed'>rsq)=0;
-            
-            for i=1:size(mappingla,1)
-                neighbors=mappingla(i,:);
-                NN{loidxs(i)}=[NN{loidxs(i)} neighbors(neighbors>0)];
-            end
-            for i=1:size(mappingal,1)
-                neighbors=mappingal(i,:);
-                NN{aoidxs(i)}=[NN{aoidxs(i)} neighbors(neighbors>0)];
-            end
-        end
-    end
-end
-
-% Down-select density to only desired points
-if (~isNotSubset && numel(X) ~= numel(P))
-    NN=NN(:,ismember(X',P','rows'));
-end
-
-if (all(ishghandle(h, 'figure')))
-    close(h);
-end
-
-disp(['Time to compute neighbors: ' num2str(toc(tstart)) 's']);
-
-end % psfConv
-
-%%
-%PARSEINPUTS    Support function for nearestneighbour
-function [P, X, isNotSubset, userParams] = parseinputs(userParams, varargin)
-if length(varargin) == 1 || ~isnumeric(varargin{2})
-    P           = varargin{1};
-    X           = varargin{1};
-    isNotSubset = false;
-    varargin(1) = [];
-else
-    P             = varargin{1};
-    X             = varargin{2};
-    varargin(1:2) = [];
-    isNotSubset = true;
-    
-    % Check the dimensions of X and P
-    if size(X, 1) ~= 1
-        % Check to see whether P is in fact a vector of indices
-        if size(P, 1) == 1
-            try
-                P = X(:, P);
-                isNotSubset = false;
-            catch me
-                error('psfConv:InvalidIndexVector', ...
-                    'Unable to index matrix using index vector');
-            end
-        end % if size(P, 1) == 1
-    end
-
-    isNotSubset= ~isNotSubset && isempty(setdiff(P',X'));
-    
-    if size(P, 1) ~= size(X, 1)
-        error('psfConv:DimensionMismatch', ...
-            'No. of rows of input arrays doesn''t match');
-    end
-end
-
-% Parse the Property/Value pairs
-if rem(length(varargin), 2) ~= 0
-    error('psfConv:propertyValueNotPair', ...
-        'Additional arguments must take the form of Property/Value pairs');
-end
-
-propertyNames = {'radius'};
-
-while ~isempty(varargin)
-    property = varargin{1};
-    value    = varargin{2};
-
-    % If the property has been supplied in a shortened form, lengthen it
-    iProperty = find(strncmpi(property, propertyNames, length(property)));
-
-    if isempty(iProperty)
-        error('psfConv:InvalidProperty', 'Invalid Property');
-    elseif length(iProperty) > 1
-        error('psfConv:AmbiguousProperty', ...
-            'Supplied shortened property name is ambiguous');
-    end
-    property = propertyNames{iProperty};
-
-    switch property
-        case 'radius'
-            if isscalar(value) && isnumeric(value) && isreal(value)
-                userParams.radius = value;
-            else
-                error('psfConv:InvalidPointWeights', ...
-                    'Radius must be a real valued scalar');
-            end
-    end % switch property
-
-    varargin(1:2) = [];
-end % while
-
-end %parseinputs
Index: Damkjer/Util/SpatialIndexing/Metrics/Metrics.h
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/Metrics.h	(revision 7)
+++ Damkjer/Util/SpatialIndexing/Metrics/Metrics.h	(revision 9)
@@ -11,4 +11,7 @@
 //> 2012-SEP-11  K. Damkjer
 //               Initial Coding.
+//  2013-JUL-23  K. Damkjer
+//               Modified free functions to functors to allow for "functions
+//               with state" like p-norm.
 //<
 //*****************************************************************************
@@ -18,84 +21,140 @@
 
 #include <cmath>
+#include <iterator>
+#include <sstream>
+
+#include "damkjerConfig.h"
 
 namespace Damkjer
 {
+//*****************************************************************************
+// FUNCTOR: EuclideanDistance
+//*****************************************************************************
+template<typename PointT, typename ReturnT = double>
+class EuclideanDistance
+{
+public:
+   typedef ReturnT value_type;
+   
+   value_type operator()(const PointT& a, const PointT& b) const
+   {
+      value_type sum = 0;
+
+      for (typename PointT::const_iterator ai = a.begin(), bi = b.begin();
+           ai != a.end() && bi != b.end();
+           ++ai, ++bi)
+      {
+         sum += (*ai - *bi) * (*ai - *bi);
+      }
+
+      return std::sqrt(sum);
+   }
+};
 
 //*****************************************************************************
-// FUNCTION: euclidean
+// FUNCTOR: ManhattanDistance
 //*****************************************************************************
-template<typename CONTAINER>
-double euclidean(const CONTAINER& a,
-                 const CONTAINER& b)
+template<typename PointT, typename ReturnT = double>
+class ManhattanDistance
 {
-    double sum = 0;
-    
-    for (typename CONTAINER::const_iterator ai = a.begin(), bi = b.begin();
-         ai != a.end() && bi != b.end();
-         ++ai, ++bi)
-    {
-        sum += (*ai - *bi) * (*ai - *bi);
-    }
-    
-    return sqrt(sum);
-}
+public:
+   typedef ReturnT value_type;
+
+   value_type operator()(const PointT& a, const PointT& b) const
+   {
+      value_type sum = 0;
+      
+      for (typename PointT::const_iterator ai = a.begin(), bi = b.begin();
+           ai != a.end() && bi != b.end();
+           ++ai, ++bi)
+      {
+         sum += std::fabs(*ai - *bi);
+      }
+      
+      return sum;
+   }
+};
 
 //*****************************************************************************
-// FUNCTION: manhattan
+// FUNCTOR: ChebyshevDistance
 //*****************************************************************************
-template<typename CONTAINER>
-double manhattan(const CONTAINER& a,
-                 const CONTAINER& b)
+template<typename PointT, typename ReturnT = double>
+class ChebyshevDistance
 {
-    double sum = 0;
-    
-    for (typename CONTAINER::const_iterator ai = a.begin(), bi = b.begin();
-         ai != a.end() && bi != b.end();
-         ++ai, ++bi)
-    {
-        sum += fabs(*ai - *bi);
-    }
-    
-    return sum;
-}
+public:
+   typedef ReturnT value_type;
+
+   value_type operator()(const PointT& a, const PointT& b) const
+   {
+      value_type my_max = 0;
+      
+      for (typename PointT::const_iterator ai = a.begin(), bi = b.begin();
+           ai != a.end() && bi != b.end();
+           ++ai, ++bi)
+      {
+         value_type temp = std::fabs(*ai - *bi);
+         my_max = (temp > my_max) ? temp : my_max;
+      }
+      
+      return my_max;
+   }
+};
 
 //*****************************************************************************
-// FUNCTION: maximum
+// FUNCTOR: MinkowskiDistance
 //*****************************************************************************
-template<typename CONTAINER>
-double maximum(const CONTAINER& a,
-               const CONTAINER& b)
+template<typename PointT, typename ReturnT = double>
+class MinkowskiDistance
 {
-    double my_max = 0;
-    
-    for (typename CONTAINER::const_iterator ai = a.begin(), bi = b.begin();
-         ai != a.end() && bi != b.end();
-         ++ai, ++bi)
-    {
-       double temp = fabs(*ai - *bi)
-       my_max = (temp > my_max) ? temp : my_max;
-    }
-    
-    return my_max;
-}
+public:
+   typedef ReturnT value_type;
 
-//*****************************************************************************
-// FUNCTION: pNorm
-//*****************************************************************************
-// template<typename CONTAINER>
-// double pNorm(const CONTAINER& a,
-//              const CONTAINER& b)
-// {
-//    double sum = 0;
-//    
-//    for (typename CONTAINER::const_iterator ai = a.begin(), bi = b.begin();
-//         ai != a.end() && bi != b.end();
-//         ++ai, ++bi)
-//    {
-//       sum += pow((*ai - *bi), theP);
-//    }
-//    
-//    return pow(sum, 1./theP);
-// }
+   MinkowskiDistance() : theP(2){}
+
+   explicit MinkowskiDistance(value_type p) : theP(p)
+   {
+      EXCEPTION_TRY("Damkjer::MinkowskiDistance<PointT, ReturnT>::MinkowskiDistance");
+
+      if (theP < 1)
+      {
+         //***
+         // In released code, there's not a whole lot that the user can do
+         // about this problem. This is a logic error and should be prevented
+         // through appropriate bounds checking on the input prior to
+         // calling the constructor.
+         //***
+         std::ostringstream msg;
+
+         msg << "Context : Defining a Minkowski distance metric.\n"
+             << "Problem : Unable to define a Minkowski distance metric with "
+             << "the requested p-value.\n"
+             << "Cause   : Minkowski distance must be defined with p >= 1 to "
+             << "describe a metric space. p-value requested: " << p << "\n"
+             << "Solution: Restrict p-values to p >= 1 if possible. "
+             << "Otherwise, contact support for assitance.";
+
+         throw DomainError(msg.str(),  MODULE, __FILE__, __LINE__);
+      }
+
+      EXCEPTION_RETHROW;
+   }
+
+   value_type operator()(const PointT& a, const PointT& b) const
+   {
+      value_type sum = 0;
+   
+      for (typename PointT::const_iterator ai = a.begin(), bi = b.begin();
+           ai != a.end() && bi != b.end();
+           ++ai, ++bi)
+      {
+         sum += std::pow(static_cast<value_type>(std::fabs(*ai - *bi)), theP);
+      }
+   
+      return std::pow(sum, static_cast<value_type>(1./theP));
+   }
+
+protected:
+   value_type theP;
+};
 
 }
Index: Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.cpp
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.cpp	(revision 9)
+++ Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.cpp	(revision 9)
@@ -0,0 +1,424 @@
+//*****************************************************************************
+// FILE:        TestMetrics.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: TestMetrics
+//
+//    See TestMetrics header for detailed description.
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include <iomanip>
+#include <sstream>
+#include <limits>
+#include <cmath>
+#include <vector>
+#include <typeinfo>
+
+#include "damkjerConfig.h"
+#include "TestMetrics.h"
+#include "Util/SpatialIndexing/Metrics/Metrics.h"
+#include "Util/Streams/BlockIndent.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// FUNCTOR: testEuclidean
+//*****************************************************************************
+template <typename PointT, typename ReturnT>
+class testEuclidean : public TestCase::TestStep
+{
+public:
+   testEuclidean()
+      : TestCase::TestStep(typeid(theMetric).name())
+      , theMetric()
+   {
+   }
+      //>
+      //<
+
+   bool approx_equal(ReturnT a, ReturnT b) const
+   {
+      double absTolI = std::numeric_limits<PointT::value_type>::epsilon();
+      double absTolO = std::numeric_limits<ReturnT>::epsilon();
+
+      double absTol = (absTolI > absTolO) ? absTolI : absTolO;
+
+      ReturnT inMax = (std::abs(a) > std::abs(b))
+                      ? std::abs(a)
+                      : std::abs(b);
+
+      inMax = (inMax > static_cast<ReturnT>(1.0))
+              ? inMax
+              : static_cast<ReturnT>(1.0);
+
+      return (std::abs(a - b) <= absTol * inMax);
+   }
+
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::testEuclidean::operator(TestCase&)");
+
+      PointT a;
+      a.push_back(static_cast<PointT::value_type>(0.3));
+      a.push_back(static_cast<PointT::value_type>(0.5));
+
+      PointT b;
+      b.push_back(static_cast<PointT::value_type>(0.7));
+      b.push_back(static_cast<PointT::value_type>(0.8));
+
+      ReturnT fromMetric = theMetric(a, b);
+
+      //***
+      // Expected value is sqrt((0.7-0.3)*(0.7-0.3)+(0.8-0.5)*(0.8-0.5))
+      //                   sqrt(0.4*0.4+0.3*0.3)
+      //                   sqrt(0.16+0.09)
+      //                   sqrt(0.25)
+      //                   0.5
+      //***
+      bool passed = approx_equal(fromMetric, static_cast<ReturnT>(0.5));
+
+      test.report() << "Value from Euclidean Metric: " << std::setprecision(12) << fromMetric << "\n"
+                    << "Expected result            : "
+                    << std::setprecision(12) << static_cast<ReturnT>(0.5) << "\n";
+
+      return passed;
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   EuclideanDistance<PointT,ReturnT> theMetric;
+      //>
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: testManhattan
+//*****************************************************************************
+template <typename PointT, typename ReturnT>
+class testManhattan : public TestCase::TestStep
+{
+public:
+   testManhattan()
+      : TestCase::TestStep(typeid(theMetric).name())
+      , theMetric()
+   {
+   }
+      //>
+      //<
+
+   bool approx_equal(ReturnT a, ReturnT b) const
+   {
+      double absTolI = std::numeric_limits<PointT::value_type>::epsilon();
+      double absTolO = std::numeric_limits<ReturnT>::epsilon();
+
+      double absTol = (absTolI > absTolO) ? absTolI : absTolO;
+
+      ReturnT inMax = (std::abs(a) > std::abs(b))
+                      ? std::abs(a)
+                      : std::abs(b);
+
+      inMax = (inMax > static_cast<ReturnT>(1.0))
+              ? inMax
+              : static_cast<ReturnT>(1.0);
+
+      return (std::abs(a - b) <= absTol * inMax);
+   }
+
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::testManhattan::operator(TestCase&)");
+
+      PointT a;
+      a.push_back(static_cast<PointT::value_type>(0.3));
+      a.push_back(static_cast<PointT::value_type>(0.5));
+
+      PointT b;
+      b.push_back(static_cast<PointT::value_type>(0.7));
+      b.push_back(static_cast<PointT::value_type>(0.8));
+
+      ReturnT fromMetric = theMetric(a, b);
+
+      //***
+      // Expected value is |0.7-0.3|+|0.8-0.5|
+      //                   0.4+0.3
+      //                   0.7
+      //***
+      bool passed = approx_equal(fromMetric, static_cast<ReturnT>(0.7));
+
+      test.report() << "Value from Euclidean Metric: " << std::setprecision(12) << fromMetric << "\n"
+                    << "Expected result            : "
+                    << std::setprecision(12) << static_cast<ReturnT>(0.7) << "\n";
+
+      return passed;
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   ManhattanDistance<PointT,ReturnT> theMetric;
+      //>
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: testChebyshev
+//*****************************************************************************
+template <typename PointT, typename ReturnT>
+class testChebyshev : public TestCase::TestStep
+{
+public:
+   testChebyshev()
+      : TestCase::TestStep(typeid(theMetric).name())
+      , theMetric()
+   {
+   }
+      //>
+      //<
+
+   bool approx_equal(ReturnT a, ReturnT b) const
+   {
+      double absTolI = std::numeric_limits<PointT::value_type>::epsilon();
+      double absTolO = std::numeric_limits<ReturnT>::epsilon();
+
+      double absTol = (absTolI > absTolO) ? absTolI : absTolO;
+
+      ReturnT inMax = (std::abs(a) > std::abs(b))
+                      ? std::abs(a)
+                      : std::abs(b);
+
+      inMax = (inMax > static_cast<ReturnT>(1.0))
+              ? inMax
+              : static_cast<ReturnT>(1.0);
+
+      return (std::abs(a - b) <= absTol * inMax);
+   }
+
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::testChebyshev::operator(TestCase&)");
+
+      PointT a;
+      a.push_back(static_cast<PointT::value_type>(0.3));
+      a.push_back(static_cast<PointT::value_type>(0.5));
+
+      PointT b;
+      b.push_back(static_cast<PointT::value_type>(0.7));
+      b.push_back(static_cast<PointT::value_type>(0.8));
+
+      ReturnT fromMetric = theMetric(a, b);
+
+      //***
+      // Expected value is max(|0.7-0.3|,|0.8-0.5|)
+      //                   max(0.4,0.3)
+      //                   0.4
+      //***
+      bool passed = approx_equal(fromMetric, static_cast<ReturnT>(0.4));
+
+      test.report() << "Value from Euclidean Metric: " << std::setprecision(12) << fromMetric << "\n"
+                    << "Expected result            : "
+                    << std::setprecision(12) << static_cast<ReturnT>(0.4) << "\n";
+
+      return passed;
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   ChebyshevDistance<PointT,ReturnT> theMetric;
+      //>
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: testMinkowski
+//*****************************************************************************
+template <typename PointT, typename ReturnT>
+class testMinkowski : public TestCase::TestStep
+{
+public:
+   testMinkowski()
+      : TestCase::TestStep(typeid(theMetric).name())
+      , theMetric(2)
+   {
+   }
+      //>
+      //<
+
+   bool approx_equal(ReturnT a, ReturnT b) const
+   {
+      double absTolI = std::numeric_limits<PointT::value_type>::epsilon();
+      double absTolO = std::numeric_limits<ReturnT>::epsilon();
+
+      double absTol = (absTolI > absTolO) ? absTolI : absTolO;
+
+      ReturnT inMax = (std::abs(a) > std::abs(b))
+                      ? std::abs(a)
+                      : std::abs(b);
+
+      inMax = (inMax > static_cast<ReturnT>(1.0))
+              ? inMax
+              : static_cast<ReturnT>(1.0);
+
+      return (std::abs(a - b) <= absTol * inMax);
+   }
+
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::testMinkowski::operator(TestCase&)");
+
+      PointT a;
+      a.push_back(static_cast<PointT::value_type>(0.3));
+      a.push_back(static_cast<PointT::value_type>(0.5));
+
+      PointT b;
+      b.push_back(static_cast<PointT::value_type>(0.7));
+      b.push_back(static_cast<PointT::value_type>(0.8));
+
+      ReturnT fromMetric = theMetric(a, b);
+
+      //***
+      // Expected value is sqrt((0.7-0.3)*(0.7-0.3)+(0.8-0.5)*(0.8-0.5))
+      //                   sqrt(0.4*0.4+0.3*0.3)
+      //                   sqrt(0.16+0.09)
+      //                   sqrt(0.25)
+      //                   0.5
+      //***
+      bool passed = approx_equal(fromMetric, static_cast<ReturnT>(0.5));
+
+      test.report() << "Value from Euclidean Metric: " << std::setprecision(12) << fromMetric << "\n"
+                    << "Expected result            : "
+                    << std::setprecision(12) << static_cast<ReturnT>(0.5) << "\n";
+
+      return passed;
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   MinkowskiDistance<PointT,ReturnT> theMetric;
+      //>
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: minkowskiThrow
+//*****************************************************************************
+template <typename PointT, typename ReturnT>
+class minkowskiThrow : public TestCase::TestStep
+{
+public:
+   minkowskiThrow()
+      : TestCase::TestStep(
+                 std::string("throw from ")+
+                 std::string(typeid(MinkowskiDistance<PointT,ReturnT>).name()))
+   {
+   }
+      //> This functor constructs with a simple default constructor since the
+      //  test body is not performing a direct comparison against an expected
+      //  value.
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::minkowskiThrow::operator(TestCase&)");
+
+      try
+      {
+         MinkowskiDistance<PointT,ReturnT> metric(0.5); // <-- Throw here.
+         test.report() << "Did not catch an exception!\n";
+
+         // If we get here, we didn't throw: failed test.
+         return false;
+      }
+      catch (const DomainError& e)
+      {
+         test.report() << "Caught expected exception:\n";
+
+         test.report() << blockIndent() << e;
+         e.stackTrace(test.report());
+         test.report() << endBlock;
+
+         // If we get here, we threw the correct exception: successful test.
+         return true;
+      }
+      catch (...)
+      {
+         test.report() << "Caught unexpected exception.\n";
+
+         // If we get here, we threw something unexpected: failed test.
+         return false;
+      }
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+};
+
+//*****************************************************************************
+// CONSTRUCTOR: TestMetrics::TestMetrics(int, char**)
+//*****************************************************************************
+TestMetrics::TestMetrics(int argc, char** argv)
+   : TestCase(argc, argv,
+              "Metrics: Metrics Functor Suite",
+              "Metrics_01",
+              "This test case tests defined distance Metrics.")
+{
+   EXCEPTION_TRY("Damkjer::TestMetrics::TestMetrics(int, char**)");
+
+   typedef std::vector<float>  FloatPtT;
+   typedef std::vector<double> DoublePtT;
+
+   registerStep(new testEuclidean<FloatPtT,float>());
+   registerStep(new testEuclidean<FloatPtT,double>());
+   registerStep(new testEuclidean<DoublePtT,float>());
+   registerStep(new testEuclidean<DoublePtT,double>());
+   registerStep(new testManhattan<FloatPtT,float>());
+   registerStep(new testManhattan<FloatPtT,double>());
+   registerStep(new testManhattan<DoublePtT,float>());
+   registerStep(new testManhattan<DoublePtT,double>());
+   registerStep(new testChebyshev<FloatPtT,float>());
+   registerStep(new testChebyshev<FloatPtT,double>());
+   registerStep(new testChebyshev<DoublePtT,float>());
+   registerStep(new testChebyshev<DoublePtT,double>());
+   registerStep(new testMinkowski<FloatPtT,float>());
+   registerStep(new testMinkowski<FloatPtT,double>());
+   registerStep(new testMinkowski<DoublePtT,float>());
+   registerStep(new testMinkowski<DoublePtT,double>());
+   registerStep(new minkowskiThrow<FloatPtT,float>());
+   registerStep(new minkowskiThrow<FloatPtT,double>());
+   registerStep(new minkowskiThrow<DoublePtT,float>());
+   registerStep(new minkowskiThrow<DoublePtT,double>());
+
+   EXCEPTION_RETHROW;
+}
+
+}
Index: Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.h
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.h	(revision 9)
+++ Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.h	(revision 9)
@@ -0,0 +1,35 @@
+//*****************************************************************************
+// FILE:        TestMetrics.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-AUG-05  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef TestMetrics_HEADER
+#define TestMetrics_HEADER
+
+#include "Util/UtilAPI.h"
+#include "Util/UnitTest/TestCase.h"
+
+namespace Damkjer
+{
+
+class TestMetrics : public TestCase
+{
+public:
+   TestMetrics(int, char**);
+      //>
+      //<
+};
+
+}
+
+#endif
Index: Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj	(revision 9)
+++ Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj	(revision 9)
@@ -0,0 +1,272 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|Win32">
+      <Configuration>OpenMP</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|x64">
+      <Configuration>OpenMP</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestMetrics.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="TestMetrics.cpp" />
+    <ClCompile Include="test_Metrics.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\Util.vcxproj">
+      <Project>{20fe2624-c64f-d61a-bd8f-1725a8e68a42}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>test_Metrics</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <CustomBuildAfterTargets>call $(TargetPath)</CustomBuildAfterTargets>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <CustomBuildAfterTargets>call $(TargetPath)</CustomBuildAfterTargets>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <CustomBuildAfterTargets>call $(TargetPath)</CustomBuildAfterTargets>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <CustomBuildAfterTargets>call $(TargetPath)</CustomBuildAfterTargets>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <CustomBuildAfterTargets>call $(TargetPath)</CustomBuildAfterTargets>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+    <CustomBuildStep />
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
Index: Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj.filters
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj.filters	(revision 9)
+++ Damkjer/Util/SpatialIndexing/Metrics/test/TestMetrics.vcxproj.filters	(revision 9)
@@ -0,0 +1,26 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4010ed24-e68d-4e6e-97b0-8b8bb335aa86}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{0c039d31-de79-478b-9dc5-c3378145e52a}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestMetrics.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="test_Metrics.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="TestMetrics.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
Index: Damkjer/Util/SpatialIndexing/Metrics/test/test_Metrics.cpp
===================================================================
--- Damkjer/Util/SpatialIndexing/Metrics/test/test_Metrics.cpp	(revision 9)
+++ Damkjer/Util/SpatialIndexing/Metrics/test/test_Metrics.cpp	(revision 9)
@@ -0,0 +1,33 @@
+//*****************************************************************************
+// FILE:        test_Metrics.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-26  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "damkjerConfig.h"
+#include "TestMetrics.h"
+
+using namespace Damkjer;
+
+//*****************************************************************************
+// main
+//*****************************************************************************
+int main(int argc, char** argv)
+{
+   EXCEPTION_TRY("main(int, char**)");
+
+   TestMetrics driver(argc, argv);
+
+   return driver.execute();
+
+   EXCEPTION_CATCHALL;
+}
Index: mkjer/Util/SpatialIndexing/VpTree/VpTree.cpp
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTree.cpp	(revision 7)
+++ 	(revision )
@@ -1,946 +1,0 @@
-//*****************************************************************************
-// FILE:        VpTree.cpp
-//
-//    Copyright (C)  2012 Kristian Damkjer.
-//
-// DESCRIPTION: This class is an implementation of the vantage point tree
-//              data structure described by Peter Yianilos in "Data
-//              Structures and Algorithms for Nearest Neighbor Search in
-//              General Metric Spaces".
-//
-// LIMITATIONS: See VpTree.h for full list of limitations.
-//
-// SOFTWARE HISTORY:
-//> 2012-SEP-11  K. Damkjer
-//               Initial Coding.
-//<
-//*****************************************************************************
-
-#ifdef _OPENMP
-#include <omp.h>
-#endif
-
-#include "VpTree.h"
-
-#include <algorithm>
-#include <iostream>
-
-namespace Damkjer
-{
-
-//*****************************************************************************
-// CLASS: VpTree::Node
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-class VpTree<T, DISTANCE>::Node
-{
-public:
-   Node();
-      //> The default constructor creates a null node.
-      //<
-    
-   Node(VpTree*);
-      //> Construct with a database reference.
-      //<
-    
-   virtual ~Node();
-      //> The default destructor. Virtual to ensure proper Node
-      //  destruction.
-      //<
-    
-   virtual void knn(const T&,
-                    const std::size_t&,
-                    std::priority_queue<ResultsCandidate>&,
-                    double&) const = 0;
-      //> The visitor that accumulates k nearest neighbor results.
-      //<
-
-   virtual void rnn(const T&,
-                    const double,
-                    std::priority_queue<ResultsCandidate>&) const = 0;
-      //> The visitor that accumulates fixed radius nearest neighbor
-      //  results.
-      //<
-
-protected:
-   VpTree<T, DISTANCE>* theTree;
-      //>
-      //<
-};
-
-//*****************************************************************************
-// CLASS: VpTree::Internal
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-class VpTree<T, DISTANCE>::Internal : public VpTree<T, DISTANCE>::Node
-{
-public:
-   Internal();
-      //> The default constructor creates a null internal node.
-      //<
-    
-   Internal(VpTree*);
-      //> Construct with a database reference.
-      //<
-    
-   virtual ~Internal();
-      //> The default destructor. Virtual to ensure proper Node
-      //  destruction.
-      //<
-    
-   std::size_t theIndex;
-      //> The index of the item in the internal database.
-      //<
-
-   double theInnerLowerBound;
-      //> The lower bound distance to elements on inner branch.
-      //<
-
-   double theInnerUpperBound;
-      //> The uuper bound distance to elements on inner branch.
-      //<
-
-   double theOuterLowerBound;
-      //> The lower bound distance to elements on outer branch.
-      //<
-
-   double theOuterUpperBound;
-      //> The upper bound distance to elements on outer branch.
-      //<
-
-   Node* theInnerBranch;
-      //> The inner branch partition containing elements closer than
-      //  theMedianPartition to this element.
-      //<
-
-   Node* theOuterBranch;
-      //> The outer branch partition containing elements at or beyond
-      //  theMedianPartition from this element.
-      //<
-
-   virtual void knn(const T&,
-                    const std::size_t&,
-                    std::priority_queue<ResultsCandidate>&,
-                    double&) const;
-      //> The visitor that accumulates k nearest neighbor results.
-      //<
-
-   virtual void rnn(const T&,
-                    const double,
-                    std::priority_queue<ResultsCandidate>&) const;
-      //> The visitor that accumulates fixed radius nearest neighbor
-      //  results.
-      //<
-};
-
-//*****************************************************************************
-// CLASS: VpTree::Leaf
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-class VpTree<T, DISTANCE>::Leaf : public VpTree<T, DISTANCE>::Node
-{
-public:
-   Leaf();
-      //> The default constructor creates a null leaf.
-      //<
-    
-   Leaf(VpTree*, const std::size_t&, const std::size_t&);
-      //> Construct a leaf representing the items in the provided index
-      //  range.
-      //<
-    
-   virtual ~Leaf(){}
-      //> The default destructor. Virtual to ensure proper Node
-      //  destruction.
-      //<
-    
-   virtual void knn(const T&,
-                    const std::size_t&,
-                    std::priority_queue<ResultsCandidate>&,
-                    double&) const;
-      //> The visitor that accumulates k nearest neighbor results.
-      //<
-
-   virtual void rnn(const T&,
-                    const double,
-                    std::priority_queue<ResultsCandidate>&) const;
-      //> The visitor that accumulates fixed radius nearest neighbor
-      //  results.
-      //<
-
-private:
-   std::size_t theHead;
-      //> The start of the index range prepresented by this Leaf.
-      //<
-
-   std::size_t theTail;
-      //> The end of the index range prepresented by this Leaf.
-      //<
-};
-
-//*****************************************************************************
-// CLASS: VpTree::Item
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-class VpTree<T, DISTANCE>::Item
-{
-public:
-   Item();
-      //> The default constructor creates a null node.
-      //<
-    
-   ~Item(){}
-      //> The default destructor. Intentionally non-virtual since Node is
-      //  a private inner class on VpTree.
-      //<
-    
-   bool operator< (const Item&) const;
-      //>
-      //<
-
-   std::size_t theIndex;
-      //> The index of the item in the input data set.
-      //<
-
-   T theElement;
-      //> The database object
-      //<
-   
-   double theDistance;
-      //> The most recent ancestral pivot history distance for this item.
-      //<
-};
-
-//*****************************************************************************
-// VpTree::ResultsCandidate
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-class VpTree<T, DISTANCE>::ResultsCandidate
-{
-public:
-   ResultsCandidate(const std::size_t&, const double);
-      //> Create a metric comparitor.
-      //<
-    
-   ~ResultsCandidate(){}
-      //> The default destructor. Intentionally non-virtual since
-      //  ResultsCandidate is a private inner class on VpTree.
-      //<
-
-   bool operator< (const ResultsCandidate&) const;
-      //> Compare result candidate distances to determine which is closer
-      //  to the query.
-      //<
-
-   std::size_t theIndex;
-      //> The index of the candidate in the internal database.
-      //<
-    
-   double theDistance;
-      //> The candidate's distance to the query point.
-      //<
-};
-
-//*****************************************************************************
-// VpTree::VpTree
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::VpTree()
-   : theRoot(0)
-   , theItems()
-   , theLeafCapacity(1)
-{
-}
-
-//*****************************************************************************
-// VpTree::VpTree
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-template<typename CONTAINER>
-inline VpTree<T, DISTANCE>::VpTree(const CONTAINER& elems,
-                                   const std::size_t& leafCapacity)
-   : theRoot(0)
-   , theItems(elems.size())
-   , theLeafCapacity((leafCapacity<1)?1:leafCapacity)
-{
-   #ifdef _OPENMP
-   omp_set_dynamic(1);
-   omp_set_num_threads(omp_get_num_procs());
-   #endif
-
-   #pragma omp parallel for
-   for (int i = 0; i < theItems.size(); ++i)
-   {
-       theItems[i].theIndex=i;
-       theItems[i].theElement=elems[i];
-   }
-
-   theRoot = makeTree(0, theItems.size());
-}
-                
-//*****************************************************************************
-// VpTree::~VpTree
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::~VpTree()
-{
-   delete theRoot;
-   theRoot = 0;
-}
-
-//*****************************************************************************
-// VpTree::Node::Node
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Node::Node()
-   : theTree(0)
-{
-}
-
-//*****************************************************************************
-// VpTree::Node::Node
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Node::Node(VpTree* tree)
-   : theTree(tree)
-{
-}
-
-//*****************************************************************************
-// VpTree::Node::~Node
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Node::~Node()
-{
-   theTree = 0;
-}
-
-//*****************************************************************************
-// VpTree::Internal::Internal
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Internal::Internal()
-   : Node()
-   , theIndex(0)
-   , theInnerLowerBound(0)
-   , theInnerUpperBound(0)
-   , theOuterLowerBound(0)
-   , theOuterUpperBound(0)
-   , theInnerBranch(0)
-   , theOuterBranch(0)
-{
-}
-
-//*****************************************************************************
-// VpTree::Internal::Internal
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Internal::Internal(VpTree<T, DISTANCE>* tree)
-   : Node(tree)
-   , theIndex(0)
-   , theInnerLowerBound(0)
-   , theInnerUpperBound(0)
-   , theOuterLowerBound(0)
-   , theOuterUpperBound(0)
-   , theInnerBranch(0)
-   , theOuterBranch(0)
-{
-}
-
-//*****************************************************************************
-// VpTree::Internal::~Internal
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Internal::~Internal()
-{
-   delete theInnerBranch;
-   delete theOuterBranch;
-   theInnerBranch = 0;
-   theOuterBranch = 0;
-}
-
-//*****************************************************************************
-// VpTree::Leaf::Leaf
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Leaf::Leaf()
-   : Node()
-   , theHead(0)
-   , theTail(0)
-{
-}
-
-//*****************************************************************************
-// VpTree::Leaf::Leaf
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Leaf::Leaf(VpTree* tree,
-                                         const std::size_t& head,
-                                         const std::size_t& tail)
-   : Node(tree)
-   , theHead(head)
-   , theTail(tail)
-{
-}
-
-//*****************************************************************************
-// VpTree::Item::Item
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::Item::Item()
-   : theIndex(0)
-   , theElement(0)
-   , theDistance(0)
-{
-}
-
-//*****************************************************************************
-// VpTree::Item::operator<
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline bool VpTree<T, DISTANCE>::Item::operator<(const Item& other) const
-{
-   return theDistance < other.theDistance;
-}
-
-//*****************************************************************************
-// VpTree::ResultsCandidate::ResultsCandidate
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline VpTree<T, DISTANCE>::ResultsCandidate::ResultsCandidate(
-                                                  const std::size_t& index,
-                                                  const double distance)
-   : theIndex(index)
-   , theDistance(distance)
-{
-}
-
-//*****************************************************************************
-// VpTree::ResultsCandidate::operator<
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-inline bool VpTree<T, DISTANCE>::ResultsCandidate::operator<(
-                                       const ResultsCandidate& other) const
-{
-   return theDistance < other.theDistance;
-}
-
-//*****************************************************************************
-// VpTree::randomSample
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-std::set<std::size_t> VpTree<T, DISTANCE>::randomSample(
-                                             const std::size_t& start,
-                                             const std::size_t& stop) const
-{
-//   std::size_t numSamps=(std::size_t)(ceil(sqrt((double)(stop - start))));
-   std::size_t numSamps=(stop-start > 5) ? 5 : (stop - start);
-
-   // If the range is smaller than the number of samples, just return the
-   // elements in the range.
-   if ((stop - start) <= numSamps)
-   {
-      std::vector<std::size_t> indices(stop-start, 0);
-
-      for (std::size_t i=start; i < stop; ++i)
-      {
-         indices[i-start]=i;
-      }
-        
-      return std::set<std::size_t>(indices.begin(), indices.end());
-   }
-    
-   std::set<std::size_t> samples;
-    
-   // If the range is close to the number of samples, select with better
-   // worst-case behvior
-   if ((stop - start) < numSamps*2)
-   {
-      std::size_t itemsNeeded=numSamps;
-        
-      for (std::size_t i = start;
-           samples.size() < numSamps && i < stop;
-           ++i)
-      {
-         if ((rand()/(RAND_MAX + 1.0)) < itemsNeeded/(stop-i))
-         {
-            samples.insert(i);
-            --itemsNeeded;
-         }
-      }
-   }
-   else
-   {
-      // Otherwise, if range dominates samples, select expecting to find
-      // unique samples
-      while (samples.size() < numSamps)
-      {
-         // Choose an arbitrary point
-         std::size_t val=(std::size_t)
-                         (rand()/(RAND_MAX + 1.0)*(stop-start)+start);
-            
-         samples.insert(val);
-      }
-   }
-   
-   return samples;
-}
-                                
-//*****************************************************************************
-// VpTree::selectVp
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-std::size_t VpTree<T, DISTANCE>::selectVp(const std::size_t& start,
-                                            const std::size_t& stop) const
-{
-#if 0
-    std::set<std::size_t> p=randomSample(start, stop);
-    
-   std::size_t bestP=*(p.begin());
-   double bestSpread=0;
-    
-   for (std::set<std::size_t>::const_iterator pItr=p.begin();
-        pItr != p.end();
-        ++pItr)
-   {
-      const T& pItem = theItems[*pItr].theElement;
-      
-      std::set<std::size_t> d=randomSample(start, stop);
-      
-      std::vector<std::pair<T,std::size_t> > dItems(d.size());
-      unsigned int i = 0;
-      
-      for (std::set<std::size_t>::const_iterator dItr=d.begin();
-           dItr != d.end();
-           ++dItr)
-      {
-          dItems[i]=theItems[*dItr];
-          ++i;
-      }
-
-      std::nth_element(
-              dItems.begin(),
-              dItems.begin() + dItems.size()/2,
-              dItems.end(),
-              MetricComparison(pItem));
-      
-      double mu = DISTANCE(pItem, dItems[dItems.size()/2].theElement);
-      
-      unsigned int k=1;
-      double x, oldM, newM;
-      x=oldM=newM=DISTANCE(pItem, dItems[0].theElement)-mu;
-      double oldS, newS;
-      oldS=newS=0;
-      
-      for (unsigned int i = 1; i < dItems.size(); ++i)
-      {
-         x=DISTANCE(pItem, dItems[i].theElement)-mu;
-         ++k;
-         newM=oldM+(x-oldM)/k;
-         newS=oldS+(x-oldM)*(x-newM);
-         oldM=newM;
-         oldS=newS;
-      }
-      
-      double spread=(k>1)?newS/(k-1):0.0;
-      
-      if (spread > bestSpread)
-      {
-          bestSpread=spread;
-          
-          bestP=*pItr;
-      }
-   }
-   
-   return bestP;
-#endif
-   // Choose an arbitrary point
-   return (std::size_t)(rand()/(RAND_MAX + 1.0)*(stop-start)+start);
-}
-
-//*****************************************************************************
-// VpTree::makeTree
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-typename VpTree<T, DISTANCE>::Node*
-VpTree<T, DISTANCE>::makeTree(const std::size_t& start,
-                                const std::size_t& stop)
-{
-   if (stop <= start) return 0;
-
-   std::size_t setSize = stop - start;
-   
-   if (setSize <= theLeafCapacity)
-   {
-      return new Leaf(this, start, stop);
-   }
-   
-   Internal* node=new Internal(this);
-   node->theIndex=start;
-
-   const std::size_t vp = selectVp(start, stop);
-   std::swap(theItems[start], theItems[vp]);
-   
-   // Identify bound elements
-   std::size_t outerLowerBound = (start + stop + 1)/2;
-   std::size_t innerLowerBound = start + 1;
-   
-   // Update Histories
-   double d_max=0;
-   double d_min=std::numeric_limits<double>::max();
-   for (std::size_t elem = stop; elem --> innerLowerBound; )
-   {
-      theItems[elem].theDistance = DISTANCE(theItems[start].theElement,
-                                            theItems[elem].theElement);
-      d_max = (theItems[elem].theDistance > d_max)
-              ? theItems[elem].theDistance : d_max;
-      d_min = (theItems[elem].theDistance < d_min)
-              ? theItems[elem].theDistance : d_min;
-   }
-   
-   // Put the median element in place
-   std::nth_element(
-           theItems.begin() + innerLowerBound,
-           theItems.begin() + outerLowerBound,
-           theItems.begin() + stop);
-
-   double d_mid=0;
-   for (std::size_t elem = outerLowerBound; elem --> innerLowerBound; )
-   {
-      d_mid = (theItems[elem].theDistance > d_mid)
-              ? theItems[elem].theDistance : d_mid;
-   }
-   
-   node->theInnerLowerBound=d_min;
-   node->theInnerUpperBound=d_mid;
-   node->theOuterLowerBound=theItems[outerLowerBound].theDistance;
-   node->theOuterUpperBound=d_max;
-   
-   #ifdef _OPENMP
-   static int threads = 0;
-   
-   if (threads < (omp_get_num_procs()-1))
-   {
-      omp_set_dynamic(1);
-      omp_set_num_threads(omp_get_num_procs());
-      omp_set_nested(1);
-      
-      #pragma omp atomic
-      ++threads;
-      
-      #pragma omp parallel
-      {         
-         #pragma omp sections nowait
-         {
-            node->theInnerBranch = makeTree(innerLowerBound,
-                                            outerLowerBound);
-              
-            #pragma omp section
-            node->theOuterBranch = makeTree(outerLowerBound,
-                                            stop);
-         }
-      }
-      
-      #pragma omp atomic
-      --threads;
-   }
-   else
-   #endif
-   {
-      node->theInnerBranch = makeTree(innerLowerBound,
-                                      outerLowerBound);
-      node->theOuterBranch = makeTree(outerLowerBound,
-                                      stop);
-   }
-   
-   return node;
-}
-
-//*****************************************************************************
-// VpTree::knn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-std::pair<std::deque<std::size_t>, std::deque<double> >
-VpTree<T, DISTANCE>::knn(const T& query,
-                           const std::size_t& k,
-                           const double limit) const
-{
-   std::priority_queue<ResultsCandidate> candidates;
-   double tau = limit;
-
-   theRoot->knn(query, k, candidates, tau);
-
-   std::deque<std::size_t> indices;
-   std::deque<double> distances;
-   
-   while(!candidates.empty())
-   {
-      indices.push_back(theItems[candidates.top().theIndex].theIndex);
-      distances.push_back(candidates.top().theDistance);
-      candidates.pop();
-   }
-
-   std::reverse(indices.begin(), indices.end());
-   std::reverse(distances.begin(), distances.end());
-
-   return std::make_pair(indices, distances);
-}
-
-//*****************************************************************************
-// VpTree::Internal::knn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-void
-VpTree<T, DISTANCE>::Internal::knn(
-        const T& query,
-        const std::size_t& k,
-        std::priority_queue<ResultsCandidate>& candidates,
-        double& kth_closest) const
-{
-   if (!(this->theTree)) return;
-   
-   double distance = DISTANCE(this->theTree->theItems[theIndex].theElement,
-                              query);
-
-   if (distance < kth_closest)
-   {
-      if (candidates.size() == k)
-      {
-          candidates.pop();
-      }
-      
-      candidates.push(ResultsCandidate(theIndex, distance));
-      
-      if (candidates.size() == k)
-      {
-          kth_closest = candidates.top().theDistance;
-      }
-   }
-
-   if (!(theInnerBranch || theOuterBranch))
-   {
-       return;
-   }
-
-   double middle = 0.5 * (theInnerUpperBound + theOuterLowerBound);
-
-   if (distance < middle)
-   {
-      if (theInnerBranch &&
-          (distance - theInnerUpperBound <= kth_closest) &&
-          (theInnerLowerBound - distance <= kth_closest))
-
-
-      if (theInnerBranch &&
-          (distance <= theInnerUpperBound + kth_closest) &&
-          (distance >= theInnerLowerBound - kth_closest))
-      {
-         theInnerBranch->knn(query, k, candidates, kth_closest);
-      }
-       
-      if (theOuterBranch &&
-          (distance >= theOuterLowerBound - kth_closest) &&
-          (distance <= theOuterUpperBound + kth_closest))
-      {
-         theOuterBranch->knn(query, k, candidates, kth_closest);
-      }
-   }
-   else
-   {
-      if (theOuterBranch &&
-          (distance >= theOuterLowerBound - kth_closest) &&
-          (distance <= theOuterUpperBound + kth_closest))
-      {
-         theOuterBranch->knn(query, k, candidates, kth_closest);
-      }
-       
-      if (theInnerBranch &&
-          (distance <= theInnerUpperBound + kth_closest) &&
-          (distance >= theInnerLowerBound - kth_closest))
-      {
-         theInnerBranch->knn(query, k, candidates, kth_closest);
-      }
-   }
-}
-
-//*****************************************************************************
-// VpTree::Leaf::knn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-void
-VpTree<T, DISTANCE>::Leaf::knn(
-        const T& query,
-        const std::size_t& k,
-        std::priority_queue<ResultsCandidate>& candidates,
-        double& kth_closest) const
-{
-   if (!(this->theTree)) return;
-   
-   // Scan the leaf
-   for (std::size_t item = theHead; item < theTail; ++item)
-   {
-      // This is the check state
-      double distance = DISTANCE(this->theTree->theItems[item].theElement,
-                                 query);
-      
-      if (distance < kth_closest)
-      {
-         if (candidates.size() == k)
-         {
-            candidates.pop();
-         }
-         
-         candidates.push(ResultsCandidate(item, distance));
-         
-         if (candidates.size() == k)
-         {
-            kth_closest = candidates.top().theDistance;
-         }
-      }
-   }
-}
-
-//*****************************************************************************
-// VpTree::rnn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-std::pair<std::deque<std::size_t>, std::deque<double> >
-VpTree<T, DISTANCE>::rnn(const T& query,
-                           const double range) const
-{
-   std::priority_queue<ResultsCandidate> candidates;
-
-   theRoot->rnn(query, range, candidates);
-
-   std::deque<std::size_t> indices;
-   std::deque<double> distances;
-
-   while(!candidates.empty())
-   {
-      indices.push_back(theItems[candidates.top().theIndex].theIndex);
-      distances.push_back(candidates.top().theDistance);
-      candidates.pop();
-   }
-
-   std::reverse(indices.begin(), indices.end());
-   std::reverse(distances.begin(), distances.end());
-
-   return std::make_pair(indices, distances);
-}
-
-//*****************************************************************************
-// VpTree::Internal::rnn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-void
-VpTree<T, DISTANCE>::Internal::rnn(
-        const T& query,
-        const double range,
-        std::priority_queue<ResultsCandidate>& candidates) const
-{
-   if (!(this->theTree)) return;
-
-   double distance = DISTANCE(this->theTree->theItems[theIndex].theElement,
-                              query);
-   
-   if (distance <= range)
-   {
-      candidates.push(ResultsCandidate(theIndex, distance));
-   }
-
-   if (!(theInnerBranch || theOuterBranch))
-   {
-       return;
-   }
-
-   double middle = 0.5 * (theInnerUpperBound + theOuterLowerBound);
-
-   if (distance < middle)
-   {
-      if (theInnerBranch &&
-          (distance <= theInnerUpperBound + range) &&
-          (distance >= theInnerLowerBound - range))
-      {
-         theInnerBranch->rnn(query, range, candidates);
-      }
-       
-      if (theOuterBranch &&
-          (distance >= theOuterLowerBound - range) &&
-          (distance <= theOuterUpperBound + range))
-      {
-         theOuterBranch->rnn(query, range, candidates);
-      }
-   }
-   else
-   {
-      if (theOuterBranch &&
-          (distance >= theOuterLowerBound - range) &&
-          (distance <= theOuterUpperBound + range))
-      {
-         theOuterBranch->rnn(query, range, candidates);
-      }
-       
-      if (theInnerBranch &&
-          (distance <= theInnerUpperBound + range) &&
-          (distance >= theInnerLowerBound - range))
-      {
-         theInnerBranch->rnn(query, range, candidates);
-      }
-   }
-}
-
-//*****************************************************************************
-// Leaf::rnn
-//*****************************************************************************
-template<typename T,
-         double (*DISTANCE)(const T&, const T&)>
-void
-VpTree<T, DISTANCE>::Leaf::rnn(
-        const T& query,
-        const double range,
-        std::priority_queue<ResultsCandidate>& candidates) const
-{
-   if (!(this->theTree)) return;
-
-   // Scan the leaf
-   for (std::size_t item = theHead; item < theTail; ++item)
-   {
-      double distance = DISTANCE(this->theTree->theItems[item].theElement,
-                                 query);
-      
-      if (distance <= range)
-      {
-         candidates.push(ResultsCandidate(item, distance));
-      }
-   }
-}
-
-}
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTree.h
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTree.h	(revision 7)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTree.h	(revision 9)
@@ -4,47 +4,52 @@
 //    Copyright (C)  2012 Kristian Damkjer.
 //
-// DESCRIPTION: This class is an implementation of the vantage point tree
-//              data structure described by Peter Yianilos in "Data
-//              Structures and Algorithms for Nearest Neighbor Search in
-//              General Metric Spaces".
-//
-//              This structure includes the enhancement to collapse subtrees
-//              near leaves into a single node. This change reduces overall
-//              storage and some recursion overhead, but may make queries
-//              less efficient if the leaf size is chosen to be too large.
-//
-// LIMITATIONS: The tree is currently coded as nearly the simplest version
-//              of the proposed structure. This yields close to the fastest
-//              construct time with potential limitations on query speed.
-//
-//              Extra effort is spent on finding a "good" pivot for large
-//              trees with more effort devoted as the tree coverage grows
-//              (currently determined by examining sqrt(size) elements for
-//              pivot). The thought is that selection of a better pivot
-//              carries more weight in queries as tree coverage increases.
-//
-//              The first proposed enhancement would be to track tighter
-//              bounds on the branch sub-spaces. We currently only track
-//              the median partition which provides only a loose upper
-//              bound on the inner partition and a tight lower bound on the
-//              outer partition. For a slight storage overhead, we can
-//              instead track the tight lower and upper bounds for each
-//              branch. Investing in this enhancement would allow for
-//              earlier pruning of branches at the cost of increased
-//              storage and construct time.
-//
-//              The second proposed enhancement would be to track distances
-//              to ancestral pivots. This change potentially incurs a
-//              signficant storage overhead, but allows for further
-//              explicit pruning or inclusion optimizations for range
-//              queries.
-//
-//              The final proposed enhancement would be to increase fan-out
-//              of the tree by establishing multiple partition boundaries,
-//              or by modifying the structure into an MVP tree.
+// DESCRIPTION: VpTree
+//
+//    This class is an implementation of the vantage point tree data structure
+//    described by Peter Yianilos in "Data Structures and Algorithms for
+//    Nearest Neighbor Search in General Metric Spaces".
+//
+//    This structure includes the enhancement to collapse subtrees near leaves
+//    into a single node. This change reduces overall storage and some
+//    recursion overhead, but may make queries less efficient if the leaf size
+//    is chosen to be too large.
+//
+// LIMITATIONS:
+//
+//    The tree is currently coded as VPsb tree to attempt to realize the best
+//    balance in construct and search performance.
+//
+//    Code was developed and analyzed to determine the benefit of enhancing
+//    the vantage point selection process. Extra effort was spent on finding a
+//    "good" pivot for large trees with more effort devoted as the tree
+//    coverage grows (determined by examining sqrt(size) elements for pivot).
+//    The thought was that selection of a better pivot carries more weight in
+//    queries as tree coverage increases. However, in practice, the vantage
+//    point selection seemed to have marginal, if any, effect on query time.
+//
+//    The tree includes the enhancement to track tight bounds on the branch
+//    sub-spaces. For a slight storage overhead, we track the tight lower and
+//    upper bounds for each branch which allows for earlier pruning of
+//    branches at the cost of slightly increased storage and construct time.
+//
+//    The tree also includes the enhancement to track distances to ancestral
+//    pivots. This change potentially incurs a signficant storage overhead,
+//    but allows for further explicit pruning or inclusion optimizations for
+//    range queries.
+//
+//    A final proposed enhancement would be to increase fan-out of the tree by
+//    establishing multiple partition boundaries, or by modifying the
+//    structure into an MVP tree. Of course, if that path is selected, we're
+//    really talking about a different data structure.
 //
 // SOFTWARE HISTORY:
+//
 //> 2012-SEP-11  K. Damkjer
 //               Initial Coding.
+//  2013-JUL-23  K. Damkjer
+//               Set typedefs to make code more readable and to allow for
+//               varying container and metric types. This is useful when the
+//               default double-precision is overkill. It is now easy to set
+//               types to float.
 //<
 //*****************************************************************************
@@ -52,14 +57,4 @@
 #ifndef VpTree_HEADER
 #define VpTree_HEADER
-
-#ifndef EXPORT
-   #if defined(MAKE_DEPENDING) || defined(TEMPLATE_INCLUSION)
-      #define EXPORT
-   #else
-      #define EXPORT export
-   #endif
-#endif
-
-#include "Util/SpatialIndexing/Metrics/Metrics.h"
 
 #include <vector>
@@ -69,4 +64,7 @@
 #include <limits>
 
+#include "damkjerConfig.h"
+#include "Util/SpatialIndexing/Metrics/Metrics.h"
+
 namespace Damkjer
 {
@@ -75,33 +73,42 @@
 // CLASS: VpTree
 //*****************************************************************************
-EXPORT template<typename T = std::vector<double>,
-         double (*DISTANCE)(const T&, const T&) = euclidean<T> >
+EXPORT template<typename PointT = std::vector<double>,
+                typename MetricT = EuclideanDistance<PointT> >
 class VpTree
 {
 public:
-   VpTree();
+   typedef typename PointT::value_type           CoordT;
+   typedef typename MetricT::value_type          DistT;
+   typedef std::size_t                           IndexT;
+   typedef std::pair<std::deque<IndexT>,
+                     std::deque<DistT> >         SearchResultsT;
+
+   VpTree(const MetricT& metric=MetricT(),
+          const IndexT& leafCapacity=8);
       //> The default constructor creates a null tree.
       //<
 
-   template<typename CONTAINER>
-   VpTree(const CONTAINER&, const std::size_t& leafCapacity=8);
-      //> Create a VpTree from a (probably unsorted) container of items.
-      //<
-    
+   template<typename DatabaseT>
+   VpTree(const DatabaseT&,
+          const MetricT& metric=MetricT(),
+          const IndexT& leafCapacity=8);
+      //> Create a VpTree from a (probably unsorted) database of items.
+      //<
+
    virtual ~VpTree();
       //> Free resources allocated by this tree.
       //<
    
-   std::pair<std::deque<std::size_t>, std::deque<double> > knn(
-           const T&,
-           const std::size_t&,
-           const double limit=std::numeric_limits<double>::max()) const;
+   SearchResultsT knn(
+                   const PointT&,
+                   const IndexT&,
+                   const DistT& limit=std::numeric_limits<DistT>::max()) const;
       //> Perform a k nearest neighbor search on the tree returning the
       //  indices of and distances to the k nearest neighbors.
       //<
    
-   std::pair<std::deque<std::size_t>, std::deque<double> > rnn(
-           const T&,
-           const double) const;
+   SearchResultsT rnn(
+           const PointT&,
+           const DistT&) const;
       //> Perform a fixed radius nearest neighbor search on the tree
       //  returning the indices of and distances to the neighbors in the
@@ -125,5 +132,7 @@
       //  intermediate priority queue of candidate results.
       //<
-    
+
+   typedef std::priority_queue<ResultsCandidate> ResultsSetT;
+
    class Node;
       //> The VpTree::Node class provides the private definition of
@@ -141,19 +150,19 @@
       //<
 
-   friend class VpTree<T, DISTANCE>::Node;
-   friend class VpTree<T, DISTANCE>::Internal;
-   friend class VpTree<T, DISTANCE>::Leaf;
-
-   Node* makeTree(const std::size_t&, const std::size_t&);
+   // All of the node-types need access to "theItems".
+   friend class VpTree<PointT, MetricT>::Node;
+   friend class VpTree<PointT, MetricT>::Internal;
+   friend class VpTree<PointT, MetricT>::Leaf;
+
+   Node* makeTree(const IndexT&, const IndexT&);
       //> Set this tree's root to be the root of the tree created from the
       //  argument set of metric-space elements.
       //<
     
-   std::size_t selectVp(const std::size_t&, const std::size_t&) const;
+   IndexT selectVp(const IndexT&, const IndexT&) const;
       //> Select a vantage point in the range between the provided indices.
       //<
     
-   std::set<std::size_t> randomSample(const std::size_t&,
-                                      const std::size_t&) const;
+   std::set<IndexT> randomSample(const IndexT&, const IndexT&) const;
       //> Select a random sample in the range between the provided indices.
       //<
@@ -170,6 +179,14 @@
       //<
    
-   std::size_t theLeafCapacity;
-      //>
+   IndexT theLeafCapacity;
+      //> Improve search efficiency by stopping recursion before completely
+      //  forming a binary search tree. The leaf capacity sets the threshold
+      //  for the number of elements that may be collapsed into a single node.
+      //  This threshold should be set by empirically testing the point at
+      //  which a linear search becomes more efficient than a binary search.
+      //<
+   
+   MetricT theMetric;
+      //> The distance metric used to construct and search this tree.
       //<
 };
@@ -177,6 +194,6 @@
 }
 
-#if defined(MAKE_DEPENDING) || defined(TEMPLATE_INCLUSION)
-#include "VpTree.cpp"
+#if MAKE_DEPENDING || TEMPLATE_INCLUSION
+#include "VpTree.hpp"
 #endif
 
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTree.hpp
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTree.hpp	(revision 9)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTree.hpp	(revision 9)
@@ -0,0 +1,962 @@
+//*****************************************************************************
+// FILE:        VpTree.cpp
+//
+//    Copyright (C)  2012 Kristian Damkjer.
+//
+// DESCRIPTION: This class is an implementation of the vantage point tree
+//              data structure described by Peter Yianilos in "Data
+//              Structures and Algorithms for Nearest Neighbor Search in
+//              General Metric Spaces".
+//
+// LIMITATIONS: See VpTree.h for full list of limitations.
+//
+// SOFTWARE HISTORY:
+//> 2012-SEP-11  K. Damkjer
+//               Initial Coding.
+//  2013-JUL-23  K. Damkjer
+//               Set typedefs to make code more readable and to allow for
+//               varying container and metric types. This is useful when the
+//               default double-precision is overkill. It is now easy to set
+//               types to float.
+//<
+//*****************************************************************************
+
+#if _OPENMP
+#include <omp.h>
+#endif
+
+#include "VpTree.h"
+
+#include <algorithm>
+#include <iostream>
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// CLASS: VpTree::Node
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+class VpTree<PointT, MetricT>::Node
+{
+public:
+   Node();
+      //> The default constructor creates a null node.
+      //<
+    
+   Node(VpTree*);
+      //> Construct with a database reference.
+      //<
+    
+   virtual ~Node();
+      //> The default destructor. Virtual to ensure proper Node
+      //  destruction.
+      //<
+    
+   virtual void knn(const PointT&,
+                    const IndexT&,
+                    ResultsSetT&,
+                    DistT&) const = 0;
+      //> The visitor that accumulates k nearest neighbor results.
+      //<
+
+   virtual void rnn(const PointT&,
+                    const DistT&,
+                    ResultsSetT&) const = 0;
+      //> The visitor that accumulates fixed-radius nearest neighbor
+      //  results.
+      //<
+
+protected:
+   VpTree<PointT, MetricT>* theTree;
+      //> The tree that this node belongs to.  Included to avoid reallocating
+      //  contained element data for each node. As a side effect, nodes
+      //  organize the tree's data contents through the construction process.
+      //
+      //  I personally debated including this pointer for quite a while since
+      //  it seemed like a bad design to have such a cyclic reference in a tree
+      //  structure, but it appears to be quite beneficial from a performance
+      //  perspective.
+      //<
+};
+
+//*****************************************************************************
+// CLASS: VpTree::Internal
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+class VpTree<PointT, MetricT>::Internal : public VpTree<PointT, MetricT>::Node
+{
+public:
+   Internal();
+      //> The default constructor creates a null internal node.
+      //<
+    
+   Internal(VpTree*);
+      //> Construct with a database reference.
+      //<
+    
+   virtual ~Internal();
+      //> The default destructor. Virtual to ensure proper Node
+      //  destruction.
+      //<
+    
+   IndexT theIndex;
+      //> The index of the item in the internal database.
+      //<
+
+   DistT theInnerLowerBound;
+      //> The lower bound distance to elements on inner branch.
+      //<
+
+   DistT theInnerUpperBound;
+      //> The uuper bound distance to elements on inner branch.
+      //<
+
+   DistT theOuterLowerBound;
+      //> The lower bound distance to elements on outer branch.
+      //<
+
+   DistT theOuterUpperBound;
+      //> The upper bound distance to elements on outer branch.
+      //<
+
+   Node* theInnerBranch;
+      //> The inner branch partition containing elements closer than
+      //  theMedianPartition to this element.
+      //<
+
+   Node* theOuterBranch;
+      //> The outer branch partition containing elements at or beyond
+      //  theMedianPartition from this element.
+      //<
+
+   virtual void knn(const PointT&,
+                    const IndexT&,
+                    ResultsSetT&,
+                    DistT&) const;
+      //> The visitor that accumulates k nearest neighbor results.
+      //<
+
+   virtual void rnn(const PointT&,
+                    const DistT&,
+                    ResultsSetT&) const;
+      //> The visitor that accumulates fixed radius nearest neighbor
+      //  results.
+      //<
+};
+
+//*****************************************************************************
+// CLASS: VpTree::Leaf
+//*****************************************************************************
+template<typename PointT,
+         typename MetricT>
+class VpTree<PointT, MetricT>::Leaf : public VpTree<PointT, MetricT>::Node
+{
+public:
+   Leaf();
+      //> The default constructor creates a null leaf.
+      //<
+    
+   Leaf(VpTree*, const IndexT&, const IndexT&);
+      //> Construct a leaf representing the items in the provided index
+      //  range.
+      //<
+    
+   virtual ~Leaf(){}
+      //> The default destructor. Virtual to ensure proper Node
+      //  destruction.
+      //<
+    
+   virtual void knn(const PointT&,
+                    const IndexT&,
+                    ResultsSetT&,
+                    DistT&) const;
+      //> The visitor that accumulates k nearest neighbor results.
+      //<
+
+   virtual void rnn(const PointT&,
+                    const DistT&,
+                    ResultsSetT&) const;
+      //> The visitor that accumulates fixed radius nearest neighbor
+      //  results.
+      //<
+
+private:
+   IndexT theHead;
+      //> The start of the index range prepresented by this Leaf.
+      //<
+
+   IndexT theTail;
+      //> The end of the index range prepresented by this Leaf.
+      //<
+};
+
+//*****************************************************************************
+// CLASS: VpTree::Item
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+class VpTree<PointT, MetricT>::Item
+{
+public:
+   Item();
+      //> The default constructor creates a null node.
+      //<
+    
+   ~Item(){}
+      //> The default destructor. Intentionally non-virtual since Node is
+      //  a private inner class on VpTree.
+      //<
+    
+   bool operator<(const Item&) const;
+      //>
+      //<
+
+   IndexT theIndex;
+      //> The index of the item in the input data set.
+      //<
+
+   PointT theElement;
+      //> The database object
+      //<
+   
+   DistT theDistance;
+      //> The most recent ancestral pivot history distance for this item.
+      //<
+};
+
+//*****************************************************************************
+// VpTree::ResultsCandidate
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+class VpTree<PointT, MetricT>::ResultsCandidate
+{
+public:
+   ResultsCandidate(const IndexT&, const DistT&);
+      //> Create a metric comparitor.
+      //<
+    
+   ~ResultsCandidate(){}
+      //> The default destructor. Intentionally non-virtual since
+      //  ResultsCandidate is a private inner class on VpTree.
+      //<
+
+   bool operator<(const ResultsCandidate&) const;
+      //> Compare result candidate distances to determine which is closer
+      //  to the query.
+      //<
+
+   IndexT theIndex;
+      //> The index of the candidate in the internal database.
+      //<
+    
+   DistT theDistance;
+      //> The candidate's distance to the query point.
+      //<
+};
+
+//*****************************************************************************
+// VpTree::VpTree
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::VpTree(const MetricT& metric,
+                                       const IndexT& leafCapacity)
+   : theRoot(0)
+   , theItems()
+   , theLeafCapacity((leafCapacity<1)?1:leafCapacity)
+   , theMetric(metric)
+{
+}
+
+//*****************************************************************************
+// VpTree::VpTree
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+template<typename DatabaseT>
+inline VpTree<PointT, MetricT>::VpTree(const DatabaseT& elems,
+                                       const MetricT& metric,
+                                       const IndexT& leafCapacity)
+   : theRoot(0)
+   , theItems(elems.size())
+   , theLeafCapacity((leafCapacity<1)?1:leafCapacity)
+   , theMetric(metric)
+{
+   #if _OPENMP
+   omp_set_dynamic(1);
+   omp_set_num_threads(omp_get_num_procs());
+   #endif
+
+   #pragma omp parallel for
+   for (int i = 0; i < theItems.size(); ++i)
+   {
+       theItems[i].theIndex=i;
+       theItems[i].theElement=elems[i];
+   }
+
+   theRoot = makeTree(0, theItems.size());
+}
+                
+//*****************************************************************************
+// VpTree::~VpTree
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::~VpTree()
+{
+   delete theRoot;
+   theRoot = 0;
+}
+
+//*****************************************************************************
+// VpTree::Node::Node
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Node::Node()
+   : theTree(0)
+{
+}
+
+//*****************************************************************************
+// VpTree::Node::Node
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Node::Node(VpTree* tree)
+   : theTree(tree)
+{
+}
+
+//*****************************************************************************
+// VpTree::Node::~Node
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Node::~Node()
+{
+   theTree = 0;
+}
+
+//*****************************************************************************
+// VpTree::Internal::Internal
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Internal::Internal()
+   : Node()
+   , theIndex(0)
+   , theInnerLowerBound(0)
+   , theInnerUpperBound(0)
+   , theOuterLowerBound(0)
+   , theOuterUpperBound(0)
+   , theInnerBranch(0)
+   , theOuterBranch(0)
+{
+}
+
+//*****************************************************************************
+// VpTree::Internal::Internal
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Internal::Internal(VpTree<PointT, MetricT>* tree)
+   : Node(tree)
+   , theIndex(0)
+   , theInnerLowerBound(0)
+   , theInnerUpperBound(0)
+   , theOuterLowerBound(0)
+   , theOuterUpperBound(0)
+   , theInnerBranch(0)
+   , theOuterBranch(0)
+{
+}
+
+//*****************************************************************************
+// VpTree::Internal::~Internal
+//*****************************************************************************
+template<typename PointT,
+         typename MetricT>
+inline VpTree<PointT, MetricT>::Internal::~Internal()
+{
+   delete theInnerBranch;
+   delete theOuterBranch;
+   theInnerBranch = 0;
+   theOuterBranch = 0;
+}
+
+//*****************************************************************************
+// VpTree::Leaf::Leaf
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Leaf::Leaf()
+   : Node()
+   , theHead(0)
+   , theTail(0)
+{
+}
+
+//*****************************************************************************
+// VpTree::Leaf::Leaf
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Leaf::Leaf(VpTree* tree,
+                                           const IndexT& head,
+                                           const IndexT& tail)
+   : Node(tree)
+   , theHead(head)
+   , theTail(tail)
+{
+}
+
+//*****************************************************************************
+// VpTree::Item::Item
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::Item::Item()
+   : theIndex(0)
+   , theElement(0)
+   , theDistance(0)
+{
+}
+
+//*****************************************************************************
+// VpTree::Item::operator<
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline bool VpTree<PointT, MetricT>::Item::operator<(const Item& other) const
+{
+   return theDistance < other.theDistance;
+}
+
+//*****************************************************************************
+// VpTree::ResultsCandidate::ResultsCandidate
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline VpTree<PointT, MetricT>::ResultsCandidate::ResultsCandidate(
+                                                      const IndexT& index,
+                                                      const DistT& distance)
+   : theIndex(index)
+   , theDistance(distance)
+{
+}
+
+//*****************************************************************************
+// VpTree::ResultsCandidate::operator<
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+inline bool VpTree<PointT, MetricT>::ResultsCandidate::operator<(
+                                           const ResultsCandidate& other) const
+{
+   return theDistance < other.theDistance;
+}
+
+//*****************************************************************************
+// VpTree::randomSample
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+std::set<typename VpTree<PointT, MetricT>::IndexT>
+VpTree<PointT, MetricT>::randomSample(const IndexT& start,
+                                      const IndexT& stop) const
+{
+   //***
+   // Sampling the sqrt of inputs, while thorough, is completely unnecessary.
+   // Leaving the note here for future reference.
+   //***
+   // IndexT numSamps=(IndexT)(ceil(sqrt((double)(stop - start))));
+
+   // A very small sample set of the population is sufficient
+   IndexT numSamps=(stop-start > 5) ? 5 : (stop - start);
+
+   //***
+   // If the range is smaller than the number of samples, just return the
+   // elements in the range.
+   //***
+   if ((stop - start) <= numSamps)
+   {
+      std::vector<IndexT> indices(stop-start, 0);
+
+      for (std::size_t i=start; i < stop; ++i)
+      {
+         indices[i-start]=i;
+      }
+        
+      return std::set<IndexT>(indices.begin(), indices.end());
+   }
+    
+   std::set<IndexT> samples;
+    
+   //***
+   // If the range is close to the number of samples, select with better
+   // worst-case behvior
+   //***
+   if ((stop - start) < numSamps*2)
+   {
+      IndexT itemsNeeded=numSamps;
+        
+      for (IndexT i = start; samples.size() < numSamps && i < stop; ++i)
+      {
+         if ((rand()/(RAND_MAX + 1.0)) < itemsNeeded/(stop-i))
+         {
+            samples.insert(i);
+            --itemsNeeded;
+         }
+      }
+   }
+   else
+   {
+      //***
+      // Otherwise, if range dominates samples, select expecting to find
+      // unique samples
+      //***
+      while (samples.size() < numSamps)
+      {
+         // Choose an arbitrary point
+         IndexT val=static_cast<IndexT>(rand() / (RAND_MAX + 1.0) *
+                                        (stop - start) + start);
+
+         samples.insert(val);
+      }
+   }
+   
+   return samples;
+}
+                                
+//*****************************************************************************
+// VpTree::selectVp
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+typename VpTree<PointT, MetricT>::IndexT
+VpTree<PointT, MetricT>::selectVp(const IndexT& start,
+                                  const IndexT& stop) const
+{
+   //***
+   // Choosing a vantage point that maximizes the balance of the sub-trees is
+   // theoretically advantageous. This involves selecting a vantage point in a 
+   // "corner" of the population. However, in practice, the trade for increased
+   // selection time dwarfs the benefit realized through search times. The
+   // incredibly simple approach of selecting a random member of the population
+   // is much simpler and yields almost identical search times in the data sets
+   // tested.
+   //
+   // The "intellegent" selection mode is included in the source code for
+   // reference, but dropped by the pre-processor.
+   //***
+
+#if 0
+   // Choose a point from a small sample set that maximizes spread 
+   std::set<IndexT> p=randomSample(start, stop);
+    
+   IndexT bestP=*(p.begin());
+   DistT bestSpread=0;
+    
+   for (std::set<IndexT>::const_iterator pItr=p.begin();
+        pItr != p.end();
+        ++pItr)
+   {
+      const VpTree<PointT, MetricT>::Item& pItem = theItems[*pItr];
+
+      std::set<IndexT> d=randomSample(start, stop);
+      
+      std::vector<VpTree<PointT, MetricT>::Item> dItems(d.size());
+      
+      IndexT i = 0;
+      
+      for (std::set<IndexT>::const_iterator dItr=d.begin();
+           dItr != d.end();
+           ++dItr)
+      {
+          dItems[i]=theItems[*dItr];
+          ++i;
+      }
+
+      std::nth_element(dItems.begin(),
+                       dItems.begin() + dItems.size()/2,
+                       dItems.end());
+      
+      DistT mu = theMetric(pItem.theElement,
+                           dItems[dItems.size()/2].theElement);
+
+      IndexT k=1;
+      DistT x, oldM, newM;
+
+      x=oldM=newM=theMetric(pItem.theElement,
+                            dItems[0].theElement)-mu;
+      
+      DistT oldS, newS;
+      oldS=newS=0;
+      
+      for (IndexT i = 1; i < dItems.size(); ++i)
+      {
+         x=theMetric(pItem.theElement,
+                     dItems[i].theElement)-mu;
+
+         ++k;
+         newM=oldM+(x-oldM)/k;
+         newS=oldS+(x-oldM)*(x-newM);
+         oldM=newM;
+         oldS=newS;
+      }
+      
+      DistT spread=static_cast<DistT>((k>1)?newS/(k-1):0.0);
+      
+      if (spread > bestSpread)
+      {
+          bestSpread=spread;
+
+          bestP=*pItr;
+      }
+   }
+   
+   return bestP;
+#else
+   // Simplest working case: just choose an arbitrary point
+   return static_cast<IndexT>(rand()/(RAND_MAX + 1.0)*(stop-start)+start);
+#endif
+}
+
+//*****************************************************************************
+// VpTree::makeTree
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+typename VpTree<PointT, MetricT>::Node*
+VpTree<PointT, MetricT>::makeTree(const IndexT& start, const IndexT& stop)
+{
+   if (stop <= start) return 0;
+
+   IndexT setSize = stop - start;
+   
+   if (setSize <= theLeafCapacity)
+   {
+      return new Leaf(this, start, stop);
+   }
+ 
+   Internal* node=new Internal(this);
+   node->theIndex=start;
+
+   const IndexT vp = selectVp(start, stop);
+   std::swap(theItems[start], theItems[vp]);
+   
+   // Identify bound elements
+   IndexT outerLowerBound = (start + stop + 1)/2;
+   IndexT innerLowerBound = start + 1;
+   
+   // Update histories
+   DistT d_max=0;
+   DistT d_min=std::numeric_limits<DistT>::max();
+   for (IndexT elem = stop; elem --> innerLowerBound; )
+   {
+      theItems[elem].theDistance = theMetric(theItems[start].theElement,
+                                             theItems[elem].theElement);
+      d_max = (theItems[elem].theDistance > d_max)
+              ? theItems[elem].theDistance : d_max;
+      d_min = (theItems[elem].theDistance < d_min)
+              ? theItems[elem].theDistance : d_min;
+   }
+   
+   // Put the median element in place
+   std::nth_element(
+           theItems.begin() + innerLowerBound,
+           theItems.begin() + outerLowerBound,
+           theItems.begin() + stop);
+
+   DistT d_mid=0;
+   for (IndexT elem = outerLowerBound; elem --> innerLowerBound; )
+   {
+      d_mid = (theItems[elem].theDistance > d_mid)
+              ? theItems[elem].theDistance : d_mid;
+   }
+   
+   node->theInnerLowerBound=d_min;
+   node->theInnerUpperBound=d_mid;
+   node->theOuterLowerBound=theItems[outerLowerBound].theDistance;
+   node->theOuterUpperBound=d_max;
+   
+   #if _OPENMP
+   static int threads = 0;
+   
+   if (threads < (omp_get_num_procs()-1))
+   {
+      omp_set_dynamic(1);
+      omp_set_num_threads(omp_get_num_procs());
+      omp_set_nested(1);
+      
+      #pragma omp atomic
+      ++threads;
+      
+      #pragma omp parallel
+      {         
+         #pragma omp sections nowait
+         {
+            node->theInnerBranch = makeTree(innerLowerBound,
+                                            outerLowerBound);
+              
+            #pragma omp section
+            node->theOuterBranch = makeTree(outerLowerBound, stop);
+         }
+      }
+      
+      #pragma omp atomic
+      --threads;
+   }
+   else
+   #endif
+   {
+      node->theInnerBranch = makeTree(innerLowerBound, outerLowerBound);
+      node->theOuterBranch = makeTree(outerLowerBound, stop);
+   }
+   
+   return node;
+}
+
+//*****************************************************************************
+// VpTree::knn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+typename VpTree<PointT, MetricT>::SearchResultsT
+VpTree<PointT, MetricT>::knn(const PointT& query,
+                             const IndexT& k,
+                             const DistT& limit) const
+{
+   ResultsSetT candidates;
+   DistT tau = limit;
+
+   theRoot->knn(query, k, candidates, tau);
+
+   std::deque<IndexT> indices;
+   std::deque<DistT> distances;
+
+
+   while(!candidates.empty())
+   {
+      indices.push_back(theItems[candidates.top().theIndex].theIndex);
+      distances.push_back(candidates.top().theDistance);
+      candidates.pop();
+   }
+
+   std::reverse(indices.begin(), indices.end());
+   std::reverse(distances.begin(), distances.end());
+
+   return std::make_pair(indices, distances);
+}
+
+//*****************************************************************************
+// VpTree::Internal::knn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+void
+VpTree<PointT, MetricT>::Internal::knn(
+        const PointT& query,
+        const IndexT& k,
+        ResultsSetT& candidates,
+        DistT& kth_closest) const
+{
+   if (!(theTree)) return;
+
+   DistT distance = theTree->theMetric(theTree->theItems[theIndex].theElement,
+                                       query);
+
+   if (distance < kth_closest)
+   {
+      if (candidates.size() == k)
+      {
+          candidates.pop();
+      }
+      
+      candidates.push(ResultsCandidate(theIndex, distance));
+      
+      if (candidates.size() == k)
+      {
+          kth_closest = candidates.top().theDistance;
+      }
+   }
+
+   if (!(theInnerBranch || theOuterBranch))
+   {
+       return;
+   }
+
+   DistT middle = static_cast<DistT>
+                  (0.5 * (theInnerUpperBound + theOuterLowerBound));
+
+   if (distance < middle)
+   {
+      if (theInnerBranch &&
+          (distance - theInnerUpperBound <= kth_closest) &&
+          (theInnerLowerBound - distance <= kth_closest))
+
+
+      if (theInnerBranch &&
+          (distance <= theInnerUpperBound + kth_closest) &&
+          (distance >= theInnerLowerBound - kth_closest))
+      {
+         theInnerBranch->knn(query, k, candidates, kth_closest);
+      }
+       
+      if (theOuterBranch &&
+          (distance >= theOuterLowerBound - kth_closest) &&
+          (distance <= theOuterUpperBound + kth_closest))
+      {
+         theOuterBranch->knn(query, k, candidates, kth_closest);
+      }
+   }
+   else
+   {
+      if (theOuterBranch &&
+          (distance >= theOuterLowerBound - kth_closest) &&
+          (distance <= theOuterUpperBound + kth_closest))
+      {
+         theOuterBranch->knn(query, k, candidates, kth_closest);
+      }
+       
+      if (theInnerBranch &&
+          (distance <= theInnerUpperBound + kth_closest) &&
+          (distance >= theInnerLowerBound - kth_closest))
+      {
+         theInnerBranch->knn(query, k, candidates, kth_closest);
+      }
+   }
+}
+
+//*****************************************************************************
+// VpTree::Leaf::knn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+void
+VpTree<PointT, MetricT>::Leaf::knn(
+        const PointT& query,
+        const IndexT& k,
+        ResultsSetT& candidates,
+        DistT& kth_closest) const
+{
+   if (!(theTree)) return;
+   
+   // Scan the leaf
+   for (IndexT item = theHead; item < theTail; ++item)
+   {
+      // This is the check state
+      DistT distance = theTree->theMetric(theTree->theItems[item].theElement,
+                                          query);
+      
+      if (distance < kth_closest)
+      {
+         if (candidates.size() == k)
+         {
+            candidates.pop();
+         }
+         
+         candidates.push(ResultsCandidate(item, distance));
+         
+         if (candidates.size() == k)
+         {
+            kth_closest = candidates.top().theDistance;
+         }
+      }
+   }
+}
+
+//*****************************************************************************
+// VpTree::rnn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+typename VpTree<PointT, MetricT>::SearchResultsT
+VpTree<PointT, MetricT>::rnn(const PointT& query,
+                             const DistT& range) const
+{
+   ResultsSetT candidates;
+
+   theRoot->rnn(query, range, candidates);
+
+   std::deque<IndexT> indices;
+   std::deque<DistT> distances;
+
+   while(!candidates.empty())
+   {
+      indices.push_back(theItems[candidates.top().theIndex].theIndex);
+      distances.push_back(candidates.top().theDistance);
+      candidates.pop();
+   }
+
+   std::reverse(indices.begin(), indices.end());
+   std::reverse(distances.begin(), distances.end());
+
+   return std::make_pair(indices, distances);
+}
+
+//*****************************************************************************
+// VpTree::Internal::rnn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+void VpTree<PointT, MetricT>::Internal::rnn(const PointT& query,
+                                            const DistT& range,
+                                            ResultsSetT& candidates) const
+{
+   if (!(theTree)) return;
+   
+   DistT distance = theTree->theMetric(theTree->theItems[theIndex].theElement,
+                                       query);
+
+   if (distance <= range)
+   {
+      candidates.push(ResultsCandidate(theIndex, distance));
+   }
+
+   if (!(theInnerBranch || theOuterBranch))
+   {
+       return;
+   }
+
+   DistT middle = static_cast<DistT>
+                  (0.5 * (theInnerUpperBound + theOuterLowerBound));
+
+   if (distance < middle)
+   {
+      if (theInnerBranch &&
+          (distance <= theInnerUpperBound + range) &&
+          (distance >= theInnerLowerBound - range))
+      {
+         theInnerBranch->rnn(query, range, candidates);
+      }
+       
+      if (theOuterBranch &&
+          (distance >= theOuterLowerBound - range) &&
+          (distance <= theOuterUpperBound + range))
+      {
+         theOuterBranch->rnn(query, range, candidates);
+      }
+   }
+   else
+   {
+      if (theOuterBranch &&
+          (distance >= theOuterLowerBound - range) &&
+          (distance <= theOuterUpperBound + range))
+      {
+         theOuterBranch->rnn(query, range, candidates);
+      }
+       
+      if (theInnerBranch &&
+          (distance <= theInnerUpperBound + range) &&
+          (distance >= theInnerLowerBound - range))
+      {
+         theInnerBranch->rnn(query, range, candidates);
+      }
+   }
+}
+
+//*****************************************************************************
+// Leaf::rnn
+//*****************************************************************************
+template<typename PointT, typename MetricT>
+void VpTree<PointT, MetricT>::Leaf::rnn(
+        const PointT& query,
+        const DistT& range,
+        ResultsSetT& candidates) const
+{
+   if (!(theTree)) return;
+
+   // Scan the leaf
+   for (IndexT item = theHead; item < theTail; ++item)
+   {
+      DistT distance = theTree->theMetric(theTree->theItems[item].theElement,
+                                          query);
+      
+      if (distance <= range)
+      {
+         candidates.push(ResultsCandidate(item, distance));
+      }
+   }
+}
+
+}
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTree.m
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTree.m	(revision 7)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTree.m	(revision 9)
@@ -5,5 +5,7 @@
 %
 % Description:
-%    This MATLAB class represents a simple vantage-point tree.
+%    This MATLAB class represents a vantage-point tree data structure. The
+%    class is derived from the MATLAB handle class to provide automated object
+%    descruction on calls to "clear".
 %
 % Limitations:
@@ -11,11 +13,16 @@
 %
 % Properties:
-%    theTree  - Brief description
+%    None.
 %
 % Methods:
-%        [tree] = VpTree(varargin)                 - Brief description
-%                 delete(tree)                     - Brief description
-%    [idx,dist] = knn(this, queries, k, varargin)  - Brief description
-%    [idx,dist] = rnn(this, data, radius)          - Brief description
+%        [tree] = VpTree(varargin)                 - VP Tree Constructor
+%                 delete(tree)                     - Release this object and
+%                                                    free memory.
+%    [idx,dist] = knn(this, queries, k, varargin)  - Perform a k-nearest
+%                                                    neighbor search against
+%                                                    the tree.
+%    [idx,dist] = rnn(this, data, radius)          - Perform a fixed-radius
+%                                                    nearest neighbor search
+%                                                    against the tree.
 %
 % Toolbox requirements:
@@ -26,8 +33,12 @@
 %
 % Data requirements:
-%    None.
+%    VpTreeAPI MEX library.
 %
 % References:
-%    None.
+%    Yianilos, P. N. (1993). Data Structures and Algorithms for Nearest
+%       Neighbor Search in General Metric Spaces. In Proceedings of the Fourth
+%       Annual ACM-SIAM Symposium on Discrete Algorithms (pp. 311321). SODA
+%       93. Philadelphia, PA, USA: Society for Industrial and Applied
+%       Mathematics. http://dl.acm.org/citation.cfm?id=313559.313789
 %
 % See Also:
@@ -45,6 +56,6 @@
    
    properties (Hidden=true, Access = private)
+      % The C++ VP-tree object owned by this handle class.
       theTree
-      theCleanUpObj
    end
    
@@ -57,5 +68,5 @@
                   'VpTree must be constructed with a set of observations');
          end
-         
+
          this.theTree = VpTreeAPI('create', varargin{1});
       end
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.cpp
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.cpp	(revision 8)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.cpp	(revision 9)
@@ -20,11 +20,17 @@
 //               Improved structure and documentation. Prevented double free of
 //               VP Tree memory and infinite locking of MEX library.
+//  2013-JUL-23  K. Damkjer
+//               Set typedefs to make code more readable and to allow for
+//               varying container and metric types. This is useful when the
+//               default double-precision is overkill. It is now easy to set
+//               types to float.
 //<
 //*****************************************************************************
 
-#ifdef _OPENMP
+#if _OPENMP
 #include <omp.h>
 #endif
 
+#include "damkjerConfig.h"
 #include "Util/MATLAB/ClassHandle.h"
 #include "VpTree.h"
@@ -32,6 +38,8 @@
 // Fix "wide char" definition for older versions of MATLAB. This must be placed
 // after other includes and before the mex.h include.
-#if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
-   #define CHAR16_T
+#if (defined(MATLAB_MAJOR) && defined(MATLAB_MINOR))
+   #if MATLAB_MAJOR <= 7 && MATLAB_MINOR <= 10 && defined(_CHAR16T)
+      #define CHAR16_T
+   #endif
 #endif
 
@@ -40,4 +48,9 @@
 namespace Damkjer
 {
+typedef std::vector<double>                      VPTAPI_PointT;
+typedef std::deque<VPTAPI_PointT>                VPTAPI_PointSetT;
+typedef MinkowskiDistance<VPTAPI_PointT, double> VPTAPI_MetricT;
+typedef VpTree<VPTAPI_PointT, VPTAPI_MetricT>    VPTAPI_TreeT;
+
 //*****************************************************************************
 // FUNCTION: vpTreeCreate
@@ -214,6 +227,5 @@
    //    This also speeds construction and destruction of the point database.
    //***
-   std::deque<std::vector<double> > pointData(elems,
-                                              std::vector<double>(dims));
+   VPTAPI_PointSetT pointData(elems, VPTAPI_PointT(dims));
    
    for (mwSize elem = elems; elem --> 0;)
@@ -221,5 +233,5 @@
       for (mwSize dim = dims; dim --> 0;)
       {
-         pointData[elem][dim]=data[elem*dims+dim];
+         pointData[elem][dim]=(VPTAPI_TreeT::CoordT)(data[elem*dims+dim]);
       }
    }
@@ -229,5 +241,12 @@
    // Tree object.
    //***
-   plhs[0] = ptrAsMat(new VpTree<>(pointData));
+   try
+   {
+      plhs[0] = ptrAsMat(new VPTAPI_TreeT(pointData, VPTAPI_MetricT(3.0)));
+   }
+   catch (const std::exception& e)
+   {
+      mexErrMsgIdAndTxt("Damkjer:vpTreeCreate:initError", e.what());
+   }
 }
 
@@ -250,5 +269,5 @@
 
    // Free the VP Tree through the ClassHandle named destructor.
-   destroyHandleTo<VpTree<> >(prhs[1]);
+   destroyHandleTo<VPTAPI_TreeT>(prhs[1]);
 }
 
@@ -276,5 +295,5 @@
 
    // Retrieve the tree object through the ClassHandle helper method.
-   const VpTree<>& tree = matAsObj<VpTree<> >(prhs[1]);
+   const VPTAPI_TreeT& tree = matAsObj<VPTAPI_TreeT>(prhs[1]);
 
    // The second parameter should be the query points.
@@ -324,5 +343,5 @@
     
    double* data = mxGetPr(queries);
-   std::deque<std::vector<double> > queryData(elems, std::vector<double>(dims));
+   VPTAPI_PointSetT queryData(elems, VPTAPI_PointT(dims));
 
    for (mwIndex elem = elems; elem --> 0;)
@@ -330,10 +349,11 @@
       for (mwIndex dim = dims; dim --> 0;)
       {
-         queryData[elem][dim]=data[elem*dims+dim];
+         queryData[elem][dim]=(VPTAPI_TreeT::CoordT)(data[elem*dims+dim]);
       }
    }
    
    // Get the desired neighborhood radius limit.
-   double radius = (*(double*)mxGetData(rData));
+   VPTAPI_TreeT::DistT radius = (VPTAPI_TreeT::DistT)
+                                (*(double*)mxGetData(rData));
 
    //***
@@ -362,5 +382,5 @@
    //***
 
-#ifdef _OPENMP
+#if _OPENMP
    omp_set_dynamic(1);
    omp_set_num_threads(omp_get_num_procs());
@@ -372,6 +392,5 @@
    // distance computations since they are required for the search algorithm.
    //***
-   std::vector<std::pair<std::deque<mwIndex>,
-                         std::deque<double> > > results(queryData.size());
+   std::deque<VPTAPI_TreeT::SearchResultsT> results(queryData.size());
 
    //***
@@ -391,9 +410,6 @@
    // place in a "critical section" since it involves exercising the MEX API.
    //***
-   std::vector<mxArray*> nbr_idxs;
-   std::vector<mwIndex*> point_idxs;
-   
-   nbr_idxs.reserve(queryData.size());
-   point_idxs.reserve(queryData.size());
+   std::deque<mxArray*> nbr_idxs;
+   std::deque<mwIndex*> point_idxs;
    
    for (int q = 0; q < queryData.size(); ++q)
@@ -446,9 +462,6 @@
       // MEX API.
       //***
-      std::vector<mxArray*> nbr_dists;
-      std::vector<double*>  point_dists;
-
-      nbr_dists.reserve(queryData.size());
-      point_dists.reserve(queryData.size());
+      std::deque<mxArray*> nbr_dists;
+      std::deque<double*>  point_dists;
 
       for (int q = 0; q < queryData.size(); ++q)
@@ -512,5 +525,5 @@
 
    // Retrieve the tree object through the ClassHandle helper method.
-   const VpTree<>& tree = matAsObj<VpTree<> >(prhs[1]);
+   const VPTAPI_TreeT& tree = matAsObj<VPTAPI_TreeT>(prhs[1]);
 
    // The second parameter should be the query points.
@@ -575,6 +588,5 @@
 
    double* data = mxGetPr(queries);
-   std::deque<std::vector<double> > queryData(elems,
-                                              std::vector<double>(dims));
+   VPTAPI_PointSetT queryData(elems, VPTAPI_PointT(dims));
 
    for (mwIndex elem = elems; elem --> 0;)
@@ -582,5 +594,5 @@
       for (mwIndex dim = dims; dim --> 0;)
       {
-         queryData[elem][dim]=data[elem*dims+dim];
+         queryData[elem][dim]=(VPTAPI_TreeT::CoordT)(data[elem*dims+dim]);
       }
    }
@@ -590,5 +602,6 @@
 
    // Get the desired neighborhood radius limit.
-   double radius = (*(double*)mxGetData(rData));
+   VPTAPI_TreeT::DistT radius = (VPTAPI_TreeT::DistT)
+                                (*(double*)mxGetData(rData));
 
    //***
@@ -617,5 +630,5 @@
    //***
 
-#ifdef _OPENMP
+#if _OPENMP
    omp_set_dynamic(1);
    omp_set_num_threads(omp_get_num_procs());
@@ -627,6 +640,5 @@
    // distance computations since they are required for the search algorithm.
    //***
-   std::vector<std::pair<std::deque<mwIndex>,
-                         std::deque<double> > > results(queryData.size());
+   std::deque<VPTAPI_TreeT::SearchResultsT> results(queryData.size());
 
    //***
@@ -646,9 +658,6 @@
    // place in a "critical section" since it involves exercising the MEX API.
    //***
-   std::vector<mxArray*> nbr_idxs;
-   std::vector<mwIndex*> point_idxs;
-   
-   nbr_idxs.reserve(queryData.size());
-   point_idxs.reserve(queryData.size());
+   std::deque<mxArray*> nbr_idxs;
+   std::deque<mwIndex*> point_idxs;
    
    for (int q = 0; q < queryData.size(); ++q)
@@ -701,9 +710,6 @@
       // MEX API.
       //***
-      std::vector<mxArray*> nbr_dists;
-      std::vector<double*>  point_dists;
-
-      nbr_dists.reserve(queryData.size());
-      point_dists.reserve(queryData.size());
+      std::deque<mxArray*> nbr_dists;
+      std::deque<double*>  point_dists;
 
       for (int q = 0; q < queryData.size(); ++q)
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj	(revision 9)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj	(revision 9)
@@ -0,0 +1,220 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|Win32">
+      <Configuration>OpenMP</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|x64">
+      <Configuration>OpenMP</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="VpTreeAPI.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\Util.vcxproj">
+      <Project>{20fe2624-c64f-d61a-bd8f-1725a8e68a42}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>VpTreeAPI</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <TargetExt>.mexw32</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <TargetExt>.mexw64</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <TargetExt>.mexw32</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <TargetExt>.mexw32</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <TargetExt>.mexw64</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <TargetExt>.mexw64</TargetExt>
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
Index: Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj.filters
===================================================================
--- Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj.filters	(revision 9)
+++ Damkjer/Util/SpatialIndexing/VpTree/VpTreeAPI.vcxproj.filters	(revision 9)
@@ -0,0 +1,18 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4010ed24-e68d-4e6e-97b0-8b8bb335aa86}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{0c039d31-de79-478b-9dc5-c3378145e52a}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="VpTreeAPI.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
Index: Damkjer/Util/Streams/BlockIndent.cpp
===================================================================
--- Damkjer/Util/Streams/BlockIndent.cpp	(revision 9)
+++ Damkjer/Util/Streams/BlockIndent.cpp	(revision 9)
@@ -0,0 +1,66 @@
+//*****************************************************************************
+// FILE:        BlockIndent.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: This class performs the function of block-indenting a stream.
+//              It is a convenience manipulator based heavily on the code
+//              provided at:
+//
+//     http://stackoverflow.com/questions/5280858/indenting-paragraph-with-cout
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-26  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "BlockIndent.h"
+
+#include <ostream>
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// blockIndent static variable instantiation
+//*****************************************************************************
+const int       blockIndent::INDENT_INDEX = std::ios_base::xalloc();
+std::deque<int> blockIndent::INDENTS;
+
+//*****************************************************************************
+// BlockIndent::operator()
+//*****************************************************************************
+Util_API std::ostream& blockIndent::operator()(std::ostream& output) const
+{
+   // Blocks should always start on a new line, but we don't always need a new
+   // line to start a block. What to do?
+   output << "\n";
+   output.iword(INDENT_INDEX) += theIndent;
+   INDENTS.push_front(theIndent);
+
+   return output;
+}
+
+//*****************************************************************************
+// endBlock
+//*****************************************************************************
+Util_API std::ostream& endBlock(std::ostream& output)
+{
+   // Blocks should always end with a new line, but we don't always need a new
+   // line to end a block. What to do?
+   output << "\n";
+
+   if (!blockIndent::INDENTS.empty())
+   {
+      int decr = blockIndent::INDENTS.front();
+      blockIndent::INDENTS.pop_front();
+      output.iword(blockIndent::INDENT_INDEX) -= decr;
+   }
+   
+   return output;
+}
+
+}
Index: Damkjer/Util/Streams/BlockIndent.h
===================================================================
--- Damkjer/Util/Streams/BlockIndent.h	(revision 9)
+++ Damkjer/Util/Streams/BlockIndent.h	(revision 9)
@@ -0,0 +1,82 @@
+//*****************************************************************************
+// FILE:        BlockIndent.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: blockIndent
+//
+//    This class performs the function of block-indenting a stream. It is a
+//    convenience manipulator based heavily on the code provided at:
+//
+//     http://stackoverflow.com/questions/5280858/indenting-paragraph-with-cout
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-26  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef BlockIndent_HEADER
+#define BlockIndent_HEADER
+
+#include <iosfwd>
+#include <deque>
+
+#include "Util/UtilAPI.h"
+#include "ManipulatorBase.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// FUNCTOR: blockIndent
+//*****************************************************************************
+class blockIndent : public ManipulatorBase<blockIndent>
+{
+public:
+   Util_API explicit blockIndent(long indent = 3)
+      : ManipulatorBase<blockIndent>()
+      , theIndent(indent)
+   {
+   }
+      //>
+      //<
+
+   Util_API std::ostream& operator()(std::ostream&) const;
+      //> This method provides a functor interface for operating on
+      //  std::ostream objects. This function cannot be templatized, otherwise
+      //  compilers will inline the method, thus exposing the private static
+      //  variables on the class to the shared library interface. Further, this
+      //  method is only valid for std::ostream objects since it manipulates
+      //  the object's std::ios_base::iword database in an output streaming
+      //  context.
+      //<
+
+   static int index() { return INDENT_INDEX; }
+      //>
+      //<
+
+private:
+
+   friend Util_API std::ostream& endBlock(std::ostream&);
+      //>
+      //<
+
+   static const int INDENT_INDEX;
+      //>
+      //<
+
+   static std::deque<int> INDENTS;
+      //>
+      //<
+   
+   const long theIndent;
+      //>
+      //<
+};
+
+}
+
+#endif
Index: Damkjer/Util/Streams/FormatFilter.cpp
===================================================================
--- Damkjer/Util/Streams/FormatFilter.cpp	(revision 9)
+++ Damkjer/Util/Streams/FormatFilter.cpp	(revision 9)
@@ -0,0 +1,225 @@
+//*****************************************************************************
+// FILE:        FormatFilter.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-AUG-04  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "damkjerConfig.h"
+#include "FormatFilter.h"
+#include "BlockIndent.h"
+
+#include <iostream>
+
+namespace Damkjer
+{
+//*****************************************************************************
+// FormatFilter static variable instantiation
+//*****************************************************************************
+const int FormatFilter::LINE_WIDTH_INDEX = std::ios_base::xalloc();
+
+//*****************************************************************************
+// FormatFilter::FormatFilter
+//*****************************************************************************
+FormatFilter::FormatFilter(std::ostream& output, long lineWidth)
+   : theDestination(output)
+   , theDestinationBuf(output.rdbuf())
+   , theCount(0)
+   , theLineWidth(lineWidth)
+{
+   EXCEPTION_TRY("Damkjer::FormatFilter::FormatFilter(std::ostream&, long)");
+
+   theDestination.iword(widthIndex()) = lineWidth;
+   theDestination.rdbuf(this);
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// FormatFilter::~FormatFilter
+//*****************************************************************************
+Util_API FormatFilter::~FormatFilter()
+{
+   if (!theBuffer.empty())
+   {
+      // flush the buffer, if needed.
+      overflow(NULL);
+   }
+
+   theDestination.rdbuf(theDestinationBuf);
+}
+
+//*****************************************************************************
+// FormatFilter::overflow
+//*****************************************************************************
+Util_API std::streambuf::int_type FormatFilter::overflow(int_type c)
+{
+   EXCEPTION_TRY("Damkjer::FormatFilter::overflow(int_type)");
+
+//   long lineWidth   = theDestination.iword(widthIndex());
+   long blockIndent = theDestination.iword(blockIndent::index());
+   long blockWidth  = theLineWidth - blockIndent;
+
+   const char* prefix = std::string(blockIndent, ' ').c_str();
+
+   if (traits_type::eq_int_type(traits_type::eof(), c))
+   {
+      return traits_type::not_eof(c);
+   }
+
+   switch (c)
+   {
+   case NULL:
+      theCount = 0;
+      theDestinationBuf->sputn(prefix, blockIndent);
+      theDestinationBuf->sputn(theBuffer.c_str(), theBuffer.size());
+      theBuffer.clear();
+      return c;
+
+   case '\n':
+   case '\r':
+      //***
+      // Explicit end of line: we flush our buffer to the underlying stream's
+      // buffer, and set our record of the line length to 0.
+      //***
+      
+      theBuffer += c;
+      theCount = 0;
+      theDestinationBuf->sputn(prefix, blockIndent);
+      theDestinationBuf->sputn(theBuffer.c_str(), theBuffer.size());
+      theBuffer.clear();
+      return c;
+
+   case '\a':
+      //***
+      // An "alert" character: sent to the underlying stream without recording
+      // its length, since it doesn't normally affect the a appearance of the
+      // output.
+      //***
+
+      return theDestinationBuf->sputc(c);
+
+   case '\t':
+      //***
+      // Tab: treated as moving to the next tab stop, which is assumed as
+      // happening every TAB_WIDTH characters.
+      //***
+
+      theBuffer += c;
+      theCount += TAB_WIDTH - theCount % TAB_WIDTH;
+
+      return c;
+
+   default:
+      //***
+      // Everything else: really basic buffering with word wrapping. We try to
+      // add the character to the buffer, and if it exceeds our line width, we
+      // search for the last space/tab in the buffer and break the line there.
+      // If there is no space/tab, we break the line at the limit.
+      //***
+      if (theCount >= blockWidth)
+      {
+         size_t wpos = theBuffer.find_last_of("\\/ \t");
+
+         if (wpos != string::npos)
+         {
+            theDestinationBuf->sputn(prefix, blockIndent);
+
+            switch (theBuffer[wpos])
+            {
+            case '\\':
+            case '/':
+               theDestinationBuf->sputn(theBuffer.c_str(), wpos+1);
+               break;
+            default:
+               theDestinationBuf->sputn(theBuffer.c_str(), wpos);
+            }
+
+            theCount = theBuffer.size()-wpos-1;
+            theBuffer = string(theBuffer, wpos+1);
+         }
+         else
+         {
+            theDestinationBuf->sputn(prefix, blockIndent);
+            theDestinationBuf->sputn(theBuffer.c_str(), theBuffer.size());
+            theBuffer.clear();
+            theCount = 0;
+         }
+
+         theDestinationBuf->sputc('\n');
+      }
+
+      theBuffer += c;
+      ++theCount;
+
+      return c;
+   }
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// sline
+//*****************************************************************************
+Util_API std::ostream& sline(std::ostream& output)
+{
+   EXCEPTION_TRY("Damkjer::sline(std::ostream&)");
+
+   long lineWidth   = output.iword(FormatFilter::widthIndex());
+
+   if (lineWidth == 0)
+   {
+      lineWidth = 79;
+      output.iword(FormatFilter::widthIndex()) = 79;
+   }
+
+   long blockIndent = output.iword(blockIndent::index());
+   long blockWidth  = lineWidth - blockIndent;
+//   long blockWidth  = (40 > lineWidth - blockIndent) ? 40 : lineWidth - blockIndent;
+
+   std::string line(blockWidth, '-');
+
+   output << line.c_str() << "\n";
+   
+   return output;
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// dline
+//*****************************************************************************
+Util_API std::ostream& dline(std::ostream& output)
+{
+   EXCEPTION_TRY("Damkjer::dline(std::ostream&)");
+
+   long lineWidth   = output.iword(FormatFilter::widthIndex());
+
+   if (lineWidth == 0)
+   {
+      lineWidth = 79;
+      output.iword(FormatFilter::widthIndex()) = 79;
+   }
+
+   long blockIndent = output.iword(blockIndent::index());
+   long blockWidth  = lineWidth - blockIndent;
+//   long blockWidth  = (40 > lineWidth - blockIndent) ? 40 : lineWidth - blockIndent;
+
+   std::string line(blockWidth, '=');
+
+   output << line.c_str() << "\n";
+   
+   return output;
+
+   EXCEPTION_RETHROW;
+}
+
+}
Index: Damkjer/Util/Streams/FormatFilter.h
===================================================================
--- Damkjer/Util/Streams/FormatFilter.h	(revision 9)
+++ Damkjer/Util/Streams/FormatFilter.h	(revision 9)
@@ -0,0 +1,103 @@
+//*****************************************************************************
+// FILE:        FormatFilter.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-AUG-04  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef ConsoleOutput_HEADER
+#define ConsoleOutput_HEADER
+
+#include <ostream>
+#include <streambuf>
+
+#include "Util/UtilAPI.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// CLASS: FormatFilter
+//*****************************************************************************
+class FormatFilter : public std::streambuf
+{
+public:
+   explicit FormatFilter(std::ostream&, long lineWidth = 79);
+      //> Create a block indent stream buffer.
+      //<
+
+   Util_API virtual ~FormatFilter();
+      //> Free resources allocated by this clas.
+      //<
+
+   static int widthIndex() { return LINE_WIDTH_INDEX; }
+
+private:
+   static const int LINE_WIDTH_INDEX;
+      //>
+      //<
+
+   static const int TAB_WIDTH = 8;
+      //> Define tab width as 8 spaces.
+      //<
+
+   Util_API int_type overflow(int_type);
+      //> This method basically implements a line-buffering stream buffer.
+      //
+      //  The algorithm is:
+      //
+      //  - Explicit end of line ("\r" or "\n"): we flush our buffer to the
+      //    underlying stream's buffer, and set our record of the line length
+      //    to 0.
+      //
+      //  - An "alert" character: sent to the underlying stream without
+      //    recording its length, since it doesn't normally affect the a
+      //    appearance of the output.
+      //
+      //  - Tab: treated as moving to the next tab stop, which is assumed as
+      //    happening every tab_width characters.
+      //
+      //  - Everything else: really basic buffering with word wrapping. We try
+      //    to add the character to the buffer, and if it exceeds our line
+      //    width, we search for the last space/tab in the buffer and break
+      //    the line there. If there is no space/tab, we break the line at the
+      //    limit.
+      //<
+
+   typedef std::basic_string<char_type> string;
+
+   std::size_t theCount;
+      //> The current count of characters in the block.
+      //<
+
+   std::ostream& theDestination;
+      //>
+      //<
+
+   std::streambuf* theDestinationBuf;
+      //> The pointer to the wrapped stream buffer.
+      //<
+
+   string theBuffer;
+      //> The actual buffer contents.
+      //<
+
+   long theLineWidth;
+      //>
+      //<
+};
+
+Util_API std::ostream& sline(std::ostream&);
+Util_API std::ostream& dline(std::ostream&);
+
+}
+
+#endif
Index: Damkjer/Util/Streams/ManipulatorBase.h
===================================================================
--- Damkjer/Util/Streams/ManipulatorBase.h	(revision 9)
+++ Damkjer/Util/Streams/ManipulatorBase.h	(revision 9)
@@ -0,0 +1,65 @@
+//*****************************************************************************
+// FILE:        ManipulatorBase.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: ManipulatorBase
+//
+//    ManipulatorBase is intended to provide the templated base class for
+//    stream manipulators modeled on the "Curiously Recurring Template Pattern"
+//    idiom. This idiom provides a simple interface for stream manipulators to
+//    be called with anonymous objects on input and output streams.
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-Aug-03  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef ManipulatorBase_HEADER
+#define ManipulatorBase_HEADER
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// CLASS: ManipulatorBase
+//*****************************************************************************
+template <class Manipulator>
+class ManipulatorBase
+{
+public:
+   template <class Stream>
+   Stream& operator()(Stream& stream) const
+   {
+      // call Manipulator::operator()
+      static_cast<const Manipulator&>(*this)(stream);
+      return stream;
+   }
+};
+
+}
+
+//*****************************************************************************
+// FUNCTION: operator<<(Ostream&, const ManipulatorBase<Manipulator>&)
+//*****************************************************************************
+template <class Ostream, class Manipulator>
+Ostream& operator<<(Ostream& outputStream,
+                    const Damkjer::ManipulatorBase<Manipulator>& manipulate)
+{
+   return manipulate(outputStream);
+}
+
+//*****************************************************************************
+// FUNCTION: operator>>(Istream&, const ManipulatorBase<Manipulator>&)
+//*****************************************************************************
+template <class Istream, class Manipulator>
+Istream& operator>>(Istream& inputStream,
+                    const Damkjer::ManipulatorBase<Manipulator>& manipulate)
+{
+   return manipulate(inputStream);
+}
+
+#endif
Index: Damkjer/Util/UnitTest/TestCase.cpp
===================================================================
--- Damkjer/Util/UnitTest/TestCase.cpp	(revision 9)
+++ Damkjer/Util/UnitTest/TestCase.cpp	(revision 9)
@@ -0,0 +1,250 @@
+//*****************************************************************************
+// FILE:        TestCase.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include <sstream>
+#include <iomanip>
+
+#include "damkjerConfig.h"
+#include "TestCase.h"
+
+#include "Util/Streams/BlockIndent.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// TestCase::TestCase
+//*****************************************************************************
+Util_API TestCase::TestCase(int argc, char** argv,
+                   const std::string& caseName,
+                   const std::string& caseID,
+                   const std::string& caseDescription,
+                   std::ostream& reportStream)
+   : theArgc(argc)
+   , theArgv(argv)
+   , theCaseName(caseName)
+   , theCaseID(caseID)
+   , theCaseDescription(caseDescription)
+   , theReportStream(reportStream)
+   , theDetailsIndent(0)
+   , theStartTime()
+   , theStepCount(0)
+   , theStreamFormatter(reportStream)
+{
+}
+   
+//*****************************************************************************
+// TestCase::argv
+//*****************************************************************************
+Util_API std::string TestCase::argv(int i) const
+{
+   EXCEPTION_TRY("Damkjer::TestCase::argv(int)");
+
+   if (i >= 0 && i < theArgc)
+   {
+      return theArgv[i];
+   }
+
+   //***
+   // In released code, there's not a whole lot that the user can do about
+   // this problem. This is a logic error and should be prevented through
+   // appropriate bounds checking on the input prior to calling the method.
+   //***
+   std::ostringstream msg;
+
+   msg << "Context : Retrieving argument vector (argv) element.\n"
+       << "Problem : Unable to access requested vector element.\n"
+       << "Cause   : Requested element, " << i << ", is out of bounds: [0, "
+       << theArgc << ").\n"
+       << "Solution: Restrict argument vector requests to element indices "
+       << "that are strictly less than the argument count if possible. "
+       << "Otherwise, contact support for assitance.";
+
+   throw OutOfRange(msg.str(),  MODULE, __FILE__, __LINE__);
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// TestCase::header
+//*****************************************************************************
+std::ostream& TestCase::header()
+{
+#if ( _WIN32 || _WIN64 )
+   QueryPerformanceCounter(&theStartTime);
+#elif ( __linux || __unix || __posix )
+   clock_gettime(CLOCK_MONOTONIC, &theStartTime);
+#else
+   // How else can we capture high-resolution timing information?
+#endif
+
+   std::time_t now = std::time(NULL);
+
+   theReportStream
+      << dline
+      << " TEST CASE   :  " << theCaseID << "\n"
+      << " NAME        :  " << theCaseName << "\n"
+      << "\n"
+      << " DESCRIPTION :\n";
+
+   // Indent this block by 4.
+   theReportStream << blockIndent(4);
+   theReportStream << theCaseDescription << "\n";
+   theReportStream << endBlock;
+
+   theReportStream
+      << dline
+      << sline
+      << " START TIME  :  " << std::asctime(std::localtime(&now))
+      << sline;
+
+   return theReportStream;
+}
+   
+//*****************************************************************************
+// TestCase::footer
+//*****************************************************************************
+std::ostream& TestCase::footer()
+{
+   double elapsed = 0;
+
+#if ( _WIN32 || _WIN64 )
+   TimeT stopTime;
+   QueryPerformanceCounter(&stopTime);
+
+   TimeT frequency;
+   QueryPerformanceFrequency(&frequency);
+
+   elapsed = 1.0 * (stopTime.QuadPart - theStartTime.QuadPart) /
+             frequency.QuadPart;
+#elif ( __linux || __unix || __posix )
+   TimeT stopTime;
+   clock_gettime(CLOCK_MONOTONIC, &stopTime);
+
+   elapsed = (stopTime.tv_sec - theStartTime.tv_sec) +
+             (stopTime.tv_nsec - theStartTime.tv_nsec) * 1e-9;
+#endif
+
+   unsigned int iElapsed = unsigned int(elapsed);
+
+   std::stringstream msg;
+   
+   char cfill = msg.fill('0');
+
+   msg << std::setw(2) << iElapsed / 3600 << ":"
+       << std::setw(2) << ((iElapsed / 60) % 60) << ":"
+       << std::setw(9) << std::fixed << std::setprecision(6)
+       << (elapsed-iElapsed+(iElapsed % 60));
+   
+   std::time_t now = std::time(NULL);
+
+   theReportStream
+//      << std::string(79,'-') << "\n"
+      << sline
+      << " STOP TIME   :  " << std::asctime(localtime(&now))
+      << sline
+      << dline
+      << " ELAPSED     :  " << msg.str() << "\n"
+      << dline;
+
+   return theReportStream;
+}
+
+//*****************************************************************************
+// TestCase::steps
+//*****************************************************************************
+int TestCase::steps()
+{
+   EXCEPTION_TRY("Damkjer::TestCase::steps()");
+
+   bool testPassed = false;
+   int passedTests = 0;
+
+   for (int i = 0; i < theSteps.size(); ++i)
+   {
+      testing(theSteps[i]->description());
+      theReportStream << blockIndent(theDetailsIndent);
+      testPassed = (*(theSteps[i]))(*this);
+      theReportStream << "\n" << ((testPassed) ? "[PASSED]" : "[FAILED]")
+                      << endBlock;
+
+      if (testPassed) ++passedTests;
+
+      theReportStream << sline;
+   }
+   
+   theReportStream << "Summary: " << passedTests << "/" << theSteps.size()
+                   << " tests passed.\n";
+
+   return (passedTests == theSteps.size()) ? EXIT_SUCCESS : EXIT_FAILURE;
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// TestCase::execute
+//*****************************************************************************
+Util_API int TestCase::execute()
+{
+   EXCEPTION_TRY("Damkjer::TestCase::execute()");
+
+   header();
+
+   theReportStream << blockIndent(4);
+   // Indent the body of the test report by 4.
+   int results = steps();
+   theReportStream << endBlock;
+
+   footer();
+
+   return results;
+
+   EXCEPTION_RETHROW;
+}
+
+//*****************************************************************************
+// TestCase::testing
+//*****************************************************************************
+void TestCase::testing(const std::string& description)
+{
+   std::ostringstream oss;
+   oss << ++theStepCount << ". ";
+   
+   theDetailsIndent = static_cast<long>(oss.str().length());
+
+   theReportStream << oss.str() << "Testing " << description << "...\n";
+
+   return;
+}
+
+
+//*****************************************************************************
+// TestCase::report
+//*****************************************************************************
+Util_API std::ostream& TestCase::report()
+{
+   return theReportStream;
+}
+
+//*****************************************************************************
+// TestCase::registerStep
+//*****************************************************************************
+Util_API std::size_t TestCase::registerStep(TestStep* step)
+{
+   theSteps.push_back(step);
+   return theSteps.size();
+}
+
+}
Index: Damkjer/Util/UnitTest/TestCase.h
===================================================================
--- Damkjer/Util/UnitTest/TestCase.h	(revision 9)
+++ Damkjer/Util/UnitTest/TestCase.h	(revision 9)
@@ -0,0 +1,167 @@
+//*****************************************************************************
+// FILE:        UnitTest.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef TestCase_HEADER
+#define TestCase_HEADER
+
+#if ( _WIN32 || _WIN64 )
+#include <windows.h>
+#elif ( __linux || __unix || __posix )
+#include <time.h>
+#endif
+
+#include <cassert>
+#include <iostream>
+#include <string>
+#include <ctime>
+#include <vector>
+
+#include "Util/UtilAPI.h"
+#include "Util/Streams/FormatFilter.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// CLASS: TestCase
+//*****************************************************************************
+class TestCase
+{
+public:
+#if ( _WIN32 || _WIN64 )
+   typedef LARGE_INTEGER TimeT;
+#elif ( __linux || __unix || __posix )
+   typedef timespec TimeT;
+#else
+   // How else can we capture high-resolution timing information?
+#endif
+
+   Util_API TestCase(int argc, char** argv,
+                     const std::string& caseName,
+                     const std::string& caseID,
+                     const std::string& caseDescription,
+                     std::ostream& reportStream=std::clog);
+      //> This constructor sets the name, ID, and description for the unit test
+      //  case. It also wraps an output stream with a report stream to easily
+      //  redirect and format test logs.
+      //<
+   
+   Util_API virtual ~TestCase(){}
+      //> Free resources owned by this class.
+      //<
+
+   Util_API virtual int execute();
+      //> Execute the test case. This method performs the simple sequence:
+      //  1) Output Header to the report stream
+      //  2) Run steps for the test
+      //  3) Output Footer to the report stream
+      //<
+
+   Util_API virtual std::ostream& report();
+      //>
+      //<
+
+   class TestStep
+   {
+   public:
+      Util_API TestStep(const std::string& description)
+         : theDescription(description)
+      {
+      }
+
+      Util_API const std::string& description() const { return theDescription; }
+
+      Util_API virtual bool operator()(TestCase&) const = 0;
+
+   private:
+      std::string theDescription;
+   };
+
+   Util_API std::size_t registerStep(TestStep* step);
+
+   Util_API int stepNum() const { return theStepCount; }
+
+   Util_API int argc() const { return theArgc; }
+      //> The command line argument count.
+      //<
+   
+   Util_API std::string argv(int i) const;
+      //> The requested command line argument, converted to a string.
+      //<
+private:
+   void testing(const std::string&);
+      //>
+      //<
+
+   std::ostream& header();
+      //> Header for the unit test case report entry.
+      //<
+   
+   int steps();
+      //>
+      //<
+
+   std::ostream& footer();
+      //> Footer for the unit test case report entry.
+      //<
+
+   int theArgc;
+      //>
+      //<
+
+   char** theArgv;
+      //>
+      //<
+
+   std::string theCaseName;
+      //>
+      //<
+
+   std::string theCaseID;
+      //>
+      //<
+
+   std::string theCaseDescription;
+      //>
+      //<
+   
+   std::ostream& theReportStream;
+      //>
+      //<
+
+   long theDetailsIndent;
+      //>
+      //<
+
+   TimeT theStartTime;
+      //>
+      //<
+
+   std::vector<TestStep*> theSteps;
+      //>
+      //<
+
+   int theStepCount;
+      //>
+      //<
+
+   FormatFilter theStreamFormatter;
+      //>
+      //<
+};
+
+}
+
+#endif
Index: Damkjer/Util/UnitTest/test/TestTestCase.cpp
===================================================================
--- Damkjer/Util/UnitTest/test/TestTestCase.cpp	(revision 9)
+++ Damkjer/Util/UnitTest/test/TestTestCase.cpp	(revision 9)
@@ -0,0 +1,272 @@
+//*****************************************************************************
+// FILE:        TestTestCase.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: TestTestCase
+//
+//    See TestTestCase header for detailed description.
+//
+// DESCRIPTION: stepReport
+//
+//    See TestTestCase header for detailed description.
+//
+// DESCRIPTION: stepIncr
+//
+//    See TestTestCase header for detailed description.
+//
+// DESCRIPTION: passArgc
+//
+//    See TestTestCase header for detailed description.
+//
+// DESCRIPTION: passArgv
+//
+//    See TestTestCase header for detailed description.
+//
+// DESCRIPTION: argvThrow
+//
+//    See TestTestCase header for detailed description.
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include <sstream>
+
+#include "damkjerConfig.h"
+#include "TestTestCase.h"
+#include "Util/Streams/BlockIndent.h"
+
+namespace Damkjer
+{
+
+//*****************************************************************************
+// FUNCTOR: stepReport
+//*****************************************************************************
+class stepReport : public TestCase::TestStep
+{
+public:
+   explicit stepReport(int expected)
+      : TestCase::TestStep("sending a message to the step method")
+      , theExpectedValue(expected)
+   {
+   }
+      //> This functor constructs with a single parameter representing an
+      //  integer expected value.
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      test.report() << "Test Number: " << test.stepNum() << "\n"
+                    << "Expecting  : " << theExpectedValue << "\n";
+      return (test.stepNum() == theExpectedValue);
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   int theExpectedValue;
+      //> The expected value for this test step.
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: stepIncr
+//*****************************************************************************
+class stepIncr : public TestCase::TestStep
+{
+public:
+   explicit stepIncr(int expected)
+      : TestCase::TestStep("another step to ensure step values increment as "
+                           "expected")
+      , theExpectedValue(expected)
+   {
+   }
+      //> This functor constructs with a single parameter representing an
+      //  integer expected value.
+      //<
+
+   bool operator()(TestCase& test) const
+   {
+      test.report() << "Test Number: " << test.stepNum() << "\n"
+                    << "Expecting  : " << theExpectedValue << "\n";
+      return (test.stepNum() == theExpectedValue);
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   int theExpectedValue;
+      //> The expected value for this test step.
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: passArgc
+//*****************************************************************************
+class passArgc : public TestCase::TestStep
+{
+public:
+   explicit passArgc(int expected)
+      : TestCase::TestStep("argc pass-through")
+      , theExpectedValue(expected)
+   {
+   }
+      //> This functor constructs with a single parameter representing an
+      //  integer expected value.
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      test.report() << "argc     : " << test.argc() << "\n"
+                    << "Expecting: " << theExpectedValue << "\n";
+      return (test.argc() == theExpectedValue);
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   int theExpectedValue;
+      //> The expected value for this test step.
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: passArgv
+//*****************************************************************************
+class passArgv : public TestCase::TestStep
+{
+public:
+   explicit passArgv(char** expected)
+      : TestCase::TestStep("argv pass-through")
+      , theExpectedValues(expected)
+   {
+   }
+      //> This functor constructs with a single parameter representing a
+      //  character pointer array of expected values.
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      bool check = true;
+
+      for (int i = 0; i < test.argc() && check; ++i)
+      {
+         std::ostringstream argStm;
+         argStm << "argv[" << i << "]";
+
+         std::ostringstream expStm;
+         expStm << "Expecting";
+
+         int pad = static_cast<int>(argStm.str().length()) -
+                   static_cast<int>(expStm.str().length());
+
+         argStm << std::string(((pad < 0) ? -pad : 0), ' ') << ": ";
+         expStm << std::string(((pad > 0) ?  pad : 0), ' ') << ": ";
+
+         test.report() << argStm.str() << test.argv(i) << "\n"
+                       << expStm.str() << theExpectedValues[i] << "\n";
+
+         check &= (strcmp(theExpectedValues[i], test.argv(i).c_str()) == 0);
+      }
+
+      return check;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+
+private:
+   char** theExpectedValues;
+      //> The expected values for this test step.
+      //<
+};
+
+//*****************************************************************************
+// FUNCTOR: argvThrow
+//*****************************************************************************
+class argvThrow : public TestCase::TestStep
+{
+public:
+   argvThrow()
+      : TestCase::TestStep("throw from argv")
+   {
+   }
+      //> This functor constructs with a simple default constructor since the
+      //  test body is not performing a direct comparison against an expected
+      //  value.
+      //<
+   
+   bool operator()(TestCase& test) const
+   {
+      EXCEPTION_TRY("Damkjer::argvThrow::operator(TestCase&)");
+
+      try
+      {
+         test.report() << test.argv(test.argc()) << "\n";
+         test.report() << "Did not catch an exception!\n";
+
+         // If we get here, we didn't throw: failed test.
+         return false;
+      }
+      catch (const OutOfRange& e)
+      {
+         test.report() << "Caught expected exception:\n";
+
+         test.report() << blockIndent() << e;
+         e.stackTrace(test.report());
+         test.report() << endBlock;
+
+         // If we get here, we threw the correct exception: successful test.
+         return true;
+      }
+      catch (...)
+      {
+         test.report() << "Caught unexpected exception.\n";
+
+         // If we get here, we threw something unexpected: failed test.
+         return false;
+      }
+
+      EXCEPTION_RETHROW;
+   }
+      //> The parentheses operator represents the body of the test step
+      //  function. It will perform the necessary evaluation and return true if
+      //  and only if the test passes.
+      //<
+};
+
+//*****************************************************************************
+// CONSTRUCTOR: TestTestCase::TestTestCase(int, char**)
+//*****************************************************************************
+TestTestCase::TestTestCase(int argc, char** argv)
+   : TestCase(argc, argv,
+              "TestCase: Basic Functionality",
+              "TestCase_01",
+              "This test case tests basic TestCase functionality.")
+{
+   //***
+   // The "step" variable is only needed for this unit test to validate
+   // expected increments.
+   //***
+   int step = 0;
+
+   registerStep(new stepReport(++step));
+   registerStep(new stepIncr(++step));
+   registerStep(new passArgc(argc));
+   registerStep(new passArgv(argv));
+   registerStep(new argvThrow());
+}
+
+}
Index: Damkjer/Util/UnitTest/test/TestTestCase.h
===================================================================
--- Damkjer/Util/UnitTest/test/TestTestCase.h	(revision 9)
+++ Damkjer/Util/UnitTest/test/TestTestCase.h	(revision 9)
@@ -0,0 +1,35 @@
+//*****************************************************************************
+// FILE:        TestTestCase.h
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-24  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#ifndef TestTestCase_HEADER
+#define TestTestCase_HEADER
+
+#include "Util/UtilAPI.h"
+#include "Util/UnitTest/TestCase.h"
+
+namespace Damkjer
+{
+
+class TestTestCase : public TestCase
+{
+public:
+   TestTestCase(int, char**);
+      //>
+      //<
+};
+
+}
+
+#endif
Index: Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj
===================================================================
--- Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj	(revision 9)
+++ Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj	(revision 9)
@@ -0,0 +1,266 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|Win32">
+      <Configuration>OpenMP</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|x64">
+      <Configuration>OpenMP</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="TestTestCase.cpp" />
+    <ClCompile Include="test_TestCase.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestTestCase.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\Util.vcxproj">
+      <Project>{20fe2624-c64f-d61a-bd8f-1725a8e68a42}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>test_TestCase</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <OutDir>$(SolutionDir)test-bin\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)\includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <SubSystem>Console</SubSystem>
+    </Link>
+    <PostBuildEvent>
+      <Command>SETLOCAL
+SET PATH=%PATH%;$(SolutionDir)lib\$(Platform)\$(Configuration)\
+call $(TargetPath) &gt; $(TargetDir)$(TargetName).txt 2&gt;&amp;1
+ENDLOCAL</Command>
+      <Message>Run Unit Test</Message>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
Index: Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj.filters
===================================================================
--- Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj.filters	(revision 9)
+++ Damkjer/Util/UnitTest/test/TestUnitTest.vcxproj.filters	(revision 9)
@@ -0,0 +1,26 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4010ed24-e68d-4e6e-97b0-8b8bb335aa86}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{0c039d31-de79-478b-9dc5-c3378145e52a}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="test_TestCase.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="TestTestCase.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="TestTestCase.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>
Index: Damkjer/Util/UnitTest/test/test_TestCase.cpp
===================================================================
--- Damkjer/Util/UnitTest/test/test_TestCase.cpp	(revision 9)
+++ Damkjer/Util/UnitTest/test/test_TestCase.cpp	(revision 9)
@@ -0,0 +1,33 @@
+//*****************************************************************************
+// FILE:        test_TestCase.cpp
+//
+//    Copyright (C)  2013 Kristian Damkjer.
+//
+// DESCRIPTION: 
+//
+// LIMITATIONS: 
+//
+// SOFTWARE HISTORY:
+//> 2012-JUL-26  K. Damkjer
+//               Initial Coding.
+//<
+//*****************************************************************************
+
+#include "damkjerConfig.h"
+#include "TestTestCase.h"
+
+using namespace Damkjer;
+
+//*****************************************************************************
+// main
+//*****************************************************************************
+int main(int argc, char** argv)
+{
+   EXCEPTION_TRY("main(int, char**)");
+
+   TestTestCase driver(argc, argv);
+
+   return driver.execute();
+
+   EXCEPTION_CATCHALL;
+}
Index: Damkjer/Util/Util.vcxproj
===================================================================
--- Damkjer/Util/Util.vcxproj	(revision 9)
+++ Damkjer/Util/Util.vcxproj	(revision 9)
@@ -0,0 +1,226 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|Win32">
+      <Configuration>OpenMP</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="OpenMP|x64">
+      <Configuration>OpenMP</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\damkjerConfig.h" />
+    <ClInclude Include="Exception\Exception.h" />
+    <ClInclude Include="MATLAB\ClassHandle.h" />
+    <ClInclude Include="MATLAB\ClassHandle.hpp" />
+    <ClInclude Include="SpatialIndexing\Metrics\Metrics.h" />
+    <ClInclude Include="SpatialIndexing\VpTree\VpTree.h" />
+    <ClInclude Include="SpatialIndexing\VpTree\VpTree.hpp" />
+    <ClInclude Include="Streams\BlockIndent.h" />
+    <ClInclude Include="Streams\FormatFilter.h" />
+    <ClInclude Include="Streams\ManipulatorBase.h" />
+    <ClInclude Include="UnitTest\TestCase.h" />
+    <ClInclude Include="UtilAPI.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Exception\Exception.cpp" />
+    <ClCompile Include="Streams\BlockIndent.cpp" />
+    <ClCompile Include="Streams\FormatFilter.cpp" />
+    <ClCompile Include="UnitTest\TestCase.cpp" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>Util</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <OutDir>$(SolutionDir)lib\$(Platform)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN32;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN64;_DEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|Win32'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN32;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+    </ClCompile>
+    <Link>
+      <TargetMachine>MachineX86</TargetMachine>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='OpenMP|x64'">
+    <ClCompile>
+      <PreprocessorDefinitions>Util_DLL;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;WIN64;NDEBUG;_WINDOWS;TEMPLATE_INCLUSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalIncludeDirectories>$(SolutionDir);$(MATLAB_R2012A)\extern\include;$(SolutionDir)includes\eigen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <OpenMPSupport>true</OpenMPSupport>
+      <WarningLevel>TurnOffAllWarnings</WarningLevel>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>libmx.lib;libmat.lib;libmex.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalLibraryDirectories>$(SolutionDir)lib\$(Platform)\$(Configuration)\;$(MATLAB_R2012A)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
Index: Damkjer/Util/Util.vcxproj.filters
===================================================================
--- Damkjer/Util/Util.vcxproj.filters	(revision 9)
+++ Damkjer/Util/Util.vcxproj.filters	(revision 9)
@@ -0,0 +1,69 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4010ed24-e68d-4e6e-97b0-8b8bb335aa86}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{0c039d31-de79-478b-9dc5-c3378145e52a}</UniqueIdentifier>
+      <Extensions>h;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Template Implementation Files">
+      <UniqueIdentifier>{62f4b789-a14a-43c6-90be-3878d8e102cf}</UniqueIdentifier>
+      <Extensions>hpp;ipp</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="MATLAB\ClassHandle.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="MATLAB\ClassHandle.hpp">
+      <Filter>Template Implementation Files</Filter>
+    </ClInclude>
+    <ClInclude Include="SpatialIndexing\Metrics\Metrics.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="SpatialIndexing\VpTree\VpTree.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="SpatialIndexing\VpTree\VpTree.hpp">
+      <Filter>Template Implementation Files</Filter>
+    </ClInclude>
+    <ClInclude Include="UtilAPI.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Exception\Exception.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="UnitTest\TestCase.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Streams\ManipulatorBase.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Streams\BlockIndent.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Streams\FormatFilter.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="..\damkjerConfig.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Exception\Exception.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="UnitTest\TestCase.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Streams\BlockIndent.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Streams\FormatFilter.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>
Index: Damkjer/Util/UtilAPI.h
===================================================================
--- Damkjer/Util/UtilAPI.h	(revision 9)
+++ Damkjer/Util/UtilAPI.h	(revision 9)
@@ -0,0 +1,34 @@
+//*****************************************************************************
+// FILE: UtilAPI.h
+//
+// COPYRIGHT:
+//    Copyright (c) Kristian Damkjer 2013
+//
+// DESCRIPTION:
+//    Macro definitions for the Util Library API.
+//
+// LIMITATIONS:
+//   None.
+//
+// SOFTWARE HISTORY:
+//    2013 JUL 26  K. Damkjer
+//       Initial Coding.
+//
+//*****************************************************************************
+
+#ifndef UtilAPI_HEADER
+#define UtilAPI_HEADER
+
+#ifndef Util_API
+   #if _WINDLL
+      #if Util_DLL
+         #define Util_API __declspec(dllexport)
+      #else
+         #define Util_API __declspec(dllimport)
+      #endif
+   #else
+      #define Util_API
+   #endif
+#endif
+
+#endif
Index: Damkjer/Util/Widgets/timebar.m
===================================================================
--- Damkjer/Util/Widgets/timebar.m	(revision 7)
+++ Damkjer/Util/Widgets/timebar.m	(revision 9)
@@ -78,5 +78,4 @@
 end
 
-
 function [message] = timeString(seconds)
    if (seconds > 7200)
@@ -87,3 +86,8 @@
       message = [num2str(seconds) 's'];
    end
+% message = sprintf('%02d:%02d:%02d',...
+%                   floor(seconds/3600),...
+%                   mod(floor(seconds/60),60),...
+%                   floor(mod(seconds,60)));
 end
+
Index: Damkjer/damkjerConfig.h
===================================================================
--- Damkjer/damkjerConfig.h	(revision 9)
+++ Damkjer/damkjerConfig.h	(revision 9)
@@ -0,0 +1,14 @@
+#ifndef config_HEADER
+#define config_HEADER
+
+#include "Util/Exception/Exception.h"
+
+#ifndef EXPORT
+   #if MAKE_DEPENDING || TEMPLATE_INCLUSION
+      #define EXPORT
+   #else
+      #define EXPORT export
+   #endif
+#endif
+
+#endif
