Esempio n. 1
0
void rspfScalarRemapper::allocate()
{
   destroy();

   if(!theInputConnection) // Nothing to do here.
   {
      setInitializedFlag(false);
      theByPassFlag = true;
      return;
   }
   
   if (theOutputScalarType == RSPF_SCALAR_UNKNOWN)
   {
      // default to RSPF_UINT8
      theOutputScalarType = RSPF_UINT8;
   }
   
   if(theInputConnection &&
      (getOutputScalarType() != theInputConnection->getOutputScalarType())&&
      (theInputConnection->getOutputScalarType() != RSPF_SCALAR_UNKNOWN)&&
      (getOutputScalarType() != RSPF_SCALAR_UNKNOWN))
   {
      theByPassFlag = false;
      
      theTile = rspfImageDataFactory::instance()->create(this, this);

      // Initialize the tile.
      theTile->initialize();
      
      // Set the base class flags to be initialized and enabled.
      setInitializedFlag(true);
      
   } // End of "if(theInputConnection->isConnected()..."
   else
   {
      // Set to not initialized and disabled.
      setInitializedFlag(false);
      theByPassFlag = true;
   }

   if (traceDebug())
   {
      rspfNotify(rspfNotifyLevel_DEBUG)
         << "rspfScalarRemapper::allocate() DEBUG"
         << "\ninput scalar:  " << theInputConnection->getOutputScalarType()
         << "\noutput scalar: " << getOutputScalarType()
         << "\nenabled:  " << (isSourceEnabled()?"true":"false")
         << std::endl;
   }
}
Esempio n. 2
0
double ossimImageChain::getMaxPixelValue(ossim_uint32 band)const
{
   if((theImageChainList.size() > 0)&&(isSourceEnabled()))
   {
      ossimImageSource* inter = PTR_CAST(ossimImageSource,
                                                  theImageChainList[0].get());
      if(inter)
      {
         return inter->getMaxPixelValue(band);
      }
   }
   else
   {
      if(getInput(0))
      {
         ossimImageSource* interface = PTR_CAST(ossimImageSource,
                                                         getInput(0));
         if(interface)
         {
            return interface->getMaxPixelValue(band);
         }
      }
   }

   return ossim::defaultMax(getOutputScalarType());
}
Esempio n. 3
0
ossimRefPtr<ossimImageData> ossimNBandToIndexFilter::convertInputTile(ossimImageData* tile)
{
   switch(getOutputScalarType())
   {
      case OSSIM_UINT8:
      {
         return convertOutputTileTemplate((ossim_uint8)0,
                                          tile);
         break;
      }
      case OSSIM_UINT16:
      {
         return convertOutputTileTemplate((ossim_uint16)0,
                                          tile);
         break;
      }
      case OSSIM_UINT32:
      {
         return convertOutputTileTemplate((ossim_uint32)0,
                                         tile);
         break;
      }
      default:
      {
         ossimNotify(ossimNotifyLevel_WARN) << "ossimNBandToIndexFilter::convertInputTile: Unsupported scalar type for conversion" << std::endl;
      }
   }

   return theTile;
}
Esempio n. 4
0
double toprsImageReader::getNullPixelValue( int band/*=0*/ ) const
{
    if(theData.getBands())
    {
        return theData.getNullPix(band);
    }
    return toprs::defaultNull(getOutputScalarType());
}
double ossimCFARFilter::getNullPixelValue(ossim_uint32 band)const
{
   if( isSourceEnabled() && (band < theNullPixValue.size()) )
   {
      return theNullPixValue[band];
   }

   return ossim::defaultNull(getOutputScalarType());
}
double rspf3x3ConvolutionFilter::getNullPixelValue(rspf_uint32 band)const
{
   if( isSourceEnabled() && (band < theNullPixValue.size()) )
   {
      return theNullPixValue[band];
   }

   return rspf::defaultNull(getOutputScalarType());
}
Esempio n. 7
0
double rspfImageSource::getMinPixelValue(rspf_uint32 band)const
{
    rspfImageSource* inter = PTR_CAST(rspfImageSource,
                                      getInput(0));
    if(inter)
    {
        return inter->getMinPixelValue(band);
    }
    return rspf::defaultMin(getOutputScalarType());
}
Esempio n. 8
0
double ossimImageSource::getMinPixelValue(ossim_uint32 band)const
{
   ossimImageSource* inter = PTR_CAST(ossimImageSource,
                                               getInput(0));
   if(inter)
   {
      return inter->getMinPixelValue(band);
   }
   return ossim::defaultMin(getOutputScalarType());
}
Esempio n. 9
0
void ossimHistogramRemapper::buildAutoLinearMinMaxTable()
{
   switch (getOutputScalarType())
   {
      case OSSIM_UINT8:
      {
         buildAutoLinearMinMaxTableTemplate(ossim_uint8(0));
         break;
      }
			
      case OSSIM_USHORT11:
      case OSSIM_UINT16:
      {
         buildAutoLinearMinMaxTableTemplate(ossim_uint16(0));
         break;
      }
			
      case OSSIM_SINT16:
      {
         buildAutoLinearMinMaxTableTemplate(ossim_sint16(0));
         break;
      }
			
      case OSSIM_NORMALIZED_FLOAT:      
      case OSSIM_FLOAT:
      {
         buildAutoLinearMinMaxTableTemplate(ossim_float32(0));
         break;
      }
			
      case OSSIM_NORMALIZED_DOUBLE:
      case OSSIM_DOUBLE:
      {
         buildAutoLinearMinMaxTableTemplate(ossim_float64(0));
         break;
      }
			
      case OSSIM_SCALAR_UNKNOWN:
      default:
      {
         if(traceDebug())
         {
         // Shouldn't hit this.
            ossimNotify(ossimNotifyLevel_WARN)
               << "ossimTableRemapper::buildTable OSSIM_SCALAR_UNKNOWN!"
               << endl;
         }
         break;
      }
			
   } // End of "switch (theTableType)"
}
Esempio n. 10
0
void ossimTableRemapper::allocate(const ossimIrect& rect)
{
   //---
   // It's either first getTile or we've had either a resize, so allocate
   // needed stuff...
   //---
   destroy();

   if (theInputConnection)
   {
      ossim_uint32 width  = rect.width();
      ossim_uint32 height = rect.height();
    
      theTile =  ossimImageDataFactory::instance()->create(this,this);
      theTile->setImageRectangle(rect); 
     // theTile =
     //    ossimImageDataFactory::instance()->create(this,
     //                                              getOutputScalarType(),
     //                                              getNumberOfOutputBands(),
     //                                              width,x
     //                                              height);
      theTile->initialize();


      if (theInputScalarType !=  getOutputScalarType() &&
          theTableType == ossimTableRemapper::NATIVE)
      {
         //---
         // We need a temp tile so we can do two remaps
         // inputTile->remapTable->tmpTile then
         // tmpTile->normalize->theTile(unnormalize to new scalar)...
         //---
         theTmpTile 
         = ossimImageDataFactory::instance()->create(this,
                                                     theInputScalarType,
                                                     getNumberOfOutputBands(),
                                                     width,
                                                     height);
         theTmpTile->setMinPix(theTile->getMinPix(), theTile->getNumberOfBands());
         theTmpTile->initialize();

      }

      if (theTableType == ossimTableRemapper::NORMALIZED ||
          theInputScalarType != theOutputScalarType)
      {
         theNormBuf = new ossim_float64[theTile->getSize()];
      }
   }
}
Esempio n. 11
0
double ossimH5Reader::getNullPixelValue( ossim_uint32 band ) const
{
   return ossimImageHandler::getNullPixelValue( band );
#if 0
   double result;
   ossimScalarType scalar = getOutputScalarType();
   if ( scalar == OSSIM_FLOAT32 )
   {
      result = -9999.0;
   }
   else
   {
      result = ossimImageHandler::getNullPixelValue( band );
   }
   return result;
#endif
}
Esempio n. 12
0
void ossimLasReader::initTile()
{
   const ossim_uint32 BANDS = getNumberOfOutputBands();

   m_tile = new ossimImageData(this,
                               getOutputScalarType(),
                               BANDS,
                               getTileWidth(),
                               getTileHeight());

   for(ossim_uint32 band = 0; band < BANDS; ++band)
   {
      m_tile->setMinPix(getMinPixelValue(band),   band);
      m_tile->setMaxPix(getMaxPixelValue(band),   band);
      m_tile->setNullPix(getNullPixelValue(band), band);
   }

   m_tile->initialize();
}
Esempio n. 13
0
ossimRefPtr<ossimImageData> ossimMemoryImageSource::getTile(const ossimIrect& rect,
                                                            ossim_uint32 /* resLevel */)
{
   if(!isSourceEnabled()||!m_image.valid()||m_boundingRect.hasNans()) return 0;
   if(!m_result.valid())
   {
      m_result = new ossimImageData(0, getOutputScalarType(), getNumberOfOutputBands(), rect.width(), rect.height());
      m_result->initialize();       
   }

   m_result->setImageRectangle(rect);
   m_result->makeBlank();
   ossimIrect clampRect = m_image->getImageRectangle().clipToRect(rect);
	
   m_result->loadTile(m_image->getBuf(),
	                    m_boundingRect,
	                    OSSIM_BSQ);

	m_result->validate();
   return m_result;
}
Esempio n. 14
0
ossimRefPtr<ossimImageData> ossimMrSidReader::getTile(
   const ossimIrect& rect, ossim_uint32 resLevel)
{
   LT_STATUS sts = LT_STS_Uninit;

   // This tile source bypassed, or invalid res level, return null tile.
   if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel))
   {
      return ossimRefPtr<ossimImageData>();
   }

   ossimIrect imageBound = getBoundingRect(resLevel);
   if(!rect.intersects(imageBound))
   {
      return ossimRefPtr<ossimImageData>();
   }

   // Check for overview.
   if( resLevel > theMinDwtLevels )
   {
      if(theOverview.valid())
      {
         ossimRefPtr<ossimImageData> tileData = theOverview->getTile(rect, resLevel);
         tileData->setScalarType(getOutputScalarType());
         return tileData;
      }
   }

   theTile->setImageRectangle(rect);

   // Compute clip rectangle with respect to the image bounds.
   ossimIrect clipRect   = rect.clipToRect(imageBound);

   if (rect.completely_within(clipRect) == false)
   {
      // Not filling whole tile so blank it out first.
      theTile->makeBlank();
   }

   lt_uint16 anOssimBandIndex = 0;

   LTIPixel pixel(theReader->getColorSpace(), theNumberOfBands, theReader->getDataType());
   LTISceneBuffer sceneBuffer(pixel, clipRect.width(), clipRect.height(), NULL);

   if (!theGeometry.valid())
   {
      theGeometry = getImageGeometry();
   }
   double mag = theGeometry->decimationFactor(resLevel).lat;
   sts = theImageNavigator->setSceneAsULWH(clipRect.ul().x,
                                           clipRect.ul().y,
                                           clipRect.lr().x - clipRect.ul().x + 1,
                                           clipRect.lr().y - clipRect.ul().y + 1, mag);

   LTIScene scene = theImageNavigator->getScene();
   sts = theReader->read(scene, sceneBuffer);

   if (LT_SUCCESS(sts) == true)
   {
      for(anOssimBandIndex = 0; anOssimBandIndex < theNumberOfBands; anOssimBandIndex++)
      {
         theTile->loadBand(sceneBuffer.getTotalBandData(anOssimBandIndex),
                           clipRect, anOssimBandIndex);
      }
   }

   theTile->validate();
   return theTile;
}
Esempio n. 15
0
void ossimHistogramRemapper::setupTable()
{
   const ossim_uint32 BANDS = getNumberOfInputBands();
   
   if (theNormalizedLowClipPoint.size() == 0)
   {
      initializeClips(BANDS);
   }
   
   ossim_uint32 values_per_band = 0;
   ossim_uint32 bytes_per_pixel = 0;
   
   switch (theOutputScalarType)
   {
      case OSSIM_UINT8:
         values_per_band = 256;  // 2 ^ 8
         bytes_per_pixel = 1;
         theTableType = ossimTableRemapper::NATIVE;
         break;
			
      case OSSIM_USHORT11:
         values_per_band = 2048; // 2 ^ 11
         bytes_per_pixel = 2;
         theTableType = ossimTableRemapper::NATIVE;
         break;
         
      case OSSIM_UINT16:
      case OSSIM_SINT16:
         values_per_band = 65536; // 2 ^ 16
         bytes_per_pixel = 2;
         theTableType = ossimTableRemapper::NATIVE;
         break;
			
      case OSSIM_NORMALIZED_FLOAT:
      case OSSIM_FLOAT:
         bytes_per_pixel = 4;
         break;
			
      case OSSIM_NORMALIZED_DOUBLE:         
      case OSSIM_DOUBLE:
         bytes_per_pixel = 8;
         theTableType = ossimTableRemapper::NORMALIZED;
         break;
         
      default:
         break;
   }
	
   if ( theOutputScalarType == OSSIM_FLOAT ||
        theOutputScalarType == OSSIM_DOUBLE ||
        theOutputScalarType == OSSIM_NORMALIZED_FLOAT ||
        theOutputScalarType == OSSIM_NORMALIZED_DOUBLE )
   {
      for (ossim_uint32 band = 0; band < BANDS; ++band)
      {
         ossimRefPtr<ossimHistogram> h  = getHistogram(band);
			
         if (h.valid())
         {
            if (h->GetRes() > static_cast<ossim_int32>(values_per_band))
            {
               values_per_band = h->GetRes();
            }
         }
      }
   }      
   
   theTableBinCount  = values_per_band;
   theTableBandCount = BANDS;
   // Check the size of the table prior to deletion and making a new one.
   ossim_uint32 size_in_bytes = values_per_band * BANDS * bytes_per_pixel;
   if(theTable.empty() || (theTable.size() != size_in_bytes))
   {
      theTable.resize(size_in_bytes);
   }

   ossimImageSource* input = dynamic_cast<ossimImageSource*>(getInput());
   double minPix = ossim::defaultMin(getOutputScalarType());
   double maxPix = ossim::defaultMax(getOutputScalarType());
   
   if(input)
   {
      //---
      // Last check for NaNs in key data members and set to some default if so.
      // This could occur if someone stripped a keyword list down to a minimal
      // set of keywords.
      //---
      for (ossim_uint32 band = 0; band < BANDS; ++band)
      {
         minPix = input->getMinPixelValue(band);
         maxPix = input->getMaxPixelValue(band);
         if ( ossim::isnan(theMinOutputValue[band]) )
         {
            theMinOutputValue[band] = minPix;
         }
         if ( ossim::isnan(theMaxOutputValue[band]) )
         {
            theMaxOutputValue[band] = maxPix;
         }
      }   
   }
   else
   {
      //---
      // Last check for NaNs in key data members and set to some default if so.
      // This could occur if someone stripped a keyword list down to a minimal
      // set of keywords.
      //---
      for (ossim_uint32 band = 0; band < BANDS; ++band)
      {
         if ( ossim::isnan(theMinOutputValue[band]) )
         {
            theMinOutputValue[band] = minPix;
         }
         if ( ossim::isnan(theMaxOutputValue[band]) )
         {
            theMaxOutputValue[band] = maxPix;
         }
      }   
   }
}
Esempio n. 16
0
void toprsImageReader::completeOpen()
{
    theData.setDataType(getOutputScalarType());
}
void ossimCFARFilter::computeNullMinMax()
{
   const ossim_uint32 BANDS = getNumberOfOutputBands();

   theNullPixValue.resize(BANDS);
   theMinPixValue.resize(BANDS);
   theMaxPixValue.resize(BANDS);

   ossim_float64 defaultNull = ossim::defaultNull(getOutputScalarType());
   ossim_float64 defaultMin = ossim::defaultMin(getOutputScalarType());
   ossim_float64 defaultMax = ossim::defaultMax(getOutputScalarType());
  
   for (ossim_uint32 band = 0; band < BANDS; ++band)
   {
      if(theInputConnection)
      {
         ossim_float64 inputNull = theInputConnection->getNullPixelValue(band);
         ossim_float64 inputMin  = theInputConnection->getMinPixelValue(band);
         ossim_float64 inputMax  = theInputConnection->getMaxPixelValue(band);
         ossim_float64 tempMin   = 0.0;
         ossim_float64 tempMax   = 0.0;
         ossim_float64 k         = 0.0;
         for(int i=0;i<5;++i)
         {
            for(int j=0;j<5;++j)
            {
               k=theKernel[i][j];
               tempMin += (k<0.0) ? k*inputMax : k*inputMin;
               tempMax += (k>0.0) ? k*inputMax : k*inputMin;
            }
         }

         if((inputNull < getMinPixelValue(band)) ||
            (inputNull > getMaxPixelValue(band)))
         {
            theNullPixValue[band] = inputNull;
         }
         else
         {
            theNullPixValue[band] = defaultNull;
         }

         if((tempMin >= defaultMin) && (tempMin <= defaultMax))
         {
            theMinPixValue[band] = tempMin;
         }
         else
         {
            theMinPixValue[band] = defaultMin;
         }

         if((tempMax >= defaultMin) && (tempMax <= defaultMax))
         {
            theMaxPixValue[band] = tempMax;
         }
         else
         {
            theMaxPixValue[band] = defaultMax;
         }
         
      }
      else // No input connection...
      {
         theNullPixValue[band] = defaultNull;
         theMinPixValue[band]  = defaultMin;
         theMaxPixValue[band]  = defaultMax;
      }
      
   } // End of band loop.
}
bool ossimGeneralRasterTileSource::getTile(ossimImageData* result,
                                           ossim_uint32 resLevel)
{
   bool status = false;
   
   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel)  &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);
      if (status)
      {
         if(getOutputScalarType() == OSSIM_USHORT11)
         {
            //---
            // Temp fix:
            // The overview handler could return a tile of OSSIM_UINT16 if
            // the max sample value was not set to 2047.
            //---
            result->setScalarType(OSSIM_USHORT11);
         }
      }
      
      if (!status) // Did not get an overview tile.
      {
         status = true;
         
         //---
         // Subtract any sub image offset to get the zero based image space
         // rectangle.
         //---
         ossimIrect tile_rect = result->getImageRectangle();
         
         // This should be the zero base image rectangle for this res level.
         ossimIrect image_rect = getImageRectangle(resLevel);
         
         //---
         // See if any point of the requested tile is in the image.
         //---
         if ( tile_rect.intersects(image_rect) )
         {
            // Make the tile rectangle zero base.
            result->setImageRectangle(tile_rect);

            // Initialize the tile if needed as we're going to stuff it.
            if (result->getDataObjectStatus() == OSSIM_NULL)
            {
               result->initialize();
            }

            ossimIrect clip_rect = tile_rect.clipToRect(image_rect);

            if ( ! tile_rect.completely_within(m_bufferRect) )
            {
               // A new buffer must be loaded.
               if ( !tile_rect.completely_within(clip_rect) )
               {
                  //---
                  // Start with a blank tile since the whole tile buffer will
                  // not be
                  // filled.
                  //---
                  result->makeBlank();
               }

               // Reallocate the buffer if needed.
               if ( m_bufferSizeInPixels != result->getSize() )
               {
                  allocateBuffer( result );
               }

               ossimIpt size(static_cast<ossim_int32>(result->getWidth()),
                             static_cast<ossim_int32>(result->getHeight()));

               if( !fillBuffer(clip_rect.ul(), size) )
               {
                  ossimNotify(ossimNotifyLevel_WARN)
                     << "Error from fill buffer..."
                     << std::endl;
                  //---
                  // Error in filling buffer.
                  //---
                  setErrorStatus();
                  status = false;
               }
            }
            
            result->loadTile(m_buffer,
                             m_bufferRect,
                             clip_rect,
                             m_bufferInterleave);
            result->validate();

            // Set the rectangle back.
            result->setImageRectangle(tile_rect);
            
         }
         else // No intersection.
         {
            result->makeBlank();
         }
      }
   }
   return status;
}
void rspfConvolutionSource::convolve(T /* dummyVariable */,
                                      rspfRefPtr<rspfImageData> inputTile,
                                      rspfDiscreteConvolutionKernel* kernel)
{
   rspfIpt startOrigin   = theTile->getOrigin();

   // Make sure that the patch is not empty or NULL
   //
   rspfIpt startDelta(startOrigin.x - inputTile->getOrigin().x,
                       startOrigin.y - inputTile->getOrigin().y);

   rspfDataObjectStatus status = inputTile->getDataObjectStatus();
   // let's setup some variables that we will need to do the
   // convolution algorithm.
   //
   rspfIrect patchRect   = inputTile->getImageRectangle();
   long tileHeight        = theTile->getHeight();
   long tileWidth         = theTile->getWidth();
   long outputBands       = theTile->getNumberOfBands();
   long convolutionWidth  = kernel->getWidth();
   long convolutionHeight = kernel->getHeight();
   long convolutionOffsetX= convolutionWidth/2;
   long convolutionOffsetY= convolutionHeight/2;
   long patchWidth        = patchRect.width();
   long convolutionTopLeftOffset = 0;
   long convolutionCenterOffset  = 0;
   
   long outputOffset          = 0;
   T np = 0;
   
   const double minPix  = rspf::defaultMin(getOutputScalarType());
   const double maxPix  = rspf::defaultMax(getOutputScalarType());
//   const double* maxPix  = inputTile->getMaxPix();
   const double* nullPix = inputTile->getNullPix();
   double convolveResult = 0;
   
   if(status == RSPF_PARTIAL) // must check for NULLS
   {
      for(long y = 0; y <tileHeight; y++)
      {
         convolutionCenterOffset  = patchWidth*(startDelta.y + y) + startDelta.x;
         convolutionTopLeftOffset = patchWidth*(startDelta.y + y - convolutionOffsetY) + startDelta.x-convolutionOffsetX;
         
         for(long x =0; x < tileWidth; x++)
         {
            if(!inputTile->isNull(convolutionCenterOffset))
            {
               for(long b = 0; b < outputBands; ++b)
               {
                  T* buf    = (T*)(inputTile->getBuf(b)) + convolutionTopLeftOffset;
                  T* outBuf = (T*)(theTile->getBuf(b));
                  kernel->convolveSubImage(buf,
                                           patchWidth,
                                           convolveResult,
                                           (T)nullPix[b]);

                  convolveResult = convolveResult < minPix? minPix:convolveResult;
                  convolveResult = convolveResult > maxPix? maxPix:convolveResult;
                  
                  outBuf[outputOffset] = (T)convolveResult;
               }
            }
            else
            {
               theTile->setNull(outputOffset);
               
            }
            ++convolutionCenterOffset;
            ++convolutionTopLeftOffset;
            ++outputOffset;
         }
      }
   }
   else  // do not need to check for nulls here.
   {
      for(long b = 0; b < outputBands; ++b)
      {                  
         double convolveResult = 0;
         const T* buf = (const T*)inputTile->getBuf(b);
         T* outBuf    = (T*)(theTile->getBuf(b));
         np =(T)nullPix[b];
         outputOffset = 0;
         
         for(long y = 0; y <tileHeight; y++)
         {
            convolutionTopLeftOffset = patchWidth*(startDelta.y + y - convolutionOffsetY) + startDelta.x-convolutionOffsetX;
            
            for(long x =0; x < tileWidth; x++)
            {
               kernel->convolveSubImage(&buf[convolutionTopLeftOffset],
                                        patchWidth,
                                        convolveResult,
                                        np);
// NOT SURE IF I WANT TO CLAMP IN A CONVOLUTION SOURCE  
// seems better to clamp to a scalar range instead of an input min max
               convolveResult = convolveResult < minPix? (T)minPix:convolveResult;
               convolveResult = convolveResult > maxPix?(T)maxPix:convolveResult;
               outBuf[outputOffset] = (T)convolveResult;
               ++outputOffset;
               ++convolutionTopLeftOffset;
            }
         }
      }
   }
}
Esempio n. 20
0
void toprsGadlReader::loadIndexTo3BandTile( const toprsIRect& clipRect,int aGdalBandStart /*= 1*/,int anToprsBandStart /*= 0*/ )
{
	// Typical case 16 bit indexes, eight bit out, NOT 16 bit out.
	toprsDataType inScalar  = getInputScalarType();
	toprsDataType outScalar = getOutputScalarType();

	if ( ( inScalar == TOPRS_UINT8 ) && ( outScalar == TOPRS_UINT8 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_uint8(0), // input type
			toprs_uint8(0), // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else if ( ( inScalar == TOPRS_UINT16 ) && ( outScalar == TOPRS_UINT8 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_uint16(0), // input type
			toprs_uint8(0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}

	else if ( ( inScalar == TOPRS_UINT16 ) && ( outScalar == TOPRS_UINT16 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_uint16(0), // input type
			toprs_uint16(0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else if ( ( inScalar == TOPRS_SINT16 ) && ( outScalar == TOPRS_SINT16 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_sint16(0), // input type
			toprs_sint16(0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else if ( ( inScalar == TOPRS_FLOAT32 ) && ( outScalar == TOPRS_FLOAT32 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_float32(0.0), // input type
			toprs_float32(0.0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else if ( ( inScalar == TOPRS_FLOAT64 ) && ( outScalar == TOPRS_FLOAT64 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_float64(0.0), // input type
			toprs_float64(0.0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else if ( ( inScalar == TOPRS_FLOAT64 ) && ( outScalar == TOPRS_UINT8 ) )
	{
		loadIndexTo3BandTileTemplate(toprs_float64(0.0), // input type
			toprs_uint8(0.0),  // output type
			clipRect,
			aGdalBandStart,
			anToprsBandStart);
	}
	else
	{
		std::cout
			<< __FILE__ << __LINE__
			<< " toprsGdalTileSource::loadIndexTo3BandTile WARNING!\n"
			<< "Unsupported scalar types:\nInupt scalar: " << inScalar
			<< "\nOutput scalar: " << outScalar
			<< std::endl;
	}
}
Esempio n. 21
0
void toprsGadlReader::computeMinMax()
{
	toprs_uint32 bands = GDALGetRasterCount(theDataset);

	if(theMinPixValues)
	{
		delete [] theMinPixValues;
		theMinPixValues = 0;
	}
	if(theMaxPixValues)
	{
		delete [] theMaxPixValues;
		theMaxPixValues = 0;
	}
	if(theNullPixValues)
	{
		delete [] theNullPixValues;
		theNullPixValues = 0;
	}
	if(isIndexTo3Band())
	{
		int i = 0;
		theMinPixValues  = new double[3];
		theMaxPixValues  = new double[3];
		theNullPixValues = new double[3];

		for(i = 0; i < 3; ++i)
		{
			theMinPixValues[i] = 1;
			theMaxPixValues[i] = 255;
			theNullPixValues[i] = 0;
		}
	}
	else if(isIndexTo1Band())
	{
		theMinPixValues  = new double[1];
		theMaxPixValues  = new double[1];
		theNullPixValues = new double[1];

		*theNullPixValues = 0;
		*theMaxPixValues = 255;
		*theMinPixValues = 1;
	}
	else
	{
		if(!theMinPixValues && !theMaxPixValues&&bands)
		{
			theMinPixValues = new double[bands];
			theMaxPixValues = new double[bands];
			theNullPixValues = new double[bands];
		}
		for(toprs_int32 band = 0; band < (toprs_int32)bands; ++band)
		{
			GDALRasterBandH aBand=0;

			aBand = GDALGetRasterBand(theDataset, band+1);

			int minOk=1;
			int maxOk=1;
			int nullOk=1;

			if(aBand)
			{
				if(hasData())
				{
					theMinPixValues[band] = theData.getMinPix(band);
					theMaxPixValues[band] = theData.getMaxPix(band);
					theNullPixValues[band] = theData.getNullPix(band);
				}
				else 
				{
					std::string driverName = theDriver ? GDALGetDriverShortName( theDriver ) : "";

					// Allow to rescale the image data 
					// to the min/max values found in the raster data only 
					// if it was not acquired with the following drivers:
					if ( driverName.find("JP2KAK") != std::string::npos  ||
						driverName.find("JPEG2000") != std::string::npos||
						driverName.find("NITF") != std::string::npos)
					{
						theMinPixValues[band] = toprs::defaultMin(getOutputScalarType());
						theMaxPixValues[band] = toprs::defaultMax(getOutputScalarType());
						theNullPixValues[band] = toprs::defaultNull(getOutputScalarType());
					}
					else
					{
						theMinPixValues[band]  = GDALGetRasterMinimum(aBand, &minOk);
						theMaxPixValues[band]  = GDALGetRasterMaximum(aBand, &maxOk);
						theNullPixValues[band] = GDALGetRasterNoDataValue(aBand, &nullOk);
					}
					if((!nullOk)||(theNullPixValues[band] < toprs::defaultNull(getOutputScalarType())))
					{
						theNullPixValues[band] = toprs::defaultNull(getOutputScalarType());
					}
				}
				if(!minOk||!maxOk)
				{
					theMinPixValues[band] = toprs::defaultMin(getOutputScalarType());
					theMaxPixValues[band] = toprs::defaultMax(getOutputScalarType());
				}
			}
			else
			{
				theMinPixValues[band] = toprs::defaultMin(getOutputScalarType());
				theMaxPixValues[band] = toprs::defaultMax(getOutputScalarType());
			}
		}
	}
}