Ejemplo n.º 1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int main(int argc, char** argv)
{
  qDebug() << "Starting Ph to HDF5 Merging...";

// Instantiate the QCoreApplication that we need to get the current path and load plugins.
  QCoreApplication app(argc, argv);
  QCoreApplication::setOrganizationName("BlueQuartz Software");
  QCoreApplication::setOrganizationDomain("bluequartz.net");
  QCoreApplication::setApplicationName("PhToHDF5");

  std::cout << "PhToHDF5 Starting. Version " << SIMPLib::Version::PackageComplete().toStdString() << std::endl;


  // Register all the filters including trying to load those from Plugins
  FilterManager::Pointer fm = FilterManager::Instance();
  SIMPLibPluginLoader::LoadPluginFilters(fm.get());

  // Send progress messages from PipelineBuilder to this object for display
  QMetaObjectUtilities::RegisterMetaTypes();

  try
  {
    // Handle program options passed on command line.
    TCLAP::CmdLine cmd("PhToHDF5", ' ', SIMPLib::Version::Complete().toStdString());

    TCLAP::ValueArg<std::string> phFileArg( "p", "phfile", "Ph Input File", true, "", "Ph Input File");
    cmd.add(phFileArg);

    TCLAP::ValueArg<std::string> angleFileArg( "e", "eulerfile", "Euler Angle File", false, "", "Euler Angle File");
    cmd.add(angleFileArg);

    TCLAP::ValueArg<std::string> h5InputFileArg( "t", "h5file", "Target HDF5 File", true, "", "Target HDF5 File");
    cmd.add(h5InputFileArg);

    // Parse the argv array.
    cmd.parse(argc, argv);
    if (argc == 1)
    {
      qDebug() << "PhToHDF5 program was not provided any arguments. Use the --help argument to show the help listing.";
      return EXIT_FAILURE;
    }


    QString phFile = QString::fromStdString(phFileArg.getValue());
    QString h5File = QString::fromStdString(h5InputFileArg.getValue());

    QVector<int> voxels;
    int nx = 0;
    int ny = 0;
    int nz = 0;

    qDebug() << "Merging the FeatureID data from " << phFile;
    qDebug() << "  into";
    qDebug() << "file: " << h5File;


    qDebug() << "Reading the Ph data file....";
    int err = ReadPHFile(phFile, voxels, nx, ny, nz);
    if (err < 0)
    {
      return EXIT_FAILURE;
    }
    qDebug() << "Ph File has dimensions: " << nx << " x " << ny << " x " << nz;


    qDebug() << "Now Overwriting the FeatureID data set in the HDF5 file....";
    err = writePhDataToHDF5File(h5File, voxels, nz, ny, nz);
    if (err < 0)
    {
      qDebug() << "There was an error writing the feature id data. Check other errors for possible clues.";
      return EXIT_FAILURE;
    }
    qDebug() << "+ Done Writing the Feature ID Data.";


    QMap<int, EulerSet> gidToEulerMap;
    if (angleFileArg.getValue().empty() == false)
    {
      qDebug() << "Reading the Euler Angle Data....";
      err = ReadEulerFile(QString::fromStdString(angleFileArg.getValue()), gidToEulerMap);
      if (err < 0)
      {
        qDebug() << "Error Reading the Euler Angle File";
        return EXIT_FAILURE;
      }

      // Over Write the Euler Angles if the Euler File was supplied

      qDebug() << "Now Over Writing the Euler Angles data in the HDF5 file.....";
      int totalPoints = nx * ny * nz;
      int numComp = 3;
      // Loop over each Voxel getting its Feature ID and then setting the Euler Angle
      QVector<float> dataf(totalPoints * 3);
      for (int i = 0; i < totalPoints; ++i)
      {
        EulerSet& angle = gidToEulerMap[voxels[i]];
        dataf[i * 3] = angle.e0;
        dataf[i * 3 + 1] = angle.e1;
        dataf[i * 3 + 2] = angle.e2;
      }
      // This is going to be a 2 Dimension Table Data set.
      int32_t rank = 2;
      hsize_t dims[2] = {totalPoints, numComp};
      err = writeEulerDataToHDF5File(h5File, dataf, numComp, rank, dims);
      if (err < 0)
      {
        qDebug() << "There was an error writing the Euler Angle data. Check other errors for possible clues.";
        return EXIT_FAILURE;
      }
      qDebug() << "+ Done Writing the Euler Angle Data.";
    }

  }
  catch (TCLAP::ArgException& e) // catch any exceptions
  {
    std::cerr << " error: " << e.error() << " for arg " << e.argId();
    return EXIT_FAILURE;
  }
  qDebug() << "Successfully completed the merge.";

  return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int main(int argc, char **argv)
{
  std::cout << "Starting Ph to HDF5 Merging..." << std::endl;

  try
  {
    // Handle program options passed on command line.
    TCLAP::CmdLine cmd("PhToHDF5", ' ', DREAM3DLib::Version::Complete());

    TCLAP::ValueArg<std::string> phFileArg( "p", "phfile", "Ph Input File", true, "", "Ph Input File");
    cmd.add(phFileArg);

    TCLAP::ValueArg<std::string> angleFileArg( "e", "eulerfile", "Euler Angle File", false, "", "Euler Angle File");
    cmd.add(angleFileArg);

    TCLAP::ValueArg<std::string> h5InputFileArg( "t", "h5file", "Target HDF5 File", true, "", "Target HDF5 File");
    cmd.add(h5InputFileArg);

    // Parse the argv array.
    cmd.parse(argc, argv);
    if (argc == 1)
    {
      std::cout << "PhToHDF5 program was not provided any arguments. Use the --help argument to show the help listing." << std::endl;
      return EXIT_FAILURE;
    }


    std::string phFile = phFileArg.getValue();
    std::string h5File = h5InputFileArg.getValue();

    std::vector<int> voxels;
    int nx = 0;
    int ny = 0;
    int nz = 0;

    std::cout << "Merging the GrainID data from " << phFile << std::endl;
    std::cout << "  into" << std::endl;
    std::cout << "file: " << h5File << std::endl;


    std::cout << "Reading the Ph data file...." << std::endl;
    int err = ReadPHFile(phFile, voxels, nx, ny, nz);
    if (err < 0)
    {
     return EXIT_FAILURE;
    }
    std::cout << "Ph File has dimensions: " << nx << " x " << ny << " x " << nz << std::endl;


    std::cout << "Now Overwriting the GrainID data set in the HDF5 file...." << std::endl;
    err = writePhDataToHDF5File(h5File, voxels, nz, ny, nz);
    if (err < 0)
    {
     std::cout << "There was an error writing the grain id data. Check other errors for possible clues." << std::endl;
     return EXIT_FAILURE;
    }
    std::cout << "+ Done Writing the Grain ID Data." << std::endl;


    std::map<int, EulerSet> gidToEulerMap;
    if (angleFileArg.getValue().empty() == false)
    {
      std::cout << "Reading the Euler Angle Data...." << std::endl;
      err = ReadEulerFile(angleFileArg.getValue(), gidToEulerMap);
      if (err < 0)
      {
        std::cout << "Error Reading the Euler Angle File" << std::endl;
        return EXIT_FAILURE;
      }

    // Over Write the Euler Angles if the Euler File was supplied

      std::cout << "Now Over Writing the Euler Angles data in the HDF5 file....." << std::endl;
      int totalPoints = nx * ny * nz;
      int numComp = 3;
      // Loop over each Voxel getting its Grain ID and then setting the Euler Angle
      std::vector<float> dataf(totalPoints * 3);
      for (int i = 0; i < totalPoints; ++i)
      {
        EulerSet& angle = gidToEulerMap[voxels[i]];
        dataf[i * 3] = angle.e0;
        dataf[i * 3 + 1] = angle.e1;
        dataf[i * 3 + 2] = angle.e2;
      }
      // This is going to be a 2 Dimension Table Data set.
      int32_t rank = 2;
      hsize_t dims[2] = {totalPoints, numComp};
      err = writeEulerDataToHDF5File(h5File, dataf, numComp, rank, dims);
      if (err < 0)
      {
       std::cout << "There was an error writing the Euler Angle data. Check other errors for possible clues." << std::endl;
       return EXIT_FAILURE;
      }
      std::cout << "+ Done Writing the Euler Angle Data." << std::endl;
    }

  }
  catch (TCLAP::ArgException &e) // catch any exceptions
  {
    std::cerr << logTime() << " error: " << e.error() << " for arg " << e.argId() << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "Successfully completed the merge." << std::endl;

  return EXIT_SUCCESS;
}