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