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 [ SizeOfLUT+1 ]; |
---|
79 | radLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ SizeOfLUT+1 ]; |
---|
80 | |
---|
81 | raiLUT [ uiSourceView ][ uiTargetView ] = new Int* [ 2 ]; |
---|
82 | raiLUT [ uiSourceView ][ uiTargetView ][ 0 ] = new Int [ SizeOfLUT+1 ]; |
---|
83 | raiLUT [ uiSourceView ][ uiTargetView ][ 1 ] = new Int [ SizeOfLUT+1 ]; |
---|
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 | #if POZNAN_NONLINEAR_DEPTH |
---|
880 | TComPowerConverter power(m_fDepthPower, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0); |
---|
881 | #endif |
---|
882 | |
---|
883 | for( UInt uiDepthValue = 0; uiDepthValue < SizeOfLUT; uiDepthValue++ ) |
---|
884 | { |
---|
885 | Double dDepthValue = (Double)uiDepthValue; |
---|
886 | Int64 iDepthValue = (Int64)uiDepthValue; |
---|
887 | #if POZNAN_NONLINEAR_DEPTH |
---|
888 | dDepthValue = power(dDepthValue); |
---|
889 | iDepthValue = (Int64)(dDepthValue+0.5); |
---|
890 | #endif |
---|
891 | #if POZNAN_LUT_INCREASED_PRECISION |
---|
892 | dDepthValue /= (1<<g_uiBitIncrement); |
---|
893 | #endif |
---|
894 | // real-valued look-up tables |
---|
895 | |
---|
896 | Double dShiftLuma = ( dDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision ); |
---|
897 | Double dShiftChroma = dShiftLuma / 2; |
---|
898 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma; |
---|
899 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma; |
---|
900 | |
---|
901 | // integer-valued look-up tables |
---|
902 | //Int64 iDepthValue = (Int64)uiDepthValue; |
---|
903 | Int64 iTempScale = iDepthValue * iScale; |
---|
904 | #if POZNAN_LUT_INCREASED_PRECISION |
---|
905 | iTempScale >>= g_uiBitIncrement; |
---|
906 | #endif |
---|
907 | Int64 iTestScale = ( iTempScale + iOffset ); // for checking accuracy of camera parameters |
---|
908 | Int64 iShiftLuma = ( iTempScale + iOffsetLuma ) >> iLog2DivLuma; |
---|
909 | Int64 iShiftChroma = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma; |
---|
910 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma; |
---|
911 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma; |
---|
912 | |
---|
913 | // maximum deviation |
---|
914 | dMaxDispDev = Max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); |
---|
915 | dMaxRndDispDvL = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); |
---|
916 | dMaxRndDispDvC = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); |
---|
917 | } |
---|
918 | |
---|
919 | radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT-1 ]; |
---|
920 | radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT-1 ]; |
---|
921 | raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ SizeOfLUT-1 ]; |
---|
922 | raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ SizeOfLUT-1 ]; |
---|
923 | } |
---|
924 | } |
---|
925 | |
---|
926 | // check maximum deviation |
---|
927 | Double dMaxAllowedDispDev = Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // counting only the impact of camera parameter rounding |
---|
928 | Double dMaxAllowedRndDispDvL = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ); // final rounding and impact of camera parameter rounding |
---|
929 | Double dMaxAllowedRndDispDvC = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ) / 2.0; // final rounding and impact of camera parameter rounding |
---|
930 | |
---|
931 | if( ( dMaxDispDev >= dMaxAllowedDispDev || dMaxRndDispDvL >= dMaxAllowedRndDispDvL || dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) && !m_bSetupFromCoded ) |
---|
932 | { |
---|
933 | std::cout << "Warning: Something wrong with the accuracy of coded camera parameters:" << std::endl; |
---|
934 | if( dMaxDispDev >= dMaxAllowedDispDev ) |
---|
935 | { |
---|
936 | std::cout << " max disparity difference is " << dMaxDispDev << " (allowed: " << dMaxAllowedDispDev << ")" << std::endl; |
---|
937 | } |
---|
938 | if( dMaxRndDispDvL >= dMaxAllowedRndDispDvL ) |
---|
939 | { |
---|
940 | std::cout << " max rnd luma disp diff is " << dMaxRndDispDvL << " (allowed: " << dMaxAllowedRndDispDvL << ")" << std::endl; |
---|
941 | } |
---|
942 | if( dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) |
---|
943 | { |
---|
944 | std::cout << " max rnd chroma disp diff is " << dMaxRndDispDvC << " (allowed: " << dMaxAllowedRndDispDvC << ")" << std::endl; |
---|
945 | } |
---|
946 | } |
---|
947 | } |
---|
948 | |
---|
949 | |
---|
950 | Void |
---|
951 | TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame ) |
---|
952 | { |
---|
953 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
954 | xSetCodedScaleOffset ( uiFrame ); |
---|
955 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, uiFrame, false, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
956 | xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
957 | }; |
---|
958 | |
---|
959 | |
---|
960 | Void |
---|
961 | TAppComCamPara::xGetCameraShifts( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift ) |
---|
962 | { |
---|
963 | Double dDummy, dCamPosSource, dCamPosTarget, dPicPosSource, dPicPosTarget; |
---|
964 | Bool bInterpolatedSource, bInterpolatedTarget; |
---|
965 | Int iTargetViewNum = m_aiBaseViews[ uiTargetView ]; |
---|
966 | Int iSourceViewNum = m_aiBaseViews[ uiSourceView ]; |
---|
967 | |
---|
968 | xGetGeometryData( iSourceViewNum, uiFrame, dDummy, dCamPosSource, dPicPosSource, bInterpolatedSource ); |
---|
969 | xGetGeometryData( iTargetViewNum, uiFrame, dDummy, dCamPosTarget, dPicPosTarget, bInterpolatedTarget ); |
---|
970 | AOT( bInterpolatedSource || bInterpolatedTarget ); |
---|
971 | |
---|
972 | rdCamPosShift = ( dCamPosTarget - dCamPosSource ); |
---|
973 | rdPicPosShift = -( dPicPosTarget - dPicPosSource ); // to be consistent |
---|
974 | } |
---|
975 | |
---|
976 | |
---|
977 | Void |
---|
978 | TAppComCamPara::xSetPdmConversionParams() |
---|
979 | { |
---|
980 | AOF( m_aiViewOrderIndex[ 0 ] == 0 ); |
---|
981 | if ( m_bSetupFromCoded || m_iNumberOfBaseViews < 2 ) |
---|
982 | { |
---|
983 | return; |
---|
984 | } |
---|
985 | |
---|
986 | //--- determine (virtual) camera parameter shift between view order index 1 and base view (view order index 0) --- |
---|
987 | Double dCamPosShift, dPicPosShift; |
---|
988 | Int iMinVOI = (1<<30); |
---|
989 | Int iMinAbsVOI = (1<<30); |
---|
990 | Int iMinAbsVOIId = 0; |
---|
991 | for( Int iBaseId = 1; iBaseId < m_iNumberOfBaseViews; iBaseId++ ) |
---|
992 | { |
---|
993 | Int iAbsVOI = ( m_aiViewOrderIndex[ iBaseId ] < 0 ? -m_aiViewOrderIndex[ iBaseId ] : m_aiViewOrderIndex[ iBaseId ] ); |
---|
994 | if( iAbsVOI < iMinAbsVOI ) |
---|
995 | { |
---|
996 | iMinVOI = m_aiViewOrderIndex[ iBaseId ]; |
---|
997 | iMinAbsVOI = iAbsVOI; |
---|
998 | iMinAbsVOIId = iBaseId; |
---|
999 | } |
---|
1000 | } |
---|
1001 | AOF( iMinAbsVOIId != 0 && iMinAbsVOI != 0 ); |
---|
1002 | xGetCameraShifts( 0, iMinAbsVOIId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
1003 | Double dCamPosShiftVOI01 = dCamPosShift / Double( iMinVOI ); |
---|
1004 | Double dAbsCamPosShiftVOI01 = ( dCamPosShiftVOI01 < 0.0 ? -dCamPosShiftVOI01 : dCamPosShiftVOI01 ); |
---|
1005 | |
---|
1006 | //--- determine maximum absolute camera position shift, precision, and base scale --- |
---|
1007 | Double dMaxAbsCamPosShift = 0.0; |
---|
1008 | for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ ) |
---|
1009 | { |
---|
1010 | for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ ) |
---|
1011 | { |
---|
1012 | xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
1013 | dCamPosShift = ( dCamPosShift < 0.0 ? -dCamPosShift : dCamPosShift ); |
---|
1014 | dMaxAbsCamPosShift = ( dCamPosShift > dMaxAbsCamPosShift ? dCamPosShift : dMaxAbsCamPosShift ); |
---|
1015 | } |
---|
1016 | } |
---|
1017 | Double dEpsilon = 1e-15; |
---|
1018 | Double dShiftRatio = dMaxAbsCamPosShift / dAbsCamPosShiftVOI01 - dEpsilon; |
---|
1019 | Int iPrecision = 0; for( ; (Double)( 1 << iPrecision ) < dShiftRatio; iPrecision++ ); |
---|
1020 | Int iPrecShift = iPrecision + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2; |
---|
1021 | AOF( iPrecShift < PDM_INTERNAL_CALC_BIT_DEPTH ); |
---|
1022 | Int iScaleVOI01 = 1 << iPrecShift; |
---|
1023 | m_iPdmPrecision = iPrecision; |
---|
1024 | |
---|
1025 | //--- loop over target views --- |
---|
1026 | for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ ) |
---|
1027 | { |
---|
1028 | // set scale and offset parameters for other views |
---|
1029 | for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ ) |
---|
1030 | { |
---|
1031 | xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); |
---|
1032 | Double dScale = Double( iScaleVOI01 ) * dCamPosShiftVOI01 / dCamPosShift; |
---|
1033 | Int iDiv = m_aiViewOrderIndex[ iTargetId ] - m_aiViewOrderIndex[ iBaseId ]; |
---|
1034 | Int iAdd = ( iDiv > 0 ? iDiv / 2 : -iDiv / 2 ); |
---|
1035 | Int iScalePred = ( iScaleVOI01 + iAdd ) / iDiv; |
---|
1036 | Double dFactor = dScale / (Double)iScalePred * pow( 2.0, PDM_LOG4_SCALE_DENOMINATOR ); |
---|
1037 | Int iNominator = (Int)floor( dFactor + .5 ); |
---|
1038 | Int iNomDelta = iNominator - ( 1 << PDM_LOG4_SCALE_DENOMINATOR ); |
---|
1039 | Int iScale = Int( ( (Int64)iNominator * (Int64)iScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR ); |
---|
1040 | Double dOffset = -dPicPosShift * Double( iScale ) * pow( 2.0, 2 - PDM_OFFSET_SHIFT ); |
---|
1041 | Int iOffset = (Int)floor( dOffset + .5 ); |
---|
1042 | |
---|
1043 | m_aaiPdmScaleNomDelta [ iTargetId ][ iBaseId ] = iNomDelta; |
---|
1044 | m_aaiPdmOffset [ iTargetId ][ iBaseId ] = iOffset; |
---|
1045 | } |
---|
1046 | } |
---|
1047 | } |
---|
1048 | |
---|
1049 | |
---|
1050 | |
---|
1051 | TAppComCamPara::TAppComCamPara() |
---|
1052 | { |
---|
1053 | m_dViewNumPrec = VIEW_NUM_PREC; // fixed |
---|
1054 | m_iLog2Precision = -1; |
---|
1055 | m_uiInputBitDepth = 0; |
---|
1056 | m_uiBitDepthForLUT = 8; // fixed |
---|
1057 | m_uiFirstFrameId = 0; |
---|
1058 | m_uiLastFrameId = 0; |
---|
1059 | |
---|
1060 | m_iNumberOfBaseViews = -1; |
---|
1061 | m_iNumberOfSynthViews = -1; |
---|
1062 | |
---|
1063 | m_uiCamParsCodedPrecision = 0; |
---|
1064 | m_bCamParsVaryOverTime = true; |
---|
1065 | |
---|
1066 | m_aaiCodedScale = 0; |
---|
1067 | m_aaiCodedOffset = 0; |
---|
1068 | m_aaiScaleAndOffsetSet = 0; |
---|
1069 | |
---|
1070 | m_iPdmPrecision = 0; |
---|
1071 | m_aaiPdmScaleNomDelta = 0; |
---|
1072 | m_aaiPdmOffset = 0; |
---|
1073 | |
---|
1074 | m_adBaseViewShiftParameter = 0; |
---|
1075 | m_aiBaseViewShiftParameter = 0; |
---|
1076 | m_adSynthViewShiftParameter = 0; |
---|
1077 | m_aiSynthViewShiftParameter = 0; |
---|
1078 | |
---|
1079 | m_adBaseViewShiftLUT = 0; |
---|
1080 | m_aiBaseViewShiftLUT = 0; |
---|
1081 | m_adSynthViewShiftLUT = 0; |
---|
1082 | m_aiSynthViewShiftLUT = 0; |
---|
1083 | |
---|
1084 | m_bSetupFromCoded = false; |
---|
1085 | m_bCamParsCodedPrecSet = false; |
---|
1086 | |
---|
1087 | |
---|
1088 | } |
---|
1089 | |
---|
1090 | |
---|
1091 | TAppComCamPara::~TAppComCamPara() |
---|
1092 | { |
---|
1093 | xDeleteArray( m_adBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
1094 | xDeleteArray( m_aiBaseViewShiftParameter, m_iNumberOfBaseViews, m_iNumberOfBaseViews ); |
---|
1095 | xDeleteArray( m_adBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
1096 | xDeleteArray( m_aiBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); |
---|
1097 | |
---|
1098 | xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews)); |
---|
1099 | xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews)); |
---|
1100 | xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 ); |
---|
1101 | xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 ); |
---|
1102 | |
---|
1103 | xDeleteArray( m_aaiCodedScale, m_iNumberOfBaseViews ); |
---|
1104 | xDeleteArray( m_aaiCodedOffset, m_iNumberOfBaseViews ); |
---|
1105 | xDeleteArray( m_aaiScaleAndOffsetSet, m_iNumberOfBaseViews ); |
---|
1106 | |
---|
1107 | xDeleteArray( m_aaiPdmScaleNomDelta, m_iNumberOfBaseViews ); |
---|
1108 | xDeleteArray( m_aaiPdmOffset, m_iNumberOfBaseViews ); |
---|
1109 | } |
---|
1110 | |
---|
1111 | Void |
---|
1112 | TAppComCamPara::xSetupBaseViewsFromCoded() |
---|
1113 | { |
---|
1114 | //===== get and sort views given in camera parameter file and set list of base views and related arrays ===== |
---|
1115 | // get left-right order and coding order from cfg-file |
---|
1116 | std::vector<Int> aiViewOrderIdx; // Left Right Order |
---|
1117 | std::vector<Int> aiViewId ; // Coding Order |
---|
1118 | |
---|
1119 | Int iMinViewOrderIdx = MAX_INT; |
---|
1120 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1121 | { |
---|
1122 | if (m_aadCameraParameters[uiRow].size() != 2 ) |
---|
1123 | break; |
---|
1124 | |
---|
1125 | Int iViewOrderIdx = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] ); |
---|
1126 | iMinViewOrderIdx = Min( iViewOrderIdx, iMinViewOrderIdx ); |
---|
1127 | |
---|
1128 | aiViewOrderIdx .push_back( iViewOrderIdx ); |
---|
1129 | aiViewId .push_back( (Int) m_aadCameraParameters[ uiRow ][ 0 ] ); |
---|
1130 | } |
---|
1131 | |
---|
1132 | // create base view numbers |
---|
1133 | AOT( aiViewId.size() != aiViewOrderIdx.size() ); |
---|
1134 | m_iNumberOfBaseViews = (Int) aiViewId.size(); |
---|
1135 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1136 | { |
---|
1137 | aiViewOrderIdx[iCurBaseView] = ( aiViewOrderIdx[iCurBaseView] - iMinViewOrderIdx); |
---|
1138 | m_aiBaseViews .push_back( aiViewOrderIdx[iCurBaseView] * ( (Int) m_dViewNumPrec) ); |
---|
1139 | m_aiBaseId2SortedId.push_back( iCurBaseView ); |
---|
1140 | m_aiBaseSortedId2Id.push_back( iCurBaseView ); |
---|
1141 | |
---|
1142 | } |
---|
1143 | |
---|
1144 | m_iNumberOfBaseViews = (Int) m_aiBaseViews.size(); |
---|
1145 | |
---|
1146 | std::vector<Int> aiSortedViewOrderIdx = aiViewOrderIdx; |
---|
1147 | |
---|
1148 | // sort base views according to View Order Idx |
---|
1149 | m_aiSortedBaseViews = m_aiBaseViews; |
---|
1150 | for (Int iCurBaseView = 1; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1151 | { |
---|
1152 | Int iCurViewOrder = aiSortedViewOrderIdx[iCurBaseView]; |
---|
1153 | for (Int iCurSearchPos = iCurBaseView; iCurSearchPos >= 0; iCurSearchPos-- ) |
---|
1154 | { |
---|
1155 | if ( iCurViewOrder < aiSortedViewOrderIdx[iCurSearchPos] ) |
---|
1156 | { |
---|
1157 | Int iTempViewId = m_aiSortedBaseViews[iCurSearchPos]; |
---|
1158 | m_aiSortedBaseViews[iCurSearchPos] = m_aiSortedBaseViews[iCurBaseView]; |
---|
1159 | m_aiSortedBaseViews[iCurBaseView ] = iTempViewId; |
---|
1160 | |
---|
1161 | Int iTempViewOrderIdx = aiSortedViewOrderIdx[iCurSearchPos]; |
---|
1162 | aiSortedViewOrderIdx[iCurSearchPos] = aiSortedViewOrderIdx[iCurBaseView]; |
---|
1163 | aiSortedViewOrderIdx[iCurBaseView ] = iTempViewOrderIdx; |
---|
1164 | |
---|
1165 | Int iTempPos = m_aiBaseSortedId2Id[iCurSearchPos]; |
---|
1166 | m_aiBaseSortedId2Id[iCurSearchPos] = m_aiBaseSortedId2Id[iCurBaseView]; |
---|
1167 | m_aiBaseSortedId2Id[iCurBaseView] = iTempPos; |
---|
1168 | iCurBaseView--; |
---|
1169 | } |
---|
1170 | } |
---|
1171 | } |
---|
1172 | |
---|
1173 | for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ ) |
---|
1174 | { |
---|
1175 | m_aiBaseId2SortedId[m_aiBaseSortedId2Id[iCurBaseView]] = iCurBaseView; |
---|
1176 | } |
---|
1177 | |
---|
1178 | m_aiViewsInCfgFile = m_aiSortedBaseViews; |
---|
1179 | |
---|
1180 | // check |
---|
1181 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
1182 | { |
---|
1183 | std::cerr << "Failed reading camera parameter file" << std::endl; |
---|
1184 | std::cerr << "At least two views must be given" << std::endl; |
---|
1185 | AOT(true); |
---|
1186 | exit( EXIT_FAILURE ); |
---|
1187 | } |
---|
1188 | |
---|
1189 | // translate coding order to view order |
---|
1190 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1191 | { |
---|
1192 | if (m_aadCameraParameters[uiRow].size() == 2 ) |
---|
1193 | continue; |
---|
1194 | |
---|
1195 | m_aadCameraParameters[ uiRow ][ 2 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 2 ] ) ]; |
---|
1196 | m_aadCameraParameters[ uiRow ][ 3 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 3 ] ) ]; |
---|
1197 | } |
---|
1198 | } |
---|
1199 | |
---|
1200 | Void TAppComCamPara::xSetupBaseViews( Char* pchBaseViewNumbers, UInt uiNumBaseViews ) |
---|
1201 | { |
---|
1202 | // init list |
---|
1203 | std::vector<Int> aiViewsInCfg; |
---|
1204 | for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ ) |
---|
1205 | { |
---|
1206 | aiViewsInCfg.push_back( (Int)( m_aadCameraParameters[ uiRow ][ 0 ] * m_dViewNumPrec ) ); |
---|
1207 | } |
---|
1208 | // remove duplicated items |
---|
1209 | std::sort( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
1210 | std::vector<Int>::iterator cIterNewEnd = std::unique( aiViewsInCfg.begin(), aiViewsInCfg.end() ); |
---|
1211 | aiViewsInCfg.erase( cIterNewEnd, aiViewsInCfg.end() ); |
---|
1212 | // sort (from left to right) |
---|
1213 | std::vector<Int> aiDummyI2SI, aiDummySI2I; |
---|
1214 | xGetSortedViewList( aiViewsInCfg, m_aiViewsInCfgFile, aiDummyI2SI, aiDummySI2I ); |
---|
1215 | // check |
---|
1216 | if( m_aiViewsInCfgFile.size() < 2 ) |
---|
1217 | { |
---|
1218 | std::cerr << "Failed reading config file" << std::endl; |
---|
1219 | std::cerr << "At least two views must be given" << std::endl; |
---|
1220 | exit( EXIT_FAILURE ); |
---|
1221 | } |
---|
1222 | |
---|
1223 | |
---|
1224 | |
---|
1225 | //===== set list of base views and related arrays ===== |
---|
1226 | if( pchBaseViewNumbers == 0 ) |
---|
1227 | { |
---|
1228 | std::cerr << "BaseViewCameraNumbers must be given" << std::endl; |
---|
1229 | exit( EXIT_FAILURE ); |
---|
1230 | }; |
---|
1231 | |
---|
1232 | convertNumberString( pchBaseViewNumbers, m_aiBaseViews, m_dViewNumPrec ); |
---|
1233 | while( (UInt)m_aiBaseViews.size() > uiNumBaseViews ) |
---|
1234 | { |
---|
1235 | m_aiBaseViews.pop_back(); |
---|
1236 | } |
---|
1237 | xGetSortedViewList( m_aiBaseViews, m_aiSortedBaseViews, m_aiBaseId2SortedId, m_aiBaseSortedId2Id ); |
---|
1238 | m_iNumberOfBaseViews = (Int)m_aiBaseViews.size(); |
---|
1239 | } |
---|
1240 | |
---|
1241 | |
---|
1242 | Void |
---|
1243 | TAppComCamPara::init( UInt uiNumBaseViews, |
---|
1244 | UInt uiInputBitDepth, |
---|
1245 | UInt uiCodedCamParsPrecision, |
---|
1246 | UInt uiStartFrameId, |
---|
1247 | UInt uiNumFrames, |
---|
1248 | Char* pchCfgFileName, |
---|
1249 | Char* pchBaseViewNumbers, |
---|
1250 | Char* pchSynthViewNumbers, |
---|
1251 | std::vector<Int>* paiSynthViewNumbers, |
---|
1252 | Int iLog2Precision |
---|
1253 | #if POZNAN_NONLINEAR_DEPTH |
---|
1254 | ,Float fDepthPower |
---|
1255 | #endif |
---|
1256 | ) |
---|
1257 | { |
---|
1258 | //===== set miscellaneous variables ===== |
---|
1259 | m_uiInputBitDepth = uiInputBitDepth; |
---|
1260 | m_uiFirstFrameId = uiStartFrameId; |
---|
1261 | m_uiLastFrameId = uiStartFrameId + uiNumFrames - 1; |
---|
1262 | m_uiCamParsCodedPrecision = uiCodedCamParsPrecision; |
---|
1263 | m_iLog2Precision = iLog2Precision; |
---|
1264 | |
---|
1265 | #if POZNAN_NONLINEAR_DEPTH |
---|
1266 | m_fDepthPower = fDepthPower; |
---|
1267 | #endif |
---|
1268 | |
---|
1269 | xReadCameraParameterFile( pchCfgFileName ); |
---|
1270 | |
---|
1271 | m_bSetupFromCoded = ( m_aadCameraParameters[ 0 ].size() == 2 ); |
---|
1272 | |
---|
1273 | if ( m_bSetupFromCoded ) |
---|
1274 | { |
---|
1275 | std::cout << "Detected decoded camera parameter file. Overwriting base view settings from cfg file. " << std::endl; |
---|
1276 | xSetupBaseViewsFromCoded(); |
---|
1277 | } |
---|
1278 | else |
---|
1279 | { |
---|
1280 | xSetupBaseViews( pchBaseViewNumbers, uiNumBaseViews ); |
---|
1281 | } |
---|
1282 | |
---|
1283 | //===== set list of external (virtual) views ===== |
---|
1284 | m_aiSynthViews.clear(); |
---|
1285 | |
---|
1286 | if( pchSynthViewNumbers != 0 || paiSynthViewNumbers != 0) |
---|
1287 | { |
---|
1288 | std::vector<Int> aiTmpSynthViews; |
---|
1289 | |
---|
1290 | AOT( ( pchSynthViewNumbers != NULL ) && ( paiSynthViewNumbers != NULL ) ); |
---|
1291 | |
---|
1292 | if ( pchSynthViewNumbers != NULL ) |
---|
1293 | { |
---|
1294 | convertNumberString( pchSynthViewNumbers, aiTmpSynthViews, m_dViewNumPrec ); |
---|
1295 | } |
---|
1296 | else |
---|
1297 | { |
---|
1298 | aiTmpSynthViews = (*paiSynthViewNumbers); |
---|
1299 | } |
---|
1300 | |
---|
1301 | for( UInt uiSId = 0; uiSId < (UInt)aiTmpSynthViews.size(); uiSId++ ) |
---|
1302 | { |
---|
1303 | |
---|
1304 | Int iViewNumPrec = (Int) m_dViewNumPrec; |
---|
1305 | Int iLeftBaseViewIdx = aiTmpSynthViews[ uiSId ] / iViewNumPrec; |
---|
1306 | Int iRightBaseViewIdx = ( aiTmpSynthViews[ uiSId ] + (iViewNumPrec - 1) ) / iViewNumPrec; |
---|
1307 | |
---|
1308 | if ( iLeftBaseViewIdx < 0 || iRightBaseViewIdx >= m_iNumberOfBaseViews ) |
---|
1309 | { |
---|
1310 | std::cerr << "SynthViewCameraNumbers must be greater and equal to 0 and smaller than number of base views" << std::endl; |
---|
1311 | AOT(true); |
---|
1312 | exit( EXIT_FAILURE ); |
---|
1313 | } |
---|
1314 | |
---|
1315 | Int64 iLeftBaseViewRelNum = iLeftBaseViewIdx * iViewNumPrec; |
---|
1316 | Int64 iRightBaseViewRelNum = iRightBaseViewIdx * iViewNumPrec; |
---|
1317 | |
---|
1318 | Int64 iDiffBaseViewRelNum = iRightBaseViewRelNum - iLeftBaseViewRelNum; |
---|
1319 | |
---|
1320 | Int64 iSynthViewRelNum = aiTmpSynthViews[ uiSId ]; |
---|
1321 | Int64 iLeftBaseNum = m_aiSortedBaseViews[ iLeftBaseViewIdx ]; |
---|
1322 | Int64 iRightBaseNum = m_aiSortedBaseViews[ iRightBaseViewIdx ]; |
---|
1323 | Int64 iDiffBaseNum = iRightBaseNum - iLeftBaseNum; |
---|
1324 | Int64 iSynthViewNum; |
---|
1325 | |
---|
1326 | if ( iDiffBaseViewRelNum != 0) |
---|
1327 | { |
---|
1328 | AOT( (Int) iDiffBaseViewRelNum != iViewNumPrec ); |
---|
1329 | Int iFact = iDiffBaseNum > 0 ? 1 : -1; |
---|
1330 | iSynthViewNum = iLeftBaseNum + ( iDiffBaseNum * ( iSynthViewRelNum - iLeftBaseViewRelNum ) + (iViewNumPrec >> 1) * iFact ) / ( iViewNumPrec ); |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | iSynthViewNum = iLeftBaseNum; |
---|
1335 | } |
---|
1336 | |
---|
1337 | m_aiRelSynthViewsNum.push_back( aiTmpSynthViews[ uiSId ] ); |
---|
1338 | m_aiSynthViews .push_back( (Int) iSynthViewNum ); |
---|
1339 | } |
---|
1340 | } |
---|
1341 | m_iNumberOfSynthViews = (Int)m_aiSynthViews.size(); |
---|
1342 | |
---|
1343 | |
---|
1344 | //===== set derived parameters ===== |
---|
1345 | xGetViewOrderIndices( m_aiBaseId2SortedId, m_aiViewOrderIndex ); |
---|
1346 | m_bCamParsVaryOverTime = xGetCamParsChangeFlag(); |
---|
1347 | |
---|
1348 | |
---|
1349 | //===== create arrays ===== |
---|
1350 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT, m_adBaseViewShiftParameter, m_aiBaseViewShiftParameter ); |
---|
1351 | xCreateLUTs ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter ); |
---|
1352 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedScale ); |
---|
1353 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiCodedOffset ); |
---|
1354 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet ); |
---|
1355 | xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); |
---|
1356 | |
---|
1357 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmScaleNomDelta ); |
---|
1358 | xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmOffset ); |
---|
1359 | |
---|
1360 | //===== init disparity to virtual depth conversion parameters ===== |
---|
1361 | xSetPdmConversionParams(); |
---|
1362 | |
---|
1363 | //===== init arrays for first frame ===== |
---|
1364 | xSetShiftParametersAndLUT( m_uiFirstFrameId ); |
---|
1365 | } |
---|
1366 | |
---|
1367 | Void |
---|
1368 | TAppComCamPara::check( Bool bCheckViewRange, Bool bCheckFrameRange ) |
---|
1369 | { |
---|
1370 | if( bCheckFrameRange ) |
---|
1371 | { |
---|
1372 | Double dDummy; |
---|
1373 | |
---|
1374 | for( UInt uiBaseView = 0; uiBaseView < m_aiBaseViews.size(); uiBaseView++ ) |
---|
1375 | { |
---|
1376 | if ( m_bSetupFromCoded ) |
---|
1377 | { |
---|
1378 | for( UInt uiTargetView = 0; uiTargetView < m_aiBaseViews.size(); uiTargetView++ ) |
---|
1379 | { |
---|
1380 | if ( uiTargetView == uiBaseView ) |
---|
1381 | continue; |
---|
1382 | |
---|
1383 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1384 | { |
---|
1385 | Int iDummy; |
---|
1386 | |
---|
1387 | xGetCodedCameraData( uiBaseView, uiTargetView, true , uiFrame, iDummy, iDummy, iDummy ); |
---|
1388 | } |
---|
1389 | } |
---|
1390 | } |
---|
1391 | else |
---|
1392 | { |
---|
1393 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1394 | { |
---|
1395 | Bool bInterpolatedCur; |
---|
1396 | xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
1397 | xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); |
---|
1398 | |
---|
1399 | if( bInterpolatedCur ) |
---|
1400 | { |
---|
1401 | std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; |
---|
1402 | exit( EXIT_FAILURE ); |
---|
1403 | } |
---|
1404 | } |
---|
1405 | |
---|
1406 | } |
---|
1407 | } |
---|
1408 | |
---|
1409 | for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) |
---|
1410 | { |
---|
1411 | Bool bInterpolated = false; |
---|
1412 | for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) |
---|
1413 | { |
---|
1414 | Bool bInterpolatedCur; |
---|
1415 | xGetGeometryData( m_aiSynthViews[ uiERView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); |
---|
1416 | bInterpolated |= bInterpolatedCur; |
---|
1417 | } |
---|
1418 | if( bInterpolated ) |
---|
1419 | { |
---|
1420 | std::cout << "Interpolating Camera Parameters for View " << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << std::endl; |
---|
1421 | } |
---|
1422 | } |
---|
1423 | } |
---|
1424 | |
---|
1425 | if( bCheckViewRange ) |
---|
1426 | { |
---|
1427 | Bool bAllExist = true; |
---|
1428 | for( Int iSynthViewIdx = 0; iSynthViewIdx < m_iNumberOfSynthViews; iSynthViewIdx++ ) |
---|
1429 | { |
---|
1430 | Bool bIsBaseView; |
---|
1431 | Int iDummy; |
---|
1432 | Bool bExist = getLeftRightBaseView( iSynthViewIdx, iDummy, iDummy, iDummy, bIsBaseView ); |
---|
1433 | bAllExist &= ( bExist || bIsBaseView ); |
---|
1434 | } |
---|
1435 | if( !bAllExist ) |
---|
1436 | { |
---|
1437 | std::cerr << "SynthViewNumbers must be within the range of BaseViewNumbers" << std::endl; |
---|
1438 | exit( EXIT_FAILURE ); |
---|
1439 | } |
---|
1440 | } |
---|
1441 | } |
---|
1442 | |
---|
1443 | |
---|
1444 | Void |
---|
1445 | TAppComCamPara::update( UInt uiFrameId ) |
---|
1446 | { |
---|
1447 | |
---|
1448 | m_iCurrentFrameId = uiFrameId; |
---|
1449 | m_bCamParsCodedPrecSet = false; |
---|
1450 | |
---|
1451 | AOF( 0 <= uiFrameId && uiFrameId <= m_uiLastFrameId - m_uiFirstFrameId ); |
---|
1452 | if ( m_bCamParsVaryOverTime ) |
---|
1453 | { |
---|
1454 | xSetShiftParametersAndLUT( m_uiFirstFrameId + uiFrameId ); |
---|
1455 | } |
---|
1456 | } |
---|
1457 | |
---|
1458 | |
---|
1459 | Bool |
---|
1460 | TAppComCamPara::getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ) |
---|
1461 | { |
---|
1462 | Int iLeftSortedViewIdx, iRightSortedViewIdx, iDummy; |
---|
1463 | Bool bExist = xGetLeftRightView( m_aiSynthViews[ iSynthViewIdx ], m_aiSortedBaseViews, iDummy, iDummy, iLeftSortedViewIdx, iRightSortedViewIdx ); |
---|
1464 | rbIsBaseView = ( iLeftSortedViewIdx == iRightSortedViewIdx && iLeftSortedViewIdx != -1 ); |
---|
1465 | |
---|
1466 | Int iLeftViewIdx = ( iLeftSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iLeftSortedViewIdx ] : -1 ); |
---|
1467 | Int iRightViewIdx = ( iRightSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iRightSortedViewIdx ] : -1 ); |
---|
1468 | |
---|
1469 | if ( iLeftSortedViewIdx != -1 && iRightSortedViewIdx != -1 ) |
---|
1470 | { |
---|
1471 | riRelDistToLeft = getRelDistLeft( iSynthViewIdx, iLeftViewIdx, iRightViewIdx); |
---|
1472 | } |
---|
1473 | else |
---|
1474 | { |
---|
1475 | riRelDistToLeft = -1; |
---|
1476 | } |
---|
1477 | |
---|
1478 | riLeftViewIdx = iLeftViewIdx; |
---|
1479 | riRightViewIdx = iRightViewIdx; |
---|
1480 | |
---|
1481 | return bExist; |
---|
1482 | } |
---|
1483 | |
---|
1484 | #if POZNAN_CU_SYNTH||POZNAN_CU_SKIP |
---|
1485 | Bool |
---|
1486 | TAppComCamPara::getNearestBaseView( Int iSynthViewIdx, Int &riNearestViewIdx, Int &riRelDistToLeft, Bool& rbRenderFromLeft) |
---|
1487 | { |
---|
1488 | riNearestViewIdx = 0; |
---|
1489 | |
---|
1490 | Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] ); |
---|
1491 | Int iFactor = ( bDecencdingVN ? -1 : 1 ); |
---|
1492 | |
---|
1493 | if( ( m_aiBaseId2SortedId[iSynthViewIdx] - m_aiBaseId2SortedId[riNearestViewIdx] ) * iFactor <= 0 ) |
---|
1494 | { |
---|
1495 | rbRenderFromLeft = true; |
---|
1496 | } |
---|
1497 | else |
---|
1498 | { |
---|
1499 | rbRenderFromLeft = false; |
---|
1500 | } |
---|
1501 | |
---|
1502 | riRelDistToLeft = 128; //Not used for now; |
---|
1503 | |
---|
1504 | return true; |
---|
1505 | } |
---|
1506 | #endif |
---|
1507 | |
---|
1508 | |
---|
1509 | |
---|
1510 | Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ) |
---|
1511 | { |
---|
1512 | //GT: Get normalized distance |
---|
1513 | Int iLeftViewDist = abs ( m_aiBaseId2SortedId[ iLeftViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
1514 | Int iRightViewDist = abs ( m_aiBaseId2SortedId[ iRightViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]); |
---|
1515 | Int64 iDistSum = iLeftViewDist + iRightViewDist; |
---|
1516 | return (iDistSum == 0) ? (1 << (REN_VDWEIGHT_PREC -1) ) : (Int) (( (((Int64) iLeftViewDist ) << REN_VDWEIGHT_PREC ) + (iDistSum >> 1) ) / iDistSum ); |
---|
1517 | } |
---|
1518 | |
---|
1519 | Int |
---|
1520 | TAppComCamPara::synthRelNum2Idx( Int iRelNum ) |
---|
1521 | { |
---|
1522 | return xGetViewId(m_aiRelSynthViewsNum, iRelNum ); |
---|
1523 | } |
---|