SpatialDataView* Nitf::NitfImporterShell::createView() const { SpatialDataView* pView = RasterElementImporterShell::createView(); VERIFYRV(pView != NULL, pView); RasterElement* pRaster = getRasterElement(); VERIFYRV(pRaster != NULL, pView); const DynamicObject* pMetadata = pRaster->getMetadata(); VERIFYRV(pMetadata != NULL, pView); const string backgroundColorPath[] = { Nitf::NITF_METADATA, Nitf::FILE_HEADER, Nitf::FileHeaderFieldNames::BACKGROUND_COLOR, END_METADATA_NAME }; const DataVariant& dvBackground = pMetadata->getAttributeByPath(backgroundColorPath); if (dvBackground.isValid() == true) { ColorType ctBackground; VERIFY(dvBackground.getValue(ctBackground) == true); pView->setBackgroundColor(ctBackground); pView->refresh(); } return pView; }
void ReplaceBandInputWizard::addSourcePage() { QWizardPage* pPage = new QWizardPage(this); pPage->setTitle("Select source data element"); QLabel* pPageLabel = new QLabel("Select the source data element.", pPage); pPageLabel->setWordWrap(true); mpSource = new QComboBox(pPage); mpSource->setEditable(false); const RasterDataDescriptor* pDestDesc = static_cast<const RasterDataDescriptor*>(mpDest->getDataDescriptor()); std::vector<DataElement*> rasters = Service<ModelServices>()->getElements(TypeConverter::toString<RasterElement>()); for(std::vector<DataElement*>::iterator raster = rasters.begin(); raster != rasters.end(); ++raster) { RasterElement* pRaster = static_cast<RasterElement*>(*raster); if (pRaster == mpDest) { continue; } const RasterDataDescriptor* pDesc = static_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); if (pDesc->getRowCount() == pDestDesc->getRowCount() && pDesc->getColumnCount() == pDestDesc->getColumnCount() && pDesc->getDataType() == pDestDesc->getDataType()) { mpSource->addItem(QString::fromStdString(pRaster->getName()), reinterpret_cast<qulonglong>(pRaster)); } } QVBoxLayout* pLayout = new QVBoxLayout(); pLayout->addWidget(pPageLabel); pLayout->addWidget(mpSource); pPage->setLayout(pLayout); addPage(pPage); }
void MeasurementObjectImp::updateGeoreferenceAttachment() { if (mpGeoreference.get() != NULL) { return; } RasterElement* pGeoreference = NULL; // Must find Georeference through the view, since the GraphicElement is a root element. GraphicLayer* pLayer = getLayer(); if (pLayer != NULL) { SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView()); if (pView != NULL) { LayerList* pLayerList = pView->getLayerList(); VERIFYNRV(pLayerList != NULL); pGeoreference = pLayerList->getPrimaryRasterElement(); } } if (pGeoreference != NULL && pGeoreference->isGeoreferenced()) { mpGeoreference.reset(pGeoreference); enableGeo(); generateGeoStrings(); } }
DataAccessorImpl* createDataAccessor(DataElement* pElement, DataAccessorArgs* pArgs) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } FactoryResource<DataRequest> pRequest; RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pArgs != NULL) { pRequest->setRows(pDescriptor->getActiveRow(pArgs->rowStart), pDescriptor->getActiveRow(pArgs->rowEnd),pArgs->concurrentRows); pRequest->setColumns(pDescriptor->getActiveColumn(pArgs->columnStart), pDescriptor->getActiveColumn(pArgs->columnEnd),pArgs->concurrentColumns); pRequest->setBands(pDescriptor->getActiveBand(pArgs->bandStart), pDescriptor->getActiveBand(pArgs->bandEnd),pArgs->concurrentBands); pRequest->setInterleaveFormat(static_cast<InterleaveFormatTypeEnum>(pArgs->interleaveFormat)); pRequest->setWritable(pArgs->writable != 0); } DataAccessor dataAccessor(pRasterElement->getDataAccessor(pRequest.release())); if (!dataAccessor.isValid()) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } DataAccessorImpl* pRval = dataAccessor.operator->(); pRval->incrementRefCount(); setLastError(SIMPLE_NO_ERROR); return pRval; }
void ChippingWindow::accept() { // Check if the original data set has been georeferenced if (mpView != NULL) { RasterElement* pRaster = getRasterElement(); VERIFYNRV(pRaster != NULL); // Display a warning if the data set has not been georeferenced if (pRaster->isGeoreferenced() == false) { QString strMessage = "The parent data set is not georeferenced so the created chip will not " "contain a GCP List.\nIf you want to preserve geographic info, press Cancel, cancel the " "chipping dialog,\ngeoreference the parent data set, and then create a new chip."; int iReturn = QMessageBox::warning(this, windowTitle(), strMessage, "Continue", "Cancel"); if (iReturn == 1) { return; } } } // Create the chip if (mpFileRadio->isChecked() == true) { createFile(); } else if (mpWindowRadio->isChecked() == true) { createView(); } // Close the dialog QDialog::accept(); }
void updateRasterElement(DataElement* pElement) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return; } pRasterElement->updateData(); setLastError(SIMPLE_NO_ERROR); }
int copyDataToRasterElement(DataElement* pElement, DataPointerArgs* pArgs, void* pData) { RasterElement* pRaster = dynamic_cast<RasterElement*>(pElement); if (pRaster == NULL || pData == NULL) { setLastError(SIMPLE_BAD_PARAMS); return 1; } const RasterDataDescriptor* pDesc = static_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); void* pRawData = pRaster->getRawData(); if (pArgs == NULL && pRawData != NULL) { size_t len = pDesc->getRowCount() * pDesc->getColumnCount() * pDesc->getBandCount() * pDesc->getBytesPerElement(); memcpy(pRawData, pData, len); setLastError(SIMPLE_NO_ERROR); return 0; } DataPointerArgs args = { 0, pDesc->getRowCount() - 1, 0, pDesc->getColumnCount() - 1, 0, pDesc->getBandCount() - 1, 0 }; switch (pDesc->getInterleaveFormat()) { case BSQ: args.interleaveFormat = 0; break; case BIP: args.interleaveFormat = 1; break; case BIL: args.interleaveFormat = 2; break; } if (pArgs == NULL) { pArgs = &args; } bool success = true; switchOnComplexEncoding(pDesc->getDataType(), copySubcube, pData, pRaster, pArgs->rowStart, pArgs->rowEnd, pArgs->columnStart, pArgs->columnEnd, pArgs->bandStart, pArgs->bandEnd, true, success); if (!success) { setLastError(SIMPLE_OTHER_FAILURE); return 1; } setLastError(SIMPLE_NO_ERROR); return 0; }
bool PseudocolorLayerImp::getExtents(double& x1, double& y1, double& x4, double& y4) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(getDataElement()); VERIFY(pRasterElement != NULL); const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); VERIFY(pDescriptor != NULL); translateDataToWorld(0, 0, x1, y1); translateDataToWorld(pDescriptor->getColumnCount(), pDescriptor->getRowCount(), x4, y4); return true; }
void ChippingWindow::createFile() { if (mpChippingWidget == NULL) { return; } RasterElement* pRaster = getRasterElement(); if (pRaster == NULL) { return; } const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); if (pDescriptor == NULL) { return; } // Rows const vector<DimensionDescriptor>& rows = mpChippingWidget->getChipRows(); const DimensionDescriptor startRow = rows.front(); const DimensionDescriptor stopRow = rows.back(); // Columns const vector<DimensionDescriptor>& columns = mpChippingWidget->getChipColumns(); const DimensionDescriptor startCol = columns.front(); const DimensionDescriptor stopCol = columns.back(); // Create a file descriptor based on the data with the chip rows and columns FactoryResource<FileDescriptor> fileDescriptor(RasterUtilities::generateFileDescriptorForExport(pDescriptor, string(), startRow, stopRow, 0, startCol, stopCol, 0, mpChippingWidget->getChipBands())); Service<DesktopServices>()->exportSessionItem(pRaster, fileDescriptor.get()); }
bool Kml::addView(const SpatialDataView* pView) { if (pView == NULL) { return false; } // ensure we are georeferenced RasterElement* pElement = static_cast<RasterElement*>(pView->getLayerList()->getPrimaryRasterElement()); VERIFY(pElement); if (!pElement->isGeoreferenced()) { if (mpProgress != NULL) { mpProgress->updateProgress("The " + pView->getDisplayName(true) + " view does not have georeference information and will not be exported.", 0, ERRORS); } return false; } Layer* pPrimaryLayer = pView->getLayerList()->getLayer(RASTER, pElement); mXml.pushAddPoint(mXml.addElement("Folder")); string name = pView->getDisplayName(); if (name.empty()) { name = pView->getName(); } mXml.addText(name, mXml.addElement("name")); mXml.addText(pView->getDisplayText(), mXml.addElement("description")); bool success = false; vector<Layer*> layers; pView->getLayerList()->getLayers(layers); int totalLayers = static_cast<int>(pView->getLayerList()->getNumLayers()); for (vector<Layer*>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer) { if (!pView->isLayerDisplayed(*layer)) { continue; } if (addLayer(*layer, pPrimaryLayer, pView, totalLayers)) { success = true; } } mXml.popAddPoint(); // Folder return success; }
DataAccessor getAccessor(int band, bool writable = false) { FactoryResource<DataRequest> pRequest = FactoryResource<DataRequest>(); pRequest->setRows(pDataDescriptor->getActiveRow(0), pDataDescriptor->getActiveRow(getRowCount() - 1)); pRequest->setColumns(pDataDescriptor->getActiveColumn(0), pDataDescriptor->getActiveColumn(getColumnCount() - 1)); pRequest->setBands(pDataDescriptor->getActiveBand(band), pDataDescriptor->getActiveBand(band)); pRequest->setWritable(writable); return pRaster->getDataAccessor(pRequest.release()); }
void SpectralLibraryMatchResults::elementModified(Subject& subject, const std::string& signal, const boost::any& value) { // check for rename RasterElement* pRaster = dynamic_cast<RasterElement*>(&subject); if (pRaster != NULL) { ResultsPage* pPage = getPage(pRaster); if (pPage != NULL) { int index = mpTabWidget->indexOf(pPage); if (index != -1 && mpTabWidget->tabToolTip(index).toStdString() != pRaster->getName()) { mpTabWidget->setTabText(index, QString::fromStdString(pRaster->getDisplayName(true))); mpTabWidget->setTabToolTip(index, QString::fromStdString(pRaster->getName())); } } } }
Image(SpatialDataView* iPView) : pView(iPView) { LayerList* pLayerList = pView->getLayerList(); VERIFYNRV(pLayerList != NULL); pRaster = dynamic_cast<RasterElement*>(pLayerList->getPrimaryRasterElement()); VERIFYNRV(pRaster != NULL); pDataDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); VERIFYNR(pDataDescriptor != NULL); /* Service<DesktopServices> pDesktop; VERIFYNRV(pDesktop.get() != NULL); SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(pDesktop->getWindow(pRaster->getName(), SPATIAL_DATA_WINDOW)); VERIFYNRV(pWindow != NULL); VERIFYNRV(pDesktop->setCurrentWorkspaceWindow(pWindow));*/ }
void PropertiesRasterLayer::setDisplayBands(QAction* pAction) { if (mpRasterLayer == NULL) { return; } RasterElement* pRasterElement = dynamic_cast<RasterElement*>(mpRasterLayer->getDataElement()); if (pRasterElement == NULL) { return; } const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pDescriptor == NULL) { return; } const std::string name = pAction->text().toStdString(); DimensionDescriptor redBand; DimensionDescriptor greenBand; DimensionDescriptor blueBand; if (RasterUtilities::findColorCompositeDimensionDescriptors( pDescriptor, name, redBand, greenBand, blueBand) == false) { Service<DesktopServices>()->showSuppressibleMsgDlg("Error", "Unable to display " + name + ": required wavelengths do not exist for all bands. " "Broaden the wavelength region or specify band numbers in the Raster Layers section of the Options dialog.", MESSAGE_ERROR, PropertiesRasterLayer::getDisplayAsWarningDialogId()); } // If at least one of red, green, or blue is valid set display mode to RGB and update the combo boxes appropriately if (redBand.isActiveNumberValid() || greenBand.isActiveNumberValid() || blueBand.isActiveNumberValid()) { mpDisplayModeCombo->setCurrentIndex(1); mpRedBandCombo->setCurrentIndex(redBand.isActiveNumberValid() ? redBand.getActiveNumber() : -1); mpGreenBandCombo->setCurrentIndex(greenBand.isActiveNumberValid() ? greenBand.getActiveNumber() : -1); mpBlueBandCombo->setCurrentIndex(blueBand.isActiveNumberValid() ? blueBand.getActiveNumber() : -1); } }
RasterElement* ResultsExporter::getGeoreferencedRaster() const { if (mpResults == NULL) { return NULL; } // First check if this RasterElement is georeferenced if (mpResults->isGeoreferenced()) { return mpResults; } // Next, assume this is a "Results matrix" and check the parent RasterElement* pParent = dynamic_cast<RasterElement*>(mpResults->getParent()); if (pParent != NULL && pParent->isGeoreferenced()) { return pParent; } // Finally, give up...there's no geodata return NULL; }
void ReplaceBandInputWizard::initializePage(int id) { if (id == mSourceBandId) { mpSourceBand->clear(); RasterElement* pSource = getSourceElement(); if (pSource != NULL) { mpSourceBand->addItems(getBandNames(static_cast<const RasterDataDescriptor*>(pSource->getDataDescriptor()))); } } }
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; }
DataInfo* createDataInfo(DataElement* pElement) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pDescriptor == NULL) { setLastError(SIMPLE_OTHER_FAILURE); return NULL; } DataInfo* pDataInfo = new DataInfo; pDataInfo->numRows = pDescriptor->getRowCount(); pDataInfo->numColumns = pDescriptor->getColumnCount(); pDataInfo->numBands = pDescriptor->getBandCount(); pDataInfo->encodingType = static_cast<uint32_t>(pDescriptor->getDataType()); pDataInfo->encodingTypeSize = RasterUtilities::bytesInEncoding(pDescriptor->getDataType()); pDataInfo->interleaveFormat = static_cast<uint32_t>(pDescriptor->getInterleaveFormat()); const std::vector<int>& badValues = pDescriptor->getBadValues(); pDataInfo->numBadValues = badValues.size(); if (pDataInfo->numBadValues == 0) { pDataInfo->pBadValues = NULL; } else { pDataInfo->pBadValues = new int32_t[pDataInfo->numBadValues]; memcpy(pDataInfo->pBadValues, &badValues[0], pDataInfo->numBadValues * sizeof(int32_t)); } setLastError(SIMPLE_NO_ERROR); return pDataInfo; }
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; }
Layer* ThresholdLayerAdapter::copy(const string& layerName, bool bCopyElement, DataElement* pParent) const { // Get the layer name string name = layerName; if (name.empty() == true) { name = getName(); } // Get the raster element RasterElement* pRasterElement = NULL; RasterElement* pCurrentRasterElement = dynamic_cast<RasterElement*>(getDataElement()); if (bCopyElement == true && pCurrentRasterElement != NULL) { pRasterElement = dynamic_cast<RasterElement*>(pCurrentRasterElement->copy(name, pParent)); } else { pRasterElement = pCurrentRasterElement; } if (pRasterElement == NULL) { return NULL; } // Create the new layer ThresholdLayerAdapter* pLayer = new ThresholdLayerAdapter(SessionItemImp::generateUniqueId(), name, pRasterElement); if (pLayer != NULL) { *pLayer = *this; } return pLayer; }
bool Sam::parseInputArgList(PlugInArgList* pInArgList) { mpProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); mProgress = ProgressTracker(mpProgress, "Spectral Angle Mapper", "spectral", "82DDE066-46DA-4241-94EE-5E3D16B5358E"); RasterElement* pElement = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pElement == NULL) { mProgress.report(SAMERR001, 0, ERRORS, true); return false; } const RasterDataDescriptor* pElementDescriptor = static_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); EncodingType dataType = pElementDescriptor->getDataType(); if (dataType == INT4SCOMPLEX || dataType == FLT8COMPLEX) { mProgress.report(SAMERR013, 0, ERRORS, true); return false; } // sensor is non-null and only one band -> bail out! if (pElementDescriptor->getBandCount() == 1) { mProgress.report(SAMERR014, 0, ERRORS, true); return false; } Signature* pSignatures = NULL; if (!isInteractive()) { pSignatures = pInArgList->getPlugInArgValue<Signature>("Target Signatures"); VERIFY(pInArgList->getPlugInArgValue("Threshold", mInputs.mThreshold)); mInputs.mpAoi = pInArgList->getPlugInArgValue<AoiElement>("AOI"); VERIFY(pInArgList->getPlugInArgValue("Display Results", mInputs.mbDisplayResults)); VERIFY(pInArgList->getPlugInArgValue("Results Name", mInputs.mResultsName)); mInputs.mSignatures = SpectralUtilities::extractSignatures(vector<Signature*>(1, pSignatures)); } const BitMask* pBitMask = NULL; if (mInputs.mpAoi != NULL) { pBitMask = mInputs.mpAoi->getSelectedPoints(); } mpSamAlg = new SamAlgorithm(pElement, mpProgress, isInteractive(), pBitMask); setAlgorithmPattern(Resource<AlgorithmPattern>(mpSamAlg)); return true; }
void EastArrowObjectImp::orient() { if (isOriented() == true) { return; } GraphicLayer* pLayer = NULL; pLayer = getLayer(); if (pLayer == NULL) { return; } View* pView = NULL; pView = pLayer->getView(); if (pView == NULL) { return; } SpatialDataView* pSpatialDataView = NULL; if (pView->isKindOf("SpatialDataView") == true) { pSpatialDataView = static_cast<SpatialDataView*> (pView); } else if (pView->isKindOf("ProductView") == true) { ProductView* pProductView = static_cast<ProductView*> (pView); GraphicLayer* pLayoutLayer = NULL; pLayoutLayer = pProductView->getLayoutLayer(); if (pLayoutLayer == pLayer) { list<GraphicObject*> viewObjects; pLayoutLayer->getObjects(VIEW_OBJECT, viewObjects); list<GraphicObject*>::iterator iter = viewObjects.begin(); while (iter != viewObjects.end()) { GraphicObject* pObject = *iter; if (pObject != NULL) { View* pObjectView = pObject->getObjectView(); if (pObjectView != NULL) { if (pObjectView->isKindOf("SpatialDataView") == true) { pSpatialDataView = static_cast<SpatialDataView*> (pObjectView); } } } ++iter; } } } if (pSpatialDataView == NULL) { return; } LayerList* pLayerList = pSpatialDataView->getLayerList(); VERIFYNRV(pLayerList != NULL); RasterElement* pRaster = pLayerList->getPrimaryRasterElement(); VERIFYNRV(pRaster != NULL); if (!pRaster->isGeoreferenced()) { return; } // Calculate the angle of the object relative to the pixel coordinates updateHandles(); LocationType pixelStart = mHandles[7]; ProductView* pProductView = dynamic_cast<ProductView*> (pView); if (pProductView != NULL) { // Convert to the screen coordinate system double dScreenX = 0; double dScreenY = 0; pLayer->translateDataToWorld(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY); pProductView->translateWorldToScreen(pixelStart.mX, pixelStart.mY, dScreenX, dScreenY); // Convert to the spatial data view coordinate system pSpatialDataView->translateScreenToWorld(dScreenX, dScreenY, pixelStart.mX, pixelStart.mY); pLayer->translateWorldToData(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY); } double dAngle; if (GeoAlgorithms::getAngleToNorth(pRaster, dAngle, pixelStart) == false) { return; } // Update the angle if the object is in the layout layer if (pProductView != NULL) { // Rotation dAngle -= pSpatialDataView->getRotation(); // Pitch double dPitch = pSpatialDataView->getPitch(); if (dPitch > 0.0) { dAngle *= -1.0; } } // Rotate the object setRotation(dAngle); // Update the orientation flag DirectionalArrowObjectImp::orient(); }
void* createDataPointer(DataElement* pElement, DataPointerArgs* pArgs, int* pOwn) { RasterElement* pRaster = dynamic_cast<RasterElement*>(pElement); if (pRaster == NULL || pOwn == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } void* pRawData = pRaster->getRawData(); if (pArgs == NULL && pRawData != NULL) { *pOwn = 0; setLastError(SIMPLE_NO_ERROR); return pRawData; } *pOwn = 1; const RasterDataDescriptor* pDesc = static_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); DataPointerArgs args = { 0, pDesc->getRowCount() - 1, 0, pDesc->getColumnCount() - 1, 0, pDesc->getBandCount() - 1, 0 }; switch (pDesc->getInterleaveFormat()) { case BSQ: args.interleaveFormat = 0; break; case BIP: args.interleaveFormat = 1; break; case BIL: args.interleaveFormat = 2; break; } if (pArgs == NULL) { pArgs = &args; } unsigned int rowCount = pArgs->rowEnd - pArgs->rowStart + 1; unsigned int columnCount = pArgs->columnEnd - pArgs->columnStart + 1; unsigned int bandCount = pArgs->bandEnd - pArgs->bandStart + 1; pRawData = new (std::nothrow) char[rowCount * columnCount * bandCount * pDesc->getBytesPerElement()]; if (pRawData == NULL) { setLastError(SIMPLE_NO_MEM); return NULL; } bool success = true; switchOnComplexEncoding(pDesc->getDataType(), copySubcube, pRawData, pRaster, pArgs->rowStart, pArgs->rowEnd, pArgs->columnStart, pArgs->columnEnd, pArgs->bandStart, pArgs->bandEnd, false, success); if (!success) { delete [] pRawData; setLastError(SIMPLE_OTHER_FAILURE); return NULL; } setLastError(SIMPLE_NO_ERROR); return pRawData; }
DataElement* createRasterElement(const char* pName, RasterElementArgs args) { if (pName == NULL || args.location > 2) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } // Check for an existing element with the name if (getDataElement(pName, TypeConverter::toString<RasterElement>(), 0) != NULL) { setLastError(SIMPLE_EXISTS); return NULL; } RasterElement* pElement = RasterUtilities::createRasterElement(std::string(pName), args.numRows, args.numColumns, args.numBands, static_cast<EncodingTypeEnum>(args.encodingType), static_cast<InterleaveFormatTypeEnum>(args.interleaveFormat), args.location != 2, args.pParent); if (pElement == NULL) { switch (args.location) { case 0: pElement = RasterUtilities::createRasterElement(std::string(pName), args.numRows, args.numColumns, args.numBands, static_cast<EncodingTypeEnum>(args.encodingType), static_cast<InterleaveFormatTypeEnum>(args.interleaveFormat), false, args.pParent); if (pElement == NULL) { setLastError(SIMPLE_OTHER_FAILURE); return NULL; } break; case 1: setLastError(SIMPLE_NO_MEM); return NULL; case 2: setLastError(SIMPLE_OTHER_FAILURE); return NULL; default: setLastError(SIMPLE_BAD_PARAMS); return NULL; } } if (args.pBadValues != NULL && args.numBadValues > 0) { RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); if (pDesc != NULL) { std::vector<int> badValues; badValues.reserve(args.numBadValues); for (uint32_t idx = 0; idx < args.numBadValues; ++idx) { badValues.push_back(args.pBadValues[idx]); } pDesc->setBadValues(badValues); // set on the statistics objects const std::vector<DimensionDescriptor>& allBands = pDesc->getBands(); for (std::vector<DimensionDescriptor>::const_iterator band = allBands.begin(); band != allBands.end(); ++band) { if (band->isValid()) { Statistics* pStats = pElement->getStatistics(*band); if (pStats != NULL) { pStats->setBadValues(badValues); } } } pElement->updateData(); } } setLastError(SIMPLE_NO_ERROR); return pElement; }
bool HIGHPASS::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Tutorial 5", "app", "219F1882-A59F-4835-BE2A-E83C0C8111EB"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "DResult", pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType())); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); int rowSize= pDesc->getRowCount(); int colSize = pDesc->getColumnCount(); int zero=0; int prevCol = 0; int prevRow = 0; int nextCol = 0; int nextRow = 0; int prevCol1 = 0; int prevRow1= 0; int nextCol1= 0; int nextRow1= 0; for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Calculating result", row * 100 / pDesc->getRowCount(), NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } return false; } if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { double value=edgeDetection7(pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount()); switchOnEncoding(pDesc->getDataType(), conversion, pDestAcc->getColumn(), value); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("HighPass is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Result", pResultCube.release()); pStep->finalize(); return true; }
QWidget* ResultsExporter::getExportOptionsWidget(const PlugInArgList *pInArgList) { const DataDescriptor* pDescriptor = NULL; if (pInArgList != NULL) { RasterElement* pElement = pInArgList->getPlugInArgValue<RasterElement>(Exporter::ExportItemArg()); if (pElement != NULL) { pDescriptor = pElement->getDataDescriptor(); } } if (mpOptionsWidget == NULL) { Service<DesktopServices> pDesktop; VERIFY(pDesktop.get() != NULL); mpOptionsWidget = new ResultsOptionsWidget(pDesktop->getMainWidget()); } if (mpOptionsWidget != NULL) { const string& name = pDescriptor->getName(); const string& type = pDescriptor->getType(); DataElement* pParent = pDescriptor->getParent(); RasterElement* pResults = dynamic_cast<RasterElement*>(mpModel->getElement(name, type, pParent)); if (pResults != NULL) { PassArea passArea = MIDDLE; double dFirstThreshold = 0.0; double dSecondThreshold = 0.0; SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(mpDesktop->getCurrentWorkspaceWindow()); if (pWindow != NULL) { SpatialDataView* pView = pWindow->getSpatialDataView(); if (pView != NULL) { LayerList* pLayerList = pView->getLayerList(); if (pLayerList != NULL) { ThresholdLayer* pThresholdLayer = static_cast<ThresholdLayer*>(pLayerList->getLayer(THRESHOLD, pResults)); if (pThresholdLayer != NULL) { passArea = pThresholdLayer->getPassArea(); dFirstThreshold = pThresholdLayer->getFirstThreshold(); dSecondThreshold = pThresholdLayer->getSecondThreshold(); } else { Statistics* pStatistics = pResults->getStatistics(); if (pStatistics != NULL) { dFirstThreshold = pStatistics->getMin(); dSecondThreshold = pStatistics->getMax(); } } } LatLonLayer* pLatLonLayer = static_cast<LatLonLayer*>(pView->getTopMostLayer(LAT_LONG)); if (pLatLonLayer != NULL) { GeocoordType geocoordType = pLatLonLayer->getGeocoordType(); mpOptionsWidget->setGeocoordType(geocoordType); } } } mpOptionsWidget->setPassArea(passArea); mpOptionsWidget->setFirstThreshold(dFirstThreshold); mpOptionsWidget->setSecondThreshold(dSecondThreshold); } } return mpOptionsWidget; }
/** * Get the name of the current data element or window. * * @param[in] DATASET @opt * This flag gets the primary data element name of the currently active window. * This is the default. * @param[in] FILE @opt * This flag gets the currently active window's primary data element's file name. * @param[in] WINDOW @opt * This flag gets the name of the currently active window. * @return The name of the element. * @usage print,get_current_name(/FILE) * @endusage */ IDL_VPTR get_current_name(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int datasetExists; IDL_LONG dataset; int fileExists; IDL_LONG file; int windowExists; IDL_LONG window; } KW_RESULT; //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the //name of the keyword, followed by the type, the mask(which should be 1), //flags, a boolean whether the value was populated and finally the value itself static IDL_KW_PAR kw_pars[] = { IDL_KW_FAST_SCAN, {"DATASET", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(datasetExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(dataset))}, {"FILE", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(fileExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(file))}, {"WINDOW", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(window))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string filename; std::string wizardName; int file = 0; int dataset = 0; int window = 0; if (kw->datasetExists) { if (kw->dataset != 0) { dataset = 1; } } else if (kw->fileExists) { if (kw->file != 0) { file = 1; } } else if (kw->windowExists) { if (kw->window != 0) { window = 1; } } else { dataset = 1; } RasterElement* pElement = IdlFunctions::getDataset(""); if (pElement == NULL) { IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "Opticks was unable to determine the current in memory dataset."); return IDL_StrToSTRING(""); } std::string name; if (dataset != 0) { // get the name of the RasterElement if dataset name = pElement->getName(); } else if (file) { // get the filename associated with the RasterElement name = pElement->getFilename(); } else { // get the window name Service<DesktopServices>()->getCurrentWorkspaceWindowName(name); } return IDL_StrToSTRING(const_cast<char*>(name.c_str())); }
ExportOptionsDlg::ExportOptionsDlg(ExporterResource& pExporter, QWidget* pParent) : QDialog(pParent), mpExporter(pExporter), mpTabWidget(NULL), mpSubsetPage(NULL), mpExporterPage(NULL) { // Options widget QStackedWidget* pStack = new QStackedWidget(this); // Subset page RasterElement* pRasterElement = dynamic_cast<RasterElement*>(mpExporter->getItem()); RasterFileDescriptor* pRasterWholeCubeFileDescriptor = NULL; RasterDataDescriptor* pRasterOrgDataDescriptor = NULL; if (pRasterElement != NULL) { pRasterOrgDataDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pRasterOrgDataDescriptor != NULL) { // we are creating a file descriptor for export from the original cube, because the SubsetWidget // uses DimensionDescriptor::operator= compare's to determine selection which dictate that on-disk, // original and active numbers need to be identical, this guarantees that DimensionDescriptors will // compare correctly. pRasterWholeCubeFileDescriptor = dynamic_cast<RasterFileDescriptor*>( RasterUtilities::generateFileDescriptorForExport(pRasterOrgDataDescriptor, "foobar")); } } RasterFileDescriptor* pRasterFileDescriptor = dynamic_cast<RasterFileDescriptor*>(mpExporter->getFileDescriptor()); if ((pRasterFileDescriptor != NULL) && (pRasterWholeCubeFileDescriptor != NULL) && (pRasterOrgDataDescriptor != NULL)) { mpSubsetPage = new SubsetWidget(); mpSubsetPage->setExportMode(true); // Rows const vector<DimensionDescriptor>& orgRows = pRasterWholeCubeFileDescriptor->getRows(); const vector<DimensionDescriptor>& selectedRows = pRasterFileDescriptor->getRows(); mpSubsetPage->setRows(orgRows, selectedRows); // Columns const vector<DimensionDescriptor>& orgColumns = pRasterWholeCubeFileDescriptor->getColumns(); const vector<DimensionDescriptor>& selectedColumns = pRasterFileDescriptor->getColumns(); mpSubsetPage->setColumns(orgColumns, selectedColumns); // Bands const vector<DimensionDescriptor>& orgBands = pRasterWholeCubeFileDescriptor->getBands(); const vector<DimensionDescriptor>& selectedBands = pRasterFileDescriptor->getBands(); vector<string> bandNames = RasterUtilities::getBandNames(pRasterOrgDataDescriptor); mpSubsetPage->setBands(orgBands, bandNames, selectedBands); // Initial bad band file directory QString strDirectory; string filename = pRasterFileDescriptor->getFilename(); if (filename.empty() == false) { QFileInfo fileInfo(QString::fromStdString(filename)); strDirectory = fileInfo.absolutePath(); } mpSubsetPage->setBadBandFileDirectory(strDirectory); } // Exporter page if (mpExporter->getPlugIn() != NULL) { mpExporterPage = mpExporter->getExportOptionsWidget(); } // Horizontal line QFrame* pLine = new QFrame(this); pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken); // Buttons QDialogButtonBox* pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); // Layout QVBoxLayout* pLayout = new QVBoxLayout(this); pLayout->setMargin(10); pLayout->setSpacing(10); pLayout->addWidget(pStack, 10); pLayout->addWidget(pLine); pLayout->addWidget(pButtonBox); // Initialization QString strWindowTitle = "Export Options"; SessionItem* pSessionItem = mpExporter->getItem(); if (pSessionItem != NULL) { string name = pSessionItem->getDisplayName(); if (name.empty() == true) { name = pSessionItem->getName(); } if (name.empty() == false) { strWindowTitle += ": " + QString::fromStdString(name); } } setWindowTitle(strWindowTitle); setModal(true); if ((mpSubsetPage != NULL) || (mpExporterPage != NULL)) { QWidget* pSubsetWidget = NULL; if (mpSubsetPage != NULL) { pSubsetWidget = new QWidget(); mpSubsetPage->setParent(pSubsetWidget); QVBoxLayout* pSubsetLayout = new QVBoxLayout(pSubsetWidget); if (mpExporterPage != NULL) { pSubsetLayout->setMargin(10); } else { pSubsetLayout->setMargin(0); } pSubsetLayout->setSpacing(10); pSubsetLayout->addWidget(mpSubsetPage); } QWidget* pExporterWidget = NULL; if (mpExporterPage != NULL) { pExporterWidget = new QWidget(); mpExporterPage->setParent(pExporterWidget); QVBoxLayout* pExporterLayout = new QVBoxLayout(pExporterWidget); if (mpSubsetPage != NULL) { pExporterLayout->setMargin(10); } else { pExporterLayout->setMargin(0); } pExporterLayout->setSpacing(10); pExporterLayout->addWidget(mpExporterPage); } if ((pSubsetWidget != NULL) && (pExporterWidget != NULL)) { QString strExporterCaption = mpExporterPage->windowTitle(); if (strExporterCaption.isEmpty() == true) { PlugIn* pPlugIn = mpExporter->getPlugIn(); if (pPlugIn != NULL) { strExporterCaption = QString::fromStdString(pPlugIn->getName()); } if (strExporterCaption.isEmpty() == true) { strExporterCaption = "Exporter"; } } mpTabWidget = new QTabWidget(this); mpTabWidget->setTabPosition(QTabWidget::North); mpTabWidget->addTab(pSubsetWidget, "Subset"); mpTabWidget->addTab(pExporterWidget, strExporterCaption); pStack->addWidget(mpTabWidget); } else if (pSubsetWidget != NULL) { pStack->addWidget(pSubsetWidget); pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); } else if (pExporterWidget != NULL) { pStack->addWidget(pExporterWidget); } } if (pStack->count() == 0) { QLabel* pNoOptionsLabel = new QLabel("No options are available", this); pNoOptionsLabel->setAlignment(Qt::AlignCenter); pNoOptionsLabel->setMinimumSize(250, 100); pStack->addWidget(pNoOptionsLabel); } // Connections VERIFYNR(connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept()))); VERIFYNR(connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()))); }
bool Deconvolution::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Deconvolution Sharpening", "app", "619F3C8A-FB70-44E0-B211-B116E604EDDA"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); EncodingType ResultType = pDesc->getDataType(); if (pDesc->getDataType() == INT4SCOMPLEX) { ResultType = INT4SBYTES; } else if (pDesc->getDataType() == FLT8COMPLEX) { ResultType = FLT8BYTES; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Deconvolution_Sharpening_Result", pDesc->getRowCount(), pDesc->getColumnCount(), ResultType)); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); Service<DesktopServices> pDesktop; DeconvolutionDlg dlg(pDesktop->getMainWidget()); int stat = dlg.exec(); if (stat != QDialog::Accepted) { return true; } double minGrayValue; double maxGrayValue; double deltaValue = 0.0; int nFilterType = dlg.getCurrentFilterType(); int windowSize = dlg.getCurrentWindowSize(); double sigmaVal = dlg.getSigmaValue(); double gamaVal = dlg.getGamaValue(); windowSize = (windowSize-1)/2; if (NULL != pOriginalImage) { free(pOriginalImage); } pOriginalImage = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *OrigData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *NewData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *ConvoData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *pTempData; InitializeData(pSrcAcc, pOriginalImage, OrigData, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType()); GetGrayScale(&minGrayValue, &maxGrayValue, pDesc->getDataType()); //Perform deconvolution iteratively for (int num = 0; num < MAX_ITERATION_NUMBER; num++) { if (pProgress != NULL) { pProgress->updateProgress("Deconvolution process", num*100/MAX_ITERATION_NUMBER, NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } free(OrigData); free(NewData); free(ConvoData); return false; } deltaValue = DeconvolutionFunc(OrigData, pOriginalImage, NewData, ConvoData, sigmaVal, gamaVal, windowSize, pDesc->getRowCount(), pDesc->getColumnCount(), nFilterType, maxGrayValue, minGrayValue); pTempData = OrigData; OrigData = NewData; NewData = pTempData; double errorRate = deltaValue/(maxGrayValue-minGrayValue); if (errorRate < CONVERGENCE_THRESHOLD) { break; } } free(NewData); free(ConvoData); //Output result unsigned int nCount = 0; for (int i = 0; i < pDesc->getRowCount(); i++) { for (int j = 0; j < pDesc->getColumnCount(); j++) { if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } free(OrigData); return false; } pDestAcc->toPixel(i, j); switchOnEncoding(ResultType, restoreImageValue, pDestAcc->getColumn(), (OrigData+nCount)); nCount++; } } free(OrigData); if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("Deconvolution enhancement is complete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Deconvolution enhancement Result", pResultCube.release()); pStep->finalize(); return true; }
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."); } } } }