コード例 #1
0
template <class T> ossimRefPtr<ossimImageData> ossimBlendMosaic::combineNorm(
   T, const ossimIrect& tileRect, ossim_uint32 resLevel)
{
   ossimRefPtr<ossimImageData> currentImageData=NULL;
   ossim_uint32 band;
   double currentWeight = 1.0;
   double previousWeight = 1.0;
   // double sumOfWeights   = 1;
   long offset = 0;
   long row    = 0;
   long col    = 0;
   ossim_uint32 layerIdx = 0;
   currentImageData = getNextNormTile(layerIdx, 0, tileRect, resLevel);
  
   if(!currentImageData.get()) // if we don't have one then return theTile
   {
      return theTile;
   }
   theNormResult->makeBlank();
   float** srcBands  = new float*[theLargestNumberOfInputBands];
   float** destBands = new float*[theLargestNumberOfInputBands];
   float*  nullPix   = new float[theTile->getNumberOfBands()];
  
   previousWeight = theWeights[layerIdx];
   //    // now get the previous weight and then combine the two into one.
   // let's assign the bands
   for(band = 0; band < theLargestNumberOfInputBands; ++band)
   {
      destBands[band] = static_cast<float*>(theNormResult->getBuf(band));
      nullPix[band]   = static_cast<float>(theNormResult->getNullPix(band));
   }
   while(currentImageData.get())
   {
      ossimDataObjectStatus currentStatus     = currentImageData->getDataObjectStatus();
     
      // set the current weight for the current tile.
      currentWeight = theWeights[layerIdx];
     
      // sumOfWeights = previousWeight+currentWeight;
      if( (currentStatus != OSSIM_EMPTY) &&
          (currentStatus != OSSIM_NULL))
      {	 
         long h = (long)currentImageData->getHeight();
         long w = (long)currentImageData->getWidth();
         offset = 0;
         ossim_uint32 minNumberOfBands = currentImageData->getNumberOfBands();
        
         // let's assign the bands
         for(band = 0; band < minNumberOfBands; ++band)
         {
            srcBands[band]  = static_cast<float*>(currentImageData->getBuf(band));
         }
         for(;band < theLargestNumberOfInputBands; ++band)
         {
            srcBands[band]  = srcBands[minNumberOfBands - 1];
         }
        
         if(currentStatus == OSSIM_PARTIAL)
         {
            for(row = 0; row < h; ++row)
            {
               for(col = 0; col < w; ++col)
               {
                  if(!currentImageData->isNull(offset))
                  {
                     for(band = 0; band < theLargestNumberOfInputBands; ++band)
                     {
                        if(destBands[band][offset] != nullPix[band])
                        {
                           destBands[band][offset] = static_cast<float>((destBands[band][offset]*previousWeight + 
                                                                         srcBands[band][offset]*currentWeight)/(previousWeight+currentWeight));
                        }
                        else
                        {
                           destBands[band][offset] = srcBands[band][offset];
                        }
                     }	 
                  }
                  ++offset;
               }
            }
         }
         else
         {
            for(row = 0; row < h; ++row)
            {
               for(col = 0; col < w; ++col)
               {
                  for(band = 0; band < theLargestNumberOfInputBands; ++band)
                  {			
                     if(destBands[band][offset] != nullPix[band])
                     {
                        destBands[band][offset] = static_cast<float>((destBands[band][offset]*previousWeight+ 
                                                                      srcBands[band][offset]*currentWeight)/(previousWeight + currentWeight));
                     }
                     else
                     {
                        destBands[band][offset] = srcBands[band][offset];
                     }
                  }
                  ++offset;
               }
            }
         }
      }
      currentImageData = getNextNormTile(layerIdx, tileRect, resLevel);
      previousWeight   = (previousWeight+currentWeight)/2.0;
   }
   theNormResult->validate();
   theTile->copyNormalizedBufferToTile((float*)theNormResult->getBuf());
   delete [] srcBands;
   delete [] destBands;
   delete [] nullPix;
   theTile->validate();

   return theTile;   
}
コード例 #2
0
ossimRefPtr<ossimImageData> ossimClosestToCenterCombiner::getTile(const ossimIrect& rect,
                                                                  ossim_uint32 resLevel)
{
   ossim_uint32 layerIdx = 0;
   if(!isSourceEnabled())
   {
      return ossimImageMosaic::getTile(rect, resLevel);
   }
   if(!theTile.valid())
   {
      allocate();
      if(!theTile.valid())
      {
         return 0;
      }
   }
   theTile->setImageRectangle(rect);
   theTile->makeBlank();
   std::vector<ossimClosestToCenterCombinerInfo > normTileList;
   ossimRefPtr<ossimImageData> currentTile = getNextNormTile(layerIdx, 0, rect);
   while(currentTile.valid())
   {
      normTileList.push_back(ossimClosestToCenterCombinerInfo((ossimImageData*)currentTile->dup(),
                                                              layerIdx));
      currentTile = getNextNormTile(layerIdx, rect, resLevel);
   }

   
   if(normTileList.size() == 1)
   {
      theTile->copyNormalizedBufferToTile((ossim_float32*)normTileList[0].theTile->getBuf());
   }
   else if(normTileList.size() > 1)
   {
      ossimRefPtr<ossimImageData> copyTile    = ossimImageDataFactory::instance()->create(0,
                                                                                          OSSIM_NORMALIZED_FLOAT);
      copyTile->setImageRectangleAndBands(rect,
                                          getNumberOfOutputBands());
      copyTile->initialize();
                                                                                          
      ossim_int32 idx   = 0;
      ossim_uint32 w     = rect.width();
      ossim_uint32 h     = rect.height();
      ossim_uint32 idxW  = 0;
      ossim_uint32 idxH  = 0;
      ossimIpt origin    = rect.ul();
      ossimIpt ulPt      = rect.ul();
      ossim_uint32 band  = 0;
      ossim_uint32 bands = copyTile->getNumberOfBands();
      ossim_uint32 srcBandIdx = 0;
      std::vector<ossim_float32*> bandList(bands);

      for(band = 0; band < bands; ++band)
      {
         bandList[band] = (ossim_float32*)copyTile->getBuf(band);
      }
      ossim_uint32 offset   = 0;
      origin.y = ulPt.y;
      for(idxH = 0; idxH < h; ++idxH)
      {
         origin.x = ulPt.x;
         for(idxW = 0; idxW < w;++idxW)
         {
            idx = findIdx(normTileList, origin, offset);

            if(idx >=0)
            {
               ossim_uint32 tileBands = normTileList[idx].theTile->getNumberOfBands();
               if (tileBands > 0)
               {
                  tileBands -= 1;
                  for(band = 0; band < bands; ++band)
                  {
                     srcBandIdx = ossim::min( tileBands, band );
                     bandList[band][offset] = *(((ossim_float32*)normTileList[idx].theTile->getBuf(srcBandIdx))+offset);
                  }
               }
            }
            ++offset;
            ++origin.x;
         }
         ++origin.y;
      }
      theTile->copyNormalizedBufferToTile((ossim_float32*)copyTile->getBuf());
   }

   theTile->validate();
   
   return theTile;

}