Skip to content

Commit b9259d9

Browse files
committed
Test Gdal
1 parent 7985c6d commit b9259d9

File tree

3 files changed

+298
-1
lines changed

3 files changed

+298
-1
lines changed

MMVII/include/MMVII_DeclareAllCmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extern cSpecMMVII_Appli TheSpec_CreateRTL;
8989
extern cSpecMMVII_Appli TheSpec_ChSysCo;
9090
extern cSpecMMVII_Appli TheSpec_CreateCalib;
9191
extern cSpecMMVII_Appli TheSpecImportPushbroom;
92+
extern cSpecMMVII_Appli TheSpec_TestGdal;
9293
};
9394

9495
#endif // _MMVII_DeclareAllCmd_H_

MMVII/src/Appli/cSpecMMVII_Appli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ std::vector<cSpecMMVII_Appli *> & cSpecMMVII_Appli::InternVecAll()
233233
TheVecAll.push_back(&TheSpec_ImportTiePMul);
234234
TheVecAll.push_back(&TheSpec_ImportMesImGCP);
235235
TheVecAll.push_back(&TheSpecImportPushbroom);
236-
236+
TheVecAll.push_back(&TheSpec_TestGdal);
237237

238238
std::sort(TheVecAll.begin(),TheVecAll.end(),CmpCmd);
239239
}

MMVII/src/GDAL/cTestGdal.cpp

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
#include "cMMVII_Appli.h"
2+
#include <iostream>
3+
4+
#include "MMVII_PCSens.h"
5+
#include "MMVII_Image2D.h"
6+
#include "MMVII_enums.h"
7+
8+
9+
namespace MMVII
10+
{
11+
12+
13+
class cAppli_TestGdal : public cMMVII_Appli
14+
{
15+
public :
16+
17+
cAppli_TestGdal(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli &);
18+
int Exe() override;
19+
cCollecSpecArg2007 & ArgObl(cCollecSpecArg2007 & anArgObl) override;
20+
cCollecSpecArg2007 & ArgOpt(cCollecSpecArg2007 & anArgOpt) override;
21+
void OpenTiffImage();
22+
void OpenTiffImageCIm2D();
23+
void OpenTiffImageCIm2DBox();
24+
void OpenTiffRGBImageCIm2DBox();
25+
void CreateTiffImage();
26+
void WriteImage();
27+
void WriteRGBImage();
28+
void WriteImageToFile();
29+
void WriteRGBImageToFile();
30+
void WriteImageTiles();
31+
32+
private :
33+
cPhotogrammetricProject mPhProj;
34+
std::string mImagePathBW;
35+
std::string mImagePathRGB;
36+
37+
};
38+
39+
40+
cAppli_TestGdal::cAppli_TestGdal
41+
(
42+
const std::vector<std::string> & aVArgs,
43+
const cSpecMMVII_Appli & aSpec
44+
) :
45+
cMMVII_Appli (aVArgs,aSpec),
46+
mPhProj (*this)
47+
{
48+
}
49+
50+
51+
52+
cCollecSpecArg2007 & cAppli_TestGdal::ArgObl(cCollecSpecArg2007 & anArgObl)
53+
{
54+
return anArgObl
55+
<< Arg2007(mImagePathBW,"Image BW")
56+
<< Arg2007(mImagePathRGB,"Image RGB")
57+
;
58+
}
59+
60+
61+
cCollecSpecArg2007 & cAppli_TestGdal::ArgOpt(cCollecSpecArg2007 & anArgOpt)
62+
{
63+
64+
return anArgOpt
65+
;
66+
}
67+
68+
69+
void cAppli_TestGdal::OpenTiffImage()
70+
{
71+
StdOut() << "Ouverture de l'image : " << mImagePathBW << std::endl;
72+
cDataFileIm2D aImage = cDataFileIm2D::Create(mImagePathBW, 0);
73+
StdOut() << "cDataFileIm2D créée" << std::endl;
74+
StdOut() << "Taille de l'image : " << aImage.Sz() << std::endl;
75+
StdOut() << "NbChannel : " << aImage.NbChannel() << std::endl;
76+
//StdOut() << "Type : " << aImage.Type() << std::endl;
77+
StdOut() << "Name : " << aImage.Name() << std::endl;
78+
StdOut() << "IsEmpty : " << aImage.IsEmpty() << std::endl;
79+
StdOut() << "" << std::endl;
80+
}
81+
82+
void cAppli_TestGdal::OpenTiffImageCIm2D()
83+
{
84+
StdOut() << "Ouverture de l'image : " << mImagePathBW << std::endl;
85+
cIm2D<tU_INT1> aIm2D = cIm2D<tU_INT1>::FromFile(mImagePathBW);
86+
cDataIm2D<tU_INT1> & aDataIm2D = aIm2D.DIm();
87+
StdOut() << "Taille de l'image : " << aDataIm2D.Sz() << std::endl;
88+
StdOut() << "Valeur du pixel (5000, 8000) : " << (int) aDataIm2D.GetV(cPt2di(5000, 8000)) << std::endl;
89+
StdOut() << "" << std::endl;
90+
91+
}
92+
93+
void cAppli_TestGdal::OpenTiffImageCIm2DBox()
94+
{
95+
StdOut() << "Ouverture de l'image avec une boite de (6000, 8000, 9000, 10000): " << mImagePathBW << std::endl;
96+
cBox2di aBox = cBox2di(cPt2di(6000, 8000), cPt2di(9000, 10000));
97+
cIm2D<tU_INT1> aIm2D = cIm2D<tU_INT1>::FromFile(mImagePathBW, aBox);
98+
StdOut() << "cDataFileIm2D créée" << std::endl;
99+
cDataIm2D<tU_INT1> & aDataIm2D = aIm2D.DIm();
100+
StdOut() << "Taille de l'image : " << aDataIm2D.Sz() << std::endl;
101+
StdOut() << "Valeur du pixel (0, 0) : " << aDataIm2D.GetV(cPt2di(0, 0)) << std::endl;
102+
StdOut() << "Valeur du pixel (0, 1) : " << aDataIm2D.GetV(cPt2di(0, 1)) << std::endl;
103+
StdOut() << "Valeur du pixel (1, 1) : " << aDataIm2D.GetV(cPt2di(1, 1)) << std::endl;
104+
StdOut() << "Valeur du pixel (1, 0) : " << aDataIm2D.GetV(cPt2di(1, 0)) << std::endl;
105+
StdOut() << "Valeur du pixel (0.5, 0.5) : " << aDataIm2D.DefGetVBL(cPt2dr(0.5, 0.5), -1) << std::endl;
106+
StdOut() << "Valeur du pixel (1000.5, 1000.5) : " << aDataIm2D.DefGetVBL(cPt2dr(1000.5, 1000.5), -1) << std::endl;
107+
108+
}
109+
110+
111+
void cAppli_TestGdal::OpenTiffRGBImageCIm2DBox()
112+
{
113+
StdOut() << "Ouverture de l'image RGB avec une boite de (6000, 8000, 9000, 10000): " << mImagePathRGB << std::endl;
114+
cBox2di aBox = cBox2di(cPt2di(6000, 8000), cPt2di(9000, 10000));
115+
cRGBImage aRGBIm = cRGBImage::FromFile(mImagePathRGB, aBox);
116+
StdOut() << "Valeur du pixel (0, 1) : " << aRGBIm.GetRGBPix(cPt2di(0, 1)) << std::endl;
117+
StdOut() << "Valeur du pixel (0.5, 0.5) : " << aRGBIm.GetRGBPixBL(cPt2dr(0.5, 0.5)) << std::endl;
118+
}
119+
120+
121+
void cAppli_TestGdal::CreateTiffImage()
122+
{
123+
std::string aCreatedImage = "image0.tif";
124+
StdOut() << "Ouverture de l'image : " << aCreatedImage << std::endl;
125+
cDataFileIm2D aImage = cDataFileIm2D::Create(aCreatedImage, eTyNums::eTN_INT2, cPt2di(1000, 1000), 3);
126+
StdOut() << "cDataFileIm2D créée : tINT2, 3 canaux" << std::endl;
127+
StdOut() << "Taille de l'image : " << aImage.Sz() << std::endl;
128+
StdOut() << "NbChannel : " << aImage.NbChannel() << std::endl;
129+
StdOut() << "Name : " << aImage.Name() << std::endl;
130+
StdOut() << "IsEmpty : " << aImage.IsEmpty() << std::endl;
131+
StdOut() << "" << std::endl;
132+
}
133+
134+
135+
136+
void cAppli_TestGdal::WriteImage()
137+
{
138+
// Open image
139+
cBox2di aBox = cBox2di(cPt2di(7000, 8000), cPt2di(7100, 8100));
140+
cIm2D<tU_INT1> aIm2D = cIm2D<tU_INT1>::FromFile(mImagePathBW, aBox);
141+
// Create the new image of type eTyNums
142+
std::string aCreatedImageName = "image1.tif";
143+
cDataFileIm2D aCreatedImage = cDataFileIm2D::Create(aCreatedImageName, eTyNums::eTN_REAL8, cPt2di(100, 100), 1);
144+
// Open the new image
145+
// Data will be written in Type (tREAL4), but the image will be save in eTyNums (eTyNums::eTN_REAL8)
146+
cIm2D<tREAL4> aCreatedIm2D = cIm2D<tREAL4>::FromFile(aCreatedImageName);
147+
148+
// Copy data
149+
for (int x = aCreatedIm2D.DIm().X0(); x < aCreatedIm2D.DIm().X1(); x++)
150+
{
151+
for (int y = aCreatedIm2D.DIm().Y0(); y < aCreatedIm2D.DIm().Y1(); y++)
152+
{
153+
aCreatedIm2D.DIm().SetV(cPt2di(x, y), aIm2D.DIm().GetV(cPt2di(x, y)));
154+
}
155+
}
156+
// Save image
157+
aCreatedIm2D.Write(aCreatedImage, cPt2di(0, 0));
158+
}
159+
160+
void cAppli_TestGdal::WriteRGBImage()
161+
{
162+
// Open image in ((7000, 8000), (7100, 8100))
163+
cBox2di aBox = cBox2di(cPt2di(7000, 8000), cPt2di(7100, 8100));
164+
cRGBImage aRGBImage = cRGBImage::FromFile(mImagePathRGB, aBox);
165+
166+
// Create the new image of size (200, 200). Type must be eTyNums::eTN_U_INT1 because it is RGB image
167+
std::string aCreatedImageName = "image2.tif";
168+
cDataFileIm2D aCreatedImage = cDataFileIm2D::Create(aCreatedImageName, eTyNums::eTN_U_INT1, cPt2di(200, 200), 3);
169+
170+
// Open the new image in ((50, 50), (150, 150))
171+
// Origin of the box does not matter in writting because it is in Write method that the origin is defined. Only the size of the box is important here
172+
cRGBImage aCreatedIm2D = cRGBImage::FromFile(aCreatedImageName, cBox2di(cPt2di(50, 50), cPt2di(150, 150)));
173+
174+
// Copy data
175+
for (int x = aRGBImage.ImR().DIm().X0(); x < aRGBImage.ImR().DIm().X1(); x++)
176+
{
177+
for (int y = aRGBImage.ImR().DIm().Y0(); y < aRGBImage.ImR().DIm().Y1(); y++)
178+
{
179+
aCreatedIm2D.SetRGBPix(cPt2di(x, y), aRGBImage.GetRGBPix(cPt2di(x, y)));
180+
}
181+
}
182+
183+
// Save data in coordinates (50, 50)
184+
aCreatedIm2D.Write(aCreatedImage, cPt2di(50, 50));
185+
}
186+
187+
188+
void cAppli_TestGdal::WriteImageToFile()
189+
{
190+
// Open image in ((7000, 8000), (10000, 11000))
191+
cBox2di aBox = cBox2di(cPt2di(7000, 8000), cPt2di(10000, 11000));
192+
cIm2D<tU_INT1> aIm2D = cIm2D<tU_INT1>::FromFile(mImagePathBW, aBox);
193+
194+
// Save extracted image
195+
//aIm2D.DIm().ToFile(mImageCreatePath);
196+
197+
// Save an extraction of the extracted image : ((8000, 9000), (9000, 10000)) of the first image
198+
std::string aCreatedImageName = "image3.tif";
199+
aIm2D.DIm().ClipToFile(aCreatedImageName, cRect2(cPt2di(1000, 1000), cPt2di(2000, 2000)));
200+
201+
}
202+
203+
204+
void cAppli_TestGdal::WriteRGBImageToFile()
205+
{
206+
// Open image in ((7000, 8000), (10000, 11000))
207+
cBox2di aBox = cBox2di(cPt2di(7000, 8000), cPt2di(10000, 11000));
208+
cRGBImage aRGBImage = cRGBImage::FromFile(mImagePathRGB, aBox);
209+
210+
// Read Image in ((15000, 12000), (18000, 15000)). Then aBox in aRGBImage is useless
211+
aRGBImage.Read(mImagePathRGB, cPt2di(0, 0), 1.0, cBox2di(cPt2di(15000, 12000), cPt2di(18000, 15000)));
212+
213+
214+
// Create new image
215+
std::string aCreatedImageName = "image4.tif";
216+
cDataFileIm2D aRGBImagecreated = cDataFileIm2D::Create(aCreatedImageName, eTyNums::eTN_U_INT1, cPt2di(3000, 3000), 3);
217+
// Write data
218+
aRGBImage.Write(aRGBImagecreated, cPt2di(0, 0));
219+
220+
// Save extracted image in RGB
221+
//aRGBImage.ImR().DIm().ToFile(mImageCreatePath, aRGBImage.ImG().DIm(), aRGBImage.ImB().DIm());
222+
223+
}
224+
225+
void cAppli_TestGdal::WriteImageTiles()
226+
{
227+
// Open image in ((7000, 8000), (10000, 11000))
228+
cBox2di aBox = cBox2di(cPt2di(7000, 8000), cPt2di(10000, 11000));
229+
cIm2D<tU_INT1> aIm2D = cIm2D<tU_INT1>::FromFile(mImagePathBW, aBox);
230+
// Create the new image of size (3000, 3000)
231+
std::string aCreatedImageName = "image5.tif";
232+
cDataFileIm2D aCreatedImage = cDataFileIm2D::Create(aCreatedImageName, eTyNums::eTN_REAL8, cPt2di(3000, 3000), 1);
233+
// Open the new image with a size of (1000, 1000)
234+
// Origin of the box does not matter in writting because it is in Write method that the origin is defined. Only the size of the box is important here
235+
cIm2D<tREAL4> aTile = cIm2D<tREAL4>::FromFile(aCreatedImageName, cBox2di(cPt2di(0, 0), cPt2di(1000, 1000)));
236+
237+
// Give the same result :
238+
// cIm2D<tREAL4> aTile = cIm2D<tREAL4>::FromFile(mImageCreatePath, cBox2di(cPt2di(300, 300), cPt2di(1300, 1300)));
239+
240+
// Copy data
241+
for (int x = aTile.DIm().X0(); x < aTile.DIm().X1(); x++)
242+
{
243+
for (int y = aTile.DIm().Y0(); y < aTile.DIm().Y1(); y++)
244+
{
245+
aTile.DIm().SetV(cPt2di(x, y), aIm2D.DIm().GetV(cPt2di(x, y)));
246+
}
247+
}
248+
249+
// Save image at the origin (0, 0)
250+
aTile.Write(aCreatedImage, cPt2di(0, 0));
251+
// Save the same image but at the origin (1000, 2000)
252+
aTile.Write(aCreatedImage, cPt2di(1000, 2000));
253+
}
254+
255+
int cAppli_TestGdal::Exe()
256+
{
257+
mPhProj.FinishInit(); // the final construction of photogrammetric project manager can only be done now
258+
259+
OpenTiffImage();
260+
OpenTiffImageCIm2D();
261+
OpenTiffImageCIm2DBox();
262+
OpenTiffRGBImageCIm2DBox();
263+
CreateTiffImage();
264+
WriteImage();
265+
WriteRGBImage();
266+
WriteImageToFile();
267+
WriteRGBImageToFile();
268+
WriteImageTiles();
269+
270+
return EXIT_SUCCESS;
271+
}
272+
273+
/* ==================================================== */
274+
/* */
275+
/* MMVII */
276+
/* */
277+
/* ==================================================== */
278+
279+
280+
tMMVII_UnikPApli Alloc_TestGdal(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec)
281+
{
282+
return tMMVII_UnikPApli(new cAppli_TestGdal(aVArgs,aSpec));
283+
}
284+
285+
cSpecMMVII_Appli TheSpec_TestGdal
286+
(
287+
"TestGdal",
288+
Alloc_TestGdal,
289+
"Test avec GDAL",
290+
{eApF::GCP,eApF::Ori},
291+
{eApDT::Orient},
292+
{eApDT::Xml},
293+
__FILE__
294+
);
295+
296+
}

0 commit comments

Comments
 (0)