Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 455)
@@ -112,4 +112,7 @@
   m_sliceStartCU        = 0;
   m_sliceSegmentStartCU = 0;
+#if H_3D_NBDV
+  m_pDvInfo              = NULL;
+#endif
 }
 
@@ -169,4 +172,7 @@
     m_pcTrCoeffCb        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
     m_pcTrCoeffCr        = (TCoeff*)xMalloc(TCoeff, uiWidth*uiHeight/4);
+#if H_3D_NBDV 
+    m_pDvInfo            = (DisInfo* )xMalloc(DisInfo,  uiNumPartition);
+#endif
     memset( m_pcTrCoeffY, 0,uiWidth*uiHeight * sizeof( TCoeff ) );
     memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
@@ -284,5 +290,7 @@
     if ( m_apiMVPNum[0]       ) { delete[] m_apiMVPNum[0];      m_apiMVPNum[0]      = NULL; }
     if ( m_apiMVPNum[1]       ) { delete[] m_apiMVPNum[1];      m_apiMVPNum[1]      = NULL; }
-    
+#if H_3D_NBDV 
+    if ( m_pDvInfo            ) { xFree(m_pDvInfo);             m_pDvInfo           = NULL; }
+#endif
     m_acCUMvField[0].destroy();
     m_acCUMvField[1].destroy();
@@ -652,5 +660,7 @@
   memset( m_puhCbf[2],          0, iSizeInUchar );
   memset( m_puhDepth,     uiDepth, iSizeInUchar );
-
+#if H_3D_NBDV
+  m_pDvInfo->bDV = false;
+#endif
   UChar uhWidth  = g_uiMaxCUWidth  >> uiDepth;
   UChar uhHeight = g_uiMaxCUHeight >> uiDepth;
@@ -800,4 +810,7 @@
   m_CUTransquantBypass  = pcCU->getCUTransquantBypass()+uiPart;
   
+#if H_3D_NBDV
+  m_pDvInfo             = pcCU->getDvInfo()           + uiPart;
+#endif
   m_pbMergeFlag         = pcCU->getMergeFlag()        + uiPart;
   m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
@@ -862,7 +875,16 @@
   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiPart,sizeof(UInt)*m_uiNumPartition);
 }
-
+#if H_3D_NBDV
+Void TComDataCU::copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx)
+{
+  m_pDvInfo            = pcCU->getDvInfo()                + uiAbsPartIdx;
+}
+#endif
 // Copy inter prediction info from the biggest CU
-Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList )
+Void TComDataCU::copyInterPredInfoFrom    ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList 
+#if H_3D_NBDV
+  , Bool bNBDV
+#endif
+  )
 {
   m_pcPic              = pcCU->getPic();
@@ -886,4 +908,14 @@
 
   m_pePartSize         = pcCU->getPartitionSize ()        + uiAbsPartIdx;
+#if H_3D_NBDV
+  if(bNBDV == true)
+  {
+    m_puhWidth           = pcCU->getWidth ()                + uiAbsPartIdx;
+    m_puhHeight          = pcCU->getHeight()                + uiAbsPartIdx;
+    m_puhDepth           = pcCU->getDepth ()                + uiAbsPartIdx;
+  }
+  else
+  {
+#endif
   m_pePredMode         = pcCU->getPredictionMode()        + uiAbsPartIdx;
   m_CUTransquantBypass = pcCU->getCUTransquantBypass()    + uiAbsPartIdx;
@@ -904,4 +936,7 @@
   memcpy(m_sliceStartCU,pcCU->m_sliceStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
   memcpy(m_sliceSegmentStartCU,pcCU->m_sliceSegmentStartCU+uiAbsPartIdx,sizeof(UInt)*m_uiNumPartition);
+#if H_3D_NBDV
+  }
+#endif
 }
 
@@ -1004,4 +1039,7 @@
 
   memcpy( rpcCU->getQP() + m_uiAbsIdxInLCU, m_phQP, sizeInChar  );
+#if H_3D_NBDV
+  memcpy( rpcCU->getDvInfo()         + m_uiAbsIdxInLCU, m_pDvInfo,    sizeof(* m_pDvInfo)     * m_uiNumPartition );
+#endif
 
   memcpy( rpcCU->getPartitionSize()  + m_uiAbsIdxInLCU, m_pePartSize, sizeof( *m_pePartSize ) * m_uiNumPartition );
@@ -2406,5 +2444,21 @@
   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
-
+#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; 
+#endif
+
+#if H_3D_NBDV //Notes from QC: Some examples to show how to use the NBDV and DoNBDV variables. Remove this comment once it is done 
+  DisInfo cDisInfo;
+  cDisInfo.bDV = false; 
+  //if(!bNoPdmMerge) 
+  //{
+    //cDisInfo.bDV = getDvInfo(uiAbsPartIdx).bDV;
+    //cDisInfo.m_aVIdxCan = getDvInfo(uiAbsPartIdx).m_aVIdxCan;
+    //cDisInfo.m_acNBDV = getDvInfo(uiAbsPartIdx).m_acNBDV;
+//#if H_3D_NBDV_REF
+    //cDisInfo.m_acDoNBDV = getDvInfo(uiAbsPartIdx).m_acDoNBDV;
+//#endif
+  //}
+#endif
   //left
   UInt uiLeftPartIdx = 0;
@@ -3846,4 +3900,352 @@
 }
 #endif
-
+#if H_3D_NBDV 
+//Notes from QC:
+//TBD#1: DoNBDV related contributions are just partially integrated under the marco of H_3D_NBDV_REF, remove this comment once DoNBDV and BVSP are done
+//TBD#2: set of DvMCP values need to be done as part of inter-view motion prediction process. Remove this comment once merge related integration is done
+//To be checked: Parallel Merge features for NBDV, related to DV_DERIVATION_PARALLEL_B0096 and LGE_IVMP_PARALLEL_MERGE_B0136 are not integrated. The need of these features due to the adoption of CU-based NBDV is not clear. We need confirmation on this, especially by proponents
+Bool TComDataCU::getDisMvpCandNBDV( DisInfo* pDInfo
+#if H_3D_NBDV_REF
+, Bool bDepthRefine
+#endif
+)
+{
+  //// ******* Init variables ******* /////
+  // Init disparity struct for results
+  pDInfo->bDV = false;   
+  // Init struct for disparities from MCP neighboring blocks
+  IDVInfo cIDVInfo;
+  cIDVInfo.m_bFound = false; 
+  UInt uiPartIdx = 0;
+  UInt uiPartAddr = 0;
+  for (UInt iCurDvMcpCand = 0; iCurDvMcpCand < IDV_CANDS; iCurDvMcpCand++)
+  {
+    for (UInt iList = 0; iList < 2; iList++)
+    {
+      cIDVInfo.m_acMvCand[iList][iCurDvMcpCand].setZero();
+      cIDVInfo.m_aVIdxCan[iList][iCurDvMcpCand] = 0; 
+      cIDVInfo.m_bAvailab[iList][iCurDvMcpCand] = false; 
+    }
+  }
+  // Get Positions  
+  PartSize eCUMode    = getPartitionSize( uiPartAddr );    
+  assert(eCUMode == SIZE_2Nx2N);
+  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;  
+
+  deriveLeftRightTopIdxGeneral(uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
+  deriveLeftBottomIdxGeneral  (uiPartAddr, uiPartIdx, uiPartIdxLB );
+
+  //// ******* Get disparity from temporal neighboring blocks ******* /////
+  if ( getSlice()->getEnableTMVPFlag() )
+  {
+    TComMv cColMv;
+    Int iTargetViewIdx = 0;
+    Int iTStartViewIdx = 0;    
+
+    ///*** Derive center position ***
+    UInt uiPartIdxCenter;
+    Int  uiLCUIdx   = getAddr();
+    xDeriveCenterIdx(uiPartIdx, uiPartIdxCenter );
+
+    ///*** Derive bottom right neighbour position ***
+    Int iLCUIdxRBNb  = -1;    
+    Int iPartIdxRBNb = -1;
+    xDeriveRightBottomNbIdx(iLCUIdxRBNb, iPartIdxRBNb );
+
+    ///*** Search temporal candidate pictures for disparity vector ***
+    const Int iNumCandPics = getPic()->getNumDdvCandPics();
+    for(Int curCandPic = 0; curCandPic < iNumCandPics; curCandPic++)
+    {
+      RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
+      Int        curCandPicRefIdx = 0;
+      if( curCandPic == 0 ) 
+      { 
+        eCurRefPicList   = RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0);
+        curCandPicRefIdx = getSlice()->getColRefIdx();
+      }
+      else                 
+      {
+        eCurRefPicList   = getPic()->getRapRefList();
+        curCandPicRefIdx = getPic()->getRapRefIdx();
+      }
+
+      // Check BR and Center       
+      for(Int curPosition = 0; curPosition < 2; curPosition++) 
+      {
+        Bool bCheck = false; 
+        if ( curPosition == 0 && iLCUIdxRBNb >= 0 )
+          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, iLCUIdxRBNb, iPartIdxRBNb,  cColMv, iTargetViewIdx, iTStartViewIdx);
+
+        if (curPosition == 1 )
+          bCheck = xGetColDisMV( eCurRefPicList, curCandPicRefIdx, uiLCUIdx,   uiPartIdxCenter,  cColMv, iTargetViewIdx, iTStartViewIdx );
+
+        if( bCheck )
+        {
+          clipMv(cColMv);
+          pDInfo->m_acNBDV = cColMv;
+          pDInfo->m_aVIdxCan  = iTargetViewIdx;
+          TComPic* picDepth = NULL;
+
+#if H_3D_NBDV_REF
+          /*Place DoNBDV*/ 
+          pDInfo->m_acDoNBDV  = cColMv;
+#endif
+          return true;
+        }
+      } 
+    }
+  } 
+
+  UInt uiIdx = 0;
+  Bool        bCheckMcpDv = false;   
+  TComDataCU* pcTmpCU     = NULL;
+
+  //// ******* Get disparity from left block ******* /////
+  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
+  bCheckMcpDv = true; 
+  if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFT
+#if H_3D_NBDV_REF
+  , bDepthRefine 
+#endif
+    ) )
+    return true;
+
+  //// ******* Get disparity from above block ******* /////
+  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
+  if(pcTmpCU != NULL )
+  {
+    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
+    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVE
+#if H_3D_NBDV_REF
+  , bDepthRefine 
+#endif
+    ) )
+      return true;
+  }
+
+  //// ******* Get disparity from above right block ******* /////
+  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true);
+  if(pcTmpCU != NULL )
+  {
+    bCheckMcpDv = ( ( getAddr() - pcTmpCU->getAddr() ) == 0);
+    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVERIGHT
+#if H_3D_NBDV_REF
+  , bDepthRefine 
+#endif
+    ) )
+      return true;
+  }
+
+  //// ******* Get disparity from below left block ******* /////
+  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true);
+  if( pcTmpCU != NULL )
+  {
+    bCheckMcpDv = true; 
+    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_LEFTBELOW
+#if H_3D_NBDV_REF
+  , bDepthRefine 
+#endif
+    ) )
+      return true;
+  }
+
+  //// ******* Get disparity from above left block ******* /////
+  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true);
+  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
+
+  if( pcTmpCU != NULL )
+  {
+    bCheckMcpDv = (( getAddr() - pcTmpCU->getAddr() ) <= 1); 
+    if ( xCheckSpatialNBDV( pcTmpCU, uiIdx, pDInfo, bCheckMcpDv, &cIDVInfo, DVFROM_ABOVELEFT
+#if H_3D_NBDV_REF
+  , bDepthRefine 
+#endif
+    ) )
+      return true;
+  }
+
+  //// ******* Search MCP blocks ******* /////
+  if( cIDVInfo.m_bFound ) 
+  {
+    for( Int curPos = 0 ; curPos < IDV_CANDS ; curPos++ ) 
+    {
+      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+      {
+        if( cIDVInfo.m_bAvailab[iList][curPos] )
+        {
+          TComMv cDispVec = cIDVInfo.m_acMvCand[iList][ curPos ];
+          clipMv( cDispVec );
+          pDInfo->m_acNBDV = cDispVec;
+          pDInfo->m_aVIdxCan = 0;
+#if H_3D_NBDV_REF
+          /*Place DoNBDV*/
+
+          pDInfo->m_acDoNBDV = cDispVec;
+          
+#endif
+          return true;
+        }
+      }
+    }
+  }
+
+  TComPic* picDepth = NULL;
+  TComMv defaultDV(0, 0);
+  pDInfo->m_acNBDV = defaultDV;
+  pDInfo->m_aVIdxCan = 0;
+#if H_3D_NBDV_REF
+  /*Place DoNBDV*/
+  
+  pDInfo->m_acDoNBDV = defaultDV;
+#endif
+  return false; 
+}
+
+Bool TComDataCU::xCheckSpatialNBDV( TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paIDVInfo, UInt uiMvpDvPos
+#if H_3D_NBDV_REF
+, Bool bDepthRefine 
+#endif
+)
+{
+  if( pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+  {
+    Bool bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
+    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
+    {
+      RefPicList eRefPicList = RefPicList(iList);
+      Int      refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
+      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
+
+      if( refId >= 0)
+      {
+        Int refViewIdx  = pcTmpCU->getSlice()->getRefPic(eRefPicList, refId)->getViewIndex();
+        if (refViewIdx != m_pcSlice->getViewIndex()) 
+        {          
+          clipMv(cMvPred);
+          pNbDvInfo->m_acNBDV = cMvPred;
+          pNbDvInfo->m_aVIdxCan = refViewIdx;
+          TComPic* picDepth = NULL;
+#if H_3D_NBDV_REF
+          /*Place DoNBDV*/
+          
+          pNbDvInfo->m_acDoNBDV = cMvPred;
+#endif
+          return true;
+        }
+        else if ( bSearchForMvpDv && cMvPred.getIDVFlag() && bTmpIsSkipped )
+        {
+          assert( uiMvpDvPos < IDV_CANDS );
+          paIDVInfo->m_acMvCand[iList][ uiMvpDvPos ] = TComMv( cMvPred.getIDVHor(), cMvPred.getIDVVer() );
+          //Notes from QC: DvMCP is implemented in a way that doesnt carry the reference view identifier as NBDV. It only works for CTC and needs to be fixed to be aligned with other part of the NBDV design.
+          paIDVInfo->m_aVIdxCan[iList][ uiMvpDvPos ] = 0; 
+          paIDVInfo->m_bAvailab[iList][ uiMvpDvPos ] = true;
+          paIDVInfo->m_bFound                        = true; 
+        }
+      }
+    }
+  }
+  return false; 
+}
+ 
+Void TComDataCU::xDeriveRightBottomNbIdx(Int &riLCUIdxRBNb, Int &riPartIdxRBNb )
+{
+  UInt uiPartIdx = 0;
+  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();  
+  Int uiLCUIdx = getAddr();
+
+  UInt uiPartIdxRB;
+  deriveRightBottomIdx(uiPartIdx, uiPartIdxRB );  
+  UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
+
+  if (( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() )>= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
+  {
+    riLCUIdxRBNb  = -1;
+    riPartIdxRBNb = -1;
+  }
+  else if(( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() )>= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
+  {
+    riLCUIdxRBNb  = -1;
+    riPartIdxRBNb = -1;
+  }
+  else
+  {
+    if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU 
+      ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
+    {
+      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
+      riLCUIdxRBNb  = uiLCUIdx; 
+    }
+    else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
+    {
+      riPartIdxRBNb = -1;
+      riLCUIdxRBNb  = -1;
+    }
+    else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
+    {
+      riPartIdxRBNb = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
+      riLCUIdxRBNb = uiLCUIdx + 1;
+    }
+    else //is the right bottom corner of LCU                       
+    {
+      riPartIdxRBNb = -1;
+      riLCUIdxRBNb  = -1;
+    }
+  }
+}
+
+
+Void TComDataCU::setDvInfoSubParts( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  UInt uiCurrPartNumb = m_pcPic->getNumPartInCU() >> (uiDepth << 1);
+  for (UInt ui = 0; ui < uiCurrPartNumb; ui++ )
+  {
+    m_pDvInfo[uiAbsPartIdx + ui] = cDvInfo;
+  }
+}
+
+Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
+{
+
+  RefPicList  eColRefPicList = REF_PIC_LIST_0;
+  Int iColViewIdx, iColRefViewIdx;
+  TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
+  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
+  iColViewIdx = pColCU->getSlice()->getViewIndex();
+  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiPartUnitIdx))
+  {
+    return false;
+  }
+  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++) 
+  {
+    if(pColCU->getSlice()->isInterB())
+    {
+        eColRefPicList = RefPicList(ilist);
+    }
+
+    Int iColRefIdx = pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartUnitIdx);
+
+    if (iColRefIdx < 0)
+    {
+      continue;
+    }
+
+    iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewIndex();
+
+    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
+    {
+      continue;
+    }
+    else 
+    {
+      rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiPartUnitIdx);
+      rcMv.setIDVFlag(0);
+      iTargetViewIdx  = iColRefViewIdx ;
+      iStartViewIdx   = iColViewIdx   ;
+      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 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 455)
@@ -187,5 +187,7 @@
   Char*         m_apiMVPNum[2];       ///< array of number of possible motion vectors predictors
   Bool*         m_pbIPCMFlag;         ///< array of intra_pcm flags
-
+#if H_3D_NBDV
+  DisInfo*      m_pDvInfo;
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // misc. variables
@@ -241,7 +243,13 @@
   Void          initSubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp );
   Void          setOutsideCUPart      ( UInt uiAbsPartIdx, UInt uiDepth );
-
+#if H_3D_NBDV
+  Void          copyDVInfoFrom (TComDataCU* pcCU, UInt uiAbsPartIdx);
+#endif
   Void          copySubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
-  Void          copyInterPredInfoFrom ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList );
+  Void          copyInterPredInfoFrom ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList
+#if H_3D_NBDV
+  , Bool bNBDV = false
+#endif
+  );
   Void          copyPartFrom          ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
   
@@ -391,5 +399,9 @@
   Void          setIPCMFlag           (UInt uiIdx, Bool b )     { m_pbIPCMFlag[uiIdx] = b;           }
   Void          setIPCMFlagSubParts   (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth);
-
+#if H_3D_NBDV
+  Void          setDvInfoSubParts     ( DisInfo cDvInfo, UInt uiAbsPartIdx, UInt uiDepth );
+  DisInfo*      getDvInfo             ()                        { return m_pDvInfo;                 }
+  DisInfo       getDvInfo             (UInt uiIdx)              { return m_pDvInfo[uiIdx];          }
+#endif
   /// get slice ID for SU
   Int           getSUSliceID          (UInt uiIdx)              {return m_piSliceSUMap[uiIdx];      } 
@@ -406,4 +418,20 @@
                                           ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
                                           ,Bool bIndependentTileBoundaryEnabled );
+#if H_3D_NBDV
+  Void          xDeriveRightBottomNbIdx(Int &uiLCUIdxRBNb, Int &uiPartIdxRBNb );
+  Bool          xCheckSpatialNBDV (TComDataCU* pcTmpCU, UInt uiIdx, DisInfo* pNbDvInfo, Bool bSearchForMvpDv, IDVInfo* paMvpDvInfo,
+                                   UInt uiMvpDvPos
+#if H_3D_NBDV_REF
+  , Bool bDepthRefine = false
+#endif
+  );
+  Bool          xGetColDisMV      ( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int & iTargetViewIdx, Int & iStartViewIdx );
+  Bool          getDisMvpCandNBDV ( DisInfo* pDInfo
+#if H_3D_NBDV_REF
+   , Bool bDepthRefine = false
+#endif
+   ); 
+   
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for accessing partition information
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMotionInfo.h	(revision 455)
@@ -58,4 +58,23 @@
 } AMVPInfo;
 
+#if H_3D_NBDV
+typedef struct _DisCand 
+{
+  Bool bDV;
+  TComMv m_acNBDV;              // DV from NBDV
+#if H_3D_NBDV_REF 
+  TComMv m_acDoNBDV;            // DV from DoNBDV
+#endif  
+  Int    m_aVIdxCan;            // View order index (the same with the NBDV and the DoNBDV)
+} DisInfo;
+
+typedef struct _IDVCand // IDV
+{
+  TComMv m_acMvCand[2][ IDV_CANDS ];            
+  Int    m_aVIdxCan[2][ IDV_CANDS ];            
+  Bool   m_bAvailab[2][ IDV_CANDS ];
+  Bool   m_bFound;                                
+} IDVInfo;
+#endif
 // ====================================================================================================================
 // Class definition
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMv.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMv.h	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComMv.h	(revision 455)
@@ -54,5 +54,9 @@
   Short m_iHor;     ///< horizontal component of motion vector
   Short m_iVer;     ///< vertical component of motion vector
-  
+#if H_3D_NBDV
+  Bool  m_bIDV;       
+  Short m_iIDVHor;    
+  Short m_iIDVVer;   
+#endif
 public:
   
@@ -64,4 +68,9 @@
   m_iHor(0),
   m_iVer(0)
+#if H_3D_NBDV
+  , m_bIDV(false)
+  , m_iIDVHor(0)
+  , m_iIDVVer(0)
+#endif
   {
   }
@@ -70,4 +79,9 @@
   m_iHor(iHor),
   m_iVer(iVer)
+ #if H_3D_NBDV
+  , m_bIDV(false)
+  , m_iIDVHor(0)
+  , m_iIDVVer(0)
+#endif
   {
   }
@@ -81,5 +95,9 @@
   Void  setVer    ( Short i )                   { m_iVer = i;                               }
   Void  setZero   ()                            { m_iHor = m_iVer = 0;  }
-  
+#if H_3D_NBDV
+  Void   setIDVHor  (Short i)                    {m_iIDVHor = i;}
+  Void   setIDVVer  (Short i)                    {m_iIDVVer = i;}
+  Void   setIDVFlag (Bool b )                    {m_bIDV    = b;}
+#endif
   // ------------------------------------------------------------------------------------------------------------------
   // get
@@ -90,5 +108,9 @@
   Int   getAbsHor () const { return abs( m_iHor );   }
   Int   getAbsVer () const { return abs( m_iVer );   }
-  
+#if H_3D_NBDV
+  Short getIDVHor () const { return m_iIDVHor;       }
+  Short getIDVVer () const { return m_iIDVVer;       }
+  Bool  getIDVFlag() const { return m_bIDV;          }
+#endif
   // ------------------------------------------------------------------------------------------------------------------
   // operations
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.cpp	(revision 455)
@@ -77,4 +77,9 @@
   m_apcPicYuv[0]      = NULL;
   m_apcPicYuv[1]      = NULL;
+#if H_3D_NBDV
+  m_iNumDdvCandPics   = 0;
+  m_eRapRefList       = REF_PIC_LIST_0;
+  m_uiRapRefIdx       = 0;
+#endif
 }
 
@@ -553,3 +558,70 @@
 #endif // H_3D
 #endif // H_MV
+#if H_3D_NBDV 
+Int TComPic::getDisCandRefPictures(Int iColPOC)
+{
+  UInt uiTempLayerCurr=7;
+  TComSlice* currSlice = getSlice(getCurrSliceIdx());
+  UInt NumDdvCandPics = 0;
+  if ( !currSlice->getEnableTMVPFlag() )
+    return NumDdvCandPics;
+  NumDdvCandPics +=1;
+
+  UInt iPOCCurr=currSlice->getPOC();
+  UInt iPOCDiff = 255;
+  Bool bCheck = false;
+
+  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
+  {
+    UInt X = lpNr? currSlice->getColFromL0Flag() : 1-currSlice->getColFromL0Flag();
+    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(X)); i++)
+    {
+      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)X, i)->getViewIndex() 
+        && (X == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)X, i)!= iColPOC) && NumDdvCandPics!=2)
+      {
+        TComSlice* refSlice = currSlice->getRefPic((RefPicList)X, i)->getSlice(getCurrSliceIdx());
+        Bool bRAP = (refSlice->getViewIndex() && refSlice->isIRAP())? 1: 0; 
+        UInt uiTempLayer = currSlice->getRefPic((RefPicList)X, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
+        Int iTempPoc = currSlice->getRefPic((RefPicList)X, i)->getPOC();
+        Int iTempDiff = (iTempPoc > iPOCCurr) ? (iTempPoc - iPOCCurr): (iPOCCurr - iTempPoc);
+        if(bRAP)
+        {
+          this->setRapRefIdx(i);
+          this->setRapRefList((RefPicList)X);
+          NumDdvCandPics = 2;
+          return NumDdvCandPics;
+        }
+        else if (uiTempLayerCurr > uiTempLayer) 
+           uiTempLayerCurr = uiTempLayer; 
+      }
+    }
+  }
+  UInt Z;
+  UInt idx=0;
+  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr ++)
+  {
+    UInt X = lpNr? currSlice->getColFromL0Flag() : 1-currSlice->getColFromL0Flag();
+    for (UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(X)); i++)
+    {
+      Int iTempPoc = currSlice->getRefPic((RefPicList)X, i)->getPOC();
+      Int iTempDiff = (iTempPoc > iPOCCurr) ? (iTempPoc - iPOCCurr): (iPOCCurr - iTempPoc);
+      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)X, i)->getViewIndex() &&  (X == currSlice->getColFromL0Flag()||currSlice->getRefPOC((RefPicList)X, i)!= iColPOC) 
+        && currSlice->getRefPic((RefPicList)X, i)->getSlice(getCurrSliceIdx())->getTLayer() == uiTempLayerCurr && iPOCDiff > iTempDiff)
+      {
+        iPOCDiff=iTempDiff;
+        Z=X;
+        idx = i;
+      }
+    }
+  }
+  if(iPOCDiff<255)
+  {
+    this->setRapRefIdx(idx);
+    this->setRapRefList((RefPicList)Z);
+    NumDdvCandPics = 2;
+  }
+
+  return NumDdvCandPics;
+}
+#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 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPic.h	(revision 455)
@@ -96,4 +96,9 @@
 #endif
 #endif
+#if H_3D_NBDV
+  UInt        m_uiRapRefIdx;
+  RefPicList  m_eRapRefList;
+  Int         m_iNumDdvCandPics;
+#endif
 public:
   TComPic();
@@ -194,4 +199,13 @@
   Void          print( Bool legend );
 #endif
+#if H_3D_NBDV
+  Int           getNumDdvCandPics()                    {return m_iNumDdvCandPics;   }
+  Int           getDisCandRefPictures(Int iColPOC);
+  Void          setRapRefIdx(UInt uiRapRefIdx)         {m_uiRapRefIdx = uiRapRefIdx;}
+  Void          setRapRefList(RefPicList eRefPicList)  {m_eRapRefList = eRefPicList;}
+  Void          setNumDdvCandPics (Int i)              {m_iNumDdvCandPics = i;       }
+  UInt          getRapRefIdx()                         {return m_uiRapRefIdx;       }
+  RefPicList    getRapRefList()                        {return m_eRapRefList;       }
+#endif
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TypeDef.h	(revision 455)
@@ -78,4 +78,15 @@
                                               // SAIT_VSO_EST_A0033, JCT3V-A0033 modification 3
                                               // LGE_WVSO_A0119
+#define H_3D_NBDV                         1   // Neighboring block disparity derivation 
+                                              // JCT3V-A0097 
+                                              // LGE_DVMCP_A0126
+                                              // LGE_DVMCP_MEM_REDUCTION_B0135     
+                                              // QC_SIMPLE_NBDV_B0047
+                                              // FIX_LGE_DVMCP_B0133
+                                              // QC_NBDV_LDB_FIX_C0055
+                                              // MTK_SAIT_TEMPORAL_FIRST_ORDER_C0141_C0097
+                                              // MTK_SIMPLIFY_DVTC_C0135           
+                                              // QC_CU_NBDV_D0181
+                                              // SEC_DEFAULT_DV_D0112
 #endif 
 
@@ -92,5 +103,13 @@
 #define H_3D_VSO_SYNTH_DIST_OUT           0   // Output of synthesized view distortion instead of depth distortion in encoder output
 #endif
-
+////   ****** Neighbouring block-based Disparity Vector  *********
+#if H_3D_NBDV
+#define IDV_CANDS                         6
+#define DVFROM_LEFTBELOW                  1
+#define DVFROM_LEFT                       2
+#define DVFROM_ABOVERIGHT                 3
+#define DVFROM_ABOVE                      4
+#define DVFROM_ABOVELEFT                  5
+#endif
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   HM RELATED DEFINES ////////////////////////////////
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecCu.cpp	(revision 455)
@@ -269,5 +269,40 @@
     pcCU->setQPSubParts( pcCU->getRefQP(uiAbsPartIdx), uiAbsPartIdx, uiDepth ); // set QP to default QP
   }
-
+#if H_3D_NBDV 
+  DisInfo DvInfo; 
+  DvInfo.bDV = false;
+  DvInfo.m_acNBDV.setZero();
+  DvInfo.m_aVIdxCan = 0;
+#if H_3D_NBDV_REF  
+  DvInfo.m_acDoNBDV.setZero();
+#endif
+ 
+ 
+  if(!pcCU->getSlice()->isIntra())
+  {
+    if(pcCU->getSlice()->getViewIndex() && !pcCU->getSlice()->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.
+    {
+      m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0, true );
+      m_ppcCU[uiDepth]->copyDVInfoFrom( pcCU, uiAbsPartIdx);
+      PartSize ePartTemp = m_ppcCU[uiDepth]->getPartitionSize(0);
+      UChar cWidTemp     = m_ppcCU[uiDepth]->getWidth(0);
+      UChar cHeightTemp  = m_ppcCU[uiDepth]->getHeight(0);
+      m_ppcCU[uiDepth]->setWidth  ( 0, pcCU->getSlice()->getSPS()->getMaxCUWidth ()/(1<<uiDepth)  );
+      m_ppcCU[uiDepth]->setHeight ( 0, pcCU->getSlice()->getSPS()->getMaxCUHeight()/(1<<uiDepth)  );
+      m_ppcCU[uiDepth]->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
+#if H_3D_NBDV_REF
+      if(pcCU->getSlice()->getSPS()->getUseDVPRefine())  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
+      else
+#endif
+        DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
+
+      pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
+      m_ppcCU[uiDepth]->setPartSizeSubParts( ePartTemp, 0, uiDepth );
+      m_ppcCU[uiDepth]->setWidth  ( 0, cWidTemp );
+      m_ppcCU[uiDepth]->setHeight ( 0, cHeightTemp );
+     }
+  }
+#endif
   if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
   {
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibDecoder/TDecGop.cpp	(revision 455)
@@ -152,4 +152,11 @@
     m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
   }
+#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.
+  {
+    Int iColPoc = pcSlice->getRefPOC(RefPicList(1-pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
+    rpcPic->setNumDdvCandPics(rpcPic->getDisCandRefPictures(iColPoc));
+  }
+#endif
   m_pcSbacDecoders[0].load(m_pcSbacDecoder);
   m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 455)
@@ -457,5 +457,32 @@
 
       rpcTempCU->initEstData( uiDepth, iQP );
-
+#if H_3D_NBDV
+      DisInfo DvInfo; 
+      DvInfo.bDV = false;
+      DvInfo.m_acNBDV.setZero();
+      DvInfo.m_aVIdxCan = 0;
+#if H_3D_NBDV_REF
+      DvInfo.m_acDoNBDV.setZero();
+#endif
+
+      if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
+      {
+        if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->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. Remove this comment once it is done.
+        {
+          PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
+          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
+#if H_3D_NBDV_REF
+          if(m_pcSlice->getSPS()->getUseDVPRefine())  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+            DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo, true);
+          else
+#endif 
+            DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo);
+
+          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
+          rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth );
+        }
+      }
+#endif
       // do inter modes, SKIP and 2Nx2N
       if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 453)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 455)
@@ -1028,5 +1028,11 @@
     m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr);
     startCUAddrSliceSegmentIdx++;
-
+#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.
+      {
+        Int iColPoc = pcSlice->getRefPOC(RefPicList(1-pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
+        pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc));
+      }
+#endif
     while(nextCUAddr<uiRealEndAddress) // determine slice boundaries
     {
