 +} // end namespace mrfLib
 +
  #endif
-diff -rupNb MRF2.1/TRW-S.cpp MRF_new/TRW-S.cpp
---- MRF2.1/TRW-S.cpp	2006-11-15 04:27:06.000000000 +0100
-+++ MRF_new/TRW-S.cpp	2012-05-24 13:56:08.000000000 +0200
-@@ -9,6 +9,7 @@
- #include "typeTruncatedQuadratic2D.h"
- #undef private
- 
-+using namespace mrfLib;
- 
- #define m_D(pix,l)  m_D[(pix)*m_nLabels+(l)]
- #define m_V(l1,l2)  m_V[(l1)*m_nLabels+(l2)]
-diff -rupNb MRF2.1/TRW-S.h MRF_new/TRW-S.h
---- MRF2.1/TRW-S.h	2006-11-15 04:27:06.000000000 +0100
-+++ MRF_new/TRW-S.h	2012-05-24 13:56:09.000000000 +0200
-@@ -1,5 +1,5 @@
--#ifndef __TRWS_H__
--#define __TRWS_H__
-+#ifndef __MRF_TRWS_H__
-+#define __MRF_TRWS_H__
- 
- #include <stdio.h>
- #include <stdlib.h>
-@@ -7,6 +7,7 @@
- #include <assert.h>
- #include "mrf.h"
- 
-+namespace mrfLib {
- 
- class TRWS : public MRF{
-  public:
-@@ -49,7 +50,7 @@ class TRWS : public MRF{
- 	    L2,
- 	    FIXED_MATRIX,
- 	    GENERAL,
--	    BINARY,
-+	    BINARY
- 	} m_type;
- 
-     CostVal m_smoothMax; // used only if
-@@ -83,4 +84,6 @@ class TRWS : public MRF{
-     void optimize_GRID_BINARY(int nIterations);
- };
- 
-+} // end namespace mrfLib
-+
- #endif /*  __TRWS_H__ */
-diff -rupNb MRF2.1/typeTruncatedQuadratic2D.h MRF_new/typeTruncatedQuadratic2D.h
+diff -rupN MRF2.1/typeTruncatedQuadratic2D.h MRF-v2.1.src-patched/typeTruncatedQuadratic2D.h
 --- MRF2.1/typeTruncatedQuadratic2D.h	2007-03-20 04:22:00.000000000 +0100
-+++ MRF_new/typeTruncatedQuadratic2D.h	2006-11-18 15:45:12.000000000 +0100
++++ MRF-v2.1.src-patched/typeTruncatedQuadratic2D.h	2006-11-18 15:45:12.000000000 +0100
 @@ -1,32 +1,574 @@
 -#ifndef __AJALSOQJAJSDFASD_H__
 -#define __AJALSOQJAJSDFASD_H__
-+/******************************************************************
-+typeTruncatedQuadratic2D.h
-+
-+Energy function with 2-dimensional truncated quadratic interactions:
-+   E(x)   =   \sum_i D_i(x_i)   +   \sum_ij V_ij(x_i,x_j)
-+   where x_i \in {0, 1, ..., KX-1} x {0, 1, ..., KY-1}
-+   (i.e. x_i = (x_i(1), x_i(2))).
-+   V_ij(ki, kj) = min { alpha1_ij*(ki(1)-kj(2))^2 + alpha2_ij*(ki(2)-kj(2))^2, lambda_ij }.
-+   alpha1_ij, alpha2_ij and lambda_ij must be non-negative.
-+
-+Example usage:
-+
-+Minimize function E(x,y) = Dx(x) + Dy(y) + min { alpha1*(x(1) - y(1))^2 + alpha2*(x(2) - y(2))^2, lambda } 
-+where 
-+  x,y \in {0,1} x {0,1,2}
-+  Dx(0,0) = 0, Dx(0,1) = 1, Dx(0,2) = 2,
-+  Dx(1,0) = 3, Dx(1,1) = 4, Dx(1,2) = 5,
-+  Dy(y) = 0 for all y,
-+  alpha1 = 6,
-+  alpha2 = 7,
-+  lambda = 8
-+
-+
-+
- 
- #include <stdio.h>
-+#include "MRFEnergy.h"
-+
-+void testTruncatedQuadratic2D()
-+{
-+	MRFEnergy<TypeTruncatedQuadratic2D>* mrf;
-+	MRFEnergy<TypeTruncatedQuadratic2D>::NodeId* nodes;
-+	MRFEnergy<TypeTruncatedQuadratic2D>::Options options;
-+	TypeTruncatedQuadratic2D::REAL energy, lowerBound;
-+
-+	const int nodeNum = 2; // number of nodes
-+	const int KX = 2; //   label
-+	const int KY = 3; // dimensions
-+	const int K = KX*KY; // number of labels
-+	TypeTruncatedQuadratic2D::REAL D[K];
-+	TypeTruncatedQuadratic2D::Label x, y;
-+
-+	mrf = new MRFEnergy<TypeTruncatedQuadratic2D>(TypeTruncatedQuadratic2D::GlobalSize(KX, KY));
-+	nodes = new MRFEnergy<TypeTruncatedQuadratic2D>::NodeId[nodeNum];
-+
-+	// construct energy
-+	D[0] = 0; D[1] = 1; D[2] = 2;
-+	D[3] = 3; D[4] = 4; D[5] = 5;
-+	nodes[0] = mrf->AddNode(TypeTruncatedQuadratic2D::LocalSize(), TypeTruncatedQuadratic2D::NodeData(D));
-+	D[0] = 0; D[1] = 0; D[2] = 0;
-+	D[3] = 0; D[4] = 0; D[5] = 0;
-+	nodes[1] = mrf->AddNode(TypeTruncatedQuadratic2D::LocalSize(), TypeTruncatedQuadratic2D::NodeData(D));
-+	mrf->AddEdge(nodes[0], nodes[1], TypeTruncatedQuadratic2D::EdgeData(6, 7, 8));
-+
-+	// Function below is optional - it may help if, for example, nodes are added in a random order
-+	// mrf->SetAutomaticOrdering();
-+
-+	/////////////////////// TRW-S algorithm //////////////////////
-+	options.m_iterMax = 30; // maximum number of iterations
-+	mrf->Minimize_TRW_S(options, lowerBound, energy);
-+
-+	// read solution
-+	x = mrf->GetSolution(nodes[0]);
-+	y = mrf->GetSolution(nodes[1]);
-+
-+	printf("Solution: %d %d\n", x, y);
-+
-+	//////////////////////// BP algorithm ////////////////////////
-+	mrf->ZeroMessages(); // in general not necessary - it may be faster to start 
-+	                     // with messages computed in previous iterations
-+
-+	options.m_iterMax = 30; // maximum number of iterations
-+	mrf->Minimize_BP(options, energy);
-+
-+	// read solution
-+	x = mrf->GetSolution(nodes[0]);
-+	y = mrf->GetSolution(nodes[1]);
-+
-+	printf("Solution: (%d, %d) (%d, %d)\n", x.m_kx, x.m_ky, y.m_kx, y.m_ky);
-+
-+	// done
-+	delete nodes;
-+	delete mrf;
-+}
-+
-+*******************************************************************/
-+
-+
-+
-+
-+
-+
- 
+-
+-#include <stdio.h>
+-
 -// This file is a stub, to make TRWS compile.
- 
- 
+-
+-
 -struct TypeTruncatedQuadratic2D
-+
-+
-+
-+
-+
-+
-+
-+
-+
-+#ifndef __TYPETRUNCATEDQUADRATIC2D_H__
-+#define __TYPETRUNCATEDQUADRATIC2D_H__
-+
-+#include <string.h>
-+#include <assert.h>
-+
-+
-+template <class T> class MRFEnergy;
-+
-+
-+class TypeTruncatedQuadratic2D
- {
-+private:
-+	struct Vector; // node parameters and messages
-+	struct Edge; // stores edge information and either forward or backward message
-+
-+public:
-+	// types declarations
-+	struct Label
-+	{
-+		int		m_kx, m_ky;
-+	};
-     typedef double REAL;
-+	struct GlobalSize; // global information about number of labels
-+	struct LocalSize; // local information about number of labels (stored at each node)
-+	struct NodeData; // argument to MRFEnergy::AddNode()
-+	struct EdgeData; // argument to MRFEnergy::AddEdge()
- 
+-{
+-    typedef double REAL;
+-
 -    struct Edge
-+
-+	struct GlobalSize
-     {
+-    {
 -	void DistanceTransformL2(int /*K*/, int /*stride*/, REAL /*alpha*/, REAL* /*source*/, REAL* /*dest*/,
 -				 int* /*parabolas*/, int* /*intersections*/)
-+		GlobalSize(int KX, int KY);
-+
-+	private:
-+	friend struct Vector;
-+	friend struct Edge;
-+		int		m_KX, m_KY; // label dimensions
-+		int		m_K; // number of labels
-+	};
-+
-+	struct LocalSize // number of labels is stored at MRFEnergy::m_Kglobal
- 	{
+-	{
 -	    printf("\n\
 -+-------------------------------------------------------------+\n\
 -|   In order to run TRW-S with truncted L2 terms,             |\n\

 
+} // end namespace mrfLib
 
diff -rupNb MRF2.1/regions-new.h MRF_new/regions-new.h
--- MRF2.1/regions-new.h	2006-11-15 04:27:06.000000000 +0100
+++ MRF_new/regions-new.h	2012-05-24 13:56:08.000000000 +0200
@@ -1,7 +1,7 @@
 // (C) 2002 Marshall Tappen, MIT AI Lab
 

 
 void MRF::initialize()
 {
diff -rupN MRF2.1/mrf.h MRF-v2.1.src-patched/mrf.h
--- MRF2.1/mrf.h	2006-11-27 16:15:42.000000000 +0100
+++ MRF-v2.1.src-patched/mrf.h	2012-08-13 12:25:46.000000000 +0200
@@ -6,6 +6,8 @@
 #define __MRF_H__
 #include <stdio.h>
