diff --git a/MMVII/include/MMVII_DeclareAllCmd.h b/MMVII/include/MMVII_DeclareAllCmd.h index 3b1a636ec..9a92a4427 100755 --- a/MMVII/include/MMVII_DeclareAllCmd.h +++ b/MMVII/include/MMVII_DeclareAllCmd.h @@ -112,10 +112,11 @@ extern cSpecMMVII_Appli TheSpec_ExportUndistMesIm; extern cSpecMMVII_Appli TheSpecAppliExtractLine; extern cSpecMMVII_Appli TheSpec_CERN_ImportClino; extern cSpecMMVII_Appli TheSpec_MMV2_MesIm_2_MMV1; - extern cSpecMMVII_Appli TheSpec_MergeMesImGCP; - extern cSpecMMVII_Appli TheSpec_ExifData; + +extern cSpecMMVII_Appli TheSpec_PerturbRandomOri; + }; #endif // _MMVII_DeclareAllCmd_H_ diff --git a/MMVII/include/MMVII_PCSens.h b/MMVII/include/MMVII_PCSens.h index 2f6f054aa..54b2dcf3f 100755 --- a/MMVII/include/MMVII_PCSens.h +++ b/MMVII/include/MMVII_PCSens.h @@ -485,6 +485,8 @@ class cSensorCamPC : public cSensorImage const cPixelDomain & PixelDomain() const override; void SetPose(const tPose & aPose); + void SetOrient(const tRotR & anOrient); + void SetCenter(const cPt3dr & aC); bool HasImageAndDepth() const override; // true cPt3dr Ground2ImageAndDepth(const cPt3dr &) const override; @@ -523,6 +525,7 @@ class cSensorCamPC : public cSensorImage // different accessor to the pose const tPose & Pose() const; + const tRotR & Orient() const; const cPt3dr & Center() const; cPt3dr & Center() ; cPt3dr AxeI() const; @@ -568,6 +571,11 @@ class cSensorCamPC : public cSensorImage cPt3dr Vec_L2W(const cPt3dr &) const; ///< Coordinat local of cam to coordinate word for a "vector" cPt3dr Vec_W2L(const cPt3dr &) const; ///< Coordinat word to coordinate local of cam for a "vector" + // Cast to possible heriting class + bool IsSensorCamPC() const override ; + const cSensorCamPC * GetSensorCamPC() const override; + cSensorCamPC * GetSensorCamPC() override; + private : void Bench(); cSensorCamPC(const cSensorCamPC&) = delete; diff --git a/MMVII/include/MMVII_Sensor.h b/MMVII/include/MMVII_Sensor.h index eacae52b8..9aa38a434 100755 --- a/MMVII/include/MMVII_Sensor.h +++ b/MMVII/include/MMVII_Sensor.h @@ -243,6 +243,14 @@ class cSensorImage : public cObj2DelAtEnd, void TransferateCoordSys(const cSensorImage & aSI); ///< Transferat coordinate sys aSI if it has any static const std::string TagCoordSys; + // Cast to possible heriting class + virtual bool IsSensorCamPC() const ; + virtual const cSensorCamPC * GetSensorCamPC() const; + virtual cSensorCamPC * GetSensorCamPC() ; + /// generete a user error + const cSensorCamPC * UserGetSensorCamPC() const; + cSensorCamPC * UserGetSensorCamPC() ; + private : std::string mNameImage; diff --git a/MMVII/include/MMVII_enums.h b/MMVII/include/MMVII_enums.h index bf820790b..8243dbc54 100755 --- a/MMVII/include/MMVII_enums.h +++ b/MMVII/include/MMVII_enums.h @@ -90,6 +90,7 @@ enum class eApF Cloud, ///< Cloud processing CodedTarget, ///< Coded target (generate, match ) Topo, ///< Topo survey + Simul, ///< Simulation of datas NoGui, ///< Will not have a GUI frontend Perso, ///< Personnal eNbVals ///< Tag for number of value diff --git a/MMVII/include/V1VII.h b/MMVII/include/V1VII.h index 2820ad67a..138617744 100755 --- a/MMVII/include/V1VII.h +++ b/MMVII/include/V1VII.h @@ -2,7 +2,8 @@ #define _V1V2_H_ #ifndef MMVII_KEEP_LIBRARY_MMV1 -#define MMVII_KEEP_LIBRARY_MMV1 false +// Maintain it for now, require for converting V1 TiePoints... +#define MMVII_KEEP_LIBRARY_MMV1 true #endif #if (MMVII_KEEP_LIBRARY_MMV1) diff --git a/MMVII/src/Appli/cSpecMMVII_Appli.cpp b/MMVII/src/Appli/cSpecMMVII_Appli.cpp index 423a5e24a..f076c60ed 100755 --- a/MMVII/src/Appli/cSpecMMVII_Appli.cpp +++ b/MMVII/src/Appli/cSpecMMVII_Appli.cpp @@ -258,10 +258,11 @@ std::vector & cSpecMMVII_Appli::InternVecAll() TheVecAll.push_back(&TheSpecAppliExtractLine); TheVecAll.push_back(&TheSpec_CERN_ImportClino); TheVecAll.push_back(&TheSpec_MMV2_MesIm_2_MMV1); - TheVecAll.push_back(&TheSpec_MergeMesImGCP); - TheVecAll.push_back(&TheSpec_ExifData); + TheVecAll.push_back(&TheSpec_PerturbRandomOri); + + std::sort(TheVecAll.begin(),TheVecAll.end(),CmpCmd); } diff --git a/MMVII/src/ImagesBase/FileImages.cpp b/MMVII/src/ImagesBase/FileImages.cpp index 7c813048d..47ed53c96 100644 --- a/MMVII/src/ImagesBase/FileImages.cpp +++ b/MMVII/src/ImagesBase/FileImages.cpp @@ -4,8 +4,10 @@ #include "MMVII_Ptxd.h" #include "cGdalApi.h" -#define MMVII_KEEP_LIBRARY_MMV1 true + + #ifdef MMVII_KEEP_MMV1_IMAGE +#define MMVII_KEEP_LIBRARY_MMV1 true # include "V1VII.h" #endif @@ -25,6 +27,7 @@ namespace MMVII #ifdef MMVII_KEEP_MMV1_IMAGE static GenIm::type_el ToMMV1(eTyNums aV2) { + // StdOut() << "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\n"; switch (aV2) { case eTyNums::eTN_INT1 : return GenIm::int1 ; diff --git a/MMVII/src/MMV1/ExportHomMMV1.cpp b/MMVII/src/MMV1/ExportHomMMV1.cpp index b306101f5..9997e66d3 100755 --- a/MMVII/src/MMV1/ExportHomMMV1.cpp +++ b/MMVII/src/MMV1/ExportHomMMV1.cpp @@ -89,11 +89,13 @@ cInterfImportHom * cInterfImportHom::CreateImportV1(const std::string&aDir,const MMVII_INTERNAL_ERROR("No CreateImportV1 "); return nullptr; } +#endif // MMVII_KEEP_LIBRARY_MMV1 + + cInterfImportHom::~cInterfImportHom() { } -#endif // MMVII_KEEP_LIBRARY_MMV1 diff --git a/MMVII/src/Sensors/SensorBases.cpp b/MMVII/src/Sensors/SensorBases.cpp index 9bb43d3f0..4d9c026f1 100644 --- a/MMVII/src/Sensors/SensorBases.cpp +++ b/MMVII/src/Sensors/SensorBases.cpp @@ -446,6 +446,33 @@ void cSensorImage::TransferateCoordSys(const cSensorImage & aSI) } const std::string cSensorImage::TagCoordSys = "CoordinateSys"; +bool cSensorImage::IsSensorCamPC() const { return false; } +const cSensorCamPC * cSensorImage::GetSensorCamPC() const +{ + MMVII_INTERNAL_ERROR("impossible required cast to cSensorCamPC"); + return nullptr; +} +cSensorCamPC * cSensorImage::GetSensorCamPC() +{ + MMVII_INTERNAL_ERROR("impossible required cast to cSensorCamPC"); + return nullptr; +} + +cSensorCamPC * cSensorImage::UserGetSensorCamPC() +{ + if (!IsSensorCamPC()) + { + MMVII_UnclasseUsEr("Camera " + NameImage() + " was not central perspective"); + } + return GetSensorCamPC(); +} + + +const cSensorCamPC * cSensorImage::UserGetSensorCamPC() const +{ + return const_cast(this)->UserGetSensorCamPC(); +} + /* ******************************************************* */ diff --git a/MMVII/src/Sensors/cSensorCamPC.cpp b/MMVII/src/Sensors/cSensorCamPC.cpp index 03ddd4695..15d263a5f 100644 --- a/MMVII/src/Sensors/cSensorCamPC.cpp +++ b/MMVII/src/Sensors/cSensorCamPC.cpp @@ -41,6 +41,7 @@ const cPt3dr & cPoseWithUK::Tr() const {return mPose.Tr();} cPt3dr & cPoseWithUK::Tr() {return mPose.Tr();} + cPt3dr & cPoseWithUK::Omega() {return mOmega;} const cPt3dr & cPoseWithUK::Omega() const {return mOmega;} @@ -156,7 +157,17 @@ void cSensorCamPC::SetPose(const tPose & aPose) mPose_WU.SetPose(aPose); } + // void SetCenter(const cPt3dr & aC); +void cSensorCamPC::SetOrient(const tRotR & anOrient) +{ + SetPose(tPose(Center(),anOrient)); +} + +void cSensorCamPC::SetCenter(const cPt3dr & aC) +{ + SetPose(tPose(aC,Orient())); +} #if (1) @@ -307,7 +318,9 @@ const cPixelDomain & cSensorCamPC::PixelDomain() const cPerspCamIntrCalib * cSensorCamPC::InternalCalib() const {return mInternalCalib;} -const cPt3dr & cSensorCamPC::Center() const {return mPose_WU.Tr();} +const cPt3dr & cSensorCamPC::Center() const {return mPose_WU.Tr();} +const tRotR & cSensorCamPC::Orient() const {return mPose_WU.Pose().Rot();} + const cPt3dr & cSensorCamPC::Omega() const {return mPose_WU.Omega();} cPt3dr & cSensorCamPC::Center() {return mPose_WU.Tr();} cPt3dr & cSensorCamPC::Omega() {return mPose_WU.Omega();} @@ -584,6 +597,13 @@ void cSensorCamPC::BenchOneCalib(cPerspCamIntrCalib * aCalib) aCam.Bench(); } + // ================= Cast =================== + +bool cSensorCamPC::IsSensorCamPC() const { return true; } +const cSensorCamPC * cSensorCamPC::GetSensorCamPC() const { return this; } +cSensorCamPC * cSensorCamPC::GetSensorCamPC() { return this; } + + }; // MMVII diff --git a/MMVII/src/Serial/ElemStrToVal.cpp b/MMVII/src/Serial/ElemStrToVal.cpp index b087646da..d8a0a7c0b 100644 --- a/MMVII/src/Serial/ElemStrToVal.cpp +++ b/MMVII/src/Serial/ElemStrToVal.cpp @@ -271,6 +271,7 @@ template<> cE2Str::tMapE2Str cE2Str::mE2S {eApF::Cloud,"Cloud"}, {eApF::CodedTarget,"CodedTarget"}, {eApF::Topo,"Topo"}, + {eApF::Simul,"Simul"}, {eApF::NoGui,"NoGui"}, {eApF::Perso,"Perso"} }; diff --git a/MMVII/src/Simul/PerturbRandOrient.cpp b/MMVII/src/Simul/PerturbRandOrient.cpp new file mode 100644 index 000000000..8bfb0f2bf --- /dev/null +++ b/MMVII/src/Simul/PerturbRandOrient.cpp @@ -0,0 +1,188 @@ +#include "MMVII_PCSens.h" +#include "MMVII_Interpolators.h" + +/** + \file PerturbRandOrient.cpp + + \brief file for generating random permutation +*/ + + +namespace MMVII +{ + + /* ********************************************************** */ + /* */ + /* cAppli_PerturbRandomOri */ + /* */ + /* ********************************************************** */ + +class cAppli_PerturbRandomOri : public cMMVII_Appli +{ + public : + typedef cIm2D tIm; + + cAppli_PerturbRandomOri(const std::vector & aVArgs,const cSpecMMVII_Appli & aSpec); + int Exe() override; + cCollecSpecArg2007 & ArgObl(cCollecSpecArg2007 & anArgObl) override ; + cCollecSpecArg2007 & ArgOpt(cCollecSpecArg2007 & anArgOpt) override ; + + std::vector Samples() const override; + + void TestPly(); + private : + + cPhotogrammetricProject mPhProj; + std::string mSpecIm; + tREAL8 mRandOri; + tREAL8 mRandC; + std::string mPlyTest; + cTriangulation3D * mTri; + std::vector mVSI; + std::vector mVIm; + +}; + +cAppli_PerturbRandomOri::cAppli_PerturbRandomOri(const std::vector & aVArgs,const cSpecMMVII_Appli & aSpec) : + cMMVII_Appli (aVArgs,aSpec), + mPhProj (*this), + mTri (nullptr) +{ +} + +cCollecSpecArg2007 & cAppli_PerturbRandomOri::ArgObl(cCollecSpecArg2007 & anArgObl) +{ + return anArgObl + << Arg2007(mSpecIm ,"Name of Input File",{{eTA2007::MPatFile,"0"},{eTA2007::FileDirProj}}) + << mPhProj.DPOrient().ArgDirInMand() + << mPhProj.DPOrient().ArgDirOutMand() + ; +} + +cCollecSpecArg2007 & cAppli_PerturbRandomOri::ArgOpt(cCollecSpecArg2007 & anArgObl) +{ + + return anArgObl + << AOpt2007(mRandOri,"RandOri","Random perturbation on orientations") + << AOpt2007(mRandC ,"RandC" ,"Random perturbation on center") + << AOpt2007(mPlyTest ,"PlyTest" ,"Test ply (temporary)") + ; +} + +// template void cTriangulation3D::PlyInit(const std::string & aNameFile) + +void cAppli_PerturbRandomOri::TestPly() +{ + if (! mTri) + return; + + if (mVIm.empty()) + { + for (auto aSI : mVSI) + { + mVIm.push_back(tIm::FromFile(aSI->NameImage())); + } + } + + cStdStatRes aStatRes; + cCubicInterpolator aInterpol(-0.5); + + for (size_t aKP=0 ; aKPNbPts() ; aKP++) + { + cPt3df aPF = mTri->KthPts(aKP); + cPt3dr aPGround(aPF.x(),aPF.y(),aPF.z()); + + cComputeStdDev aStdDev; + int aNbOk=0; + for (size_t aKIm=0 ; aKImIsVisible(aPGround)) + { + cDataIm2D & aDIm = mVIm[aKIm].DIm(); + cPt2dr aPIm = mVSI[aKIm]->Ground2Image(aPGround); + if (aDIm.InsideInterpolator(aInterpol,aPIm)) + { + aStdDev.Add(aDIm.GetValueInterpol(aInterpol,aPIm)); + aNbOk++; + } + } + } + if (aNbOk>=2) + { + tREAL8 aDev = aStdDev.StdDev(1e-5); + aStatRes.Add( (aDev *aNbOk) / (aNbOk-1)); + } + } + StdOut() << " Avg=" << aStatRes.Avg() + << " Med=" << aStatRes.ErrAtProp(0.5) + << " P80=" << aStatRes.ErrAtProp(0.8) + << " P95=" << aStatRes.ErrAtProp(0.95) + << "\n"; +} + +int cAppli_PerturbRandomOri::Exe() +{ + mPhProj.FinishInit(); + + if (IsInit(&mPlyTest)) + { + mTri = new cTriangulation3D(mPlyTest); + StdOut() << "TRIII, NbPts=" << mTri->NbPts() << " NbF=" << mTri->NbFace() << "\n"; + } + + + for (const auto & aNameIm : VectMainSet(0)) + { + cSensorImage* aSI = mPhProj.ReadSensor(aNameIm,true,false); + mVSI.push_back(aSI); + } + + TestPly(); + + for (auto aSI : mVSI) + { + if (IsInit(&mRandOri)) + { + cSensorCamPC * aCamPC = aSI->UserGetSensorCamPC(); + aCamPC->SetOrient( aCamPC->Orient() * tRotR::RandomRot(mRandOri) ); + } + if (IsInit(&mRandC)) + { + cSensorCamPC * aCamPC = aSI->UserGetSensorCamPC(); + aCamPC->SetCenter(aCamPC->Center() + cPt3dr::PRandC() * mRandC); + } + + mPhProj.SaveSensor(*aSI); + } + TestPly(); + + delete mTri; + return EXIT_SUCCESS; +} + + +std::vector cAppli_PerturbRandomOri::Samples() const +{ + return {"NO SAMPLES FOR NOW"}; +} + + + +tMMVII_UnikPApli Alloc_PerturbRandomOri(const std::vector & aVArgs,const cSpecMMVII_Appli & aSpec) +{ + return tMMVII_UnikPApli(new cAppli_PerturbRandomOri(aVArgs,aSpec)); +} + +cSpecMMVII_Appli TheSpec_PerturbRandomOri +( + "SimulOriPerturbRandom", + Alloc_PerturbRandomOri, + "Perturbate random de orientation (for simulations)", + {eApF::Ori,eApF::Simul}, + {eApDT::Ori}, + {eApDT::Ori}, + __FILE__ +); + +}; // MMVII +