[56] | 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 | * |
---|
[1179] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[56] | 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 | |
---|
| 51 | class TAppComCamPara |
---|
| 52 | { |
---|
| 53 | private: |
---|
| 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; |
---|
[608] | 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 |
---|
[102] | 73 | Double m_dDispCoeff; |
---|
| 74 | |
---|
[56] | 75 | // view lists |
---|
| 76 | std::vector<Int> m_aiViewsInCfgFile; ///< views for which parameters are specified in cfg file (from left to right) |
---|
[100] | 77 | std::vector<Int> m_aiSynthViews; ///< View numbers of External ViewReferences |
---|
| 78 | std::vector<Int> m_aiRelSynthViewsNum; ///< Relative view numbers of External ViewReferences |
---|
[56] | 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 | UInt m_uiCamParsCodedPrecision; ///< precision for coding of camera parameters (x: max error in disparity is 2^(-x) luma samples) |
---|
| 88 | Bool m_bCamParsVaryOverTime; ///< flag specifying whether camera parameters vary for given frame numbers |
---|
| 89 | Int** m_aaiCodedScale; ///< array of coded scaling parameters [RefView][TargetView] |
---|
| 90 | Int** m_aaiCodedOffset; ///< array of coded offset parameters [RefView][TargetView] |
---|
| 91 | Int** m_aaiScaleAndOffsetSet; ///< array indicating whether scale and offset have been set |
---|
| 92 | |
---|
| 93 | // scale and offset parameters |
---|
[100] | 94 | 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 |
---|
| 95 | 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? */ |
---|
| 96 | Double*** m_adSynthViewShiftParameter; ///< ShiftParameters between BaseViews and ERViews e.g. [2][1][0] shift scale from base view 2 to er view 1; |
---|
| 97 | 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? */ |
---|
[56] | 98 | |
---|
| 99 | // look-up tables |
---|
[100] | 100 | Double**** m_adBaseViewShiftLUT; ///< Disparity LUT |
---|
| 101 | Int**** m_aiBaseViewShiftLUT; ///< Disparity LUT |
---|
| 102 | Double**** m_adSynthViewShiftLUT; ///< Disparity LUT |
---|
| 103 | Int**** m_aiSynthViewShiftLUT; ///< Disparity LUT |
---|
[56] | 104 | |
---|
| 105 | protected: |
---|
| 106 | // create and delete arrays |
---|
| 107 | Void xCreateLUTs ( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ); |
---|
| 108 | Void xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray ); |
---|
| 109 | Void xInit2dArray ( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray, Int iValue ); |
---|
| 110 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 ); |
---|
| 111 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize1, UInt uiSize2 ); |
---|
| 112 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize ); |
---|
| 113 | |
---|
| 114 | // functions for reading, initialization, sorting, getting data, etc. |
---|
| 115 | Void xReadCameraParameterFile ( Char* pchCfgFileName ); |
---|
| 116 | Bool xGetCameraDataRow ( Int iView, UInt uiFrame, UInt& ruiFoundLine ); |
---|
| 117 | |
---|
| 118 | Void xGetSortedViewList ( const std::vector<Int>& raiViews, std::vector<Int>& raiSortedViews, std::vector<Int>& raiId2SortedId, std::vector<Int>& raiSortedId2Id ); |
---|
| 119 | Void xGetViewOrderIndices ( const std::vector<Int>& raiId2SortedId, std::vector<Int>& raiVOIdx ); |
---|
| 120 | Bool xGetCamParsChangeFlag (); |
---|
| 121 | Int xGetBaseViewId ( Int iBaseView ); |
---|
| 122 | Int xGetViewId ( std::vector<Int> aiViewList, Int iBaseView ); |
---|
| 123 | |
---|
| 124 | Bool xGetLeftRightView ( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx ); |
---|
| 125 | Void xGetPrevAndNextBaseView ( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum ); |
---|
[655] | 126 | #if !KWU_RC_MADPRED_E0227 |
---|
[56] | 127 | Void xGetZNearZFar ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar ); |
---|
| 128 | Void xGetGeometryData ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ); |
---|
[655] | 129 | #endif |
---|
[56] | 130 | Void xSetupBaseViewsFromCoded (); |
---|
| 131 | Void xSetupBaseViews ( Char* pchBaseViewNumbers, UInt uiNumBaseViews ); |
---|
[608] | 132 | Bool xIsIn ( std::vector<Int>& rVec, Int iNumber); |
---|
[56] | 133 | |
---|
| 134 | // functions for getting and setting scales and offsets |
---|
| 135 | Bool xGetShiftParameterReal ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset ); |
---|
| 136 | Void xGetShiftParameterCoded ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bByIdx, Int& riScale, Int& riOffset ); |
---|
| 137 | Void xGetShiftParameterInt ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64& riScale, Int64& riOffset ); |
---|
| 138 | Void xGetCodedCameraData ( UInt uiSourceView, UInt uiTargetView, Bool bByIdx, UInt uiFrame, Int& riScale, Int& riOffset, Int& riPrecision ); |
---|
| 139 | |
---|
| 140 | Void xSetCodedScaleOffset ( UInt uiFrame ); |
---|
| 141 | Void xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Bool bExternalReference, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams ); |
---|
| 142 | Void xSetShiftParametersAndLUT ( UInt uiFrame ); |
---|
| 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 | |
---|
| 147 | public: |
---|
| 148 | // constructor and destructor |
---|
| 149 | TAppComCamPara(); |
---|
| 150 | ~TAppComCamPara(); |
---|
| 151 | |
---|
| 152 | // initialization, check, and and update |
---|
| 153 | Void init ( UInt uiNumBaseViews, |
---|
| 154 | UInt uiInputBitDepth, |
---|
| 155 | UInt uiCodedCamParsPrecision, |
---|
| 156 | UInt uiStartFrameId, |
---|
| 157 | UInt uiNumFrames, |
---|
| 158 | Char* pchCfgFileName, |
---|
| 159 | Char* pchBaseViewNumbers, |
---|
| 160 | Char* pchSynthViewNumbers, |
---|
| 161 | std::vector<Int>* paiSynthViewNumbers, |
---|
| 162 | Int iLog2Precision ); |
---|
| 163 | |
---|
| 164 | Void init ( UInt uiInputBitDepth, |
---|
| 165 | UInt uiStartFrameId, |
---|
| 166 | UInt uiNumFrames, |
---|
| 167 | Char* pchCfgFileName, |
---|
| 168 | Char* pchSynthViewNumbers, |
---|
| 169 | std::vector<Int>* paiSynthViewNumbers, |
---|
| 170 | Int iLog2Precision |
---|
| 171 | ); |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | Void check ( Bool bCheckViewRange, |
---|
| 176 | Bool bCheckFrameRange ); |
---|
| 177 | Void update ( UInt uiFrameId ); |
---|
| 178 | |
---|
| 179 | // miscellaneous functions |
---|
| 180 | |
---|
| 181 | Int synthRelNum2Idx ( Int iRelNum ); |
---|
[608] | 182 | Bool getLeftRightBaseView ( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ); |
---|
[56] | 183 | Int getRelDistLeft ( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ); |
---|
| 184 | UInt getCurFrameId () { return m_iCurrentFrameId; } |
---|
| 185 | static Void convertNumberString ( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec ); |
---|
[608] | 186 | #if H_3D_REN_MAX_DEV_OUT |
---|
| 187 | Double getMaxShiftDeviation () { return m_dMaxShiftDeviation; }; |
---|
| 188 | #endif |
---|
[56] | 189 | |
---|
[1313] | 190 | #if NH_3D_VSO |
---|
[608] | 191 | // SAIT_VSO_EST_A033 |
---|
| 192 | Void setDispCoeff ( UInt uiStartFrameId, Int iViewIdx ); |
---|
| 193 | Double getDispCoeff () { return m_dDispCoeff; } |
---|
[102] | 194 | #endif |
---|
| 195 | |
---|
[56] | 196 | // function for getting parameters and parameter arrays |
---|
| 197 | std::vector<Int>& getBaseViewNumbers () { return m_aiBaseViews; } |
---|
| 198 | std::vector<Int>& getSortedBaseViewNumbers () { return m_aiSortedBaseViews; } |
---|
| 199 | std::vector<Int>& getSynthViewNumbers () { return m_aiSynthViews; } |
---|
| 200 | std::vector<Int>& getRelSynthViewNumbers () { return m_aiRelSynthViewsNum;} |
---|
| 201 | |
---|
| 202 | std::vector<Int>& getBaseId2SortedId () { return m_aiBaseId2SortedId; } |
---|
| 203 | std::vector<Int>& getBaseSortedId2Id () { return m_aiBaseSortedId2Id; } |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | Double*** getBaseViewShiftParameterD() { return m_adBaseViewShiftParameter; } |
---|
| 207 | Int*** getBaseViewShiftParameterI() { return (Int***)m_aiBaseViewShiftParameter; } |
---|
| 208 | |
---|
| 209 | Double**** getSynthViewShiftLUTD () { return m_adSynthViewShiftLUT; } |
---|
| 210 | Double**** getBaseViewShiftLUTD () { return m_adBaseViewShiftLUT; } |
---|
| 211 | Int**** getSynthViewShiftLUTI () { return m_aiSynthViewShiftLUT; } |
---|
| 212 | Int**** getBaseViewShiftLUTI () { return m_aiBaseViewShiftLUT; } |
---|
| 213 | |
---|
| 214 | Bool getVaryingCameraParameters() { return m_bCamParsVaryOverTime; } |
---|
| 215 | UInt getCamParsCodedPrecision () { return m_uiCamParsCodedPrecision; } |
---|
| 216 | Int** getCodedScale () { return m_aaiCodedScale; } |
---|
| 217 | Int** getCodedOffset () { return m_aaiCodedOffset; } |
---|
[655] | 218 | |
---|
| 219 | #if KWU_RC_MADPRED_E0227 |
---|
| 220 | Void xGetZNearZFar ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar ); |
---|
| 221 | Void xGetGeometryData ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ); |
---|
| 222 | #endif |
---|
[56] | 223 | }; |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | template <class T> |
---|
| 228 | Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 ) |
---|
| 229 | { |
---|
| 230 | if( rpt ) |
---|
| 231 | { |
---|
| 232 | for( UInt uiK = 0; uiK < uiSize1; uiK++ ) |
---|
| 233 | { |
---|
| 234 | for( UInt uiL = 0; uiL < uiSize2; uiL++ ) |
---|
| 235 | { |
---|
| 236 | for( UInt uiM = 0; uiM < uiSize3; uiM++ ) |
---|
| 237 | { |
---|
| 238 | delete[] rpt[ uiK ][ uiL ][ uiM ]; |
---|
| 239 | } |
---|
| 240 | delete[] rpt[ uiK ][ uiL ]; |
---|
| 241 | } |
---|
| 242 | delete[] rpt[ uiK ]; |
---|
| 243 | } |
---|
| 244 | delete[] rpt; |
---|
| 245 | } |
---|
| 246 | rpt = NULL; |
---|
| 247 | }; |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | template <class T> |
---|
| 251 | Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2 ) |
---|
| 252 | { |
---|
| 253 | if( rpt ) |
---|
| 254 | { |
---|
| 255 | for( UInt uiK = 0; uiK < uiSize1; uiK++ ) |
---|
| 256 | { |
---|
| 257 | for( UInt uiL = 0; uiL < uiSize2; uiL++ ) |
---|
| 258 | { |
---|
| 259 | delete[] rpt[ uiK ][ uiL ]; |
---|
| 260 | } |
---|
| 261 | delete[] rpt[ uiK ]; |
---|
| 262 | } |
---|
| 263 | delete[] rpt; |
---|
| 264 | } |
---|
| 265 | rpt = NULL; |
---|
| 266 | }; |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | template <class T> |
---|
| 270 | Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize ) |
---|
| 271 | { |
---|
| 272 | if( rpt ) |
---|
| 273 | { |
---|
| 274 | for( UInt uiK = 0; uiK < uiSize; uiK++ ) |
---|
| 275 | { |
---|
| 276 | delete[] rpt[ uiK ]; |
---|
| 277 | } |
---|
| 278 | delete[] rpt; |
---|
| 279 | } |
---|
| 280 | rpt = NULL; |
---|
| 281 | }; |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | #endif // __TAPPCOMCAMPARA__ |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | |
---|