otbImageWidgetBase.txx 14.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
18 19
#ifndef __otbImageWidgetBase_txx
#define __otbImageWidgetBase_txx
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
#include "itkImageRegionConstIterator.h"
#include "itkMacro.h"
#include "otbMacro.h"

namespace otb
{
/**
 * Constructor.
 */
template <class TPixel>
ImageWidgetBase<TPixel>
::ImageWidgetBase()
  : Fl_Gl_Window(0,0,0,0,0)
{
  m_Image = NULL;
  m_OpenGlIsotropicZoom = 1.0;
  SizeType size;
  size.Fill(0);
  IndexType index;
  index.Fill(0);
  RegionType region;
  region.SetSize(size);
  region.SetIndex(index);
  m_BufferedRegion = region;
  m_ViewedRegion = region;
Julien Michel's avatar
Julien Michel committed
47
  m_ViewModel=RGB;
48 49 50 51 52 53 54 55 56 57 58
  m_RedChannelIndex = 0;
  m_GreenChannelIndex = 1;
  m_BlueChannelIndex = 2;
  m_OpenGlBuffer = NULL;
  m_FormOverlayVisible = false;
  m_ImageOverlayVisible = false;
  m_BlackTransparency = false;
  m_FormList = FormListType::New();
  m_ImageOverlay = NULL;
  m_OpenGlImageOverlayBuffer = NULL;
  m_ImageOverlayOpacity = 128;
Julien Michel's avatar
Julien Michel committed
59 60
  m_TransferFunctionList = TransferFunctionListType::New();
  m_TransferFunctionList->PushBack(AffineTransferFunctionType::New());
Cyrille Valladeau's avatar
Cyrille Valladeau committed
61
  m_SubSamplingRate = 1;
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
}
/**
 * Destructor.
 */
template <class TPixel>
ImageWidgetBase<TPixel>
::~ImageWidgetBase()
{
  if(m_OpenGlBuffer != NULL)
    {
      delete [] m_OpenGlBuffer;
    }
  if(m_OpenGlImageOverlayBuffer != NULL)
    {
      delete [] m_OpenGlImageOverlayBuffer;
    }
}
/** 
 * Reset the widget.
 */
template <class TPixel>
void 
ImageWidgetBase<TPixel>
::Reset(void)
{
  int x = this->x();
  int y = this->y();
  int w = this->w();
  int h = this->h();
  const char * label = this->label();
92 93 94 95 96 97 98 99 100
  ClearBufferedRegion();
  Init(x,y,w,h,label);
}

template <class TPixel>
void 
ImageWidgetBase<TPixel>
::ClearBufferedRegion(void)
{
Julien Michel's avatar
Oubli.  
Julien Michel committed
101 102 103
  SizeType size;
  size.Fill(0);
  m_BufferedRegion.SetSize(size);
104 105 106 107
}


template <class TPixel>
Emmanuel Christophe's avatar
Emmanuel Christophe committed
108 109 110
    void 
    ImageWidgetBase<TPixel>
  ::Init(int x, int y, int w, int h, const char * l)
111 112
{
  for(unsigned int i = 0; i<m_Image->GetNumberOfComponentsPerPixel();++i)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
113 114
  {
    if(i>=m_TransferFunctionList->Size())
115
    {
Emmanuel Christophe's avatar
Emmanuel Christophe committed
116
      m_TransferFunctionList->PushBack(AffineTransferFunctionType::New());
117
    }
Emmanuel Christophe's avatar
Emmanuel Christophe committed
118
  }
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
}

/**
 * Convert window to image coordinate.
 * \param index The window coordinate.
 * \return The image coordinate.
 */
template <class TPixel>
typename ImageWidgetBase<TPixel>
::IndexType
ImageWidgetBase<TPixel>
::WindowToImageCoordinates(IndexType index)
{
  double x,y;
  IndexType resp;
  IndexType origin = this->GetViewedRegion().GetIndex();
  x = static_cast<double>(index[0])/m_OpenGlIsotropicZoom
Emmanuel Christophe's avatar
Emmanuel Christophe committed
136
      +static_cast<double>(origin[0]);
137
  y = static_cast<double>(origin[1])
Emmanuel Christophe's avatar
Emmanuel Christophe committed
138
      +static_cast<double>(index[1])/m_OpenGlIsotropicZoom;
139 140 141 142 143

  SizeType maxSize = this->GetInput()->GetLargestPossibleRegion().GetSize();
  IndexType maxIndex = this->GetInput()->GetLargestPossibleRegion().GetIndex();

  if(x<maxIndex[0])
Emmanuel Christophe's avatar
Emmanuel Christophe committed
144 145 146
  {
    resp[0]=maxIndex[0];
  }
147
  else if(x>maxIndex[0]+maxSize[0])
Emmanuel Christophe's avatar
Emmanuel Christophe committed
148 149 150
  {
    resp[0] = maxIndex[0]+maxSize[0];
  }
151
  else
Emmanuel Christophe's avatar
Emmanuel Christophe committed
152 153 154
  {
    resp[0]=static_cast<int>(x);
  }
155
  
156
  if(y<maxIndex[1])
Emmanuel Christophe's avatar
Emmanuel Christophe committed
157 158
  {
    resp[1]=maxIndex[1];
159
      
Emmanuel Christophe's avatar
Emmanuel Christophe committed
160
  }
161
  else if(y>maxIndex[1]+maxSize[1])
Emmanuel Christophe's avatar
Emmanuel Christophe committed
162 163 164
  {
    resp[1] = maxIndex[1]+maxSize[1];
  }
165
  else
Emmanuel Christophe's avatar
Emmanuel Christophe committed
166 167 168
  {
    resp[1]=static_cast<int>(y);
  }
169 170
  return resp;
}
Emmanuel Christophe's avatar
Emmanuel Christophe committed
171

172 173 174 175 176 177 178 179 180
/** Set the input image.
 * \param image The image to view.
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::SetInput(ImageType * image)
{
  m_Image=image;
181
  m_Image->UpdateOutputInformation();
182 183 184
  SizeType size;
  size.Fill(0);
  m_BufferedRegion.SetSize(size);
185 186 187 188 189
  SizeType displaySize;
  displaySize[0]=this->w();
  displaySize[1]=this->h();
  m_ViewedRegion.SetSize(displaySize);
  m_ViewedRegion.Crop(m_Image->GetLargestPossibleRegion());
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
}
/** Get the input image.
 * \return The image to view.
 */
template <class TPixel>
typename ImageWidgetBase<TPixel>
::ImageType *
ImageWidgetBase<TPixel>
::GetInput(void)
{
  return m_Image;
}

/** Set the input overlay image.
 * \param image The image to view.
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
209
::SetInputOverlay(OverlayImageType * image)
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
{
  m_ImageOverlay=image;
}

/** Set the input overlay form list.
 * \param image The form list to view.
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::SetFormListOverlay(FormListType* formList)
{
  m_FormList = formList;
}

Jordi Inglada's avatar
Jordi Inglada committed
225 226
/** Set the transfer function list
 *  \param list The transfer function list.
227 228 229 230
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
Julien Michel's avatar
Julien Michel committed
231
::SetTransferFunctionList(TransferFunctionListType * list)
232
{
Julien Michel's avatar
Julien Michel committed
233
  m_TransferFunctionList = list;
234 235
}

236 237 238 239 240
/** Get the input overlay image.
 * \return The image to view.
 */
template <class TPixel>
typename ImageWidgetBase<TPixel>
241
::OverlayImageType *
242 243 244 245 246
ImageWidgetBase<TPixel>
::GetInputOverlay(void)
{
  return m_ImageOverlay;
}
Emmanuel Christophe's avatar
Emmanuel Christophe committed
247

248 249 250 251 252 253 254 255 256
/** 
 * Show The widget. 
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::Show(void)
{ 
  if(!m_Image)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
257 258 259
  {
    itkExceptionMacro(<<"No input image !");
  }
260
  else
Emmanuel Christophe's avatar
Emmanuel Christophe committed
261
  {
262
      //otbMsgDebugMacro(<<"Zoomable widget Show");       
Emmanuel Christophe's avatar
Emmanuel Christophe committed
263
    this->show();
264
      //otbMsgDebugMacro(<<"Before redraw.");
Emmanuel Christophe's avatar
Emmanuel Christophe committed
265
    this->redraw();
266
      //otbMsgDebugMacro(<<"After redraw.");
Emmanuel Christophe's avatar
Emmanuel Christophe committed
267
  }
268
}
269 270 271 272 273 274

template <class TPixel>
unsigned char
ImageWidgetBase<TPixel>
::Normalize(PixelType value, unsigned int channelIndex)
{
Julien Michel's avatar
Julien Michel committed
275
  return m_TransferFunctionList->GetNthElement(channelIndex)->Map(value);
276 277
}

278 279 280 281 282 283 284 285
/** 
 * Draw the widget 
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::draw(void)
{
286 287 288


#ifndef MESA
Emmanuel Christophe's avatar
Emmanuel Christophe committed
289
  glDrawBuffer(GL_FRONT_AND_BACK);
290 291 292 293 294
#endif // !MESA


//   otbMsgDebugMacro(<<"Draw");

Emmanuel Christophe's avatar
Emmanuel Christophe committed
295 296 297 298 299 300 301 302
  if(this->UpdateOpenGlBufferedRegionRequested())
  {
    UpdateOpenGlBufferedRegion();
    m_Image->SetRequestedRegion(m_BufferedRegion);
    m_Image->PropagateRequestedRegion();
    m_Image->UpdateOutputData();
    RebuildOpenGlBuffer(); 
    if(m_ImageOverlayVisible)
303
    {
Emmanuel Christophe's avatar
Emmanuel Christophe committed
304 305 306
      m_ImageOverlay->SetRequestedRegion(m_BufferedRegion);
      m_ImageOverlay->PropagateRequestedRegion();
      m_ImageOverlay->UpdateOutputData();
307
    }
Emmanuel Christophe's avatar
Emmanuel Christophe committed
308
  }
Julien Michel's avatar
Julien Michel committed
309 310
 
  if(m_ImageOverlayVisible)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
311 312 313 314 315 316 317 318 319 320 321 322 323
  {
    RebuildOpenGlImageOverlayBuffer();
  }

  if (!this->valid())
  {
    valid(1);
    glLoadIdentity();
    glViewport(0,0,w(),h());
    glClearColor((float)0.0, (float)0.0, (float)0.0, (float)0.0);          
    glShadeModel(GL_FLAT);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  }
324
 
Emmanuel Christophe's avatar
Emmanuel Christophe committed
325 326 327 328 329 330
  glClear(GL_COLOR_BUFFER_BIT);    //this clears and paints to black
  glMatrixMode(GL_MODELVIEW);    //clear previous 3D draw params
  glLoadIdentity();
  glMatrixMode(GL_PROJECTION);
  this->ortho();
  glDisable(GL_BLEND);
331 332


333
  glRasterPos2i(0,this->h());
334

335 336
#ifdef GL_NO_ACCEL
  glPixelZoom(m_OpenGlIsotropicZoom ,-m_OpenGlIsotropicZoom);
337

338 339 340 341 342 343 344
  // display the image
  glDrawPixels(m_BufferedRegion.GetSize()[0],
	       m_BufferedRegion.GetSize()[1], 
	       GL_RGBA,
	       GL_UNSIGNED_BYTE, 
	       m_OpenGlBuffer);
#else
345
  glEnable(GL_TEXTURE_2D);
346 347
  glColor4f(1.0,1.0,1.0,0.0);
  GLuint texture;
348 349
  glGenTextures(1, &texture);
  glBindTexture(GL_TEXTURE_2D, texture);
350
  glTexImage2D(GL_TEXTURE_2D, 0, 3, m_BufferedRegion.GetSize()[0], m_BufferedRegion.GetSize()[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, m_OpenGlBuffer);
351 352
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);	// Nearest Filtering
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	// Nearest Filtering
353 354
//   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering
//   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering
355

356 357 358 359 360 361 362 363 364 365
  glBindTexture (GL_TEXTURE_2D, texture);
  glBegin (GL_QUADS);
  int hOffset = this->h() - this->hDisplayed();
  glTexCoord2f (0.0, 1.0);  glVertex3f (0.0, 0.0+hOffset, 0.0);
  glTexCoord2f (1.0, 1.0);  glVertex3f (this->wDisplayed(), 0.0+hOffset, 0.0);
  glTexCoord2f (1.0, 0.0);  glVertex3f (this->wDisplayed(), this->hDisplayed()+hOffset, 0.0);
  glTexCoord2f (0.0, 0.0);  glVertex3f (0.0, this->hDisplayed()+hOffset, 0.0);
  glEnd ();

  glDisable(GL_TEXTURE_2D);
366 367
#endif
  
368
 // if image overlay is activated, display image overlay
Emmanuel Christophe's avatar
Emmanuel Christophe committed
369
  if(m_ImageOverlayVisible)
370 371 372 373 374 375 376 377 378 379 380 381 382
    {
#ifdef GL_NO_ACCEL
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glDrawPixels(m_BufferedRegion.GetSize()[0],
                 m_BufferedRegion.GetSize()[1], 
		 GL_RGBA,
		 GL_UNSIGNED_BYTE, 
		 m_OpenGlImageOverlayBuffer);

    glDisable(GL_BLEND);
    glEnd();
#else
383
    glEnable(GL_BLEND);
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    GLuint textureOverlay;
    glGenTextures(1, &textureOverlay);
    glBindTexture(GL_TEXTURE_2D, textureOverlay);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, m_BufferedRegion.GetSize()[0], m_BufferedRegion.GetSize()[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, m_OpenGlImageOverlayBuffer);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);  // Nearest Filtering
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);  // Nearest Filtering
    
    glBindTexture (GL_TEXTURE_2D, textureOverlay);
    glBegin (GL_QUADS);
    int hOffset = this->h() - this->hDisplayed();
    glTexCoord2f (0.0, 1.0);  glVertex3f (0.0, 0.0+hOffset, 0.0);
    glTexCoord2f (1.0, 1.0);  glVertex3f (this->wDisplayed(), 0.0+hOffset, 0.0);
    glTexCoord2f (1.0, 0.0);  glVertex3f (this->wDisplayed(), this->hDisplayed()+hOffset, 0.0);
    glTexCoord2f (0.0, 0.0);  glVertex3f (0.0, this->hDisplayed()+hOffset, 0.0);
    glEnd ();
    glDisable(GL_TEXTURE_2D);
402
    glDisable(GL_BLEND);
403 404 405
#endif

    } 
406

Emmanuel Christophe's avatar
Emmanuel Christophe committed
407 408 409
  if(m_FormOverlayVisible)
  {
    ReverseIteratorType it =  m_FormList->ReverseBegin();
410
     //otbMsgDebugMacro(<<"Formlist size: "<<m_FormList->Size());
Emmanuel Christophe's avatar
Emmanuel Christophe committed
411 412 413 414 415 416 417 418
    for(;it!=m_FormList->ReverseEnd();++it)
    {
      it.Get()->Draw(m_OpenGlIsotropicZoom,
             m_ViewedRegion.GetIndex()[0],
                                     m_ViewedRegion.GetIndex()[1],
                                         this->h(), m_SubSamplingRate);
    }
  }
419 420 421 422
  
  

  
423
#ifndef MESA
Emmanuel Christophe's avatar
Emmanuel Christophe committed
424
  glDrawBuffer(GL_BACK);
425 426 427
#endif // !MESA


428 429 430 431 432 433 434 435 436 437
}

/** 
 * Rebuild opengl buffer. 
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::RebuildOpenGlBuffer(void)
{
438
  //otbMsgDebugMacro(<<"RebuildOpenGlBuffer");
439
  if(m_OpenGlBuffer != NULL)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
440
  {
441
      //otbMsgDebugMacro(<<"Deleting previous buffer ...");
Emmanuel Christophe's avatar
Emmanuel Christophe committed
442 443
    delete [] m_OpenGlBuffer;
  }
444 445
  //otbMsgDebugMacro(<<"Buffered region: "<<m_BufferedRegion); 
  unsigned int bufferLenght = 4*m_BufferedRegion.GetSize()[0]
Emmanuel Christophe's avatar
Emmanuel Christophe committed
446
      *m_BufferedRegion.GetSize()[1];
447 448 449
  //otbMsgDebugMacro(<<"New buffer lenght: "<<bufferLenght);
  m_OpenGlBuffer = new unsigned char[bufferLenght];

Emmanuel Christophe's avatar
Emmanuel Christophe committed
450
  typedef itk::ImageRegionConstIterator<ImageType> IteratorType;
451 452 453
  IteratorType it(m_Image,m_BufferedRegion);
  unsigned int index = 0;
  for(it.GoToBegin();!it.IsAtEnd();++it)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
454 455
  {
    switch(m_ViewModel)
456
    {
Emmanuel Christophe's avatar
Emmanuel Christophe committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
      case RGB:
      {
        m_OpenGlBuffer[index] = Normalize(it.Get()[m_RedChannelIndex],m_RedChannelIndex);
        m_OpenGlBuffer[index+1] = Normalize(it.Get()[m_GreenChannelIndex],m_GreenChannelIndex);
        m_OpenGlBuffer[index+2] = Normalize(it.Get()[m_BlueChannelIndex],m_BlueChannelIndex);
        m_OpenGlBuffer[index+3] = 255;
        index+=4;
        break;
      }
      case GRAYSCALE:
      {
        unsigned char  gray = Normalize(it.Get()[m_RedChannelIndex],m_RedChannelIndex);
        m_OpenGlBuffer[index] =   gray;
        m_OpenGlBuffer[index+1] = gray;
        m_OpenGlBuffer[index+2] = gray;
        m_OpenGlBuffer[index+3] = 255;
        index+=4;
        break;
      }
      case COMPLEX_MODULUS:
      {
        double re = static_cast<double>(it.Get()[m_RedChannelIndex]);
        double im = static_cast<double>(it.Get()[m_GreenChannelIndex]);
480
//     std::cout << " *** " << m_RedChannelIndex << " " << m_GreenChannelIndex << std::endl;
Emmanuel Christophe's avatar
Emmanuel Christophe committed
481
        unsigned char  modulus = Normalize(static_cast<PixelType>(vcl_sqrt(static_cast<double>(im*im+re*re))),0);
482
//     std::cout << " ** " << im << " " << re << " -> " << static_cast<int>(modulus) << std::endl;
Emmanuel Christophe's avatar
Emmanuel Christophe committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
        m_OpenGlBuffer[index] =   modulus;
        m_OpenGlBuffer[index+1] = modulus;
        m_OpenGlBuffer[index+2] = modulus;
        m_OpenGlBuffer[index+3] = 255;
        index+=4;
        break;
      }
      case COMPLEX_PHASE:
      {
        unsigned char phase =  Normalize(static_cast<PixelType>(vcl_atan2(static_cast<double>(it.Get()[m_GreenChannelIndex]),static_cast<double>(it.Get()[m_RedChannelIndex]))),0);
        m_OpenGlBuffer[index]   = phase;
        m_OpenGlBuffer[index+1] = phase;
        m_OpenGlBuffer[index+2] = phase;
        m_OpenGlBuffer[index+3] = 255;
        index+=4;
        break;
      }
500
    }
Emmanuel Christophe's avatar
Emmanuel Christophe committed
501
  }
502 503 504 505 506 507 508 509 510
}
/** 
 * Rebuild opengl image overlay buffer. 
 */
template <class TPixel>
void
ImageWidgetBase<TPixel>
::RebuildOpenGlImageOverlayBuffer(void)
{
511
  //otbMsgDebugMacro(<<"RebuildOpenGlImageOverlayBuffer");
512
  if(m_OpenGlImageOverlayBuffer != NULL)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
513
  {
514
      //otbMsgDebugMacro(<<"Deleting previous buffer ...");
Emmanuel Christophe's avatar
Emmanuel Christophe committed
515 516
    delete [] m_OpenGlImageOverlayBuffer;
  }
517 518
  //otbMsgDebugMacro(<<"Buffered region: "<<m_BufferedRegion); 
  unsigned int bufferLenght = 4*m_BufferedRegion.GetSize()[0]
Emmanuel Christophe's avatar
Emmanuel Christophe committed
519
      *m_BufferedRegion.GetSize()[1];
520 521 522
  //otbMsgDebugMacro(<<"New buffer lenght: "<<bufferLenght);
  m_OpenGlImageOverlayBuffer = new unsigned char[bufferLenght];

Emmanuel Christophe's avatar
Emmanuel Christophe committed
523
  typedef itk::ImageRegionConstIterator<OverlayImageType> IteratorType;
Julien Michel's avatar
Julien Michel committed
524
//   m_ImageOverlay->SetNumberOfComponentsPerPixel(3);
Julien Michel's avatar
Julien Michel committed
525
  IteratorType it(m_ImageOverlay,m_BufferedRegion);
526 527
  unsigned int index = 0;
  if(m_BlackTransparency)
Emmanuel Christophe's avatar
Emmanuel Christophe committed
528 529
  {
    for(it.GoToBegin();!it.IsAtEnd();++it)
530
    {
Emmanuel Christophe's avatar
Emmanuel Christophe committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
      if ((it.Get()[0]==0)&&(it.Get()[1]==0)&&(it.Get()[2]==0))
      {
        m_OpenGlImageOverlayBuffer[index] = 0;
        m_OpenGlImageOverlayBuffer[index+1] = 0;
        m_OpenGlImageOverlayBuffer[index+2] =0;
        m_OpenGlImageOverlayBuffer[index+3] = 0;
      }
      else
      {
        m_OpenGlImageOverlayBuffer[index] =   static_cast<unsigned char>(it.Get()[0]);
        m_OpenGlImageOverlayBuffer[index+1] = static_cast<unsigned char>( it.Get()[1]);
        m_OpenGlImageOverlayBuffer[index+2] = static_cast<unsigned char>(it.Get()[2]);
        m_OpenGlImageOverlayBuffer[index+3] = m_ImageOverlayOpacity;
      } 
      index+=4;
    }     
  }
548
  else 
Emmanuel Christophe's avatar
Emmanuel Christophe committed
549 550
  {
    for(it.GoToBegin();!it.IsAtEnd();++it)
551
    {
Emmanuel Christophe's avatar
Emmanuel Christophe committed
552 553 554 555 556
      m_OpenGlImageOverlayBuffer[index] =  static_cast<unsigned char>(it.Get()[0]);
      m_OpenGlImageOverlayBuffer[index+1] =static_cast<unsigned char>(it.Get()[1]);
      m_OpenGlImageOverlayBuffer[index+2] =static_cast<unsigned char>(it.Get()[2]);
      m_OpenGlImageOverlayBuffer[index+3] =m_ImageOverlayOpacity;
      index+=4;
557
    }
Emmanuel Christophe's avatar
Emmanuel Christophe committed
558
  }
559 560 561 562 563
}


}// end namespace otb
#endif