Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 518)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.cpp	(revision 519)
@@ -2189,4 +2189,5 @@
   setSubPart<Char>( iVSPFlag, m_piVSPFlag, uiAbsPartIdx, uiDepth, uiPartIdx );
 }
+
 #endif
 
@@ -2632,7 +2633,8 @@
  * \param uiCount: The next position to add merge candidate. Will be updated if VSP is successfully added
  * \param abCandIsInter: abCandIsInter[iCount] tells that VSP candidate is an Inter candidate, if VSP is successfully added
- * \param pcMvFieldNeighbours:   Return the "disparity vector". Type 1 MV. To be used to fetch a depth block. A "global" variable
- * \param puhInterDirNeighbours: Tells the VSP prediction direction. TODO: The value does NOT matter for VSP, as the direction will be determined based on availability later
- *                                Having it as output is mainly for coding beauty
+ * \param pcMvFieldNeighbours:   Return combined motion information, then stored to a global buffer
+ *                                    1) the "disparity vector". Type 1 MV. To be used to fetch a depth block.
+ *                                    2) the ref index /list.    Type 2 reference picture pointer, typically for texture
+ * \param puhInterDirNeighbours: Indicate the VSP prediction direction.
  * \param vspFlag: vspFlag[iCount] will be set (equal to 1), if VSP is successfully added. To be used to indicate the actual position of the VSP candidate
  *
@@ -2654,32 +2656,4 @@
     return false;
   
-  //////////
-  // Code if simply re-writing
-//  if(ucVspMergePos == H_3D_VSPPOSITION && picDepth != NULL && 0 != m_pcSlice->getViewIndex() ) // VSP can be used only when depth is used as input
-//  {
-//    abCandIsInter[iCount] = true;
-//    puhInterDirNeighbours[iCount] = 1;
-//    vspFlag[iCount] = 1;
-//    vspDirTrue[iCount] = 0; // TODO: Check if this is really useful!!!!
-//
-//    Int iRefIdxList0 = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC() == getSlice()->getPOC() ? 0 :
-//                      (getSlice()->getAlterRefIdx(REF_PIC_LIST_0) == -1 ? NOT_VALID : getSlice()->getAlterRefIdx(REF_PIC_LIST_0));
-//    pcMvFieldNeighbours[iCount<<1].setMvField( pDInfo->m_acDoNBDV, iRefIdxList0 );
-//    if (getSlice()->isInterB())
-//    {
-//      puhInterDirNeighbours[iCount] = xGetVspDirection(uiPUIdx);
-//      Int iRefIdxList1 = getSlice()->getRefPic(REF_PIC_LIST_1, 0)->getPOC() == getSlice()->getPOC() ? 0 :
-//                        (getSlice()->getAlterRefIdx(REF_PIC_LIST_1) == -1 ? NOT_VALID : getSlice()->getAlterRefIdx(REF_PIC_LIST_1));
-//      pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acDoNBDV, iRefIdxList1 );
-//    }
-//
-//    if ( mrgCandIdx == iCount )
-//      return true;
-//
-//    iCount++;
-//  }
-  /////////////
-  
-  
   Bool refViewAvailFlag = false;
   UChar predFlag[2] = {0, 0};
@@ -2711,5 +2685,5 @@
     {
       TComPic* refPic = m_pcSlice->getRefPic(eRefPicList, i);
-      if ( refPic->getPOC() == m_pcSlice->getPOC() ) // is inter-view reference
+      if ( refPic->getPOC() == m_pcSlice->getPOC() ) // inter-view reference
       {
         Int viewIdxRefInList = refPic->getViewIndex();
@@ -2736,4 +2710,5 @@
   return false;
 }
+
 #endif
 
@@ -4726,13 +4701,4 @@
             estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
 
-#if 0 // H_3D_VSP
-          Int refFrmIdx = 0;
-          RefPicList privateRefPicList = REF_PIC_LIST_0;
-          //getRefListAndRefFrmIdx(iTargetViewIdx, privateRefPicList, refFrmIdx);
-
-          //pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
-          //pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
-          assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
-#endif //H_3D_VSP
           pDInfo->m_acDoNBDV  = cColMv;
 #endif //H_3D_NBDV_REF
@@ -4844,15 +4810,4 @@
 #endif
           pDInfo->m_acDoNBDV = cDispVec;
-          
-#if 0 // H_3D_VSP
-          Int refFrmIdx = 0;
-          RefPicList privateRefPicList = REF_PIC_LIST_0 ;
-          getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
-
-          pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
-          pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
-          assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
-#endif //H_3D_VSP
-          
 #endif
           return true;
@@ -4875,15 +4830,6 @@
   }
   pDInfo->m_acDoNBDV = defaultDV;
-
-#if 0 // H_3D_VSP
-  Int refFrmIdx = 0;
-  RefPicList privateRefPicList = REF_PIC_LIST_0 ;
-  getRefListAndRefFrmIdx(0, privateRefPicList, refFrmIdx); // find the reference picture from base view
-
-  pDInfo->m_aListIdx[ pDInfo->iN ]  = privateRefPicList;
-  pDInfo->m_aRefIdx [ pDInfo->iN ]  = -1-refFrmIdx;
-  assert(pDInfo->m_aRefIdx [ pDInfo->iN ] < 0);
-#endif
-#endif
+#endif
+
   return false; 
 }
@@ -4968,10 +4914,4 @@
           if (picDepth && bDepthRefine)
             estimateDVFromDM(refViewIdx, uiPartIdx, picDepth, uiPartAddr, &cMvPred );
-
-#if 0 // H_3D_VSP
-          pNbDvInfo->m_aListIdx[ pNbDvInfo->iN ] = eRefPicList;
-          pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] = -1-refId;
-          assert(pNbDvInfo->m_aRefIdx [ pNbDvInfo->iN ] < 0);
-#endif
 
           pNbDvInfo->m_acDoNBDV = cMvPred;
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 518)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDataCU.h	(revision 519)
@@ -564,7 +564,7 @@
                                             , Int mrgCandIdx = -1 );
 #if H_3D_VSP
-  Char*         getVSPFlag        ()                        { return m_piVSPFlag;        }
-  Char          getVSPFlag        ( UInt uiIdx )            { return m_piVSPFlag[uiIdx]; }
-  Void          setVSPFlag        ( UInt uiIdx, Int n )     { m_piVSPFlag[uiIdx] = n;    }
+  Char*         getVSPFlag        ()                        { return m_piVSPFlag;          }
+  Char          getVSPFlag        ( UInt uiIdx )            { return m_piVSPFlag[uiIdx];   }
+  Void          setVSPFlag        ( UInt uiIdx, Int n )     { m_piVSPFlag[uiIdx] = n;      }
   Void          setVSPFlagSubParts( Char iVSPFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
 #endif
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp	(revision 518)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp	(revision 519)
@@ -437,7 +437,4 @@
   Int         iHeight;
   UInt        uiPartAddr;
-#if H_3D_VSP
-  UInt        uiAbsPartIdx = pcCU->getZorderIdxInCU();
-#endif
 
   if ( iPartIdx >= 0 )
@@ -479,7 +476,7 @@
     {
       if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
-        xPredInterUniVSP( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
+        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
       else
-        xPredInterBiVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, pcYuvPred );
+        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     }
 #endif
@@ -526,7 +523,7 @@
     {
       if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
-        xPredInterUniVSP( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
+        xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
       else
-        xPredInterBiVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, pcYuvPred );
+        xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     }
 #endif
@@ -573,6 +570,8 @@
 
 #if H_3D_VSP
-Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
-{
+Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
+{
+  UInt uiAbsPartIdx = pcCU->getZorderIdxInCU();
+
   // Step 1: get depth reference
   Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
@@ -592,12 +591,13 @@
   Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
   Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
+  assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() );
 
   // Step 4: Do compensation
-  TComMv cMv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cMv is the disparity vector derived from the neighbors
-  pcCU->clipMv(cMv);
+  TComMv cDv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); // cDv is the disparity vector derived from the neighbors
+  pcCU->clipMv(cDv);
   Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
   Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
-  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
-  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
+  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
+  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cDv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
 }
 #endif
@@ -748,5 +748,5 @@
 #if H_3D_VSP
 
-Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
+Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
 {
   TComYuv* pcMbYuv;
@@ -765,7 +765,7 @@
     pcMbYuv = &m_acYuvPred[iRefList];
     if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
-      xPredInterUniVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, true );
+      xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true );
     else
-      xPredInterUniVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv );
+      xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv );
   }
 
@@ -1390,8 +1390,8 @@
 // sizeX, sizeY: PU size
 // partAddr: z-order index
-// mv: disparity vector. derived from neighboring blocks
+// dv: disparity vector. derived from neighboring blocks
 //
 // Output: dstPic, PU predictor 64x64
-Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* mv, UInt partAddr,Int posX, Int posY
+Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY
                                             , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
 {
@@ -1426,6 +1426,6 @@
   Int dstStride = dstPic->getStride();
   Int depStride =  pPicBaseDepth->getStride();
-  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((mv->getHor()+2)>>2));
-  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((mv->getVer()+2)>>2));
+  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2));
+  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2));
   Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
   Pel *dst    = dstPic->getLumaAddr(partAddr);
@@ -1595,5 +1595,5 @@
 }
 
-Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*mv, UInt partAddr, Int posX, Int posY
+Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY
                                                , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
 {
@@ -1629,5 +1629,5 @@
     nTxtPerDepthX = widthChroma / widthDepth;
     nDepthPerTxtX = 1;
-    depthPosX = posX / nTxtPerDepthX + ((mv->getHor()+2)>>2);
+    depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2);
   }
   else
@@ -1635,5 +1635,5 @@
     nTxtPerDepthX = 1;
     nDepthPerTxtX = widthDepth / widthChroma;
-    depthPosX = posX * nDepthPerTxtX + ((mv->getHor()+2)>>2);
+    depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2);
   }
   depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
@@ -1642,5 +1642,5 @@
     nTxtPerDepthY = heightChroma / heightDepth;
     nDepthPerTxtY = 1;
-    depthPosY = posY / nTxtPerDepthY + ((mv->getVer()+2)>>2);
+    depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2);
   }
   else
@@ -1648,5 +1648,5 @@
     nTxtPerDepthY = 1;
     nDepthPerTxtY = heightDepth / heightChroma;
-    depthPosY = posY * nDepthPerTxtY + ((mv->getVer()+2)>>2);
+    depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2);
   }
   depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
Index: /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.h	(revision 518)
+++ /branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.h	(revision 519)
@@ -96,6 +96,6 @@
   Void xPredInterBi             ( TComDataCU* pcCU,                          UInt uiPartAddr,                    Int iWidth, Int iHeight,                         TComYuv*& rpcYuvPred );
 #if H_3D_VSP
-  Void xPredInterUniVSP         ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi=false          );
-  Void xPredInterBiVSP          ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight,                         TComYuv*& rpcYuvPred );
+  Void xPredInterUniVSP         ( TComDataCU* pcCU,                          UInt uiPartAddr,                    Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi=false          );
+  Void xPredInterBiVSP          ( TComDataCU* pcCU,                          UInt uiPartAddr,                    Int iWidth, Int iHeight,                         TComYuv*& rpcYuvPred );
 #endif
 
@@ -119,8 +119,8 @@
 
 #if H_3D_VSP
-  Void xPredInterLumaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* mv, UInt partAddr,Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
+  Void xPredInterLumaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
                                 , TComYuv *&dstPic
                                 , Bool bi );
-  Void xPredInterChromaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*mv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
+  Void xPredInterChromaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr, Int posX, Int posY, Int sizeX, Int sizeY, Bool isDepth
                                 , TComYuv *&dstPic
                                 , Bool bi );
