source: 3DVCSoftware/branches/HTM-15.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.cpp @ 1360

Last change on this file since 1360 was 1360, checked in by tech, 9 years ago

Update to HM-16.7.

  • Property svn:eol-style set to native
File size: 12.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-2015, ITU/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#include "TRenImage.h"
36#include "TRenFilter.h"
37#include "TRenModSetupStrParser.h"
38
39#if NH_3D
40Int
41TRenModSetupStrParser::getNumOfModels()
42{
43  return m_iNumberOfModels;
44}
45
46Int
47TRenModSetupStrParser::getNumOfBaseViews()
48{
49  return (Int) m_aiAllBaseViewIdx  .size();
50}
51
52Int
53TRenModSetupStrParser::getNumOfModelsForView( Int iViewIdx, Int iContent )
54{
55  return (Int) m_aaaiModelNums[iContent][iViewIdx].size();
56}
57
58Int
59TRenModSetupStrParser::getNumOfBaseViewsForView( Int iViewIdx, Int iContent )
60{
61  return (Int) m_aaaiBaseViewsIdx[iContent][iViewIdx].size();
62}
63
64Void
65TRenModSetupStrParser::getSingleModelData( Int iSrcViewIdx,
66                                           Int iSrcCnt,
67                                           Int iCurModel,
68                                           Int& riModelNum,
69                                           Int& riBlendMode,
70                                           Int& riLeftBaseViewIdx,
71                                           Int& riRightBaseViewIdx,
72                                           Int& riOrgRefBaseViewIdx,
73                                           Int& riSynthViewRelNum )
74{
75  Bool bExtrapolate    = m_aaabExtrapolate[iSrcCnt][iSrcViewIdx][iCurModel];
76  Bool bOrgRef         = m_aaabOrgRef     [iSrcCnt][iSrcViewIdx][iCurModel];
77
78  riOrgRefBaseViewIdx = bOrgRef ? m_aaaiSynthViewNums[iSrcCnt][iSrcViewIdx][iCurModel] / ( (Int) VIEW_NUM_PREC ) : -1;
79  riSynthViewRelNum    = m_aaaiSynthViewNums[iSrcCnt][iSrcViewIdx][iCurModel];
80  riModelNum           = m_aaaiModelNums    [iSrcCnt][iSrcViewIdx][iCurModel];
81  riBlendMode          = m_aaaiBlendMode    [iSrcCnt][iSrcViewIdx][iCurModel];
82
83
84  Int iSrcViewNum = iSrcViewIdx * ((Int) VIEW_NUM_PREC );
85  if ( iSrcViewNum < riSynthViewRelNum )
86  {
87    riLeftBaseViewIdx  = iSrcViewIdx;
88    riRightBaseViewIdx = -1;
89  }
90  else
91  {
92    riLeftBaseViewIdx = -1;
93    riRightBaseViewIdx  = iSrcViewIdx;
94  }
95
96  if ( !bExtrapolate )
97  {
98    std::vector<Int> cCurBaseViews = m_aaaiBaseViewsIdx[iSrcCnt][iSrcViewIdx];
99
100    Int iMinDist = MAX_INT;
101    Int iNearestNum = -1;
102
103    for (Int iCurBaseView = 0; iCurBaseView < cCurBaseViews.size(); iCurBaseView++ )
104    {
105      Int iCurBaseNum = m_aaaiBaseViewsIdx [iSrcCnt][iSrcViewIdx][iCurBaseView];
106
107      if ( iCurBaseNum == iSrcViewNum )
108        continue;
109
110      Int iDist = iCurBaseNum - riSynthViewRelNum;
111
112      if ( ( iDist <= 0  && riLeftBaseViewIdx == -1) || ( iDist >= 0  && riRightBaseViewIdx == -1 ) )
113      {
114        if ( abs(iDist) < iMinDist )
115        {
116          iMinDist = abs(iDist);
117          iNearestNum = iCurBaseNum;
118        }
119      }
120    }
121    xError(iNearestNum == -1);
122
123    if (riLeftBaseViewIdx == -1 )
124    {
125      riLeftBaseViewIdx = iNearestNum / (Int) (VIEW_NUM_PREC);
126    }
127    else
128    {
129      riRightBaseViewIdx = iNearestNum / (Int) (VIEW_NUM_PREC);
130    }
131
132    xError(riLeftBaseViewIdx  == -1 );
133    xError(riRightBaseViewIdx == -1 );
134    xError(riLeftBaseViewIdx  >= riRightBaseViewIdx );
135  }
136}
137
138Void
139TRenModSetupStrParser::getBaseViewData( Int iSourceViewIdx, Int iSourceContent, Int iCurView, Int& riBaseViewSIdx, Int& riVideoDistMode, Int& riDepthDistMode )
140{
141  riBaseViewSIdx = m_aaaiBaseViewsIdx  [iSourceContent][iSourceViewIdx][iCurView] / (Int) VIEW_NUM_PREC;
142  riVideoDistMode            = m_aaaiVideoDistMode [iSourceContent][iSourceViewIdx][iCurView];
143  riDepthDistMode            = m_aaaiDepthDistMode [iSourceContent][iSourceViewIdx][iCurView];
144}
145
146TRenModSetupStrParser::TRenModSetupStrParser()
147{
148  m_pchSetStr       = NULL;
149  m_iPosInStr       = 0;
150  m_iNumberOfModels = 0;
151  m_bCurrentViewSet = false;
152}
153
154Void
155TRenModSetupStrParser::setString( Int iNumOfBaseViews, TChar* pchSetStr )
156{
157  for (Int iContent = 0; iContent < 2; iContent++)
158  {
159    m_aaaiBaseViewsIdx  [iContent].resize( iNumOfBaseViews );
160    m_aaaiDepthDistMode [iContent].resize( iNumOfBaseViews );
161    m_aaaiVideoDistMode [iContent].resize( iNumOfBaseViews );
162    m_aaaiSynthViewNums [iContent].resize( iNumOfBaseViews );
163    m_aaaiModelNums     [iContent].resize( iNumOfBaseViews );
164    m_aaabOrgRef        [iContent].resize( iNumOfBaseViews );
165    m_aaabExtrapolate   [iContent].resize( iNumOfBaseViews );
166    m_aaaiBlendMode     [iContent].resize( iNumOfBaseViews );
167  }
168
169  AOT( m_pchSetStr );
170  m_pchSetStr = pchSetStr;
171  m_iPosInStr       = 0;
172  m_bCurrentViewSet = false;
173
174  xParseString();
175}
176
177Void
178TRenModSetupStrParser::xParseString()
179{
180  TChar cChar;
181  xGetNextChar(cChar);
182  while(  cChar != '\0' )
183  {
184    xParseSourceView();
185    xGetNextChar(cChar);
186  }
187  // CHECK
188  size_t iNumOfSrcViews = m_aaaiBaseViewsIdx[0].size();
189
190  for (Int iSrcView = 0; iSrcView < iNumOfSrcViews; iSrcView++)
191  {
192    for (Int iContent = 0; iContent < 2; iContent++ )
193    {
194      size_t iNumOfBase  = m_aaaiBaseViewsIdx  [iContent][iSrcView].size();
195      AOF( iNumOfBase   == m_aaaiDepthDistMode [iContent][iSrcView].size());
196      AOF( iNumOfBase   == m_aaaiVideoDistMode [iContent][iSrcView].size());
197
198      size_t iNumOfModels = m_aaaiSynthViewNums[iContent][iSrcView].size();
199      AOF( iNumOfModels == m_aaaiModelNums     [iContent][iSrcView].size());
200      AOF( iNumOfModels == m_aaabOrgRef        [iContent][iSrcView].size());
201      AOF( iNumOfModels == m_aaabExtrapolate   [iContent][iSrcView].size());
202    }
203  }
204
205  // SORT
206  std::vector<Int>::iterator cIterNewEnd;
207
208  std::sort( m_aiAllBaseViewIdx.begin(), m_aiAllBaseViewIdx.end() );
209  cIterNewEnd = std::unique( m_aiAllBaseViewIdx.begin(), m_aiAllBaseViewIdx.end() );
210  m_aiAllBaseViewIdx.erase( cIterNewEnd, m_aiAllBaseViewIdx.end() );
211
212  std::sort( m_aiAllSynthViewNums.begin(), m_aiAllSynthViewNums.end() );
213  cIterNewEnd = std::unique( m_aiAllSynthViewNums.begin(), m_aiAllSynthViewNums.end() );
214  m_aiAllSynthViewNums.erase( cIterNewEnd, m_aiAllSynthViewNums.end() );
215}
216
217Void
218TRenModSetupStrParser::xParseSourceView()
219{
220  m_bCurrentViewSet = false;
221
222  TChar cChar;
223  xGetNextCharGoOn( cChar );
224  xError( cChar != '[' );
225  xReadViewInfo('B');
226
227  Bool bContinueReading = true;
228  while( bContinueReading )
229  {
230    xGetNextCharGoOn( cChar );
231    switch ( cChar )
232    {
233    case 'B':
234    case 'I':
235    case 'E':
236    case 'L':
237    case 'R':
238      xReadViews( cChar );
239      break;
240    case ']':
241      bContinueReading = false;
242      break;
243    default:
244      xError(true);
245      break;
246    }
247  }
248}
249
250Void
251TRenModSetupStrParser::xReadViews( TChar cType )
252{
253  TChar cChar;
254  xGetNextCharGoOn( cChar );
255  xError( cChar != '(' );
256
257  Bool bContinue = true;
258  while ( bContinue )
259  {
260    xGetNextChar( cChar );
261    if (cChar == ')')
262    {
263      xGetNextCharGoOn( cChar );
264      bContinue = false;
265    }
266    else
267    {
268      xReadViewInfo( cType );
269    }
270  }
271}
272
273Void
274TRenModSetupStrParser::xReadViewInfo( TChar cType )
275{
276  std::vector<Int> aiViewNums;
277  aiViewNums.clear();
278
279  switch ( cType )
280  {
281  case 'B':
282    TChar cVideoType;
283    TChar cDepthType;
284
285    xGetNextCharGoOn   ( cVideoType );
286    xGetNextCharGoOn   ( cDepthType );
287    xGetViewNumberRange( aiViewNums );
288
289    if ( !m_bCurrentViewSet )
290    {
291      xError( aiViewNums.size() != 1 );
292      m_iCurrentView = aiViewNums[0] / (Int) VIEW_NUM_PREC;
293      if      ( cVideoType == 'x' )
294      {
295        m_iCurrentContent = 0;
296        m_bCurrentViewSet = true;
297      }
298      else if ( cDepthType == 'x' )
299      {
300        m_iCurrentContent = 1;
301        m_bCurrentViewSet = true;
302      }
303      else
304      {
305        xError( true );
306      }
307    }
308
309    for ( Int iIdx = 0; iIdx < aiViewNums.size(); iIdx++ )
310    {
311      xAddBaseView( aiViewNums[iIdx], cVideoType, cDepthType );
312    }
313    break;
314
315  case 'E':
316  case 'I':
317  case 'L':
318  case 'R':
319    TChar cRefType;
320    xGetNextCharGoOn   ( cRefType   );
321    xGetViewNumberRange( aiViewNums );
322    for ( Int iIdx = 0; iIdx < aiViewNums.size(); iIdx++ )
323    {
324      xAddSynthView( aiViewNums[iIdx], cType, cRefType );
325    }
326  }
327}
328
329Void
330TRenModSetupStrParser::xAddBaseView( Int iViewIdx, TChar cVideoType, TChar cDepthType )
331{
332  AOF( m_bCurrentViewSet );
333
334  if ( cDepthType == 'x' ) cDepthType = 'o';
335  if ( cVideoType == 'x' ) cVideoType = 'o';
336 
337  xError( cDepthType != 'o' && cDepthType != 'c' && cVideoType != 'r' );
338  xError( cVideoType != 'o' && cVideoType != 'c' && cVideoType != 'r' );
339  m_aiAllBaseViewIdx.push_back( iViewIdx );
340  m_aaaiBaseViewsIdx  [m_iCurrentContent][m_iCurrentView].push_back( iViewIdx          );
341  m_aaaiVideoDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cVideoType == 'c' ) ? 2 : ( (cVideoType == 'r') ? 1 :  0 ) );
342  m_aaaiDepthDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cDepthType == 'c' ) ? 2 : ( (cDepthType == 'r') ? 1 :  0 ) );
343}
344
345Void
346TRenModSetupStrParser::xAddSynthView( Int iViewNum, TChar cType, TChar cRefType )
347{
348  AOF( m_bCurrentViewSet );
349
350  xError( cRefType != 's' && cRefType != 'o' );
351
352  m_aiAllSynthViewNums.push_back( iViewNum );
353
354  Int iBlendMode;
355  switch ( cType )
356  {
357  case 'E':
358    iBlendMode = BLEND_NONE;
359    break;
360  case 'I':
361    iBlendMode = BLEND_AVRG;
362    break;
363  case 'L':
364    iBlendMode = BLEND_LEFT;
365    break;
366  case 'R':
367    iBlendMode = BLEND_RIGHT;
368    break;
369  default:
370    xError(false);
371    break;
372  }
373
374  m_aaaiBlendMode    [m_iCurrentContent][m_iCurrentView].push_back( iBlendMode        );
375  m_aaaiSynthViewNums[m_iCurrentContent][m_iCurrentView].push_back( iViewNum          );
376  m_aaabExtrapolate  [m_iCurrentContent][m_iCurrentView].push_back( cType    == 'E'   );
377  m_aaabOrgRef       [m_iCurrentContent][m_iCurrentView].push_back( cRefType == 'o'   );
378  m_aaaiModelNums    [m_iCurrentContent][m_iCurrentView].push_back( m_iNumberOfModels );
379
380  m_iNumberOfModels++;
381}
382
383Void
384TRenModSetupStrParser::xError( Bool bIsError )
385{
386  if ( bIsError )
387  {
388    std::cout << "RenModel setup string invalid. Last character read: " << m_iPosInStr << std::endl;
389    AOF( false );
390    exit(0);
391  }
392}
393
394Void
395TRenModSetupStrParser::xGetViewNumberRange( std::vector<Int>& raiViewNumbers )
396{
397  size_t iStartPos;
398  size_t iEndPos;
399  TChar cChar;
400  xGetNextCharGoOn(cChar );
401  if (cChar == '{')
402  {
403    iStartPos = m_iPosInStr;
404    while( m_pchSetStr[m_iPosInStr] != '}' )
405    {
406      xError( m_iPosInStr == '\0' );
407      m_iPosInStr++;
408    }
409    iEndPos = m_iPosInStr - 1;
410    m_iPosInStr++;
411  }
412  else
413  {
414    iStartPos = m_iPosInStr - 1;
415    while( m_pchSetStr[m_iPosInStr] != ' ' && m_pchSetStr[m_iPosInStr] != ',' && m_pchSetStr[m_iPosInStr] != ')' )
416    {
417      xError( m_iPosInStr == '\0' );
418      m_iPosInStr++;
419    }
420    iEndPos = m_iPosInStr - 1;
421  }
422
423  size_t iNumElem = iEndPos - iStartPos + 1;
424  TChar* pcTempBuffer = new TChar[  iNumElem + 1];
425  strncpy( pcTempBuffer, m_pchSetStr + iStartPos, iNumElem );
426  pcTempBuffer[iNumElem] = '\0';
427
428  TAppComCamPara::convertNumberString( pcTempBuffer, raiViewNumbers, VIEW_NUM_PREC );
429  delete[] pcTempBuffer;
430}
431
432Void
433TRenModSetupStrParser::xGetNextCharGoOn( TChar& rcNextChar )
434{
435  while ( m_pchSetStr[m_iPosInStr] == ' ' || m_pchSetStr[m_iPosInStr] == ',' )
436  {
437    xError( m_pchSetStr[m_iPosInStr] == '\0' );
438    m_iPosInStr++;
439  }
440  rcNextChar = m_pchSetStr[m_iPosInStr];
441  m_iPosInStr++;
442}
443
444Void
445TRenModSetupStrParser::xGetNextChar( TChar& rcNextChar )
446{
447  size_t iPos = m_iPosInStr;
448  while ( ( m_pchSetStr[iPos] == ' ' || m_pchSetStr[iPos] == ',' ) && m_pchSetStr[iPos] != '\0' ) iPos++;
449  rcNextChar = m_pchSetStr[iPos];
450}
451#endif // NH_3D
452
Note: See TracBrowser for help on using the repository browser.