MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffeGymUiService.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.ServiceModel;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace MyCaffe.gym
9{
13 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
15 {
16 static Dictionary<int, FormGym> m_rgGyms = new Dictionary<int, FormGym>();
17 static object m_syncObjGym = new object();
18 IXMyCaffeGymUiCallback m_callback;
19
24 {
25 m_callback = OperationContext.Current.GetCallbackChannel<IXMyCaffeGymUiCallback>();
26 }
27
28 private void dlg_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
29 {
30 if (m_callback != null)
31 {
32 m_callback.Closing();
33 m_callback = null;
34 }
35 }
36
41 public void CloseUi(int nId)
42 {
43 if (!m_rgGyms.ContainsKey(nId))
44 return;
45
46 m_rgGyms[nId].Hide();
47
48 if (m_callback != null)
49 {
50 m_callback.Closing();
51 m_callback = null;
52 }
53 }
54
62 public int OpenUi(string strName, int nId, bool bStartRecording = false)
63 {
64 lock (m_syncObjGym)
65 {
66 if (m_rgGyms.ContainsKey(nId))
67 {
68 m_rgGyms[nId].BringToFront();
69 return nId;
70 }
71
72 FormGym dlg = new FormGym(strName, null, bStartRecording);
73 dlg.FormClosing += dlg_FormClosing;
74 dlg.Show();
75 dlg.BringToFront();
76
77 nId = m_rgGyms.Count;
78 m_rgGyms.Add(nId, dlg);
79 }
80
81 return nId;
82 }
83
89 public void Render(int nId, Observation obs)
90 {
91 if (!m_rgGyms.ContainsKey(nId))
92 return;
93
94 if (!m_rgGyms[nId].Visible)
95 return;
96
97 if (obs.RequireDisplayImage && obs.ImageDisplay == null)
98 return;
99
100 double[] rgData = obs.State;
101
102 m_rgGyms[nId].Render(rgData, obs.ImageDisplay, obs.Image);
103 }
104
110 public bool IsOpen(int nId)
111 {
112 if (!m_rgGyms.ContainsKey(nId))
113 return false;
114
115 return m_rgGyms[nId].Visible;
116 }
117 }
118}
The FormGym displays the gym visualization.
Definition: FormGym.cs:20
The MyCaffeGymUiService provides the service used to show the Gym visualizations.
void CloseUi(int nId)
Close the user interface of a Gym.
bool IsOpen(int nId)
Returns true when the visualization is open, false otherwise.
int OpenUi(string strName, int nId, bool bStartRecording=false)
Open the Gym user interface.
void Render(int nId, Observation obs)
Render an observation on the Gym user-interface.
The Observation contains data describing the Gym as it runs.
double[] State
Get/set the state data.
bool RequireDisplayImage
Get/set whether or not the image for display (ImageDisplay) is required.
Bitmap ImageDisplay
Get/set the image to display.
Bitmap Image
Get/set the action image, if it exists.
The IXMyCaffeGymUiCallback is used to interact with the user of the IXMyCaffeGymUiService interface.
void Closing()
The Closing method is called when closing the Gym user interface.
The IXMYCaffeGymUiService interface provides access to the MyCaffeGymUiService used to display the vi...
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.