Package org.osm2world.core.math

Examples of org.osm2world.core.math.SimplePolygonXZ


       
        List<SimplePolygonXZ> subtractPolygons = new ArrayList<SimplePolygonXZ>();
       
        for (TerrainBoundaryWorldObject o : tbWorldObjects) {
         
          SimplePolygonXZ subtractPoly = o.getOutlinePolygonXZ();
         
          subtractPolygons.add(subtractPoly);
         
          if (o instanceof WaySegmentWorldObject) {
           
            // extend the subtract polygon for segments that end
            // at a common node with this building part's outline.
            // (otherwise, the subtract polygon will probably
            // not exactly line up with the polygon boundary)
           
            WaySegmentWorldObject waySegmentWO = (WaySegmentWorldObject)o;
            VectorXZ start = waySegmentWO.getStartPosition();
            VectorXZ end = waySegmentWO.getEndPosition();
           
            boolean startCommonNode = false;
            boolean endCommonNode = false;
           
            for (SimplePolygonXZ p : polygon.getPolygons()) {
              startCommonNode |= p.getVertexCollection().contains(start);
              endCommonNode |= p.getVertexCollection().contains(end);
            }
           
            VectorXZ direction = end.subtract(start).normalize();
           
            if (startCommonNode) {
              subtractPolygons.add(subtractPoly.shift(direction));
            }
           
            if (endCommonNode) {
              subtractPolygons.add(subtractPoly.shift(direction.invert()));
            }
           
          }
         
        }
View Full Code Here


    for (WorldObject worldObject : worldObjects) {
     
      if (worldObject.getGroundState() == GroundState.ON
        && (worldObject instanceof WorldObjectWithOutline)) {
       
        SimplePolygonXZ outline = null;
       
        try {
          outline = ((WorldObjectWithOutline)worldObject).
              getOutlinePolygonXZ();
        } catch (InvalidGeometryException e) {
View Full Code Here

     
      public PyramidalRoof() {
     
        super();
       
        SimplePolygonXZ outerPoly = polygon.getOuter();
       
        apex = outerPoly.getCentroid();
       
        innerSegments = new ArrayList<LineSegmentXZ>();
        for (VectorXZ v : outerPoly.getVertices()) {
          innerSegments.add(new LineSegmentXZ(v, apex));
        }
       
      }
View Full Code Here

          }
        }
       
        if (slopeDirection != null) {
         
          SimplePolygonXZ simplifiedOuter =
              polygon.getOuter().getSimplifiedPolygon();
         
          /* find ridge by calculating the outermost intersections of
           * the quasi-infinite slope "line" towards the centroid vector
           * with segments of the polygon */
         
          VectorXZ center = simplifiedOuter.getCentroid();
         
          Collection<LineSegmentXZ> intersections =
              simplifiedOuter.intersectionSegments(new LineSegmentXZ(
                center.add(slopeDirection.mult(-1000)), center));
         
          LineSegmentXZ outermostIntersection = null;
          double distanceOutermostIntersection = -1;
         
View Full Code Here

       */
      public RoofWithRidge(double relativeRoofOffset) {
     
        super();
       
        SimplePolygonXZ outerPoly = polygon.getOuter();
       
        SimplePolygonXZ simplifiedPolygon =
          outerPoly.getSimplifiedPolygon();
       
        /* determine ridge direction based on tag if it exists,
         * otherwise choose direction of longest polygon segment */
       
        VectorXZ ridgeDirection = null;
       
        if (getValue("roof:ridge:direction") != null) {
          Float angle = parseAngle(
              getValue("roof:ridge:direction"));
          if (angle != null) {
            ridgeDirection = VectorXZ.fromAngle(toRadians(angle));
          }
        }
       
        if (ridgeDirection == null) {
         
          LineSegmentXZ longestSeg = MinMaxUtil.max(
              simplifiedPolygon.getSegments(),
              new Function<LineSegmentXZ, Double>() {
                public Double apply(LineSegmentXZ s) {
                  return s.getLength();
                };
              });
         
          ridgeDirection =
            longestSeg.p2.subtract(longestSeg.p1).normalize();
         
          if (area.getTags().contains("roof:orientation", "across")) {
            ridgeDirection = ridgeDirection.rightNormal();
          }
         
        }
       
        /* calculate the two outermost intersections of the
         * quasi-infinite ridge line with segments of the polygon */
       
        VectorXZ p1 = outerPoly.getCentroid();
       
        Collection<LineSegmentXZ> intersections =
          simplifiedPolygon.intersectionSegments(new LineSegmentXZ(
              p1.add(ridgeDirection.mult(-1000)),
              p1.add(ridgeDirection.mult(1000))
          ));

        if (intersections.size() < 2) {
View Full Code Here

    List<List<VectorXZ>> lines = asList(
        primaryRep.getCenterlineXZ(),
        primaryRep.getOutlineXZ(true),
        primaryRep.getOutlineXZ(false));
   
    SimplePolygonXZ outlinePolygonXZ = primaryRep.getOutlinePolygonXZ();
   
    /* ensure a minimum vertical distance to ways and areas below,
     * at intersections */
   
    for (MapOverlap<?,?> overlap : segment.getOverlaps()) {
     
      MapElement other = overlap.getOther(segment);
      WorldObject otherWO = other.getPrimaryRepresentation();
     
      if (otherWO == null
          || otherWO.getGroundState() != ON//TODO remove the ground state check
        continue;
     
      boolean thisIsUpper = this.getGroundState() == ABOVE; //TODO check layers
     
      double distance = 10.0; //TODO base on clearing
     
      if (overlap instanceof MapIntersectionWW) {
       
        MapIntersectionWW intersection = (MapIntersectionWW) overlap;
       
        if (otherWO instanceof AbstractNetworkWaySegmentWorldObject) {
         
          AbstractNetworkWaySegmentWorldObject otherANWSWO =
              ((AbstractNetworkWaySegmentWorldObject)otherWO);
         
          EleConnector thisConn = primaryRep.getEleConnectors()
              .getConnector(intersection.pos);
          EleConnector otherConn = otherANWSWO.getEleConnectors()
              .getConnector(intersection.pos);
         
          if (thisIsUpper) {
            enforcer.requireVerticalDistance(
                MIN, distance, thisConn, otherConn);
          } else {
            enforcer.requireVerticalDistance(
                MIN, distance, otherConn, thisConn);
          }
         
        }
       
      } else if (overlap instanceof MapOverlapWA) {
       
        /*
         * require minimum distance at intersection points
         * (these have been inserted into this segment,
         * but not into the area)
         */
       
        MapOverlapWA overlapWA = (MapOverlapWA) overlap;
       
        if (overlap.type == MapOverlapType.INTERSECT
            && otherWO instanceof AbstractAreaWorldObject) {
         
          AbstractAreaWorldObject otherAAWO =
              ((AbstractAreaWorldObject)otherWO);
         
          for (int i = 0; i < overlapWA.getIntersectionPositions().size(); i++) {
           
            VectorXZ pos =
                overlapWA.getIntersectionPositions().get(i);
            MapAreaSegment areaSegment =
                overlapWA.getIntersectingAreaSegments().get(i);
           
            EleConnector thisConn = primaryRep.getEleConnectors()
                .getConnector(pos);
           
            EleConnector base1 = otherAAWO.getEleConnectors()
                .getConnector(areaSegment.getStartNode().getPos());
            EleConnector base2 = otherAAWO.getEleConnectors()
                .getConnector(areaSegment.getEndNode().getPos());
                       
            if (thisConn != null && base1 != null && base2 != null) {
             
              if (thisIsUpper) {
                enforcer.requireVerticalDistance(MIN, distance,
                    thisConn, base1, base2);
              } else {
                enforcer.requireVerticalDistance(MAX, -distance,
                    thisConn, base1, base2);
              }
             
            }
           
          }
         
        }
       
        /*
         * require minimum distance to the area's elevation connectors.
         * There is usually no direct counterpart for these in this segment.
         * Examples include trees on terrain above tunnels.
         */
       
        if (!(otherWO instanceof Forest)) continue; //TODO enable and debug for other WO classes
       
        eleConnectors:
        for (EleConnector c : otherWO.getEleConnectors()) {
         
          if (outlinePolygonXZ == null ||
              !outlinePolygonXZ.contains(c.pos))
            continue eleConnectors;
         
          for (List<VectorXZ> line : lines) {
            for (int i = 0; i+1 < line.size(); i++) {
             
View Full Code Here

TOP

Related Classes of org.osm2world.core.math.SimplePolygonXZ

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.