private static Dictionary <BHoMObject, BoundingBox> FilterObjects(List <BHoMObject> objects, SpatialSpecification spatialSpec) { Dictionary <BHoMObject, BoundingBox> passedObj_zoneBox = new Dictionary <BHoMObject, BoundingBox>(); Dictionary <BHoMObject, IGeometry> objsGeometry = new Dictionary <BHoMObject, IGeometry>(); // Compute the geometry for each object. foreach (var obj in objects) { BHoMObject bhomObj = obj as BHoMObject; IGeometry geom = BH.Engine.Base.Query.IGeometry(bhomObj); if (geom == null) { BH.Engine.Reflection.Compute.RecordWarning($"Could not Query the Geometry out of a given {bhomObj.GetType().Name}."); continue; } objsGeometry[bhomObj] = geom; } // Filter objects based on the spatialSpecifications. ZoneSpecification zoneSpec = spatialSpec.ZoneSpecification; // A bounding box is calculated per each object as defined by the individual ZoneSpecification Dictionary <BHoMObject, BoundingBox> bbPerObj = new Dictionary <BHoMObject, BoundingBox>(); List <BoundingBox> allZoneBoxes = spatialSpec.SpatialBoundingBoxes(); foreach (BHoMObject bhomObj in objsGeometry.Keys) { // Check if any of the Specification's boundingBoxes contains the object foreach (var zoneBB in allZoneBoxes) { if (zoneBB.IsContaining(objsGeometry[bhomObj])) { // If the zone bounding box contains the bhomObject's Geometry, let's apply the other filters. var res = VerifyCondition(new List <object>() { bhomObj }, new LogicalCondition() { Conditions = zoneSpec.FilterConditions }); if (res.PassedObjects.Count == 1) // if the object passed all the provided Conditions, then it's passed. { passedObj_zoneBox[res.PassedObjects.First() as BHoMObject] = zoneBB; } } } } return(passedObj_zoneBox); }
public static List <BoundingBox> SpatialBoundingBoxes(this SpatialSpecification spatialSpec) { List <BoundingBox> result = new List <BoundingBox>(); List <IGeometry> locations = spatialSpec.Locations.Select(l => BH.Engine.CIH.Query.IGeometry(l)).ToList(); ZoneSpecification zoneSpec = spatialSpec.ZoneSpecification; foreach (var loc in locations) { BoundingBox bb = Query.IElementBoundingBox(loc, zoneSpec.Width, zoneSpec.Height, zoneSpec.Depth); if (bb != null) { result.Add(bb); } } return(result); }
public static SpatialSpecification SpatialSpecification(List <IObject> referenceElements, ZoneSpecification zoneSpecification, string prop = "ZoneName") { SpatialSpecification result = new SpatialSpecification(); foreach (var loc in referenceElements) { string zoneName = Reflection.Query.PropertyValue(loc, "ZoneName") as string; if (zoneName == zoneSpecification.ZoneName) { result.Locations.Add(loc); } } result.ZoneSpecification = zoneSpecification; return(result); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static SpecificationResult VerifySpecification(List <object> objects, ZoneSpecification spatialSpec) { BH.Engine.Reflection.Compute.RecordError($"Zone Specifications cannot be applied directly: they have to be paired with a specific location. Read the description of the method `Create.{nameof(Create.SpatialSpecification)}`."); return(null); }