source: 3DVCSoftware/trunk/source/App/TAppRenderer/TAppRendererTop.cpp @ 18

Last change on this file since 18 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

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