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