root / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / simbology3D / geometry3D / Abstract3DGeometry.java @ 20892
History | View | Annotate | Download (4.33 KB)
1 |
package com.iver.ai2.gvsig3d.simbology3D.geometry3D; |
---|---|
2 |
|
3 |
|
4 |
import java.awt.geom.PathIterator; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
|
8 |
import org.apache.log4j.Logger; |
9 |
import org.gvsig.osgvp.Group; |
10 |
import org.gvsig.osgvp.Node; |
11 |
import org.gvsig.osgvp.Vec3; |
12 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
13 |
import org.gvsig.osgvp.planets.Planet; |
14 |
|
15 |
import com.iver.ai2.gvsig3d.gui.Hud; |
16 |
import com.iver.ai2.gvsig3d.simbology3D.symbol3D.I3DSymbol; |
17 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
18 |
import com.iver.cit.gvsig.fmap.core.FShape; |
19 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
20 |
|
21 |
public abstract class Abstract3DGeometry implements I3DGeometry { |
22 |
|
23 |
private int geomType; |
24 |
private IGeometry geometry;
|
25 |
private boolean zEnable = false; |
26 |
|
27 |
private float vertEx = 1; |
28 |
private float heigth; |
29 |
private Planet planet;
|
30 |
|
31 |
private static Logger logger = Logger.getLogger(Abstract3DGeometry.class.getName()); |
32 |
|
33 |
public Abstract3DGeometry(IGeometry geometry) {
|
34 |
this.geometry = geometry;
|
35 |
} |
36 |
|
37 |
public Group generateGeometry(I3DSymbol symbol3D) { |
38 |
Group groupAux = new Group(); |
39 |
Node node = null;
|
40 |
|
41 |
if (geometry == null || symbol3D == null) |
42 |
return null; |
43 |
|
44 |
geomType = geometry.getGeometryType(); |
45 |
|
46 |
// Getting the Iterator
|
47 |
PathIterator theIteratorL = geometry.getPathIterator(null); |
48 |
|
49 |
double[] dataLine = new double[6]; |
50 |
List<Vec3> posi = new ArrayList<Vec3>(); |
51 |
int contH = 0; |
52 |
while (!theIteratorL.isDone()) {
|
53 |
int type = theIteratorL.currentSegment(dataLine);
|
54 |
|
55 |
Vec3 position = getGeometryPosition(geometry, dataLine, heigth, |
56 |
contH); |
57 |
// Adding points
|
58 |
switch (type) {
|
59 |
case PathIterator.SEG_MOVETO: |
60 |
// System.out.println("SEG_MOVETO");
|
61 |
node = symbol3D.generateSymbol(posi); |
62 |
if (node != null) { |
63 |
try {
|
64 |
groupAux.addChild(node); |
65 |
} catch (NodeException e) {
|
66 |
logger.error("Command:" + "Error setting new child.",e); |
67 |
} |
68 |
posi.clear(); |
69 |
posi = new ArrayList<Vec3>(); |
70 |
} |
71 |
posi.add(position); |
72 |
break;
|
73 |
|
74 |
case PathIterator.SEG_LINETO: |
75 |
// System.out.println("SEG_LINETO");
|
76 |
posi.add(position); |
77 |
break;
|
78 |
|
79 |
case PathIterator.SEG_QUADTO: |
80 |
// System.out.println("SEG_QUADTO");
|
81 |
break;
|
82 |
|
83 |
case PathIterator.SEG_CUBICTO: |
84 |
// System.out.println("SEG_CUBICTO");
|
85 |
break;
|
86 |
|
87 |
case PathIterator.SEG_CLOSE: |
88 |
// System.out.println("SEG_CLOSE");
|
89 |
break;
|
90 |
} |
91 |
contH++; |
92 |
theIteratorL.next(); |
93 |
} |
94 |
// System.out.println("Numero de puntos: " + contH);
|
95 |
|
96 |
// Adding last symbol
|
97 |
if (posi.size() > 0) { |
98 |
// if ((geomType & FShape.LINE) == FShape.LINE) {
|
99 |
// }
|
100 |
node = symbol3D.generateSymbol(posi); |
101 |
if (node != null) |
102 |
try {
|
103 |
groupAux.addChild(node); |
104 |
} catch (NodeException e) {
|
105 |
logger.error("Command:" + "Error adding new child.",e); |
106 |
} |
107 |
} |
108 |
return groupAux;
|
109 |
|
110 |
} |
111 |
|
112 |
public Vec3 getGeometryPosition(IGeometry geometry, double[] dataLine, |
113 |
float heigth, int contH) { |
114 |
// TRANSFORMANDO A GEOMETRIA CON VALOR Z
|
115 |
FGeometry g3D = null;
|
116 |
if (geometry instanceof FGeometry) { |
117 |
g3D = (FGeometry) geometry; |
118 |
} |
119 |
Vec3 posGeo = null;
|
120 |
Vec3 pos = null;
|
121 |
double h = 0; |
122 |
if (isZEnable()) {
|
123 |
if ((geomType & FShape.Z) == FShape.Z) {
|
124 |
if (g3D != null) { |
125 |
h = (g3D.getZs()[contH]) * vertEx; |
126 |
} |
127 |
} |
128 |
} else {
|
129 |
h = heigth; |
130 |
} |
131 |
|
132 |
if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
|
133 |
posGeo = new Vec3(dataLine[1], dataLine[0], h); |
134 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
135 |
} else {
|
136 |
pos = new Vec3(dataLine[0], dataLine[1], h); |
137 |
} |
138 |
return pos;
|
139 |
} |
140 |
|
141 |
public int getGeomType() { |
142 |
return geomType;
|
143 |
} |
144 |
|
145 |
public void setGeomType(int geomType) { |
146 |
this.geomType = geomType;
|
147 |
} |
148 |
|
149 |
public IGeometry getGeometry() {
|
150 |
return geometry;
|
151 |
} |
152 |
|
153 |
public void setGeometry(IGeometry geometry) { |
154 |
this.geometry = geometry;
|
155 |
} |
156 |
|
157 |
public boolean isZEnable() { |
158 |
return zEnable;
|
159 |
} |
160 |
|
161 |
public void setZEnable(boolean enable) { |
162 |
zEnable = enable; |
163 |
} |
164 |
|
165 |
public float getVertEx() { |
166 |
return vertEx;
|
167 |
} |
168 |
|
169 |
public void setVertEx(float vertEx) { |
170 |
this.vertEx = vertEx;
|
171 |
} |
172 |
|
173 |
public float getHeigth() { |
174 |
return heigth;
|
175 |
} |
176 |
|
177 |
public void setHeigth(float heigth) { |
178 |
this.heigth = heigth;
|
179 |
} |
180 |
|
181 |
public Planet getPlanet() {
|
182 |
return planet;
|
183 |
} |
184 |
|
185 |
public void setPlanet(Planet planet) { |
186 |
this.planet = planet;
|
187 |
} |
188 |
|
189 |
} |