Exemplo n.º 1
0
  /**
   * Updates a strip vertex with vertices shaping a rounded beginning. This method is called when
   * the polygon is open (not {@link #isClosedPolygon()}).
   *
   * @param inside whether this is a <b>inside</b> triangle strip, as opposed to an outside triangle
   *     strip.
   */
  private void updateVertexBeginning(boolean inside) {
    // if polygon is not closed the endings must be fixed
    int index = 0;

    BoundingBox box = boundingBoxes.items[0];
    box.needsCullingUpdate = true;

    StripVertex stripVertex = vertexDataArray.items[index];
    AuxVertexFinder auxVertexFinder = this.auxVertexFinder;

    Array<Float> vertexData = inside ? stripVertex.insideVertexData : stripVertex.outsideVertexData;
    vertexData.clear();

    auxVertexFinder.setInsideStrip(inside);

    Vector2 currentVertex = vertices.items[index];

    Vector2 currentAux = auxVertexFinder.getAuxBeginning(vertices, index, MathUtils.PI * 0.5f);
    add(currentVertex, VERTEX_TYPE_USER, vertexData);
    add(currentAux, VERTEX_TYPE_AUX, vertexData);

    currentAux = auxVertexFinder.getAuxBeginning(vertices, index, MathUtils.PI * 0.25f);
    add(currentVertex, VERTEX_TYPE_USER, vertexData);
    add(currentAux, VERTEX_TYPE_AUX, vertexData);

    currentAux = auxVertexFinder.getAuxBeginning(vertices, index, 0);
    add(currentVertex, VERTEX_TYPE_USER, vertexData);
    add(currentAux, VERTEX_TYPE_AUX, vertexData);
  }
Exemplo n.º 2
0
  Bounds getBounds(int childIndex) {
    if (boundsAutoCompute) {
      ArrayList glist = (ArrayList) geometryInfo.get(childIndex);

      if (glist != null) {
        BoundingBox bbox = new BoundingBox((Bounds) null);
        for (int i = 0; i < glist.size(); i++) {
          Geometry g = (Geometry) glist.get(i);
          if (g != null) {
            GeometryRetained geometry = (GeometryRetained) g.retained;
            if (geometry.geoType != GeometryRetained.GEO_TYPE_NONE) {
              geometry.computeBoundingBox();
              synchronized (geometry.geoBounds) {
                bbox.combine(geometry.geoBounds);
              }
            }
          }
        }

        return (Bounds) bbox;

      } else {
        return null;
      }

    } else {
      return super.getBounds();
    }
  }
Exemplo n.º 3
0
  /**
   * When you call methods like for example {@link #setHalfWidth(float)} or {@link
   * #updateVertex(int, float, float)} work is being queued up. Before each draw call this method is
   * automatically called to do all this work.
   *
   * <p>It can be smart to call this method after you are done configuring your OutlinePolygon, but
   * before you exit your loading screen. This way you do more work during the loading screen and
   * get less initial lag.
   */
  public void updateStripAndCulling() {
    if (!changesToStripOrCulling) return;

    updateAllBoxIndices();

    boolean clockwiseUpdated = false;

    for (int i = 0; i < needsUpdate.size; i++) {
      boolean update = needsUpdate.items[i];
      if (update) {
        if (!clockwiseUpdated) {
          clockwiseUpdated = true;
          updateAuxVertexFinderClockwise();
        }
        if (drawInside) {
          updateVertex(i, true);
        }
        if (drawOutside) {
          updateVertex(i, false);
        }

        needsUpdate.items[i] = false;
      }
    }

    for (BoundingBox box : boundingBoxes) {
      if (box.needsCullingUpdate) {
        updateBoxCulling(box);
        box.needsCullingUpdate = false;
      }
    }
  }
Exemplo n.º 4
0
 public BoundingBox getBoundingBoxInViewSpace() {
   Vec2 ll = boundingBox.getLowerLeft();
   Vec2 ur = boundingBox.getUpperRight();
   transform.getLocalToViewMatrix().transform(ll);
   transform.getLocalToViewMatrix().transform(ur);
   return new BoundingBox(ll, ur);
 }
Exemplo n.º 5
0
 public boolean intersectsBB(BoundingBox which) {
   Vec2 ll = which.getLowerLeft();
   Vec2 ur = which.getUpperRight();
   transform.getViewToLocalMatrix().transform(ll);
   transform.getViewToLocalMatrix().transform(ur);
   return boundingBox.intersects(new BoundingBox(ll, ur));
 }
Exemplo n.º 6
0
  /**
   * <code>mergeLocal</code> combines this sphere with a second bounding sphere locally. Altering
   * this sphere to contain both the original and the additional sphere volumes;
   *
   * @param volume the sphere to combine with this sphere.
   * @return this
   */
  @Override
  public BoundingVolume mergeLocal(final BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          final BoundingSphere sphere = (BoundingSphere) volume;
          final double temp_radius = sphere.getRadius();
          final ReadOnlyVector3 temp_center = sphere.getCenter();
          return merge(temp_radius, temp_center, this);
        }

      case AABB:
        {
          final BoundingBox box = (BoundingBox) volume;
          final Vector3 temp_center = box._center;
          _compVect1.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
          final double radius = _compVect1.length();
          return merge(radius, temp_center, this);
        }

      case OBB:
        {
          return mergeLocalOBB((OrientedBoundingBox) volume);
        }

      default:
        return null;
    }
  }
Exemplo n.º 7
0
  @Override
  public void tankMove(Coordinates delta) {
    for (int i = 0; i < this.elements.length; i++) {
      Movable toMove = null;

      try {
        toMove = (Movable) this.elements[i];
      } catch (ClassCastException e) {
        continue;
      }

      if (toMove == null) continue;

      if (toMove.getType() != Type.TANK) continue;

      if (!(toMove.isAlive())) continue;

      try {
        BoundingBox toMoveNextBb = toMove.getArea().translate(delta);
        BoundingBox gridBb = new BoundingBox(new Coordinates(0, 0), this.maxSize);

        BoundingBox intersection = toMoveNextBb.intersection(gridBb);

        if (!(intersection.equals(toMoveNextBb))) return;

        toMove.move(delta);
      } catch (NegativeSizeException e) {
        // ignore this, nothing is moved
      }
    }
  }
Exemplo n.º 8
0
 public boolean intersects(BoundingBox box) {
   final Vector3 rMax = box.getMax();
   if (rMax.getX() < min.getX() || rMax.getY() < min.getY() || rMax.getZ() < min.getZ()) {
     return false;
   }
   final Vector3 rMin = box.getMin();
   return !(rMin.getX() > max.getX() || rMin.getY() > max.getY() || rMin.getZ() > max.getZ());
 }
Exemplo n.º 9
0
 @Override
 public BoundingBox getWorldBoundingBox() {
   if (worldBoundingBox == null) {
     final BoundingBox newWorldBoundingBox = new BoundingBox(getRenderGeometry().getVertices());
     worldBoundingBox =
         newWorldBoundingBox.transform(getWorldRotation(), getWorldTranslation(), getWorldScale());
   }
   return worldBoundingBox;
 }
Exemplo n.º 10
0
  public static TexturedPolygon newTexturedPolygon(Texture texture, Vector... vectors) {
    TexturedPolygon texturedPolygon = TexturedPolygonImpl.newInstance(texture, vectors);

    if (vectors.length >= 2) {
      if (texture instanceof ShadedTexture) {
        ShadedTexture shadedTexture = ShadedTexture.class.cast(texture);

        List<PointLight> pointLights = new ArrayList<>();

        Vector normal = texturedPolygon.getNormal();
        Vector location = null;

        double x = normal.getX();
        double y = normal.getY() + 500.0D;
        double z = normal.getZ();
        double distanceFalloff = 2500.0D;

        Color intensity = Color.white();

        location = Vector.newInstance(x, y, z);

        PointLight pointLight = PointLight.newInstance();
        pointLight.setLocation(location);
        pointLight.setIntensity(intensity);
        pointLight.setDistanceFalloff(distanceFalloff);

        pointLights.add(pointLight);

        Color ambientLightIntensity = Color.valueOf(0xFF333333);

        ShadedSurfaceTexture.createShadedSurfaceTexture(
            texturedPolygon,
            shadedTexture,
            pointLights,
            new ArrayList<Polygon>(),
            ambientLightIntensity);
      } else {
        Vector origin = vectors[0];
        Vector v = vectors[1].copy();
        Vector normal = texturedPolygon.getNormal();

        v.subtract(origin);

        Vector u = Vector.toCrossProduct(normal, v);

        BoundingBox boundingBox = texturedPolygon.getTextureBounds();
        boundingBox.setOrigin(origin);
        boundingBox.setU(u);
        boundingBox.setV(v);
      }
    }

    return texturedPolygon;
  }
 public static Sampleable sampleable(Renderable base) {
   BoundingBox bb = base.getBoundingBox();
   OverlayRaster or = new OverlayRaster(bb.intRight() + 1, bb.intBottom() + 1);
   base.render(or);
   return new AbstractSampleable(bb) {
     @Override
     public Color getColorAt(Point<Double> point) {
       return or.getColor(point.toIntegerPoint());
     }
   };
 }
 /**
  * Scales a sampleable by the given factor. The position of the origin is fixed.
  *
  * @param factor the factor to scale by
  * @param base the sampleable to scale
  * @return the scaled sampleable
  */
 public static Sampleable scale(double factor, Sampleable base) {
   BoundingBox bb = base.getBoundingBox();
   return new AbstractSampleable(
       factor * bb.top(), factor * bb.bottom(),
       factor * bb.left(), factor * bb.right()) {
     @Override
     public Color getColorAt(Point<Double> point) {
       return base.getColorAt(point.scaleBy(1 / factor));
     }
   };
 }
Exemplo n.º 13
0
  @Override
  public boolean intersectsBoundingBox(final BoundingBox bb) {
    if (!Vector3.isValid(_center) || !Vector3.isValid(bb._center)) {
      return false;
    }

    if (Math.abs(bb._center.getX() - getCenter().getX()) < getRadius() + bb.getXExtent()
        && Math.abs(bb._center.getY() - getCenter().getY()) < getRadius() + bb.getYExtent()
        && Math.abs(bb._center.getZ() - getCenter().getZ()) < getRadius() + bb.getZExtent()) {
      return true;
    }

    return false;
  }
Exemplo n.º 14
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;
  }
Exemplo n.º 15
0
 public boolean isBoundingBoxVisible(BoundingBox box) {
   return (frustum.isPointInside(box.getBottomLeftFrontPoint())
       || frustum.isPointInside(box.getTopRightBackPoint())
       || frustum.isPointInside(box.getBottomLeftBackPoint())
       || frustum.isPointInside(box.getBottomRightFrontPoint())
       || frustum.isPointInside(box.getBottomRightBackPoint())
       || frustum.isPointInside(box.getTopLeftFrontPoint())
       || frustum.isPointInside(box.getTopLeftBackPoint())
       || frustum.isPointInside(box.getTopRightFrontPoint()));
 }
  public void LoadObjects(ProjectLevel p) {
    for (int i = 0; i < p.getModels().size(); i++) {
      mParser = new ObjParser(this, p.getModels().get(i).getModel());
      mParser.parse();
      BaseObject3D obj = mParser.getParsedObject();
      obj.setDepthMaskEnabled(true);
      obj.setDepthTestEnabled(true);
      obj.setBlendingEnabled(true);
      obj.setBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
      if (p.getModels().get(i).isDoubleSided()) {
        obj.setDoubleSided(true);
      }
      if (p.getModels().get(i).isVideo()) {
        // Log.d("isvideo", "yeees");
        // obj.setMaterial(vmaterial);
        // obj.addTexture(vt);
      } else {
        obj.setMaterial(new SimpleMaterial());
        String tn = p.getModels().get(i).getTexture();
        if (!textureNames.contains(tn)) {
          textureNames.add(tn); // store texture names for unique
          // textures
          int idx = textureNames.indexOf(tn); // get index

          Bitmap mBM =
              BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + tn);
          TextureInfo ti = mTextureManager.addTexture(mBM);
          textureInfos.add(idx, ti); // store texture info with same
          // index as texture name
          obj.addTexture(ti);
        } else {
          int idx = textureNames.indexOf(tn);
          obj.addTexture(textureInfos.get(idx));
        }
      }
      addChild(obj);
      BoundingBox bb = obj.getGeometry().getBoundingBox();
      Number3D mi = bb.getMin();
      Number3D mx = bb.getMax();
      Number3D cnt = new Number3D((mi.x + mx.x) / 2, (mi.y + mx.y) / 2, (mi.z + mx.z) / 2);
      p.getModels().get(i).setCenter(cnt);
      p.getModels().get(i).setObj(obj);
    }
    Log.d("objloader", "objects in scene:" + getNumChildren());
  }
Exemplo n.º 17
0
  /**
   * Returns the 3D bounding box of the specified glyph code.
   *
   * @param glyphCode the glyphCode from the original 2D Font
   * @param bounds the 3D glyph's bounds
   */
  public void getBoundingBox(int glyphCode, BoundingBox bounds) {
    int[] gCodes = {glyphCode};
    GlyphVector gVec = font.createGlyphVector(frc, gCodes);
    Rectangle2D.Float bounds2d =
        (Rectangle2D.Float) (((GlyphMetrics) (gVec.getGlyphMetrics(0))).getBounds2D());

    Point3d lower = new Point3d(bounds2d.x, bounds2d.y, 0.0);
    Point3d upper;
    if (fontExtrusion != null) {
      upper =
          new Point3d(
              bounds2d.x + bounds2d.width, bounds2d.y + bounds2d.height, fontExtrusion.length);
    } else {
      upper = new Point3d(bounds2d.x + bounds2d.width, bounds2d.y + bounds2d.height, 0.0);
    }
    bounds.setLower(lower);
    bounds.setUpper(upper);
  }
    @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) {
        }
      }
    }
Exemplo n.º 19
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;

    for (BufferedImage heatmap : resultHeatmaps.values()) {
      g2.drawImage(heatmap, null, null);
    }

    if (testResultHeatmap != null) {
      g2.drawImage(testResultHeatmap, null, null);
    }

    for (List<BoundingBox> rr : resultPatches) {
      for (BoundingBox r : rr) {
        int x0 = r.getX0();
        int y0 = r.getY0();
        int x1 = r.getX1();
        int y1 = r.getY1();

        g2.setColor(Color.GREEN);
        g2.drawRect(x0, y0, x1 - x0, y1 - y0);
      }
    }

    for (BoundingBox r : testResultPatches) {
      int x0 = r.getX0();
      int y0 = r.getY0();
      int x1 = r.getX1();
      int y1 = r.getY1();

      g2.setColor(Color.BLUE);
      g2.drawRect(x0, y0, x1 - x0, y1 - y0);
    }

    for (Rectangle r : drawnPatches) {
      g2.setColor(new Color(255, 0, 0, 32));
      g2.fill(r);
      g2.setColor(Color.RED);
      g2.draw(r);
    }
  }
  /**
   * 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);
    }
  }
Exemplo n.º 21
0
  void updateLocaleVwcBounds() {

    // it is possible that inRenderBin could be false because
    // the renderAtom could have been removed from RenderBin
    // in the same frame, and removeRenderAtoms does happen
    // before updateLocaleVwcBounds
    if (inRenderBin()) {
      // Check if the locale of this is different from the
      // locale on which the view is,then compute the translated
      // localeVwcBounds
      if (renderMolecule.renderBin.locale != geometryAtom.source.locale) {

        geometryAtom.source.locale.hiRes.difference(
            renderMolecule.renderBin.locale.hiRes, renderMolecule.renderBin.localeTranslation);
        localeVwcBounds.translate(
            geometryAtom.source.vwcBounds, renderMolecule.renderBin.localeTranslation);
      } else {
        localeVwcBounds.set(geometryAtom.source.vwcBounds);
      }
      dirtyMask &= ~ON_LOCALE_VWC_BOUNDS_UPDATELIST;
    }
  }
  // TODO maybe we should add missing codewords to store the correct row number to make
  // finding row numbers for other columns easier
  // use row height count to make detection of invalid row numbers more reliable
  int adjustIncompleteIndicatorColumnRowNumbers(BarcodeMetadata barcodeMetadata) {
    BoundingBox boundingBox = getBoundingBox();
    ResultPoint top = isLeft ? boundingBox.getTopLeft() : boundingBox.getTopRight();
    ResultPoint bottom = isLeft ? boundingBox.getBottomLeft() : boundingBox.getBottomRight();
    int firstRow = imageRowToCodewordIndex((int) top.getY());
    int lastRow = imageRowToCodewordIndex((int) bottom.getY());
    float averageRowHeight = (lastRow - firstRow) / (float) barcodeMetadata.getRowCount();
    Codeword[] codewords = getCodewords();
    int barcodeRow = -1;
    int maxRowHeight = 1;
    int currentRowHeight = 0;
    for (int codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow++) {
      if (codewords[codewordsRow] == null) {
        continue;
      }
      Codeword codeword = codewords[codewordsRow];

      codeword.setRowNumberAsRowIndicatorColumn();

      int rowDifference = codeword.getRowNumber() - barcodeRow;

      // TODO improve handling with case where first row indicator doesn't start with 0

      if (rowDifference == 0) {
        currentRowHeight++;
      } else if (rowDifference == 1) {
        maxRowHeight = Math.max(maxRowHeight, currentRowHeight);
        currentRowHeight = 1;
        barcodeRow = codeword.getRowNumber();
      } else if (codeword.getRowNumber() >= barcodeMetadata.getRowCount()) {
        codewords[codewordsRow] = null;
      } else {
        barcodeRow = codeword.getRowNumber();
        currentRowHeight = 1;
      }
    }
    return (int) (averageRowHeight + 0.5);
  }
 /**
  * Overlays layers of {@code Sampleable}s with the first element of {@code layers} being on top.
  * This method respects the transparency in the alpha component of each layer
  *
  * @param layers the array of layers
  */
 public static Sampleable overlay(Sampleable... layers) {
   if (layers.length == 0) {
     throw new IllegalArgumentException("Empty array was passed into overlay");
   }
   if (layers.length == 1) {
     return new AbstractSampleable(layers[0].getBoundingBox()) {
       @Override
       public Color getColorAt(Point<Double> point) {
         return layers[0].getColorAt(point);
       }
     };
   }
   return overlay(
       BoundingBox.containing(layers), layers[layers.length - 1], layers.length - 1, layers);
 }
Exemplo n.º 24
0
  public void doDraw(Painter p) {
    WorkCraftServer server = ownerDocument.getServer();

    Vec2 ll = boundingBox.getLowerLeft();
    Vec2 ur = boundingBox.getUpperRight();
    Vec2 ul = new Vec2(ll.getX(), ur.getY());
    Vec2 lr = new Vec2(ur.getX(), ll.getY());

    transform.getLocalToViewMatrix().transform(ll);
    transform.getLocalToViewMatrix().transform(ur);
    transform.getLocalToViewMatrix().transform(ul);
    transform.getLocalToViewMatrix().transform(lr);

    BoundingBox superbb = new BoundingBox();

    superbb.addPoint(ll);
    superbb.addPoint(ul);
    superbb.addPoint(ur);
    superbb.addPoint(lr);

    Vec2 v1 = superbb.getLowerLeft();
    Vec2 v2 = superbb.getUpperRight();
    Vec2 center;

    p.setTextColor(getLabelColor());

    PyObject po;
    if (server != null) po = server.python.get("_draw_labels");
    else po = null;

    if ((server == null) || (po != null && po.__nonzero__()))
      if (!label.equals("")) {
        if (labelOrder == 0)
          center = new Vec2(0.5f * (v1.getX() + v2.getX()), v1.getY() + getLabelYOffset());
        else center = new Vec2((v1.getX() + v2.getX()) * 0.5f, v2.getY() + getLabelYOffset());

        //		transform.getLocalToViewMatrix().transform(center);
        p.drawString(label, center, 0.05f, TextAlign.CENTER);
      }

    if (server != null) po = server.python.get("_draw_ids");
    else po = null;

    if ((server == null) || (po != null && po.__nonzero__()))
      if (id != null && !id.equals("")) {
        if (labelOrder == 0) center = new Vec2((v1.getX() + v2.getX()) * 0.5f, v2.getY() + 0.025f);
        else center = new Vec2(0.5f * (v1.getX() + v2.getX()), v1.getY() - 0.05f);
        //		transform.getLocalToViewMatrix().transform(center);
        p.drawString(id, center, 0.05f, TextAlign.CENTER);
      }
  }
Exemplo n.º 25
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;
 }
Exemplo n.º 26
0
 public void writeRegionKeys(DS.CacheWriter cw, BoundingBox bb) {
   JSONObject json = new JSONObject();
   JSONArray jarray = new JSONArray();
   json.put("keys", jarray);
   for (Map.Entry<BoundingBox, List<Pair<BoundingBox, Key>>> entry : boxList.entrySet()) {
     if (bb.isIntersecting(entry.getKey())) {
       for (Pair<BoundingBox, Key> pair : entry.getValue()) {
         if (bb.isIntersecting(pair.getFirst())) {
           jarray.put(KeyFactory.keyToString(pair.getSecond()));
         }
       }
     }
   }
   for (Pair<GeoPt, Key> pair : locationList) {
     if (bb.isInside(pair.getFirst())) {
       jarray.put(KeyFactory.keyToString(pair.getSecond()));
     }
   }
   if (firstPlacemarkKey != null && bb.isIntersecting(placemarkBoundingBox)) {
     jarray.put(KeyFactory.keyToString(firstPlacemarkKey));
   }
   json.write(cw);
   cw.cache();
 }
Exemplo n.º 27
0
  // returns true iff the bHull is completely inside this
  // bounding hull i.e.  bHull values are strictly less
  // than or equal to all this.bHull values
  boolean isInside(BoundingBox bHull) {
    if (bHull == null) return false;

    if (this.bHull.isEmpty() || bHull.isEmpty()) {
      return false;
    }

    if (this.bHull.upper.x < bHull.upper.x
        || this.bHull.upper.y < bHull.upper.y
        || this.bHull.upper.z < bHull.upper.z
        || this.bHull.lower.x > bHull.lower.x
        || this.bHull.lower.y > bHull.lower.y
        || this.bHull.lower.z > bHull.lower.z) return false;
    else return true;
  }
Exemplo n.º 28
0
  /**
   * <code>merge</code> combines this sphere with a second bounding sphere. This new sphere contains
   * both bounding spheres and is returned.
   *
   * @param volume the sphere to combine with this sphere.
   * @return a new sphere
   */
  @Override
  public BoundingVolume merge(final BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          final BoundingSphere sphere = (BoundingSphere) volume;
          final double temp_radius = sphere.getRadius();
          final ReadOnlyVector3 tempCenter = sphere.getCenter();
          final BoundingSphere rVal = new BoundingSphere();
          return merge(temp_radius, tempCenter, rVal);
        }

      case AABB:
        {
          final BoundingBox box = (BoundingBox) volume;
          final Vector3 radVect = new Vector3(box.getXExtent(), box.getYExtent(), box.getZExtent());
          final Vector3 tempCenter = box._center;
          final BoundingSphere rVal = new BoundingSphere();
          return merge(radVect.length(), tempCenter, rVal);
        }

      case OBB:
        {
          final OrientedBoundingBox box = (OrientedBoundingBox) volume;
          final BoundingSphere rVal = (BoundingSphere) this.clone(null);
          return rVal.mergeLocalOBB(box);
        }

      default:
        return null;
    }
  }
Exemplo n.º 29
0
 public static BoundingBox createBoundingBox(
     String id, double x, double y, double width, double height) {
   BoundingBox bounds = new BoundingBox();
   bounds.setId(id);
   bounds.setX(x);
   bounds.setY(y);
   bounds.setWidth(width);
   bounds.setHeight(height);
   return bounds;
 }
Exemplo n.º 30
0
  public GeoData(DS ds) {
    Iterable<Entity> tracksIterable = ds.fetchTracks();
    Iterable<Entity> imageLocationsIterable = ds.fetchImageLocations();
    Iterable<Entity> blogLocationsIterable = ds.fetchBlogLocations();

    boxList = new HashMapList<>();
    Date lastBegin = null;
    for (Entity track : tracksIterable) {
      BoundingBox bbTrack = new BoundingBox(track);
      for (Entity trackSeq : ds.fetchTrackSeqs(track.getKey())) {
        BoundingBox bbTrackSeq = new BoundingBox(trackSeq);
        boxList.add(bbTrack, new Pair<BoundingBox, Key>(bbTrackSeq, trackSeq.getKey()));
        Date begin = (Date) trackSeq.getProperty(BeginProperty);
        if (lastBegin == null || lastBegin.before(begin)) {
          lastBegin = begin;
        }
      }
    }
    Iterable<Entity> placemarksIterable;
    if (lastBegin != null) {
      placemarksIterable = ds.fetchPlacemarks(lastBegin);
    } else {
      placemarksIterable = ds.fetchPlacemarks();
    }
    firstPlacemarkKey = null;
    placemarkBoundingBox = new BoundingBox();
    for (Entity placemark : placemarksIterable) {
      if (firstPlacemarkKey == null) {
        firstPlacemarkKey = placemark.getKey();
      }
      GeoPt location = (GeoPt) placemark.getProperty(LocationProperty);
      placemarkBoundingBox.add(location);
    }
    locationList = new ArrayList<>();
    for (Entity metadata : imageLocationsIterable) {
      GeoPt location = (GeoPt) metadata.getProperty(LocationProperty);
      if (location != null) {
        locationList.add(new Pair<>(location, metadata.getKey()));
      }
    }
    for (Entity blog : blogLocationsIterable) {
      GeoPt location = (GeoPt) blog.getProperty(LocationProperty);
      if (location != null) {
        locationList.add(new Pair<>(location, blog.getKey()));
      }
    }
  }