예제 #1
0
DataObjectPtr CSD::makeDuplicate() const{

  CSDPtr csd = store()->createObject<CSD>();
  csd->change(_inputVectors[CSD_INVECTOR],
              _frequency,
              _average,
              _removeMean,
              _apodize,
              _apodizeFxn,
              _windowSize,
              _averageLength,
              _gaussianSigma,
              _outputType,
              _vectorUnits,
              _rateUnits);
  if (descriptiveNameIsManual()) {
    csd->setDescriptiveName(descriptiveName());
  }
  csd->writeLock();
  csd->registerChange();
  csd->unlock();

  return DataObjectPtr(csd);
}
DataObjectPtr CSDFactory::generateObject(ObjectStore *store, QXmlStreamReader& xml) {
  Q_ASSERT(store);

  double frequency=1.0, gaussianSigma=1.0;
  int length=8, windowSize=8, apodizeFunction=0, outputType=0;
  QString vectorName, vectorUnits, rateUnits, descriptiveName;
  bool average=false, removeMean=false, apodize=false;

  while (!xml.atEnd()) {
      const QString n = xml.name().toString();
    if (xml.isStartElement()) {
      if (n == CSD::staticTypeTag) {
        QXmlStreamAttributes attrs = xml.attributes();
        vectorName = attrs.value("vector").toString();
        vectorUnits = attrs.value("vectorunits").toString();
        rateUnits = attrs.value("rateunits").toString();

        frequency = attrs.value("samplerate").toString().toDouble();
        gaussianSigma = attrs.value("gaussiansigma").toString().toDouble();

        length = attrs.value("fftlength").toString().toInt();
        windowSize = attrs.value("windowsize").toString().toInt();
        apodizeFunction = attrs.value("apodizefunction").toString().toInt();
        outputType = attrs.value("outputtype").toString().toInt();

        average = attrs.value("average").toString() == "true" ? true : false;
        removeMean = attrs.value("removemean").toString() == "true" ? true : false;
        apodize = attrs.value("apodize").toString() == "true" ? true : false;
        if (attrs.value("descriptiveNameIsManual").toString() == "true") {
          descriptiveName = attrs.value("descriptiveName").toString();
        }
        Object::processShortNameIndexAttributes(attrs);
      } else {
        return 0;
      }
    } else if (xml.isEndElement()) {
      if (n == CSD::staticTypeTag) {
        break;
      } else {
        Debug::self()->log(QObject::tr("Error creating CSD from Kst file."), Debug::Warning);
        return 0;
      }
    }
    xml.readNext();
  }

  if (xml.hasError()) {
    return 0;
  }

  VectorPtr vector = 0;
  if (store && !vectorName.isEmpty()) {
    vector = kst_cast<Vector>(store->retrieveObject(vectorName));
  }

  if (!vector) {
    Debug::self()->log(QObject::tr("Error creating CSD from Kst file.  Could not find Vector."), Debug::Warning);
    return 0;
  }

  CSDPtr csd = store->createObject<CSD>();
  csd->change(vector,
              frequency,
              average,
              removeMean,
              apodize,
              (ApodizeFunction)apodizeFunction,
              windowSize,
              length,
              gaussianSigma,
              (PSDType)outputType,
              vectorUnits,
              rateUnits);

  csd->setDescriptiveName(descriptiveName);
  csd->writeLock();
  csd->registerChange();
  csd->unlock();

  return csd;
}
예제 #3
0
ObjectPtr CSDDialog::createNewDataObject() const {
  Q_ASSERT(_document && _document->objectStore());
  ObjectTag tag = _document->objectStore()->suggestObjectTag<CSD>(tagString(), ObjectTag::globalTagContext);
  CSDPtr csd = _document->objectStore()->createObject<CSD>(tag);
  csd->setVector(_CSDTab->vector());
  csd->setFreq(_CSDTab->FFTOptionsWidget()->sampleRate());
  csd->setAverage(_CSDTab->FFTOptionsWidget()->interleavedAverage());
  csd->setRemoveMean(_CSDTab->FFTOptionsWidget()->removeMean());
  csd->setApodize(_CSDTab->FFTOptionsWidget()->apodize());
  csd->setApodizeFxn(_CSDTab->FFTOptionsWidget()->apodizeFunction());
  csd->setWindowSize(_CSDTab->windowSize());
  csd->setLength(_CSDTab->FFTOptionsWidget()->FFTLength());
  csd->setGaussianSigma(_CSDTab->FFTOptionsWidget()->sigma());
  csd->setOutput(_CSDTab->FFTOptionsWidget()->output());
  csd->setVectorUnits(_CSDTab->FFTOptionsWidget()->vectorUnits());
  csd->setRateUnits(_CSDTab->FFTOptionsWidget()->rateUnits());

  csd->writeLock();
  csd->update(0);
  csd->unlock();

  Palette* newPalette = new Palette(_CSDTab->colorPalette()->selectedPalette());

  tag = _document->objectStore()->suggestObjectTag<Image>(csd->tag().tagString(), ObjectTag::globalTagContext);
  ImagePtr image = _document->objectStore()->createObject<Image>(tag);
  image->changeToColorOnly(csd->outputMatrix(), 0, 1, true, newPalette->paletteData());

  image->writeLock();
  image->update(0);
  image->unlock();

  PlotItem *plotItem = 0;
  switch (_CSDTab->curvePlacement()->place()) {
  case CurvePlacement::NoPlot:
    break;
  case CurvePlacement::ExistingPlot:
    {
      plotItem = static_cast<PlotItem*>(_CSDTab->curvePlacement()->existingPlot());
      break;
    }
  case CurvePlacement::NewPlot:
    {
      CreatePlotForCurve *cmd = new CreatePlotForCurve(
        _CSDTab->curvePlacement()->createLayout(),
        _CSDTab->curvePlacement()->appendToLayout());
      cmd->createItem();

      plotItem = static_cast<PlotItem*>(cmd->item());
      break;
    }
  default:
    break;
  }

  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
  //TODO  Adam, is this the correct way to draw an image?  It runs very slow.
  renderItem->addRelation(kst_cast<Relation>(image));
  plotItem->update();

  return ObjectPtr(image.data());
}