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 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."); } } } }