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