Skip to content

Commit d81027e

Browse files
author
deseilligny
committed
Chg Ori, in clino
1 parent 3a34182 commit d81027e

File tree

9 files changed

+207
-61
lines changed

9 files changed

+207
-61
lines changed

MMVII/include/MMVII_InstrumentalBlock.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ class cIrbCal_Clino1 : public cMemCheck
180180
bool IsInit() const;
181181
void UnInit();
182182
private :
183-
std::string mName; //< name of the clino
184-
bool mIsInit; //< was values computed ?
185-
cP3dNormWithUK * mTrInBlock; //< Position in the block
186-
tREAL8 mSigmaR; //< sigma a priori on orientation
183+
std::string mName; //< name of the clino
184+
bool mIsInit; //< was values computed ?
185+
cP3dNormWithUK * mTrInBlock; //< Position in the block
186+
std::vector<tREAL8> mPolCorr; //< Polynomial correction 2 angles, def [0,1,0]
187+
// tREAL8 mSigmaR; //< sigma a priori on orientation
187188
};
188189
void AddData(const cAuxAr2007 & anAux,cIrbCal_Clino1 & aClino);
189190

@@ -200,10 +201,11 @@ class cIrbCal_ClinoSet : public cMemCheck
200201
size_t NbClino() const;
201202

202203
int IndexClinoFromName(const std::string& aName) const;
204+
cIrbCal_Clino1 & KthClino(int aK);
203205

204206
private :
205207
cIrbCal_Clino1 * ClinoFromName(const std::string& aName);
206-
void AddClino(const std::string &,bool SVP=false);
208+
void AddClino(const std::string &,tREAL8 aSigma,bool SVP=false);
207209

208210
std::vector<cIrbCal_Clino1> mVClinos; //< set of clinos
209211
cIrbCal_Block * mCalBlock;

MMVII/include/MMVII_nums.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ template <class Type> Type Average(const std::vector<Type> &);
1818

1919
tREAL8 AngleFromRad(eTyUnitAngle);
2020
tREAL8 AngleFromRad(tREAL8 aAngInRad,eTyUnitAngle);
21+
tREAL8 Rad2DMgon(tREAL8 aAngInRad);
22+
2123

2224
bool AssertRadAngleInOneRound(tREAL8 aAngleRad, bool makeError=true);
2325

MMVII/include/MMVII_util_tpl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,22 @@ class cComputeAssociation
593593
};
594594
void AddData(const cAuxAr2007 & anAux,cComputeAssociation & aTransl);
595595

596+
597+
598+
template <class TypeCont> typename TypeCont::value_type SumElem(const TypeCont &aCont)
599+
{
600+
typename TypeCont::value_type aResult = cNV<typename TypeCont::value_type>::V0();
601+
for (const auto aVal : aCont)
602+
aResult += aVal;
603+
return aResult;
604+
}
605+
606+
template <class TypeCont> typename TypeCont::value_type AvgElem(const TypeCont &aCont)
607+
{
608+
MMVII_INTERNAL_ASSERT_tiny(!aCont.empty(),"AvgElem on empty vect");
609+
return SumElem(aCont) / double (aCont.size());
610+
}
611+
596612
};
597613

598614
#endif // _MMVII_Util_TPL_H_

MMVII/src/Instrumental/cAppli_BlockInstrInitClino.cpp

Lines changed: 120 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace MMVII
1616
{
1717

18+
1819
/* *************************************************************** */
1920
/* */
2021
/* cAppli_BlockInstrInitClino */
@@ -38,7 +39,7 @@ class cAppli_BlockInstrInitClino : public cMMVII_Appli,
3839

3940
// force a pair of clino to be orthog
4041
void OrthogPair(const cPt2di &);
41-
void DoOneClino();
42+
void DoOneClino(int aK);
4243

4344
cPt1dr Value(const cPt2dr&) const override ;
4445
cPt1dr Value(const cPt3dr&) const override ;
@@ -48,36 +49,56 @@ class cAppli_BlockInstrInitClino : public cMMVII_Appli,
4849

4950
cPhotogrammetricProject mPhProj;
5051
std::string mSpecImIn;
52+
53+
// ------------- Optionnal parameters ----------------
54+
std::string mNameBloc; //< name of the bloc inside the
55+
int mNbSS;
56+
std::vector<cPt2di> mPairOrthog; //< vector of orthog if we change (more for test)
57+
eTyUnitAngle mUnitShow; //< Unity for print result
58+
bool mReSetSigma; //< do we use sigma
59+
60+
// ----------
5161
cIrbComp_Block * mBlock;
5262
cIrbCal_Block * mCalBlock;
5363
cIrbCal_ClinoSet * mSetClinos ; //< Accessors
54-
std::string mNameBloc; //< name of the bloc inside the
64+
int mNbClino;
65+
66+
67+
5568
//bool mAvgSigma; //< Do we average sigma of pairs
5669
int mKCurClino;
70+
int mK1CurC;
71+
int mK2CurC;
5772
cPt2di mK1K2CurC;
58-
int mNbSS;
5973
tRotR mAxesCur;
60-
std::vector<int> mNumPoseInstr;
74+
std::vector<int> mNumPoseInstr; //< Num cams used for pose estimation
75+
std::vector<bool> mInPairOrthog; //< Is the clino used in a pair
76+
6177
cWeightAv<tREAL8,tREAL8> mAvgClinIndep;
62-
std::vector<tREAL8> mScoreClino;
78+
std::vector<tREAL8> mScoreClinoIndep;
6379
std::vector<cPt3dr> mDirClinoIndep;
64-
std::vector<cPt2di> mPairOrthog;
65-
eTyUnitAngle mUnity;
80+
81+
cWeightAv<tREAL8,tREAL8> mAvgClinGlob;
82+
std::vector<tREAL8> mScoreClinoGlob;
83+
std::vector<cPt3dr> mDirClinoGlob;
84+
85+
6686
};
6787

6888

6989

7090
cAppli_BlockInstrInitClino::cAppli_BlockInstrInitClino(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec) :
7191
cMMVII_Appli (aVArgs,aSpec),
7292
mPhProj (*this),
93+
94+
mNameBloc (cIrbCal_Block::theDefaultName),
95+
mNbSS (100),
96+
mUnitShow (eTyUnitAngle::eUA_DMgon),
97+
mReSetSigma (true),
7398
mBlock (nullptr),
7499
mCalBlock (nullptr),
75100
mSetClinos (nullptr),
76-
mNameBloc (cIrbCal_Block::theDefaultName),
77-
// mAvgSigma (true),
78-
mKCurClino (-1),
79-
mNbSS (100),
80-
mUnity (eTyUnitAngle::eUA_DMgon)
101+
mKCurClino (-1)
81102
{
82103
}
83104

@@ -98,10 +119,11 @@ cCollecSpecArg2007 & cAppli_BlockInstrInitClino::ArgOpt(cCollecSpecArg2007 & anA
98119
<< AOpt2007(mNameBloc,"NameBloc","Name of bloc to calib ",{{eTA2007::HDV}})
99120
<< AOpt2007(mNbSS,"NbSS","Number of sample on the sphere ",{{eTA2007::HDV}})
100121
<< AOpt2007(mNumPoseInstr,"NPI","Num of cams used for estimate pose of intsrument")
101-
<< AOpt2007(mPairOrthog,"PairOrthog","Num of cams used for estimate pose of intsrument")
102-
<< AOpt2007(mUnity,"USA","Unity Show Angles",{AC_ListVal<eTyUnitAngle>(),{eTA2007::HDV}})
122+
<< AOpt2007(mPairOrthog,"PairOrthog","Pair of orthogonal camera (if reset)")
123+
<< AOpt2007(mUnitShow,"USA","Unity Show Angles",{AC_ListVal<eTyUnitAngle>(),{eTA2007::HDV}})
124+
<< AOpt2007(mReSetSigma,"ResetSigma","Do we use sigma",{{eTA2007::HDV}})
103125

104-
;
126+
;
105127
}
106128

107129
tREAL8 cAppli_BlockInstrInitClino::ScoreDirClino(const cPt3dr& aDir,size_t aKClino) const
@@ -111,7 +133,7 @@ tREAL8 cAppli_BlockInstrInitClino::ScoreDirClino(const cPt3dr& aDir,size_t aKCli
111133

112134
tREAL8 cAppli_BlockInstrInitClino::Ang4Show(tREAL8 anAng) const
113135
{
114-
return AngleFromRad(anAng,mUnity);
136+
return AngleFromRad(anAng,mUnitShow);
115137
}
116138
// ======================== 3D optimisation ==========================
117139

@@ -132,30 +154,35 @@ tRotR cAppli_BlockInstrInitClino::P3toRot(const cPt3dr& aWPK) const
132154
void cAppli_BlockInstrInitClino::OrthogPair(const cPt2di & aK1K2)
133155
{
134156
mK1K2CurC = aK1K2;
135-
cPt3dr aP1 = mDirClinoIndep.at(mK1K2CurC.x());
136-
cPt3dr aP2 = mDirClinoIndep.at(mK1K2CurC.y());
137-
tREAL8 aSc1 = mScoreClino.at(mK1K2CurC.x());
138-
tREAL8 aSc2 = mScoreClino.at(mK1K2CurC.y());
157+
mK1CurC = mK1K2CurC.x();
158+
mK2CurC = mK1K2CurC.y();
159+
mInPairOrthog.at(mK1CurC) = true;
160+
mInPairOrthog.at(mK2CurC) = true;
161+
162+
cPt3dr aP1 = mDirClinoIndep.at(mK1CurC);
163+
cPt3dr aP2 = mDirClinoIndep.at(mK2CurC);
164+
//tREAL8 aSc1 = mScoreClinoIndep.at(mK1CurC);
165+
//tREAL8 aSc2 = mScoreClinoIndep.at(mK2CurC);
139166

140167

141168
auto [aQ1,aQ2] = OrthogonalizePair(aP1,aP2);
142169
cPt3dr aQ3 = aQ1 ^ aQ2;
143170
mAxesCur = tRotR(aQ1,aQ2,aQ3,false);
144171

145-
tREAL8 anAng = std::abs(AbsAngleTrnk(aP1,aP2)-M_PI/2.0) ;
146-
StdOut() << " * ANGL-Orthog =" << Ang4Show(anAng) << "\n";
172+
//tREAL8 anAng = std::abs(AbsAngleTrnk(aP1,aP2)-M_PI/2.0) ;
147173

148174
cOptimByStep<3> anOptim(*this,true,1.0);
149175
auto [aScMin,aPt3Min] = anOptim.Optim(cPt3dr(0,0,0),2.0/mNbSS,1e-8,1/sqrt(2.0));
150176

151-
StdOut() << " SC-ORTHO=" << Ang4Show(aScMin)
152-
<< " SC-INDIV=" << Ang4Show((aSc1+aSc2)/2.0)
153-
<< "\n";
177+
mAxesCur = P3toRot(aPt3Min);
178+
179+
mScoreClinoGlob.at(mK1CurC) = mScoreClinoGlob.at(mK2CurC) = aScMin;
180+
mDirClinoGlob.at(mK1CurC) = mAxesCur.AxeI();
181+
mDirClinoGlob.at(mK2CurC) = mAxesCur.AxeJ();
154182
}
155183

156184
// ======================== 2D optimisation ==========================
157185

158-
159186
cPt3dr cAppli_BlockInstrInitClino::P2toP3(const cPt2dr& aP2) const
160187
{
161188
return VUnit(mAxesCur.Value(cPt3dr(1.0,aP2.x(),aP2.y())));
@@ -168,8 +195,9 @@ cPt1dr cAppli_BlockInstrInitClino::Value(const cPt2dr&aP2) const
168195
}
169196

170197

171-
void cAppli_BlockInstrInitClino::DoOneClino()
198+
void cAppli_BlockInstrInitClino::DoOneClino(int aK)
172199
{
200+
mKCurClino = aK;
173201
cSampleSphere3D aSSph(mNbSS);
174202

175203
cWhichMin<cPt3dr,tREAL8> aWMin(cPt3dr(0,0,1),1e10);
@@ -190,7 +218,7 @@ void cAppli_BlockInstrInitClino::DoOneClino()
190218

191219
tREAL8 aSc2 = aScMin;
192220

193-
if (0)
221+
if (NeverHappens())
194222
{
195223
StdOut() << " K=" << mKCurClino
196224
<< " V=" << Ang4Show(aWMin.ValExtre())
@@ -222,15 +250,18 @@ void cAppli_BlockInstrInitClino::DoOneClino()
222250
}
223251

224252
tREAL8 aSc3 = aScMin;
225-
226-
StdOut() << " SCORE CLINO "
227-
<< " A0=" << Ang4Show(aSc1)
228-
<< " Opt1=" << Ang4Show(aSc2)
229-
<< " Opt2=" << Ang4Show(aSc3)
253+
if (NeverHappens())
254+
{
255+
StdOut() << " SCORE CLINO "
256+
<< " A0=" << Ang4Show(aSc1)
257+
<< " Opt1=" << Ang4Show(aSc2)
258+
<< " Opt2=" << Ang4Show(aSc3)
230259
<< "\n";
231-
mAvgClinIndep.Add(1.0,aSc3);
232-
mScoreClino.push_back(aSc3);
233-
mDirClinoIndep.push_back(mAxesCur.AxeI());
260+
}
261+
262+
mAvgClinIndep.Add(1.0,aSc3);
263+
mScoreClinoIndep.at(mKCurClino) = aSc3;
264+
mDirClinoIndep.at(mKCurClino) = mAxesCur.AxeI();
234265
}
235266

236267

@@ -244,6 +275,11 @@ int cAppli_BlockInstrInitClino::Exe()
244275
mBlock = new cIrbComp_Block(mPhProj,mNameBloc);
245276
mCalBlock = & mBlock->CalBlock();
246277
mSetClinos = & mCalBlock->SetClinos();
278+
mNbClino = mSetClinos->NbClino() ;
279+
280+
mScoreClinoIndep.resize(mNbClino);
281+
mDirClinoIndep.resize(mNbClino);
282+
mInPairOrthog.resize(mNbClino,false);
247283

248284
if (IsInit(&mNumPoseInstr))
249285
mCalBlock->SetCams().SetNumPoseInstr(mNumPoseInstr);
@@ -258,8 +294,11 @@ int cAppli_BlockInstrInitClino::Exe()
258294
mBlock->ComputePoseInstrument();
259295
mBlock->SetClinoValues();
260296

261-
for (mKCurClino=0 ; mKCurClino<(int)mSetClinos->NbClino() ; mKCurClino++)
262-
DoOneClino();
297+
for (int aKC=0 ; aKC<(int)mSetClinos->NbClino() ; aKC++)
298+
DoOneClino(aKC);
299+
300+
mScoreClinoGlob = mScoreClinoIndep;
301+
mDirClinoGlob = mDirClinoIndep;
263302

264303
mPhProj.SaveRigBoI(mBlock->CalBlock());
265304

@@ -272,8 +311,6 @@ int cAppli_BlockInstrInitClino::Exe()
272311

273312
if ((aK1>=0) && (aK2>=0))
274313
mPairOrthog.push_back(cPt2di(aK1,aK2));
275-
276-
StdOut() << "KKKK " << aK1 << " " << aK2 << "\n";
277314
}
278315
}
279316

@@ -282,7 +319,49 @@ int cAppli_BlockInstrInitClino::Exe()
282319
OrthogPair(aPt);
283320
}
284321

285-
StdOut() << " AVG CLINO INDEP=" << Ang4Show(mAvgClinIndep.Average()) << "\n";
322+
StdOut() << " AVG ; INDEP=" << Ang4Show(mAvgClinIndep.Average()) ;
323+
if (! mPairOrthog.empty())
324+
StdOut() << " ; ORTHOG=" << Ang4Show(AvgElem(mScoreClinoGlob)) ;
325+
StdOut() << "\n\n";
326+
327+
328+
// ========================= print the result (Reports 2 add) ===========================================
329+
for (int aKC=0 ; aKC<mNbClino ; aKC++)
330+
{
331+
tREAL8 aScore = mScoreClinoGlob.at(aKC);
332+
std::string aName = mSetClinos->VNames().at(aKC);
333+
if (mReSetSigma)
334+
{
335+
auto & aDescInstr = mCalBlock->AddSigma_Indiv(aName,eTyInstr::eClino);
336+
aDescInstr.SetSigma(cIrb_SigmaInstr(0.0,1.0,0.0,aScore));
337+
}
338+
mSetClinos->KthClino(aKC).SetPNorm(mDirClinoGlob.at(aKC));
339+
340+
StdOut() << " K=" << aKC << " N=" << aName
341+
<< " Score=" << Ang4Show(aScore)
342+
<< " Dir=" << mDirClinoGlob.at(aKC)
343+
<< "\n";
344+
}
345+
346+
if (! mPairOrthog.empty())
347+
{
348+
StdOut() << " =============== Orthogonality ===================\n";
349+
for (const auto & aPair : mPairOrthog)
350+
{
351+
int aK1 = aPair.x();
352+
int aK2 = aPair.y();
353+
tREAL8 aDelta1 = mScoreClinoGlob.at(aK1) - mScoreClinoIndep.at(aK1);
354+
tREAL8 aDelta2 = mScoreClinoGlob.at(aK2) - mScoreClinoIndep.at(aK2);
355+
356+
tREAL8 anAng = std::abs(AbsAngleTrnk( mDirClinoIndep.at(aK1),mDirClinoIndep.at(aK2))-M_PI/2.0) ;
357+
StdOut() << " * Pair=" << aPair
358+
<< " OrthoAPrior=" << Ang4Show(anAng)
359+
<< " Dif:Indep/Orthog=" << Ang4Show(aDelta1) << " " << Ang4Show(aDelta2) << "\n";
360+
}
361+
}
362+
363+
mPhProj.SaveRigBoI(*mCalBlock);
364+
286365

287366
delete mBlock;
288367
return EXIT_SUCCESS;

MMVII/src/Instrumental/cAppli_EditBlockInstr.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,25 @@ int cAppli_EditBlockInstr::Exe()
128128
if (mPhProj.DPMeasuresClino().DirInIsInit())
129129
{
130130
cSetMeasureClino aMesClin = mPhProj.ReadMeasureClino();
131-
for (const auto & aName : aMesClin.NamesClino())
131+
const std::vector<std::string> & aVNames = aMesClin.NamesClino();
132+
size_t aNbC = aVNames.size();
133+
std::vector<cWeightAv<tREAL8,tREAL8>> aVW (aNbC);
134+
135+
for (const auto & aMes: aMesClin.SetMeasures())
136+
{
137+
const auto & aSigm = aMes.VSigma();
138+
if (aSigm.has_value())
139+
{
140+
for (size_t aK=0 ; aK<aNbC ; aK++ )
141+
aVW.at(aK).Add(1.0,aSigm.value().at(aK));
142+
}
143+
// StdOut() << "SIGINIT= " << aSigm.has_value() << " " << aMes.Ident()<< "\n";
144+
}
145+
for(size_t aK=0 ; aK<aNbC ; aK++ )
132146
{
133-
aBlock->SetClinos().AddClino(aName,SVP::Yes);
147+
tREAL8 aSigma = aVW.at(aK).Average(-1.0);
148+
// StdOut() << " SIGMA " << aSigma << "\n";
149+
aBlock->SetClinos().AddClino(aVNames.at(aK),aSigma,SVP::Yes);
134150
}
135151
}
136152

MMVII/src/Instrumental/cInstrumentalBloc.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ void cIrb_SigmaInstr::AddData(const cAuxAr2007 & anAux)
4545

4646
MMVII::AddData(cAuxAr2007("Rot",anAux) ,mAvgSigRot);
4747
if (mAvgSigRot.SW() >0 )
48-
anAux.Ar().AddComment("SigRot="+ToStr(mAvgSigRot.Average()));
49-
50-
// StdOut() << "cIrb_SigmaInstr::AddData::Done \n";
48+
{
49+
anAux.Ar().AddComment
50+
(
51+
"SigRot="
52+
+ ToStr(mAvgSigRot.Average()) + " rad, "
53+
+ ToStr(Rad2DMgon(mAvgSigRot.Average())) + " dmgon "
54+
);
55+
}
5156
}
5257

5358

0 commit comments

Comments
 (0)