/// <summary> /// Device coords provider /// </summary> /// <param name="maxMinPoint">MinMax point of entity or entity array</param> /// <param name="stage">Number of splits</param> /// <returns> /// Math.Pow(2, 3 * stage) Elements with center coords distributed gradually in maxMinPoint-limited block. /// MoveUsingNegativeOffsetVector ABSOLUTELY MUST be applied! /// </returns> public static List<Element> GetSplitBlockCollection(BasePoint[] maxMinPoint, int stage) { var resultCollection = new List<Element>(); var dimension = GetDimensions(maxMinPoint); var tmpElementBase = new ElementBase( Math.Round(dimension.X / (Math.Pow(2, stage)), 0), Math.Round(dimension.Y / (Math.Pow(2, stage)), 0), Math.Round(dimension.Z / (Math.Pow(2, stage)), 0) ); var limitX = Math.Abs((int)(maxMinPoint[0].X - maxMinPoint[1].X) / tmpElementBase.XLength); var limitY = Math.Abs((int)(maxMinPoint[0].Y - maxMinPoint[1].Y) / tmpElementBase.YLength); var limitZ = Math.Abs((int)(maxMinPoint[0].Z - maxMinPoint[1].Z) / tmpElementBase.ZLength); var startX = maxMinPoint[0].X; var startY = maxMinPoint[0].Y; var startZ = maxMinPoint[0].Z; for (var z = 0; z < limitZ; z++) for (var y = 0; y < limitY; y++) for (var x = 0; x < limitX; x++) { var center = new BasePoint(startX + (x + 0.5) * tmpElementBase.XLength, startY + (y + 0.5) * tmpElementBase.YLength, startZ + (z + 0.5) * tmpElementBase.ZLength); var element = new Element(center, tmpElementBase.XLength, tmpElementBase.YLength, tmpElementBase.ZLength); resultCollection.Add(element); } return resultCollection; }
//#region ElementBasePro //private ElementBase InitializeElementBasePro(double delta, int stage) //{ // var containmentPrev = double.MinValue; // var difference = 1d; // while (difference > delta) // { // var containment = GetContainmentPercentage(MaxMinPoint, stage); // if (stage > 0) // difference = containment - containmentPrev; // containmentPrev = containment; // stage++; // } // var dimension = GetDimensions(MaxMinPoint); // //var coefficient = GetCoefficient(dimension); // //var result = new ElementBase // // ( // // Math.Round(dimension.X / (Math.Pow(2, stage) * coefficient.X), 0), // // Math.Round(dimension.Y / (Math.Pow(2, stage) * coefficient.Y), 0), // // Math.Round(dimension.Z / (Math.Pow(2, stage) * coefficient.Z), 0) // // ); // var result = new ElementBase //wrong // ( // Math.Round(dimension.X / (Math.Pow(2, stage)), 0), // Math.Round(dimension.Y / (Math.Pow(2, stage)), 0), // Math.Round(dimension.Z / (Math.Pow(2, stage)), 0) // ); // return result; //} //private double GetContainmentPercentage(BasePoint[] maxMinPoint, int stage) //{ // var collection = GetCollection(maxMinPoint, stage); // var containees = 0; // for (var i = 0; i < collection.Count; i++) // { // foreach (var solid in _solid) // { // var brep = new Brep(solid); // PointContainment containment; // brep.GetPointContainment(collection[i].Center.ConverToAcadPoint(), out containment); // if (containment != PointContainment.Inside) // continue; // containees++; // } // } // return (double)containees / collection.Count; //} //private static BasePoint GetCoefficient(BasePoint dimensions) //{ // const int decimals = 1; // var minValue = MathOperations.FindMin(dimensions.X, dimensions.Y, dimensions.Z); // var result = new BasePoint // ( // Math.Round(dimensions.X / minValue, decimals), // Math.Round(dimensions.Y / minValue, decimals), // Math.Round(dimensions.Z / minValue, decimals) // ); // return result; //} //#endregion //private static double Length(Edge edge) //{ // return Math.Sqrt( // edge.Length() // Math.Pow(edge.Vertex2.Point.X - edge.Vertex1.Point.X, 2) + // Math.Pow(edge.Vertex2.Point.Y - edge.Vertex1.Point.X, 2) + // Math.Pow(edge.Vertex2.Point.Z - edge.Vertex1.Point.X, 2) + // ) //} /// <summary> /// Provides collection of all elements bounded by rectangle of MaxMinPoint /// </summary> /// <returns>Collection of all elements</returns> protected List<Element> GetAllElements() { if (_fullCollection == null) _fullCollection = new List<Element>(); else return _fullCollection; var limitX = Math.Abs((int)(MaxMinPoint[0].X - MaxMinPoint[1].X) / _elementBase.XLength); var limitY = Math.Abs((int)(MaxMinPoint[0].Y - MaxMinPoint[1].Y) / _elementBase.YLength); var limitZ = Math.Abs((int)(MaxMinPoint[0].Z - MaxMinPoint[1].Z) / _elementBase.ZLength); var startX = MaxMinPoint[0].X; var startY = MaxMinPoint[0].Y; var startZ = MaxMinPoint[0].Z; for (var z = 0; z < limitZ; z++) for (var y = 0; y < limitY; y++) for (var x = 0; x < limitX; x++) { var center = new BasePoint(startX + (x + 0.5) * _elementBase.XLength, startY + (y + 0.5) * _elementBase.YLength, startZ + (z + 0.5) * _elementBase.ZLength); try { var element = new Element(center, _elementBase, _fullCollection.Count); _fullCollection.Add(element); } catch (System.Exception) { IsSuccessfullConversion = false; return _fullCollection; } } return _fullCollection; }
/// <summary> /// Provides collection of all elements bounded by rectangle of MaxMinPoint /// </summary> /// <returns>Collection of all elements</returns> protected List <Element> GetAllElements() { if (_fullCollection == null) { _fullCollection = new List <Element>(); } else { return(_fullCollection); } var limitX = Math.Abs((int)(MaxMinPoint[0].X - MaxMinPoint[1].X) / _elementBase.XLength); var limitY = Math.Abs((int)(MaxMinPoint[0].Y - MaxMinPoint[1].Y) / _elementBase.YLength); var limitZ = Math.Abs((int)(MaxMinPoint[0].Z - MaxMinPoint[1].Z) / _elementBase.ZLength); var startX = MaxMinPoint[0].X; var startY = MaxMinPoint[0].Y; var startZ = MaxMinPoint[0].Z; for (var z = 0; z < limitZ; z++) { for (var y = 0; y < limitY; y++) { for (var x = 0; x < limitX; x++) { var center = new BasePoint(startX + (x + 0.5) * _elementBase.XLength, startY + (y + 0.5) * _elementBase.YLength, startZ + (z + 0.5) * _elementBase.ZLength); var element = new Element(center, _elementBase, _fullCollection.Count); _fullCollection.Add(element); } } } return(_fullCollection); }