Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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 456)
+++ 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
