Beispiel #1
0
  FileName FileName::addExtension(const QString &newExtension) const {
    FileName result = *this;

    if (result.extension() != newExtension) {
      QString attributesStr = result.attributes();

      if (attributesStr == "")
        result = FileName(result.originalPath() + "/" + result.name() + "." + newExtension);
      else
        result = FileName(result.originalPath() + "/" + result.name() + "." + newExtension
                          + "+" + attributesStr);
    }

    return result;
  }
  /**
   * Fills the list box with the cube name list
   *
   * @internal
   *   @history  2009-01-26 Jeannie Walldren - Original version
   */
  void QnetPointCubeNameFilter::createCubeList() {
    // Clear the old list and update with the entire list
    p_listBox->setCurrentRow(-1);
    p_listBox->clear();

    SerialNumberList *snList = serialNumberList();
    for (int i = 0; i < snList->Size(); i++) {
      FileName filename = FileName(snList->FileName(i));
      QString tempFileName = filename.name();
      p_listBox->insertItem(i, tempFileName);
    }
  }
Beispiel #3
0
void IsisMain() {
  // Grab the file to import
  UserInterface &ui = Application::GetUserInterface();
  FileName in = ui.GetFileName("FROM");
  FileName out = ui.GetFileName("TO");

  // Make sure it is a Clementine EDR
  bool projected;
  try {
    Pvl lab(in.expanded());
    projected = lab.hasObject("IMAGE_MAP_PROJECTION");
    QString id;
    id = (QString)lab["DATA_SET_ID"];
    id = id.simplified().trimmed();
    if(!id.contains("CLEM")) {
      QString msg = "Invalid DATA_SET_ID [" + id + "]";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
  }
  catch(IException &e) {
    QString msg = "Input file [" + in.expanded() +
                  "] does not appear to be " +
                  "in Clementine EDR format";
    throw IException(IException::Unknown, msg, _FILEINFO_);
  }

  //Checks if in file is rdr
  if(projected) {
    QString msg = "[" + in.name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  //Decompress the file
  long int lines = 0;
  long int samps = 0;
  QString filename = in.expanded();
  pdsi = PDSR(filename.toAscii().data(), &lines, &samps);

  ProcessByLine p;
  CubeAttributeOutput cubeAtt("+unsignedByte+1.0:254.0");
  Cube *ocube = p.SetOutputCube(ui.GetFileName("TO"), cubeAtt, pdsi->image_ncols, pdsi->image_nrows);
  p.StartProcess(WriteLine);
  TranslateLabels(in, ocube);
  p.EndProcess();
}
Beispiel #4
0
  FileName FileName::newVersion() const {
    validateVersioningState();

    FileName result = *this;

    if (!isVersioned()) {
      throw IException(IException::Unknown,
                       QObject::tr("Asked for new version of file named [%1] in [%2] but there "
                                   "are no version sequences in the name")
                         .arg(name()).arg(originalPath()),
                       _FILEINFO_);
    }

    // Look for date
    if (isDateVersioned()) {
      result = result.version(QDate::currentDate());
    }

    // Look for #'s
    if (isNumericallyVersioned()) {
      try {
        result = result.version(result.highestVersionNum() + 1);
      }
      catch (IException &) {
        result = result.version(1);
      }
    }

    if (result.fileExists()) {
      throw IException(IException::Unknown,
                       QObject::tr("Could not generate unique new version of file named [%1] in "
                                   "[%2] because the file [%3] exists")
                         .arg(name()).arg(originalPath()).arg(result.name()),
                       _FILEINFO_);

    }

    return result;
  }
Beispiel #5
0
  foreach (QString fileToTest, filesToTestSafely) {
    cout << "Running Safe Test on [" << qPrintable(fileToTest) << "]" << endl;
    TestGenericAccessors("\t", fileToTest, false);
    TestExtensionChanges("\t", fileToTest, false);
  }

  // Test temp files thoroughly
  cout << "Testing temporary file name placement" << endl;
  QString tempFileNameTestStr = "$TEMPORARY/tttt.tmp";
  FileName n = FileName::createTempFile(tempFileNameTestStr);
  cout << "\tInput name and extension : " << tempFileNameTestStr << endl;
  cout << "\tExtension:               : " << n.extension() << endl;
  cout << "\tOriginal Path:           : " << n.originalPath() << endl;
  cout << "\tExists:                  : " << n.fileExists() << endl;
  cout << "\tName (cleaned):          : " <<
      QString(n.name().mid(0, 4) +
              QString("%1").arg("", n.name().size() - 8, '?') +
              n.name().mid(n.name().size() - 4)) << endl;
  cout << endl;

  if (!QFile(n.toString()).remove()) {
    cout << "\t**Failed to delete temporary file [" << n.toString() << "]**" << endl;
  }

  {
    cout << "Testing parallel temporary file name creation for atomicity" << endl;
    int numToTest = QThreadPool::globalInstance()->maxThreadCount() * 20;

    QStringList templateFileNames;
    for (int i = 0; i < numToTest; i++)
      templateFileNames.append(QString("tttt.tmp"));
Beispiel #6
0
/**
 * This program imports Mars Express HRSC files
 *
 *  This works by first determining whether or not the input file
 *    has prefix data.
 *
 *  If there is prefix data, a StartProcess is called with the
 *    IgnoreData() function callback in order to get the import class to
 *    collect prefix data. Once the prefix data is populated, we go ahead
 *    and look for "gaps" - HRSC files can give us a time and exposure duration
 *    for each line, we look for where the time + exposure duration != next line's time.
 *    We populate a table (LineScanTimes) with the prefix data and lineInFile with whether or not
 *    a gap should be inserted.
 *
 *  For all files, we now process the data using the WriteOutput callback. If there were gaps,
 *    WriteOutput will put them in their proper places. Finally, we translate the labels and put
 *    the LineScanTimes (if necessary) in the output cube.
 *
 *   This is a two-pass system for files with prefix data, one-pass for files without.
 *
 *   The Isis2 equivalent to this program is mex2isis.pl. It is worth noting that regardless of the
 *     input file's byte order, the prefix data byte order is always LSB.
 */
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  try {
    Pvl temp(ui.GetFileName("FROM"));
    // Check for HRSC file
    if(temp["INSTRUMENT_ID"][0] != "HRSC") throw IException();
  }
  catch(IException &e) {
    IString msg = "File [" + ui.GetFileName("FROM") +
                  "] does not appear to be a Mars Express HRSC image.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  ProcessImportPds p;
  Pvl label;
  lineInFile.clear();
  numLinesSkipped = 0;

  p.SetPdsFile(ui.GetFileName("FROM"), "", label);

  CubeAttributeOutput outAtt(ui.GetFileName("TO"));
  outCube = new Cube();

  outCube->setByteOrder(outAtt.byteOrder());
  outCube->setFormat(outAtt.fileFormat());
  outCube->setLabelsAttached(outAtt.labelAttachment() == AttachedLabel);

  /**
    * Isis2 mex2isis.pl:
    *   if (index($detector_id,"MEX_HRSC_SRC") < 0 &&
    *   $processing_level_id < 3)
    */
  bool hasPrefix = (label["DETECTOR_ID"][0] != "MEX_HRSC_SRC" && (int)label["PROCESSING_LEVEL_ID"] < 3);

  TableField ephTimeField("EphemerisTime", TableField::Double);
  TableField expTimeField("ExposureTime", TableField::Double);
  TableField lineStartField("LineStart", TableField::Integer);

  TableRecord timesRecord;
  timesRecord += ephTimeField;
  timesRecord += expTimeField;
  timesRecord += lineStartField;

  Table timesTable("LineScanTimes", timesRecord);

  if(hasPrefix) {
    p.SetDataPrefixBytes((int)label.findObject("IMAGE")["LINE_PREFIX_BYTES"]);
    p.SaveDataPrefix();

    p.Progress()->SetText("Reading Prefix Data");
    p.StartProcess(IgnoreData);

    // The prefix data is always in LSB format, regardless of the overall file format
    EndianSwapper swapper("LSB");

    std::vector<double> ephemerisTimes;
    std::vector<double> exposureTimes;
    std::vector< std::vector<char *> > prefix = p.DataPrefix();

    for(int line = 0; line < p.Lines(); line++) {
      double ephTime = swapper.Double((double *)prefix[0][line]);
      double expTime = swapper.Float((float *)(prefix[0][line] + 8)) / 1000.0;

      if(line > 0) {
        /**
         * We know how many skipped lines with this equation. We take the
         *   difference in the current line and the last line's time, which will
         *   ideally be equal to the last line's exposure duration. We divide this by
         *   the last line's exposure duration, and the result is the 1-based count of
         *   how many exposures there were between the last line and the current line.
         *   We subtract one in order to remove the known exposure, and the remaining should
         *   be the 1-based count of how many lines were skipped. Add 0.5 to round up.
         */
        int skippedLines = (int)((ephTime - ephemerisTimes.back()) / exposureTimes.back() - 1.0 + 0.5);

        for(int i = 0; i < skippedLines; i++) {
          ephemerisTimes.push_back(ephemerisTimes.back() + exposureTimes.back());
          exposureTimes.push_back(exposureTimes.back());
          lineInFile.push_back(false);
        }
      }

      ephemerisTimes.push_back(ephTime);
      exposureTimes.push_back(expTime);
      lineInFile.push_back(true);
    }

    double lastExp = 0.0;
    for(unsigned int i = 0; i < ephemerisTimes.size(); i++) {
      if(lastExp != exposureTimes[i]) {
        lastExp = exposureTimes[i];
        timesRecord[0] = ephemerisTimes[i];
        timesRecord[1] = exposureTimes[i];
        timesRecord[2] = (int)i + 1;
        timesTable += timesRecord;
      }
    }

    outCube->setDimensions(p.Samples(), lineInFile.size(), p.Bands());
  }
  else {
    //Checks if in file is rdr
    FileName inFile = ui.GetFileName("FROM");
    QString msg = "[" + inFile.name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  p.Progress()->SetText("Importing");
  outCube->create(ui.GetFileName("TO"));
  p.StartProcess(WriteOutput);

  if(hasPrefix) {
    outCube->write(timesTable);
  }

  // Get as many of the other labels as we can
  Pvl otherLabels;

  //p.TranslatePdsLabels (otherLabels);
  TranslateHrscLabels(label, otherLabels);

  if(otherLabels.hasGroup("Mapping") &&
      (otherLabels.findGroup("Mapping").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Mapping"));
  }

  if(otherLabels.hasGroup("Instrument") &&
      (otherLabels.findGroup("Instrument").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Instrument"));
  }

  if(otherLabels.hasGroup("BandBin") &&
      (otherLabels.findGroup("BandBin").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("BandBin"));
  }

  if(otherLabels.hasGroup("Archive") &&
      (otherLabels.findGroup("Archive").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Archive"));
  }

  if(otherLabels.hasGroup("Kernels") &&
      (otherLabels.findGroup("Kernels").keywords() > 0)) {
    outCube->putGroup(otherLabels.findGroup("Kernels"));
  }

  p.EndProcess();

  outCube->close();
  delete outCube;
  outCube = NULL;
  lineInFile.clear();
}
Beispiel #7
0
    void importOBJ(const std::shared_ptr<Node> &world, const FileName &fileName)
    {
      tinyobj::attrib_t attrib;
      std::vector<tinyobj::shape_t> shapes;
      std::vector<tinyobj::material_t> materials;

      std::string err;
      const std::string containingPath = fileName.path();

      std::cout << "parsing OBJ input file... \n";
      bool ret = tinyobj::LoadObj(&attrib,
                                  &shapes,
                                  &materials,
                                  &err,
                                  fileName.c_str(),
                                  containingPath.c_str());

#if 0 // NOTE(jda) - enable if you want to see warnings from TinyOBJ
      if (!err.empty())
        std::cerr << "#ospsg: obj parsing warning(s)...\n" << err << std::endl;
#endif

      if (!ret) {
        std::cerr << "#ospsg: FATAL error parsing obj file, no geometry added"
                  << " to the scene!" << std::endl;
        return;
      }

      auto sgMaterials = createSgMaterials(materials, containingPath);

      std::string base_name = fileName.name() + '_';
      int shapeId           = 0;

      std::cout << "...adding found triangle groups to the scene...\n";

      size_t shapeCounter = 0;
      size_t numShapes    = shapes.size();
      size_t increment    = numShapes / size_t(10);
      int    incrementer  = 0;

#if !USE_INSTANCES
      auto objInstance = createNode("instance", "Instance");
      world->add(objInstance);
#endif
      for (auto &shape : shapes) {
        for (int numVertsInFace : shape.mesh.num_face_vertices) {
          if (numVertsInFace != 3) {
            std::cerr << "Warning: more thant 3 verts in face!";
            PRINT(numVertsInFace);
          }
        }

        if (shapeCounter++ > (increment * incrementer + 1))
          std::cout << incrementer++ * 10 << "%\n";

        auto name = base_name + std::to_string(shapeId++) + '_' + shape.name;
        auto mesh = createNode(name, "TriangleMesh")->nodeAs<TriangleMesh>();

        auto v = createNode("vertex", "DataVector3f")->nodeAs<DataVector3f>();
        auto numSrcIndices = shape.mesh.indices.size();
        v->v.reserve(numSrcIndices);

        auto vi = createNode("index", "DataVector3i")->nodeAs<DataVector3i>();
        vi->v.reserve(numSrcIndices / 3);

        auto vn = createNode("normal", "DataVector3f")->nodeAs<DataVector3f>();
        vn->v.reserve(numSrcIndices);

        auto vt =
            createNode("texcoord", "DataVector2f")->nodeAs<DataVector2f>();
        vt->v.reserve(numSrcIndices);

        for (size_t i = 0; i < shape.mesh.indices.size(); i += 3) {
          auto idx0 = shape.mesh.indices[i + 0];
          auto idx1 = shape.mesh.indices[i + 1];
          auto idx2 = shape.mesh.indices[i + 2];

          auto prim = vec3i(i + 0, i + 1, i + 2);
          vi->push_back(prim);

          v->push_back(vec3f(attrib.vertices[idx0.vertex_index * 3 + 0],
                             attrib.vertices[idx0.vertex_index * 3 + 1],
                             attrib.vertices[idx0.vertex_index * 3 + 2]));
          v->push_back(vec3f(attrib.vertices[idx1.vertex_index * 3 + 0],
                             attrib.vertices[idx1.vertex_index * 3 + 1],
                             attrib.vertices[idx1.vertex_index * 3 + 2]));
          v->push_back(vec3f(attrib.vertices[idx2.vertex_index * 3 + 0],
                             attrib.vertices[idx2.vertex_index * 3 + 1],
                             attrib.vertices[idx2.vertex_index * 3 + 2]));

          // TODO create missing normals&texcoords if only some faces have them
          if (!attrib.normals.empty() && idx0.normal_index != -1) {
            vn->push_back(vec3f(attrib.normals[idx0.normal_index * 3 + 0],
                                attrib.normals[idx0.normal_index * 3 + 1],
                                attrib.normals[idx0.normal_index * 3 + 2]));
            vn->push_back(vec3f(attrib.normals[idx1.normal_index * 3 + 0],
                                attrib.normals[idx1.normal_index * 3 + 1],
                                attrib.normals[idx1.normal_index * 3 + 2]));
            vn->push_back(vec3f(attrib.normals[idx2.normal_index * 3 + 0],
                                attrib.normals[idx2.normal_index * 3 + 1],
                                attrib.normals[idx2.normal_index * 3 + 2]));
          }

          if (!attrib.texcoords.empty() && idx0.texcoord_index != -1) {
            vt->push_back(vec2f(attrib.texcoords[idx0.texcoord_index * 2 + 0],
                                attrib.texcoords[idx0.texcoord_index * 2 + 1]));
            vt->push_back(vec2f(attrib.texcoords[idx1.texcoord_index * 2 + 0],
                                attrib.texcoords[idx1.texcoord_index * 2 + 1]));
            vt->push_back(vec2f(attrib.texcoords[idx2.texcoord_index * 2 + 0],
                                attrib.texcoords[idx2.texcoord_index * 2 + 1]));
          }
        }

        mesh->add(v);
        mesh->add(vi);
        if (!vn->empty())
          mesh->add(vn);
        if (!vt->empty())
          mesh->add(vt);

        auto pmids = createNode("prim.materialID",
                                "DataVector1i")->nodeAs<DataVector1i>();

        auto numMatIds = shape.mesh.material_ids.size();
        pmids->v.reserve(numMatIds);

        for (auto id : shape.mesh.material_ids)
          pmids->v.push_back(id);

        mesh->add(pmids);
        mesh->add(sgMaterials);

        auto model = createNode(name + "_model", "Model");
        model->add(mesh);

        // TODO: Large .obj models with lots of groups run much slower with each
        //       group put in a separate instance. In the future, we want to
        //       support letting the user (ospExampleViewer, for starters)
        //       specify if each group should be placed in an instance or not.
#if USE_INSTANCES
        auto instance = createNode(name + "_instance", "Instance");
        instance->setChild("model", model);
        model->setParent(instance);

        world->add(instance);
#else
        (*objInstance)["model"].add(mesh);
#endif

      }

      std::cout << "...finished import!\n";
    }
Beispiel #8
0
//***********************************************************************
//   IsisMain()
//***********************************************************************
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();
  FileName in = ui.GetFileName("FROM");
  FileName outIr = ui.GetFileName("IR");
  FileName outVis = ui.GetFileName("VIS");
  Pvl lab(in.expanded());

  //Checks if in file is rdr
  if(lab.hasObject("IMAGE_MAP_PROJECTION")) {
    QString msg = "[" + in.name() + "] appears to be an rdr file.";
    msg += " Use pds2isis.";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  //Make sure it is a vims cube
  try {
    PvlObject qube(lab.findObject("QUBE"));
    QString id;
    id = (QString)qube["INSTRUMENT_ID"];
    id = id.simplified().trimmed();
    if(id != "VIMS") {
      QString msg = "Invalid INSTRUMENT_ID [" + id + "]";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
  }
  catch(IException &e) {
    QString msg = "Input file [" + in.expanded() +
                 "] does not appear to be " +
                 "in VIMS EDR/RDR format";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  FileName tempname(in.baseName() + ".bsq.cub");
  Pvl pdsLab(in.expanded());

  // It's VIMS, let's figure out if it has the suffix data or not
  if(toInt(lab.findObject("QUBE")["SUFFIX_ITEMS"][0]) == 0) {
    // No suffix data, we can use processimportpds
    ProcessImportPds p;

    p.SetPdsFile(in.expanded(), "", pdsLab);
    // Set up the temporary output cube
    //The temporary cube is set to Real pixeltype, regardless of input pixel type
    Isis::CubeAttributeOutput outatt = CubeAttributeOutput("+Real");
    p.SetOutputCube(tempname.name(), outatt);
    p.StartProcess();
    p.EndProcess();
  }
  else {
    // We do it the hard way
    ReadVimsBIL(in.expanded(), lab.findObject("QUBE")["SUFFIX_ITEMS"], tempname.name());
  }

  // Create holder for original labels
  OriginalLabel origLabel(pdsLab);

  //Now separate the cubes
  ProcessByLine l;

  PvlGroup status("Results");

  //VIS cube
  const PvlObject &qube = lab.findObject("Qube");
  if(qube["SAMPLING_MODE_ID"][1] != "N/A") {
    CubeAttributeInput inattvis = CubeAttributeInput("+1-96");
    l.SetInputCube(tempname.name(), inattvis);
    Cube *oviscube = l.SetOutputCube("VIS");
    oviscube->write(origLabel);
    l.StartProcess(ProcessCube);
    TranslateVimsLabels(pdsLab, oviscube, VIS);
    l.EndProcess();

    status += PvlKeyword("VisCreated", "true");
  }
  else {
    status += PvlKeyword("VisCreated", "false");
  }

  //IR cube
  if(qube["SAMPLING_MODE_ID"][0] != "N/A") {
    CubeAttributeInput inattir = CubeAttributeInput("+97-352");
    l.SetInputCube(tempname.name(), inattir);
    Cube *oircube = l.SetOutputCube("IR");
    oircube->write(origLabel);
    l.StartProcess(ProcessCube);
    TranslateVimsLabels(pdsLab, oircube, IR);
    l.EndProcess();

    status += PvlKeyword("IrCreated", "true");
  }
  else {
    status += PvlKeyword("IrCreated", "false");
  }

  Application::Log(status);

  //Clean up
  QString tmp(tempname.expanded());
  QFile::remove(tmp);
}