Ejemplo n.º 1
0
  protected Angle computeIconRadius(DrawContext dc, double regionPixelSize, Sector drawSector) {
    double minCosLat =
        Math.min(drawSector.getMinLatitude().cos(), drawSector.getMaxLatitude().cos());
    if (minCosLat < 0.001) return Angle.POS180;

    Rectangle2D iconDimension = this.computeDrawDimension(regionPixelSize); // Meter
    double dLat = iconDimension.getHeight() / dc.getGlobe().getRadius();
    double dLon = iconDimension.getWidth() / dc.getGlobe().getRadius() / minCosLat;
    return Angle.fromRadians(Math.sqrt(dLat * dLat + dLon * dLon) / 2);
  }
Ejemplo n.º 2
0
  protected Vec4 computeReferencePoint(DrawContext dc) {
    if (dc.getViewportCenterPosition() != null)
      return dc.getGlobe().computePointFromPosition(dc.getViewportCenterPosition());

    java.awt.geom.Rectangle2D viewport = dc.getView().getViewport();
    int x = (int) viewport.getWidth() / 2;
    for (int y = (int) (0.5 * viewport.getHeight()); y >= 0; y--) {
      Position pos = dc.getView().computePositionFromScreenPoint(x, y);
      if (pos == null) continue;

      return dc.getGlobe().computePointFromPosition(pos.getLatitude(), pos.getLongitude(), 0d);
    }

    return null;
  }
Ejemplo n.º 3
0
  protected static boolean isTileVisible(
      DrawContext dc, Tile tile, double minDistanceSquared, double maxDistanceSquared) {
    if (!tile.getSector().intersects(dc.getVisibleSector())) return false;

    View view = dc.getView();
    Position eyePos = view.getEyePosition();
    if (eyePos == null) return false;

    Angle lat =
        clampAngle(
            eyePos.getLatitude(),
            tile.getSector().getMinLatitude(),
            tile.getSector().getMaxLatitude());
    Angle lon =
        clampAngle(
            eyePos.getLongitude(),
            tile.getSector().getMinLongitude(),
            tile.getSector().getMaxLongitude());
    Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
    double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
    //noinspection RedundantIfStatement
    if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

    return true;
  }
Ejemplo n.º 4
0
  /**
   * Generate the positions required to draw the line.
   *
   * @param dc Current draw context.
   * @param positions Positions that define the polygon boundary.
   */
  @Override
  protected void generateIntermediatePositions(
      DrawContext dc, Iterable<? extends Position> positions) {
    Globe globe = dc.getGlobe();

    boolean useDefaultWaveLength = false;
    double waveLength = this.getWaveLength();
    if (waveLength == 0) {
      waveLength = this.computeDefaultWavelength(positions, globe);
      useDefaultWaveLength = true;
    }

    // Generate lines that parallel the control line.
    List<Position> leftPositions = new ArrayList<Position>();
    List<Position> rightPositions = new ArrayList<Position>();
    this.generateParallelLines(
        positions.iterator(), leftPositions, rightPositions, waveLength / 2.0, globe);

    if (useDefaultWaveLength) waveLength = this.computeDefaultWavelength(leftPositions, globe);
    double radius = (waveLength) / 2.0;

    // Generate wavy line to the left of the control line.
    PositionIterator iterator = new PositionIterator(leftPositions, waveLength, globe);
    this.computedPositions =
        this.generateWavePositions(iterator, radius / globe.getRadius(), false);
    this.path.setPositions(this.computedPositions);

    if (useDefaultWaveLength) waveLength = this.computeDefaultWavelength(rightPositions, globe);
    radius = (waveLength) / 2.0;

    // Generate wavy line to the right of the control line.
    iterator = new PositionIterator(rightPositions, waveLength, globe);
    this.path2.setPositions(this.generateWavePositions(iterator, radius / globe.getRadius(), true));
  }
Ejemplo n.º 5
0
  /**
   * Compute the positions of the arrow head of the graphic's legs.
   *
   * @param dc Current draw context
   * @param base Position of the arrow's starting point.
   * @param tip Position of the arrow head tip.
   * @param arrowLength Length of the arrowhead as a fraction of the total line length.
   * @param arrowAngle Angle of the arrow head.
   * @return Positions required to draw the arrow head.
   */
  protected List<Position> computeArrowheadPositions(
      DrawContext dc, Position base, Position tip, double arrowLength, Angle arrowAngle) {
    // Build a triangle to represent the arrowhead. The triangle is built from two vectors, one
    // parallel to the
    // segment, and one perpendicular to it.

    Globe globe = dc.getGlobe();

    Vec4 ptA = globe.computePointFromPosition(base);
    Vec4 ptB = globe.computePointFromPosition(tip);

    // Compute parallel component
    Vec4 parallel = ptA.subtract3(ptB);

    Vec4 surfaceNormal = globe.computeSurfaceNormalAtPoint(ptB);

    // Compute perpendicular component
    Vec4 perpendicular = surfaceNormal.cross3(parallel);

    double finalArrowLength = arrowLength * parallel.getLength3();
    double arrowHalfWidth = finalArrowLength * arrowAngle.tanHalfAngle();

    perpendicular = perpendicular.normalize3().multiply3(arrowHalfWidth);
    parallel = parallel.normalize3().multiply3(finalArrowLength);

    // Compute geometry of direction arrow
    Vec4 vertex1 = ptB.add3(parallel).add3(perpendicular);
    Vec4 vertex2 = ptB.add3(parallel).subtract3(perpendicular);

    return TacticalGraphicUtil.asPositionList(globe, vertex1, vertex2, ptB);
  }
Ejemplo n.º 6
0
  protected void setDepthFunc(DrawContext dc, OrderedIcon uIcon, Vec4 screenPoint) {
    GL gl = dc.getGL();

    if (uIcon.icon.isAlwaysOnTop()) {
      gl.glDepthFunc(GL.GL_ALWAYS);
      return;
    }

    Position eyePos = dc.getView().getEyePosition();
    if (eyePos == null) {
      gl.glDepthFunc(GL.GL_ALWAYS);
      return;
    }

    double altitude = eyePos.getElevation();
    if (altitude < (dc.getGlobe().getMaxElevation() * dc.getVerticalExaggeration())) {
      double depth = screenPoint.z - (8d * 0.00048875809d);
      depth = depth < 0d ? 0d : (depth > 1d ? 1d : depth);
      gl.glDepthFunc(GL.GL_LESS);
      gl.glDepthRange(depth, depth);
    } else if (uIcon.eyeDistance > uIcon.horizonDistance) {
      gl.glDepthFunc(GL.GL_EQUAL);
      gl.glDepthRange(1d, 1d);
    } else {
      gl.glDepthFunc(GL.GL_ALWAYS);
    }
  }
  /**
   * Select the visible grid elements
   *
   * @param dc the current <code>DrawContext</code>.
   */
  protected void selectRenderables(DrawContext dc) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
    Sector vs = dc.getVisibleSector();
    OrbitView view = (OrbitView) dc.getView();
    // Compute labels offset from view center
    Position centerPos = view.getCenterPosition();
    Double pixelSizeDegrees =
        Angle.fromRadians(
                view.computePixelSizeAtDistance(view.getZoom())
                    / dc.getGlobe().getEquatorialRadius())
            .degrees;
    Double labelOffsetDegrees = pixelSizeDegrees * view.getViewport().getWidth() / 4;
    Position labelPos =
        Position.fromDegrees(
            centerPos.getLatitude().degrees - labelOffsetDegrees,
            centerPos.getLongitude().degrees - labelOffsetDegrees,
            0);
    Double labelLatDegrees = labelPos.getLatitude().normalizedLatitude().degrees;
    labelLatDegrees = Math.min(Math.max(labelLatDegrees, -76), 78);
    labelPos =
        new Position(
            Angle.fromDegrees(labelLatDegrees), labelPos.getLongitude().normalizedLongitude(), 0);

    if (vs != null) {
      for (GridElement ge : this.gridElements) {
        if (ge.isInView(dc)) {
          if (ge.renderable instanceof GeographicText) {
            GeographicText gt = (GeographicText) ge.renderable;
            if (labelPos.getLatitude().degrees < 72
                || "*32*34*36*".indexOf("*" + gt.getText() + "*") == -1) {
              // Adjust label position according to eye position
              Position pos = gt.getPosition();
              if (ge.type.equals(GridElement.TYPE_LATITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        pos.getLatitude().degrees,
                        labelPos.getLongitude().degrees,
                        pos.getElevation());
              else if (ge.type.equals(GridElement.TYPE_LONGITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        labelPos.getLatitude().degrees,
                        pos.getLongitude().degrees,
                        pos.getElevation());

              gt.setPosition(pos);
            }
          }

          this.graticuleSupport.addRenderable(ge.renderable, GRATICULE_UTM);
        }
      }
      // System.out.println("Total elements: " + count + " visible sector: " + vs);
    }
  }
Ejemplo n.º 8
0
  protected void requestTile(DrawContext dc, Tile tile) {
    Vec4 centroid = dc.getGlobe().computePointFromPosition(tile.getSector().getCentroid(), 0);
    if (this.getReferencePoint() != null)
      tile.setPriority(centroid.distanceTo3(this.getReferencePoint()));

    RequestTask task = new RequestTask(tile, this);
    this.getRequestQ().add(task);
  }
    @SuppressWarnings({"RedundantIfStatement"})
    public boolean isInView(DrawContext dc) {
      if (!viewFrustum.intersects(this.getExtent(dc.getGlobe(), dc.getVerticalExaggeration())))
        return false;

      // Check apparent size
      if (getSizeInPixels(dc) <= MIN_CELL_SIZE_PIXELS) return false;

      return true;
    }
Ejemplo n.º 10
0
  protected static boolean isNameVisible(
      DrawContext dc, PlaceNameService service, Position namePosition) {
    double elevation = dc.getVerticalExaggeration() * namePosition.getElevation();
    Vec4 namePoint =
        dc.getGlobe()
            .computePointFromPosition(
                namePosition.getLatitude(), namePosition.getLongitude(), elevation);
    Vec4 eyeVec = dc.getView().getEyePoint();

    double dist = eyeVec.distanceTo3(namePoint);
    return dist >= service.getMinDisplayDistance() && dist <= service.getMaxDisplayDistance();
  }
  protected void computeQuadSize(DrawContext dc) {
    if (this.positions == null) return;

    Iterator<? extends Position> iterator = this.positions.iterator();

    Position pos1 = iterator.next();
    Position pos2 = iterator.next();

    Angle angularDistance = LatLon.greatCircleDistance(pos1, pos2);
    double length = angularDistance.radians * dc.getGlobe().getRadius();

    this.quad.setWidth(length);
  }
Ejemplo n.º 12
0
  /**
   * Compute the lat/lon position of the view center
   *
   * @param dc the current DrawContext
   * @param view the current View
   * @return the ground position of the view center or null
   */
  protected Position computeGroundPosition(DrawContext dc, View view) {
    if (view == null) return null;

    Position groundPos =
        view.computePositionFromScreenPoint(
            view.getViewport().getWidth() / 2, view.getViewport().getHeight() / 2);
    if (groundPos == null) return null;

    double elevation =
        dc.getGlobe().getElevation(groundPos.getLatitude(), groundPos.getLongitude());
    return new Position(
        groundPos.getLatitude(),
        groundPos.getLongitude(),
        elevation * dc.getVerticalExaggeration());
  }
 public void computeZone(DrawContext dc) {
   try {
     Position centerPos = ((OrbitView) dc.getView()).getCenterPosition();
     if (centerPos != null) {
       if (centerPos.latitude.degrees <= UTM_MAX_LATITUDE
           && centerPos.latitude.degrees >= UTM_MIN_LATITUDE) {
         UTMCoord UTM =
             UTMCoord.fromLatLon(
                 centerPos.getLatitude(), centerPos.getLongitude(), dc.getGlobe());
         this.zone = UTM.getZone();
       } else this.zone = 0;
     }
   } catch (Exception ex) {
     this.zone = 0;
   }
 }
Ejemplo n.º 14
0
 /**
  * Compute the view range footprint on the globe.
  *
  * @param dc the current <code>DrawContext</code>
  * @param steps the number of steps.
  * @return an array list of <code>LatLon</code> forming a closed shape.
  */
 protected ArrayList<LatLon> computeViewFootPrint(DrawContext dc, int steps) {
   ArrayList<LatLon> positions = new ArrayList<LatLon>();
   Position eyePos = dc.getView().getEyePosition();
   Angle distance =
       Angle.fromRadians(
           Math.asin(
               dc.getView().getFarClipDistance()
                   / (dc.getGlobe().getRadius() + eyePos.getElevation())));
   if (distance.degrees > 10) {
     double headStep = 360d / steps;
     Angle heading = Angle.ZERO;
     for (int i = 0; i <= steps; i++) {
       LatLon p = LatLon.greatCircleEndPosition(eyePos, heading, distance);
       positions.add(p);
       heading = heading.addDegrees(headStep);
     }
     return positions;
   } else return null;
 }
Ejemplo n.º 15
0
  /**
   * Determine the positions that make up the arrowhead.
   *
   * @param dc Current draw context.
   * @param startPosition Position of the arrow's base.
   * @param endPosition Position of the arrow head tip.
   * @return Positions that define the arrowhead.
   */
  protected List<Position> computeArrowheadPositions(
      DrawContext dc, Position startPosition, Position endPosition) {
    Globe globe = dc.getGlobe();

    // Arrowhead looks like this:
    //                  _
    //        A\         | 1/2 width
    // ________B\       _|
    // Pt. 1    /
    //        C/
    //         | |
    //      Length

    Vec4 p1 = globe.computePointFromPosition(startPosition);
    Vec4 pB = globe.computePointFromPosition(endPosition);

    // Find vector in the direction of the arrow
    Vec4 vB1 = p1.subtract3(pB);

    double arrowLengthFraction = this.getArrowLength();

    // Find the point at the base of the arrowhead
    Vec4 arrowBase = pB.add3(vB1.multiply3(arrowLengthFraction));

    Vec4 normal = globe.computeSurfaceNormalAtPoint(arrowBase);

    // Compute the length of the arrowhead
    double arrowLength = vB1.getLength3() * arrowLengthFraction;
    double arrowHalfWidth = arrowLength * this.getArrowAngle().tanHalfAngle();

    // Compute a vector perpendicular to the segment and the normal vector
    Vec4 perpendicular = vB1.cross3(normal);
    perpendicular = perpendicular.normalize3().multiply3(arrowHalfWidth);

    // Find points A and C
    Vec4 pA = arrowBase.add3(perpendicular);
    Vec4 pC = arrowBase.subtract3(perpendicular);

    return TacticalGraphicUtil.asPositionList(globe, pA, pB, pC);
  }
  /** {@inheritDoc} */
  @Override
  protected void determineLabelPositions(DrawContext dc) {
    Position center = this.getReferencePosition();
    if (center == null) return;

    // Position the labels along a line radiating out from the center of the circle. The angle (60
    // degrees) is
    // chosen to match the graphic template defined by MIL-STD-2525C, pg. 613.
    double globeRadius = dc.getGlobe().getRadius();

    Angle labelAngle = this.getLabelAngle();

    int i = 0;
    for (SurfaceCircle ring : this.rings) {
      double radius = ring.getRadius();

      LatLon ll = LatLon.greatCircleEndPosition(center, labelAngle.radians, radius / globeRadius);

      this.labels.get(i).setPosition(new Position(ll, 0));
      i += 1;
    }
  }
  /**
   * Create the circles used to draw this graphic.
   *
   * @param dc Current draw context.
   */
  protected void createShapes(DrawContext dc) {
    if (this.positions == null) return;

    this.rings = new ArrayList<SurfaceCircle>();

    Iterator<? extends Position> iterator = this.positions.iterator();

    Position center = iterator.next();
    double globeRadius = dc.getGlobe().getRadius();

    while (iterator.hasNext()) {
      SurfaceCircle ring = this.createCircle();
      ring.setCenter(center);

      Position pos = iterator.next();
      Angle radius = LatLon.greatCircleDistance(center, pos);

      double radiusMeters = radius.radians * globeRadius;
      ring.setRadius(radiusMeters);

      this.rings.add(ring);
    }
  }
Ejemplo n.º 18
0
  protected List<Sector> computeSectors(DrawContext dc) {
    if (this.locations == null || !this.locations.iterator().hasNext()) return null;

    // Compute all locations bounding sector, then add some padding for the icon half diagonal
    // extent
    Sector sector = Sector.boundingSector(this.locations);
    // Compute padding
    double minCosLat = Math.min(sector.getMinLatitude().cos(), sector.getMaxLatitude().cos());
    minCosLat = Math.max(minCosLat, .01); // avoids division by zero at the poles
    Rectangle2D iconDimension = this.computeDrawDimension(dc, sector.getCentroid());
    double diagonalLength =
        Math.sqrt(
            iconDimension.getWidth() * iconDimension.getWidth()
                + iconDimension.getHeight() * iconDimension.getHeight());
    double padLatRadians = diagonalLength / 2 / dc.getGlobe().getRadius();
    double padLonRadians = diagonalLength / 2 / dc.getGlobe().getRadius() / minCosLat;
    // Apply padding to sector
    Angle minLat = sector.getMinLatitude().subtractRadians(padLatRadians);
    Angle maxLat = sector.getMaxLatitude().addRadians(padLatRadians);
    Angle minLon = sector.getMinLongitude().subtractRadians(padLonRadians);
    Angle maxLon = sector.getMaxLongitude().addRadians(padLatRadians);

    return this.computeNormalizedSectors(new Sector(minLat, maxLat, minLon, maxLon));
  }
Ejemplo n.º 19
0
    protected boolean isNavSectorVisible(
        DrawContext dc, double minDistanceSquared, double maxDistanceSquared) {
      if (!navSector.intersects(dc.getVisibleSector())) return false;

      View view = dc.getView();
      Position eyePos = view.getEyePosition();
      if (eyePos == null) return false;

      // check for eyePos over globe
      if (Double.isNaN(eyePos.getLatitude().getDegrees())
          || Double.isNaN(eyePos.getLongitude().getDegrees())) return false;

      Angle lat =
          clampAngle(eyePos.getLatitude(), navSector.getMinLatitude(), navSector.getMaxLatitude());
      Angle lon =
          clampAngle(
              eyePos.getLongitude(), navSector.getMinLongitude(), navSector.getMaxLongitude());
      Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
      double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
      //noinspection RedundantIfStatement
      if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

      return true;
    }
Ejemplo n.º 20
0
  // Rendering
  public void draw(DrawContext dc) {
    GL gl = dc.getGL();

    boolean attribsPushed = false;
    boolean modelviewPushed = false;
    boolean projectionPushed = false;

    try {
      gl.glPushAttrib(
          GL.GL_DEPTH_BUFFER_BIT
              | GL.GL_COLOR_BUFFER_BIT
              | GL.GL_ENABLE_BIT
              | GL.GL_TEXTURE_BIT
              | GL.GL_TRANSFORM_BIT
              | GL.GL_VIEWPORT_BIT
              | GL.GL_CURRENT_BIT);
      attribsPushed = true;

      gl.glDisable(GL.GL_TEXTURE_2D); // no textures

      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.size.width;
      double height = this.size.height;

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION);
      gl.glPushMatrix();
      projectionPushed = true;
      gl.glLoadIdentity();
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glPushMatrix();
      modelviewPushed = true;
      gl.glLoadIdentity();

      // Scale to a width x height space
      // located at the proper position on screen
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      gl.glScaled(scale, scale, 1);

      // Compute scale size in real world
      Position referencePosition = dc.getViewportCenterPosition();
      if (referencePosition != null) {
        Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition);
        Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget);
        this.pixelSize = dc.getView().computePixelSizeAtDistance(distance);
        Double scaleSize = this.pixelSize * width * scale; // meter
        String unitLabel = "m";
        if (this.unit.equals(UNIT_METRIC)) {
          if (scaleSize > 10000) {
            scaleSize /= 1000;
            unitLabel = "Km";
          }
        } else if (this.unit.equals(UNIT_IMPERIAL)) {
          scaleSize *= 3.280839895; // feet
          unitLabel = "ft";
          if (scaleSize > 5280) {
            scaleSize /= 5280;
            unitLabel = "mile(s)";
          }
        }

        // Rounded division size
        int pot = (int) Math.floor(Math.log10(scaleSize));
        if (!Double.isNaN(pot)) {
          int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1));
          double divSize = digit * Math.pow(10, pot);
          if (digit >= 5) divSize = 5 * Math.pow(10, pot);
          else if (digit >= 2) divSize = 2 * Math.pow(10, pot);
          double divWidth = width * divSize / scaleSize;

          // Draw scale
          if (!dc.isPickingMode()) {
            // Set color using current layer opacity
            Color backColor = this.getBackgroundColor(this.color);
            float[] colorRGB = backColor.getRGBColorComponents(null);
            gl.glColor4d(
                colorRGB[0],
                colorRGB[1],
                colorRGB[2],
                (double) backColor.getAlpha() / 255d * this.getOpacity());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawScale(dc, divWidth, height);

            colorRGB = this.color.getRGBColorComponents(null);
            gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());
            gl.glTranslated(-1d / scale, 1d / scale, 0d);
            this.drawScale(dc, divWidth, height);

            // Draw label
            String label = String.format("%.0f ", divSize) + unitLabel;
            gl.glLoadIdentity();
            gl.glDisable(GL.GL_CULL_FACE);
            drawLabel(
                dc,
                label,
                locationSW.add3(
                    new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0)));
          } else {
            // Picking
            this.pickSupport.clearPickList();
            this.pickSupport.beginPicking(dc);
            // Draw unique color across the map
            Color color = dc.getUniquePickColor();
            int colorCode = color.getRGB();
            // Add our object(s) to the pickable list
            this.pickSupport.addPickableObject(colorCode, this, referencePosition, false);
            gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
            gl.glTranslated((width - divWidth) / 2, 0d, 0d);
            this.drawRectangle(dc, divWidth, height);
            // Done picking
            this.pickSupport.endPicking(dc);
            this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
          }
        }
      }
    } finally {
      if (projectionPushed) {
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPopMatrix();
      }
      if (modelviewPushed) {
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPopMatrix();
      }
      if (attribsPushed) gl.glPopAttrib();
    }
  }
    public void selectRenderables(DrawContext dc) {
      try {
        OrbitView view = (OrbitView) dc.getView();
        // Compute easting and northing label offsets
        Double pixelSize = view.computePixelSizeAtDistance(view.getZoom());
        Double eastingOffset = view.getViewport().width * pixelSize * offsetFactorX / 2;
        Double northingOffset = view.getViewport().height * pixelSize * offsetFactorY / 2;
        // Derive labels center pos from the view center
        Position centerPos = view.getCenterPosition();
        double labelEasting;
        double labelNorthing;
        String labelHemisphere;
        if (this.zone > 0) {
          UTMCoord UTM =
              UTMCoord.fromLatLon(centerPos.getLatitude(), centerPos.getLongitude(), dc.getGlobe());
          labelEasting = UTM.getEasting() + eastingOffset;
          labelNorthing = UTM.getNorthing() + northingOffset;
          labelHemisphere = UTM.getHemisphere();
          if (labelNorthing < 0) {
            labelNorthing = 10e6 + labelNorthing;
            labelHemisphere = AVKey.SOUTH;
          }
        } else {
          UPSCoord UPS =
              UPSCoord.fromLatLon(centerPos.getLatitude(), centerPos.getLongitude(), dc.getGlobe());
          labelEasting = UPS.getEasting() + eastingOffset;
          labelNorthing = UPS.getNorthing() + northingOffset;
          labelHemisphere = UPS.getHemisphere();
        }

        Position labelPos;
        for (int i = 0; i < this.extremes.length; i++) {
          UTMExtremes levelExtremes = this.extremes[i];
          double gridStep = Math.pow(10, i);
          double gridStepTimesTen = gridStep * 10;
          String graticuleType = getTypeFor((int) gridStep);
          if (levelExtremes.minX <= levelExtremes.maxX) {
            // Process easting scale labels for this level
            for (double easting = levelExtremes.minX;
                easting <= levelExtremes.maxX;
                easting += gridStep) {
              // Skip multiples of ten grid steps except for last (higher) level
              if (i == this.extremes.length - 1 || easting % gridStepTimesTen != 0) {
                try {
                  labelPos = computePosition(this.zone, labelHemisphere, easting, labelNorthing);
                  if (labelPos == null) continue;
                  Angle lat = labelPos.getLatitude();
                  Angle lon = labelPos.getLongitude();
                  Vec4 surfacePoint = getSurfacePoint(dc, lat, lon);
                  if (viewFrustum.contains(surfacePoint) && isPointInRange(dc, surfacePoint)) {
                    String text = String.valueOf((int) (easting % this.scaleModulo));
                    GeographicText gt = new UserFacingText(text, new Position(lat, lon, 0));
                    gt.setPriority(gridStepTimesTen);
                    addRenderable(gt, graticuleType);
                  }
                } catch (IllegalArgumentException ignore) {
                }
              }
            }
          }
          if (!(levelExtremes.maxYHemisphere.equals(AVKey.SOUTH) && levelExtremes.maxY == 0)) {
            // Process northing scale labels for this level
            String currentHemisphere = levelExtremes.minYHemisphere;
            for (double northing = levelExtremes.minY;
                (northing <= levelExtremes.maxY)
                    || !currentHemisphere.equals(levelExtremes.maxYHemisphere);
                northing += gridStep) {
              // Skip multiples of ten grid steps except for last (higher) level
              if (i == this.extremes.length - 1 || northing % gridStepTimesTen != 0) {
                try {
                  labelPos = computePosition(this.zone, currentHemisphere, labelEasting, northing);
                  if (labelPos == null) continue;
                  Angle lat = labelPos.getLatitude();
                  Angle lon = labelPos.getLongitude();
                  Vec4 surfacePoint = getSurfacePoint(dc, lat, lon);
                  if (viewFrustum.contains(surfacePoint) && isPointInRange(dc, surfacePoint)) {
                    String text = String.valueOf((int) (northing % this.scaleModulo));
                    GeographicText gt = new UserFacingText(text, new Position(lat, lon, 0));
                    gt.setPriority(gridStepTimesTen);
                    addRenderable(gt, graticuleType);
                  }
                } catch (IllegalArgumentException ignore) {
                }

                if (!currentHemisphere.equals(levelExtremes.maxYHemisphere)
                    && northing >= 10e6 - gridStep) {
                  // Switch hemisphere
                  currentHemisphere = levelExtremes.maxYHemisphere;
                  northing = -gridStep;
                }
              }
            }
          } // end northing
        } // for levels
      } catch (IllegalArgumentException ignore) {
      }
    }
Ejemplo n.º 22
0
  protected void drawMany(DrawContext dc, Iterable<? extends WWIcon> icons, Layer layer) {
    if (dc == null) {
      String msg = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (dc.getVisibleSector() == null) return;

    SectorGeometryList geos = dc.getSurfaceGeometry();
    //noinspection RedundantIfStatement
    if (geos == null) return;

    if (icons == null) {
      String msg = Logging.getMessage("nullValue.IconIterator");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    Iterator<? extends WWIcon> iterator = icons.iterator();

    if (!iterator.hasNext()) return;

    double horizon = dc.getView().getHorizonDistance();

    while (iterator.hasNext()) {
      WWIcon icon = iterator.next();
      if (!isIconValid(icon, true)) {
        // Record feedback data for this WWIcon if feedback is enabled.
        if (icon != null) this.recordFeedback(dc, icon, null, null);

        continue;
      }

      if (!icon.isVisible()) {
        // Record feedback data for this WWIcon if feedback is enabled.
        this.recordFeedback(dc, icon, null, null);

        continue;
      }

      // Determine Cartesian position from the surface geometry if the icon is near the surface,
      // otherwise draw it from the globe.
      Position pos = icon.getPosition();
      Vec4 iconPoint = null;
      if (pos.getElevation() < dc.getGlobe().getMaxElevation()
          && !this.isAlwaysUseAbsoluteElevation()) {
        iconPoint = dc.getSurfaceGeometry().getSurfacePoint(icon.getPosition());
      }

      if (iconPoint == null) {
        Angle lat = pos.getLatitude();
        Angle lon = pos.getLongitude();
        double elevation = pos.getElevation();
        if (!this.isAlwaysUseAbsoluteElevation()) elevation += dc.getGlobe().getElevation(lat, lon);
        iconPoint = dc.getGlobe().computePointFromPosition(lat, lon, elevation);
      }

      double eyeDistance =
          icon.isAlwaysOnTop() ? 0 : dc.getView().getEyePoint().distanceTo3(iconPoint);

      // X-PATCH Marjan
      // extracted skip conditions into an overrideable method
      if (!meetsRenderCriteria(dc, icon, iconPoint, eyeDistance)) {
        this.recordFeedback(dc, icon, iconPoint, null);
        continue;
      }
      // X-END

      // The icons aren't drawn here, but added to the ordered queue to be drawn back-to-front.
      dc.addOrderedRenderable(new OrderedIcon(icon, iconPoint, layer, eyeDistance, horizon));

      if (icon.isShowToolTip()) this.addToolTip(dc, icon, iconPoint);
    }
  }