Files
fist/arg_eval.cpp
SaraP cbec90699f FIST 6.8 :
- creato il progetto in Visual Studio per compilare come libreria statica
- modifiche al codice originale per integrarlo nelle nostre librerie.
2025-03-04 16:19:35 +01:00

467 lines
17 KiB
C++

/*****************************************************************************/
/* */
/* F I S T : Fast, Industrial-Strength Triangulation */
/* */
/*****************************************************************************/
/* */
/* (C) Martin Held */
/* (C) Universitaet Salzburg, Salzburg, Austria */
/* */
/* This code is not in the public domain. All rights reserved! Please make */
/* sure to read the full copyright statement contained in api_functions.cpp. */
/* */
/*****************************************************************************/
/* */
/* get standard libraries */
/* */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
/* */
/* get my header files */
/* */
#include "fpkernel.h"
#include "martin.h"
#include "defs.h"
#include "header.h"
/* */
/* function prototypes of functions provided in this file */
/* */
void InitDefaults(rt_options *rt_opt);
boolean ArgEval(int argc, char *argv[], rt_options *rt_opt);
void EvalError(void);
void InitDefaults(rt_options *rt_opt)
{
/* */
/* default run-time options */
/* */
rt_opt->color_graphics = true;
rt_opt->save_poly = false;
rt_opt->read_input = false;
rt_opt->read_lines = false;
rt_opt->read_poly = false;
rt_opt->read_dxf = false;
rt_opt->graphics = false;
rt_opt->write_geom = false;
rt_opt->step_size = INT_MAX;
rt_opt->verbose = false;
rt_opt->read_obj = false;
rt_opt->write_tri = false;
rt_opt->write_dxf = false;
rt_opt->write_ipe7 = false;
rt_opt->c2p = false;
rt_opt->help = false;
rt_opt->time = false;
rt_opt->statistics = false;
rt_opt->ears_fancy = false;
rt_opt->ears_top = true;
rt_opt->ears_sorted = false;
rt_opt->ears_random = false;
rt_opt->copy = true;
rt_opt->do_quads = false;
rt_opt->keep_quads = false;
rt_opt->use_colors = false;
rt_opt->draw_concave = false;
rt_opt->sgi_output = false;
rt_opt->quiet = false;
rt_opt->draw_groups = false;
rt_opt->keep_convex = false;
rt_opt->scale_data = false;
rt_opt->full_screen = false;
rt_opt->inputprec = -1;
rt_opt->mpfr_prec = 53;
return;
}
/* */
/* this function parses the command-line arguments */
/* */
boolean ArgEval(int argc, char *argv[], rt_options *rt_opt)
{
int count = 1;
boolean success = true;
/* */
/* parse the command-line arguments */
/* */
while ((count < argc) && success) {
if (strcmp(argv[count],"--b+w") == 0) {
rt_opt->color_graphics = false;
}
else if (strcmp(argv[count],"--scale") == 0) {
rt_opt->scale_data = true;
}
else if (strcmp(argv[count],"--sorted") == 0) {
rt_opt->ears_sorted = true;
rt_opt->ears_top = false;
}
else if (strcmp(argv[count],"--random") == 0) {
rt_opt->ears_random = true;
rt_opt->ears_top = false;
rt_opt->ears_fancy = false;
rt_opt->ears_sorted = false;
}
else if (strcmp(argv[count],"--sequen") == 0) {
rt_opt->ears_sorted = false;
rt_opt->ears_top = false;
rt_opt->ears_fancy = false;
rt_opt->ears_random = false;
}
else if (strcmp(argv[count],"--fancy") == 0) {
rt_opt->ears_top = false;
rt_opt->ears_fancy = true;
}
else if (strcmp(argv[count],"--top") == 0) {
rt_opt->ears_top = true;
}
else if (strcmp(argv[count],"--OGL") == 0) {
rt_opt->graphics = true;
}
else if (strcmp(argv[count],"--full") == 0) {
rt_opt->full_screen = true;
}
else if (strcmp(argv[count],"--quiet") == 0) {
rt_opt->quiet = true;
}
#ifndef NORMALS
else if (strcmp(argv[count],"--quads") == 0) {
rt_opt->do_quads = true;
}
else if (strcmp(argv[count],"--keep_quads") == 0) {
rt_opt->keep_quads = true;
}
#endif
else if (strcmp(argv[count],"--stat") == 0) {
rt_opt->statistics = true;
}
else if (strcmp(argv[count],"--verbose") == 0) {
rt_opt->verbose = true;
}
else if (strcmp(argv[count],"--copy") == 0) {
rt_opt->copy = false;
}
else if (strcmp(argv[count],"--obj") == 0) {
rt_opt->read_obj = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->input_file, argv[count]);
}
else if (strcmp(argv[count],"--geom") == 0) {
rt_opt->write_geom = true;
}
else if (strcmp(argv[count],"--time") == 0) {
rt_opt->time = true;
}
else if (strcmp(argv[count],"--color") == 0) {
rt_opt->use_colors = true;
}
else if (strcmp(argv[count],"--draw_groups") == 0) {
rt_opt->draw_groups = true;
}
else if (strcmp(argv[count],"--concave") == 0) {
rt_opt->draw_concave = true;
}
else if (strcmp(argv[count],"--help") == 0) {
rt_opt->help = true;
}
else if (strcmp(argv[count],"--Ipe") == 0) {
rt_opt->write_ipe7 = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->ipe_file, argv[count]);
}
else if (strcmp(argv[count],"--c2p") == 0) {
rt_opt->c2p = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->c2p_file, argv[count]);
}
else if (strcmp(argv[count],"--sgi") == 0) {
rt_opt->sgi_output = true;
}
#ifndef NORMALS
else if (strcmp(argv[count],"--convex") == 0) {
rt_opt->keep_convex = true;
}
#endif
else if (strcmp(argv[count],"--save") == 0) {
rt_opt->save_poly = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->output_file, argv[count]);
}
else if (strcmp(argv[count],"--output") == 0) {
rt_opt->write_tri = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->tri_file, argv[count]);
}
else if (strcmp(argv[count],"--out_dxf") == 0) {
rt_opt->write_dxf = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->tri_file, argv[count]);
}
else if (strcmp(argv[count],"--step") == 0) {
++count;
if ((success = (count < argc)))
rt_opt->step_size = atoi(argv[count]);
if (rt_opt->step_size < 1) rt_opt->step_size = 1;
}
else if (strcmp(argv[count],"--input") == 0) {
rt_opt->read_input = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->input_file, argv[count]);
}
else if (strcmp(argv[count],"--dxf") == 0) {
rt_opt->read_dxf = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->input_file, argv[count]);
}
else if (strcmp(argv[count],"--poly") == 0) {
rt_opt->read_poly = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->input_file, argv[count]);
}
else if (strcmp(argv[count],"--lines") == 0) {
rt_opt->read_lines = true;
++count;
if ((success = (count < argc)))
strcpy(rt_opt->input_file, argv[count]);
}
#if defined(WITH_COREBACKEND) || defined(WITH_EXPR_WRAPPER)
else if (strcmp(argv[count],"--inputprec") == 0) {
++count;
if ((success = (count < argc)))
rt_opt->inputprec = atoi(argv[count]);
if (rt_opt->inputprec < -1) rt_opt->inputprec = -1;
}
#endif
#if defined(WITH_MPFRBACKEND) || defined(WITH_EXPR_WRAPPER)
else if (strcmp(argv[count],"--mpfr-prec") == 0) {
++count;
if ((success = (count < argc)))
rt_opt->mpfr_prec = atoi(argv[count]);
if (rt_opt->mpfr_prec < 23) {
fprintf(stderr, "MPFR precision below 23 not supported\n");
exit(1);
}
}
#endif
else {
success = false;
}
++count;
}
if (rt_opt->full_screen) rt_opt->graphics = true;
if (!rt_opt->graphics) rt_opt->step_size = INT_MAX;
if (rt_opt->ears_top) {
rt_opt->ears_sorted = true;
rt_opt->ears_random = false;
rt_opt->ears_fancy = false;
}
else if (rt_opt->ears_fancy) {
rt_opt->ears_sorted = true;
rt_opt->ears_random = false;
rt_opt->ears_top = false;
}
if (rt_opt->keep_convex) {
if (rt_opt->write_geom && !rt_opt->quiet)
fprintf(stderr, "output for Geomview not supported with `--convex'\n");
rt_opt->write_geom = false;
if (rt_opt->sgi_output && !rt_opt->quiet)
fprintf(stderr, "output in SGO format not supported with `--convex'\n");
rt_opt->sgi_output = false;
}
return success;
}
void EvalError(void)
{
fprintf(stderr,
"\nUsage: triangulation [--help] [--b+w] [--geom] [--OGL] ");
fprintf(stderr,"[--step n] [--stat]\n");
fprintf(stderr,
" [--time] [--verbose] [--c2p XXX]\n");
fprintf(stderr,
" [--obj XXX|--poly XXX|--input XXX|--dxf XXX|--lines XXX]\n");
fprintf(stderr,
" [--save XXX] [--output XXX|--out_dxf XXX ] ");
fprintf(stderr,
"[--Ipe XXX] [--sgi]\n");
fprintf(stderr,
" [--sorted|--random|--sequen|--fancy|--top] [--scale]\n");
fprintf(stderr,
" [--color] [--full]");
#ifndef NORMALS
fprintf(stderr,
" [--convex] [--quads] [--keep_quads]");
#endif
#ifdef WITH_MPFRBACKEND
fprintf(stderr,
" [--mpfr-prec NNN]\n");
#elif defined(WITH_COREBACKEND)
fprintf(stderr,
" [--inputprec NNN]\n");
#endif
fprintf(stderr, "\n");
fprintf(stderr,
" [--draw_groups] [--concave] [--quiet]\n\n");
fprintf(stderr,
"--help: causes the program to print a help message\n");
fprintf(stderr,
"--quiet: do not print warning messages to stdout/stderr\n");
fprintf(stderr,
"--b+w: b/w rather than color graphics\n");
fprintf(stderr,
"--verbose: write warning messages to stdout\n");
fprintf(stderr,
"--OGL: enable an interactive OpenGL display\n");
fprintf(stderr,
"--full: run in full-screen mode\n");
fprintf(stderr,
"--time: time the computation of the triangulation\n");
fprintf(stderr,
"--stat: compute and output some statistics\n");
fprintf(stderr,
"--c2p: clean and convert input to triangle's .poly format\n");
fprintf(stderr,
"--Ipe XXX: write data in Ipe 7.0 format to file `XXX'\n");
fprintf(stderr,
"--geom: write data in Geomview format to `triang.geo'\n");
fprintf(stderr,
"--scale: scale the data within FIST to the unit square\n");
fprintf(stderr,
"--draw_groups: color triangles in Geomview according to their ");
fprintf(stderr,
".obj groups\n");
fprintf(stderr,
"--sorted: clip ears according to Martin's quality ");
fprintf(stderr,
"heuristic; default\n");
fprintf(stderr,
"--fancy: clip ears according to Martin's enhanced ");
fprintf(stderr,
"quality heuristic\n");
fprintf(stderr,
"--top: clip ears according to Martin's newest ");
fprintf(stderr,
"top-quality heuristic\n");
fprintf(stderr,
"--random: clip ears in random order\n");
fprintf(stderr,
"--sequen: clip ears in the order in which they are ");
fprintf(stderr,
"discovered\n");
fprintf(stderr,
"--step n: clip `n' ears at a time before OpenGL redrawing\n");
fprintf(stderr,
"--input XXX: read polygons in Martin's format from file `XXX'\n");
fprintf(stderr,
"--dxf XXX: read .dxf data from file `XXX'\n");
fprintf(stderr,
"--poly XXX: read a polygon in Martin's simplified format from file `XXX'\n");
fprintf(stderr,
"--lines XXX: read polygons in Martin's .line format from file `XXX'\n");
fprintf(stderr,
"--obj XXX: read polyhedron in obj-format from file `XXX'\n");
fprintf(stderr,
"--save XXX: save polygons in Martin's .line format to file ");
fprintf(stderr,
"`XXX'\n");
fprintf(stderr,
"--output XXX: write triangles in obj-format to file `XXX'\n");
fprintf(stderr,
"--out_dxf XXX: write (2D) triangles in .dxf-format to file `XXX'\n");
fprintf(stderr,
"--sgi: write triangles in SGI's SGO format (rather ");
fprintf(stderr,
"than .obj format)\n");
#ifdef WITH_COREBACKEND
fprintf(stderr,
"--inputprec n: Input precision (CORE library). -1 for CORE_INFTY\n");
#elif defined(WITH_MPFRBACKEND)
fprintf(stderr,
"--mpfr-prec n: Precision to use in MPFR backend, must be at least 23\n");
#endif
#ifndef NORMALS
fprintf(stderr,
"--quads: group the generated triangles into quads\n");
fprintf(stderr,
"--keep_quads: preserve quads and keep as pairs of triangles\n");
fprintf(stderr,
"--convex: keep convex faces untriangulated\n");
#endif
fprintf(stderr,
"--color: color the triangles in Geomview according to ");
fprintf(stderr,
"the face type\n");
fprintf(stderr,
"--concave: draw only the concave faces in Geomview\n");
fprintf(stderr,
"\nThe options `--OGL', `--Ipe', and `--save XXX' do not ");
fprintf(stderr,
"work in conjunction with\n");
fprintf(stderr,
"option `--obj'; the options `--step n' and `--b&w' require ");
fprintf(stderr,
"the option `--OGL'!\n");
fprintf(stderr,
"Also, the option `--obj XXX' supersedes the option ");
fprintf(stderr,
"`--input XXX'! The option\n");
fprintf(stderr,
"`--time' only works with OpenGL graphics being disabled. The ");
fprintf(stderr,
"options `--quads',\n");
fprintf(stderr,
"`--keep_quads' and `--color' only work with `--obj XXX'. Also, ");
fprintf(stderr,
"`--color' is\n");
fprintf(stderr,
"`meaningless unless `--geom' is used. When using `--concave' in ");
fprintf(stderr,
"conjunction\n");
fprintf(stderr,
"with `--color', only the concave faces will be drawn. Note that ");
fprintf(stderr,
"the run-time\n");
fprintf(stderr,
"options `--quads', `--keep_quads' and `--convex' are not ");
fprintf(stderr,
"available when\n");
fprintf(stderr,
"the code has been compiled with the compile-time option `-DNORMALS'.\n\n\n");
return;
}