Skip to content

Commit 97beb0f

Browse files
author
arthur
committed
git-svn-id: https://valelab.ucsf.edu/svn/micromanager2/trunk@12652 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd
1 parent e995b83 commit 97beb0f

6 files changed

Lines changed: 214 additions & 28 deletions

File tree

DeviceAdapters/GenericSLM/GenericSLM.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class GenericSLM : public CSLMBase<GenericSLM>
9191
int OnInversion(MM::PropertyBase* pProp, MM::ActionType eAct);
9292
int OnMonochromeColor(MM::PropertyBase* pProp, MM::ActionType eAct);
9393

94+
int IsSLMSequenceable(bool& isSequenceable) const {isSequenceable = false; return DEVICE_OK;}
95+
9496
private:
9597
string graphicsPortDescription_;
9698
long chosenDisplayIndex_;

MMCore/MMCore.cpp

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,7 @@ void CMMCore::loadPropertySequence(const char* label, const char* propName, std:
34883488
if (ret != DEVICE_OK)
34893489
throw CMMError(getDeviceErrorText(ret, pDevice));
34903490

3491-
std::vector<std::string>::iterator it;
3491+
std::vector<std::string>::iterator it;
34923492
for (std::vector<std::string>::const_iterator it = eventSequence.begin(),
34933493
end = eventSequence.end();
34943494
it < end; ++it)
@@ -5011,9 +5011,7 @@ void CMMCore::setSLMImage(const char* deviceLabel, unsigned char* pixels) throw
50115011
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
50125012
if (!pixels)
50135013
throw CMMError("Null image");
5014-
50155014
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5016-
50175015
int ret = pSLM->SetImage(pixels);
50185016
if (ret != DEVICE_OK)
50195017
{
@@ -5030,9 +5028,7 @@ void CMMCore::setSLMImage(const char* deviceLabel, imgRGB32 pixels) throw (CMMEr
50305028
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
50315029
if (!pixels)
50325030
throw CMMError("Null image");
5033-
50345031
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5035-
50365032
int ret = pSLM->SetImage((unsigned int *) pixels);
50375033
if (ret != DEVICE_OK)
50385034
{
@@ -5047,9 +5043,7 @@ void CMMCore::setSLMImage(const char* deviceLabel, imgRGB32 pixels) throw (CMMEr
50475043
void CMMCore::setSLMPixelsTo(const char* deviceLabel, unsigned char intensity) throw (CMMError)
50485044
{
50495045
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5050-
50515046
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5052-
50535047
int ret = pSLM->SetPixelsTo(intensity);
50545048
if (ret != DEVICE_OK)
50555049
{
@@ -5064,9 +5058,7 @@ void CMMCore::setSLMPixelsTo(const char* deviceLabel, unsigned char intensity) t
50645058
void CMMCore::setSLMPixelsTo(const char* deviceLabel, unsigned char red, unsigned char green, unsigned char blue) throw (CMMError)
50655059
{
50665060
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5067-
50685061
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5069-
50705062
int ret = pSLM->SetPixelsTo(red, green, blue);
50715063
if (ret != DEVICE_OK)
50725064
{
@@ -5081,9 +5073,7 @@ void CMMCore::setSLMPixelsTo(const char* deviceLabel, unsigned char red, unsigne
50815073
void CMMCore::displaySLMImage(const char* deviceLabel) throw (CMMError)
50825074
{
50835075
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5084-
50855076
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5086-
50875077
int ret = pSLM->DisplayImage();
50885078
if (ret != DEVICE_OK)
50895079
{
@@ -5095,9 +5085,7 @@ void CMMCore::displaySLMImage(const char* deviceLabel) throw (CMMError)
50955085
void CMMCore::setSLMExposure(const char* deviceLabel, double exposure_ms) throw (CMMError)
50965086
{
50975087
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5098-
50995088
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5100-
51015089
int ret = pSLM->SetExposure(exposure_ms);
51025090
if (ret != DEVICE_OK)
51035091
{
@@ -5109,47 +5097,93 @@ void CMMCore::setSLMExposure(const char* deviceLabel, double exposure_ms) throw
51095097
double CMMCore::getSLMExposure(const char* deviceLabel) throw (CMMError)
51105098
{
51115099
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5112-
51135100
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5114-
51155101
return pSLM->GetExposure();
51165102
}
51175103

51185104

51195105
unsigned CMMCore::getSLMWidth(const char* deviceLabel)
51205106
{
51215107
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5122-
51235108
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
51245109
return pSLM->GetWidth();
51255110
}
51265111

51275112
unsigned CMMCore::getSLMHeight(const char* deviceLabel)
51285113
{
51295114
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5130-
51315115
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
51325116
return pSLM->GetHeight();
51335117
}
51345118

51355119
unsigned CMMCore::getSLMNumberOfComponents(const char* deviceLabel)
51365120
{
51375121
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5138-
51395122
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
51405123
return pSLM->GetNumberOfComponents();
51415124
}
51425125

51435126
unsigned CMMCore::getSLMBytesPerPixel(const char* deviceLabel)
51445127
{
51455128
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5146-
51475129
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
51485130
return pSLM->GetBytesPerPixel();
51495131
}
51505132

5151-
/* GALVO CODE */
5133+
long CMMCore::getSLMSequenceMaxLength(const char* deviceLabel)
5134+
{
5135+
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5136+
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5137+
long numEvents;
5138+
int ret = pSLM->GetSLMSequenceMaxLength(numEvents);
5139+
if (ret != DEVICE_OK)
5140+
throw CMMError(getDeviceErrorText(ret, pSLM));
5141+
return numEvents;
5142+
}
5143+
5144+
void CMMCore::startSLMSequence(const char* deviceLabel) throw (CMMError)
5145+
{
5146+
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5147+
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5148+
int ret = pSLM->StartSLMSequence();
5149+
if (ret != DEVICE_OK)
5150+
throw CMMError(getDeviceErrorText(ret, pSLM));
5151+
}
51525152

5153+
void CMMCore::stopSLMSequence(const char* deviceLabel) throw (CMMError)
5154+
{
5155+
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5156+
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5157+
int ret = pSLM->StopSLMSequence();
5158+
if (ret != DEVICE_OK)
5159+
throw CMMError(getDeviceErrorText(ret, pSLM));
5160+
}
5161+
5162+
void CMMCore::loadSLMSequence(const char* deviceLabel, std::vector<unsigned char *> imageSequence) throw (CMMError)
5163+
{
5164+
MM::SLM* pSLM = GetDeviceWithCheckedLabelAndType<MM::SLM>(deviceLabel);
5165+
5166+
MMThreadGuard guard(pluginManager_.getModuleLock(pSLM));
5167+
int ret = pSLM->ClearSLMSequence();
5168+
if (ret != DEVICE_OK)
5169+
throw CMMError(getDeviceErrorText(ret, pSLM));
5170+
5171+
std::vector<unsigned char *>::iterator it;
5172+
for (std::vector<unsigned char *>::const_iterator it = imageSequence.begin(),
5173+
end = imageSequence.end();
5174+
it < end; ++it)
5175+
{
5176+
ret = pSLM->AddToSLMSequence(*it);
5177+
if (ret != DEVICE_OK)
5178+
throw CMMError(getDeviceErrorText(ret, pSLM));
5179+
}
5180+
5181+
ret = pSLM->SendSLMSequence();
5182+
if (ret != DEVICE_OK)
5183+
throw CMMError(getDeviceErrorText(ret, pSLM));
5184+
}
5185+
5186+
/* GALVO CODE */
51535187

51545188
/**
51555189
* Set the Galvo to an x,y position and fire the laser for a predetermined duration.

MMCore/MMCore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ class CMMCore
452452
unsigned getSLMHeight(const char* deviceLabel);
453453
unsigned getSLMNumberOfComponents(const char* deviceLabel);
454454
unsigned getSLMBytesPerPixel(const char* deviceLabel);
455+
long getSLMSequenceMaxLength(const char* deviceLabel);
456+
void startSLMSequence(const char* deviceLabel) throw (CMMError);
457+
void stopSLMSequence(const char* deviceLabel) throw (CMMError);
458+
void loadSLMSequence(const char* label, std::vector<unsigned char*> imageSequence) throw (CMMError);
455459
//@ }
456460

457461
/** @name Galvo control

MMCoreJ_wrap/MMCoreJ.i

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
// Java typemap
45-
// change deafult SWIG mapping of unsigned char* return values
45+
// change default SWIG mapping of unsigned char* return values
4646
// to byte[]
4747
//
4848
// Assumes that class has the following method defined:
@@ -98,17 +98,56 @@
9898
%typemap(javain) unsigned char* "$javainput"
9999

100100

101+
101102

103+
// Map input argument: java List<byte[]> -> C++ std::vector<unsigned char*>
104+
%typemap(jni) std::vector<unsigned char*> "jobject"
105+
%typemap(jtype) std::vector<unsigned char*> "java.util.List<byte[]>"
106+
%typemap(jstype) std::vector<unsigned char*> "java.util.List<byte[]>"
107+
%typemap(in) std::vector<unsigned char*>
108+
{
109+
// Assume that we are sending an image to an SLM device, one byte per pixel (monochrome grayscale).
110+
111+
long expectedLength = (arg1)->getSLMWidth(arg2) * (arg1)->getSLMHeight(arg2);
112+
std::vector<unsigned char*> inputVector;
113+
jclass clazz = jenv->FindClass("java/util/List");
114+
jmethodID sizeMethodID = jenv->GetMethodID(clazz, "size", "()I");
115+
// get JNI ID for java.util.List.get(int i) method.
116+
// Because of type erasure we specify an "Object" return value,
117+
// but we expect a byte[] to be returned.
118+
jmethodID getMethodID = jenv->GetMethodID(clazz, "get", "(I)Ljava/lang/Object;");
119+
int listSize = jenv->CallIntMethod($input, sizeMethodID);
120+
121+
for (int i = 0; i < listSize; ++i) {
122+
jbyteArray pixels = (jbyteArray) jenv->CallObjectMethod($input, getMethodID, i);
123+
long receivedLength = jenv->GetArrayLength(pixels);
124+
if (receivedLength != expectedLength && receivedLength != expectedLength*4)
125+
{
126+
jclass excep = jenv->FindClass("java/lang/Exception");
127+
if (excep)
128+
jenv->ThrowNew(excep, "Image dimensions are wrong for this SLM.");
129+
return;
130+
}
131+
inputVector.push_back((unsigned char *) JCALL2(GetByteArrayElements, jenv, pixels, 0));
132+
}
133+
$1 = inputVector;
134+
}
135+
136+
%typemap(freearg) std::vector<unsigned char*> {
137+
// Allow the Java List to be garbage collected.
138+
// Not sure how to do that here -- may not be necessary.
139+
//JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, JNI_ABORT); // JNI_ABORT = Don't alter the original array.
140+
}
141+
142+
%typemap(javain) std::vector<unsigned char*> "$javainput"
143+
102144
// Java typemap
103-
// change deafult SWIG mapping of void* return values
145+
// change default SWIG mapping of void* return values
104146
// to return CObject containing array of pixel values
105147
//
106148
// Assumes that class has the following methods defined:
107149
// unsigned GetImageWidth()
108150
// unsigned GetImageHeight()
109-
// unsigned GetImageDepth()
110-
// unsigned GetNumberOfComponents
111-
112151

113152
%typemap(jni) void* "jobject"
114153
%typemap(jtype) void* "Object"
@@ -204,7 +243,7 @@
204243
}
205244

206245
// Java typemap
207-
// change deafult SWIG mapping of void* return values
246+
// change default SWIG mapping of void* return values
208247
// to return CObject containing array of pixel values
209248
//
210249
// Assumes that class has the following methods defined:
@@ -728,7 +767,6 @@ namespace std {
728767

729768

730769

731-
732770
}
733771

734772

MMDevice/DeviceBase.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,37 @@ class CMagnifierBase : public CDeviceBase<MM::Magnifier, U>
20402040
template <class U>
20412041
class CSLMBase : public CDeviceBase<MM::SLM, U>
20422042
{
2043+
virtual int GetSLMSequenceMaxLength(long& /*nrEvents*/) const
2044+
{
2045+
return DEVICE_UNSUPPORTED_COMMAND;
2046+
}
2047+
2048+
virtual int StartSLMSequence()
2049+
{
2050+
return DEVICE_UNSUPPORTED_COMMAND;
2051+
}
2052+
2053+
virtual int StopSLMSequence() {
2054+
return DEVICE_UNSUPPORTED_COMMAND;
2055+
}
20432056

2057+
virtual int ClearSLMSequence() {
2058+
return DEVICE_UNSUPPORTED_COMMAND;
2059+
}
2060+
2061+
virtual int AddToSLMSequence(const unsigned char * const /*image*/)
2062+
{
2063+
return DEVICE_UNSUPPORTED_COMMAND;
2064+
}
2065+
2066+
virtual int AddToSLMSequence(const unsigned int * const /*image*/)
2067+
{
2068+
return DEVICE_UNSUPPORTED_COMMAND;
2069+
}
2070+
2071+
virtual int SendSLMSequence() {
2072+
return DEVICE_UNSUPPORTED_COMMAND;
2073+
}
20442074
};
20452075

20462076
/**

0 commit comments

Comments
 (0)