void Controller::DispatchUpdate(DeltaTime &delta) { if (!mScene) { return; } LayerList *layers = &mScene->GetLayers(); LayerIter liter = layers->begin(); mScene->Update(delta); while (liter != layers->end()) { (*liter)->UpdateSelfAndChildren(delta); liter++; } }
void Node::assignToLayers(const LayerList& newLayers) { if (!newLayers.empty()) { _layers = newLayers; } }
bool GeocoordLinkFunctor::initialize() { if (mInitialized) { return true; } if (mpSrcView != NULL) { LayerList* pSrcLayerList = mpSrcView->getLayerList(); if (pSrcLayerList == NULL) { return false; } mpSrcGeo = pSrcLayerList->getPrimaryRasterElement(); if (mpSrcGeo == NULL || !mpSrcGeo->isGeoreferenced()) { return false; } mpSrcLayer = pSrcLayerList->getLayer(RASTER, mpSrcGeo); if (mpSrcLayer == NULL) { return false; } LocationType srcWorldCenter(mpSrcView->getVisibleCenter()); LocationType srcScreenCenter; mpSrcView->translateWorldToScreen(srcWorldCenter.mX, srcWorldCenter.mY, srcScreenCenter.mX, srcScreenCenter.mY); mSrcScreenCenter = complex<double>(srcScreenCenter.mX, srcScreenCenter.mY); LocationType srcDataCenter; mpSrcLayer->translateWorldToData(srcWorldCenter.mX, srcWorldCenter.mY, srcDataCenter.mX, srcDataCenter.mY); mCenterGeocoord = mpSrcGeo->convertPixelToGeocoord(srcDataCenter); mTightness = findResolution(mpSrcGeo, mpSrcLayer, mCenterGeocoord) * LINK_TIGHTNESS; mInitialized = true; return true; } return false; }
/// <summary> /// Returns what index the specified item would be if the entire scene was /// represented in a linear list. /// </summary> int Scene::listIndexOfItem(SceneItem *item) const { int index = 0; for(int i = 0; i < m_groups.count(); i++) { const GroupInfo &group = m_groups.at(i); if(item == group.sceneItem) return index; index++; LayerList layers = group.group->getLayers(); for(int j = 0; j < layers.count(); j++) { if(item == itemForLayer(layers.at(j))) return index; index++; } } return -1; // Not found }
void LayerRendererChromium::paintLayerContents(const LayerList& renderSurfaceLayerList) { for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get(); RenderSurfaceChromium* renderSurface = renderSurfaceLayer->renderSurface(); ASSERT(renderSurface); // Make sure any renderSurfaceLayer is associated with this layerRenderer. // This is a defensive assignment in case the owner of this layer hasn't // set the layerRenderer on this layer already. renderSurfaceLayer->setLayerRenderer(this); // Render surfaces whose drawable area has zero width or height // will have no layers associated with them and should be skipped. if (!renderSurface->m_layerList.size()) continue; LayerList& layerList = renderSurface->m_layerList; ASSERT(layerList.size()); for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex) { CCLayerImpl* ccLayerImpl = layerList[layerIndex].get(); // Layers that start a new render surface will be painted when the render // surface's list is processed. if (ccLayerImpl->renderSurface() && ccLayerImpl->renderSurface() != renderSurface) continue; LayerChromium* layer = ccLayerImpl->owner(); layer->setLayerRenderer(this); if (layer->maskLayer()) layer->maskLayer()->setLayerRenderer(this); if (layer->replicaLayer()) { layer->replicaLayer()->setLayerRenderer(this); if (layer->replicaLayer()->maskLayer()) layer->replicaLayer()->maskLayer()->setLayerRenderer(this); } if (layer->bounds().isEmpty()) continue; IntRect targetSurfaceRect = ccLayerImpl->targetRenderSurface() ? ccLayerImpl->targetRenderSurface()->contentRect() : m_defaultRenderSurface->contentRect(); IntRect scissorRect = layer->ccLayerImpl()->scissorRect(); if (!scissorRect.isEmpty()) targetSurfaceRect.intersect(scissorRect); if (layer->drawsContent()) layer->paintContentsIfDirty(targetSurfaceRect); if (layer->maskLayer() && layer->maskLayer()->drawsContent()) layer->maskLayer()->paintContentsIfDirty(targetSurfaceRect); if (layer->replicaLayer() && layer->replicaLayer()->drawsContent()) layer->replicaLayer()->paintContentsIfDirty(targetSurfaceRect); if (layer->replicaLayer() && layer->replicaLayer()->maskLayer() && layer->replicaLayer()->maskLayer()->drawsContent()) layer->replicaLayer()->maskLayer()->paintContentsIfDirty(targetSurfaceRect); } } }
/// <summary> /// Returns the item at the specified index if the entire scene was represented /// in a linear list. /// </summary> SceneItem *Scene::itemAtListIndex(int index) const { int item = 0; for(int i = 0; i < m_groups.count(); i++) { const GroupInfo &group = m_groups.at(i); if(item == index) return group.sceneItem; item++; LayerList layers = group.group->getLayers(); for(int j = 0; j < layers.count(); j++) { Layer *layer = layers.at(j); if(item == index) return itemForLayer(layer); item++; } } return NULL; // Not found }
void FusionLayersSelectPage::layerListDeleted(Subject& subject, const string& signal, const boost::any& v) { LayerList* pLayerList = dynamic_cast<LayerList*>(&subject); if (pLayerList != NULL) { vector<Layer*> pLayers; pLayerList->getLayers(pLayers); for (vector<Layer*>::iterator it = pLayers.begin(); it != pLayers.end(); ++it) { Layer* pLayer = *it; if (pLayer != NULL) { pLayer->detach(SIGNAL_NAME(Subject, Deleted), Slot(this, &FusionLayersSelectPage::layerDeleted)); pLayer->detach(SIGNAL_NAME(Subject, Modified), Slot(this, &FusionLayersSelectPage::layerModified)); } } } }
void FusionLayersSelectPage::layerListModified(Subject& subject, const string& signal, const boost::any& v) { LayerList* pLayerList = dynamic_cast<LayerList*>(&subject); if (pLayerList != NULL) { vector<Layer*> layerListLayers; pLayerList->getLayers(layerListLayers); // for each layer list layer, check map. If not there, add it. for (vector<Layer*>::iterator it = layerListLayers.begin(); it != layerListLayers.end(); ++it) { LayerMap::iterator found = mLayers.find(*it); if (found == mLayers.end()) { addLayerToGui(*it); } } } }
// Reports whether the passed in layers have visible damage or are otherwise // dirty because render properties changed. // Assumes that layers in the list belong to same composition. ie. damage to // one layer affects the others. A warning is logged if the assumption is wrong. bool GLXGraphicsystem::needsRedraw(LayerList layers) { // TODO: Ignore damage from completely obscured surfaces for (LayerListConstIterator layer = layers.begin(); layer != layers.end(); layer++) { if ((*layer)->getLayerType() == Hardware && layers.size() > 1) { // Damage in a hardware layer should not imply a redraw in other layers LOG_WARNING("GLXGraphicsystem", "needsRedraw() called with layers not in the same composition"); } if (needsRedraw(*layer)) { return true; } } return false; }
static void move_or_copy_cels( DocApi& api, Op op, const LayerList& srcLayers, const LayerList& dstLayers, const SelectedFrames& srcFrames, const SelectedFrames& dstFrames) { ASSERT(srcLayers.size() == dstLayers.size()); for (layer_t i=0; i<srcLayers.size(); ++i) { auto srcFrame = srcFrames.begin(); auto dstFrame = dstFrames.begin(); auto srcFrameEnd = srcFrames.end(); auto dstFrameEnd = dstFrames.end(); for (; srcFrame != srcFrameEnd && dstFrame != dstFrameEnd; ++srcFrame, ++dstFrame) { if (i >= 0 && i < srcLayers.size() && srcLayers[i]->isImage()) { LayerImage* srcLayer = static_cast<LayerImage*>(srcLayers[i]); if (i < dstLayers.size() && dstLayers[i]->isImage()) { LayerImage* srcLayer = static_cast<LayerImage*>(srcLayers[i]); LayerImage* dstLayer = static_cast<LayerImage*>(dstLayers[i]); #ifdef TRACE_RANGE_OPS std::clog << (op == Move ? "Moving": "Copying") << " cel " << srcLayer->name() << "[" << *srcFrame << "]" << " into " << dstLayer->name() << "[" << *dstFrame << "]\n"; #endif switch (op) { case Move: api.moveCel(srcLayer, *srcFrame, dstLayer, *dstFrame); break; case Copy: api.copyCel(srcLayer, *srcFrame, dstLayer, *dstFrame); break; } } else if (op == Move) { api.clearCel(srcLayer, *srcFrame); } } } } }
void OverviewWindow::updateView(const vector<LocationType>& selectionArea) { if ((mpView == NULL) || (selectionArea.size() != 4)) { return; } LayerList* pLayerList = mpView->getLayerList(); VERIFYNRV(pLayerList != NULL); Layer* pLayer = pLayerList->getLayer(RASTER, pLayerList->getPrimaryRasterElement()); VERIFYNRV(pLayer != NULL); LocationType worldLl; LocationType worldUr; pLayer->translateDataToWorld(selectionArea[0].mX, selectionArea[0].mY, worldLl.mX, worldLl.mY); pLayer->translateDataToWorld(selectionArea[2].mX, selectionArea[2].mY, worldUr.mX, worldUr.mY); // Update the view mpView->zoomToBox(worldLl, worldUr); mpView->repaint(); }
void GLXGraphicsystem::renderSWLayers(LayerList layers, bool clear) { // This is a stub. // // TODO: render in a more optimal way // 1. Turn off blending for first surface rendered // 2. Don't clear when it's legal to avoid it // eg. a fullscreen opaque surface exists // 3. Render multiple surfaces at time via multi-texturing // 4. Remove fully obscured layers/surfaces if (clear) { clearBackground(); } for (LayerListConstIterator layer = layers.begin(); layer != layers.end(); layer++) { renderSWLayer(*layer, false); // Don't clear } }
/** * Get the number of layers in a window. * * @param[in] WINDOW @opt * The name of the window. Defaults to the active window. * @return The number of layers in the window. * @usage num_layers = get_num_layers() * @endusage */ IDL_VPTR get_num_layers(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int windowExists; IDL_STRING windowName; } 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, {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string windowName; int layers = 0; if (kw->windowExists) { windowName = IDL_STRING_STR(&kw->windowName); } SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName)); if (pView != NULL) { LayerList* pList = pView->getLayerList(); if (pList != NULL) { layers = pList->getNumLayers(); } } return IDL_GettmpInt(layers); }
void FusionLayersSelectPage::setViews(SpatialDataView* pPrimary, SpatialDataView* pSecondary) { vector<Layer*> layers; vector<Layer*>::iterator it; SpatialDataView* pOldPrimaryView = getPrimaryView(); if (pOldPrimaryView != NULL) { LayerList* pLayerList = pOldPrimaryView->getLayerList(); if (pLayerList != NULL) { pLayerList->detach(SIGNAL_NAME(Subject, Deleted), Slot(this, &FusionLayersSelectPage::layerListDeleted)); pLayerList->detach(SIGNAL_NAME(Subject, Modified), Slot(this, &FusionLayersSelectPage::layerListModified)); } } FusionPage::setViews(pPrimary, pSecondary); if (pPrimary != NULL) { LayerList* pLayerList = pPrimary->getLayerList(); if (pLayerList != NULL) { pLayerList->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &FusionLayersSelectPage::layerListDeleted)); pLayerList->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &FusionLayersSelectPage::layerListModified)); } } }
SpatialDataView* ChippingWindow::createChipView() const { if (mpView == NULL) { return NULL; } SpatialDataView* pChipView = dynamic_cast<SpatialDataView*>(mpView->copy()); if (pChipView != NULL) { vector<std::pair<View*, LinkType> > linkedViews; pChipView->getLinkedViews(linkedViews); for (unsigned int i = 0; i < linkedViews.size(); ++i) { if (linkedViews[i].second == NO_LINK) { continue; } pChipView->unlinkView(linkedViews[i].first); } LayerList* pLayerList = pChipView->getLayerList(); if (pLayerList != NULL) { vector<Layer*> layers; pLayerList->getLayers(layers); for (unsigned int i = 0; i < layers.size(); i++) { Layer* pLayer = layers.at(i); if (dynamic_cast<RasterLayer*>(pLayer) == NULL) { pChipView->deleteLayer(pLayer); } } } } return pChipView; }
void CCLayerTreeHost::updateLayers(LayerChromium* rootLayer, CCTextureUpdater& updater) { TRACE_EVENT0("cc", "CCLayerTreeHost::updateLayers"); if (!rootLayer->renderSurface()) rootLayer->createRenderSurface(); rootLayer->renderSurface()->setContentRect(IntRect(IntPoint(0, 0), deviceViewportSize())); IntRect rootClipRect(IntPoint(), deviceViewportSize()); rootLayer->setClipRect(rootClipRect); LayerList updateList; updateList.append(rootLayer); RenderSurfaceChromium* rootRenderSurface = rootLayer->renderSurface(); rootRenderSurface->clearLayerList(); { TRACE_EVENT0("cc", "CCLayerTreeHost::updateLayers::calcDrawEtc"); WebTransformationMatrix identityMatrix; WebTransformationMatrix deviceScaleTransform; deviceScaleTransform.scale(m_deviceScaleFactor); CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, rootLayer, deviceScaleTransform, identityMatrix, updateList, rootRenderSurface->layerList(), layerRendererCapabilities().maxTextureSize); FloatRect rootScissorRect(FloatPoint(0, 0), viewportSize()); CCLayerTreeHostCommon::calculateVisibleAndScissorRects(updateList, rootScissorRect); } // Reset partial texture update requests. m_partialTextureUpdateRequests = 0; prioritizeTextures(updateList); bool needMoreUpdates = paintLayerContents(updateList, updater); if (m_triggerIdleUpdates && needMoreUpdates) setNeedsCommit(); for (size_t i = 0; i < updateList.size(); ++i) updateList[i]->clearRenderSurface(); }
void CCLayerTreeHost::updateLayers(LayerChromium* rootLayer, CCTextureUpdateQueue& queue) { TRACE_EVENT0("cc", "CCLayerTreeHost::updateLayers"); LayerList updateList; { TRACE_EVENT0("cc", "CCLayerTreeHost::updateLayers::calcDrawEtc"); CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize(), m_deviceScaleFactor, rendererCapabilities().maxTextureSize, updateList); CCLayerTreeHostCommon::calculateVisibleRects(updateList); } // Reset partial texture update requests. m_partialTextureUpdateRequests = 0; bool needMoreUpdates = paintLayerContents(updateList, queue); if (m_triggerIdleUpdates && needMoreUpdates) setNeedsCommit(); for (size_t i = 0; i < updateList.size(); ++i) updateList[i]->clearRenderSurface(); }
void CCLayerTreeHost::prioritizeTextures(const LayerList& updateList) { // Use BackToFront since it's cheap and this isn't order-dependent. typedef CCLayerIterator<LayerChromium, Vector<RefPtr<LayerChromium> >, RenderSurfaceChromium, CCLayerIteratorActions::BackToFront> CCLayerIteratorType; m_contentsTextureManager->clearPriorities(); CCPriorityCalculator calculator; CCLayerIteratorType end = CCLayerIteratorType::end(&updateList); for (CCLayerIteratorType it = CCLayerIteratorType::begin(&updateList); it != end; ++it) { if (it.representsItself()) it->setTexturePriorities(calculator); else if (it.representsTargetRenderSurface()) { if (it->maskLayer()) it->maskLayer()->setTexturePriorities(calculator); if (it->replicaLayer() && it->replicaLayer()->maskLayer()) it->replicaLayer()->maskLayer()->setTexturePriorities(calculator); } } size_t readbackBytes = 0; size_t maxBackgroundTextureBytes = 0; size_t contentsTextureBytes = 0; // Start iteration at 1 to skip the root surface as it does not have a texture cost. for (size_t i = 1; i < updateList.size(); ++i) { LayerChromium* renderSurfaceLayer = updateList[i].get(); RenderSurfaceChromium* renderSurface = renderSurfaceLayer->renderSurface(); size_t bytes = TextureManager::memoryUseBytes(renderSurface->contentRect().size(), GraphicsContext3D::RGBA); contentsTextureBytes += bytes; if (renderSurface->backgroundFilters().isEmpty()) continue; if (bytes > maxBackgroundTextureBytes) maxBackgroundTextureBytes = bytes; if (!readbackBytes) readbackBytes = TextureManager::memoryUseBytes(m_deviceViewportSize, GraphicsContext3D::RGBA); } size_t renderSurfacesBytes = readbackBytes + maxBackgroundTextureBytes + contentsTextureBytes; m_contentsTextureManager->prioritizeTextures(renderSurfacesBytes); }
size_t CCLayerTreeHost::calculateMemoryForRenderSurfaces(const LayerList& updateList) { size_t readbackBytes = 0; size_t maxBackgroundTextureBytes = 0; size_t contentsTextureBytes = 0; // Start iteration at 1 to skip the root surface as it does not have a texture cost. for (size_t i = 1; i < updateList.size(); ++i) { LayerChromium* renderSurfaceLayer = updateList[i].get(); RenderSurfaceChromium* renderSurface = renderSurfaceLayer->renderSurface(); size_t bytes = CCTexture::memorySizeBytes(renderSurface->contentRect().size(), GraphicsContext3D::RGBA); contentsTextureBytes += bytes; if (renderSurfaceLayer->backgroundFilters().isEmpty()) continue; if (bytes > maxBackgroundTextureBytes) maxBackgroundTextureBytes = bytes; if (!readbackBytes) readbackBytes = CCTexture::memorySizeBytes(m_deviceViewportSize, GraphicsContext3D::RGBA); } return readbackBytes + maxBackgroundTextureBytes + contentsTextureBytes; }
bool CgmImporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { Progress* pProgress = NULL; DataElement* pElement = NULL; StepResource pStep("Import cgm element", "app", "8D5522FE-4A89-44cb-9735-6920A3BFC903"); // get input arguments and log some useful info about them { // scope the MessageResource MessageResource pMsg("Input arguments", "app", "A1735AC7-C182-45e6-826F-690DBA15D84A"); pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); pMsg->addBooleanProperty("Progress Present", (pProgress != NULL)); pElement = pInArgList->getPlugInArgValue<DataElement>(Importer::ImportElementArg()); if (pElement == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No data element", 0, ERRORS); } pStep->finalize(Message::Failure, "No data element"); return false; } pMsg->addProperty("Element name", pElement->getName()); } if (pProgress != NULL) { pProgress->updateProgress((string("Read and parse file ") + pElement->getFilename()), 20, NORMAL); } // Create a new annotation layer for a spatial data view or get the layout layer for a product view if (pProgress != NULL) { pProgress->updateProgress("Create a new layer", 30, NORMAL); } View* pView = mpDesktop->getCurrentWorkspaceWindowView(); if (pView == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Could not access the current view.", 0, ERRORS); } pStep->finalize(Message::Failure, "Could not access the current view."); return false; } UndoGroup undoGroup(pView, "Import CGM"); AnnotationLayer* pLayer = NULL; SpatialDataView* pSpatialDataView = dynamic_cast<SpatialDataView*>(pView); if (pSpatialDataView != NULL) { // Set the parent element of the annotation element to the primary raster element LayerList* pLayerList = pSpatialDataView->getLayerList(); if (pLayerList != NULL) { RasterElement* pNewParentElement = pLayerList->getPrimaryRasterElement(); if (pNewParentElement != NULL) { Service<ModelServices> pModel; pModel->setElementParent(pElement, pNewParentElement); } } pLayer = dynamic_cast<AnnotationLayer*>(pSpatialDataView->createLayer(ANNOTATION, pElement)); } else { ProductView* pProductView = dynamic_cast<ProductView*>(mpDesktop->getCurrentWorkspaceWindowView()); if (pProductView != NULL) { pLayer = pProductView->getLayoutLayer(); } } if (pLayer == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Unable to get the annotation layer", 0, ERRORS); } pStep->finalize(Message::Failure, "Unable to get the annotation layer"); return false; } // add the CGM object if (pProgress != NULL) { pProgress->updateProgress("Create the CGM object", 60, NORMAL); } CgmObject* pCgmObject = dynamic_cast<CgmObject*>(pLayer->addObject(CGM_OBJECT)); if (pCgmObject == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Unable to create the CGM object", 0, ERRORS); } pStep->finalize(Message::Failure, "Unable to create the CGM object"); return false; } // load the CGM file if (pProgress != NULL) { pProgress->updateProgress("Load the CGM file", 90, NORMAL); } string fname = pElement->getDataDescriptor()->getFileDescriptor()->getFilename().getFullPathAndName(); if (!pCgmObject->deserializeCgm(fname)) { if (pProgress != NULL) { pProgress->updateProgress("Error loading the CGM element", 0, ERRORS); } pStep->finalize(Message::Failure, "Unable to parse the CGM file."); return false; } if (pProgress != NULL) { pProgress->updateProgress("Successfully loaded the CGM file", 100, NORMAL); } pStep->finalize(Message::Success); 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; }
bool ResamplerPlugIn::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { VERIFY(pInArgList != NULL && pOutArgList != NULL); ProgressTracker progress(pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()), "Executing Spectral Resampler.", "spectral", "{88CD3E49-A522-431A-AE2A-96A6B2EB4012}"); Service<DesktopServices> pDesktop; const DataElement* pElement(NULL); std::string waveFilename; // get default resampling options from user config std::string resampleMethod = ResamplerOptions::getSettingResamplerMethod(); double dropOutWindow = ResamplerOptions::getSettingDropOutWindow(); double fwhm = ResamplerOptions::getSettingFullWidthHalfMax(); bool useFillValue = ResamplerOptions::getSettingUseFillValue(); double fillValue = ResamplerOptions::getSettingSignatureFillValue(); std::vector<Signature*> originalSignatures; std::auto_ptr<std::vector<Signature*> > pResampledSignatures(new std::vector<Signature*>); std::string errorMsg; if (isBatch()) { VERIFY(pInArgList->getPlugInArgValue("Signatures to resample", originalSignatures)); if (originalSignatures.empty()) { Signature* pSignature = pInArgList->getPlugInArgValue<Signature>("Signature to resample"); if (pSignature != NULL) { originalSignatures.push_back(pSignature); } } if (originalSignatures.empty()) { progress.report("No signatures are available to be resampled.", 0, ERRORS, true); return false; } pElement = pInArgList->getPlugInArgValue<DataElement>("Data element wavelength source"); Filename* pWaveFilename = pInArgList->getPlugInArgValue<Filename>("Wavelengths Filename"); if (pWaveFilename != NULL) { waveFilename = pWaveFilename->getFullPathAndName(); } VERIFY(pInArgList->getPlugInArgValue("Resampling Method", resampleMethod)); VERIFY(pInArgList->getPlugInArgValue("Drop out window", dropOutWindow)); VERIFY(pInArgList->getPlugInArgValue("FWHM", fwhm)); VERIFY(pInArgList->getPlugInArgValue("Use fill value", useFillValue)); VERIFY(pInArgList->getPlugInArgValue("Fill value", fillValue)); } else { ResamplerPlugInDlg dlg(pDesktop->getMainWidget()); if (dlg.exec() == QDialog::Rejected) { progress.report("User canceled resampling.", 0, ABORT, true); progress.upALevel(); return false; } originalSignatures = dlg.getSignaturesToResample(); resampleMethod = dlg.getResamplingMethod(); dropOutWindow = dlg.getDropOutWindow(); fwhm = dlg.getFWHM(); useFillValue = dlg.getUseFillValue(); fillValue = dlg.getFillValue(); pElement = dlg.getWavelengthsElement(); waveFilename = dlg.getWavelengthsFilename(); } std::string resampledTo; FactoryResource<Wavelengths> pWavelengths; if (pElement != NULL) // try loading wavelengths from user specified data element { if (getWavelengthsFromElement(pElement, pWavelengths.get(), errorMsg) == false) { progress.report(errorMsg, 0, ERRORS, true); return false; } resampledTo = pElement->getName(); } else if (waveFilename.empty() == false) // if no user provided raster, look for a wavelengths file { if (QFile::exists(QString::fromStdString(waveFilename))) { if (getWavelengthsFromFile(waveFilename, pWavelengths.get(), errorMsg) == false) { progress.report(errorMsg, 0, ERRORS, true); return false; } } else { errorMsg = "The wavelengths file \"" + waveFilename + "\" could not be found."; progress.report(errorMsg, 0, ERRORS, true); return false; } resampledTo = waveFilename; } else // if no wavelength source provided, look for raster in current active spatial data view { SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pDesktop->getCurrentWorkspaceWindowView()); if (pView != NULL) { LayerList* pLayerList = pView->getLayerList(); if (pLayerList != NULL) { pElement = pLayerList->getPrimaryRasterElement(); pWavelengths->initializeFromDynamicObject(pElement->getMetadata(), false); if (pWavelengths->isEmpty()) { progress.report("No target wavelengths are available for resampling the signatures.", 0, ERRORS, true); return false; } resampledTo = pElement->getName(); } } } PlugInResource pPlugIn("Resampler"); Resampler* pResampler = dynamic_cast<Resampler*>(pPlugIn.get()); if (pResampler == NULL) { progress.report("The \"Resampler\" plug-in is not available so the signatures can not be resampled.", 0, ERRORS, true); return false; } std::string dataName("Reflectance"); std::string wavelengthName("Wavelength"); // save user config settings - Resampler doesn't have interface to set them separately from user config std::string configMethod = ResamplerOptions::getSettingResamplerMethod(); ResamplerOptions::setSettingResamplerMethod(resampleMethod); double configDropout = ResamplerOptions::getSettingDropOutWindow(); ResamplerOptions::setSettingDropOutWindow(dropOutWindow); double configFwhm = ResamplerOptions::getSettingFullWidthHalfMax(); ResamplerOptions::setSettingFullWidthHalfMax(fwhm); std::vector<double> toWavelengths = pWavelengths->getCenterValues(); std::vector<double> toFwhm = pWavelengths->getFwhm(); if (toFwhm.size() != toWavelengths.size()) { toFwhm.clear(); // Resampler will use the default config setting fwhm if this vector is empty } unsigned int numSigs = originalSignatures.size(); unsigned int numSigsResampled(0); progress.report("Begin resampling signatures...", 0, NORMAL); for (unsigned int index = 0; index < numSigs; ++index) { if (isAborted()) { progress.report("Resampling aborted by user", 100 * index / numSigs, ABORT, true); return false; } if (originalSignatures[index] == NULL) { continue; } // check if signature has target wavelength centers and doesn't need to be resampled if (needToResample(originalSignatures[index], pWavelengths.get()) == false) { pResampledSignatures->push_back(originalSignatures[index]); ++numSigsResampled; continue; } DataVariant var = originalSignatures[index]->getData(dataName); if (var.isValid() == false) { continue; } std::vector<double> fromData; if (!var.getValue(fromData)) { continue; } var = originalSignatures[index]->getData(wavelengthName); if (var.isValid() == false) { continue; } std::vector<double> fromWavelengths; if (!var.getValue(fromWavelengths)) { continue; } std::string resampledSigName = originalSignatures[index]->getName() + "_resampled"; int suffix(2); ModelResource<Signature> pSignature(resampledSigName, NULL); // probably not needed but just in case resampled name already used while (pSignature.get() == NULL) { pSignature = ModelResource<Signature>(resampledSigName + StringUtilities::toDisplayString(suffix), NULL); ++suffix; } if (resampledTo.empty() == false) { DynamicObject* pMetaData = pSignature->getMetadata(); if (pMetaData != NULL) { pMetaData->setAttribute(CommonSignatureMetadataKeys::ResampledTo(), resampledTo); } } std::vector<double> toData; std::vector<int> toBands; if (pResampler->execute(fromData, toData, fromWavelengths, toWavelengths, toFwhm, toBands, errorMsg)) { if (toWavelengths.size() != toBands.size()) { if (toBands.size() < 2) // no need to try if only one point { continue; } if (useFillValue) { std::vector<double> values(toWavelengths.size(), fillValue); for (unsigned int i = 0; i < toBands.size(); ++i) { values[static_cast<unsigned int>(toBands[i])] = toData[i]; } toData.swap(values); DynamicObject* pMetaData = pSignature->getMetadata(); if (pMetaData != NULL) { pMetaData->setAttribute(CommonSignatureMetadataKeys::FillValue(), fillValue); } } else { std::vector<double> wavelengths(toBands.size()); for (unsigned int i = 0; i < toBands.size(); ++i) { wavelengths[i] = toWavelengths[static_cast<unsigned int>(toBands[i])]; } toWavelengths.swap(wavelengths); } } pSignature->setData(dataName, toData); pSignature->setData(wavelengthName, toWavelengths); SignatureDataDescriptor* pDesc = dynamic_cast<SignatureDataDescriptor*>(pSignature->getDataDescriptor()); if (pDesc == NULL) { continue; } pDesc->setUnits(dataName, originalSignatures[index]->getUnits(dataName)); pResampledSignatures->push_back(pSignature.release()); ++numSigsResampled; } std::string progressStr = QString("Resampled signature %1 of %2 signatures").arg(index + 1).arg(numSigs).toStdString(); progress.report(progressStr, (index + 1) * 100 / numSigs, NORMAL); } // reset config options ResamplerOptions::setSettingResamplerMethod(configMethod); ResamplerOptions::setSettingDropOutWindow(configDropout); ResamplerOptions::setSettingFullWidthHalfMax(configFwhm); if (numSigsResampled == numSigs) { progress.report("Complete", 100, NORMAL); progress.upALevel(); } else { errorMsg = QString("Only %1 of the %2 signatures were successfully resampled.").arg( numSigsResampled).arg(numSigs).toStdString(); progress.report(errorMsg, 100, WARNING, true); } VERIFY(pOutArgList->setPlugInArgValue("Resampled signatures", pResampledSignatures.release())); return true; }
/** * Get the names of all the data elements which are children of the primary raster element. * * @param[in] WINDOW @opt * The name of the window. Defaults to the active window. * @return An array of data element names or the string "failure" if an error occurred. * @usage names = get_data_element_names() * @endusage */ IDL_VPTR get_data_element_names(int argc, IDL_VPTR pArgv[], char* pArgk) { typedef struct { IDL_KW_RESULT_FIRST_FIELD; int windowExists; IDL_STRING windowName; } 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, {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)), reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))}, {NULL} }; IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1); std::string windowName; std::string name; bool bSuccess = false; IDL_VPTR idlPtr; unsigned int total = 0; IDL_STRING* pStrarr = NULL; if (kw->windowExists) { windowName = IDL_STRING_STR(&kw->windowName); } SpatialDataWindow* pWindow = NULL; if (windowName.empty()) { pWindow = dynamic_cast<SpatialDataWindow*>(Service<DesktopServices>()->getCurrentWorkspaceWindow()); } else { pWindow = dynamic_cast<SpatialDataWindow*>( Service<DesktopServices>()->getWindow(windowName, SPATIAL_DATA_WINDOW)); } if (pWindow != NULL) { SpatialDataView* pView = pWindow->getSpatialDataView(); if (pView != NULL) { LayerList* pList = pView->getLayerList(); if (pList != NULL) { RasterElement* pElement = pList->getPrimaryRasterElement(); if (pElement != NULL) { std::vector<std::string> names = Service<ModelServices>()->getElementNames(pElement, ""); total = names.size(); if (total > 0) { pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total * sizeof(IDL_STRING))); for (unsigned int i=0; i < total; ++i) { IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str())); } bSuccess = true; } } } } } else if (windowName == "all") { std::vector<std::string> names = Service<ModelServices>()->getElementNames("RasterElement"); total = names.size(); if (total > 0) { pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total* sizeof(IDL_STRING))); for (unsigned int i=0; i < total; ++i) { IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str())); } bSuccess = true; } } if (!bSuccess) { IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "No elements matched."); return IDL_StrToSTRING("failure"); } IDL_MEMINT dims[] = {total}; idlPtr = IDL_ImportArray(1, dims, IDL_TYP_STRING, reinterpret_cast<UCHAR*>(pStrarr), reinterpret_cast<IDL_ARRAY_FREE_CB>(free), NULL); return idlPtr; }
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(); }
bool LayerImporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { Layer* pLayer = NULL; Progress* pProgress = NULL; DataElement* pElement = NULL; SpatialDataView* pView = NULL; StepResource pStep("Import layer", "app", "DF24688A-6B34-4244-98FF-5FFE2063AC05"); // get input arguments and log some useful info about them { // scope the MessageResource MessageResource pMsg("Input arguments", "app", "C0A532DE-0E19-44D3-837C-16ABD267B2C1"); pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); pMsg->addBooleanProperty("Progress Present", (pProgress != NULL)); pElement = pInArgList->getPlugInArgValue<DataElement>(Importer::ImportElementArg()); if (pElement == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No data element", 100, ERRORS); } pStep->finalize(Message::Failure, "No data element"); return false; } pMsg->addProperty("Element name", pElement->getName()); pView = pInArgList->getPlugInArgValue<SpatialDataView>(Executable::ViewArg()); if (pView != NULL) { pMsg->addProperty("View name", pView->getName()); } } if (pProgress != NULL) { pProgress->updateProgress((string("Read and parse file ") + pElement->getFilename()), 20, NORMAL); } // parse the xml XmlReader xml(Service<MessageLogMgr>()->getLog()); XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDomDocument = xml.parse(pElement->getFilename()); if (pDomDocument == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Unable to parse the file", 100, ERRORS); } pStep->finalize(Message::Failure, "Unable to parse the file"); return false; } DOMElement* pRootElement = pDomDocument->getDocumentElement(); VERIFY(pRootElement != NULL); if (pProgress != NULL) { pProgress->updateProgress("Create the layer", 40, NORMAL); } string name(A(pRootElement->getAttribute(X("name")))); string type(A(pRootElement->getAttribute(X("type")))); unsigned int formatVersion = atoi(A(pRootElement->getAttribute(X("version")))); { // scope the MessageResource MessageResource pMsg("Layer information", "app", "AA358F7A-107E-456E-8D11-36DDBE5B1645"); pMsg->addProperty("name", name); pMsg->addProperty("type", type); pMsg->addProperty("format version", formatVersion); } // If user requested pixel coordinates be used. bool usePixelCoords = false; DataDescriptor* pDesc = pElement->getDataDescriptor(); VERIFY( pDesc ); pDesc->getMetadata()->getAttributeByPath( "Layer/Import Options/Use Pixel Coordinates" ).getValue( usePixelCoords ); if (usePixelCoords) { // Remove geoVertices and geoBox elements. removeGeoNodes(pRootElement); } if (pView == NULL) { //no view provided, so find current view SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(mpDesktop->getCurrentWorkspaceWindow()); if (pWindow != NULL) { pView = pWindow->getSpatialDataView(); } } if (pView == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Could not access the view to create the layer.", 100, ERRORS); } pStep->finalize(Message::Failure, "Could not access the view to create the layer."); return false; } bool error = false; LayerType layerType = StringUtilities::fromXmlString<LayerType>(type, &error); if (error == true) { if (pProgress != NULL) { pProgress->updateProgress("The layer type is invalid.", 100, ERRORS); } pStep->finalize(Message::Failure, "The layer type is invalid."); return false; } LayerList* pLayerList = pView->getLayerList(); if (pLayerList != NULL) { RasterElement* pNewParentElement = pLayerList->getPrimaryRasterElement(); if (pNewParentElement != NULL) { Service<ModelServices> pModel; if (pModel->setElementParent(pElement, pNewParentElement) == false) { pProgress->updateProgress("The layer already exists.", 100, ERRORS); pStep->finalize(Message::Failure, "The layer already exists."); return false; } } } UndoGroup group(pView, "Import " + StringUtilities::toDisplayString(layerType) + " Layer"); pLayer = pView->createLayer(layerType, pElement); if (pLayer == NULL) { if (pProgress != NULL) { pProgress->updateProgress("Unable to create the layer", 100, ERRORS); } pStep->finalize(Message::Failure, "Unable to create the layer"); return false; } if (pProgress != NULL) { pProgress->updateProgress("Build the layer", 60, NORMAL); } // deserialize the layer try { if (pLayer->fromXml(pRootElement, formatVersion) == false) { pProgress->updateProgress("Problem with layer file.", 100, ERRORS); pStep->finalize(Message::Failure, "Problem with layer file."); return false; } } catch (XmlReader::DomParseException&) { return false; } pStep->finalize(Message::Success); if (pProgress != NULL) { pProgress->updateProgress("Finished loading the layer", 100, NORMAL); } // Add the layer to the view pView->addLayer(pLayer); pView->setActiveLayer(pLayer); pView->setMouseMode("LayerMode"); if (pOutArgList != NULL) { // set the output arguments pOutArgList->setPlugInArgValue("Layer", pLayer); } return true; }
static DocRange drop_range_op( Doc* doc, const Op op, const DocRange& from, DocRangePlace place, const TagsHandling tagsHandling, DocRange to) { // Convert "first child" operation into a insert after last child. LayerGroup* parent = nullptr; if (to.type() == DocRange::kLayers && !to.selectedLayers().empty()) { if (place == kDocRangeFirstChild && (*to.selectedLayers().begin())->isGroup()) { place = kDocRangeAfter; parent = static_cast<LayerGroup*>((*to.selectedLayers().begin())); to.clearRange(); to.startRange(parent->lastLayer(), -1, DocRange::kLayers); to.endRange(parent->lastLayer(), -1); } else { parent = (*to.selectedLayers().begin())->parent(); } // Check that we're not moving a group inside itself for (auto moveThis : from.selectedLayers()) { if (moveThis == parent || (moveThis->isGroup() && has_child(static_cast<LayerGroup*>(moveThis), parent))) return from; } } if (place != kDocRangeBefore && place != kDocRangeAfter) { ASSERT(false); throw std::invalid_argument("Invalid 'place' argument"); } Sprite* sprite = doc->sprite(); // Check noop/trivial/do nothing cases, i.e., move a range to the same place. // Also check invalid cases, like moving a Background layer. switch (from.type()) { case DocRange::kCels: if (from == to) return from; break; case DocRange::kFrames: if (op == Move) { // Simple cases with one continuos range of frames that are a // no-op. if ((from.selectedFrames().ranges() == 1) && ((to.firstFrame() >= from.firstFrame() && to.lastFrame() <= from.lastFrame()) || (place == kDocRangeBefore && to.firstFrame() == from.lastFrame()+1) || (place == kDocRangeAfter && to.lastFrame() == from.firstFrame()-1)) && // If there are tags, this might not be a no-op (sprite->frameTags().empty() || tagsHandling == kDontAdjustTags)) { return from; } } break; case DocRange::kLayers: if (op == Move) { SelectedLayers srcSelLayers = from.selectedLayers(); SelectedLayers dstSelLayers = to.selectedLayers(); LayerList srcLayers = srcSelLayers.toLayerList(); LayerList dstLayers = dstSelLayers.toLayerList(); ASSERT(!srcLayers.empty()); if (srcLayers.empty()) return from; // dstLayers can be nullptr when we insert the first child in // a group. // Check no-ops when we move layers at the same level (all // layers with the same parent), all adjacents, and which are // moved to the same place. if (!dstSelLayers.empty() && srcSelLayers.hasSameParent() && dstSelLayers.hasSameParent() && are_layers_adjacent(srcLayers) && are_layers_adjacent(dstLayers)) { for (Layer* srcLayer : srcLayers) if (dstSelLayers.contains(srcLayer)) return from; if ((place == kDocRangeBefore && dstLayers.front() == srcLayers.back()->getNext()) || (place == kDocRangeAfter && dstLayers.back() == srcLayers.front()->getPrevious())) return from; } // We cannot move the background for (Layer* layer : srcSelLayers) if (layer->isBackground()) throw std::runtime_error("The background layer cannot be moved"); } // Before background if (place == kDocRangeBefore) { for (Layer* background : to.selectedLayers()) { if (background && background->isBackground()) throw std::runtime_error("You cannot move or copy something below the background layer"); } } break; } const char* undoLabel = NULL; switch (op) { case Move: undoLabel = "Move Range"; break; case Copy: undoLabel = "Copy Range"; break; default: ASSERT(false); throw std::invalid_argument("Invalid 'op' argument"); } DocRange resultRange; { const app::Context* context = static_cast<app::Context*>(doc->context()); const ContextReader reader(context); ContextWriter writer(reader, 500); Transaction transaction(writer.context(), undoLabel, ModifyDocument); DocApi api = doc->getApi(transaction); // TODO Try to add the range with just one call to DocApi // methods, to avoid generating a lot of cmd::SetCelFrame (see // DocApi::setCelFramePosition() function). switch (from.type()) { case DocRange::kCels: { LayerList allLayers = sprite->allBrowsableLayers(); if (allLayers.empty()) break; LayerList srcLayers = from.selectedLayers().toLayerList(); LayerList dstLayers = to.selectedLayers().toLayerList(); if (srcLayers.empty() || dstLayers.empty()) throw std::invalid_argument("You need to specify a non-empty cels range"); if (find_layer_index(allLayers, srcLayers.front()) < find_layer_index(allLayers, dstLayers.front())) { std::reverse(srcLayers.begin(), srcLayers.end()); std::reverse(dstLayers.begin(), dstLayers.end()); } if (from.firstFrame() < to.firstFrame()) { auto srcFrames = from.selectedFrames().makeReverse(); auto dstFrames = to.selectedFrames().makeReverse(); move_or_copy_cels(api, op, srcLayers, dstLayers, srcFrames, dstFrames); } else { const auto& srcFrames = from.selectedFrames(); const auto& dstFrames = to.selectedFrames(); move_or_copy_cels(api, op, srcLayers, dstLayers, srcFrames, dstFrames); } resultRange = to; break; } case DocRange::kFrames: { frame_t dstFrame; if (place == kDocRangeBefore) dstFrame = to.firstFrame(); else dstFrame = to.lastFrame(); resultRange = move_or_copy_frames(api, op, sprite, from, dstFrame, place, tagsHandling); break; } case DocRange::kLayers: { LayerList allLayers = sprite->allBrowsableLayers(); if (allLayers.empty()) break; LayerList srcLayers = from.selectedLayers().toLayerList(); LayerList dstLayers = to.selectedLayers().toLayerList(); ASSERT(!srcLayers.empty()); switch (op) { case Move: if (place == kDocRangeBefore) { Layer* beforeThis = (!dstLayers.empty() ? dstLayers.front(): nullptr); Layer* afterThis = nullptr; for (Layer* srcLayer : srcLayers) { if (afterThis) api.restackLayerAfter(srcLayer, parent, afterThis); else api.restackLayerBefore(srcLayer, parent, beforeThis); afterThis = srcLayer; } } else if (place == kDocRangeAfter) { Layer* afterThis = (!dstLayers.empty() ? dstLayers.back(): nullptr); for (Layer* srcLayer : srcLayers) { api.restackLayerAfter(srcLayer, parent, afterThis); afterThis = srcLayer; } } // Same set of layers than the "from" range resultRange = from; break; case Copy: { if (place == kDocRangeBefore) { Layer* beforeThis = (!dstLayers.empty() ? dstLayers.front(): nullptr); for (Layer* srcLayer : srcLayers) { Layer* copiedLayer = api.duplicateLayerBefore( srcLayer, parent, beforeThis); resultRange.startRange(copiedLayer, -1, DocRange::kLayers); resultRange.endRange(copiedLayer, -1); } } else if (place == kDocRangeAfter) { std::reverse(srcLayers.begin(), srcLayers.end()); Layer* afterThis = (!dstLayers.empty() ? dstLayers.back(): nullptr); for (Layer* srcLayer : srcLayers) { Layer* copiedLayer = api.duplicateLayerAfter( srcLayer, parent, afterThis); resultRange.startRange(copiedLayer, -1, DocRange::kLayers); resultRange.endRange(copiedLayer, -1); } } break; } } break; } } if (resultRange.type() != DocRange::kNone) transaction.setNewDocRange(resultRange); transaction.commit(); } return resultRange; }
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."); } } } }
string MeasurementObjectImp::generateGeoStrings() const { LocationType llCorner = getLlCorner(); LocationType urCorner = getUrCorner(); LocationType llCornerLatLon; LocationType urCornerLatLon; bool unitsValid = false; // Get lat lon coordinates and terrain raster const RasterElement* pTerrain = NULL; bool geoValid(false); if (mpGeoreference.get() != NULL) { GraphicLayer* pLayer = getLayer(); if (pLayer != NULL) { SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView()); if (pView != NULL) { LayerList* pLayerList = pView->getLayerList(); VERIFYRV(pLayerList != NULL, ""); VERIFYRV(pLayerList->getPrimaryRasterElement() == mpGeoreference.get(), ""); pTerrain = mpGeoreference->getTerrain(); Layer* pPrimaryRasterLayer = pLayerList->getLayer(RASTER, mpGeoreference.get()); if (pPrimaryRasterLayer != NULL) { pPrimaryRasterLayer->translateWorldToData(llCorner.mX, llCorner.mY, llCorner.mX, llCorner.mY); pPrimaryRasterLayer->translateWorldToData(urCorner.mX, urCorner.mY, urCorner.mX, urCorner.mY); } } } if (mpGeoreference->isGeoreferenced()) { bool llValid(false); bool urValid(false); llCornerLatLon = mpGeoreference->convertPixelToGeocoord(llCorner, false, &llValid); urCornerLatLon = mpGeoreference->convertPixelToGeocoord(urCorner, false, &urValid); geoValid = llValid && urValid; } } mUsingInaccurateGeocoords = !geoValid; unitsValid = geoValid; //String Variables string startLoc = ""; string endLoc = ""; string distance = ""; string bearing = ""; string distanceUnit = ""; GeoAlgorithms algs; double distanceVal = 0; double azimuthVal = 0; // Create GeoPoint objects LatLonPoint startLlPoint = llCornerLatLon; LatLonPoint endLlPoint = urCornerLatLon; UtmPoint startUtmPoint = startLlPoint; UtmPoint endUtmPoint = endLlPoint; MgrsPoint startMgrsPoint = startLlPoint; MgrsPoint endMgrsPoint = endLlPoint; // find elevations double elevation1(0.0); double elevation2(0.0); if (pTerrain != NULL) { const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pTerrain->getDataDescriptor()); if (pDescriptor != NULL) { const vector<DimensionDescriptor>& activeRows = pDescriptor->getRows(); const vector<DimensionDescriptor>& activeColumns = pDescriptor->getColumns(); if ( llCorner.mY >= 0 && llCorner.mY < activeRows.size() && llCorner.mX >= 0 && llCorner.mX < activeColumns.size() && urCorner.mY >= 0 && urCorner.mY < activeRows.size() && urCorner.mX >= 0 && urCorner.mX < activeColumns.size() ) { DimensionDescriptor llRowDim(activeRows[llCorner.mY]); DimensionDescriptor llColumnDim(activeColumns[llCorner.mX]); DimensionDescriptor urRowDim(activeRows[urCorner.mY]); DimensionDescriptor urColumnDim(activeColumns[urCorner.mX]); elevation1 = pTerrain->getPixelValue(llColumnDim, llRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE); elevation2 = pTerrain->getPixelValue(urColumnDim, urRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE); const Units* pElevationUnits = pDescriptor->getUnits(); if (pElevationUnits != NULL) { double scale = pElevationUnits->getScaleFromStandard(); elevation1 *= scale; elevation2 *= scale; } } } } if (unitsValid == true) { // Calculate bearing and distance distanceVal = algs.getPythagoreanOrVincentyDistance(startLlPoint.getLatitude().getValue(), startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(), endLlPoint.getLongitude().getValue(), elevation1, elevation2); azimuthVal = algs.getVincentyAzimuth(startLlPoint.getLatitude().getValue(), startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(), endLlPoint.getLongitude().getValue()); azimuthVal = GeoConversions::convertRadToDeg(azimuthVal); // Set distance text if (mDrawnDistanceUnit == KILOMETER) { distanceUnit = "km"; distanceVal = distanceVal/1000; } else if (mDrawnDistanceUnit == MILE) { distanceUnit = "mi"; distanceVal = GeoConversions::convertMetersToMiles(distanceVal); } else if (mDrawnDistanceUnit == NAUTICAL_MILE) { distanceUnit = "Nm"; distanceVal = GeoConversions::convertMetersToNm(distanceVal); } else if (mDrawnDistanceUnit == METER) { distanceUnit = "m"; } else if (mDrawnDistanceUnit == YARD) { distanceUnit = "yd"; distanceVal = GeoConversions::convertMetersToFeet(distanceVal)/3; } else if (mDrawnDistanceUnit == FOOT) { distanceUnit = "ft"; distanceVal = GeoConversions::convertMetersToFeet(distanceVal); } // set location text switch (mDrawnGeocoord) { case GEOCOORD_LATLON: startLoc = startLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision); endLoc = endLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision); break; case GEOCOORD_UTM: startLoc = startUtmPoint.getText(); endLoc = endUtmPoint.getText(); break; case GEOCOORD_MGRS: startLoc = startMgrsPoint.getText(); endLoc = endMgrsPoint.getText(); break; default: startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " + QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")"; endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " + QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")"; break; } } else { startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " + QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")"; endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " + QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")"; azimuthVal = algs.getPythagoreanAzimuth(llCorner.mX, llCorner.mY, urCorner.mX, urCorner.mY); azimuthVal = GeoConversions::convertRadToDeg(azimuthVal); distanceVal = algs.getPythagoreanDistance(urCorner.mX, urCorner.mY, llCorner.mX, llCorner.mY); distanceUnit = "pix"; } bearing = QString::number(azimuthVal, 'f', mBearingPrecision).toStdString(); distance = QString::number(distanceVal, 'f', mDistancePrecision).toStdString(); QString bearingText = QString::fromStdString(bearing) + " deg"; QString distanceText = QString::fromStdString(distance) + " " + QString::fromStdString(distanceUnit); QString startLocText = QString::fromStdString(startLoc); QString endLocText = QString::fromStdString(endLoc); // Final strings if (bearingText != mBearingText) { mBearingText = bearingText; mBearingTextTexture.invalidate(); } if (distanceText != mDistanceText) { mDistanceText = distanceText; mDistanceTextTexture.invalidate(); } if (startLocText != mStartLocText) { mStartLocText = startLocText; mStartLocTextTexture.invalidate(); } if (endLocText != mEndLocText) { mEndLocText = endLocText; mEndLocTextTexture.invalidate(); } string rtnVal = "DISTANCE: " + distanceText.toStdString() + " : LOCATION: " + startLoc + " to " + endLoc + " at " + bearingText.toStdString(); return rtnVal; }
LocateDialog::LocateDialog(const RasterElement* pRaster, QWidget* pParent) : QDialog(pParent, Qt::WindowCloseButtonHint), mpRaster(pRaster), mLayerNameBase("Spectral Library Match Locate Results - "), mpAlgCombo(NULL), mpThreshold(NULL), mpOutputLayerName(NULL), mpUseAoi(NULL), mpAoiCombo(NULL), mpSaveSettings(NULL) { setWindowTitle("Locate Matched Signatures Settings"); // layout QGridLayout* pGrid = new QGridLayout(this); pGrid->setSpacing(5); pGrid->setMargin(10); QLabel* pNameLabel = new QLabel("Dataset:", this); QLabel* pDataLabel = new QLabel(QString::fromStdString(pRaster->getDisplayName(true)), this); pDataLabel->setToolTip(QString::fromStdString(pRaster->getName())); QLabel* pAlgLabel = new QLabel("Algorithm:", this); mpAlgCombo = new QComboBox(this); QLabel* pThresLabel = new QLabel("Threshold:", this); mpThreshold = new QDoubleSpinBox(this); mpThreshold->setSingleStep(0.1); QLabel* pLayerLabel = new QLabel("Output Layer Name:", this); mpOutputLayerName = new QLineEdit(this); mpUseAoi = new QCheckBox("Area of Interest:", this); mpUseAoi->setToolTip("Check box to limit the Locate function to an AOI"); mpAoiCombo = new QComboBox(this); mpAoiCombo->setEnabled(false); mpSaveSettings = new QCheckBox("Save the algorithm and threshold settings", this); QFrame* pLineSeparator = new QFrame(this); pLineSeparator->setFrameStyle(QFrame::HLine | QFrame::Sunken); QDialogButtonBox* pButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); pGrid->addWidget(pNameLabel, 0, 0, Qt::AlignRight); pGrid->addWidget(pDataLabel, 0, 1); pGrid->addWidget(pAlgLabel, 1, 0, Qt::AlignRight); pGrid->addWidget(mpAlgCombo, 1, 1); pGrid->addWidget(pThresLabel, 2, 0, Qt::AlignRight); pGrid->addWidget(mpThreshold, 2, 1); pGrid->addWidget(pLayerLabel, 3, 0, Qt::AlignRight); pGrid->addWidget(mpOutputLayerName, 3, 1); pGrid->addWidget(mpUseAoi, 4, 0, Qt::AlignRight); pGrid->addWidget(mpAoiCombo, 4, 1); pGrid->addWidget(mpSaveSettings, 5, 1); pGrid->addWidget(pLineSeparator, 7, 0, 1, 2); pGrid->addWidget(pButtons, 8, 0, 1, 2, Qt::AlignRight); pGrid->setRowStretch(6, 10); pGrid->setColumnStretch(1, 10); // initialize algorithm combo std::vector<std::string> algNames = StringUtilities::getAllEnumValuesAsDisplayString<SpectralLibraryMatch::LocateAlgorithm>(); for (std::vector<std::string>::const_iterator it = algNames.begin(); it != algNames.end(); ++it) { mpAlgCombo->addItem(QString::fromStdString(*it)); } // set up algorithm threshold map std::vector<std::string> algorithmNames = StringUtilities::getAllEnumValuesAsDisplayString<SpectralLibraryMatch::LocateAlgorithm>(); for (std::vector<std::string>::iterator it = algorithmNames.begin(); it != algorithmNames.end(); ++it) { float threshold(0.0f); switch (StringUtilities::fromDisplayString<SpectralLibraryMatch::LocateAlgorithm>(*it)) { case SpectralLibraryMatch::SLLA_CEM: threshold = SpectralLibraryMatchOptions::getSettingLocateCemThreshold(); break; case SpectralLibraryMatch::SLLA_SAM: threshold = SpectralLibraryMatchOptions::getSettingLocateSamThreshold(); break; case SpectralLibraryMatch::SLLA_WBI: threshold = SpectralLibraryMatchOptions::getSettingLocateWbiThreshold(); break; default: threshold = 0.0f; break; } mLocateThresholds.insert(std::pair<std::string, float>(*it, threshold)); } // load aoi combo std::vector<DataElement*> aois = Service<ModelServices>()->getElements(pRaster, TypeConverter::toString<AoiElement>()); for (std::vector<DataElement*>::const_iterator it = aois.begin(); it != aois.end(); ++it) { mpAoiCombo->addItem(QString::fromStdString((*it)->getName())); } // try to determine the active aoi layer and set combo to the element for that layer std::vector<Window*> windows; SpatialDataView* pView(NULL); Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows); for (std::vector<Window*>::iterator it = windows.begin(); it != windows.end(); ++it) { SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(*it); if (pWindow != NULL) { SpatialDataView* pTmpView = dynamic_cast<SpatialDataView*>(pWindow->getView()); if (pTmpView != NULL) { LayerList* pLayerList = pTmpView->getLayerList(); if (pLayerList != NULL) { if (pRaster == pLayerList->getPrimaryRasterElement()) { pView = pTmpView; break; } } } } } if (pView != NULL) { Layer* pLayer = pView->getActiveLayer(); if (pLayer != NULL) { DataElement* pElement = pLayer->getDataElement(); if (pElement != NULL) { std::string elementName = pElement->getName(); int index = mpAoiCombo->findText(QString::fromStdString(elementName)); if (index != -1) { mpAoiCombo->setCurrentIndex(index); } } } } if (mpAoiCombo->count() == 0) { mpUseAoi->setEnabled(false); } // Initialize From Settings SpectralLibraryMatch::LocateAlgorithm locType = StringUtilities::fromXmlString<SpectralLibraryMatch::LocateAlgorithm>( SpectralLibraryMatchOptions::getSettingLocateAlgorithm()); mpAlgCombo->setCurrentIndex(mpAlgCombo->findText(QString::fromStdString( StringUtilities::toDisplayString<SpectralLibraryMatch::LocateAlgorithm>(locType)))); mpThreshold->setValue(mLocateThresholds[mpAlgCombo->currentText().toStdString()]); QString layerName = mLayerNameBase; switch (locType) { case SpectralLibraryMatch::SLLA_CEM: layerName += "CEM"; break; case SpectralLibraryMatch::SLLA_SAM: layerName += "SAM"; break; case SpectralLibraryMatch::SLLA_WBI: layerName += "WBI"; break; default: layerName += "Unknown Algorithm"; break; } mpOutputLayerName->setText(layerName); // connections VERIFYNR(connect(pButtons, SIGNAL(accepted()), this, SLOT(accept()))); VERIFYNR(connect(pButtons, SIGNAL(rejected()), this, SLOT(reject()))); VERIFYNR(connect(mpAlgCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(algorithmChanged(const QString&)))); VERIFYNR(connect(mpThreshold, SIGNAL(valueChanged(double)), this, SLOT(thresholdChanged(double)))); VERIFYNR(connect(mpUseAoi, SIGNAL(toggled(bool)), mpAoiCombo, SLOT(setEnabled(bool)))); }
void Wms::getCapabilities() { QByteArray data; QTextStream out(&data); QString wmsurl = Qt::escape(m_request->url(FastCgiQt::LocationUrl).toEncoded()); QString proj = renderer.map.getProjection(); LayerList layers = renderer.map.getLayerList(); //out << XML_HEADER << endl; out << "<WMT_MS_Capabilities version=\"1.1.1\">"; // service info out << "<Service>" << "<Name>OGC:WMS</Name>" << "<Title>" << Qt::escape(renderer.title()) << "</Title>" << "<Abstract/>" << "<OnlineResource " << XML_XLINK_NS << " xlink:href=\"" << wmsurl << "\"/>" << "<ContactInformation/>" << "<Fees/>" << "<AccessConstraints/>" << "<KeywordList>"; out << "<Keyword>" << "</Keyword>"; // TODO out << "</KeywordList>" << "</Service>"; out << "<Capability>" << "<Request>" << "<GetCapabilities>" << "<Format>" << MIMETYPE_GC << "</Format>" << "<DCPType><HTTP><Get>" << "<OnlineResource " << XML_XLINK_NS << " xlink:href=\"" << wmsurl << "?Service=WMS&" << "\"/></Get></HTTP></DCPType>" << "</GetCapabilities>" << "<GetMap>"; // image formats QList<QByteArray> formats = renderer.getImageFormats(); for (QList<QByteArray>::ConstIterator fit = formats.constBegin(); fit != formats.constEnd(); ++fit) { QByteArray fb = *fit; QString outf; // ony return a few formats we want to support if (fb == "png") { outf = MIMETYPE_PNG; } else if (fb == "jpg") { outf = MIMETYPE_JPG; } else if (fb == "tiff") { outf = MIMETYPE_TIF; } if (!outf.isEmpty()) { out << "<Format>" << QString(outf) << "</Format>"; } } out << "<DCPType><HTTP><Get>" << "<OnlineResource " << XML_XLINK_NS << " xlink:href=\"" << wmsurl << "?SERVICE=WMS&\"/>" << "</Get></HTTP></DCPType>" << "</GetMap>" << "</Request>"; out << "<Exception><Format>" << MIMETYPE_SE << "</Format></Exception>"; out << "<Layer>" << "<Title>" << Qt::escape(renderer.title()) << "</Title>" << "<SRS>" << Qt::escape(proj) << "</SRS>"; //<LatLonBoundingBox minx="-179.992" miny="-90.008" maxx="180.008" maxy="89.992"/> // // layers /* for (LayerList::ConstIterator layer_it = layers.constBegin(); layer_it != layers.constEnd(); ++layer_it) { Layer layer = **layer_it; */ for(int i = 0; i < layers.count(); ++i) { Layer* layer = layers[i]; out << "<Layer queryable=\"0\">" << "<Name>" << Qt::escape(layer->name) << "</Name>" << "<Title>" << Qt::escape(layer->title) << "</Title>" << "<SRS>" << Qt::escape(proj) << "</SRS>"; out << "<LatLonBoundingBox minx=\"" << layer->bbox.left << "\" miny=\"" << layer->bbox.bottom << "\" maxx=\"" << layer->bbox.right << "\" maxy=\"" << layer->bbox.top << "\"/>" << "<BoundingBox SRS=\"" << Qt::escape(proj) << "\" minx=\"" << layer->bbox.left << "\" miny=\"" << layer->bbox.bottom << "\" maxx=\"" << layer->bbox.right << "\" maxy=\"" << layer->bbox.top << "\"/>"; out << "</Layer>"; } out << "</Layer>" << "</Capability>" << "</WMT_MS_Capabilities>"; out.flush(); m_request->setHeader(HTTP_CONTENT_TYPE, MIMETYPE_GC); QByteArray content_length = QByteArray::number(data.length()); m_request->setHeader(HTTP_CONTENT_LEN, content_length ); m_request->write(data); }