source: 3DVCSoftware/trunk/source/Lib/TLibRenderer/TRenModSetupStrParser.cpp @ 1327

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

Merged 14.1-update-dev1@1312.

  • Property svn:eol-style set to native
File size: 12.8 KB
RevLine 
[5]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 *
[1179]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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 */
[2]33
34
35#include "TRenImage.h"
36#include "TRenFilter.h"
37#include "TRenModSetupStrParser.h"
[608]38
[1313]39#if NH_3D
[2]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, Char* 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  Char 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  Char 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( Char cType )
252{
253  Char 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( Char cType )
275{
276  std::vector<Int> aiViewNums;
277  aiViewNums.clear();
278
279  switch ( cType )
280  {
281  case 'B':
282    Char cVideoType;
283    Char 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    Char 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, Char cVideoType, Char cDepthType )
331{
332  AOF( m_bCurrentViewSet );
333
334  if ( cDepthType == 'x' ) cDepthType = 'o';
335  if ( cVideoType == 'x' ) cVideoType = 'o';
336
337
338
339  xError( cDepthType != 'o' && cDepthType != 'c' && cVideoType != 'r' );
340  xError( cVideoType != 'o' && cVideoType != 'c' && cVideoType != 'r' );
341  m_aiAllBaseViewIdx.push_back( iViewIdx );
342  m_aaaiBaseViewsIdx  [m_iCurrentContent][m_iCurrentView].push_back( iViewIdx          );
343  m_aaaiVideoDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cVideoType == 'c' ) ? 2 : ( (cVideoType == 'r') ? 1 :  0 ) );
344  m_aaaiDepthDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cDepthType == 'c' ) ? 2 : ( (cDepthType == 'r') ? 1 :  0 ) );
345}
346
347Void
348TRenModSetupStrParser::xAddSynthView( Int iViewNum, Char cType, Char cRefType )
349{
350  AOF( m_bCurrentViewSet );
351
352  xError( cRefType != 's' && cRefType != 'o' );
353
354  m_aiAllSynthViewNums.push_back( iViewNum );
355
356  Int iBlendMode;
357  switch ( cType )
358  {
359  case 'E':
[100]360    iBlendMode = BLEND_NONE;
[2]361    break;
362  case 'I':
[100]363    iBlendMode = BLEND_AVRG;
[2]364    break;
365  case 'L':
[100]366    iBlendMode = BLEND_LEFT;
[2]367    break;
368  case 'R':
[100]369    iBlendMode = BLEND_RIGHT;
[2]370    break;
371  default:
372    xError(false);
373    break;
374  }
375
376  m_aaaiBlendMode    [m_iCurrentContent][m_iCurrentView].push_back( iBlendMode        );
377  m_aaaiSynthViewNums[m_iCurrentContent][m_iCurrentView].push_back( iViewNum          );
378  m_aaabExtrapolate  [m_iCurrentContent][m_iCurrentView].push_back( cType    == 'E'   );
379  m_aaabOrgRef       [m_iCurrentContent][m_iCurrentView].push_back( cRefType == 'o'   );
380  m_aaaiModelNums    [m_iCurrentContent][m_iCurrentView].push_back( m_iNumberOfModels );
381
382  m_iNumberOfModels++;
383}
384
385Void
386TRenModSetupStrParser::xError( Bool bIsError )
387{
388  if ( bIsError )
389  {
390    std::cout << "RenModel setup string invalid. Last character read: " << m_iPosInStr << std::endl;
391    AOF( false );
392    exit(0);
393  }
394}
395
396Void
397TRenModSetupStrParser::xGetViewNumberRange( std::vector<Int>& raiViewNumbers )
398{
399  size_t iStartPos;
400  size_t iEndPos;
401  Char cChar;
402  xGetNextCharGoOn(cChar );
403  if (cChar == '{')
404  {
405    iStartPos = m_iPosInStr;
406    while( m_pchSetStr[m_iPosInStr] != '}' )
407    {
408      xError( m_iPosInStr == '\0' );
409      m_iPosInStr++;
410    }
411    iEndPos = m_iPosInStr - 1;
412    m_iPosInStr++;
413  }
414  else
415  {
416    iStartPos = m_iPosInStr - 1;
417    while( m_pchSetStr[m_iPosInStr] != ' ' && m_pchSetStr[m_iPosInStr] != ',' && m_pchSetStr[m_iPosInStr] != ')' )
418    {
419      xError( m_iPosInStr == '\0' );
420      m_iPosInStr++;
421    }
422    iEndPos = m_iPosInStr - 1;
423  }
424
425  size_t iNumElem = iEndPos - iStartPos + 1;
426  Char* pcTempBuffer = new Char[  iNumElem + 1];
427  strncpy( pcTempBuffer, m_pchSetStr + iStartPos, iNumElem );
428  pcTempBuffer[iNumElem] = '\0';
429
430  TAppComCamPara::convertNumberString( pcTempBuffer, raiViewNumbers, VIEW_NUM_PREC );
431  delete[] pcTempBuffer;
432}
433
434Void
435TRenModSetupStrParser::xGetNextCharGoOn( Char& rcNextChar )
436{
437  while ( m_pchSetStr[m_iPosInStr] == ' ' || m_pchSetStr[m_iPosInStr] == ',' )
438  {
439    xError( m_pchSetStr[m_iPosInStr] == '\0' );
440    m_iPosInStr++;
441  }
442  rcNextChar = m_pchSetStr[m_iPosInStr];
443  m_iPosInStr++;
444}
445
446Void
447TRenModSetupStrParser::xGetNextChar( Char& rcNextChar )
448{
449  size_t iPos = m_iPosInStr;
450  while ( ( m_pchSetStr[iPos] == ' ' || m_pchSetStr[iPos] == ',' ) && m_pchSetStr[iPos] != '\0' ) iPos++;
451  rcNextChar = m_pchSetStr[iPos];
452}
[1313]453#endif // NH_3D
[210]454
Note: See TracBrowser for help on using the repository browser.