[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 | * |
---|
| 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 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
| 35 | |
---|
[5] | 36 | |
---|
[2] | 37 | // Include files |
---|
| 38 | #include "TAppComCamPara.h" |
---|
| 39 | |
---|
| 40 | #include <math.h> |
---|
| 41 | #include <errno.h> |
---|
| 42 | #include <vector> |
---|
| 43 | #include <iostream> |
---|
| 44 | #include <fstream> |
---|
| 45 | #include <algorithm> |
---|
| 46 | #include <functional> |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | Void |
---|
| 52 | TAppComCamPara::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ) |
---|
| 53 | { |
---|
| 54 | AOF( m_uiBitDepthForLUT == 8 ); |
---|
| 55 | AOF( radShiftParams == NULL && raiShiftParams == NULL && radLUT == NULL && raiLUT == NULL ); |
---|
| 56 | |
---|
| 57 | uiNumberSourceViews = Max( 1, uiNumberSourceViews ); |
---|
| 58 | uiNumberTargetViews = Max( 1, uiNumberTargetViews ); |
---|
| 59 | |
---|
| 60 | radShiftParams = new Double** [ uiNumberSourceViews ]; |
---|
| 61 | raiShiftParams = new Int64 ** [ uiNumberSourceViews ]; |
---|
| 62 | radLUT = new Double***[ uiNumberSourceViews ]; |
---|
| 63 | raiLUT = new Int ***[ uiNumberSourceViews ]; |
---|
| 64 | |
---|
| 65 | for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) |
---|
| 66 | { |
---|
| 67 | radShiftParams[ uiSourceView ] = new Double* [ uiNumberTargetViews ]; |
---|
| 68 | raiShiftParams[ uiSourceView ] = new Int64 * [ uiNumberTargetViews ]; |
---|
| 69 | radLUT [ uiSourceView ] = new Double**[ uiNumberTargetViews ]; |
---|
| 70 | raiLUT [ uiSourceView ] = new Int **[ uiNumberTargetViews ]; |
---|
| 71 | |
---|
| 72 | for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ ) |
---|
| 73 | { |
---|
| 74 | radShiftParams[ uiSourceView ][ uiTargetView ] = new Double [ 2 ]; |
---|
| 75 | raiShiftParams[ uiSourceView ][ uiTargetView ] = new Int64 [ 2 ]; |
---|
| 76 | |
---|
| 77 | radLUT [ uiSourceView ][ uiTargetView ] = new Double*[ 2 ]; |
---|
[28] | 78 | radLUT [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ SizeOfLUT+1 ]; |
---|
| 79 | radLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ SizeOfLUT+1 ]; |
---|
[2] | 80 | |
---|
| 81 | raiLUT [ uiSourceView ][ uiTargetView ] = new Int* [ 2 ]; |
---|
[28] | 82 | raiLUT [ uiSourceView ][ uiTargetView ][ 0 ] = new Int [ SizeOfLUT+1 ]; |
---|
| 83 | raiLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Int [ SizeOfLUT+1 ]; |
---|
[2] | 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | Void |
---|
| 90 | TAppComCamPara::xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray ) |
---|
| 91 | { |
---|
| 92 | AOT( raaiArray || uiNum1Ids == 0 || uiNum2Ids == 0 ); |
---|
| 93 | raaiArray = new Int* [ uiNum1Ids ]; |
---|
| 94 | for( UInt uiId1 = 0; uiId1 < uiNum1Ids; uiId1++ ) |
---|
| 95 | { |
---|
| 96 | raaiArray[ uiId1 ] = new Int [ uiNum2Ids ]; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | Void |
---|
| 102 | TAppComCamPara::xInit2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray, Int iValue ) |
---|
| 103 | { |
---|
| 104 | for( UInt uiId1 = 0; uiId1 < uiNum1Ids; uiId1++ ) |
---|
| 105 | { |
---|
| 106 | for( UInt uiId2 = 0; uiId2 < uiNum2Ids; uiId2++ ) |
---|
| 107 | { |
---|
| 108 | raaiArray[ uiId1 ][ uiId2 ] = iValue; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | Void |
---|
| 115 | TAppComCamPara::convertNumberString( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec ) |
---|
| 116 | { |
---|
| 117 | Bool bStringIsRange = false; |
---|
| 118 | Int iIdx = 0; |
---|
| 119 | std::vector<Double> adViewNumbers; |
---|
| 120 | |
---|
| 121 | while( pchViewNumberString != 0 && pchViewNumberString[ iIdx ] != 0 ) |
---|
| 122 | { |
---|
| 123 | if( pchViewNumberString[ iIdx ] == ':' ) |
---|
| 124 | { |
---|
| 125 | bStringIsRange = true; |
---|
| 126 | pchViewNumberString[ iIdx ] = ' '; |
---|
| 127 | } |
---|
| 128 | iIdx++; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | Char* pcNextStart = pchViewNumberString; |
---|
| 132 | Char* pcEnd = pcNextStart + iIdx; |
---|
| 133 | Char* pcOldStart = 0; |
---|
| 134 | |
---|
| 135 | while( pcNextStart < pcEnd ) |
---|
| 136 | { |
---|
| 137 | errno = 0; |
---|
| 138 | adViewNumbers.push_back( ( strtod( pcNextStart, &pcNextStart ) ) ); |
---|
| 139 | |
---|
| 140 | if( errno == ERANGE || pcNextStart == pcOldStart ) |
---|
| 141 | { |
---|
| 142 | std::cerr << "Error Parsing View Number String: `" << pchViewNumberString << "'" << std::endl; |
---|
| 143 | AOT(true); |
---|
| 144 | exit( EXIT_FAILURE ); |
---|
| 145 | }; |
---|
| 146 | |
---|
| 147 | while( pcNextStart < pcEnd && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++; |
---|
| 148 | |
---|
| 149 | pcOldStart = pcNextStart; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | if( bStringIsRange ) |
---|
| 153 | { |
---|
| 154 | if( adViewNumbers.size() != 3 ) |
---|
| 155 | { |
---|
| 156 | std::cerr << "Error Parsing SynthViewNumbers: `" << pchViewNumberString << "'" << std::endl; |
---|
| 157 | AOT(true); |
---|
| 158 | exit( EXIT_FAILURE ); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | Double dRangeBegin = adViewNumbers[0]; |
---|
| 162 | Double dRangeStep = adViewNumbers[1]; |
---|
| 163 | Double dRangeEnd = adViewNumbers[2]; |
---|
| 164 | |
---|
| 165 | if( ( ( dRangeEnd - dRangeBegin > 0 ) != ( dRangeStep > 0 ) ) || dRangeStep == 0 ) |
---|
| 166 | { |
---|
| 167 | std::cerr << "Error Parsing SynthViewNumbers: `" << pchViewNumberString << "'" << std::endl; |
---|
| 168 | AOT(true); |
---|
| 169 | exit( EXIT_FAILURE ); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | raiViewNumbers.clear(); |
---|
| 173 | |
---|
| 174 | Double dFac = ( dRangeBegin > dRangeEnd ? -1 : 1 ); |
---|
| 175 | |
---|
| 176 | for( Double dViewNumber = dRangeBegin; ( dViewNumber - dRangeEnd ) * dFac <= 0; dViewNumber += dRangeStep ) |
---|
| 177 | { |
---|
| 178 | raiViewNumbers.push_back( (Int)( dViewNumber * dViewNumPrec ) ); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | for( UInt uiViewNum = 0; uiViewNum < adViewNumbers.size(); uiViewNum++ ) |
---|
| 184 | { |
---|
| 185 | raiViewNumbers.push_back( (Int)( adViewNumbers[ uiViewNum ] * dViewNumPrec ) ); |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | Void |
---|
| 192 | TAppComCamPara::xReadCameraParameterFile( Char* pchCfgFileName ) |
---|
| 193 | { |
---|
| 194 | std::ifstream cCfgStream( pchCfgFileName, std::ifstream::in ); |
---|
| 195 | if( !cCfgStream ) |
---|
| 196 | { |
---|
| 197 | std::cerr << "Failed to open config file: `" << pchCfgFileName << "'" << std::endl; |
---|
| 198 | exit( EXIT_FAILURE ); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | Int iLineNumber = 0; |
---|
| 202 | do |
---|
| 203 | { |
---|
| 204 | std::string cLine; |
---|
| 205 | getline( cCfgStream, cLine ); |
---|
| 206 | iLineNumber++; |
---|
| 207 | |
---|
| 208 | size_t iStart = cLine.find_first_not_of( " \t\n\r" ); |
---|
| 209 | |
---|
| 210 | if( iStart == std::string::npos ) |
---|
| 211 | { |
---|
| 212 | continue; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | if( cLine[iStart] == '#' ) |
---|
| 216 | { |
---|
| 217 | continue; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | Char* pcNextStart = (Char*) cLine.data(); |
---|
| 221 | Char* pcEnd = pcNextStart + cLine.length(); |
---|
| 222 | |
---|
| 223 | std::vector<Double> caNewLine; |
---|
| 224 | caNewLine.clear(); |
---|
| 225 | |
---|
| 226 | Char* pcOldStart = 0; |
---|
| 227 | while( pcNextStart < pcEnd ) |
---|
| 228 | { |
---|
| 229 | errno = 0; |
---|
| 230 | caNewLine.push_back( strtod( pcNextStart, &pcNextStart ) ) ; |
---|
| 231 | |
---|
| 232 | if( errno == ERANGE || ( pcNextStart == pcOldStart ) ) |
---|
| 233 | { |
---|
| 234 | std::cerr << "Failed reading config file: `" << pchCfgFileName << "' Error parsing double values in Line: " << iLineNumber << ' ' << std::endl; |
---|
| 235 | assert( 0 ); |
---|
| 236 | exit( EXIT_FAILURE ); |
---|
| 237 | }; |
---|
| 238 | pcOldStart = pcNextStart; |
---|
| 239 | |
---|
| 240 | while( ( pcNextStart < pcEnd ) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | if ( ( caNewLine.size() != 2 ) && ( caNewLine.size() != 7 ) && ( caNewLine.size() != 6 ) && ( caNewLine.size() != 8 ) ) |
---|
| 244 | { |
---|
| 245 | std::cerr << "Failed reading config file: `" << pchCfgFileName << "'" << std::endl; |
---|
| 246 | std::cerr << "Invalid number of entries" << std::endl; |
---|
| 247 | AOF(false); |
---|
| 248 | exit( EXIT_FAILURE ); |
---|
| 249 | } |
---|
| 250 | m_aadCameraParameters.push_back( caNewLine ); |
---|
| 251 | } |
---|
| 252 | while( cCfgStream ); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | Void |
---|
| 256 | TAppComCamPara::xGetCodedCameraData( UInt uiSourceView, UInt uiTargetView, Bool bByIdx, UInt uiFrame, Int& riScale, Int& riOffset, Int& riPrecision ) |
---|
| 257 | { |
---|
| 258 | if( bByIdx ) |
---|
| 259 | { |
---|
| 260 | uiSourceView = m_aiBaseViews[ uiSourceView ]; |
---|
| 261 | uiTargetView = m_aiBaseViews[ uiTargetView ]; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | Int iFoundLine = -1; |
---|
| 265 | for( UInt uiCurViewLine = 0; uiCurViewLine < m_aadCameraParameters.size(); uiCurViewLine++ ) |
---|
| 266 | { |
---|
| 267 | if ( m_aadCameraParameters[uiCurViewLine].size() == 2 ) |
---|
| 268 | continue; |
---|
| 269 | |
---|
| 270 | if( ( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 3 ] * m_dViewNumPrec ) == uiSourceView ) |
---|
| 271 | && ( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 2 ] * m_dViewNumPrec ) == uiTargetView ) |
---|
| 272 | ) |
---|
| 273 | { |
---|
| 274 | if( ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 0 ] <= uiFrame ) && ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 1 ] >= uiFrame ) ) |
---|
| 275 | { |
---|
| 276 | if( iFoundLine != -1 ) |
---|
| 277 | { |
---|
| 278 | std::cerr << "Error CameraParameters for SourceView " << (Double) uiSourceView / m_dViewNumPrec << " and Target View " << (Double) uiTargetView / m_dViewNumPrec << " and Frame " << uiFrame << " given multiple times." << std::endl; |
---|
| 279 | AOT(true); |
---|
| 280 | exit( EXIT_FAILURE ); |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | { |
---|
| 284 | iFoundLine = uiCurViewLine; |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | if ( iFoundLine == -1 ) |
---|
| 291 | { |
---|
| 292 | std::cerr << "Error CameraParameters for SourceView " << (Double) uiSourceView / m_dViewNumPrec << " and Target View " << (Double) uiTargetView / m_dViewNumPrec << " and Frame " << uiFrame << " not found." << std::endl; |
---|
| 293 | AOT(true); |
---|
| 294 | exit( EXIT_FAILURE ); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | riScale = (Int)( m_aadCameraParameters[ iFoundLine ][ 4 ] ); |
---|
| 298 | riOffset = (Int)( m_aadCameraParameters[ iFoundLine ][ 5 ] ); |
---|
| 299 | riPrecision = (Int)( m_aadCameraParameters[ iFoundLine ][ 6 ] ); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | Bool |
---|
| 303 | TAppComCamPara::xGetCameraDataRow( Int iView, UInt uiFrame, UInt& ruiFoundLine ) |
---|
| 304 | { |
---|
| 305 | ruiFoundLine = -1; |
---|
| 306 | for( UInt uiCurViewLine = 0; uiCurViewLine < m_aadCameraParameters.size(); uiCurViewLine++ ) |
---|
| 307 | { |
---|
| 308 | if( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 0 ] * m_dViewNumPrec ) == iView ) |
---|
| 309 | { |
---|
| 310 | if( ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 1 ] <= uiFrame ) && ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 2 ] >= uiFrame ) ) |
---|
| 311 | { |
---|
| 312 | if( ruiFoundLine != -1 ) |
---|
| 313 | { |
---|
| 314 | std::cerr << "Error CameraParameters for View " << (Double) iView / m_dViewNumPrec << " and Frame " << uiFrame << " given multiple times." << std::endl; |
---|
| 315 | exit( EXIT_FAILURE ); |
---|
| 316 | } |
---|
| 317 | else |
---|
| 318 | { |
---|
| 319 | ruiFoundLine = uiCurViewLine; |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | return ( ruiFoundLine == -1 ); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | |
---|
| 328 | Void |
---|
| 329 | TAppComCamPara::xGetSortedViewList( const std::vector<Int>& raiViews, std::vector<Int>& raiSortedViews, std::vector<Int>& raiId2SortedId, std::vector<Int>& raiSortedId2Id ) |
---|
| 330 | { |
---|
| 331 | AOF( raiViews.size() > 0 ); |
---|
| 332 | Int iNumViews = (Int)raiViews.size(); |
---|
| 333 | raiId2SortedId = std::vector<Int>( raiViews.size(), -1 ); |
---|
| 334 | raiSortedId2Id.clear(); |
---|
| 335 | raiSortedViews.clear(); |
---|
| 336 | for( Int iSortId = 0; iSortId < iNumViews; iSortId++ ) |
---|
| 337 | { |
---|
| 338 | Int iLeftMostBaseId = -1; |
---|
| 339 | for( Int iBaseId = 0; iLeftMostBaseId == -1 && iBaseId < iNumViews; iBaseId++ ) |
---|
| 340 | { |
---|
| 341 | if( raiId2SortedId[ iBaseId ] == -1 ) |
---|
| 342 | { |
---|
| 343 | UInt uiFoundLine = -1; |
---|
| 344 | xGetCameraDataRow( raiViews[ iBaseId ], 0, uiFoundLine ); |
---|
| 345 | AOT( uiFoundLine == -1 ); // something wrong |
---|
| 346 | Double dXPos = m_aadCameraParameters[ uiFoundLine ][ 4 ]; |
---|
| 347 | Double dZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ]; |
---|
| 348 | Double dZFar = m_aadCameraParameters[ uiFoundLine ][ 7 ]; |
---|
| 349 | Double dSign = ( dZFar > 0 ? 1.0 : -1.0 ); |
---|
| 350 | Bool bLeftMost = true; |
---|
| 351 | AOF( dZNear * dZFar > 0.0 ); // otherwise, z parameters are not correct |
---|
| 352 | |
---|
| 353 | for( Int iTestBaseId = 0; bLeftMost && iTestBaseId < iNumViews; iTestBaseId++ ) |
---|
| 354 | { |
---|
| 355 | if( iTestBaseId != iBaseId && raiId2SortedId[ iTestBaseId ] == -1 ) |
---|
| 356 | { |
---|
| 357 | UInt uiFoundLineTest = -1; |
---|
| 358 | xGetCameraDataRow( raiViews[ iTestBaseId ], 0, uiFoundLineTest ); |
---|
| 359 | AOT( uiFoundLineTest == -1 ); // something wrong |
---|
| 360 | Double dXPosTest = m_aadCameraParameters[ uiFoundLineTest ][ 4 ]; |
---|
| 361 | Double dZNearTest = m_aadCameraParameters[ uiFoundLineTest ][ 6 ]; |
---|
| 362 | Double dZFarTest = m_aadCameraParameters[ uiFoundLineTest ][ 7 ]; |
---|
| 363 | AOF( dZNearTest * dZFarTest > 0.0 ); // otherwise, z parameters are not correct |
---|
| 364 | AOF( dZNearTest * dSign > 0.0 ); // otherwise, z parameters are not consistent |
---|
| 365 | Double dDeltaXPos = dSign * ( dXPosTest - dXPos ); |
---|
| 366 | bLeftMost = ( bLeftMost && dDeltaXPos > 0.0 ); |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | if( bLeftMost ) |
---|
| 370 | { |
---|
| 371 | iLeftMostBaseId = iBaseId; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | AOT( iLeftMostBaseId == -1 ); // something wrong |
---|
| 376 | raiId2SortedId[ iLeftMostBaseId ] = iSortId; |
---|
| 377 | raiSortedId2Id.push_back( iLeftMostBaseId ); |
---|
| 378 | raiSortedViews.push_back( raiViews[ iLeftMostBaseId ] ); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | // sanity check |
---|
| 382 | if( iNumViews > 2 ) |
---|
| 383 | { |
---|
| 384 | Int iDeltaView = gSign( raiSortedViews[ 1 ] - raiSortedViews[ 0 ] ); |
---|
| 385 | Bool bOutOfOrder = false; |
---|
| 386 | for( Int iSIdx = 2; iSIdx < iNumViews; iSIdx++ ) |
---|
| 387 | { |
---|
| 388 | bOutOfOrder = ( bOutOfOrder || iDeltaView * gSign( raiSortedViews[ iSIdx ] - raiSortedViews[ iSIdx - 1 ] ) < 0 ); |
---|
| 389 | } |
---|
| 390 | if( bOutOfOrder ) |
---|
| 391 | { |
---|
| 392 | std::cerr << "ERROR: View numbering must be strictly increasing or decreasing from left to right" << std::endl; |
---|
| 393 | exit(EXIT_FAILURE); |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | |
---|
| 399 | Void |
---|
| 400 | TAppComCamPara::xGetViewOrderIndices( const std::vector<Int>& raiId2SortedId, std::vector<Int>& raiVOIdx ) |
---|
| 401 | { |
---|
| 402 | AOF( raiId2SortedId.size() ); |
---|
| 403 | raiVOIdx = raiId2SortedId; |
---|
| 404 | Int iSize = (Int)raiId2SortedId.size(); |
---|
| 405 | Int iOffs = raiId2SortedId[ 0 ]; |
---|
| 406 | for( Int iIdx = 0; iIdx < iSize; iIdx++ ) |
---|
| 407 | { |
---|
| 408 | raiVOIdx[ iIdx ] -= iOffs; |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | |
---|
| 413 | Bool |
---|
| 414 | TAppComCamPara::xGetCamParsChangeFlag() |
---|
| 415 | { |
---|
| 416 | Bool bChangeDetected = false; |
---|
| 417 | for( Int iBaseViewId = 0; !bChangeDetected && iBaseViewId < m_iNumberOfBaseViews; iBaseViewId++ ) |
---|
| 418 | { |
---|
| 419 | if ( m_bSetupFromCoded ) |
---|
| 420 | { |
---|
| 421 | for( Int iTargetViewId = 0; !bChangeDetected && iTargetViewId < m_iNumberOfBaseViews; iTargetViewId++ ) |
---|
| 422 | { |
---|
| 423 | Int iTargetView = m_aiBaseViews[iTargetViewId]; |
---|
| 424 | Int iSourceView = m_aiBaseViews[iBaseViewId ]; |
---|
| 425 | |
---|
| 426 | Int iS1 ,iSX; |
---|
| 427 | Int iO1 ,iOX; |
---|
| 428 | Int iP1 ,iPX; |
---|
| 429 | |
---|
| 430 | if ( iSourceView == iTargetView ) |
---|
| 431 | continue; |
---|
| 432 | |
---|
| 433 | xGetCodedCameraData( iSourceView, iTargetView, false, 0, iS1, iO1, iP1 ); |
---|
| 434 | for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ ) |
---|
| 435 | { |
---|
| 436 | xGetCodedCameraData( iSourceView, iTargetView, false, uiFrameId, iSX, iOX, iPX ); |
---|
| 437 | |
---|
| 438 | if( iS1 != iSX || iO1 != iOX || iP1 != iPX ) |
---|
| 439 | { |
---|
| 440 | bChangeDetected = true; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | else |
---|
| 446 | { |
---|
| 447 | Int iBaseView = m_aiBaseViews[ iBaseViewId ]; |
---|
| 448 | Double dFL1, dFLX; |
---|
| 449 | Double dCP1, dCPX; |
---|
| 450 | Double dCS1, dCSX; |
---|
| 451 | Double dZN1, dZNX; |
---|
| 452 | Double dZF1, dZFX; |
---|
| 453 | Bool bInterpolated; |
---|
| 454 | xGetGeometryData( iBaseView, m_uiFirstFrameId, dFL1, dCP1, dCS1, bInterpolated ); AOT( bInterpolated ); |
---|
| 455 | xGetZNearZFar ( iBaseView, m_uiFirstFrameId, dZN1, dZF1 ); |
---|
| 456 | |
---|
| 457 | for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ ) |
---|
| 458 | { |
---|
| 459 | xGetGeometryData( iBaseView, uiFrameId, dFLX, dCPX, dCSX, bInterpolated ); AOT( bInterpolated ); |
---|
| 460 | xGetZNearZFar ( iBaseView, uiFrameId, dZNX, dZFX ); |
---|
| 461 | |
---|
| 462 | if( dFL1 != dFLX || dCP1 != dCPX || dCS1 != dCSX || dZN1 != dZNX || dZF1 != dZFX ) |
---|
| 463 | { |
---|
| 464 | bChangeDetected = true; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | return bChangeDetected; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | Int |
---|
| 473 | TAppComCamPara::xGetViewId( std::vector<Int> aiViewList, Int iBaseView ) |
---|
| 474 | { |
---|
| 475 | Int iViewId = -1; |
---|
| 476 | for( Int iId = 0; iId < (Int)aiViewList.size(); iId++ ) |
---|
| 477 | { |
---|
| 478 | if( aiViewList[ iId ] == iBaseView ) |
---|
| 479 | { |
---|
| 480 | iViewId = iId; |
---|
| 481 | break; |
---|
| 482 | } |
---|
| 483 | } |
---|
| 484 | AOT( iViewId == -1 ); |
---|
| 485 | return iViewId; |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | Int |
---|
| 489 | TAppComCamPara::xGetBaseViewId( Int iBaseView ) |
---|
| 490 | { |
---|
| 491 | return xGetViewId( m_aiBaseViews, iBaseView ); |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | |
---|
| 495 | Bool |
---|
| 496 | TAppComCamPara::xGetLeftRightView( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx ) |
---|
| 497 | { |
---|
| 498 | Bool bFoundLRView = false; |
---|
| 499 | Int iLeftView = -1; |
---|
| 500 | Int iRightView = -1; |
---|
| 501 | Int iLeftViewIdx = -1; |
---|
| 502 | Int iRightViewIdx = -1; |
---|
| 503 | Bool bDecencdingVN = ( aiSortedViews.size() >= 2 && aiSortedViews[ 0 ] > aiSortedViews[ 1 ] ); |
---|
| 504 | Int iFactor = ( bDecencdingVN ? -1 : 1 ); |
---|
| 505 | |
---|
| 506 | for( Int iIdx = -1; iIdx < (Int)aiSortedViews.size(); iIdx++ ) |
---|
| 507 | { |
---|
| 508 | if( iIdx == -1 ) |
---|
| 509 | { |
---|
| 510 | if( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor > 0 ) |
---|
| 511 | { |
---|
| 512 | bFoundLRView = false; |
---|
| 513 | iLeftView = -1; |
---|
| 514 | iRightView = aiSortedViews[ iIdx + 1 ]; |
---|
| 515 | iLeftViewIdx = -1; |
---|
| 516 | iRightViewIdx = iIdx + 1; |
---|
| 517 | break; |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | else if ( iIdx == (Int)aiSortedViews.size() - 1 ) |
---|
| 521 | { |
---|
| 522 | if( ( aiSortedViews[ iIdx ] - iView ) * iFactor < 0 ) |
---|
| 523 | { |
---|
| 524 | bFoundLRView = false; |
---|
| 525 | iLeftView = aiSortedViews[ iIdx ]; |
---|
| 526 | iRightView = -1; |
---|
| 527 | iLeftViewIdx = iIdx; |
---|
| 528 | iRightViewIdx = -1; |
---|
| 529 | break; |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | else |
---|
| 533 | { |
---|
| 534 | if( ( ( aiSortedViews[ iIdx ] - iView ) * iFactor <= 0 ) && ( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor >= 0 ) ) |
---|
| 535 | { |
---|
| 536 | bFoundLRView = true; |
---|
| 537 | iLeftView = aiSortedViews[ iIdx ]; |
---|
| 538 | iRightView = aiSortedViews[ iIdx + 1 ]; |
---|
| 539 | iLeftViewIdx = iIdx; |
---|
| 540 | iRightViewIdx = iIdx + 1; |
---|
| 541 | break; |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | if ( ( iView == iLeftView ) || ( iView == iRightView ) ) |
---|
| 547 | { |
---|
| 548 | iLeftViewIdx = ( iView == iLeftView ) ? iLeftViewIdx : iRightViewIdx; |
---|
| 549 | iRightViewIdx = iLeftViewIdx; |
---|
| 550 | iLeftView = iView; |
---|
| 551 | iRightView = iView; |
---|
| 552 | bFoundLRView = false; |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | riLeftView = iLeftView; |
---|
| 556 | riRightView = iRightView; |
---|
| 557 | riLeftSortedViewIdx = iLeftViewIdx; |
---|
| 558 | riRightSortedViewIdx = iRightViewIdx; |
---|
| 559 | |
---|
| 560 | return bFoundLRView; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | |
---|
| 564 | Void |
---|
| 565 | TAppComCamPara::xGetPrevAndNextBaseView( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum ) |
---|
| 566 | { |
---|
| 567 | Int iLeftView; |
---|
| 568 | Int iRightView; |
---|
| 569 | Int iDummy; |
---|
| 570 | xGetLeftRightView( iTargetViewNum, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ); |
---|
| 571 | |
---|
| 572 | if( iLeftView == iRightView ) |
---|
| 573 | { |
---|
| 574 | riPrevBaseViewNum = iLeftView; |
---|
| 575 | riNextBaseViewNum = iLeftView; |
---|
| 576 | } |
---|
| 577 | else |
---|
| 578 | { |
---|
| 579 | Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] ); |
---|
| 580 | Bool bNextViewIsLeft = ( bDecencdingVN ? ( iSourceViewNum < iTargetViewNum ) : ( iSourceViewNum > iTargetViewNum ) ); |
---|
| 581 | if ( bNextViewIsLeft ) |
---|
| 582 | { |
---|
| 583 | riPrevBaseViewNum = iRightView; |
---|
| 584 | riNextBaseViewNum = iLeftView; |
---|
| 585 | } |
---|
| 586 | else |
---|
| 587 | { |
---|
| 588 | riPrevBaseViewNum = iLeftView; |
---|
| 589 | riNextBaseViewNum = iRightView; |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | |
---|
| 595 | Void |
---|
| 596 | TAppComCamPara::xGetZNearZFar( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar ) |
---|
| 597 | { |
---|
| 598 | UInt uiFoundLine = -1; |
---|
| 599 | if( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) || !( m_aadCameraParameters[ uiFoundLine ].size() < 8 ) ) |
---|
| 600 | { |
---|
| 601 | rdZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ]; |
---|
| 602 | rdZFar = m_aadCameraParameters[ uiFoundLine ][ 7 ]; |
---|
| 603 | } |
---|
| 604 | else |
---|
| 605 | { |
---|
| 606 | std::cerr << "No ZNear or no ZFar for View " << (Double)iView / m_dViewNumPrec << " and Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
| 607 | exit( EXIT_FAILURE ); |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | |
---|
| 612 | Void |
---|
| 613 | TAppComCamPara::xGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ) |
---|
| 614 | { |
---|
| 615 | UInt uiFoundLine = -1; |
---|
| 616 | if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) ) |
---|
| 617 | { |
---|
| 618 | AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 ); |
---|
| 619 | rbInterpolated = false; |
---|
| 620 | rdFocalLength = m_aadCameraParameters[ uiFoundLine ][ 3 ]; |
---|
| 621 | rdPosition = m_aadCameraParameters[ uiFoundLine ][ 4 ]; |
---|
| 622 | rdCameraShift = m_aadCameraParameters[ uiFoundLine ][ 5 ]; |
---|
| 623 | } |
---|
| 624 | else |
---|
| 625 | { |
---|
| 626 | UInt uiLeftViewLine; |
---|
| 627 | UInt uiRightViewLine; |
---|
| 628 | Int iLeftView; |
---|
| 629 | Int iRightView; |
---|
| 630 | Int iDummy; |
---|
| 631 | |
---|
| 632 | if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) || |
---|
| 633 | xGetCameraDataRow( iLeftView, uiFrame, uiLeftViewLine ) || |
---|
| 634 | xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine ) |
---|
| 635 | ) |
---|
| 636 | { |
---|
| 637 | std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
| 638 | AOT(true); |
---|
| 639 | exit( EXIT_FAILURE ); |
---|
| 640 | } |
---|
| 641 | AOT( m_aadCameraParameters[ uiLeftViewLine ].size() < 6 ); |
---|
| 642 | AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 ); |
---|
| 643 | |
---|
| 644 | // Linear Interpolation |
---|
| 645 | Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) ); |
---|
| 646 | rdFocalLength = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] ); |
---|
| 647 | rdPosition = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] ); |
---|
| 648 | rdCameraShift = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] ); |
---|
| 649 | rbInterpolated = true; |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | |
---|
| 654 | Bool |
---|
| 655 | TAppComCamPara::xGetShiftParameterReal( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset ) |
---|
| 656 | { |
---|
| 657 | AOT( m_bSetupFromCoded ); |
---|
| 658 | |
---|
| 659 | Bool bInterpolatedSource; |
---|
| 660 | Double dMinDepthSource; |
---|
| 661 | Double dMaxDepthSource; |
---|
| 662 | Double dFocalLengthSource; |
---|
| 663 | Double dPositionSource; |
---|
| 664 | Double dIntersectionSource; |
---|
| 665 | |
---|
| 666 | Bool bInterpolatedTarget; |
---|
| 667 | Double dPositionTarget; |
---|
| 668 | Double dIntersectionTarget; |
---|
| 669 | Double dFocalLengthTarget; |
---|
| 670 | |
---|
| 671 | Int iTargetViewNum; |
---|
| 672 | Int iSourceViewNum; |
---|
| 673 | |
---|
| 674 | if( bByIdx ) |
---|
| 675 | { |
---|
| 676 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 677 | iTargetViewNum = ( bExternal ? m_aiSynthViews[ uiTargetView ] : m_aiBaseViews[ uiTargetView ] ); |
---|
| 678 | } |
---|
| 679 | else |
---|
| 680 | { |
---|
| 681 | iSourceViewNum = (Int) uiSourceView; |
---|
| 682 | iTargetViewNum = (Int) uiTargetView; |
---|
| 683 | } |
---|
| 684 | |
---|
| 685 | xGetGeometryData( iSourceViewNum, uiFrame, dFocalLengthSource, dPositionSource, dIntersectionSource, bInterpolatedSource ); |
---|
| 686 | xGetZNearZFar ( iSourceViewNum, uiFrame, dMinDepthSource, dMaxDepthSource ); |
---|
| 687 | xGetGeometryData( iTargetViewNum, uiFrame, dFocalLengthTarget, dPositionTarget, dIntersectionTarget, bInterpolatedTarget ); |
---|
| 688 | |
---|
| 689 | Double dFactor = dFocalLengthSource * ( dPositionTarget - dPositionSource ); |
---|
| 690 | rdScale = dFactor * ( 1.0 / dMinDepthSource - 1.0 / dMaxDepthSource ) / (Double)( ( 1 << m_uiInputBitDepth ) - 1 ); |
---|
| 691 | rdOffset = dFactor / dMaxDepthSource - dIntersectionTarget + dIntersectionSource; |
---|
| 692 | |
---|
| 693 | return ( bInterpolatedSource || bInterpolatedTarget ); |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | |
---|
| 697 | Void |
---|
| 698 | TAppComCamPara::xGetShiftParameterCoded( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bByIdx, Int& riScale, Int& riOffset ) |
---|
| 699 | { |
---|
| 700 | if ( m_bSetupFromCoded ) |
---|
| 701 | { |
---|
| 702 | if ( uiSourceView == uiTargetView ) |
---|
| 703 | { |
---|
| 704 | riScale = 0; |
---|
| 705 | riOffset = 0; |
---|
| 706 | return; |
---|
| 707 | } |
---|
| 708 | Int iCamParsCodedPrecision; |
---|
| 709 | xGetCodedCameraData( uiSourceView, uiTargetView, bByIdx, uiFrame, riScale, riOffset, iCamParsCodedPrecision ); |
---|
| 710 | |
---|
| 711 | if ( m_bCamParsCodedPrecSet ) |
---|
| 712 | { |
---|
| 713 | AOT( m_uiCamParsCodedPrecision != (UInt) iCamParsCodedPrecision ); |
---|
| 714 | } |
---|
| 715 | else |
---|
| 716 | { |
---|
| 717 | m_uiCamParsCodedPrecision = (UInt) iCamParsCodedPrecision; |
---|
| 718 | m_bCamParsCodedPrecSet = true; |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | else |
---|
| 722 | { |
---|
| 723 | Double dScale, dOffset; |
---|
| 724 | Bool bInterpolated = xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, false, bByIdx, dScale, dOffset ); |
---|
| 725 | AOT( bInterpolated ); // must be base view |
---|
| 726 | |
---|
| 727 | Double dMultOffset = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 ) ); |
---|
| 728 | Double dMultScale = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 + m_uiInputBitDepth ) ); |
---|
| 729 | riOffset = (Int)floor( dMultOffset * dOffset + .5 ); |
---|
| 730 | riScale = (Int)floor( dMultScale * dScale + .5 ); |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | |
---|
| 736 | Void |
---|
| 737 | TAppComCamPara::xGetShiftParameterInt( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64& riScale, Int64& riOffset ) |
---|
| 738 | { |
---|
| 739 | Int iTargetViewNum; |
---|
| 740 | Int iSourceViewNum; |
---|
| 741 | Int iPrevBaseViewNum; |
---|
| 742 | Int iNextBaseViewNum; |
---|
| 743 | Int iSourceViewRelNum; |
---|
| 744 | Int iTargetViewRelNum; |
---|
| 745 | |
---|
| 746 | if( bByIdx ) |
---|
| 747 | { |
---|
| 748 | |
---|
| 749 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 750 | iSourceViewRelNum = m_aiBaseId2SortedId[ uiSourceView ] * ((Int) m_dViewNumPrec ); |
---|
| 751 | |
---|
| 752 | if ( bExternal ) |
---|
| 753 | { |
---|
| 754 | iTargetViewNum = m_aiSynthViews [ uiTargetView ]; |
---|
| 755 | iTargetViewRelNum = m_aiRelSynthViewsNum[ uiTargetView ]; |
---|
| 756 | } |
---|
| 757 | else |
---|
| 758 | { |
---|
| 759 | iTargetViewNum = m_aiBaseViews [ uiTargetView ]; |
---|
| 760 | iTargetViewRelNum = m_aiBaseId2SortedId [ uiTargetView ] * ((Int) m_dViewNumPrec ); |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | else |
---|
| 764 | { |
---|
| 765 | iSourceViewNum = (Int) uiSourceView; |
---|
| 766 | iTargetViewNum = (Int) uiTargetView; |
---|
| 767 | iSourceViewRelNum = m_aiBaseId2SortedId[ xGetBaseViewId( uiSourceView) ] * ((Int) m_dViewNumPrec ); |
---|
| 768 | |
---|
| 769 | if ( bExternal ) |
---|
| 770 | { |
---|
| 771 | iTargetViewRelNum = m_aiRelSynthViewsNum[ xGetViewId( m_aiSynthViews, (Int) uiTargetView )]; |
---|
| 772 | } |
---|
| 773 | else |
---|
| 774 | { |
---|
| 775 | iTargetViewRelNum = m_aiBaseId2SortedId[ xGetBaseViewId( uiTargetView) ] * ((Int) m_dViewNumPrec ); |
---|
| 776 | } |
---|
| 777 | } |
---|
| 778 | xGetPrevAndNextBaseView( iSourceViewNum, iTargetViewNum, iPrevBaseViewNum, iNextBaseViewNum ); |
---|
| 779 | AOT( iPrevBaseViewNum == -1 ); // should not happen |
---|
| 780 | AOT( iNextBaseViewNum == -1 ); // should not happen |
---|
| 781 | |
---|
| 782 | Int iSrcId = xGetBaseViewId( iSourceViewNum ); |
---|
| 783 | Int iPrevId = xGetBaseViewId( iPrevBaseViewNum ); |
---|
| 784 | Int iNextId = xGetBaseViewId( iNextBaseViewNum ); |
---|
| 785 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iPrevId ] ); // coded scale and offset must be set |
---|
| 786 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iNextId ] ); // coded scale and offset must be set |
---|
| 787 | |
---|
| 788 | Int iNextBaseViewRelNum = m_aiBaseId2SortedId[ iNextId ] * ((Int) m_dViewNumPrec ); |
---|
| 789 | Int iPrevBaseViewRelNum = m_aiBaseId2SortedId[ iPrevId ] * ((Int) m_dViewNumPrec ); |
---|
| 790 | |
---|
| 791 | Int64 iPrevScale = (Int64)m_aaiCodedScale [ iSrcId ][ iPrevId ]; |
---|
| 792 | Int64 iNextScale = (Int64)m_aaiCodedScale [ iSrcId ][ iNextId ]; |
---|
| 793 | Int64 iPrevOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iPrevId ] << m_uiBitDepthForLUT; |
---|
| 794 | Int64 iNextOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iNextId ] << m_uiBitDepthForLUT; |
---|
| 795 | |
---|
| 796 | if( iPrevBaseViewNum == iNextBaseViewNum ) |
---|
| 797 | { |
---|
| 798 | riScale = iNextScale; |
---|
| 799 | riOffset = iNextOffset; |
---|
| 800 | } |
---|
| 801 | else |
---|
| 802 | { |
---|
| 803 | riScale = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextScale; |
---|
| 804 | riScale += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevScale; |
---|
| 805 | riOffset = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextOffset; |
---|
| 806 | riOffset += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevOffset; |
---|
| 807 | Int64 iD = Int64( iNextBaseViewRelNum - iPrevBaseViewRelNum ); |
---|
| 808 | Int64 iSA = ( riScale > 0 ? iD / 2 : -iD / 2 ); |
---|
| 809 | Int64 iOA = ( riOffset > 0 ? iD / 2 : -iD / 2 ); |
---|
| 810 | riScale = ( riScale + iSA ) / iD; |
---|
| 811 | riOffset = ( riOffset + iOA ) / iD; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | |
---|
| 816 | Void |
---|
| 817 | TAppComCamPara::xSetCodedScaleOffset( UInt uiFrame ) |
---|
| 818 | { |
---|
| 819 | for( UInt uiSourceId = 0; uiSourceId < m_iNumberOfBaseViews; uiSourceId++ ) |
---|
| 820 | { |
---|
| 821 | for( UInt uiTargetId = 0; uiTargetId < m_iNumberOfBaseViews; uiTargetId++ ) |
---|
| 822 | { |
---|
| 823 | Int iScale, iOffset; |
---|
| 824 | xGetShiftParameterCoded( uiSourceId, uiTargetId, uiFrame, true, iScale, iOffset ); |
---|
| 825 | m_aaiCodedScale [ uiSourceId ][ uiTargetId ] = iScale; |
---|
| 826 | m_aaiCodedOffset [ uiSourceId ][ uiTargetId ] = iOffset; |
---|
| 827 | m_aaiScaleAndOffsetSet [ uiSourceId ][ uiTargetId ] = 1; |
---|
| 828 | } |
---|
| 829 | } |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | |
---|
| 833 | Void |
---|
| 834 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiNumberSourceViews, UInt uiNumberTargetViews, UInt uiFrame, Bool bExternalReference , Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ) |
---|
| 835 | { |
---|
| 836 | if( uiNumberSourceViews <= 1 || uiNumberTargetViews == 0 ) |
---|
| 837 | { |
---|
| 838 | return; |
---|
| 839 | } |
---|
| 840 | AOF( radShiftParams != NULL && raiShiftParams != NULL && radLUT != NULL && raiLUT != NULL ); |
---|
| 841 | AOF( m_uiBitDepthForLUT == 8 ); |
---|
| 842 | |
---|
| 843 | Int iLog2DivLuma = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision; AOF( iLog2DivLuma > 0 ); |
---|
| 844 | Int iLog2DivChroma = iLog2DivLuma + 1; |
---|
| 845 | Double dMaxDispDev = 0.0; |
---|
| 846 | Double dMaxRndDispDvL = 0.0; |
---|
| 847 | Double dMaxRndDispDvC = 0.0; |
---|
| 848 | for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) |
---|
| 849 | { |
---|
| 850 | for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ ) |
---|
| 851 | { |
---|
| 852 | |
---|
| 853 | // integer-valued scale and offset |
---|
| 854 | Int64 iScale, iOffset; |
---|
| 855 | xGetShiftParameterInt ( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, iScale, iOffset ); |
---|
| 856 | raiShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = iScale; |
---|
| 857 | raiShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = iOffset; |
---|
| 858 | |
---|
| 859 | // offsets including rounding offsets |
---|
| 860 | Int64 iOffsetLuma = iOffset + ( ( 1 << iLog2DivLuma ) >> 1 ); |
---|
| 861 | Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 ); |
---|
| 862 | |
---|
| 863 | // real-valued scale and offset |
---|
| 864 | Double dScale, dOffset; |
---|
| 865 | |
---|
| 866 | if ( m_bSetupFromCoded ) |
---|
| 867 | { |
---|
| 868 | dScale = (Double) iScale / (( Double ) ( 1 << iLog2DivLuma )); |
---|
| 869 | dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma )); |
---|
| 870 | } |
---|
| 871 | else |
---|
| 872 | { |
---|
| 873 | xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, dScale, dOffset ); |
---|
| 874 | } |
---|
| 875 | |
---|
| 876 | radShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = dScale; |
---|
| 877 | radShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = dOffset; |
---|
| 878 | |
---|
[28] | 879 | for( UInt uiDepthValue = 0; uiDepthValue < SizeOfLUT; uiDepthValue++ ) |
---|
[2] | 880 | { |
---|
[41] | 881 | // real-valued look-up tables |
---|
[28] | 882 | #if POZNAN_NONLINEAR_DEPTH |
---|
[41] | 883 | Double dShiftLuma; |
---|
| 884 | if(m_bUseNonlinearDepth) |
---|
| 885 | dShiftLuma = ( m_cNonlinearDepthModel.BackwardD((Double)uiDepthValue, dScale) + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
| 886 | else |
---|
| 887 | dShiftLuma = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
| 888 | #else |
---|
| 889 | Double dShiftLuma = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
[28] | 890 | #endif |
---|
[2] | 891 | Double dShiftChroma = dShiftLuma / 2; |
---|
| 892 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma; |
---|
| 893 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma; |
---|
| 894 | |
---|
| 895 | // integer-valued look-up tables |
---|
[41] | 896 | #if POZNAN_NONLINEAR_DEPTH |
---|
| 897 | Int64 iTempScale; |
---|
| 898 | if(m_bUseNonlinearDepth) |
---|
| 899 | iTempScale = (Int64)m_cNonlinearDepthModel.BackwardI(uiDepthValue, iScale); |
---|
| 900 | else |
---|
| 901 | iTempScale = (Int64)uiDepthValue * iScale; |
---|
| 902 | |
---|
| 903 | #else |
---|
| 904 | Int64 iTempScale = (Int64)uiDepthValue * iScale; |
---|
[28] | 905 | #endif |
---|
[2] | 906 | Int64 iTestScale = ( iTempScale + iOffset ); // for checking accuracy of camera parameters |
---|
| 907 | Int64 iShiftLuma = ( iTempScale + iOffsetLuma ) >> iLog2DivLuma; |
---|
| 908 | Int64 iShiftChroma = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma; |
---|
| 909 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma; |
---|
| 910 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma; |
---|
| 911 | |
---|
| 912 | // maximum deviation |
---|
| 913 | dMaxDispDev = Max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); |
---|
| 914 | dMaxRndDispDvL = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); |
---|
| 915 | dMaxRndDispDvC = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); |
---|
| 916 | } |
---|
| 917 | |
---|
[28] | 918 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT-1 ]; |
---|
| 919 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT-1 ]; |
---|
| 920 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT-1 ]; |
---|
| 921 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT-1 ]; |
---|
[2] | 922 | } |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | // check maximum deviation |
---|
| 926 | Double dMaxAllowedDispDev = Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // counting only the impact of camera parameter rounding |
---|
| 927 | Double dMaxAllowedRndDispDvL = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // final rounding and impact of camera parameter rounding |
---|
| 928 | Double dMaxAllowedRndDispDvC = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ) / 2.0; // final rounding and impact of camera parameter rounding |
---|
| 929 | |
---|
| 930 | if( ( dMaxDispDev >= dMaxAllowedDispDev || dMaxRndDispDvL >= dMaxAllowedRndDispDvL || dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) && !m_bSetupFromCoded ) |
---|
| 931 | { |
---|
| 932 | std::cout << "Warning: Something wrong with the accuracy of coded camera parameters:" << std::endl; |
---|
| 933 | if( dMaxDispDev >= dMaxAllowedDispDev ) |
---|
| 934 | { |
---|
| 935 | std::cout << " max disparity difference is " << dMaxDispDev << " (allowed: " << dMaxAllowedDispDev << ")" << std::endl; |
---|
| 936 | } |
---|
| 937 | if( dMaxRndDispDvL >= dMaxAllowedRndDispDvL ) |
---|
| 938 | { |
---|
| 939 | std::cout << " max rnd luma disp diff is " << dMaxRndDispDvL << " (allowed: " << dMaxAllowedRndDispDvL << ")" << std::endl; |
---|
| 940 | } |
---|
| 941 | if( dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) |
---|
| 942 | { |
---|
| 943 | std::cout << " max rnd chroma disp diff is " << dMaxRndDispDvC << " (allowed: " << dMaxAllowedRndDispDvC << ")" << std::endl; |
---|
| 944 | } |
---|
| 945 | } |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | |
---|
| 949 | Void |
---|
| 950 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame ) |
---|
| 951 | { |
---|
| 952 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
| 953 | xSetCodedScaleOffset ( uiFrame ); |
---|
| 954 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, uiFrame, false, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
| 955 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
| 956 | }; |
---|
| 957 | |
---|
| 958 | |
---|
| 959 | Void |
---|
| 960 | TAppComCamPara::xGetCameraShifts( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift ) |
---|
| 961 | { |
---|
| 962 | Double dDummy, dCamPosSource, dCamPosTarget, dPicPosSource, dPicPosTarget; |
---|
| 963 | Bool bInterpolatedSource, bInterpolatedTarget; |
---|
| 964 | Int iTargetViewNum = m_aiBaseViews[ uiTargetView ]; |
---|
| 965 | Int iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 966 | |
---|
| 967 | xGetGeometryData( iSourceViewNum, uiFrame, dDummy, dCamPosSource, dPicPosSource, bInterpolatedSource ); |
---|
| 968 | xGetGeometryData( iTargetViewNum, uiFrame, dDummy, dCamPosTarget, dPicPosTarget, bInterpolatedTarget ); |
---|
| 969 | AOT( bInterpolatedSource || bInterpolatedTarget ); |
---|
| 970 | |
---|
| 971 | rdCamPosShift = ( dCamPosTarget - dCamPosSource ); |
---|
| 972 | rdPicPosShift = -( dPicPosTarget - dPicPosSource ); // to be consistent |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | |
---|
| 976 | Void |
---|
| 977 | TAppComCamPara::xSetPdmConversionParams() |
---|
| 978 | { |
---|
| 979 | AOF( m_aiViewOrderIndex[ 0 ] == 0 ); |
---|
| 980 | if ( m_bSetupFromCoded || m_iNumberOfBaseViews < 2 ) |
---|
| 981 | { |
---|
| 982 | return; |
---|
| 983 | } |
---|
| 984 | |
---|
| 985 | //--- determine (virtual) camera parameter shift between view order index 1 and base view (view order index 0) --- |
---|
| 986 | Double dCamPosShift, dPicPosShift; |
---|
| 987 | Int iMinVOI = (1<<30); |
---|
| 988 | Int iMinAbsVOI = (1<<30); |
---|
| 989 | Int iMinAbsVOIId = 0; |
---|
| 990 | for( Int iBaseId = 1; iBaseId < m_iNumberOfBaseViews; iBaseId++ ) |
---|
| 991 | { |
---|
| 992 | Int iAbsVOI = ( m_aiViewOrderIndex[ iBaseId ] < 0 ? -m_aiViewOrderIndex[ iBaseId ] : m_aiViewOrderIndex[ iBaseId ] ); |
---|
| 993 | if( iAbsVOI < iMinAbsVOI ) |
---|
| 994 | { |
---|
| 995 | iMinVOI = m_aiViewOrderIndex[ iBaseId ]; |
---|
| 996 | iMinAbsVOI = iAbsVOI; |
---|
| 997 | iMinAbsVOIId = iBaseId; |
---|
| 998 | } |
---|
| 999 | } |
---|
| 1000 | AOF( iMinAbsVOIId != 0 && iMinAbsVOI != 0 ); |
---|
| 1001 | xGetCameraShifts( 0, iMinAbsVOIId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
| 1002 | Double dCamPosShiftVOI01 = dCamPosShift / Double( iMinVOI ); |
---|
| 1003 | |
---|
| 1004 | //--- determine maximum absolute camera position shift, precision, and base scale --- |
---|
| 1005 | Double dMaxAbsCamPosShift = 0.0; |
---|
| 1006 | for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ ) |
---|
| 1007 | { |
---|
| 1008 | for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ ) |
---|
| 1009 | { |
---|
| 1010 | xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
| 1011 | dCamPosShift = ( dCamPosShift < 0.0 ? -dCamPosShift : dCamPosShift ); |
---|
| 1012 | dMaxAbsCamPosShift = ( dCamPosShift > dMaxAbsCamPosShift ? dCamPosShift : dMaxAbsCamPosShift ); |
---|
| 1013 | } |
---|
| 1014 | } |
---|
[21] | 1015 | Int iPrecision = 0; |
---|
| 1016 | #if 0 // enabling this lines might be reasonable, but produces different results for the 2 view and 3 view test cases |
---|
[2] | 1017 | Double dEpsilon = 1e-15; |
---|
[21] | 1018 | Double dAbsCamPosShiftVOI01 = ( dCamPosShiftVOI01 < 0.0 ? -dCamPosShiftVOI01 : dCamPosShiftVOI01 ); |
---|
[2] | 1019 | Double dShiftRatio = dMaxAbsCamPosShift / dAbsCamPosShiftVOI01 - dEpsilon; |
---|
[21] | 1020 | for( ; (Double)( 1 << iPrecision ) < dShiftRatio; iPrecision++ ); |
---|
| 1021 | #endif |
---|
[2] | 1022 | Int iPrecShift = iPrecision + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2; |
---|
| 1023 | AOF( iPrecShift < PDM_INTERNAL_CALC_BIT_DEPTH ); |
---|
| 1024 | Int iScaleVOI01 = 1 << iPrecShift; |
---|
| 1025 | m_iPdmPrecision = iPrecision; |
---|
| 1026 | |
---|
| 1027 | //--- loop over target views --- |
---|
| 1028 | for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ ) |
---|
| 1029 | { |
---|
| 1030 | // set scale and offset parameters for other views |
---|
| 1031 | for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ ) |
---|
| 1032 | { |
---|
| 1033 | xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
| 1034 | Double dScale = Double( iScaleVOI01 ) * dCamPosShiftVOI01 / dCamPosShift; |
---|
| 1035 | Int iDiv = m_aiViewOrderIndex[ iTargetId ] - m_aiViewOrderIndex[ iBaseId ]; |
---|
| 1036 | Int iAdd = ( iDiv > 0 ? iDiv / 2 : -iDiv / 2 ); |
---|
| 1037 | Int iScalePred = ( iScaleVOI01 + iAdd ) / iDiv; |
---|
| 1038 | Double dFactor = dScale / (Double)iScalePred * pow( 2.0, PDM_LOG4_SCALE_DENOMINATOR ); |
---|
| 1039 | Int iNominator = (Int)floor( dFactor + .5 ); |
---|
| 1040 | Int iNomDelta = iNominator - ( 1 << PDM_LOG4_SCALE_DENOMINATOR ); |
---|
| 1041 | Int iScale = Int( ( (Int64)iNominator * (Int64)iScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR ); |
---|
| 1042 | Double dOffset = -dPicPosShift * Double( iScale ) * pow( 2.0, 2 - PDM_OFFSET_SHIFT ); |
---|
| 1043 | Int iOffset = (Int)floor( dOffset + .5 ); |
---|
| 1044 | |
---|
| 1045 | m_aaiPdmScaleNomDelta [ iTargetId ][ iBaseId ] = iNomDelta; |
---|
| 1046 | m_aaiPdmOffset [ iTargetId ][ iBaseId ] = iOffset; |
---|
| 1047 | } |
---|
| 1048 | } |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | |
---|
| 1052 | |
---|
| 1053 | TAppComCamPara::TAppComCamPara() |
---|
| 1054 | { |
---|
| 1055 | m_dViewNumPrec = VIEW_NUM_PREC; // fixed |
---|
| 1056 | m_iLog2Precision = -1; |
---|
| 1057 | m_uiInputBitDepth = 0; |
---|
| 1058 | m_uiBitDepthForLUT = 8; // fixed |
---|
| 1059 | m_uiFirstFrameId = 0; |
---|
| 1060 | m_uiLastFrameId = 0; |
---|
| 1061 | |
---|
| 1062 | m_iNumberOfBaseViews = -1; |
---|
| 1063 | m_iNumberOfSynthViews = -1; |
---|
| 1064 | |
---|
| 1065 | m_uiCamParsCodedPrecision = 0; |
---|
| 1066 | m_bCamParsVaryOverTime = true; |
---|
| 1067 | |
---|
| 1068 | m_aaiCodedScale = 0; |
---|
| 1069 | m_aaiCodedOffset = 0; |
---|
| 1070 | m_aaiScaleAndOffsetSet = 0; |
---|
| 1071 | |
---|
| 1072 | m_iPdmPrecision = 0; |
---|
| 1073 | m_aaiPdmScaleNomDelta = 0; |
---|
| 1074 | m_aaiPdmOffset = 0; |
---|
| 1075 | |
---|
| 1076 | m_adBaseViewShiftParameter = 0; |
---|
| 1077 | m_aiBaseViewShiftParameter = 0; |
---|
| 1078 | m_adSynthViewShiftParameter = 0; |
---|
| 1079 | m_aiSynthViewShiftParameter = 0; |
---|
| 1080 | |
---|
| 1081 | m_adBaseViewShiftLUT = 0; |
---|
| 1082 | m_aiBaseViewShiftLUT = 0; |
---|
| 1083 | m_adSynthViewShiftLUT = 0; |
---|
| 1084 | m_aiSynthViewShiftLUT = 0; |
---|
| 1085 | |
---|
| 1086 | m_bSetupFromCoded = false; |
---|
| 1087 | m_bCamParsCodedPrecSet = false; |
---|
| 1088 | |
---|
| 1089 | |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | |
---|
| 1093 | TAppComCamPara::~TAppComCamPara() |
---|
| 1094 | { |
---|
| 1095 | xDeleteArray( m_adBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
| 1096 | xDeleteArray( m_aiBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
| 1097 | xDeleteArray( m_adBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
| 1098 | xDeleteArray( m_aiBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
| 1099 | |
---|
| 1100 | xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews)); |
---|
| 1101 | xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews)); |
---|
| 1102 | xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 ); |
---|
| 1103 | xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 ); |
---|
| 1104 | |
---|
| 1105 | xDeleteArray( m_aaiCodedScale, m_iNumberOfBaseViews ); |
---|
| 1106 | xDeleteArray( m_aaiCodedOffset, m_iNumberOfBaseViews ); |
---|
| 1107 | xDeleteArray( m_aaiScaleAndOffsetSet, m_iNumberOfBaseViews ); |
---|
| 1108 | |
---|
| 1109 | xDeleteArray( m_aaiPdmScaleNomDelta, m_iNumberOfBaseViews ); |
---|
| 1110 | xDeleteArray( m_aaiPdmOffset, m_iNumberOfBaseViews ); |
---|
| 1111 | } |
---|
| 1112 | |
---|
| 1113 | Void |
---|
| 1114 | TAppComCamPara::xSetupBaseViewsFromCoded() |
---|
| 1115 | { |
---|
| 1116 | //===== get and sort views given in camera parameter file and set list of base views and related arrays ===== |
---|
| 1117 | // get left-right order and coding order from cfg-file |
---|
| 1118 | std::vector<Int> aiViewOrderIdx; // Left Right Order |
---|
| 1119 | std::vector<Int> aiViewId ; // Coding Order |
---|
| 1120 | |
---|
| 1121 | Int iMinViewOrderIdx = MAX_INT; |
---|
| 1122 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1123 | { |
---|
| 1124 | if (m_aadCameraParameters[uiRow].size() != 2 ) |
---|
| 1125 | break; |
---|
| 1126 | |
---|
| 1127 | Int iViewOrderIdx = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] ); |
---|
| 1128 | iMinViewOrderIdx = Min( iViewOrderIdx, iMinViewOrderIdx ); |
---|
| 1129 | |
---|
| 1130 | aiViewOrderIdx .push_back( iViewOrderIdx ); |
---|
| 1131 | aiViewId .push_back( (Int) m_aadCameraParameters[ uiRow ][ 0 ] ); |
---|
| 1132 | } |
---|
| 1133 | |
---|
| 1134 | // create base view numbers |
---|
| 1135 | AOT( aiViewId.size() != aiViewOrderIdx.size() ); |
---|
| 1136 | m_iNumberOfBaseViews = (Int) aiViewId.size(); |
---|
| 1137 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1138 | { |
---|
| 1139 | aiViewOrderIdx[iCurBaseView] = ( aiViewOrderIdx[iCurBaseView] - iMinViewOrderIdx); |
---|
| 1140 | m_aiBaseViews .push_back( aiViewOrderIdx[iCurBaseView] * ( (Int) m_dViewNumPrec) ); |
---|
| 1141 | m_aiBaseId2SortedId.push_back( iCurBaseView ); |
---|
| 1142 | m_aiBaseSortedId2Id.push_back( iCurBaseView ); |
---|
| 1143 | |
---|
| 1144 | } |
---|
| 1145 | |
---|
| 1146 | m_iNumberOfBaseViews = (Int) m_aiBaseViews.size(); |
---|
| 1147 | |
---|
| 1148 | std::vector<Int> aiSortedViewOrderIdx = aiViewOrderIdx; |
---|
| 1149 | |
---|
| 1150 | // sort base views according to View Order Idx |
---|
| 1151 | m_aiSortedBaseViews = m_aiBaseViews; |
---|
| 1152 | for (Int iCurBaseView = 1; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1153 | { |
---|
| 1154 | Int iCurViewOrder = aiSortedViewOrderIdx[iCurBaseView]; |
---|
| 1155 | for (Int iCurSearchPos = iCurBaseView; iCurSearchPos >= 0; iCurSearchPos-- ) |
---|
| 1156 | { |
---|
| 1157 | if ( iCurViewOrder < aiSortedViewOrderIdx[iCurSearchPos] ) |
---|
| 1158 | { |
---|
| 1159 | Int iTempViewId = m_aiSortedBaseViews[iCurSearchPos]; |
---|
| 1160 | m_aiSortedBaseViews[iCurSearchPos] = m_aiSortedBaseViews[iCurBaseView]; |
---|
| 1161 | m_aiSortedBaseViews[iCurBaseView ] = iTempViewId; |
---|
| 1162 | |
---|
| 1163 | Int iTempViewOrderIdx = aiSortedViewOrderIdx[iCurSearchPos]; |
---|
| 1164 | aiSortedViewOrderIdx[iCurSearchPos] = aiSortedViewOrderIdx[iCurBaseView]; |
---|
| 1165 | aiSortedViewOrderIdx[iCurBaseView ] = iTempViewOrderIdx; |
---|
| 1166 | |
---|
| 1167 | Int iTempPos = m_aiBaseSortedId2Id[iCurSearchPos]; |
---|
| 1168 | m_aiBaseSortedId2Id[iCurSearchPos] = m_aiBaseSortedId2Id[iCurBaseView]; |
---|
| 1169 | m_aiBaseSortedId2Id[iCurBaseView] = iTempPos; |
---|
| 1170 | iCurBaseView--; |
---|
| 1171 | } |
---|
| 1172 | } |
---|
| 1173 | } |
---|
| 1174 | |
---|
| 1175 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1176 | { |
---|
| 1177 | m_aiBaseId2SortedId[m_aiBaseSortedId2Id[iCurBaseView]] = iCurBaseView; |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | m_aiViewsInCfgFile = m_aiSortedBaseViews; |
---|
| 1181 | |
---|
| 1182 | // check |
---|
| 1183 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
| 1184 | { |
---|
| 1185 | std::cerr << "Failed reading camera parameter file" << std::endl; |
---|
| 1186 | std::cerr << "At least two views must be given" << std::endl; |
---|
| 1187 | AOT(true); |
---|
| 1188 | exit( EXIT_FAILURE ); |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | // translate coding order to view order |
---|
| 1192 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1193 | { |
---|
| 1194 | if (m_aadCameraParameters[uiRow].size() == 2 ) |
---|
| 1195 | continue; |
---|
| 1196 | |
---|
| 1197 | m_aadCameraParameters[ uiRow ][ 2 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 2 ] ) ]; |
---|
| 1198 | m_aadCameraParameters[ uiRow ][ 3 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 3 ] ) ]; |
---|
| 1199 | } |
---|
| 1200 | } |
---|
| 1201 | |
---|
| 1202 | Void TAppComCamPara::xSetupBaseViews( Char* pchBaseViewNumbers, UInt uiNumBaseViews ) |
---|
| 1203 | { |
---|
| 1204 | // init list |
---|
| 1205 | std::vector<Int> aiViewsInCfg; |
---|
| 1206 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1207 | { |
---|
| 1208 | aiViewsInCfg.push_back( (Int)( m_aadCameraParameters[ uiRow ][ 0 ] * m_dViewNumPrec ) ); |
---|
| 1209 | } |
---|
| 1210 | // remove duplicated items |
---|
| 1211 | std::sort( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
| 1212 | std::vector<Int>::iterator cIterNewEnd = std::unique( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
| 1213 | aiViewsInCfg.erase( cIterNewEnd, aiViewsInCfg.end() ); |
---|
| 1214 | // sort (from left to right) |
---|
| 1215 | std::vector<Int> aiDummyI2SI, aiDummySI2I; |
---|
| 1216 | xGetSortedViewList( aiViewsInCfg, m_aiViewsInCfgFile, aiDummyI2SI, aiDummySI2I ); |
---|
| 1217 | // check |
---|
| 1218 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
| 1219 | { |
---|
| 1220 | std::cerr << "Failed reading config file" << std::endl; |
---|
| 1221 | std::cerr << "At least two views must be given" << std::endl; |
---|
| 1222 | exit( EXIT_FAILURE ); |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | |
---|
| 1226 | |
---|
| 1227 | //===== set list of base views and related arrays ===== |
---|
| 1228 | if( pchBaseViewNumbers == 0 ) |
---|
| 1229 | { |
---|
| 1230 | std::cerr << "BaseViewCameraNumbers must be given" << std::endl; |
---|
| 1231 | exit( EXIT_FAILURE ); |
---|
| 1232 | }; |
---|
| 1233 | |
---|
| 1234 | convertNumberString( pchBaseViewNumbers, m_aiBaseViews, m_dViewNumPrec ); |
---|
| 1235 | while( (UInt)m_aiBaseViews.size() > uiNumBaseViews ) |
---|
| 1236 | { |
---|
| 1237 | m_aiBaseViews.pop_back(); |
---|
| 1238 | } |
---|
| 1239 | xGetSortedViewList( m_aiBaseViews, m_aiSortedBaseViews, m_aiBaseId2SortedId, m_aiBaseSortedId2Id ); |
---|
| 1240 | m_iNumberOfBaseViews = (Int)m_aiBaseViews.size(); |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | |
---|
| 1244 | Void |
---|
| 1245 | TAppComCamPara::init( UInt uiNumBaseViews, |
---|
| 1246 | UInt uiInputBitDepth, |
---|
| 1247 | UInt uiCodedCamParsPrecision, |
---|
| 1248 | UInt uiStartFrameId, |
---|
| 1249 | UInt uiNumFrames, |
---|
| 1250 | Char* pchCfgFileName, |
---|
| 1251 | Char* pchBaseViewNumbers, |
---|
| 1252 | Char* pchSynthViewNumbers, |
---|
| 1253 | std::vector<Int>* paiSynthViewNumbers, |
---|
[28] | 1254 | Int iLog2Precision |
---|
| 1255 | #if POZNAN_NONLINEAR_DEPTH |
---|
[41] | 1256 | ,TComNonlinearDepthModel* pcNonlinearDepthModel |
---|
[28] | 1257 | #endif |
---|
| 1258 | ) |
---|
[2] | 1259 | { |
---|
| 1260 | //===== set miscellaneous variables ===== |
---|
| 1261 | m_uiInputBitDepth = uiInputBitDepth; |
---|
| 1262 | m_uiFirstFrameId = uiStartFrameId; |
---|
| 1263 | m_uiLastFrameId = uiStartFrameId + uiNumFrames - 1; |
---|
| 1264 | m_uiCamParsCodedPrecision = uiCodedCamParsPrecision; |
---|
| 1265 | m_iLog2Precision = iLog2Precision; |
---|
| 1266 | |
---|
[28] | 1267 | #if POZNAN_NONLINEAR_DEPTH |
---|
[41] | 1268 | m_bUseNonlinearDepth = (pcNonlinearDepthModel != NULL) ? true : false; |
---|
| 1269 | if(pcNonlinearDepthModel != NULL) |
---|
| 1270 | m_cNonlinearDepthModel = *pcNonlinearDepthModel; |
---|
[28] | 1271 | #endif |
---|
| 1272 | |
---|
[2] | 1273 | xReadCameraParameterFile( pchCfgFileName ); |
---|
| 1274 | |
---|
| 1275 | m_bSetupFromCoded = ( m_aadCameraParameters[ 0 ].size() == 2 ); |
---|
| 1276 | |
---|
| 1277 | if ( m_bSetupFromCoded ) |
---|
| 1278 | { |
---|
| 1279 | std::cout << "Detected decoded camera parameter file. Overwriting base view settings from cfg file. " << std::endl; |
---|
| 1280 | xSetupBaseViewsFromCoded(); |
---|
| 1281 | } |
---|
| 1282 | else |
---|
| 1283 | { |
---|
| 1284 | xSetupBaseViews( pchBaseViewNumbers, uiNumBaseViews ); |
---|
| 1285 | } |
---|
| 1286 | |
---|
| 1287 | //===== set list of external (virtual) views ===== |
---|
| 1288 | m_aiSynthViews.clear(); |
---|
| 1289 | |
---|
| 1290 | if( pchSynthViewNumbers != 0 || paiSynthViewNumbers != 0) |
---|
| 1291 | { |
---|
| 1292 | std::vector<Int> aiTmpSynthViews; |
---|
| 1293 | |
---|
| 1294 | AOT( ( pchSynthViewNumbers != NULL ) && ( paiSynthViewNumbers != NULL ) ); |
---|
| 1295 | |
---|
| 1296 | if ( pchSynthViewNumbers != NULL ) |
---|
| 1297 | { |
---|
| 1298 | convertNumberString( pchSynthViewNumbers, aiTmpSynthViews, m_dViewNumPrec ); |
---|
| 1299 | } |
---|
| 1300 | else |
---|
| 1301 | { |
---|
| 1302 | aiTmpSynthViews = (*paiSynthViewNumbers); |
---|
| 1303 | } |
---|
| 1304 | |
---|
| 1305 | for( UInt uiSId = 0; uiSId < (UInt)aiTmpSynthViews.size(); uiSId++ ) |
---|
| 1306 | { |
---|
| 1307 | |
---|
| 1308 | Int iViewNumPrec = (Int) m_dViewNumPrec; |
---|
| 1309 | Int iLeftBaseViewIdx = aiTmpSynthViews[ uiSId ] / iViewNumPrec; |
---|
| 1310 | Int iRightBaseViewIdx = ( aiTmpSynthViews[ uiSId ] + (iViewNumPrec - 1) ) / iViewNumPrec; |
---|
| 1311 | |
---|
| 1312 | if ( iLeftBaseViewIdx < 0 || iRightBaseViewIdx >= m_iNumberOfBaseViews ) |
---|
| 1313 | { |
---|
| 1314 | std::cerr << "SynthViewCameraNumbers must be greater and equal to 0 and smaller than number of base views" << std::endl; |
---|
| 1315 | AOT(true); |
---|
| 1316 | exit( EXIT_FAILURE ); |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | Int64 iLeftBaseViewRelNum = iLeftBaseViewIdx * iViewNumPrec; |
---|
| 1320 | Int64 iRightBaseViewRelNum = iRightBaseViewIdx * iViewNumPrec; |
---|
| 1321 | |
---|
| 1322 | Int64 iDiffBaseViewRelNum = iRightBaseViewRelNum - iLeftBaseViewRelNum; |
---|
| 1323 | |
---|
| 1324 | Int64 iSynthViewRelNum = aiTmpSynthViews[ uiSId ]; |
---|
| 1325 | Int64 iLeftBaseNum = m_aiSortedBaseViews[ iLeftBaseViewIdx ]; |
---|
| 1326 | Int64 iRightBaseNum = m_aiSortedBaseViews[ iRightBaseViewIdx ]; |
---|
| 1327 | Int64 iDiffBaseNum = iRightBaseNum - iLeftBaseNum; |
---|
| 1328 | Int64 iSynthViewNum; |
---|
| 1329 | |
---|
| 1330 | if ( iDiffBaseViewRelNum != 0) |
---|
| 1331 | { |
---|
| 1332 | AOT( (Int) iDiffBaseViewRelNum != iViewNumPrec ); |
---|
| 1333 | Int iFact = iDiffBaseNum > 0 ? 1 : -1; |
---|
| 1334 | iSynthViewNum = iLeftBaseNum + ( iDiffBaseNum * ( iSynthViewRelNum - iLeftBaseViewRelNum ) + (iViewNumPrec >> 1) * iFact ) / ( iViewNumPrec ); |
---|
| 1335 | } |
---|
| 1336 | else |
---|
| 1337 | { |
---|
| 1338 | iSynthViewNum = iLeftBaseNum; |
---|
| 1339 | } |
---|
| 1340 | |
---|
| 1341 | m_aiRelSynthViewsNum.push_back( aiTmpSynthViews[ uiSId ] ); |
---|
| 1342 | m_aiSynthViews .push_back( (Int) iSynthViewNum ); |
---|
| 1343 | } |
---|
| 1344 | } |
---|
| 1345 | m_iNumberOfSynthViews = (Int)m_aiSynthViews.size(); |
---|
| 1346 | |
---|
| 1347 | |
---|
| 1348 | //===== set derived parameters ===== |
---|
| 1349 | xGetViewOrderIndices( m_aiBaseId2SortedId, m_aiViewOrderIndex ); |
---|
| 1350 | m_bCamParsVaryOverTime = xGetCamParsChangeFlag(); |
---|
| 1351 | |
---|
| 1352 | |
---|
| 1353 | //===== create arrays ===== |
---|
| 1354 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
| 1355 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
| 1356 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedScale ); |
---|
| 1357 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedOffset ); |
---|
| 1358 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet ); |
---|
| 1359 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
| 1360 | |
---|
| 1361 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmScaleNomDelta ); |
---|
| 1362 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmOffset ); |
---|
| 1363 | |
---|
| 1364 | //===== init disparity to virtual depth conversion parameters ===== |
---|
| 1365 | xSetPdmConversionParams(); |
---|
| 1366 | |
---|
| 1367 | //===== init arrays for first frame ===== |
---|
| 1368 | xSetShiftParametersAndLUT( m_uiFirstFrameId ); |
---|
| 1369 | } |
---|
| 1370 | |
---|
| 1371 | |
---|
| 1372 | Void |
---|
| 1373 | TAppComCamPara::check( Bool bCheckViewRange, Bool bCheckFrameRange ) |
---|
| 1374 | { |
---|
| 1375 | if( bCheckFrameRange ) |
---|
| 1376 | { |
---|
| 1377 | Double dDummy; |
---|
| 1378 | |
---|
| 1379 | for( UInt uiBaseView = 0; uiBaseView < m_aiBaseViews.size(); uiBaseView++ ) |
---|
| 1380 | { |
---|
| 1381 | if ( m_bSetupFromCoded ) |
---|
| 1382 | { |
---|
| 1383 | for( UInt uiTargetView = 0; uiTargetView < m_aiBaseViews.size(); uiTargetView++ ) |
---|
| 1384 | { |
---|
| 1385 | if ( uiTargetView == uiBaseView ) |
---|
| 1386 | continue; |
---|
| 1387 | |
---|
| 1388 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1389 | { |
---|
| 1390 | Int iDummy; |
---|
| 1391 | |
---|
| 1392 | xGetCodedCameraData( uiBaseView, uiTargetView, true , uiFrame, iDummy, iDummy, iDummy ); |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | } |
---|
| 1396 | else |
---|
| 1397 | { |
---|
| 1398 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1399 | { |
---|
| 1400 | Bool bInterpolatedCur; |
---|
| 1401 | xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
| 1402 | xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); |
---|
| 1403 | |
---|
| 1404 | if( bInterpolatedCur ) |
---|
| 1405 | { |
---|
| 1406 | std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; |
---|
| 1407 | exit( EXIT_FAILURE ); |
---|
| 1408 | } |
---|
| 1409 | } |
---|
| 1410 | |
---|
| 1411 | } |
---|
| 1412 | } |
---|
| 1413 | |
---|
| 1414 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
| 1415 | { |
---|
| 1416 | Bool bInterpolated = false; |
---|
| 1417 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1418 | { |
---|
| 1419 | Bool bInterpolatedCur; |
---|
| 1420 | xGetGeometryData( m_aiSynthViews[ uiERView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
| 1421 | bInterpolated |= bInterpolatedCur; |
---|
| 1422 | } |
---|
| 1423 | if( bInterpolated ) |
---|
| 1424 | { |
---|
| 1425 | std::cout << "Interpolating Camera Parameters for View " << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << std::endl; |
---|
| 1426 | } |
---|
| 1427 | } |
---|
| 1428 | } |
---|
| 1429 | |
---|
| 1430 | if( bCheckViewRange ) |
---|
| 1431 | { |
---|
| 1432 | Bool bAllExist = true; |
---|
| 1433 | for( Int iSynthViewIdx = 0; iSynthViewIdx < m_iNumberOfSynthViews; iSynthViewIdx++ ) |
---|
| 1434 | { |
---|
| 1435 | Bool bIsBaseView; |
---|
| 1436 | Int iDummy; |
---|
| 1437 | Bool bExist = getLeftRightBaseView( iSynthViewIdx, iDummy, iDummy, iDummy, bIsBaseView ); |
---|
| 1438 | bAllExist &= ( bExist || bIsBaseView ); |
---|
| 1439 | } |
---|
| 1440 | if( !bAllExist ) |
---|
| 1441 | { |
---|
| 1442 | std::cerr << "SynthViewNumbers must be within the range of BaseViewNumbers" << std::endl; |
---|
| 1443 | exit( EXIT_FAILURE ); |
---|
| 1444 | } |
---|
| 1445 | } |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | |
---|
| 1449 | Void |
---|
| 1450 | TAppComCamPara::update( UInt uiFrameId ) |
---|
| 1451 | { |
---|
| 1452 | |
---|
| 1453 | m_iCurrentFrameId = uiFrameId; |
---|
| 1454 | m_bCamParsCodedPrecSet = false; |
---|
| 1455 | |
---|
| 1456 | AOF( 0 <= uiFrameId && uiFrameId <= m_uiLastFrameId - m_uiFirstFrameId ); |
---|
| 1457 | if ( m_bCamParsVaryOverTime ) |
---|
| 1458 | { |
---|
| 1459 | xSetShiftParametersAndLUT( m_uiFirstFrameId + uiFrameId ); |
---|
| 1460 | } |
---|
| 1461 | } |
---|
| 1462 | |
---|
| 1463 | |
---|
| 1464 | Bool |
---|
| 1465 | TAppComCamPara::getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ) |
---|
| 1466 | { |
---|
| 1467 | Int iLeftSortedViewIdx, iRightSortedViewIdx, iDummy; |
---|
| 1468 | Bool bExist = xGetLeftRightView( m_aiSynthViews[ iSynthViewIdx ], m_aiSortedBaseViews, iDummy, iDummy, iLeftSortedViewIdx, iRightSortedViewIdx ); |
---|
| 1469 | rbIsBaseView = ( iLeftSortedViewIdx == iRightSortedViewIdx && iLeftSortedViewIdx != -1 ); |
---|
| 1470 | |
---|
| 1471 | Int iLeftViewIdx = ( iLeftSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iLeftSortedViewIdx ] : -1 ); |
---|
| 1472 | Int iRightViewIdx = ( iRightSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iRightSortedViewIdx ] : -1 ); |
---|
| 1473 | |
---|
| 1474 | if ( iLeftSortedViewIdx != -1 && iRightSortedViewIdx != -1 ) |
---|
| 1475 | { |
---|
| 1476 | riRelDistToLeft = getRelDistLeft( iSynthViewIdx, iLeftViewIdx, iRightViewIdx); |
---|
| 1477 | } |
---|
| 1478 | else |
---|
| 1479 | { |
---|
| 1480 | riRelDistToLeft = -1; |
---|
| 1481 | } |
---|
| 1482 | |
---|
| 1483 | riLeftViewIdx = iLeftViewIdx; |
---|
| 1484 | riRightViewIdx = iRightViewIdx; |
---|
| 1485 | |
---|
| 1486 | return bExist; |
---|
| 1487 | } |
---|
| 1488 | |
---|
[28] | 1489 | #if POZNAN_SYNTH |
---|
| 1490 | Bool |
---|
| 1491 | TAppComCamPara::getNearestBaseView( Int iSynthViewIdx, Int &riNearestViewIdx, Int &riRelDistToLeft, Bool& rbRenderFromLeft) |
---|
| 1492 | { |
---|
| 1493 | riNearestViewIdx = 0; |
---|
| 1494 | |
---|
[29] | 1495 | if( ( m_aiBaseId2SortedId[iSynthViewIdx] - m_aiBaseId2SortedId[riNearestViewIdx] ) > 0 ) |
---|
[28] | 1496 | { |
---|
| 1497 | rbRenderFromLeft = true; |
---|
| 1498 | } |
---|
| 1499 | else |
---|
| 1500 | { |
---|
| 1501 | rbRenderFromLeft = false; |
---|
| 1502 | } |
---|
| 1503 | |
---|
| 1504 | riRelDistToLeft = 128; //Not used for now; |
---|
| 1505 | |
---|
| 1506 | return true; |
---|
| 1507 | } |
---|
| 1508 | #endif |
---|
| 1509 | |
---|
| 1510 | |
---|
| 1511 | |
---|
[2] | 1512 | Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ) |
---|
| 1513 | { |
---|
| 1514 | //GT: Get normalized distance |
---|
| 1515 | Int iLeftViewDist = abs ( m_aiBaseId2SortedId[ iLeftViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
| 1516 | Int iRightViewDist = abs ( m_aiBaseId2SortedId[ iRightViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
| 1517 | Int64 iDistSum = iLeftViewDist + iRightViewDist; |
---|
| 1518 | return (iDistSum == 0) ? (1 << (REN_VDWEIGHT_PREC -1) ) : (Int) (( (((Int64) iLeftViewDist ) << REN_VDWEIGHT_PREC ) + (iDistSum >> 1) ) / iDistSum ); |
---|
| 1519 | } |
---|
| 1520 | |
---|
| 1521 | Int |
---|
| 1522 | TAppComCamPara::synthRelNum2Idx( Int iRelNum ) |
---|
| 1523 | { |
---|
| 1524 | return xGetViewId(m_aiRelSynthViewsNum, iRelNum ); |
---|
| 1525 | } |
---|
[28] | 1526 | |
---|
| 1527 | |
---|
| 1528 | #if POZNAN_MP |
---|
| 1529 | Bool |
---|
| 1530 | TAppComCamPara::isLeftView( Int iSynthViewIdx, Int iNearestViewIdx) |
---|
| 1531 | { |
---|
| 1532 | Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] ); |
---|
| 1533 | Int iFactor = ( bDecencdingVN ? -1 : 1 ); |
---|
| 1534 | |
---|
| 1535 | if( ( m_aiBaseId2SortedId[iSynthViewIdx] - m_aiBaseId2SortedId[iNearestViewIdx] ) * iFactor <= 0 ) return true; |
---|
| 1536 | else return false; |
---|
| 1537 | } |
---|
| 1538 | #endif |
---|