/** * Detects the locations of the sector geometries in this list that intersect a specified screen point. * <p/> * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be * called. * * @param dc the current draw context. * @param pickPoint the screen point to test. */ public void pick(DrawContext dc, java.awt.Point pickPoint) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (pickPoint == null) { return; } this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glShadeModel(GL2.GL_FLAT); try { // render each sector in unique color this.beginRendering(dc); foreach (SectorGeometry sector in this) { Color color = dc.getUniquePickColor(); gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()); sector.render(dc); // lat/lon/elevation not used in this case this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true); } PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint); if (pickedSector == null || pickedSector.getObject() == null) { return; // no sector picked } this.beginSectorGeometryPicking(dc); SectorGeometry sector = (SectorGeometry)pickedSector.getObject(); sector.pick(dc, pickPoint); } finally { this.endSectorGeometryPicking(dc); this.endRendering(dc); gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib this.pickSupport.endPicking(dc); this.pickSupport.clearPickList(); } }
public Object getTopObject() { PickedObject tpo = this.getTopPickedObject(); return(tpo != null?tpo.getObject() : null); }
/** * Detects the locations of the sector geometries in this list that intersect any of the points in a specified list * of screen points. * <p/> * Note: Prior to calling this method, {@link #beginRendering(gov.nasa.worldwind.render.DrawContext)} must be * called. * * @param dc the current draw context. * @param pickPoints the points to test. * * @return an array of picked objects that intersect one or more of the specified screen points. */ public List <PickedObject> pick(DrawContext dc, List <Point> pickPoints) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (pickPoints == null || pickPoints.Count < 1) { return(null); } this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glShadeModel(GL2.GL_FLAT); try { // render each sector in a unique color this.beginRendering(dc); foreach (SectorGeometry sector in this) { Color color = dc.getUniquePickColor(); gl.glColor3ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()); sector.render(dc); // lat/lon/elevation not used in this case this.pickSupport.addPickableObject(color.getRGB(), sector, Position.ZERO, true); } // Determine the sectors underneath the pick points. Assemble a pick-points per sector map. // Several pick points might intersect the same sector. this.pickSectors.Clear(); foreach (Point pickPoint in pickPoints) { PickedObject pickedSector = this.pickSupport.getTopObject(dc, pickPoint); if (pickedSector == null || pickedSector.getObject() == null) { continue; } SectorGeometry sector = (SectorGeometry)pickedSector.getObject(); List <Point> sectorPickPoints; if (!this.pickSectors.ContainsKey(sector)) { sectorPickPoints = new List <Point>(); this.pickSectors.Add(sector, sectorPickPoints); } else { this.pickSectors.TryGetValue(sector, out sectorPickPoints); } sectorPickPoints.Add(pickPoint); } if (this.pickSectors.Count < 1) { return(null); } // Now have each sector determine the pick position for each intersecting pick point. this.beginSectorGeometryPicking(dc); List <PickedObject> pickedObjects = new List <PickedObject>(); foreach (KeyValuePair <SectorGeometry, List <Point> > sector in this.pickSectors) { List <Point> sectorPickPoints = sector.Value; PickedObject[] pos = sector.Key.pick(dc, sectorPickPoints); if (pos == null) { continue; } foreach (PickedObject po in pos) { if (po != null) { pickedObjects.Add(po); } } } return(pickedObjects); } finally { this.endSectorGeometryPicking(dc); this.endRendering(dc); gl.glShadeModel(GL2.GL_SMOOTH); // restore to default explicitly to avoid more expensive pushAttrib this.pickSupport.endPicking(dc); this.pickSupport.clearPickList(); } }