Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • wander/vectortile
1 result
Show changes
Commits on Source (2)
using GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Configuration;
using Mapbox.Vector.Tile; using Mapbox.Vector.Tile;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -193,6 +192,13 @@ namespace Wander ...@@ -193,6 +192,13 @@ namespace Wander
return numFailedPolys; return numFailedPolys;
} }
bool IsPolygonLayerWater( int layerIdx, int featureIdx, int waterLayerIdx )
{
var layer = layers[layerIdx];
var feature = layer.VectorTileFeatures[featureIdx];
return feature.SelectedLayerIdx==waterLayerIdx;
}
bool DoesPolygonLayerQualify( int layerIdx, int featureIdx ) bool DoesPolygonLayerQualify( int layerIdx, int featureIdx )
{ {
var layer = layers[layerIdx]; var layer = layers[layerIdx];
...@@ -351,6 +357,37 @@ namespace Wander ...@@ -351,6 +357,37 @@ namespace Wander
layersIdentified = true; layersIdentified = true;
} }
public List<List<TriangulatedPolygon>> GetWaterPolygons( int waterLayerIdx, ref bool cancelToken )
{
UnityEngine.Debug.Assert( triangulated, "First call Triangulate." );
UnityEngine.Debug.Assert( layersIdentified, "Identify layers first." );
Stopwatch sw = new Stopwatch();
sw.Restart();
var waters = new List<List<TriangulatedPolygon>>();
for (int l = 0;l < polygonLayers.Count;l++)
{
var layer = layers[l];
var water = new List<TriangulatedPolygon>();
for (int f = 0;f < layer.VectorTileFeatures.Count && !cancelToken ;f++)
{
if (DoesPolygonLayerQualify( l, f ) && IsPolygonLayerWater(l, f, waterLayerIdx))
{
var poly = polygonLayers[l][f];
water.Add( poly );
}
}
if (water.Count> 0)
{
waters.Add( water );
}
}
return waters;
}
// Generates a raster for each position (pixel). 2 pixels are pushed in 1 (each 16 bit). // Generates a raster for each position (pixel). 2 pixels are pushed in 1 (each 16 bit).
// If no polygon was hit, 15 is encoded (reserved). // If no polygon was hit, 15 is encoded (reserved).
// If polygon was hit, but no feature was matched, also 15 is encoded. // If polygon was hit, but no feature was matched, also 15 is encoded.
...@@ -371,6 +408,8 @@ namespace Wander ...@@ -371,6 +408,8 @@ namespace Wander
UnityEngine.Debug.Assert( resolution > 1, "Must be at least 2." ); UnityEngine.Debug.Assert( resolution > 1, "Must be at least 2." );
byte [] texture = new byte[resolution*resolution/2]; byte [] texture = new byte[resolution*resolution/2];
bool [] written = new bool[resolution*resolution];
int d = 4096 / resolution; int d = 4096 / resolution;
int shift = -1; int shift = -1;
while (d!=0) while (d!=0)
...@@ -393,6 +432,7 @@ namespace Wander ...@@ -393,6 +432,7 @@ namespace Wander
{ {
var min = poly.mins[t]; var min = poly.mins[t];
var max = poly.maxs[t]; var max = poly.maxs[t];
int x1 = Mathf.FloorToInt( min.x ); int x1 = Mathf.FloorToInt( min.x );
int y1 = Mathf.FloorToInt( min.y ); int y1 = Mathf.FloorToInt( min.y );
int x2 = Mathf.FloorToInt( max.x ); int x2 = Mathf.FloorToInt( max.x );
...@@ -425,11 +465,14 @@ namespace Wander ...@@ -425,11 +465,14 @@ namespace Wander
if (PointInTriangle( new Vector2( xk2, yk2 ), poly.vertices[i], poly.vertices[i+1], poly.vertices[i+2] )) if (PointInTriangle( new Vector2( xk2, yk2 ), poly.vertices[i], poly.vertices[i+1], poly.vertices[i+2] ))
{ {
var addr2 = (resolution - y -1)*resolution+x; var addr2 = (resolution - y -1)*resolution+x;
//var addr2 = (resolution* y)+x; if (!written[addr2])
if (layerIdx > 15) {
layerIdx = 15; // max layers 15 (15 is reserved, nothing was hit). written[addr2]=true;
var shift2 = (addr2&1) << 2; if (layerIdx > 15)
texture[addr2>>1] |= (byte)(layerIdx << shift2); layerIdx = 15; // max layers 15 (15 is reserved, nothing was hit).
var shift2 = (addr2&1) << 2;
texture[addr2>>1] |= (byte)(layerIdx << shift2);
}
} }
} }
} }
...@@ -563,8 +606,9 @@ namespace Wander ...@@ -563,8 +606,9 @@ namespace Wander
{ {
if ((x&1) == 0) if ((x&1) == 0)
pixel = texture[addr>>1]; pixel = texture[addr>>1];
UnityEngine.Debug.Assert( (pixel&0xF) < 10 && ((pixel>>4)&0xF) < 10 );
byte shift = (byte)((addr&1)); byte shift = (byte)((addr&1));
byte pixel2 = (byte)((pixel >> (shift<<2)) & 15); byte pixel2 = (byte)((pixel >> (shift<<2)) & 0xF);
if (pixel2 != 15) if (pixel2 != 15)
{ {
if (pixel2 != cachedPixel) if (pixel2 != cachedPixel)
......