Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / SectorGeometryList.java
blob9d471c563bd5238154636ef592e20d2a9e763e31
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind;
9 import gov.nasa.worldwind.geom.*;
11 import javax.media.opengl.*;
12 import java.awt.*;
13 import java.util.*;
14 import java.util.List;
16 /**
17 * @author tag
18 * @version $Id: SectorGeometryList.java 1994 2007-06-11 16:33:33Z dcollins $
20 public class SectorGeometryList extends ArrayList<SectorGeometry>
22 private PickSupport pickSupport = new PickSupport();
24 public SectorGeometryList()
28 public SectorGeometryList(SectorGeometryList list)
30 super(list);
33 public List<SectorGeometry> getIntersectingSectors(Sector sector)
35 ArrayList<SectorGeometry> list = null;
37 for (SectorGeometry sg : this)
39 if (sg.getSector().intersects(sector))
41 if (list == null)
42 list = new ArrayList<SectorGeometry>();
43 list.add(sg);
45 else
47 // System.out.println("no intersection");
51 return list;
54 public void pick(DrawContext dc, java.awt.Point pickPoint)
56 this.pickSupport.clearPickList();
57 this.pickSupport.beginPicking(dc);
59 GL gl = dc.getGL();
60 gl.glPushAttrib(GL.GL_LIGHTING_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_CURRENT_BIT);
61 gl.glEnable(GL.GL_DEPTH_TEST);
62 gl.glShadeModel(GL.GL_FLAT);
63 gl.glDisable(GL.GL_CULL_FACE);
65 try
67 // render each sector in unique color
68 for (SectorGeometry sector : this)
70 Color color = dc.getUniquePickColor();
71 dc.getGL().glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
72 sector.render(dc);
73 // lat/lon/elevation not used in this case
74 this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true);
77 PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint, null);
78 if (pickedSector == null || pickedSector.getObject() == null)
79 return; // no sector picked
81 SectorGeometry sector = (SectorGeometry) pickedSector.getObject();
82 gl.glDepthFunc(GL.GL_LEQUAL);
83 sector.pick(dc, pickPoint);
85 finally
87 gl.glPopAttrib();
88 this.pickSupport.endPicking(dc);
89 this.pickSupport.clearPickList();
93 public Vec4 getSurfacePoint(Position position)
95 return this.getSurfacePoint(position.getLatitude(), position.getLongitude(), position.getElevation());
98 public Vec4 getSurfacePoint(Angle latitude, Angle longitude)
100 return this.getSurfacePoint(latitude, longitude, 0d);
103 public Vec4 getSurfacePoint(Angle latitude, Angle longitude, double metersOffset)
105 if (latitude == null || longitude == null)
107 String msg = WorldWind.retrieveErrMsg("nullValue.LatLonIsNull");
108 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
109 throw new IllegalArgumentException(msg);
112 for (SectorGeometry sg : this)
114 if (sg.getSector().contains(latitude, longitude))
116 Vec4 point = sg.getSurfacePoint(latitude, longitude, metersOffset);
117 if (point != null)
118 return point;
122 return null;