-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockinfo.c
130 lines (114 loc) · 4.36 KB
/
rockinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*************************************************************
*
* rockinfo.c - Dump out some key info for each input file
*
* Mark J. Stock, [email protected]
*
*
* rocktools - Tools for creating and manipulating triangular meshes
* Copyright (C) 1999,2004,2006,2008,2015,2021 Mark J. Stock
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*********************************************************** */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define INFO
#include "structs.h"
node_ptr node_head = NULL;
norm_ptr norm_head = NULL;
text_ptr text_head = NULL;
// this subroutine appears in this file
int Usage(char[MAX_FN_LEN],int);
const char* nice_print (const float _x) {
char* out = "10.2";
return out;
}
int main(int argc,char **argv) {
int doCM = FALSE;
int doNICE = FALSE;
int num_nodes = 0;
int num_tris = 0;
VEC bmax,bmin; // mesh bounds
VEC cm; // center of mass
float volume; // enclosed volume
char infile[MAX_FN_LEN]; // name of input file
char progname[MAX_FN_LEN]; // name of binary executable
/* Parse command-line args */
(void) strcpy(progname,argv[0]);
if (argc < 2) (void) Usage(progname,0);
if (strncmp(argv[1], "-help", 2) == 0)
(void) Usage(progname,0);
for (int i=2; i<argc; i++) {
if (strncmp(argv[i], "-cm", 2) == 0) {
doCM = TRUE;
} else if (strncmp(argv[i], "-nice", 2) == 0) {
doNICE = TRUE;
} else {
(void) Usage(progname,0);
}
}
(void) strcpy(infile,argv[1]);
// external subroutine does all the work
find_mesh_stats(infile,&bmin,&bmax,doCM,&cm,&volume,&num_tris,&num_nodes);
fprintf(stdout,"nodes %d tris %d ",num_nodes,num_tris);
fprintf(stdout,"x %g %g y %g %g z %g %g",bmin.x,bmax.x,bmin.y,bmax.y,bmin.z,bmax.z);
if (doCM) fprintf(stdout," cm %g %g %g vol %g",cm.x,cm.y,cm.z,volume);
if (doNICE) {
const float xc = 0.1*(bmax.x-bmin.x);
const float yc = 0.1*(bmax.y-bmin.y);
const float zc = 0.1*(bmax.z-bmin.z);
//fprintf(stdout,"\nModel measures %s x %s x %s cm (%s\" x %s\" x %s\")\n",
// nice_print(xc), nice_print(yc), nice_print(zc),
// nice_print(xc/2.54), nice_print(yc/2.54), nice_print(zc/2.54));
fprintf(stdout,"\nModel measures %.3g x %.3g x %.3g cm (%.3g\" x %.3g\" x %.3g\")\n",
xc, yc, zc, xc/2.54, yc/2.54, zc/2.54);
fprintf(stdout,"\nModel measures %.3g\" x %.3g\" x %.3g\" (%.3g x %.3g x %.3g cm)\n",
xc/2.54, yc/2.54, zc/2.54, xc, yc, zc);
}
fprintf(stdout,"\n");
exit(0);
}
/*
* This function writes basic usage information to stderr,
* and then quits. Too bad.
*/
int Usage(char progname[MAX_FN_LEN],int status) {
/* Usage for rockinfo */
static char **cpp, *help_message[] =
{
" -nice print the size nicely ",
" ",
" -cm also compute and print center of mass and volume ",
" ",
" -help (in place of infile) returns this help information ",
" ",
"The input file can be raw, tin, rad, or obj format, and the program requires",
" the input file to use its valid 3-character filename extension.",
" ",
"Options may be abbreviated to an unambiguous length (duh).",
"Output is to stdout",
NULL
};
fprintf(stderr, "usage:\n %s infile [-options]\n\n", progname);
for (cpp = help_message; *cpp; cpp++) {
fprintf(stderr, "%s\n", *cpp);
fflush(stderr);
}
exit(status);
return(0);
}