28 #include "itksys/SystemTools.hxx"
36 #include "otbLogo.inc"
105 itkDebugMacro(<<
"No filename specified.");
109 std::string filename = file;
110 std::string::size_type gmPos = filename.rfind(
".otb");
112 if ((gmPos != std::string::npos)
113 && (gmPos == filename.length() - 4))
119 else if (filename.find(
"http://") == 0)
137 unsigned char * p =
static_cast<unsigned char *
>(buffer);
140 itkExceptionMacro(<<
"Memory allocation error");
149 int nTilesX = (int) ceil(totSamples / static_cast<double>(
m_TileSize)) + 1;
150 int nTilesY = (int) ceil(totLines / static_cast<double>(
m_TileSize)) + 1;
159 for (
int numTileY = 0; numTileY < nTilesY; numTileY++)
161 for (
int numTileX = 0; numTileX < nTilesX; numTileX++)
166 std::string lFilename;
195 std::ostringstream quad2;
198 std::ostringstream filename;
207 lTileInfos.
filename = filename.str();
219 bool fileExists = itksys::SystemTools::FileExists(filename.c_str(),
true);
227 return imageIO->CanReadFile(filename.c_str());
235 std::ostringstream urlStream;
240 std::ostringstream quad;
244 urlStream << quad.str();
252 urlStream << (
long int) (((
double) x * (1 << m_Depth)));
254 urlStream << (
long int) (((
double) y * (1 <<
m_Depth)));
261 urlStream <<
"hl=en&x=";
262 urlStream << vcl_floor(x * (1 <<
m_Depth));
264 urlStream << vcl_floor(y * (1 <<
m_Depth));
267 urlStream <<
"&nml=Vert&s=Ga";
272 std::ostringstream quad, filename;
276 urlStream << filename.str();
280 itkExceptionMacro(<<
"TileMapImageIO : Bad addressing Style");
299 for (
unsigned int currentTile = 0; currentTile <
m_ListTiles.size(); currentTile++)
308 for (
int tileJ = 0; tileJ <
m_TileSize; tileJ++)
310 long int yImageOffset = (
long int) (m_TileSize * floor(firstLine / static_cast<double>(m_TileSize)) + m_TileSize * numTileY - firstLine + tileJ);
311 if ((yImageOffset >= 0) && (yImageOffset < totLines))
313 long int xImageOffset = (
long int)
314 (m_TileSize * floor(firstSample / static_cast<double>(m_TileSize)) + m_TileSize * numTileX - firstSample);
315 unsigned char * dst = p + nComponents * (xImageOffset + totSamples * yImageOffset);
316 unsigned char * src = bufferTile + nComponents * m_TileSize * tileJ;
319 if (xImageOffset < 0)
321 dst -= nComponents * xImageOffset;
322 src -= nComponents * xImageOffset;
323 size += nComponents * xImageOffset;
325 if (xImageOffset + m_TileSize > totSamples)
327 size += nComponents * (totSamples - xImageOffset -
m_TileSize);
331 memcpy(dst, src, size);
345 unsigned char * bufferCacheFault =
NULL;
350 bool lCanRead = imageIO->CanReadFile(filename.c_str());
352 if (lCanRead ==
true)
354 imageIO->SetFileName(filename.c_str());
355 imageIO->ReadImageInformation();
361 imageIO->SetIORegion(ioRegion);
363 imageIO->Read(buffer);
367 if (bufferCacheFault ==
NULL)
379 int quadsize = quad.str().size();
380 std::ostringstream directory;
387 while ((i < 8) && (i < quadsize))
390 directory << (quad.str().c_str())[i];
394 itksys::SystemTools::MakeDirectory(directory.str().c_str());
396 filename << directory.str();
399 filename << quad.str();
421 itkExceptionMacro(<<
"TileMap read : empty image file name file.");
431 std::ifstream file(
m_FileName.c_str(), std::ifstream::in);
435 itkExceptionMacro(<<
"Can't read server name from file");
439 std::getline(file, mode);
440 switch (atoi(mode.c_str()))
455 itkExceptionMacro(<<
"Addressing style unknown");
465 itkExceptionMacro(<<
"Can't read server name from file");
467 std::string osmServer =
"http://tile.openstreetmap.org/";
468 std::string nmServer =
"http://www.nearmap.com/maps/";
469 std::string otbServer1 =
"http://tile.orfeo-toolbox.org/hillShade/";
513 itkDebugMacro(<<
"No filename specified.");
518 std::string filename = name;
519 std::string::size_type gmPos = filename.rfind(
".otb");
520 if ((gmPos != std::string::npos)
521 && (gmPos == filename.length() - 3))
535 const unsigned char * p =
static_cast<const unsigned char *
>(buffer);
538 itkExceptionMacro(<<
"Memory allocation error");
552 int originLine = (int) this->
GetOrigin(1);
553 int originSample = (int) this->
GetOrigin(0);
556 otbMsgDevMacro(<<
"TileMapImageIO::Write: Size " << totLines <<
", " << totSamples);
557 otbMsgDevMacro(<<
"TileMapImageIO::Write: Index " << firstLine <<
", " << firstSample);
558 otbMsgDevMacro(<<
"TileMapImageIO::Write: Origin " << originLine <<
", " << originSample);
564 otbMsgDevMacro(<<
" sizeof(streamsize) : " <<
sizeof(std::streamsize));
565 otbMsgDevMacro(<<
" sizeof(streampos) : " <<
sizeof(std::streampos));
566 otbMsgDevMacro(<<
" sizeof(streamoff) : " <<
sizeof(std::streamoff));
567 otbMsgDevMacro(<<
" sizeof(std::ios::beg) : " <<
sizeof(std::ios::beg));
569 otbMsgDevMacro(<<
" sizeof(unsigned long) : " <<
sizeof(
unsigned long));
574 otbMsgDevMacro(<<
"Number of tile to process " << nTilesX <<
"x" << nTilesY);
579 for (
int numTileY = 0; numTileY < nTilesY; numTileY++)
581 for (
int numTileX = 0; numTileX < nTilesX; numTileX++)
587 bufferTile[iInit] = 0;
590 for (
int tileJ = 0; tileJ <
m_TileSize; tileJ++)
592 long int yImageOffset = (
long int) (m_TileSize * floor((originLine + firstLine) / static_cast<double>(m_TileSize))
593 + m_TileSize * numTileY - (originLine + firstLine) + tileJ);
594 if ((yImageOffset >= 0) && (yImageOffset < totLines))
596 long int xImageOffset = (
long int)
598 floor((originSample +
599 firstSample) /
static_cast<double>(
m_TileSize)) + m_TileSize * numTileX - (originSample + firstSample));
600 unsigned char * dst = bufferTile + nComponents * m_TileSize * tileJ;
601 const unsigned char * src = p + nComponents * (xImageOffset + totSamples * yImageOffset);
603 if (xImageOffset < 0)
605 src -= nComponents * xImageOffset;
606 dst -= nComponents * xImageOffset;
607 size += nComponents * xImageOffset;
609 if (xImageOffset + m_TileSize > totSamples)
611 size += nComponents * (totSamples - xImageOffset -
m_TileSize);
615 memcpy(dst, src, size);
621 double xTile = (originSample + firstSample + m_TileSize * numTileX) / ((1 <<
m_Depth) *
static_cast<double>(
m_TileSize));
622 double yTile = (originLine + firstLine + m_TileSize * numTileY) / ((1 <<
m_Depth) *
static_cast<double>(
m_TileSize));
636 std::ostringstream quad;
642 std::ostringstream filename;
647 bool lCanWrite = imageIO->CanWriteFile(filename.str().c_str());
652 itksys::SystemTools::RemoveFile(filename.str().c_str());
654 imageIO->CanStreamWrite();
655 imageIO->SetNumberOfDimensions(2);
658 imageIO->SetSpacing(0, 1);
659 imageIO->SetSpacing(1, 1);
660 imageIO->SetOrigin(0, 0);
661 imageIO->SetOrigin(1, 0);
662 imageIO->SetNumberOfComponents(3);
664 vnl_vector<double> axisDirection(2);
666 axisDirection[0] = 1;
667 axisDirection[1] = 0;
668 imageIO->SetDirection(0, axisDirection);
669 axisDirection[0] = 0;
670 axisDirection[1] = 1;
671 imageIO->SetDirection(1, axisDirection);
673 imageIO->SetUseCompression(1);
675 imageIO->SetFileName(filename.str().c_str());
676 imageIO->WriteImageInformation();
679 for (
unsigned int i = 0; i < 2; ++i)
685 imageIO->SetIORegion(ioRegion);
687 imageIO->Write(buffer);
691 itkExceptionMacro(<<
"TileMap write : bad file name.");
705 int quad_index = ((x >= 0.5 ? 1 : 0) + (y >= 0.5 ? 2 : 0));
739 int quad_index = ((x >= 0.5 ? 1 : 0) + (y >= 0.5 ? 2 : 0));
769 RegionType tileMapRegion;
770 RegionType::IndexType index;
774 return m_TileMapSplitter->GetNumberOfSplits(tileMapRegion, numberOfRequestedSplits);
779 unsigned int numberOfActualSplits,
783 RegionType tileMapRegion;
784 RegionType::IndexType index;
790 numberOfActualSplits,
791 tileMapRegion), returnRegion, index);
801 for (
int col = 0; col < m_TileSize/64; col++)
803 memcpy(((
unsigned char *) buffer) + line * m_TileSize * 3 + 64 * 3 * col,
804 kLogoOtb + (line % 64) * 64 * 3,
820 if ( itksys::SystemTools::FileIsDirectory( _arg ) )
822 std::ostringstream oss;
824 if( itksys::SystemTools::Touch( oss.str().c_str(), true ) ==
false )
826 itkExceptionMacro(
"Error, no write permission in given CacheDirectory "<<_arg<<
".");
830 itksys::SystemTools::RemoveFile( oss.str().c_str() );
834 else if( itksys::SystemTools::FileExists(_arg) == true )
836 itkExceptionMacro(
"Error, given CacheDirectory "<<_arg<<
" is an existing file.");
839 else if( itksys::SystemTools::MakeDirectory( _arg ) ==
false )
841 itkExceptionMacro(
"Error, no permission to create the given CacheDirectory "<<_arg<<
".");
845 itksys::SystemTools::RemoveADirectory( _arg );