Example #1
0
        private void DoAnalysis(List<Individual> indvds, Rectangle viewport)
        {
            if (indvds.Count() > 0)
            {
                //string robinstxt = "";
                //foreach (var indvd in indvds)
                //{
                //    robinstxt += "" + Normalizer.NormalizeWidthCentered((float)indvd.X) + "," + Normalizer.NormalizeHeight((float)indvd.Y) + ",";
                //}

                tempClusters.Clear();

                tempClusters.Add(new Cluster() { indvds[0] });

                for (int i = 0; i < indvds.Count; i++)
                {
                    ResetColor(indvds[i]);
                    if (!InExistingCluster(indvds[i]))
                    {
                        tempClusters.Add(new Cluster() { indvds[i] });
                    }
                }

                RemoveSmallClusters();

                #region Update
                foreach (Cluster cluster in tempClusters)
                {
                    cluster.Update();
                }
                #endregion

                #region Persisted Clusters
                //Update persisting clusters

                for (int n = 0; n < trackedClusters.Count; n++)
                {
                    var trackedClusterValues = trackedClusters.Select(e => e.Value.IdentifyingAgent).ToList();

                    #region Try to add cluster to tracked clusters
                    //Can only add if there is an open cluster
                    if (trackedClusterValues[n] == -2)
                    {
                        Cluster tempCluster = null;

                        foreach (Cluster cluster in tempClusters)
                        {
                            bool flag = false;

                            foreach (Individual indvd in cluster)
                            {
                                foreach (int value in trackedClusterValues)
                                {
                                    if (indvd.ID == value)
                                    {
                                        flag = true;
                                    }
                                }
                            }

                            if (!flag)
                            {
                                tempCluster = cluster;
                            }
                        }

                        if (tempCluster != null)
                        {
                            //TODO: Why should i have to do this
                            bool really = trackedClusterValues.Contains(tempCluster.GetPointNearestToCenter());
                            if (!really && trackedClusters[n].IdentifyingAgent == -2)
                            {
                                //SoundEngine.StartCluster(n);
                                trackedClusters[n] = new PersistedCluster() { IdentifyingAgent = tempCluster.GetPointNearestToCenter(), ColorID = trackedClusters[n].ColorID };
                                continue;
                            }
                        }
                    }
                    #endregion

                    bool updated = false;

                    foreach (Cluster cluster in tempClusters.Where(c => c.Any(g => trackedClusterValues.Contains(g.ID))).ToList<Cluster>())
                    {
                        if (cluster.Any(i => i.ID == trackedClusters[n].IdentifyingAgent))
                        {
                            var multiples = cluster.Where(z => trackedClusterValues.Contains(z.ID));
                            if (multiples.Count() <= 1)
                            {
                                //this cluster is being tracked
                                SetClusterColor(cluster, n);
                                updated = true;
                            }
                            else
                            {
                                //There is more than one id tracked id in the cluster
                                var multiplesValues = multiples.Select(i => i.ID);
                                bool firstpass = true;
                                for (int i = 0; i < trackedClusters.Count(); i++)//var t in  trackedClusters)
                                {
                                    if (multiplesValues.Contains(trackedClusters[i].IdentifyingAgent))
                                    {
                                        //Reset the tracked agents of cluster
                                        if (firstpass)
                                        {
                                            trackedClusters[i] = new PersistedCluster() { IdentifyingAgent = multiplesValues.First(), ColorID = trackedClusters[n].ColorID };
                                            SetClusterColor(cluster, i);
                                            firstpass = false;
                                            updated = true;
                                        }
                                        else
                                        {
                                            //Reset
                                            trackedClusters[i] = new PersistedCluster() { IdentifyingAgent = -2, ColorID = trackedClusters[n].ColorID };
                                            updated = true;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (!updated && trackedClusters[n].IdentifyingAgent >= 0)
                    {
                        //SoundEngine.StopCluster(n);
                    }
                }

                #endregion

                GenerateMessages();
                GenerateFilterResult();

                if (tempClusters.Count > 0)
                {
                    Cluster firstTrackedCluster = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[0].IdentifyingAgent));
                    Cluster secondTrackedCluster = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[1].IdentifyingAgent));
                    Cluster thirdTrackedCluster = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[2].IdentifyingAgent));
                    Cluster forthTrackedCluster = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[3].IdentifyingAgent));

                    if (firstTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_1(firstTrackedCluster.Agents,
                                                  new Vector2(Normalizer.NormalizeWidthCentered(firstTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(firstTrackedCluster.Center.Y)),
                                                  firstTrackedCluster.Area,
                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.AverageAgentEnergy),
                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.ClusterVelocity),
                                                  new Vector3(firstTrackedCluster.Symmetry.X, firstTrackedCluster.Symmetry.Y, firstTrackedCluster.Symmetry.Z));
                    }

                    if (secondTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_2(secondTrackedCluster.Agents,
                                                  new Vector2(Normalizer.NormalizeWidthCentered(secondTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(secondTrackedCluster.Center.Y)),
                                                  secondTrackedCluster.Area,
                                                  Normalizer.Normalize0ToOne(secondTrackedCluster.AverageAgentEnergy),
                                                  Normalizer.Normalize0ToOne(secondTrackedCluster.ClusterVelocity),
                                                  new Vector3(secondTrackedCluster.Symmetry.X, secondTrackedCluster.Symmetry.Y, secondTrackedCluster.Symmetry.Z));

                    }

                    if (thirdTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_3(thirdTrackedCluster.Agents,
                                                  new Vector2(Normalizer.NormalizeWidthCentered(thirdTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(thirdTrackedCluster.Center.Y)),
                                                  thirdTrackedCluster.Area,
                                                  Normalizer.Normalize0ToOne(thirdTrackedCluster.AverageAgentEnergy),
                                                  Normalizer.Normalize0ToOne(thirdTrackedCluster.ClusterVelocity),
                                                  new Vector3(thirdTrackedCluster.Symmetry.X, thirdTrackedCluster.Symmetry.Y, thirdTrackedCluster.Symmetry.Z));

                    }

                    if (forthTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_4(forthTrackedCluster.Agents,
                                                  new Vector2(Normalizer.NormalizeWidthCentered(forthTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(forthTrackedCluster.Center.Y)),
                                                  forthTrackedCluster.Area,
                                                  Normalizer.Normalize0ToOne(forthTrackedCluster.AverageAgentEnergy),
                                                  Normalizer.Normalize0ToOne(forthTrackedCluster.ClusterVelocity),
                                                  new Vector3(forthTrackedCluster.Symmetry.X, forthTrackedCluster.Symmetry.Y, forthTrackedCluster.Symmetry.Z));
                    }

                    //Cluster firstTrackedCluster = clusters.OrderBy(x => x.Area).First();
            #if WINDOWS

                    //SoundEngine.AgentDataRefresh(cluster.GetEveryOtherIndvd());
                    //SoundEngine.SendAgentEnergy(Normalizer.Normalize120To800(cluster.AverageAgentEnergy));
                    //SoundEngine.SendXYsymmetry(cluster.Symmetry);
                    //SoundEngine.SendNumAgents(cluster.Agents);
                    //SoundEngine.SendArea(cluster.Area);
                    //SoundEngine.SendClusterXY(cluster.Center.X, cluster.Center.Y);
                    //SoundEngine.StartCluster();
                    //SoundEngine.UpdateCluster(biggestCluster.Agents,
                    //                          biggestCluster.Center,
                    //                          biggestCluster.Area,
                    //                          Normalizer.Normalize0ToOne(biggestCluster.AverageAgentEnergy),
                    //                          biggestCluster.ClusterVelocity,
                    //                          new Vector3(biggestCluster.Symmetry.X, biggestCluster.Symmetry.Y, biggestCluster.Symmetry.Z));
                    //SoundEngine.StopCluster();
            #endif
                    //SoundEngine.UpdateCluster(1, new Vector2(.1f, .2f), 1.1f, 1.1f, 1, new Vector3(1, 1, 1));
                    //SoundEngine.SendClusterXY(Normalizer.NormalizeWidthCentered(cluster.Center.X), Normalizer.NormalizeHeight(cluster.Center.Y));
                    //}
            //                    if (firstTrackedCluster != null)
            //                    {

            //#if  !NETFX_CORE

            //                        SoundEngine.UpdateCluster(firstTrackedCluster.Agents,
            //                                                  new Vector2(Normalizer.NormalizeWidthCentered(firstTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(firstTrackedCluster.Center.Y)),
            //                                                  firstTrackedCluster.Area,
            //                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.AverageAgentEnergy),
            //                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.ClusterVelocity),
            //                                                  new Vector3(firstTrackedCluster.Symmetry.X, firstTrackedCluster.Symmetry.Y, firstTrackedCluster.Symmetry.Z));
            //#endif
            //                    }
                }
            }
        }
Example #2
0
        private void DoAnalysis(List <Individual> indvds, Rectangle viewport)
        {
            if (indvds.Count() > 0)
            {
                //string robinstxt = "";
                //foreach (var indvd in indvds)
                //{
                //    robinstxt += "" + Normalizer.NormalizeWidthCentered((float)indvd.X) + "," + Normalizer.NormalizeHeight((float)indvd.Y) + ",";
                //}

                tempClusters.Clear();

                tempClusters.Add(new Cluster()
                {
                    indvds[0]
                });

                for (int i = 0; i < indvds.Count; i++)
                {
                    ResetColor(indvds[i]);
                    if (!InExistingCluster(indvds[i]))
                    {
                        tempClusters.Add(new Cluster()
                        {
                            indvds[i]
                        });
                    }
                }

                RemoveSmallClusters();

                #region Update
                foreach (Cluster cluster in tempClusters)
                {
                    cluster.Update();
                }
                #endregion

                #region Persisted Clusters
                //Update persisting clusters


                for (int n = 0; n < trackedClusters.Count; n++)
                {
                    var trackedClusterValues = trackedClusters.Select(e => e.Value.IdentifyingAgent).ToList();

                    #region Try to add cluster to tracked clusters
                    //Can only add if there is an open cluster
                    if (trackedClusterValues[n] == -2)
                    {
                        Cluster tempCluster = null;

                        foreach (Cluster cluster in tempClusters)
                        {
                            bool flag = false;

                            foreach (Individual indvd in cluster)
                            {
                                foreach (int value in trackedClusterValues)
                                {
                                    if (indvd.ID == value)
                                    {
                                        flag = true;
                                    }
                                }
                            }

                            if (!flag)
                            {
                                tempCluster = cluster;
                            }
                        }


                        if (tempCluster != null)
                        {
                            //TODO: Why should i have to do this
                            bool really = trackedClusterValues.Contains(tempCluster.GetPointNearestToCenter());
                            if (!really && trackedClusters[n].IdentifyingAgent == -2)
                            {
                                //SoundEngine.StartCluster(n);
                                trackedClusters[n] = new PersistedCluster()
                                {
                                    IdentifyingAgent = tempCluster.GetPointNearestToCenter(), ColorID = trackedClusters[n].ColorID
                                };
                                continue;
                            }
                        }
                    }
                    #endregion

                    bool updated = false;

                    foreach (Cluster cluster in tempClusters.Where(c => c.Any(g => trackedClusterValues.Contains(g.ID))).ToList <Cluster>())
                    {
                        if (cluster.Any(i => i.ID == trackedClusters[n].IdentifyingAgent))
                        {
                            var multiples = cluster.Where(z => trackedClusterValues.Contains(z.ID));
                            if (multiples.Count() <= 1)
                            {
                                //this cluster is being tracked
                                SetClusterColor(cluster, n);
                                updated = true;
                            }
                            else
                            {
                                //There is more than one id tracked id in the cluster
                                var  multiplesValues = multiples.Select(i => i.ID);
                                bool firstpass       = true;
                                for (int i = 0; i < trackedClusters.Count(); i++)//var t in  trackedClusters)
                                {
                                    if (multiplesValues.Contains(trackedClusters[i].IdentifyingAgent))
                                    {
                                        //Reset the tracked agents of cluster
                                        if (firstpass)
                                        {
                                            trackedClusters[i] = new PersistedCluster()
                                            {
                                                IdentifyingAgent = multiplesValues.First(), ColorID = trackedClusters[n].ColorID
                                            };
                                            SetClusterColor(cluster, i);
                                            firstpass = false;
                                            updated   = true;
                                        }
                                        else
                                        {
                                            //Reset
                                            trackedClusters[i] = new PersistedCluster()
                                            {
                                                IdentifyingAgent = -2, ColorID = trackedClusters[n].ColorID
                                            };
                                            updated = true;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (!updated && trackedClusters[n].IdentifyingAgent >= 0)
                    {
                        //SoundEngine.StopCluster(n);
                    }
                }


                #endregion

                GenerateMessages();
                GenerateFilterResult();



                if (tempClusters.Count > 0)
                {
                    Cluster firstTrackedCluster  = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[0].IdentifyingAgent));
                    Cluster secondTrackedCluster = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[1].IdentifyingAgent));
                    Cluster thirdTrackedCluster  = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[2].IdentifyingAgent));
                    Cluster forthTrackedCluster  = tempClusters.FirstOrDefault(c => c.Any(i => i.ID == trackedClusters[3].IdentifyingAgent));

                    if (firstTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_1(firstTrackedCluster.Agents,
                                                    new Vector2(Normalizer.NormalizeWidthCentered(firstTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(firstTrackedCluster.Center.Y)),
                                                    firstTrackedCluster.Area,
                                                    Normalizer.Normalize0ToOne(firstTrackedCluster.AverageAgentEnergy),
                                                    Normalizer.Normalize0ToOne(firstTrackedCluster.ClusterVelocity),
                                                    new Vector3(firstTrackedCluster.Symmetry.X, firstTrackedCluster.Symmetry.Y, firstTrackedCluster.Symmetry.Z));
                    }

                    if (secondTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_2(secondTrackedCluster.Agents,
                                                    new Vector2(Normalizer.NormalizeWidthCentered(secondTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(secondTrackedCluster.Center.Y)),
                                                    secondTrackedCluster.Area,
                                                    Normalizer.Normalize0ToOne(secondTrackedCluster.AverageAgentEnergy),
                                                    Normalizer.Normalize0ToOne(secondTrackedCluster.ClusterVelocity),
                                                    new Vector3(secondTrackedCluster.Symmetry.X, secondTrackedCluster.Symmetry.Y, secondTrackedCluster.Symmetry.Z));
                    }

                    if (thirdTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_3(thirdTrackedCluster.Agents,
                                                    new Vector2(Normalizer.NormalizeWidthCentered(thirdTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(thirdTrackedCluster.Center.Y)),
                                                    thirdTrackedCluster.Area,
                                                    Normalizer.Normalize0ToOne(thirdTrackedCluster.AverageAgentEnergy),
                                                    Normalizer.Normalize0ToOne(thirdTrackedCluster.ClusterVelocity),
                                                    new Vector3(thirdTrackedCluster.Symmetry.X, thirdTrackedCluster.Symmetry.Y, thirdTrackedCluster.Symmetry.Z));
                    }

                    if (forthTrackedCluster != null)
                    {
                        SoundEngine.UpdateCluster_4(forthTrackedCluster.Agents,
                                                    new Vector2(Normalizer.NormalizeWidthCentered(forthTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(forthTrackedCluster.Center.Y)),
                                                    forthTrackedCluster.Area,
                                                    Normalizer.Normalize0ToOne(forthTrackedCluster.AverageAgentEnergy),
                                                    Normalizer.Normalize0ToOne(forthTrackedCluster.ClusterVelocity),
                                                    new Vector3(forthTrackedCluster.Symmetry.X, forthTrackedCluster.Symmetry.Y, forthTrackedCluster.Symmetry.Z));
                    }

                    //Cluster firstTrackedCluster = clusters.OrderBy(x => x.Area).First();
#if WINDOWS
                    //SoundEngine.AgentDataRefresh(cluster.GetEveryOtherIndvd());
                    //SoundEngine.SendAgentEnergy(Normalizer.Normalize120To800(cluster.AverageAgentEnergy));
                    //SoundEngine.SendXYsymmetry(cluster.Symmetry);
                    //SoundEngine.SendNumAgents(cluster.Agents);
                    //SoundEngine.SendArea(cluster.Area);
                    //SoundEngine.SendClusterXY(cluster.Center.X, cluster.Center.Y);
                    //SoundEngine.StartCluster();
                    //SoundEngine.UpdateCluster(biggestCluster.Agents,
                    //                          biggestCluster.Center,
                    //                          biggestCluster.Area,
                    //                          Normalizer.Normalize0ToOne(biggestCluster.AverageAgentEnergy),
                    //                          biggestCluster.ClusterVelocity,
                    //                          new Vector3(biggestCluster.Symmetry.X, biggestCluster.Symmetry.Y, biggestCluster.Symmetry.Z));
                    //SoundEngine.StopCluster();
#endif
                    //SoundEngine.UpdateCluster(1, new Vector2(.1f, .2f), 1.1f, 1.1f, 1, new Vector3(1, 1, 1));
                    //SoundEngine.SendClusterXY(Normalizer.NormalizeWidthCentered(cluster.Center.X), Normalizer.NormalizeHeight(cluster.Center.Y));
                    //}
//                    if (firstTrackedCluster != null)
//                    {

//#if  !NETFX_CORE

//                        SoundEngine.UpdateCluster(firstTrackedCluster.Agents,
//                                                  new Vector2(Normalizer.NormalizeWidthCentered(firstTrackedCluster.Center.X), Normalizer.NormalizeHeightCentered0to1(firstTrackedCluster.Center.Y)),
//                                                  firstTrackedCluster.Area,
//                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.AverageAgentEnergy),
//                                                  Normalizer.Normalize0ToOne(firstTrackedCluster.ClusterVelocity),
//                                                  new Vector3(firstTrackedCluster.Symmetry.X, firstTrackedCluster.Symmetry.Y, firstTrackedCluster.Symmetry.Z));
//#endif
//                    }
                }
            }
        }