ossim_uint32 ossimDtedElevationImageSource::computeIndex(
   const ossimImageData& id,
   const ossimGrect& idRect,
   const ossimGpt& gpt,
   const ossimDpt& postSpacing) const
{
   if ( ! idRect.pointWithin(gpt) )
   {
      return OSSIM_INT_NAN;
   }

   ossim_uint32 line = static_cast<ossim_uint32>( (idRect.ul().lat - gpt.lat)
                                                  / postSpacing.y );
   ossim_uint32 samp = static_cast<ossim_uint32>( (gpt.lon - idRect.ul().lon)
                                                  / postSpacing.x );
   return ( (line * id.getWidth()) + samp );
}
void ossimDtedElevationImageSource::getPostSpacing(const ossimGrect& rect,
                                                   ossim_uint32 lines,
                                                   ossim_uint32 samples,
                                                   ossimDpt& result) const
{
   result.lat = (rect.ul().lat - rect.ll().lat) / (lines   - 1);
   result.lon = (rect.lr().lon - rect.ll().lon) / (samples - 1);
}
Пример #3
0
void oms::SingleImageChain::setViewCut(const ossimGrect& grect)
{
   std::vector<ossimGpt> pointList(4);
   pointList[0] = grect.ul();
   pointList[1] = grect.ur();
   pointList[2] = grect.lr();
   pointList[3] = grect.ll();
   setViewCut(pointList);
};
Пример #4
0
void ossimUsgsQuad::getQuadList(vector<ossimUsgsQuad>& result,
                                const ossimGrect& rect)
{
   result.clear();
//   QUAD_SIZE_IN_DEGREES;

   ossimGpt point = rect.ul();

   while(rect.pointWithin(point))
   {
      while(rect.pointWithin(point))
      {
         result.push_back(ossimUsgsQuad(point));

         point.lond(point.lond()+QUAD_SIZE_IN_DEGREES);
      }
      point.lond(rect.ul().lond());
      point.latd(point.latd()-QUAD_SIZE_IN_DEGREES);
   }
}
void ossimDtedElevationImageSource::computeImageRect(
   const ossimMapProjection* view,
   const ossimGrect& grect,
   ossimIrect& irect) const
{
   if (!view)
   {
      return;
   }
   
   ossimDpt dpt;
   view->worldToLineSample(grect.ul(), dpt);
   irect.set_ul(dpt);
   view->worldToLineSample(grect.lr(), dpt);
   irect.set_lr(dpt);
}
Пример #6
0
void ossimElevManager::getCellsForBounds( const ossimGrect& bbox,
                                          std::vector<std::string>& cells,
                                          ossim_uint32 maxCells)
{
   getCellsForBounds(bbox.lr().lat, bbox.ul().lon, bbox.ul().lat, bbox.lr().lon, cells, maxCells);
}
ossimRefPtr<ossimImageData> ossimDtedElevationImageSource::getBlock(
   const ossimGrect& rect,
   ossim_uint32 lines,
   ossim_uint32 samples) const
{

   ossimDpt postSpacing;
   getPostSpacing(rect, lines, samples, postSpacing);
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::getBlock DEBUG:"
         << "\nrect:          " << rect
         << "\nlines:         " << lines
         << "\nsamples:       " << samples
         << "\npost spacing:  " << postSpacing
         << "\ntheDirectory:  " << theDirectory
         << endl;
   }

   // Get a list of needed cells.
   vector<ossimFilename> vf;
   findCells(rect, vf);

   // Create a mosaic of them.
   ossimRefPtr<ossimImageChain> mosaic = createMosaic(vf);
   if (!mosaic)
   {
      return 0;
   }

   // Get the view.
   ossimMapProjection* view = getView(mosaic.get());
   if (!view)
   {
      mosaic = 0;
      return 0;
   }
   
   // Set the output resolution.
   view->setDecimalDegreesPerPixel(postSpacing);

   // Set the tie point to be the upper left of the requested rect.
   view->setUlTiePoints(rect.ul());

   // Convert the ground rectangle to the view's image space.
   ossimIrect tileRect;
   computeImageRect(view, rect, tileRect);

   cout << "tileRect:  " << tileRect << endl;
   
   ossimRefPtr<ossimImageData> result = mosaic->getTile(tileRect);

   mosaic = 0;
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::getBlock DEBUG:"
         << *result
         << "\nReturning..."
         << endl;
   }

   return result;
}
void ossimDtedElevationImageSource::snap(const ossimGrect& rect,
                                         const ossimDpt& postSpacing,
                                         ossimGrect& clipRect) const
{
   ossim_float64 d;

   // upper left latitude
   d = (rect.ul().lat - clipRect.ul().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ul().lat = floor(d) * postSpacing.y;
   }

   // upper left longitude
   d = (rect.ul().lon - clipRect.ul().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = ceil(d) * postSpacing.x;
   }

   // upper right latitude
   d = (rect.ul().lat - clipRect.ur().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ur().lat = floor(d) * postSpacing.y;
   }

   // upper right longitude
   d = (rect.ul().lon - clipRect.ur().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = floor(d) * postSpacing.x;
   }

   // lower right latitude
   d = (rect.ul().lat - clipRect.lr().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.lr().lat = ceil(d) * postSpacing.y;
   }

   // lower right longitude
   d = (rect.ul().lon - clipRect.lr().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = floor(d) * postSpacing.x;
   }

   // lower left latitude
   d = (rect.ul().lat - clipRect.ll().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ll().lat = ceil(d) * postSpacing.y;
   }

   // lower left longitude
   d = (rect.ul().lon - clipRect.ll().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = ceil(d) * postSpacing.x;
   }
}
void ossimDtedElevationImageSource::resampleCellBilinear(
   const ossimGrect& rect,
   const ossimFilename& dtedFile,
   ossimImageData& id,
   const ossimDpt& postSpacing) const
{
   cout << dtedFile << endl;
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::resampleCellBilinear DEBUG:"
         << " Entered..."
         << endl;
   }

   ossimRefPtr<ossimDtedHandler> dh = new ossimDtedHandler(dtedFile);
   if (!dh)
   {
      return;
   }
   if (dh->getErrorStatus() != ossimErrorCodes::OSSIM_OK)
   {
      dh = 0;
      return;
   }

   ossim_float32* buf = id.getFloatBuf();
   if (!buf)
   {
      dh = 0;
      return;
   }
   
   // Get the clip rectangle.
   const ossimGrect clipRect = rect.clipToRect(dh->getBoundingGndRect());
   const ossimGpt STOP_GPT = clipRect.lr();
   ossimGpt gpt = clipRect.ul();

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "clipRect:  " << clipRect
         << "\nSTOP_GPT:  " << STOP_GPT
         << "\nStarting gpt:       " << gpt
         << endl;
   }

   // Walk in the latitude (line) direction.
   while (gpt.lat >= STOP_GPT.lat)
   {
      // Walk in longitude (sample) direction.
      gpt.lon = clipRect.ul().lon;
      while (gpt.lon <= STOP_GPT.lon)
      {
         ossim_int32 index = computeIndex(id, rect, gpt, postSpacing);
//         cout << "index:  " << index << endl;
         if (index != OSSIM_INT_NAN)
         {
            ossim_float32 hgt =
               static_cast<ossim_float32>(dh->getHeightAboveMSL(gpt));
//             cout << "index: " << index
//                  << "\ngpt: " << gpt
//                  << "\nhgt: " << hgt
//                  << endl;
            buf[index] = hgt;
            if (hgt == -32767.0)
            {
               cout << gpt << endl;
            }
            // static_cast<ossim_float32>(dh->getHeightAboveMSL(gpt));
         }
         else
         {
            cout << "nan index for gpt:\n" << gpt << endl;
         }
         
         gpt.lon = gpt.lon + postSpacing.x;
      }
      gpt.lat = gpt.lat - postSpacing.y;
   }
//   cout << "Ending gpt:  " << gpt << endl;

//    // Walk in the latitude direction
//    while (gpt.lat <= STOP_GPT.lat)
//    {
//       while (gpt.lon <= STOP_GPT.lon)
//       {
//          gpt.lon += postSpacing.x;
//       }
//       gpt.lat += postSpacing.y;
//    }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::resampleCellBilinear DEBUG:"
         << " Exited..."
         << endl;
   }

   dh = 0;
}