Beispiel #1
0
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  // Determine whether input is a raw Mariner 10 image or an Isis 2 cube
  bool isRaw = false;
  FileName inputFile = ui.GetFileName("FROM");
  Pvl label(inputFile.expanded());

  // If the PVL created from the input labels is empty, then input is raw
  if(label.groups() + label.objects() + label.keywords() == 0) {
    isRaw = true;
  }

  // Import for RAW files
  if(isRaw) {
    ProcessImport p;

    // All mariner images from both cameras share this size
    p.SetDimensions(832, 700, 1);
    p.SetFileHeaderBytes(968);
    p.SaveFileHeader();
    p.SetPixelType(UnsignedByte);
    p.SetByteOrder(Lsb);
    p.SetDataSuffixBytes(136);

    p.SetInputFile(ui.GetFileName("FROM"));
    Cube *oCube = p.SetOutputCube("TO");

    p.StartProcess();
    unsigned char *header = (unsigned char *) p.FileHeader();
    QString labels = EbcdicToAscii(header);
    UpdateLabels(oCube, labels);
    p.EndProcess();
  }
  // Import for Isis 2 cubes
  else {
    ProcessImportPds p;

    // All mariner images from both cameras share this size
    p.SetDimensions(832, 700, 1);
    p.SetPixelType(UnsignedByte);
    p.SetByteOrder(Lsb);
    p.SetDataSuffixBytes(136);

    p.SetPdsFile(inputFile.expanded(), "", label);
    Cube *oCube = p.SetOutputCube("TO");

    TranslateIsis2Labels(inputFile, oCube);
    p.StartProcess();
    p.EndProcess();
  }
}
Beispiel #2
0
void IsisMain () {
    flipDataBrick1 = NULL;
    flipDataBrick2 = NULL;
    ProcessImportPds p;

    // Input data for MARCI is unsigned byte
    p.SetPixelType(Isis::UnsignedByte);

    UserInterface &ui = Application::GetUserInterface();
    Filename inFile = ui.GetFilename("FROM");

    //Checks if in file is rdr
    Pvl lab(inFile.Expanded());
    if( lab.HasObject("IMAGE_MAP_PROJECTION") ) {
        string msg = "[" + inFile.Name() + "] appears to be an rdr file.";
        msg += " Use pds2isis.";
        throw iException::Message(iException::User,msg, _FILEINFO_);
    }

    Pvl pdsLab;
    p.SetPdsFile(inFile.Expanded(), "", pdsLab);

    if((int)pdsLab["SAMPLING_FACTOR"] == 12) {
        throw iException::Message(iException::User, "Summing mode of 12 not supported", _FILEINFO_);
    }

    // We need to know how many filters and their height to import the data properly
    numFilters = pdsLab["FILTER_NAME"].Size();
    currentLine.resize(numFilters);
    filterHeight = 16 / (int)pdsLab["SAMPLING_FACTOR"];

    // For simplicity, we'll keep track of line #'s on each band that we've written so far.
    for(int band = 0; band < numFilters; band ++) {
        currentLine[band] = 1;
    }

    int maxPadding = 0;

    padding.resize(numFilters);
    for(int filter = 0; filter < numFilters; filter++) {
        if(ui.GetBoolean("COLOROFFSET") == true) {
            colorOffset = ui.GetInteger("COLOROFFSET_SIZE");

            // find the filter num
            int filtNum = 0;
            int numKnownFilters = sizeof(knownFilters) / sizeof(std::string);

            while(filtNum < numKnownFilters &&
                    (std::string)pdsLab["FILTER_NAME"][filter] != knownFilters[filtNum]) {
                filtNum ++;
            }

            if(filtNum >= numKnownFilters) {
                throw iException::Message(iException::Pvl,
                                          "Nothing is known about the [" + pdsLab["FILTER_NAME"][filter] + "] filter. COLOROFFSET not possible.",
                                          _FILEINFO_);
            }
            else {
                padding[filter] = (colorOffset * filterHeight) * filtNum;
                maxPadding = max(maxPadding, padding[filter]);
            }
        }
        else {
            colorOffset = 0;
            padding[filter] = 0;
        }
    }

    // Output lines/samps.

    int numLines = (int)p.Lines() / numFilters + maxPadding;
    int numSamples = pdsLab.FindKeyword("LINE_SAMPLES", Pvl::Traverse);
    cubeHeight = numLines;

    outputCubes.push_back(new Isis::Cube());
    outputCubes.push_back(new Isis::Cube());

    outputCubes[0]->SetDimensions(numSamples, numLines, numFilters);
    outputCubes[1]->SetDimensions(numSamples, numLines, numFilters);

    Filename outputFile(ui.GetFilename("TO"));
    iString evenFile = outputFile.Path() + "/" + outputFile.Basename() + ".even.cub";
    iString oddFile = outputFile.Path() + "/" + outputFile.Basename() + ".odd.cub";

    outputCubes[0]->Create(evenFile);
    outputCubes[1]->Create(oddFile);

    if(ui.GetString("FLIP") == "AUTO") {
        flip = -1; // Flip is unknown, this let's us know we need to figure it out later
        flipDataBrick1 = new Isis::Brick(numSamples, filterHeight, numFilters, Isis::UnsignedByte);
        flipDataBrick2 = new Isis::Brick(numSamples, filterHeight, numFilters, Isis::UnsignedByte);
    }
    else if(ui.GetString("FLIP") == "YES") {
        flip = 1;
    }
    else {
        flip = 0;
    }

    writeOutputPadding();
    p.StartProcess(writeCubeOutput);

    // Add original labels
    OriginalLabel origLabel(pdsLab);

    std::vector<iString> framelets;

    framelets.push_back("Even");
    framelets.push_back("Odd");

    // Translate labels to every image and close output cubes before calling EndProcess
    for(unsigned int i = 0; i < outputCubes.size(); i++) {
        translateMarciLabels(pdsLab, *outputCubes[i]->Label());

        PvlObject &isisCube = outputCubes[i]->Label()->FindObject("IsisCube");
        isisCube.FindGroup("Instrument").AddKeyword(PvlKeyword("Framelets", framelets[i]));

        outputCubes[i]->Write(origLabel);
        delete outputCubes[i];
    }

    outputCubes.clear();

    if(flipDataBrick1 != NULL) {
        delete flipDataBrick1;
        delete flipDataBrick2;
        flipDataBrick1 = NULL;
        flipDataBrick2 = NULL;
    }

    p.EndProcess();
}