bool DeriveLayer::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { VERIFY(pInArgList != NULL); StepResource pStep("Execute Wizard Item", "app", "56D70072-0716-4506-B70D-9E6BD10C96A3"); pStep->addProperty("Item", getName()); mpStep = pStep.get(); if (!extractInputArgs(pInArgList)) { reportError("Unable to extract input arguments.", "4DB42DD5-2198-4d1e-BBB5-9745D4242C9D"); return false; } // Get the view SpatialDataView* pView = dynamic_cast<SpatialDataView*>(mpInputLayer->getView()); if (pView == NULL) { reportError("Only layers in a spatial data view can be converted.", "{039ac767-e6d5-441b-9b27-bf59cbb9ee9d}"); return false; } Layer* pNewLayer = NULL; if (mNewLayerName.empty()) { pNewLayer = pView->convertLayer(mpInputLayer, mNewLayerType); } else { pNewLayer = pView->deriveLayer(mpInputLayer, mNewLayerType); if (pNewLayer != NULL) { if (!pView->getLayerList()->renameLayer(pNewLayer, mNewLayerName)) { pView->deleteLayer(pNewLayer); reportError("Unable to derive a layer with the given name, because another layer " "with the same name already exists.", "{1e81e201-624f-4e96-83b5-8ceae01d7c1d}"); return false; } } } if (pNewLayer == NULL) { reportError("Unable to convert the layer.", "{f09810c2-f2a2-4887-a0f0-6848d74ffd28}"); return false; } // Set the output value if (pOutArgList != NULL) { if (!pOutArgList->setPlugInArgValue("Layer", pNewLayer) || !pOutArgList->setPlugInArgValue("Element", pNewLayer->getDataElement())) { reportError("Could not set the output value!", "3E2591B0-F41B-4de1-9D76-45245F9EF343"); return false; } } reportComplete(); return true; }
void destroyLayer(Layer* pLayer) { SpatialDataView* pSdv = (pLayer == NULL) ? NULL : dynamic_cast<SpatialDataView*>(pLayer->getView()); if (pSdv != NULL) { pSdv->deleteLayer(pLayer); } }
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 AlgorithmPattern::displayPseudocolorResults(RasterElement* pRasterElement, std::vector<std::string>& sigNames, Opticks::PixelOffset offset) { REQUIRE(pRasterElement != NULL); SpatialDataView* pView = NULL; vector<Window*> windows; mpDesktopServices->getWindows(SPATIAL_DATA_WINDOW, windows); for (unsigned int j = 0; j < windows.size() && pView == NULL; j++) { SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(windows[j]); if (pWindow != NULL) { SpatialDataView* pCurrentView = pWindow->getSpatialDataView(); if (pCurrentView != NULL) { LayerList* pLList = pCurrentView->getLayerList(); REQUIRE(pLList != NULL); vector<Layer*> layers; pLList->getLayers(RASTER, layers); for (vector<Layer*>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer) { if (*layer != NULL && static_cast<RasterElement*>((*layer)->getDataElement()) == getRasterElement()) { pView = pCurrentView; break; } } } } } REQUIRE(pView != NULL); PseudocolorLayer* pLayer = NULL; // Get or create a valid pseudocolor layer LayerList* pLayerList = pView->getLayerList(); if (pLayerList != NULL) { pLayer = static_cast<PseudocolorLayer*>(pLayerList->getLayer(PSEUDOCOLOR, pRasterElement)); if (pLayer == NULL) { pLayer = static_cast<PseudocolorLayer*>(pView->createLayer(PSEUDOCOLOR, pRasterElement)); } // Remove existing layers of other types if (pLayer != NULL) { Layer* pThresholdLayer = pLayerList->getLayer(THRESHOLD, pRasterElement); if (pThresholdLayer != NULL) { pView->deleteLayer(pThresholdLayer); } Layer* pRasterLayer = pLayerList->getLayer(RASTER, pRasterElement); if (pRasterLayer != NULL) { pView->deleteLayer(pRasterLayer); } } } INVARIANT(pLayer != NULL); UndoLock lock(pView); int iSignatureCount = sigNames.size(); vector<ColorType> layerColors; vector<ColorType> excludeColors; excludeColors.push_back(ColorType(0, 0, 0)); excludeColors.push_back(ColorType(255, 255, 255)); // 1 for each sig + no sigs + multiple sigs ColorType::getUniqueColors(iSignatureCount + 2, layerColors, excludeColors); pLayer->clear(); for (int i = 0; i < iSignatureCount; i++) { pLayer->addInitializedClass(sigNames[i], i + 1, layerColors[i], true); } pLayer->addInitializedClass(std::string("Indeterminate"), -1, layerColors[iSignatureCount], true); pLayer->addInitializedClass(std::string("No match"), 0, layerColors[iSignatureCount + 1], false); pLayer->setXOffset(offset.mX); pLayer->setYOffset(offset.mY); }
void AlgorithmPattern::displayThresholdResults(RasterElement* pRasterElement, ColorType color, PassArea passArea, double firstThreshold, double secondThreshold, Opticks::PixelOffset offset) { REQUIRE(pRasterElement != NULL); SpatialDataView* pView = NULL; vector<Window*> windows; mpDesktopServices->getWindows(SPATIAL_DATA_WINDOW, windows); for (unsigned int i = 0; i < windows.size() && pView == NULL; i++) { SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(windows[i]); if (pWindow != NULL) { SpatialDataView* pCurrentView = pWindow->getSpatialDataView(); if (pCurrentView != NULL) { LayerList* pLList = pCurrentView->getLayerList(); REQUIRE(pLList != NULL); vector<Layer*> layers; pLList->getLayers(RASTER, layers); for (vector<Layer*>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer) { if (*layer != NULL && static_cast<RasterElement*>((*layer)->getDataElement()) == getRasterElement()) { pView = pCurrentView; break; } } } } } REQUIRE(pView != NULL); ThresholdLayer* pLayer = NULL; // Get or create a valid threshold layer LayerList* pLayerList = pView->getLayerList(); if (pLayerList != NULL) { pLayer = static_cast<ThresholdLayer*>(pLayerList->getLayer(THRESHOLD, pRasterElement)); if (pLayer == NULL) { pLayer = static_cast<ThresholdLayer*>(pView->createLayer(THRESHOLD, pRasterElement)); } // Remove existing layers of other types if (pLayer != NULL) { Layer* pRasterLayer = pLayerList->getLayer(RASTER, pRasterElement); if (pRasterLayer != NULL) { pView->deleteLayer(pRasterLayer); } Layer* pPseudocolorLayer = pLayerList->getLayer(PSEUDOCOLOR, pRasterElement); if (pPseudocolorLayer != NULL) { pView->deleteLayer(pPseudocolorLayer); } } } INVARIANT(pLayer != NULL); UndoLock lock(pView); if (color.isValid()) { pLayer->setColor(color); } pLayer->setRegionUnits(RAW_VALUE); pLayer->setPassArea(passArea); pLayer->setFirstThreshold(firstThreshold); pLayer->setSecondThreshold(secondThreshold); pLayer->setXOffset(offset.mX); pLayer->setYOffset(offset.mY); }