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