#ifndef _OTB_TRISKELE_I_IMAGE_TPP #define _OTB_TRISKELE_I_IMAGE_TPP // ======================================== template inline void Raster::setSize (const Size &size) { DEF_LOG ("Raster::setSize", "size: " << size); if (this->size == size) return; pixels.resize (DimImg (size.width)*DimImg (size.height)); this->size = size; } template inline const Size & Raster::getSize () const { return size; } template inline const PixelT * Raster::getPixels () const { return &pixels[0]; } template inline PixelT * Raster::getPixels () { return &pixels[0]; } template inline vector & Raster::getPixelsVector () { return pixels; } template inline DimNodeId Raster::pointIdx (const Point &p) const { return point2idx (size, p); } template inline PixelT Raster::getValue (const DimImg &idx) const { return pixels[idx]; } template inline PixelT Raster::getValue (const Point &point) const { return pixels [pointIdx (point)]; } template inline Raster::Raster (const Size &size) : size (NullSize), pixels () { setSize (size); } template inline Raster::Raster (const Raster &raster, const Rect &tile) : size (tile.width, tile.height), pixels () { tile.cpToTile (raster.size, &raster.pixels[0], pixels); } template inline Raster::~Raster () { } // ======================================== inline void IImage::setFileName (string fileName) { if (this->fileName == fileName) return; this->fileName = fileName; if (read) close (); } inline void IImage::getGeo (string& projectionRef, vector &geoTransform) const { projectionRef = this->projectionRef; geoTransform = this->geoTransform; } inline void IImage::setGeo (const string& projectionRef, vector geoTransform, const Point &topLeft) { DEF_LOG ("IImage::setGeo", "projectionRef:" << projectionRef); // move TopLeft cf WordFile double x (geoTransform[0]), xScale (geoTransform[1]), xSkew (geoTransform[2]), y (geoTransform[3]), ySkew (geoTransform[4]), yScale (geoTransform[5]); double xTrans = x + topLeft.x*xScale + topLeft.y*xSkew, yTrans = y + topLeft.x*ySkew + topLeft.y*yScale; geoTransform[0] = xTrans; geoTransform[3] = yTrans; CPLErr err = gdalOutputDataset->SetGeoTransform (&geoTransform[0]); if (err != CE_None) cerr << "IImage::setGeo: can't set geoTransform for " << fileName << endl; err = gdalOutputDataset->SetProjection (projectionRef.c_str ()); if (err != CE_None) cerr << "IImage::setGeo: can't set projection for " << fileName << endl; } inline const string & IImage::getFileName () const { return fileName; } inline const Size & IImage::getSize () const { return size; } inline const DimChanel & IImage::getBandCount () const { return bandCount; } inline GDALDataType IImage::getDataType () const { return dataType; } inline const bool IImage::isRead () const { return read; } inline const bool IImage::isEmpty () const { return size == NullSize; } // ======================================== template inline void IImage::readBand (Raster &raster, const DimChanel &band) const { readBand (raster, band, NullPoint, size); } template inline void IImage::readBand (Raster &raster, DimChanel band, const Point &cropOrig, const Size &cropSize) const { DEF_LOG ("IImage::readBand", "band: " << band << " crop: " << cropOrig << " - " << cropSize); BOOST_ASSERT (gdalInputDataset); raster.setSize (cropSize); band++; // !!! GDAL bands start at 1 (not 0 :-( ) GDALRasterBand &poBand = *gdalInputDataset->GetRasterBand (band); GDALDataType bandType = poBand.GetRasterDataType (); CPLErr err = poBand.RasterIO (GF_Read, cropOrig.x, cropOrig.y, cropSize.width, cropSize.height, raster.getPixels (), cropSize.width, cropSize.height, bandType, 0, 0); if (err != CE_None) cerr << "IImage::readBand: can't acces " << fileName << endl; } template inline void IImage::writeBand (PixelT *pixels, DimChanel band) const { DEF_LOG ("IImage::writeBand", "band: " << band); BOOST_ASSERT (gdalOutputDataset); band++; // !!! GDAL layers starts at 1 (not 0 :-( ) GDALRasterBand &poBand = *gdalOutputDataset->GetRasterBand (band); CPLErr err = poBand.RasterIO (GF_Write, 0, 0, size.width, size.height, pixels, size.width, size.height, dataType, 0, 0); if (err != CE_None) cerr << "IImage::writeBand: can't acces " << fileName << endl; } #endif // _OTB_TRISKELE_I_IMAGE_TPP