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-2015, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | // Include files |
---|
38 | #include "TAppComCamPara.h" |
---|
39 | |
---|
40 | |
---|
41 | #include <stdlib.h> |
---|
42 | #include <math.h> |
---|
43 | #include <errno.h> |
---|
44 | #include <assert.h> |
---|
45 | #include <vector> |
---|
46 | #include <iostream> |
---|
47 | #include <fstream> |
---|
48 | #include <algorithm> |
---|
49 | #include <functional> |
---|
50 | #include <string> |
---|
51 | #if NH_3D |
---|
52 | |
---|
53 | |
---|
54 | Void |
---|
55 | TAppComCamPara::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ) |
---|
56 | { |
---|
57 | AOF( m_uiBitDepthForLUT == 8 ); |
---|
58 | AOF( radShiftParams == NULL && raiShiftParams == NULL && radLUT == NULL && raiLUT == NULL ); |
---|
59 | |
---|
60 | uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews ); |
---|
61 | uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews ); |
---|
62 | |
---|
63 | radShiftParams = new Double** [ uiNumberSourceViews ]; |
---|
64 | raiShiftParams = new Int64 ** [ uiNumberSourceViews ]; |
---|
65 | radLUT = new Double***[ uiNumberSourceViews ]; |
---|
66 | raiLUT = new Int ***[ uiNumberSourceViews ]; |
---|
67 | |
---|
68 | for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) |
---|
69 | { |
---|
70 | radShiftParams[ uiSourceView ] = new Double* [ uiNumberTargetViews ]; |
---|
71 | raiShiftParams[ uiSourceView ] = new Int64 * [ uiNumberTargetViews ]; |
---|
72 | radLUT [ uiSourceView ] = new Double**[ uiNumberTargetViews ]; |
---|
73 | raiLUT [ uiSourceView ] = new Int **[ uiNumberTargetViews ]; |
---|
74 | |
---|
75 | for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ ) |
---|
76 | { |
---|
77 | radShiftParams[ uiSourceView ][ uiTargetView ] = new Double [ 2 ]; |
---|
78 | raiShiftParams[ uiSourceView ][ uiTargetView ] = new Int64 [ 2 ]; |
---|
79 | |
---|
80 | radLUT [ uiSourceView ][ uiTargetView ] = new Double*[ 2 ]; |
---|
81 | radLUT [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ]; |
---|
82 | radLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ]; |
---|
83 | |
---|
84 | raiLUT [ uiSourceView ][ uiTargetView ] = new Int* [ 2 ]; |
---|
85 | raiLUT [ uiSourceView ][ uiTargetView ][ 0 ] = new Int [ 257 ]; |
---|
86 | raiLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Int [ 257 ]; |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | 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 | |
---|
402 | |
---|
403 | Bool |
---|
404 | TAppComCamPara::xGetCamParsChangeFlag() |
---|
405 | { |
---|
406 | Bool bChangeDetected = false; |
---|
407 | for( Int iBaseViewId = 0; !bChangeDetected && iBaseViewId < m_iNumberOfBaseViews; iBaseViewId++ ) |
---|
408 | { |
---|
409 | if ( m_bSetupFromCoded ) |
---|
410 | { |
---|
411 | for( Int iTargetViewId = 0; !bChangeDetected && iTargetViewId < m_iNumberOfBaseViews; iTargetViewId++ ) |
---|
412 | { |
---|
413 | Int iTargetView = m_aiBaseViews[iTargetViewId]; |
---|
414 | Int iSourceView = m_aiBaseViews[iBaseViewId ]; |
---|
415 | |
---|
416 | Int iS1 ,iSX; |
---|
417 | Int iO1 ,iOX; |
---|
418 | Int iP1 ,iPX; |
---|
419 | |
---|
420 | if ( iSourceView == iTargetView ) |
---|
421 | continue; |
---|
422 | |
---|
423 | xGetCodedCameraData( iSourceView, iTargetView, false, 0, iS1, iO1, iP1 ); |
---|
424 | for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ ) |
---|
425 | { |
---|
426 | xGetCodedCameraData( iSourceView, iTargetView, false, uiFrameId, iSX, iOX, iPX ); |
---|
427 | |
---|
428 | if( iS1 != iSX || iO1 != iOX || iP1 != iPX ) |
---|
429 | { |
---|
430 | bChangeDetected = true; |
---|
431 | } |
---|
432 | } |
---|
433 | } |
---|
434 | } |
---|
435 | else |
---|
436 | { |
---|
437 | Int iBaseView = m_aiBaseViews[ iBaseViewId ]; |
---|
438 | Double dFL1, dFLX; |
---|
439 | Double dCP1, dCPX; |
---|
440 | Double dCS1, dCSX; |
---|
441 | Double dZN1, dZNX; |
---|
442 | Double dZF1, dZFX; |
---|
443 | Bool bInterpolated; |
---|
444 | xGetGeometryData( iBaseView, m_uiFirstFrameId, dFL1, dCP1, dCS1, bInterpolated ); AOT( bInterpolated ); |
---|
445 | xGetZNearZFar ( iBaseView, m_uiFirstFrameId, dZN1, dZF1 ); |
---|
446 | |
---|
447 | for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ ) |
---|
448 | { |
---|
449 | xGetGeometryData( iBaseView, uiFrameId, dFLX, dCPX, dCSX, bInterpolated ); AOT( bInterpolated ); |
---|
450 | xGetZNearZFar ( iBaseView, uiFrameId, dZNX, dZFX ); |
---|
451 | |
---|
452 | if( dFL1 != dFLX || dCP1 != dCPX || dCS1 != dCSX || dZN1 != dZNX || dZF1 != dZFX ) |
---|
453 | { |
---|
454 | bChangeDetected = true; |
---|
455 | } |
---|
456 | } |
---|
457 | } |
---|
458 | } |
---|
459 | return bChangeDetected; |
---|
460 | } |
---|
461 | |
---|
462 | Int |
---|
463 | TAppComCamPara::xGetViewId( std::vector<Int> aiViewList, Int iBaseView ) |
---|
464 | { |
---|
465 | Int iViewId = -1; |
---|
466 | for( Int iId = 0; iId < (Int)aiViewList.size(); iId++ ) |
---|
467 | { |
---|
468 | if( aiViewList[ iId ] == iBaseView ) |
---|
469 | { |
---|
470 | iViewId = iId; |
---|
471 | break; |
---|
472 | } |
---|
473 | } |
---|
474 | AOT( iViewId == -1 ); |
---|
475 | return iViewId; |
---|
476 | } |
---|
477 | |
---|
478 | Int |
---|
479 | TAppComCamPara::xGetBaseViewId( Int iBaseView ) |
---|
480 | { |
---|
481 | return xGetViewId( m_aiBaseViews, iBaseView ); |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | Bool |
---|
486 | TAppComCamPara::xGetLeftRightView( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx ) |
---|
487 | { |
---|
488 | Bool bFoundLRView = false; |
---|
489 | Int iLeftView = -1; |
---|
490 | Int iRightView = -1; |
---|
491 | Int iLeftViewIdx = -1; |
---|
492 | Int iRightViewIdx = -1; |
---|
493 | Bool bDecencdingVN = ( aiSortedViews.size() >= 2 && aiSortedViews[ 0 ] > aiSortedViews[ 1 ] ); |
---|
494 | Int iFactor = ( bDecencdingVN ? -1 : 1 ); |
---|
495 | |
---|
496 | for( Int iIdx = -1; iIdx < (Int)aiSortedViews.size(); iIdx++ ) |
---|
497 | { |
---|
498 | if( iIdx == -1 ) |
---|
499 | { |
---|
500 | if( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor > 0 ) |
---|
501 | { |
---|
502 | bFoundLRView = false; |
---|
503 | iLeftView = -1; |
---|
504 | iRightView = aiSortedViews[ iIdx + 1 ]; |
---|
505 | iLeftViewIdx = -1; |
---|
506 | iRightViewIdx = iIdx + 1; |
---|
507 | break; |
---|
508 | } |
---|
509 | } |
---|
510 | else if ( iIdx == (Int)aiSortedViews.size() - 1 ) |
---|
511 | { |
---|
512 | if( ( aiSortedViews[ iIdx ] - iView ) * iFactor < 0 ) |
---|
513 | { |
---|
514 | bFoundLRView = false; |
---|
515 | iLeftView = aiSortedViews[ iIdx ]; |
---|
516 | iRightView = -1; |
---|
517 | iLeftViewIdx = iIdx; |
---|
518 | iRightViewIdx = -1; |
---|
519 | break; |
---|
520 | } |
---|
521 | } |
---|
522 | else |
---|
523 | { |
---|
524 | if( ( ( aiSortedViews[ iIdx ] - iView ) * iFactor <= 0 ) && ( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor >= 0 ) ) |
---|
525 | { |
---|
526 | bFoundLRView = true; |
---|
527 | iLeftView = aiSortedViews[ iIdx ]; |
---|
528 | iRightView = aiSortedViews[ iIdx + 1 ]; |
---|
529 | iLeftViewIdx = iIdx; |
---|
530 | iRightViewIdx = iIdx + 1; |
---|
531 | break; |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | if ( ( iView == iLeftView ) || ( iView == iRightView ) ) |
---|
537 | { |
---|
538 | iLeftViewIdx = ( iView == iLeftView ) ? iLeftViewIdx : iRightViewIdx; |
---|
539 | iRightViewIdx = iLeftViewIdx; |
---|
540 | iLeftView = iView; |
---|
541 | iRightView = iView; |
---|
542 | bFoundLRView = false; |
---|
543 | } |
---|
544 | |
---|
545 | riLeftView = iLeftView; |
---|
546 | riRightView = iRightView; |
---|
547 | riLeftSortedViewIdx = iLeftViewIdx; |
---|
548 | riRightSortedViewIdx = iRightViewIdx; |
---|
549 | |
---|
550 | return bFoundLRView; |
---|
551 | } |
---|
552 | |
---|
553 | |
---|
554 | Void |
---|
555 | TAppComCamPara::xGetPrevAndNextBaseView( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum ) |
---|
556 | { |
---|
557 | Int iLeftView; |
---|
558 | Int iRightView; |
---|
559 | Int iDummy; |
---|
560 | xGetLeftRightView( iTargetViewNum, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ); |
---|
561 | |
---|
562 | if( iLeftView == iRightView ) |
---|
563 | { |
---|
564 | riPrevBaseViewNum = iLeftView; |
---|
565 | riNextBaseViewNum = iLeftView; |
---|
566 | } |
---|
567 | else |
---|
568 | { |
---|
569 | Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] ); |
---|
570 | Bool bNextViewIsLeft = ( bDecencdingVN ? ( iSourceViewNum < iTargetViewNum ) : ( iSourceViewNum > iTargetViewNum ) ); |
---|
571 | if ( bNextViewIsLeft ) |
---|
572 | { |
---|
573 | riPrevBaseViewNum = iRightView; |
---|
574 | riNextBaseViewNum = iLeftView; |
---|
575 | } |
---|
576 | else |
---|
577 | { |
---|
578 | riPrevBaseViewNum = iLeftView; |
---|
579 | riNextBaseViewNum = iRightView; |
---|
580 | } |
---|
581 | } |
---|
582 | } |
---|
583 | |
---|
584 | |
---|
585 | Void |
---|
586 | TAppComCamPara::xGetZNearZFar( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar ) |
---|
587 | { |
---|
588 | UInt uiFoundLine = -1; |
---|
589 | if( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) || !( m_aadCameraParameters[ uiFoundLine ].size() < 8 ) ) |
---|
590 | { |
---|
591 | rdZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ]; |
---|
592 | rdZFar = m_aadCameraParameters[ uiFoundLine ][ 7 ]; |
---|
593 | } |
---|
594 | else |
---|
595 | { |
---|
596 | std::cerr << "No ZNear or no ZFar for View " << (Double)iView / m_dViewNumPrec << " and Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
597 | exit( EXIT_FAILURE ); |
---|
598 | } |
---|
599 | } |
---|
600 | |
---|
601 | Void |
---|
602 | TAppComCamPara::xGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ) |
---|
603 | { |
---|
604 | UInt uiFoundLine = -1; |
---|
605 | if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) && xIsIn( m_aiSortedBaseViews, iView )) |
---|
606 | { |
---|
607 | AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 ); |
---|
608 | rbInterpolated = false; |
---|
609 | rdFocalLength = m_aadCameraParameters[ uiFoundLine ][ 3 ]; |
---|
610 | rdPosition = m_aadCameraParameters[ uiFoundLine ][ 4 ]; |
---|
611 | rdCameraShift = m_aadCameraParameters[ uiFoundLine ][ 5 ]; |
---|
612 | } |
---|
613 | else |
---|
614 | { |
---|
615 | UInt uiLeftViewLine; |
---|
616 | UInt uiRightViewLine; |
---|
617 | Int iLeftView; |
---|
618 | Int iRightView; |
---|
619 | Int iDummy; |
---|
620 | |
---|
621 | if( !xGetLeftRightView( iView, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ) || |
---|
622 | xGetCameraDataRow( iLeftView, uiFrame, uiLeftViewLine ) || |
---|
623 | xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine ) |
---|
624 | ) |
---|
625 | { |
---|
626 | std::cerr << "No left or no right base view next to view " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; |
---|
627 | AOT(true); |
---|
628 | exit( EXIT_FAILURE ); |
---|
629 | } |
---|
630 | AOT( m_aadCameraParameters[ uiLeftViewLine ].size() < 6 ); |
---|
631 | AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 ); |
---|
632 | |
---|
633 | // Linear Interpolation |
---|
634 | Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) ); |
---|
635 | rdFocalLength = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] ); |
---|
636 | rdPosition = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] ); |
---|
637 | rdCameraShift = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] ); |
---|
638 | rbInterpolated = true; |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | Bool |
---|
643 | TAppComCamPara::xGetShiftParameterReal( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset ) |
---|
644 | { |
---|
645 | AOT( m_bSetupFromCoded ); |
---|
646 | |
---|
647 | Bool bInterpolatedSource; |
---|
648 | Double dMinDepthSource; |
---|
649 | Double dMaxDepthSource; |
---|
650 | Double dFocalLengthSource; |
---|
651 | Double dPositionSource; |
---|
652 | Double dIntersectionSource; |
---|
653 | |
---|
654 | Bool bInterpolatedTarget; |
---|
655 | Double dPositionTarget; |
---|
656 | Double dIntersectionTarget; |
---|
657 | Double dFocalLengthTarget; |
---|
658 | |
---|
659 | Int iTargetViewNum; |
---|
660 | Int iSourceViewNum; |
---|
661 | |
---|
662 | if( bByIdx ) |
---|
663 | { |
---|
664 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
665 | iTargetViewNum = ( bExternal ? m_aiSynthViews[ uiTargetView ] : m_aiBaseViews[ uiTargetView ] ); |
---|
666 | } |
---|
667 | else |
---|
668 | { |
---|
669 | iSourceViewNum = (Int) uiSourceView; |
---|
670 | iTargetViewNum = (Int) uiTargetView; |
---|
671 | } |
---|
672 | |
---|
673 | xGetGeometryData( iSourceViewNum, uiFrame, dFocalLengthSource, dPositionSource, dIntersectionSource, bInterpolatedSource ); |
---|
674 | xGetZNearZFar ( iSourceViewNum, uiFrame, dMinDepthSource, dMaxDepthSource ); |
---|
675 | xGetGeometryData( iTargetViewNum, uiFrame, dFocalLengthTarget, dPositionTarget, dIntersectionTarget, bInterpolatedTarget ); |
---|
676 | |
---|
677 | Double dFactor = dFocalLengthSource * ( dPositionTarget - dPositionSource ); |
---|
678 | rdScale = dFactor * ( 1.0 / dMinDepthSource - 1.0 / dMaxDepthSource ) / (Double)( ( 1 << m_uiInputBitDepth ) - 1 ); |
---|
679 | rdOffset = dFactor / dMaxDepthSource - dIntersectionTarget + dIntersectionSource; |
---|
680 | |
---|
681 | return ( bInterpolatedSource || bInterpolatedTarget ); |
---|
682 | } |
---|
683 | |
---|
684 | |
---|
685 | Void |
---|
686 | TAppComCamPara::xGetShiftParameterCoded( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bByIdx, Int& riScale, Int& riOffset ) |
---|
687 | { |
---|
688 | if ( m_bSetupFromCoded ) |
---|
689 | { |
---|
690 | if ( uiSourceView == uiTargetView ) |
---|
691 | { |
---|
692 | riScale = 0; |
---|
693 | riOffset = 0; |
---|
694 | return; |
---|
695 | } |
---|
696 | Int iCamParsCodedPrecision; |
---|
697 | xGetCodedCameraData( uiSourceView, uiTargetView, bByIdx, uiFrame, riScale, riOffset, iCamParsCodedPrecision ); |
---|
698 | |
---|
699 | if ( m_bCamParsCodedPrecSet ) |
---|
700 | { |
---|
701 | AOT( m_uiCamParsCodedPrecision != (UInt) iCamParsCodedPrecision ); |
---|
702 | } |
---|
703 | else |
---|
704 | { |
---|
705 | m_uiCamParsCodedPrecision = (UInt) iCamParsCodedPrecision; |
---|
706 | m_bCamParsCodedPrecSet = true; |
---|
707 | } |
---|
708 | } |
---|
709 | else |
---|
710 | { |
---|
711 | Double dScale, dOffset; |
---|
712 | Bool bInterpolated = xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, false, bByIdx, dScale, dOffset ); |
---|
713 | AOT( bInterpolated ); // must be base view |
---|
714 | |
---|
715 | Double dMultOffset = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 ) ); |
---|
716 | Double dMultScale = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 + m_uiInputBitDepth ) ); |
---|
717 | riOffset = (Int)floor( dMultOffset * dOffset + .5 ); |
---|
718 | riScale = (Int)floor( dMultScale * dScale + .5 ); |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | |
---|
723 | Void |
---|
724 | TAppComCamPara::xGetShiftParameterInt( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64& riScale, Int64& riOffset ) |
---|
725 | { |
---|
726 | Int iTargetViewNum; |
---|
727 | Int iSourceViewNum; |
---|
728 | Int iPrevBaseViewNum; |
---|
729 | Int iNextBaseViewNum; |
---|
730 | Int iTargetViewRelNum; |
---|
731 | |
---|
732 | if( bByIdx ) |
---|
733 | { |
---|
734 | |
---|
735 | iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
736 | |
---|
737 | if ( bExternal ) |
---|
738 | { |
---|
739 | iTargetViewNum = m_aiSynthViews [ uiTargetView ]; |
---|
740 | iTargetViewRelNum = m_aiRelSynthViewsNum[ uiTargetView ]; |
---|
741 | } |
---|
742 | else |
---|
743 | { |
---|
744 | iTargetViewNum = m_aiBaseViews [ uiTargetView ]; |
---|
745 | iTargetViewRelNum = m_aiBaseId2SortedId [ uiTargetView ] * ((Int) m_dViewNumPrec ); |
---|
746 | } |
---|
747 | } |
---|
748 | else |
---|
749 | { |
---|
750 | iSourceViewNum = (Int) uiSourceView; |
---|
751 | iTargetViewNum = (Int) uiTargetView; |
---|
752 | |
---|
753 | if ( bExternal ) |
---|
754 | { |
---|
755 | iTargetViewRelNum = m_aiRelSynthViewsNum[ xGetViewId( m_aiSynthViews, (Int) uiTargetView )]; |
---|
756 | } |
---|
757 | else |
---|
758 | { |
---|
759 | iTargetViewRelNum = m_aiBaseId2SortedId[ xGetBaseViewId( uiTargetView) ] * ((Int) m_dViewNumPrec ); |
---|
760 | } |
---|
761 | } |
---|
762 | xGetPrevAndNextBaseView( iSourceViewNum, iTargetViewNum, iPrevBaseViewNum, iNextBaseViewNum ); |
---|
763 | AOT( iPrevBaseViewNum == -1 ); // should not happen |
---|
764 | AOT( iNextBaseViewNum == -1 ); // should not happen |
---|
765 | |
---|
766 | Int iSrcId = xGetBaseViewId( iSourceViewNum ); |
---|
767 | Int iPrevId = xGetBaseViewId( iPrevBaseViewNum ); |
---|
768 | Int iNextId = xGetBaseViewId( iNextBaseViewNum ); |
---|
769 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iPrevId ] ); // coded scale and offset must be set |
---|
770 | AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iNextId ] ); // coded scale and offset must be set |
---|
771 | |
---|
772 | Int iNextBaseViewRelNum = m_aiBaseId2SortedId[ iNextId ] * ((Int) m_dViewNumPrec ); |
---|
773 | Int iPrevBaseViewRelNum = m_aiBaseId2SortedId[ iPrevId ] * ((Int) m_dViewNumPrec ); |
---|
774 | |
---|
775 | Int64 iPrevScale = (Int64)m_aaiCodedScale [ iSrcId ][ iPrevId ]; |
---|
776 | Int64 iNextScale = (Int64)m_aaiCodedScale [ iSrcId ][ iNextId ]; |
---|
777 | Int64 iPrevOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iPrevId ] << m_uiBitDepthForLUT; |
---|
778 | Int64 iNextOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iNextId ] << m_uiBitDepthForLUT; |
---|
779 | |
---|
780 | if( iPrevBaseViewNum == iNextBaseViewNum ) |
---|
781 | { |
---|
782 | riScale = iNextScale; |
---|
783 | riOffset = iNextOffset; |
---|
784 | } |
---|
785 | else |
---|
786 | { |
---|
787 | riScale = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextScale; |
---|
788 | riScale += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevScale; |
---|
789 | riOffset = Int64( iTargetViewRelNum - iPrevBaseViewRelNum ) * iNextOffset; |
---|
790 | riOffset += Int64( iNextBaseViewRelNum - iTargetViewRelNum ) * iPrevOffset; |
---|
791 | Int64 iD = Int64( iNextBaseViewRelNum - iPrevBaseViewRelNum ); |
---|
792 | Int64 iSA = ( riScale > 0 ? iD / 2 : -iD / 2 ); |
---|
793 | Int64 iOA = ( riOffset > 0 ? iD / 2 : -iD / 2 ); |
---|
794 | riScale = ( riScale + iSA ) / iD; |
---|
795 | riOffset = ( riOffset + iOA ) / iD; |
---|
796 | } |
---|
797 | } |
---|
798 | |
---|
799 | |
---|
800 | Void |
---|
801 | TAppComCamPara::xSetCodedScaleOffset( UInt uiFrame ) |
---|
802 | { |
---|
803 | for( UInt uiSourceId = 0; uiSourceId < m_iNumberOfBaseViews; uiSourceId++ ) |
---|
804 | { |
---|
805 | for( UInt uiTargetId = 0; uiTargetId < m_iNumberOfBaseViews; uiTargetId++ ) |
---|
806 | { |
---|
807 | Int iScale, iOffset; |
---|
808 | xGetShiftParameterCoded( uiSourceId, uiTargetId, uiFrame, true, iScale, iOffset ); |
---|
809 | m_aaiCodedScale [ uiSourceId ][ uiTargetId ] = iScale; |
---|
810 | m_aaiCodedOffset [ uiSourceId ][ uiTargetId ] = iOffset; |
---|
811 | m_aaiScaleAndOffsetSet [ uiSourceId ][ uiTargetId ] = 1; |
---|
812 | } |
---|
813 | } |
---|
814 | } |
---|
815 | |
---|
816 | |
---|
817 | Void |
---|
818 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiNumberSourceViews, UInt uiNumberTargetViews, UInt uiFrame, Bool bExternalReference , Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ) |
---|
819 | { |
---|
820 | if( uiNumberSourceViews <= 1 || uiNumberTargetViews == 0 ) |
---|
821 | { |
---|
822 | return; |
---|
823 | } |
---|
824 | AOF( radShiftParams != NULL && raiShiftParams != NULL && radLUT != NULL && raiLUT != NULL ); |
---|
825 | AOF( m_uiBitDepthForLUT == 8 ); |
---|
826 | |
---|
827 | Int iLog2DivLuma = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision; AOF( iLog2DivLuma > 0 ); |
---|
828 | Int iLog2DivChroma = iLog2DivLuma + 1; |
---|
829 | |
---|
830 | Double dMaxDispDev = 0.0; |
---|
831 | Double dMaxRndDispDvL = 0.0; |
---|
832 | Double dMaxRndDispDvC = 0.0; |
---|
833 | |
---|
834 | for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) |
---|
835 | { |
---|
836 | for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ ) |
---|
837 | { |
---|
838 | |
---|
839 | // integer-valued scale and offset |
---|
840 | Int64 iScale, iOffset; |
---|
841 | xGetShiftParameterInt ( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, iScale, iOffset ); |
---|
842 | raiShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = iScale; |
---|
843 | raiShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = iOffset; |
---|
844 | |
---|
845 | // offsets including rounding offsets |
---|
846 | Int64 iOffsetLuma = iOffset + ( ( 1 << iLog2DivLuma ) >> 1 ); |
---|
847 | Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 ); |
---|
848 | |
---|
849 | // real-valued scale and offset |
---|
850 | Double dScale, dOffset; |
---|
851 | |
---|
852 | if ( m_bSetupFromCoded ) |
---|
853 | { |
---|
854 | dScale = (Double) iScale / (( Double ) ( 1 << iLog2DivLuma )); |
---|
855 | dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma )); |
---|
856 | } |
---|
857 | else |
---|
858 | { |
---|
859 | xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, dScale, dOffset ); |
---|
860 | } |
---|
861 | |
---|
862 | radShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = dScale; |
---|
863 | radShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = dOffset; |
---|
864 | |
---|
865 | for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ ) |
---|
866 | { |
---|
867 | // real-valued look-up tables |
---|
868 | Double dShiftLuma = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
869 | Double dShiftChroma = dShiftLuma / 2; |
---|
870 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma; |
---|
871 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma; |
---|
872 | |
---|
873 | // integer-valued look-up tables |
---|
874 | Int64 iTempScale = (Int64)uiDepthValue * iScale; |
---|
875 | Int64 iTestScale = ( iTempScale + iOffset ); // for checking accuracy of camera parameters |
---|
876 | Int64 iShiftLuma = ( iTempScale + iOffsetLuma ) >> iLog2DivLuma; |
---|
877 | Int64 iShiftChroma = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma; |
---|
878 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma; |
---|
879 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma; |
---|
880 | |
---|
881 | // maximum deviation |
---|
882 | #if H_3D_REN_MAX_DEV_OUT |
---|
883 | m_dMaxShiftDeviation = std::max( m_dMaxShiftDeviation, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) / Double( 1 << m_iLog2Precision ) ); |
---|
884 | #endif |
---|
885 | dMaxDispDev = std::max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); |
---|
886 | dMaxRndDispDvL = std::max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); |
---|
887 | dMaxRndDispDvC = std::max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); |
---|
888 | } |
---|
889 | |
---|
890 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ]; |
---|
891 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ]; |
---|
892 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ]; |
---|
893 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ]; |
---|
894 | } |
---|
895 | } |
---|
896 | |
---|
897 | // check maximum deviation |
---|
898 | Double dMaxAllowedDispDev = Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // counting only the impact of camera parameter rounding |
---|
899 | Double dMaxAllowedRndDispDvL = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // final rounding and impact of camera parameter rounding |
---|
900 | Double dMaxAllowedRndDispDvC = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ) / 2.0; // final rounding and impact of camera parameter rounding |
---|
901 | |
---|
902 | if( ( dMaxDispDev >= dMaxAllowedDispDev || dMaxRndDispDvL >= dMaxAllowedRndDispDvL || dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) && !m_bSetupFromCoded ) |
---|
903 | { |
---|
904 | std::cout << "Warning: Something wrong with the accuracy of coded camera parameters:" << std::endl; |
---|
905 | if( dMaxDispDev >= dMaxAllowedDispDev ) |
---|
906 | { |
---|
907 | std::cout << " max disparity difference is " << dMaxDispDev << " (allowed: " << dMaxAllowedDispDev << ")" << std::endl; |
---|
908 | } |
---|
909 | if( dMaxRndDispDvL >= dMaxAllowedRndDispDvL ) |
---|
910 | { |
---|
911 | std::cout << " max rnd luma disp diff is " << dMaxRndDispDvL << " (allowed: " << dMaxAllowedRndDispDvL << ")" << std::endl; |
---|
912 | } |
---|
913 | if( dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) |
---|
914 | { |
---|
915 | std::cout << " max rnd chroma disp diff is " << dMaxRndDispDvC << " (allowed: " << dMaxAllowedRndDispDvC << ")" << std::endl; |
---|
916 | } |
---|
917 | } |
---|
918 | } |
---|
919 | |
---|
920 | Void |
---|
921 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame ) |
---|
922 | { |
---|
923 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
924 | xSetCodedScaleOffset ( uiFrame ); |
---|
925 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, uiFrame, false, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
926 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
927 | }; |
---|
928 | |
---|
929 | |
---|
930 | Void |
---|
931 | TAppComCamPara::xGetCameraShifts( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift ) |
---|
932 | { |
---|
933 | Double dDummy, dCamPosSource, dCamPosTarget, dPicPosSource, dPicPosTarget; |
---|
934 | Bool bInterpolatedSource, bInterpolatedTarget; |
---|
935 | Int iTargetViewNum = m_aiBaseViews[ uiTargetView ]; |
---|
936 | Int iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
937 | |
---|
938 | xGetGeometryData( iSourceViewNum, uiFrame, dDummy, dCamPosSource, dPicPosSource, bInterpolatedSource ); |
---|
939 | xGetGeometryData( iTargetViewNum, uiFrame, dDummy, dCamPosTarget, dPicPosTarget, bInterpolatedTarget ); |
---|
940 | AOT( bInterpolatedSource || bInterpolatedTarget ); |
---|
941 | |
---|
942 | rdCamPosShift = ( dCamPosTarget - dCamPosSource ); |
---|
943 | rdPicPosShift = -( dPicPosTarget - dPicPosSource ); // to be consistent |
---|
944 | } |
---|
945 | |
---|
946 | |
---|
947 | |
---|
948 | |
---|
949 | |
---|
950 | |
---|
951 | TAppComCamPara::TAppComCamPara() |
---|
952 | { |
---|
953 | m_dViewNumPrec = VIEW_NUM_PREC; // fixed |
---|
954 | m_iLog2Precision = -1; |
---|
955 | m_uiInputBitDepth = 0; |
---|
956 | m_uiBitDepthForLUT = 8; // fixed |
---|
957 | m_uiFirstFrameId = 0; |
---|
958 | m_uiLastFrameId = 0; |
---|
959 | |
---|
960 | m_iNumberOfBaseViews = -1; |
---|
961 | m_iNumberOfSynthViews = -1; |
---|
962 | |
---|
963 | m_uiCamParsCodedPrecision = 0; |
---|
964 | m_bCamParsVaryOverTime = true; |
---|
965 | |
---|
966 | m_aaiCodedScale = 0; |
---|
967 | m_aaiCodedOffset = 0; |
---|
968 | m_aaiScaleAndOffsetSet = 0; |
---|
969 | |
---|
970 | m_adBaseViewShiftParameter = 0; |
---|
971 | m_aiBaseViewShiftParameter = 0; |
---|
972 | m_adSynthViewShiftParameter = 0; |
---|
973 | m_aiSynthViewShiftParameter = 0; |
---|
974 | |
---|
975 | m_adBaseViewShiftLUT = 0; |
---|
976 | m_aiBaseViewShiftLUT = 0; |
---|
977 | m_adSynthViewShiftLUT = 0; |
---|
978 | m_aiSynthViewShiftLUT = 0; |
---|
979 | |
---|
980 | m_bSetupFromCoded = false; |
---|
981 | m_bCamParsCodedPrecSet = false; |
---|
982 | |
---|
983 | #if H_3D_REN_MAX_DEV_OUT |
---|
984 | m_dMaxShiftDeviation = -1; |
---|
985 | #endif |
---|
986 | |
---|
987 | } |
---|
988 | |
---|
989 | |
---|
990 | TAppComCamPara::~TAppComCamPara() |
---|
991 | { |
---|
992 | xDeleteArray( m_adBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
993 | xDeleteArray( m_aiBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
994 | xDeleteArray( m_adBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
995 | xDeleteArray( m_aiBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
996 | |
---|
997 | xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); |
---|
998 | xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); |
---|
999 | xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews), 2 ); |
---|
1000 | xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, std::max( (Int)1 ,m_iNumberOfSynthViews), 2 ); |
---|
1001 | |
---|
1002 | xDeleteArray( m_aaiCodedScale, m_iNumberOfBaseViews ); |
---|
1003 | xDeleteArray( m_aaiCodedOffset, m_iNumberOfBaseViews ); |
---|
1004 | xDeleteArray( m_aaiScaleAndOffsetSet, m_iNumberOfBaseViews ); |
---|
1005 | |
---|
1006 | } |
---|
1007 | |
---|
1008 | Void |
---|
1009 | TAppComCamPara::xSetupBaseViewsFromCoded() |
---|
1010 | { |
---|
1011 | //===== get and sort views given in camera parameter file and set list of base views and related arrays ===== |
---|
1012 | // get left-right order and coding order from cfg-file |
---|
1013 | std::vector<Int> aiViewOrderIdx; // Left Right Order |
---|
1014 | std::vector<Int> aiViewId ; // Coding Order |
---|
1015 | |
---|
1016 | Int iMinViewOrderIdx = MAX_INT; |
---|
1017 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1018 | { |
---|
1019 | if (m_aadCameraParameters[uiRow].size() != 2 ) |
---|
1020 | break; |
---|
1021 | |
---|
1022 | Int iViewOrderIdx = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] ); |
---|
1023 | iMinViewOrderIdx = std::min( iViewOrderIdx, iMinViewOrderIdx ); |
---|
1024 | |
---|
1025 | aiViewOrderIdx .push_back( iViewOrderIdx ); |
---|
1026 | aiViewId .push_back( (Int) m_aadCameraParameters[ uiRow ][ 0 ] ); |
---|
1027 | } |
---|
1028 | |
---|
1029 | // create base view numbers |
---|
1030 | AOT( aiViewId.size() != aiViewOrderIdx.size() ); |
---|
1031 | m_iNumberOfBaseViews = (Int) aiViewId.size(); |
---|
1032 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1033 | { |
---|
1034 | aiViewOrderIdx[iCurBaseView] = ( aiViewOrderIdx[iCurBaseView] - iMinViewOrderIdx); |
---|
1035 | m_aiBaseViews .push_back( aiViewOrderIdx[iCurBaseView] * ( (Int) m_dViewNumPrec) ); |
---|
1036 | m_aiBaseId2SortedId.push_back( iCurBaseView ); |
---|
1037 | m_aiBaseSortedId2Id.push_back( iCurBaseView ); |
---|
1038 | } |
---|
1039 | |
---|
1040 | m_iNumberOfBaseViews = (Int) m_aiBaseViews.size(); |
---|
1041 | |
---|
1042 | std::vector<Int> aiSortedViewOrderIdx = aiViewOrderIdx; |
---|
1043 | |
---|
1044 | // sort base views according to View Order Idx |
---|
1045 | m_aiSortedBaseViews = m_aiBaseViews; |
---|
1046 | for (Int iCurBaseView = 1; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1047 | { |
---|
1048 | Int iCurViewOrder = aiSortedViewOrderIdx[iCurBaseView]; |
---|
1049 | for (Int iCurSearchPos = iCurBaseView; iCurSearchPos >= 0; iCurSearchPos-- ) |
---|
1050 | { |
---|
1051 | if ( iCurViewOrder < aiSortedViewOrderIdx[iCurSearchPos] ) |
---|
1052 | { |
---|
1053 | Int iTempViewId = m_aiSortedBaseViews[iCurSearchPos]; |
---|
1054 | m_aiSortedBaseViews[iCurSearchPos] = m_aiSortedBaseViews[iCurBaseView]; |
---|
1055 | m_aiSortedBaseViews[iCurBaseView ] = iTempViewId; |
---|
1056 | |
---|
1057 | Int iTempViewOrderIdx = aiSortedViewOrderIdx[iCurSearchPos]; |
---|
1058 | aiSortedViewOrderIdx[iCurSearchPos] = aiSortedViewOrderIdx[iCurBaseView]; |
---|
1059 | aiSortedViewOrderIdx[iCurBaseView ] = iTempViewOrderIdx; |
---|
1060 | |
---|
1061 | Int iTempPos = m_aiBaseSortedId2Id[iCurSearchPos]; |
---|
1062 | m_aiBaseSortedId2Id[iCurSearchPos] = m_aiBaseSortedId2Id[iCurBaseView]; |
---|
1063 | m_aiBaseSortedId2Id[iCurBaseView] = iTempPos; |
---|
1064 | iCurBaseView--; |
---|
1065 | } |
---|
1066 | } |
---|
1067 | } |
---|
1068 | |
---|
1069 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1070 | { |
---|
1071 | m_aiBaseId2SortedId[m_aiBaseSortedId2Id[iCurBaseView]] = iCurBaseView; |
---|
1072 | } |
---|
1073 | |
---|
1074 | m_aiViewsInCfgFile = m_aiSortedBaseViews; |
---|
1075 | |
---|
1076 | // check |
---|
1077 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
1078 | { |
---|
1079 | std::cerr << "Failed reading camera parameter file" << std::endl; |
---|
1080 | std::cerr << "At least two views must be given" << std::endl; |
---|
1081 | AOT(true); |
---|
1082 | exit( EXIT_FAILURE ); |
---|
1083 | } |
---|
1084 | |
---|
1085 | // translate coding order to view order |
---|
1086 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1087 | { |
---|
1088 | if (m_aadCameraParameters[uiRow].size() == 2 ) |
---|
1089 | continue; |
---|
1090 | |
---|
1091 | m_aadCameraParameters[ uiRow ][ 2 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 2 ] ) ]; |
---|
1092 | m_aadCameraParameters[ uiRow ][ 3 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 3 ] ) ]; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | |
---|
1096 | Void TAppComCamPara::xSetupBaseViews( Char* pchBaseViewNumbers, UInt uiNumBaseViews ) |
---|
1097 | { |
---|
1098 | // init list |
---|
1099 | std::vector<Int> aiViewsInCfg; |
---|
1100 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1101 | { |
---|
1102 | aiViewsInCfg.push_back( (Int)( m_aadCameraParameters[ uiRow ][ 0 ] * m_dViewNumPrec ) ); |
---|
1103 | } |
---|
1104 | // remove duplicated items |
---|
1105 | std::sort( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
1106 | std::vector<Int>::iterator cIterNewEnd = std::unique( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
1107 | aiViewsInCfg.erase( cIterNewEnd, aiViewsInCfg.end() ); |
---|
1108 | // sort (from left to right) |
---|
1109 | std::vector<Int> aiDummyI2SI, aiDummySI2I; |
---|
1110 | xGetSortedViewList( aiViewsInCfg, m_aiViewsInCfgFile, aiDummyI2SI, aiDummySI2I ); |
---|
1111 | // check |
---|
1112 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
1113 | { |
---|
1114 | std::cerr << "Failed reading config file" << std::endl; |
---|
1115 | std::cerr << "At least two views must be given" << std::endl; |
---|
1116 | exit( EXIT_FAILURE ); |
---|
1117 | } |
---|
1118 | |
---|
1119 | |
---|
1120 | |
---|
1121 | //===== set list of base views and related arrays ===== |
---|
1122 | if( pchBaseViewNumbers == 0 ) |
---|
1123 | { |
---|
1124 | std::cerr << "BaseViewCameraNumbers must be given" << std::endl; |
---|
1125 | exit( EXIT_FAILURE ); |
---|
1126 | }; |
---|
1127 | |
---|
1128 | convertNumberString( pchBaseViewNumbers, m_aiBaseViews, m_dViewNumPrec ); |
---|
1129 | while( (UInt)m_aiBaseViews.size() > uiNumBaseViews ) |
---|
1130 | { |
---|
1131 | m_aiBaseViews.pop_back(); |
---|
1132 | } |
---|
1133 | xGetSortedViewList( m_aiBaseViews, m_aiSortedBaseViews, m_aiBaseId2SortedId, m_aiBaseSortedId2Id ); |
---|
1134 | m_iNumberOfBaseViews = (Int)m_aiBaseViews.size(); |
---|
1135 | } |
---|
1136 | |
---|
1137 | |
---|
1138 | Void |
---|
1139 | TAppComCamPara::init( UInt uiNumBaseViews, |
---|
1140 | UInt uiInputBitDepth, |
---|
1141 | UInt uiCodedCamParsPrecision, |
---|
1142 | UInt uiStartFrameId, |
---|
1143 | UInt uiNumFrames, |
---|
1144 | Char* pchCfgFileName, |
---|
1145 | Char* pchBaseViewNumbers, |
---|
1146 | Char* pchSynthViewNumbers, |
---|
1147 | std::vector<Int>* paiSynthViewNumbers, |
---|
1148 | Int iLog2Precision ) |
---|
1149 | { |
---|
1150 | //===== set miscellaneous variables ===== |
---|
1151 | m_uiInputBitDepth = uiInputBitDepth; |
---|
1152 | m_uiFirstFrameId = uiStartFrameId; |
---|
1153 | m_uiLastFrameId = uiStartFrameId + uiNumFrames - 1; |
---|
1154 | m_uiCamParsCodedPrecision = uiCodedCamParsPrecision; |
---|
1155 | m_iLog2Precision = iLog2Precision; |
---|
1156 | |
---|
1157 | xReadCameraParameterFile( pchCfgFileName ); |
---|
1158 | |
---|
1159 | m_bSetupFromCoded = ( m_aadCameraParameters[ 0 ].size() == 2 ); |
---|
1160 | |
---|
1161 | if ( m_bSetupFromCoded ) |
---|
1162 | { |
---|
1163 | std::cout << "Detected decoded camera parameter file. Overwriting base view settings from cfg file. " << std::endl; |
---|
1164 | xSetupBaseViewsFromCoded(); |
---|
1165 | } |
---|
1166 | else |
---|
1167 | { |
---|
1168 | xSetupBaseViews( pchBaseViewNumbers, uiNumBaseViews ); |
---|
1169 | } |
---|
1170 | |
---|
1171 | //===== set list of external (virtual) views ===== |
---|
1172 | m_aiSynthViews.clear(); |
---|
1173 | |
---|
1174 | if( pchSynthViewNumbers != 0 || paiSynthViewNumbers != 0) |
---|
1175 | { |
---|
1176 | std::vector<Int> aiTmpSynthViews; |
---|
1177 | |
---|
1178 | AOT( ( pchSynthViewNumbers != NULL ) && ( paiSynthViewNumbers != NULL ) ); |
---|
1179 | |
---|
1180 | if ( pchSynthViewNumbers != NULL ) |
---|
1181 | { |
---|
1182 | convertNumberString( pchSynthViewNumbers, aiTmpSynthViews, m_dViewNumPrec ); |
---|
1183 | } |
---|
1184 | else |
---|
1185 | { |
---|
1186 | aiTmpSynthViews = (*paiSynthViewNumbers); |
---|
1187 | } |
---|
1188 | |
---|
1189 | for( UInt uiSId = 0; uiSId < (UInt)aiTmpSynthViews.size(); uiSId++ ) |
---|
1190 | { |
---|
1191 | |
---|
1192 | Int iViewNumPrec = (Int) m_dViewNumPrec; |
---|
1193 | Int iLeftBaseViewIdx = aiTmpSynthViews[ uiSId ] / iViewNumPrec; |
---|
1194 | Int iRightBaseViewIdx = ( aiTmpSynthViews[ uiSId ] + (iViewNumPrec - 1) ) / iViewNumPrec; |
---|
1195 | |
---|
1196 | if ( iLeftBaseViewIdx < 0 || iRightBaseViewIdx >= m_iNumberOfBaseViews ) |
---|
1197 | { |
---|
1198 | std::cerr << "SynthViewCameraNumbers must be greater and equal to 0 and smaller than number of base views" << std::endl; |
---|
1199 | AOT(true); |
---|
1200 | exit( EXIT_FAILURE ); |
---|
1201 | } |
---|
1202 | |
---|
1203 | Int64 iLeftBaseViewRelNum = iLeftBaseViewIdx * iViewNumPrec; |
---|
1204 | Int64 iRightBaseViewRelNum = iRightBaseViewIdx * iViewNumPrec; |
---|
1205 | |
---|
1206 | Int64 iDiffBaseViewRelNum = iRightBaseViewRelNum - iLeftBaseViewRelNum; |
---|
1207 | |
---|
1208 | Int64 iSynthViewRelNum = aiTmpSynthViews[ uiSId ]; |
---|
1209 | Int64 iLeftBaseNum = m_aiSortedBaseViews[ iLeftBaseViewIdx ]; |
---|
1210 | Int64 iRightBaseNum = m_aiSortedBaseViews[ iRightBaseViewIdx ]; |
---|
1211 | Int64 iDiffBaseNum = iRightBaseNum - iLeftBaseNum; |
---|
1212 | Int64 iSynthViewNum; |
---|
1213 | |
---|
1214 | if ( iDiffBaseViewRelNum != 0) |
---|
1215 | { |
---|
1216 | AOT( (Int) iDiffBaseViewRelNum != iViewNumPrec ); |
---|
1217 | Int iFact = iDiffBaseNum > 0 ? 1 : -1; |
---|
1218 | iSynthViewNum = iLeftBaseNum + ( iDiffBaseNum * ( iSynthViewRelNum - iLeftBaseViewRelNum ) + (iViewNumPrec >> 1) * iFact ) / ( iViewNumPrec ); |
---|
1219 | } |
---|
1220 | else |
---|
1221 | { |
---|
1222 | iSynthViewNum = iLeftBaseNum; |
---|
1223 | } |
---|
1224 | |
---|
1225 | m_aiRelSynthViewsNum.push_back( aiTmpSynthViews[ uiSId ] ); |
---|
1226 | m_aiSynthViews .push_back( (Int) iSynthViewNum ); |
---|
1227 | } |
---|
1228 | } |
---|
1229 | m_iNumberOfSynthViews = (Int)m_aiSynthViews.size(); |
---|
1230 | |
---|
1231 | |
---|
1232 | //===== set derived parameters ===== |
---|
1233 | m_bCamParsVaryOverTime = xGetCamParsChangeFlag(); |
---|
1234 | |
---|
1235 | |
---|
1236 | //===== create arrays ===== |
---|
1237 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
1238 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
1239 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedScale ); |
---|
1240 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedOffset ); |
---|
1241 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet ); |
---|
1242 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
1243 | |
---|
1244 | //===== init arrays for first frame ===== |
---|
1245 | xSetShiftParametersAndLUT( m_uiFirstFrameId ); |
---|
1246 | } |
---|
1247 | |
---|
1248 | |
---|
1249 | Void |
---|
1250 | TAppComCamPara::check( Bool bCheckViewRange, Bool bCheckFrameRange ) |
---|
1251 | { |
---|
1252 | if( bCheckFrameRange ) |
---|
1253 | { |
---|
1254 | Double dDummy; |
---|
1255 | |
---|
1256 | for( UInt uiBaseView = 0; uiBaseView < m_aiBaseViews.size(); uiBaseView++ ) |
---|
1257 | { |
---|
1258 | if ( m_bSetupFromCoded ) |
---|
1259 | { |
---|
1260 | for( UInt uiTargetView = 0; uiTargetView < m_aiBaseViews.size(); uiTargetView++ ) |
---|
1261 | { |
---|
1262 | if ( uiTargetView == uiBaseView ) |
---|
1263 | continue; |
---|
1264 | |
---|
1265 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1266 | { |
---|
1267 | Int iDummy; |
---|
1268 | |
---|
1269 | xGetCodedCameraData( uiBaseView, uiTargetView, true , uiFrame, iDummy, iDummy, iDummy ); |
---|
1270 | } |
---|
1271 | } |
---|
1272 | } |
---|
1273 | else |
---|
1274 | { |
---|
1275 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1276 | { |
---|
1277 | Bool bInterpolatedCur; |
---|
1278 | xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
1279 | xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); |
---|
1280 | |
---|
1281 | if( bInterpolatedCur ) |
---|
1282 | { |
---|
1283 | std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; |
---|
1284 | exit( EXIT_FAILURE ); |
---|
1285 | } |
---|
1286 | } |
---|
1287 | } |
---|
1288 | } |
---|
1289 | |
---|
1290 | Bool bIgnoreFirst = true; |
---|
1291 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
1292 | { |
---|
1293 | if ( xIsIn(m_aiViewsInCfgFile, m_aiSynthViews[ uiERView ] ) ) |
---|
1294 | { |
---|
1295 | if ( bIgnoreFirst ) |
---|
1296 | { |
---|
1297 | std::cout << "Ignoring CameraParameterFile entries for virtual view(s): " ; |
---|
1298 | //GT: Integer precision virtual view camera parameters are always interpolated from coded views camera parameters. |
---|
1299 | bIgnoreFirst = false; |
---|
1300 | } |
---|
1301 | std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; |
---|
1302 | } |
---|
1303 | } |
---|
1304 | if ( !bIgnoreFirst ) |
---|
1305 | { |
---|
1306 | std::cout << std::endl; |
---|
1307 | } |
---|
1308 | |
---|
1309 | Bool bInterpolateFirst = true; |
---|
1310 | Bool bAnyInterpolated = false; |
---|
1311 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
1312 | { |
---|
1313 | Bool bInterpolated = false; |
---|
1314 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1315 | { |
---|
1316 | Bool bInterpolatedCur; |
---|
1317 | xGetGeometryData( m_aiSynthViews[ uiERView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
1318 | bInterpolated |= bInterpolatedCur; |
---|
1319 | } |
---|
1320 | |
---|
1321 | if( bInterpolated ) |
---|
1322 | { |
---|
1323 | bAnyInterpolated = true; |
---|
1324 | if ( bInterpolateFirst ) |
---|
1325 | { |
---|
1326 | std::cout << "Interpolating camera parameters for virtual view(s): " ; |
---|
1327 | bInterpolateFirst = false; |
---|
1328 | } |
---|
1329 | std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; |
---|
1330 | } |
---|
1331 | } |
---|
1332 | if ( bAnyInterpolated ) |
---|
1333 | std::cout << std::endl; |
---|
1334 | } |
---|
1335 | |
---|
1336 | if( bCheckViewRange ) |
---|
1337 | { |
---|
1338 | Bool bAllExist = true; |
---|
1339 | for( Int iSynthViewIdx = 0; iSynthViewIdx < m_iNumberOfSynthViews; iSynthViewIdx++ ) |
---|
1340 | { |
---|
1341 | Bool bIsBaseView; |
---|
1342 | Int iDummy; |
---|
1343 | Bool bExist = getLeftRightBaseView( iSynthViewIdx, iDummy, iDummy, iDummy, bIsBaseView ); |
---|
1344 | bAllExist &= ( bExist || bIsBaseView ); |
---|
1345 | } |
---|
1346 | if( !bAllExist ) |
---|
1347 | { |
---|
1348 | std::cerr << "SynthViewNumbers must be within the range of BaseViewNumbers" << std::endl; |
---|
1349 | exit( EXIT_FAILURE ); |
---|
1350 | } |
---|
1351 | } |
---|
1352 | } |
---|
1353 | |
---|
1354 | |
---|
1355 | Void |
---|
1356 | TAppComCamPara::update( UInt uiFrameId ) |
---|
1357 | { |
---|
1358 | |
---|
1359 | m_iCurrentFrameId = uiFrameId; |
---|
1360 | m_bCamParsCodedPrecSet = false; |
---|
1361 | |
---|
1362 | if ( m_bCamParsVaryOverTime ) |
---|
1363 | { |
---|
1364 | xSetShiftParametersAndLUT( m_uiFirstFrameId + uiFrameId ); |
---|
1365 | } |
---|
1366 | } |
---|
1367 | |
---|
1368 | #if NH_3D_VSO |
---|
1369 | Void |
---|
1370 | TAppComCamPara::setDispCoeff( UInt uiFrameId, Int iViewIdx ) |
---|
1371 | { |
---|
1372 | UInt uiFrame = m_uiFirstFrameId + uiFrameId; |
---|
1373 | Int iSourceViewNum = m_aiBaseViews[ iViewIdx ]; |
---|
1374 | Double dBaseLine = 0.0; |
---|
1375 | Double dFL1 = 1.0, dCS1 = 1.0, dCP1 = 1.0, dZN1 = 1.0, dZF1 = 1.0; |
---|
1376 | Bool bInterpolated = false; |
---|
1377 | double dPos[3] = {0.0, 0.0, 0.0}; |
---|
1378 | |
---|
1379 | if( m_iNumberOfBaseViews == 3 ) |
---|
1380 | { |
---|
1381 | xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated ); |
---|
1382 | xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated ); |
---|
1383 | xGetGeometryData( m_aiBaseViews[2], uiFrame, dFL1, dPos[2], dCS1, bInterpolated ); |
---|
1384 | |
---|
1385 | xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated ); |
---|
1386 | xGetZNearZFar ( iSourceViewNum, uiFrame, dZN1, dZF1 ); |
---|
1387 | |
---|
1388 | dBaseLine = ( std::max( dPos[0], std::max( dPos[1], dPos[2] ) ) - std::min( dPos[0], std::min( dPos[1], dPos[2] ) ) ) / 2.0; |
---|
1389 | } |
---|
1390 | else if( m_iNumberOfBaseViews == 2 ) |
---|
1391 | { |
---|
1392 | xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated ); |
---|
1393 | xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated ); |
---|
1394 | |
---|
1395 | xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated ); |
---|
1396 | xGetZNearZFar ( iSourceViewNum, uiFrame, dZN1, dZF1 ); |
---|
1397 | |
---|
1398 | dBaseLine = dPos[0] - dPos[1]; |
---|
1399 | } |
---|
1400 | |
---|
1401 | m_dDispCoeff = fabs( dFL1 * ( dBaseLine / 2.0 ) / 255.0 * ( 1.0/dZN1 - 1.0/dZF1 ) ); |
---|
1402 | } |
---|
1403 | #endif |
---|
1404 | |
---|
1405 | Bool |
---|
1406 | TAppComCamPara::getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ) |
---|
1407 | { |
---|
1408 | Int iLeftSortedViewIdx, iRightSortedViewIdx, iDummy; |
---|
1409 | Bool bExist = xGetLeftRightView( m_aiSynthViews[ iSynthViewIdx ], m_aiSortedBaseViews, iDummy, iDummy, iLeftSortedViewIdx, iRightSortedViewIdx ); |
---|
1410 | rbIsBaseView = ( iLeftSortedViewIdx == iRightSortedViewIdx && iLeftSortedViewIdx != -1 ); |
---|
1411 | |
---|
1412 | Int iLeftViewIdx = ( iLeftSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iLeftSortedViewIdx ] : -1 ); |
---|
1413 | Int iRightViewIdx = ( iRightSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iRightSortedViewIdx ] : -1 ); |
---|
1414 | |
---|
1415 | if ( iLeftSortedViewIdx != -1 && iRightSortedViewIdx != -1 ) |
---|
1416 | { |
---|
1417 | riRelDistToLeft = getRelDistLeft( iSynthViewIdx, iLeftViewIdx, iRightViewIdx); |
---|
1418 | } |
---|
1419 | else |
---|
1420 | { |
---|
1421 | riRelDistToLeft = -1; |
---|
1422 | } |
---|
1423 | |
---|
1424 | riLeftViewIdx = iLeftViewIdx; |
---|
1425 | riRightViewIdx = iRightViewIdx; |
---|
1426 | |
---|
1427 | return bExist; |
---|
1428 | } |
---|
1429 | |
---|
1430 | Bool |
---|
1431 | TAppComCamPara::xIsIn( std::vector<Int>& rVec, Int iElem) |
---|
1432 | { |
---|
1433 | Bool bFound = false; |
---|
1434 | for (Int idx = 0; idx < rVec.size() && !bFound; idx++) |
---|
1435 | { |
---|
1436 | bFound = bFound || rVec[idx] == iElem; |
---|
1437 | } |
---|
1438 | return bFound; |
---|
1439 | } |
---|
1440 | |
---|
1441 | Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ) |
---|
1442 | { |
---|
1443 | //GT: Get normalized distance |
---|
1444 | Int iLeftViewDist = abs ( m_aiBaseId2SortedId[ iLeftViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
1445 | Int iRightViewDist = abs ( m_aiBaseId2SortedId[ iRightViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
1446 | Int64 iDistSum = iLeftViewDist + iRightViewDist; |
---|
1447 | return (iDistSum == 0) ? (1 << (REN_VDWEIGHT_PREC -1) ) : (Int) (( (((Int64) iLeftViewDist ) << REN_VDWEIGHT_PREC ) + (iDistSum >> 1) ) / iDistSum ); |
---|
1448 | } |
---|
1449 | |
---|
1450 | Int |
---|
1451 | TAppComCamPara::synthRelNum2Idx( Int iRelNum ) |
---|
1452 | { |
---|
1453 | return xGetViewId(m_aiRelSynthViewsNum, iRelNum ); |
---|
1454 | } |
---|
1455 | #endif |
---|