source: 3DVCSoftware/trunk/source/App/TAppCommon/TAppComCamPara.h @ 18

Last change on this file since 18 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 14.3 KB
Line 
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#ifndef __TAPPCOMCAMPARA__
37#define __TAPPCOMCAMPARA__
38
39// Include files
40#include "../../Lib/TLibCommon/CommonDef.h"
41#include "../../Lib/TLibCommon/TComMVDRefData.h"
42#include <vector>
43
44
45#define LOG10_VIEW_NUM_PREC         5  // Precision of view numbering
46#define VIEW_NUM_PREC               pow( 10.0, (Int)LOG10_VIEW_NUM_PREC )
47
48// ====================================================================================================================
49// Class definition
50// ====================================================================================================================
51
52class TAppComCamPara
53{
54private:
55  // camera parameter data
56  std::vector< std::vector<Double> >  m_aadCameraParameters;  ///< buffer for double values from file
57
58  // miscellaneous variables
59  Double              m_dViewNumPrec;                         ///< factor for camera number to create integer representation
60  Int                 m_iLog2Precision;                       ///< shift precision in LUT
61  UInt                m_uiInputBitDepth;                      ///< bit depth of input depth maps
62  UInt                m_uiBitDepthForLUT;                     ///< bit depth used for table look-up
63  UInt                m_uiFirstFrameId;                       ///< first frame id
64  UInt                m_uiLastFrameId;                        ///< last frame id
65  UInt                m_iCurrentFrameId;                      ///< currently set frame id
66
67  Bool                m_bSetupFromCoded;                      ///< setup from coded parameter file
68  Bool                m_bCamParsCodedPrecSet;                 ///< Coded Cam Para precision set for current frame;
69
70  // view lists
71  std::vector<Int>    m_aiViewsInCfgFile;                     ///< views for which parameters are specified in cfg file (from left to right)
72  std::vector<Int>    m_aiSynthViews;                           ///< View numbers of External ViewReferences
73  std::vector<Int>    m_aiRelSynthViewsNum;                   ///< Relative view numbers of External ViewReferences
74  std::vector<Int>    m_aiBaseViews;                          ///< View numbers of Base View References (in coding order)
75  std::vector<Int>    m_aiSortedBaseViews;                    ///< View numbers of Base View References (from left to right)
76  std::vector<Int>    m_aiBaseId2SortedId;                    ///< mapping from coding order to left-right order for base views
77  std::vector<Int>    m_aiBaseSortedId2Id;                    ///< mapping from left-right order to coding order for base views
78  Int                 m_iNumberOfBaseViews;                   ///< number of base views
79  Int                 m_iNumberOfSynthViews;                  ///< number of synthesized views
80
81  // SPS and slice header related variables
82  std::vector<Int>    m_aiViewOrderIndex;                     ///< list of view order indices
83  UInt                m_uiCamParsCodedPrecision;              ///< precision for coding of camera parameters (x: max error in disparity is 2^(-x) luma samples)
84  Bool                m_bCamParsVaryOverTime;                 ///< flag specifying whether camera parameters vary for given frame numbers
85  Int**               m_aaiCodedScale;                        ///< array of coded scaling parameters [RefView][TargetView]
86  Int**               m_aaiCodedOffset;                       ///< array of coded offset  parameters [RefView][TargetView]
87  Int**               m_aaiScaleAndOffsetSet;                 ///< array indicating whether scale and offset have been set
88
89  // parameters for virtual depth map generation
90  Int                 m_iPdmPrecision;                        ///< additional precision for disparity - virtual depth conversion
91  Int**               m_aaiPdmScaleNomDelta;                  ///< [TargetView][RefView] delta for nominator of scale factor
92  Int**               m_aaiPdmOffset;                         ///< [TargetView][RefView] offset parameter
93
94  // scale and offset parameters
95  Double***           m_adBaseViewShiftParameter;                                                       ///< ShiftParameters between BaseViews e.g. [2][1][0] shift scale from view 2 to view 1; [2][1][1] shift offset from view 2 to view 1
96  Int64 ***           m_aiBaseViewShiftParameter;                                       ///< ShiftParameters between BaseViews e.g. [2][1][0] shift scale from view 2 to view 1; [2][1][1] shift offset from view 2 to view 1           /* do we need 64 bit? */
97  Double***           m_adSynthViewShiftParameter;                                        ///< ShiftParameters between BaseViews and ERViews e.g. [2][1][0] shift scale from base view 2 to er view 1;
98  Int64 ***           m_aiSynthViewShiftParameter;                              ///< ShiftParameters between BaseViews and ERViews e.g. [2][1][0] shift scale from base view 2 to er view 1;            /* do we need 64 bit? */
99
100  // look-up tables
101  Double****          m_adBaseViewShiftLUT;                                                                             ///< Disparity LUT
102  Int****             m_aiBaseViewShiftLUT;                                                                       ///< Disparity LUT
103  Double****          m_adSynthViewShiftLUT;                                                                    ///< Disparity LUT
104  Int****             m_aiSynthViewShiftLUT;                                                                    ///< Disparity LUT
105
106
107protected:
108  // create and delete arrays
109  Void                    xCreateLUTs   ( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
110  Void                    xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray );
111  Void                    xInit2dArray  ( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray, Int iValue );
112  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 );
113  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2 );
114  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize );
115
116  // functions for reading, initialization, sorting, getting data, etc.
117  Void  xReadCameraParameterFile  ( Char* pchCfgFileName );
118  Bool  xGetCameraDataRow         ( Int iView, UInt uiFrame, UInt& ruiFoundLine );
119
120  Void  xGetSortedViewList        ( const std::vector<Int>& raiViews, std::vector<Int>& raiSortedViews, std::vector<Int>& raiId2SortedId, std::vector<Int>& raiSortedId2Id );
121  Void  xGetViewOrderIndices      ( const std::vector<Int>& raiId2SortedId, std::vector<Int>& raiVOIdx );
122  Bool  xGetCamParsChangeFlag     ();
123  Int   xGetBaseViewId            ( Int iBaseView );
124  Int   xGetViewId                 ( std::vector<Int> aiViewList, Int iBaseView );
125
126  Bool  xGetLeftRightView         ( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx );
127  Void  xGetPrevAndNextBaseView   ( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum );
128  Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
129  Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
130  Void  xSetupBaseViewsFromCoded  ();
131  Void  xSetupBaseViews           ( Char* pchBaseViewNumbers, UInt uiNumBaseViews );
132
133  // functions for getting and setting scales and offsets
134  Bool  xGetShiftParameterReal    ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset );
135  Void  xGetShiftParameterCoded   ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame,                 Bool bByIdx, Int&    riScale, Int&    riOffset );
136  Void  xGetShiftParameterInt     ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64&  riScale, Int64&  riOffset );
137  Void  xGetCodedCameraData       ( UInt uiSourceView, UInt uiTargetView, Bool bByIdx,  UInt uiFrame, Int& riScale, Int& riOffset, Int& riPrecision );
138
139  Void  xSetCodedScaleOffset      ( UInt uiFrame );
140  Void  xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Bool bExternalReference, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
141  Void  xSetShiftParametersAndLUT ( UInt uiFrame );
142
143
144  // getting conversion parameters for disparity to virtual depth conversion
145  Void  xGetCameraShifts          ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift );
146  Void  xSetPdmConversionParams   ();
147
148public:
149  // constructor and destructor
150  TAppComCamPara();
151  ~TAppComCamPara();
152
153  // initialization, check, and and update
154  Void init   ( UInt    uiNumBaseViews,
155                UInt    uiInputBitDepth,
156                UInt    uiCodedCamParsPrecision,
157                UInt    uiStartFrameId,
158                UInt    uiNumFrames,
159                Char*   pchCfgFileName,
160                Char*   pchBaseViewNumbers,
161                Char*   pchSynthViewNumbers,
162                std::vector<Int>* paiSynthViewNumbers,
163                Int     iLog2Precision );
164
165  Void init   ( UInt    uiInputBitDepth,
166                UInt    uiStartFrameId,
167                UInt    uiNumFrames,
168                Char*   pchCfgFileName,
169                Char*   pchSynthViewNumbers,
170                std::vector<Int>* paiSynthViewNumbers,
171                Int     iLog2Precision
172              );
173
174
175
176  Void check  ( Bool    bCheckViewRange,
177                Bool    bCheckFrameRange );
178  Void update ( UInt    uiFrameId );
179
180  // miscellaneous functions
181
182  Int                 synthRelNum2Idx           ( Int iRelNum );
183  Bool getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView );
184  Int                 getRelDistLeft            ( Int iSynthViewIdx, Int   iLeftViewIdx, Int iRightViewIdx );
185  UInt                getCurFrameId             ()  { return m_iCurrentFrameId;   }
186  static Void         convertNumberString       ( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec );
187
188  // function for getting parameters and parameter arrays
189  std::vector<Int>&   getBaseViewNumbers        ()  { return m_aiBaseViews;       }
190  std::vector<Int>&   getSortedBaseViewNumbers  ()  { return m_aiSortedBaseViews; }
191  std::vector<Int>&   getSynthViewNumbers       ()  { return m_aiSynthViews;      }
192  std::vector<Int>&   getRelSynthViewNumbers    ()  { return m_aiRelSynthViewsNum;}
193
194  std::vector<Int>&   getBaseId2SortedId        ()   { return m_aiBaseId2SortedId; }
195  std::vector<Int>&   getBaseSortedId2Id        ()   { return m_aiBaseSortedId2Id; }
196
197
198  Double***           getBaseViewShiftParameterD()  { return         m_adBaseViewShiftParameter;  }
199  Int***              getBaseViewShiftParameterI()  { return (Int***)m_aiBaseViewShiftParameter;  }
200
201  Double****          getSynthViewShiftLUTD     ()  { return m_adSynthViewShiftLUT;  }
202  Double****          getBaseViewShiftLUTD      ()  { return m_adBaseViewShiftLUT;   }
203  Int****             getSynthViewShiftLUTI     ()  { return m_aiSynthViewShiftLUT;  }
204  Int****             getBaseViewShiftLUTI      ()  { return m_aiBaseViewShiftLUT;   }
205
206  Bool                getVaryingCameraParameters()  { return m_bCamParsVaryOverTime;    }
207  UInt                getCamParsCodedPrecision  ()  { return m_uiCamParsCodedPrecision; }
208  std::vector<Int>&   getViewOrderIndex         ()  { return m_aiViewOrderIndex;        }
209  Int**               getCodedScale             ()  { return m_aaiCodedScale;           }
210  Int**               getCodedOffset            ()  { return m_aaiCodedOffset;          }
211
212  // parameters for virtual depth map generation
213  Int                 getPdmPrecision           ()  { return m_iPdmPrecision;           }
214  Int**               getPdmScaleNomDelta       ()  { return m_aaiPdmScaleNomDelta;     }
215  Int**               getPdmOffset              ()  { return m_aaiPdmOffset;            }
216};
217
218
219
220
221
222template <class T>
223Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 )
224{
225  if( rpt )
226  {
227    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
228    {
229      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
230      {
231        for( UInt uiM = 0; uiM < uiSize3; uiM++ )
232        {
233          delete[] rpt[ uiK ][ uiL ][ uiM ];
234        }
235        delete[] rpt[ uiK ][ uiL ];
236      }
237      delete[] rpt[ uiK ];
238    }
239    delete[] rpt;
240  }
241  rpt = NULL;
242};
243
244
245template <class T>
246Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2 )
247{
248  if( rpt )
249  {
250    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
251    {
252      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
253      {
254        delete[] rpt[ uiK ][ uiL ];
255      }
256      delete[] rpt[ uiK ];
257    }
258    delete[] rpt;
259  }
260  rpt = NULL;
261};
262
263
264template <class T>
265Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize )
266{
267  if( rpt )
268  {
269    for( UInt uiK = 0; uiK < uiSize; uiK++ )
270    {
271      delete[] rpt[ uiK ];
272    }
273    delete[] rpt;
274  }
275  rpt = NULL;
276};
277
278
279
280#endif // __TAPPCOMCAMPARA__
281
282
283
Note: See TracBrowser for help on using the repository browser.