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