10mã¡ãã·ã¥æ¨é«DEMãªã©ã®é«è§£å度ã®ã©ã¹ã¿ãã¼ã¿ãåºåã«è¨ç®ãããã¨ããã¨ãã¨ã¦ãæéãããã£ã¦å¾
ã£ã¦ããã¾ããã
ããã§ããã«ãã³ã¢CPU(Core2Duoã¨ã)ããã«æ´»ç¨ãã¦ãçæéã§ã©ã¹ã¿æ¼ç®ã§ããGDALã¨OpenMPã使ã£ã並åããã°ã©ãã³ã°ã®æ¹æ³ãç´¹ä»ãã¾ãã
æé
- Visual c++ 2008 Express Edition ãã¤ã³ã¹ãã¼ã«(ããã°ã©ãã³ã°ç°å¢)
- Windows SDK for Windows Server 2008 and .NET Framework 3.5ãã¤ã³ã¹ãã¼ã«(OpenMPç°å¢)
- GDALã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«(ã©ã¹ã¿æ¼ç®ç°å¢)
- GDALã¨OpenMPã使ã£ã¦ããã°ã©ãã³ã°
- OpenMPãªãã·ã§ã³ã§ã³ã³ãã¤ã«ãããã¦å®è¡
1.Visual c++ 2008 Express Edition ãã¤ã³ã¹ãã¼ã«(ããã°ã©ãã³ã°ç°å¢)
âãã¡ããããã¦ã³ãã¼ãï¼ã¤ã³ã¹ãã¼ã«
http://www.microsoft.com/japan/msdn/vstudio/Express/
2.Windows SDK for Windows Server 2008 and .NET Framework 3.5ãã¤ã³ã¹ãã¼ã«(OpenMPç°å¢)
âãã¡ããããã¦ã³ãã¼ãï¼ã¤ã³ã¹ãã¼ã«
http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&displaylang=en
ããã¥ã¡ã³ãã¨ãã¯ã¤ã³ã¹ãã¼ã«ããªãã¦ãããã§ãã
3.GDALã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«(ã©ã¹ã¿æ¼ç®ç°å¢)
âãã¡ãããææ°ã®ã½ã¼ã¹ããã¦ã³ãã¼ã
http://trac.osgeo.org/gdal/wiki/DownloadSource
ã³ãã³ãããã³ããã§ã³ã³ãã¤ã«ã®ããã®ç°å¢å¤æ°ãè¨å®
Set PATH=C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin;%PATH%
Set INCLUDE=C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;%INCLUDE%
Set LIB=C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;%LIB%
nmake.optãã¡ã¢å¸³ã§éãã¦ãMSVC_VER= ã®ã¨ããããMSVC_VER=1500ã«å¤æ´
ã³ãã³ãããã³ããã§ãã³ã³ãã¤ã«ï¼ã¤ã³ã¹ãã¼ã«
nmake /f makefile.vc
nmake /f makefile.vc install
nmake /f makefile.vc devinstall
4.GDALã¨OpenMPã使ã£ã¦ããã°ã©ãã³ã°
gdalã¨openmpã使ã£ã¦ããã°ã©ãã³ã°ã詳細ã¯ãã¾ãä»åº¦ã
ã¨ãããããå¾æãåºãããã°ã©ã ãå¼µã£ã¦ããã¾ãã
#include <stdio.h> #include <stdlib.h> #include <math.h> #include "gdal_priv.h" #include <omp.h> int main(int argc, char **argv) { if (argc < 4) { printf("###############################\n"); printf("USAGE:\n"); printf("slope_mp.exe input_dem.tif output.tif div\n"); printf("###############################\n"); exit(1); } GDALDataset *poDataset; const float degrees_to_radians = 3.14159 / 180.0; const float radians_to_degrees = 180.0 / 3.14159; double adfGeoTransform[6]; const char *pszFilename = argv[1]; const char *pszSlopeFilename = argv[2]; int divmax = atoi(argv[3]); int R = 10; GDALAllRegister(); poDataset = (GDALDataset *) GDALOpen(pszFilename, GA_ReadOnly); GDALRasterBand *poBand; poBand = poDataset->GetRasterBand(1); poDataset->GetGeoTransform(adfGeoTransform); const double cellsizeY = adfGeoTransform[5]; const double cellsizeX = adfGeoTransform[1]; const float nullValue = -9999; const int nXSize = poBand->GetXSize(); const int nYSize = poBand->GetYSize(); const int celln = ceil(R * 2 / cellsizeX); const int pcell = (celln + 1) / 2; GDALDriver *poDriver; poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); GDALDataset *poSlopeDS; GDALRasterBand *poSlopeBand; char **papszOptions = NULL; papszOptions = CSLSetNameValue(papszOptions, "PROFILE", "GeoTIFF"); poSlopeDS = poDriver->Create(pszSlopeFilename, nXSize, nYSize, 1, GDT_Float32, papszOptions); poSlopeDS->SetGeoTransform(adfGeoTransform); poSlopeDS->SetProjection(poDataset->GetProjectionRef()); poSlopeBand = poSlopeDS->GetRasterBand(1); poSlopeBand->SetNoDataValue(-9999); int percent[11]; for (int i = 0; i <= 10; i++) { percent[i] = nXSize * nYSize * 0.1 * i; } int start[100], end[100]; for (int i = 0; i < divmax; i++) { start[i] = i * nYSize / divmax - celln; end[i] = (i + 1) * nYSize / divmax - celln; if (i == 0) start[i] = 0; } float win[10000]; float SlopeBuf[50000]; int p = 0; int strp = 0; for (int div = 0; div < divmax; div++) { float *bigwin = (float *) VSIMalloc3((end[div] - start[div] + celln), nXSize, sizeof(float)); if (bigwin == NULL) { printf("### Please gain div count. ###\n"); exit(1); } poBand->RasterIO(GF_Read, 0, start[div], nXSize, (end[div] - start[div] + celln), bigwin, nXSize, (end[div] - start[div] + celln), GDT_Float32, 0, 0); #pragma omp parallel for firstprivate(win,SlopeBuf) for (int i = start[div]; i < end[div]; i++) { for (int j = 0; j < nXSize; j++) { #pragma omp critical { if (p >= percent[strp]) { printf("%d%s", strp * 10, "..."); strp++; } p++; } if (i > nYSize - celln || j > nXSize - celln) { SlopeBuf[j] = nullValue; continue; } for (int ii = 0; ii < celln; ii++) { for (int jj = 0; jj < celln; jj++) { win[ii * celln + jj] = bigwin[((i - start[div] + ii) * nXSize + j) + jj]; } } float dx = ((win[celln * (pcell - 2) + pcell - 2] + win[celln * (pcell - 1) + pcell - 2] + win[celln * (pcell) + pcell - 2]) - (win[celln * (pcell - 2) + pcell] + win[celln * (pcell - 1) + pcell] + win[celln * (pcell) + pcell - 2])) / (6 * cellsizeX); float dy = ((win[celln * (pcell - 2) + pcell - 2] + win[celln * (pcell - 2) + pcell - 1] + win[celln * (pcell - 2) + pcell]) - (win[celln * (pcell) + pcell - 2] + win[celln * (pcell) + pcell - 1] + win[celln * (pcell) + pcell])) / (6 * cellsizeY); SlopeBuf[j] = atan(sqrt(dx * dx + dy * dy)) * radians_to_degrees; } poSlopeBand->RasterIO(GF_Write, pcell - 1, pcell - 1 + i, nXSize - (pcell - 1), 1, SlopeBuf, nXSize - (pcell - 1), 1, GDT_Float32, 0, 0); } VSIFree(bigwin); } delete poBand; delete poSlopeDS; return 0; }
5.OpenMPãªãã·ã§ã³ã§ã³ã³ãã¤ã«ãããã¦å®è¡
OpenMPãªãã·ã§ã³ã¨gdalã®ã©ã¤ãã©ãªããªã³ã¯ãã¦ã³ã³ãã¤ã«
cl /EHsc /openmp -IC:\warmerda\bld\include C:\warmerda\bld\lib\gdal_i.lib dem.cpp