MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffeGymControl.cs
1using System;
2using System.Collections.Generic;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.Threading;
11using MyCaffe.basecode;
12using System.Collections;
14using System.Diagnostics;
15using System.IO;
16
20namespace MyCaffe.gym
21{
25 public partial class MyCaffeGymControl : UserControl
26 {
27 string m_strName = "";
28 Bitmap m_bmp = null;
29 GymCollection m_colGym = new GymCollection();
30 List<Exception> m_loadErrors;
31 bool m_bEnableRecording = false;
32 int m_nRecordingIndex = 0;
33 string m_strRecordingFolder;
34
39 {
40 InitializeComponent();
41 m_loadErrors = m_colGym.Load();
42 m_strRecordingFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MyCaffe\\gym\\recordings";
43 }
44
51 public bool EnableRecording
52 {
53 get { return m_bEnableRecording; }
54 set { m_bEnableRecording = value; }
55 }
56
60 public List<Exception> LoadErrors
61 {
62 get { return m_loadErrors; }
63 }
64
68 public string GymName
69 {
70 get { return m_strName; }
71 }
72
73 private void MyCaffeGymControl_Resize(object sender, EventArgs e)
74 {
75 }
76
77 private void MyCaffeGymControl_Load(object sender, EventArgs e)
78 {
79 }
80
81 private void record(Bitmap bmp)
82 {
83 if (!m_bEnableRecording)
84 return;
85
86 if (!System.IO.Directory.Exists(m_strRecordingFolder))
87 System.IO.Directory.CreateDirectory(m_strRecordingFolder);
88
89 string strFile = m_strRecordingFolder + "\\" + m_nRecordingIndex.ToString("000000") + ".png";
90 bmp.Save(strFile, System.Drawing.Imaging.ImageFormat.Png);
91
92 m_nRecordingIndex++;
93 }
94
98 public bool HasRecordingData
99 {
100 get
101 {
102 if (Directory.Exists(m_strRecordingFolder))
103 {
104 string[] rgstrFiles = Directory.GetFiles(m_strRecordingFolder, "*.png");
105 return (rgstrFiles.Length > 0);
106 }
107
108 return false;
109 }
110 }
111
116 {
117 if (Directory.Exists(m_strRecordingFolder))
118 {
119 string[] rgstrFiles = Directory.GetFiles(m_strRecordingFolder, "*.png");
120
121 foreach (string strFile in rgstrFiles)
122 {
123 File.Delete(strFile);
124 }
125
126 m_nRecordingIndex = 0;
127 }
128 }
129
135 public void Render(string strName, Image bmp)
136 {
137 m_strName = strName;
138 m_bmp = new Bitmap(bmp);
139
140 if (IsHandleCreated && Visible)
141 Invalidate(true);
142
143 record(m_bmp);
144 }
145
153 public void Render(bool bShowUi, string strName, double[] rgData, Image bmp)
154 {
155 m_strName = strName;
156
157 IXMyCaffeGym igym = m_colGym.Find(strName);
158
159 if (bmp != null)
160 {
161 m_bmp = new Bitmap(bmp);
162 }
163 else
164 {
165 Tuple<Bitmap, SimpleDatum> data = igym.Render(bShowUi, Width, Height, rgData, false);
166 if (data != null)
167 m_bmp = data.Item1;
168 }
169
170 if (IsHandleCreated && Visible)
171 Invalidate(true);
172
173 record(m_bmp);
174 }
175
176 private void MyCaffeGymControl_Paint(object sender, PaintEventArgs e)
177 {
178 if (m_bmp != null)
179 e.Graphics.DrawImage(m_bmp, new Point(0, 0));
180 }
181 }
182}
The GymCollection contains the available Gyms.
List< Exception > Load()
Loads the default and dynamic gyms.
IXMyCaffeGym Find(string strName)
Search for a given Gym by its name.
The MyCaffeGymControl displays the actual Gym visualizations.
bool HasRecordingData
Returns whether or not the Gym has any recording data.
string GymName
Returns the GymName.
void Render(bool bShowUi, string strName, double[] rgData, Image bmp)
Renders the Gym visualizations.
List< Exception > LoadErrors
Returns any load errors that may have occured while loading the gyms.
bool EnableRecording
Enable or disable recording. When recording is enabled, each image is saved to the recording folder.
void DeleteRecordingData()
Delete any recording data that exists.
void Render(string strName, Image bmp)
Renders the Gym visualization.
MyCaffeGymControl()
The constructor.
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:99
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
Render the gym on a bitmap.
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12