예제 #1
0
/**
 * This program generates a sphere (closed surface, vtkPolyData) and converts it into volume
 * representation (vtkImageData) where the foreground voxels are 1 and the background voxels are
 * 0. Internally vtkPolyDataToImageStencil is utilized. The resultant image is saved to disk
 * in metaimage file format (SphereVolume.mhd).
 */
int main(int argc, char * argv[])
{
    /*
    vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
    sphereSource->SetRadius(20);
    sphereSource->SetPhiResolution(30);
    sphereSource->SetThetaResolution(30);
    vtkSmartPointer<vtkPolyData> pd = sphereSource->GetOutput();
    sphereSource->Update();
     */

    Options opts;
    opts.addOption("--v", "voxelize a given mesh into a binary image [mesh] [refimage] [outimage]", SO_NONE);
    opts.addOption("--m", "create a binary image with a mark per point [mesh] [refimage] [outimage]", SO_NONE);
    StringVector args = opts.ParseOptions(argc, argv, NULL);


    if (opts.GetBool("--v")) {
        runScanConversion(opts, args);
    } else if (opts.GetBool("--m")) {
        runPointMarks(opts, args);
    }



}
예제 #2
0
파일: Options.cpp 프로젝트: WFRT/Comps
Options Options::getOption(const std::string& iKey) const {
   std::map<std::string,std::string>::const_iterator it = mMap.find(iKey);
   Options opt;
   if(it != mMap.end()) 
      opt.addOption(it->first, it->second);
   return opt;
}
예제 #3
0
Options *
SelectionTester::initOptions(TrajectoryAnalysisSettings * /*settings*/)
{
    static const char *const desc[] = {
        "This is a test program for selections.",
        NULL
    };

    _options.setDescription(desc);

    _options.addOption(SelectionOption("select").storeVector(&_selections)
                           .required().multiValue().allowMultiple()
                           .description("Selections to test"));
    _options.addOption(IntegerOption("pmax").store(&_nmaxind)
                           .description("Maximum number of indices to print in lists (-1 = print all)"));

    return &_options;
}
예제 #4
0
Options *
AnalysisTemplate::initOptions(TrajectoryAnalysisSettings *settings)
{
    static const char *const desc[] = {
        "This is a template for writing your own analysis tools for",
        "Gromacs. The advantage of using Gromacs for this is that you",
        "have access to all information in the topology, and your",
        "program will be able to handle all types of coordinates and",
        "trajectory files supported by Gromacs. In addition,",
        "you get a lot of functionality for free from the trajectory",
        "analysis library, including support for flexible dynamic",
        "selections. Go ahead an try it![PAR]",
        "To get started with implementing your own analysis program,",
        "follow the instructions in the README file provided.",
        "This template implements a simple analysis programs that calculates",
        "average distances from the a reference group to one or more",
        "analysis groups.",
        NULL
    };

    _options.setDescription(desc);

    _options.addOption(FileNameOption("o")
                       .filetype(eftPlot).writeOnly()
                       .store(&_fnDist).defaultValueIfSet("avedist")
                       .description("Average distances from reference group"));

    _options.addOption(SelectionOption("reference")
                       .store(&_refsel).required()
                       .description("Reference group to calculate distances from"));
    _options.addOption(SelectionOption("select")
                       .storeVector(&_sel).required().multiValue()
                       .description("Groups to calculate distances to"));

    _options.addOption(DoubleOption("cutoff").store(&_cutoff)
                       .description("Cutoff for distance calculation (0 = no cutoff)"));

    settings->setFlag(TrajectoryAnalysisSettings::efRequireTop);

    return &_options;
}
예제 #5
0
파일: Options.cpp 프로젝트: WFRT/Comps
void Options::appendOption(std::string iKey, const Options& iFrom, Options& iTo) {
   if(!iFrom.hasValues(iKey)) {
      return;
   }
   else if(iTo.hasValues(iKey)) {
      std::stringstream ss;
      std::string from;
      iFrom.getValuesAsString(iKey, from);
      std::string to;
      iTo.getValuesAsString(iKey, to);
      assert(from != "");
      ss << from << "," << to;
      iTo.addOption(iKey, ss.str());
   }
   else {
      copyOption(iKey, iFrom, iTo);
   }
}
예제 #6
0
//! \cond internal
void initTestUtils(const char *dataPath, const char *tempPath, bool usesMpi,
                   bool usesHardwareDetection, int *argc, char ***argv)
{
#if !defined NDEBUG &&                                                  \
    !((defined __clang__ || (defined(__GNUC__) && !defined(__ICC) && __GNUC__ == 7)) \
    && defined __OPTIMIZE__)
    gmx_feenableexcept();
#endif
    const CommandLineProgramContext &context = initForCommandLine(argc, argv);
    try
    {
        if (!usesMpi && gmx_node_num() > 1)
        {
            // We cannot continue, since some tests might be using
            // MPI_COMM_WORLD, which could deadlock if we would only
            // continue with the master rank here.
            if (gmx_node_rank() == 0)
            {
                fprintf(stderr, "NOTE: You are running %s on %d MPI ranks, "
                        "but it is does not contain MPI-enabled tests. "
                        "The test will now exit.\n",
                        context.programName(), gmx_node_num());
            }
            finalizeForCommandLine();
            std::exit(1);
        }
        if (usesHardwareDetection)
        {
            callAddGlobalTestEnvironment();
        }
        g_testContext = gmx::compat::make_unique<TestProgramContext>(context);
        setProgramContext(g_testContext.get());
        // Use the default finder that does not respect GMXLIB, since the tests
        // generally can only get confused by a different set of data files.
        setLibraryFileFinder(nullptr);
        ::testing::InitGoogleMock(argc, *argv);
        if (dataPath != nullptr)
        {
            TestFileManager::setInputDataDirectory(
                    Path::join(CMAKE_SOURCE_DIR, dataPath));
        }
        if (tempPath != nullptr)
        {
            TestFileManager::setGlobalOutputTempDirectory(tempPath);
        }
        bool        bHelp = false;
        std::string sourceRoot;
        Options     options;
        // TODO: A single option that accepts multiple names would be nicer.
        // Also, we recognize -help, but GTest doesn't, which leads to a bit
        // unintuitive behavior.
        options.addOption(BooleanOption("h").store(&bHelp)
                              .description("Print GROMACS-specific unit test options"));
        options.addOption(BooleanOption("help").store(&bHelp).hidden());
        options.addOption(BooleanOption("?").store(&bHelp).hidden());
        // TODO: Make this into a FileNameOption (or a DirectoryNameOption).
        options.addOption(StringOption("src-root").store(&sourceRoot)
                              .description("Override source tree location (for data files)"));
        // The potential MPI test event listener must be initialized first,
        // because it should appear in the start of the event listener list,
        // before other event listeners that may generate test failures
        // (currently, such an event listener is used by the reference data
        // framework).
        if (usesMpi)
        {
            initMPIOutput();
        }
        // TODO: Consider removing this option from test binaries that do not need it.
        initReferenceData(&options);
        initTestOptions(&options);
        try
        {
            CommandLineParser(&options).parse(argc, *argv);
            options.finish();
        }
        catch (const UserInputError &)
        {
            printHelp(options);
            throw;
        }
        if (bHelp)
        {
            printHelp(options);
        }
        if (!sourceRoot.empty())
        {
            g_testContext->overrideSourceRoot(sourceRoot);
            TestFileManager::setInputDataDirectory(
                    Path::join(sourceRoot, dataPath));
        }
    }
    catch (const std::exception &ex)
    {
        printFatalErrorMessage(stderr, ex);
        int retcode = processExceptionAtExitForCommandLine(ex);
        // TODO: It could be nice to destroy things in proper order such that
        // g_testContext would not contain hanging references at this point,
        // but in practice that should not matter.
        g_testContext.reset();
        std::exit(retcode);
    }
}
예제 #7
0
int main(int argc, char* argv[]) {
    // show which dimension this executable is handling
    cout << argv[0] << " with dimension = " << __Dim << endl;

    
    Options opts;
    opts.addOption("-o", "Specify a filename for an output image", SO_REQ_SEP);
    opts.addOption("--fusion", "label fusion from a config", "`--fusion config-file output-file target-image`", SO_REQ_SEP);
    opts.addOption("--overlap", "Compute the overlap ratio (dice|jaccard). This option can take two or arguments. The first argument is a gold standard, and other arguments are multiple number of label images to be compared.", "--overlap dice output-text ref1 ref2-1 ref2-2 ... ref2-n", SO_REQ_SEP);
    opts.addOption("--p2mat", "point list to matrix", SO_NONE);
    opts.addOption("--slice", "extract a slice from 3d volume", "--slice dim index imagefile outputfile", SO_NONE);
    opts.addOption("--imageMerge", "merge 2D images into a 3d volume (--imageMerge output input1 input2 ...)", SO_REQ_SEP);
    opts.addOption("--qa", "extract a slice with a label map", SO_NONE);
    opts.addOption("--config", "[file] use this config file", SO_REQ_SEP);
    opts.addOption("--demons", "run Demons registration", SO_NONE);
    opts.addOption("--separate", "[input] [x] [y] [z] ... separate vector images into individual image files", SO_NONE);
    opts.addOption("--rx", "registration experiments ", SO_NONE);
    opts.addOption("--dots", "--rx --dots generate a series of gaussian dot images", SO_NONE);
    opts.addOption("--sigma", "sigma value [double]", "--sigma 0.8", SO_REQ_SEP);
    opts.addOption("--entropyImage", "Compute an entropy image from a set of given images", "`--entropyImage -o output.nrrd input1.nrrd input2.nrrd ...`", SO_NONE);
    opts.addOption("--test", "Run in a test mode. The test mode is context sensitive depending on the given argument. For example, if `--entropyImage --test` is given, it will automatically provide a set of input images and produce an output into a specific directory.", SO_NONE);
    opts.addOption("--distanceMap", "Compute the Danielsson's distance map. This will also generate distmag.nrrd, x.nrrd, y.nrrd, and z.nrrd that stores the component of the vector distance map for debugging purpose.", "--distanceMap input output-vector output-magnitude", SO_NONE);
    opts.addOption("--help", "print this message", SO_NONE);

    opts.ParseOptions(argc, argv, NULL);
    StringVector& args = opts.GetStringVector("args");

    if (opts.GetBool("--help") || opts.GetBool("-h")) {
        cout << "## ParticleRun Command Line Options" << endl;
        opts.PrintUsage();
        return 0;
    }


    particle2mat(opts, args);
    doSlice(opts, args);
    doSeparate(opts, args);


    if (opts.GetBool("--qa")) {
        executeQARunner(opts, args);
    } else if (opts.GetString("--imageMerge", "") != "" && args.size() > 0) {
        doMerge(opts, args);
    } else if (opts.GetBool("--demons")) {
        executeDemonsRunner(opts, args);
    } else if (opts.GetBool("--rx")) {
        executeRxRunner(opts, args);
    } else if (opts.GetString("--fusion", "") != "") {
        executeLabelFusionRunner(opts, args);
    } else if (opts.GetBool("--entropyImage")) {
        executeEntropyImage(opts, args);
    } else if (opts.GetString("--overlap") == "dice" || opts.GetString("--overlap") == "jaccard") {
        executeVolumeOverlaps(opts, args);
    } else if (opts.GetBool("--distanceMap")) {
        executeComputeDistanceMap(opts, args);
    } else {
        executeParticleRunner(opts, args);
    }
}
예제 #8
0
// TODO: For now always use the default configuration, so that we don't have to add
// class=ConfigurationDefault on every line in the configurations.nl file
Configuration* Configuration::getScheme(const Options& iOptions, const Data& iData) {
   Options opt = iOptions;
   opt.addOption("class", "ConfigurationDefault");
   return new ConfigurationDefault(opt, iData);
}
예제 #9
0
파일: kcalc.cpp 프로젝트: fayhot/gradworks
int main(int argc, char* argv[]) {
    Options argParser;
    argParser.addOption("-i", "print image information as ImageStat --info option", SO_NONE);
    argParser.addOption("-e", "The equation to compute each output pixel.", "-e (A+B)", SO_REQ_SEP);
    argParser.addOption("-o", "output filename (the same data type with the last input)", "-o output.nrrd", SO_REQ_SEP);
    argParser.addOption("-h", "print this message", SO_NONE);

    StringVector args = argParser.ParseOptions(argc, argv, NULL);
    string eq = argParser.GetString("-e");
    string outputFilename = argParser.GetString("-o");
    
    if (argParser.GetBool("-i") && args.size() > 0) {
        ImageInfo lastImageInfo;
        imgIo.ReadCastedImage(args[0], lastImageInfo);
        printf("Filename: %s\n", args[0].c_str());
        printf("Dims: %d %d %d\n", lastImageInfo.dimensions[0], lastImageInfo.dimensions[1], lastImageInfo.dimensions[2]);
        printf("Pixdims: %.2f %.2f %.2f\n", lastImageInfo.spacing[0], lastImageInfo.spacing[1], lastImageInfo.spacing[2]);
        printf("Origins: %.2f %.2f %.2f\n", lastImageInfo.origin[0], lastImageInfo.origin[1], lastImageInfo.origin[2]);
        return 0;
    }

    if (argParser.GetBool("-h") || eq == "" || args.size() == 0 || outputFilename == "") {
        cout << "## kcalc usage \n"
            "\tkcalc [-e equation] [-o output-file] input1:A input2:B ...\n\n"
            "The kcalc performs a pixel-wise arithmetic. The pixel value of each input image is given as variables, A,B,C,D, and E. Several functions implemented in [MuParser](http://muparser.beltoforion.de/) includes +,-,*,/, and ? as well as trigonometric functions.\n\n"
            "Also, there are the min, max values of each input image for the use of scaling and other purposes, which are given as AMIN, AMAX, BMIN, BMAX, and etc.\n\n"
            "Note that the output data type is the same with the last input file. The order of images may produce different results, if images with different types are used.\n\n"
            "Some examples are:\n"
            "* **Addition**: kcalc -e \"(A+B)\" input1.nrrd input2.nrrd -o output.nrrd\n"
            "* **Averaging**: kcalc -e \"(A+B)/2\" input1.nrrd input2.nrrd -o output.nrrd\n"
            "* **Thresholding**: kcalc -e \"(A>10?1:0)\" input.nrrd -o output.nrrd\n"
            "* **Scaling**: -e (A-AMIN)/AMAX*255\n"
            "* **Masking**: -e (A==8?B:0)\n"
            "* ...\n\n"
            "### Options\n";
        argParser.PrintUsage();
        cout << endl;
        return 0;
    }

    if (argParser.GetBool("-2")) {
        cout << "Working on 2D images" << endl;
        ImageIO<Image2D> io2;
        ImageInfo lastImageInfo;
        PixelMathImageFilter<Image2D, Image2D>::Pointer pixelFilter = PixelMathImageFilter<Image2D, Image2D>::New();
        pixelFilter->SetEquation(eq);
        for (int i = 0; i < args.size(); i++) {
            pixelFilter->PushBackInput(io2.ReadCastedImage(args[i], lastImageInfo));
        }
        try {
            pixelFilter->Update();
        } catch (itk::ExceptionObject& e) {
            cout << e.what() << endl;
        }
        io2.WriteCastedImage(outputFilename, pixelFilter->GetOutput(), lastImageInfo.componenttype);
    } else {
        ImageInfo lastImageInfo;
        PixelMathImageFilter<ImageType, ImageType>::Pointer pixelFilter = PixelMathImageFilter<ImageType, ImageType>::New();
        pixelFilter->SetEquation(eq);
        for (int i = 0; i < args.size(); i++) {
            pixelFilter->PushBackInput(imgIo.ReadCastedImage(args[i], lastImageInfo));
        }
        try {
            pixelFilter->Update();
        } catch (itk::ExceptionObject& e) {
            cout << e.what() << endl;
        }

        imgIo.WriteCastedImage(outputFilename, pixelFilter->GetOutput(), lastImageInfo.componenttype);
    }
    return 0;
}
예제 #10
0
int main()
{
    system("resize -s 40 80");
    initscr();
    raw();
    noecho();
    cbreak();
    keypad(stdscr, TRUE);
    timeout(100);
    srand(time(NULL));
    start_color();

    init_pair(1, COLOR_BLACK, COLOR_WHITE);
    init_pair(2, COLOR_WHITE, COLOR_BLACK);

    log("beginning");

    OpTitle *e = new OpTitle("The game:\nThis is the title.\nBy me", Rect(0, 0, 80, 40));
    e->addOption("Generate new World", []() {
        menu.pop();
        Dialogue *d = new Dialogue("hello this is a dialogue", Rect(40, 0, 40, 21));
        log("to create wg");
        WorldGen *wg = new WorldGen(d);
        log("created wg");
        updating.push_back(wg);
        menu.addElem(wg->getVis());
        menu.addElem(d);
        log("created visualization, dialogue");
    });
    e->addOption("option 1", []() {
        Dialogue *d = new Dialogue("Option 1", Rect(15, 15, 10, 5));
        throw Creation(d);
    });
    e->addOption("exit", []() {
        OpTitle *o = new OpTitle("Are you sure you don't want to not exit?",
                                 Rect(10, 10, 20, 10));
        o->addOption("no", []() {
            on = false;
        });
        o->addOption("No I am Not", []() {
            throw Deletion();
        });
        throw Creation(o);
    });
    e->addOption("option 3", []() {
        Options *o = new Options(Rect(16, 5, 20, 20));
        o->addOption("something", []() {
            throw Creation(new Dialogue("you selected something", Rect(18, 10, 10, 10)));
        });
        o->addOption("something else", []() {
            throw Deletion();
        });
        throw Creation(o);
    });
    menu.addElem(e);

    refresh();

    while (on)
    {
        auto t1 = Clock::now();
        draw();
        move(0, 0);
        if (req_refresh)
            ;//refresh();
        req_refresh = false;
        update();
        auto t2 = Clock::now();
        input(33 - chrono::duration_cast<chrono::milliseconds>(t2 - t1).count());
        auto t3 = Clock::now();
        auto left = 33 - chrono::duration_cast<chrono::milliseconds>(t3 - t1).count();
        this_thread::sleep_for(chrono::milliseconds(left));
    }

    endwin();
}
예제 #11
0
Options *OptionParser::parse(int argc, char *const argv[])
{
	Options *options = new Options();
	QByteArray shortOptions;
	int shortIndexes[256];
	std::fill(shortIndexes, shortIndexes + 256, -1);
	ScopedArrayPtr<struct option> longOptions(new struct option[m_options.size() + 1]);
	int i;
	for (i = 0; i < m_options.size(); i++) {
		const Option *option = m_options.at(i);
		QByteArray name = option->longName().toLocal8Bit();
		longOptions[i].name = strdup(name.constData());
		if (option->argument() == Option::NoArgument) {
			longOptions[i].has_arg = no_argument;
		}
		else {
			longOptions[i].has_arg = required_argument;
		}
		longOptions[i].flag = 0;
		longOptions[i].val = 0;
		if (option->shortName()) {
			shortOptions += option->shortName();
			if (option->argument() != Option::NoArgument) {
				shortOptions += ':';
			}
			shortIndexes[option->shortName()] = i;
		}
		if (!option->defaultValue().isNull()) {
			options->addOption(name, option->defaultValue());
		}
	}
	longOptions[i].name = 0;
	longOptions[i].has_arg = 0;
	longOptions[i].flag = 0;
	longOptions[i].val = 0;

	m_prog = argv[0];
	int longIndex = 0;
	while (true) {
		int c = getopt_long(argc, argv, shortOptions.constData(), longOptions.get(), &longIndex);
		if (c == -1) {
			break;
		}
		if (c == 0 || shortIndexes[c] != -1) {
			i = (c == 0) ? longIndex : shortIndexes[c];
			QString name = m_options[i]->longName();
			options->addOption(name, QString::fromLocal8Bit(optarg));
			if (name == "help") {
				showHelp();
				exit(EXIT_SUCCESS);
			}
		}
		else {
			showHelp();
			exit(EXIT_FAILURE);
		}
	}
	while (optind < argc) {
		options->addArgument(QString::fromLocal8Bit(argv[optind++]));
	}
	for (i = 0; i < m_options.size(); i++) {
		free((void *) longOptions[i].name);
	}
	return options;
}