Esempio n. 1
0
 int isRasterLayerRgbDisplayed(Layer* pLayer)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    setLastError(SIMPLE_NO_ERROR);
    return static_cast<int>(pRaster->getDisplayMode() == RGB_MODE);
 }
Esempio n. 2
0
PlotWidget* HistogramWindowImp::getPlot(Layer* pLayer) const
{
   if (pLayer == NULL)
   {
      return NULL;
   }

   RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(pLayer);
   if (pRasterLayer != NULL)
   {
      RasterChannelType channel = GRAY;
      if (pRasterLayer->getDisplayMode() == RGB_MODE)
      {
         channel = RED;
      }

      return getPlot(pRasterLayer, channel);
   }

   // Iterate over all histogram plots on all plot sets to find the plot
   vector<PlotWidget*> plots = mpPlotSetGroup->getPlots(HISTOGRAM_PLOT);
   for (vector<PlotWidget*>::iterator iter = plots.begin(); iter != plots.end(); ++iter)
   {
      PlotWidget* pPlot = *iter;
      if (pPlot != NULL)
      {
         HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pPlot->getPlot());
         if (pHistogramPlot != NULL)
         {
            Layer* pCurrentLayer = pHistogramPlot->getLayer();
            if (pCurrentLayer == pLayer)
            {
               return pPlot;
            }
         }
      }
   }

   return NULL;
}
Esempio n. 3
0
void ChippingWindow::createView()
{
   if (mpChippingWidget == NULL)
   {
      return;
   }

   RasterElement* pRaster = getRasterElement();
   if (pRaster == NULL)
   {
      return;
   }

   // Create the new raster element from the primary element of the source.
   // Note that this does not chip displayed elements if they differ from the primary element.
   // This causes a special case below where the stretch values are being applied to the chipped layer.
   RasterElement* pRasterChip = pRaster->createChip(pRaster->getParent(), "_chip",
      mpChippingWidget->getChipRows(), mpChippingWidget->getChipColumns(), mpChippingWidget->getChipBands());
   if (pRasterChip == NULL)
   {
      QMessageBox::critical(this, windowTitle(), "Unable to create a new cube!");
      return;
   }

   const RasterDataDescriptor* pDescriptor =
      dynamic_cast<const RasterDataDescriptor*>(pRasterChip->getDataDescriptor());
   VERIFYNRV(pDescriptor != NULL);

   // Create a view for the new chip
   SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(
      Service<DesktopServices>()->createWindow(pRasterChip->getName(), SPATIAL_DATA_WINDOW));
   if (pWindow == NULL)
   {
      return;
   }

   SpatialDataView* pView = pWindow->getSpatialDataView();
   if (pView == NULL)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   UndoLock lock(pView);
   if (pView->setPrimaryRasterElement(pRasterChip) == false)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   // RasterLayerImp is needed for the call to setCurrentStretchAsOriginalStretch().
   RasterLayerImp* pLayer = dynamic_cast<RasterLayerImp*>(pView->createLayer(RASTER, pRasterChip));
   if (pLayer == NULL)
   {
      Service<DesktopServices>()->deleteWindow(pWindow);
      return;
   }

   string origName = pRaster->getName();

   SpatialDataWindow* pOrigWindow = dynamic_cast<SpatialDataWindow*>(
      Service<DesktopServices>()->getWindow(origName, SPATIAL_DATA_WINDOW));
   if (pOrigWindow != NULL)
   {
      SpatialDataView* pOrigView = pOrigWindow->getSpatialDataView();
      if (pOrigView != NULL)
      {
         LayerList* pLayerList = pOrigView->getLayerList();
         if (pLayerList != NULL)
         {
            RasterLayer* pOrigLayer = static_cast<RasterLayer*>(pLayerList->getLayer(RASTER, pRaster));
            if (pOrigLayer != NULL)
            {
               // Set the stretch type first so that stretch values are interpreted correctly.
               pLayer->setStretchType(GRAYSCALE_MODE, pOrigLayer->getStretchType(GRAYSCALE_MODE));
               pLayer->setStretchType(RGB_MODE, pOrigLayer->getStretchType(RGB_MODE));
               pLayer->setDisplayMode(pOrigLayer->getDisplayMode());

               // Set the properties of the cube layer in the new view.
               // For each channel, display the first band if the previously displayed band was chipped.
               vector<RasterChannelType> channels = StringUtilities::getAllEnumValues<RasterChannelType>();
               for (vector<RasterChannelType>::const_iterator iter = channels.begin(); iter != channels.end(); ++iter)
               {
                  bool bandCopied = true;
                  DimensionDescriptor newBand;
                  DimensionDescriptor oldBand = pOrigLayer->getDisplayedBand(*iter);
                  if (oldBand.isOriginalNumberValid() == true)
                  {
                     newBand = pDescriptor->getOriginalBand(oldBand.getOriginalNumber());
                  }

                  if (newBand.isValid() == false)
                  {
                     bandCopied = false;
                     newBand = pDescriptor->getBands().front();
                  }

                  // No need to explicitly set the RasterElement here since the new view only has one RasterElement.
                  pLayer->setDisplayedBand(*iter, newBand);

                  // Use the default stretch properties if the displayed band was removed from the view or
                  // if the non-primary raster element was displayed. Otherwise, copy the stretch properties.
                  if (bandCopied && pRaster == pOrigLayer->getDisplayedRasterElement(*iter))
                  {
                     // Set the stretch units first so that stretch values are interpreted correctly.
                     pLayer->setStretchUnits(*iter, pOrigLayer->getStretchUnits(*iter));

                     double lower;
                     double upper;
                     pOrigLayer->getStretchValues(*iter, lower, upper);
                     pLayer->setStretchValues(*iter, lower, upper);
                  }
               }

               pLayer->setCurrentStretchAsOriginalStretch();
               pView->refresh();
            }
         }
      }
   }

   // Create a GCP layer
   if (pRaster->isGeoreferenced() == true)
   {
      const vector<DimensionDescriptor>& rows = mpChippingWidget->getChipRows();
      const vector<DimensionDescriptor>& columns = mpChippingWidget->getChipColumns();
      if ((rows.empty() == false) && (columns.empty() == false))
      {
         // Get the geocoordinates at the chip corners
         VERIFYNRV(rows.front().isActiveNumberValid() == true);
         VERIFYNRV(rows.back().isActiveNumberValid() == true);
         VERIFYNRV(columns.front().isActiveNumberValid() == true);
         VERIFYNRV(columns.back().isActiveNumberValid() == true);

         unsigned int startRow = rows.front().getActiveNumber();
         unsigned int endRow = rows.back().getActiveNumber();
         unsigned int startCol = columns.front().getActiveNumber();
         unsigned int endCol = columns.back().getActiveNumber();

         GcpPoint ulPoint;
         ulPoint.mPixel = LocationType(startCol, startRow);
         ulPoint.mCoordinate = pRaster->convertPixelToGeocoord(ulPoint.mPixel);

         GcpPoint urPoint;
         urPoint.mPixel = LocationType(endCol, startRow);
         urPoint.mCoordinate = pRaster->convertPixelToGeocoord(urPoint.mPixel);

         GcpPoint llPoint;
         llPoint.mPixel = LocationType(startCol, endRow);
         llPoint.mCoordinate = pRaster->convertPixelToGeocoord(llPoint.mPixel);

         GcpPoint lrPoint;
         lrPoint.mPixel = LocationType(endCol, endRow);
         lrPoint.mCoordinate = pRaster->convertPixelToGeocoord(lrPoint.mPixel);

         GcpPoint centerPoint;
         centerPoint.mPixel = LocationType((startCol + endCol) / 2, (startRow + endRow) / 2);
         centerPoint.mCoordinate = pRaster->convertPixelToGeocoord(centerPoint.mPixel);

         // Reset the coordinates to be in active numbers relative to the chip
         const vector<DimensionDescriptor>& chipRows = pDescriptor->getRows();
         const vector<DimensionDescriptor>& chipColumns = pDescriptor->getColumns();

         VERIFYNRV(chipRows.front().isActiveNumberValid() == true);
         VERIFYNRV(chipRows.back().isActiveNumberValid() == true);
         VERIFYNRV(chipColumns.front().isActiveNumberValid() == true);
         VERIFYNRV(chipColumns.back().isActiveNumberValid() == true);

         unsigned int chipStartRow = chipRows.front().getActiveNumber();
         unsigned int chipEndRow = chipRows.back().getActiveNumber();
         unsigned int chipStartCol = chipColumns.front().getActiveNumber();
         unsigned int chipEndCol = chipColumns.back().getActiveNumber();
         ulPoint.mPixel = LocationType(chipStartCol, chipStartRow);
         urPoint.mPixel = LocationType(chipEndCol, chipStartRow);
         llPoint.mPixel = LocationType(chipStartCol, chipEndRow);
         lrPoint.mPixel = LocationType(chipEndCol, chipEndRow);
         centerPoint.mPixel = LocationType((chipStartCol + chipEndCol) / 2, (chipStartRow + chipEndRow) / 2);

         // Create the GCP list
         Service<ModelServices> pModel;

         GcpList* pGcpList = static_cast<GcpList*>(pModel->createElement("Corner Coordinates",
            TypeConverter::toString<GcpList>(), pRasterChip));
         if (pGcpList != NULL)
         {
            list<GcpPoint> gcps;
            gcps.push_back(ulPoint);
            gcps.push_back(urPoint);
            gcps.push_back(llPoint);
            gcps.push_back(lrPoint);
            gcps.push_back(centerPoint);

            pGcpList->addPoints(gcps);

            // Create the layer
            if (pView->createLayer(GCP_LAYER, pGcpList) == NULL)
            {
               QMessageBox::warning(this, windowTitle(), "Could not create a GCP layer.");
            }
         }
         else
         {
            QMessageBox::warning(this, windowTitle(), "Could not create a GCP list.");
         }
      }
   }
}
Esempio n. 4
0
bool ImageHandler::getSessionItemImage(SessionItem* pItem, QBuffer& buffer, const QString& format, int band, int* pBbox)
{
   if (format.isEmpty())
   {
      return false;
   }
   bool success = true;
   QImage image;
   Layer* pLayer = dynamic_cast<Layer*>(pItem);
   View* pView = dynamic_cast<View*>(pItem);
   if (pLayer != NULL)
   {
      SpatialDataView* pSDView = dynamic_cast<SpatialDataView*>(pLayer->getView());
      if (pSDView != NULL)
      {
         UndoLock ulock(pSDView);
         DimensionDescriptor cur;
         DisplayMode mode;
         RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(pLayer);
         if (band >= 0 && pRasterLayer != NULL)
         {
            RasterElement* pRaster = pRasterLayer->getDisplayedRasterElement(GRAY);
            DimensionDescriptor bandDesc =
               static_cast<RasterDataDescriptor*>(pRaster->getDataDescriptor())->getActiveBand(band);
            cur = pRasterLayer->getDisplayedBand(GRAY);
            mode = pRasterLayer->getDisplayMode();
            pRasterLayer->setDisplayedBand(GRAY, bandDesc);
            pRasterLayer->setDisplayMode(GRAYSCALE_MODE);
         }
         int bbox[4] = {0, 0, 0, 0};
         ColorType transparent(255, 255, 254);
         success = pSDView->getLayerImage(pLayer, image, transparent, bbox);
         if (pBbox != NULL)
         {
            memcpy(pBbox, bbox, sizeof(bbox));
         }
         QImage alphaChannel(image.size(), QImage::Format_Indexed8);
         if (image.hasAlphaChannel())
         {
            alphaChannel = image.alphaChannel();
         }
         else
         {
            alphaChannel.fill(0xff);
         }
         QRgb transColor = COLORTYPE_TO_QCOLOR(transparent).rgb();
         for (int y = 0; y < image.height(); y++)
         {
            for (int x = 0; x < image.width(); x++)
            {
               if (image.pixel(x, y) == transColor)
               {
                  alphaChannel.setPixel(x, y, 0x00);
               }
            }
         }
         image.setAlphaChannel(alphaChannel);
         if (mode.isValid())
         {
            pRasterLayer->setDisplayedBand(GRAY, cur);
            pRasterLayer->setDisplayMode(mode);
         }
      }
   }
   else if (pView != NULL)
   {
      success = pView->getCurrentImage(image);
   }
   else
   {
      success = false;
   }
   if (success)
   {
      buffer.open(QIODevice::WriteOnly);
      QImageWriter writer(&buffer, format.toAscii());
      success = writer.write(image);
   }
   return success;
}
Esempio n. 5
0
bool RasterTimingTest::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   if (isBatch())
   {
      VERIFY(pOutArgList != NULL);
   }
   Service<DesktopServices> pDesktop;
   SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pDesktop->getCurrentWorkspaceWindowView());
   if (pView)
   {
      UndoLock lock(pView);

      RasterElement* pElement = pView->getLayerList()->getPrimaryRasterElement();
      RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(pElement->getDataDescriptor());
      int bands = pDesc->getBandCount();
      int frameNumber = 0;
      RasterLayer* pLayer = NULL;
      vector<Layer*> layers;
      pView->getLayerList()->getLayers(RASTER, layers);
      for (vector<Layer*>::iterator iter = layers.begin(); iter != layers.end(); ++iter)
      {
         RasterLayer* pRasterLayer = static_cast<RasterLayer*>(*iter);
         if (pRasterLayer != NULL)
         {
            RasterElement* pCurrentRasterElement = dynamic_cast<RasterElement*>(pRasterLayer->getDataElement());
            if (pCurrentRasterElement == pElement)
            {
               pLayer = pRasterLayer;
               break;
            }
         }
      }
      for (int i = 0; i < bands; ++i)
      {
         pElement->getStatistics(pDesc->getActiveBand(i))->getMin();
      }
      // set grayscale display mode
      DisplayMode initialDisplayMode = pLayer->getDisplayMode();
      pLayer->setDisplayMode(GRAYSCALE_MODE);
      const int frameiterations = 10000;
      clock_t startTime = clock();
      QWidget* pWidget = pView->getWidget();
      int i = 0;
      for (i = 0; i < frameiterations; ++i, ++frameNumber)
      {
         if (frameNumber >= bands)
         {
            frameNumber = 0;
         }

         pLayer->setDisplayedBand(GRAY, pDesc->getActiveBand(frameNumber));
         if (pWidget)
         {
            pWidget->repaint();
         }

         if ((i + 1) % (frameiterations / 100) == 0)
         {
            QString message = QString("Frame ") + QString::number(i+1) + QString(" of ") +
               QString::number(frameiterations);
            pDesktop->setStatusBarMessage(message.toStdString());
         }
         if ((i + 1) % 20 == 0)
         {
            clock_t stopTime = clock();
            double elapsedTime = static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC;
            if (elapsedTime > 30)
            {
               ++i;
               break;
            }
         }
      }
      clock_t stopTime = clock();
      double framesPerSec = i / (static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC);

      // restore display mode
      pLayer->setDisplayMode(initialDisplayMode);

      if (isBatch())
      {
         pOutArgList->setPlugInArgValue<double>("Framerate", &framesPerSec);
      }
      else
      {
         QMessageBox::information(pDesktop->getMainWidget(), "Frame Rate", 
            QString("The number of frames per second was: %1\nGPU Acceleration was%2 enabled\n").arg(framesPerSec)
                     .arg(pLayer->isGpuImageEnabled() ? "" : " not"));
      }

      return true;
   }

   return false;
}