Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="initialNode"></param>
        /// <returns></returns>
        private PartitionNode GetClusterAsPartitionNode(INodeShape initialNode)
        {
            // Determine if the provided node is already
            // stored in our internal collection.  If it
            // is, return it.
            if (_nodeToPartition.ContainsKey(initialNode))
            {
                return(_nodeToPartition[initialNode]);
            }

            PartitionNode pn = new PartitionNode(_sourceGraph.Scope, "Partition" + (_currentId++).ToString());

            _partitionNodes.Add(pn);

            Dictionary <INodeShape, bool> nodesInCluster     = new Dictionary <INodeShape, bool>();
            Queue <INodeShape>            nodesToTriangulate = new Queue <INodeShape>();

            nodesInCluster[initialNode] = true;
            nodesToTriangulate.Enqueue(initialNode);

            while (nodesToTriangulate.Count > 0)
            {
                List <INodeShape> tempList = FindTrianglesToAdd(nodesToTriangulate.Dequeue(), nodesInCluster);

                foreach (INodeShape nodeVM in tempList)
                {
                    // Add the node view model to our queue
                    nodesToTriangulate.Enqueue(nodeVM);
                }
            }

            // Loop over all the node view models in the dictionary
            foreach (NodeViewModelBase nodeVM in nodesInCluster.Keys)
            {
                // Add the node to the partition
                pn.AddNode(nodeVM);

                // Save the updated partition node
                _nodeToPartition[nodeVM] = pn;
            }

            return(pn);
        }