DataAccessor BackgroundSuppressionShell::getCurrentFrameAccessor() const
{
   if(mpRaster == NULL)
   {
      return DataAccessor(NULL, NULL);
   }
   RasterDataDescriptor *pDesc = static_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor());
   VERIFYRV(pDesc != NULL, DataAccessor(NULL, NULL));
   FactoryResource<DataRequest> request;
   VERIFYRV(request.get() != NULL, DataAccessor(NULL, NULL));
   request->setInterleaveFormat(BSQ);
   DimensionDescriptor band = pDesc->getBands()[mCurrentFrame];
   request->setBands(band, band, 1);
   return mpRaster->getDataAccessor(request.release());
}
Esempio n. 2
0
DynamicObject* FeatureQueryOptions::toDynamicObject() const
{
   DynamicObject* pDynObj = QueryOptions::toDynamicObject();
   VERIFYRV(pDynObj != NULL, NULL);
   pDynObj->setAttribute(FORMAT_STRING, mFormatString);
   return pDynObj;
}
QWidget* RangeProfilePlotManager::createWidget()
{
   DockWindow* pWindow = getDockWindow();
   VERIFYRV(pWindow, NULL);
   pWindow->attach(SIGNAL_NAME(Window, SessionItemDropped), Slot(this, &RangeProfilePlotManager::dropSessionItem));
   pWindow->enableSessionItemDrops(this);
   if (!Service<SessionManager>()->isSessionLoading())
   {
      mpPlot = Service<DesktopServices>()->createPlotWidget(getName(), CARTESIAN_PLOT);
   }
   if (mpPlot == NULL)
   {
      return NULL;
   }
   mpView = mpPlot->getPlot();
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : If a SHALLOW_SELECTION selection mode is added " \
                                              "to plot view (OPTICKS-528), mpView should use it (tclarke)")
   mpMode = (mpView == NULL) ? NULL : mpView->getMouseMode("SelectionMode");
   if (mpMode == NULL)
   {
      return NULL;
   }
   mpView->getWidget()->installEventFilter(this);
   mpPlot->attach(SIGNAL_NAME(PlotWidget, AboutToShowContextMenu),
      Slot(this, &RangeProfilePlotManager::updateContextMenu));
   mpView->enableMouseMode(mpMode, true);
   mpView->setMouseMode(mpMode);

   return mpPlot->getWidget();
}
Esempio n. 4
0
CachedPage::UnitPtr DicomRasterPager::fetchUnit(DataRequest *pOriginalRequest)
{
   VERIFYRV(pOriginalRequest != NULL, CachedPage::UnitPtr());
   unsigned int frame = pOriginalRequest->getStartBand().getOriginalNumber();
   if(mConvertRgb)
   {
      frame /= 3;
   }
   const RasterDataDescriptor *pDesc = static_cast<const RasterDataDescriptor*>(getRasterElement()->getDataDescriptor());
   unsigned int bpp = pDesc->getBytesPerElement() * 8;
   size_t bufsize = mpImage->getOutputDataSize(bpp);
   char *pBuffer = new char[bufsize];
   if(!mpImage->getOutputData(pBuffer, bufsize, bpp, frame, 1))
   {
      delete pBuffer;
      return CachedPage::UnitPtr();
   }
   if(mConvertRgb)
   {
      unsigned int band = pOriginalRequest->getStartBand().getOriginalNumber();
      size_t bandsize = bufsize / 3;
      char *pNewBuffer = new char[bandsize];
      memcpy(pNewBuffer, pBuffer + (band * bandsize), bandsize);
      delete pBuffer;
      pBuffer = pNewBuffer;
      bufsize = bandsize;
   }
   return CachedPage::UnitPtr(new CachedPage::CacheUnit(pBuffer, pDesc->getRows()[0], pDesc->getRowCount(), bufsize));
}
Esempio n. 5
0
DynamicObject* DisplayQueryOptions::toDynamicObject() const
{
   DynamicObject* pDynObj = QueryOptions::toDynamicObject();
   VERIFYRV(pDynObj != NULL, NULL);

   pDynObj->setAttribute(UNIQUE_NAME, mUniqueName);
   pDynObj->setAttribute(CHECKED, mbQueryActive);
   pDynObj->setAttribute(ORDER, mOrder);

   return pDynObj;
}
Esempio n. 6
0
DynamicObject *QueryOptions::toDynamicObject() const
{
   FactoryResource<DynamicObject> pDynObj;
   VERIFYRV(pDynObj.get() != NULL, NULL);

   pDynObj->setAttribute(QUERY_NAME, mQueryName);
   pDynObj->setAttribute(QUERY_STRING, mQueryString);
   pDynObj->setAttribute(SYMBOL_NAME, mSymbolName);
   pDynObj->setAttribute(SYMBOL_SIZE, mSymbolSize);
   pDynObj->setAttribute(LINE_STATE, mLineState);
   pDynObj->setAttribute(LINE_STYLE, mLineStyle);
   pDynObj->setAttribute(LINE_WIDTH, mLineWidth);
   pDynObj->setAttribute(LINE_COLOR, mLineColor);
   pDynObj->setAttribute(LINE_SCALED, mLineScaled);
   pDynObj->setAttribute(FILL_COLOR, mFillColor);
   pDynObj->setAttribute(FILL_STYLE, mFillStyle);
   pDynObj->setAttribute(HATCH_STYLE, mHatchStyle);

   return pDynObj.release();
}
Esempio n. 7
0
CachedPage::UnitPtr DiHdfRasterPager::fetchUnit(DataRequest *pOriginalRequest)
{
   VERIFYRV(pOriginalRequest != NULL, CachedPage::UnitPtr());
   unsigned int frame = pOriginalRequest->getStartBand().getOnDiskNumber();
   if (mHdf.toFrame(frame) == FAIL)
   {
      return CachedPage::UnitPtr();
   }
   const RasterDataDescriptor *pDesc = static_cast<const RasterDataDescriptor*>(getRasterElement()->getDataDescriptor());
   unsigned int bpp = pDesc->getBytesPerElement();
   size_t bufsize = pOriginalRequest->getConcurrentRows() * pDesc->getColumnCount() * bpp;
   char* pBuffer = new char[bufsize];
   int32 pStart[] = {pDesc->getActiveColumn(0).getOnDiskNumber(), pOriginalRequest->getStartRow().getOnDiskNumber()};
   int32 pCount[] = {pDesc->getColumnCount(), pOriginalRequest->getConcurrentRows()};
   int32 pStride[] = {1, 1};
   if (GRreadimage(mHdf.riid(), pStart, pStride, pCount, pBuffer) == FAIL)
   {
      delete pBuffer;
      return CachedPage::UnitPtr();
   }
   return CachedPage::UnitPtr(new CachedPage::CacheUnit(
      pBuffer, pOriginalRequest->getStartRow(), pOriginalRequest->getConcurrentRows(),
      bufsize, pOriginalRequest->getStartBand()));
}
Esempio n. 8
0
QString LabeledSection::getText() const
{
   VERIFYRV(mpTextLabel != NULL, QString());
   return mpTextLabel->text();
}
Esempio n. 9
0
std::vector<ImportDescriptor*> FitsImporter::getImportDescriptors(const std::string& fname)
{
   std::string filename = fname;
   std::vector<std::vector<std::string> >& errors = mErrors[fname];
   std::vector<std::vector<std::string> >& warnings = mWarnings[fname];
   errors.clear();
   warnings.clear();
   int status=0;
   std::vector<ImportDescriptor*> descriptors;

   FitsFileResource pFile(filename);
   if (!pFile.isValid())
   {
      errors.resize(1);
      errors[0].push_back(pFile.getStatus());
      RETURN_DESCRIPTORS;
   }

   int hduCnt = 0;
   int specificHdu = 0;
   int hdu = 1;
   if (!splitFilename(filename, hduCnt, specificHdu, hdu, pFile, errors, warnings))
   {
      RETURN_DESCRIPTORS;
   }
   errors.resize(hduCnt+1);
   warnings.resize(hduCnt+1);

   for(; hdu <= hduCnt; ++hdu)
   {
      std::string datasetName = filename + "[" + StringUtilities::toDisplayString(hdu) + "]";
      int hduType;
      CHECK_FITS(fits_movabs_hdu(pFile, hdu, &hduType, &status), hdu, false, continue);
      ImportDescriptorResource pImportDescriptor(static_cast<ImportDescriptor*>(NULL));
      FactoryResource<DynamicObject> pMetadata;
      VERIFYRV(pMetadata.get() != NULL, descriptors);
      { // scope
         std::vector<std::string> comments;
         char pCard[81];
         char pValue[81];
         char pComment[81];
         int nkeys = 0;
         CHECK_FITS(fits_get_hdrspace(pFile, &nkeys, NULL, &status), hdu, true, ;);
         for(int keyidx = 1; keyidx <= nkeys; ++keyidx)
         {
            CHECK_FITS(fits_read_keyn(pFile, keyidx, pCard, pValue, pComment, &status), hdu, true, continue);
            std::string name = StringUtilities::stripWhitespace(std::string(pCard));
            std::string val = StringUtilities::stripWhitespace(std::string(pValue));
            std::string comment = StringUtilities::stripWhitespace(std::string(pComment));
            if (!val.empty())
            {
               pMetadata->setAttributeByPath("FITS/" + name, val);
            }
            else if (!comment.empty())
            {
               comments.push_back(comment);
            }
         }
         if (!comments.empty())
         {
            // ideally, this would add a multi-line string but Opticks doesn't display this properly
            // pMetadata->setAttributeByPath("FITS/COMMENT", StringUtilities::join(comments, "\n"));
            for(unsigned int idx = 0; idx < comments.size(); ++idx)
            {
               pMetadata->setAttributeByPath("FITS/COMMENT/" + StringUtilities::toDisplayString(idx), comments[idx]);
            }
         }
      }
      switch(hduType)
      {
      case IMAGE_HDU:
      {
         pImportDescriptor = ImportDescriptorResource(datasetName, TypeConverter::toString<RasterElement>());
         VERIFYRV(pImportDescriptor.get() != NULL, descriptors);

         EncodingType fileEncoding;
         InterleaveFormatType interleave(BSQ);
         unsigned int rows=0;
         unsigned int cols=0;
         unsigned int bands=1;

         int bitpix;
         int naxis;
         long axes[3];
         CHECK_FITS(fits_get_img_param(pFile, 3, &bitpix, &naxis, axes, &status), hdu, false, continue);
         switch(bitpix)
         {
         case BYTE_IMG:
            fileEncoding = INT1UBYTE;
            break;
         case SHORT_IMG:
            fileEncoding = INT2SBYTES;
            break;
         case LONG_IMG:
            fileEncoding = INT4SBYTES;
            break;
         case FLOAT_IMG:
            fileEncoding = FLT4BYTES;
            break;
         case DOUBLE_IMG:
            fileEncoding = FLT8BYTES;
            break;
         default:
            warnings[hdu].push_back("Unsupported BITPIX value " + StringUtilities::toDisplayString(bitpix) + ".");
            continue;
         }
         EncodingType dataEncoding = checkForOverflow(fileEncoding, pMetadata.get(), hdu, errors, warnings);
         if (naxis == 1)
         {
            // 1-D data is a signature
            pImportDescriptor = ImportDescriptorResource(datasetName, TypeConverter::toString<Signature>());
            pMetadata->setAttributeByPath(METADATA_SIG_ENCODING, dataEncoding);
            pMetadata->setAttributeByPath(METADATA_SIG_LENGTH, axes[0]);

            RasterUtilities::generateAndSetFileDescriptor(pImportDescriptor->getDataDescriptor(), filename,
               StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER);

            // add units
            SignatureDataDescriptor* pSigDd =
               dynamic_cast<SignatureDataDescriptor*>(pImportDescriptor->getDataDescriptor());
            if (pSigDd != NULL)
            {
               FactoryResource<Units> pUnits;
               pUnits->setUnitName("Custom");
               pUnits->setUnitType(CUSTOM_UNIT);
               pSigDd->setUnits("Reflectance", pUnits.get());
            }

            break; // leave switch()
         }
         else if (naxis == 2)
         {
            cols = axes[0];
            rows = axes[1];
         }
         else if (naxis == 3)
         {
            cols = axes[0];
            rows = axes[1];
            bands = axes[2];
         }
         else
         {
            errors[hdu].push_back(StringUtilities::toDisplayString(naxis) + " axis data not supported.");
         }

         RasterDataDescriptor* pDataDesc = RasterUtilities::generateRasterDataDescriptor(
            datasetName, NULL, rows, cols, bands, interleave, dataEncoding, IN_MEMORY);
         pImportDescriptor->setDataDescriptor(pDataDesc);
         if (specificHdu == 0 && hdu == 1 && naxis == 2 && (axes[0] <= 5 || axes[1] <= 5))
         {
            // use 5 as this is a good top end for the number of astronomical band pass filters
            // in general usage. this is not in a spec anywhere and is derived from various sample
            // FITS files for different astronomical instruments.
            //
            // There's a good chance this is really a spectrum. (0th HDU)
            // We'll create an import descriptor for the spectrum version of this
            // And disable the raster descriptor by default
            pImportDescriptor->setImported(false);
            ImportDescriptorResource pSigDesc(datasetName, TypeConverter::toString<SignatureLibrary>());
            DynamicObject* pSigMetadata = pSigDesc->getDataDescriptor()->getMetadata();
            pSigMetadata->merge(pMetadata.get());
            std::vector<double> centerWavelengths;
            unsigned int cnt = (axes[0] <= 5) ? axes[1] : axes[0];
            double startVal = StringUtilities::fromDisplayString<double>(
               dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/MINWAVE"), "0.0"));
            double endVal = StringUtilities::fromDisplayString<double>(
               dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/MAXWAVE"), "0.0"));
            double incr = (endVal == 0.0) ? 1.0 : ((endVal - startVal) / static_cast<double>(cnt));
            centerWavelengths.reserve(cnt);
            for (unsigned int idx = 0; idx < cnt; idx++)
            {
               centerWavelengths.push_back(startVal + (idx * incr));
            }
            pSigMetadata->setAttributeByPath(CENTER_WAVELENGTHS_METADATA_PATH, centerWavelengths);

            // Units
            std::string unitsName = dv_cast<std::string>(pMetadata->getAttributeByPath("FITS/BUNIT"), std::string());
            if (!unitsName.empty())
            {
               FactoryResource<Units> units;
               units->setUnitName(unitsName);
               units->setUnitType(RADIANCE);
               SignatureDataDescriptor* pSigDd =
                  dynamic_cast<SignatureDataDescriptor*>(pSigDesc->getDataDescriptor());
               if (pSigDd != NULL)
               {
                  pSigDd->setUnits("Reflectance", units.get());
               }
            }

            RasterUtilities::generateAndSetFileDescriptor(pSigDesc->getDataDescriptor(),
               filename, StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER);

            // If units are not available, set custom units into the data descriptor so that the user can
            // modify them - this must occur after the call to RasterUtilities::generateAndSetFileDescriptor()
            // so that the file descriptor will still display no defined units
            if (unitsName.empty())
            {
               FactoryResource<Units> units;
               units->setUnitName("Custom");
               units->setUnitType(CUSTOM_UNIT);
               SignatureDataDescriptor* pSigDd = dynamic_cast<SignatureDataDescriptor*>(pSigDesc->getDataDescriptor());
               if (pSigDd != NULL)
               {
                  pSigDd->setUnits("Reflectance", units.get());
               }
            }

            descriptors.push_back(pSigDesc.release());
         }

         RasterFileDescriptor* pFileDescriptor = dynamic_cast<RasterFileDescriptor*>(
            RasterUtilities::generateAndSetFileDescriptor(pDataDesc, filename,
            StringUtilities::toDisplayString(hdu), BIG_ENDIAN_ORDER));
         if (pFileDescriptor != NULL)
         {
            unsigned int bitsPerElement = RasterUtilities::bytesInEncoding(fileEncoding) * 8;
            pFileDescriptor->setBitsPerElement(bitsPerElement);
         }

         break; // leave switch()
      }
      case ASCII_TBL:
      case BINARY_TBL:
         warnings[hdu].push_back("Tables not supported. [HDU " + StringUtilities::toDisplayString(hdu) + "]");
         continue;
      default:
         warnings[hdu].push_back("HDU " + StringUtilities::toDisplayString(hdu) + " is an unknown type.");
         continue;
      }

      pImportDescriptor->getDataDescriptor()->setMetadata(pMetadata.release());
      pImportDescriptor->setImported(errors[hdu].empty());
      descriptors.push_back(pImportDescriptor.release());
   }
Esempio n. 10
0
std::vector<ImportDescriptor*> VideoImporter::getImportDescriptors(const std::string &filename)
{
   std::vector<ImportDescriptor*> descriptors;
   AVFormatResource pFormatCtx;
   { // scope
      AVFormatContext* pTmp = NULL;
      if (av_open_input_file(&pTmp, filename.c_str(), NULL, 0, NULL) != 0)
      {
         return descriptors;
      }
      pFormatCtx.reset(pTmp);
   }
   if (av_find_stream_info(pFormatCtx) < 0)
   {
      return descriptors;
   }
   for(int streamId = 0; streamId < pFormatCtx->nb_streams; streamId++)
   {
      if(pFormatCtx->streams[streamId]->codec->codec_type == CODEC_TYPE_VIDEO)
      {
         AVCodecContext* pCodecCtx = pFormatCtx->streams[streamId]->codec;
         AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
         VERIFYRV(pCodec != NULL, descriptors);
         if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
         {
            pCodecCtx->flags |= CODEC_FLAG_TRUNCATED;
         }
         if(avcodec_open(pCodecCtx, pCodec) < 0)
         {
            return descriptors;
         }

         ImportDescriptorResource pStreamDescriptor(filename, "VideoStream");
         VERIFYRV(pStreamDescriptor.get() != NULL, descriptors);
         pStreamDescriptor->getDataDescriptor()->setProcessingLocation(ON_DISK_READ_ONLY);
         RasterUtilities::generateAndSetFileDescriptor(pStreamDescriptor->getDataDescriptor(), filename,
            StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN);
         std::string rasterName = filename + QString(":%1").arg(streamId).toStdString();
         ImportDescriptorResource pRasterDescriptor(rasterName,
                                                    TypeConverter::toString<RasterElement>(),
                                                    std::vector<std::string>(1, filename));
         VERIFYRV(pRasterDescriptor.get() != NULL, descriptors);

         RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pRasterDescriptor->getDataDescriptor());

         std::vector<DimensionDescriptor> rowDims = RasterUtilities::generateDimensionVector(pCodecCtx->height);
         pDesc->setRows(rowDims);
         std::vector<DimensionDescriptor> colDims = RasterUtilities::generateDimensionVector(pCodecCtx->width);
         pDesc->setColumns(colDims);
         std::vector<DimensionDescriptor> bandDims = RasterUtilities::generateDimensionVector(3);
         pDesc->setBands(bandDims);
         pDesc->setInterleaveFormat(BIP);
         pDesc->setDataType(INT1UBYTE);
         pDesc->setProcessingLocation(IN_MEMORY);
         pDesc->setDisplayMode(RGB_MODE);
         pDesc->setDisplayBand(RED, pDesc->getActiveBand(0));
         pDesc->setDisplayBand(GREEN, pDesc->getActiveBand(1));
         pDesc->setDisplayBand(BLUE, pDesc->getActiveBand(2));
         RasterUtilities::generateAndSetFileDescriptor(pDesc, filename, StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN);

         descriptors.push_back(pStreamDescriptor.release());
         descriptors.push_back(pRasterDescriptor.release());
      }
   }
   return descriptors;
}
Esempio n. 11
0
CachedPage::UnitPtr Jpeg2000Pager::populateImageData(const DimensionDescriptor& startRow,
                                                     const DimensionDescriptor& startColumn,
                                                     unsigned int concurrentRows, unsigned int concurrentColumns) const
{
   VERIFYRV(startRow.isOnDiskNumberValid() == true, CachedPage::UnitPtr());
   VERIFYRV(startColumn.isOnDiskNumberValid() == true, CachedPage::UnitPtr());
   VERIFYRV(concurrentRows > 0, CachedPage::UnitPtr());
   VERIFYRV(concurrentColumns > 0, CachedPage::UnitPtr());

   // Get the rows, colums, and bands to load
   unsigned int onDiskStartRow = startRow.getOnDiskNumber();
   unsigned int onDiskStopRow = onDiskStartRow + concurrentRows;
   unsigned int onDiskStartColumn = startColumn.getOnDiskNumber();
   unsigned int onDiskStopColumn = onDiskStartColumn + concurrentColumns;

   const RasterElement* pRaster = getRasterElement();
   VERIFYRV(pRaster != NULL, CachedPage::UnitPtr());

   const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor());
   VERIFYRV(pDescriptor != NULL, CachedPage::UnitPtr());

   const RasterFileDescriptor* pFileDescriptor =
      dynamic_cast<const RasterFileDescriptor*>(pDescriptor->getFileDescriptor());
   VERIFYRV(pFileDescriptor != NULL, CachedPage::UnitPtr());

   const std::vector<DimensionDescriptor>& allBands = pFileDescriptor->getBands();
   if (allBands.empty() == true)
   {
      return CachedPage::UnitPtr();
   }

   // Create the output data
   unsigned int numPixels = concurrentRows * concurrentColumns * allBands.size();
   unsigned int numBytes = numPixels * getBytesPerBand();

   if (numPixels > static_cast<unsigned int>(std::numeric_limits<int>::max()))   // ArrayResource only allocates up
                                                                                 // to INT_MAX number of values
   {
      return CachedPage::UnitPtr();
   }

   ArrayResource<Out> pDestination(numPixels, true);
   char* pDest = reinterpret_cast<char*>(pDestination.get());
   if (pDest == NULL)
   {
      return CachedPage::UnitPtr();
   }

   memset(pDest, 0, numPixels);

   // Decode the image from the file, first trying the codestream format then the file format
   opj_image_t* pImage = decodeImage(onDiskStartRow, onDiskStartColumn, onDiskStopRow, onDiskStopColumn,
      Jpeg2000Utilities::J2K_CFMT);
   if (pImage == NULL)
   {
      pImage = decodeImage(onDiskStartRow, onDiskStartColumn, onDiskStopRow, onDiskStopColumn,
         Jpeg2000Utilities::JP2_CFMT);
   }

   if (pImage == NULL)
   {
      return CachedPage::UnitPtr();
   }

   // Populate the output image data
   int bandFactor = 1;

   std::string filename = pRaster->getFilename();
   if (filename.empty() == false)
   {
      QStringList parts = QString::fromStdString(filename).split('.');
      foreach (QString part, parts)
      {
         bool error;
         EncodingType dataType = StringUtilities::fromXmlString<EncodingType>(part.toStdString(), &error);
         if (dataType.isValid() == true && error == false)
         {
            int currentBandFactor = Jpeg2000Utilities::get_num_bands(dataType);
            if (currentBandFactor > 0)
            {
               bandFactor = currentBandFactor;
               break;
            }
         }
      }
Esempio n. 12
0
CachedPage::UnitPtr Jpeg2000Pager::fetchUnit(DataRequest* pOriginalRequest)
{
   if (pOriginalRequest == NULL)
   {
      return CachedPage::UnitPtr();
   }

   // Check for interleave conversions, which are not supported by this pager
   const RasterElement* pRaster = getRasterElement();
   VERIFYRV(pRaster != NULL, CachedPage::UnitPtr());

   const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor());
   VERIFYRV(pDescriptor != NULL, CachedPage::UnitPtr());

   const RasterFileDescriptor* pFileDescriptor =
      dynamic_cast<const RasterFileDescriptor*>(pDescriptor->getFileDescriptor());
   VERIFYRV(pFileDescriptor != NULL, CachedPage::UnitPtr());

   if (pFileDescriptor->getBandCount() > 1)
   {
      InterleaveFormatType requestedInterleave = pOriginalRequest->getInterleaveFormat();
      InterleaveFormatType fileInterleave = pFileDescriptor->getInterleaveFormat();
      if (requestedInterleave != fileInterleave)
      {
         return CachedPage::UnitPtr();
      }

      VERIFYRV(requestedInterleave == BIP, CachedPage::UnitPtr());   // The JPEG2000 data is stored BIP
   }

   // Get and validate the extents of the data to be loaded
   DimensionDescriptor startRow = pOriginalRequest->getStartRow();
   DimensionDescriptor stopRow = pOriginalRequest->getStopRow();
   unsigned int concurrentRows = pOriginalRequest->getConcurrentRows();

   DimensionDescriptor startColumn = pOriginalRequest->getStartColumn();
   DimensionDescriptor stopColumn = pOriginalRequest->getStopColumn();
   unsigned int concurrentColumns = pOriginalRequest->getConcurrentColumns();

   DimensionDescriptor startBand = pOriginalRequest->getStartBand();
   DimensionDescriptor stopBand = pOriginalRequest->getStopBand();

   if ((startRow.isOnDiskNumberValid() == false) || (stopRow.isOnDiskNumberValid() == false) ||
      (startColumn.isOnDiskNumberValid() == false) || (stopColumn.isOnDiskNumberValid() == false) ||
      (startBand.isOnDiskNumberValid() == false) || (stopBand.isOnDiskNumberValid() == false))
   {
      return CachedPage::UnitPtr();
   }

   if ((startRow.getOnDiskNumber() > stopRow.getOnDiskNumber()) ||
      (startColumn.getOnDiskNumber() > stopColumn.getOnDiskNumber()) ||
      (startBand.getOnDiskNumber() > stopBand.getOnDiskNumber()))
   {
      return CachedPage::UnitPtr();
   }

   if ((startRow.getActiveNumber() + concurrentRows - 1) > stopRow.getActiveNumber())
   {
      concurrentRows = stopRow.getActiveNumber() - startRow.getActiveNumber() + 1;
   }

   if ((startColumn.getActiveNumber() + concurrentColumns - 1) > stopColumn.getActiveNumber())
   {
      concurrentColumns = stopColumn.getActiveNumber() - startColumn.getActiveNumber() + 1;
   }

   // Populate the image data based on the output data type
   EncodingType outputDataType = pDescriptor->getDataType();
   switch (outputDataType)
   {
   case INT1UBYTE:
      return populateImageData<unsigned char>(startRow, startColumn, concurrentRows, concurrentColumns);

   case INT1SBYTE:
      return populateImageData<signed char>(startRow, startColumn, concurrentRows, concurrentColumns);

   case INT2UBYTES:
      return populateImageData<unsigned short>(startRow, startColumn, concurrentRows, concurrentColumns);

   case INT2SBYTES:
      return populateImageData<signed short>(startRow, startColumn, concurrentRows, concurrentColumns);

   case INT4UBYTES:
      return populateImageData<unsigned int>(startRow, startColumn, concurrentRows, concurrentColumns);

   case INT4SBYTES:
      return populateImageData<signed int>(startRow, startColumn, concurrentRows, concurrentColumns);

   case FLT4BYTES:
      return populateImageData<float>(startRow, startColumn, concurrentRows, concurrentColumns);

   case FLT8BYTES:
      return populateImageData<double>(startRow, startColumn, concurrentRows, concurrentColumns);

   default:
      break;
   }

   return CachedPage::UnitPtr();
}
Esempio n. 13
0
RasterPage* ConvertToBsqPager::getPage(DataRequest* pOriginalRequest, DimensionDescriptor startRow,
   DimensionDescriptor startColumn, DimensionDescriptor startBand)
{
   VERIFYRV(pOriginalRequest != NULL, NULL);
   if (pOriginalRequest->getWritable())
   {
      return NULL;
   }

   InterleaveFormatType requestedType = pOriginalRequest->getInterleaveFormat();
   DimensionDescriptor stopRow = pOriginalRequest->getStopRow();
   DimensionDescriptor stopColumn = pOriginalRequest->getStopColumn();
   DimensionDescriptor stopBand = pOriginalRequest->getStopBand();

   unsigned int concurrentRows = std::min(pOriginalRequest->getConcurrentRows(),
      stopRow.getActiveNumber() - startRow.getActiveNumber() + 1);
   unsigned int concurrentBands = pOriginalRequest->getConcurrentBands();

   VERIFY(requestedType == BSQ);
   VERIFY(startBand == stopBand && concurrentBands == 1);

   VERIFY(mpRaster != NULL);
   const RasterDataDescriptor* pDd = dynamic_cast<const RasterDataDescriptor*>(mpRaster->getDataDescriptor());
   VERIFY(pDd != NULL);
   InterleaveFormatType interleave = pDd->getInterleaveFormat();

   VERIFY(interleave == BIL || interleave == BIP);

   unsigned int numRows = pDd->getRowCount();
   unsigned int numCols = pDd->getColumnCount();
   unsigned int numBands = pDd->getBandCount();

   if (startRow.getActiveNumber() >= numRows || stopRow.getActiveNumber() >= numRows ||
      startColumn.getActiveNumber() >= numCols || stopColumn.getActiveNumber() >= numCols ||
      startBand.getActiveNumber() >= numBands || stopBand.getActiveNumber() >= numBands)
   {
      return NULL;
   }

   unsigned int cols = stopColumn.getActiveNumber() - startColumn.getActiveNumber() + 1;
   std::auto_ptr<ConvertToBsqPage> pPage(new ConvertToBsqPage(concurrentRows, cols, mBytesPerElement));
   unsigned char* pDst = reinterpret_cast<unsigned char*>(pPage->getRawData());
   if (pDst == NULL)
   {
      return NULL;
   }

   FactoryResource<DataRequest> pRequest;
   pRequest->setRows(startRow, stopRow);
   pRequest->setColumns(startColumn, stopColumn, cols);
   pRequest->setBands(startBand, startBand, 1);
   DataAccessor da = mpRaster->getDataAccessor(pRequest.release());

   if (interleave == BIP)
   {
      for (unsigned int row = 0; row < concurrentRows; ++row)
      {
         for (unsigned int col = 0; col < cols; ++col)
         {
            if (da.isValid() == false)
            {
               return NULL;
            }

            memcpy(pDst, da->getColumn(), mBytesPerElement);
            pDst += mBytesPerElement;
            da->nextColumn();
         }

         da->nextRow();
      }
   }
   else if (interleave == BIL)
   {
      for (unsigned int row = 0; row < concurrentRows; ++row)
      {
         if (da.isValid() == false)
         {
            return NULL;
         }

         memcpy(pDst, da->getRow(), mBytesPerElement * cols);
         pDst += mBytesPerElement * cols;
         da->nextRow();
      }
   }

   return pPage.release();
}
bool RangeProfilePlotManager::plotProfile(Signature* pSignature)
{
   VERIFY(mpView && pSignature);
   std::string plotName = pSignature->getDisplayName();
   if (plotName.empty())
   {
      plotName = pSignature->getName();
   }
   if (plotName == "Difference")
   {
      QMessageBox::warning(Service<DesktopServices>()->getMainWidget(),
         "Invalid signature", "Signatures can not be named 'Difference' as this is a reserved "
                              "name for this plot. Please rename your signature and try again.");
      return false;
   }
   const Units* pXUnits = NULL;
   const Units* pYUnits = NULL;
   std::vector<double> xData;
   std::vector<double> yData;
   std::set<std::string> dataNames = pSignature->getDataNames();
   for (std::set<std::string>::const_iterator dataName = dataNames.begin();
      dataName != dataNames.end() && (pXUnits == NULL || pYUnits == NULL);
      ++dataName)
   {
      const Units* pUnits = pSignature->getUnits(*dataName);
      if (pUnits == NULL)
      {
         continue;
      }
      if (pUnits->getUnitType() == DISTANCE)
      {
         if (pXUnits == NULL)
         {
            pXUnits = pUnits;
            xData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>());
         }
      }
      else if (pYUnits == NULL)
      {
         pYUnits = pUnits;
         yData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>());
      }
   }
   if (xData.empty() || xData.size() != yData.size())
   {
      QMessageBox::warning(Service<DesktopServices>()->getMainWidget(),
         "Invalid signature", QString("Signatures must have a distance axis. '%1' does not and will not be plotted.")
                                 .arg(QString::fromStdString(pSignature->getName())));
      return false;
   }
   std::map<Signature*, std::string>::iterator oldPointSet = mSigPointSets.find(pSignature);
   PointSet* pSet = getPointSet(pSignature);
   if (pSet != NULL)
   {
      pSet->clear(true);
   }
   std::list<PlotObject*> curObjects;
   mpView->getObjects(POINT_SET, curObjects);
   if (pSet == NULL)
   {
      std::vector<ColorType> excluded;
      excluded.push_back(ColorType(255, 255, 255)); // background
      excluded.push_back(ColorType(200, 0, 0)); // color for the difference plot
      for (std::list<PlotObject*>::const_iterator cur = curObjects.begin(); cur != curObjects.end(); ++cur)
      {
         excluded.push_back(static_cast<PointSet*>(*cur)->getLineColor());
      }
      pSet = static_cast<PointSet*>(mpView->addObject(POINT_SET, true));
      mSigPointSets[pSignature] = plotName;
      pSignature->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &RangeProfilePlotManager::signatureDeleted));
      pSignature->getDataDescriptor()->attach(SIGNAL_NAME(DataDescriptor, Renamed),
         Slot(this, &RangeProfilePlotManager::signatureRenamed));
      std::vector<ColorType> colors;
      ColorType::getUniqueColors(1, colors, excluded);
      if (!colors.empty())
      {
         pSet->setLineColor(colors.front());
      }
   }
   pSet->setObjectName(plotName);
   for (size_t idx = 0; idx < xData.size(); ++idx)
   {
      pSet->addPoint(xData[idx], yData[idx]);
   }

   VERIFY(mpPlot);
   Axis* pBottom = mpPlot->getAxis(AXIS_BOTTOM);
   Axis* pLeft = mpPlot->getAxis(AXIS_LEFT);
   VERIFYRV(pBottom && pLeft, NULL);
   if (pBottom->getTitle().empty())
   {
      pBottom->setTitle(pXUnits->getUnitName());
   }
   if (pLeft->getTitle().empty())
   {
      pLeft->setTitle(pYUnits->getUnitName());
   }
   else if (pLeft->getTitle() != pYUnits->getUnitName())
   {
      Axis* pRight = mpPlot->getAxis(AXIS_RIGHT);
      VERIFYRV(pRight, NULL);
      if (pRight->getTitle().empty())
      {
         pRight->setTitle(pYUnits->getUnitName());
      }
   }

   std::string classificationText = dv_cast<std::string>(pSignature->getMetadata()->getAttribute("Raw Classification"),
      mpPlot->getClassificationText());
   if (classificationText.empty() == false)
   {
      FactoryResource<Classification> pClassification;
      if (pClassification->setClassification(classificationText) == true)
      {
         mpPlot->setClassification(pClassification.get());
      }
      else
      {
         QMessageBox::warning(Service<DesktopServices>()->getMainWidget(), QString::fromStdString(getName()),
            "The plot could not be updated with the signature classification.  Please ensure that the plot "
            "has the proper classification.");
      }
   }

   getDockWindow()->show();
   mpView->zoomExtents();
   mpView->refresh();

   return true;
}
Esempio n. 15
0
std::vector<ImportDescriptor*> DicomImporter::getImportDescriptors(const std::string &filename)
{
   mErrors.clear();
   mWarnings.clear();
   std::vector<ImportDescriptor*> descriptors;

   DcmFileFormat fileformat;
   OFCondition status;
   if((status = fileformat.loadFile(filename.c_str())).bad())
   {
      return descriptors;
   }

   ImportDescriptorResource pImportDescriptor(filename, TypeConverter::toString<RasterElement>());
   VERIFYRV(pImportDescriptor.get() != NULL, descriptors);
   descriptors.push_back(pImportDescriptor.release());

   DicomImage img(fileformat.getDataset(), fileformat.getDataset()->getOriginalXfer());
   if(img.getStatus() != EIS_Normal)
   {
      mErrors.push_back(std::string("Unable to decode image: ") + DicomImage::getString(img.getStatus()));
      pImportDescriptor->setDataDescriptor(RasterUtilities::generateRasterDataDescriptor(filename, NULL, 0, 0, INT1UBYTE, IN_MEMORY));
      return descriptors;
   }
   InterleaveFormatType interleave(BSQ);
   EncodingType encoding(INT4UBYTES);
   bool rgb = false;
   unsigned long rows = img.getHeight(), columns = img.getWidth(), frames = img.getFrameCount();
   int imgDepth = img.getDepth();
   switch(img.getPhotometricInterpretation())
   {
   case EPI_Monochrome1:
   case EPI_Monochrome2:
      // do nothing special....this is single or multi-frame grayscale, 1 or 2 byte
      break;
   case EPI_RGB:
   case EPI_PaletteColor:
      // supported if there's only 1 frame
      if(frames == 1)
      {
         frames = 3;
         rgb = true;
      }
      else
      {
         mWarnings.push_back("RGB and palette color not supported when multiple frames are present. Converting to grayscale.");
      }
      break;
   default:
      mWarnings.push_back(std::string(DicomImage::getString(img.getPhotometricInterpretation())) +
         " not supported. Attempting to convert to grayscale.");
   }

   if(imgDepth <= 8)
   {
      encoding = INT1UBYTE;
   }
   else if(imgDepth <= 16)
   {
      encoding = INT2UBYTES;
   }
   else if(imgDepth <= 32)
   {
      encoding = INT4UBYTES;
   }
   else
   {
      mWarnings.push_back("Bit depth " + StringUtilities::toDisplayString(imgDepth) + " not supported. Downgrading to 32 bits.");
      encoding = INT4UBYTES;
   }

   RasterDataDescriptor *pDescriptor = RasterUtilities::generateRasterDataDescriptor(
      filename, NULL, rows, columns, frames, interleave, encoding, IN_MEMORY);
   if(pDescriptor != NULL)
   {
      if(rgb)
      {
         pDescriptor->setDisplayBand(RED, pDescriptor->getBands()[0]);
         pDescriptor->setDisplayBand(GREEN, pDescriptor->getBands()[1]);
         pDescriptor->setDisplayBand(BLUE, pDescriptor->getBands()[2]);
         pDescriptor->setDisplayMode(RGB_MODE);
      }
      pImportDescriptor->setDataDescriptor(pDescriptor);
      FactoryResource<DynamicObject> pMeta;
      int idx = 0;
      DcmElement *pElmnt;
      while((pElmnt = fileformat.getDataset()->getElement(idx++)) != NULL)
      {
         if(pElmnt->error().bad())
         {
            continue;
         }
         const DcmTag &tag = pElmnt->getTag();
         std::string name = const_cast<DcmTag&>(tag).getTagName();
         if(name.empty())
         {
            name = QString("(%1,%2)").arg(pElmnt->getGTag(), 4, 16, QChar('0')).arg(pElmnt->getETag(), 4, 16, QChar('0')).toStdString();
         }
         pMeta->setAttributeByPath(std::string("DICOM/") + name, dcmElementToDataVariant(*pElmnt));
      }
      pImportDescriptor->getDataDescriptor()->setMetadata(pMeta.release());
   }
   RasterUtilities::generateAndSetFileDescriptor(pImportDescriptor->getDataDescriptor(), filename, std::string(), LITTLE_ENDIAN_ORDER);

   return descriptors;
}
Esempio n. 16
0
std::vector<ImportDescriptor*> DiHdfImporter::getImportDescriptors(const std::string &filename)
{
   mErrors.clear();
   mWarnings.clear();
   std::vector<ImportDescriptor*> descriptors;

   ImportDescriptorResource pImportDescriptor(filename, TypeConverter::toString<RasterElement>());
   VERIFYRV(pImportDescriptor.get(), descriptors);
   descriptors.push_back(pImportDescriptor.release());

   HdfContext hdf(filename);
   if (hdf.grid() == FAIL)
   {
      mErrors.push_back("Invalid DI HDF file.");
      return descriptors;
   }

   int32 frames = 0;
   int32 attrs = 0;
   GRfileinfo(hdf.grid(), &frames, &attrs);
   if (frames <= 0)
   {
      mErrors.push_back("Dataset does not contain and frames.");
      return descriptors;
   }
   if (hdf.toFrame(0) == FAIL)
   {
      mErrors.push_back("Unable to access image data.");
      return descriptors;
   }
   char pName[256];
   int32 comps = 0;
   int32 data_type = 0;
   int32 interlace_mode = 0;
   int32 pDims[2] = {0,0};
   EncodingType encoding;
   GRgetiminfo(hdf.riid(), pName, &comps, &data_type, &interlace_mode, pDims, &attrs);
   switch(data_type)
   {
   case DFNT_FLOAT32:
      encoding = FLT4BYTES;
      break;
   case DFNT_FLOAT64:
      encoding = FLT8BYTES;
      break;
   case DFNT_CHAR8:
   case DFNT_INT8:
      encoding = INT1SBYTE;
      break;
   case DFNT_UCHAR8:
   case DFNT_UINT8:
      encoding = INT1UBYTE;
      break;
   case DFNT_INT16:
      encoding = INT2SBYTES;
      break;
   case DFNT_UINT16:
      encoding = INT2UBYTES;
      break;
   case DFNT_INT32:
      encoding = INT4SBYTES;
      break;
   case DFNT_UINT32:
      encoding = INT4UBYTES;
      break;
   case DFNT_INT64:
   case DFNT_UINT64:
   default:
      mErrors.push_back("Unknown data encoding.");
      break;
   }
   pImportDescriptor->setDataDescriptor(RasterUtilities::generateRasterDataDescriptor(
            filename, NULL, pDims[1], pDims[0], frames, BSQ, encoding, IN_MEMORY));
   RasterUtilities::generateAndSetFileDescriptor(pImportDescriptor->getDataDescriptor(), filename,
      std::string(), LITTLE_ENDIAN_ORDER);

   return descriptors;
}
Esempio n. 17
0
std::vector<ImportDescriptor*> NefImporter::getImportDescriptors(const std::string &filename)
{
   std::vector<ImportDescriptor*> descriptors;

   try
   {
     	
	   
	   
	   ImportDescriptorResource pImportDescriptor(filename, TypeConverter::toString<RasterElement>());
	   VERIFYRV(pImportDescriptor.get() != NULL, descriptors);
	   descriptors.push_back(pImportDescriptor.release());
	   
	   InterleaveFormatType interleave(BSQ);
	   EncodingType encoding(INT4UBYTES);
	   
	   //bool rgb = false;
	   
	   LibRaw iProcessor;
	   const char *fn=filename.c_str();
	   iProcessor.open_file(fn);

	   unsigned long rows = iProcessor.imgdata.sizes.iheight, columns = iProcessor.imgdata.sizes.iwidth,frames=3;
	   
	   RasterDataDescriptor *pDescriptor = RasterUtilities::generateRasterDataDescriptor(
      filename, NULL, rows, columns, frames, interleave, encoding, IN_MEMORY);

	  if(pDescriptor != NULL)
      {
      
         pDescriptor->setDisplayBand(RED, pDescriptor->getBands()[0]);
         pDescriptor->setDisplayBand(GREEN, pDescriptor->getBands()[1]);
         pDescriptor->setDisplayBand(BLUE, pDescriptor->getBands()[2]);
         pDescriptor->setDisplayMode(RGB_MODE);
      }

	  
	  pImportDescriptor->setDataDescriptor(pDescriptor);
	  RasterUtilities::generateAndSetFileDescriptor(pImportDescriptor->getDataDescriptor(), filename, std::string(), LITTLE_ENDIAN_ORDER);
	  descriptors.push_back(pImportDescriptor.release());
	  //return descriptors;

	   
	   /*   
	   Endian e;
      DynamicObject* pMeta = NULL;
      { // scope the geotiff importer
         ImporterResource geotiff("GeoTIFF Importer", filename);
         if (geotiff.get() == NULL)
         {
            return descriptors;
         }
         std::vector<ImportDescriptor*> tiffDescriptors = geotiff->getImportDescriptors();
         if (tiffDescriptors.size() != 1)
         {
            return descriptors;
         }
         e = Endian(tiffDescriptors.front()->getDataDescriptor()->getFileDescriptor()->getEndian());
         pMeta = tiffDescriptors.front()->getDataDescriptor()->getMetadata();
      }
      if (dv_cast<std::string>(pMeta->getAttributeByPath("TIFF/Make")) != "NIKON CORPORATION")
      {
         return descriptors;
      }
	  

      // Reload the file and parse the RAW IFD
      FileResource pNef(filename.c_str(), "rb");
      if (pNef.get() == NULL)
      {
         return descriptors;
      }
      // JpegImageOffset, RawOffset
      std::vector<unsigned int> ifds = dv_cast<std::vector<unsigned int> >(pMeta->getAttributeByPath("TIFF/SubIFD"));
      if (ifds.size() != 2)
      {
         return descriptors;
      }
      fseek(pNef, ifds[1], SEEK_SET);
      
      unsigned int rows = 0;
      unsigned int cols = 0;
      unsigned int bpp = 0;
      // parse the entries
      size_t entryCount = getVal<uint16_t>(pNef, e);
      while (--entryCount >= 0)
      {
         uint16_t tag = getVal<uint16_t>(pNef, e);
         uint16_t type = getVal<uint16_t>(pNef, e);
         uint16_t count = getVal<uint32_t>(pNef, e);
         bool compressed = false;
         switch(tag)
         {
         case 254: // SubfileType == 0 (full resolution)
            if (type != 4 && count != 1 && getVal<uint32_t>(pNef, e) != 0)
            {
               return descriptors;
            }
            break;
         case 256: // ImageWidth
            if (type != 4 && count != 1)
            {
               return descriptors;
            }
            cols = getVal<uint32_t>(pNef, e);
            break;
         case 257: // ImageHight
            if (type != 4 && count != 1)
            {
               return descriptors;
            }
            rows = getVal<uint32_t>(pNef, e);
            break;
         case 258: // BitsPerSample
            if (type != 1 && count != 1)
            {
               return descriptors;
            }
            bpp = getVal<unsigned char>(pNef, e);
            fseek(pNef, 3, SEEK_CUR);
            break;
         case 259: // Compression
            if (type != 3 && count != 1)
            {
               return descriptors;
            }
            {
               uint16_t comp = getVal<uint16_t>(pNef, e);
               fseek(pNef, 2, SEEK_CUR);
               if (comp == 1)
               {
                  compressed = false;
               }
               else if (comp == 34713)
               {
                  compressed = true;
               }
               else
               {
                  return descriptors;
               }
            }
            break;
         default:
            fseek(pNef, 4, SEEK_CUR);
            break;
         }
      }

	  */
   }
   catch (const std::bad_cast&)
   {
      // metadata not present, wrong kind of file
   }
   return descriptors;
}