コード例 #1
0
bool GetPrimaryRasterLayer::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "5D20DF72-1C71-4a5d-9B1A-398A91154EBD");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (pInArgList == NULL || pOutArgList == NULL)
   {
      reportError("Invalid Plug-In Arg List specified.", "8161F92F-124F-4118-8E24-532187A442AA");
      return false;
   }

   if (extractInputArgs(pInArgList) == false)
   {
      return false;
   }

   LayerList* pLayerList = mpSpatialDataView->getLayerList();
   VERIFY(pLayerList != NULL);

   RasterElement* pElement = pLayerList->getPrimaryRasterElement();
   RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pLayerList->getLayer(RASTER, pElement));
   if (pOutArgList->setPlugInArgValue(Executable::LayerArg(), pLayer) == false)
   {
      reportError("Unable to set output argument.", "B4DE1827-3B96-4a96-89BB-62431B6E81CF");
      return false;
   }

   reportComplete();
   return true;
}
コード例 #2
0
ファイル: DeriveProduct.cpp プロジェクト: Siddharthk/opticks
bool DeriveProduct::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "58FE5CAB-E941-4E60-BA55-B29D70715FC4");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (!extractInputArgs(pInArgList))
   {
      reportError("Unable to extract input arguments.", "5E158F48-6089-4A88-ABD0-55C717BD13E2");
      return false;
   }
   View* pView = pInArgList->getPlugInArgValue<View>("View");
   if (pView == NULL)
   {
      std::vector<Window*> windows;
      Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows);
      if (!windows.empty())
      {
         pView = static_cast<SpatialDataWindow*>(windows.front())->getSpatialDataView();
      }
   }
   if (pView == NULL)
   {
      reportError("No view provided.", "852F585B-D239-4C0A-B993-70EE68EC8DEE");
      return false;
   }

   ProductWindow* pProductWindow = Service<DesktopServices>()->deriveProduct(pView);
   if (pProductWindow == NULL)
   {
      reportError("Unable to derive product", "E24BB5A5-A675-4897-9C48-A4E4109379DF");
      return false;
   }

   // Load a template if one is specified
   Filename* pTemplate = pInArgList->getPlugInArgValue<Filename>("Template");
   if (pTemplate != NULL)
   {
      if (!pProductWindow->getProductView()->loadTemplate(pTemplate->getFullPathAndName()))
      {
         reportError("Could not load the requested template!", "C99CE97E-3F0F-4CBB-8460-28D96D55596B");
         return false;
      }
   }

   // Set the output values
   if (!pOutArgList->setPlugInArgValue("Window", pProductWindow) ||
      !pOutArgList->setPlugInArgValue("View", pProductWindow->getProductView()))
   {
      reportError("Could not set the data set output value!", "3C53EDAE-DC70-4141-9759-ECD3EB9BE186");
      return false;
   }

   reportComplete();
   pStep->finalize(Message::Success);
   return true;
}
コード例 #3
0
ファイル: SetDisplayMode.cpp プロジェクト: Siddharthk/opticks
bool SetDisplayMode::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "0B137CEF-B7AF-4999-95AC-2873C39279E5");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (extractInputArgs(pInArgList) == false)
   {
      return false;
   }

   mpRasterLayer->setDisplayMode(mDisplayMode);
   reportComplete();
   return true;
}
コード例 #4
0
ファイル: ThresholdData.cpp プロジェクト: Tom-VdE/opticks
bool ThresholdData::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   VERIFY(pInArgList != NULL);
   StepResource pStep("Execute Wizard Item", "app", "{2501975d-7cd5-49b0-a3e7-49f7106793c0}");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();

   if (!extractInputArgs(pInArgList))
   {
      return false;
   }

   const RasterDataDescriptor* pDesc = static_cast<const RasterDataDescriptor*>(mpInputElement->getDataDescriptor());
   VERIFY(pDesc);
   DimensionDescriptor band;
   if (mDisplayBandNumber > 0)
   {
      band = pDesc->getOriginalBand(mDisplayBandNumber - 1);
      if (band.isValid() == false)
      {
         reportError("The specified band is invalid.", "{a529538b-5b82-425d-af10-385a2581beec}");
         return false;
      }
   }
   else
   {
      band = pDesc->getActiveBand(mDisplayBandNumber);
   }
   FactoryResource<DataRequest> pReq;
   pReq->setInterleaveFormat(BSQ);
   pReq->setBands(band, band, 1);
   DataAccessor acc = mpInputElement->getDataAccessor(pReq.release());
   if (!acc.isValid())
   {
      reportError("Unable to access data element.", "{b5f1b7dd-7cf7-4cd5-b5bc-7b747d3561b9}");
      return false;
   }

   // If necessary, convert region units
   if (mRegionUnits != RAW_VALUE)
   {
      Statistics* pStatistics = mpInputElement->getStatistics(band);
      if (pStatistics == NULL)
      {
         reportError("Unable to calculate data statistics.", "{61a44ced-a4aa-4423-b379-5783137eb980}");
         return false;
      }
      mFirstThreshold = convertToRawUnits(pStatistics, mRegionUnits, mFirstThreshold);
      mSecondThreshold = convertToRawUnits(pStatistics, mRegionUnits, mSecondThreshold);
   }
   FactoryResource<BitMask> pBitmask;
   for (unsigned int row = 0; row < pDesc->getRowCount(); ++row)
   {
      reportProgress("Thresholding data", 100 * row / pDesc->getRowCount(),
         "{2fc3dbea-1307-471c-bba2-bf86032be518}");
      for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col)
      {
         VERIFY(acc.isValid());
         double val = ModelServices::getDataValue(pDesc->getDataType(), acc->getColumn(), 0);
         switch (mPassArea)
         {
         case UPPER:
            if (val >= mFirstThreshold)
            {
               pBitmask->setPixel(col, row, true);
            }
            break;
         case LOWER:
            if (val <= mFirstThreshold)
            {
               pBitmask->setPixel(col, row, true);
            }
            break;
         case MIDDLE:
            if (val >= mFirstThreshold && val <= mSecondThreshold)
            {
               pBitmask->setPixel(col, row, true);
            }
            break;
         case OUTSIDE:
            if (val <= mFirstThreshold || val >= mSecondThreshold)
            {
               pBitmask->setPixel(col, row, true);
            }
            break;
         default:
            reportError("Unknown or invalid pass area.", "{19c92b3b-52e9-442b-a01f-b545f819f200}");
            return false;
         }
         acc->nextColumn();
      }
      acc->nextRow();
   }
   std::string aoiName = pDesc->getName() + "_aoi";
   ModelResource<AoiElement> pAoi(aoiName, mpInputElement);
   if (pAoi.get() == NULL)
   {
      reportWarning("Overwriting existing AOI.", "{d953a030-dd63-43a1-98db-b0f491dee123}");
      Service<ModelServices>()->destroyElement(
         Service<ModelServices>()->getElement(aoiName, TypeConverter::toString<AoiElement>(), mpInputElement));
      pAoi = ModelResource<AoiElement>(aoiName, mpInputElement);
   }
   if (pAoi.get() == NULL)
   {
      reportError("Unable to create output AOI.", "{f76c2f4d-9a7f-4055-9383-022116cdcadb}");
      return false;
   }
   pAoi->addPoints(pBitmask.get());
   AoiLayer* pLayer = NULL;
   if (mpView != NULL)
   {
      if ((pLayer = static_cast<AoiLayer*>(mpView->createLayer(AOI_LAYER, pAoi.get()))) == NULL)
      {
         reportWarning("Unable to create AOI layer, continuing thresholding.",
            "{5eca6ea0-33c1-4b1a-b777-c8e1b86fd2fb}");
      }
   }
   if (pOutArgList != NULL)
   {
      pOutArgList->setPlugInArgValue("Result", pAoi.get());
      if (pLayer != NULL)
      {
         pOutArgList->setPlugInArgValue("Result Layer", pLayer);
      }
   }
   pAoi.release();

   reportComplete();
   return true;
}
コード例 #5
0
bool GetSessionItemBase<T>::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   StepResource pStep("Execute Wizard Item", "app", "{234E6866-C61D-4ca8-9152-8CA3DCEFC3C0}");
   pStep->addProperty("Item", getName());
   mpStep = pStep.get();
   if (pInArgList == NULL || pOutArgList == NULL)
   {
      reportError("Invalid arguments.", "{0012BA62-EE8E-451e-B725-26D7335436AC}");
      return false;
   }

   if (extractInputArgs(pInArgList) == false)
   {
      reportError("Unable to extract input arguments.", "{365B8383-651C-421f-87D4-01238F4E3398}");
      return false;
   }

   // Create the dialog.
   QDialog dialog(Service<DesktopServices>()->getMainWidget());

   // Tree view containing available session items.
   QStringList columnNames;
   columnNames << "Name" << "Type";

   QTreeWidget* pTree = new QTreeWidget(&dialog);
   pTree->setColumnCount(columnNames.count());
   pTree->setHeaderLabels(columnNames);

   std::auto_ptr<QTreeWidgetItem> pRoot(new QTreeWidgetItem);
   pRoot->setFlags(Qt::NoItemFlags);
   pRoot->setText(GetSessionItemBase<T>::NameColumn, "No items available");
   pRoot->setData(GetSessionItemBase<T>::NameColumn,
      GetSessionItemBase<T>::SessionItemRole, QVariant::fromValue<void*>(NULL));
   populateTreeWidgetItem(pRoot.get());

   if (pRoot->childCount() > 0)
   {
      pTree->addTopLevelItems(pRoot->takeChildren());
   }
   else
   {
      pTree->addTopLevelItem(pRoot.release());
   }

   pTree->expandAll();
   pTree->resizeColumnToContents(0);

   // Buttons.
   QFrame* pLine = new QFrame(&dialog);
   pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
   QDialogButtonBox* pButtonBox = new QDialogButtonBox(
      QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);

   // Layout.
   QVBoxLayout* pLayout = new QVBoxLayout(&dialog);
   pLayout->setMargin(10);
   pLayout->setSpacing(10);
   pLayout->addWidget(pTree);
   pLayout->addWidget(pLine);
   pLayout->addWidget(pButtonBox);
   dialog.setWindowTitle(QString::fromStdString(mDialogCaption));
   dialog.resize(400, 400);

   // Connections.
   VERIFY(QObject::connect(pButtonBox, SIGNAL(accepted()), &dialog, SLOT(accept())));
   VERIFY(QObject::connect(pButtonBox, SIGNAL(rejected()), &dialog, SLOT(reject())));
   if (dialog.exec() != QDialog::Accepted)
   {
      reportError("User cancelled.", "{27E33A95-0DFB-486b-ABAE-BFC849418201}");
      return false;
   }

   QTreeWidgetItem* pItem = pTree->currentItem();
   if (pItem == NULL)
   {
      reportError("No item selected.", "{27B21666-19BB-4932-BF08-A81E340F1A54}");
      return false;
   }

   QVariant value = pItem->data(GetSessionItemBase<T>::NameColumn, GetSessionItemBase<T>::SessionItemRole);
   SessionItem* pSessionItem = reinterpret_cast<SessionItem*>(value.value<void*>());
   mpSessionItem = dynamic_cast<T*>(pSessionItem);
   if (mpSessionItem == NULL)
   {
      reportError("Wrong item type selected.", "{E6D3E131-4E71-4989-9D34-BC9A1157AB8E}");
      return false;
   }

   if (populateOutputArgs(pOutArgList) == false)
   {
      reportError("Unable to populate the output argument list.", "{C3AB6771-50C4-4091-BA39-3D44C82C93A8}");
      return false;
   }

   reportComplete();
   return true;
}