/// <summary> /// Process member references. /// </summary> /// <param name="expression"> /// The expression to visit. /// </param> /// <returns> /// The visited expression. /// </returns> private Expression VisitMemberAccess(MemberExpression expression) { // Lookup the Mobile Services name of the member and use that string memberName = GetTableMemberName(expression, this.contractResolver); if (memberName != null) { this.filter.Append(memberName); return(expression); } // Check if this member is actually a function that looks like a // property (like string.Length, etc.) string methodName = null; MemberInfoKey memberInfoKey = new MemberInfoKey(expression.Member); if (InstanceProperties.TryGetValue(memberInfoKey, out methodName)) { this.filter.Append(methodName); this.filter.Append("("); this.Visit(expression.Expression); this.filter.Append(")"); return(expression); } // Otherwise we can't process the member. throw new NotSupportedException( string.Format( CultureInfo.InvariantCulture, Resources.FilterBuildingExpressionVisitor_MemberUnsupported, expression != null && expression.Member != null ? expression.Member.Name : null, expression != null ? expression.ToString() : null)); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static ModelInstance ModelInstanceFromRevit(this FamilyInstance adaptiveComponent, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); ModelInstance modelInstance = refObjects.GetValue <ModelInstance>(adaptiveComponent.Id); if (modelInstance != null) { return(modelInstance); } ElementType elementType = adaptiveComponent.Document.GetElement(adaptiveComponent.GetTypeId()) as ElementType; InstanceProperties instanceProperties = elementType.InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties; IEnumerable <BH.oM.Geometry.Point> pts = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(adaptiveComponent).Select(x => ((ReferencePoint)adaptiveComponent.Document.GetElement(x)).Position.PointFromRevit()); modelInstance = new ModelInstance { Properties = instanceProperties, Location = new CompositeGeometry { Elements = new List <IGeometry>(pts) } }; modelInstance.Name = adaptiveComponent.Name; //Set identifiers, parameters & custom data modelInstance.SetIdentifiers(adaptiveComponent); modelInstance.CopyParameters(adaptiveComponent, settings.ParameterSettings); modelInstance.SetProperties(adaptiveComponent, settings.ParameterSettings); refObjects.AddOrReplace(adaptiveComponent.Id, modelInstance); return(modelInstance); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static ElementType ToRevitElementType(this InstanceProperties instanceProperties, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { ElementType elementType = refObjects.GetValue <ElementType>(document, instanceProperties.BHoM_Guid); if (elementType != null) { return(elementType); } settings = settings.DefaultIfNull(); elementType = instanceProperties.ElementType(document, new List <BuiltInCategory> { instanceProperties.BuiltInCategory(document) }, settings); if (elementType == null) { return(null); } // Copy parameters from BHoM object to Revit element elementType.CopyParameters(instanceProperties, settings); refObjects.AddOrReplace(instanceProperties, elementType); return(elementType); }
private void OnAddExpression(ConditionGroup group) { var propertyExpression = new PropertyExpression(); propertyExpression.Property = InstanceProperties.FirstOrDefault(); group.Items.Add(propertyExpression); propertyExpression.Parent = group; }
public static DraftingInstance DraftingInstance(string name, string viewName, ISurface location) { InstanceProperties instanceProperties = new InstanceProperties(); instanceProperties.Name = name; return(Create.DraftingInstance(instanceProperties, viewName, location)); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static DraftingInstance DraftingInstanceFromRevit(this FilledRegion filledRegion, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); DraftingInstance draftingInstance = refObjects.GetValue <DraftingInstance>(filledRegion.Id); if (draftingInstance != null) { return(draftingInstance); } View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View; if (view == null) { return(null); } InstanceProperties instanceProperties = (filledRegion.Document.GetElement(filledRegion.GetTypeId()) as ElementType).InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties; List <ICurve> curves = new List <oM.Geometry.ICurve>(); foreach (CurveLoop loop in filledRegion.GetBoundaries()) { curves.Add(loop.FromRevit()); } List <PlanarSurface> surfaces = BH.Engine.Geometry.Create.PlanarSurface(curves); if (surfaces.Count == 1) { draftingInstance = new DraftingInstance { Properties = instanceProperties, ViewName = view.Name, Location = surfaces[0] } } ; else { draftingInstance = new DraftingInstance { Properties = instanceProperties, ViewName = view.Name, Location = new PolySurface { Surfaces = surfaces.Cast <ISurface>().ToList() } } }; draftingInstance.Name = filledRegion.Name; //Set identifiers, parameters & custom data draftingInstance.SetIdentifiers(filledRegion); draftingInstance.CopyParameters(filledRegion, settings.ParameterSettings); draftingInstance.SetProperties(filledRegion, settings.ParameterSettings); refObjects.AddOrReplace(filledRegion.Id, draftingInstance); return(draftingInstance); } /***************************************************/ }
public IPropertyCollection GetInstanceProperties(Type targetType) { Argument.IsNotNull(() => targetType); return _cache.GetFromCacheOrFetch(targetType, () => { var instanceProperties = new InstanceProperties(targetType); _filterCustomizationService.CustomizeInstanceProperties(instanceProperties); return instanceProperties; }); }
public IPropertyCollection GetInstanceProperties(Type targetType) { Argument.IsNotNull(() => targetType); return(_cache.GetFromCacheOrFetch(targetType, () => { var instanceProperties = new InstanceProperties(targetType); _filterCustomizationService.CustomizeInstanceProperties(instanceProperties); return instanceProperties; })); }
public async Task <bool> ReportInstancePropertiesAsync(ServiceInstancePropertiesRequest serviceInstancePropertiesRequest, CancellationToken cancellationToken = default) { if (!_connectionManager.Ready) { return(false); } var connection = _connectionManager.GetConnection(); return(await new Call(_logger, _connectionManager).Execute(async() => { var client = new ManagementService.ManagementServiceClient(connection); var instance = new InstanceProperties { Service = serviceInstancePropertiesRequest.ServiceId, ServiceInstance = serviceInstancePropertiesRequest.ServiceInstanceId, }; instance.Properties.Add(new KeyStringValuePair { Key = OS_NAME, Value = serviceInstancePropertiesRequest.Properties.OsName }); instance.Properties.Add(new KeyStringValuePair { Key = HOST_NAME, Value = serviceInstancePropertiesRequest.Properties.HostName }); instance.Properties.Add(new KeyStringValuePair { Key = PROCESS_NO, Value = serviceInstancePropertiesRequest.Properties.ProcessNo.ToString() }); instance.Properties.Add(new KeyStringValuePair { Key = LANGUAGE, Value = serviceInstancePropertiesRequest.Properties.Language }); foreach (var ip in serviceInstancePropertiesRequest.Properties.IpAddress) { instance.Properties.Add(new KeyStringValuePair { Key = IPV4, Value = ip }); } var mapping = await client.reportInstancePropertiesAsync(instance, _config.GetMeta(), _config.GetTimeout(), cancellationToken); //todo: should assert the result? return true; }, () => false, () => ExceptionHelpers.ReportServiceInstancePropertiesError)); }
public static DraftingInstance DraftingInstance(InstanceProperties properties, string viewName, ISurface location) { if (properties == null || string.IsNullOrWhiteSpace(viewName)) { return(null); } List <PlanarSurface> surfaces = new List <PlanarSurface>(); if (location is PlanarSurface) { surfaces.Add((PlanarSurface)location); } else if (location is PolySurface) { PolySurface polySurface = (PolySurface)location; if (polySurface.Surfaces.Any(x => !(x is PlanarSurface))) { BH.Engine.Reflection.Compute.RecordError("Only PlanarSurfaces and PolySurfaces consisting of PlanarSurfaces can be used as location for ISurface-based DraftingInstances."); return(null); } surfaces = polySurface.Surfaces.Cast <PlanarSurface>().ToList(); } else { BH.Engine.Reflection.Compute.RecordError("Only PlanarSurfaces and PolySurfaces consisting of PlanarSurfaces can be used as location for ISurface-based DraftingInstances."); return(null); } foreach (PlanarSurface surface in surfaces) { Vector normal = (surface).Normal(); if (normal == null || 1 - Math.Abs(normal.DotProduct(Vector.ZAxis)) > Tolerance.Angle) { BH.Engine.Reflection.Compute.RecordError("Normal of the surface or its components is not parallel to the global Z axis."); return(null); } } DraftingInstance draftingInstance = new DraftingInstance() { Properties = properties, Name = properties.Name, ViewName = viewName, Location = location }; return(draftingInstance); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static oM.Adapters.Revit.Elements.Family FamilyFromRevit(this Family revitFamily, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); oM.Adapters.Revit.Elements.Family family = refObjects.GetValue <oM.Adapters.Revit.Elements.Family>(revitFamily.Id); if (family != null) { return(family); } family = new oM.Adapters.Revit.Elements.Family(); family.Name = revitFamily.Name; IEnumerable <ElementId> elementIDs = revitFamily.GetFamilySymbolIds(); if (elementIDs != null) { foreach (ElementId elementID in elementIDs) { if (elementID == null || elementID == ElementId.InvalidElementId) { continue; } ElementType elementType = revitFamily.Document.GetElement(elementID) as ElementType; if (elementType == null) { continue; } InstanceProperties instanceProperties = elementType.InstancePropertiesFromRevit(settings, refObjects); if (instanceProperties == null) { continue; } family.PropertiesList.Add(instanceProperties); } } //Set identifiers, parameters & custom data family.SetIdentifiers(revitFamily); family.CopyParameters(revitFamily, settings.ParameterSettings); family.SetProperties(revitFamily, settings.ParameterSettings); refObjects.AddOrReplace(revitFamily.Id, family); return(family); }
public static ModelInstance ModelInstance(InstanceProperties properties, ICurve location, int hostId = -1) { if (properties == null || location == null) { return(null); } ModelInstance modelInstance = new ModelInstance() { Properties = properties, Name = properties.Name, Location = location, HostId = hostId }; return(modelInstance); }
public static DraftingInstance DraftingInstance(InstanceProperties properties, string viewName, ICurve location) { if (properties == null || string.IsNullOrWhiteSpace(viewName) || location == null) { return(null); } DraftingInstance draftingInstance = new DraftingInstance() { Properties = properties, Name = properties.Name, ViewName = viewName, Location = location }; return(draftingInstance); }
/// <summary> /// Similar to BindEditProps(), but this is called from GetShallowClone /// to peform (of all things) a deep clone of the properties that /// have been flagged with the InstanceEditProps attribute. /// This properties will then display controls for instances /// of templates (cards) and will be bound to thoses instances /// rather than the master template. /// /// NOTE: The current system is flawed in that a reconciliation of /// instances will revert per-instance changes made using these controls. /// This makes them significantly less useful in a lot of cases as /// they can never be 'future-proofed'. /// </summary> public virtual void BindInstanceEditProps() { Type type = this.GetType(); PropertyInfo[] propInfo = type.GetProperties(); Dictionary <int, List <UIElement> > templateGroups = new Dictionary <int, List <UIElement> >(); Dictionary <int, List <UIElement> > instanceGroups = new Dictionary <int, List <UIElement> >(); foreach (PropertyInfo prop in propInfo) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { InstanceEditPropAttribute instancePropAttr = attr as InstanceEditPropAttribute; if (instancePropAttr != null) { //makes the controls and bind them to the property in question StackPanel stack = BindEditPropHelper(instancePropAttr, prop); if (instanceGroups.ContainsKey(instancePropAttr.GroupID)) { instanceGroups[instancePropAttr.GroupID].Add(stack); } else { List <UIElement> list = new List <UIElement>(); list.Add(stack); instanceGroups.Add(instancePropAttr.GroupID, list); } } } } //sort by group id and add properties in-order List <int> sortedList = instanceGroups.Keys.ToList(); sortedList.Sort(); foreach (int group in sortedList) { foreach (UIElement element in instanceGroups[group]) { InstanceProperties.Add(element); } } }
public static ModelInstance ModelInstance(InstanceProperties properties, Point location, Basis orientation = null, int hostId = -1) { if (properties == null || location == null) { return(null); } ModelInstance modelInstance = new ModelInstance() { Properties = properties, Name = properties.Name, Location = location, Orientation = orientation, HostId = hostId }; return(modelInstance); }
public static ModelInstance ModelInstance(InstanceProperties properties, List <Point> location) { if (properties == null || location == null) { return(null); } ModelInstance modelInstance = new ModelInstance() { Properties = properties, Name = properties.Name, Location = new CompositeGeometry { Elements = new List <IGeometry>(location) }, }; return(modelInstance); }
public static ModelInstance ModelInstance(string categoryName, ISolid location) { if (string.IsNullOrWhiteSpace(categoryName) || location == null) { return(null); } InstanceProperties instanceProperties = new InstanceProperties(); instanceProperties.CategoryName = categoryName; ModelInstance modelInstance = new ModelInstance() { Properties = instanceProperties, Name = "Solid", Location = location }; return(modelInstance); }
public static ModelInstance ModelInstance(ICurve location) { if (location == null) { return(null); } InstanceProperties instanceProperties = new InstanceProperties(); instanceProperties.CategoryName = "Lines"; ModelInstance modelInstance = new ModelInstance() { Properties = instanceProperties, Name = "Lines", Location = location }; return(modelInstance); }
public static DraftingInstance DraftingInstance(string viewName, ICurve location) { if (string.IsNullOrWhiteSpace(viewName) || location == null) { return(null); } InstanceProperties instanceProperties = new InstanceProperties(); instanceProperties.CategoryName = "Lines"; DraftingInstance draftingInstance = new DraftingInstance() { Properties = instanceProperties, Name = "Detail Lines", ViewName = viewName, Location = location }; return(draftingInstance); }
public static ModelInstance ModelInstance(oM.Base.IBHoMObject bHoMObject) { if (bHoMObject == null) { return(null); } InstanceProperties instanceProperties = new InstanceProperties() { Name = bHoMObject.Name, CustomData = new System.Collections.Generic.Dictionary <string, object>(bHoMObject.CustomData) }; ModelInstance modelInstance = new ModelInstance() { Name = bHoMObject.Name, Properties = instanceProperties, CustomData = new System.Collections.Generic.Dictionary <string, object>(bHoMObject.CustomData) }; return(modelInstance); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static InstanceProperties InstancePropertiesFromRevit(this ElementType elementType, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); InstanceProperties instanceProperties = refObjects.GetValue <InstanceProperties>(elementType.Id); if (instanceProperties != null) { return(instanceProperties); } instanceProperties = BH.Engine.Adapters.Revit.Create.InstanceProperties(elementType.FamilyName, elementType.Name); instanceProperties.CategoryName = elementType.Category?.Name; //Set identifiers, parameters & custom data instanceProperties.SetIdentifiers(elementType); instanceProperties.CopyParameters(elementType, settings.ParameterSettings); instanceProperties.SetProperties(elementType, settings.ParameterSettings); refObjects.AddOrReplace(elementType.Id, instanceProperties); return(instanceProperties); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static IInstance InstanceFromRevit(this CurveElement curveElement, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); IInstance instance = refObjects.GetValue <ModelInstance>(curveElement.Id); if (instance != null) { return(instance); } InstanceProperties instanceProperties = (curveElement.LineStyle as GraphicsStyle).InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties; if (curveElement.ViewSpecific) { View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as View; if (view == null) { return(null); } instance = BH.Engine.Adapters.Revit.Create.DraftingInstance(instanceProperties, view.Name, curveElement.GeometryCurve.IFromRevit()); } else { instance = BH.Engine.Adapters.Revit.Create.ModelInstance(instanceProperties, curveElement.GeometryCurve.IFromRevit()); } instance.Name = curveElement.Name; //Set identifiers, parameters & custom data instance.SetIdentifiers(curveElement); instance.CopyParameters(curveElement, settings.ParameterSettings); instance.SetProperties(curveElement, settings.ParameterSettings); refObjects.AddOrReplace(curveElement.Id, instance); return(instance); }
/// <summary> /// Process member references. /// </summary> /// <param name="expression"> /// The expression to visit. /// </param> /// <returns> /// The visited expression. /// </returns> private Expression VisitMemberAccess(MemberExpression expression) { // Lookup the Mobile Services name of the member and use that string memberName = GetTableMemberName(expression); if (memberName != null) { this.filterExpression.Push(new MemberAccessNode(null, memberName)); return(expression); } // Check if this member is actually a function that looks like a // property (like string.Length, etc.) string methodName = null; MemberInfoKey memberInfoKey = new MemberInfoKey(expression.Member); if (InstanceProperties.TryGetValue(memberInfoKey, out methodName)) { var fnCallNode = new FunctionCallNode(methodName, null); this.filterExpression.Push(fnCallNode); this.Visit(expression.Expression); this.SetChildren(fnCallNode); return(expression); } // Otherwise we can't process the member. throw new NotSupportedException( string.Format( CultureInfo.InvariantCulture, "The member '{0}' is not supported in the 'Where' Mobile Services query expression '{1}'.", expression != null && expression.Member != null ? expression.Member.Name : null, expression != null ? expression.ToString() : null)); }
private void DrawInstanced([NotNull] CommandBuffer cmd, ArraySegment <int> visible, int shaderPass) { if (visible.Count < 1) { return; } EnsureArrayCapacity(ref _matrices, visible.Count); EnsureArrayCapacity(ref _saturation, visible.Count); EnsureArrayCapacity(ref _edgeFadeout, visible.Count); EnsureArrayCapacity(ref _edgeSharpness, visible.Count); if (Batch.Permutation.LayerMode == LayerMode.None) { _yLayerInputStart = null; _yLayerInputExtent = null; _yLayerOutputStart = null; _yLayerOutputEnd = null; } else { EnsureArrayCapacity(ref _yLayerInputStart, visible.Count); EnsureArrayCapacity(ref _yLayerInputExtent, visible.Count); EnsureArrayCapacity(ref _yLayerOutputStart, visible.Count); EnsureArrayCapacity(ref _yLayerOutputEnd, visible.Count); } if (Batch.Permutation.LayerMode != LayerMode.Triplanar) { _xLayerInputStart = null; _xLayerInputExtent = null; _xLayerOutputStart = null; _xLayerOutputEnd = null; _zLayerInputStart = null; _zLayerInputExtent = null; _zLayerOutputStart = null; _zLayerOutputEnd = null; } else { EnsureArrayCapacity(ref _xLayerInputStart, visible.Count); EnsureArrayCapacity(ref _xLayerInputExtent, visible.Count); EnsureArrayCapacity(ref _xLayerOutputStart, visible.Count); EnsureArrayCapacity(ref _xLayerOutputEnd, visible.Count); EnsureArrayCapacity(ref _zLayerInputStart, visible.Count); EnsureArrayCapacity(ref _zLayerInputExtent, visible.Count); EnsureArrayCapacity(ref _zLayerOutputStart, visible.Count); EnsureArrayCapacity(ref _zLayerOutputEnd, visible.Count); } // Copy decal data into arrays var arx = LayerArrays.Create(_xLayerInputStart, _xLayerInputExtent, _xLayerOutputStart, _xLayerOutputEnd); var ary = LayerArrays.Create(_yLayerInputStart, _yLayerInputExtent, _yLayerOutputStart, _yLayerOutputEnd); var arz = LayerArrays.Create(_zLayerInputStart, _zLayerInputExtent, _zLayerOutputStart, _zLayerOutputEnd); for (var i = 0; i < visible.Count; i++) { // ReSharper disable once PossibleNullReferenceException var decal = Batch.Decals[visible.Array[visible.Offset + i]]; decal.Properties.LoadInto( i, _saturation, _edgeFadeout, _edgeSharpness, arx, ary, arz ); _matrices[i] = decal.Decal.WorldTransform; } // Set arrays into instancing property block _instancingPropertyBlock.Clear(); InstanceProperties.LoadInto( _instancingPropertyBlock, _saturation, _edgeFadeout, _edgeSharpness, arx, ary, arz ); var mat = Batch.GetMaterial(true); cmd.DrawMeshInstanced(_box, 0, mat, shaderPass, _matrices, visible.Count, _instancingPropertyBlock); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static IBHoMObject ObjectFromRevit(this Element element, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); IBHoMObject iBHoMObject = refObjects.GetValue <IBHoMObject>(element.Id); if (iBHoMObject != null) { return(iBHoMObject); } IGeometry iGeometry = element.Location.IFromRevit(); if (iGeometry != null) { ElementType elementType = element.Document.GetElement(element.GetTypeId()) as ElementType; if (elementType != null) { InstanceProperties objectProperties = elementType.InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties; if (objectProperties != null) { if (element.ViewSpecific) { iBHoMObject = BH.Engine.Adapters.Revit.Create.DraftingInstance(objectProperties, element.Document.GetElement(element.OwnerViewId).Name, iGeometry as dynamic); } else { iBHoMObject = BH.Engine.Adapters.Revit.Create.ModelInstance(objectProperties, iGeometry as dynamic); if (iBHoMObject is ModelInstance && (element as FamilyInstance)?.Host != null) { ((ModelInstance)iBHoMObject).HostId = (element as FamilyInstance).Host.Id.IntegerValue; } } if (iGeometry is BH.oM.Geometry.Point) { Basis orientation = null; if (element is FamilyInstance) { FamilyInstance fi = ((FamilyInstance)element); XYZ x = fi.HandOrientation; XYZ y = fi.FacingOrientation; XYZ z = fi.GetTotalTransform().BasisZ; orientation = new Basis(new Vector { X = x.X, Y = x.Y, Z = x.Z }, new Vector { X = y.X, Y = y.Y, Z = y.Z }, new Vector { X = z.X, Y = z.Y, Z = z.Z }); } ((IInstance)iBHoMObject).Orientation = orientation; } } } } if (iBHoMObject == null) { iBHoMObject = new BHoMObject(); } iBHoMObject.Name = element.Name; iBHoMObject.SetIdentifiers(element); iBHoMObject.CopyParameters(element, settings.ParameterSettings); iBHoMObject.SetProperties(element, settings.ParameterSettings); refObjects.AddOrReplace(element.Id, iBHoMObject); return(iBHoMObject); }
/// <summary> /// This method tries to load as much as possible from the cursor into the buffer until the memorySize is reached. /// </summary> public void LoadAsMuchAsPossible() { _instValues.ResetIndexing(); _instIndices.ResetIndexing(); _instanceProperties.Clear(); while (_cursorMoveNext) { var featureValues = _cursor.Features.GetValues(); int featureCount = featureValues.Length; // If the instance has no feature, ignore it! if (featureCount == 0) { _cursorMoveNext = _cursor.MoveNext(); continue; } // We assume that cursor.Features.values are represented by float and cursor.Features.indices are represented by int // We conservatively assume that an instance is sparse and therefore, it has an array of Floats and ints for values and indices int perNonZeroInBytes = sizeof(float) + sizeof(int); if (featureCount > _trainer.AcceleratedMemoryBudgetBytes / perNonZeroInBytes) { // Hopefully this never happens. But the memorySize must >= perNonZeroInBytes * length(the longest instance). throw _ch.Except("Acceleration memory budget is too small! Need at least {0} MB for at least one of the instances", featureCount * perNonZeroInBytes / (1024 * 1024)); } bool couldLoad = true; if (!_cursor.Features.IsDense) { // If it is a sparse instance, load its indices to instIndices buffer couldLoad = _instIndices.AddToStorage(_cursor.Features.GetIndices()); } // Load values of an instance into instValues if (couldLoad) { couldLoad = _instValues.AddToStorage(featureValues); } // If the load was successful, load the instance properties to instanceProperties if (couldLoad) { float label = _cursor.Label; InstanceProperties prop = new InstanceProperties(featureCount, label, _cursor.Features.IsDense); _instanceProperties.Add(prop); _cursorMoveNext = _cursor.MoveNext(); if (_instanceProperties.Count > (1 << 30)) { // If it happened to be the case that we have so much memory that we were able to load (1<<30) instances, // break. This is because in such a case _instanceProperties can only be addressed by int32 and (1<<30) is // getting close to the limits. This should rarely happen! _isFullyLoaded = false; break; } } else { // If couldLoad fails at any point (which is becuase of memorySize), isFullyLoaded becomes false forever _isFullyLoaded = false; break; } } }
/***************************************************/ public static BuiltInCategory BuiltInCategory(this InstanceProperties properties, Document document, bool caseSensitive = true) { return(document.BuiltInCategory(properties?.CategoryName, caseSensitive)); }