Пример #1
0
void IsisMain() {
  colorOffset = 0;
  frameletLines.clear();
  outputCubes.clear();

  uveven = NULL;
  uvodd = NULL;
  viseven = NULL;
  visodd = NULL;

  ProcessImportPds p;
  Pvl pdsLab;

  UserInterface &ui = Application::GetUserInterface();
  QString fromFile = ui.GetFileName("FROM");

  flip = false;//ui.GetBoolean("FLIP");

  p.SetPdsFile(fromFile, "", pdsLab);
  ValidateInputLabels(pdsLab);
  inputCubeLines = p.Lines();

  lookupTable = Stretch();

  // read the lut if the option is on
  if(ui.GetBoolean("UNLUT") && pdsLab["LRO:LOOKUP_TABLE_TYPE"][0] == "STORED") {
    PvlKeyword lutKeyword = pdsLab["LRO:LOOKUP_CONVERSION_TABLE"];

    for(int i = 0; i < lutKeyword.size(); i ++) {
      IString lutPair = lutKeyword[i];
      lutPair.ConvertWhiteSpace();
      lutPair.Remove("() ");
      QString outValueMin = lutPair.Token(" ,").ToQt();
      QString outValueMax = lutPair.Token(" ,").ToQt();
      lookupTable.AddPair(i, (toDouble(outValueMin) + toDouble(outValueMax)) / 2.0);
    }
  }

  QString instModeId = pdsLab["INSTRUMENT_MODE_ID"];

  // this will be used to convert num input lines to num output lines,
  //   only changed for when both uv and vis exist (varying summing)
  double visOutputLineRatio = 1.0;
  double uvOutputLineRatio = 1.0;

  int numFilters = 0;
  if(ui.GetBoolean("COLOROFFSET")) {
    colorOffset = ui.GetInteger("COLOROFFSETSIZE");
  }

  // Determine our band information based on
  // INSTRUMENT_MODE_ID - FILTER_NUMBER is
  // only going to be used for BW images
  if(instModeId == "COLOR") {
    numFilters = 7;
    frameletLines.push_back(4);
    frameletLines.push_back(4);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);

    uveven  = new Cube();
    uvodd   = new Cube();
    viseven = new Cube();
    visodd  = new Cube();

    // 14 output lines (1 framelet) from 5vis/2uv lines
    visOutputLineRatio = 14.0 / (14.0 * 5.0 + 4.0 * 2.0);

    // 4 output lines (1 framelet) from 5vis/2uv lines
    uvOutputLineRatio = 4.0 / (14.0 * 5.0 + 4.0 * 2.0);
  }
  else if(instModeId == "VIS") {
    numFilters = 5;

    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);
    frameletLines.push_back(14);

    viseven = new Cube();
    visodd  = new Cube();

    // 14 output lines (1 framelet) from 5vis/2uv lines
    visOutputLineRatio = 14.0 / (14.0 * 5.0);
  }
  else if(instModeId == "UV") {
    numFilters = 2;

    frameletLines.push_back(4);
    frameletLines.push_back(4);

    uveven = new Cube();
    uvodd  = new Cube();

    // 4 output lines (1 framelet) from 2uv lines
    uvOutputLineRatio = 4.0 / (4.0 * 2.0);
  }
  else if(instModeId == "BW") {
    numFilters = 1;

    frameletLines.push_back(14);

    viseven = new Cube();
    visodd  = new Cube();
  }

  padding.resize(numFilters);


  for(int filter = 0; filter < numFilters; filter++) {
    padding[filter] = (colorOffset * frameletLines[filter]) * filter;

    // dont count UV for VIS offsetting
    if(instModeId == "COLOR" && filter > 1) {
      padding[filter] -= 2 * colorOffset * frameletLines[filter];
    }
  }

  FileName baseFileName(ui.GetFileName("TO"));

  if(uveven && uvodd) {
    // padding[1] is max padding for UV
    int numSamples = ((viseven) ? p.Samples() / 4 : p.Samples());
    numSamples     = 128; // UV is alway sum 4 so it is 128 samples
    int numLines   = (int)(uvOutputLineRatio * inputCubeLines + 0.5) + padding[1];
    int numBands   = 2;

    uveven->setDimensions(numSamples, numLines, numBands);
    uveven->setPixelType(Isis::Real);

    QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.even.cub";
    uveven->create(filename);

    uvodd->setDimensions(numSamples, numLines, numBands);
    uvodd->setPixelType(Isis::Real);

    filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.odd.cub";
    uvodd->create(filename);
  }

  if(viseven && visodd) {
    // padding[size-1] is max padding for vis (padding[0] or padding[4] or padding[6])
    int numSamples = p.Samples();
    int numLines   = (int)(visOutputLineRatio * inputCubeLines + 0.5) + padding[padding.size()-1];
    int numBands   = ((uveven) ? padding.size() - 2 : padding.size());

    viseven->setDimensions(numSamples, numLines, numBands);
    viseven->setPixelType(Isis::Real);

    QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.even.cub";
    viseven->create(filename);

    visodd->setDimensions(numSamples, numLines, numBands);
    visodd->setPixelType(Isis::Real);

    filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.odd.cub";
    visodd->create(filename);
  }

  Pvl isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab;
  TranslateLabels(pdsLab, isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab);

  writeNullsToFile();
  p.StartProcess(separateFramelets);
  p.EndProcess();

  // Add original labels
  OriginalLabel origLabel(pdsLab);

  int numFramelets = padding.size();
  PvlKeyword numFrameletsKeyword("NumFramelets", toString(numFramelets));

  if(uveven) {
    for(int grp = 0; grp < isis3UvEvenLab.groups(); grp++) {
      uveven->putGroup(isis3UvEvenLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    uveven->write(history);
    uveven->write(origLabel);

    uveven->close();
    delete uveven;
    uveven = NULL;
  }

  if(uvodd) {
    for(int grp = 0; grp < isis3UvOddLab.groups(); grp++) {
      uvodd->putGroup(isis3UvOddLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    uvodd->write(history);
    uvodd->write(origLabel);

    uvodd->close();
    delete uvodd;
    uvodd = NULL;
  }

  if(viseven) {
    for(int grp = 0; grp < isis3VisEvenLab.groups(); grp++) {
      viseven->putGroup(isis3VisEvenLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    viseven->write(history);
    viseven->write(origLabel);

    viseven->close();
    delete viseven;
    viseven = NULL;
  }

  if(visodd) {
    for(int grp = 0; grp < isis3VisOddLab.groups(); grp++) {
      visodd->putGroup(isis3VisOddLab.group(grp));
    }

    History history("IsisCube");
    history.AddEntry();
    visodd->write(history);
    visodd->write(origLabel);

    visodd->close();
    delete visodd;
    visodd = NULL;
  }
}