Package toxi.geom

Examples of toxi.geom.AABB


  @Test
  public void testReorientPlusX2MinusY() {
    gml = createGml();
    gml.environment.up = new Vec3D(1, 0, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.35f, 0.15f, 0.25F), new Vec3D(0.95f, 0.9f, 0.7f));
   
    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testPlusX2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());
   
    // Check min-max bounding box
    assertTrue("x=1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here


  @Test
  public void testReorientMinusX2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(-1, 0, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.05f, 0.1f, 0.25f), new Vec3D(0.65f, 0.85f, 0.7f));

    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testMinusX2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());

    // Check min-max bounding box
    assertTrue("x=-1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

  @Test
  public void testReorientPlusY2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(0, 1, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.15f, 0.05f, 0.7f), new Vec3D(0.9f, 0.65f, 0.25f));
   
    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testPlusY2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());
   
    // Check min-max bounding box
    assertTrue("y=1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

  @Test
  public void testReorientMinusY2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(0, -1, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.1f, 0.35f, 0.25f), new Vec3D(0.85f, 0.95f, 0.7f));

    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testMinusY2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());
   
    // Check min-max bounding box
    assertTrue("y=-1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
 
View Full Code Here

  @Test
  public void testReorientPlusZ2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(0, 0, 1);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.1f, 0.3f, 0.35f), new Vec3D(0.85f, 0.75f, 0.95f));

    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "plusZ2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());

    // Check min-max bounding box
    assertTrue("z=1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

  @Test
  public void testReorientMinusZ2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(0, 0, -1);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.15f, 0.25f, 0.35f), new Vec3D(0.9f, 0.7f, 0.95f));

    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testMinusZ2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());

    // Check min-max bounding box
    assertTrue("z=-1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

   * Checks if the Gml striclty fits into the (0, 0, 0) (1, 1, 1) box
   * @param gml - Gml
   * @return boolean
   */
  public static boolean isNormalized(Gml gml) {
    AABB refBox = AABB.fromMinMax(new Vec3D(0, 0, 0), new Vec3D(1, 1, 1));
    AABB boundingBox = gml.getBoundingBox();

    return boundingBox.equalsWithTolerance(refBox, 0.0000001f);
  }
View Full Code Here

    // Case by case normalization
    //Rescale all Z for Graffiti Analysis 2.0: DustTag

    // Get BoundingBox
    AABB boundingBox = gml.getBoundingBox();
    LOGGER.log(Level.FINEST, "bounding box before scaling"+ boundingBox.getMin() + " " + boundingBox.getMax());

    // Get bounding box min for later substraction
    Vec3D originShift = boundingBox.getMin();

    // Original aspect ratio of the tag
    Vec3D originalAspectRatio = boundingBox.getExtent().scale(2);

    // Used to scale the tag to a max of 1 on the longest axis
    Vec3D scaling = originalAspectRatio.getReciprocal();

    // Remap all points to fit within a min of 0, 0, 0 and a max of 1, 1, 1
    List<GmlStroke> strokes = (List<GmlStroke>) gml.getStrokes();
    for (GmlStroke stroke : strokes) {
      List<GmlPoint> points = stroke.getPoints();

      //for(GmlPoint point: points) {

      //point.subSelf(originShift);
      //point.scaleSelf(scaling);
      // Fix NaN
      //if (point.x != point.x) point.x = 0;
      //if (point.y != point.y) point.y = 0;
      //if (point.z != point.z) point.z = 0;
      //}

      for(int i=0; i<points.size(); i++) {
        GmlPoint p = points.get(i);
        p.subSelf(originShift);
        p.scaleSelf(scaling);

        // Fix NaN
        if (p.x != p.x || p.y != p.y || p.z != p.z) {
          points.remove(i);
        }
        else {
          points.set(i, p);
        }

      }
      stroke.replacePoints(points);
    }
    gml.replaceStrokes(strokes);

    // Normalize z axis
    // Get max z
   
    boundingBox = gml.getBoundingBox();
    LOGGER.log(Level.FINEST, "bounding box after rescale"+ boundingBox.getMin() + " " + boundingBox.getMax());
   
    float maxZ = boundingBox.getMax().z;
    if(maxZ > 1) {
      LOGGER.log(Level.FINEST, "Z axis too long. Rescaling to fit 0-1");
    // Else remap between 0 and 1
      for (GmlStroke strok : gml.getStrokes()) {
        float nPoints = strok.getPoints().size();
        for (int i=0; i<nPoints; i++) {
          strok.getPoints().get(i).z = strok.getPoints().get(i).z/maxZ;
        }
      }   
    }
    boundingBox = gml.getBoundingBox();
    LOGGER.log(Level.FINEST, "bounding box after z axis correction"+ boundingBox.getMin() + " " + boundingBox.getMax());   


    // Store the aspect ratio and origin for reverse scaling
    // Any point can then be rescaled to original value by doing:
    //(point.scaleSelf(originalAspectRatio).addSelf(originShift);
View Full Code Here

      // Normalize
      LOGGER.log(Level.FINEST, "Client "+CLIENT_GRAFANALYSIS);
     
      // Get max z from normalized screenBounds
      Vec3D screenScale = Vec3DUtils.getNormalized(gml.environment.screenBounds);     
      AABB boundingBox = gml.getBoundingBox();
           
      // Remap all points' z coords so they fit between 0 and 0.25
      // Might not be super accurate but good enough
      List<GmlStroke> strokes = (List<GmlStroke>) gml.getStrokes();
      for (GmlStroke stroke : strokes) {
        List<GmlPoint> points = stroke.getPoints();
        for(GmlPoint point: points) {
          point.z = MappingUtils.map(point.z, boundingBox.getMin().z, boundingBox.getMax().z, 0, .25f);
          if (point.z != point.z) point.z = 0;
        }
        stroke.replacePoints(points);
      }
      gml.replaceStrokes(strokes);
View Full Code Here

    PointCloud pointCloud = new PointCloud();
    ArrayList<Vec3D> list = new ArrayList<Vec3D>();

    // TODO choose what to return (0 or center) when there is no stroke
    for (GmlStroke stroke : getStrokes()) {
      AABB bounds = stroke.getBoundingBox();
      list.add(bounds.getMin());
      list.add(bounds.getMax());
    }

    pointCloud.addAll(list);
    return pointCloud.getBoundingBox();
  }
View Full Code Here

TOP

Related Classes of toxi.geom.AABB

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.