Index: /branches/HTM-DEV-0.3-dev2/build/linux/lib/TLibCommon/makefile
===================================================================
--- /branches/HTM-DEV-0.3-dev2/build/linux/lib/TLibCommon/makefile	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/build/linux/lib/TLibCommon/makefile	(revision 476)
@@ -37,4 +37,5 @@
 			$(OBJ_DIR)/SEI.o \
 			$(OBJ_DIR)/TComCABACTables.o \
+			$(OBJ_DIR)/TComDepthMapGenerator.o \			
 			$(OBJ_DIR)/TComSampleAdaptiveOffset.o \
 			$(OBJ_DIR)/TComBitStream.o \
Index: /branches/HTM-DEV-0.3-dev2/build/vc9/TAppDecoder_vc9.vcproj
===================================================================
--- /branches/HTM-DEV-0.3-dev2/build/vc9/TAppDecoder_vc9.vcproj	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/build/vc9/TAppDecoder_vc9.vcproj	(revision 476)
@@ -22,5 +22,5 @@
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			OutputDirectory="..\..\bin\"
 			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
 			ConfigurationType="1"
@@ -92,78 +92,6 @@
 		</Configuration>
 		<Configuration
-			Name="Debug|x64"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
-			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
-			ConfigurationType="1"
-			CharacterSet="2"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-				TargetEnvironment="3"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
-				MinimalRebuild="true"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				WarningLevel="3"
-				DebugInformationFormat="3"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="1"
-				TargetMachine="17"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			OutputDirectory="..\..\bin\"
 			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
 			ConfigurationType="1"
@@ -239,4 +167,76 @@
 		</Configuration>
 		<Configuration
+			Name="Debug|x64"
+			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="17"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
 			Name="Release|x64"
 			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
Index: /branches/HTM-DEV-0.3-dev2/build/vc9/TAppEncoder_vc9.vcproj
===================================================================
--- /branches/HTM-DEV-0.3-dev2/build/vc9/TAppEncoder_vc9.vcproj	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/build/vc9/TAppEncoder_vc9.vcproj	(revision 476)
@@ -2,5 +2,5 @@
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="9,00"
+	Version="9.00"
 	Name="TAppEncoder"
 	ProjectGUID="{D759E4E1-D33A-4483-B57B-0FD248E022FE}"
@@ -22,5 +22,5 @@
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			OutputDirectory="..\..\bin\"
 			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
 			ConfigurationType="1"
@@ -92,78 +92,6 @@
 		</Configuration>
 		<Configuration
-			Name="Debug|x64"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
-			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
-			ConfigurationType="1"
-			CharacterSet="2"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-				TargetEnvironment="3"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
-				MinimalRebuild="true"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				WarningLevel="3"
-				DebugInformationFormat="3"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="1"
-				TargetMachine="17"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			OutputDirectory="..\..\bin\"
 			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
 			ConfigurationType="1"
@@ -239,4 +167,76 @@
 		</Configuration>
 		<Configuration
+			Name="Debug|x64"
+			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
+			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="17"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
 			Name="Release|x64"
 			OutputDirectory="$(SolutionDir)\..\bin\vc9\$(PlatformName)\$(ConfigurationName)\"
Index: /branches/HTM-DEV-0.3-dev2/build/vc9/TLibCommon_vc9.vcproj
===================================================================
--- /branches/HTM-DEV-0.3-dev2/build/vc9/TLibCommon_vc9.vcproj	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/build/vc9/TLibCommon_vc9.vcproj	(revision 476)
@@ -2,5 +2,5 @@
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="9,00"
+	Version="9.00"
 	Name="TLibCommon"
 	ProjectGUID="{78018D78-F890-47E3-A0B7-09D273F0B11D}"
@@ -82,66 +82,4 @@
 		</Configuration>
 		<Configuration
-			Name="Debug|x64"
-			OutputDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
-			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
-			ConfigurationType="4"
-			CharacterSet="2"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-				TargetEnvironment="3"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
-				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
-				MinimalRebuild="true"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				WarningLevel="3"
-				DebugInformationFormat="3"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLibrarianTool"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
 			Name="Release|Win32"
 			OutputDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
@@ -209,4 +147,66 @@
 		</Configuration>
 		<Configuration
+			Name="Debug|x64"
+			OutputDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
+			IntermediateDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
+			ConfigurationType="4"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				TargetEnvironment="3"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="$(SolutionDir)\..\source\Lib\;$(SolutionDir)\..\compat\msvc"
+				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
 			Name="Release|x64"
 			OutputDirectory="$(SolutionDir)\vc9\$(PlatformName)\$(ConfigurationName)\$(RootNamespace)"
@@ -312,4 +312,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComDepthMapGenerator.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComInterpolationFilter.cpp"
 				>
@@ -438,4 +442,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\TComDepthMapGenerator.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\TLibCommon\TComInterpolationFilter.h"
 				>
Index: /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view+depth.cfg	(revision 476)
@@ -195,5 +195,6 @@
 
 #========== multiview coding tools ==========
-
+PredDepthMapGen           : 1                                      # generation of prediction depth maps (0:off, 1:using coded motion data, 2:using coded depth maps)
+MultiviewMvPred           : 7                                      # usage of prediction depth maps (0:off, 1:for interview, 2:for inter, 4:for merge, X:bit-wise combinations)
 
 #========== depth coding tools ==========
Index: /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_2view.cfg	(revision 476)
@@ -149,4 +149,8 @@
 RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
 
+#========== multiview coding tools ==========
+PredDepthMapGen           : 1                                      # generation of prediction depth maps (0:off, 1:using coded motion data, 2:using coded depth maps)
+MultiviewMvPred           : 7                                      # usage of prediction depth maps (0:off, 1:for interview, 2:for inter, 4:for merge, X:bit-wise combinations)
+
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
 ### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view+depth.cfg	(revision 476)
@@ -194,4 +194,6 @@
 
 #========== multiview coding tools ==========
+PredDepthMapGen           : 1                                      # generation of prediction depth maps (0:off, 1:using coded motion data, 2:using coded depth maps)
+MultiviewMvPred           : 7                                      # usage of prediction depth maps (0:off, 1:for interview, 2:for inter, 4:for merge, X:bit-wise combinations)
 
 
Index: /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg
===================================================================
--- /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/cfg/3D-HEVC/baseCfg_3view.cfg	(revision 476)
@@ -159,4 +159,7 @@
 RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
 
+#========== multiview coding tools ==========
+PredDepthMapGen           : 1                                      # generation of prediction depth maps (0:off, 1:using coded motion data, 2:using coded depth maps)
+MultiviewMvPred           : 7                                      # usage of prediction depth maps (0:off, 1:for interview, 2:for inter, 4:for merge, X:bit-wise combinations)
 ### DO NOT ADD ANYTHING BELOW THIS LINE ###
 ### DO NOT DELETE THE EMPTY LINE BELOW ###
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.cpp	(revision 476)
@@ -641,5 +641,9 @@
     m_tDecTop[ decIdx ] =  new TDecTop;
     m_tDecTop[ decIdx ]->create();
+#if H_3D_IV_MERGE
+    m_tDecTop[ decIdx ]->init(this );
+#else
     m_tDecTop[ decIdx ]->init( );
+#endif
     m_tDecTop[ decIdx ]->setLayerId( layerId );
     m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
@@ -678,3 +682,23 @@
 }
 #endif
+#if H_3D_IV_MERGE
+TComPic* TAppDecTop::xGetPicFromView( Int viewIdx, Int poc, Bool isDepth )
+{
+  assert( ( viewIdx >= 0 ) );
+
+  TComList<TComPic*>* apcListPic = m_tDecTop[ (isDepth ? 1 : 0) + viewIdx * 2 ]->getListPic();
+
+  TComPic* pcPic = NULL;
+  for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ )
+  {
+    if( (*it)->getPOC() == poc )
+    {
+      pcPic = *it;
+      break;
+    }
+  }
+  return pcPic;
+}
+#endif
+
 //! \}
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppDecoder/TAppDecTop.h	(revision 476)
@@ -49,4 +49,7 @@
 #include "TAppDecCfg.h"
 
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
 //! \ingroup TAppDecoder
 //! \{
@@ -73,4 +76,9 @@
     // for output control
   Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
+
+#if H_3D_IV_MERGE
+  Int  m_fcoViewDepthId;
+  Char m_fcoOrder[MAX_VIEW_NUM*2];
+#endif
 #if H_MV
   Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
@@ -82,4 +90,9 @@
   FILE*                           m_pScaleOffsetFile;
   CamParsCollector                m_cCamParsCollector;
+#if H_3D_IV_MERGE
+  TComVPSAccess                   m_cVPSAccess;
+  TComSPSAccess                   m_cSPSAccess;
+  TComAUPicAccess                 m_cAUPicAccess;
+#endif
 #endif
 public:
@@ -90,10 +103,26 @@
   Void  destroy           (); ///< destroy internal members
   Void  decode            (); ///< main decoding function
- 
+
+#if H_3D_IV_MERGE 
+  TDecTop* getTDecTop     ( Int viewIdx, Bool isDepth );
+  TComPic*              getPicFromView     ( Int viewIdx, Int poc, bool isDepth ) { return xGetPicFromView( viewIdx, poc, isDepth ); }
+#endif
+
+#if H_3D_IV_MERGE
+  TComVPSAccess*    getVPSAccess  () { return &m_cVPSAccess;   }
+  TComSPSAccess*    getSPSAccess  () { return &m_cSPSAccess;   }
+  TComAUPicAccess*  getAUPicAccess() { return &m_cAUPicAccess; }
+  TDecTop*          getDecTop0    () { return m_tDecTop[0]; }
+#endif
+
 protected:
   Void  xCreateDecLib     (); ///< create internal classes
   Void  xDestroyDecLib    (); ///< destroy internal classes
   Void  xInitDecLib       (); ///< initialize decoder class
-  
+
+#if H_3D_IV_MERGE 
+  TComPic* xGetPicFromView( Int viewIdx, Int poc, Bool isDepth );
+#endif
+
 #if H_MV
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
@@ -104,4 +133,5 @@
   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
 #endif
+
   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
 };
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 476)
@@ -717,4 +717,9 @@
 
 #endif //HHI_VSO
+
+#if H_3D_IV_MERGE
+  ("PredDepthMapGen",  m_uiPredDepthMapGeneration, (UInt)0, "generation of prediction depth maps for motion data prediction" )
+  ("MultiviewMvPred",  m_uiMultiviewMvPredMode,    (UInt)0, "usage of predicted depth maps" )
+#endif
 #endif //H_3D
   ;
@@ -1439,4 +1444,9 @@
   xConfirmPara( ((UInt) m_numberOfLayers >> 1 ) != m_cCameraData.getBaseViewNumbers().size(),   "Number of Views in BaseViewCameraNumbers must be equal to NumberOfViews" );
   xConfirmPara    ( m_iCodedCamParPrecision < 0 || m_iCodedCamParPrecision > 5,       "CodedCamParsPrecision must be in range of 0..5" );
+#if H_3D_IV_MERGE
+  xConfirmPara    ( m_uiPredDepthMapGeneration > 2,                                   "PredDepthMapGen must be less than or equal to 2" );
+  xConfirmPara    ( m_uiMultiviewMvPredMode > 7,                                      "MultiviewMvPred must be less than or equal to 7" );  
+  xConfirmPara    ( m_uiMultiviewMvPredMode > 0 && m_uiPredDepthMapGeneration == 0 ,  "MultiviewMvPred > 0 requires PredDepthMapGen > 0" );
+#endif
 #if H_3D_VSO
     if( m_bUseVSO )
@@ -2278,4 +2288,7 @@
   printf("WVSO:%d ", m_bUseWVSO );  
 #endif
+#if H_3D_IV_MERGE
+  printf("MultiviewMvPred:%d", m_uiMultiviewMvPredMode);
+#endif
   printf("\n\n");  
 
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncCfg.h	(revision 476)
@@ -381,4 +381,8 @@
   TAppComCamPara m_cCameraData;
   Int       m_iCodedCamParPrecision;                          ///< precision for coding of camera parameters
+#if H_3D_IV_MERGE
+  UInt      m_uiMultiviewMvPredMode;   
+  UInt      m_uiPredDepthMapGeneration;
+#endif
 #if H_3D_VSO
   Char*     m_pchVSOConfig;
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.cpp	(revision 476)
@@ -128,8 +128,29 @@
     m_frameRcvd                 .push_back(0);
     m_acTEncTopList             .push_back(new TEncTop); 
+#if H_3D_IV_MERGE
+//    m_acTEncDepthTopList        .push_back(new TEncTop); 
+#endif
     m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
     m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
     m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
-
+#if H_3D_IV_MERGE
+    //m_acTEncDepthTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
+    //m_acTEncDepthTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
+    //m_acTEncDepthTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
+    //m_acTEncDepthTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
+    //m_acTEncDepthTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
+    //m_acTEncDepthTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
+    //m_acTEncDepthTopList[iViewIdx]->setCropRight                    ( m_cropRight );
+    //m_acTEncDepthTopList[iViewIdx]->setCropTop                      ( m_cropTop );
+    //m_acTEncDepthTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
+    //m_acTEncDepthTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
+    //m_acTEncDepthTopList[iViewIdx]->setViewId                       ( iViewIdx );
+    //m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
+
+    //m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
+
+    //m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( layerId );
+
+#endif
     m_ivPicLists.push_back( m_acTEncTopList[ layer ]->getListPic()  ); 
     TEncTop& m_cTEncTop = *m_acTEncTopList[ layer ];  // It is not a member, but this name helps avoiding code duplication !!!
@@ -143,4 +164,10 @@
     m_cTEncTop.setIsDepth                      ( isDepth );
     //====== Camera Parameters =========
+#if H_3D_IV_MERGE
+      //m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
+      //m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
+      //m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
+      //m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
+#endif
     m_cTEncTop.setCameraParameters             ( &m_cCameraData );     
     m_cTEncTop.setCamParPrecision              ( isDepth ? false : m_cCameraData.getCamParsCodedPrecision  () );
@@ -166,4 +193,8 @@
     m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
 #endif // H_3D_VSO
+#if H_3D_IV_MERGE
+    m_cTEncTop.setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode     );
+    m_cTEncTop.setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
+#endif
 #endif // H_3D
 
@@ -189,4 +220,11 @@
   
   //====== Coding Structure ========
+#if H_3D_IV_MERGE
+      //m_acTEncDepthTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
+      //m_acTEncDepthTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
+      //m_acTEncDepthTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
+      //m_acTEncDepthTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
+      //m_acTEncDepthTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
+#endif
   m_cTEncTop.setIntraPeriod                  ( m_iIntraPeriod );
   m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
@@ -207,9 +245,29 @@
     m_cTEncTop.setNumReorderPics             ( m_numReorderPics[i], i );
     m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
-  }
+#if H_3D_IV_MERGE
+        m_acTEncDepthTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
+        m_acTEncDepthTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
+#endif
+  }
+#if H_3D_IV_MERGE
+      m_acTEncDepthTopList[iViewIdx]->setQP                           ( m_aiQP[1] );
+
+      m_acTEncDepthTopList[iViewIdx]->setTemporalLayerQPOffset        ( m_aiTLayerQPOffset );
+      m_acTEncDepthTopList[iViewIdx]->setPad                          ( m_aiPad );
+
+      m_acTEncDepthTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
+
+      m_acTEncDepthTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
+
+      m_acTEncDepthTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
+      m_acTEncDepthTopList[iViewIdx]->setUseAMP( m_enableAMP );
+#endif
 #endif
   for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
   {
     m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
+#if H_3D_IV_MERGE
+//        m_acTEncDepthTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
+#endif
   }
 #if H_MV
@@ -231,4 +289,11 @@
   
   //====== Loop/Deblock Filter ========
+#if H_3D_IV_MERGE
+      //m_acTEncDepthTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[1]   );
+      //m_acTEncDepthTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
+      //m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
+      //m_acTEncDepthTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
+      //m_acTEncDepthTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
+#endif
 #if H_MV
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
@@ -604,5 +669,9 @@
   for(Int layer=0; layer<m_numberOfLayers; layer++)
   {
+#if H_3D_IV_MERGE
+    m_acTEncTopList[layer]->init(this );
+#else
     m_acTEncTopList[layer]->init( );
+#endif
   }
 #else
@@ -1032,3 +1101,25 @@
 }
 #endif
+#if H_3D_IV_MERGE
+TComPic* TAppEncTop::xGetPicFromView( Int viewIdx, Int poc, Bool isDepth )
+{
+  assert( ( viewIdx >= 0 ) && ( viewIdx < m_iNumberOfViews ) );
+
+  TComList<TComPic*>* apcListPic =  m_acTEncTopList[(isDepth ? 1 : 0) + viewIdx * 2]->getListPic() ;
+
+  
+
+  TComPic* pcPic = NULL;
+  for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
+  {
+    if( (*it)->getPOC() == poc )
+    {
+      pcPic = *it ;
+      break ;
+    }
+  }
+
+  return pcPic;
+};
+#endif
 //! \}
Index: /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/App/TAppEncoder/TAppEncTop.h	(revision 476)
@@ -48,4 +48,7 @@
 #if H_3D
 #include "../../Lib/TLibRenderer/TRenTop.h"
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
 #endif
 
@@ -89,4 +92,10 @@
   TRenModel                   m_cRendererModel;   
 #endif
+
+#if H_3D_IV_MERGE
+  TComVPSAccess               m_cVPSAccess;
+  TComSPSAccess               m_cSPSAccess;
+  TComAUPicAccess             m_cAUPicAccess;
+#endif
 protected:
   // initialization
@@ -114,5 +123,7 @@
   void rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& stats);
   void printRateSummary();
-  
+#if H_3D_IV_MERGE
+  TComPic* xGetPicFromView( Int viewIdx, Int iPoc, Bool isDepth );
+#endif
 #if H_MV
   Void xSetLayerIds               ( TComVPS& vps );  
@@ -126,8 +137,17 @@
   
   Void        encode      ();                               ///< main encoding function
+#if H_3D_IV_MERGE
+  TComPic*              getPicFromView     ( Int viewIdx, Int poc, Bool isDepth ) { return xGetPicFromView( viewIdx, poc, isDepth ); }
+#endif
 #if H_MV
   TEncTop*    getTEncTop( UInt layer ) { return  m_acTEncTopList[layer]; }  ///< return pointer to encoder class for specific layer
 #else
   TEncTop&    getTEncTop  ()   { return  m_cTEncTop; }      ///< return encoder class pointer reference
+#endif
+
+#if H_3D_IV_MERGE
+  TComVPSAccess*    getVPSAccess  () { return &m_cVPSAccess;   }
+  TComSPSAccess*    getSPSAccess  () { return &m_cSPSAccess;   }
+  TComAUPicAccess*  getAUPicAccess() { return &m_cAUPicAccess; }
 #endif
 };// END CLASS DEFINITION TAppEncTop
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/CommonDef.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/CommonDef.h	(revision 476)
@@ -178,4 +178,38 @@
 }
 
+#if H_3D_IV_MERGE
+#define ROFVS( exp )          \
+{                             \
+  if( !( exp ) )              \
+{                           \
+  return;                   \
+}                           \
+}
+
+#define ROTVS( exp )          \
+{                             \
+  if( ( exp ) )               \
+{                           \
+  return;                   \
+}                           \
+}
+
+#define ROTRS( exp, retVal )  \
+{                             \
+  if( ( exp ) )               \
+{                           \
+  return retVal;            \
+}                           \
+}
+
+#define ROFRS( exp, retVal )  \
+{                             \
+  if( !( exp ) )              \
+{                           \
+  return retVal;            \
+}                           \
+}
+#endif
+
 template <typename T>
 __inline T gSign(const T& t)
@@ -200,5 +234,7 @@
 // MERGE
 #define MRG_MAX_NUM_CANDS           5
-
+#if H_3D_IV_MERGE
+#define MRG_MAX_NUM_CANDS_MEM       (MRG_MAX_NUM_CANDS+1) // one extra for inter-view motion prediction
+#endif
 // Reference memory management
 #define DYN_REF_FREE                0           ///< dynamic free of reference memories
@@ -325,4 +361,25 @@
 #define STD_CAM_PARAMETERS_PRECISION 5        ///< quarter luma sample accuarcy for derived disparities (as default)
 
+#if H_3D_IV_MERGE
+#define PDM_USE_FOR_IVIEW                 1
+#define PDM_USE_FOR_INTER                 2
+#define PDM_USE_FOR_MERGE                 4
+
+#define MAX_VIEW_NUM                      10
+#define PDM_SUBSAMPLING_EXP               2         // subsampling factor is 2^PDM_SUBSAMPLING_EXP
+#define PDM_SUB_SAMP_EXP_X(Pdm)           ((Pdm)==1?PDM_SUBSAMPLING_EXP:0)
+#define PDM_SUB_SAMP_EXP_Y(Pdm)           ((Pdm)==1?PDM_SUBSAMPLING_EXP:0)
+
+#define PDM_INTERNAL_CALC_BIT_DEPTH       31        // bit depth for internal calculations (32 - 1 for signed values)
+#define PDM_BITDEPTH_VIRT_DEPTH           15        // bit depth for virtual depth storage (16 - 1 for signed values)
+#define PDM_LOG2_MAX_ABS_NORMAL_DISPARITY 8         // maximum absolute normal disparity = 256 (for setting accuracy)
+#define PDM_VIRT_DEPTH_PRECISION          4         // must be greater than or equal to 2 (since MVs are given in quarter-pel units)
+
+#define PDM_INTER_CALC_SHIFT              ( PDM_INTERNAL_CALC_BIT_DEPTH - PDM_BITDEPTH_VIRT_DEPTH )         // avoids overflow
+#define PDM_LOG4_SCALE_DENOMINATOR        ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY + PDM_VIRT_DEPTH_PRECISION )  // accuracy of scaling factor
+#define PDM_OFFSET_SHIFT                  ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY )                             // accuracy of offset
+
+#endif
+
 #endif // end of H_3D
 //! \}
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 476)
@@ -40,4 +40,7 @@
 #include "TComPic.h"
 
+#if H_3D_IV_MERGE
+#include "TComDepthMapGenerator.h"
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -2426,10 +2429,20 @@
 {
   UInt uiAbsPartAddr = m_uiAbsIdxInLCU + uiAbsPartIdx;
+#if H_3D_IV_MERGE
+  TComMv cZeroMv;
+  Bool abCandIsInter[ MRG_MAX_NUM_CANDS_MEM ];
+#else
   Bool abCandIsInter[ MRG_MAX_NUM_CANDS ];
+#endif
   for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ++ui )
   {
     abCandIsInter[ui] = false;
+#if H_3D_IV_MERGE
+    pcMvFieldNeighbours[ ( ui << 1 )     ].setMvField(cZeroMv, NOT_VALID);
+    pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setMvField(cZeroMv, NOT_VALID);
+#else
     pcMvFieldNeighbours[ ( ui << 1 )     ].setRefIdx(NOT_VALID);
     pcMvFieldNeighbours[ ( ui << 1 ) + 1 ].setRefIdx(NOT_VALID);
+#endif
   }
   numValidMergeCand = getSlice()->getMaxNumMergeCand();
@@ -2444,4 +2457,132 @@
   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
+
+#if H_3D_IV_MERGE
+  Bool bNoPdmMerge   = ( m_pcSlice->getSPS()->getViewIndex() == 0 || ( m_pcSlice->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) != PDM_USE_FOR_MERGE );
+
+  //===== add merge with predicted depth maps =====
+  TComMv  acPdmMv       [4];
+  Int     aiPdmRefIdx   [4] = {-1, -1, -1, -1};
+  Bool    bLeftAvai         = false;
+  Int     iPosLeftAbove[2]  = {-1, -1};
+
+  //Notes from QC: DvMCP related variables.  
+  //acPdmMv[0].m_bDvMcp = acPdmMv[1].m_bDvMcp = acPdmMv[2].m_bDvMcp = acPdmMv[3].m_bDvMcp = false;
+
+  DisInfo cDisInfo;
+
+  cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
+  cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
+  cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
+
+  if( m_pcSlice->getIsDepth())
+  {
+    UInt uiPartIdxCenter;
+    xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );    
+    TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
+ 
+    if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+    {
+      abCandIsInter[iCount] = true;      
+      puhInterDirNeighbours[iCount] = pcTextureCU->getInterDir( uiPartIdxCenter );
+      if( ( puhInterDirNeighbours[iCount] & 1 ) == 1 )
+      {
+        pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
+        
+        TComMv cMvPred = pcMvFieldNeighbours[iCount<<1].getMv();
+
+        //Notes from MTK: shoud be aligned with " full-pel mv accuracy for depth maps", currently not supported
+        //const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
+        //cMvPred+=cAdd;
+        //cMvPred>>=2;
+        //clipMv(cMvPred);
+        //pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,pcMvFieldNeighbours[iCount<<1].getRefIdx());
+        if (pcMvFieldNeighbours[iCount<<1].getRefIdx()<0)
+        {
+          for (Int i=0; i<getSlice()->getNumRefIdx(REF_PIC_LIST_0); i++)
+          {
+            if (getSlice()->getRefPOC(REF_PIC_LIST_0, i) == getSlice()->getPOC())
+            {
+              pcMvFieldNeighbours[iCount<<1].setMvField(cMvPred,i);
+              break;
+            }
+          }
+        }
+
+      }
+      
+      if ( getSlice()->isInterB() )
+      {
+        if( ( puhInterDirNeighbours[iCount] & 2 ) == 2 )
+        {
+          pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
+          TComMv cMvPred = pcMvFieldNeighbours[(iCount<<1)+1].getMv();
+
+          //Notes from MTK: shoud be aligned with " full-pel mv accuracy for depth maps", currently not supported
+          //const TComMv cAdd( 1 << ( 2 - 1 ), 1 << ( 2 - 1 ) );
+          //cMvPred+=cAdd;
+          //cMvPred>>=2;
+          //clipMv(cMvPred);
+          //pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx());
+          if (pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()<0)
+          {
+            for (Int i=0; i<getSlice()->getNumRefIdx(REF_PIC_LIST_1); i++)
+            {
+              if (getSlice()->getRefPOC(REF_PIC_LIST_1, i) == getSlice()->getPOC())
+              {
+                pcMvFieldNeighbours[(iCount<<1)+1].setMvField(cMvPred,i);
+                break;
+              }
+            }
+          }
+
+        }
+      }
+
+      if (!((pcMvFieldNeighbours[iCount<<1].getRefIdx()<0 && !getSlice()->isInterB())
+        || (pcMvFieldNeighbours[iCount<<1].getRefIdx()<0 && pcMvFieldNeighbours[(iCount<<1)+1].getRefIdx()<0 && getSlice()->isInterB())))
+      {
+        if ( mrgCandIdx == iCount )
+        {
+          return;
+        }
+        iCount ++;
+      }
+      else
+      {
+        assert(0);
+      }
+    }
+  }
+
+  Int iPdmDir[2] = {0, 0};
+  getUnifiedMvPredCan(uiPUIdx, REF_PIC_LIST_0, 0, aiPdmRefIdx, acPdmMv, &cDisInfo, iPdmDir, true);
+  Int iPdmInterDir;
+
+  if( iPdmDir[0] && !bNoPdmMerge )
+  {
+    abCandIsInter        [ iCount ] = true;
+    puhInterDirNeighbours[ iCount ] = iPdmDir[0];
+    iPdmInterDir                    = iPdmDir[0];
+
+    if( ( iPdmInterDir & 1 ) == 1 )
+    {
+      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 0 ], aiPdmRefIdx[ 0 ] );
+    }
+
+    if( ( iPdmInterDir & 2 ) == 2 )
+    {
+      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 1 ], aiPdmRefIdx[ 1 ] );
+    }
+
+    if ( mrgCandIdx == iCount )
+    {
+      return;
+    }
+    iCount ++;
+  }  
+#endif
+
+#if !H_3D_IV_MERGE
 #if H_3D_NBDV //Notes from QC: DvMCP related variables.  
   //acPdmMv[0].m_bDvMcp = acPdmMv[1].m_bDvMcp = acPdmMv[2].m_bDvMcp = acPdmMv[3].m_bDvMcp = false; 
@@ -2461,4 +2602,6 @@
   //}
 #endif
+#endif
+
   //left
   UInt uiLeftPartIdx = 0;
@@ -2480,4 +2623,34 @@
       pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+
+#if H_3D_IV_MERGE 
+    Bool bRemoveSpa = false; //pruning to inter-view candidates
+    Int  iCnloop    = iCount - 1;
+    for(; iCnloop >= 0; iCnloop --)
+    {
+      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
+      {
+        bRemoveSpa                      = true;
+        abCandIsInter        [ iCount ] = false;
+
+        //reset to the default value for MC
+        puhInterDirNeighbours[iCount]   = 0;
+        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
+        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
+        break;
+      }
+    }
+    if(!bRemoveSpa)
+    {
+      bLeftAvai = true;
+      iPosLeftAbove[0] = iCount;
+
+      if ( mrgCandIdx == iCount )
+      {
+        return;
+      }
+      iCount ++;
+    }
+#else
     if ( mrgCandIdx == iCount )
     {
@@ -2485,4 +2658,5 @@
     }
     iCount ++;
+#endif
   }
   
@@ -2511,4 +2685,33 @@
       pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
     }
+#if H_3D_IV_MERGE 
+    Bool bRemoveSpa = false; //pruning to inter-view candidates
+    Int  iCnloop    = bLeftAvai? (iCount-2): (iCount-1);
+    for(; iCnloop >= 0; iCnloop --)
+    {
+      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
+      {
+        bRemoveSpa                      = true;
+        abCandIsInter        [ iCount ] = false;
+
+        //reset to the default value for MC
+        puhInterDirNeighbours[iCount]   = 0;
+
+        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
+        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
+        break;
+      }
+    }
+    if(!bRemoveSpa)
+    {
+      iPosLeftAbove[1] = iCount;
+
+      if ( mrgCandIdx == iCount )
+      {
+        return;
+      }
+      iCount ++;
+    }
+#else
     if ( mrgCandIdx == iCount )
     {
@@ -2516,4 +2719,5 @@
     }
     iCount ++;
+#endif
   }
   // early termination
@@ -2552,4 +2756,51 @@
     return;
   }
+
+#if H_3D_IV_MERGE 
+  if(!bNoPdmMerge && iPdmDir[1] )
+  {
+    assert(iCount < getSlice()->getMaxNumMergeCand());
+    abCandIsInter        [ iCount ] = true;
+    puhInterDirNeighbours[ iCount ] = iPdmDir[1];
+    if( ( iPdmDir[1] & 1 ) == 1 )
+    {
+      pcMvFieldNeighbours[ iCount<<1    ].setMvField( acPdmMv[ 2 ], aiPdmRefIdx[ 2 ] );
+    }
+    if( ( iPdmDir[1] & 2 ) == 2 )
+    {
+      pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField( acPdmMv[ 3 ], aiPdmRefIdx[ 3 ] );
+    }
+
+    Bool bRemoveSpa = false; //pruning to A1, B1
+    for(Int i = 0; i < 2; i ++)
+    {
+      Int iCnloop = iPosLeftAbove[i];
+      if(iCnloop == -1) 
+        continue;
+      if(puhInterDirNeighbours[iCount] == puhInterDirNeighbours[iCnloop] && pcMvFieldNeighbours[iCnloop<<1]==pcMvFieldNeighbours[(iCount<<1)] && pcMvFieldNeighbours[(iCnloop<<1)+1]==pcMvFieldNeighbours[(iCount<<1)+1])
+      {
+        bRemoveSpa                      = true;
+        abCandIsInter        [ iCount ] = false;
+        //reset to the default value for MC
+        puhInterDirNeighbours[iCount]   = 0;
+        pcMvFieldNeighbours[iCount<<1].setMvField( cZeroMv, NOT_VALID );
+        pcMvFieldNeighbours[(iCount<<1)+1].setMvField( cZeroMv, NOT_VALID );
+        break;
+      }      
+    }
+    if(!bRemoveSpa)
+    {
+      if ( mrgCandIdx == iCount )
+        return;
+      iCount ++;
+
+      // early termination
+      if (iCount == getSlice()->getMaxNumMergeCand()) 
+      {
+        return;
+      }
+    }
+  } 
+#endif
 
   //left bottom
@@ -2717,6 +2968,11 @@
   if ( getSlice()->isInterB())
   {
+#if H_3D_IV_MERGE
+    UInt uiPriorityList0[20] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3,    0, 4, 1, 4, 2, 4, 3, 4 };
+    UInt uiPriorityList1[20] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2,    4, 0, 4, 1, 4, 2, 4, 3 };
+#else
     UInt uiPriorityList0[12] = {0 , 1, 0, 2, 1, 2, 0, 3, 1, 3, 2, 3};
     UInt uiPriorityList1[12] = {1 , 0, 2, 0, 2, 1, 3, 0, 3, 1, 3, 2};
+#endif
 
     for (Int idx=0; idx<uiCutoff*(uiCutoff-1) && uiArrayAddr!= getSlice()->getMaxNumMergeCand(); idx++)
@@ -4246,3 +4502,14 @@
 }
 #endif 
+
+#if H_3D_IV_MERGE
+Bool TComDataCU::getUnifiedMvPredCan(UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  TComDepthMapGenerator* pcDepthMapGenerator = m_pcSlice->getSPS()->getDepthMapGenerator();
+  ROFRS( pcDepthMapGenerator, false );
+  if (pcDepthMapGenerator->getPdmCandidate(this, uiPartIdx, eRefPicList, iRefIdx, paiPdmRefIdx, pacPdmMv, pDInfo, iPdm, bMerge))
+    return true;
+  return false;
+}
+#endif
 //! \}
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 476)
@@ -434,4 +434,8 @@
    
 #endif
+
+#if H_3D_IV_MERGE
+  Bool          getUnifiedMvPredCan       ( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for accessing partition information
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 476)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 476)
@@ -0,0 +1,301 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+/** \file     TComDepthMapGenerator.cpp
+    \brief    depth map generator class
+*/
+
+
+
+#include "CommonDef.h"
+#include "TComDepthMapGenerator.h"
+
+
+
+TComDepthMapGenerator::TComDepthMapGenerator()
+{
+  m_bCreated            = false;
+  m_bInit               = false;
+  m_bDecoder            = false;
+  m_pcPrediction        = 0;
+  m_pcSPSAccess         = 0;
+  m_pcAUPicAccess       = 0;
+
+  m_uiSubSampExpX       = 0;
+  m_uiSubSampExpY       = 0;
+}
+
+TComDepthMapGenerator::~TComDepthMapGenerator()
+{
+  destroy ();
+  uninit  ();
+}
+
+Void
+TComDepthMapGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY )
+{
+  destroy();
+  m_bDecoder            = bDecoder;
+
+  m_uiSubSampExpX       = uiSubSampExpX;
+  m_uiSubSampExpY       = uiSubSampExpY;
+  m_bCreated    = true;
+}
+
+Void
+TComDepthMapGenerator::destroy()
+{
+  if( m_bCreated )
+  {
+    m_bCreated    = false;
+
+    m_uiSubSampExpX       = 0;
+    m_uiSubSampExpY       = 0;
+    m_bDecoder            = false;
+  }
+}
+
+
+Void
+TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
+{
+  AOF( pcPrediction  );
+  AOF( pcSPSAccess   );
+  AOF( pcAUPicAccess );
+  uninit();
+  m_pcPrediction  = pcPrediction;
+  m_pcVPSAccess   = pcVPSAccess;
+  m_pcSPSAccess   = pcSPSAccess;
+  m_pcAUPicAccess = pcAUPicAccess;
+  m_bInit         = true;
+}
+
+Void
+TComDepthMapGenerator::uninit()
+{
+  if( m_bInit )
+  {
+    m_bInit         = false;
+    m_pcPrediction  = 0;
+    m_pcSPSAccess   = 0;
+    m_pcAUPicAccess = 0;
+  }
+}
+
+Void  
+TComDepthMapGenerator::initViewComponent( TComPic* pcPic )
+{
+  AOF  ( m_bCreated && m_bInit );
+  AOF  ( pcPic );
+  AOT  ( pcPic->getSPS()->getViewIndex() && !pcPic->getSPS()->isDepth() && pcPic->getPOC() && pcPic->getSPS()->getPredDepthMapGeneration() != m_pcSPSAccess->getPdm() );
+  m_bPDMAvailable = false;
+  m_uiCurrViewIndex  = pcPic->getSPS()->getViewIndex();
+
+  // update SPS list and AU pic list and set depth map generator in SPS
+  m_pcVPSAccess  ->addVPS( pcPic->getVPS() );
+  m_pcSPSAccess  ->addSPS( pcPic->getSPS() );
+  m_pcAUPicAccess->addPic( pcPic );
+  pcPic->getSPS()->setDepthMapGenerator( this );
+
+  // check whether we have depth data or don't use pred depth prediction
+  ROFVS( pcPic->getSPS()->getViewIndex() );
+  ROTVS( pcPic->getSPS()->isDepth  () );
+  ROFVS( m_pcSPSAccess->getPdm     () ); 
+}
+
+
+#if H_3D_IV_MERGE
+Bool
+TComDepthMapGenerator::getPdmCandidate(TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
+{
+  AOF  ( m_bCreated && m_bInit );
+  TComSlice*    pcSlice     = pcCU->getSlice ();
+  TComSPS*      pcSPS       = pcSlice->getSPS();
+  AOF  ( pcSPS->getViewIndex() == m_uiCurrViewIndex );
+
+  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
+  UInt          uiRefViewId = pcRefPic->getSPS()->getViewIndex();
+  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewIndex );
+  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
+  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
+  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
+  if(!bMerge)
+  {
+    ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
+    ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
+    ROTRS(                  bMerge   && !bPdmMerge, false );
+  }
+  else
+    ROTRS( !bPdmMerge, 0 );
+
+
+  Bool abPdmAvailable[4] = {false, false, false, false};
+
+  Int iValid = 0;
+  Int iViewIndex = 0;
+  for( UInt uiBIndex = 0; uiBIndex < m_uiCurrViewIndex && iValid==0; uiBIndex++ )
+  {
+
+    UInt        uiBaseIndex    = uiBIndex;
+    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseIndex );
+    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
+    {
+      RefPicList  eRefPicListTest = RefPicList( iRefListId );
+      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
+      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
+      { 
+        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
+          && pcBasePic->getViewIndex() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
+        {
+          iValid=1;
+          iViewIndex = uiBaseIndex;
+          break;
+        }
+      }
+    }
+  }
+  if (iValid == 0)
+    return false;
+
+  //--- get base CU/PU and check prediction mode ---
+  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewIndex );
+  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
+  if(bMerge || !bInterview)
+  {
+    Int  iCurrPosX, iCurrPosY;
+    UInt          uiPartAddr;
+    Int           iWidth;
+    Int           iHeight;
+
+    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
+    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
+    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
+    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
+
+    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acNBDV.getHor() + 2 ) >> 2 ) );
+    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acNBDV.getVer() + 2 ) >> 2 )); 
+    Int         iBaseCUAddr;
+    Int         iBaseAbsPartIdx;
+    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
+
+    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
+    if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
+    {
+      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
+      {
+        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
+        if(!bMerge && eCurrRefPicList != eRefPicList)
+          continue;
+        Bool bLoop_stop = false;
+        for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
+        {
+          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
+          TComMvField cBaseMvField;
+          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
+          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
+          if (iBaseRefIdx >= 0)
+          {
+            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
+            if (iBaseRefPOC != pcSlice->getPOC())    
+            {
+              for (Int iPdmRefIdx = (bMerge?0: iRefIdx); iPdmRefIdx < (bMerge? pcSlice->getNumRefIdx( eCurrRefPicList ): (iRefIdx+1)); iPdmRefIdx++)
+              {
+                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
+                {
+                  abPdmAvailable[ uiCurrRefListId ] = true;
+                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
+
+                  //if( bMerge )
+                  //{
+                    //cMv.m_bDvMcp = true;
+                    //cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
+                  //}
+
+                  pcCU->clipMv( cMv );
+                  if(bMerge)
+                  {
+                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
+                    pacPdmMv      [ uiCurrRefListId ] = cMv;
+                    bLoop_stop = true;
+                    break;
+                  }else
+                  {
+                    pacPdmMv  [0] = cMv;
+                    return true;
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+    if( bMerge )
+      iPdm[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
+  }
+  if(bMerge || bInterview)
+  {
+    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
+    {
+      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
+      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
+      for( Int iPdmRefIdx = (bMerge ? 0: iRefIdx); iPdmRefIdx < (bMerge ? iNumRefPics: (iRefIdx+1) ); iPdmRefIdx++ )
+      {
+        if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
+        {
+          abPdmAvailable[ iRefListId+2 ] = true;
+          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
+
+          TComMv cMv = pDInfo->m_acNBDV; 
+          cMv.setVer(0);
+
+          pcCU->clipMv( cMv );
+          pacPdmMv      [ iRefListId + 2] = cMv;
+          if(bMerge)
+            break;
+          else
+          {
+            pacPdmMv [0] = cMv;
+            return true;
+          }
+        }
+      }
+    }
+    iPdm[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
+  }
+  return false;
+}
+#endif
+
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 476)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 476)
@@ -0,0 +1,163 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+/** \file     TComDepthMapGenerator.h
+    \brief    depth map generator class (header)
+*/
+
+
+#ifndef __TCOM_DEPTH_MAP_GENERATOR__
+#define __TCOM_DEPTH_MAP_GENERATOR__
+
+
+#include "CommonDef.h"
+#include "TComPic.h"
+#include "TComPrediction.h"
+#include "TComSlice.h"
+
+
+
+class TComVPSAccess // would be better to have a real VPS buffer
+{
+public:
+  TComVPSAccess ()  { clear(); }
+  ~TComVPSAccess()  {}
+
+  Void      clear   ()                                { ::memset( m_aacVPS, 0x00, sizeof( m_aacVPS ) ); m_uiActiceVPSId = 0;}
+  Void      addVPS  ( TComVPS* pcVPS )                { m_aacVPS[ pcVPS->getVPSId() ] = pcVPS; }
+  TComVPS*  getVPS  ( UInt uiVPSId )                  { return m_aacVPS[ uiVPSId ]; }
+  TComVPS*  getActiveVPS  ( )                         { return m_aacVPS[ m_uiActiceVPSId ]; }
+  Void      setActiveVPSId  ( UInt activeVPSId )      { m_uiActiceVPSId = activeVPSId; }
+private:
+  TComVPS*  m_aacVPS[ MAX_NUM_VPS ];
+  UInt      m_uiActiceVPSId;
+};
+
+
+class TComSPSAccess // would be better to have a real SPS buffer
+{
+public:
+  TComSPSAccess ()  { clear(); }
+  ~TComSPSAccess()  {}
+
+  Void      clear   ()                            { ::memset( m_aacActiveSPS, 0x00, sizeof( m_aacActiveSPS ) ); }
+  Void      addSPS  ( TComSPS* pcSPS    )         { m_aacActiveSPS[ pcSPS->isDepth() ? 1 : 0 ][ pcSPS->getViewIndex() ] = pcSPS; }
+  TComSPS*  getSPS  ( UInt     uiViewId, 
+                      Bool     bIsDepth = false ) { return m_aacActiveSPS[ bIsDepth ? 1 : 0 ][ uiViewId ]; }
+
+  UInt      getPdm  ()                            { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getPredDepthMapGeneration(); } return 0; }
+
+private:
+  TComSPS*  m_aacActiveSPS[ 2 ][ MAX_VIEW_NUM ];
+};
+
+
+
+class TComAUPicAccess // would be better to have a real decoded picture buffer
+{
+public:
+  TComAUPicAccess () : m_iLastPoc( 0 ), m_uiMaxViewId( 0 ) { clear(); }
+  ~TComAUPicAccess()                   {}
+
+  Void      clear   ()                            { ::memset( m_aacCurrAUPics, 0x00, sizeof( m_aacCurrAUPics ) ); }
+  Void      addPic    ( TComPic* pcPic    )         { if( m_iLastPoc != pcPic->getPOC() ) 
+                                                      { 
+                                                        clear(); 
+                                                        m_iLastPoc = pcPic->getPOC(); 
+                                                      } 
+                                                      m_aacCurrAUPics[ pcPic->getSPS()->isDepth() ? 1 : 0 ][ pcPic->getSPS()->getViewIndex() ] = pcPic; 
+                                                      if( pcPic->getSPS()->getViewIndex() > m_uiMaxViewId )
+                                                      {
+                                                        m_uiMaxViewId = pcPic->getSPS()->getViewIndex();
+                                                      }
+                                                    }
+  TComPic*  getPic  ( UInt     uiViewId,
+                      Bool     bIsDepth = false ) { return m_aacCurrAUPics[ bIsDepth ? 1 : 0 ][ uiViewId ]; }
+  UInt      getMaxVId ()                            { return m_uiMaxViewId; }
+
+private:
+  Int       m_iLastPoc;
+  UInt      m_uiMaxViewId;
+  TComPic*  m_aacCurrAUPics[ 2 ][ MAX_VIEW_NUM ];
+};
+
+
+
+class TComDepthMapGenerator
+{
+public:
+  TComDepthMapGenerator ();
+  ~TComDepthMapGenerator();
+
+  Void  create                ( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY );
+  Void  destroy               ();
+
+  Void  init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess );
+  Void  uninit                ();
+
+  Void  initViewComponent     ( TComPic*      pcPic );
+
+  UInt  getSubSampExpX        ()                      { return m_uiSubSampExpX; }
+  UInt  getSubSampExpY        ()                      { return m_uiSubSampExpY; }
+  
+
+  Bool  getPdmCandidate       ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge );
+
+  
+private:
+  // general parameters
+  Bool              m_bCreated;
+  Bool              m_bInit;
+  Bool              m_bDecoder;
+  TComPrediction*   m_pcPrediction;
+  TComVPSAccess*    m_pcVPSAccess;
+  TComSPSAccess*    m_pcSPSAccess;
+  TComAUPicAccess*  m_pcAUPicAccess;
+  UInt              m_uiSubSampExpX;
+  UInt              m_uiSubSampExpY;
+
+  // conversion parameters
+  UInt              m_uiCurrViewIndex;
+  Bool              m_bPDMAvailable;
+};
+
+
+
+
+#endif // __TCOM_DEPTH_MAP_GENERATOR__
+
+
+
+
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h	(revision 476)
@@ -105,4 +105,11 @@
   Int getHor   () const { return  m_acMv.getHor(); }
   Int getVer   () const { return  m_acMv.getVer(); }
+
+#if H_3D_IV_MERGE
+  Bool operator== ( const TComMvField& rcMv ) const
+  {
+    return (m_acMv.getHor()==rcMv.getHor() && m_acMv.getVer()==rcMv.getVer() && m_iRefIdx == rcMv.getRefIdx());
+  }
+#endif
 };
 
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.h	(revision 476)
@@ -141,4 +141,9 @@
   Int           getPOC()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getPOC();  }
   TComDataCU*&  getCU( UInt uiCUAddr )  { return  m_apcPicSym->getCU( uiCUAddr ); }
+#if H_3D_IV_MERGE
+  TComSlice*    getCurrSlice()        { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx);  }
+  TComSPS*      getSPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getSPS();  }
+  TComVPS*      getVPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getVPS();  }
+#endif
   
   TComPicYuv*   getPicYuvOrg()        { return  m_apcPicYuv[0]; }
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 476)
@@ -77,4 +77,12 @@
   m_iCuHeight       = uiMaxCUHeight;
 
+#if H_3D_IV_MERGE
+  m_iNumCuInWidth   = m_iPicWidth / m_iCuWidth;
+  m_iNumCuInWidth  += ( m_iPicWidth % m_iCuWidth ) ? 1 : 0;
+
+  m_iBaseUnitWidth  = uiMaxCUWidth  >> uiMaxCUDepth;
+  m_iBaseUnitHeight = uiMaxCUHeight >> uiMaxCUDepth;
+#endif
+
   Int numCuInWidth  = m_iPicWidth  / m_iCuWidth  + (m_iPicWidth  % m_iCuWidth  != 0);
   Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);
@@ -325,4 +333,31 @@
 
 #if H_3D
+#if H_3D_IV_MERGE
+Void
+TComPicYuv::getTopLeftSamplePos( Int iCuAddr, Int iAbsZorderIdx, Int& riX, Int& riY )
+{
+  Int iRastPartIdx    = g_auiZscanToRaster[iAbsZorderIdx];
+  Int iCuSizeInBases  = m_iCuWidth   / m_iBaseUnitWidth;
+  Int iCuX            = iCuAddr      % m_iNumCuInWidth;
+  Int iCuY            = iCuAddr      / m_iNumCuInWidth;
+  Int iBaseX          = iRastPartIdx % iCuSizeInBases;
+  Int iBaseY          = iRastPartIdx / iCuSizeInBases;
+  riX                 = iCuX * m_iCuWidth  + iBaseX * m_iBaseUnitWidth;
+  riY                 = iCuY * m_iCuHeight + iBaseY * m_iBaseUnitHeight; 
+}
+
+Void
+TComPicYuv::getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx )
+{
+  Int iCuX            = iX / m_iCuWidth;
+  Int iCuY            = iY / m_iCuHeight;
+  Int iBaseX          = ( iX - iCuX * m_iCuWidth  ) / m_iBaseUnitWidth;
+  Int iBaseY          = ( iY - iCuY * m_iCuHeight ) / m_iBaseUnitHeight;
+  Int iCuSizeInBases  = m_iCuWidth                  / m_iBaseUnitWidth;
+  riCuAddr            = iCuY   * m_iNumCuInWidth + iCuX;
+  Int iRastPartIdx    = iBaseY * iCuSizeInBases  + iBaseX;
+  riAbsZorderIdx      = g_auiRasterToZscan[ iRastPartIdx ];
+}
+#endif
 Void TComPicYuv::setLumaTo( Pel pVal )
 {
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPicYuv.h	(revision 476)
@@ -88,4 +88,9 @@
   Bool  m_bIsBorderExtended;
   
+#if H_3D_IV_MERGE
+  Int   m_iBaseUnitWidth;       ///< Width of Base Unit (with maximum depth or minimum size, m_iCuWidth >> Max. Depth)
+  Int   m_iBaseUnitHeight;      ///< Height of Base Unit (with maximum depth or minimum size, m_iCuHeight >> Max. Depth)
+  Int   m_iNumCuInWidth;
+#endif
 protected:
   Void  xExtendPicCompBorder (Pel* piTxt, Int iStride, Int iWidth, Int iHeight, Int iMarginX, Int iMarginY);
@@ -165,4 +170,9 @@
   Void  setLumaTo    ( Pel pVal );  
   Void  setChromaTo  ( Pel pVal );  
+#if H_3D_IV_MERGE
+  // sample to block and block to sample conversion
+  Void  getTopLeftSamplePos( Int iCuAddr, Int iAbsZorderIdx, Int& riX, Int& riY );
+  Void  getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx );
+#endif
 #endif
 };// END CLASS DEFINITION TComPicYuv
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.cpp	(revision 476)
@@ -68,4 +68,7 @@
 , m_iSliceQpDeltaCb               ( 0 )
 , m_iSliceQpDeltaCr               ( 0 )
+#if H_3D_IV_MERGE
+, m_pcTexturePic                  ( NULL )
+#endif
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
@@ -171,4 +174,7 @@
   
   m_colRefIdx = 0;
+#if H_3D_IV_MERGE
+  m_pcTexturePic = NULL;
+#endif
   initEqualRef();
 #if !L0034_COMBINED_LIST_CLEANUP
@@ -185,5 +191,9 @@
 #endif
 
+#if H_3D_IV_MERGE
+  m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM;
+#else
   m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
+#endif
 
   m_bFinalized=false;
@@ -1847,4 +1857,19 @@
   }
 }
+
+#if H_3D_IV_MERGE
+Void
+TComSPS::setPredDepthMapGeneration( UInt uiViewIndex, Bool bIsDepth, UInt uiPdmGenMode, UInt uiPdmMvPredMode)
+{ 
+  AOF( m_uiViewIndex == uiViewIndex );
+  AOF( m_bDepth   == bIsDepth );
+  AOT( ( uiViewIndex == 0 || bIsDepth ) && uiPdmGenMode );
+  AOT( uiPdmMvPredMode && uiPdmGenMode == 0 );
+
+  m_uiPredDepthMapGeneration = uiPdmGenMode;
+  m_uiMultiviewMvPredMode    = uiPdmMvPredMode;
+}
+#endif
+
 const Int TComSPS::m_winUnitX[]={1,2,2,1};
 const Int TComSPS::m_winUnitY[]={1,2,1,1};
@@ -1913,4 +1938,9 @@
   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
 
+#if H_3D_IV_MERGE  
+  m_uiViewIndex           = uiViewIndex;
+  m_bDepth                = false;
+#endif
+
   if( !m_bCamParInSliceHeader )
   {
@@ -1924,4 +1954,19 @@
   }
 }
+
+#if H_3D_IV_MERGE
+Void
+TComSPS::initCamParaSPSDepth( UInt uiViewIndex)
+{  
+  m_uiCamParPrecision     = 0;
+  m_bCamParInSliceHeader  = false;
+
+  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
+  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
+
+  m_uiViewIndex           = uiViewIndex;
+  m_bDepth                = true;
+}
+#endif
 #endif
 
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComSlice.h	(revision 476)
@@ -53,4 +53,8 @@
 #if H_MV
 class TComPicLists; 
+#endif
+
+#if H_3D_IV_MERGE
+class TComDepthMapGenerator;
 #endif
 // ====================================================================================================================
@@ -981,4 +985,12 @@
   Int         m_aaiCodedScale [2][MAX_NUM_LAYERS];
   Int         m_aaiCodedOffset[2][MAX_NUM_LAYERS];
+#if H_3D_IV_MERGE
+  UInt        m_uiMultiviewMvPredMode;
+  UInt        m_uiPredDepthMapGeneration;
+
+  UInt        m_uiViewIndex;
+  Bool        m_bDepth;
+  TComDepthMapGenerator* m_pcDepthMapGenerator;
+#endif
 #endif
 public:
@@ -1124,4 +1136,15 @@
   Int* getInvCodedScale      ()  { return m_aaiCodedScale [1]; }
   Int* getInvCodedOffset     ()  { return m_aaiCodedOffset[1]; }
+#if H_3D_IV_MERGE
+  Void  initCamParaSPSDepth      ( UInt uiViewIndex);
+  UInt  getMultiviewMvPredMode   ()          { return m_uiMultiviewMvPredMode;    }
+  UInt  getPredDepthMapGeneration()          { return m_uiPredDepthMapGeneration; }
+
+  UInt  getViewIndex             ()  { return m_uiViewIndex; }
+  Bool  isDepth               ()  { return m_bDepth; }
+  Void  setDepthMapGenerator( TComDepthMapGenerator* pcDepthMapGenerator )  { m_pcDepthMapGenerator = pcDepthMapGenerator; }
+  TComDepthMapGenerator*  getDepthMapGenerator()                                              { return m_pcDepthMapGenerator; }
+  Void setPredDepthMapGeneration( UInt uiViewIndex, Bool bIsDepth, UInt uiPdmGenMode = 0, UInt uiPdmMvPredMode = 0);
+#endif
 #endif
 };
@@ -1414,4 +1437,7 @@
 #endif
   Bool        m_bIsUsedAsLongTerm[2][MAX_NUM_REF+1];
+#if H_3D_IV_MERGE
+  TComPic*    m_pcTexturePic;
+#endif
   Int         m_iDepth;
   
@@ -1544,4 +1570,7 @@
   TComPic*  getRefPic           ( RefPicList e, Int iRefIdx)    { return  m_apcRefPicList[e][iRefIdx];  }
   Int       getRefPOC           ( RefPicList e, Int iRefIdx)    { return  m_aiRefPOCList[e][iRefIdx];   }
+#if H_3D_IV_MERGE
+  TComPic*  getTexturePic       () const                        { return  m_pcTexturePic; }
+#endif
   Int       getDepth            ()                              { return  m_iDepth;                     }
   UInt      getColFromL0Flag    ()                              { return  m_colFromL0Flag;              }
@@ -1594,4 +1623,7 @@
   Void      setRefPic           ( TComPic* p, RefPicList e, Int iRefIdx ) { m_apcRefPicList[e][iRefIdx] = p; }
   Void      setRefPOC           ( Int i, RefPicList e, Int iRefIdx ) { m_aiRefPOCList[e][iRefIdx] = i; }
+#if H_3D_IV_MERGE
+  Void      setTexturePic       ( TComPic *pcTexturePic )       { m_pcTexturePic = pcTexturePic; }
+#endif
   Void      setNumRefIdx        ( RefPicList e, Int i )         { m_aiNumRefIdx[e]    = i;      }
   Void      setPic              ( TComPic* p )                  { m_pcPic             = p;      }
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 476)
@@ -42,5 +42,4 @@
 //! \{
 
-
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////// EXTENSION SELECTION ///////////////////////////////////  
@@ -89,4 +88,14 @@
                                               // QC_CU_NBDV_D0181
                                               // SEC_DEFAULT_DV_D0112
+
+#define H_3D_IV_MERGE                     1   // Inter-view motion merge candidate
+                                              // HHI_INTER_VIEW_MOTION_PRED 
+                                              // SAIT_IMPROV_MOTION_PRED_M24829, improved inter-view motion vector prediction
+                                              // QC_MRG_CANS_B0048             , JCT3V-B0048, B0086, B0069
+                                              // OL_DISMV_POS_B0069            , different pos for disparity MV candidate, B0069
+                                              // MTK_INTERVIEW_MERGE_A0049     , second part
+                                              // QC_AMVP_MRG_UNIFY_IVCAN_C0051     
+                                              // TEXTURE MERGING CANDIDATE     , JCT3V-C0137
+
 #endif 
 
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 476)
@@ -759,4 +759,39 @@
     }
 #endif // !H_MV
+
+#if H_3D_IV_MERGE
+    READ_FLAG( uiCode, "base_view_flag" );
+    if( uiCode )
+    { // baseview SPS -> set standard values
+      pcSPS->initCamParaSPS         ( 0 );
+      pcSPS->setPredDepthMapGeneration( 0, false );
+    }
+    else
+    {
+      READ_FLAG( uiCode, "depth_flag" ); 
+      if( uiCode )
+      {
+        READ_UVLC( uiCode, "view_idx" ); 
+        pcSPS->initCamParaSPSDepth    ( uiCode );
+        pcSPS->setPredDepthMapGeneration( uiCode, true );
+      }
+      else
+      {
+        UInt  uiViewIndex;
+        READ_UVLC( uiViewIndex, "view_idx" );  uiViewIndex++; 
+        UInt uiPredDepthMapGeneration = 0;
+        UInt uiMultiviewMvPredMode = 0;
+
+        READ_UVLC( uiPredDepthMapGeneration, "Pdm_generation" );
+        if( uiPredDepthMapGeneration )
+        {
+          READ_UVLC( uiMultiviewMvPredMode, "multi_view_mv_pred_mode" );
+        }
+
+        pcSPS->setPredDepthMapGeneration( uiViewIndex, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode);
+
+      }
+    }
+#endif
   }
 }
@@ -1414,5 +1449,9 @@
     {
       READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
+#if H_3D_IV_MERGE
+      rpcSlice->setMaxNumMergeCand(((rpcSlice->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE) == PDM_USE_FOR_MERGE ? MRG_MAX_NUM_CANDS_MEM: MRG_MAX_NUM_CANDS) - uiCode);
+#else
       rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
+#endif
     }
 
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 476)
@@ -320,6 +320,12 @@
     m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
     m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
+    m_ppcCU[uiDepth]->copyDVInfoFrom(pcCU, uiAbsPartIdx);
+#if H_3D_IV_MERGE
+    TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
+    UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
+#else
     TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
     UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
+#endif
     Int numValidMergeCand = 0;
     for( UInt ui = 0; ui < m_ppcCU[uiDepth]->getSlice()->getMaxNumMergeCand(); ++ui )
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 476)
@@ -156,6 +156,11 @@
   UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxCUDepth() - uiDepth ) << 1 ) ) >> 4;
 
+#if H_3D_IV_MERGE
+  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
+  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
+#else
   TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
+#endif
 
   for ( UInt ui = 0; ui < pcCU->getSlice()->getMaxNumMergeCand(); ui++ )
@@ -168,4 +173,7 @@
   pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
   pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_1 );
+#if H_3D_IV_MERGE
+  pcSubCU->copyDVInfoFrom( pcCU, uiAbsPartIdx);
+#endif
   for ( UInt uiPartIdx = 0, uiSubPartIdx = uiAbsPartIdx; uiPartIdx < uiNumPU; uiPartIdx++, uiSubPartIdx += uiPUOffset )
   {
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 476)
@@ -84,4 +84,7 @@
                    TComLoopFilter*         pcLoopFilter,
                    TComSampleAdaptiveOffset* pcSAO
+#if H_3D_IV_MERGE
+                    ,TComDepthMapGenerator*  pcDepthMapGenerator
+#endif
                    )
 {
@@ -93,4 +96,7 @@
   m_pcLoopFilter          = pcLoopFilter;
   m_pcSAO  = pcSAO;
+#if H_3D_IV_MERGE
+  m_pcDepthMapGenerator   = pcDepthMapGenerator;
+#endif
 }
 
@@ -152,4 +158,12 @@
     m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
   }
+
+#if H_3D_IV_MERGE
+  if( uiStartCUAddr == 0 )
+  {
+    m_pcDepthMapGenerator->initViewComponent( rpcPic );
+  }
+#endif
+
 #if H_3D_NBDV 
   if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.h	(revision 476)
@@ -51,4 +51,8 @@
 #include "TLibCommon/TComSampleAdaptiveOffset.h"
 
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
+
 #include "TDecEntropy.h"
 #include "TDecSlice.h"
@@ -79,4 +83,8 @@
   TComLoopFilter*       m_pcLoopFilter;
   
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator*  m_pcDepthMapGenerator;
+#endif
+
   TComSampleAdaptiveOffset*     m_pcSAO;
   Double                m_dDecTime;
@@ -98,4 +106,7 @@
                  TComLoopFilter*         pcLoopFilter,
                  TComSampleAdaptiveOffset* pcSAO
+#if H_3D_IV_MERGE
+                 ,TComDepthMapGenerator* pcDepthMapGenerator
+#endif
                  );
   Void  create  ();
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.cpp	(revision 476)
@@ -37,4 +37,7 @@
 
 #include "NALread.h"
+#if H_3D_IV_MERGE
+#include "../../App/TAppDecoder/TAppDecTop.h"
+#endif
 #include "TDecTop.h"
 
@@ -389,5 +392,9 @@
 }
 
+#if H_3D_IV_MERGE
+Void TDecTop::init(TAppDecTop* pcTAppDecTop)
+#else
 Void TDecTop::init()
+#endif
 {
   // initialize ROM
@@ -395,7 +402,16 @@
   initROM();
 #endif
-  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
+  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO
+#if H_3D_IV_MERGE
+    , &m_cDepthMapGenerator
+#endif
+    );
   m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
   m_cEntropyDecoder.init(&m_cPrediction);
+
+#if H_3D_IV_MERGE
+  m_tAppDecTop = pcTAppDecTop;
+  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
+#endif
 }
 
@@ -754,4 +770,13 @@
 
     m_cSliceDecoder.create();
+#if H_3D_IV_MERGE
+    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewIndex() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
+    m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_bitDepthY, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
+    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
+    if( m_apcSlicePilot->getSPS()->getViewIndex() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
+    {
+      pcDMG0->create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_bitDepthY, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
+    }
+#endif
   }
   else
@@ -893,4 +918,10 @@
 #endif
 
+#endif
+
+#if H_3D_IV_MERGE
+    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewIndex, pcSlice->getPOC(), false ) : NULL;
+    assert( !m_isDepth || pcTexturePic != NULL );
+    pcSlice->setTexturePic( pcTexturePic );
 #endif
     // For generalized B
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecTop.h	(revision 476)
@@ -45,4 +45,7 @@
 #include "TLibCommon/TComTrQuant.h"
 #include "TLibCommon/SEI.h"
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
 
 #include "TDecGop.h"
@@ -222,4 +225,8 @@
   Bool                    m_isDepth;
   CamParsCollector*       m_pcCamParsCollector;
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator   m_cDepthMapGenerator;
+  TAppDecTop*             m_tAppDecTop;
+#endif
 #endif
 #endif
@@ -234,5 +241,9 @@
   void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
 
+#if H_3D_IV_MERGE
+  Void  init(TAppDecTop* pcTAppDecTop);
+#else
   Void  init();
+#endif
 #if H_MV  
   Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayer );
@@ -265,4 +276,7 @@
   Bool                    getIsDepth            ()               { return m_isDepth;    }
   Void                    setCamParsCollector( CamParsCollector* pcCamParsCollector ) { m_pcCamParsCollector = pcCamParsCollector; }
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator*  getDepthMapGenerator  () { return &m_cDepthMapGenerator; }
+#endif
 #endif
 #endif
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 476)
@@ -581,4 +581,30 @@
   WRITE_FLAG( 0, "sps_extension_flag" );
 #endif
+
+#if H_3D_IV_MERGE
+  if( pcSPS->getViewIndex() || pcSPS->isDepth() )
+  {
+    WRITE_FLAG( 0, "base_view_flag" ); 
+    if( pcSPS->isDepth() )
+    {
+      WRITE_FLAG( 1, "depth_flag" ); 
+      WRITE_UVLC( pcSPS->getViewIndex(), "view_idx" );
+    }
+    else
+    {
+      WRITE_FLAG( 0, "depth_flag" ); 
+      WRITE_UVLC( pcSPS->getViewIndex() - 1, "view_idx_minus1" );
+      WRITE_UVLC( pcSPS->getPredDepthMapGeneration(), "Pdm_generation" );
+      if( pcSPS->getPredDepthMapGeneration() )
+      {
+        WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
+      }
+    }
+  }
+  else
+  {
+    WRITE_FLAG( 1, "base_view_flag" );   
+  }
+#endif
 }
 
@@ -1071,8 +1097,16 @@
       xCodePredWeightTable( pcSlice );
     }
+#if H_3D_IV_MERGE
+    assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_MEM);
+#else
     assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS);
+#endif
     if (!pcSlice->isIntra())
     {
+#if H_3D_IV_MERGE
+      WRITE_UVLC(((pcSlice->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE) == PDM_USE_FOR_MERGE? MRG_MAX_NUM_CANDS_MEM: MRG_MAX_NUM_CANDS) - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
+#else
       WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
+#endif
     }
     Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h	(revision 476)
@@ -375,4 +375,8 @@
   TAppComCamPara* m_cameraParameters; 
   
+#if H_3D_IV_MERGE
+  UInt      m_uiPredDepthMapGeneration;
+  UInt      m_uiMultiviewMvPredMode;
+#endif
 #if H_3D_VSO
   //====== View Synthesis Optimization ======
@@ -926,4 +930,10 @@
   Void      setDispCoeff                    ( Double  d )   { m_dDispCoeff  = d; }
 #endif // H_3D_VSO
+#if H_3D_IV_MERGE
+  Void      setMultiviewMvPredMode              (UInt ui)   { m_uiMultiviewMvPredMode = ui;}
+  Void      setPredDepthMapGeneration       ( UInt  u )      { m_uiPredDepthMapGeneration   = u; }  
+
+  UInt      getMultiviewMvPredMode          ()              { return m_uiMultiviewMvPredMode;}
+#endif
 #endif // H_3D
 };
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 476)
@@ -1259,6 +1259,11 @@
 {
   assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
+#if H_3D_IV_MERGE
+  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
+  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
+#else
   TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
+#endif
   Int numValidMergeCand = 0;
 
@@ -1284,5 +1289,9 @@
   rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
 
+#if H_3D_IV_MERGE
+  Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM];
+#else
   Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
+#endif
   for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
   {
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 476)
@@ -49,5 +49,7 @@
 #include <time.h>
 #include <math.h>
-
+#if H_3D_IV_MERGE
+#include "../../App/TAppEncoder/TAppEncTop.h"
+#endif
 using namespace std;
 //! \ingroup TLibEncoder
@@ -107,4 +109,7 @@
   m_viewIndex  =   0; 
   m_isDepth = false;
+#if H_3D_IV_MERGE
+  m_pcDepthMapGenerator = NULL;
+#endif
 #endif
 #endif
@@ -155,4 +160,7 @@
   m_viewIndex            = pcTEncTop->getViewIndex();
   m_isDepth              = pcTEncTop->getIsDepth();
+#if H_3D_IV_MERGE
+  m_pcDepthMapGenerator  = pcTEncTop->getDepthMapGenerator();
+#endif
 #endif
 #endif
@@ -674,4 +682,10 @@
 #endif
 
+#if H_3D_IV_MERGE
+    TAppEncTop* tAppEncTop = m_pcEncTop->getEncTop();
+    TComPic * const pcTexturePic = m_pcEncTop->getIsDepth() ? tAppEncTop->getPicFromView( getViewIndex(), pcSlice->getPOC(), false ) : NULL;
+    assert( !m_pcEncTop->getIsDepth() || pcTexturePic != NULL );
+    pcSlice->setTexturePic( pcTexturePic );
+#endif
     //  Slice info. refinement
 #if H_MV
@@ -1028,4 +1042,9 @@
     m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr);
     startCUAddrSliceSegmentIdx++;
+
+#if H_3D_IV_MERGE
+    m_pcDepthMapGenerator->initViewComponent( pcPic );
+#endif
+
 #if H_3D_NBDV
       if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
@@ -2478,5 +2497,5 @@
 #if ADAPTIVE_QP_SELECTION
 #if H_MV
-  printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
+  printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d  bits",
     pcSlice->getLayerId(),
     pcSlice->getPOC(),
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h	(revision 476)
@@ -59,4 +59,7 @@
 #include <vector>
 
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
 //! \ingroup TLibEncoder
 //! \{
@@ -107,4 +110,9 @@
   Int                     m_viewIndex; 
   Bool                    m_isDepth;
+
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator*  m_pcDepthMapGenerator;
+#endif
+
 #endif
 #endif
@@ -166,5 +174,7 @@
   
   TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
-  
+#if H_3D_IV_MERGE
+  TEncTop* getEncTop() { return m_pcEncTop; }
+#endif
 #if !H_MV
   Void  printOutSummary      ( UInt uiNumAllPicCoded );
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 476)
@@ -3315,6 +3315,11 @@
 #endif
 
+#if H_3D_IV_MERGE
+  TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
+  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
+#else
   TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
+#endif
   Int numValidMergeCand = 0 ;
 
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 476)
@@ -529,5 +529,9 @@
   rpcSlice->setSliceSegmentMode     ( m_pcCfg->getSliceSegmentMode()     );
   rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
+#if H_3D_IV_MERGE
+  rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()   + ((rpcSlice->getSPS()->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE) ? 1:0)      );
+#else
   rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
+#endif
   xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
 }
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp	(revision 476)
@@ -119,5 +119,9 @@
 #endif
   m_cLoopFilter.        create( g_uiMaxCUDepth );
-  
+
+#if H_3D_IV_MERGE
+  m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_bitDepthY, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
+#endif
+
 #if RATE_CONTROL_LAMBDA_DOMAIN
   if ( m_RCEnableRateControl )
@@ -225,4 +229,8 @@
   m_cLoopFilter.        destroy();
   m_cRateCtrl.          destroy();
+
+#if H_3D_IV_MERGE
+  m_cDepthMapGenerator. destroy();
+#endif
   // SBAC RD
   if( m_bUseSBACRD )
@@ -284,5 +292,9 @@
 }
 
+#if H_3D_IV_MERGE
+Void TEncTop::init( TAppEncTop* pcTAppEncTop)
+#else
 Void TEncTop::init()
+#endif
 {
   // initialize SPS
@@ -306,4 +318,9 @@
   m_cCuEncoder.   init( this );
   
+#if H_3D_IV_MERGE
+  m_pcTAppEncTop = pcTAppEncTop;
+  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#endif
+
   // initialize transform & quantization class
   m_pcCavlcCoder = getCavlcCoder();
@@ -658,5 +675,22 @@
   {
     m_cSPS.initCamParaSPS           ( m_viewIndex, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
-  }
+#if H_3D_IV_MERGE
+    if( m_viewIndex )
+    {
+      m_cSPS.setPredDepthMapGeneration( m_viewIndex, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode);
+    }
+    else
+    {
+      m_cSPS.setPredDepthMapGeneration( m_viewIndex, false );
+    }
+#endif
+  }
+#if H_3D_IV_MERGE
+  else
+  {
+    m_cSPS.initCamParaSPSDepth           ( m_viewIndex);
+    m_cSPS.setPredDepthMapGeneration( m_viewIndex, true );
+  }
+#endif
 #endif
 }
@@ -1300,3 +1334,5 @@
 }
 #endif
+
+
 //! \}
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h	(revision 475)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h	(revision 476)
@@ -57,4 +57,8 @@
 #include "TEncPreanalyzer.h"
 #include "TEncRateCtrl.h"
+
+#if H_3D_IV_MERGE
+#include "TLibCommon/TComDepthMapGenerator.h"
+#endif
 //! \ingroup TLibEncoder
 //! \{
@@ -63,4 +67,8 @@
 // Class definition
 // ====================================================================================================================
+
+#if H_3D_IV_MERGE
+class TAppEncTop;
+#endif
 
 /// encoder class
@@ -96,4 +104,9 @@
   TEncSlice               m_cSliceEncoder;                ///< slice encoder
   TEncCu                  m_cCuEncoder;                   ///< CU encoder
+
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator   m_cDepthMapGenerator;           ///< depth map generator
+#endif
+
   // SPS
   TComSPS                 m_cSPS;                         ///< SPS
@@ -119,4 +132,7 @@
   TEncBinCABAC*           m_pcRDGoOnBinCodersCABAC;        ///< going on bin coder CABAC for RD stage per substream
 
+#if H_3D_IV_MERGE  
+  TAppEncTop*             m_pcTAppEncTop;
+#endif
   // quality control
   TEncPreanalyzer         m_cPreanalyzer;                 ///< image characteristics analyzer for TM5-step3-like adaptive QP
@@ -145,5 +161,9 @@
   Void      create          ();
   Void      destroy         ();
+#if H_3D_IV_MERGE
+  Void      init            ( TAppEncTop* pcTAppEncTop );
+#else
   Void      init            ();
+#endif
 #if H_MV  
   TComPicLists* getIvPicLists() { return m_ivPicLists; }
@@ -185,4 +205,7 @@
   TEncSbac*               getRDGoOnSbacCoders   () { return  m_pcRDGoOnSbacCoders;   }
   TEncRateCtrl*           getRateCtrl           () { return &m_cRateCtrl;             }
+#if H_3D_IV_MERGE
+  TAppEncTop*             getEncTop             () { return m_pcTAppEncTop; }
+#endif
   TComSPS*                getSPS                () { return  &m_cSPS;                 }
   TComPPS*                getPPS                () { return  &m_cPPS;                 }
@@ -205,4 +228,7 @@
   Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
 #endif
+#if H_3D_IV_MERGE
+  TComDepthMapGenerator*  getDepthMapGenerator  () { return  &m_cDepthMapGenerator;   }
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // encoder function
