Пример #1
0
QStringList ReplaceBandInputWizard::getBandNames(const RasterDataDescriptor* pDesc) const
{
   const DynamicObject* pMetadata = pDesc->getMetadata();
   const std::vector<DimensionDescriptor>& bands = pDesc->getBands();

   std::vector<std::string> bandNames;
   std::string pNamesPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, NAMES_METADATA_NAME, END_METADATA_NAME };
   const std::vector<std::string>* pBandNames = dv_cast<std::vector<std::string> >(&pMetadata->getAttributeByPath(pNamesPath));
   if ((pBandNames != NULL) && (pBandNames->size() == bands.size()))
   {
      bandNames = *pBandNames;
   }
   else
   {
      std::string pPrefixPath[] = { SPECIAL_METADATA_NAME, BAND_NAME_PREFIX_METADATA_NAME, END_METADATA_NAME };
      const std::string* pBandPrefix = dv_cast<std::string>(&pMetadata->getAttributeByPath(pPrefixPath));
      if (pBandPrefix != NULL)
      {
         std::string bandNamePrefix = *pBandPrefix;
         for (std::vector<DimensionDescriptor>::const_iterator band = bands.begin(); band != bands.end(); ++band)
         {
            bandNames.push_back(bandNamePrefix + " " + StringUtilities::toDisplayString(band->getOriginalNumber() + 1));
         }
      }
   }
   QStringList qBandNames;
   for (unsigned int i = 0; i < bands.size(); i++)
   {
      DimensionDescriptor bandDim = bands[i];
      QString name;
      if ((i < bandNames.size()) && (bands.size() == bandNames.size()))
      {
         name = QString::fromStdString(bandNames[i]);
      }
      else
      {
         name = "Band ";
         if (bandDim.isOriginalNumberValid())
         {
            unsigned int originalNumber = bandDim.getOriginalNumber() + 1;
            name.append(QString::number(originalNumber));
         }
      }
      qBandNames.append(name);
   }
   return qBandNames;
}
Пример #2
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.");
         }
      }
   }
}
RasterLayer* RasterElementImporterShell::createRasterLayer(SpatialDataView* pView, Step* pStep) const
{
   if ((pView == NULL) || (mpRasterElement == NULL))
   {
      return NULL;
   }

   RasterLayer* pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, mpRasterElement));
   if (pLayer != NULL)
   {
      // Log the initial cube layer properties
      const RasterDataDescriptor* pDescriptor =
         dynamic_cast<RasterDataDescriptor*>(mpRasterElement->getDataDescriptor());
      VERIFYRV(pDescriptor != NULL, NULL);

      if (pStep != NULL)
      {
         DimensionDescriptor grayBand = pDescriptor->getDisplayBand(GRAY);
         DimensionDescriptor redBand = pDescriptor->getDisplayBand(RED);
         DimensionDescriptor greenBand = pDescriptor->getDisplayBand(GREEN);
         DimensionDescriptor blueBand = pDescriptor->getDisplayBand(BLUE);
         DisplayMode displayMode = pDescriptor->getDisplayMode();

         if (grayBand.isOriginalNumberValid())
         {
            pStep->addProperty("Gray Band", grayBand.getOriginalNumber());
         }

         if (redBand.isOriginalNumberValid())
         {
            pStep->addProperty("Red Band", redBand.getOriginalNumber());
         }
         else
         {
            pStep->addProperty("Red Band", "No Band Displayed");
         }

         if (greenBand.isOriginalNumberValid())
         {
            pStep->addProperty("Green Band", greenBand.getOriginalNumber());
         }
         else
         {
            pStep->addProperty("Green Band", "No Band Displayed");
         }

         if (blueBand.isOriginalNumberValid())
         {
            pStep->addProperty("Blue Band", blueBand.getOriginalNumber());
         }
         else
         {
            pStep->addProperty("Blue Band", "No Band Displayed");
         }

         pStep->addProperty("Display Mode", StringUtilities::toDisplayString(displayMode));
      }
   }
   else
   {
      string message = "Could not create the raster layer.";
      if (mpProgress != NULL)
      {
         mpProgress->updateProgress(message, 0, WARNING);
      }

      if (pStep != NULL)
      {
         pStep->addMessage(message, "app", "3F06A978-3F1A-4E03-BBA7-E295A8B7CF72");
      }
   }

   return pLayer;
}
bool RasterElementImporterShell::validate(const DataDescriptor* pDescriptor,
                                          const vector<const DataDescriptor*>& importedDescriptors,
                                          string& errorMessage) const
{
   bool isValid = ImporterShell::validate(pDescriptor, importedDescriptors, errorMessage);
   if (isValid == false)
   {
      ValidationTest errorTest = getValidationError();
      if (errorTest == NO_PRE_POST_BAND_BYTES)
      {
         errorMessage += "  Preband and postband bytes are not supported for interleave formats other than BSQ.";
      }
      else if (errorTest == NO_BAND_FILES)
      {
         errorMessage += "  Bands in multiple files are not supported for interleave formats other than BSQ.";
      }
      else if ((errorTest == NO_INTERLEAVE_CONVERSIONS) || (errorTest == NO_ROW_SKIP_FACTOR) ||
         (errorTest == NO_COLUMN_SKIP_FACTOR) || (errorTest == NO_BAND_SUBSETS))
      {
         errorMessage = errorMessage.substr(0, errorMessage.length() - 1);
         errorMessage += " with on-disk read-only processing.";
      }
   }
   else
   {
      // Check for display bands that are not loaded
      const RasterDataDescriptor* pRasterDescriptor = dynamic_cast<const RasterDataDescriptor*>(pDescriptor);
      VERIFY(pRasterDescriptor != NULL);

      DimensionDescriptor grayBand = pRasterDescriptor->getDisplayBand(GRAY);
      if (grayBand.isOriginalNumberValid() == true)
      {
         DimensionDescriptor band = pRasterDescriptor->getOriginalBand(grayBand.getOriginalNumber());
         if (band.isValid() == false)
         {
            if (errorMessage.empty() == false)
            {
               errorMessage += "\n";
            }

            errorMessage += "The gray display band is not available.  The first loaded band will be displayed instead.";
         }
      }

      DimensionDescriptor redBand = pRasterDescriptor->getDisplayBand(RED);
      if (redBand.isOriginalNumberValid() == true)
      {
         DimensionDescriptor band = pRasterDescriptor->getOriginalBand(redBand.getOriginalNumber());
         if (band.isValid() == false)
         {
            if (errorMessage.empty() == false)
            {
               errorMessage += "\n";
            }

            errorMessage += "The red display band is not available.  The first loaded band will be displayed instead.";
         }
      }

      DimensionDescriptor greenBand = pRasterDescriptor->getDisplayBand(GREEN);
      if (greenBand.isOriginalNumberValid() == true)
      {
         DimensionDescriptor band = pRasterDescriptor->getOriginalBand(greenBand.getOriginalNumber());
         if (band.isValid() == false)
         {
            if (errorMessage.empty() == false)
            {
               errorMessage += "\n";
            }

            errorMessage += "The green display band is not available.  The first loaded band will be "
               "displayed instead.";
         }
      }

      DimensionDescriptor blueBand = pRasterDescriptor->getDisplayBand(BLUE);
      if (blueBand.isOriginalNumberValid() == true)
      {
         DimensionDescriptor band = pRasterDescriptor->getOriginalBand(blueBand.getOriginalNumber());
         if (band.isValid() == false)
         {
            if (errorMessage.empty() == false)
            {
               errorMessage += "\n";
            }

            errorMessage += "The blue display band is not available.  The first loaded band will be displayed instead.";
         }
      }
   }

   return isValid;
}
Пример #5
0
bool BandMath::createReturnValue(string partialResultsName)
{
   // Set the short and long result names
   FactoryResource<Filename> pFilename;
   string shortResultsName;
   string longResultsName;
   if (pFilename.get() != NULL)
   {
      pFilename->setFullPathAndName(mpCube->getFilename());
      shortResultsName = pFilename->getTitle() + " = " + partialResultsName;
      longResultsName = pFilename->getPath() + "/" + pFilename->getTitle() + " = " + partialResultsName;
   }
   mResultsName = longResultsName;

   const RasterDataDescriptor* pOrigDescriptor = dynamic_cast<RasterDataDescriptor*>(mpCube->getDataDescriptor());
   const vector<DimensionDescriptor>& origRows = pOrigDescriptor->getRows();
   const vector<DimensionDescriptor>& origColumns = pOrigDescriptor->getColumns();

   mpResultData = NULL;

   unsigned int bandCount = mCubeBands;
   if (mbCubeMath == false)
   {
      bandCount = 1;
   }

   RasterElement* pParent = NULL;
   if (mbAsLayerOnExistingView)
   {
      pParent = mpCube;
   }
   RasterElement* pRaster = RasterUtilities::createRasterElement(mResultsName, origRows.size(),
      origColumns.size(), bandCount, FLT4BYTES, BIP, pOrigDescriptor->getProcessingLocation() == IN_MEMORY, pParent);

   if (pRaster == NULL)
   {
      mstrProgressString = "Error creating result raster element";
      meGabbiness = ERRORS;
      displayErrorMessage();
      mbError = true;
      return false;
   }

   if (!mbAsLayerOnExistingView)
   {
      // need to copy classification since parent was NULL in call to createRasterElement
      pRaster->copyClassification(mpCube);

      // make copies of existing GcpLists only if going into a new view
      vector<DataElement*> gcps = mpDataModel->getElements(mpCube, "GcpList");
      if (!gcps.empty())
      {
         vector<DataElement*>::iterator iter;
         for (iter = gcps.begin(); iter != gcps.end(); ++iter)
         {
            GcpList* theGcp = dynamic_cast<GcpList*>(*iter);
            theGcp->copy(theGcp->getName(), pRaster);
         }
      }
   }

   mpResultData = pRaster;

   RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>
      (mpResultData->getDataDescriptor());
   if (pDescriptor != NULL)
   {
      // Rows
      vector<DimensionDescriptor> rows = pDescriptor->getRows();
      for (unsigned int i = 0; i < origRows.size(); ++i)
      {
         // Original number
         DimensionDescriptor origRow = origRows[i];
         if (origRow.isOriginalNumberValid() == true)
         {
            rows[i].setOriginalNumber(origRow.getOriginalNumber());
         }
      }
      pDescriptor->setRows(rows);

      // Columns
      vector<DimensionDescriptor> columns = pDescriptor->getColumns();
      for (unsigned int i = 0; i < origColumns.size(); ++i)
      {
         // Original number
         DimensionDescriptor origColumn = origColumns[i];
         if (origColumn.isOriginalNumberValid() == true)
         {
            columns[i].setOriginalNumber(origColumn.getOriginalNumber());
         }
      }
      pDescriptor->setColumns(columns);
   }

   return true;
}