2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.geom
;
9 import gov
.nasa
.worldwind
.*;
10 import gov
.nasa
.worldwind
.layers
.*;
12 import javax
.media
.opengl
.*;
14 import java
.awt
.image
.*;
17 import com
.sun
.opengl
.util
.texture
.*;
21 * @version $Id: SurfaceShape.java 1767 2007-05-07 21:36:12Z tgaskins $
23 public abstract class SurfaceShape
implements Renderable
, Disposable
25 private static final Color DEFAULT_COLOR
= new Color(1f
, 1f
, 0f
, 0.4f
);
26 private static final Color DEFAULT_BORDER_COLOR
= new Color(1f
, 1f
, 0f
, 0.7f
);
27 private static final int DEFAULT_TEXTURE_SIZE
= 512;
28 private static final int DEFAULT_NUM_EDGE_INTERVALS
= 10;
30 private TextureTile tile
;
31 private int textureSize
= DEFAULT_TEXTURE_SIZE
;
33 private Color borderColor
;
34 private Stroke stroke
= new BasicStroke();
35 private boolean drawBorder
= true;
36 private boolean drawInterior
= true;
37 private boolean antiAlias
= true;
38 private int numEdgeIntervals
= DEFAULT_NUM_EDGE_INTERVALS
;
39 private ArrayList
<LatLon
> positions
= new ArrayList
<LatLon
>();
41 protected abstract BufferedImage
drawShape(BufferedImage image
);
43 public SurfaceShape(Iterable
<LatLon
> positions
, Color color
, Color borderColor
)
45 if (positions
== null)
47 String message
= WorldWind
.retrieveErrMsg("nullValue.PositionsListIsNull");
48 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
49 throw new IllegalArgumentException(message
);
52 createTextureTiles(Sector
.boundingSector(positions
));
53 this.paint
= color
!= null ? color
: DEFAULT_COLOR
;
54 this.borderColor
= borderColor
!= null ? borderColor
: DEFAULT_BORDER_COLOR
;
56 for (LatLon p
: positions
)
58 this.positions
.add(p
);
62 private void createTextureTiles(Sector sector
)
64 this.tile
= new TextureTile(sector
);
69 if (this.tile
!= null)
73 public Sector
getSector()
75 return this.tile
.getSector();
78 public ArrayList
<LatLon
> getPositions()
83 private TextureTile
getTextureTile()
88 public Paint
getPaint()
93 public void setPaint(Paint paint
)
96 this.getTextureTile().setTextureData(null);
99 public Color
getBorderColor()
104 public void setBorderColor(Color borderColor
)
106 this.borderColor
= borderColor
;
107 this.getTextureTile().setTextureData(null);
110 public int getTextureSize()
115 public void setTextureSize(int textureSize
)
117 this.textureSize
= textureSize
;
118 this.getTextureTile().setTextureData(null);
121 public Stroke
getStroke()
126 public void setStroke(Stroke stroke
)
128 this.stroke
= stroke
;
129 this.getTextureTile().setTextureData(null);
132 public boolean isDrawBorder()
137 public void setDrawBorder(boolean drawBorder
)
139 this.drawBorder
= drawBorder
;
142 public boolean isDrawInterior()
147 public void setDrawInterior(boolean drawInterior
)
149 this.drawInterior
= drawInterior
;
152 public boolean isAntiAlias()
157 public void setAntiAlias(boolean antiAlias
)
159 this.antiAlias
= antiAlias
;
162 public int getNumEdgeIntervals()
164 return numEdgeIntervals
;
167 public void setNumEdgeIntervals(int numEdgeIntervals
)
169 this.numEdgeIntervals
= numEdgeIntervals
;
172 private boolean intersects(Sector sector
)
174 return this.tile
.getSector().intersects(sector
);
177 public void render(DrawContext dc
)
179 if (!this.intersects(dc
.getVisibleSector()))
182 if (this.getTextureTile().getTextureData() == null)
183 this.tile
.setTextureData(this.makeTextureData(this.textureSize
));
187 gl
.glPushAttrib(GL
.GL_COLOR_BUFFER_BIT
| GL
.GL_POLYGON_BIT
);
191 if (!dc
.isPickingMode())
193 gl
.glEnable(GL
.GL_BLEND
);
194 gl
.glBlendFunc(GL
.GL_SRC_ALPHA
, GL
.GL_ONE_MINUS_SRC_ALPHA
);
197 gl
.glPolygonMode(GL
.GL_FRONT
, GL
.GL_FILL
);
198 gl
.glEnable(GL
.GL_CULL_FACE
);
199 gl
.glCullFace(GL
.GL_BACK
);
201 dc
.getSurfaceTileRenderer().renderTile(dc
, this.tile
);
209 private TextureData
makeTextureData(int size
)
211 BufferedImage image
= new BufferedImage(size
, size
, BufferedImage
.TYPE_4BYTE_ABGR
);
213 TextureData td
= new TextureData(GL
.GL_RGBA
, GL
.GL_RGBA
, false, this.drawShape(image
));
214 td
.setMustFlipVertically(false);