source: 3DVCSoftware/branches/HTM-6.2-dev3-Mediatek/source/App/TAppRenderer/TAppRendererTop.cpp @ 383

Last change on this file since 383 was 296, checked in by tech, 12 years ago

Reintegrated branch 5.1-dev0 rev. 295.

  • Property svn:eol-style set to native
File size: 34.8 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#include <list>
37#include <stdio.h>
38#include <fcntl.h>
39#include <assert.h>
40#include <math.h>
41
42#include "TAppRendererTop.h"
43
44// ====================================================================================================================
45// Constructor / destructor / initialization / destroy
46// ====================================================================================================================
47#if !QC_MVHEVC_B0046
48TAppRendererTop::TAppRendererTop()
49{
50
51}
52
53TAppRendererTop::~TAppRendererTop()
54{
55
56}
57
58
59Void TAppRendererTop::xCreateLib()
60{
61  Int iInteralBitDepth = g_uiBitDepth + g_uiBitIncrement;
62  Int iFileBitDepth    = 8;
63  m_pcRenTop = new TRenTop();
64
65  for(Int iViewIdx=0; iViewIdx<m_iNumberOfInputViews; iViewIdx++)
66  {
67    TVideoIOYuv* pcVideoInput = new TVideoIOYuv;
68    TVideoIOYuv* pcDepthInput = new TVideoIOYuv;
69
70    pcVideoInput->open( m_pchVideoInputFileList[iViewIdx], false, iFileBitDepth, iInteralBitDepth );  // read mode
71    pcDepthInput->open( m_pchDepthInputFileList[iViewIdx], false, iFileBitDepth, iInteralBitDepth );  // read mode
72    pcVideoInput->skipFrames(m_iFrameSkip, m_iSourceWidth, m_iSourceHeight  );
73    pcDepthInput->skipFrames(m_iFrameSkip, m_iSourceWidth, m_iSourceHeight  );
74
75    m_apcTVideoIOYuvVideoInput.push_back( pcVideoInput );
76    m_apcTVideoIOYuvDepthInput.push_back( pcDepthInput );
77  }
78
79  for(Int iViewIdx=0; iViewIdx<m_iNumberOfOutputViews; iViewIdx++)
80  {
81    TVideoIOYuv* pcSynthOutput = new TVideoIOYuv;
82    pcSynthOutput->open( m_pchSynthOutputFileList[iViewIdx], true, iFileBitDepth, iInteralBitDepth );  // write mode
83    m_apcTVideoIOYuvSynthOutput.push_back( pcSynthOutput );
84  }
85}
86
87
88Void TAppRendererTop::xDestroyLib()
89{
90  delete m_pcRenTop;
91
92  for ( Int iViewIdx = 0; iViewIdx < m_iNumberOfInputViews; iViewIdx++ )
93  {
94    m_apcTVideoIOYuvVideoInput[iViewIdx]->close();
95    m_apcTVideoIOYuvDepthInput[iViewIdx]->close();
96
97    delete m_apcTVideoIOYuvDepthInput[iViewIdx];
98    delete m_apcTVideoIOYuvVideoInput[iViewIdx];
99  };
100
101  for ( Int iViewIdx = 0; iViewIdx < m_iNumberOfOutputViews; iViewIdx++ )
102  {
103    m_apcTVideoIOYuvSynthOutput[iViewIdx]->close();
104    delete m_apcTVideoIOYuvSynthOutput[iViewIdx];
105  };
106}
107
108Void TAppRendererTop::xInitLib()
109{
110    m_pcRenTop->init(
111    m_iSourceWidth,
112    m_iSourceHeight,
113    (m_iRenderDirection != 0),
114    m_iLog2SamplingFactor,
115    m_iLog2SamplingFactor+m_iShiftPrecision,
116    m_bUVUp,
117    m_iPreProcMode,
118    m_iPreFilterSize,
119    m_iBlendMode,
120    m_iBlendZThresPerc,
121    m_bBlendUseDistWeight,
122    m_iBlendHoleMargin,
123    m_iInterpolationMode,
124    m_iHoleFillingMode,
125    m_iPostProcMode,
126    m_iUsedPelMapMarExt
127    );
128}
129
130// ====================================================================================================================
131// Public member functions
132// ====================================================================================================================
133
134
135
136Void TAppRendererTop::render()
137{
138  xCreateLib();
139  xInitLib();
140
141  // Create Buffers Input Views;
142  std::vector<TComPicYuv*> apcPicYuvBaseVideo;
143  std::vector<TComPicYuv*> apcPicYuvBaseDepth;
144
145  // TemporalImprovement Filter
146  std::vector<TComPicYuv*> apcPicYuvLastBaseVideo;
147  std::vector<TComPicYuv*> apcPicYuvLastBaseDepth;
148
149  Int aiPad[2] = { 0, 0 };
150
151  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
152  {
153    TComPicYuv* pcNewVideoPic = new TComPicYuv;
154    TComPicYuv* pcNewDepthPic = new TComPicYuv;
155
156    pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
157    apcPicYuvBaseVideo.push_back(pcNewVideoPic);
158
159    pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
160    apcPicYuvBaseDepth.push_back(pcNewDepthPic);
161
162    //Temporal improvement Filter
163    if ( m_bTempDepthFilter )
164    {
165      pcNewVideoPic = new TComPicYuv;
166      pcNewDepthPic = new TComPicYuv;
167
168      pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
169      apcPicYuvLastBaseVideo.push_back(pcNewVideoPic);
170
171      pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
172      apcPicYuvLastBaseDepth.push_back(pcNewDepthPic);
173    }
174  }
175
176  // Create Buffer for synthesized View
177  TComPicYuv* pcPicYuvSynthOut = new TComPicYuv;
178  pcPicYuvSynthOut->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
179
180  Bool bAnyEOS = false;
181
182  Int iNumOfRenderedFrames = 0;
183  Int iFrame = 0;
184
185  while ( ( ( iNumOfRenderedFrames < m_iFramesToBeRendered ) || ( m_iFramesToBeRendered == 0 ) ) && !bAnyEOS )
186  {
187    if ( iFrame >= m_iFrameSkip ) 
188    {
189      // read in depth and video
190      for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
191      {
192        m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->read( apcPicYuvBaseVideo[iBaseViewIdx], aiPad  ) ;
193
194        apcPicYuvBaseVideo[iBaseViewIdx]->extendPicBorder();
195
196        bAnyEOS |= m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->isEof();
197
198        m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->read( apcPicYuvBaseDepth[iBaseViewIdx], aiPad  ) ;
199        apcPicYuvBaseDepth[iBaseViewIdx]->extendPicBorder();
200        bAnyEOS |= m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->isEof();
201
202        if ( m_bTempDepthFilter && (iFrame >= m_iFrameSkip) )
203        {
204          m_pcRenTop->temporalFilterVSRS( apcPicYuvBaseVideo[iBaseViewIdx], apcPicYuvBaseDepth[iBaseViewIdx], apcPicYuvLastBaseVideo[iBaseViewIdx], apcPicYuvLastBaseDepth[iBaseViewIdx], ( iFrame == m_iFrameSkip) );
205        }
206      }
207    }
208    else   
209    {
210      std::cout << "Skipping Frame " << iFrame << std::endl;
211
212      iFrame++;
213      continue;
214    }
215
216    m_cCameraData.update( (UInt)iFrame - m_iFrameSkip );
217
218    for(Int iSynthViewIdx=0; iSynthViewIdx < m_iNumberOfOutputViews; iSynthViewIdx++ )
219    {
220      Int  iLeftBaseViewIdx  = -1;
221      Int  iRightBaseViewIdx = -1;
222
223      Bool bIsBaseView = false;
224
225      Int iRelDistToLeft;
226      Bool bHasLRView = m_cCameraData.getLeftRightBaseView( iSynthViewIdx, iLeftBaseViewIdx, iRightBaseViewIdx, iRelDistToLeft, bIsBaseView );
227      Bool bHasLView = ( iLeftBaseViewIdx != -1 );
228      Bool bHasRView = ( iRightBaseViewIdx != -1 );
229      Bool bRender   = true;
230
231      Int  iBlendMode = m_iBlendMode;
232      Int  iSimEnhBaseView = 0;
233
234      switch( m_iRenderDirection )
235      {
236      /// INTERPOLATION
237      case 0:
238        AOF( bHasLRView || bIsBaseView );
239
240        if ( !bHasLRView && bIsBaseView && m_iBlendMode == 0 )
241        {
242          bRender = false;
243        }
244        else
245        {
246          if ( bIsBaseView )
247          {
248            AOF( iLeftBaseViewIdx == iRightBaseViewIdx );
249            Int iSortedBaseViewIdx = m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx];
250
251            if ( m_iBlendMode == 1 )
252            {
253              if ( iSortedBaseViewIdx - 1 >= 0 )
254              {
255                iLeftBaseViewIdx = m_cCameraData.getBaseSortedId2Id()[ iSortedBaseViewIdx - 1];
256                bRender = true;
257              }
258              else
259              {
260                bRender = false;
261              }
262            }
263            else if ( m_iBlendMode == 2 )
264            {
265              if ( iSortedBaseViewIdx + 1 < m_iNumberOfInputViews )
266              {
267                iRightBaseViewIdx = m_cCameraData.getBaseSortedId2Id()[ iSortedBaseViewIdx + 1];
268                bRender = true;
269              }
270              else
271              {
272                bRender = false;
273              }
274            }
275          }
276
277          if ( m_iBlendMode == 3 )
278          {
279            if ( bIsBaseView && (iLeftBaseViewIdx == 0) )
280            {
281              bRender = false;
282            }
283            else
284            {
285              Int iDistLeft  = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx ]  );
286              Int iDistRight = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iRightBaseViewIdx]  );
287
288              Int iFillViewIdx = iDistLeft > iDistRight ? iLeftBaseViewIdx : iRightBaseViewIdx;
289
290              if( m_cCameraData.getBaseId2SortedId()[0] < m_cCameraData.getBaseId2SortedId() [iFillViewIdx] )
291              {
292                iBlendMode        = 1;
293                iLeftBaseViewIdx  = 0;
294                iRightBaseViewIdx = iFillViewIdx;
295              }
296              else
297              {
298                iBlendMode        = 2;
299                iLeftBaseViewIdx  = iFillViewIdx;
300                iRightBaseViewIdx = 0;
301              }
302
303            }
304          }
305          else
306          {
307            iBlendMode = m_iBlendMode;
308          }
309        }
310
311        if ( m_bSimEnhance )
312        {
313          if ( m_iNumberOfInputViews == 3 && m_cCameraData.getRelSynthViewNumbers()[ iSynthViewIdx ] < VIEW_NUM_PREC  )
314          {
315            iSimEnhBaseView = 2; // Take middle view
316          }
317          else
318          {
319            iSimEnhBaseView = 1; // Take left view
320          }
321        }
322
323          if ( bRender )
324          {
325          std::cout << "Rendering Frame "    << iFrame
326                    << " of View "           << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx    ] / VIEW_NUM_PREC
327                    << "   Left BaseView: "  << (Double) m_cCameraData.getBaseViewNumbers() [iLeftBaseViewIdx ] / VIEW_NUM_PREC
328                    << "   Right BaseView: " << (Double) m_cCameraData.getBaseViewNumbers() [iRightBaseViewIdx] / VIEW_NUM_PREC
329                    << "   BlendMode: "      << iBlendMode
330                    << std::endl;
331
332          m_pcRenTop->setShiftLUTs(
333            m_cCameraData.getSynthViewShiftLUTD()[iLeftBaseViewIdx ][iSynthViewIdx],
334            m_cCameraData.getSynthViewShiftLUTI()[iLeftBaseViewIdx ][iSynthViewIdx],
335            m_cCameraData.getBaseViewShiftLUTI ()[iLeftBaseViewIdx ][iRightBaseViewIdx],
336            m_cCameraData.getSynthViewShiftLUTD()[iRightBaseViewIdx][iSynthViewIdx],
337            m_cCameraData.getSynthViewShiftLUTI()[iRightBaseViewIdx][iSynthViewIdx],
338            m_cCameraData.getBaseViewShiftLUTI ()[iRightBaseViewIdx][iLeftBaseViewIdx ],
339
340            iRelDistToLeft
341          );
342
343          m_pcRenTop->interpolateView(
344            apcPicYuvBaseVideo[iLeftBaseViewIdx ],
345            apcPicYuvBaseDepth[iLeftBaseViewIdx ],
346            apcPicYuvBaseVideo[iRightBaseViewIdx],
347            apcPicYuvBaseDepth[iRightBaseViewIdx],
348            pcPicYuvSynthOut,
349            iBlendMode,
350            iSimEnhBaseView
351            );
352        }
353        else
354        {
355          AOT(iLeftBaseViewIdx != iRightBaseViewIdx );
356          apcPicYuvBaseVideo[iLeftBaseViewIdx]->copyToPic( pcPicYuvSynthOut );
357          std::cout << "Copied    Frame " << iFrame
358                    << " of View "        << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC
359                    << "   (BaseView)  "    << std::endl;
360        }
361
362        break;
363      /// EXTRAPOLATION FROM LEFT
364      case 1:
365        if ( !bHasLView ) // View to render is BaseView
366        {
367          bRender = false;
368        }
369
370          if (  bIsBaseView )
371          {
372          AOF( iLeftBaseViewIdx == iRightBaseViewIdx );
373          Int iSortedBaseViewIdx = m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx];
374          if ( iSortedBaseViewIdx - 1 >= 0 )
375          {
376            iLeftBaseViewIdx = m_cCameraData.getBaseSortedId2Id()[ iSortedBaseViewIdx - 1];
377          }
378          else
379          {
380            std::cout << "Copied    Frame " << iFrame << " of BaseView " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
381            apcPicYuvBaseVideo[iLeftBaseViewIdx]->copyToPic( pcPicYuvSynthOut ); // Copy Original
382            bRender = false;
383          }
384        }
385
386
387        if (bRender)
388        {
389          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
390          m_pcRenTop->setShiftLUTs( m_cCameraData.getSynthViewShiftLUTD()[iLeftBaseViewIdx ][iSynthViewIdx],
391            m_cCameraData.getSynthViewShiftLUTI()[iLeftBaseViewIdx ][iSynthViewIdx], NULL, NULL, NULL, NULL, -1 );
392          m_pcRenTop->extrapolateView( apcPicYuvBaseVideo[iLeftBaseViewIdx ], apcPicYuvBaseDepth[iLeftBaseViewIdx ], pcPicYuvSynthOut, true );
393        }
394        break;
395      /// EXTRAPOLATION FROM RIGHT
396      case 2:            // extrapolation from right
397        if ( !bHasRView ) // View to render is BaseView
398        {
399          bRender = false;
400        }
401
402          if (  bIsBaseView )
403          {
404
405          AOF( iLeftBaseViewIdx == iRightBaseViewIdx );
406          Int iSortedBaseViewIdx = m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx];
407          if ( iSortedBaseViewIdx + 1 < m_iNumberOfInputViews )
408          {
409            iRightBaseViewIdx = m_cCameraData.getBaseSortedId2Id()[ iSortedBaseViewIdx + 1];
410          }
411          else
412          {
413            std::cout << "Copied    Frame " << iFrame << " of BaseView " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
414            apcPicYuvBaseVideo[iLeftBaseViewIdx]->copyToPic( pcPicYuvSynthOut ); // Copy Original
415            bRender = false;
416          }
417        }
418
419        if ( bRender )
420        {
421          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
422          m_pcRenTop->setShiftLUTs( NULL, NULL,NULL, m_cCameraData.getSynthViewShiftLUTD()[iRightBaseViewIdx ][iSynthViewIdx],
423            m_cCameraData.getSynthViewShiftLUTI()[iRightBaseViewIdx ][iSynthViewIdx],NULL, iRelDistToLeft);
424          m_pcRenTop->extrapolateView( apcPicYuvBaseVideo[iRightBaseViewIdx ], apcPicYuvBaseDepth[iRightBaseViewIdx ], pcPicYuvSynthOut, false);
425        }
426        break;
427      }
428
429      // Write Output
430
431      m_apcTVideoIOYuvSynthOutput[m_bSweep ? 0 : iSynthViewIdx]->write( pcPicYuvSynthOut, 0, 0, 0, 0 );
432    }
433    iFrame++;
434    iNumOfRenderedFrames++;
435  }
436
437  // Delete Buffers
438  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
439  {
440    apcPicYuvBaseVideo[uiBaseView]->destroy();
441    delete apcPicYuvBaseVideo[uiBaseView];
442
443    apcPicYuvBaseDepth[uiBaseView]->destroy();
444    delete apcPicYuvBaseDepth[uiBaseView];
445
446    // Temporal Filter
447    if ( m_bTempDepthFilter )
448    {
449      apcPicYuvLastBaseVideo[uiBaseView]->destroy();
450      delete apcPicYuvLastBaseVideo[uiBaseView];
451
452      apcPicYuvLastBaseDepth[uiBaseView]->destroy();
453      delete apcPicYuvLastBaseDepth[uiBaseView];
454    }
455  }
456
457  pcPicYuvSynthOut->destroy();
458  delete pcPicYuvSynthOut;
459
460  xDestroyLib();
461
462}
463
464Void TAppRendererTop::go()
465{
466  switch ( m_iRenderMode )
467  {
468  case 0:
469    render();
470    break;
471  case 1:
472    renderModel();
473    break;
474  case 10:
475    renderUsedPelsMap( );
476      break;
477
478  default:
479    AOT(true);
480  }
481}
482
483Void TAppRendererTop::renderModel()
484{
485  if ( m_bUseSetupString )
486  {
487    xRenderModelFromString();
488  }
489  else
490  {
491    xRenderModelFromNums();
492  }
493}
494
495Void TAppRendererTop::xRenderModelFromString()
496{
497
498    xCreateLib();
499    xInitLib();
500
501    // Create Buffers Input Views;
502    std::vector<TComPicYuv*> apcPicYuvBaseVideo;
503    std::vector<TComPicYuv*> apcPicYuvBaseDepth;
504
505
506    for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
507    {
508      TComPicYuv* pcNewVideoPic = new TComPicYuv;
509      TComPicYuv* pcNewDepthPic = new TComPicYuv;
510
511      pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
512      apcPicYuvBaseVideo.push_back(pcNewVideoPic);
513
514      pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
515      apcPicYuvBaseDepth.push_back(pcNewDepthPic);
516    }
517
518    Int aiPad[2] = { 0, 0 };
519
520    // Init Model
521    TRenModel cCurModel;
522
523    AOT( m_iLog2SamplingFactor != 0 );
524#if LGE_VSO_EARLY_SKIP_A0093
525    cCurModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_iSourceHeight, m_iShiftPrecision, m_iBlendHoleMargin, false );
526#else
527    cCurModel.create( m_cRenModStrParser.getNumOfBaseViews(), m_cRenModStrParser.getNumOfModels(), m_iSourceWidth, m_iSourceHeight, m_iShiftPrecision, m_iBlendHoleMargin );
528#endif
529
530    cCurModel.setupPart( 0, m_iSourceHeight  ); 
531
532    for ( Int iViewIdx = 0; iViewIdx < m_iNumberOfInputViews; iViewIdx++ )
533    {
534      Int iNumOfModels   = m_cRenModStrParser.getNumOfModelsForView(iViewIdx, 1);
535
536      for (Int iCurModel = 0; iCurModel < iNumOfModels; iCurModel++ )
537      {
538        Int iModelNum; Int iLeftViewNum; Int iRightViewNum; Int iDump; Int iOrgRefNum; Int iBlendMode;
539        m_cRenModStrParser.getSingleModelData  ( iViewIdx, 1, iCurModel, iModelNum, iBlendMode, iLeftViewNum, iRightViewNum, iOrgRefNum, iDump ) ;
540        cCurModel         .createSingleModel   ( iViewIdx, 1, iModelNum, iLeftViewNum, iRightViewNum, false, iBlendMode );
541
542      }
543    }
544
545    // Create Buffer for synthesized View
546    TComPicYuv* pcPicYuvSynthOut = new TComPicYuv;
547    pcPicYuvSynthOut->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
548
549    Bool bAnyEOS = false;
550
551    Int iNumOfRenderedFrames = 0;
552    Int iFrame = 0;
553
554    while ( ( ( iNumOfRenderedFrames < m_iFramesToBeRendered ) || ( m_iFramesToBeRendered == 0 ) ) && !bAnyEOS )
555    {
556
557      if ( iFrame >= m_iFrameSkip )
558      {     
559        // read in depth and video
560        for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
561        {
562          m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->read( apcPicYuvBaseVideo[iBaseViewIdx], aiPad  ) ;
563          bAnyEOS |= m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->isEof();
564
565          m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->read( apcPicYuvBaseDepth[iBaseViewIdx], aiPad  ) ;
566          bAnyEOS |= m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->isEof();
567        }
568      }
569      else
570      {
571        iFrame++;
572        continue;
573      }
574
575
576      for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
577      {
578        TComPicYuv* pcPicYuvVideo = apcPicYuvBaseVideo[iBaseViewIdx];
579        TComPicYuv* pcPicYuvDepth = apcPicYuvBaseDepth[iBaseViewIdx];
580        Int iBaseViewSIdx = m_cCameraData.getBaseId2SortedId()[iBaseViewIdx ];
581        cCurModel.setBaseView( iBaseViewSIdx, pcPicYuvVideo, pcPicYuvDepth, NULL, NULL );
582      }
583
584      m_cCameraData.update( (UInt) ( iFrame - m_iFrameSkip ));
585
586      for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
587      {
588        // setup virtual views
589        Int iBaseViewSIdx = m_cCameraData.getBaseId2SortedId()[iBaseViewIdx];
590
591        cCurModel.setErrorMode( iBaseViewSIdx, 1, 0 );
592        Int iNumOfSV  = m_cRenModStrParser.getNumOfModelsForView( iBaseViewSIdx, 1);
593        for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
594        {
595          Int iOrgRefBaseViewSIdx;
596          Int iLeftBaseViewSIdx;
597          Int iRightBaseViewSIdx;
598          Int iSynthViewRelNum;
599          Int iModelNum;
600          Int iBlendMode;
601
602          m_cRenModStrParser.getSingleModelData(iBaseViewSIdx, 1, iCurView, iModelNum, iBlendMode, iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
603
604          Int iLeftBaseViewIdx    = -1;
605          Int iRightBaseViewIdx   = -1;
606
607          TComPicYuv* pcPicYuvOrgRef  = NULL;
608          Int**      ppiShiftLUTLeft  = NULL;
609          Int**      ppiShiftLUTRight = NULL;
610          Int**      ppiBaseShiftLUTLeft  = NULL;
611          Int**      ppiBaseShiftLUTRight = NULL;
612
613
614          Int        iDistToLeft      = -1;
615
616          Int iSynthViewIdx = m_cCameraData.synthRelNum2Idx( iSynthViewRelNum );
617
618          if ( iLeftBaseViewSIdx != -1 )
619          {
620            iLeftBaseViewIdx   = m_cCameraData.getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
621            ppiShiftLUTLeft    = m_cCameraData.getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
622          }
623
624          if ( iRightBaseViewSIdx != -1 )
625          {
626            iRightBaseViewIdx  = m_cCameraData.getBaseSortedId2Id()   [iRightBaseViewSIdx ];
627            ppiShiftLUTRight   = m_cCameraData.getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
628          }
629
630          if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
631          {
632
633            ppiBaseShiftLUTLeft  = m_cCameraData.getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
634            ppiBaseShiftLUTRight = m_cCameraData.getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
635            iDistToLeft    = m_cCameraData.getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
636          }
637
638          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
639
640          cCurModel.setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
641
642          Int iViewPos;
643          if (iLeftBaseViewSIdx != -1 && iRightBaseViewSIdx != -1)
644          {
645            iViewPos = VIEWPOS_MERGED;
646          }
647          else if ( iLeftBaseViewSIdx != -1 )
648          {
649            iViewPos = VIEWPOS_LEFT;
650          }
651          else if ( iRightBaseViewSIdx != -1 )
652          {
653            iViewPos = VIEWPOS_RIGHT;
654          }
655          else
656          {
657            AOT(true);
658          }
659
660          cCurModel.getSynthVideo ( iModelNum, iViewPos, pcPicYuvSynthOut );
661
662          // Write Output
663          m_apcTVideoIOYuvSynthOutput[m_bSweep ? 0 : iModelNum]->write( pcPicYuvSynthOut, 0 ,0 ,0, 0 );
664        }
665      }
666      iFrame++;
667      iNumOfRenderedFrames++;
668  }
669
670    // Delete Buffers
671    for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
672    {
673      apcPicYuvBaseVideo[uiBaseView]->destroy();
674      delete apcPicYuvBaseVideo[uiBaseView];
675
676      apcPicYuvBaseDepth[uiBaseView]->destroy();
677      delete apcPicYuvBaseDepth[uiBaseView];
678}
679    pcPicYuvSynthOut->destroy();
680    delete pcPicYuvSynthOut;
681
682    xDestroyLib();
683}
684
685Void TAppRendererTop::xRenderModelFromNums()
686{
687  xCreateLib();
688  xInitLib();
689
690  // Create Buffers Input Views;
691  std::vector<TComPicYuv*> apcPicYuvBaseVideo;
692  std::vector<TComPicYuv*> apcPicYuvBaseDepth;
693
694
695  Int aiPad[2] = { 0, 0 };
696
697  // Init Model
698  TRenModel cCurModel;
699
700  AOT( m_iLog2SamplingFactor != 0 );
701  cCurModel.setupPart( 0, m_iSourceHeight  ); 
702#if LGE_VSO_EARLY_SKIP_A0093
703  cCurModel.create( m_iNumberOfInputViews, m_iNumberOfOutputViews, m_iSourceWidth, m_iSourceHeight, m_iShiftPrecision, m_iBlendHoleMargin, false );
704#else
705  cCurModel.create( m_iNumberOfInputViews, m_iNumberOfOutputViews, m_iSourceWidth, m_iSourceHeight, m_iShiftPrecision, m_iBlendHoleMargin );
706#endif
707
708  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
709  {
710    TComPicYuv* pcNewVideoPic = new TComPicYuv;
711    TComPicYuv* pcNewDepthPic = new TComPicYuv;
712
713    pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
714    apcPicYuvBaseVideo.push_back(pcNewVideoPic);
715
716    pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
717    apcPicYuvBaseDepth.push_back(pcNewDepthPic);
718  }
719
720  for(Int iSynthViewIdx=0; iSynthViewIdx < m_iNumberOfOutputViews; iSynthViewIdx++ )
721  {
722    Int  iLeftBaseViewIdx  = -1;
723    Int  iRightBaseViewIdx = -1;
724    Bool bIsBaseView = false;
725
726    Int iRelDistToLeft;
727    m_cCameraData.getLeftRightBaseView( iSynthViewIdx, iLeftBaseViewIdx, iRightBaseViewIdx, iRelDistToLeft,  bIsBaseView );
728
729    if (m_iRenderDirection == 1 )
730    {
731      iRightBaseViewIdx = -1;
732      AOT( iLeftBaseViewIdx == -1);
733    }
734
735    if (m_iRenderDirection == 2 )
736    {
737      iLeftBaseViewIdx = -1;
738      AOT( iRightBaseViewIdx == -1);
739    }
740
741    Int iLeftBaseViewSIdx  = -1;
742    Int iRightBaseViewSIdx = -1;
743
744    if (iLeftBaseViewIdx != -1 )
745    {
746      iLeftBaseViewSIdx = m_cCameraData.getBaseId2SortedId()[iLeftBaseViewIdx];
747    }
748
749    if (iRightBaseViewIdx != -1 )
750    {
751      iRightBaseViewSIdx = m_cCameraData.getBaseId2SortedId()[iRightBaseViewIdx];
752    }
753    cCurModel.createSingleModel(-1, -1, iSynthViewIdx, iLeftBaseViewSIdx, iRightBaseViewSIdx, false, m_iBlendMode );
754  }
755
756  // Create Buffer for synthesized View
757  TComPicYuv* pcPicYuvSynthOut = new TComPicYuv;
758  pcPicYuvSynthOut->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
759
760  Bool bAnyEOS = false;
761
762  Int iNumOfRenderedFrames = 0;
763  Int iFrame = 0;
764
765  while ( ( ( iNumOfRenderedFrames < m_iFramesToBeRendered ) || ( m_iFramesToBeRendered == 0 ) ) && !bAnyEOS )
766  {
767
768    if ( iFrame >= m_iFrameSkip )
769    {     
770      // read in depth and video
771      for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
772      {
773        m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->read( apcPicYuvBaseVideo[iBaseViewIdx], aiPad  ) ;
774        bAnyEOS |= m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->isEof();
775
776        m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->read( apcPicYuvBaseDepth[iBaseViewIdx], aiPad  ) ;
777        bAnyEOS |= m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->isEof();
778
779        if ( iFrame >= m_iFrameSkip )
780        {
781          Int iBaseViewSIdx = m_cCameraData.getBaseId2SortedId()[iBaseViewIdx];
782          cCurModel.setBaseView( iBaseViewSIdx, apcPicYuvBaseVideo[iBaseViewIdx], apcPicYuvBaseDepth[iBaseViewIdx], NULL, NULL );
783        }
784      }
785    }
786    else
787    {
788      iFrame++;
789      continue;
790    }
791    m_cCameraData.update( (UInt) (iFrame - m_iFrameSkip ));
792    for(Int iSynthViewIdx=0; iSynthViewIdx < m_iNumberOfOutputViews; iSynthViewIdx++ )
793    {
794
795      Int  iLeftBaseViewIdx  = -1;
796      Int  iRightBaseViewIdx = -1;
797
798      Bool bIsBaseView = false;
799
800      Int iRelDistToLeft;
801      Bool bHasLRView = m_cCameraData.getLeftRightBaseView( iSynthViewIdx, iLeftBaseViewIdx, iRightBaseViewIdx, iRelDistToLeft, bIsBaseView );
802      Bool bHasLView = ( iLeftBaseViewIdx != -1 );
803      Bool bHasRView = ( iRightBaseViewIdx != -1 );
804
805      switch( m_iRenderDirection )
806      {
807        /// INTERPOLATION
808      case 0:
809        assert( bHasLRView || bIsBaseView );
810
811        if ( !bHasLRView && bIsBaseView ) // View to render is BaseView
812        {
813          std::cout << "Copied    Frame " << iFrame << " of BaseView " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
814          apcPicYuvBaseVideo[iLeftBaseViewIdx]->copyToPic( pcPicYuvSynthOut ); // Copy Original
815        }
816        else  // Render
817        {
818          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
819          cCurModel.setSingleModel( iSynthViewIdx,
820                                    m_cCameraData.getSynthViewShiftLUTI()[iLeftBaseViewIdx ][iSynthViewIdx]    ,
821                                    m_cCameraData.getBaseViewShiftLUTI ()[iLeftBaseViewIdx ][iRightBaseViewIdx],
822                                    m_cCameraData.getSynthViewShiftLUTI()[iRightBaseViewIdx][iSynthViewIdx]    ,
823                                    m_cCameraData.getBaseViewShiftLUTI ()[iRightBaseViewIdx][iLeftBaseViewIdx] ,
824                                    iRelDistToLeft,
825                                    NULL );
826          cCurModel.getSynthVideo ( iSynthViewIdx, VIEWPOS_MERGED, pcPicYuvSynthOut );
827        }
828        break;
829        /// EXTRAPOLATION FROM LEFT
830      case 1:
831
832        if ( !bHasLView ) // View to render is BaseView
833        {
834          std::cout << "Copied    Frame " << iFrame << " of BaseView " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
835          apcPicYuvBaseVideo[iLeftBaseViewIdx]->copyToPic( pcPicYuvSynthOut ); // Copy Original
836        }
837        else  // Render
838        {
839          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
840          cCurModel.setSingleModel( iSynthViewIdx, m_cCameraData.getSynthViewShiftLUTI()[iLeftBaseViewIdx ][iSynthViewIdx], NULL, NULL, NULL, -1,  NULL);
841          cCurModel.getSynthVideo ( iSynthViewIdx, VIEWPOS_LEFT, pcPicYuvSynthOut );
842        }
843        break;
844        /// EXTRAPOLATION FROM RIGHT
845      case 2:            // extrapolation from right
846        if ( !bHasRView ) // View to render is BaseView
847        {
848          std::cout << "Copied    Frame " << iFrame << " of BaseView " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
849          apcPicYuvBaseVideo[iRightBaseViewIdx]->copyToPic( pcPicYuvSynthOut ); // Copy Original
850        }
851        else  // Render
852        {
853          std::cout << "Rendering Frame " << iFrame << " of View " << (Double) m_cCameraData.getSynthViewNumbers()[iSynthViewIdx] / VIEW_NUM_PREC  << std::endl;
854          cCurModel.setSingleModel( iSynthViewIdx, NULL , NULL, m_cCameraData.getSynthViewShiftLUTI()[iRightBaseViewIdx ][iSynthViewIdx], NULL, -1, NULL);
855          cCurModel.getSynthVideo ( iSynthViewIdx, VIEWPOS_RIGHT, pcPicYuvSynthOut );
856        }
857        break;
858      }
859
860      // Write Output
861      m_apcTVideoIOYuvSynthOutput[m_bSweep ? 0 : iSynthViewIdx]->write( pcPicYuvSynthOut, 0, 0, 0, 0 );
862    }
863    iFrame++;
864    iNumOfRenderedFrames++;
865  }
866
867  // Delete Buffers
868  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
869  {
870    apcPicYuvBaseVideo[uiBaseView]->destroy();
871    delete apcPicYuvBaseVideo[uiBaseView];
872
873    apcPicYuvBaseDepth[uiBaseView]->destroy();
874    delete apcPicYuvBaseDepth[uiBaseView];
875  }
876  pcPicYuvSynthOut->destroy();
877  delete pcPicYuvSynthOut;
878
879  xDestroyLib();
880
881}
882
883Void TAppRendererTop::renderUsedPelsMap( )
884{
885  xCreateLib();
886  xInitLib();
887
888  // Create Buffers Input Views;
889  std::vector<TComPicYuv*> apcPicYuvBaseVideo;
890  std::vector<TComPicYuv*> apcPicYuvBaseDepth;
891
892  // TemporalImprovement Filter
893  std::vector<TComPicYuv*> apcPicYuvLastBaseVideo;
894  std::vector<TComPicYuv*> apcPicYuvLastBaseDepth;
895
896  Int aiPad[2] = { 0, 0 };
897
898  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
899  {
900    TComPicYuv* pcNewVideoPic = new TComPicYuv;
901    TComPicYuv* pcNewDepthPic = new TComPicYuv;
902
903    pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
904    apcPicYuvBaseVideo.push_back(pcNewVideoPic);
905
906    pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
907    apcPicYuvBaseDepth.push_back(pcNewDepthPic);
908
909    //Temporal improvement Filter
910    if ( m_bTempDepthFilter )
911    {
912      pcNewVideoPic = new TComPicYuv;
913      pcNewDepthPic = new TComPicYuv;
914
915      pcNewVideoPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
916      apcPicYuvLastBaseVideo.push_back(pcNewVideoPic);
917
918      pcNewDepthPic->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
919      apcPicYuvLastBaseDepth.push_back(pcNewDepthPic);
920    }
921  }
922
923  // Create Buffer for synthesized View
924  TComPicYuv* pcPicYuvSynthOut = new TComPicYuv;
925  pcPicYuvSynthOut->create( m_iSourceWidth, m_iSourceHeight, 1, 1, 1 );
926
927  Bool bAnyEOS = false;
928
929  Int iNumOfRenderedFrames = 0;
930  Int iFrame = 0;
931
932  while ( ( ( iNumOfRenderedFrames < m_iFramesToBeRendered ) || ( m_iFramesToBeRendered == 0 ) ) && !bAnyEOS )
933  {
934
935
936    if ( iFrame >= m_iFrameSkip )
937    {     
938      // read in depth and video
939      for(Int iBaseViewIdx=0; iBaseViewIdx < m_iNumberOfInputViews; iBaseViewIdx++ )
940      {
941        m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->read( apcPicYuvBaseVideo[iBaseViewIdx], aiPad  ) ;
942        apcPicYuvBaseVideo[iBaseViewIdx]->extendPicBorder();
943        bAnyEOS |= m_apcTVideoIOYuvVideoInput[iBaseViewIdx]->isEof();
944
945        m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->read( apcPicYuvBaseDepth[iBaseViewIdx], aiPad  ) ;
946        apcPicYuvBaseDepth[iBaseViewIdx]->extendPicBorder();
947        bAnyEOS |= m_apcTVideoIOYuvDepthInput[iBaseViewIdx]->isEof();
948
949        if ( m_bTempDepthFilter && (iFrame >= m_iFrameSkip) )
950        {
951          m_pcRenTop->temporalFilterVSRS( apcPicYuvBaseVideo[iBaseViewIdx], apcPicYuvBaseDepth[iBaseViewIdx], apcPicYuvLastBaseVideo[iBaseViewIdx], apcPicYuvLastBaseDepth[iBaseViewIdx], ( iFrame == m_iFrameSkip) );
952        }
953      }
954    }
955    else
956    {
957      std::cout << "Skipping Frame " << iFrame << std::endl;
958
959      iFrame++;
960      continue;
961    }
962    m_cCameraData.update( (UInt) ( iFrame - m_iFrameSkip ) );
963
964    for(Int iViewIdx=1; iViewIdx < m_iNumberOfInputViews; iViewIdx++ )
965    {
966      std::cout << "Rendering UsedPelsMap for Frame " << iFrame << " of View " << (Double) m_cCameraData.getBaseViewNumbers()[iViewIdx] << std::endl;
967
968      Int iViewSIdx      = m_cCameraData.getBaseId2SortedId()[iViewIdx];
969      Int iFirstViewSIdx = m_cCameraData.getBaseId2SortedId()[0];
970
971      AOT( iViewSIdx == iFirstViewSIdx );
972
973      Bool bFirstIsLeft = (iFirstViewSIdx < iViewSIdx);
974
975      m_pcRenTop->setShiftLUTs(
976        m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
977        m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
978        m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
979        m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
980        m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
981        m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
982        -1
983        );
984
985      m_pcRenTop->getUsedSamplesMap( apcPicYuvBaseDepth[0], pcPicYuvSynthOut, bFirstIsLeft );
986
987      // Write Output
988      m_apcTVideoIOYuvSynthOutput[iViewIdx-1]->write( pcPicYuvSynthOut, 0, 0, 0 );
989
990    }
991    iFrame++;
992    iNumOfRenderedFrames++;
993  }
994
995  // Delete Buffers
996  for ( UInt uiBaseView = 0; uiBaseView < m_iNumberOfInputViews; uiBaseView++ )
997  {
998    apcPicYuvBaseVideo[uiBaseView]->destroy();
999    delete apcPicYuvBaseVideo[uiBaseView];
1000
1001    apcPicYuvBaseDepth[uiBaseView]->destroy();
1002    delete apcPicYuvBaseDepth[uiBaseView];
1003
1004    // Temporal Filter
1005    if ( m_bTempDepthFilter )
1006    {
1007      apcPicYuvLastBaseVideo[uiBaseView]->destroy();
1008      delete apcPicYuvLastBaseVideo[uiBaseView];
1009
1010      apcPicYuvLastBaseDepth[uiBaseView]->destroy();
1011      delete apcPicYuvLastBaseDepth[uiBaseView];
1012    }
1013  }
1014  pcPicYuvSynthOut->destroy();
1015  delete pcPicYuvSynthOut;
1016
1017  xDestroyLib();
1018
1019}
1020#endif
Note: See TracBrowser for help on using the repository browser.