Exemplo n.º 1
0
void
Job::openOutputFolder()
  const {
  auto folder = outputFolder();

  if (!folder.isEmpty())
    QDesktopServices::openUrl(QUrl{Q("file:///%1").arg(folder)});
}
Exemplo n.º 2
0
    /**
     * Module cleanup function. This is where the module should free any resources 
     * allocated during initialization or execution.
     *
     * @returns TskModule::OK on success and TskModule::FAIL on error.
     */
    TskModule::Status TSK_MODULE_EXPORT finalize()
    {
        std::ostringstream msgPrefix;
        msgPrefix << MODULE_NAME << "::finalize : ";
        try
        {
            #if !defined(_DEBUG) 

            // Delete the output folder if it's empty.
            Poco::Path outputFolderPath = Poco::Path::forDirectory(GetSystemProperty(TskSystemProperties::MODULE_OUT_DIR));
            outputFolderPath.pushDirectory(MODULE_NAME);
            Poco::File outputFolder(outputFolderPath);
            std::vector<Poco::File> filesList;
            outputFolder.list(filesList);
            if (filesList.empty())
            {
                outputFolder.remove(true);
            }

            #endif

            return TskModule::OK;
        }
        catch (TskException &ex)
        {
            std::ostringstream msg;
            msg << msgPrefix.str() << "TskException: " << ex.message();
            LOGERROR(msg.str());
            return TskModule::FAIL;
        }
        catch (Poco::Exception &ex)
        {
            std::ostringstream msg;
            msg << msgPrefix.str() << "Poco::Exception: " << ex.displayText();
            LOGERROR(msg.str());
            return TskModule::FAIL;
        }
        catch (std::exception &ex)
        {
            std::ostringstream msg;
            msg << msgPrefix.str() << "std::exception: " << ex.what();
            LOGERROR(msg.str());
            return TskModule::FAIL;
        }
        catch (...)
        {
            LOGERROR(msgPrefix.str() + "unrecognized exception");
            return TskModule::FAIL;
        }
    }
    /**
     * Module cleanup function. Deletes output folder if empty.
     *
     * @returns TskModule::OK on success and TskModule::FAIL on error.
     */
    TSK_MODULE_EXPORT TskModule::Status finalize()
    {
        TskModule::Status status = TskModule::OK;        

        const std::string MSG_PREFIX = "SaveInterestingFilesModule::finalize : ";
        try
        {
            Poco::File outputFolder(outputFolderPath);
            std::vector<Poco::File> filesList;
            outputFolder.list(filesList);
            if (filesList.empty())
            {
                outputFolder.remove(true);
            }
        }
        catch (TskException &ex)
        {
            status = TskModule::FAIL;
            std::stringstream msg;
            msg << MSG_PREFIX << "TskException: " << ex.message();
            LOGERROR(msg.str());
        }
        catch (Poco::Exception &ex)
        {
            status = TskModule::FAIL;
            std::stringstream msg;
            msg << MSG_PREFIX << "Poco::Exception: " << ex.displayText();
            LOGERROR(msg.str());
        }
        catch (std::exception &ex)
        {
            status = TskModule::FAIL;
            std::stringstream msg;
            msg << MSG_PREFIX << "std::exception: " << ex.what();
            LOGERROR(msg.str());
        }
        catch (...)
        {
            status = TskModule::FAIL;
            LOGERROR(MSG_PREFIX + "unrecognized exception");
        }

        return status;
    }
Exemplo n.º 4
0
void SegmentationImpl::saveResult()
{
    try {
        fs::path outputFolder(outputSettings()->resultPath());
        if (outputSettings()->subFolderByDate()) {
            outputFolder /= currentDateString();
        }
        fs::create_directories(outputFolder);

        // compute filename (remove possible exisiting datetime prefix when loading an image from the results folder)
        std::string colorFilenameStr = fs::path(inputSettings()->color()).filename().string();
        boost::regex re("^\\d{8}_\\d{6}_");
        colorFilenameStr = boost::regex_replace(colorFilenameStr, re, "");
        if (outputSettings()->prefixDateTime()) {
            colorFilenameStr = currentDateTimeString() + "_" + colorFilenameStr;
        }

        // Note: we don't save groundTruthLabelMapping, since it will already be applied to the save ground truth image.
        fs::path colorFilename = colorFilenameStr;
        fs::path depthFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->depthReplace());
        fs::path depthFilenameNormalized = depthFilename.stem().string() + "_norm" + depthFilename.extension().string();
        fs::path groundTruthFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->groundTruthReplace());
        fs::path groundTruthFilenameNormalized = groundTruthFilename.stem().string() + "_norm" + groundTruthFilename.extension().string();
        fs::path scribbleFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->scribblesReplace());
        fs::path settingsFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->settingsReplace());
        fs::path solutionFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->solutionReplace());
        fs::path solutionFilenameNormalized = solutionFilename.stem().string() + "_norm" + solutionFilename.extension().string();
        fs::path weightFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->weightReplace());
        fs::path datatermFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->datatermReplace());
        fs::path datatermFilenameEqual = datatermFilename.stem().string() + "_equalized" + datatermFilename.extension().string();
        fs::path visualizationFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->visualizationReplace());
        fs::path metricsFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->metricsReplace());

        std::string colorPath = (outputFolder / colorFilename).string();

        if (inputImageColorAvailable()) {
            saveImage(colorPath, inputImageColor());
        }
        if (inputImageDepthAvailable()) {
            saveDepthImage((outputFolder / depthFilename).string(), inputImageDepth());
            saveDepthImage((outputFolder / depthFilenameNormalized).string(), inputImageDepth(), true);
        }
        if (inputImageGroundTruthAvailable()) {
            saveImage((outputFolder / groundTruthFilename).string(), inputImageGroundTruth(), false);
            saveImage((outputFolder / groundTruthFilenameNormalized).string(), inputImageGroundTruth(), true);
        }
        saveScribbleImage((outputFolder / scribbleFilename).string(), scribbles_);
        if (solutionAvailable()) {
            saveImage((outputFolder / solutionFilename).string(), solution(), false);
            saveImage((outputFolder / solutionFilenameNormalized).string(), solution(), true);
        }
        if (weightAvailable()) {
            saveImage((outputFolder / weightFilename).string(), weight(), true);
        }
        if (datatermAvailable()) {
            saveImage((outputFolder / datatermFilename).string(), dataterm(), true);
            saveImage((outputFolder / datatermFilenameEqual).string(), dataterm(), true, true);
        }
        if (tvvisualizer_->visualizationAvailable()) {
            saveImage((outputFolder / visualizationFilename).string(), tvvisualizer_->visualization());
        }

        settings::BackendPtr backend(new settings::Backend());
        copyAlgorithmicSettings(settingsBackend_, backend);
        InputSettings inputSettings(backend);
        inputSettings.set_color(colorPath);
        inputSettings.set_overrideGroundTruthLabelMapping(false);
        settings::SerializerQt serializer(backend, (outputFolder / settingsFilename).string(), false);
        serializer.save();

        if (solutionAvailable() && inputImageGroundTruthAvailable()) {
            saveMetrics((outputFolder / metricsFilename).string(), computeMetrics());
        }
    } catch (const fs::filesystem_error& ex) {
        LERROR << "Failed to save result with filesystem error: " << ex.what();
    }
}
Exemplo n.º 5
0
void Plot2hists1D(TString hist1Name,
		TString hist2Name, 
		Double_t scaleFactor1=1.0, 
		Double_t scaleFactor2=1.0, 
		TString hist1Label = "",
		TString hist2Label = "")
{

  Int_t LogY = 0;  // Y-axis, No log = 0, Log = 1
  int lineWidth = 2; // Line width for 1D histograms.
  TString outputFolder("Images");
  TString outputName(outputFolder+"/"+hist1Name+"-"+hist2Name+".gif");



  gSystem->MakeDirectory(outputFolder);

  // This is the cool part where we find the two histograms
  // based only on their names.  This is stored as a TKey for
  // the moment.
  TKey *key1 = (TKey*)gDirectory->GetListOfKeys()->FindObject(hist1Name);
  TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(hist2Name);

  if ((key1)&&(key2)) {

    // Now turn the TKeys into histograms
    TH1 *hist1 = (TH1*)key1->ReadObj();
    TH1 *hist2 = (TH1*)key2->ReadObj();

    // Scale them
    hist1->Scale(scaleFactor1);
    hist2->Scale(scaleFactor2);

    // Set the color
    hist1->SetLineColor(kBlue);
    hist2->SetLineColor(kRed);

    // Set the line width
    hist1->SetLineWidth(lineWidth);
    hist2->SetLineWidth(lineWidth);

    // Get rid of Stats box
    hist1->SetStats(kFALSE);

    // ****
    // Find the max value
    // & rescale Y axis
    Double_t max1 = hist1->GetMaximum();
    Double_t max2 = hist2->GetMaximum();

    if (max1 > max2) {
      hist1->SetMaximum(1.05*max1);
    } else {
      hist1->SetMaximum(1.05*max2);
    }
    // ****

    // Draw them!
    hist1->Draw();
    hist2->Draw("same");

/*
    // ****************
    // Draw Info Label
    TPaveText *infoBox = new TPaveText(0.85, 0.85, 0.98, 0.98, "NDC");
    TText *t1;
    TText *t2;
    if ( (hist1Label=="") || (hist2Label=="") ) {
     *t1 = infoBox->AddText(hist1Name);
     *t2 = infoBox->AddText(hist2Name);
    } else {
     *t1 = infoBox->AddText(hist1Label);
     *t2 = infoBox->AddText(hist2Label);
    }
    infoBox->SetFillColor(kWhite);
    t1->SetTextColor(kBlue);
    t2->SetTextColor(kRed);
    infoBox->Draw();
    // ****************
*/

    // ****************
    // Draw Info Label
    TLegend *infoBox = new TLegend(0.74, 0.74, 0.98, 0.98, "");
    if ( (hist1Label=="") || (hist2Label=="") ) {
      infoBox->AddEntry(hist1,hist1Name,"L");
      infoBox->AddEntry(hist2,hist2Name,"L");
    } else {
      infoBox->AddEntry(hist1,hist1Label,"L");
      infoBox->AddEntry(hist2,hist2Label,"L");
    }
    infoBox->Draw();
    // ****************

    c1->SetLogy(LogY);       // Set the axis to a log or not-log scale
    c1->Print(outputName);   // Save the histogram to a file

  } else {
    cout << "ERROR: One of the histogram names is wrong." << endl;
  }
}
Exemplo n.º 6
0
int main(int argc, const char* argv[])
{
    //
    // Parse arguments
    //
    std::string outputFolder("output");
    std::string inputFolder;

    for (int i = 1; i < argc; ++i)
    {
        if (strncmp(argv[i], "-h", 2) == 0)
        {
            printUsage();
            return EXIT_SUCCESS;
        }
        else if (strncmp(argv[i], "-v", 2) == 0)
        {
            printVersion();
            return EXIT_SUCCESS;
        }
        else if (strncmp(argv[i], "-o", 2) == 0)
        {
            i++;
            if (i == argc)
            {
                logError("The output folder is missing!\n");
                printUsage();
                return EXIT_FAILURE;
            }
            outputFolder = std::string(argv[i]);
        }
        else 
        {
            inputFolder = std::string(argv[i]);
            if (i != argc - 1)
            {
                logError("Not support more than one input file folder!\n");
                printUsage();
                return EXIT_FAILURE;
            }
        }
    }

    if (inputFolder == "")
    {
        logError("Invalid input path!\n");
        printUsage();
        return EXIT_FAILURE;
    }

    //
    // Create directory of output
    //
    if (!CreateDirectoryA(outputFolder.c_str(), NULL))
    {
        DWORD err = GetLastError();
        if (err == ERROR_PATH_NOT_FOUND)
        {
            logError("Some intermediate directories in the path (%s) are missing.\n", outputFolder.c_str());
            return EXIT_FAILURE;
        }
    }

    if (!makeHeaders(inputFolder.c_str(), outputFolder.c_str()))
    {
        return EXIT_FAILURE;
    }

    // If debugger is present, a pause is required to keep the console output
    // visible. Otherwise the pause is automatic. 
    if (IsDebuggerPresent())
    {
        system("pause");
    }

    return EXIT_SUCCESS;
}