Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libGPE-OSG / src / main / java / org / gvsig / driver / OSGDriver.java @ 29817

History | View | Annotate | Download (7.27 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *  osgVP. OSG Virtual Planets.
3
 *
4
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
5
 * of the Valencian Government (CIT)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 */
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Instituto de Automática e Informática Industrial, UPV.
26
 */
27

    
28
/**
29
 * 
30
 */
31
package org.gvsig.driver;
32

    
33
import java.awt.Color;
34
import java.awt.image.BufferedImage;
35

    
36
import org.gvsig.fmap.geom.aggregate.MultiSolid;
37
import org.gvsig.fmap.geom.primitive.Solid;
38
import org.gvsig.fmap.geom.primitive.Appearance.Material;
39
import org.gvsig.fmap.geom.primitive.impl.AbstractPrimitive;
40
import org.gvsig.geometries3D.MultiGeometry;
41
import org.gvsig.gpe.IGPEContentHandler3D;
42

    
43
import org.gvsig.gpe.parser.GPEContentHandler;
44

    
45
/**
46
 * @author rgaitan
47
 * 
48
 */
49
public class OSGDriver extends GPEContentHandler implements
50
                IGPEContentHandler3D {
51

    
52
        private MultiGeometry _root;
53

    
54
        @Override
55
        public Object startMultiGeometry(String id, String srs) {
56
//                Util.logger.log(Level.FINEST, "Starting MultiGeometry");
57
//                MultiGeometry feature = (MultiGeometry) ((GeometryFactory3D) GeometryManager
58
//                                .getInstance().getGeometryFactory()).createMultiGeometry(id);
59
//                if (_root == null)
60
//                        _root = feature;
61
//                return feature;
62
                return null;
63
        }
64

    
65
        public Object startMultiSolid(String id, String srs) {
66
//                Util.logger.log(Level.FINEST, "Starting MultiSolid");
67
//                return (MultiSolid) ((GeometryFactory3D) GeometryManager.getInstance()
68
//                                .getGeometryFactory()).createMultiSolid(id);
69
                return null;
70
        }
71

    
72
        public void endMultiSolid(Object solid) {
73
        }
74

    
75
        public Object startSolid(String id, String srs) {
76
                // Util.logger.log(Level.FINEST,"Starting Geometry");
77
//                Solid geometry = (Solid) ((GeometryFactory3D) GeometryManager
78
//                                .getInstance().getGeometryFactory()).createSolid(id);
79
//                return geometry;
80
        return null;
81
        }
82

    
83
        public void endSolid(Object geometry) {
84
                // Util.logger.log(Level.FINEST,"Ending Geometry");
85

    
86
        }
87

    
88
        @Override
89
        public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) {
90
                // Util.logger.log(Level.FINEST,"Adding Feature to Feature");
91
                ((MultiGeometry) multiGeometry)
92
                                .addGeometry((AbstractPrimitive) geometry);
93
        }
94

    
95
        public void addSolidToMultiSolid(Object solid, Object multiSolid) {
96
                // Util.logger.log(Level.FINEST,"Adding Geometry to Feature");
97
                ((MultiSolid) multiSolid).addSolid((Solid) solid);
98
        }
99

    
100
        public void startSolidVertexArray(Object geometry) {
101
        }
102

    
103
        public void endSolidVertexArray() {
104
        }
105

    
106
        public void startSolidNormalArray(Object geometry) {
107
        }
108

    
109
        public void endSolidNormalArray() {
110
        }
111

    
112
        public void startSolidColorArray(Object geometry) {
113

    
114
        }
115

    
116
        public void endSolidColorArray() {
117
        }
118

    
119
        public void startSolidTexCoordArray(Object geometry, int nTexCoords,
120
                        int stage) {
121
        }
122

    
123
        public void endSolidTexCoordArray() {
124
        }
125

    
126
        public void addVertexToSolid(Object geometry, double x, double y, double z) {
127

    
128
//                Point3D point = (Point3D) ((GeometryFactory3D) GeometryManager
129
//                                .getInstance().getGeometryFactory()).createPoint3D("");
130
//                point.setX(x);
131
//                point.setY(y);
132
//                point.setZ(z);
133
//                ((Solid) geometry).getVertices().add(point);
134
                // Util.logger.log(Level.FINEST,"Adding Vertex");
135
        }
136

    
137
        public void addNormalToSolid(Object geometry, double x, double y, double z) {
138
//                Point3D point = (Point3D) ((GeometryFactory3D) GeometryManager
139
//                                .getInstance().getGeometryFactory()).createPoint3D("");
140
//                point.setX(x);
141
//                point.setY(y);
142
//                point.setZ(z);
143
//                ((Solid) geometry).getNormals().add(point);
144
//                Util.logger.log(Level.FINEST, "Adding Normal" + point.getX());
145
        }
146

    
147
        public void addTextureToSolid(Object geometry, int stage,
148
                        BufferedImage image) {
149

    
150
//                ((Solid) geometry).getTextures().add(stage, image);
151

    
152
        }
153

    
154
        public void setNormalBindingToSolid(Object geometry, int mode) {
155

    
156
//                ((Solid) geometry).setNormalBinding(mode);
157

    
158
        }
159

    
160
        public void setColorBindingToSolid(Object geometry, int mode) {
161

    
162
//                ((Solid) geometry).setColorBinding(mode);
163

    
164
        }
165

    
166
        public void addColorToSolid(Object geometry, float r, float g, float b,
167
                        float a) {
168

    
169
//                ((Solid) geometry).getColors().add(convertColor(r, g, b, a));
170

    
171
        }
172

    
173
        public void addTextureCoordinateToSolid(Object geometry, double x,
174
                        double y, int stage) {
175
//                try {
176
//                        ((Solid) geometry).getTexcoord().get(stage);
177
//                } catch (ArrayIndexOutOfBoundsException ex) {
178
//                        ((Solid) geometry).getTexcoord().add(stage, new Vector<Point2D>());
179
//                }
180
//                Point2D point = new Point2D.Double();
181
//                point.setLocation(x, y);
182
//                ((Solid) geometry).getTexcoord().get(stage).add(point);
183

    
184
        }
185

    
186
        public MultiGeometry getRootFeature() {
187
                return _root;
188
        }
189

    
190
        public void addPrimitiveSetToSolid(Object geometry, Object primitiveSet) {
191
        //        ((Solid) geometry).getPrimitiveSets().add((PrimitiveSet) primitiveSet);
192
        }
193

    
194
        public void addIndexToPrimitiveSet(Object primitiveSet, int i) {
195
        //        ((PrimitiveSet) primitiveSet).getIndices().add(i);
196
        }
197

    
198
        public void endPrimitiveSet(Object primitiveSet) {
199
        }
200

    
201
        public void endPrimitiveSetIndexArray() {
202
        }
203

    
204
        public Object startPrimitiveSet(int mode, int type) {
205
        //        return new PrimitiveSet(mode, type);
206
                return null;
207
        }
208

    
209
        public void startPrimitiveSetIndexArray(Object primitiveSet, int indices) {
210
                //((PrimitiveSet) primitiveSet).setIndices(new Vector<Integer>());
211
        }
212

    
213
        public void addMaterialToSolid(Object solid, Object material) {
214
//                ((Solid) solid).setMaterial((Material) material);
215

    
216
        }
217

    
218
        public void endMaterial(Object material) {
219

    
220
        }
221

    
222
        public Object startMaterial() {
223
//                Material material = new Material();
224
//                return material;
225
                return null;
226
        }
227

    
228
        public void addAmbientToMaterial(Object material, float r, float g,
229
                        float b, float a) {
230

    
231
                ((Material) material).setAmbient(convertColor(r, g, b, a));
232

    
233
        }
234

    
235
        public void addDiffuseToMaterial(Object material, float r, float g,
236
                        float b, float a) {
237

    
238
                ((Material) material).setDiffuse(convertColor(r, g, b, a));
239

    
240
        }
241

    
242
        public void addEmissionToMaterial(Object material, float r, float g,
243
                        float b, float a) {
244

    
245
                ((Material) material).setEmission(convertColor(r, g, b, a));
246

    
247
        }
248

    
249
        public void addShininessToMaterial(Object material, float s) {
250

    
251
                ((Material) material).setShininess(s);
252

    
253
        }
254

    
255
        public void addSpecularToMaterial(Object material, float r, float g,
256
                        float b, float a) {
257

    
258
                ((Material) material).setSpecular(convertColor(r, g, b, a));
259

    
260
        }
261

    
262
        protected Color convertColor(float r, float g, float b, float a) {
263

    
264
                int _r, _g, _b, _a;
265

    
266
                _r = Math.min((int) (r * 255), 255);
267
                _g = Math.min((int) (g * 255), 255);
268
                _b = Math.min((int) (b * 255), 255);
269
                _a = Math.min((int) (a * 255), 255);
270

    
271
                Color color = new Color(_r, _g, _b, _a);
272

    
273
                return color;
274

    
275
        }
276

    
277
        public void addBlendingToSolid(Object solid, boolean blending) {
278

    
279
        //        ((Solid) solid).setBlending(blending);
280

    
281
        }
282

    
283
}