コード例 #1
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
        /// <summary>
        /// This call removes cached data from the transform to reduce memory footprint
        /// </summary>
        public void MinimizeMemory()
        {
            //if(_mapTriangles != null)
                //_mapTriangles.Clear();

            try
            {
                rwLockTriangles.EnterWriteLock();

                _mapTriangles = null;
                _controlTriangles = null;
            }
            finally
            {
                if (rwLockTriangles.IsWriteLockHeld)
                    rwLockTriangles.ExitWriteLock();
            }

            try
            {
                rwLockEdges.EnterWriteLock();
                if (_edges != null)
                    _edges.Clear();
                _edges = null;
            }
            finally
            {
                if (rwLockEdges.IsWriteLockHeld)
                    rwLockEdges.ExitWriteLock();
            }

            this._LineSegmentGrid = null;
        }
コード例 #2
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
        protected void CalculateEdges()
        {
            try
            {
                rwLockEdges.EnterWriteLock();

                //In this case someone went through this routine ahead of us exit if the data structure is built
                if (_edges != null)
                    return;

                _edges = new Dictionary<int, List<int>>();

                List<int> EdgeIndicies = new List<int>(8);
                for (int i = 0; i < this.TriangleIndicies.Length; i += 3)
                {
                    int iOne = TriangleIndicies[i];
                    int iTwo = TriangleIndicies[i + 1];
                    int iThree = TriangleIndicies[i + 2];

                    //Add edges to the lists for each node
                    if (!_edges.ContainsKey(iOne))
                        _edges.Add(iOne, new List<int>(new int[] { iTwo, iThree }));
                    else
                    {
                        //Doing this the long way to avoid the new operator which slows down threads
                        List<int> listOne = _edges[iOne];
                        listOne.Add(iTwo);
                        listOne.Add(iThree);
               //             _edges[iOne].AddRange(new int[] { iTwo, iThree });
                    }

                    //Add edges to the lists for each node
                    if (!_edges.ContainsKey(iTwo))
                        _edges.Add(iTwo, new List<int>(new int[] { iOne, iThree }));
                    else
                    {
                        //Doing this the long way to avoid the new operator which slows down threads
                        List<int> listOne = _edges[iTwo];
                        listOne.Add(iOne);
                        listOne.Add(iThree);
               //             _edges[iTwo].AddRange(new int[] { iOne, iThree });
                    }

                    //Add edges to the lists for each node
                    if (!_edges.ContainsKey(iThree))
                        _edges.Add(iThree, new List<int>(new int[] { iOne, iTwo }));
                    else
                    {
                        //Doing this the long way to avoid the new operator which slows down threads
                        List<int> listOne = _edges[iThree];
                        listOne.Add(iOne);
                        listOne.Add(iTwo);
               //             _edges[iThree].AddRange(new int[] { iOne, iTwo });
                    }
                }

                //Remove duplicates from edge list
                foreach (List<int> indexList in _edges.Values)
                {
                    //Sort indicies and remove duplicates
                    indexList.Sort();
                    for (int iTest = 1; iTest < indexList.Count; iTest++)
                    {
                        if (indexList[iTest - 1] == indexList[iTest])
                        {
                            indexList.RemoveAt(iTest);
                            iTest--;
                        }
                    }
                }

                _LineSegmentGrid = new PairedLineSearchGrid(this._mapPoints, CachedMappedBounds, _edges);
            }
            finally
            {
                if(rwLockEdges.IsWriteLockHeld)
                    rwLockEdges.ExitWriteLock();
            }
        }