@@ -6,7 +6,46 @@ namespace MMVII
66{
77
88
9+ class cMerged_MultipleLines
10+ {
11+ public :
12+ typedef std::vector<cOneLineAntiParal> tContLAP;
13+ typedef std::map<std::string,tContLAP> tMapOf1L;
14+
15+ void AddLAP (const cLinesAntiParal1Im &);
16+ const std::map<std::string,tMapOf1L>& LinesAP () const ;
17+
18+ private :
19+
20+ // mMapL[NameLine][NameIm]
21+ std::map<std::string,tMapOf1L> mLinesAP ;
22+ std::map<std::string,std::string> mNamesCalib ;
23+ };
24+
25+ void cMerged_MultipleLines::AddLAP (const cLinesAntiParal1Im & aSetLAP)
26+ {
27+ // Check coherence in calibration folders
28+ {
29+ std::string & aNameCal = mNamesCalib [aSetLAP.mNameIm ];
30+ if (aNameCal==" " )
31+ {
32+ aNameCal = aSetLAP.mDirCalib ;
33+ }
34+ else
35+ {
36+ MMVII_INTERNAL_ASSERT_always (aNameCal == aSetLAP.mDirCalib ," Multiple Caliv in cMerged_MultipleLines" );
37+ }
38+ }
939
40+ //
41+ for (const auto & aLAP : aSetLAP.mLines )
42+ {
43+ mLinesAP [aLAP.NameLine ()][aLAP.mNameIm ].push_back (aLAP); // std::string aNameLine;
44+ }
45+ }
46+
47+ const std::map<std::string,typename cMerged_MultipleLines::tMapOf1L>&
48+ cMerged_MultipleLines::LinesAP () const {return mLinesAP ;}
1049
1150
1251/* * Store data one line 2d->3d, essentially data */
@@ -41,7 +80,8 @@ class cOneData_L23 : public cMemCheck
4180class cCam2_Line_2Dto3D : public cMemCheck
4281{
4382 public :
44- cCam2_Line_2Dto3D (const std::vector<cSensorCamPC *> & aVCam,cPhotogrammetricProject *);
83+
84+ static std::vector<cCam2_Line_2Dto3D*> AllocV (const std::vector<cSensorCamPC *> &,const cPhotogrammetricProject &);
4585
4686 const tSegComp3dr & Seg3d () const ; // < Accessor
4787 const std::string & NameLine () const ; // < Accessor
@@ -51,6 +91,9 @@ class cCam2_Line_2Dto3D : public cMemCheck
5191 cPt3dr PtOfWeight (const tREAL8 aWeight);
5292
5393 private :
94+ cCam2_Line_2Dto3D (const std::vector<cSensorCamPC *> & aVCam,const std::string & aNameLine,const cMerged_MultipleLines::tMapOf1L & );
95+
96+
5497 cCam2_Line_2Dto3D (const cCam2_Line_2Dto3D&) = delete ;
5598 void AssertSeg3dIsInit () const ;
5699
@@ -68,7 +111,7 @@ class cUK_Line3D_4BA : public cObjWithUnkowns<tREAL8>
68111 public :
69112 friend cMMVII_BundleAdj;
70113 // < constructor,
71- cUK_Line3D_4BA (const std::vector<cSensorCamPC *> & aVCam,cPhotogrammetricProject *,cMMVII_BundleAdj *,tREAL8 aSigmaIm,int aNbPts);
114+ cUK_Line3D_4BA (cCam2_Line_2Dto3D *,cMMVII_BundleAdj *,tREAL8 aSigmaIm,int aNbPts);
72115 ~cUK_Line3D_4BA ();
73116
74117 void AddEquation ();
@@ -151,22 +194,30 @@ cWeightAv<tREAL8,tREAL8> & cOneData_L23::AvgResidual()
151194/* */
152195/* *********************************************************** */
153196
154- cCam2_Line_2Dto3D::cCam2_Line_2Dto3D (const std::vector<cSensorCamPC *> & aVCam,cPhotogrammetricProject * aPhProj) :
197+
198+ cCam2_Line_2Dto3D::cCam2_Line_2Dto3D
199+ (
200+ const std::vector<cSensorCamPC *> & aVCam,
201+ const std::string & aNameLine,
202+ const cMerged_MultipleLines::tMapOf1L & aMapOf1L
203+ ) :
155204 mSeg3d (cPt3dr(0 ,0 ,0 ),cPt3dr(1 ,1 ,1 )),
156- mSeg3dIsInit (false )
205+ mSeg3dIsInit (false ),
206+ mNameLine (aNameLine)
157207{
158208 std::vector<cPlane3D> aVPlaneOk;
159209
160210 for (size_t aKCam=0 ; aKCam<aVCam.size () ; aKCam++)
161211 {
162212 const auto & aCam = aVCam.at (aKCam);
163- if (aCam != nullptr )
164- {
213+ if (aCam != nullptr )
214+ {
165215 const std::string & aNameIm = aCam->NameImage ();
166- if (aPhProj->HasFileLines (aNameIm))
216+ const auto & anIter = aMapOf1L.find (aNameIm);
217+
218+ if (anIter != aMapOf1L.end ())
167219 {
168- cLinesAntiParal1Im aSetL = aPhProj->ReadLines (aNameIm);
169- const std::vector<cOneLineAntiParal> & aVL = aSetL.mLines ;
220+ const cMerged_MultipleLines::tContLAP & aVL = anIter->second ;
170221
171222 // At this step we dont handle multiple lines
172223 if (aVL.size ()==1 )
@@ -183,7 +234,6 @@ cCam2_Line_2Dto3D::cCam2_Line_2Dto3D(const std::vector<cSensorCamPC *> & aVCam,c
183234 mSeg3dIsInit = true ;
184235 mSeg3d = tSegComp3dr (cPlane3D::InterPlane (aVPlaneOk));
185236 cBoundVals<tREAL8> aIntervAbsc;
186- mNameLine = aPhProj-> DPGndPt2D ().DirIn ();
187237
188238 for (auto & aData : mDatas_L23 )
189239 {
@@ -206,6 +256,27 @@ cCam2_Line_2Dto3D::cCam2_Line_2Dto3D(const std::vector<cSensorCamPC *> & aVCam,c
206256
207257}
208258
259+ std::vector<cCam2_Line_2Dto3D*> cCam2_Line_2Dto3D::AllocV (const std::vector<cSensorCamPC *> & aVCam,const cPhotogrammetricProject & aPhProj)
260+ {
261+ std::vector<cCam2_Line_2Dto3D*> aResult;
262+
263+ cMerged_MultipleLines aMML;
264+
265+ for (const auto & aCam : aVCam)
266+ {
267+ cLinesAntiParal1Im aLAP = aPhProj.ReadLines (aCam->NameImage ());
268+ aMML.AddLAP (aLAP);
269+ }
270+
271+ for (const auto & [aNameLine,aMapOf1L]: aMML.LinesAP ())
272+ {
273+ aResult.push_back (new cCam2_Line_2Dto3D (aVCam,aNameLine,aMapOf1L));
274+ }
275+
276+ return aResult;
277+ }
278+
279+
209280void cCam2_Line_2Dto3D::AssertSeg3dIsInit () const
210281{
211282 MMVII_INTERNAL_ASSERT_always (mSeg3dIsInit ," cCam2_Line_2Dto3D::AssertSeg3dIsInit" );
@@ -242,28 +313,21 @@ std::vector<cOneData_L23> & cCam2_Line_2Dto3D::Datas_L23()
242313 // mUkN1 (cPt2dr(0,0),std::string("Line3d_Uk1") + mLineInit->NameLine()),
243314cUK_Line3D_4BA::cUK_Line3D_4BA
244315(
245- const std::vector<cSensorCamPC *> & aVCam,
246- cPhotogrammetricProject * aPhProj,
316+ cCam2_Line_2Dto3D * aLine,
247317 cMMVII_BundleAdj * aBA,
248318 tREAL8 aSigmaIm,
249319 int aNbPts
250320) :
251321 mBA (aBA),
252- mLineInit (new cCam2_Line_2Dto3D (aVCam,aPhProj) ),
322+ mLineInit (aLine ),
253323 mSeg (mLineInit ->Seg3d ()),
254324 mUkN1 (0.0 ,0.0 ),
255325 mUkN2 (0.0 ,0.0 ) ,
256326 mSigmaIm (aSigmaIm),
257327 mNbPtSampling (aNbPts)
258328{
259- // ddOneObj()
260-
261- // aBA->SetIntervUK().AddOneObj(&mUkN1);
262- // aBA->SetIntervUK().AddOneObj(&mUkN2);
263-
264329 InitNormals ();
265- for (auto aCam : aVCam)
266- aCam->InternalCalib ()->SetAndGet_EqProjSeg ();
330+
267331}
268332
269333cUK_Line3D_4BA::~cUK_Line3D_4BA ()
@@ -332,17 +396,22 @@ void cUK_Line3D_4BA::AddOneEquation(tREAL8 aLambda,tREAL8 aWeight,cOneData_L23&
332396 cPt2dr aNormL2 = Rot90 (aTgtL2);
333397
334398 tREAL8 aResidual= Norm2 (aPImPG-aPImOnL2);
399+ /*
335400 {
336401 auto aCalib = aData.mCam->InternalCalib();
337402 const tSeg2dr aSegD = aData.mSeg;
338403
339404 tSegComp2dr aSeg_UD (aCalib->Undist(aSegD.P1()),aCalib->Undist(aSegD.P2()));
340405 cPt2dr aP_UD = aCalib->Undist(aPImPG);
341406
342- StdOut () << " ** RRRR " << aResidual << " DD=" << aSeg_UD.Dist (aP_UD) << " \n " ;
407+ cPt2dr aP_UD2 = aCalib->Undist(aPImOnL2);
408+
409+
410+ StdOut() << "** RRRR " << aResidual << " DD=" << aSeg_UD.Dist(aP_UD) << " D2=" << aSeg_UD.Dist(aP_UD2) << "\n";
343411
344412 //const tSeg2dr mSeg
345413 }
414+ */
346415 aData.AvgResidual ().Add (1.0 ,aResidual);
347416// StdOut() << " PIMG=" << aPImPG << " PL=" << aPImOnL2 << "\n";
348417
@@ -397,6 +466,14 @@ void cUK_Line3D_4BA::AddEquation()
397466 for ( auto & aData_L23 : mLineInit ->Datas_L23 ())
398467 AddOneEquation (aLambda,aWeight,aData_L23);
399468 }
469+
470+ StdOut () << " LineResidual " ;
471+ for ( auto & aData_L23 : mLineInit ->Datas_L23 ())
472+ {
473+ StdOut () << " " << aData_L23.AvgResidual ().Average ();
474+ }
475+ StdOut () << " \n " ;
476+
400477}
401478
402479/* *********************************************************** */
@@ -407,25 +484,34 @@ void cUK_Line3D_4BA::AddEquation()
407484
408485void cMMVII_BundleAdj::AddLineAdjust (const std::vector<std::string> & aVParam)
409486{
410- tREAL8 aSigmaIm = cStrIO<double >::FromStr (aVParam.at (0 ));
411- int aNbPts = cStrIO<int >::FromStr (aVParam.at (1 ));
487+ for (auto aCam : mVSCPC )
488+ aCam->InternalCalib ()->SetAndGet_EqProjSeg ();
489+
490+ tREAL8 aSigmaIm = cStrIO<double >::FromStr (aVParam.at (0 ));
491+ int aNbPts = cStrIO<int >::FromStr (aVParam.at (1 ));
412492
413- mLineAdjust = new cUK_Line3D_4BA (mVSCPC ,mPhProj ,this ,aSigmaIm,aNbPts);
414- mSetIntervUK .AddOneObj (mLineAdjust );
493+ std::vector<cCam2_Line_2Dto3D*> aVecL = cCam2_Line_2Dto3D::AllocV (mVSCPC ,*mPhProj );
494+
495+ for (const auto & aPtrL : aVecL)
496+ {
497+ mVecLineAdjust .push_back ( new cUK_Line3D_4BA (aPtrL,this ,aSigmaIm,aNbPts));
498+ mSetIntervUK .AddOneObj (mVecLineAdjust .back ());
499+ }
415500}
416501
417502void cMMVII_BundleAdj::IterAdjustOnLine ()
418503{
419- if ( mLineAdjust )
420- mLineAdjust ->AddEquation ();
504+ for ( auto aPtrL : mVecLineAdjust )
505+ aPtrL ->AddEquation ();
421506}
422507
423508
424509// cUK_Line3D_4BA::cUK_Line3D_4BA(const std::vector<cSensorCamPC *> & aVCam,cPhotogrammetricProject * aPhProj,cMMVII_BundleAdj * aBA) :
425510
426511void cMMVII_BundleAdj::DeleteLineAdjust ()
427512{
428- delete mLineAdjust ;
513+ DeleteAllAndClear (mVecLineAdjust );
514+ // delete mLineAdjust;
429515}
430516
431517
0 commit comments