Esempio n. 1
0
 uint32_t getRasterLayerFilterName(Layer* pLayer, uint32_t index, int enabled, char* pName, uint32_t nameSize)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL || pName == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    std::vector<std::string> filters =
       (enabled != 0) ? pRaster->getEnabledFilterNames() : pRaster->getSupportedFilters();
    if (index >= filters.size())
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    std::string name = filters[index];
    if (nameSize == 0)
    {
       return name.size() + 1;
    }
    else if (name.size() > nameSize - 1) // extra char for the null
    {
       setLastError(SIMPLE_BUFFER_SIZE);
       return 0;
    }
    memcpy(pName, name.c_str(), name.size());
    pName[name.size()] = '\0';
    setLastError(SIMPLE_NO_ERROR);
    return name.size();
 }
Esempio n. 2
0
   int getRasterLayerStatistics(Layer* pLayer, uint32_t channel,
                                uint32_t component, struct RasterStatistics* pStatistics)
   {
      RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
      RasterChannelType chan(static_cast<RasterChannelTypeEnum>(channel));
      ComplexComponent comp(static_cast<ComplexComponentEnum>(component));
      if (pRaster == NULL || pStatistics == NULL || !chan.isValid() || !comp.isValid())
      {
         setLastError(SIMPLE_BAD_PARAMS);
         return 1;
      }
      Statistics* pStats = pRaster->getStatistics(chan);
      if (pStats == NULL || !pStats->areStatisticsCalculated(comp))
      {
         setLastError(SIMPLE_OTHER_FAILURE);
         return 1;
      }
      pStatistics->min = pStats->getMin(comp);
      pStatistics->max = pStats->getMax(comp);
      pStatistics->mean = pStats->getAverage(comp);
      pStatistics->stddev = pStats->getStandardDeviation(comp);
      const double* pTmp = NULL;
      const unsigned int* pTmp2 = NULL;
      pStats->getHistogram(pTmp, pTmp2, comp);
      pStatistics->pHistogramCenters = const_cast<double*>(pTmp);
      pStatistics->pHistogramCounts = const_cast<unsigned int*>(pTmp2);
      pStatistics->pPercentiles = const_cast<double*>(pStats->getPercentiles(comp));
      pStatistics->resolution = pStats->getStatisticsResolution();

      setLastError(SIMPLE_NO_ERROR);
      return 0;
   }
Esempio n. 3
0
   int setRasterLayerColormapValues(Layer* pLayer, const char* pName, uint32_t* pColormap)
   {
      RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
      if (pRaster == NULL || pColormap == NULL)
      {
         setLastError(SIMPLE_BAD_PARAMS);
         return 1;
      }
      std::vector<ColorType> colormap;
      colormap.reserve(256);
      for (size_t idx = 0; idx < 256; ++idx)
      {
         colormap.push_back(decodeColor(pColormap[idx]));
      }
      try
      {
         pRaster->setColorMap(ColorMap(std::string((pName == NULL) ? "" : pName), colormap));
      }
      catch (const std::exception&)
      {
         setLastError(SIMPLE_BAD_PARAMS);
         return 1;
      }

      setLastError(SIMPLE_NO_ERROR);
      return 0;
   }
Esempio n. 4
0
void Timeline::AddRasterLayer(int index)
{
    if (!mScene)
    {
        return;
    }

    if (index < 0 || index > mLayers.size())
    {
        index = mLayers.size();
    }

    int width = mScene->GetWidth();
    int height = mScene->GetHeight();
    QString name;
    name.sprintf("layer%d", mLayers.size());
    RasterLayerModel* layerModel = mScene->AddRasterLayer(index, name, width, height);
    if (layerModel)
    {
        RasterLayer* layer = new RasterLayer(this, layerModel);
        layer->SetUndoStack(mUndoStack);

        std::vector<Layer*>::iterator it = mLayers.begin();
        it += index;
        mLayers.insert(it, layer);
        UpdateLayersUi();
    }
}
Esempio n. 5
0
 uint32_t getRasterLayerFilterCount(Layer* pLayer, int enabled)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    setLastError(SIMPLE_NO_ERROR);
    return (enabled != 0) ? pRaster->getEnabledFilterNames().size() : pRaster->getSupportedFilters().size();
 }
Esempio n. 6
0
 int getRasterLayerGpuEnabled(Layer* pLayer)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    setLastError(SIMPLE_NO_ERROR);
    return static_cast<int>(pRaster->isGpuImageEnabled());
 }
Esempio n. 7
0
 uint32_t getRasterLayerComplexComponent(Layer* pLayer)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    setLastError(SIMPLE_NO_ERROR);
    return pRaster->getComplexComponent();
 }
Esempio n. 8
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. 9
0
 int setRasterLayerRgbDisplayed(Layer* pLayer, int rgb)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    pRaster->setDisplayMode(rgb == 0 ? GRAYSCALE_MODE : RGB_MODE);
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 10
0
 int setRasterLayerComplexComponent(Layer* pLayer, uint32_t component)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    ComplexComponent comp(static_cast<ComplexComponentEnum>(component));
    if (pRaster == NULL || !comp.isValid())
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    pRaster->setComplexComponent(comp);
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 11
0
 int setRasterLayerFilterFrozen(Layer* pLayer, const char* pFilterName, int freeze)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL || pFilterName == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    pRaster->freezeFilter(std::string(pFilterName), freeze != 0);
    pRaster->getView()->refresh();
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 12
0
void Timeline::Render(QPainter& painter)
{
    std::vector<QImage*> onions;

    for (size_t i = 0; i < mLayers.size(); ++i)
    {
        Layer* layer = mLayers[i];
        if (!layer->IsEnabled())
        {
            continue;
        }
        if (layer->GetType() == LayerTypeRaster)
        {
            QImage* img = mLayers[i]->GetImage(mFrameIndex);
            if (img)
            {
                if (mEditor->IsOnionEnabled() && mLayerIndex == (int)i)
                {
                    if (layer->GetType() == LayerTypeRaster && layer->IsOnionEnabled())
                    {
                        RasterLayer* l = (RasterLayer*)mLayers[i];
                        QImage* prev = l->GetImage(l->GetPrevImageIndex(mFrameIndex));
                        if(prev && prev != img)
                        {
                            onions.push_back(prev);
                        }
                        QImage* next = l->GetImage(l->GetNextImageIndex(mFrameIndex));
                        if(next && next != img)
                        {
                            onions.push_back(next);
                        }
                    }
                }

                painter.setOpacity(layer->GetOpacity() / 255.0f);
                painter.drawImage(0, 0, *img);
            }
        }
        else if (layer->GetType() == LayerTypeTrace)
        {
            TraceLayer* tl = (TraceLayer*)layer;
            tl->Render(painter);
        }
    }

    painter.setOpacity(0.25f);
    for (size_t i = 0; i < onions.size(); ++i)
    {
        painter.drawImage(0, 0, *onions[i]);
    }
}
Esempio n. 13
0
 int setRasterLayerColormapName(Layer* pLayer, const char* pName)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    std::string name(pName);
    ColorMap map;
    if (!map.loadFromFile(name))
    {
       // see if name is a colormap name
       const Filename* pSupportFiles = Service<ConfigurationSettings>()->getSettingSupportFilesPath();
       if (pSupportFiles == NULL)
       {
          setLastError(SIMPLE_OTHER_FAILURE);
          return 1;
       }
       std::string mapDir = pSupportFiles->getFullPathAndName() + SLASH + "ColorTables" + SLASH;
       if (!map.loadFromFile(mapDir + name) && !map.loadFromFile(mapDir + name + ".clu")
        && !map.loadFromFile(mapDir + name + ".cgr"))
       {
          // scan all the default files and check for a valid name
          bool located = false;
          FactoryResource<FileFinder> pFinder;
          pFinder->findFile(mapDir, "*.c??");
          while (pFinder->findNextFile())
          {
             std::string filePath;
             pFinder->getFullPath(filePath);
             if (map.loadFromFile(filePath) && map.getName() == name)
             {
                located = true;
                break;
             }
          }
          if (!located)
          {
             setLastError(SIMPLE_NOT_FOUND);
             return 1;
          }
       }
    }
    pRaster->setColorMap(map);
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 14
0
 uint32_t getRasterLayerDisplayedBand(Layer* pLayer, uint32_t channel, DataElement** pElement)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    RasterChannelType chan(static_cast<RasterChannelTypeEnum>(channel));
    if (pRaster == NULL || !chan.isValid())
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    if (pElement != NULL)
    {
       *pElement = pRaster->getDisplayedRasterElement(chan);
    }
    setLastError(SIMPLE_NO_ERROR);
    return pRaster->getDisplayedBand(chan).getActiveNumber();
 }
Esempio n. 15
0
 int setRasterLayerStretchInfo(Layer* pLayer, uint32_t channel, struct RasterLayerStretchInfo* pInfo)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    RasterChannelType chan(static_cast<RasterChannelTypeEnum>(channel));
    if (pRaster == NULL || pInfo == NULL || !chan.isValid())
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    DisplayMode mode(chan == GRAY ? GRAYSCALE_MODE : RGB_MODE);
    pRaster->setStretchValues(chan, pInfo->lowerStretch, pInfo->upperStretch);
    pRaster->setStretchType(mode, static_cast<StretchTypeEnum>(pInfo->stretchType));
    pRaster->setStretchUnits(chan, static_cast<RegionUnitsEnum>(pInfo->stretchUnits));
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 16
0
 int setRasterLayerGpuEnabled(Layer* pLayer, int gpu)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    if (!pRaster->isGpuImageSupported())
    {
       setLastError(SIMPLE_OTHER_FAILURE);
       return 1;
    }
    setLastError(SIMPLE_NO_ERROR);
    pRaster->enableGpuImage(gpu != 0);
    return 0;
 }
Esempio n. 17
0
SpatialDataView* VideoImporter::createView() const
{
   if ((isBatch()) || (mpRasterElement == NULL))
   {
      return NULL;
   }

   mProgress.report("Creating view...", 85, NORMAL);

   // Get the data set name
   std::string name = mpRasterElement->getName();
   if (name.empty())
   {
      mProgress.report("The data set name is invalid!  A view cannot be created.", 0, ERRORS, true);
      return NULL;
   }

   // Create the spatial data window
   SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(Service<DesktopServices>()->createWindow(name, SPATIAL_DATA_WINDOW));
   SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView();
   if (pView == NULL)
   {
      mProgress.report("Could not create the view window!", 0, ERRORS, true);
      return NULL;
   }

   // Set the spatial data in the view
   pView->setPrimaryRasterElement(mpRasterElement);

   // Block undo actions when creating the layers
   UndoLock lock(pView);

   // Add the cube layer
   RasterLayer* pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, mpRasterElement));
   if (pLayer == NULL)
   {
      mProgress.report("Could not create the cube layer!", 0, ERRORS, true);
      return NULL;
   }
   pLayer->setStretchUnits(RED, RAW_VALUE);
   pLayer->setStretchUnits(GREEN, RAW_VALUE);
   pLayer->setStretchUnits(BLUE, RAW_VALUE);
   pLayer->setStretchValues(RED, 0, 255);
   pLayer->setStretchValues(GREEN, 0, 255);
   pLayer->setStretchValues(BLUE, 0, 255);
   if (pLayer->isGpuImageSupported())
   {
      pLayer->enableGpuImage(true);
   }
   return pView;
}
Esempio n. 18
0
void FrameLabelObjectImp::setAnimations(View* pView)
{
   if (getLocked() == false)
   {
      reset();
      vector<Animation*> pAnimations;
      if (pView != NULL)
      {
         SpatialDataView* pSpatialDataView = dynamic_cast<SpatialDataView*>(pView);
         if (pSpatialDataView == NULL)
         {
            mpView.reset(pView);
            mpAnimationController.reset(mpView->getAnimationController());
            if (mpAnimationController.get() != NULL)
            {
               pAnimations = mpAnimationController->getAnimations();
            }
         }
         else
         {
            mpLayerList.reset(pSpatialDataView->getLayerList());
            VERIFYNRV(mpLayerList.get() != NULL);

            vector<Layer*> pLayers;
            mpLayerList->getLayers(RASTER, pLayers);
            for (vector<Layer*>::iterator iter = pLayers.begin(); iter != pLayers.end(); ++iter)
            {
               RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(*iter);
               VERIFYNRV(pRasterLayer != NULL);
               pRasterLayer->attach(SIGNAL_NAME(RasterLayer, AnimationChanged),
                  Slot(this, &FrameLabelObjectImp::updateAnimations));
               pRasterLayer->attach(SIGNAL_NAME(Subject, Deleted),
                  Slot(this, &FrameLabelObjectImp::layerDeleted));
               mLayers.push_back(pRasterLayer);
               if (pRasterLayer->getAnimation() != NULL)
               {
                  pAnimations.push_back(pRasterLayer->getAnimation());
               }
            }
         }
      }

      insertAnimations(pAnimations);
   }
}
Esempio n. 19
0
 int getRasterLayerColormapValues(Layer* pLayer, uint32_t* pColormap)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL || pColormap == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    const std::vector<ColorType>& colormap = pRaster->getColorMap().getTable();
    if (colormap.size() != 256)
    {
       setLastError(SIMPLE_NO_MEM);
       return 1;
    }
    for (size_t idx = 0; idx < colormap.size(); ++idx)
    {
       pColormap[idx] = encodeColor(colormap[idx]);
    }
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 20
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. 21
0
void Timeline::UpdateCanvas()
{
    std::vector<QImage*> layerImages;
    std::vector<QImage*> onions;
    QImage* editImage = NULL;

    for (size_t i = 0; i < mLayers.size(); ++i)
    {
        if (!mLayers[i]->IsEnabled())
        {
            continue;
        }
        QImage* img = mLayers[i]->GetImage(mFrameIndex);
        if (img)
        {
            if (mLayerIndex == i)
            {
                if (mLayers[i]->GetType() == LayerTypeRaster)
                {
                    RasterLayer* l = (RasterLayer*)mLayers[i];
                    QImage* prev = l->GetImage(l->GetPrevImageIndex(mFrameIndex));
                    if(prev && prev != img)
                    {
                        onions.push_back(prev);
                    }
                    QImage* next = l->GetImage(l->GetNextImageIndex(mFrameIndex));
                    if(next && next != img)
                    {
                        onions.push_back(next);
                    }
                }

                editImage = img;
            }
            layerImages.push_back(img);
        }
    }
    mEditor->Load(editImage);
    update();
}
Esempio n. 22
0
 int setRasterLayerDisplayedBand(Layer* pLayer, uint32_t channel, uint32_t band, DataElement* pElement)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    RasterChannelType chan(static_cast<RasterChannelTypeEnum>(channel));
    if (pRaster == NULL || !chan.isValid())
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    RasterElement* pRasterElement =
       (pElement == NULL) ? pRaster->getDisplayedRasterElement(chan) : dynamic_cast<RasterElement*>(pElement);
    if (pRasterElement == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    DimensionDescriptor bandDD(static_cast<const RasterDataDescriptor*>(
       pRasterElement->getDataDescriptor())->getActiveBand(band));
    pRaster->setDisplayedBand(chan, bandDD, pRasterElement);
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 23
0
 uint32_t getRasterLayerColormapName(Layer* pLayer, char* pName, uint32_t nameSize)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    std::string name = pRaster->getColorMap().getName();
    if (nameSize == 0)
    {
       return name.size() + 1;
    }
    else if (name.size() > nameSize - 1) // extra char for the null
    {
       setLastError(SIMPLE_BUFFER_SIZE);
       return 0;
    }
    memcpy(pName, name.c_str(), name.size());
    pName[name.size()] = '\0';
    setLastError(SIMPLE_NO_ERROR);
    return name.size();
 }
Esempio n. 24
0
bool TimelineWidget::saveAnimationTimes(Animation  *pAnim)
{
   if(pAnim == NULL)
   {
      return false;
   }
   bool success = false;
   const std::vector<AnimationFrame> frames = pAnim->getFrames();
   std::vector<double> times(frames.size(), 0.0);
   for(unsigned int idx = 0; idx < frames.size(); idx++)
   {
      times[idx] = frames[idx].mTime;
   }

   std::vector<Window*> windows;
   Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows);
   for(std::vector<Window*>::iterator window = windows.begin(); window != windows.end(); ++window)
   {
      SpatialDataView *pView = static_cast<SpatialDataWindow*>(*window)->getSpatialDataView();
      std::vector<Layer*> layers;
      pView->getLayerList()->getLayers(RASTER, layers);
      for(std::vector<Layer*>::iterator layer = layers.begin(); layer != layers.end(); ++layer)
      {
         RasterLayer *pLayer = static_cast<RasterLayer*>(*layer);
         if(pLayer->getAnimation() == pAnim)
         {
            RasterElement *pElement = static_cast<RasterElement*>(pLayer->getDataElement());
            DynamicObject *pMetadata = static_cast<RasterDataDescriptor*>(pElement->getDataDescriptor())->getMetadata();
            if(pMetadata != NULL)
            {
               success = success || pMetadata->setAttributeByPath(FRAME_TIMES_METADATA_PATH, times);
            }
         }
      }
   }
   return success;
}
Esempio n. 25
0
 int setRasterLayerFilters(Layer* pLayer, uint32_t count, const char** pFilters)
 {
    RasterLayer* pRaster = dynamic_cast<RasterLayer*>(pLayer);
    if (pRaster == NULL || (count > 0 && pFilters == NULL))
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 1;
    }
    std::vector<std::string> filters;
    filters.reserve(count);
    for (size_t idx = 0; idx < count; ++idx)
    {
       if (pFilters[idx] == NULL)
       {
          setLastError(SIMPLE_BAD_PARAMS);
          return 1;
       }
       filters.push_back(std::string(pFilters[idx]));
    }
    pRaster->enableFilters(filters);
    pRaster->getView()->refresh();
    setLastError(SIMPLE_NO_ERROR);
    return 0;
 }
Esempio n. 26
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. 27
0
bool Kml::addLayer(Layer* pLayer, const Layer* pGeoLayer, const SpatialDataView* pView, int totalLayers)
{
   if (pLayer == NULL)
   {
      return false;
   }
   switch (pLayer->getLayerType())
   {
   case ANNOTATION:
   case AOI_LAYER:
   case GRAPHIC_LAYER:
      // These are polygonal layers
      generatePolygonalLayer(dynamic_cast<GraphicLayer*>(pLayer),
         pView->isLayerDisplayed(pLayer), totalLayers - pView->getLayerDisplayIndex(pLayer), pGeoLayer);
      break;
   case RASTER:
      {
         RasterLayer* pRasterLayer = dynamic_cast<RasterLayer*>(pLayer);
         RasterElement* pRasterElement = pRasterLayer->getDisplayedRasterElement(GRAY);
         if (pRasterElement != NULL)
         {
            bool layerIsDisplayed = pView->isLayerDisplayed(pLayer);
            int order = totalLayers - pView->getLayerDisplayIndex(pLayer) - 1;
            if (pView->getAnimationController() == NULL)
            {
               generateGroundOverlayLayer(pLayer, layerIsDisplayed, order, pGeoLayer, -1);
            }
            else
            {
               mXml.pushAddPoint(mXml.addElement("Folder"));
               mXml.addText("Frame Data", mXml.addElement("name"));
               vector<DimensionDescriptor> frames =
                  static_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor())->getBands();
               for (vector<DimensionDescriptor>::const_iterator frame = frames.begin(); frame != frames.end(); ++frame)
               {
                  generateGroundOverlayLayer(pLayer, layerIsDisplayed, order, pGeoLayer, frame->getActiveNumber());
               }
               mXml.popAddPoint();
            }
            break;
         }
         // fall through...if there is no displayed raster element, export the flattened layer
      }
   case PSEUDOCOLOR:
   case THRESHOLD:
      // These are image layers
      generateGroundOverlayLayer(pLayer, pView->isLayerDisplayed(pLayer),
         totalLayers - pView->getLayerDisplayIndex(pLayer), pGeoLayer);
      break;
   case CONTOUR_MAP:
   case LAT_LONG:
   case TIEPOINT_LAYER:
   default:
      // These are unsupported layers
      if (mpProgress != NULL)
      {
         mpProgress->updateProgress("Unable to export unsupported layer " + pLayer->getName(), 0, WARNING);
      }
      return false;
   }
   return true;
}
Esempio n. 28
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. 29
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;
}
Esempio n. 30
0
bool SampleGeoref::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
    // Do any kind of setup we need before converting coordinates.
    // In this case, get our X and Y factors.

    StepResource pStep("Run Sample Georef", "app", "CFCB8AA9-D504-42e9-86F0-547DF9B4798A");
    Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg());

    FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false);

    // Default values
    bool animated = false;

    // get factors from pInArgList
    pInArgList->getPlugInArgValue("XSize", mXSize);
    pInArgList->getPlugInArgValue("YSize", mYSize);
    pInArgList->getPlugInArgValue("Extrapolate", mExtrapolate);
    pInArgList->getPlugInArgValue("Animated", animated);
    pInArgList->getPlugInArgValue("Rotate", mRotate);

    View* pView = pInArgList->getPlugInArgValue<View>(Executable::ViewArg());
    mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg());
    FAIL_IF(mpRaster == NULL, "Could not find raster element", return false);

    if (mpGui != NULL)
    {
        mXSize = mpGui->getXSize();
        mYSize = mpGui->getYSize();
        animated = mpGui->getAnimated();
        mRotate = mpGui->getRotate();
        mExtrapolate = mpGui->getExtrapolate();
    }

    if (animated)
    {
        SpatialDataView* pSpatialView = dynamic_cast<SpatialDataView*>(pView);
        FAIL_IF(pSpatialView == NULL, "Could not find spatial data view.", return false);

        LayerList* pLayerList = pSpatialView->getLayerList();
        FAIL_IF(pLayerList == NULL, "Could not find layer list.", return false);

        RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pLayerList->getLayer(RASTER, mpRaster));
        FAIL_IF(pLayer == NULL, "Could not find raster layer", return false);

        Animation* pAnim = pLayer->getAnimation();
        FAIL_IF(pAnim == NULL, "Could not find animation", return false);

        const std::vector<AnimationFrame>& frames = pAnim->getFrames();
        FAIL_IF(frames.empty(), "No frames in animation.", return false);

        mpAnimation.reset(pAnim);
        mFrames = frames.size();
        mCurrentFrame = 0;
    }

    RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor());
    FAIL_IF(pDescriptor == NULL, "Could not get data descriptor.", return false);

    unsigned int rows = pDescriptor->getRowCount();
    unsigned int cols = pDescriptor->getColumnCount();
    unsigned int bands = pDescriptor->getBandCount();

    mXScale = static_cast<double>(mXSize) / rows;
    mYScale = static_cast<double>(mYSize) / cols;

    mpRaster->setGeoreferencePlugin(this);

    mpGui = NULL; // Pointer not guaranteed to be valid after execute() is called
    return true;
}