private bool ProcessFeature(int index, UnityTile tile, VectorLayerVisualizerProperties layerProperties, float layerExtent) { var fe = layerProperties.vectorTileLayer.GetFeature(index); List <List <Point2d <float> > > geom; if (layerProperties.buildingsWithUniqueIds == true) //ids from building dataset is big ulongs { geom = fe.Geometry <float>(); //and we're not clipping by passing no parameters if (geom[0][0].X <0 || geom[0][0].X> layerExtent || geom[0][0].Y <0 || geom[0][0].Y> layerExtent) { return(false); } } else //streets ids, will require clipping { geom = fe.Geometry <float>(0); //passing zero means clip at tile edge } var feature = new VectorFeatureUnity(layerProperties.vectorTileLayer.GetFeature(index), geom, tile, layerProperties.vectorTileLayer.Extent, layerProperties.buildingsWithUniqueIds); if (IsFeatureEligibleAfterFiltering(feature, tile, layerProperties)) { if (tile != null && tile.gameObject != null && tile.VectorDataState != Enums.TilePropertyState.Cancelled) { switch (layerProperties.featureProcessingStage) { case FeatureProcessingStage.PreProcess: //pre process features. PreProcessFeatures(feature, tile, tile.gameObject); break; case FeatureProcessingStage.Process: //skip existing features, only works on tilesets with unique ids if (ShouldSkipProcessingFeatureWithId(feature.Data.Id, tile, layerProperties)) { return(false); } //feature not skipped. Add to pool only if features are in preprocess stage. AddFeatureToTileObjectPool(feature, tile); Build(feature, tile, tile.gameObject); break; case FeatureProcessingStage.PostProcess: break; default: break; } _entityInCurrentCoroutine++; } } return(true); }
private bool ProcessFeature(int index, UnityTile tile, VectorLayerVisualizerProperties layerProperties) { var feature = GetFeatureinTileAtIndex(index, tile, layerProperties); if (IsFeatureEligibleAfterFiltering(feature, tile, layerProperties)) { if (tile != null && tile.gameObject != null && tile.VectorDataState != Enums.TilePropertyState.Cancelled) { switch (layerProperties.featureProcessingStage) { case FeatureProcessingStage.PreProcess: //pre process features. PreProcessFeatures(feature, tile, tile.gameObject); break; case FeatureProcessingStage.Process: //skip existing features, only works on tilesets with unique ids if (ShouldSkipProcessingFeatureWithId(feature.Data.Id, tile, layerProperties)) { return(false); } //feature not skipped. Add to pool only if features are in preprocess stage. AddFeatureToTileObjectPool(feature, tile); Build(feature, tile, tile.gameObject); break; case FeatureProcessingStage.PostProcess: break; default: break; } _entityInCurrentCoroutine++; } } return(true); }
protected IEnumerator ProcessLayer(VectorTileLayer layer, UnityTile tile, UnwrappedTileId tileId, Action <UnityTile, LayerVisualizerBase> callback = null) { if (tile == null) { yield break; } VectorLayerVisualizerProperties tempLayerProperties = new VectorLayerVisualizerProperties(); tempLayerProperties.vectorTileLayer = layer; tempLayerProperties.featureProcessingStage = FeatureProcessingStage.PreProcess; //Get all filters in the array. tempLayerProperties.layerFeatureFilters = _layerProperties.filterOptions.filters.Select(m => m.GetFilterComparer()).ToArray(); // Pass them to the combiner tempLayerProperties.layerFeatureFilterCombiner = new Filters.LayerFilterComparer(); switch (_layerProperties.filterOptions.combinerType) { case Filters.LayerFilterCombinerOperationType.Any: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.AnyOf(tempLayerProperties.layerFeatureFilters); break; case Filters.LayerFilterCombinerOperationType.All: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.AllOf(tempLayerProperties.layerFeatureFilters); break; case Filters.LayerFilterCombinerOperationType.None: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.NoneOf(tempLayerProperties.layerFeatureFilters); break; default: break; } tempLayerProperties.buildingsWithUniqueIds = (_layerProperties.honorBuildingIdSetting) && _layerProperties.buildingsWithUniqueIds; //find any replacement criteria and assign them foreach (var goModifier in _defaultStack.GoModifiers) { if (goModifier is IReplacementCriteria && goModifier.Active) { SetReplacementCriteria((IReplacementCriteria)goModifier); } } #region PreProcess & Process. var featureCount = (tempLayerProperties.vectorTileLayer == null) ? 0 : tempLayerProperties.vectorTileLayer.FeatureCount(); do { for (int i = 0; i < featureCount; i++) { //checking if tile is recycled and changed if (tile.UnwrappedTileId != tileId || !_activeCoroutines.ContainsKey(tile) || tile.TileState == Enums.TilePropertyState.Unregistered) { yield break; } ProcessFeature(i, tile, tempLayerProperties, layer.Extent); if (IsCoroutineBucketFull && !(Application.isEditor && !Application.isPlaying)) { //Reset bucket.. _entityInCurrentCoroutine = 0; yield return(null); } } // move processing to next stage. tempLayerProperties.featureProcessingStage++; } while (tempLayerProperties.featureProcessingStage == FeatureProcessingStage.PreProcess || tempLayerProperties.featureProcessingStage == FeatureProcessingStage.Process); #endregion #region PostProcess // TODO : Clean this up to follow the same pattern. var mergedStack = _defaultStack as MergedModifierStack; if (mergedStack != null && tile != null) { mergedStack.End(tile, tile.gameObject, layer.Name); } #endregion if (callback != null) { callback(tile, this); } }
/// <summary> /// Function to check if the feature is already in the active Id pool, features already in active Id pool should be skipped from processing. /// </summary> /// <returns><c>true</c>, if feature is already in activeId pool or if the layer has buildingsWithUniqueId flag set to <see langword="true"/>, <c>false</c> otherwise.</returns> /// <param name="featureId">Feature identifier.</param> private bool ShouldSkipProcessingFeatureWithId(ulong featureId, UnityTile tile, VectorLayerVisualizerProperties layerProperties) { return(layerProperties.buildingsWithUniqueIds && _activeIds.Contains(featureId)); }
/// <summary> /// Function to fetch feature in vector tile at the index specified. /// </summary> /// <returns>The feature in tile at the index requested.</returns> /// <param name="tile">Unity Tile containing the feature.</param> /// <param name="index">Index of the vector feature being requested.</param> private VectorFeatureUnity GetFeatureinTileAtIndex(int index, UnityTile tile, VectorLayerVisualizerProperties layerProperties) { return(new VectorFeatureUnity(layerProperties.vectorTileLayer.GetFeature(index), tile, layerProperties.vectorTileLayer.Extent, layerProperties.buildingsWithUniqueIds)); }
/// <summary> /// Apply filters to the layer and check if the current feature is eleigible for rendering. /// </summary> /// <returns><c>true</c>, if feature eligible after filtering was applied, <c>false</c> otherwise.</returns> /// <param name="feature">Feature.</param> private bool IsFeatureEligibleAfterFiltering(VectorFeatureUnity feature, UnityTile tile, VectorLayerVisualizerProperties layerProperties) { if (layerProperties.layerFeatureFilters.Count() == 0) { return(true); } else { // build features only if the filter returns true. if (layerProperties.layerFeatureFilterCombiner.Try(feature)) { return(true); } } return(false); }
protected IEnumerator ProcessLayer(VectorTileLayer layer, UnityTile tile, Action callback = null) { //HACK to prevent request finishing on same frame which breaks modules started/finished events yield return(null); if (tile == null) { yield break; } VectorLayerVisualizerProperties tempLayerProperties = new VectorLayerVisualizerProperties(); tempLayerProperties.vectorTileLayer = layer; tempLayerProperties.featureProcessingStage = FeatureProcessingStage.PreProcess; //Get all filters in the array. tempLayerProperties.layerFeatureFilters = _layerProperties.filterOptions.filters.Select(m => m.GetFilterComparer()).ToArray(); // Pass them to the combiner tempLayerProperties.layerFeatureFilterCombiner = new Filters.LayerFilterComparer(); switch (_layerProperties.filterOptions.combinerType) { case Filters.LayerFilterCombinerOperationType.Any: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.AnyOf(tempLayerProperties.layerFeatureFilters); break; case Filters.LayerFilterCombinerOperationType.All: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.AllOf(tempLayerProperties.layerFeatureFilters); break; case Filters.LayerFilterCombinerOperationType.None: tempLayerProperties.layerFeatureFilterCombiner = Filters.LayerFilterComparer.NoneOf(tempLayerProperties.layerFeatureFilters); break; default: break; } tempLayerProperties.buildingsWithUniqueIds = (_layerProperties.honorBuildingIdSetting) && _layerProperties.buildingsWithUniqueIds; ////find any replacement criteria and assign them foreach (var goModifier in _defaultStack.GoModifiers) { if (goModifier is IReplacementCriteria && goModifier.Active) { SetReplacementCriteria((IReplacementCriteria)goModifier); } } #region PreProcess & Process. var featureCount = tempLayerProperties.vectorTileLayer.FeatureCount(); do { for (int i = 0; i < featureCount; i++) { ProcessFeature(i, tile, tempLayerProperties); if (IsCoroutineBucketFull) { //Reset bucket.. _entityInCurrentCoroutine = 0; yield return(null); } } // move processing to next stage. tempLayerProperties.featureProcessingStage++; } while (tempLayerProperties.featureProcessingStage == FeatureProcessingStage.PreProcess || tempLayerProperties.featureProcessingStage == FeatureProcessingStage.Process); #endregion #region PostProcess // TODO : Clean this up to follow the same pattern. var mergedStack = _defaultStack as MergedModifierStack; if (mergedStack != null && tile != null) { mergedStack.End(tile, tile.gameObject, layer.Name); } #endregion if (callback != null) { callback(); } }
/// <summary> /// Apply filters to the layer and check if the current feature is eleigible for rendering. /// </summary> /// <returns><c>true</c>, if feature eligible after filtering was applied, <c>false</c> otherwise.</returns> /// <param name="feature">Feature.</param> private bool IsFeatureEligibleAfterFiltering(VectorFeatureUnity feature, UnityTile tile, VectorLayerVisualizerProperties layerProperties) { return(!layerProperties.layerFeatureFilters.Any() || layerProperties.layerFeatureFilterCombiner.Try(feature)); // build features only if the filter returns true. }