Street Builder

26
Stefano Tranquillini Street Builder Principi di Computer Grafica – UNITN 0809

description

This project aim to be a run-time street builder done inside World Wind. This application works drawing texturized shapes accordingly to the position given by the user. The program modifies the terrain taken the elevation from these shapes in order to have a street every time over the terrain. User can: add and remove pieces of shap, add and remove shape, select shapes already present, move points of the street, modify the blend. All these stuff are explained inside this paper.

Transcript of Street Builder

Page 1: Street Builder

 

 

 

 

 

 

 

  

 

 

 

Stefano Tranquillini Street Builder 

 

Principi di Computer Grafica – UNITN 08‐09 

    

Page 2: Street Builder

   

Page 3: Street Builder

Summary Abstract ....................................................................................................................................................................6 

Street Builder ............................................................................................................................................................6 

Library used ..........................................................................................................................................................6 

Interface ...................................................................................................................................................................6 

Load and Save .......................................................................................................................................................7 

Add .......................................................................................................................................................................7 

Edit ........................................................................................................................................................................7 

Pick........................................................................................................................................................................7 

Move .....................................................................................................................................................................7 

Delete ...................................................................................................................................................................8 

Setting ...................................................................................................................................................................8 

The Project’s file .......................................................................................................................................................8 

Street ....................................................................................................................................................................8 

Shape ....................................................................................................................................................................8 

Street ................................................................................................................................................................8 

Guard rail ..........................................................................................................................................................9 

The classes ............................................................................................................................................................. 10 

How Project Works ................................................................................................................................................ 10 

Construction of a street ..................................................................................................................................... 10 

Modification of points ....................................................................................................................................... 15 

Modification of the terrain ................................................................................................................................ 16 

Rectangular Tessellator ................................................................................................................................. 16 

ModifiedTerrain ............................................................................................................................................. 20 

TerrainBoundary ............................................................................................................................................ 21 

Some Results and image ........................................................................................................................................ 22 

Modification of terrain ...................................................................................................................................... 22 

Line construction ............................................................................................................................................... 23 

Blend .................................................................................................................................................................. 23 

Tile density ......................................................................................................................................................... 25 

Conclusion ............................................................................................................................................................. 26 

Possible extension ............................................................................................................................................. 26 

Page 4: Street Builder

Known bugs ....................................................................................................................................................... 26 

 

   

Page 5: Street Builder

   

Page 6: Street Builder

Abstract This project  aim  to be  a  run‐time  street builder done  inside World Wind. This application works drawing  texturized  shapes accordingly to the positions given by the user. The program modifies the terrain taken the elevation from these shapes in order to have a street every time over  the  terrain. User can: add and  remove pieces of a shape, add and remove shape, select shapes already present, move points of the street, modify the blend. All these stuff are explained  inside this paper. 

Street Builder 

Library used Inside this project I’d use: 

• World Wind source by NASA. Use the modify package (jar)! 

• JTS: java topological suite. 

• JOGL: a binding of OpenGL in java. 

• SimpleFramework to store and load XML. 

Interface 

 

Page 7: Street Builder

              

Load  Save  Add  Edit  Pick  Move  Delete  Setting  Information 

• Load: permits to load shape or shapes from file. 

• Save: store shape or shapes into a file.  

• Add: Adding a shape (street). 

• Edit: adding or removing pieces of the shape. 

• Pick: select a shape. 

• Move: permits to move the points of the street, and the Bezier control point. 

• Delete: remove the current shape. 

• Setting: change the setting of the system. 

Load and Save The user can select or specify the file to store or load. 

Add  This interface appears when a user tries to add a shape. The user can select the type of the street and the type of the guardrail. As we can see, each street has a different texture and dimension. Same thing for the guardrails.  All these information are store into a XML file. 

Edit The user can works on the current shape. If no shape is selected the add dialog is displayed and the user can specify the new shape to add. The edit functionality permits to: 

• Add a piece: simply click on the terrain with the left mouse button 

• Remove a piece: Clicking by the right mouse button 

Pick This function permits to select a shape. When is activates and the mouse rollover a shape the shape become green. If the user click on the shape, the shape become the current shape and the user can work on it. 

Move Clicking on this button, the system shown points on the current shape, points for: start and end pieces, 3 points for the Bezier. 

If inside setting, snap is enabling, the points of the street can be moved only on the middle line of the pieces. 

 

Page 8: Street Builder

NB: Bezier point can be: 

• Move: Simply click and drag the point 

• Rotate: Press and hold the “A” button and drag the point. 

• Resize: Press and hold the “S” button and drag the point. 

These last three functionalities are given to let at the user a way to have a better result. 

Delete Remove an entire shape. When a shape has to be removed a prompt is shown and the street becomes green. 

Setting 

 

This is the setting’s dialog, the user can specified: • The numbers of points that will be add at the current tile density. • If shown or not the current shape • If shown or not the interior boundary (grid) • If the points have to be snapped: the points is moved on the line of the quad, 

otherwise the movement is freehand. • If has to be shown the construction line. (see the results section ) • The path of the skirt Texture • The path from where load the shape configuration. 

 When click on save these information are stored into a file. 

The Project’s file Al lots of stuff are stored in files: shapes’ setting and the streets done by the user. 

Street In order to store the street the system serialize a class that aim to transport the information of the street. 

Shape There are two type of shape: street and guardrail. To add new shape need to construct a new file that follows the structure above. 

Street <shapeConfig> <path>shape\city.png</path> <delta_width>6.0</delta_width> <name>City Street </name> <description> </description> </shapeConfig>  

Contains: The texture path The dimension The name and a description. 

Page 9: Street Builder

Guard rail <guardrailConfig> <texGuard>shape\guardrail1.png</texGuard> <dimGuard>1.0</dimGuard> <name>GuardRail 1</name> </guardrailConfig>  

Contains: The texture path The dimension (elevation) The name and a description. 

 

   

Page 10: Street Builder

The classes This section contains a brief explanation of the classes. To have a better explanation looks on the JavaDoc or inside the code. 

 

• Gui: Contains the gui parts (the prompts shown on add and setting) • Information: Contains a static class (TempAdd). This class is used to 

share information into the project • Main: Contains the main class. This class manages the menu and the 

interaction. • Setting: This package contains the setting parts of the system. • Shape: Contains the classes that are used to build and render the 

shape. Shape is the parent class that contains a list of shapeQuad. Each ShapQuad is a piece of the street. 

• Terrain: This package contains the classes used to modify the terrain. ModifiedTerrain is the parent class that contains a list of TerrainBoundary. The RectangularTessellator is a modified version of the RectangularTessleator done by world wind. Dragable classes are used to allow the movement of the points. 

• UTIL:  This package contains the util part of the system o Listener: The manager of the listener: mouse and keyboard o Geom: My class that is used to compute line, intersection 

and other things. o Other: Class that allows a simply way to load stuff 

How Project Works In this section there’s the explanation about how the project works. 

Construction of a street The construction of a street is done in two different ways. The first time is a simple construction of a rectangle around a line (see image 1, 2 and 3). When a new piece is added the previous quad is cut and the new quad is added. Between these two quads a number of quads are added as connectors that are used to construct a blend. 

Page 11: Street Builder

Construct a line with two points. 

Construct the rectangle around the line 

Add a new point. 

Page 12: Street Builder

Construct the rectangle around the second and third points. As we can see the rectangles are overlapped and are not connected. 

To avoid the problem mentioned above, compute the line of the left boundary (green) and right boundary (red) and the center line (blue). Use these lines to find the new point of the rectangle. As we can see in the figure the intersection in red is the new points for the rectangle (has the minimum distance).  

Compute the normal line for the center line that pass inside the intersection point. This new point (the intersection of middle line and the normal line) give the new rectangle. 

Page 13: Street Builder

The new squares compute. 

Compute Bezier for the internal and external, in order to have a good result in a simply way for all the possible case. http://en.wikipedia.org/wiki/B%C3%A9zier_bend In this figure a simple bend done by the system.            

The user can modify the bend moving the points. 

Page 14: Street Builder

The result. 

NB: the vertexes are named in this way. The Boundary indexes are 2 and 3 near the start position and 0, 1 near the end. This is done by JTS that give us the boundary in this way. This figure is useful to understand how the algorithm for the newPieces works and how the vertexes are attached. 

 

These entire steps are done using a Meters coordinates, WW works in lat Lon (angle) and so, inside the render, there’s a converting of the coordinate in latlon done using a class PositionUtil:  

private Position fromUTMtoPosition(Position p, Coordinate e)  Inside the converting step there’s the calculation of the guard rail points done taken the boundary of the street and computing points that has an elevation plus the elevation of guard rail. In render step, each quad render a skirt from the boundary of the street to the center of the earth. 

Page 15: Street Builder

The guardrail and the skirt. The skirt is shown better in the following image. 

 

Modification of points The project permits to modify the point of the street. Clicking on button, on the shape appears some points, these points’ permits to move the pieces of the shape or the Bezier points. 

 

When a point is moved, the system recalculates all the connectors and the new vertices. These steps are done in the render. 

Page 16: Street Builder

 

The modification of the streets permits to create a lot of different type of bend. 

Using the “A” key hold and the movement of the mouse the point are rotated, if press “S” the points change its distance.  

Modification of the terrain When a new piece is added the project adds a TerrainBoundary at the quad. The TerrainBoundary class contains some proprieties and methods to compute the elevation of the points. First of all contains two points: the same of the street (the points around of which the rectangle is computed) used to create the rectangle of the points that will be modified.  

The use of TerrainBoundary is done by ModifiedTerrain class and this last class is called inside RectangularTessellator. 

Rectangular Tessellator RectangularTessellator is the class that calculate and create tiles and points, there’s a modification in two function that’s: BuildVerts and MakeVerts. 

A hashmap is added inside the RectangularTessellator in order to have a sort of cache of my modified terrain 

private HashMap<TileKey, ModifiedTerrain> ModifiedTerrains = new HashMap<TileKey, ModifiedTerrain>();  MakeVerts  

Page 17: Street Builder

 

The creation of the ModifiedTerrain 

if (Setting.showInterior == this.makeTileSkirts) { this.makeTileSkirts = !Setting.showInterior; WorldWind.getMemoryCache(CACHE_ID).clear(); dc.getModel().setShowWireframeInterior(Setting.showInterior);

This part is done to shown the interior Wireframe without the skirt. If there’s a change remove all the cache and recomputed all the tiles 

MemoryCache cache = WorldWind.getMemoryCache(CACHE_ID); CacheKey cacheKey = this.createCacheKey(dc, tile, resolution);

Page 18: Street Builder

 Read the cache of WW 

if (!TempAdd.toRemove) { tile.ri = (RenderInfo) cache.getObject(cacheKey);

if (tile.ri != null) { return;

} } else {

ModifiedTerrains.clear(); cache.clear(); cacheKey = null;

}  If there’s a modification (a pieces is added or removed: the ELSE branch) remove my cache and all the cache. Otherwise (the IF branch) load the information already present.  int totShape = TempAdd.shapes.size(); ModifiedTerrain mf = new ModifiedTerrain(); if (ModifiedTerrains.containsKey(tile.getTileKey())) {

mf = ModifiedTerrains.get(tile.getTileKey()); } else {

//construtct all. mf = new ModifiedTerrain();

for (int i = 0; i < totShape; i++) { Shape Shape_now = TempAdd.shapes.get(i); if (tile.sector.intersects(Shape_now.sector())) {

int tot_pice = Shape_now.pieces.size(); for (int j = 0; j < tot_pice; j++) {

TerrainBoundary sq = Shape_now.pieces.get(j).terrainBoundary; if (tile.sector.intersects(sq.sector())) {

mf.addTerrainBoundary(sq); } Vector<ShapeQuad> connectors = (Vector<ShapeQuad>)Shape_now.connectors.get(j + "-" + (j + 1)); if (connectors != null) {

int tot_partial = connectors.size(); for (int k = 0; k < tot_partial; k++) {

TerrainBoundary tb = connectors.get(k).terrainBoundary; if (tile.sector.intersects(tb.sector())) {

mf.addTerrainBoundary(tb); }

} }

} mf.isModified = true;

} }

} This part is the construction of the Modified terrain for the current tile. First check if inside my HashMap already present the modified terrain, if true: load it. Otherwise recreate all the Modified terrain. 

Page 19: Street Builder

For each shape check if the shape intersect the current tile. If is true check if a single piece intersect the tile, if the answer is positive, add this piece; otherwise do nothing. Same thing is done for connectors. At the end I’ve inside the ModifiedTerrain all the TerrainBoundary of all shape that is contained in this tile. 

if (mf.isModified) { ModifiedTerrains.put(tile.getTileKey(), mf); tile.mf = mf;

} tile.ri = this.buildVerts(dc, tile, resolution, this.makeTileSkirts); if (tile.ri != null && tile.ri.resolution >= 0) {

cacheKey = this.createCacheKey(dc, tile, tile.ri.resolution); cache.add(cacheKey, tile.ri, tile.ri.getSizeInBytes());

} In this step set the cache and add the ModifiedTerrain at the tile. 

BuildVerts 

 

The calculation of the elevation. 

if (tile.mf != null) { density += tile.mf.density;

} If ModifiedTerrain info exists, change the density adding the information of MT. 

..skip code skip code is the same of WW.. 

if (tile.mf != null) { double t_wwEle = elevations.getElevation(lat.radians, lon.radians); double t_elev = tile.mf.getElevation(lat, lon, delta, t_wwEle); elevation = t_elev;

} else { elevation = elevations.getElevation(lat.radians, lon.radians);

}

Page 20: Street Builder

 

If Modified Terrain information exists then calculate the elevation of WW, and using this elevation as parameter, passing lat lon of the point and the delta (the distance of two point) take the elevation from Modified terrain (I’ll explain this function in the next section). Otherwise if no information is present take simple the elevation of WW. 

NB: in BuildVerts are passed all the points of the tile, not only the point contained into TerrainBoundary so I’ve implemented the check of intersection of sector and contains of the points (see the following parts, especially the TerrainBoundary) to have a better performance. 

ModifiedTerrain This class contains all the TerrainBoundary, in other words all the TerrainBoundary contained in the tile. The most important function is getElevation (is two methods, one public and one private) 

public double getElevation(Angle lat, Angle lon, double delta, double wwElevation) { Position p = new Position(lat, lon, 0); double e = getElevation(p, delta); if (e == 0) {

return wwElevation; } else {

return Math.min(wwElevation, e); }

} This simply recall the private method and check if the private method give a 0 value (so, NO modification of elevation for this point) or return the minimum elevation between WWelevation and the project elevation. The function returns the minimum in order to have bridge if the point is over the terrain and a hole if the point is under the terrain. 

private double getElevation(Position p, double delta) { double ret = Double.MAX_VALUE; for (int i = 0; i < TerrainBoundarys.size(); i++) {

TerrainBoundary q = TerrainBoundarys.get(i); if (q.contains(p, delta)) {

if (q.isMiddle()) { return q.getElevation(p);

} else { ret = Math.min(ret, q.getElevation(p));

} }

} if (ret == Double.MAX_VALUE) {

return 0; } else {

return ret; }

}  

This function check for all the TerrainBoundary contained if the points is contains of the current TB, if is contained check if is a connector piece (is middle), in this case simply return the elevation (there’s no interpolation to do) otherwise return the minimum elevation found for all the TerrainBoundary. 

Page 21: Street Builder

The last if check there’s a modification or not. 

TerrainBoundary This class contains information of the terrain for a single piece.  

Contains: the sector of this piece; the two point of the piece in order to calculate the elevation (interpolation), these two points is the point uses to construct the piece of street and a polygon. The polygon is constructing using these two points and a delta value that change accordingly to delta value given by BuildVerts. This is done in order to check if the point is contained into this TB (so, needs to calculate the elevation) or not. 

From BuildVerts: tile.mf.getElevation(lat, lon, delta, t_wwEle);

Form ModifiedTerrain: q.contains(p, delta)

this delta value is the delta used to construct the rectangle of the terrain boundary. 

The red line is the middle line created from start to end point. The black rectangle is the street The blue rectangle is the rectangle that contains the point to modify.  The red point is a point that’s not taken by the interpolation. The green point is affected in elevation by the interpolation of these two point (start and end) 

 

The elevation is a simple interpolation of two point (start and end) done by a calculation of the distance (in latlon). 

The check of containing step is done using Polygon of JTS and "isContained" method. In order to have a better performance the polygon are stored into a hashmap to calculate these polygon once time. 

 

   

Page 22: Street Builder

Some Results and image 

Modification of terrain 

  

The bridge: the terrain is below the line 

A cutting of the terrain: the terrain is above the line In these 2 image we can see the difference of delta               

Page 23: Street Builder

Line construction  

The system allows to shown only the construction line of a street. You can show using the setting gui. 

 

Blend Some blend shown by construction line and rendered shape. In 3rd and 4th figure there’s a modification of the rotation and distance of Bezier points.  

Page 24: Street Builder

 

 

 

 

 

 

 

 

 

 

 

Page 25: Street Builder

Tile density  How change density affects the modification of the terrain: in first 0 added, second 40 added, last 100 added. The change of density takes only the tile that contains at least a pieces of a street. Otherwise the density still remain the same 

 

 

Page 26: Street Builder

Conclusion The project permits to construct street. New street type can be simply added using some special file XML. User can store and load streets from file, can pick and eliminated and change some setting, can modify points and blend.  All these stuff is done over WW using OpenGL and JTS. 

To run the project checks if the library are present. Check that the WW library is from MyWW modified library because I’ve modify some classes adding SimpleFramework stuff and other things to simplify my work (the name in ScreenAnnotation). 

Possible extension One extension is to add more points in Bezier in order to have a better result. Other extension can be: add some real constraint for the street like max and min slope, add the crossroad and other stuff.  

Known bugs The conversation from meters to latlon needs the hemisphere information. If a street goes across the equator the system return an exception. This is unsolvable in a simple way. 

Too much long street is not render as well. Some part is over the terrain interpolated. Probably is due to the spherical shape of the earth (is not a plane, the interpolation for long distance goes wrong)