Debian Codegraph @

apps/examples/Mentor/CXX/11.2.ReadString.c++

raw
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 * This is an example from the Inventor Mentor,
39 * chapter 11, example 2.
40 *
41 * Example of creatinge a scene graph by reading from a string.
42 * Create a dodecahedron, made of an IndexedFaceSet.
43 *------------------------------------------------------------*/
44
45 #include <cstdlib>
46 #include <cstring>
47
48 #include <Inventor/SoDB.h>
49 #include <Inventor/SoInput.h>
50 #include <Inventor/Xt/SoXt.h>
51 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
52 #include <Inventor/nodes/SoSeparator.h>
53
54 /////////////////////////////////////////////////////////////
55 // CODE FOR The Inventor Mentor STARTS HERE
56
57 // Reads a dodecahedron from the following string:
58 // (Note: ANSI compilers automatically concatenate
59 // adjacent string literals together, so the compiler sees
60 // this as one big string)
61
62 static char *dodecahedron =
63 "Separator {"
64 " Normal {"
65 " vector ["
66 " 0.553341 0 0.832955, 0.832955 0.553341 0,"
67 " 0.832955 -0.553341 0, 0 -0.832955 0.553341,"
68 " -0.553341 0 0.832955, 0 0.832955 0.553341,"
69 " 0 0.832955 -0.553341, -0.832955 0.553341 0,"
70 " -0.832955 -0.553341 0, 0 -0.832955 -0.553341,"
71 " 0.553341 0 -0.832955, -0.553341 0 -0.832955,"
72 " ]"
73 " }"
74 " NormalBinding { value PER_FACE }"
75 " Material {"
76 " diffuseColor ["
77 " 1 0 0, 0 1 0, 0 0 1, 0 1 1,"
78 " 1 0 1, .5 1 0, .5 0 1, .5 1 1,"
79 " 1 .3 .7, .3 1 .7, .3 .7 1, .5 .5 .8"
80 " ]"
81 " }"
82 " MaterialBinding { value PER_FACE }"
83 " Coordinate3 {"
84 " point ["
85 " 1.7265 0 0.618, 1 1 1,"
86 " 0 0.618 1.7265, 0 -0.618 1.7265,"
87 " 1 -1 1, -1 -1 1,"
88 " -0.618 -1.7265 0, 0.618 -1.7265 0,"
89 " 1 -1 -1, 1.7265 0 -0.618,"
90 " 1 1 -1, 0.618 1.7265 0,"
91 " -0.618 1.7265 0, -1 1 1,"
92 " -1.7265 0 0.618, -1.7265 0 -0.618,"
93 " -1 -1 -1, 0 -0.618 -1.7265,"
94 " 0 0.618 -1.7265, -1 1 -1"
95 " ]"
96 " }"
97 " IndexedFaceSet {"
98 " coordIndex ["
99 " 1, 2, 3, 4, 0, -1, 0, 9, 10, 11, 1, -1,"
100 " 4, 7, 8, 9, 0, -1, 3, 5, 6, 7, 4, -1,"
101 " 2, 13, 14, 5, 3, -1, 1, 11, 12, 13, 2, -1,"
102 " 10, 18, 19, 12, 11, -1, 19, 15, 14, 13, 12, -1,"
103 " 15, 16, 6, 5, 14, -1, 8, 7, 6, 16, 17, -1,"
104 " 9, 8, 17, 18, 10, -1, 18, 17, 16, 15, 19, -1,"
105 " ]"
106 " }"
107 "}";
108
109 // Routine to create a scene graph representing a dodecahedron
110 SoNode *
111 makeDodecahedron()
112 {
113 // Read from the string.
114 SoInput in;
115 in.setBuffer(dodecahedron, strlen(dodecahedron));
116
117 SoNode *result;
118 SoDB::read(&in, result);
119
120 return result;
121 }
122
123 // CODE FOR The Inventor Mentor ENDS HERE
124 /////////////////////////////////////////////////////////////
125
126 int
127 main(int argc, char **argv)
128 {
129 // Initialize Inventor and Xt
130 Widget myWindow = SoXt::init(argv[0]);
131 if (myWindow == NULL) exit(1);
132
133 SoNode *root = makeDodecahedron();
134 root->ref();
135
136 SoXtExaminerViewer *myViewer =
137 new SoXtExaminerViewer(myWindow);
138 myViewer->setSceneGraph(root);
139 myViewer->setTitle("String Reader");
140 myViewer->show();
141
142 SoXt::show(myWindow);
143 SoXt::mainLoop();
144 }