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