[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> |
---|
[608] | 51 | #if H_3D |
---|
[56] | 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 | |
---|
[608] | 60 | uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews ); |
---|
| 61 | uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews ); |
---|
[56] | 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 | Void |
---|
| 614 | TAppComCamPara::xGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ) |
---|
| 615 | { |
---|
| 616 | UInt uiFoundLine = -1; |
---|
[608] | 617 | #if H_3D_FIX_REN_WARNING |
---|
| 618 | if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) && xIsIn( m_aiSortedBaseViews, iView )) |
---|
| 619 | #else |
---|
[56] | 620 | if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) ) |
---|
[608] | 621 | #endif |
---|
[56] | 622 | { |
---|
| 623 | AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 ); |
---|
| 624 | rbInterpolated = false; |
---|
| 625 | rdFocalLength = m_aadCameraParameters[ uiFoundLine ][ 3 ]; |
---|
| 626 | rdPosition = m_aadCameraParameters[ uiFoundLine ][ 4 ]; |
---|
| 627 | rdCameraShift = m_aadCameraParameters[ uiFoundLine ][ 5 ]; |
---|
| 628 | } |
---|
| 629 | else |
---|
| 630 | { |
---|
| 631 | UInt uiLeftViewLine; |
---|
| 632 | UInt uiRightViewLine; |
---|
| 633 | Int iLeftView; |
---|
| 634 | Int iRightView; |
---|
| 635 | Int iDummy; |
---|
| 636 | |
---|
[608] | 637 | #if H_3D_FIX_REN_WARNING |
---|
| 638 | if( !xGetLeftRightView( iView, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ) || |
---|
| 639 | #else |
---|
[56] | 640 | if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) || |
---|
[608] | 641 | #endif |
---|
[56] | 642 | xGetCameraDataRow( iLeftView, uiFrame, uiLeftViewLine ) || |
---|
| 643 | xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine ) |
---|
| 644 | ) |
---|
| 645 | { |
---|
[608] | 646 | #if H_3D_FIX_REN_WARNING |
---|
| 647 | std::cerr << "No left or no right base view next to view " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
| 648 | #else |
---|
[56] | 649 | std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
[608] | 650 | #endif |
---|
[56] | 651 | AOT(true); |
---|
| 652 | exit( EXIT_FAILURE ); |
---|
| 653 | } |
---|
| 654 | AOT( m_aadCameraParameters[ uiLeftViewLine ].size() < 6 ); |
---|
| 655 | AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 ); |
---|
| 656 | |
---|
| 657 | // Linear Interpolation |
---|
| 658 | Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) ); |
---|
| 659 | rdFocalLength = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] ); |
---|
| 660 | rdPosition = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] ); |
---|
| 661 | rdCameraShift = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] ); |
---|
| 662 | rbInterpolated = true; |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | Bool |
---|
| 667 | TAppComCamPara::xGetShiftParameterReal( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset ) |
---|
| 668 | { |
---|
| 669 | AOT( m_bSetupFromCoded ); |
---|
| 670 | |
---|
| 671 | Bool bInterpolatedSource; |
---|
| 672 | Double dMinDepthSource; |
---|
| 673 | Double dMaxDepthSource; |
---|
| 674 | Double dFocalLengthSource; |
---|
| 675 | Double dPositionSource; |
---|
| 676 | Double dIntersectionSource; |
---|
| 677 | |
---|
| 678 | Bool bInterpolatedTarget; |
---|
| 679 | Double dPositionTarget; |
---|
| 680 | Double dIntersectionTarget; |
---|
| 681 | Double dFocalLengthTarget; |
---|
| 682 | |
---|
| 683 | Int iTargetViewNum; |
---|
| 684 | Int iSourceViewNum; |
---|
| 685 | |
---|
| 686 | if( bByIdx ) |
---|
| 687 | { |
---|
| 688 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 689 | iTargetViewNum = ( bExternal ? m_aiSynthViews[ uiTargetView ] : m_aiBaseViews[ uiTargetView ] ); |
---|
| 690 | } |
---|
| 691 | else |
---|
| 692 | { |
---|
| 693 | iSourceViewNum = (Int) uiSourceView; |
---|
| 694 | iTargetViewNum = (Int) uiTargetView; |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | xGetGeometryData( iSourceViewNum, uiFrame, dFocalLengthSource, dPositionSource, dIntersectionSource, bInterpolatedSource ); |
---|
| 698 | xGetZNearZFar ( iSourceViewNum, uiFrame, dMinDepthSource, dMaxDepthSource ); |
---|
| 699 | xGetGeometryData( iTargetViewNum, uiFrame, dFocalLengthTarget, dPositionTarget, dIntersectionTarget, bInterpolatedTarget ); |
---|
| 700 | |
---|
| 701 | Double dFactor = dFocalLengthSource * ( dPositionTarget - dPositionSource ); |
---|
| 702 | rdScale = dFactor * ( 1.0 / dMinDepthSource - 1.0 / dMaxDepthSource ) / (Double)( ( 1 << m_uiInputBitDepth ) - 1 ); |
---|
| 703 | rdOffset = dFactor / dMaxDepthSource - dIntersectionTarget + dIntersectionSource; |
---|
| 704 | |
---|
| 705 | return ( bInterpolatedSource || bInterpolatedTarget ); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | |
---|
| 709 | Void |
---|
| 710 | TAppComCamPara::xGetShiftParameterCoded( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bByIdx, Int& riScale, Int& riOffset ) |
---|
| 711 | { |
---|
| 712 | if ( m_bSetupFromCoded ) |
---|
| 713 | { |
---|
| 714 | if ( uiSourceView == uiTargetView ) |
---|
| 715 | { |
---|
| 716 | riScale = 0; |
---|
| 717 | riOffset = 0; |
---|
| 718 | return; |
---|
| 719 | } |
---|
| 720 | Int iCamParsCodedPrecision; |
---|
| 721 | xGetCodedCameraData( uiSourceView, uiTargetView, bByIdx, uiFrame, riScale, riOffset, iCamParsCodedPrecision ); |
---|
| 722 | |
---|
| 723 | if ( m_bCamParsCodedPrecSet ) |
---|
| 724 | { |
---|
| 725 | AOT( m_uiCamParsCodedPrecision != (UInt) iCamParsCodedPrecision ); |
---|
| 726 | } |
---|
| 727 | else |
---|
| 728 | { |
---|
| 729 | m_uiCamParsCodedPrecision = (UInt) iCamParsCodedPrecision; |
---|
| 730 | m_bCamParsCodedPrecSet = true; |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | else |
---|
| 734 | { |
---|
| 735 | Double dScale, dOffset; |
---|
| 736 | Bool bInterpolated = xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, false, bByIdx, dScale, dOffset ); |
---|
| 737 | AOT( bInterpolated ); // must be base view |
---|
| 738 | |
---|
| 739 | Double dMultOffset = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 ) ); |
---|
| 740 | Double dMultScale = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 + m_uiInputBitDepth ) ); |
---|
| 741 | riOffset = (Int)floor( dMultOffset * dOffset + .5 ); |
---|
| 742 | riScale = (Int)floor( dMultScale * dScale + .5 ); |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | } |
---|
| 746 | |
---|
| 747 | |
---|
| 748 | Void |
---|
| 749 | TAppComCamPara::xGetShiftParameterInt( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64& riScale, Int64& riOffset ) |
---|
| 750 | { |
---|
| 751 | Int iTargetViewNum; |
---|
| 752 | Int iSourceViewNum; |
---|
| 753 | Int iPrevBaseViewNum; |
---|
| 754 | Int iNextBaseViewNum; |
---|
| 755 | Int iTargetViewRelNum; |
---|
| 756 | |
---|
| 757 | if( bByIdx ) |
---|
| 758 | { |
---|
| 759 | |
---|
| 760 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 761 | |
---|
| 762 | if ( bExternal ) |
---|
| 763 | { |
---|
| 764 | iTargetViewNum = m_aiSynthViews [ uiTargetView ]; |
---|
| 765 | iTargetViewRelNum = m_aiRelSynthViewsNum[ uiTargetView ]; |
---|
| 766 | } |
---|
| 767 | else |
---|
| 768 | { |
---|
| 769 | iTargetViewNum = m_aiBaseViews [ uiTargetView ]; |
---|
| 770 | iTargetViewRelNum = m_aiBaseId2SortedId [ uiTargetView ] * ((Int) m_dViewNumPrec ); |
---|
| 771 | } |
---|
| 772 | } |
---|
| 773 | else |
---|
| 774 | { |
---|
| 775 | iSourceViewNum = (Int) uiSourceView; |
---|
| 776 | iTargetViewNum = (Int) uiTargetView; |
---|
| 777 | |
---|
| 778 | if ( bExternal ) |
---|
| 779 | { |
---|
| 780 | iTargetViewRelNum = m_aiRelSynthViewsNum[ xGetViewId( m_aiSynthViews, (Int) uiTargetView )]; |
---|
| 781 | } |
---|
| 782 | else |
---|
| 783 | { |
---|
| 784 | iTargetViewRelNum = m_aiBaseId2SortedId[ xGetBaseViewId( uiTargetView) ] * ((Int) m_dViewNumPrec ); |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | xGetPrevAndNextBaseView( iSourceViewNum, iTargetViewNum, iPrevBaseViewNum, iNextBaseViewNum ); |
---|
| 788 | AOT( iPrevBaseViewNum == -1 ); // should not happen |
---|
| 789 | AOT( iNextBaseViewNum == -1 ); // should not happen |
---|
| 790 | |
---|
| 791 | Int iSrcId = xGetBaseViewId( iSourceViewNum ); |
---|
| 792 | Int iPrevId = xGetBaseViewId( iPrevBaseViewNum ); |
---|
| 793 | Int iNextId = xGetBaseViewId( iNextBaseViewNum ); |
---|
| 794 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iPrevId ] ); // coded scale and offset must be set |
---|
| 795 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iNextId ] ); // coded scale and offset must be set |
---|
| 796 | |
---|
| 797 | Int iNextBaseViewRelNum = m_aiBaseId2SortedId[ iNextId ] * ((Int) m_dViewNumPrec ); |
---|
| 798 | Int iPrevBaseViewRelNum = m_aiBaseId2SortedId[ iPrevId ] * ((Int) m_dViewNumPrec ); |
---|
| 799 | |
---|
| 800 | Int64 iPrevScale = (Int64)m_aaiCodedScale [ iSrcId ][ iPrevId ]; |
---|
| 801 | Int64 iNextScale = (Int64)m_aaiCodedScale [ iSrcId ][ iNextId ]; |
---|
| 802 | Int64 iPrevOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iPrevId ] << m_uiBitDepthForLUT; |
---|
| 803 | Int64 iNextOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iNextId ] << m_uiBitDepthForLUT; |
---|
| 804 | |
---|
| 805 | if( iPrevBaseViewNum == iNextBaseViewNum ) |
---|
| 806 | { |
---|
| 807 | riScale = iNextScale; |
---|
| 808 | riOffset = iNextOffset; |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
| 812 | riScale = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextScale; |
---|
| 813 | riScale += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevScale; |
---|
| 814 | riOffset = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextOffset; |
---|
| 815 | riOffset += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevOffset; |
---|
| 816 | Int64 iD = Int64( iNextBaseViewRelNum - iPrevBaseViewRelNum ); |
---|
| 817 | Int64 iSA = ( riScale > 0 ? iD / 2 : -iD / 2 ); |
---|
| 818 | Int64 iOA = ( riOffset > 0 ? iD / 2 : -iD / 2 ); |
---|
| 819 | riScale = ( riScale + iSA ) / iD; |
---|
| 820 | riOffset = ( riOffset + iOA ) / iD; |
---|
| 821 | } |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | |
---|
| 825 | Void |
---|
| 826 | TAppComCamPara::xSetCodedScaleOffset( UInt uiFrame ) |
---|
| 827 | { |
---|
| 828 | for( UInt uiSourceId = 0; uiSourceId < m_iNumberOfBaseViews; uiSourceId++ ) |
---|
| 829 | { |
---|
| 830 | for( UInt uiTargetId = 0; uiTargetId < m_iNumberOfBaseViews; uiTargetId++ ) |
---|
| 831 | { |
---|
| 832 | Int iScale, iOffset; |
---|
| 833 | xGetShiftParameterCoded( uiSourceId, uiTargetId, uiFrame, true, iScale, iOffset ); |
---|
| 834 | m_aaiCodedScale [ uiSourceId ][ uiTargetId ] = iScale; |
---|
| 835 | m_aaiCodedOffset [ uiSourceId ][ uiTargetId ] = iOffset; |
---|
| 836 | m_aaiScaleAndOffsetSet [ uiSourceId ][ uiTargetId ] = 1; |
---|
| 837 | } |
---|
| 838 | } |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | |
---|
| 842 | Void |
---|
| 843 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiNumberSourceViews, UInt uiNumberTargetViews, UInt uiFrame, Bool bExternalReference , Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ) |
---|
| 844 | { |
---|
| 845 | if( uiNumberSourceViews <= 1 || uiNumberTargetViews == 0 ) |
---|
| 846 | { |
---|
| 847 | return; |
---|
| 848 | } |
---|
| 849 | AOF( radShiftParams != NULL && raiShiftParams != NULL && radLUT != NULL && raiLUT != NULL ); |
---|
| 850 | AOF( m_uiBitDepthForLUT == 8 ); |
---|
| 851 | |
---|
| 852 | Int iLog2DivLuma = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision; AOF( iLog2DivLuma > 0 ); |
---|
| 853 | Int iLog2DivChroma = iLog2DivLuma + 1; |
---|
[608] | 854 | |
---|
[56] | 855 | Double dMaxDispDev = 0.0; |
---|
| 856 | Double dMaxRndDispDvL = 0.0; |
---|
| 857 | Double dMaxRndDispDvC = 0.0; |
---|
[608] | 858 | |
---|
[56] | 859 | for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) |
---|
| 860 | { |
---|
| 861 | for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ ) |
---|
| 862 | { |
---|
| 863 | |
---|
| 864 | // integer-valued scale and offset |
---|
| 865 | Int64 iScale, iOffset; |
---|
| 866 | xGetShiftParameterInt ( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, iScale, iOffset ); |
---|
| 867 | raiShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = iScale; |
---|
| 868 | raiShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = iOffset; |
---|
| 869 | |
---|
| 870 | // offsets including rounding offsets |
---|
| 871 | Int64 iOffsetLuma = iOffset + ( ( 1 << iLog2DivLuma ) >> 1 ); |
---|
| 872 | Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 ); |
---|
| 873 | |
---|
| 874 | // real-valued scale and offset |
---|
| 875 | Double dScale, dOffset; |
---|
| 876 | |
---|
| 877 | if ( m_bSetupFromCoded ) |
---|
| 878 | { |
---|
| 879 | dScale = (Double) iScale / (( Double ) ( 1 << iLog2DivLuma )); |
---|
| 880 | dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma )); |
---|
| 881 | } |
---|
| 882 | else |
---|
| 883 | { |
---|
| 884 | xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, dScale, dOffset ); |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | radShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = dScale; |
---|
| 888 | radShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = dOffset; |
---|
| 889 | |
---|
| 890 | for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ ) |
---|
| 891 | { |
---|
| 892 | // real-valued look-up tables |
---|
| 893 | Double dShiftLuma = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
| 894 | Double dShiftChroma = dShiftLuma / 2; |
---|
| 895 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma; |
---|
| 896 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma; |
---|
| 897 | |
---|
| 898 | // integer-valued look-up tables |
---|
| 899 | Int64 iTempScale = (Int64)uiDepthValue * iScale; |
---|
| 900 | Int64 iTestScale = ( iTempScale + iOffset ); // for checking accuracy of camera parameters |
---|
| 901 | Int64 iShiftLuma = ( iTempScale + iOffsetLuma ) >> iLog2DivLuma; |
---|
| 902 | Int64 iShiftChroma = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma; |
---|
| 903 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma; |
---|
| 904 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma; |
---|
| 905 | |
---|
| 906 | // maximum deviation |
---|
[608] | 907 | #if H_3D_REN_MAX_DEV_OUT |
---|
| 908 | m_dMaxShiftDeviation = std::max( m_dMaxShiftDeviation, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) / Double( 1 << m_iLog2Precision ) ); |
---|
| 909 | #endif |
---|
| 910 | dMaxDispDev = std::max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); |
---|
| 911 | dMaxRndDispDvL = std::max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); |
---|
| 912 | dMaxRndDispDvC = std::max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); |
---|
[56] | 913 | } |
---|
| 914 | |
---|
| 915 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ]; |
---|
| 916 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ]; |
---|
| 917 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ]; |
---|
| 918 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ]; |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | // check maximum deviation |
---|
| 923 | Double dMaxAllowedDispDev = Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // counting only the impact of camera parameter rounding |
---|
| 924 | Double dMaxAllowedRndDispDvL = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // final rounding and impact of camera parameter rounding |
---|
| 925 | Double dMaxAllowedRndDispDvC = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ) / 2.0; // final rounding and impact of camera parameter rounding |
---|
| 926 | |
---|
| 927 | if( ( dMaxDispDev >= dMaxAllowedDispDev || dMaxRndDispDvL >= dMaxAllowedRndDispDvL || dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) && !m_bSetupFromCoded ) |
---|
| 928 | { |
---|
| 929 | std::cout << "Warning: Something wrong with the accuracy of coded camera parameters:" << std::endl; |
---|
| 930 | if( dMaxDispDev >= dMaxAllowedDispDev ) |
---|
| 931 | { |
---|
| 932 | std::cout << " max disparity difference is " << dMaxDispDev << " (allowed: " << dMaxAllowedDispDev << ")" << std::endl; |
---|
| 933 | } |
---|
| 934 | if( dMaxRndDispDvL >= dMaxAllowedRndDispDvL ) |
---|
| 935 | { |
---|
| 936 | std::cout << " max rnd luma disp diff is " << dMaxRndDispDvL << " (allowed: " << dMaxAllowedRndDispDvL << ")" << std::endl; |
---|
| 937 | } |
---|
| 938 | if( dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) |
---|
| 939 | { |
---|
| 940 | std::cout << " max rnd chroma disp diff is " << dMaxRndDispDvC << " (allowed: " << dMaxAllowedRndDispDvC << ")" << std::endl; |
---|
| 941 | } |
---|
| 942 | } |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | Void |
---|
| 946 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame ) |
---|
| 947 | { |
---|
| 948 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
| 949 | xSetCodedScaleOffset ( uiFrame ); |
---|
| 950 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, uiFrame, false, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
| 951 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
| 952 | }; |
---|
| 953 | |
---|
| 954 | |
---|
| 955 | Void |
---|
| 956 | TAppComCamPara::xGetCameraShifts( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift ) |
---|
| 957 | { |
---|
| 958 | Double dDummy, dCamPosSource, dCamPosTarget, dPicPosSource, dPicPosTarget; |
---|
| 959 | Bool bInterpolatedSource, bInterpolatedTarget; |
---|
| 960 | Int iTargetViewNum = m_aiBaseViews[ uiTargetView ]; |
---|
| 961 | Int iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
| 962 | |
---|
| 963 | xGetGeometryData( iSourceViewNum, uiFrame, dDummy, dCamPosSource, dPicPosSource, bInterpolatedSource ); |
---|
| 964 | xGetGeometryData( iTargetViewNum, uiFrame, dDummy, dCamPosTarget, dPicPosTarget, bInterpolatedTarget ); |
---|
| 965 | AOT( bInterpolatedSource || bInterpolatedTarget ); |
---|
| 966 | |
---|
| 967 | rdCamPosShift = ( dCamPosTarget - dCamPosSource ); |
---|
| 968 | rdPicPosShift = -( dPicPosTarget - dPicPosSource ); // to be consistent |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | |
---|
| 972 | Void |
---|
| 973 | TAppComCamPara::xSetPdmConversionParams() |
---|
| 974 | { |
---|
| 975 | AOF( m_aiViewOrderIndex[ 0 ] == 0 ); |
---|
| 976 | if ( m_bSetupFromCoded || m_iNumberOfBaseViews < 2 ) |
---|
| 977 | { |
---|
| 978 | return; |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | //--- determine (virtual) camera parameter shift between view order index 1 and base view (view order index 0) --- |
---|
| 982 | Double dCamPosShift, dPicPosShift; |
---|
| 983 | Int iMinAbsVOI = (1<<30); |
---|
| 984 | Int iMinAbsVOIId = 0; |
---|
| 985 | for( Int iBaseId = 1; iBaseId < m_iNumberOfBaseViews; iBaseId++ ) |
---|
| 986 | { |
---|
| 987 | Int iAbsVOI = ( m_aiViewOrderIndex[ iBaseId ] < 0 ? -m_aiViewOrderIndex[ iBaseId ] : m_aiViewOrderIndex[ iBaseId ] ); |
---|
| 988 | if( iAbsVOI < iMinAbsVOI ) |
---|
| 989 | { |
---|
| 990 | iMinAbsVOI = iAbsVOI; |
---|
| 991 | iMinAbsVOIId = iBaseId; |
---|
| 992 | } |
---|
| 993 | } |
---|
| 994 | AOF( iMinAbsVOIId != 0 && iMinAbsVOI != 0 ); |
---|
| 995 | xGetCameraShifts( 0, iMinAbsVOIId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
| 996 | |
---|
| 997 | //--- determine maximum absolute camera position shift, precision, and base scale --- |
---|
| 998 | Double dMaxAbsCamPosShift = 0.0; |
---|
| 999 | for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ ) |
---|
| 1000 | { |
---|
| 1001 | for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ ) |
---|
| 1002 | { |
---|
| 1003 | xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
| 1004 | dCamPosShift = ( dCamPosShift < 0.0 ? -dCamPosShift : dCamPosShift ); |
---|
| 1005 | dMaxAbsCamPosShift = ( dCamPosShift > dMaxAbsCamPosShift ? dCamPosShift : dMaxAbsCamPosShift ); |
---|
| 1006 | } |
---|
| 1007 | } |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | |
---|
| 1011 | |
---|
| 1012 | TAppComCamPara::TAppComCamPara() |
---|
| 1013 | { |
---|
| 1014 | m_dViewNumPrec = VIEW_NUM_PREC; // fixed |
---|
| 1015 | m_iLog2Precision = -1; |
---|
| 1016 | m_uiInputBitDepth = 0; |
---|
| 1017 | m_uiBitDepthForLUT = 8; // fixed |
---|
| 1018 | m_uiFirstFrameId = 0; |
---|
| 1019 | m_uiLastFrameId = 0; |
---|
| 1020 | |
---|
| 1021 | m_iNumberOfBaseViews = -1; |
---|
| 1022 | m_iNumberOfSynthViews = -1; |
---|
| 1023 | |
---|
| 1024 | m_uiCamParsCodedPrecision = 0; |
---|
| 1025 | m_bCamParsVaryOverTime = true; |
---|
| 1026 | |
---|
| 1027 | m_aaiCodedScale = 0; |
---|
| 1028 | m_aaiCodedOffset = 0; |
---|
| 1029 | m_aaiScaleAndOffsetSet = 0; |
---|
| 1030 | |
---|
| 1031 | m_adBaseViewShiftParameter = 0; |
---|
| 1032 | m_aiBaseViewShiftParameter = 0; |
---|
| 1033 | m_adSynthViewShiftParameter = 0; |
---|
| 1034 | m_aiSynthViewShiftParameter = 0; |
---|
| 1035 | |
---|
| 1036 | m_adBaseViewShiftLUT = 0; |
---|
| 1037 | m_aiBaseViewShiftLUT = 0; |
---|
| 1038 | m_adSynthViewShiftLUT = 0; |
---|
| 1039 | m_aiSynthViewShiftLUT = 0; |
---|
| 1040 | |
---|
| 1041 | m_bSetupFromCoded = false; |
---|
| 1042 | m_bCamParsCodedPrecSet = false; |
---|
| 1043 | |
---|
[608] | 1044 | #if H_3D_REN_MAX_DEV_OUT |
---|
| 1045 | m_dMaxShiftDeviation = -1; |
---|
| 1046 | #endif |
---|
[56] | 1047 | |
---|
| 1048 | } |
---|
| 1049 | |
---|
| 1050 | |
---|
| 1051 | TAppComCamPara::~TAppComCamPara() |
---|
| 1052 | { |
---|
| 1053 | xDeleteArray( m_adBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
| 1054 | xDeleteArray( m_aiBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
| 1055 | xDeleteArray( m_adBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
| 1056 | xDeleteArray( m_aiBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
| 1057 | |
---|
[608] | 1058 | xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); |
---|
| 1059 | xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); |
---|
| 1060 | xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews), 2 ); |
---|
| 1061 | xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, std::max( (Int)1 ,m_iNumberOfSynthViews), 2 ); |
---|
[56] | 1062 | |
---|
| 1063 | xDeleteArray( m_aaiCodedScale, m_iNumberOfBaseViews ); |
---|
| 1064 | xDeleteArray( m_aaiCodedOffset, m_iNumberOfBaseViews ); |
---|
| 1065 | xDeleteArray( m_aaiScaleAndOffsetSet, m_iNumberOfBaseViews ); |
---|
| 1066 | |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | Void |
---|
| 1070 | TAppComCamPara::xSetupBaseViewsFromCoded() |
---|
| 1071 | { |
---|
| 1072 | //===== get and sort views given in camera parameter file and set list of base views and related arrays ===== |
---|
| 1073 | // get left-right order and coding order from cfg-file |
---|
| 1074 | std::vector<Int> aiViewOrderIdx; // Left Right Order |
---|
| 1075 | std::vector<Int> aiViewId ; // Coding Order |
---|
| 1076 | |
---|
| 1077 | Int iMinViewOrderIdx = MAX_INT; |
---|
| 1078 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1079 | { |
---|
| 1080 | if (m_aadCameraParameters[uiRow].size() != 2 ) |
---|
| 1081 | break; |
---|
| 1082 | |
---|
| 1083 | Int iViewOrderIdx = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] ); |
---|
[608] | 1084 | iMinViewOrderIdx = std::min( iViewOrderIdx, iMinViewOrderIdx ); |
---|
[56] | 1085 | |
---|
| 1086 | aiViewOrderIdx .push_back( iViewOrderIdx ); |
---|
| 1087 | aiViewId .push_back( (Int) m_aadCameraParameters[ uiRow ][ 0 ] ); |
---|
| 1088 | } |
---|
| 1089 | |
---|
| 1090 | // create base view numbers |
---|
| 1091 | AOT( aiViewId.size() != aiViewOrderIdx.size() ); |
---|
| 1092 | m_iNumberOfBaseViews = (Int) aiViewId.size(); |
---|
| 1093 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1094 | { |
---|
| 1095 | aiViewOrderIdx[iCurBaseView] = ( aiViewOrderIdx[iCurBaseView] - iMinViewOrderIdx); |
---|
| 1096 | m_aiBaseViews .push_back( aiViewOrderIdx[iCurBaseView] * ( (Int) m_dViewNumPrec) ); |
---|
| 1097 | m_aiBaseId2SortedId.push_back( iCurBaseView ); |
---|
| 1098 | m_aiBaseSortedId2Id.push_back( iCurBaseView ); |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | m_iNumberOfBaseViews = (Int) m_aiBaseViews.size(); |
---|
| 1102 | |
---|
| 1103 | std::vector<Int> aiSortedViewOrderIdx = aiViewOrderIdx; |
---|
| 1104 | |
---|
| 1105 | // sort base views according to View Order Idx |
---|
| 1106 | m_aiSortedBaseViews = m_aiBaseViews; |
---|
| 1107 | for (Int iCurBaseView = 1; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1108 | { |
---|
| 1109 | Int iCurViewOrder = aiSortedViewOrderIdx[iCurBaseView]; |
---|
| 1110 | for (Int iCurSearchPos = iCurBaseView; iCurSearchPos >= 0; iCurSearchPos-- ) |
---|
| 1111 | { |
---|
| 1112 | if ( iCurViewOrder < aiSortedViewOrderIdx[iCurSearchPos] ) |
---|
| 1113 | { |
---|
| 1114 | Int iTempViewId = m_aiSortedBaseViews[iCurSearchPos]; |
---|
| 1115 | m_aiSortedBaseViews[iCurSearchPos] = m_aiSortedBaseViews[iCurBaseView]; |
---|
| 1116 | m_aiSortedBaseViews[iCurBaseView ] = iTempViewId; |
---|
| 1117 | |
---|
| 1118 | Int iTempViewOrderIdx = aiSortedViewOrderIdx[iCurSearchPos]; |
---|
| 1119 | aiSortedViewOrderIdx[iCurSearchPos] = aiSortedViewOrderIdx[iCurBaseView]; |
---|
| 1120 | aiSortedViewOrderIdx[iCurBaseView ] = iTempViewOrderIdx; |
---|
| 1121 | |
---|
| 1122 | Int iTempPos = m_aiBaseSortedId2Id[iCurSearchPos]; |
---|
| 1123 | m_aiBaseSortedId2Id[iCurSearchPos] = m_aiBaseSortedId2Id[iCurBaseView]; |
---|
| 1124 | m_aiBaseSortedId2Id[iCurBaseView] = iTempPos; |
---|
| 1125 | iCurBaseView--; |
---|
| 1126 | } |
---|
| 1127 | } |
---|
| 1128 | } |
---|
| 1129 | |
---|
| 1130 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
| 1131 | { |
---|
| 1132 | m_aiBaseId2SortedId[m_aiBaseSortedId2Id[iCurBaseView]] = iCurBaseView; |
---|
| 1133 | } |
---|
| 1134 | |
---|
| 1135 | m_aiViewsInCfgFile = m_aiSortedBaseViews; |
---|
| 1136 | |
---|
| 1137 | // check |
---|
| 1138 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
| 1139 | { |
---|
| 1140 | std::cerr << "Failed reading camera parameter file" << std::endl; |
---|
| 1141 | std::cerr << "At least two views must be given" << std::endl; |
---|
| 1142 | AOT(true); |
---|
| 1143 | exit( EXIT_FAILURE ); |
---|
| 1144 | } |
---|
| 1145 | |
---|
| 1146 | // translate coding order to view order |
---|
| 1147 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1148 | { |
---|
| 1149 | if (m_aadCameraParameters[uiRow].size() == 2 ) |
---|
| 1150 | continue; |
---|
| 1151 | |
---|
| 1152 | m_aadCameraParameters[ uiRow ][ 2 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 2 ] ) ]; |
---|
| 1153 | m_aadCameraParameters[ uiRow ][ 3 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 3 ] ) ]; |
---|
| 1154 | } |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | Void TAppComCamPara::xSetupBaseViews( Char* pchBaseViewNumbers, UInt uiNumBaseViews ) |
---|
| 1158 | { |
---|
| 1159 | // init list |
---|
| 1160 | std::vector<Int> aiViewsInCfg; |
---|
| 1161 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
| 1162 | { |
---|
| 1163 | aiViewsInCfg.push_back( (Int)( m_aadCameraParameters[ uiRow ][ 0 ] * m_dViewNumPrec ) ); |
---|
| 1164 | } |
---|
| 1165 | // remove duplicated items |
---|
| 1166 | std::sort( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
| 1167 | std::vector<Int>::iterator cIterNewEnd = std::unique( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
| 1168 | aiViewsInCfg.erase( cIterNewEnd, aiViewsInCfg.end() ); |
---|
| 1169 | // sort (from left to right) |
---|
| 1170 | std::vector<Int> aiDummyI2SI, aiDummySI2I; |
---|
| 1171 | xGetSortedViewList( aiViewsInCfg, m_aiViewsInCfgFile, aiDummyI2SI, aiDummySI2I ); |
---|
| 1172 | // check |
---|
| 1173 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
| 1174 | { |
---|
[608] | 1175 | std::cerr << "Failed reading config file" << std::endl; |
---|
[56] | 1176 | std::cerr << "At least two views must be given" << std::endl; |
---|
| 1177 | exit( EXIT_FAILURE ); |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | |
---|
| 1181 | |
---|
| 1182 | //===== set list of base views and related arrays ===== |
---|
| 1183 | if( pchBaseViewNumbers == 0 ) |
---|
| 1184 | { |
---|
| 1185 | std::cerr << "BaseViewCameraNumbers must be given" << std::endl; |
---|
| 1186 | exit( EXIT_FAILURE ); |
---|
| 1187 | }; |
---|
| 1188 | |
---|
| 1189 | convertNumberString( pchBaseViewNumbers, m_aiBaseViews, m_dViewNumPrec ); |
---|
| 1190 | while( (UInt)m_aiBaseViews.size() > uiNumBaseViews ) |
---|
| 1191 | { |
---|
| 1192 | m_aiBaseViews.pop_back(); |
---|
| 1193 | } |
---|
| 1194 | xGetSortedViewList( m_aiBaseViews, m_aiSortedBaseViews, m_aiBaseId2SortedId, m_aiBaseSortedId2Id ); |
---|
| 1195 | m_iNumberOfBaseViews = (Int)m_aiBaseViews.size(); |
---|
| 1196 | } |
---|
| 1197 | |
---|
| 1198 | |
---|
| 1199 | Void |
---|
| 1200 | TAppComCamPara::init( UInt uiNumBaseViews, |
---|
| 1201 | UInt uiInputBitDepth, |
---|
| 1202 | UInt uiCodedCamParsPrecision, |
---|
| 1203 | UInt uiStartFrameId, |
---|
| 1204 | UInt uiNumFrames, |
---|
| 1205 | Char* pchCfgFileName, |
---|
| 1206 | Char* pchBaseViewNumbers, |
---|
| 1207 | Char* pchSynthViewNumbers, |
---|
| 1208 | std::vector<Int>* paiSynthViewNumbers, |
---|
| 1209 | Int iLog2Precision ) |
---|
| 1210 | { |
---|
| 1211 | //===== set miscellaneous variables ===== |
---|
| 1212 | m_uiInputBitDepth = uiInputBitDepth; |
---|
| 1213 | m_uiFirstFrameId = uiStartFrameId; |
---|
| 1214 | m_uiLastFrameId = uiStartFrameId + uiNumFrames - 1; |
---|
| 1215 | m_uiCamParsCodedPrecision = uiCodedCamParsPrecision; |
---|
| 1216 | m_iLog2Precision = iLog2Precision; |
---|
| 1217 | #if HHI_INTERVIEW_SKIP |
---|
| 1218 | m_iCurrentFrameId = 0 ; |
---|
| 1219 | #endif |
---|
| 1220 | |
---|
| 1221 | xReadCameraParameterFile( pchCfgFileName ); |
---|
| 1222 | |
---|
| 1223 | m_bSetupFromCoded = ( m_aadCameraParameters[ 0 ].size() == 2 ); |
---|
| 1224 | |
---|
| 1225 | if ( m_bSetupFromCoded ) |
---|
| 1226 | { |
---|
| 1227 | std::cout << "Detected decoded camera parameter file. Overwriting base view settings from cfg file. " << std::endl; |
---|
| 1228 | xSetupBaseViewsFromCoded(); |
---|
| 1229 | } |
---|
| 1230 | else |
---|
| 1231 | { |
---|
| 1232 | xSetupBaseViews( pchBaseViewNumbers, uiNumBaseViews ); |
---|
| 1233 | } |
---|
| 1234 | |
---|
| 1235 | //===== set list of external (virtual) views ===== |
---|
| 1236 | m_aiSynthViews.clear(); |
---|
| 1237 | |
---|
| 1238 | if( pchSynthViewNumbers != 0 || paiSynthViewNumbers != 0) |
---|
| 1239 | { |
---|
| 1240 | std::vector<Int> aiTmpSynthViews; |
---|
| 1241 | |
---|
| 1242 | AOT( ( pchSynthViewNumbers != NULL ) && ( paiSynthViewNumbers != NULL ) ); |
---|
| 1243 | |
---|
| 1244 | if ( pchSynthViewNumbers != NULL ) |
---|
| 1245 | { |
---|
| 1246 | convertNumberString( pchSynthViewNumbers, aiTmpSynthViews, m_dViewNumPrec ); |
---|
| 1247 | } |
---|
| 1248 | else |
---|
| 1249 | { |
---|
| 1250 | aiTmpSynthViews = (*paiSynthViewNumbers); |
---|
| 1251 | } |
---|
| 1252 | |
---|
| 1253 | for( UInt uiSId = 0; uiSId < (UInt)aiTmpSynthViews.size(); uiSId++ ) |
---|
| 1254 | { |
---|
| 1255 | |
---|
| 1256 | Int iViewNumPrec = (Int) m_dViewNumPrec; |
---|
| 1257 | Int iLeftBaseViewIdx = aiTmpSynthViews[ uiSId ] / iViewNumPrec; |
---|
| 1258 | Int iRightBaseViewIdx = ( aiTmpSynthViews[ uiSId ] + (iViewNumPrec - 1) ) / iViewNumPrec; |
---|
| 1259 | |
---|
| 1260 | if ( iLeftBaseViewIdx < 0 || iRightBaseViewIdx >= m_iNumberOfBaseViews ) |
---|
| 1261 | { |
---|
| 1262 | std::cerr << "SynthViewCameraNumbers must be greater and equal to 0 and smaller than number of base views" << std::endl; |
---|
| 1263 | AOT(true); |
---|
| 1264 | exit( EXIT_FAILURE ); |
---|
| 1265 | } |
---|
| 1266 | |
---|
| 1267 | Int64 iLeftBaseViewRelNum = iLeftBaseViewIdx * iViewNumPrec; |
---|
| 1268 | Int64 iRightBaseViewRelNum = iRightBaseViewIdx * iViewNumPrec; |
---|
| 1269 | |
---|
| 1270 | Int64 iDiffBaseViewRelNum = iRightBaseViewRelNum - iLeftBaseViewRelNum; |
---|
| 1271 | |
---|
| 1272 | Int64 iSynthViewRelNum = aiTmpSynthViews[ uiSId ]; |
---|
| 1273 | Int64 iLeftBaseNum = m_aiSortedBaseViews[ iLeftBaseViewIdx ]; |
---|
| 1274 | Int64 iRightBaseNum = m_aiSortedBaseViews[ iRightBaseViewIdx ]; |
---|
| 1275 | Int64 iDiffBaseNum = iRightBaseNum - iLeftBaseNum; |
---|
| 1276 | Int64 iSynthViewNum; |
---|
| 1277 | |
---|
| 1278 | if ( iDiffBaseViewRelNum != 0) |
---|
| 1279 | { |
---|
| 1280 | AOT( (Int) iDiffBaseViewRelNum != iViewNumPrec ); |
---|
| 1281 | Int iFact = iDiffBaseNum > 0 ? 1 : -1; |
---|
| 1282 | iSynthViewNum = iLeftBaseNum + ( iDiffBaseNum * ( iSynthViewRelNum - iLeftBaseViewRelNum ) + (iViewNumPrec >> 1) * iFact ) / ( iViewNumPrec ); |
---|
| 1283 | } |
---|
| 1284 | else |
---|
| 1285 | { |
---|
| 1286 | iSynthViewNum = iLeftBaseNum; |
---|
| 1287 | } |
---|
| 1288 | |
---|
| 1289 | m_aiRelSynthViewsNum.push_back( aiTmpSynthViews[ uiSId ] ); |
---|
| 1290 | m_aiSynthViews .push_back( (Int) iSynthViewNum ); |
---|
| 1291 | } |
---|
| 1292 | } |
---|
| 1293 | m_iNumberOfSynthViews = (Int)m_aiSynthViews.size(); |
---|
| 1294 | |
---|
| 1295 | |
---|
| 1296 | //===== set derived parameters ===== |
---|
| 1297 | xGetViewOrderIndices( m_aiBaseId2SortedId, m_aiViewOrderIndex ); |
---|
| 1298 | m_bCamParsVaryOverTime = xGetCamParsChangeFlag(); |
---|
| 1299 | |
---|
| 1300 | |
---|
| 1301 | //===== create arrays ===== |
---|
| 1302 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
| 1303 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
| 1304 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedScale ); |
---|
| 1305 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedOffset ); |
---|
| 1306 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet ); |
---|
| 1307 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
| 1308 | |
---|
| 1309 | //===== init arrays for first frame ===== |
---|
| 1310 | xSetShiftParametersAndLUT( m_uiFirstFrameId ); |
---|
| 1311 | } |
---|
| 1312 | |
---|
| 1313 | |
---|
| 1314 | Void |
---|
| 1315 | TAppComCamPara::check( Bool bCheckViewRange, Bool bCheckFrameRange ) |
---|
| 1316 | { |
---|
| 1317 | if( bCheckFrameRange ) |
---|
| 1318 | { |
---|
| 1319 | Double dDummy; |
---|
| 1320 | |
---|
| 1321 | for( UInt uiBaseView = 0; uiBaseView < m_aiBaseViews.size(); uiBaseView++ ) |
---|
| 1322 | { |
---|
| 1323 | if ( m_bSetupFromCoded ) |
---|
| 1324 | { |
---|
| 1325 | for( UInt uiTargetView = 0; uiTargetView < m_aiBaseViews.size(); uiTargetView++ ) |
---|
| 1326 | { |
---|
| 1327 | if ( uiTargetView == uiBaseView ) |
---|
| 1328 | continue; |
---|
| 1329 | |
---|
| 1330 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1331 | { |
---|
| 1332 | Int iDummy; |
---|
| 1333 | |
---|
| 1334 | xGetCodedCameraData( uiBaseView, uiTargetView, true , uiFrame, iDummy, iDummy, iDummy ); |
---|
| 1335 | } |
---|
| 1336 | } |
---|
| 1337 | } |
---|
| 1338 | else |
---|
| 1339 | { |
---|
[608] | 1340 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1341 | { |
---|
| 1342 | Bool bInterpolatedCur; |
---|
| 1343 | xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
| 1344 | xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); |
---|
| 1345 | |
---|
| 1346 | if( bInterpolatedCur ) |
---|
| 1347 | { |
---|
| 1348 | std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; |
---|
| 1349 | exit( EXIT_FAILURE ); |
---|
| 1350 | } |
---|
| 1351 | } |
---|
| 1352 | } |
---|
| 1353 | } |
---|
| 1354 | #if H_3D_FIX_REN_WARNING |
---|
| 1355 | Bool bIgnoreFirst = true; |
---|
| 1356 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
| 1357 | { |
---|
| 1358 | if ( xIsIn(m_aiViewsInCfgFile, m_aiSynthViews[ uiERView ] ) ) |
---|
[56] | 1359 | { |
---|
[608] | 1360 | if ( bIgnoreFirst ) |
---|
[56] | 1361 | { |
---|
[608] | 1362 | std::cout << "Ignoring CameraParameterFile entries for virtual view(s): " ; |
---|
| 1363 | //GT: Integer precision virtual view camera parameters are always interpolated from coded views camera parameters. |
---|
| 1364 | bIgnoreFirst = false; |
---|
[56] | 1365 | } |
---|
[608] | 1366 | std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; |
---|
[56] | 1367 | } |
---|
| 1368 | } |
---|
[608] | 1369 | if ( !bIgnoreFirst ) |
---|
| 1370 | { |
---|
| 1371 | std::cout << std::endl; |
---|
| 1372 | } |
---|
| 1373 | #endif |
---|
[56] | 1374 | |
---|
[608] | 1375 | Bool bInterpolateFirst = true; |
---|
| 1376 | Bool bAnyInterpolated = false; |
---|
[56] | 1377 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
| 1378 | { |
---|
| 1379 | Bool bInterpolated = false; |
---|
| 1380 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
| 1381 | { |
---|
| 1382 | Bool bInterpolatedCur; |
---|
| 1383 | xGetGeometryData( m_aiSynthViews[ uiERView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
| 1384 | bInterpolated |= bInterpolatedCur; |
---|
| 1385 | } |
---|
[608] | 1386 | |
---|
[56] | 1387 | if( bInterpolated ) |
---|
| 1388 | { |
---|
[608] | 1389 | bAnyInterpolated = true; |
---|
| 1390 | if ( bInterpolateFirst ) |
---|
| 1391 | { |
---|
| 1392 | #if H_3D_FIX_REN_WARNING |
---|
| 1393 | std::cout << "Interpolating camera parameters for virtual view(s): " ; |
---|
| 1394 | #else |
---|
| 1395 | std::cout << "Interpolating Camera Parameters for View(s) " ; |
---|
| 1396 | #endif |
---|
| 1397 | bInterpolateFirst = false; |
---|
| 1398 | } |
---|
| 1399 | std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; |
---|
[56] | 1400 | } |
---|
| 1401 | } |
---|
[608] | 1402 | if ( bAnyInterpolated ) |
---|
| 1403 | std::cout << std::endl; |
---|
[56] | 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 | |
---|
[608] | 1438 | #if H_3D_VSO |
---|
[102] | 1439 | Void |
---|
[608] | 1440 | TAppComCamPara::setDispCoeff( UInt uiFrameId, Int iViewIdx ) |
---|
[102] | 1441 | { |
---|
| 1442 | UInt uiFrame = m_uiFirstFrameId + uiFrameId; |
---|
| 1443 | Int iSourceViewNum = m_aiBaseViews[ iViewIdx ]; |
---|
| 1444 | Double dBaseLine = 0.0; |
---|
| 1445 | Double dFL1, dCS1, dCP1, dZN1, dZF1; |
---|
| 1446 | Bool bInterpolated; |
---|
| 1447 | double dPos[3]; |
---|
[56] | 1448 | |
---|
[102] | 1449 | if( m_iNumberOfBaseViews == 3 ) |
---|
| 1450 | { |
---|
| 1451 | xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated ); |
---|
| 1452 | xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated ); |
---|
| 1453 | xGetGeometryData( m_aiBaseViews[2], uiFrame, dFL1, dPos[2], dCS1, bInterpolated ); |
---|
| 1454 | |
---|
| 1455 | xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated ); |
---|
| 1456 | xGetZNearZFar ( iSourceViewNum, uiFrame, dZN1, dZF1 ); |
---|
| 1457 | |
---|
[608] | 1458 | dBaseLine = ( std::max( dPos[0], std::max( dPos[1], dPos[2] ) ) - std::min( dPos[0], std::min( dPos[1], dPos[2] ) ) ) / 2.0; |
---|
[102] | 1459 | } |
---|
| 1460 | else if( m_iNumberOfBaseViews == 2 ) |
---|
| 1461 | { |
---|
| 1462 | xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated ); |
---|
| 1463 | xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated ); |
---|
| 1464 | |
---|
| 1465 | xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated ); |
---|
| 1466 | xGetZNearZFar ( iSourceViewNum, uiFrame, dZN1, dZF1 ); |
---|
| 1467 | |
---|
| 1468 | dBaseLine = dPos[0] - dPos[1]; |
---|
| 1469 | } |
---|
| 1470 | |
---|
| 1471 | m_dDispCoeff = fabs( dFL1 * ( dBaseLine / 2.0 ) / 255.0 * ( 1.0/dZN1 - 1.0/dZF1 ) ); |
---|
| 1472 | } |
---|
| 1473 | #endif |
---|
| 1474 | |
---|
[56] | 1475 | Bool |
---|
| 1476 | TAppComCamPara::getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ) |
---|
| 1477 | { |
---|
| 1478 | Int iLeftSortedViewIdx, iRightSortedViewIdx, iDummy; |
---|
| 1479 | Bool bExist = xGetLeftRightView( m_aiSynthViews[ iSynthViewIdx ], m_aiSortedBaseViews, iDummy, iDummy, iLeftSortedViewIdx, iRightSortedViewIdx ); |
---|
| 1480 | rbIsBaseView = ( iLeftSortedViewIdx == iRightSortedViewIdx && iLeftSortedViewIdx != -1 ); |
---|
| 1481 | |
---|
| 1482 | Int iLeftViewIdx = ( iLeftSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iLeftSortedViewIdx ] : -1 ); |
---|
| 1483 | Int iRightViewIdx = ( iRightSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iRightSortedViewIdx ] : -1 ); |
---|
| 1484 | |
---|
| 1485 | if ( iLeftSortedViewIdx != -1 && iRightSortedViewIdx != -1 ) |
---|
| 1486 | { |
---|
| 1487 | riRelDistToLeft = getRelDistLeft( iSynthViewIdx, iLeftViewIdx, iRightViewIdx); |
---|
| 1488 | } |
---|
| 1489 | else |
---|
| 1490 | { |
---|
| 1491 | riRelDistToLeft = -1; |
---|
| 1492 | } |
---|
| 1493 | |
---|
| 1494 | riLeftViewIdx = iLeftViewIdx; |
---|
| 1495 | riRightViewIdx = iRightViewIdx; |
---|
| 1496 | |
---|
| 1497 | return bExist; |
---|
| 1498 | } |
---|
| 1499 | |
---|
[608] | 1500 | #if H_3D_FIX_REN_WARNING |
---|
| 1501 | Bool |
---|
| 1502 | TAppComCamPara::xIsIn( std::vector<Int>& rVec, Int iElem) |
---|
| 1503 | { |
---|
| 1504 | Bool bFound = false; |
---|
| 1505 | for (Int idx = 0; idx < rVec.size() && !bFound; idx++) |
---|
| 1506 | { |
---|
| 1507 | bFound = bFound || rVec[idx] == iElem; |
---|
| 1508 | } |
---|
| 1509 | return bFound; |
---|
| 1510 | } |
---|
| 1511 | #endif |
---|
| 1512 | |
---|
[56] | 1513 | Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ) |
---|
| 1514 | { |
---|
| 1515 | //GT: Get normalized distance |
---|
| 1516 | Int iLeftViewDist = abs ( m_aiBaseId2SortedId[ iLeftViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
| 1517 | Int iRightViewDist = abs ( m_aiBaseId2SortedId[ iRightViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
| 1518 | Int64 iDistSum = iLeftViewDist + iRightViewDist; |
---|
| 1519 | return (iDistSum == 0) ? (1 << (REN_VDWEIGHT_PREC -1) ) : (Int) (( (((Int64) iLeftViewDist ) << REN_VDWEIGHT_PREC ) + (iDistSum >> 1) ) / iDistSum ); |
---|
| 1520 | } |
---|
| 1521 | |
---|
| 1522 | Int |
---|
| 1523 | TAppComCamPara::synthRelNum2Idx( Int iRelNum ) |
---|
| 1524 | { |
---|
| 1525 | return xGetViewId(m_aiRelSynthViewsNum, iRelNum ); |
---|
| 1526 | } |
---|
[608] | 1527 | #endif |
---|