Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 637)
@@ -2179,5 +2179,5 @@
     xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
 
-#if !(KWU_RC_MADPRED_E0227 || KWU_RC_VIEWRC_E0227)
+#if !KWU_FIX_URQ
     m_iMaxDeltaQP       = MAX_DELTA_QP;
 #endif
Index: branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 637)
@@ -512,5 +512,5 @@
   m_cTEncTop.setSignHideFlag(m_signHideFlag);
 #if RATE_CONTROL_LAMBDA_DOMAIN
-#if KWU_RC_MADPRED_E0227
+#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
   if(!m_cTEncTop.getIsDepth())    //only for texture
   {
@@ -522,5 +522,5 @@
   }
 #else
-  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
+    m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
 #endif
 #if !KWU_RC_VIEWRC_E0227
@@ -603,11 +603,9 @@
 #endif
 #else
-#if KWU_RC_MADPRED_E0227
+#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
   if(!m_cTEncTop.getIsDepth())    //only for texture
   {
     m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
-#if !KWU_RC_VIEWRC_E0227
     m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
-#endif
     m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
   }
@@ -617,8 +615,9 @@
   }
 #else
-  m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
-  m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
-  m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
-#endif
+  m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
+  m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
+  m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
+#endif
+
   
 #if KWU_RC_MADPRED_E0227
@@ -962,5 +961,5 @@
     }
 
-#if !RATE_CONTROL_LAMBDA_DOMAIN
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
     for(Int layer=0; layer < m_numberOfLayers; layer++ )
     {
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 637)
@@ -1526,63 +1526,2 @@
 }
 #endif
-
-
-#if KWU_RC_MADPRED_E0227
-Void
-  TAppComCamPara::getZNearZFar( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar )
-{
-  UInt uiFoundLine = -1;
-  if( !xGetCameraDataRow( m_aiBaseViews[iView], uiFrame, uiFoundLine ) || !( m_aadCameraParameters[ uiFoundLine ].size() < 8 ) )
-  {
-    rdZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ];
-    rdZFar  = m_aadCameraParameters[ uiFoundLine ][ 7 ];
-  }
-  else
-  {
-    std::cerr << "No ZNear or no ZFar for View " << (Double)iView / m_dViewNumPrec << " and Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
-    exit( EXIT_FAILURE );
-  }
-}
-
-
-Void
-  TAppComCamPara::getGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated )
-{
-  UInt uiFoundLine = -1;
-  if ( !xGetCameraDataRow( m_aiBaseViews[iView], uiFrame, uiFoundLine ) )
-  {
-    AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 );
-    rbInterpolated = false;
-    rdFocalLength =  m_aadCameraParameters[ uiFoundLine ][ 3 ];
-    rdPosition    =  m_aadCameraParameters[ uiFoundLine ][ 4 ];
-    rdCameraShift =  m_aadCameraParameters[ uiFoundLine ][ 5 ];
-  }
-  else
-  {
-    UInt uiLeftViewLine;
-    UInt uiRightViewLine;
-    Int  iLeftView;
-    Int  iRightView;
-    Int  iDummy;
-
-    if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) ||
-      xGetCameraDataRow( iLeftView,  uiFrame, uiLeftViewLine  )                             ||
-      xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine )
-      )
-    {
-      std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
-      AOT(true);
-      exit( EXIT_FAILURE );
-    }
-    AOT( m_aadCameraParameters[ uiLeftViewLine  ].size() < 6 );
-    AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 );
-
-    // Linear Interpolation
-    Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) );
-    rdFocalLength  = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] );
-    rdPosition     = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] );
-    rdCameraShift  = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] );
-    rbInterpolated = true;
-  }
-}
-#endif
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TAppCommon/TAppComCamPara.h	(revision 637)
@@ -125,6 +125,8 @@
   Bool  xGetLeftRightView         ( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx );
   Void  xGetPrevAndNextBaseView   ( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum );
+#if !KWU_RC_MADPRED_E0227
   Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
   Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+#endif
   Void  xSetupBaseViewsFromCoded  ();
   Void  xSetupBaseViews           ( Char* pchBaseViewNumbers, UInt uiNumBaseViews );
@@ -222,6 +224,6 @@
 
 #if KWU_RC_MADPRED_E0227
-  Void  getZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
-  Void  getGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+  Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
+  Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
 #endif
 };
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 637)
@@ -305,9 +305,11 @@
 #define M0036_RC_IMPROVEMENT                        1  ///< JCTVC-M0036, improvement for R-lambda model based rate control
 #define TICKET_1090_FIX                             1
-
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#define KWU_FIX_URQ                                 1
+
+#if KWU_FIX_URQ && RATE_CONTROL_LAMBDA_DOMAIN
 #define RC_FIX                                      1  /// suggested fix for M0036
 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra 
 #endif
+
 #define KWU_RC_VIEWRC_E0227                         1  ///< JCT3V-E0227, view-wise target bitrate allocation
 #define KWU_RC_MADPRED_E0227                        1  ///< JCT3V-E0227, inter-view MAD prediction
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 637)
@@ -103,5 +103,5 @@
   
   m_bEncodeDQP = false;
-#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+#if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
   m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
@@ -242,17 +242,5 @@
   
   m_bUseSBACRD        = pcEncTop->getUseSBACRD();
-
-#if KWU_RC_MADPRED_E0227
-  if(!pcEncTop->getIsDepth())
-  {
-    m_pcRateCtrl        = pcEncTop->getRateCtrl();
-  }
-  else
-  {
-    m_pcRateCtrl = NULL;
-  }
-#else
   m_pcRateCtrl        = pcEncTop->getRateCtrl();
-#endif
 }
 
@@ -478,5 +466,5 @@
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth() )
+  if ( m_pcEncCfg->getUseRateCtrl() )
   {
     iMinQP = m_pcRateCtrl->getRCQP();
@@ -484,5 +472,5 @@
   }
 #else
-  if(m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth())
+  if(m_pcEncCfg->getUseRateCtrl())
   {
     Int qp = m_pcRateCtrl->getUnitQP();
@@ -692,5 +680,5 @@
     }
 #endif
-#if !RATE_CONTROL_LAMBDA_DOMAIN
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
     if(m_pcEncCfg->getUseRateCtrl())
     {
@@ -1175,5 +1163,5 @@
   }
 #if RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth() )
+  if ( m_pcEncCfg->getUseRateCtrl() )
   {
     iMinQP = m_pcRateCtrl->getRCQP();
@@ -1181,5 +1169,5 @@
   }
 #else
-  if(m_pcEncCfg->getUseRateCtrl() && !m_pcEncCfg->getIsDepth())
+  if(m_pcEncCfg->getUseRateCtrl())
   {
     Int qp = m_pcRateCtrl->getUnitQP();
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 637)
@@ -154,5 +154,5 @@
 #endif
 
-#if !RATE_CONTROL_LAMBDA_DOMAIN
+#if KWU_FIX_URQ
   m_pcRateCtrl           = pcTEncTop->getRateCtrl();
 #endif
@@ -2216,5 +2216,10 @@
       delete[] pcSubstreamsOut;
   }
-
+#if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN
+  if(m_pcCfg->getUseRateCtrl())
+  {
+    m_pcRateCtrl->updateRCGOPStatus();
+  }
+#endif
   delete pcBitstreamRedirect;
 
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 637)
@@ -644,5 +644,5 @@
 
 #if KWU_RC_MADPRED_E0227
-Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int LayerID )
+Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID )
 #else
 Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures )
@@ -717,5 +717,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  m_LayerID = LayerID;
+  m_LayerID = layerID;
   m_lastIVPicture = NULL;
   m_IVtotalMAD            = 0.0;
@@ -1074,5 +1074,5 @@
 
 #if KWU_RC_MADPRED_E0227
-Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction, Int* iDisparity )
+Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
 {
   Int   LCUIdx    = getLCUCoded();
@@ -1098,6 +1098,6 @@
     Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
 
-    Int   iWidth  = m_LCUs[ LCUIdx ].m_CUWidth;
-    Int   iHeight = m_LCUs[ LCUIdx ].m_CUHeight;
+    Int   width  = m_LCUs[ LCUIdx ].m_CUWidth;
+    Int   height = m_LCUs[ LCUIdx ].m_CUHeight;
 
     for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
@@ -1112,30 +1112,28 @@
     Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
 
-    //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
-
-    Double dFL = FocalLen * abs( BasePos - CurPos );
-    Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
-    *iDisparity = (Int)(Direction*dFL * dZ);
+    Double fL = focalLen * abs( basePos - curPos );
+    Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
+    *disparity = (Int)(direction*fL * z);
     Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
 
-    Int Disp = *iDisparity;
-    Int PosX, PosY;
-    pcCU->getPosInPic(0, PosX, PosY);
-    if((PosX + *iDisparity) < 0 || (PosX + *iDisparity + iWidth) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
-    {
-      Disp = 0;
-    }
-
-    for( y = 0; y < iHeight; y++ )
-    {
-      for( x = 0; x < iWidth; x++ )
-      {
-        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
-                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
+    Int disp = *disparity;
+    Int posX, posY;
+    pcCU->getPosInPic(0, posX, posY);
+    if((posX + *disparity) < 0 || (posX + *disparity + width) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
+    {
+      disp = 0;
+    }
+
+    for( y = 0; y < height; y++ )
+    {
+      for( x = 0; x < width; x++ )
+      {
+        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
+                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
       }
       pOrg += iStride;
       pRec += iStride;
     }
-    IVMAD = SAD / (Double)(iHeight * iWidth);
+    IVMAD = SAD / (Double)(height * width);
     IVMAD = IVMAD * IVMAD;
 
@@ -1440,5 +1438,7 @@
   m_picLambda           = averageLambda;
 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
+#if KWU_RC_MADPRED_E0227
   m_totalMAD = 0;
+#endif
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
@@ -1649,5 +1649,5 @@
 #if M0036_RC_IMPROVEMENT
 #if KWU_RC_MADPRED_E0227
-Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int LayerID )
+Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int layerID )
 #else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
@@ -1867,5 +1867,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  setLayerID(LayerID);
+  setLayerID(layerID);
 #endif
 
@@ -2082,11 +2082,8 @@
   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0);  
   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
-#if KWU_RC_MADPRED_E0227
-  m_prevBitrate              = ( targetKbps * 1000 );  // in units of 1,024 bps
-  m_currBitrate              = ( targetKbps * 1000 );
-#else
+
   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
   m_currBitrate              = ( targetKbps << 10 );
-#endif
+
   m_frameRate                = frameRate;
   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
@@ -2486,5 +2483,5 @@
 
 #if KWU_RC_MADPRED_E0227
-Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int iQP, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction)
+Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)
 {
   Int     x, y;
@@ -2498,6 +2495,6 @@
   Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
 
-  Int   iWidth  = m_pcLCUData[m_indexLCU].m_widthInPixel;
-  Int   iHeight = m_pcLCUData[m_indexLCU].m_heightInPixel;
+  Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
+  Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
 
   for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
@@ -2511,25 +2508,22 @@
 
   Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
-
-  //Int iDisparity = pDepthGen->RCGetDisparityFromVirtDepth(0, (Int)AvgDepth);
-
-  Double dFL = FocalLen * abs( BasePos - CurPos );
-  Double dZ  = abs( 1.0 / Znear - 1.0 / Zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / Zfar);
-  Int   iDisparity = (Int)(Direction*dFL * dZ);
+  Double fL = focalLen * abs( basePos - curPos );
+  Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
+  Int   disparity = (Int)(direction*fL * z);
   Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
-  Int Disp = iDisparity;
-
-  for( y = 0; y < iHeight; y++ )
-  {
-    for( x = 0; x < iWidth; x++ )
-    {
-      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)]
-      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + Disp)] )>>shift;
+  Int disp = disparity;
+
+  for( y = 0; y < height; y++ )
+  {
+    for( x = 0; x < width; x++ )
+    {
+      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
+      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
     }
     pOrg += iStride;
     pRec += iStride;
   }
-  m_pcLCUData[m_indexLCU].m_qp   = iQP;
-  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(iWidth*iHeight));
+  m_pcLCUData[m_indexLCU].m_qp   = qp;
+  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(width*height));
   m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
 }
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 637)
@@ -257,5 +257,5 @@
 public:
 #if KWU_RC_MADPRED_E0227
-  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int LayerID );
+  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID );
 #else
   Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures );
@@ -264,5 +264,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC );
+  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC );
 #endif
 #if !RATE_CONTROL_INTRA
@@ -284,5 +284,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction, Int* iDisparity );
+  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity );
 #endif
 
@@ -305,5 +305,5 @@
 #if KWU_RC_MADPRED_E0227
   Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures );
-  Void setIVPic( TEncRCPic* BaseRCPic );
+  Void setIVPic( TEncRCPic* baseRCPic );
 #endif
 
@@ -419,5 +419,5 @@
 #if M0036_RC_IMPROVEMENT
 #if KWU_RC_MADPRED_E0227
-  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int LayerID );
+  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID );
 #else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
@@ -579,5 +579,5 @@
   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
 #if KWU_RC_MADPRED_E0227
-  Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int iQP, Double BasePos, Double CurPos, Double FocalLen, Double Znear, Double Zfar, Int Direction);
+  Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction);
 #endif
   Void          updateFrameData       (UInt64 actualFrameBits);
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 637)
@@ -332,5 +332,5 @@
   }
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-  if ( m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
+  if ( m_pcCfg->getUseRateCtrl())
   {
     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
@@ -1134,19 +1134,19 @@
 #endif
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-    if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
+    if(m_pcCfg->getUseRateCtrl())
     {
 #if KWU_RC_MADPRED_E0227
       if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
       {
-        double Zn, Zf, FocalLength, Position, CamShift;
-        double BasePos;
+        double zn, zf, focallength, position, camshift;
+        double basepos;
         bool bInterpolated;
-        Int Direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
-
-        pcEncTop->getCamParam()->getZNearZFar(pcSlice->getViewId(), pcSlice->getPOC(), Zn, Zf);
-        pcEncTop->getCamParam()->getGeometryData(0, pcSlice->getPOC(), FocalLength, BasePos, CamShift, bInterpolated);
-        pcEncTop->getCamParam()->getGeometryData(pcSlice->getViewId(), pcSlice->getPOC(), FocalLength, Position, CamShift, bInterpolated);
-
-        m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), BasePos, Position, FocalLength, Zn, Zf, (Direction > 0 ? 1 : -1));
+        Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+
+        pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
+        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);
+        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);
+
+        m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));
       }
 #endif
@@ -1252,15 +1252,15 @@
           if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
           {
-            double Zn, Zf, FocalLength, Position, CamShift;
-            double BasePos;
+            double zn, zf, focallength, position, camShift;
+            double basePos;
             bool bInterpolated;
-            Int Direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
-            Int iDisparity;
-
-            pcEncTop->getCamParam()->getZNearZFar(pcSlice->getViewId(), pcSlice->getPOC(), Zn, Zf);
-            pcEncTop->getCamParam()->getGeometryData(0, pcSlice->getPOC(), FocalLength, BasePos, CamShift, bInterpolated);
-            pcEncTop->getCamParam()->getGeometryData(pcSlice->getViewId(), pcSlice->getPOC(), FocalLength, Position, CamShift, bInterpolated);
+            Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
+            Int disparity;
+
+            pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
+            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basePos, camShift, bInterpolated);
+            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camShift, bInterpolated);
             bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBppforInterView( m_pcRateCtrl->getPicList(), pcCU,
-                            BasePos, Position, FocalLength, Zn, Zf, (Direction > 0 ? 1 : -1), &iDisparity );
+              basePos, position, focallength, zn, zf, (direction > 0 ? 1 : -1), &disparity );
           }
           else
@@ -1391,5 +1391,5 @@
 #if TICKET_1090_FIX
 #if RATE_CONTROL_LAMBDA_DOMAIN
-      if ( m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth() )
+      if ( m_pcCfg->getUseRateCtrl() )
       {
 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
@@ -1456,5 +1456,5 @@
     m_uiPicDist      += pcCU->getTotalDistortion();
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-    if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
+    if(m_pcCfg->getUseRateCtrl())
     {
       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
@@ -1477,5 +1477,5 @@
   xRestoreWPparam( pcSlice );
 #if !RATE_CONTROL_LAMBDA_DOMAIN
-  if(m_pcCfg->getUseRateCtrl() && !m_pcCfg->getIsDepth())
+  if(m_pcCfg->getUseRateCtrl())
   {
     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
Index: branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp	(revision 636)
+++ branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp	(revision 637)
@@ -132,5 +132,7 @@
   }
 #else
+#if KWU_FIX_URQ
   if(m_enableRateCtrl)
+#endif
     m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
 #endif
@@ -230,4 +232,5 @@
   }
   m_cLoopFilter.        destroy();
+  m_cRateCtrl.          destroy();
   // SBAC RD
   if( m_bUseSBACRD )
@@ -750,6 +753,7 @@
     m_cPPS.setMaxCuDQPDepth( 0 );
     m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
-  } 
-#else
+  }
+#endif 
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
   if ( m_enableRateCtrl )
   {
