Example #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <Tuple <LocalData <T>, LocalData <T> > > RelatedPairs <T>(this PointMatrix <T> matrix, double minDist, double maxDist)
        {
            int    range      = (int)Math.Ceiling(maxDist / matrix.CellSize);
            double minSqrDist = minDist * minDist;
            double maxSqrDist = maxDist * maxDist;

            List <Tuple <LocalData <T>, LocalData <T> > > result = new List <Tuple <LocalData <T>, LocalData <T> > >();

            foreach (KeyValuePair <DiscretePoint, List <LocalData <T> > > kvp in matrix.Data)
            {
                DiscretePoint         k           = kvp.Key;
                List <LocalData <T> > closePoints = matrix.SubMatrixData <T>(
                    new DiscretePoint {
                    X = k.X - range, Y = k.Y - range, Z = k.Z - range
                },
                    new DiscretePoint {
                    X = k.X + range, Y = k.Y + range, Z = k.Z + range
                });

                foreach (LocalData <T> value in kvp.Value)
                {
                    foreach (LocalData <T> other in closePoints)
                    {
                        double sqrDist = value.Position.PMSquareDistance(other.Position);
                        if (sqrDist < maxSqrDist && sqrDist > minSqrDist)
                        {
                            result.Add(new Tuple <LocalData <T>, LocalData <T> >(value, other));
                        }
                    }
                }
            }

            return(result);
        }
Example #2
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <LocalData <T> > SubMatrixData <T>(this PointMatrix <T> matrix, DiscretePoint minCell, DiscretePoint maxCell)
        {
            Dictionary <DiscretePoint, List <LocalData <T> > > data = matrix.Data;

            List <LocalData <T> > inCells = new List <LocalData <T> >();

            for (int x = minCell.X; x <= maxCell.X; x++)
            {
                for (int y = minCell.Y; y <= maxCell.Y; y++)
                {
                    for (int z = minCell.Z; z <= maxCell.Z; z++)
                    {
                        DiscretePoint key = new DiscretePoint {
                            X = x, Y = y, Z = z
                        };
                        if (data.ContainsKey(key))
                        {
                            foreach (LocalData <T> comp in data[key])
                            {
                                inCells.Add(comp);
                            }
                        }
                    }
                }
            }

            return(inCells);
        }
Example #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            double[] d = Validate();

            PointMatrix baseMatrix = new PointMatrix((float)d[3], (float)d[2], (float)d[1], (float)d[0]);
            SPDView     spdView    = new SPDView(AdvancedPointMatrix?pointMatrix:PointMatrixPick.SingularMatrixCondition(baseMatrix, _ic.Grid.CellGrid.GetLength(0), _ic.Grid.CellGrid.GetLength(1)), Transform(_ic.Grid), GetNeighboursCount((Neighbourhoods)NeighbourBox.SelectedItem, (int)Slider1.Value), GetNeighbourhood((Neighbourhoods)NeighbourBox.SelectedItem, (Shape)ShapeBox.SelectedItem, (int)Slider1.Value, _ic.Grid.CellGrid.GetLength(0), _ic.Grid.CellGrid.GetLength(1)));

            spdView.ShowDialog();
        }
Example #4
0
 public MainWindow()
 {
     InitializeComponent();
     matrix      = new PointMatrix();
     dt          = new DispatcherTimer();
     dt.Tick    += new EventHandler(Update);
     dt.Interval = new TimeSpan(0, 0, 1);
     dt.Start();
 }
Example #5
0
        /***************************************/

        public static void Add <T>(this PointMatrix <T> matrix, Point position, T data = default(T))
        {
            Dictionary <DiscretePoint, List <LocalData <T> > > cells = matrix.Data;

            DiscretePoint key = Create.DiscretePoint(position, matrix.CellSize);

            if (!cells.ContainsKey(key))
            {
                cells[key] = new List <LocalData <T> >();
            }
            cells[key].Add(new LocalData <T> {
                Position = position, Data = data
            });
        }
Example #6
0
        /// <summary>
        /// Need to perform recursive clone of vertecies PointMatrix
        /// </summary>
        /// <returns>a shallow copy of this object</returns>
        public virtual Object3 Clone()
        {
            PointMatrix newVerts = new PointMatrix(vertecies.ToArray());

            for (int i = 0; i < newVerts.ColumnCount; i++)
            {
                newVerts.Set(i, vertecies.Get(i).Clone());
            }

            Object3 result = (Object3)MemberwiseClone();

            result.SetVertecies(newVerts);
            return(result);
        }
Example #7
0
        public ComplexCube()
        {
            ConvertGeometry(GeometryBuilder.Cube());
            originalGeo = MatrixD.OfArray(GeometryBuilder.Cube());

            vertecies = new PointMatrix(originalGeo.ToArray());
            geometry  = vertecies.ToColumnWiseArray();
            colors    = new double[geometry.Length];
            for (int i = 0; i < colors.Length; i += 3)
            {
                colors[i]     = 1;
                colors[i + 1] = 0;
                colors[i + 2] = 1;
            }
        }
Example #8
0
        protected override void ConvertGeometry(double[,] _geometry)
        {
            TypedArrayList <Point3> _vertecies = new TypedArrayList <Point3>();
            SysVertex sysVert;

            for (int i = 0; i < _geometry.GetLength(1); i++)
            {
                sysVert = new SysVertex(
                    (float)_geometry[0, i],
                    (float)_geometry[1, i],
                    (float)_geometry[2, i]);
                sysVert.obj      = (Object3)masterObj.Clone();
                sysVert.distance = i;
                _vertecies.Add(sysVert);
            }

            vertecies = new PointMatrix(_vertecies);
        }
Example #9
0
        /***************************************************/

        public static PointMatrix <T> PointMatrix <T>(List <LocalData <T> > data, double cellSize = 1.0)
        {
            PointMatrix <T> matrix = new PointMatrix <T> {
                CellSize = cellSize
            };
            Dictionary <DiscretePoint, List <LocalData <T> > > cells = matrix.Data;

            foreach (LocalData <T> d in data)
            {
                DiscretePoint key = Create.DiscretePoint(d.Position, cellSize);
                if (!cells.ContainsKey(key))
                {
                    cells[key] = new List <LocalData <T> >();
                }
                cells[key].Add(d);
            }

            return(matrix);
        }
Example #10
0
        public static PointMatrixPick SingularMatrixCondition(PointMatrix M, int size1, int size2)
        {
            PointMatrixPick p = new PointMatrixPick
            {
                Indices  = new int[size1, size2],
                Matrices = new List <PointMatrix> {
                    M
                }
            };

            for (int i = 0; i < size1; i++)
            {
                for (int j = 0; j < size2; j++)
                {
                    p.Indices[i, j] = 0;
                }
            }
            return(p);
        }
Example #11
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <LocalData <T> > CloseToPoint <T>(this PointMatrix <T> matrix, Point refPt, double maxDist)
        {
            // Collect all the points within cells in range
            Vector range = new Vector {
                X = maxDist, Y = maxDist, Z = maxDist
            };
            List <LocalData <T> > inCells = matrix.SubMatrixData <T>(Create.DiscretePoint(refPt - range, matrix.CellSize), Create.DiscretePoint(refPt + range, matrix.CellSize));

            // Keep only points within maxDist distance of refPt
            double maxSqrDist            = maxDist * maxDist;
            List <LocalData <T> > result = new List <LocalData <T> >();

            foreach (LocalData <T> tuple in inCells)
            {
                if (tuple.Position.PMSquareDistance(refPt) < maxSqrDist)
                {
                    result.Add(tuple);
                }
            }

            // Return final result
            return(result);
        }
Example #12
0
        internal PointMatrixPicker(PointMatrix matrix, int Size1, int Size2, PointMatrixPick condition = null)
        {
            _condition      = condition ?? PointMatrixPick.SingularMatrixCondition(matrix, Size1, Size2);
            BrushRectangles = SPDAssets.GetBrushRectangles((int)MatrixCount);
            if (Condition.Size != Size)
            {
                _condition = Condition.Resize(Size);
            }
            this.Size1 = Size1;
            this.Size2 = Size2;
            Size       = Math.Max(Size1, Size2);
            InitializeComponent();


            _selectedOperation = Operation.None;

            _comboBox.ItemsSource   = BrushRectangles;
            _comboBox.SelectedIndex = 0;

            DataContext     = this;
            _conditionNames = new List <Tuple <string, Tuple <string, bool> > >();
            _conditions     = new Dictionary <Tuple <string, bool>, Func <bool, int, int, bool, InitialConditions> >();
            foreach (var T in new[] { false, true })
            {
                _conditions.Add(new Tuple <string, bool>("Donut", T), InitialConditions.DonutFactory);
                _conditions.Add(new Tuple <string, bool>("Circle", T), InitialConditions.CircleFactory);
                _conditions.Add(new Tuple <string, bool>("Diagonal", T), InitialConditions.DiagonalFactory);
            }
            _conditionNames.AddRange(
                _conditions.Select(
                    k =>
                    new Tuple <string, Tuple <string, bool> >(k.Value(k.Key.Item2, 1, 10, false).Name,
                                                              new Tuple <string, bool>(k.Key.Item1, k.Key.Item2))));
            ComboBoxCopy.ItemsSource = _conditionNames.Select(s => s.Item1);
            _canvalidate             = true;
            Condition = Condition;
        }
Example #13
0
 protected void SetPointMatrix(PointMatrix vertecies)
 {
     this.vertecies = vertecies;
 }
Example #14
0
        /// <summary>
        /// Fills in the geometry array with points to create a smooth effect.
        /// Calculates distance and slope at each point.
        /// </summary>
        /// <param name="geometry"></param>
        /// <param name="rmaxDist">The maximum distance objects are allowed to be from each other</param>
        protected override void ConvertGeometry(double[,] g)
        {
            //Create the temp points array
            TypedArrayList <Point3> _points = new TypedArrayList <Point3>();
            double dist, _dist, xdist, ydist, zdist;

            float[] slope = new float[] { 0f, 0f, 0f };
            int     noPoints;

            dist = 0;
            PenVertex _point;

            for (int i = 1; i < g.GetLength(1); i++)
            {
                slope = new float[] {
                    (float)(g[0, i] / g[0, i - 1]),
                    (float)(g[1, i] / g[1, i - 1]),
                    (float)(g[2, i] / g[2, i - 1])
                };

                //Determine relevant values
                dist     = MathUtil.Distance3(g[0, i - 1], g[0, i], g[1, i - 1], g[1, i], g[2, i - 1], g[2, i]);
                noPoints = (int)Math.Floor(dist / maxDist);

                //fill the list
                if (dist > maxDist)
                {
                    xdist = (g[0, i] - g[0, i - 1]) / noPoints;
                    ydist = (g[1, i] - g[1, i - 1]) / noPoints;
                    zdist = (g[2, i] - g[2, i - 1]) / noPoints;

                    for (double d = 0; d < noPoints; d += 1)
                    {
                        _point = new PenVertex(
                            (float)(d * xdist + g[0, i - 1]),
                            (float)(d * ydist + g[1, i - 1]),
                            (float)(d * zdist + g[2, i - 1]));
                        _point.obj = (Object3)masterObj.Clone();

                        _dist           = (_points.Count() > 0) ? ((PenVertex)_points.Last()).distance : 0;
                        _point.distance = (float)(_dist + maxDist);
                        _point.slope    = slope;
                        _points.Add(_point);
                    }
                }

                _point     = new PenVertex((float)g[0, i], (float)g[1, i], (float)g[2, i]);
                _point.obj = (Object3)masterObj.Clone();

                //calculate distance
                if (_points.Count() > 0)
                {
                    _point.distance = ((PenVertex)_points.Last()).distance + ((float)maxDist);
                }
                else
                {
                    _point.distance = 0;
                }
                _point.slope = slope;
                _points.Add(_point);
            }

            length = (_points.Count() > 0) ? ((PenVertex)_points.Last()).distance : 0;

            vertecies = new PointMatrix(_points);
        }
Example #15
0
        /***********************************************/
        /**** Point Matrix                          ****/
        /***********************************************/

        public static LocalData <T> ClosestData <T>(this PointMatrix <T> matrix, Point refPt, double maxDist)
        {
            List <LocalData <T> > closePts = matrix.CloseToPoint(refPt, maxDist);

            return(closePts.OrderBy(x => x.Position.PMSquareDistance(refPt)).FirstOrDefault());
        }
Example #16
0
 /// <summary>
 /// Converts a 2D double array into a PointMatrix
 /// </summary>
 /// <param name="geometry"></param>
 protected virtual void ConvertGeometry(double[,] geometry)
 {
     vertecies = new PointMatrix(geometry);
 }
Example #17
0
 public void SetVertecies(PointMatrix vertecies)
 {
     this.vertecies = vertecies;
 }
        //注意输入和输出类型 ,利用mypoloygons类进行旋转及求交
        /// <summary>
        /// 划分最小格子,并求交集
        /// </summary>
        /// <param name="pgPaths">最小多边形盒子构成的Paths</param>
        /// <param name="rotation"></param>
        /// <param name="side_length"></param>
        /// <param name="rownum"></param>
        /// <param name="colnum"></param>
        /// <returns></returns>
        private List<Paths> GetMeshPologons(Path pgPaths, float rotation, int side_length, int rownum, int colnum)
        {
            PointMatrix matrix = new PointMatrix(rotation);     //生成旋转矩阵

            PointMatrix matrix1 = new PointMatrix(-rotation);   //反旋转矩阵,恢复数据使用

            mypolygons pgPolygons = new mypolygons(pgPaths);
            pgPolygons.applyMatrix(matrix);                    //对多边形轮廓进行旋转
            pgPolygons.calculateAABB();

            mypolygons mmpgPolygons = new mypolygons(mOrignalPaths);
            pgPolygons.applyMatrix(matrix);

            Paths convPgpaths = pgPolygons.getPologons();  //获得旋转后返回的pologons值
            IntPoint minPoint = pgPolygons.getMinPoint();  //获得最小包围盒的最小点和最大点
            IntPoint maxPoint = pgPolygons.getMaxPoint();

            IntPoint[,] IntPointDotMatrix = new IntPoint[rownum+1,colnum+1];     //定义点阵存储交点

            List<Paths> meshPath = new List<Paths>();       //网格输出,每一行一个paths

            //存储数据点矩阵
            for (int i = 0; i < rownum + 1; i++)
            {
                for (int j = 0; j < colnum + 1; j++)
                {
                    if (i < rownum)    //不是最后一行
                    { IntPointDotMatrix[i, j].Y = maxPoint.Y - i * side_length; }
                    else { IntPointDotMatrix[i, j].Y = minPoint.Y; }           //最后一行,直接等于ymin

                    if (j < colnum)
                    { IntPointDotMatrix[i, j].X = minPoint.X + j * side_length; }
                    else { IntPointDotMatrix[i, j].X = maxPoint.X; }           //最后一列
                }
            }

            // 存储网格多边形
            List<maddtionpologonIndex> mtempoutAddtionPathsIndex = new List<maddtionpologonIndex>();
            for (int i = 0; i < rownum ; i++)    //行数
            {
                Paths tempPaths = new Paths();    //存储行Paths
                for (int j = 0; j < colnum ; j++) //列数
                {
                    Path pathgezi = new Path();
                    pathgezi.Add(IntPointDotMatrix[i,j]);          //逆时针存储
                    pathgezi.Add(IntPointDotMatrix[i+1, j]);
                    pathgezi.Add(IntPointDotMatrix[i+1, j+1]);
                    pathgezi.Add(IntPointDotMatrix[i, j+1]);
                    tempPaths.Add(pathgezi);
                }
                mypolygons temppgPolygons = new mypolygons(tempPaths);
                temppgPolygons.applyMatrix(matrix1);              //旋转回去,恢复最开始的方向

                ////不求交集时使用
               // meshPath.Add(temppgPolygons.getPologons());

                ////求交集时使用,但是如果temppgPolygons完全在原始多边形内就会被合并了。需修改intersection函数2016_04_21
                //注意在填充时为保证位置上的相邻判断,在结果中添加了空格子占位 2016_04_22
                //Paths m_testOut = temppgPolygons.intersection(mOrignalPaths);
                //meshPath.Add(temppgPolygons.intersection(mOrignalPaths));
                List<maddtionpologonIndex> tempoutAddtionPathsIndex = new List<maddtionpologonIndex> ();
                meshPath.Add(temppgPolygons.intersection(mOrignalPaths, i, ref tempoutAddtionPathsIndex));

                mtempoutAddtionPathsIndex.AddRange(tempoutAddtionPathsIndex);  //给符合的多边形
            }
            outAddtionRectPologons.Add(mtempoutAddtionPathsIndex);
               return meshPath;
        }