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