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