Skip to content

Commit ed16b1a

Browse files
committed
MMVII: Ajout d'un test APBI (teste l'ecriture en parallele dans 1 image)
1 parent fb70830 commit ed16b1a

File tree

7 files changed

+152
-3
lines changed

7 files changed

+152
-3
lines changed

MMVII/include/MMVII_Bench.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void BenchExtre(cParamExeBench & aParam); ///< Test Extremum computations, refi
119119
void BenchStat(cParamExeBench & aParam);
120120

121121
void BenchGlobImage(cParamExeBench & aParam); ///< Global bench on image
122+
void BenchAPBI(cParamExeBench & aParam);
122123
void BenchFilterImage1(cParamExeBench & aParam);
123124
void BenchFilterLinear(cParamExeBench & aParam);
124125
void BenchGeom(cParamExeBench & aParam);

MMVII/include/MMVII_DeclareAllCmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ extern cSpecMMVII_Appli TheSpec_PerturbRandomOri;
136136
extern cSpecMMVII_Appli TheSpec_ImportTriplet;
137137
extern cSpecMMVII_Appli TheSpec_ArboTriplet;
138138

139+
extern cSpecMMVII_Appli TheSpecAppliBenchAPBI;
139140
};
140141

141142
#endif // _MMVII_DeclareAllCmd_H_

MMVII/include/MMVII_Image2D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ template<class TypeEl> class cAppliParseBoxIm
482482
cAppliParseBoxIm(cMMVII_Appli & anAppli,eForceGray IsGray,const cPt2di & aSzTiles,const cPt2di & aSzOverlap,bool ParalTiles) ;
483483
~cAppliParseBoxIm();
484484

485-
void APBI_ExecAll(); ///< Execute Action on all Box of file OR only on Test Box if exist
485+
void APBI_ExecAll(bool Silence=false); ///< Execute Action on all Box of file OR only on Test Box if exist
486486

487487
cCollecSpecArg2007 & APBI_ArgObl(cCollecSpecArg2007 & anArgObl) ; ///< For sharing mandatory args
488488
cCollecSpecArg2007 & APBI_ArgOpt(cCollecSpecArg2007 & anArgOpt); ///< For sharing optionnal args

MMVII/src/Appli/cSpecMMVII_Appli.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ std::vector<cSpecMMVII_Appli *> & cSpecMMVII_Appli::InternVecAll()
283283
TheVecAll.push_back(&TheSpec_ImportTriplet);
284284
TheVecAll.push_back(&TheSpec_ArboTriplet);
285285

286+
TheVecAll.push_back(&TheSpecAppliBenchAPBI);
286287

287288
std::sort(TheVecAll.begin(),TheVecAll.end(),CmpCmd);
288289
}

MMVII/src/Bench/BenchAPBI.cpp

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#include "MMVII_Image2D.h"
2+
3+
namespace MMVII
4+
{
5+
6+
namespace { // private
7+
8+
class cAppliTestAPBI : public cMMVII_Appli,
9+
public cAppliParseBoxIm<tREAL4>
10+
{
11+
public :
12+
typedef cAppliParseBoxIm<tREAL4> tAPBI;
13+
typedef tAPBI::tIm tImAPBI;
14+
typedef tAPBI::tDataIm tDImAPBI;
15+
typedef cIm2D<tREAL4> tImPx;
16+
typedef cIm2D<tU_INT1> tImMasq;
17+
18+
// typedef cIm2D
19+
20+
// =========== Declaration ========
21+
// --- Method to be a MMVII application
22+
cAppliTestAPBI(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli &);
23+
int Exe() override;
24+
// --- Method to be a cAppliParseBoxIm<tREAL4>
25+
int ExeOnParsedBox() override; ///< Action to exec for each box, When the appli parse a big file
26+
27+
static std::string ImNameIn() { return cMMVII_Appli::CurrentAppli().TmpDirTestMMVII() + "TestAPBI.tif"; }
28+
static std::string ImNameOut() { return cMMVII_Appli::CurrentAppli().TmpDirTestMMVII() + "TestAPBI_out.tif"; }
29+
static tU_INT1 valFromBox(const cPixBox<2>& box) { return (box.P0().x() + box.P0().y()) % 255;}
30+
31+
private:
32+
cCollecSpecArg2007 &ArgObl(cCollecSpecArg2007 &anArgObl) override;
33+
cCollecSpecArg2007 &ArgOpt(cCollecSpecArg2007 &anArgOpt) override;
34+
};
35+
36+
37+
38+
cAppliTestAPBI::cAppliTestAPBI
39+
(
40+
const std::vector<std::string> & aVArgs,
41+
const cSpecMMVII_Appli & aSpec
42+
) :
43+
cMMVII_Appli (aVArgs,aSpec) ,
44+
cAppliParseBoxIm<tREAL4> (*this,eForceGray::Yes,cPt2di(0,0),cPt2di(0,0),true)
45+
{
46+
}
47+
48+
cCollecSpecArg2007 & cAppliTestAPBI::ArgObl(cCollecSpecArg2007 & anArgObl)
49+
{
50+
return anArgObl;
51+
// return APBI_ArgObl(anArgObl); <-- should be used, but for bench, it's simplier to don't
52+
}
53+
54+
cCollecSpecArg2007 & cAppliTestAPBI::ArgOpt(cCollecSpecArg2007 & anArgOpt)
55+
{
56+
return APBI_ArgOpt(anArgOpt);
57+
}
58+
59+
60+
int cAppliTestAPBI::ExeOnParsedBox()
61+
{
62+
cIm2D<tU_INT1> aImTest(CurSzIn());
63+
tU_INT1 aVal = valFromBox(CurBoxIn());
64+
auto &imSrc = LoadI(CurBoxIn());
65+
for (const auto & aPix : aImTest.DIm())
66+
aImTest.DIm().SetVTrunc(aPix,(aVal + (int)imSrc.GetV(aPix)) % 255);
67+
APBI_WriteIm(ImNameOut(),aImTest);
68+
69+
return EXIT_SUCCESS;
70+
}
71+
72+
int cAppliTestAPBI::Exe()
73+
{
74+
mNameIm = ImNameIn();
75+
APBI_ExecAll(true);
76+
return EXIT_SUCCESS;
77+
}
78+
79+
80+
/* ============================================= */
81+
/* ALLOCATION */
82+
/* ============================================= */
83+
84+
tMMVII_UnikPApli Alloc_cAppliTestAPBI(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec)
85+
{
86+
return tMMVII_UnikPApli(new cAppliTestAPBI(aVArgs,aSpec));
87+
}
88+
89+
90+
} // namespace private
91+
92+
cSpecMMVII_Appli TheSpecAppliBenchAPBI
93+
(
94+
"TestAPBI",
95+
Alloc_cAppliTestAPBI,
96+
"Internal only !! Used by APBI bench",
97+
{eApF::Test,eApF::NoGui},
98+
{eApDT::None},
99+
{eApDT::Image},
100+
__FILE__
101+
);
102+
103+
104+
105+
void BenchAPBI(cParamExeBench & aParam)
106+
{
107+
if (! aParam.NewBench("APBI")) return;
108+
109+
110+
cDataFileIm2D::Create(cAppliTestAPBI::ImNameIn(),eTyNums::eTN_U_INT1,
111+
cPt2di(2000+RandUnif_M_N(-100,100),2000+RandUnif_M_N(-100,100)),
112+
1
113+
);
114+
auto aIm2d = cIm2D<tU_INT1>(cPt2di(2000+RandUnif_M_N(-100,100),2000+RandUnif_M_N(-100,100)));
115+
for (const auto& aPix : aIm2d.DIm()) {
116+
aIm2d.DIm().SetV(aPix,(aPix.x()+aPix.y()) % 255);
117+
}
118+
cDataFileIm2D aDF = cDataFileIm2D::Create(cAppliTestAPBI::ImNameIn(),eTyNums::eTN_U_INT1,aIm2d.DIm().Sz(),1);
119+
aIm2d.Write(aDF,cPt2di(0,0));
120+
auto aBoxSize = cPt2di(200+RandUnif_M_N(-10,10),200+RandUnif_M_N(-10,10));
121+
122+
cMMVII_Appli & anAp = cMMVII_Appli::CurrentAppli();
123+
124+
anAp.ExeCallMMVII
125+
(
126+
TheSpecAppliBenchAPBI,
127+
anAp.StrObl(),
128+
anAp.StrOpt() << std::make_pair("SzTiles",cStrIO<cPt2di>::ToStr(aBoxSize))
129+
);
130+
131+
132+
auto mIm2d = cIm2D<tU_INT1>::FromFile(cAppliTestAPBI::ImNameOut());
133+
cParseBoxInOut<2> aPBIO = cParseBoxInOut<2>::CreateFromSize(mIm2d.DIm(),aBoxSize);
134+
for (const auto & aPixI : aPBIO.BoxIndex()) {
135+
auto aBox = aPBIO.BoxOut(aPixI);
136+
tU_INT1 aVal = cAppliTestAPBI::valFromBox(aBox);
137+
for (const auto &aPix : aBox) {
138+
MMVII_INTERNAL_ASSERT_bench(mIm2d.DIm().GetV(aPix) == (aVal + (aPix.x() + aPix.y()) % 255)%255,"BenchAPBI failed");
139+
}
140+
}
141+
aParam.EndBench();
142+
}
143+
144+
} // namespace MMVII
145+

MMVII/src/Bench/BenchGlob.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ int cAppli_MMVII_Bench::ExecuteBench(cParamExeBench & aParam)
545545

546546
// Call several test on images : File, RectObj, Im1D, Im2D, BaseImage
547547
BenchGlobImage(aParam);
548+
BenchAPBI(aParam);
548549

549550
BenchFilterImage1(aParam);
550551
BenchFilterLinear(aParam);

MMVII/src/ImagesBase/cIm2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ template<class TypeEl> bool cAppliParseBoxIm<TypeEl>::TopCallParallTile() const
377377
return mParalTiles && (!InsideParalRecall());
378378
}
379379

380-
template<class TypeEl> void cAppliParseBoxIm<TypeEl>::APBI_ExecAll()
380+
template<class TypeEl> void cAppliParseBoxIm<TypeEl>::APBI_ExecAll(bool Silence)
381381
{
382382
mDFI2d = cDataFileIm2D::Create(mNameIm,mIsGray);
383383
if (APBI_TestMode())
@@ -413,7 +413,7 @@ template<class TypeEl> void cAppliParseBoxIm<TypeEl>::APBI_ExecAll()
413413
}
414414
}
415415
mParseBox = nullptr ; // No longer inside parsing
416-
mAppli.ExeComParal(aLComParal);
416+
mAppli.ExeComParal(aLComParal,Silence);
417417
}
418418

419419
template<class TypeEl> const std::string & cAppliParseBoxIm<TypeEl>::APBI_NameIm() const

0 commit comments

Comments
 (0)