/usr/include/terralib/kernel/TeRasterTransform.h is in libterralib-dev 4.0.0-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | /************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
You should have received a copy of the GNU Lesser General Public
License along with this library.
The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/*! \file TeRasterTransform.h
\brief This file deals with the transformation functions over raster pixels
*/
#ifndef __TERRALIB_INTERNAL_RASTERTRANSFORM_H
#define __TERRALIB_INTERNAL_RASTERTRANSFORM_H
#include "TeRaster.h"
#include "TeLegendEntry.h"
#include <map>
#include <vector>
using namespace std;
//! This class defines a way of evaluating the final value of a raster element
class TL_DLL TeRasterTransform
{
public:
//! The three channels of a display
enum TeRGBChannels { TeREDCHANNEL=0, TeGREENCHANNEL=1, TeBLUECHANNEL=2 };
enum TeRasterTransfFunctions
{ TeNoTransf=0, TeMono2Three=1, TeBand2Band=2, TePall2Three=3, TeLUT2Three=4,
TeExtractRGB=5, TeExtractBand=6, TeExtractBands=7, TeThreeBand2RGB=8,
TeThree2LUTThreeBand=9, TeMono2LUTMonoBand=10
};
//! One of the available transformation methods
typedef void (TeRasterTransform::*TransformFunction)(double, double, double, double);
private:
TeRaster* rasterIn_;
TeRaster* rasterOut_;
double gain_, offset_;
map<TeRGBChannels,short> rgbmap_;
short mband_, mbout_;
TransformFunction transfFuncPtr_;
double rmin_, rmax_;
int lutSize_;
double contrastR_, contrastG_, contrastB_;
double contrastM_;
unsigned int transp_;
std::string lutTable_;
public:
vector<unsigned char> lutr_;
vector<unsigned char> lutg_;
vector<unsigned char> lutb_;
//! Constructor
TeRasterTransform(TeRaster* rIn=0, TeRaster* rOut=0):
rasterIn_(rIn),
rasterOut_(rOut),
gain_(1),
offset_(0),
mband_(0),
mbout_(0),
transfFuncPtr_(&TeRasterTransform::Band2Band),
rmax_(TeMAXFLOAT),
lutSize_(0),
contrastR_(1.0),
contrastG_(1.0),
contrastB_(1.0),
contrastM_(1.0),
transp_(255),
lutTable_("")
{
rmin_ = -1 * TeMAXFLOAT;
}
//! Destructor
~TeRasterTransform()
{
lutr_.clear();
lutb_.clear();
lutg_.clear();
rgbmap_.clear();
transfFuncPtr_ = 0;
}
//! Sets the size of the LUT being used
void setLutSize(int n)
{ lutSize_ = n; }
//! Gets the size of the LUT being used
int getLutSize()
{ return lutSize_; }
//! Sets the input raster
void setRasterIn(TeRaster* rIn)
{ rasterIn_ = rIn; }
//! Sets the input raster
void setRasterOut(TeRaster* rOut)
{ rasterOut_ = rOut; }
//! Sets the gain
void setGain(double g)
{ gain_= g; }
//! Gets the gain
double getGain() const
{ return gain_; }
//! Sets the offset
void setOffset(double o)
{ offset_= o; }
//! Gets the offset
double getOffset() const
{ return offset_; }
//! Sets the transformation method to be used
void setTransfFunction(TeRasterTransform::TransformFunction transfFuncPtr)
{ transfFuncPtr_ = transfFuncPtr; }
//! Sets the mapping from bands to R,G and B channels
void setRGBmap (map<TeRGBChannels,short>& rgbmap)
{
rgbmap_.clear();
rgbmap_[TeREDCHANNEL] = -1;
rgbmap_[TeGREENCHANNEL] = -1;
rgbmap_[TeBLUECHANNEL] = -1;
map<TeRGBChannels,short>::iterator it = rgbmap.begin();
while (it != rgbmap.end())
{
if (it->first == TeREDCHANNEL)
rgbmap_[TeREDCHANNEL] = it->second;
else if (it->first == TeGREENCHANNEL)
rgbmap_[TeGREENCHANNEL] = it->second;
else if (it->first == TeBLUECHANNEL)
rgbmap_[TeBLUECHANNEL] = it->second;
++it;
}
}
//! Sets the mapping from a particular input band to a particular output channel
void setBChannelMapping(short bIn, TeRGBChannels bOut)
{
rgbmap_[bOut] = bIn;
}
//! Clears current mapping from bands to channel
void clearRGBMap()
{
rgbmap_.clear();
}
//! Returns the mapping from a particular input band to a particular output channel
map<TeRGBChannels,short>& getRGBMap()
{
return rgbmap_;
}
//! Sets the mono band to be transformed
void setSrcBand(short n)
{ mband_ = n; }
//! Gets the mono band to be transformed
short getSrcBand()
{ return mband_; }
//! Sets the destination of the mono band
void setDestBand(short n)
{ mbout_ = n; }
//! Gets the destination of the mono band
short getDestBand()
{ return mbout_; }
//! Generates a LUT with nentries to display the vector of legends
void generateLUT(TeLegendEntryVector& legs, unsigned int nentries, TeColor& backColor);
//! Set parameters of linear transformation
/*!
\param vmin smallest input value
\param vmax largest input value
\param rmin smallest value of the output range
\param rmax largest value of the output range
*/
void setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax)
{
rmin_ = rmin;
rmax_ = rmax;
gain_ = (double)(rmax-rmin)/(vmax-vmin);
offset_ = -1*gain_*vmin+rmin;
}
//--- Simple contrast linear factors
void setContrastR(double cR)
{ contrastR_ = cR; }
void setContrastG(double cG)
{ contrastG_ = cG; }
void setContrastB(double cB)
{ contrastB_ = cB; }
void setContrastM(double cM)
{ contrastM_ = cM; }
double getContrastR()
{ return contrastR_; }
double getContrastG()
{ return contrastG_; }
double getContrastB()
{ return contrastB_; }
double getContrastM()
{ return contrastM_; }
void setTransparency(unsigned int transp)
{ transp_ = transp; }
unsigned int getTransparency()
{ return transp_; }
//-- Lut Table
void setLutTableName(const std::string& tableName)
{ lutTable_ = tableName; }
std::string getLutTableName()
{ return lutTable_; }
//---
//! Applies the selected transformation method
void apply(double icol, double ilin, double ocol, double olin)
{ (this->*transfFuncPtr_)(icol,ilin,ocol,olin); }
//! Returns the identifier of the transformation function currently set
TeRasterTransfFunctions getTransfFunction();
//! Sets the associated transformation function from an identifier
void setTransfFunction(TeRasterTransfFunctions func);
// --- The transformation functions available ----
//! This transformation repeats the value of the first band in input three bands of the output
void Mono2ThreeBand(double icol, double ilin, double ocol, double olin)
{
double val;
if (rasterIn_->getElement((int)icol,(int)ilin,val,mband_))
{
val = (val*gain_ + offset_)*contrastM_;
if (val < rmin_)
val = rmin_;
else if (val > rmax_)
val = rmax_;
rasterOut_->setElement((int)ocol,(int)olin, val, val, val, transp_);
}
}
//! This transformation repeats the value of each band in input to the same band in output
void Band2Band(double icol, double ilin, double ocol, double olin)
{
double val;
int n = rasterOut_->params().nBands();
for (int i=0; i<n; i++)
if (rasterIn_->getElement((int)icol,(int)ilin,val,i))
{
val = val*gain_ + offset_;
if (val < rmin_)
val = rmin_;
else if (val > rmax_)
val = rmax_;
rasterOut_->setElement((int)ocol,(int)olin,val,i);
}
}
//! This transformation repeats the value of the raster LUT in input to the first 3 bands of output
void Pallete2ThreeBand(double icol, double ilin, double ocol, double olin)
{
double val;
if (rasterIn_->getElement((int)icol,(int)ilin,val))
{
if (val>= 0 && (unsigned int)val < rasterIn_->params().lutr_.size())
{
rasterOut_->setElement((int)ocol,(int)olin,rasterIn_->params().lutr_[(int)val],
rasterIn_->params().lutg_[(int)val],
rasterIn_->params().lutb_[(int)val], transp_);
}
}
}
//! This transformation repeats the value of the first band in input three bands of the output
void ThreeBand2RGB(double icol, double ilin, double ocol, double olin)
{
double valR, valG, valB;
bool flag = rasterIn_->getElement((int)icol,(int)ilin,valR,0);
flag = rasterIn_->getElement((int)icol,(int)ilin,valG,1) || flag;
flag = rasterIn_->getElement((int)icol,(int)ilin,valB,2) || flag;
if (flag)
rasterOut_->setElement((int)ocol,(int)olin, (valR*gain_ + offset_)*contrastR_,
(valG*gain_ + offset_)*contrastG_,
(valB*gain_ + offset_)*contrastB_, transp_);
}
//! This transformation repeats the value of an external LUT to the first 3 bands of output
void LUT2ThreeBand(double icol, double ilin, double ocol, double olin)
{
double idx, val;
if (rasterIn_->getElement((int)icol,(int)ilin,val,mband_))
{
idx = (val*gain_) + offset_;
if (idx >= 0 && idx < lutSize_)
{
rasterOut_->setElement((int)ocol,(int)olin,lutr_[(int)idx]*contrastR_,
lutg_[(int)idx]*contrastG_,
lutb_[(int)idx]*contrastB_, transp_);
}
}
}
void ThreeBand2LUTThreeBand(double icol, double ilin, double ocol, double olin)
{
double idxR, valR;
double idxG, valG;
double idxB, valB;
double outR = 0.;
double outG = 0.;
double outB = 0.;
if(rgbmap_.empty())
{
return;
}
bool flag = rasterIn_->getElement((int)icol,(int)ilin,valR,rgbmap_[TeREDCHANNEL]);
idxR = (valR*gain_) + offset_;
if (idxR >= 0 && idxR < lutSize_)
{
outR = lutr_[(int)idxR]*contrastR_;
}
flag = rasterIn_->getElement((int)icol,(int)ilin,valG,rgbmap_[TeGREENCHANNEL]) || flag;
idxG = (valG*gain_) + offset_;
if (idxG >= 0 && idxG < lutSize_)
{
outG = lutg_[(int)idxG]*contrastG_;
}
flag = rasterIn_->getElement((int)icol,(int)ilin,valB,rgbmap_[TeBLUECHANNEL]) || flag;
idxB = (valB*gain_) + offset_;
if (idxB >= 0 && idxB < lutSize_)
{
outB = lutb_[(int)idxB]*contrastB_;
}
if (flag)
rasterOut_->setElement((int)ocol,(int)olin, outR, outG, outB, transp_);
}
void MonoBand2LUTMonoBand(double icol, double ilin, double ocol, double olin)
{
double idxMono, valMono;
double outMono = 0.;
bool flag = rasterIn_->getElement((int)icol,(int)ilin,valMono,mband_);
if(flag)
{
idxMono = (valMono*gain_) + offset_;
if (idxMono >= 0 && idxMono < lutSize_)
outMono = lutr_[(int)idxMono]*contrastM_;
rasterOut_->setElement((int)ocol,(int)olin, outMono, outMono, outMono, transp_);
}
}
// This transformation is used to define a particular mapping from input bands to RGB channels
void ExtractRGB(double icol, double ilin, double ocol, double olin)
{
double valR, valG, valB;
bool flag = rasterIn_->getElement((int)icol,(int)ilin,valR,rgbmap_[TeREDCHANNEL]);
flag = rasterIn_->getElement((int)icol,(int)ilin,valG,rgbmap_[TeGREENCHANNEL]) || flag;
flag = rasterIn_->getElement((int)icol,(int)ilin,valB,rgbmap_[TeBLUECHANNEL]) || flag;
if (flag)
rasterOut_->setElement((int)ocol,(int)olin, (valR*gain_ + offset_)*contrastR_,
(valG*gain_ + offset_)*contrastG_,
(valB*gain_ + offset_)*contrastB_, transp_);
}
//! This transformation repeats the value of a particular band in input to a particular band of the output
void ExtractBand(double icol, double ilin, double ocol, double olin)
{
double val;
if (rasterIn_->getElement((int)icol,(int)ilin,val,mband_))
{
val = val*gain_ + offset_;
if (val < rmin_)
val = rmin_;
else if (val > rmax_)
val = rmax_;
rasterOut_->setElement((int)ocol,(int)olin,val*contrastM_,mbout_);
}
}
// This transformation extracts selected bands of the input raster and
// writes each to a particular band of the output
void ExtractBands(double icol, double ilin, double ocol, double olin)
{
double val;
int bOut;
if (rgbmap_[TeREDCHANNEL] != -1)
{
bOut = 0;
if (rasterIn_->getElement((int)icol,(int)ilin,val,rgbmap_[TeREDCHANNEL]))
rasterOut_->setElement((int)ocol,(int)olin,val*contrastR_,bOut);
}
if (rgbmap_[TeGREENCHANNEL] != -1)
{
bOut = 1;
if (rasterIn_->getElement((int)icol,(int)ilin,val,rgbmap_[TeGREENCHANNEL]))
rasterOut_->setElement((int)ocol,(int)olin,val*contrastG_,bOut);
}
if (rgbmap_[TeBLUECHANNEL] != -1)
{
bOut = 2;
if (rasterIn_->getElement((int)icol,(int)ilin,val,rgbmap_[TeBLUECHANNEL]))
rasterOut_->setElement((int)ocol,(int)olin,val*contrastB_,bOut);
}
}
};
#endif
|