Пример #1
0
        private SpatialCollectionType GetNeighbors()
        {
            neighbors        = new SpatialCollectionAsList <IQuelea>();
            wrappedPositions = new List <Point3d>();
            if (agent.VisionRadius > 0)
            {
                if (agent.Environment.Wrap)
                {
                    neighbors = GetNeighborsWrapped();
                }
                else
                {
                    neighbors = queleaNetwork.Quelea.GetNeighborsInSphere(agent, agent.VisionRadius * visionRadiusMultiplier);

                    if (visionAngleMultiplier < 1.0)
                    {
                        neighbors = GetNeighborsInVisionAngle(neighbors);
                    }
                }
            }
            SpatialCollectionType neighborsType = new SpatialCollectionType(neighbors);

            neighborsType.WrappedPositions = wrappedPositions;
            return(neighborsType);
        }
Пример #2
0
        private ISpatialCollection <IQuelea> GetNeighborsInVisionAngle(ISpatialCollection <IQuelea> neighborsInSphere)
        {
            ISpatialCollection <IQuelea> neighborsInVisionAngle = new SpatialCollectionAsList <IQuelea>();
            Point3d  position = agent.Position;
            Vector3d velocity = agent.Velocity;
            Plane    pl1      = new Plane(position, velocity);

            pl1.Rotate(-RS.HALF_PI, pl1.YAxis);
            Plane pl2 = pl1;

            pl2.Rotate(-RS.HALF_PI, pl1.XAxis);
            double halfVisionAngle = agent.VisionAngle * visionAngleMultiplier / 2;

            foreach (IQuelea neighbor in neighborsInSphere)
            {
                Vector3d diff   = Util.Vector.Vector2Point(position, neighbor.Position);
                double   angle1 = Util.Vector.CalcAngle(velocity, diff, pl1);
                double   angle2 = Util.Vector.CalcAngle(velocity, diff, pl2);
                if (Util.Number.DefinitelyLessThan(angle1, halfVisionAngle, Constants.AbsoluteTolerance) &&
                    Util.Number.DefinitelyLessThan(angle2, halfVisionAngle, Constants.AbsoluteTolerance))
                {
                    neighborsInVisionAngle.Add(neighbor);
                }
            }

            return(neighborsInVisionAngle);
        }
Пример #3
0
        public void Run()
        {
            IList <IQuelea> toRemove = new List <IQuelea>();

            foreach (IQuelea quelea in Quelea)
            {
                quelea.Environment = environment;
                quelea.Run();

                if (quelea.IsDead())
                {
                    toRemove.Add(quelea);
                }
            }

            foreach (AbstractEmitterType emitter in emitters)
            {
                if (emitter.ContinuousFlow && (timestep % emitter.CreationRate == 0))
                {
                    if ((emitter.NumAgents == 0) || (Quelea.Count < emitter.NumAgents))
                    {
                        Add(emitter);
                    }
                }
            }
            Quelea = UpdateDynamicSpatialDataStructure((IList <IQuelea>)Quelea.SpatialObjects);
            foreach (IQuelea deadParticle in toRemove)
            {
                Quelea.Remove(deadParticle);
            }
            timestep++;
        }
Пример #4
0
 public Ray2D(ISpatial character, Vector2 position, Vector2 direction, ISpatialCollection collection)
 {
     Position              = position;
     Direction             = direction;
     _mapSpatialCollection = collection;
     _owner = character;
 }
 protected override bool GetInputs(IGH_DataAccess da)
 {
   if (!base.GetInputs(da)) return false;
   SpatialCollectionType neighborsCollection = new SpatialCollectionType();
   if (!da.GetData(nextInputIndex++, ref neighborsCollection)) return false;
   neighbors = neighborsCollection.Quelea;
   return true;
 }
Пример #6
0
 public SystemType(SystemType system)
 {
     // private ISpatialCollection<AgentType> particles;
     queleaSettings = system.queleaSettings;
     emitters       = system.emitters;
     environment    = system.environment;
     Quelea         = UpdateDynamicSpatialDataStructure((IList <IQuelea>)system.Quelea.SpatialObjects);
 }
Пример #7
0
 protected AbstractSystemType(AbstractSystemType <T> system)
 {
     // private ISpatialCollection<AgentType> agents;
     queleaSettings = system.queleaSettings;
     emitters       = system.emitters;
     environment    = system.environment;
     UpdateBounds();
     Quelea = new SpatialCollectionAsBinLattice <T>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)), (IList <T>)system.Quelea.SpatialObjects);
 }
Пример #8
0
 public SystemType(List <IQuelea> queleaSettings, List <AbstractEmitterType> emitters, AbstractEnvironmentType environment)
 {
     timestep            = 0;
     nextIndex           = 0;
     this.queleaSettings = queleaSettings;
     this.emitters       = emitters;
     this.environment    = environment;
     Quelea = MakeDynamicSpatialDataStructure();//new SpatialCollectionAsBinLattice<IQuelea>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)));
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the NeighborsComponent class.
 /// </summary>
 public NeighborsComponent()
   : base(RS.getNeighborsInRadiusName, RS.getNeighborsInRadiusComponentNickname,
       RS.getNeighborsInRadiusDescription,
       RS.pluginCategoryName, RS.utilitySubcategoryName, RS.icon_neighborsInRadius, RS.neighborsGuid)
 {
   neighbors = new SpatialCollectionAsList<IQuelea>();
   wrappedPositions = new List<Point3d>();
   visionRadiusMultiplier = RS.visionRadiusMultiplierDefault;
   visionAngleMultiplier = RS.visionAngleMultiplierDefault;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the NeighborsComponent class.
 /// </summary>
 public NeighborsComponent()
     : base(RS.getNeighborsInRadiusName, RS.getNeighborsInRadiusComponentNickname,
            RS.getNeighborsInRadiusDescription,
            RS.pluginCategoryName, RS.utilitySubcategoryName, RS.icon_neighborsInRadius, RS.neighborsGuid)
 {
     neighbors              = new SpatialCollectionAsList <IQuelea>();
     wrappedPositions       = new List <Point3d>();
     visionRadiusMultiplier = RS.visionRadiusMultiplierDefault;
     visionAngleMultiplier  = RS.visionAngleMultiplierDefault;
 }
Пример #11
0
 protected AbstractSystemType(T[] queleaSettings, AbstractEmitterType[] emitters, AbstractEnvironmentType environment, AbstractSystemType <T> system)
 {
     timestep            = system.timestep;
     nextIndex           = system.nextIndex;
     this.queleaSettings = queleaSettings;
     this.emitters       = emitters;
     this.environment    = environment;
     UpdateBounds();
     Quelea = new SpatialCollectionAsBinLattice <T>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)), (IList <T>)system.Quelea.SpatialObjects);
 }
        public SpatialCollectionAsBinLattice(ISpatialCollection <T> spatialCollection)
        {
            // TODO: Complete member initialization
            SpatialCollectionAsBinLattice <T> sC = ((SpatialCollectionAsBinLattice <T>)spatialCollection);

            this.spatialObjects = sC.spatialObjects;
            this.binSize        = sC.binSize;
            this.min            = sC.min;
            this.max            = sC.max;
            populateLattice();
        }
Пример #13
0
 private static bool listContainsByReferenceEquals(AgentType agent, ISpatialCollection <AgentType> neighbors)
 {
     foreach (AgentType neighbor in neighbors)
     {
         if (Object.ReferenceEquals(agent, neighbor))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #14
0
 public SystemType(List <IQuelea> queleaSettings, List <AbstractEmitterType> emitters, AbstractEnvironmentType environment, SystemType system)
 {
     timestep = system.timestep;
     //nextIndex = system.nextIndex;
     this.queleaSettings = queleaSettings;
     this.emitters       = emitters;
     this.environment    = environment;
     //this.min = system.min;
     //this.max = system.max;
     this.Quelea = system.Quelea;
     Quelea      = UpdateDynamicSpatialDataStructure((IList <IQuelea>)system.Quelea.SpatialObjects);//new SpatialCollectionAsBinLattice<IQuelea>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)), (IList<IQuelea>)system.Quelea.SpatialObjects);
 }
Пример #15
0
        public void Inject()
        {
            m_Culling           = new SpatialCulling(m_Settings);
            m_SpatialCollection = CreateDefaultSpatialCollection();

            m_VisibilityPredicate   = DefaultVisibilityPredicate;
            m_VisibilityPrioritizer = DefaultVisibilityPrioritizer;

            InitCamera();

            m_DoubleExecutor.Actor = this;
            m_BackgroundThreadSynchronizer.Set();
        }
        protected override bool GetInputs(IGH_DataAccess da)
        {
            if (!base.GetInputs(da))
            {
                return(false);
            }
            SpatialCollectionType neighborsCollection = new SpatialCollectionType();

            if (!da.GetData(nextInputIndex++, ref neighborsCollection))
            {
                return(false);
            }
            neighbors = neighborsCollection.Quelea;
            return(true);
        }
Пример #17
0
 public void Populate()
 {
     Quelea.Clear();
     Quelea = MakeDynamicSpatialDataStructure();
     foreach (AbstractEmitterType emitter in emitters)
     {
         if (emitter.ContinuousFlow)
         {
             continue;
         }
         for (int i = 0; i < emitter.NumAgents; i++)
         {
             Add(emitter);
         }
     }
 }
Пример #18
0
            void CreateSpatialCollection(Func <ClassTypeTree, ISpatialCollection> createSpatial)
            {
                // First, recurse all the way down to ensure the leaves are built first
                if (!IsLeaf)
                {
                    foreach (var child in Children.Cast <SpatialTypeTree>())
                    {
                        child.CreateSpatialCollection(createSpatial);
                    }

                    // Now build an aggregate to attach all the children
                    _spatialCollection = new SpatialAggregate(Children.Cast <SpatialTypeTree>().Select(x => x.SpatialCollection));
                }
                else
                {
                    // The leaf is easier to handle - just build a single spatial collection (not an aggregate)
                    _spatialCollection = createSpatial(this);
                }
            }
Пример #19
0
        public SpatialCollectionAsBinLattice(ISpatialCollection <T> spatialCollection)
        {
            // TODO: Complete member initialization
            this.spatialObjects = (IList <T>)spatialCollection.SpatialObjects;
            if (spatialCollection is SpatialCollectionAsBinLattice <T> )
            {
                SpatialCollectionAsBinLattice <T> sC = ((SpatialCollectionAsBinLattice <T>)spatialCollection);
                this.binSize = sC.binSize;
                this.min     = sC.min;
                this.max     = sC.max;
                this.lattice = sC.lattice;
            }
            else
            {
                updateBounds();
                this.binSize = (this.max.X - this.min.X) / 10;
            }

            PopulateLattice();
        }
        public SpatialFilter(Transform root, SpatialFilterSettings settings,
                             StreamAssetOutput streamOutput,
                             ISpatialCollection <ISpatialObject> spatialCollection = null,
                             Func <ISpatialObject, bool> visibilityPredicate       = null,
                             Func <ISpatialObject, float> visibilityPrioritizer    = null)
        {
            m_Root                 = root;
            this.settings          = settings;
            m_StreamOutput         = streamOutput;
            this.spatialCollection = spatialCollection ?? CreateDefaultSpatialCollection();

            m_VisibilityPredicate   = visibilityPredicate ?? DefaultVisibilityPredicate;
            m_VisibilityPrioritizer = visibilityPrioritizer ?? DefaultVisibilityPrioritizer;

            InitCamera();

            if (settings.displayUnloadedObjectBoundingBoxes)
            {
                InitBoundingBoxSceneObjects();
            }

            m_ObjectsToLoad = new PriorityHeap <SpatialObject>(settings.visibleObjectsMax, Comparer <SpatialObject> .Create((a, b) => a.priority.CompareTo(b.priority)));
        }
Пример #21
0
 private static bool listContainsByReferenceEquals(AgentType agent, ISpatialCollection<AgentType> neighbors)
 {
   foreach(AgentType neighbor in neighbors) {
       if(Object.ReferenceEquals(agent, neighbor)) {
         return true;
       }
   }
   return false;
   
 }
Пример #22
0
 private ISpatialCollection <IQuelea> MakeDynamicSpatialDataStructure()
 {
     Quelea = new SpatialCollectionAsList <IQuelea>();
     return(UpdateDynamicSpatialDataStructure(new List <IQuelea>()));
 }
Пример #23
0
 public SpatialCollectionType(SpatialCollectionType spatialCollection)
 {
     quelea = new SpatialCollectionAsBinLattice <IQuelea>(spatialCollection.quelea);
 }
Пример #24
0
 /// <summary>
 /// Gets the first <see cref="IUsableEntity"/> that intersects a specified area.
 /// </summary>
 /// <param name="c">The <see cref="ISpatialCollection"/>.</param>
 /// <param name="rect"><see cref="Rectangle"/> of the area to check.</param>
 /// <param name="charEntity"><see cref="CharacterEntity"/> that must be able to use the
 /// <see cref="IUsableEntity"/>.</param>
 /// <returns>First <see cref="IUsableEntity"/> that intersects the specified area that the
 /// <paramref name="charEntity"/> is able to use, or null if none.</returns>
 public static IUsableEntity GetUsable(this ISpatialCollection c, Rectangle rect, CharacterEntity charEntity)
 {
     return(c.Get <IUsableEntity>(rect, x => x.CanUse(charEntity)));
 }
Пример #25
0
 /// <summary>
 /// Initializes a new instance of the ViewForceComponent class.
 /// </summary>
 protected AbstractBoidForceComponent(string name, string nickname, string description, 
                                      Bitmap icon, String componentGuid)
   : base(name, nickname, description, icon, componentGuid)
 {
   neighbors = new SpatialCollectionAsList<IQuelea>();
 }
Пример #26
0
 public SpatialCollectionAsOctTree(ISpatialCollection <T> spatialCollection)
 {
     // TODO: Complete member initialization
     this.spatialObjects = ((SpatialCollectionAsOctTree <T>)spatialCollection).spatialObjects;
     this.octTree        = ((SpatialCollectionAsOctTree <T>)spatialCollection).octTree;
 }
Пример #27
0
        public static void testSpatialCollection(ISpatialCollection <AgentType> testingAgents)
        {
            Console.WriteLine("Running test for " + testingAgents.GetType().Name);
            ISpatialCollection <AgentType> baseAgents = new SpatialCollectionAsList <AgentType>();
            List <AgentType> agents = new List <AgentType>();

            Console.WriteLine("Creating Agents.");
            for (int i = 0; i < NUM_AGENTS; i++)
            {
                agents.Add(new AgentType(Random.RandomPoint(min, max)));
            }
            // DK: For testing/debugging, was using just these 2 points:
            // agents.Add(new AgentType(new Point3d(1, 1, 1)));
            // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

            Stopwatch stopwatchBase    = new Stopwatch();
            Stopwatch stopwatchTesting = new Stopwatch();

            Console.WriteLine("Getting add time data.");

            stopwatchBase.Start();
            foreach (AgentType agent in agents)
            {
                baseAgents.Add(agent);
            }
            //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchBase.Stop();

            stopwatchTesting.Start();
            foreach (AgentType agent in agents)
            {
                testingAgents.Add(agent);
            }
            //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
            stopwatchTesting.Stop();

            TimeSpan baseAddTime = stopwatchBase.Elapsed;
            TimeSpan testAddTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseAddTime);
            Console.WriteLine("Testing time elapsed: {0}", testAddTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

            if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
            {
                Console.WriteLine("Checking neighbors match.");
                foreach (AgentType agent in agents)
                {
                    ISpatialCollection <AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
                    ISpatialCollection <AgentType> baseNeighbors    = baseAgents.getNeighborsInSphere(agent, visionRadius);
                    foreach (AgentType neighbor in testingNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                        {
                            Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                    foreach (AgentType neighbor in baseNeighbors)
                    {
                        if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                        {
                            Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                            Console.ReadLine();
                            //throw new Exception();
                        }
                    }
                }
            }
            Console.WriteLine("Getting getNeighbors timing data.");
            stopwatchBase.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchBase.Stop();
            TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;

            Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);


            stopwatchTesting.Restart();
            foreach (AgentType agent in agents)
            {
                ISpatialCollection <AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
            }
            stopwatchTesting.Stop();
            TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;

            Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

            Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

            TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);

            Console.WriteLine("Total base time: {0}", totalBaseTime);
            TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);

            Console.WriteLine("Total test time: {0}", totalTestTime);
            Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
        }
Пример #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpatialManager"/> class.
 /// </summary>
 /// <param name="spatialCollectionTypes">The key <see cref="Type"/>s that will be used to build
 /// <see cref="ISpatialCollection"/>s on. The more <see cref="Type"/>s that are included, the smaller each
 /// <see cref="ISpatialCollection"/> will be which will allow for faster look-up for specific types, but
 /// slower look-up for less specific types since there will be more <see cref="ISpatialCollection"/>s to crawl. It
 /// is recommended to just include <see cref="Type"/>s that you plan to filter by.</param>
 /// <param name="createSpatialCollection">The delegate that describes how to create the
 /// <see cref="ISpatialCollection"/>s.</param>
 public SpatialManager(IEnumerable <Type> spatialCollectionTypes,
                       Func <ClassTypeTree, ISpatialCollection> createSpatialCollection)
 {
     _treeRoot    = new SpatialTypeTree(spatialCollectionTypes, createSpatialCollection);
     _rootSpatial = _treeRoot.SpatialCollection;
 }
 public SpatialCollectionAsLinkedList(ISpatialCollection <T> spatialCollection)
 {
     // TODO: Complete member initialization
     this.spatialObjects = ((SpatialCollectionAsLinkedList <T>)spatialCollection).spatialObjects;
 }
Пример #30
0
 /// <summary>
 /// Gets the <see cref="ISpatial"/>s found intersecting the given region.
 /// </summary>
 /// <param name="c">The <see cref="ISpatialCollection"/>.</param>
 /// <param name="spatial">The <see cref="ISpatial"/> representing the map area to check.</param>
 /// <param name="condition">Condition the <see cref="ISpatial"/>s must meet.</param>
 /// <typeparam name="T">Type of ISpatial to convert to.</typeparam>
 /// <returns>List of all <see cref="ISpatial"/>s found intersecting the given region.</returns>
 public static IEnumerable <T> GetMany <T>(this ISpatialCollection c, ISpatial spatial, Predicate <T> condition)
 {
     return(c.GetMany(spatial.ToRectangle(), condition));
 }
Пример #31
0
 /// <summary>
 /// Gets the <see cref="ISpatial"/>s found intersecting the given region.
 /// </summary>
 /// <param name="c">The <see cref="ISpatialCollection"/>.</param>
 /// <param name="spatial">The <see cref="ISpatial"/> representing the map area to check.</param>
 /// <typeparam name="T">Type of ISpatial to convert to.</typeparam>
 /// <returns>List of all <see cref="ISpatial"/>s found intersecting the given region.</returns>
 public static IEnumerable <T> GetMany <T>(this ISpatialCollection c, ISpatial spatial)
 {
     return(c.GetMany <T>(spatial.ToRectangle()));
 }
Пример #32
0
 public SpatialCollectionType(ISpatialCollection <IQuelea> quelea)
 {
     this.quelea = quelea;
 }
Пример #33
0
    private ISpatialCollection<IQuelea> GetNeighborsInVisionAngle(ISpatialCollection<IQuelea> neighborsInSphere)
    {
      ISpatialCollection<IQuelea> neighborsInVisionAngle = new SpatialCollectionAsList<IQuelea>();
      Point3d position = agent.Position;
      Vector3d velocity = agent.Velocity;
      Plane pl1 = new Plane(position, velocity);
      pl1.Rotate(-RS.HALF_PI, pl1.YAxis);
      Plane pl2 = pl1;
      pl2.Rotate(-RS.HALF_PI, pl1.XAxis);
      double halfVisionAngle = agent.VisionAngle * visionAngleMultiplier / 2;
      foreach (IQuelea neighbor in neighborsInSphere)
      {
        Vector3d diff = Util.Vector.Vector2Point(position, neighbor.Position);
        double angle1 = Util.Vector.CalcAngle(velocity, diff, pl1);
        double angle2 = Util.Vector.CalcAngle(velocity, diff, pl2);
        if (Util.Number.DefinitelyLessThan(angle1, halfVisionAngle, Constants.AbsoluteTolerance) &&
            Util.Number.DefinitelyLessThan(angle2, halfVisionAngle, Constants.AbsoluteTolerance))
        {
          neighborsInVisionAngle.Add(neighbor);
        }
      }

      return neighborsInVisionAngle;
    }
Пример #34
0
 public Ray2D(Vector2 position, Vector2 direction, ISpatialCollection collection)
 {
     Position              = position;
     Direction             = direction;
     _mapSpatialCollection = collection;
 }
Пример #35
0
    public static void testSpatialCollection(ISpatialCollection<AgentType> testingAgents)
    {
      Console.WriteLine("Running test for " + testingAgents.GetType().Name);
      ISpatialCollection<AgentType> baseAgents = new SpatialCollectionAsList<AgentType>();
      List<AgentType> agents = new List<AgentType>();
      Console.WriteLine("Creating Agents.");
      for (int i = 0; i < NUM_AGENTS; i++) agents.Add(new AgentType(Random.RandomPoint(min, max)));
      // DK: For testing/debugging, was using just these 2 points:
      // agents.Add(new AgentType(new Point3d(1, 1, 1)));
      // agents.Add(new AgentType(new Point3d(1, 1, 1.01)));

      Stopwatch stopwatchBase = new Stopwatch();
      Stopwatch stopwatchTesting = new Stopwatch();
      Console.WriteLine("Getting add time data.");

      stopwatchBase.Start();
      foreach (AgentType agent in agents)
      {
          baseAgents.Add(agent);
      }
      //baseAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchBase.Stop();

      stopwatchTesting.Start();
      foreach (AgentType agent in agents)
      {
        testingAgents.Add(agent);
      }
      //testingAgents.Add(new AgentType(new Point3d(min.X - 100, 0, 0)));
      stopwatchTesting.Stop();

      TimeSpan baseAddTime = stopwatchBase.Elapsed;
      TimeSpan testAddTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseAddTime);
      Console.WriteLine("Testing time elapsed: {0}", testAddTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedTicks / stopwatchBase.ElapsedTicks);

      if (CHECKMATCH) // DK: added so we can easily turn on and off this expensive check
      {
          Console.WriteLine("Checking neighbors match.");
          foreach (AgentType agent in agents)
          {
              ISpatialCollection<AgentType> testingNeighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
              ISpatialCollection<AgentType> baseNeighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
              foreach (AgentType neighbor in testingNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, baseNeighbors))
                  {
                    Console.WriteLine("Mismatch1! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
              foreach (AgentType neighbor in baseNeighbors)
              {
                  if (!listContainsByReferenceEquals(neighbor, testingNeighbors))
                  {
                    Console.WriteLine("Mismatch2! testingNeighbors size: " + testingNeighbors.Count + " baseNeighbors size: " + baseNeighbors.Count);
                      Console.ReadLine();
                      //throw new Exception();
                  }
              }
          }
      }
      Console.WriteLine("Getting getNeighbors timing data.");
      stopwatchBase.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = baseAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchBase.Stop();
      TimeSpan baseNeighborsTime = stopwatchBase.Elapsed;
      Console.WriteLine("Base time elapsed: {0}", baseNeighborsTime);

      
      stopwatchTesting.Restart();
      foreach (AgentType agent in agents)
      {
        ISpatialCollection<AgentType> neighbors = testingAgents.getNeighborsInSphere(agent, visionRadius);
      }
      stopwatchTesting.Stop();
      TimeSpan testNeighborsTime = stopwatchTesting.Elapsed;
      Console.WriteLine("Testing time elapsed: {0}", testNeighborsTime);

      Console.WriteLine("Elapsed time ratio: {0}", 1.0 * stopwatchTesting.ElapsedMilliseconds / stopwatchBase.ElapsedMilliseconds);

      TimeSpan totalBaseTime = baseAddTime.Add(baseNeighborsTime);
      Console.WriteLine("Total base time: {0}", totalBaseTime);
      TimeSpan totalTestTime = testAddTime.Add(testNeighborsTime);
      Console.WriteLine("Total test time: {0}", totalTestTime);
      Console.WriteLine("Total elapsed time ratio: {0}", 1.0 * totalTestTime.TotalMilliseconds / totalBaseTime.TotalMilliseconds);
    }
Пример #36
0
    private SpatialCollectionType GetNeighbors()
    {
      neighbors = new SpatialCollectionAsList<IQuelea>();
      wrappedPositions = new List<Point3d>();
      if (agent.VisionRadius > 0)
      {
        if (agent.Environment.Wrap)
        {
          neighbors = GetNeighborsWrapped();
        }
        else
        {
          neighbors = queleaNetwork.Quelea.GetNeighborsInSphere(agent, agent.VisionRadius * visionRadiusMultiplier);

          if (visionAngleMultiplier < 1.0)
          {
            neighbors = GetNeighborsInVisionAngle(neighbors);
          }
        }
      }
      SpatialCollectionType neighborsType = new SpatialCollectionType(neighbors);
      neighborsType.WrappedPositions = wrappedPositions;
      return neighborsType;
    }
Пример #37
0
 public SpatialCollectionType()
 {
     quelea = new SpatialCollectionAsBinLattice <IQuelea>();
 }