Пример #1
0
  @Override
  public BoundingBox getBounds() {
    // If there are no charges, return an empty box.
    if (charges.size() <= 0) return new BoundingBox(0, 0, 0, 0, 0, 0);

    if (cachedBounds == null) {
      // Start with the box of the first charge.
      Charge c = charges.get(0);
      double ext = Math.abs(c.w);
      double corr = 1.0 + (0.1 / hardness); // see note
      cachedBounds =
          new BoundingBox(
              new Vec3(c.x - ext, c.y - ext, c.z - ext).times(corr),
              new Vec3(c.x + ext, c.y + ext, c.z + ext).times(corr));

      // A note on "corr":
      // As blobs are blobby, we can't use their weight/radius
      // directly. This would result in unwanted cut-off's. To
      // correct this, we extend the bounding box of a charge "a
      // bit". That "bit" can be smaller if the charge is harder.

      // Iteratively add the remaining charges.
      for (int i = 1; i < charges.size(); i++) {
        c = charges.get(i);
        ext = Math.abs(c.w);
        corr = 1.0 + (0.1 / hardness);
        cachedBounds.extend(
            new BoundingBox(
                new Vec3(c.x - ext, c.y - ext, c.z - ext).times(corr),
                new Vec3(c.x + ext, c.y + ext, c.z + ext).times(corr)));
      }
    }

    return cachedBounds;
  }
    @Override
    public void sourceAdded(SourceEvent e) {
      String name = e.getName();
      SourceManager sm = dsf.getSourceManager();
      if (e.isWellKnownName()
          && !sm.getSource(name).isSystemTableSource()
          && !layerMap.containsKey(name)) {
        try {
          Layer layer = new Layer();
          layer.setName(name);
          layer.setTitle(name);

          // Setting the bounding box data
          DataSource ds = dsf.getDataSource(name);
          ds.open();
          Envelope env = ds.getFullExtent();
          CoordinateReferenceSystem crs = ds.getCRS();
          ds.close();
          BoundingBox bBox = getBoundingBox(env, crs);
          if (bBox == null) {
            return;
          }
          layer.getCRS().add(bBox.getCRS());
          layer.getBoundingBox().add(bBox);
          layer.setEXGeographicBoundingBox(getGeographicBoundingBox(env, bBox.getCRS()));
          layer.setQueryable(true);
          if (layerStyles.containsKey(name)) {
            String[] lStyles = layerStyles.get(name);
            for (int i = 0; i < lStyles.length; i++) {
              Style style = new Style();
              String styleName = lStyles[i];
              style.setName(styleName);
              style.setTitle(styleName);
              layer.getStyle().add(style);
            }
          }
          layerMap.put(name, layer);
        } catch (NoSuchTableException ex) {
        } catch (DataSourceCreationException ex) {
        } catch (DriverException ex) {
        }
      }
    }
  /**
   * Handles the getCapabilities request and gives the XML formated server capabilities to the
   * outputStream
   *
   * @param output servlet outputStream
   * @param wmsResponse HttpServletResponse modified for WMS use
   * @throws WMSException
   * @throws UnsupportedEncodingException
   */
  public void getCap(OutputStream output, WMSResponse wmsResponse)
      throws WMSException, UnsupportedEncodingException {
    PrintStream pr = new PrintStream(output, false, "UTF-8");
    WMSCapabilities cap = new WMSCapabilities();
    // Setting service WMS metadata
    cap.setService(getService());
    // Setting Capability parameters
    // Setting Layers capabilities
    Capability c = new Capability();
    // Bounding box of the highest layer is dummy
    Envelope dummy = new Envelope(WEST, EAST, SOUTH, NORTH);
    EXGeographicBoundingBox bb = getGeographicBoundingBox(dummy, "EPSG:4326");
    Layer availableLayers = new Layer();
    availableLayers.setEXGeographicBoundingBox(bb);
    BoundingBox bBox = new BoundingBox();
    bBox.setCRS("EPSG:4326");
    bBox.setMaxx(EAST);
    bBox.setMinx(WEST);
    bBox.setMaxy(NORTH);
    bBox.setMiny(SOUTH);
    availableLayers.getBoundingBox().add(bBox);
    for (Layer e : layerMap.values()) {
      availableLayers.getLayer().add(e);
    }
    // Server supported CRS
    availableLayers.getCRS().addAll(authCRS);
    availableLayers.setName("Available_layers");
    availableLayers.setTitle("Server available layers");
    c.setLayer(availableLayers);
    // Setting the request capabilities
    // GetMap capabilities
    Request req = new Request();
    req.setGetMap(getMapOperation(wmsResponse));
    // GetCap capabilities
    req.setGetCapabilities(getCapOperation(wmsResponse));
    // GetFeatureInfo capabilities
    req.setGetFeatureInfo(getFeatureOperation(wmsResponse));
    c.setRequest(req);
    cap.setCapability(c);

    try {
      // Marshalling the WMS Capabilities into an XML response
      Marshaller marshaller = jaxbContext.createMarshaller();
      NamespacePrefixMapper mapper = new NamespaceMapper();
      marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);

      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

      wmsResponse.setContentType("text/xml;charset=UTF-8");
      marshaller.marshal(cap, pr);

    } catch (JAXBException ex) {
      wmsResponse.setContentType("text/xml;charset=UTF-8");
      wmsResponse.setResponseCode(500);
      pr.append(
          "<?xml version='1.0' encoding=\"UTF-8\"?><ServiceExceptionReport xmlns=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.3.0\" xsi:schemaLocation=\"http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd\"><ServiceException>Something went wrong</ServiceException></ServiceExceptionReport>");
      pr.append(ex.toString());
      ex.printStackTrace(pr);
    }
  }
Пример #4
0
 private static boolean pickingInFrustum(
     Selectable selectable,
     float[][] frustum,
     float z_offset,
     float selection_radius,
     float selection_height) {
   picking_selection_box.setBounds(
       -selection_radius + selectable.getPositionX(),
       selection_radius + selectable.getPositionX(),
       -selection_radius + selectable.getPositionY(),
       selection_radius + selectable.getPositionY(),
       z_offset,
       z_offset + selection_height);
   return RenderTools.inFrustum(picking_selection_box, frustum) >= RenderTools.IN_FRUSTUM;
 }
 private BoundingBox getBoundingBox(Envelope env, CoordinateReferenceSystem crs) {
   BoundingBox bBox = new BoundingBox();
   if (crs != null) {
     Integer code = null;
     try {
       code = Integer.valueOf(crs.getAuthorityKey());
     } catch (NumberFormatException ex) {
       LOGGER.error("Cannot find a unique authority key from the crs " + crs.getName(), ex);
     }
     if (code != null) {
       bBox.setCRS("EPSG:" + code);
     } else {
       return null;
     }
   } else {
     return null;
   }
   bBox.setMaxx(env.getMaxX());
   bBox.setMinx(env.getMinX());
   bBox.setMiny(env.getMinY());
   bBox.setMaxy(env.getMaxY());
   return bBox;
 }