Index: /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 110)
@@ -335,4 +335,10 @@
   ("AllowNegDist",                    m_bAllowNegDist           , true          , "Allow negative Distortion in VSO")
 #endif
+#if LGE_WVSO_A0119
+  ("WVSO",                            m_bWVSO                   , true         , "Use WVSO" )
+  ("VSOWeight",                       m_iVSOWeight              , 10 					 , "VSO Weight" )
+  ("VSDWeight",                       m_iVSDWeight             , 1 					  , "SAIT Weight" )
+  ("DWeight",									        m_iDWeight						    , 1						 , "SSE Weight" )
+#endif
 
 #endif
@@ -644,4 +650,7 @@
 #endif
 
+#if LGE_WVSO_A0119
+  m_bWVSO = m_bUseVSO && m_bWVSO && m_bUsingDepthMaps;
+#endif
   xCleanUpVectors();
 
@@ -1688,5 +1697,8 @@
 #if HHI_VSO
   printf("VSO:%d ", m_bUseVSO             );
-#endif  
+#endif
+#if LGE_WVSO_A0119
+  printf("WVSO:%d ", m_bWVSO );
+#endif
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   printf("DMM:%d ", m_bUseDMM );
@@ -1694,4 +1706,7 @@
 #if HHI_MPI
   printf("MVI:%d ", m_bUseMVI ? 1 : 0 );
+#endif
+#if LGE_WVSO_A0119
+  printf("\nVSO : SAIT : SAD weight = %d : %d : %d ", m_iVSOWeight, m_iVSDWeight, m_iDWeight );
 #endif
   printf("\n\n");
Index: /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.h	(revision 109)
+++ /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncCfg.h	(revision 110)
@@ -297,5 +297,10 @@
   Bool      m_bUseEstimatedVSD;                           ///< Flag for using model based VSD estimation instead of VSO for some encoder decisions (JCT3V-A0033 modification 3)  
 #endif
-
+#if LGE_WVSO_A0119
+  Bool      m_bWVSO;                                    ///< flag for using View Synthesis Optimization  
+  Int				m_iVSOWeight;
+  Int       m_iVSDWeight;
+  Int				m_iDWeight;
+#endif
   // coding tools (depth intra modes)
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
Index: /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncTop.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/App/TAppEncoder/TAppEncTop.cpp	(revision 110)
@@ -207,4 +207,7 @@
     m_acTEncTopList[iViewIdx]->setUseEstimatedVSD              ( false );
 #endif
+#if LGE_WVSO_A0119
+    m_acTEncTopList[iViewIdx]->setWVSO												 ( false ); 
+#endif
 #endif
 
@@ -524,4 +527,7 @@
       m_acTEncDepthTopList[iViewIdx]->setUseEstimatedVSD              ( m_bUseEstimatedVSD );
 #endif
+#if LGE_WVSO_A0119
+      m_acTEncDepthTopList[iViewIdx]->setWVSO                          ( m_bWVSO      );
+#endif
 #endif
 
@@ -690,4 +696,17 @@
       AOT(true);
     }
+#if LGE_WVSO_A0119 
+    for ( Int iViewNum = 0; iViewNum < m_iNumberOfViews; iViewNum++ )
+    {
+      for (Int iContent = 0; iContent < 2; iContent++ )
+      {
+        TEncTop* pcEncTop = ( iContent == 0 ) ? m_acTEncTopList[iViewNum] : m_acTEncDepthTopList[iViewNum]; 
+        pcEncTop->setWVSO( m_bWVSO );
+        pcEncTop->setVSOWeight( m_iVSOWeight );
+        pcEncTop->setVSDWeight( m_iVSDWeight );
+        pcEncTop->setDWeight( m_iDWeight );
+      }
+    }
+#endif
   }
 #endif
Index: /branches/HTM-4.0-LG/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibCommon/TComRdCost.h	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibCommon/TComRdCost.h	(revision 110)
@@ -377,4 +377,10 @@
   Bool                    m_bUseEstimatedVSD; 
 #endif
+#if LGE_WVSO_A0119
+  Int											m_iDWeight;
+  Int											m_iVSOWeight;
+  Int                     m_iVSDWeight;
+  Bool                    m_bWVSO;
+#endif
 
   Bool                    m_bUseVSO;
@@ -410,5 +416,14 @@
   Void    setVSOMode( UInt uiIn);
   UInt    getVSOMode( )                  { return m_uiVSOMode; }
-
+#if LGE_WVSO_A0119
+  Void    setWVSO ( Bool bIn )         { m_bWVSO = bIn; }; 
+  Bool    getWVSO ( )                  { return m_bWVSO;};
+  Void		setDWeight ( Int iDWeight )			{ m_iDWeight = iDWeight; };
+  Int			getDWeight ()										{ return m_iDWeight; };
+  Void		setVSOWeight ( Int iVSOWeight ) { m_iVSOWeight = iVSOWeight; };
+  Int			getVSOWeight ()									{ return m_iVSOWeight; };
+  Void		setVSDWeight ( Int iVSDWeight ) { m_iVSDWeight = iVSDWeight; };
+  Int			getVSDWeight ()									{ return m_iVSDWeight; };
+#endif 
 #if HHI_VSO_DIST_INT
   Void    setAllowNegDist ( Bool bAllowNegDist );
Index: /branches/HTM-4.0-LG/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibCommon/TypeDef.h	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibCommon/TypeDef.h	(revision 110)
@@ -94,5 +94,5 @@
 #define SAIT_VSO_EST_A0033                1 // JCT2-A0033 modification 3
 #define LGE_VSO_EARLY_SKIP_A0093          1 // JCT2-A0093 modification 4
-
+#define LGE_WVSO_A0119                    1 // JCT2-A0119 Depth Metric with a weighted depth fidelity term
 
 #define HHI_INTERVIEW_SKIP                1
Index: /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncCfg.h	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncCfg.h	(revision 110)
@@ -204,4 +204,10 @@
   Double    m_dLambdaScaleVSO;
   UInt      m_uiVSOMode;
+#if LGE_WVSO_A0119
+  Bool      m_bWVSO;
+  Int				m_iVSOWeight;
+  Int       m_iVSDWeight;
+  Int				m_iDWeight;
+#endif
 #endif
 #if SAIT_VSO_EST_A0033
@@ -466,4 +472,10 @@
   Void      setAllowNegDist                 ( Bool b  )     { m_bAllowNegDist     = b; };
 #endif
+#if LGE_WVSO_A0119
+  Void      setWVSO													( Bool  b )     { m_bWVSO				= b; }
+  Void      setVSOWeight										( Int   i )     { m_iVSOWeight  = i; }
+  Void      setVSDWeight										( Int   i )     { m_iVSDWeight  = i; }
+  Void      setDWeight											( Int   i )     { m_iDWeight  = i; }
+#endif
 #endif
 
@@ -545,4 +557,10 @@
 #if HHI_VSO_DIST_INT
   Bool      getAllowNegDist                 ()      { return m_bAllowNegDist;     }
+#endif
+#if LGE_WVSO_A0119
+  Bool      getWVSO                         ()      { return m_bWVSO;     }
+  Int       getVSOWeight                    ()      { return m_iVSOWeight;    }
+  Int       getVSDWeight                    ()      { return m_iVSDWeight;    }
+  Int       getDWeight									    ()      { return m_iDWeight;    }
 #endif
 #endif
Index: /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 110)
@@ -464,5 +464,8 @@
     m_pcRdCost->setDepthPicYuv   ( m_pcEncTop->getEncTop()->getPicYuvFromView( pcSlice->getViewId(), pcSlice->getPOC(), true, false ) );
 #endif
-
+#if LGE_WVSO_A0119
+    Bool bWVSO  = m_pcEncTop->getWVSO();
+    m_pcRdCost->setWVSO( bWVSO );
+#endif
 
   }
Index: /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 110)
@@ -1129,5 +1129,14 @@
   if ( m_pcRdCost->getUseVSO() )
   {
+#if LGE_WVSO_A0119
+    Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+    Int iVSOWeight = m_pcRdCost->getVSOWeight() * m_pcRdCost->getVSOWeight();
+    Dist iD = (Dist) m_pcRdCost->getDistPart( piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
+    Dist iVSO = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
+    ruiDist += (iDWeight * iD + iVSOWeight * iVSO) / ( iDWeight + iVSOWeight);
+
+#else
     ruiDist += m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
+#endif
   }
   else
@@ -1902,4 +1911,10 @@
 
             uiSad = (Dist) ( m_pcRdCost->getDistPart( piPred, uiStride, piOrg, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiPartOffset), pcVirRec->getStride(), uiWidth, uiHeight ) );
+#if LGE_WVSO_A0119
+            Int iDWeight = m_pcRdCost->getDWeight();
+            Int iVSDWeight = m_pcRdCost->getVSDWeight();
+            Dist iD = (Dist) m_pcRdCost->calcHAD( piOrg, uiStride, piPred, uiStride, uiWidth, uiHeight );
+            uiSad = (Dist) (iDWeight * iD + iVSDWeight * uiSad) / (iDWeight + iVSDWeight);
+#endif
           }
           else
@@ -4391,4 +4406,10 @@
     {
       uiDistortion = m_pcRdCost->getDistVS( pcCU, 0, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight     , false, 0 );
+#if LGE_WVSO_A0119
+      Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+      Int iVSOWeight = m_pcRdCost->getVSOWeight() * m_pcRdCost->getVSOWeight();
+      Dist iD   = (Dist) m_pcRdCost->getDistPart( rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      );
+      uiDistortion = (iDWeight * iD + iVSOWeight * (Dist)uiDistortion) / ( iDWeight + iVSOWeight);
+#endif
     }
     else    
@@ -4750,4 +4771,10 @@
   {
     uiDistortionBest = m_pcRdCost->getDistVS  ( pcCU, 0, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight, false, 0    );
+#if LGE_WVSO_A0119
+    Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+    Int iVSOWeight = m_pcRdCost->getVSOWeight() * m_pcRdCost->getVSOWeight();
+    Dist iD        = (Dist) m_pcRdCost->getDistPart( rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      );
+    uiDistortionBest = (iDWeight * iD + iVSOWeight * (Dist) uiDistortionBest) / ( iDWeight + iVSOWeight);
+#endif
   }
   else
@@ -4985,4 +5012,10 @@
         TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
         uiDistY = m_pcRdCost->getDistPart( m_pTempPel, 1<< uiLog2TrSize, pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPartIdx), pcVirRec->getStride(), 1<< uiLog2TrSize, 1<< uiLog2TrSize );
+#if LGE_WVSO_A0119
+        Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+        Int iVSDWeight = m_pcRdCost->getVSDWeight() * m_pcRdCost->getVSDWeight();
+        Dist iD   = (Dist) m_pcRdCost->getDistPart( m_pTempPel, trWidth, pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth, trHeight );
+        uiDistY = (iDWeight * iD + iVSDWeight * (Dist)uiDistY) / ( iDWeight + iVSDWeight);
+#endif
       }
       else
@@ -5035,4 +5068,10 @@
           TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
           uiNonzeroDistY = m_pcRdCost->getDistPart( m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( uiAbsPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcResi->getLumaAddr( uiAbsPartIdx ), pcResi->getStride(), pcVirRec->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirOrg->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiAbsPartIdx ), pcVirRec->getStride(), 1<< uiLog2TrSize,    1<< uiLog2TrSize );
+#if LGE_WVSO_A0119
+          Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+          Int iVSDWeight = m_pcRdCost->getVSDWeight() * m_pcRdCost->getVSDWeight();
+          Dist iD = (Dist) m_pcRdCost->getDistPart( m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight );
+          uiNonzeroDistY = (iDWeight * iD + iVSDWeight * (Dist) uiNonzeroDistY) / ( iDWeight + iVSDWeight);
+#endif
         }
         else
@@ -6119,4 +6158,10 @@
           TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
           uiActDist = m_pcRdCost->getDistPart( piPredic, uiStride, piOrig, uiStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
+#if LGE_WVSO_A0119
+          Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+          Int iVSDWeight = m_pcRdCost->getVSDWeight() * m_pcRdCost->getVSDWeight();
+          Dist iD = (Dist) m_pcRdCost->getDistPart( piPredic, uiStride, piOrig, uiStride, uiWidth, uiHeight, false, DF_SAD );
+          uiActDist = (iDWeight * iD + iVSDWeight * (Dist) uiActDist) / ( iDWeight + iVSDWeight);
+#endif
         }
         else       
@@ -6232,4 +6277,10 @@
         TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
         uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()), pcVirRec->getStride(), uiWidth, uiHeight );
+#if LGE_WVSO_A0119
+        Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+        Int iVSDWeight = m_pcRdCost->getVSDWeight() * m_pcRdCost->getVSDWeight();
+        Dist iD = (Dist) m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, DF_SAD );
+        uiActDist = (iDWeight * iD + iVSDWeight * (Int) uiActDist) / ( iDWeight + iVSDWeight);
+#endif
       }
       else
@@ -6298,4 +6349,10 @@
         TComPicYuv* pcVirOrg = m_pcRdCost->getDepthPicYuv();
         uiActDist = m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, pcVirRec->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirOrg->getLumaAddr(pcCU->getAddr(),pcCU->getZorderIdxInCU()+uiAbsPtIdx), pcVirRec->getStride(), uiWidth, uiHeight );
+#if LGE_WVSO_A0119
+        Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
+        Int iVSDWeight = m_pcRdCost->getVSDWeight() * m_pcRdCost->getVSDWeight();
+        Dist iD = (Dist) m_pcRdCost->getDistPart( piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false, DF_SAD );
+        uiActDist = (iDWeight * iD + iVSDWeight * (Int) uiActDist) / ( iDWeight + iVSDWeight);
+#endif
       }
       else
Index: /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 110)
@@ -376,5 +376,23 @@
   m_pcRdCost->setDisparityCoeff( m_pcCfg->getDispCoeff() );
 #endif
-
+#if LGE_WVSO_A0119
+  if( m_pcCfg->getWVSO() && m_pcCfg->isDepthCoder() )
+  {
+
+    Int iDWeight, iVSOWeight, iVSDWeight;
+    iDWeight = m_pcCfg->getDWeight();
+    iVSOWeight = m_pcCfg->getVSOWeight();
+    iVSDWeight = m_pcCfg->getVSDWeight();
+    //    if( rpcSlice->getViewId() )  iDWeight = ( iDWeight >> 1 );
+    //    if( rpcSlice->getPOC() % 8 != 0 )  iDWeight = ( iDWeight >> 1 );
+    //    if( rpcSlice->getPOC() % 4 != 0 )  iDWeight = ( iDWeight >> 1 );
+    //    if( rpcSlice->getPOC() % 2 != 0 )  iDWeight = ( iDWeight >> 1 );
+
+    m_pcRdCost->setDWeight( iDWeight );
+    m_pcRdCost->setVSOWeight( iVSOWeight );
+    m_pcRdCost->setVSDWeight( iVSDWeight );
+
+  }
+#endif
 #if RDOQ_CHROMA_LAMBDA 
 // for RDOQ
Index: /branches/HTM-4.0-LG/source/Lib/TLibRenderer/TRenModel.cpp
===================================================================
--- /branches/HTM-4.0-LG/source/Lib/TLibRenderer/TRenModel.cpp	(revision 109)
+++ /branches/HTM-4.0-LG/source/Lib/TLibRenderer/TRenModel.cpp	(revision 110)
