-
Notifications
You must be signed in to change notification settings - Fork 6
/
FullExample.java
76 lines (56 loc) · 2.82 KB
/
FullExample.java
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
package org.micromanager.acqj.example;
import java.util.Iterator;
import java.util.concurrent.Future;
import org.micromanager.acqj.api.AcquisitionAPI;
import org.micromanager.acqj.api.AcqEngJDataSink;
import org.micromanager.acqj.main.Acquisition;
import org.micromanager.acqj.main.AcquisitionEvent;
import org.micromanager.acqj.util.AcqEventModules;
/**
* This class demonstrates how to setup an acquisition using AcqEngJ
*/
public class FullExample {
public FullExample() {
// Create a DataSink where images will be sent
AcqEngJDataSink dataSink = new BlackHoleDataSink();
// Create the acquisition
AcquisitionAPI acquisition = new Acquisition(dataSink);
// Create an acquisition hook, which will be run on the same thread that controls
// hardware
acquisition.addHook(new WorthlessAcquisitionHook(), AcquisitionAPI.AFTER_HARDWARE_HOOK);
// Create an image processor, which will run on its own thread
acquisition.addImageProcessor(new WorthlessImageProcessor());
// Ready the acquisiton to receive events
acquisition.start();
// Now that everything is setup, AcquistionEvents can be added in order to
// start acquiring data.
// Each AcquisitionEvent will order the collection of one image per camera
// Acquisitions accept lazy sequences of AcquisitionEvents, in for form of
// an Iterator<AcquisitionEvent>.
// below is an example of using a convenience function AcqEventModules to order the
// collection a 5 image timelapse with 0 interval between images.
Iterator<AcquisitionEvent> lazySequence = AcqEventModules.timelapse(
5, 0).apply(new AcquisitionEvent(acquisition));
// Make sure that all desired hooks and image processors have been added by this point,
// or else they may miss the Events/images
Future result = acquisition.submitEventIterator(lazySequence);
//Submitting an event iterator returns a Future. Since the actual acquisition occurs on a
// different thread, submitEventIterotor will return immediately. The future can be used
// to check on the progress of the events:
// Calling get will block until the events are acquired, or throw an exceoption if something
// went wrong
try {
result.get();
} catch (Exception e) {
// Something went wrong when acquiring the data
}
// Cancel the execution of the previously submitted events
result.cancel(true);
// submitEventIterator can be called again, if desired
// once no more events will be submitted, signal the acquisition to shutdown.
// This will automatically handle the orderly shutdown of all DataSinks/Hooks/Image processors
acquisition.finish();
// Block until everythin cleaned up
acquisition.waitForCompletion();
}
}