-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultSetup.cs
More file actions
81 lines (72 loc) · 3.35 KB
/
DefaultSetup.cs
File metadata and controls
81 lines (72 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using NITHlibrary.Nith.Module;
using NITHlibrary.Nith.Wrappers.NithWebcamWrapper;
using NITHlibrary.Tools.Ports;
using NITHtemplate.Modules;
using NITHtutorial;
namespace NITHtemplate.Setups
{
/// <summary>
/// The DefaultSetup class is responsible for initializing and configuring the necessary modules and connections for the application.
/// It manages the creation of various modules such as mapping, rendering, and communication receivers, as well as handling cleanup through the Dispose method.
/// It's advised to use this to instance all the modules contained in the Rack, and manage their connections to let them interact together.
/// </summary>
public class DefaultSetup
{
/// <summary>
/// Initializes a new instance of the DefaultSetup class with a specified main window.
/// </summary>
/// <param name="window">The main window reference used for rendering.</param>
public DefaultSetup(MainWindow window)
{
Window = window;
Disposables = new List<IDisposable>();
}
private List<IDisposable> Disposables { get; set; }
private MainWindow Window { get; set; }
/// <summary>
/// Launches the setup actions for the application.
/// This method initializes various modules, connects them,
/// and starts the rendering process for visual output.
/// </summary>
public void Setup()
{
// Make modules
Rack.MappingModule = new MappingModule();
Rack.RenderingModule = new RenderingModule(Window);
Rack.NithModule = new NithModule();
// Initialize the UDP receiver
Rack.UDPreceiver = new UDPreceiver(20100);
// Connect the UDP receiver
Rack.UDPreceiver.Connect();
Rack.UDPreceiver.MaxSamplesPerSecond = 60;
// Add the NithModule as listener to the UDPreceiver
Rack.UDPreceiver.Listeners.Add(Rack.NithModule);
// Initialize the NithWebcamWrapper Preprocessor
Rack.NithPreprocessor_WebcamWrapper = new NithPreprocessor_WebcamWrapper();
Rack.NithModule.Preprocessors.Add(Rack.NithPreprocessor_WebcamWrapper);
Rack.NithModule.MaxQueueSize = 100;
Rack.NithModule.OverflowBehavior = NITHlibrary.Nith.Internals.QueueOverflowBehavior.DropOldest;
// Add behaviors to NithModule
Rack.NithModule.SensorBehaviors.Add(new Behavior_WebcamToProgressBar());
Rack.NithModule.SensorBehaviors.Add(new Behavior_BlinkBasedColorChange());
Rack.NithModule.SensorBehaviors.Add(new Behavior_MouseClick());
// Add disposables to list
Disposables.Add(Rack.RenderingModule);
Disposables.Add(Rack.UDPreceiver);
Disposables.Add(Rack.NithModule);
// Fire the RenderingModule. You will probably want to leave this at the end!
Rack.RenderingModule.StartRendering();
}
/// <summary>
/// Disposes all the disposable modules to free up resources.
/// This method should be called upon program exit to ensure proper cleanup.
/// </summary>
public void Dispose()
{
foreach (IDisposable disposable in Disposables)
{
disposable.Dispose();
}
}
}
}