Ejemplo n.º 1
0
        public static FieldSolveContext FromReflectedObject(object reflObj)
        {
            var rv = new FieldSolveContext();

            rv.RADeg   = StarMap.GetPropValue <double>(reflObj, "RADeg");
            rv.DEDeg   = StarMap.GetPropValue <double>(reflObj, "DEDeg");
            rv.ErrFoVs = StarMap.GetPropValue <double>(reflObj, "ErrFoVs");

            rv.Method = (RecognitionMethod)StarMap.GetPropValue <int>(reflObj, "Method");

            rv.DataBaseServer = StarMap.GetPropValue <string>(reflObj, "DataBaseServer");
            rv.DataBaseName   = StarMap.GetPropValue <string>(reflObj, "DataBaseName");

            rv.CellX         = StarMap.GetPropValue <double>(reflObj, "CellX");
            rv.CellY         = StarMap.GetPropValue <double>(reflObj, "CellY");
            rv.FocalLength   = StarMap.GetPropValue <double>(reflObj, "FocalLength");
            rv.LimitMagn     = StarMap.GetPropValue <double>(reflObj, "LimitMagn");
            rv.PyramidMinMag = StarMap.GetPropValue <double>(reflObj, "PyramidMinMag");
            rv.PyramidMaxMag = StarMap.GetPropValue <double>(reflObj, "PyramidMaxMag");

            rv.UtcTime = StarMap.GetPropValue <DateTime>(reflObj, "UtcTime");

            rv.FrameNoOfUtcTime = StarMap.GetPropValue <int>(reflObj, "FrameNoOfUtcTime");
            rv.ObsCode          = StarMap.GetPropValue <string>(reflObj, "ObsCode");
            rv.UseFilter        = (TangraConfig.PreProcessingFilter)StarMap.GetPropValue <int>(reflObj, "UseFilter");

            object stars = StarMap.GetPropValue <object>(reflObj, "CatalogueStars");

            rv.CatalogueStars = CreateStars(stars);

            return(rv);
        }
        void Service_GetMapDataCompleted(object sender, GetMapDataCompletedEventArgs e)
        {
            StarMap = e.Result;
            StarMap.Initialize();

            MapCanvas.Children.Clear();

            // add bodies and orbits to canvas
            foreach (var star in StarMap.CelestialObjects.Where(o => o.CelestialObjectType == CelestialObjectType.Star)) {
                var starIcon = new StarIcon(star, this);
                MapCanvas.Children.Add(starIcon);
                MapCanvas.Children.Add(new OrbitIcon(starIcon, this));
                ProcessSatellites(starIcon, StarMap.CelestialObjects);
            }

            MapIcons = MapCanvas.Children.OfType<IMapIcon>().Where(icon => icon.Body != null).ToDictionary(icon => icon.Body.CelestialObjectID);

            // add links to canvas
            foreach (var link in e.Result.ObjectLinks) {
                var linkIcon = new LinkIcon(MapIcons[link.FirstObjectID].Body, MapIcons[link.SecondObjectID].Body, this);
                MapCanvas.Children.Add(linkIcon);
            }

            // add transits to canvas
            foreach (var transit in e.Result.Transits) {
                MapCanvas.Children.Add(new TransitIcon(transit, this));
            }

            PlanetTree.ItemsSource = e.Result.CelestialObjects.Where(body => body.OrbitNestingLevel == 0);
        }
Ejemplo n.º 3
0
    public bool ProveA()
    {
        var tests = new string[] {
            "Examples//10-1.txt",
            "Examples//10-2.txt",
            "Examples//10-3.txt",
            "Examples//10-4.txt",
            "Examples//10-5.txt"
        };

        if (!StarMap.Test())
        {
            return(false);
        }

        foreach (var test in tests)
        {
            if (!ProveFor(test))
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 4
0
 public static StarMap getInstance()
 {
     if (null == uniqueInstance) {
         uniqueInstance = new StarMap();
     }
     return uniqueInstance;
 }
Ejemplo n.º 5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            StarMapInternalConfig starMapConfig = StarMapInternalConfig.Default;

            if (rbAuto.Checked)
            {
                starMapConfig.OptimumStarsInField = (int)TangraConfig.Settings.Astrometry.PyramidOptimumStarsToMatch;
                starMapConfig.StarMapperTolerance = 2;
            }
            else
            {
                starMapConfig.OptimumStarsInField = -1;
                starMapConfig.StarMapperTolerance = trbarDepth.Value;
            }

            var starMap = new StarMap();

            var image = new AstroImage(m_InitialPixelmap);

            starMap.FindBestMap(
                starMapConfig,
                image,
                AstrometryContext.Current.OSDRectToExclude,
                AstrometryContext.Current.RectToInclude,
                AstrometryContext.Current.LimitByInclusion);

            AstrometryContext.Current.StarMap       = starMap;
            AstrometryContext.Current.StarMapConfig = starMapConfig;

            m_VideoController.RedrawCurrentFrame(false, true, false);
        }
Ejemplo n.º 6
0
        // Create a new StarMap from InnerSphereMap system data
        private static StarMap InitializeNewMap()
        {
            logger.Warn("Initializing map from InnerSphereMap system data.");
            StarMap map = new StarMap();

            map.systems = new List <PersistentMapAPI.System>();

            foreach (string filePaths in Directory.GetFiles(StarMapStateManager.systemDataFilePath))
            {
                string  originalJson    = File.ReadAllText(filePaths);
                JObject originalJObject = JObject.Parse(originalJson);
                Faction owner           = (Faction)Enum.Parse(typeof(Faction), (string)originalJObject["Owner"]);

                FactionControl ownerControl = new FactionControl();
                ownerControl.faction = owner;
                if (owner != Faction.NoFaction)
                {
                    ownerControl.percentage = 100;
                }
                else
                {
                    ownerControl.percentage = 0;
                }

                PersistentMapAPI.System system = new PersistentMapAPI.System();
                system.controlList = new List <FactionControl>();
                system.name        = (string)originalJObject["Description"]["Name"];
                system.controlList.Add(ownerControl);

                map.systems.Add(system);
            }
            return(map);
        }
Ejemplo n.º 7
0
        void Service_GetMapDataCompleted(StarMap result)
        {
            StarMap = result;
            StarMap.Initialize();

            MapCanvas.Children.Clear();

            // add bodies and orbits to canvas
            foreach (var star in StarMap.CelestialObjects.Where(o => o.CelestialObjectType == CelestialObjectType.Star))
            {
                var starIcon = new StarIcon(star, this);
                MapCanvas.Children.Add(starIcon);
                MapCanvas.Children.Add(new OrbitIcon(starIcon, this));
                ProcessSatellites(starIcon, StarMap.CelestialObjects);
            }

            MapIcons = MapCanvas.Children.OfType <IMapIcon>().Where(icon => icon.Body != null).ToDictionary(icon => icon.Body.CelestialObjectID);

            // add links to canvas
            foreach (var link in result.ObjectLinks)
            {
                var linkIcon = new LinkIcon(MapIcons[link.FirstObjectID].Body, MapIcons[link.SecondObjectID].Body, this);
                MapCanvas.Children.Add(linkIcon);
            }

            // add transits to canvas
            foreach (var transit in e.Result.Transits)
            {
                MapCanvas.Children.Add(new TransitIcon(transit, this));
            }

            PlanetTree.ItemsSource = e.Result.CelestialObjects.Where(body => body.OrbitNestingLevel == 0);
        }
Ejemplo n.º 8
0
        public override void Initialize()
        {
            this._app.UI.SetEnabled(this._app.UI.Path(this.ID, ReactionDialog.UIConfirmButton), false);
            AdmiralInfo admiralInfo = this._app.GameDatabase.GetAdmiralInfo(this._currentReaction.fleet.AdmiralID);

            if (admiralInfo != null)
            {
                this._app.UI.SetText(this._app.UI.Path(this.ID, ReactionDialog.UIAdmiralLabel), admiralInfo.Name);
            }
            this._sky   = new Sky(this._app, SkyUsage.StarMap, 0);
            this._crits = new GameObjectSet(this._app);
            this._crits.Add((IGameObject)this._sky);
            this._cameraReduced                 = new OrbitCameraController(this._app);
            this._cameraReduced.MinDistance     = 2.5f;
            this._cameraReduced.MaxDistance     = 100f;
            this._cameraReduced.DesiredDistance = 50f;
            this._cameraReduced.DesiredYaw      = MathHelper.DegreesToRadians(45f);
            this._cameraReduced.DesiredPitch    = -MathHelper.DegreesToRadians(25f);
            this._cameraReduced.SnapToDesiredPosition();
            this._starmapReduced = new StarMap(this._app, this._app.Game, this._sky);
            this._starmapReduced.Initialize(this._crits);
            this._starmapReduced.SetCamera(this._cameraReduced);
            this._starmapReduced.FocusEnabled = false;
            this._starmapReduced.SetFocus((IGameObject)this._starmapReduced.Systems.Reverse[this._currentReaction.fleet.SystemID]);
            this._starmapReduced.Select((IGameObject)this._starmapReduced.Systems.Reverse[this._currentReaction.fleet.SystemID]);
            this._starmapReduced.SelectEnabled = false;
            this._starmapReduced.PostSetProp("MissionTarget", (object)this._starmapReduced.Systems.Reverse[this._currentReaction.fleet.SystemID].ObjectID, (object)true);
            this._starmapReduced.PostSetProp("CullCenter", this._app.GameDatabase.GetStarSystemInfo(this._currentReaction.fleet.SystemID).Origin);
            this._starmapReduced.PostSetProp("CullRadius", 15f);
            this._app.UI.Send((object)"SetGameObject", (object)this._app.UI.Path(this.ID, "gameStarMapViewport"), (object)this._starmapReduced.ObjectID);
            this._app.UI.SetVisible(this._app.UI.Path(this.ID, "gameStarMapViewport"), true);
            this._app.PostRequestSpeech(string.Format("STRAT_014-01_{0}_{1}AdmiralGetsReactionPhase", (object)this._app.GameDatabase.GetFactionName(this._app.GameDatabase.GetPlayerFactionID(this._app.LocalPlayer.ID)), (object)admiralInfo.GetAdmiralSoundCueContext(this._app.AssetDatabase)), 50, 120, 0.0f);
            this._crits.Activate();
        }
Ejemplo n.º 9
0
        public static PlateConstantsLinearFit FromReflectedLinearFit(object reflObj)
        {
            var rv = new PlateConstantsLinearFit();

            rv.Const_A = StarMap.GetPropValue <double>(reflObj, "Const_A");
            rv.Const_B = StarMap.GetPropValue <double>(reflObj, "Const_B");
            rv.Const_C = StarMap.GetPropValue <double>(reflObj, "Const_C");
            rv.Const_D = StarMap.GetPropValue <double>(reflObj, "Const_D");
            rv.Const_E = StarMap.GetPropValue <double>(reflObj, "Const_E");
            rv.Const_F = StarMap.GetPropValue <double>(reflObj, "Const_F");

            rv.Const_A1 = StarMap.GetPropValue <double>(reflObj, "Const_A1");
            rv.Const_B1 = StarMap.GetPropValue <double>(reflObj, "Const_B1");
            rv.Const_C1 = StarMap.GetPropValue <double>(reflObj, "Const_C1");
            rv.Const_D1 = StarMap.GetPropValue <double>(reflObj, "Const_D1");
            rv.Const_E1 = StarMap.GetPropValue <double>(reflObj, "Const_E1");
            rv.Const_F1 = StarMap.GetPropValue <double>(reflObj, "Const_F1");

            rv.m_FitInfo = new FitInfo(new List <PlateConstStarPair>());
            object fitInfo = StarMap.GetPropValue <object>(reflObj, "m_FitInfo");

            rv.m_FitInfo.FittedFocalLength = StarMap.GetPropValue <double>(fitInfo, "FittedFocalLength");

            return(rv);
        }
Ejemplo n.º 10
0
 public OverlayDeployAccelMission(
     App game,
     StarMapState state,
     StarMap starmap,
     string template = "OverlayAcceleratorMission")
     : base(game, state, starmap, MissionType.DEPLOY_NPG, template)
 {
 }
Ejemplo n.º 11
0
 public static bool Test()
 {
     if (!StarMap.PointOnLineSegment(new Point(3, 4), new Point(1, 0), new Point(2, 2)))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 12
0
 public OverlayEvacuationMission(
     App game,
     StarMapState state,
     StarMap starmap,
     string template = "OverlayEvacuationMission")
     : base(game, state, starmap, MissionType.EVACUATE, template)
 {
 }
Ejemplo n.º 13
0
 // Use this for initialization
 void Awake()
 {
     player  = GameObject.FindGameObjectWithTag("Player");
     starMap = FindObjectOfType <StarMap> ();
     station = FindObjectOfType <SpaceStation> ().gameObject;
     EventSystem.Current.RegisterListener(EventTypeEnum.NEW_LEVEL, OnNewLevel);
     EventSystem.Current.RegisterListener(EventTypeEnum.ENEMY_KILLED, OnEnemyKilled);
 }
 public OverlaySpecialConstructionMission(
     App game,
     StarMapState state,
     StarMap starmap,
     SpecialConstructionMission smission = null,
     string template = "OverlayGMBuildStationMission")
     : base(game, state, starmap, smission, template, MissionType.SPECIAL_CONSTRUCT_STN)
 {
 }
Ejemplo n.º 15
0
 void OnEnable()
 {
     if (starMap == null)
     {
         starMap = FindObjectOfType <StarMap> ();
     }
     transform.position           = starMap.transform.position + new Vector3(starMap.GetMapsize() / 2f, 0, 0);
     Camera.main.orthographicSize = 1.1f * starMap.GetMapsize() / (2 * Camera.main.aspect);
 }
Ejemplo n.º 16
0
        public static FocalLengthFit FromReflectedObject(object reflObj)
        {
            var rv = new FocalLengthFit();

            rv.A        = StarMap.GetPropValue <double>(reflObj, "A");
            rv.B        = StarMap.GetPropValue <double>(reflObj, "B");
            rv.Variance = StarMap.GetPropValue <double>(reflObj, "Variance");

            return(rv);
        }
Ejemplo n.º 17
0
 public OverlayConstructionMission(
     App game,
     StarMapState state,
     StarMap starmap,
     SpecialConstructionMission smission = null,
     string template = "OverlayStationMission",
     MissionType mt  = MissionType.CONSTRUCT_STN)
     : base(game, state, starmap, mt, template)
 {
     this._superspecialsecretmission = smission;
 }
Ejemplo n.º 18
0
        public void PlateSolve(PlateSolveTesterConfig config)
        {
            var pixelMap = new Pixelmap(config.Width, config.Height, config.BitPix, config.Pixels, null, null);
            var image    = new AstroImage(pixelMap);

            StarMap starMap = new StarMap(
                TangraConfig.Settings.Astrometry.PyramidRemoveNonStellarObject,
                TangraConfig.Settings.Astrometry.MinReferenceStarFWHM,
                TangraConfig.Settings.Astrometry.MaxReferenceStarFWHM,
                TangraConfig.Settings.Astrometry.MaximumPSFElongation,
                TangraConfig.Settings.Astrometry.LimitReferenceStarDetection);

            Rectangle excludeRect = new Rectangle(config.OSDRectToExclude.X, config.OSDRectToExclude.Y, config.OSDRectToExclude.Width, config.OSDRectToExclude.Height);
            Rectangle includeRect = new Rectangle(config.RectToInclude.X, config.RectToInclude.Y, config.RectToInclude.Width, config.RectToInclude.Height);

            starMap.FindBestMap(
                StarMapInternalConfig.Default,
                image,
                excludeRect,
                includeRect,
                config.LimitByInclusion);

            var facade         = new StarCatalogueFacade(TangraConfig.Settings.StarCatalogue);
            var catalogueStars = facade.GetStarsInRegion(
                config.RADeg,
                config.DEDeg,
                (config.ErrFoVs + 1.0) * config.PlateConfig.GetMaxFOVInArcSec() / 3600.0,
                config.LimitMagn,
                config.Epoch);

            var distBasedMatcher = new DistanceBasedAstrometrySolver(
                new MockedOperationNotifier(),
                config.PlateConfig,
                TangraConfig.Settings.Astrometry,
                catalogueStars,
                config.RADeg,
                config.DEDeg,
                config.DetermineAutoLimitMagnitude);

            distBasedMatcher.SetMinMaxMagOfStarsForAstrometry(config.PyramidMinMag, config.LimitMagn);
            distBasedMatcher.SetMinMaxMagOfStarsForPyramidAlignment(config.PyramidMinMag, config.PyramidMaxMag);

            distBasedMatcher.InitNewMatch(starMap, PyramidMatchType.PlateSolve, null);


            distBasedMatcher.InitNewFrame(starMap);

            distBasedMatcher.SetManuallyIdentifiedHints(new Dictionary <PSFFit, IStar>());

            LeastSquareFittedAstrometry astrometricFit;
            PerformMatchResult          result = distBasedMatcher.PerformMatch(out astrometricFit);
        }
Ejemplo n.º 19
0
    bool ProveFor(string test)
    {
        var lines   = File.ReadAllLines(test, Encoding.UTF8);
        var bestLoc = lines[0].Split(",").Select(x => int.Parse(x));
        var count   = int.Parse(lines[1]);
        var map     = lines.Skip(2).ToArray();
        var starMap = StarMap.Parse(map);

        starMap.FindBestAsteroid();

        var bestStar = starMap.bestStar;

        return(bestStar.X == bestLoc.ElementAt(0) && bestStar.Y == bestLoc.ElementAt(1) && starMap.maxStarsVisible == count);
    }
Ejemplo n.º 20
0
 public static void SyncFleetAndPlanetListWidget(
     GameSession game,
     string panelName,
     int systemId,
     bool show = true)
 {
     if (systemId == 0)
     {
         game.UI.SetVisible(panelName, false);
     }
     else
     {
         bool               flag1 = game.GameDatabase.IsSurveyed(game.LocalPlayer.ID, systemId);
         List <FleetInfo>   list1 = game.GameDatabase.GetFleetInfoBySystemID(systemId, FleetType.FL_NORMAL | FleetType.FL_RESERVE | FleetType.FL_GATE | FleetType.FL_ACCELERATOR).ToList <FleetInfo>();
         List <StationInfo> list2 = game.GameDatabase.GetStationForSystemAndPlayer(systemId, game.LocalPlayer.ID).ToList <StationInfo>();
         bool               flag2 = true;
         if (!game.SystemHasPlayerColony(systemId, game.LocalPlayer.ID) && !StarMap.IsInRange(game.GameDatabase, game.LocalPlayer.ID, game.GameDatabase.GetStarSystemInfo(systemId), (Dictionary <int, List <ShipInfo> >)null))
         {
             flag2 = false;
         }
         List <int> list3 = game.GameDatabase.GetStarSystemPlanets(systemId).ToList <int>();
         if (list1.Count == 0 && list2.Count == 0 && !flag1 || !flag2 && !flag1)
         {
             game.UI.SetVisible(panelName, false);
         }
         else
         {
             bool flag3 = FleetUI.ShowFleetListDefault;
             bool flag4 = (list1.Count <FleetInfo>() != 0 && flag2 || list2.Count != 0) && show;
             bool flag5 = list3.Count <int>() != 0 && flag1 && show;
             if (flag3 && !flag4)
             {
                 flag3 = false;
             }
             else if (!flag3 && !flag5)
             {
                 flag3 = true;
             }
             game.UI.SetEnabled("planetsTab", flag5);
             game.UI.SetVisible("partSystemPlanets", flag5 && !flag3);
             game.UI.SetChecked("planetsTab", flag5 && !flag3);
             game.UI.SetEnabled("fleetsTab", flag4);
             game.UI.SetChecked("fleetsTab", flag4 && flag3);
             game.UI.SetVisible("partSystemFleets", flag4 && flag3);
             game.UI.SetVisible(panelName, show);
             FleetUI.SyncPlanetListControl(game, "partSystemPlanets", systemId, (IEnumerable <int>)list3);
         }
     }
 }
Ejemplo n.º 21
0
 public string Solve(bool isA)
 {
     if (isA)
     {
         var lines   = File.ReadAllLines(Input, Encoding.UTF8);
         var starMap = StarMap.Parse(lines);
         starMap.FindBestAsteroid();
         Console.WriteLine($"Best star is {starMap.bestStar} with {starMap.maxStarsVisible} visible.");
         return(starMap.maxStarsVisible.ToString());
     }
     else
     {
         return(SolveB(Input, new Point(37, 25)).ToString());
     }
 }
Ejemplo n.º 22
0
        public static DirectTransRotAstrometry FromReflectedObject(object reflObj)
        {
            var rv = new DirectTransRotAstrometry();

            rv.m_RA0Deg = StarMap.GetPropValue <double>(reflObj, "m_RA0Deg");
            rv.m_DE0Deg = StarMap.GetPropValue <double>(reflObj, "m_DE0Deg");
            rv.m_EtaDeg = StarMap.GetPropValue <double>(reflObj, "m_EtaDeg");
            rv.m_Aspect = StarMap.GetPropValue <double>(reflObj, "m_Aspect");

            object image = StarMap.GetPropValue <object>(reflObj, "m_Image");

            rv.m_Image = AstroPlate.FromReflectedObject(image);

            return(rv);
        }
Ejemplo n.º 23
0
        public void PlateSolve(PlateSolveTesterConfig config)
        {
            var pixelMap = new Pixelmap(config.Width, config.Height, config.BitPix, config.Pixels, null, null);
            var image = new AstroImage(pixelMap);

            StarMap starMap = new StarMap(
                TangraConfig.Settings.Astrometry.PyramidRemoveNonStellarObject,
                TangraConfig.Settings.Astrometry.MinReferenceStarFWHM,
                TangraConfig.Settings.Astrometry.MaxReferenceStarFWHM,
                TangraConfig.Settings.Astrometry.MaximumPSFElongation,
                TangraConfig.Settings.Astrometry.LimitReferenceStarDetection);

            Rectangle excludeRect = new Rectangle(config.OSDRectToExclude.X, config.OSDRectToExclude.Y, config.OSDRectToExclude.Width, config.OSDRectToExclude.Height);
            Rectangle includeRect = new Rectangle(config.RectToInclude.X, config.RectToInclude.Y, config.RectToInclude.Width, config.RectToInclude.Height);

            starMap.FindBestMap(
                StarMapInternalConfig.Default,
                image,
                excludeRect,
                includeRect,
                config.LimitByInclusion);

            var facade = new StarCatalogueFacade(TangraConfig.Settings.StarCatalogue);
            var catalogueStars = facade.GetStarsInRegion(
                config.RADeg,
                config.DEDeg,
                (config.ErrFoVs + 1.0) * config.PlateConfig.GetMaxFOVInArcSec() / 3600.0,
                config.LimitMagn,
                config.Epoch);

            var distBasedMatcher = new DistanceBasedAstrometrySolver(
                new MockedOperationNotifier(),
                config.PlateConfig,
                TangraConfig.Settings.Astrometry,
                catalogueStars, config.DetermineAutoLimitMagnitude);

            distBasedMatcher.SetMinMaxMagOfStarsForAstrometry(config.PyramidMinMag, config.LimitMagn);
            distBasedMatcher.SetMinMaxMagOfStarsForPyramidAlignment(config.PyramidMinMag, config.PyramidMaxMag);

            distBasedMatcher.InitNewMatch(starMap, PyramidMatchType.PlateSolve, null);

            distBasedMatcher.InitNewFrame(starMap);

            distBasedMatcher.SetManuallyIdentifiedHints(new Dictionary<PSFFit, IStar>());

            LeastSquareFittedAstrometry astrometricFit;
            PerformMatchResult result = distBasedMatcher.PerformMatch(out astrometricFit);
        }
Ejemplo n.º 24
0
        public static StarMap Parse(string[] lines)
        {
            var starMap = new StarMap();

            for (int y = 0; y < lines.Count(); y++)
            {
                for (int x = 0; x < lines[y].Length; x++)
                {
                    if (lines[y][x] == '#')
                    {
                        starMap.stars.Add(new Point(x, y));
                    }
                }
            }
            return(starMap);
        }
Ejemplo n.º 25
0
 public RequestSystemSelectDialog(App game, RequestType type, int otherPlayer, string template = "dialogRequestSystemSelect")
     : base(game, template)
 {
     this._otherPlayer = otherPlayer;
     this._type        = type;
     this._request     = new RequestInfo();
     this._request.InitiatingPlayer = game.LocalPlayer.ID;
     this._request.ReceivingPlayer  = this._otherPlayer;
     this._request.State            = AgreementState.Unrequested;
     this._request.Type             = type;
     this._crits = new GameObjectSet(game);
     this._sky   = new Sky(game, SkyUsage.StarMap, 0);
     this._crits.Add((IGameObject)this._sky);
     this._starmap = new StarMap(game, game.Game, this._sky);
     this._crits.Add((IGameObject)this._starmap);
     this._starmap.SetCamera(game.Game.StarMapCamera);
 }
Ejemplo n.º 26
0
        public override void Initialize()
        {
            this._sky        = new Sky(this._app, SkyUsage.StarMap, 0);
            this._crits      = new GameObjectSet(this._app);
            this._planetView = this._crits.Add <PlanetView>();
            this._crits.Add((IGameObject)this._sky);
            OrbitalObjectInfo orbitalObjectInfo = this._app.GameDatabase.GetOrbitalObjectInfo(this._planetID);
            StarSystemInfo    starSystemInfo    = this._app.GameDatabase.GetStarSystemInfo(orbitalObjectInfo.StarSystemID);

            this._app.UI.SetText("gameColonyName", orbitalObjectInfo.Name);
            this._enteredColonyName = orbitalObjectInfo.Name;
            this._app.UI.SetVisible(this._app.UI.Path(this.ID, "btnAbandon"), false);
            this._app.UI.SetText(this._app.UI.Path("colonyCreateTitle"), (this._homeworld ? App.Localize("@UI_STARMAP_HOMEWORLD_ESTABLISHED") : App.Localize("@UI_STARMAP_COLONY_ESTABLISHED")) + " - " + starSystemInfo.Name);
            this._cameraReduced                 = new OrbitCameraController(this._app);
            this._cameraReduced.MinDistance     = 2.5f;
            this._cameraReduced.MaxDistance     = 100f;
            this._cameraReduced.DesiredDistance = 50f;
            this._cameraReduced.DesiredYaw      = MathHelper.DegreesToRadians(45f);
            this._cameraReduced.DesiredPitch    = -MathHelper.DegreesToRadians(25f);
            this._cameraReduced.SnapToDesiredPosition();
            this._starmapReduced = new StarMap(this._app, this._app.Game, this._sky);
            this._starmapReduced.Initialize(this._crits);
            this._starmapReduced.SetCamera(this._cameraReduced);
            this._starmapReduced.FocusEnabled = false;
            this._starmapReduced.SetFocus((IGameObject)this._starmapReduced.Systems.Reverse[starSystemInfo.ID]);
            this._starmapReduced.Select((IGameObject)this._starmapReduced.Systems.Reverse[starSystemInfo.ID]);
            this._starmapReduced.SelectEnabled = false;
            this._starmapReduced.PostSetProp("MissionTarget", (object)this._starmapReduced.Systems.Reverse[starSystemInfo.ID].ObjectID, (object)true);
            this._starmapReduced.PostSetProp("CullCenter", this._app.GameDatabase.GetStarSystemInfo(starSystemInfo.ID).Origin);
            this._starmapReduced.PostSetProp("CullRadius", 15f);
            this._app.UI.Send((object)"SetGameObject", (object)this._app.UI.Path(this.ID, "gameStarMapViewport"), (object)this._starmapReduced.ObjectID);
            this.CachePlanet(this._app.GameDatabase.GetPlanetInfo(this._planetID));
            this._planetView.PostSetProp("Planet", this._cachedPlanet != null ? this._cachedPlanet.ObjectID : 0);
            this._app.UI.Send((object)"SetGameObject", (object)this._app.UI.Path(this.ID, "system_details.Planet_panel"), (object)this._planetView.ObjectID);
            StarSystemMapUI.Sync(this._app, orbitalObjectInfo.StarSystemID, this._app.UI.Path(this.ID, "system_map"), true);
            StarSystemUI.SyncSystemDetailsWidget(this._app, "colony_event_dialog.system_details", orbitalObjectInfo.StarSystemID, true, true);
            StarSystemUI.SyncPlanetDetailsControl(this._app.Game, this._app.UI.Path(this.ID, "system_details"), this._planetID);
            StarSystemUI.SyncColonyDetailsWidget(this._app.Game, this._app.UI.Path(this.ID, "colony_details"), orbitalObjectInfo.ID, "");
            this._app.UI.SetVisible(this._app.UI.Path(this.ID, "system_map"), true);
            this._app.UI.SetVisible(this._app.UI.Path(this.ID, "gameStarMapViewport"), false);
            this._app.UI.AddItem(this._app.UI.Path(this.ID, "gameViewportList"), "", 0, App.Localize("@SYSTEMDETAILS_SYS_MAP"));
            this._app.UI.AddItem(this._app.UI.Path(this.ID, "gameViewportList"), "", 1, App.Localize("@SYSTEMDETAILS_STAR_MAP"));
            this._app.UI.SetSelection(this._app.UI.Path(this.ID, "gameViewportList"), 0);
            this._crits.Activate();
        }
Ejemplo n.º 27
0
        public override void Initialize()
        {
            this._sky        = new Sky(this._app, SkyUsage.StarMap, 0);
            this._crits      = new GameObjectSet(this._app);
            this._planetView = this._crits.Add <PlanetView>();
            this._crits.Add((IGameObject)this._sky);
            StationInfo       stationInfo        = this._app.GameDatabase.GetStationInfo(this._stationID);
            OrbitalObjectInfo orbitalObjectInfo1 = this._app.GameDatabase.GetOrbitalObjectInfo(this._stationID);
            OrbitalObjectInfo orbitalObjectInfo2 = this._app.GameDatabase.GetOrbitalObjectInfo(orbitalObjectInfo1.ParentID.Value);

            this._app.UI.SetText(this._app.UI.Path(this.ID, "station_class"), string.Format(App.Localize("@STATION_LEVEL"), (object)stationInfo.DesignInfo.StationLevel.ToString(), (object)stationInfo.DesignInfo.StationType.ToString()));
            this._app.UI.SetText(this._app.UI.Path(this.ID, "upkeep_cost"), string.Format(App.Localize("@STATION_UPKEEP_COST"), (object)GameSession.CalculateStationUpkeepCost(this._app.GameDatabase, this._app.AssetDatabase, stationInfo).ToString()));
            if (stationInfo.DesignInfo.StationType == StationType.NAVAL)
            {
                this._app.UI.SetText(this._app.UI.Path(this.ID, "naval_capacity"), string.Format(App.Localize("@STATION_FLEET_CAPACITY"), (object)this._app.GameDatabase.GetSystemSupportedCruiserEquivalent(this._app.Game, orbitalObjectInfo2.StarSystemID, this._app.LocalPlayer.ID).ToString()));
            }
            else
            {
                this._app.UI.SetVisible(this._app.UI.Path(this.ID, "naval_capacity"), false);
            }
            StarSystemInfo starSystemInfo = this._app.GameDatabase.GetStarSystemInfo(orbitalObjectInfo2.StarSystemID);

            this._app.UI.SetText("gameStationName", orbitalObjectInfo1.Name);
            this._enteredStationName = orbitalObjectInfo2.Name;
            this._app.UI.SetText(this._app.UI.Path(this.ID, "system_name"), string.Format(App.Localize("@STATION_BUILT"), (object)starSystemInfo.Name).ToUpperInvariant());
            this._cameraReduced                 = new OrbitCameraController(this._app);
            this._cameraReduced.MinDistance     = 1002.5f;
            this._cameraReduced.MaxDistance     = 10000f;
            this._cameraReduced.DesiredDistance = 2000f;
            this._cameraReduced.DesiredYaw      = MathHelper.DegreesToRadians(45f);
            this._cameraReduced.DesiredPitch    = -MathHelper.DegreesToRadians(25f);
            this._cameraReduced.SnapToDesiredPosition();
            this._starmapReduced = new StarMap(this._app, this._app.Game, this._sky);
            this._starmapReduced.Initialize(this._crits);
            this._starmapReduced.SetCamera(this._cameraReduced);
            this._starmapReduced.FocusEnabled = false;
            this._starmapReduced.PostSetProp("Selected", this._starmapReduced.Systems.Reverse[starSystemInfo.ID].ObjectID);
            this._starmapReduced.PostSetProp("CullCenter", this._app.GameDatabase.GetStarSystemInfo(starSystemInfo.ID).Origin);
            this._starmapReduced.PostSetProp("CullRadius", 15f);
            DesignInfo di = DesignLab.CreateStationDesignInfo(this._app.AssetDatabase, this._app.GameDatabase, this._app.LocalPlayer.ID, stationInfo.DesignInfo.StationType, stationInfo.DesignInfo.StationLevel, false);

            this._stationModel = new StarSystemDummyOccupant(this._app, this._app.AssetDatabase.ShipSections.First <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == di.DesignSections[0].FilePath)).ModelName, stationInfo.DesignInfo.StationType);
            this._stationModel.PostSetScale(1f / 500f);
            this._stationModel.PostSetPosition(this._trans);
        }
Ejemplo n.º 28
0
        public PolarStarMap(StarMap map, Point station)
        {
            stars = new List <Point>(map.stars.Where(p => p != station));

            // Order them by theta
            stars.Sort((p1, p2) =>
            {
                // First by Y (theta) then by X (r)
                var theta1 = Helper.theta(p1, station);
                var theta2 = Helper.theta(p2, station);
                if (Helper.sameAs(theta1, theta2))
                {
                    // Reverse order
                    return(Helper.r(p1, station).CompareTo(Helper.r(p2, station)));
                }
                return(theta1.CompareTo(theta2));
            });
        }
Ejemplo n.º 29
0
        protected void InitStarMap()
        {
            var starMap = new StarMap();

            AstroImage image = m_VideoController.GetCurrentAstroImage(false);

            starMap.FindBestMap(
                AstrometryContext.Current.StarMapConfig,
                image,
                AstrometryContext.Current.OSDRectToExclude,
                AstrometryContext.Current.RectToInclude,
                AstrometryContext.Current.LimitByInclusion);

            AstrometryContext.Current.StarMap = starMap;

#if ASTROMETRY_DEBUG
            Trace.Assert(AstrometryContext.Current.StarMap != null);
            Trace.Assert(AstrometryContext.Current.StarMap.Features.Count > 0);
#endif
        }
Ejemplo n.º 30
0
    public int SolveB(string input, Point station)
    {
        var lines   = File.ReadAllLines(input, Encoding.UTF8);
        var starMap = StarMap.Parse(lines);

        // Convert all the stars to polar coords
        var polar = new PolarStarMap(starMap, station);

        var             destroyed = new List <Point>();
        Func <int, int> increment = (index) =>
        {
            index++;
            if (index >= polar.stars.Count)
            {
                index = 0;
            }
            return(index);
        };
        Point?last = null;

        for (int index = 0; destroyed.Count < 200 && destroyed.Count < polar.stars.Count; index = increment(index))
        {
            if (index == 0)
            {
                last = null;
            }
            var  consider  = polar.stars[index];
            bool sameAngle = last.HasValue && Helper.sameAs(Helper.theta(last.Value, station), Helper.theta(consider, station));
            bool valid     = !destroyed.Contains(polar.stars[index]) && !sameAngle;
            if (valid)
            {
                destroyed.Add(consider);
                last = consider;
                // Console.WriteLine(consider);
            }
        }

        var asteroid = last.Value;

        return((int)Math.Round(asteroid.X * 100 + asteroid.Y));
    }
Ejemplo n.º 31
0
        public static LeastSquareFittedAstrometry FromReflectedObject(object reflObj)
        {
            var rv = new LeastSquareFittedAstrometry();

            rv.m_RA0Deg         = StarMap.GetPropValue <double>(reflObj, "m_RA0Deg");
            rv.m_DE0Deg         = StarMap.GetPropValue <double>(reflObj, "m_DE0Deg");
            rv.m_Variance       = StarMap.GetPropValue <double>(reflObj, "m_Variance");
            rv.m_StdDevRAArcSec = StarMap.GetPropValue <double>(reflObj, "m_StdDevRAArcSec");
            rv.m_StdDevDEArcSec = StarMap.GetPropValue <double>(reflObj, "m_StdDevDEArcSec");

            object image = StarMap.GetPropValue <object>(reflObj, "m_Image");

            rv.m_Image = AstroPlate.FromReflectedObject(image);

            object constants = StarMap.GetPropValue <object>(reflObj, "m_SolvedConstants");

            if (constants != null)
            {
                rv.m_SolvedConstants = PlateConstantsFit.FromReflectedObject(constants);
            }

            return(rv);
        }
Ejemplo n.º 32
0
        public static PlateConstantsQadraticFit FromReflectedQadraticFit(object reflObj)
        {
            var rv = new PlateConstantsQadraticFit();

            rv.Const_A = StarMap.GetPropValue <double>(reflObj, "Const_A");
            rv.Const_B = StarMap.GetPropValue <double>(reflObj, "Const_B");
            rv.Const_C = StarMap.GetPropValue <double>(reflObj, "Const_C");
            rv.Const_D = StarMap.GetPropValue <double>(reflObj, "Const_D");
            rv.Const_E = StarMap.GetPropValue <double>(reflObj, "Const_E");
            rv.Const_F = StarMap.GetPropValue <double>(reflObj, "Const_F");
            rv.Const_G = StarMap.GetPropValue <double>(reflObj, "Const_G");
            rv.Const_H = StarMap.GetPropValue <double>(reflObj, "Const_H");
            rv.Const_K = StarMap.GetPropValue <double>(reflObj, "Const_K");
            rv.Const_L = StarMap.GetPropValue <double>(reflObj, "Const_L");
            rv.Const_M = StarMap.GetPropValue <double>(reflObj, "Const_M");
            rv.Const_N = StarMap.GetPropValue <double>(reflObj, "Const_N");

            rv.Const_A1 = StarMap.GetPropValue <double>(reflObj, "Const_A1");
            rv.Const_B1 = StarMap.GetPropValue <double>(reflObj, "Const_B1");
            rv.Const_C1 = StarMap.GetPropValue <double>(reflObj, "Const_C1");
            rv.Const_D1 = StarMap.GetPropValue <double>(reflObj, "Const_D1");
            rv.Const_E1 = StarMap.GetPropValue <double>(reflObj, "Const_E1");
            rv.Const_F1 = StarMap.GetPropValue <double>(reflObj, "Const_F1");
            rv.Const_G1 = StarMap.GetPropValue <double>(reflObj, "Const_G1");
            rv.Const_H1 = StarMap.GetPropValue <double>(reflObj, "Const_H1");
            rv.Const_K1 = StarMap.GetPropValue <double>(reflObj, "Const_K1");
            rv.Const_L1 = StarMap.GetPropValue <double>(reflObj, "Const_L1");
            rv.Const_M1 = StarMap.GetPropValue <double>(reflObj, "Const_M1");
            rv.Const_N1 = StarMap.GetPropValue <double>(reflObj, "Const_N1");

            rv.m_FitInfo = new FitInfo(new List <PlateConstStarPair>());
            object fitInfo = StarMap.GetPropValue <object>(reflObj, "m_FitInfo");

            rv.m_FitInfo.FittedFocalLength = StarMap.GetPropValue <double>(fitInfo, "FittedFocalLength");

            return(rv);
        }
Ejemplo n.º 33
0
        private void UpdatePivotDistances(StarMap starMap, Dictionary <int, int> pivotMap)
        {
            // Remove distance records that are too old
            while (m_TargetPivotDistancesListX.Count >= MAX_DIST_HISTORY)
            {
                m_TargetPivotDistancesListX.RemoveAt(0);
            }
            while (m_TargetPivotDistancesListY.Count >= MAX_DIST_HISTORY)
            {
                m_TargetPivotDistancesListY.RemoveAt(0);
            }

            // Add the new distance recods
            for (int i = 0; i < m_TrackedObjects.Count; i++)
            {
                var targetXDistList = new List <double>();
                var targetYDistList = new List <double>();

                m_TargetPivotDistancesListX.Add(targetXDistList);
                m_TargetPivotDistancesListY.Add(targetYDistList);

                for (int j = 0; j < pivotMap.Count; j++)
                {
                    targetXDistList.Add(m_TrackedObjects[i].Center.XDouble - starMap.Features[pivotMap[j]].GetCenter().XDouble);
                    targetYDistList.Add(m_TrackedObjects[i].Center.YDouble - starMap.Features[pivotMap[j]].GetCenter().YDouble);
                }
            }

            // Calcluate the new median and set the current values
            for (int i = 0; i < m_TrackedObjects.Count; i++)
            {
                // Updating the distances is important for a slow field rotation. However this may break the
                // tracking of some of the pivots are not recognized correctly. No updates for now.

                // TODO: Implement this once the pivot identification has been made very reliable
            }
        }
Ejemplo n.º 34
0
		public static StarMap GetMapData(string playerName, string password)
		{
			var db = new DbDataContext();

			var ret = new StarMap();

			var lo = new DataLoadOptions();
			lo.LoadWith<CelestialObject>(x => x.CelestialObjectShips); // todo stealth also in all fleet structures
			lo.LoadWith<CelestialObject>(x => x.CelestialObjectStructures);
			db.LoadOptions = lo;
			ret.CelestialObjects = db.CelestialObjects.ToList();

			ret.Players = db.Players.Where(x => x.IsActive).ToList();

			ret.StarSystems = db.StarSystems.ToList();

			ret.Transits = FleetLogic.GetTransits(playerName, password);

			ret.Config = db.GetConfig();

			ret.ObjectLinks = db.CelestialObjectLinks.ToList();

			return ret;
		}
Ejemplo n.º 35
0
        public bool InitializeNewTracking(IAstroImage astroImage)
        {
            m_StarMapConfig = new StarMapInternalConfig(StarMapInternalConfig.Default);
            m_StarMapConfig.CustomMaxSignalValue = astroImage.GetPixelmapPixels().Max();
            m_StarMapConfig.CustomOptimumStarsValue = 25;
            m_StarMapConfig.IsFITSFile = true;

            StarMap starMap = new StarMap();
            starMap.FindBestMap(
                            m_StarMapConfig,
                            (AstroImage)astroImage,
                            Rectangle.Empty,
                            new Rectangle(0, 0, astroImage.Width, astroImage.Height),
                            AstrometryContext.Current.LimitByInclusion);

            if (starMap.Features.Count < 10)
            {
                MessageBox.Show("Cannot initialize object tracking as less than 10 stars can be identified in the field");
                return false;
            }

            // Build a signature of the largest 10 features (pivots)
            m_PivotDistances.Clear();
            for (int i = 0; i < 10; i++) m_PivotDistances.Add(new List<double>(UNINITIALIZED_DISTANCES));

            double fwhmSum = 0;
            int fwhmCount = 0;

            starMap.Features.Sort((x, y) => y.PixelCount.CompareTo(x.PixelCount));
            for (int i = 0; i < 10; i++)
            {
                var feature_i = starMap.Features[i];
                for (int j = i + 1; j < 10; j++)
                {
                    var feature_j = starMap.Features[j];
                    double distance = feature_j.GetCenter().DistanceTo(feature_i.GetCenter());
                    m_PivotDistances[i][j] = distance;
                    m_PivotDistances[j][i] = distance;
                }

                int x0 = feature_i.GetCenter().X;
                int y0 = feature_i.GetCenter().Y;
                PSFFit fit = new PSFFit((int) x0, (int) y0);
                uint[,] data = ((AstroImage) astroImage).GetMeasurableAreaPixels((int) x0, (int) y0);
                fit.Fit(data);

                if (fit.IsSolved)
                {
                    fwhmSum += fit.FWHM;
                    fwhmCount++;
                }
            }

            m_FWHMAverage = (float)(fwhmSum / fwhmCount);

            for (int i = 0; i < m_TrackedObjects.Count; i++)
            {
                m_TrackedObjectsPivotDistancesX[i] = new List<double>();
                m_TrackedObjectsPivotDistancesY[i] = new List<double>();
                for (int j = 0; j < 10; j++)
                {
                    m_TrackedObjectsPivotDistancesX[i].Add(m_TrackedObjects[i].Center.XDouble - starMap.Features[j].GetCenter().XDouble);
                    m_TrackedObjectsPivotDistancesY[i].Add(m_TrackedObjects[i].Center.YDouble - starMap.Features[j].GetCenter().YDouble);
                }

                int x0 = m_TrackedObjects[i].Center.X;
                int y0 = m_TrackedObjects[i].Center.Y;
                PSFFit fit = new PSFFit((int)x0, (int)y0);
                uint[,] data = ((AstroImage)astroImage).GetMeasurableAreaPixels((int)x0, (int)y0);
                fit.Fit(data);

                if (fit.IsSolved)
                {
                    SetTargetFWHM(i, (float)fit.FWHM);
                }
            }

            m_TargetPivotDistancesListX.Clear();
            m_TargetPivotDistancesListY.Clear();

            return true;
        }
Ejemplo n.º 36
0
 public StarMapView(StarMap gameObject, Assets assets)
 {
     _gameObject = gameObject;
     _assets = assets;
 }
Ejemplo n.º 37
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            StarMapInternalConfig starMapConfig = StarMapInternalConfig.Default;

            if (rbAuto.Checked)
            {
                starMapConfig.OptimumStarsInField = (int) TangraConfig.Settings.Astrometry.PyramidOptimumStarsToMatch;
                starMapConfig.StarMapperTolerance = 2;
            }
            else
            {
                starMapConfig.OptimumStarsInField = -1;
                starMapConfig.StarMapperTolerance = trbarDepth.Value;
            }

            var starMap = new StarMap();

            var image = new AstroImage(m_InitialPixelmap);

            starMap.FindBestMap(
                starMapConfig,
                image,
                AstrometryContext.Current.OSDRectToExclude,
                AstrometryContext.Current.RectToInclude,
                AstrometryContext.Current.LimitByInclusion);

            AstrometryContext.Current.StarMap = starMap;
            AstrometryContext.Current.StarMapConfig = starMapConfig;

            m_VideoController.RedrawCurrentFrame(false, true);
        }
Ejemplo n.º 38
0
        protected void InitStarMap()
        {
            var starMap = new StarMap();

            AstroImage image = m_VideoController.GetCurrentAstroImage(false);

            starMap.FindBestMap(
                AstrometryContext.Current.StarMapConfig,
                image,
                AstrometryContext.Current.OSDRectToExclude,
                AstrometryContext.Current.RectToInclude,
                AstrometryContext.Current.LimitByInclusion);

            AstrometryContext.Current.StarMap = starMap;

            #if ASTROMETRY_DEBUG
            Trace.Assert(AstrometryContext.Current.StarMap != null);
            Trace.Assert(AstrometryContext.Current.StarMap.Features.Count > 0);
            #endif
        }
Ejemplo n.º 39
0
        public void NextFrame(int frameNo, IAstroImage astroImage)
        {
            m_IsTrackedSuccessfully = false;

            StarMap starMap = new StarMap();
            starMap.FindBestMap(
                            m_StarMapConfig,
                            (AstroImage)astroImage,
                            Rectangle.Empty,
                            new Rectangle(0, 0, astroImage.Width, astroImage.Height),
                            AstrometryContext.Current.LimitByInclusion);

            if (starMap.Features.Count >= 5)
            {
                starMap.Features.Sort((x, y) => y.PixelCount.CompareTo(x.PixelCount));
                int featuresToConsider = Math.Min(10, starMap.Features.Count);

                var featureDistances = new List<List<double>>();
                for (int i = 0; i < featuresToConsider; i++)
                {
                    var dist = new List<double>();
                    for (int j = 0; j < featuresToConsider; j++) dist.Add(double.NaN);
                    featureDistances.Add(dist);
                }

                var pivotDistances = new List<List<double>>();
                for (int i = 0; i < featuresToConsider; i++) pivotDistances.Add(new List<double>(UNINITIALIZED_DISTANCES));

                for (int i = 0; i < featuresToConsider; i++)
                {
                    var feature_i = starMap.Features[i];
                    for (int j = i + 1; j < featuresToConsider; j++)
                    {
                        var feature_j = starMap.Features[j];
                        double distance = feature_j.GetCenter().DistanceTo(feature_i.GetCenter());
                        pivotDistances[i][j] = distance;
                        pivotDistances[j][i] = distance;
                    }
                }

                Dictionary<int, int> pivotMap = IdentifyPivots(pivotDistances);

                int identifiedObjects = 0;

                for (int i = 0; i < m_TrackedObjects.Count; i++)
                {
                    ((TrackedObject)m_TrackedObjects[i]).NewFrame();

                    var xVals = new List<double>();
                    var yVals = new List<double>();
                    foreach (int key in pivotMap.Keys)
                    {
                        int mapsToSourceFeatureId = pivotMap[key];
                        xVals.Add(starMap.Features[key].GetCenter().XDouble + m_TrackedObjectsPivotDistancesX[i][mapsToSourceFeatureId]);
                        yVals.Add(starMap.Features[key].GetCenter().YDouble + m_TrackedObjectsPivotDistancesY[i][mapsToSourceFeatureId]);
                    }

                    double x0 = xVals.Median();
                    double y0 = yVals.Median();

                    double sigmaX = Math.Sqrt(xVals.Select(x => (x - x0)*(x - x0)).Sum()) / (xVals.Count - 1);
                    double sigmaY = Math.Sqrt(yVals.Select(y => (y - y0)*(y - y0)).Sum()) / (yVals.Count - 1);

                    if (!double.IsNaN(x0) && !double.IsNaN(y0) && xVals.Count > 1 &&
                        (sigmaX > m_FWHMAverage || sigmaY > m_FWHMAverage))
                    {
                        // Some of the pivots may have been misidentified. Remove all entries with too large residuals and try again
                        xVals.RemoveAll(x => Math.Abs(x - x0) > sigmaX);
                        yVals.RemoveAll(y => Math.Abs(y - y0) > sigmaY);

                        if (xVals.Count > 1)
                        {
                            x0 = xVals.Median();
                            y0 = yVals.Median();

                            sigmaX = Math.Sqrt(xVals.Select(x => (x - x0) * (x - x0)).Sum()) / (xVals.Count - 1);
                            sigmaY = Math.Sqrt(yVals.Select(y => (y - y0) * (y - y0)).Sum()) / (yVals.Count - 1);
                        }
                    }

                    if (!double.IsNaN(x0) && !double.IsNaN(y0) && xVals.Count > 1 &&
                        (sigmaX > m_FWHMAverage || sigmaY > m_FWHMAverage))
                    {
                        // There is something really wrong about this. Reject the position and fail the frame
                        m_TrackedObjects[i].SetIsTracked(false, NotMeasuredReasons.FoundObjectNotWithInExpectedPositionTolerance, null, null);
                    }
                    else
                    {
                        PSFFit fit = new PSFFit((int)x0, (int)y0);
                        uint[,] data = ((AstroImage)astroImage).GetMeasurableAreaPixels((int)x0, (int)y0);
                        fit.Fit(data);

                        if (fit.IsSolved)
                        {
                            m_TrackedObjects[i].SetIsTracked(true, NotMeasuredReasons.TrackedSuccessfully, new ImagePixel(fit.XCenter, fit.YCenter), fit.Certainty);
                            ((TrackedObject)m_TrackedObjects[i]).ThisFrameX = (float)fit.XCenter;
                            ((TrackedObject)m_TrackedObjects[i]).ThisFrameY = (float)fit.YCenter;
                            ((TrackedObjectBase)m_TrackedObjects[i]).PSFFit = fit;
                            identifiedObjects++;
                        }
                        else
                        {
                            m_TrackedObjects[i].SetIsTracked(false, NotMeasuredReasons.PSFFittingFailed, null, null);
                        }
                    }
                }

                m_IsTrackedSuccessfully = identifiedObjects == m_TrackedObjects.Count;

                if (m_IsTrackedSuccessfully)
                    UpdatePivotDistances(starMap, pivotMap);
            }
        }
Ejemplo n.º 40
0
        private void UpdatePivotDistances(StarMap starMap, Dictionary<int, int> pivotMap)
        {
            // Remove distance records that are too old
            while (m_TargetPivotDistancesListX.Count >= MAX_DIST_HISTORY) m_TargetPivotDistancesListX.RemoveAt(0);
            while (m_TargetPivotDistancesListY.Count >= MAX_DIST_HISTORY) m_TargetPivotDistancesListY.RemoveAt(0);

            // Add the new distance recods
            for (int i = 0; i < m_TrackedObjects.Count; i++)
            {
                var targetXDistList = new List<double>();
                var targetYDistList = new List<double>();

                m_TargetPivotDistancesListX.Add(targetXDistList);
                m_TargetPivotDistancesListY.Add(targetYDistList);

                for (int j = 0; j < pivotMap.Count; j++)
                {
                    targetXDistList.Add(m_TrackedObjects[i].Center.XDouble - starMap.Features[pivotMap[j]].GetCenter().XDouble);
                    targetYDistList.Add(m_TrackedObjects[i].Center.YDouble - starMap.Features[pivotMap[j]].GetCenter().YDouble);
                }
            }

            // Calcluate the new median and set the current values
            for (int i = 0; i < m_TrackedObjects.Count; i++)
            {
                // Updating the distances is important for a slow field rotation. However this may break the
                // tracking of some of the pivots are not recognized correctly. No updates for now.

                // TODO: Implement this once the pivot identification has been made very reliable
            }
        }
Ejemplo n.º 41
0
        public Bitmap ResolveObjects(
			TangraConfig.PhotometryReductionMethod photometryReductionMethod,
			TangraConfig.PsfQuadrature psfQuadrature,
			TangraConfig.PsfFittingMethod psfFittingMethod,
			TangraConfig.BackgroundMethod backgroundMethod,
			TangraConfig.PreProcessingFilter filter,
			Guid magnitudeBandId,
			Rectangle osdRectangleToExclude,
			Rectangle rectToInclude,
			bool limitByInclusion,
			IAstrometrySettings astrometrySettings,
			ObjectResolverSettings objectResolverSettings)
        {
            m_AstrometrySettings = astrometrySettings;

            StarMap starMap = new StarMap(
                astrometrySettings.PyramidRemoveNonStellarObject,
                astrometrySettings.MinReferenceStarFWHM,
                astrometrySettings.MaxReferenceStarFWHM,
                astrometrySettings.MaximumPSFElongation,
                astrometrySettings.LimitReferenceStarDetection);

            starMap.FindBestMap(StarMapInternalConfig.Default, m_Image, osdRectangleToExclude, rectToInclude, limitByInclusion);

            float r0 = 0;

            m_MagnitudeFit = StarMagnitudeFit.PerformFit(
                m_AstrometryController,
                m_VideoController,
                m_Image.Pixelmap.BitPixCamera,
                m_Image.Pixelmap.MaxSignalValue,
                m_Astrometry.FitInfo,
                photometryReductionMethod,
                psfQuadrature,
                psfFittingMethod,
                backgroundMethod,
                filter,
                m_Stars,
                magnitudeBandId,
                1.0f,
                TangraConfig.KnownCameraResponse.Undefined,
                null, null, null,
                ref r0);

            m_BackgroundFlux = m_MagnitudeFit.GetBackgroundIntencity();
            m_BackgroundMag = m_MagnitudeFit.GetMagnitudeForIntencity(m_BackgroundFlux);

            if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceVerbose())
                Trace.WriteLine(string.Format("Plate FWHM: {0}", 2 * Math.Sqrt(Math.Log(2)) * r0));

            PeakPixelResolver resolver = new PeakPixelResolver(m_Image);
            resolver.ResolvePeakPixels(osdRectangleToExclude, rectToInclude, limitByInclusion, objectResolverSettings.ExcludeEdgeAreaPixels, objectResolverSettings.MinDistanceBetweenPeakPixels);

            List<double> identifiedMagnitudes = new List<double>();
            List<double> identifiedR0s = new List<double>();

            m_IdentifiedObjects.Clear();
            m_UidentifiedObjects.Clear();

            foreach(KeyValuePair<int, int> peakPixel in resolver.PeakPixels.Keys)
            {
                int x = peakPixel.Key;
                int y = peakPixel.Value;

                bool isSaturated;
                double intencity = m_MagnitudeFit.GetIntencity(new ImagePixel(255, x, y), out isSaturated);
                double magnitude = m_MagnitudeFit.GetMagnitudeForIntencity(intencity);

                if (magnitude < m_MaxMagForAstrometry)
                {
                    double RADeg, DEDeg;

                    PSFFit fit;
                    starMap.GetPSFFit(x, y, PSFFittingMethod.NonLinearFit, out fit);

                    if (fit.IMax < 0) continue;
                    if (fit.IMax < fit.I0) continue;
                    if (fit.Certainty < objectResolverSettings.MinCertainty) continue;
                    if (fit.FWHM < objectResolverSettings.MinFWHM) continue;
                    if (fit.IMax - fit.I0 < objectResolverSettings.MinAmplitude) continue;

                    m_Astrometry.GetRADEFromImageCoords(fit.XCenter, fit.YCenter, out RADeg, out DEDeg);

                    // All stars closer than 2 arcsec to this position
                    List<IStar> matchingStars = m_Stars.Where(s => Math.Abs(AngleUtility.Elongation(s.RADeg, s.DEDeg, RADeg, DEDeg) * 3600.0) < objectResolverSettings.MaxStarMatchMagDif).ToList();

                    bool identified = false;
                    if (matchingStars.Count >= 1)
                    {
                        foreach(IStar star in matchingStars)
                        {
                            if (objectResolverSettings.MaxStarMatchMagDif >= Math.Abs(magnitude - star.Mag))
                            {
                                // The star is identified. Do we care more?
                                if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceVerbose())
                                    Trace.WriteLine(string.Format("STAR ({0}, {1}) No -> {2}; Mag -> {3} (Expected: {4}); R0 = {5}",
                                        x, y, star.StarNo, magnitude.ToString("0.00"), star.Mag.ToString("0.00"), fit.R0.ToString("0.0")));

                                identifiedMagnitudes.Add(magnitude);
                                identifiedR0s.Add(fit.R0);
                                m_IdentifiedObjects.Add(fit, star);
                                identified = true;
                                break;
                            }
                        }
                    }

                    if (matchingStars.Count == 0 ||
                        !identified)
                    {
                        // The object is not in the star database

                        // TODO: Test for hot pixel. Match to hot pixel profile from the brightest pixel in the area
                        m_UidentifiedObjects.Add(fit, magnitude);
                    }
                }
                else
                {
                    // Don't bother with too faint objects
                }
            }

            if (m_IdentifiedObjects.Count > 0)
            {
                double mean = identifiedR0s.Average();
                double variance = 0;
                foreach (double rr0 in identifiedR0s)
                {
                    variance += (rr0 - mean) * (rr0 - mean);
                }
                variance = Math.Sqrt(variance / (m_IdentifiedObjects.Count - 1));
                double minR0 = mean - variance;
                double maxR0 = mean + variance;

                identifiedMagnitudes.Sort();
                double maxStarMag = identifiedMagnitudes[Math.Max(0, (int)Math.Truncate(0.9 * identifiedMagnitudes.Count))];

                if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceVerbose())
                    Trace.WriteLine(string.Format("Max Star Mag: {0}; R0 ({1}, {2})", maxStarMag.ToString("0.00"), minR0.ToString("0.0"), maxR0.ToString("0.0")));

                // NOTE: The R0 exclusion may ignore bright comets !
                m_UnknownObjects = m_UidentifiedObjects
                    .Where(p => p.Value < maxStarMag && p.Key.R0 >= minR0 && p.Key.R0 <= maxR0)
                    .ToDictionary(p => p.Key, p => p.Value);

                if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceVerbose())
                {
                    foreach (PSFFit obj in m_UnknownObjects.Keys)
                    {
                        Trace.WriteLine(string.Format("UNK: ({0}, {1}) Mag -> {2}; R0 = {3}", obj.XCenter.ToString("0.0"), obj.YCenter.ToString("0.0"), m_UnknownObjects[obj].ToString("0.00"), obj.R0.ToString("0.0")));
                    }
                }
            }

            Bitmap bitmap = m_Image.Pixelmap.CreateDisplayBitmapDoNotDispose();
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                foreach (PSFFit star in m_IdentifiedObjects.Keys)
                {
                    float x = (float)star.XCenter;
                    float y = (float)star.YCenter;

                    g.DrawEllipse(Pens.GreenYellow, x - 5, y - 5, 10, 10);
                }

                foreach (PSFFit star in m_UnknownObjects.Keys)
                {
                    float x = (float)star.XCenter;
                    float y = (float)star.YCenter;

                    g.DrawEllipse(Pens.Tomato, x - 8, y - 8, 16, 16);
                }

                g.Save();
            }

            return bitmap;
        }