Skip to content
Snippets Groups Projects
Commit 518f8b1c authored by Knuiman, Bart's avatar Knuiman, Bart
Browse files

bugfixes

parent 1e8fdf0f
No related branches found
No related tags found
No related merge requests found
...@@ -183,8 +183,6 @@ namespace Wander ...@@ -183,8 +183,6 @@ namespace Wander
// vector tile provider. // vector tile provider.
public void IdentifyLayers( Func<VectorTileLayer, List<KeyValuePair<string, object>>, int> selectionCallback ) public void IdentifyLayers( Func<VectorTileLayer, List<KeyValuePair<string, object>>, int> selectionCallback )
{ {
Debug.Assert( triangulated, "First call Triangulate." );
for (int l = 0;l < layers.Count;l++) for (int l = 0;l < layers.Count;l++)
{ {
var layer = layers[l]; var layer = layers[l];
...@@ -196,16 +194,10 @@ namespace Wander ...@@ -196,16 +194,10 @@ namespace Wander
int uniqueId = selectionCallback( layer, feature.Attributes ); int uniqueId = selectionCallback( layer, feature.Attributes );
if (uniqueId > -1) if (uniqueId > -1)
{ {
if ( uniqueId == 8 )
{
int jt = 0;
}
feature.SelectedLayerIdx = uniqueId; feature.SelectedLayerIdx = uniqueId;
break; // Done with this feature.
} }
} }
} }
layersIdentified = true; layersIdentified = true;
} }
...@@ -229,21 +221,25 @@ namespace Wander ...@@ -229,21 +221,25 @@ namespace Wander
failedPixels = new List<Vector3Int>(); failedPixels = new List<Vector3Int>();
remappedLayerIndices = new Dictionary<byte, byte>(); remappedLayerIndices = new Dictionary<byte, byte>();
byte cachedPixel = 0; byte cachedPixel = 0;
float oneOverRes = 1.0f / resolution;
TriangulatedPolygon cachedPoly = default;
int cachedVtxIdx = -1;
int cachedTriIdx = -1;
// For each layer, for each pixel, check triangle intersections. // For each pixel.
for (int l = 0;l < layers.Count && !cancelToken.Value;l++) for (int y = 0;y < resolution ;y++)
{ {
var layer = layers[l]; for (int x = 0;x < resolution && !cancelToken.Value ;x++)
float fx = (float)layer.Extent / resolution;
TriangulatedPolygon cachedPoly = default;
int cachedVtxIdx = -1;
int cachedTriIdx = -1;
for (int y = 0;y < resolution && !cancelToken.Value;y++)
{ {
for (int x = 0; x < resolution; x++) bool hit = false;
// For each layer, check triangle intersections.
for (int l = 0;l < layers.Count && !cancelToken.Value;l++)
{ {
var layer = layers[l];
float fx = layer.Extent * oneOverRes;
Vector2 p = new Vector2(fx*x+0.5f*fx, fx*y+0.5f*fx); Vector2 p = new Vector2(fx*x+0.5f*fx, fx*y+0.5f*fx);
bool hit = false;
// First try cache, quite often adjacent pixels will hit the same triangle. // First try cache, quite often adjacent pixels will hit the same triangle.
if (cachedVtxIdx!=-1) if (cachedVtxIdx!=-1)
...@@ -259,7 +255,7 @@ namespace Wander ...@@ -259,7 +255,7 @@ namespace Wander
if (hit) if (hit)
{ {
texture[(resolution - y -1)*resolution+x] = cachedPixel; texture[(resolution - y -1)*resolution+x] = cachedPixel;
continue; // Pass from cache, continue to next pixel. break; // Pass from cache, continue to next pixel.
} }
} }
} }
...@@ -279,23 +275,19 @@ namespace Wander ...@@ -279,23 +275,19 @@ namespace Wander
cachedVtxIdx = -1; cachedVtxIdx = -1;
cachedPoly = polygonLayers[l][f]; cachedPoly = polygonLayers[l][f];
var mins = cachedPoly.mins; var mins = cachedPoly.mins;
var maxs = cachedPoly.maxs; var maxs = cachedPoly.maxs;
var denoms = cachedPoly.denoms; var denoms = cachedPoly.denoms;
var vertices = cachedPoly.vertices; var vertices = cachedPoly.vertices;
for (int vIdx = 0, triIdx = 0; vIdx < vertices.Count; vIdx += 3, triIdx++) for (int vIdx = 0, triIdx = 0;vIdx < vertices.Count;vIdx += 3, triIdx++)
{ {
if ( p.x < mins[triIdx].x || p.x > maxs[triIdx].x ) continue; if (p.x < mins[triIdx].x || p.x > maxs[triIdx].x) continue;
if ( p.y < mins[triIdx].y || p.y > maxs[triIdx].y ) continue; if (p.y < mins[triIdx].y || p.y > maxs[triIdx].y) continue;
hit = GeomUtil.PointIsInsideTriangle2( p, vertices[vIdx], vertices[vIdx+1], vertices[vIdx+2], denoms[triIdx] ); hit = GeomUtil.PointIsInsideTriangle2( p, vertices[vIdx], vertices[vIdx+1], vertices[vIdx+2], denoms[triIdx] );
if (hit) if (hit)
{ {
cachedTriIdx = triIdx; cachedTriIdx = triIdx;
cachedVtxIdx = vIdx; cachedVtxIdx = vIdx;
cachedPixel = (byte)feature.SelectedLayerIdx; cachedPixel = (byte)feature.SelectedLayerIdx;
if ( cachedPixel == 8 )
{
int jt = 0;
}
texture[(resolution - y -1)*resolution+x] = cachedPixel; texture[(resolution - y -1)*resolution+x] = cachedPixel;
break; break;
} }
...@@ -304,11 +296,13 @@ namespace Wander ...@@ -304,11 +296,13 @@ namespace Wander
if (hit) break; if (hit) break;
} }
if ( !hit ) if (hit) break;
{ }
// texture[(resolution - y -1)*resolution+x] = 255;
failedPixels.Add( new Vector3Int( x, y, 255 ) ); if (!hit)
} {
texture[(resolution - y -1)*resolution+x] = 255;
failedPixels.Add( new Vector3Int( x, y, 255 ) );
} }
} }
} }
...@@ -324,11 +318,7 @@ namespace Wander ...@@ -324,11 +318,7 @@ namespace Wander
for (int x = 0;x < resolution;x++) for (int x = 0;x < resolution;x++)
{ {
byte pixel = texture[addr]; byte pixel = texture[addr];
if (pixel == 8 ) if ( pixel != cachedPixel && pixel < 254 /*used for not matched layer*/ )
{
int jt = 0;
}
if ( pixel != cachedPixel && pixel != 254 /*used for not matched layer*/ )
{ {
if (!remappedLayerIndices.TryGetValue( pixel, out remappedPixel )) if (!remappedLayerIndices.TryGetValue( pixel, out remappedPixel ))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment