source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComDepthMapGenerator.cpp @ 478

Last change on this file since 478 was 478, checked in by tech, 11 years ago

Minor clean ups.

File size: 10.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2011, ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36/** \file     TComDepthMapGenerator.cpp
37    \brief    depth map generator class
38*/
39
40
41
42#include "CommonDef.h"
43#include "TComDepthMapGenerator.h"
44
45#if H_3D_IV_MERGE
46
47TComDepthMapGenerator::TComDepthMapGenerator()
48{
49  m_bCreated            = false;
50  m_bInit               = false;
51  m_bDecoder            = false;
52  m_pcPrediction        = 0;
53  m_pcSPSAccess         = 0;
54  m_pcAUPicAccess       = 0;
55
56  m_uiSubSampExpX       = 0;
57  m_uiSubSampExpY       = 0;
58}
59
60TComDepthMapGenerator::~TComDepthMapGenerator()
61{
62  destroy ();
63  uninit  ();
64}
65
66Void
67TComDepthMapGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY )
68{
69  destroy();
70  m_bDecoder            = bDecoder;
71
72  m_uiSubSampExpX       = uiSubSampExpX;
73  m_uiSubSampExpY       = uiSubSampExpY;
74  m_bCreated    = true;
75}
76
77Void
78TComDepthMapGenerator::destroy()
79{
80  if( m_bCreated )
81  {
82    m_bCreated    = false;
83
84    m_uiSubSampExpX       = 0;
85    m_uiSubSampExpY       = 0;
86    m_bDecoder            = false;
87  }
88}
89
90
91Void
92TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
93{
94  AOF( pcPrediction  );
95  AOF( pcSPSAccess   );
96  AOF( pcAUPicAccess );
97  uninit();
98  m_pcPrediction  = pcPrediction;
99  m_pcVPSAccess   = pcVPSAccess;
100  m_pcSPSAccess   = pcSPSAccess;
101  m_pcAUPicAccess = pcAUPicAccess;
102  m_bInit         = true;
103}
104
105Void
106TComDepthMapGenerator::uninit()
107{
108  if( m_bInit )
109  {
110    m_bInit         = false;
111    m_pcPrediction  = 0;
112    m_pcSPSAccess   = 0;
113    m_pcAUPicAccess = 0;
114  }
115}
116
117Void 
118TComDepthMapGenerator::initViewComponent( TComPic* pcPic )
119{
120  AOF  ( m_bCreated && m_bInit );
121  AOF  ( pcPic );
122  AOT  ( pcPic->getSPS()->getViewIndex() && !pcPic->getSPS()->isDepth() && pcPic->getPOC() && pcPic->getSPS()->getPredDepthMapGeneration() != m_pcSPSAccess->getPdm() );
123  m_bPDMAvailable = false;
124  m_uiCurrViewIndex  = pcPic->getSPS()->getViewIndex();
125
126  // update SPS list and AU pic list and set depth map generator in SPS
127  m_pcVPSAccess  ->addVPS( pcPic->getVPS() );
128  m_pcSPSAccess  ->addSPS( pcPic->getSPS() );
129  m_pcAUPicAccess->addPic( pcPic );
130  pcPic->getSPS()->setDepthMapGenerator( this );
131
132  // check whether we have depth data or don't use pred depth prediction
133  ROFVS( pcPic->getSPS()->getViewIndex() );
134  ROTVS( pcPic->getSPS()->isDepth  () );
135  ROFVS( m_pcSPSAccess->getPdm     () ); 
136}
137
138Bool
139TComDepthMapGenerator::getPdmCandidate(TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
140{
141  AOF  ( m_bCreated && m_bInit );
142  TComSlice*    pcSlice     = pcCU->getSlice ();
143  TComSPS*      pcSPS       = pcSlice->getSPS();
144  AOF  ( pcSPS->getViewIndex() == m_uiCurrViewIndex );
145
146  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
147  UInt          uiRefViewId = pcRefPic->getSPS()->getViewIndex();
148  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewIndex );
149  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
150  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
151  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
152  if(!bMerge)
153  {
154    ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
155    ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
156    ROTRS(                  bMerge   && !bPdmMerge, false );
157  }
158  else
159    ROTRS( !bPdmMerge, 0 );
160
161
162  Bool abPdmAvailable[4] = {false, false, false, false};
163
164  Int iValid = 0;
165  Int iViewIndex = 0;
166  for( UInt uiBIndex = 0; uiBIndex < m_uiCurrViewIndex && iValid==0; uiBIndex++ )
167  {
168
169    UInt        uiBaseIndex    = uiBIndex;
170    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseIndex );
171    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
172    {
173      RefPicList  eRefPicListTest = RefPicList( iRefListId );
174      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
175      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
176      { 
177        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
178          && pcBasePic->getViewIndex() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewIndex())
179        {
180          iValid=1;
181          iViewIndex = uiBaseIndex;
182          break;
183        }
184      }
185    }
186  }
187  if (iValid == 0)
188    return false;
189
190  //--- get base CU/PU and check prediction mode ---
191  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewIndex );
192  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
193  if(bMerge || !bInterview)
194  {
195    Int  iCurrPosX, iCurrPosY;
196    UInt          uiPartAddr;
197    Int           iWidth;
198    Int           iHeight;
199
200    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
201    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
202    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
203    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
204
205    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acNBDV.getHor() + 2 ) >> 2 ) );
206    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acNBDV.getVer() + 2 ) >> 2 )); 
207    Int         iBaseCUAddr;
208    Int         iBaseAbsPartIdx;
209    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
210
211    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
212    if(!( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTRA ))
213    {
214      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
215      {
216        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
217        if(!bMerge && eCurrRefPicList != eRefPicList)
218          continue;
219        Bool bLoop_stop = false;
220        for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
221        {
222          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
223          TComMvField cBaseMvField;
224          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
225          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
226          if (iBaseRefIdx >= 0)
227          {
228            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
229            if (iBaseRefPOC != pcSlice->getPOC())   
230            {
231              for (Int iPdmRefIdx = (bMerge?0: iRefIdx); iPdmRefIdx < (bMerge? pcSlice->getNumRefIdx( eCurrRefPicList ): (iRefIdx+1)); iPdmRefIdx++)
232              {
233                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
234                {
235                  abPdmAvailable[ uiCurrRefListId ] = true;
236                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
237
238                  //if( bMerge )
239                  //{
240                    //cMv.m_bDvMcp = true;
241                    //cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
242                  //}
243
244                  pcCU->clipMv( cMv );
245                  if(bMerge)
246                  {
247                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
248                    pacPdmMv      [ uiCurrRefListId ] = cMv;
249                    bLoop_stop = true;
250                    break;
251                  }else
252                  {
253                    pacPdmMv  [0] = cMv;
254                    return true;
255                  }
256                }
257              }
258            }
259          }
260        }
261      }
262    }
263    if( bMerge )
264      iPdm[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
265  }
266  if(bMerge || bInterview)
267  {
268    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
269    {
270      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
271      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
272      for( Int iPdmRefIdx = (bMerge ? 0: iRefIdx); iPdmRefIdx < (bMerge ? iNumRefPics: (iRefIdx+1) ); iPdmRefIdx++ )
273      {
274        if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
275        {
276          abPdmAvailable[ iRefListId+2 ] = true;
277          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
278
279          TComMv cMv = pDInfo->m_acNBDV; 
280          cMv.setVer(0);
281
282          pcCU->clipMv( cMv );
283          pacPdmMv      [ iRefListId + 2] = cMv;
284          if(bMerge)
285            break;
286          else
287          {
288            pacPdmMv [0] = cMv;
289            return true;
290          }
291        }
292      }
293    }
294    iPdm[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
295  }
296  return false;
297}
298#endif
299
Note: See TracBrowser for help on using the repository browser.