Debian Codegraph @

apps/tools/ivnorm/ivnorm.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 //
38 //______________________________________________________________________
39 //_____________ S I L I C O N G R A P H I C S I N C . ____________
40 //
41 // $Source: /oss/CVS/cvs/inventor/apps/tools/ivnorm/ivnorm.c++,v $
42 // $Revision: 1.3 $
43 // $Date: 2001/09/25 00:45:30 $
44 //
45 // ivnorm
46 //
47 // This is the mainline for the IRIS Inventor `ivnorm' program.
48 // This program reads an Inventor data file, finds all of the
49 // indexed face set nodes, generates normals for each, and writes the
50 // result in tact (it does not remove any properties or hierarchy)
51 // to a new file.
52 //
53 // Author(s) : Gavin Bell
54 //
55 // Notes:
56 //
57 //_____________ S I L I C O N G R A P H I C S I N C . ____________
58 //______________________________________________________________________
59
60 #include <cstdio>
61 #include <unistd.h>
62 #include <cmath>
63 #include <assert.h>
64 #include <cstdlib>
65
66 #include <Inventor/SoInteraction.h>cxx . . $ `<file>/lib/interaction/include/Inventor/SoInteraction.h`/
67 #include <Inventor/SoDB.h>cxx . . $ `<file>/lib/database/include/Inventor/SoDB.h`/
68 #include <Inventor/SoInput.h>cxx . . $ `<file>/lib/database/include/Inventor/SoInput.h`/
69 #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/
70
71 #include "FindNormals.h"cxx . . $ `<file>/apps/tools/ivnorm/FindNormals.h`/
72
73 Facecxx . . $ Face#::Orientationcxx . . $ Face#Orientation# orientationcxx . . $ orientation. = Facecxx . . $ Face#::UNKNOWNcxx . . $ Face#UNKNOWN.;
74 float creaseAnglecxx . . $ creaseAngle. = M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`!/6.0; // 30 degrees
75 int findVNormscxx . . $ findVNorms. = 0;
76 int verbosecxx . . $ verbose. = 0;
77 char *inFileNamecxx . . $ inFileName. = "stdin";
78 char *outFileNamecxx . . $ outFileName. = "stdout";
79
80 //-----------------------------------------------------------------------------
81 //
82 // My standard command-line parser for tools that can take two
83 // filenames or act as a filter.
84 //
85 //-----------------------------------------------------------------------------
86 static void
87 ParseCommandLinecxx . . $ ParseCommandLine(b5b3cbfb2ba850bd).(int argc, char **argv, FILE **in, FILE **out)
88 {
89 int err; /* Flag: error in options? */
90 int c;
91 *in = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!;
92 *out = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!;
93 err = 0;
94
95 while ((c = getopt(argc, argv, "cCva:bVh")) != -1)
96 {
97 switch(c)
98 {
99 case 'c':
100 orientationcxx . . $ orientation. = Facecxx . . $ Face#::CCWcxx . . $ Face#CCW.;
101 break;
102 case 'C':
103 orientationcxx . . $ orientation. = Facecxx . . $ Face#::CWcxx . . $ Face#CW.;
104 break;
105 case 'v':
106 findVNormscxx . . $ findVNorms. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
107 break;
108 case 'a':
109 findVNormscxx . . $ findVNorms. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
110 // convert from given arg (in degrees) to radians
111 creaseAnglecxx . . $ creaseAngle. = atof(optarg) * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! / 180.0;
112 break;
113 case 'V':
114 verbosecxx . . $ verbose. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
115 break;
116 case 'h': /* Help */
117 default:
118 err = 1;
119 break;
120 }
121 }
122 /* Handle optional filenames */
123 for (; optind < argc; optind++)
124 {
125 if (*in == stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)
126 {
127 inFileNamecxx . . $ inFileName. = argv[optind];
128 *in = fopen(inFileNamecxx . . $ inFileName., "r");
129 if (*in == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
130 {
131 char buf[500];
132 sprintf(buf, "%s: %s", argv[0], inFileNamecxx . . $ inFileName.);
133 perror(buf);
134 exit(99);
135 }
136 }
137 else if (*out == stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!)
138 {
139 outFileNamecxx . . $ outFileName. = argv[optind];
140 *out = fopen(outFileNamecxx . . $ outFileName., "w");
141 if (*out == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
142 {
143 char buf[500];
144 sprintf(buf, "%s: %s", argv[0], outFileNamecxx . . $ outFileName.);
145 perror(buf);
146 exit(99);
147 }
148 }
149 else err = 1; /* Too many arguments */
150 }
151
152 /* If stdin is a terminal, spit out usage */
153 if (*in == stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`! && isatty(fileno(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!))) err = 1;
154
155 if (err)
156 {
157 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage: %s [options]", argv[0]);
158 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " [infile] [outfile]\n");
159 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-c Assume counter-clockwise faces\n");
160 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-C Assume clockwise faces\n");
161 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-v Find vertex normals\n");
162 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-a angle Use angle (in degrees)"
163 " as crease angle\n");
164 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-V verbose trace\n");
165 (void)fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "-h This message (help)\n");
166 exit(99);
167 }
168 }
169
170
171 int
172 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
173 {
174 FILE *fin;
175 FILE *fout;
176
177 SoInteractioncxx . . $ SoInteraction#::initcxx . . $ SoInteraction#init(49f6e7a06ebc5aa8).();
178
179 ParseCommandLinecxx . . $ ParseCommandLine(b5b3cbfb2ba850bd).(argc, argv, &fin, &fout);
180
181 SoNodecxx . . $ SoNode# *node = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
182 SbBoolcxx . . $ SbBool# ok;
183
184 SoInputcxx . . $ SoInput# incxx . . $ SoInput#SoInput(49f6e7a06ebc5aa8).;
185 in.setFilePointercxx . . $ SoInput#setFilePointer(8d4262d45fc644ab).(fin);
186
187 SoOutputcxx . . $ SoOutput# outcxx . . $ SoOutput#SoOutput(49f6e7a06ebc5aa8).;
188 out.setFilePointercxx . . $ SoOutput#setFilePointer(8d4262d45fc644ab).(fout);
189 SoWriteActioncxx . . $ SoWriteAction# wacxx . . $ SoWriteAction#SoWriteAction(46d85c4d426f339d).(&out);
190
191 FindNormalscxx . . $ FindNormals# normalFindercxx . . $ FindNormals#FindNormals(49f6e7a06ebc5aa8).;
192 normalFinder.AssumeOrientationcxx . . $ FindNormals#AssumeOrientation(5d3e26acd51309dc).(orientationcxx . . $ orientation.);
193 normalFinder.setCreaseAnglecxx . . $ FindNormals#setCreaseAngle(9364e6e7bff7660).(creaseAnglecxx . . $ creaseAngle.);
194 normalFinder.setVerbosecxx . . $ FindNormals#setVerbose(d4f767463ce0a6b3).(verbosecxx . . $ verbose.);
195
196 for (;;) {
197 if (verbosecxx . . $ verbose.) fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: reading graph from '%s'.\n", argv[0], inFileNamecxx . . $ inFileName.);
198 ok = SoDBcxx . . $ SoDB#::readcxx . . $ SoDB#read(37dc7a38c6a5bc19).(&in, node);
199 if (verbosecxx . . $ verbose.) fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: finished reading graph from '%s'.\n", argv[0], inFileNamecxx . . $ inFileName.);
200 if (!ok || !node)
201 break;
202
203 node->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
204 // Generate normals
205 normalFinder.applycxx . . $ FindNormals#apply(de18c6a3dadfdca6).(node, findVNormscxx . . $ findVNorms.);
206
207 // Write out the (modified) scene graph
208 if (verbosecxx . . $ verbose.) fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: writing graph to '%s'.\n", argv[0], outFileNamecxx . . $ outFileName.);
209 out.setBinarycxx . . $ SoOutput#setBinary(d4f767463ce0a6b3).(in.isBinarycxx . . $ SoInput#isBinary(b126dc7c1de90089).());
210 wa.applycxx . . $ SoAction#apply(da6c7544ccee32bd).(node);
211 if (verbosecxx . . $ verbose.) fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: finished writing graph to '%s'.\n", argv[0], outFileNamecxx . . $ outFileName.);
212 }
213
214 if (!ok)
215 {
216 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Bad data.\n");
217 return 1;
218 }
219
220 return 0;
221 }