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; }
ChippingWindow::ChippingWindow(SpatialDataView* pView, QWidget* parent) : QDialog(parent), mpView(pView), mpChippingWidget(NULL), mpWindowRadio(NULL), mpFileRadio(NULL) { // View widget SpatialDataView* pChipView = createChipView(); pChipView->getWidget()->installEventFilter(this); mpChippingWidget = new ChippingWidget(pChipView, NULL, this); mpChippingWidget->setExportMode(true); // Chip mode QGroupBox* pModeGroup = new QGroupBox("Chipping Mode", this); mpWindowRadio = new QRadioButton("Create new window", pModeGroup); mpFileRadio = new QRadioButton("Export to file", pModeGroup); // Horizontal line QFrame* pHLine = new QFrame(this); pHLine->setFrameStyle(QFrame::HLine | QFrame::Sunken); // Buttons QPushButton* pOkButton = new QPushButton("&OK", this); QPushButton* pCancelButton = new QPushButton("&Cancel", this); // Layout QVBoxLayout* pModeLayout = new QVBoxLayout(pModeGroup); pModeLayout->setMargin(10); pModeLayout->setSpacing(5); pModeLayout->addWidget(mpWindowRadio); pModeLayout->addWidget(mpFileRadio); QHBoxLayout* pButtonLayout = new QHBoxLayout(); pButtonLayout->setMargin(0); pButtonLayout->setSpacing(5); pButtonLayout->addStretch(10); pButtonLayout->addWidget(pOkButton); pButtonLayout->addWidget(pCancelButton); QVBoxLayout* pLayout = new QVBoxLayout(this); pLayout->setMargin(10); pLayout->setSpacing(10); pLayout->addWidget(mpChippingWidget, 10); pLayout->addWidget(pModeGroup, 0, Qt::AlignLeft); pLayout->addWidget(pHLine); pLayout->addLayout(pButtonLayout); // Initialization setModal(true); resize(400, 200); mpWindowRadio->setChecked(true); // Set the window icon setWindowIcon(QIcon(":/icon/ChipImage")); // Set the caption of the dialog QString strCaption = "Create Image Chip"; if (mpView != NULL) { string viewName = mpView->getName(); if (viewName.empty() == false) { QFileInfo fileInfo(QString::fromStdString(viewName)); QString strFilename = fileInfo.fileName(); if (strFilename.isEmpty() == false) { strCaption += ": " + strFilename; } } } setWindowTitle(strCaption); // Connections connect(pOkButton, SIGNAL(clicked()), this, SLOT(accept())); connect(pCancelButton, SIGNAL(clicked()), this, SLOT(reject())); }
QWidget* RasterElementImporterShell::getPreview(const DataDescriptor* pDescriptor, Progress* pProgress) { if (pDescriptor == NULL) { return NULL; } // Create a copy of the descriptor to change the loading parameters string previewName = string("Preview: ") + pDescriptor->getName(); RasterDataDescriptor* pLoadDescriptor = dynamic_cast<RasterDataDescriptor*>(pDescriptor->copy(previewName, NULL)); if (pLoadDescriptor == NULL) { return NULL; } // Set the active row and column numbers vector<DimensionDescriptor> newRows = pLoadDescriptor->getRows(); for (unsigned int i = 0; i < newRows.size(); ++i) { newRows[i].setActiveNumber(i); } pLoadDescriptor->setRows(newRows); vector<DimensionDescriptor> newColumns = pLoadDescriptor->getColumns(); for (unsigned int i = 0; i < newColumns.size(); ++i) { newColumns[i].setActiveNumber(i); } pLoadDescriptor->setColumns(newColumns); // Set the bands to load to just the first band and display it in grayscale mode const vector<DimensionDescriptor>& bands = pLoadDescriptor->getBands(); if (bands.empty() == false) { DimensionDescriptor displayBand = bands.front(); displayBand.setActiveNumber(0); vector<DimensionDescriptor> newBands; newBands.push_back(displayBand); pLoadDescriptor->setBands(newBands); pLoadDescriptor->setDisplayMode(GRAYSCALE_MODE); pLoadDescriptor->setDisplayBand(GRAY, displayBand); } // Set the processing location to load on-disk read-only pLoadDescriptor->setProcessingLocation(ON_DISK_READ_ONLY); // Do not georeference GeoreferenceDescriptor* pLoadGeorefDescriptor = pLoadDescriptor->getGeoreferenceDescriptor(); if (pLoadGeorefDescriptor != NULL) { pLoadGeorefDescriptor->setGeoreferenceOnImport(false); } // Validate the preview string errorMessage; bool bValidPreview = validate(pLoadDescriptor, vector<const DataDescriptor*>(), errorMessage); if (bValidPreview == false) { // Try an in-memory preview pLoadDescriptor->setProcessingLocation(IN_MEMORY); bValidPreview = validate(pLoadDescriptor, vector<const DataDescriptor*>(), errorMessage); } QWidget* pPreviewWidget = NULL; if (bValidPreview == true) { // Create the model element RasterElement* pRasterElement = static_cast<RasterElement*>(mpModel->createElement(pLoadDescriptor)); if (pRasterElement != NULL) { // Add the progress and raster element to an input arg list PlugInArgList* pInArgList = NULL; bool bSuccess = getInputSpecification(pInArgList); if ((bSuccess == true) && (pInArgList != NULL)) { bSuccess = pInArgList->setPlugInArgValue(Executable::ProgressArg(), pProgress); if (bSuccess) { bSuccess = pInArgList->setPlugInArgValue(Importer::ImportElementArg(), pRasterElement); } } // Load the data in batch mode bool bBatch = isBatch(); setBatch(); bSuccess = execute(pInArgList, NULL); // Restore to interactive mode if necessary if (bBatch == false) { setInteractive(); } // Create the spatial data view if (bSuccess == true) { string name = pRasterElement->getName(); SpatialDataView* pView = static_cast<SpatialDataView*>(mpDesktop->createView(name, SPATIAL_DATA_VIEW)); if (pView != NULL) { // Set the spatial data in the view pView->setPrimaryRasterElement(pRasterElement); // Add the cube layer RasterLayer* pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, pRasterElement)); if (pLayer != NULL) { // Get the widget from the view pPreviewWidget = pView->getWidget(); } else { string message = "Could not create the cube layer!"; if (pProgress != NULL) { pProgress->updateProgress(message, 0, ERRORS); } mpModel->destroyElement(pRasterElement); } } else { string message = "Could not create the view!"; if (pProgress != NULL) { pProgress->updateProgress(message, 0, ERRORS); } mpModel->destroyElement(pRasterElement); } } else { mpModel->destroyElement(pRasterElement); } } } // Delete the data descriptor copy mpModel->destroyDataDescriptor(pLoadDescriptor); return pPreviewWidget; }