source: 3DVCSoftware/branches/HTM-8.2-dev2-LG/source/Lib/TAppCommon/TAppComCamPara.h

Last change on this file was 655, checked in by tech, 11 years ago

Merged 8.1-Cleanup@654

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