Ejemplo n.º 1
0
bool BandMath::createReturnValue(string partialResultsName)
{
   // Set the short and long result names
   FactoryResource<Filename> pFilename;
   string shortResultsName;
   string longResultsName;
   if (pFilename.get() != NULL)
   {
      pFilename->setFullPathAndName(mpCube->getFilename());
      shortResultsName = pFilename->getTitle() + " = " + partialResultsName;
      longResultsName = pFilename->getPath() + "/" + pFilename->getTitle() + " = " + partialResultsName;
   }
   mResultsName = longResultsName;

   const RasterDataDescriptor* pOrigDescriptor = dynamic_cast<RasterDataDescriptor*>(mpCube->getDataDescriptor());
   const vector<DimensionDescriptor>& origRows = pOrigDescriptor->getRows();
   const vector<DimensionDescriptor>& origColumns = pOrigDescriptor->getColumns();

   mpResultData = NULL;

   unsigned int bandCount = mCubeBands;
   if (mbCubeMath == false)
   {
      bandCount = 1;
   }

   RasterElement* pParent = NULL;
   if (mbAsLayerOnExistingView)
   {
      pParent = mpCube;
   }
   RasterElement* pRaster = RasterUtilities::createRasterElement(mResultsName, origRows.size(),
      origColumns.size(), bandCount, FLT4BYTES, BIP, pOrigDescriptor->getProcessingLocation() == IN_MEMORY, pParent);

   if (pRaster == NULL)
   {
      mstrProgressString = "Error creating result raster element";
      meGabbiness = ERRORS;
      displayErrorMessage();
      mbError = true;
      return false;
   }

   if (!mbAsLayerOnExistingView)
   {
      // need to copy classification since parent was NULL in call to createRasterElement
      pRaster->copyClassification(mpCube);

      // make copies of existing GcpLists only if going into a new view
      vector<DataElement*> gcps = mpDataModel->getElements(mpCube, "GcpList");
      if (!gcps.empty())
      {
         vector<DataElement*>::iterator iter;
         for (iter = gcps.begin(); iter != gcps.end(); ++iter)
         {
            GcpList* theGcp = dynamic_cast<GcpList*>(*iter);
            theGcp->copy(theGcp->getName(), pRaster);
         }
      }
   }

   mpResultData = pRaster;

   RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>
      (mpResultData->getDataDescriptor());
   if (pDescriptor != NULL)
   {
      // Rows
      vector<DimensionDescriptor> rows = pDescriptor->getRows();
      for (unsigned int i = 0; i < origRows.size(); ++i)
      {
         // Original number
         DimensionDescriptor origRow = origRows[i];
         if (origRow.isOriginalNumberValid() == true)
         {
            rows[i].setOriginalNumber(origRow.getOriginalNumber());
         }
      }
      pDescriptor->setRows(rows);

      // Columns
      vector<DimensionDescriptor> columns = pDescriptor->getColumns();
      for (unsigned int i = 0; i < origColumns.size(); ++i)
      {
         // Original number
         DimensionDescriptor origColumn = origColumns[i];
         if (origColumn.isOriginalNumberValid() == true)
         {
            columns[i].setOriginalNumber(origColumn.getOriginalNumber());
         }
      }
      pDescriptor->setColumns(columns);
   }

   return true;
}