3
* This file is part of jReality. jReality is open source software, made
4
* available under a BSD license:
6
* Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
7
* Schmies, Steffen Weissmann.
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions are met:
14
* - Redistributions of source code must retain the above copyright notice, this
15
* list of conditions and the following disclaimer.
17
* - Redistributions in binary form must reproduce the above copyright notice,
18
* this list of conditions and the following disclaimer in the documentation
19
* and/or other materials provided with the distribution.
21
* - Neither the name of jReality nor the names of its contributors nor the
22
* names of their associated organizations may be used to endorse or promote
23
* products derived from this software without specific prior written
26
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
* POSSIBILITY OF SUCH DAMAGE.
41
package opencog.spacetime.io.in;
43
import java.awt.Color;
44
import java.io.BufferedReader;
45
import java.io.IOException;
46
import java.io.InputStream;
47
import java.io.InputStreamReader;
48
import java.io.Reader;
49
import java.io.StreamTokenizer;
50
import java.util.logging.Level;
52
import opencog.math.Rn;
53
import opencog.spacetime.geometry.IndexedFaceSetFactory;
54
import opencog.spacetime.geometry.Primitives;
55
import opencog.spacetime.geometry.QuadMeshFactory;
56
import opencog.spacetime.space.IndexedFaceSet;
57
import opencog.spacetime.space.IndexedLineSet;
58
import opencog.spacetime.space.SpaceComponent;
59
import opencog.spacetime.space.Transformation;
60
import opencog.spacetime.space.data.Attribute;
61
import opencog.spacetime.space.data.StorageModel;
62
import opencog.spacetime.util.Input;
63
import opencog.spacetime.util.LoggingSystem;
64
import opencog.spacetime.util.SceneGraphUtility;
70
* A rudimentary reader for OOGL files (Geomview format).
72
* Needs to be converted to a real parser, e.g., by
73
* using the antlr parsing package.
75
* Current limitations: handles only following types: "OFF", "MESH", "VECT", "LIST", "inst", "tlist".
76
* @author Charles Gunn
79
public class ReaderMSMS extends AbstractReader {
81
public void setInput(Input input) throws IOException {
82
super.setInput(input);
83
root = load(input.getInputStream());
90
SpaceComponent load(InputStream inputStream) {
91
Reader r = new BufferedReader(new InputStreamReader(inputStream));
93
StreamTokenizer st = new StreamTokenizer(r);
96
st.eolIsSignificant(false);
97
st.wordChars('0', '9');
98
st.wordChars('A', 'Z');
99
st.wordChars('a' , 'z');
100
st.wordChars('.','.');
101
st.wordChars('-','-');
102
st.wordChars('+','+');
103
st.wordChars('\u00A0', '\u00FF' );
104
st.ordinaryChar('=');
105
st.ordinaryChar('{');
106
st.ordinaryChar('}');
107
st.whitespaceChars('\u0000', '\u0020');
111
SpaceComponent current= null;
112
LoggingSystem.getLogger(ReaderMSMS.class).log(Level.FINER,"start.");
114
current =SceneGraphUtility.createFullSceneGraphComponent("MSMS-node");
115
//LoggingSystem.getLogger().log(Level.FINER,"found object!");
117
double density, probeRadius;
119
numV = Integer.parseInt(st.sval);
121
numS = Integer.parseInt(st.sval);
123
density = Double.parseDouble(st.sval);
125
probeRadius = Double.parseDouble(st.sval);
126
double[][] verts = new double[numV][3],
127
normals = new double[numV][3];
128
int[] nearestSphere = new int[numV], vertexType = new int[numV];
129
for (int i=0; i<numV; ++i) {
130
for (int j = 0; j<3; ++j) {
132
//LoggingSystem.getLogger().log(Level.FINER,"Token is "+st.sval);
133
verts[i][j] = Double.parseDouble(st.sval);
135
for (int j = 0; j<3; ++j) {
137
//LoggingSystem.getLogger().log(Level.FINER,"Token is "+st.sval);
138
normals[i][j] = Double.parseDouble(st.sval);
142
nearestSphere[i] = Integer.parseInt(st.sval);
144
vertexType[i] = Integer.parseInt(st.sval);
149
numF = Integer.parseInt(st.sval);
150
// skip over redundant fields
154
int[][] indices = new int[numF][3];
155
int[] faceType = new int[numF];
156
Color[] facec = new Color[numF];
158
new Color(255,55,0), new Color(100,255,0), new Color(50,50,255),
159
new Color(255,200,0), new Color(255,0,255), new Color(0,255,255)};
160
for (int i = 0; i<numF; ++i) {
161
for (int j = 0; j<3; ++j) {
163
indices[i][j] = Integer.parseInt(st.sval) - 1;
166
faceType[i] = Integer.parseInt(st.sval);
167
facec[i] = colors[faceType[i] % colors.length];
171
LoggingSystem.getLogger(ReaderMSMS.class).log(Level.INFO,"Read "+numV+" vertices and "+numF+" faces");
172
IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
173
ifsf.setVertexCount(verts.length);
174
ifsf.setVertexCoordinates(verts);
175
ifsf.setVertexNormals(normals);
176
ifsf.setFaceCount(indices.length);
177
ifsf.setFaceIndices(indices);
178
// ifsf.setFaceColors(facec);
179
ifsf.setGenerateEdgesFromFaces(true);
180
ifsf.setGenerateFaceNormals(true);
182
IndexedFaceSet ifs = ifsf.getIndexedFaceSet();
183
ifs.setName("OFF Geometry");
184
current.setGeometry(ifs);
185
} catch (IOException e) {