Changeset 608 in 3DVCSoftware for trunk/source/Lib/TAppCommon
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- Location:
- trunk/source/Lib/TAppCommon
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TAppCommon/TAppComCamPara.cpp
r296 r608 49 49 #include <functional> 50 50 #include <string> 51 51 #if H_3D 52 52 53 53 … … 58 58 AOF( radShiftParams == NULL && raiShiftParams == NULL && radLUT == NULL && raiLUT == NULL ); 59 59 60 uiNumberSourceViews = Max(1, uiNumberSourceViews );61 uiNumberTargetViews = Max(1, uiNumberTargetViews );60 uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews ); 61 uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews ); 62 62 63 63 radShiftParams = new Double** [ uiNumberSourceViews ]; … … 611 611 } 612 612 613 614 613 Void 615 614 TAppComCamPara::xGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated ) 616 615 { 617 616 UInt uiFoundLine = -1; 617 #if H_3D_FIX_REN_WARNING 618 if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) && xIsIn( m_aiSortedBaseViews, iView )) 619 #else 618 620 if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) ) 621 #endif 619 622 { 620 623 AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 ); … … 632 635 Int iDummy; 633 636 637 #if H_3D_FIX_REN_WARNING 638 if( !xGetLeftRightView( iView, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy ) || 639 #else 634 640 if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) || 641 #endif 635 642 xGetCameraDataRow( iLeftView, uiFrame, uiLeftViewLine ) || 636 643 xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine ) 637 644 ) 638 645 { 646 #if H_3D_FIX_REN_WARNING 647 std::cerr << "No left or no right base view next to view " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; 648 #else 639 649 std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl; 650 #endif 640 651 AOT(true); 641 652 exit( EXIT_FAILURE ); … … 841 852 Int iLog2DivLuma = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision; AOF( iLog2DivLuma > 0 ); 842 853 Int iLog2DivChroma = iLog2DivLuma + 1; 854 843 855 Double dMaxDispDev = 0.0; 844 856 Double dMaxRndDispDvL = 0.0; 845 857 Double dMaxRndDispDvC = 0.0; 858 846 859 for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ ) 847 860 { … … 892 905 893 906 // maximum deviation 894 dMaxDispDev = Max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); 895 dMaxRndDispDvL = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); 896 dMaxRndDispDvC = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); 907 #if H_3D_REN_MAX_DEV_OUT 908 m_dMaxShiftDeviation = std::max( m_dMaxShiftDeviation, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) / Double( 1 << m_iLog2Precision ) ); 909 #endif 910 dMaxDispDev = std::max( dMaxDispDev, fabs( Double( (Int) iTestScale ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) ); 911 dMaxRndDispDvL = std::max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma ) - dShiftLuma ) ); 912 dMaxRndDispDvC = std::max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) ); 897 913 } 898 914 … … 965 981 //--- determine (virtual) camera parameter shift between view order index 1 and base view (view order index 0) --- 966 982 Double dCamPosShift, dPicPosShift; 967 Int iMinVOI = (1<<30);968 983 Int iMinAbsVOI = (1<<30); 969 984 Int iMinAbsVOIId = 0; … … 973 988 if( iAbsVOI < iMinAbsVOI ) 974 989 { 975 iMinVOI = m_aiViewOrderIndex[ iBaseId ];976 990 iMinAbsVOI = iAbsVOI; 977 991 iMinAbsVOIId = iBaseId; … … 980 994 AOF( iMinAbsVOIId != 0 && iMinAbsVOI != 0 ); 981 995 xGetCameraShifts( 0, iMinAbsVOIId, m_uiFirstFrameId, dCamPosShift, dPicPosShift ); 982 Double dCamPosShiftVOI01 = dCamPosShift / Double( iMinVOI );983 996 984 997 //--- determine maximum absolute camera position shift, precision, and base scale --- … … 991 1004 dCamPosShift = ( dCamPosShift < 0.0 ? -dCamPosShift : dCamPosShift ); 992 1005 dMaxAbsCamPosShift = ( dCamPosShift > dMaxAbsCamPosShift ? dCamPosShift : dMaxAbsCamPosShift ); 993 }994 }995 Int iPrecision = 0;996 #if 0 // enabling this lines might be reasonable, but produces different results for the 2 view and 3 view test cases997 Double dEpsilon = 1e-15;998 Double dAbsCamPosShiftVOI01 = ( dCamPosShiftVOI01 < 0.0 ? -dCamPosShiftVOI01 : dCamPosShiftVOI01 );999 Double dShiftRatio = dMaxAbsCamPosShift / dAbsCamPosShiftVOI01 - dEpsilon;1000 for( ; (Double)( 1 << iPrecision ) < dShiftRatio; iPrecision++ );1001 #endif1002 Int iPrecShift = iPrecision + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2;1003 AOF( iPrecShift < PDM_INTERNAL_CALC_BIT_DEPTH );1004 Int iScaleVOI01 = 1 << iPrecShift;1005 m_iPdmPrecision = iPrecision;1006 1007 //--- loop over target views ---1008 for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ )1009 {1010 // set scale and offset parameters for other views1011 for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ )1012 {1013 xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift );1014 Double dScale = Double( iScaleVOI01 ) * dCamPosShiftVOI01 / dCamPosShift;1015 Int iDiv = m_aiViewOrderIndex[ iTargetId ] - m_aiViewOrderIndex[ iBaseId ];1016 Int iAdd = ( iDiv > 0 ? iDiv / 2 : -iDiv / 2 );1017 Int iScalePred = ( iScaleVOI01 + iAdd ) / iDiv;1018 Double dFactor = dScale / (Double)iScalePred * pow( 2.0, PDM_LOG4_SCALE_DENOMINATOR );1019 Int iNominator = (Int)floor( dFactor + .5 );1020 Int iNomDelta = iNominator - ( 1 << PDM_LOG4_SCALE_DENOMINATOR );1021 Int iScale = Int( ( (Int64)iNominator * (Int64)iScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR );1022 Double dOffset = -dPicPosShift * Double( iScale ) * pow( 2.0, 2 - PDM_OFFSET_SHIFT );1023 Int iOffset = (Int)floor( dOffset + .5 );1024 1025 m_aaiPdmScaleNomDelta [ iTargetId ][ iBaseId ] = iNomDelta;1026 m_aaiPdmOffset [ iTargetId ][ iBaseId ] = iOffset;1027 1006 } 1028 1007 } … … 1050 1029 m_aaiScaleAndOffsetSet = 0; 1051 1030 1052 m_iPdmPrecision = 0;1053 m_aaiPdmScaleNomDelta = 0;1054 m_aaiPdmOffset = 0;1055 1056 1031 m_adBaseViewShiftParameter = 0; 1057 1032 m_aiBaseViewShiftParameter = 0; … … 1067 1042 m_bCamParsCodedPrecSet = false; 1068 1043 1044 #if H_3D_REN_MAX_DEV_OUT 1045 m_dMaxShiftDeviation = -1; 1046 #endif 1069 1047 1070 1048 } … … 1078 1056 xDeleteArray( m_aiBaseViewShiftLUT, m_iNumberOfBaseViews, m_iNumberOfBaseViews, 2 ); 1079 1057 1080 xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews));1081 xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews));1082 xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 );1083 xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 );1058 xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); 1059 xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews)); 1060 xDeleteArray( m_adSynthViewShiftLUT, m_iNumberOfBaseViews, std::max((Int) 1 ,m_iNumberOfSynthViews), 2 ); 1061 xDeleteArray( m_aiSynthViewShiftLUT, m_iNumberOfBaseViews, std::max( (Int)1 ,m_iNumberOfSynthViews), 2 ); 1084 1062 1085 1063 xDeleteArray( m_aaiCodedScale, m_iNumberOfBaseViews ); … … 1087 1065 xDeleteArray( m_aaiScaleAndOffsetSet, m_iNumberOfBaseViews ); 1088 1066 1089 xDeleteArray( m_aaiPdmScaleNomDelta, m_iNumberOfBaseViews );1090 xDeleteArray( m_aaiPdmOffset, m_iNumberOfBaseViews );1091 1067 } 1092 1068 … … 1106 1082 1107 1083 Int iViewOrderIdx = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] ); 1108 iMinViewOrderIdx = Min( iViewOrderIdx, iMinViewOrderIdx );1084 iMinViewOrderIdx = std::min( iViewOrderIdx, iMinViewOrderIdx ); 1109 1085 1110 1086 aiViewOrderIdx .push_back( iViewOrderIdx ); … … 1121 1097 m_aiBaseId2SortedId.push_back( iCurBaseView ); 1122 1098 m_aiBaseSortedId2Id.push_back( iCurBaseView ); 1123 1124 1099 } 1125 1100 … … 1198 1173 if( m_aiViewsInCfgFile.size() < 2 ) 1199 1174 { 1200 std::cerr << "Failed reading config file" << std::endl;1175 std::cerr << "Failed reading config file" << std::endl; 1201 1176 std::cerr << "At least two views must be given" << std::endl; 1202 1177 exit( EXIT_FAILURE ); … … 1332 1307 xInit2dArray ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiScaleAndOffsetSet, 0 ); 1333 1308 1334 xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmScaleNomDelta );1335 xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews, m_aaiPdmOffset );1336 1337 //===== init disparity to virtual depth conversion parameters =====1338 xSetPdmConversionParams();1339 1340 1309 //===== init arrays for first frame ===== 1341 1310 xSetShiftParametersAndLUT( m_uiFirstFrameId ); … … 1369 1338 else 1370 1339 { 1371 for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) 1372 { 1373 Bool bInterpolatedCur; 1374 xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); 1375 xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); 1376 1377 if( bInterpolatedCur ) 1340 for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ ) 1378 1341 { 1379 std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; 1380 exit( EXIT_FAILURE ); 1342 Bool bInterpolatedCur; 1343 xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur ); 1344 xGetZNearZFar ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy ); 1345 1346 if( bInterpolatedCur ) 1347 { 1348 std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. " << std::endl; 1349 exit( EXIT_FAILURE ); 1350 } 1381 1351 } 1382 1352 } 1383 1384 } 1385 } 1386 1353 } 1354 #if H_3D_FIX_REN_WARNING 1355 Bool bIgnoreFirst = true; 1356 for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) 1357 { 1358 if ( xIsIn(m_aiViewsInCfgFile, m_aiSynthViews[ uiERView ] ) ) 1359 { 1360 if ( bIgnoreFirst ) 1361 { 1362 std::cout << "Ignoring CameraParameterFile entries for virtual view(s): " ; 1363 //GT: Integer precision virtual view camera parameters are always interpolated from coded views camera parameters. 1364 bIgnoreFirst = false; 1365 } 1366 std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; 1367 } 1368 } 1369 if ( !bIgnoreFirst ) 1370 { 1371 std::cout << std::endl; 1372 } 1373 #endif 1374 1375 Bool bInterpolateFirst = true; 1376 Bool bAnyInterpolated = false; 1387 1377 for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ ) 1388 1378 { … … 1394 1384 bInterpolated |= bInterpolatedCur; 1395 1385 } 1386 1396 1387 if( bInterpolated ) 1397 1388 { 1398 std::cout << "Interpolating Camera Parameters for View " << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << std::endl; 1399 } 1400 } 1389 bAnyInterpolated = true; 1390 if ( bInterpolateFirst ) 1391 { 1392 #if H_3D_FIX_REN_WARNING 1393 std::cout << "Interpolating camera parameters for virtual view(s): " ; 1394 #else 1395 std::cout << "Interpolating Camera Parameters for View(s) " ; 1396 #endif 1397 bInterpolateFirst = false; 1398 } 1399 std::cout << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << " " ; 1400 } 1401 } 1402 if ( bAnyInterpolated ) 1403 std::cout << std::endl; 1401 1404 } 1402 1405 … … 1433 1436 } 1434 1437 1435 #if SAIT_VSO_EST_A00331436 Void 1437 TAppComCamPara:: xSetDispCoeff( UInt uiFrameId, Int iViewIdx )1438 #if H_3D_VSO 1439 Void 1440 TAppComCamPara::setDispCoeff( UInt uiFrameId, Int iViewIdx ) 1438 1441 { 1439 1442 UInt uiFrame = m_uiFirstFrameId + uiFrameId; … … 1453 1456 xGetZNearZFar ( iSourceViewNum, uiFrame, dZN1, dZF1 ); 1454 1457 1455 dBaseLine = ( Max( dPos[0], Max( dPos[1], dPos[2] ) ) - Min( dPos[0], Min( dPos[1], dPos[2] ) ) ) / 2.0;1458 dBaseLine = ( std::max( dPos[0], std::max( dPos[1], dPos[2] ) ) - std::min( dPos[0], std::min( dPos[1], dPos[2] ) ) ) / 2.0; 1456 1459 } 1457 1460 else if( m_iNumberOfBaseViews == 2 ) … … 1465 1468 dBaseLine = dPos[0] - dPos[1]; 1466 1469 } 1467 1468 1470 1469 1471 m_dDispCoeff = fabs( dFL1 * ( dBaseLine / 2.0 ) / 255.0 * ( 1.0/dZN1 - 1.0/dZF1 ) ); … … 1495 1497 return bExist; 1496 1498 } 1499 1500 #if H_3D_FIX_REN_WARNING 1501 Bool 1502 TAppComCamPara::xIsIn( std::vector<Int>& rVec, Int iElem) 1503 { 1504 Bool bFound = false; 1505 for (Int idx = 0; idx < rVec.size() && !bFound; idx++) 1506 { 1507 bFound = bFound || rVec[idx] == iElem; 1508 } 1509 return bFound; 1510 } 1511 #endif 1497 1512 1498 1513 Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ) … … 1510 1525 return xGetViewId(m_aiRelSynthViewsNum, iRelNum ); 1511 1526 } 1527 #endif -
trunk/source/Lib/TAppCommon/TAppComCamPara.h
r296 r608 66 66 Bool m_bSetupFromCoded; ///< setup from coded parameter file 67 67 Bool m_bCamParsCodedPrecSet; ///< Coded Cam Para precision set for current frame; 68 69 #if SAIT_VSO_EST_A0033 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 70 73 Double m_dDispCoeff; 71 #endif72 74 73 75 // view lists … … 90 92 Int** m_aaiScaleAndOffsetSet; ///< array indicating whether scale and offset have been set 91 93 92 // parameters for virtual depth map generation93 Int m_iPdmPrecision; ///< additional precision for disparity - virtual depth conversion94 Int** m_aaiPdmScaleNomDelta; ///< [TargetView][RefView] delta for nominator of scale factor95 Int** m_aaiPdmOffset; ///< [TargetView][RefView] offset parameter96 97 94 // scale and offset parameters 98 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 … … 132 129 Void xSetupBaseViewsFromCoded (); 133 130 Void xSetupBaseViews ( Char* pchBaseViewNumbers, UInt uiNumBaseViews ); 131 #if H_3D_FIX_REN_WARNING 132 Bool xIsIn ( std::vector<Int>& rVec, Int iNumber); 133 #endif 134 134 135 135 136 // functions for getting and setting scales and offsets … … 182 183 183 184 Int synthRelNum2Idx ( Int iRelNum ); 184 Bool getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView );185 Bool getLeftRightBaseView ( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView ); 185 186 Int getRelDistLeft ( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx ); 186 187 UInt getCurFrameId () { return m_iCurrentFrameId; } 187 188 static Void convertNumberString ( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec ); 188 189 #if SAIT_VSO_EST_A0033 190 Void xSetDispCoeff( UInt uiStartFrameId, Int iViewIdx ); 191 Double getDispCoeff() { return m_dDispCoeff; } 189 #if H_3D_REN_MAX_DEV_OUT 190 Double getMaxShiftDeviation () { return m_dMaxShiftDeviation; }; 191 #endif 192 193 #if H_3D_VSO 194 // SAIT_VSO_EST_A033 195 Void setDispCoeff ( UInt uiStartFrameId, Int iViewIdx ); 196 Double getDispCoeff () { return m_dDispCoeff; } 192 197 #endif 193 198 … … 215 220 Int** getCodedScale () { return m_aaiCodedScale; } 216 221 Int** getCodedOffset () { return m_aaiCodedOffset; } 217 218 // parameters for virtual depth map generation 219 Int getPdmPrecision () { return m_iPdmPrecision; } 220 Int** getPdmScaleNomDelta () { return m_aaiPdmScaleNomDelta; } 221 Int** getPdmOffset () { return m_aaiPdmOffset; } 222 }; 223 224 222 }; 225 223 226 224 -
trunk/source/Lib/TAppCommon/program_options_lite.cpp
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 39 39 #include <map> 40 40 #include "program_options_lite.h" 41 41 #include "../TLibCommon/TypeDef.h" 42 42 using namespace std; 43 43 … … 146 146 for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++) 147 147 { 148 #if H_MV 149 if ( (*it)->opt->opt_duplicate ) continue; 150 #endif 148 151 ostringstream line(ios_base::out); 149 152 doHelpOpt(line, **it, pad_short); … … 161 164 for(Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++) 162 165 { 166 #if H_MV 167 if ( (*it)->opt->opt_duplicate ) continue; 168 #endif 163 169 ostringstream line(ios_base::out); 164 170 line << " "; … … 192 198 newline_pos++; 193 199 line << opt_desc.substr(cur_pos, newline_pos - cur_pos); 194 cur_pos = newline_pos = newline_pos;200 cur_pos = newline_pos; 195 201 continue; 196 202 } -
trunk/source/Lib/TAppCommon/program_options_lite.h
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 34 34 #include <sstream> 35 35 #include <string> 36 #include <vector>37 36 #include <list> 38 37 #include <map> 39 #include <stdlib.h> 38 #include "../TLibCommon/TypeDef.h" 39 40 #if H_MV 41 #include <vector> 40 42 #include <errno.h> 41 43 #include <cstring> 42 #include <math.h>43 44 44 45 #ifdef WIN32 45 46 #define strdup _strdup 46 47 #endif 47 48 #endif 48 49 //! \ingroup TAppCommon 49 50 //! \{ … … 56 57 struct Options; 57 58 59 struct ParseFailure : public std::exception 60 { 61 ParseFailure(std::string arg0, std::string val0) throw() 62 : arg(arg0), val(val0) 63 {} 64 65 ~ParseFailure() throw() {}; 66 67 std::string arg; 68 std::string val; 69 70 const char* what() const throw() { return "Option Parse Failure"; } 71 }; 72 58 73 void doHelp(std::ostream& out, Options& opts, unsigned columns = 80); 59 74 unsigned parseGNU(Options& opts, unsigned argc, const char* argv[]); … … 71 86 struct OptionBase 72 87 { 88 #if H_MV 89 OptionBase(const std::string& name, const std::string& desc, bool duplicate = false) 90 : opt_string(name), opt_desc(desc), opt_duplicate(duplicate) 91 #else 73 92 OptionBase(const std::string& name, const std::string& desc) 74 93 : opt_string(name), opt_desc(desc) 94 #endif 75 95 {}; 76 96 … … 84 104 std::string opt_string; 85 105 std::string opt_desc; 106 #if H_MV 107 bool opt_duplicate; 108 #endif 86 109 }; 87 110 … … 90 113 struct Option : public OptionBase 91 114 { 115 #if H_MV 116 Option(const std::string& name, T& storage, T default_val, const std::string& desc, bool duplicate = false) 117 : OptionBase(name, desc, duplicate), opt_storage(storage), opt_default_val(default_val) 118 #else 92 119 Option(const std::string& name, T& storage, T default_val, const std::string& desc) 93 120 : OptionBase(name, desc), opt_storage(storage), opt_default_val(default_val) 121 #endif 94 122 {} 95 123 … … 111 139 { 112 140 std::istringstream arg_ss (arg,std::istringstream::in); 113 arg_ss >> opt_storage; 141 arg_ss.exceptions(std::ios::failbit); 142 try 143 { 144 arg_ss >> opt_storage; 145 } 146 catch (...) 147 { 148 throw ParseFailure(opt_string, arg); 149 } 114 150 } 115 151 … … 122 158 opt_storage = arg; 123 159 } 124 160 161 #if H_MV 125 162 template<> 126 163 inline void … … 258 295 } 259 296 } 260 297 #endif 261 298 /** Option class for argument handling using a user provided function */ 262 299 struct OptionFunc : public OptionBase … … 333 370 } 334 371 372 #if H_MV 335 373 template<typename T> 336 374 OptionSpecific& … … 338 376 { 339 377 std::string cNameBuffer; 340 std::string cDesc riptionBuffer;378 std::string cDescBuffer; 341 379 342 380 cNameBuffer .resize( name.size() + 10 ); 343 cDesc riptionBuffer.resize( desc.size() + 10 );381 cDescBuffer.resize( desc.size() + 10 ); 344 382 345 383 storage.resize(uiMaxNum); 346 384 for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ ) 347 385 { 386 Bool duplicate = (uiK != 0); 348 387 // isn't there are sprintf function for string?? 349 388 sprintf((char*) cNameBuffer.c_str() ,name.c_str(),uiK,uiK); 350 sprintf((char*) cDescriptionBuffer.c_str(),desc.c_str(),uiK,uiK); 351 352 parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescriptionBuffer )); 389 390 if ( !duplicate ) 391 { 392 sprintf((char*) cDescBuffer.c_str(),desc.c_str(),uiK,uiK); 393 } 394 395 cNameBuffer.resize( std::strlen(cNameBuffer.c_str()) ); 396 cDescBuffer.resize( std::strlen(cDescBuffer.c_str()) ); 397 398 399 parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescBuffer, duplicate )); 353 400 } 354 401 355 402 return *this; 356 403 } 357 404 #endif 358 405 /** 359 406 * Add option described by name to the parent Options list,
Note: See TracChangeset for help on using the changeset viewer.