Skip to content

Commit

Permalink
Merge pull request #446 from micro-manager/galvoProjector2
Browse files Browse the repository at this point in the history
Galvo projector: adds ability to run polygons to Utilities::DAGalvo device.
  • Loading branch information
nicost authored Mar 5, 2024
2 parents 7b4cacb + 47f8419 commit b50b1d9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 18 deletions.
34 changes: 21 additions & 13 deletions DeviceAdapters/DemoCamera/DemoCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ int CDemoCamera::SnapImage()
{
while (exp > (GetCurrentMMTime() - startTime).getMsec())
{
#ifdef _WIN32
// SleepShort(1);
#elif
CDeviceUtils::SleepMs(1);
#endif
}
}
else
Expand Down Expand Up @@ -2410,17 +2414,17 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
// this function.
for (unsigned int i = 0; i < imgWidth; ++i)
{
for (unsigned j = 0; j < img.Height(); ++j)
for (unsigned h = 0; h < img.Height(); ++h)
{
bool shouldKeep = false;
for (unsigned int k = 0; k < multiROIXs_.size(); ++k)
for (unsigned int mr = 0; mr < multiROIXs_.size(); ++mr)
{
unsigned xOffset = multiROIXs_[k] - roiX_;
unsigned yOffset = multiROIYs_[k] - roiY_;
unsigned width = multiROIWidths_[k];
unsigned height = multiROIHeights_[k];
unsigned xOffset = multiROIXs_[mr] - roiX_;
unsigned yOffset = multiROIYs_[mr] - roiY_;
unsigned width = multiROIWidths_[mr];
unsigned height = multiROIHeights_[mr];
if (i >= xOffset && i < xOffset + width &&
j >= yOffset && j < yOffset + height)
h >= yOffset && h < yOffset + height)
{
// Pixel is inside an ROI.
shouldKeep = true;
Expand All @@ -2430,7 +2434,7 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
if (!shouldKeep)
{
// Blank the pixel.
long lIndex = imgWidth * j + i;
long lIndex = imgWidth * h + i;
if (pixelType.compare(g_PixelType_8bit) == 0)
{
*((unsigned char*) rawBuf + lIndex) = static_cast<unsigned char>(multiROIFillValue_);
Expand Down Expand Up @@ -4221,7 +4225,8 @@ DemoGalvo::DemoGalvo() :
offsetX_(20),
vMaxX_(10.0),
offsetY_(15),
vMaxY_(10.0)
vMaxY_(10.0),
pulseTime_Us_(100000.0)
{
// handwritten 5x5 gaussian kernel, no longer used
/*
Expand Down Expand Up @@ -4309,8 +4314,9 @@ int DemoGalvo::PointAndFire(double x, double y, double pulseTime_us)
return DEVICE_OK;
}

int DemoGalvo::SetSpotInterval(double /* pulseInterval_us */)
int DemoGalvo::SetSpotInterval(double pulseTime_Us)
{
pulseTime_Us_ = pulseTime_Us;
return DEVICE_OK;
}

Expand Down Expand Up @@ -4368,17 +4374,19 @@ int DemoGalvo::SetPolygonRepetitions(int /* repetitions */)

int DemoGalvo::RunPolygons()
{
/*
std::ostringstream os;
os << "# of polygons: " << vertices_.size() << std::endl;
for (std::map<int, std::vector<PointD> >::iterator it = vertices_.begin();
it != vertices_.end(); ++it)
{
os << "ROI " << it->first << " has " << it->second.size() << " points" << std::endl;
// illuminate just the first point
this->PointAndFire(it->second.at(0).x, it->second.at(0).y, pulseTime_Us_);
CDeviceUtils::SleepMs((long) (pulseTime_Us_ / 1000.0));
}
LogMessage(os.str().c_str());
*/
runROIS_ = true;

//runROIS_ = true;
return DEVICE_OK;
}

Expand Down
1 change: 1 addition & 0 deletions DeviceAdapters/DemoCamera/DemoCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -1191,4 +1191,5 @@ class DemoGalvo : public CGalvoBase<DemoGalvo>, ImgManipulator
double vMaxX_;
int offsetY_;
double vMaxY_;
double pulseTime_Us_;
};
37 changes: 32 additions & 5 deletions DeviceAdapters/Utilities/DAGalvo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <chrono>
#include <thread>
#include <vector>


extern const char* g_NoDevice;
Expand All @@ -46,6 +47,7 @@ DAGalvo::DAGalvo() :
pulseIntervalUs_(100000),
initialized_(false)
{
polygons_ = new std::vector<DAPolygon*>();
}

DAGalvo::~DAGalvo()
Expand Down Expand Up @@ -236,21 +238,40 @@ double DAGalvo::GetYMinimum()
return yMin;
}

int DAGalvo::AddPolygonVertex(int /* polygonIndex */, double /* x */, double /* y */)
int DAGalvo::AddPolygonVertex(int index, double x, double y)
{
return DEVICE_NOT_YET_IMPLEMENTED;
if (index > 0) {
size_t nrPolygons = polygons_->size();
if (index < nrPolygons) {
DAPolygon* polygon = polygons_->at(index);
polygon->addVertex(x, y);
return true;
}
else if (index == nrPolygons) {
DAPolygon* polygon = new DAPolygon(x, y);
polygons_->push_back(polygon);
return true;
}
}
return false; // the index is more than nrPolygons and our vector does not accomodate this
}

int DAGalvo::DeletePolygons()
{
return DEVICE_NOT_YET_IMPLEMENTED;
for (int i = 0; i < polygons_->size(); i++) {
delete(polygons_->at(i));
}
return polygons_->empty();
}

int DAGalvo::RunSequence()
{
return DEVICE_NOT_YET_IMPLEMENTED;
}

int DAGalvo::LoadPolygons()
{
return DEVICE_NOT_YET_IMPLEMENTED;
return DEVICE_OK; // Not sure how we can benefit, this is supposed to load the polygons to the device
}

int DAGalvo::SetPolygonRepetitions(int repetitions)
Expand All @@ -262,8 +283,14 @@ int DAGalvo::SetPolygonRepetitions(int repetitions)

int DAGalvo::RunPolygons()
{
return DEVICE_NOT_YET_IMPLEMENTED;
for (int i = 0; i < polygons_->size(); i++) {
DAPolygon* polygon = polygons_->at(i);
std::pair<double, double> xyPair = polygon->getVertex(0);
this->PointAndFire(xyPair.first, xyPair.second, pulseIntervalUs_);
}
return DEVICE_OK;
}

int DAGalvo::StopSequence()
{
return DEVICE_NOT_YET_IMPLEMENTED;
Expand Down
33 changes: 33 additions & 0 deletions DeviceAdapters/Utilities/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ImgBuffer.h"
#include <string>
#include <map>
#include <vector>

//////////////////////////////////////////////////////////////////////////////
// Error codes
Expand Down Expand Up @@ -632,6 +633,37 @@ class DATTLStateDevice : public CStateDeviceBase<DATTLStateDevice>
MM::MMTime lastChangeTime_;
};

class DAPolygon
{
private:
std::vector<std::pair<double, double>> polygon_;
public:
DAPolygon(double x, double y) {
polygon_.push_back(std::make_pair(x, y));
}
void addVertex(double x, double y) {
polygon_.push_back(std::make_pair(x, y));
}

boolean hasVertex(size_t index) {
return polygon_.size() <= index + 1;
}

std::pair<double, double> getVertex(size_t index) {
if (polygon_.size() <= index + 1) {
return polygon_[index];
}
else {
// TODO: throw exception
}
}

size_t getNumberOfVertices() {
return polygon_.size();
}
};



class DAGalvo : public CGalvoBase<DAGalvo>
{
Expand Down Expand Up @@ -673,6 +705,7 @@ class DAGalvo : public CGalvoBase<DAGalvo>
long nrRepetitions_;
double pulseIntervalUs_;
std::string shutter_;
std::vector<DAPolygon*> *polygons_;

};

Expand Down

0 comments on commit b50b1d9

Please sign in to comment.