Esempio n. 1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void TestErrorMessage()
{
  PipelineMessage e0;

  QString a0("Some Class Name");
  QString a1("Description");
  int eCode = -10;
  PipelineMessage e1;


  PipelineMessage e2(a0, a1, eCode);

  AbstractFilter::Pointer f = AbstractFilter::New();
  f->notifyErrorMessage("Some Test", a1, eCode);
  f->notifyErrorMessage("Another Test", "A description", -10);

  PipelineMessage pm("Joey's Test", "Testing Warning Message...", -23, PipelineMessage::Warning);
  PipelineMessage pm1("Joey's Test", "Testing Error Message...", -23, PipelineMessage::Error);
  PipelineMessage pm2("Joey's Test", "Testing Status Message...", -23, PipelineMessage::StatusMessage);
  PipelineMessage pm3("Joey's Test", "Testing Status Message...", -23, PipelineMessage::ProgressValue, 23);
  f->broadcastPipelineMessage(pm);
  f->broadcastPipelineMessage(pm1);
  f->broadcastPipelineMessage(pm2);

  if (true)
  { return; }

}
Esempio n. 2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void readPipeline(QFilterParametersReader::Pointer paramsReader, FilterPipeline::Pointer pipeline)
{
  FilterManager* filtManager = FilterManager::Instance();
  QSettings* prefs = paramsReader->getPrefs();
  prefs->beginGroup(DREAM3D::Settings::PipelineBuilderGroup);
  bool ok = false;
  int filterCount = prefs->value("Number_Filters").toInt(&ok);
  prefs->endGroup();
  if (false == ok) {filterCount = 0;}

  for (int i = 0; i < filterCount; ++i)
  {
    QString gName = QString::number(i);

    // Open the group to get the name of the filter then close again.
    prefs->beginGroup(gName);
    QString filterName = prefs->value("Filter_Name", "").toString();
    prefs->endGroup();
    //  qDebug() << filterName;

    IFilterFactory::Pointer factory = filtManager->getFactoryForFilter(filterName);
    AbstractFilter::Pointer filter = factory->create();

    if(NULL != filter.get())
    {
      filter->readFilterParameters(paramsReader.get(), i);
      pipeline->pushBack(filter);
    }
  }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void LoopOnFilters()
{
  FilterManager::Pointer fm = FilterManager::Instance();
  FilterManager::Collection factories = fm->getFactories();

  FilterManager::CollectionIterator i(factories);
  int count = 0;
  while (i.hasNext())
  {
    i.next();
    std::cout << ++count << ": " << i.key().toStdString() << ": " << std::endl;

    //std::cout << "  public:" << std::endl;
    IFilterFactory::Pointer factory = i.value();
    AbstractFilter::Pointer filter = factory->create();
    //if (filter->getGroupName().compare(DREAM3D::FilterGroups::StatisticsFilters) == 0)
    // if(filter->getNameOfClass().compare("FindSchmids") == 0)
    {
      //   std::cout << "" << filter->getGroupName().toStdString() << "Filters/" << filter->getNameOfClass().toStdString() << ".cpp" << std::endl;
      QString cpp = findPath(filter->getGroupName(), filter->getNameOfClass(), ".cpp");
      std::cout << filter << " " << cpp.toStdString() << std::endl;
    }

  }

}
Esempio n. 4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool CorrectInitializerList( AbstractFilter::Pointer filter, const QString& hFile, const QString& cppFile)
{
  QString contents;
  {
    // Read the Source File
    QFileInfo fi(cppFile);
    //
    if (fi.baseName().compare("RegisterPointSets") != 0)
    {
      return false;
    }
    QFile source(cppFile);
    source.open(QFile::ReadOnly);
    contents = source.readAll();
    source.close();
  }


  QStringList names;
  bool didReplace = false;

  QString searchString = filter->getNameOfClass() + "::" + filter->getNameOfClass();
  QStringList outLines;
  QStringList list = contents.split(QRegExp("\\n"));
  QStringListIterator sourceLines(list);

  int index = 0;
  while (sourceLines.hasNext())
  {
    QString line = sourceLines.next();
    if(line.contains(searchString) )
    {
      outLines.push_back(line);
      line = sourceLines.next();
      outLines.push_back(line); // get the call to the superclass

      fixInitializerList(sourceLines, outLines, hFile, cppFile);
      didReplace = true;
    }
    else
    {
      outLines.push_back(line);
    }
  }


  writeOutput(didReplace, outLines, cppFile);
  index++;

  return didReplace;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int DataContainerReader::readExistingPipelineFromFile(hid_t fileId)
{
  herr_t err = 0;
  m_PipelineFromFile->clear();

  H5FilterParametersReader::Pointer reader = H5FilterParametersReader::New();

  // HDF5: Open the "Pipeline" Group
  hid_t pipelineGroupId = H5Gopen(fileId, DREAM3D::StringConstants::PipelineGroupName.toLatin1().data(), H5P_DEFAULT);
  reader->setPipelineGroupId(pipelineGroupId);

  // Use QH5Lite to ask how many "groups" are in the "Pipeline Group"
  QList<QString> groupList;
  err = QH5Utilities::getGroupObjects(pipelineGroupId, H5Utilities::H5Support_GROUP, groupList);

  // Loop over the items getting the "ClassName" attribute from each group
  QString classNameStr = "";
  for (int32_t i = 0; i < groupList.size(); i++)
  {
    QString ss = QString::number(i, 10);

    err = QH5Lite::readStringAttribute(pipelineGroupId, ss, "ClassName", classNameStr);
    if (err < 0)
    {
      qDebug() << "Filter Index = " << i;
    }
    // Instantiate a new filter using the FilterFactory based on the value of the className attribute
    FilterManager* fm = FilterManager::Instance();
    IFilterFactory::Pointer ff = fm->getFactoryForFilter(classNameStr);
    if (NULL != ff.get())
    {
      AbstractFilter::Pointer filter = ff->create();
      if (NULL != filter.get())
      {
        // Read the parameters
        filter->readFilterParameters( reader.get(), i);

        // Add filter to m_PipelineFromFile
        m_PipelineFromFile->pushBack(filter);
      }
    }
  }
  err = H5Gclose(pipelineGroupId);
  return err;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int QFilterParametersWriter::WritePipelineToFile(FilterPipeline::Pointer pipeline, const QString& filePath, const QString& name, QSettings::Format format, IObserver* obs)
{

  if(NULL == pipeline.get())
  {
    if(NULL != obs)
    {
      PipelineMessage pm(QFilterParametersWriter::ClassName(), "FilterPipeline Object was NULL for writing", -1, PipelineMessage::Error);
      obs->processPipelineMessage(pm);
    }
    return -1;
  }

  FilterPipeline::FilterContainerType& filters = pipeline->getFilterContainer();

  QFilterParametersWriter::Pointer writer = QFilterParametersWriter::New();
  // This will open the file, and write/update the initial group of settings like the name and DREAM3D Version
  writer->openFile(filePath, format);
  // Loop over each filter and write it's input parameters to the file
  int count = filters.size();
  int index = 0;
  for(qint32 i = 0; i < count; ++i)
  {
    AbstractFilter::Pointer filter = filters.at(i);
    if(NULL != filter.get())
    {
      index = filter->writeFilterParameters(writer.get(), index);
    }
    else
    {
      AbstractFilter::Pointer badFilter = AbstractFilter::New();
      writer->openFilterGroup(badFilter.get(), i);
      writer->writeValue("Unkown Filter", "ERROR: Filter instance was NULL within the PipelineFilterWidget instance. Report this error to the DREAM3D Developers");
      writer->closeFilterGroup();
    }
  }

  writer->setNumberOfFilters(index);
  writer->setPipelineName(name);
  writer->closeFile(); // Close the file
  return 0;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void GenerateFilterParametersCode()
{

  FilterManager::Pointer fm = FilterManager::Instance();
  FilterManager::Collection factories = fm->getFactories();
  QMapIterator<QString, IFilterFactory::Pointer> iter(factories);
  // Loop on each filter
  while(iter.hasNext())
  {
    iter.next();
    IFilterFactory::Pointer factory = iter.value();
    AbstractFilter::Pointer filter = factory->create();

    QString cpp = findPath(filter->getGroupName(), filter->getNameOfClass(), ".cpp");
    QString h = findPath(filter->getGroupName(), filter->getNameOfClass(), ".h");

    fixFile(filter, h, cpp);
  }

}
Esempio n. 8
0
/**
 *
 * @param FileName
 * @param data
 * @param nx X Dimension
 * @param ny Y Dimension
 * @param nz Z Dimension
 */
int  ReadPHFile(QString FileName, QVector<int>& data, int& nx, int& ny, int& nz)
{
  DataContainerArray::Pointer dca = DataContainerArray::New();
  DataContainer::Pointer m = DataContainer::New(); /* FIXME: What Geometry do we need? */
  dca->pushBack(m);

  FilterManager::Pointer fm = FilterManager::Instance();
  AbstractFilter::Pointer reader = fm->getFactoryForFilter("PhReader")->create();
  reader->setDataContainerArray(dca);
  bool propWasSet = reader->setProperty("InputFile", FileName);
  if(propWasSet == false)
  {

  }
  reader->execute();
  if (reader->getErrorCondition() < 0)
  {
    qDebug() << "Error Reading the Ph File '" << FileName << "' Error Code:" << reader->getErrorCondition();
    return -1;
  }

  Int32ArrayType* featureIds = Int32ArrayType::SafePointerDownCast(m->getAttributeMatrix(DREAM3D::Defaults::CellAttributeMatrixName)->getAttributeArray(DREAM3D::CellData::FeatureIds).get());
  size_t count = featureIds->getNumberOfTuples();

  data.resize(count);
  for(size_t i = 0; i < count; ++i)
  {
    data[i] = featureIds->getValue(i);
  }


  return 0;
}
Esempio n. 9
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void GenerateCodeForFilter(const QString& outDir, AbstractFilter::Pointer filter)
{
  QString filterClassName = filter->getNameOfClass();

  // Generate our Output File Name for this filter. If we are going to generate a single file for everything then,
  // We need to think abit more about how this is setup. There is a potential for 2 plugins to clash with a filter's
  // C++ Class name, which would be interesting to say the least.

  QFile f(outDir + QDir::separator() + filterClassName + ".m");
  f.open(QFile::WriteOnly);
  QTextStream out(&f);


  QVector<FilterParameter::Pointer> options = filter->getFilterParameters();

  out << "function [ Filter_Parts ] = " << filterClassName << '\n';

  int i = 1;
  for (QVector<FilterParameter::Pointer>::iterator iter = options.begin(); iter != options.end(); ++iter )
  {
    SeparatorFilterParameter::Pointer sepFiltParam = SeparatorFilterParameter::New();
    FilterParameter* option = (*iter).get();
    if (option->getHumanLabel().compare("Required Information") == 0
        || option->getHumanLabel().compare("Created Information") == 0
        || option->getHumanLabel().compare("Optional Information") == 0
        || option->getWidgetType().compare(sepFiltParam->getWidgetType()) == 0)
    { continue; }

    // creates a working MATLAB m-file function per file per filter
    out << "Filter_Parts{1}{" << i << "} = '" << option->getPropertyName() << "';\n"
        << "Filter_Parts{2}{" << i << "} = '" << option->getWidgetType() << "';\n";
    ++i;
  }

  out << "end";

  f.close();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int H5FilterParametersWriter::WritePipelineToFile(FilterPipeline::Pointer pipeline, QString filePath, QString name, IObserver* obs)
{
  if (NULL == pipeline.get())
  {
    if (NULL != obs)
    {
      PipelineMessage pm(H5FilterParametersWriter::ClassName(), "FilterPipeline Object was NULL for writing", -1, PipelineMessage::Error);
      obs->processPipelineMessage(pm);
    }
    return -1;
  }

  QFileInfo fileInfo(filePath);

  // WRITE THE PIPELINE TO THE HDF5 FILE
  H5FilterParametersWriter::Pointer writer = H5FilterParametersWriter::New();

  hid_t fileId = -1;

  fileId = QH5Utilities::createFile(filePath);
  if (fileId < 0)
  {
    if (NULL != obs)
    {
      PipelineMessage pm(H5FilterParametersWriter::ClassName(), "Output .dream3d file could not be created.", -1, PipelineMessage::Error);
      obs->processPipelineMessage(pm);
    }
    return -1;
  }

  // This will make sure if we return early from this method that the HDF5 File is properly closed.
  // This will also take care of making sure all groups and file ids are closed
  // before this method returns.
  HDF5ScopedFileSentinel scopedFileSentinel(&fileId, true);

  // Write our File Version string to the Root "/" group
  QH5Lite::writeStringAttribute(fileId, "/", DREAM3D::HDF5::FileVersionName, DREAM3D::HDF5::FileVersion);
  QH5Lite::writeStringAttribute(fileId, "/", DREAM3D::HDF5::DREAM3DVersion, DREAM3DLib::Version::Complete() );

  hid_t pipelineGroupId = QH5Utilities::createGroup(fileId, DREAM3D::StringConstants::PipelineGroupName);
  scopedFileSentinel.addGroupId(&pipelineGroupId);
  writer->setGroupId(pipelineGroupId);

  FilterPipeline::FilterContainerType& filters = pipeline->getFilterContainer();

  // Loop over each filter and write it's input parameters to the file
  int count = filters.size();
  int index = 0;
  for (qint32 i = 0; i < count; ++i)
  {
    AbstractFilter::Pointer filter = filters.at(i);
    if (NULL != filter.get())
    {
      index = filter->writeFilterParameters(writer.get(), index);
    }
    else
    {
      AbstractFilter::Pointer badFilter = AbstractFilter::New();
      writer->openFilterGroup(badFilter.get(), i);
      writer->writeValue("Unknown Filter", "ERROR: Filter instance was NULL within the PipelineFilterWidget instance. Report this error to the DREAM3D Developers");
      writer->closeFilterGroup();
    }
  }

  return 0;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
FilterPipeline::Pointer JsonFilterParametersReader::ReadPipelineFromFile(QString filePath, IObserver* obs)
{
    QFileInfo fInfo(filePath);

    if (filePath.isEmpty() == true)
    {
        return FilterPipeline::NullPointer();
    }
    QFileInfo fi(filePath);
    if (fi.exists() == false)
    {
        return FilterPipeline::NullPointer();
    }

    FilterManager* filtManager = FilterManager::Instance();
    FilterFactory<EmptyFilter>::Pointer emptyFilterFactory = FilterFactory<EmptyFilter>::New();
    filtManager->addFilterFactory("EmptyFilter", emptyFilterFactory);

    JsonFilterParametersReader::Pointer reader = JsonFilterParametersReader::New();
    int err = reader->openFile(filePath);

    if (err < 0)
    {
        if (NULL != obs)
        {
            PipelineMessage pm(JsonFilterParametersReader::ClassName(), "File '" + fInfo.fileName() + "' could not be opened for reading.", -1, PipelineMessage::Error);
            obs->processPipelineMessage(pm);
        }
        return FilterPipeline::NullPointer();
    }

    reader->openGroup(DREAM3D::Settings::PipelineBuilderGroup);
    int filterCount = reader->readValue(DREAM3D::Settings::NumFilters, 0);
    reader->closeGroup();

    FilterPipeline::Pointer pipeline = FilterPipeline::New();

    for (int i = 0; i < filterCount; ++i)
    {
        // Open the group to get the name of the filter then close again.
        reader->openFilterGroup(NULL, i);
        QString filterName = reader->readString(DREAM3D::Settings::FilterName, "");
        reader->closeFilterGroup();
        //qDebug() << "Group: " << gName << " FilterName: " << filterName;
        if (filterName.isEmpty() == false)
        {
            IFilterFactory::Pointer factory = filtManager->getFactoryForFilter(filterName);
            if (factory.get() != NULL)
            {
                AbstractFilter::Pointer filter = factory->create();

                if (NULL != filter.get())
                {
                    filter->readFilterParameters(reader.get(), i);
                    pipeline->pushBack(filter);
                }
            }
            else // Could not find the filter because the specific name has not been registered. This could
                // be due to a name change for the filter.
            {
                EmptyFilter::Pointer filter = EmptyFilter::New();
                QString humanLabel = QString("UNKNOWN FILTER: ") + filterName;
                filter->setHumanLabel(humanLabel);
                filter->setOriginalFilterName(filterName);
                pipeline->pushBack(filter);

                if (NULL != obs)
                {
                    QString ss = QObject::tr("An implementation for filter '%1' could not be located. Possible reasons include a name change of the filter, plugin not loading or a simple spelling mistake? A blank filter has been inserted in its place.").arg(filterName);
                    PipelineMessage pm(filterName, ss, -66066, PipelineMessage::Error);
                    pm.setPrefix("JsonFilterParametersReader::ReadPipelineFromFile()");
                    obs->processPipelineMessage(pm);
                }
            }
        }
        else
        {
            EmptyFilter::Pointer filter = EmptyFilter::New();
            QString humanLabel = QString("MISSING FILTER: ") + filterName;
            filter->setHumanLabel(humanLabel);
            filter->setOriginalFilterName(filterName);
            pipeline->pushBack(filter);

            if (NULL != obs)
            {
                QString gName = QString::number(i);
                QString ss = QObject::tr("A filter for index '%1' is missing in the file. Is the numbering of the filters correct in the pipeline file?").arg(gName);
                PipelineMessage pm(filterName, ss, -66067, PipelineMessage::Error);
                pm.setPrefix("JsonFilterParametersReader::ReadPipelineFromFile()");
                obs->processPipelineMessage(pm);
            }
        }
    }
    return pipeline;
}