DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
WidefieldLocalization.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
10#pragma once
11
12#include "stdafx.h"
13#include "DynExpCore.h"
15
16#include "WidefieldLocalization.pb.h"
17#include "WidefieldLocalization.grpc.pb.h"
18
19namespace DynExpInstr
20{
21 class WidefieldLocalization;
22
24 {
25 std::string IDString;
26 uint32_t X_id = 0;
27 uint32_t Y_id = 0;
28 bool Valid = false;
29
30 // Optional, stays zero if not returned by ReadCellID rpc.
31 int32_t CellShift_px_x = 0;
32 int32_t CellShift_px_y = 0;
33
34 constexpr bool HasCellShift() const noexcept { return CellShift_px_x || CellShift_px_y; }
36 };
37
38 std::strong_ordering operator<=>(const WidefieldLocalizationCellIDType& lhs, const WidefieldLocalizationCellIDType& rhs);
39 std::ostream& operator<<(std::ostream& stream, const WidefieldLocalizationCellIDType& CellID);
40
41 namespace WidefieldLocalizationTasks
42 {
43 class InitTask : public gRPCInstrumentTasks::InitTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
44 {
46 virtual void InitFuncImpl(dispatch_tag<InitTask>, DynExp::InstrumentInstance& Instance) {}
47 };
48
49 class ExitTask : public gRPCInstrumentTasks::ExitTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
50 {
52 virtual void ExitFuncImpl(dispatch_tag<ExitTask>, DynExp::InstrumentInstance& Instance) {}
53 };
54
55 class UpdateTask : public gRPCInstrumentTasks::UpdateTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
56 {
58 virtual void UpdateFuncImpl(dispatch_tag<UpdateTask>, DynExp::InstrumentInstance& Instance) {}
59 };
60
62 {
63 public:
64 ImageProcessingTaskBase(const QImage& Image) noexcept;
65
66 // Consumes ImageData.
67 DynExpProto::WidefieldLocalization::ImageMessage MakeImageMessage();
68
69 private:
70 const google::protobuf::uint32 ImageWidth;
71 const google::protobuf::uint32 ImageHeight;
72 const QImage::Format ImageFormat;
73 std::string ImageData;
74 };
75
77 {
78 public:
79 ReadCellIDTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
80
81 private:
83 };
84
86 {
87 public:
88 AnalyzeWidefieldTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
89
90 private:
92 };
93
95 {
96 public:
97 AnalyzeDistortionTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
98
99 private:
101 };
102
104 {
105 public:
107 std::string_view MeasureSavePath, CallbackType CallbackFunc) noexcept;
108
109 private:
111
113 const std::string MeasureSavePath;
114 };
115 }
116
117 class WidefieldLocalizationData : public gRPCInstrumentData<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
118 {
122
123 public:
125 virtual ~WidefieldLocalizationData() = default;
126
127 const auto& GetCellID() const noexcept { return CellID; }
128 const auto& GetLocalizedPositions() const noexcept { return LocalizedPositions; }
129
130 private:
131 void ResetImpl(dispatch_tag<gRPCInstrumentData>) override final;
132 virtual void ResetImpl(dispatch_tag<WidefieldLocalizationData>) {};
133
134 void SetLocalizedPositions(const DynExpProto::WidefieldLocalization::PositionsMessage& PositionsMsg);
135
137 std::map<google::protobuf::uint32, QPoint> LocalizedPositions;
138 };
139
140 class WidefieldLocalizationParams : public gRPCInstrumentParams<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
141 {
142 public:
144 virtual ~WidefieldLocalizationParams() = default;
145
146 virtual const char* GetParamClassTag() const noexcept override { return "WidefieldLocalizationParams"; }
147
148 private:
150 virtual void ConfigureParamsImpl(dispatch_tag<WidefieldLocalizationParams>) {}
151
152 DummyParam Dummy = { *this };
153 };
154
155 class WidefieldLocalizationConfigurator : public gRPCInstrumentConfigurator<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
156 {
157 public:
160
163
164 private:
165 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<WidefieldLocalizationConfigurator>(ID, Core); }
166 };
167
168 class WidefieldLocalization : public gRPCInstrument<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
169 {
170 public:
174
175 constexpr static auto Name() noexcept { return "Widefield Localization"; }
176
179
180 virtual std::string GetName() const override { return Name(); }
181
182 virtual void ReadCellID(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::ReadCellIDTask>(Image, std::move(CallbackFunc)); }
183 virtual void AnalyzeWidefield(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::AnalyzeWidefieldTask>(Image, std::move(CallbackFunc)); }
184 virtual void AnalyzeDistortion(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::AnalyzeDistortionTask>(Image, std::move(CallbackFunc)); }
185 virtual void RecallPositions(const QImage& Image, const WidefieldLocalizationCellIDType& CellID, std::string_view MeasureSavePath, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::RecallPositionsTask>(Image, CellID, MeasureSavePath, std::move(CallbackFunc)); }
186
187 private:
188 void ResetImpl(dispatch_tag<gRPCInstrument>) override final;
190
191 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::InitTask>(); }
192 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::ExitTask>(); }
193 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::UpdateTask>(); }
194 };
195}
Defines DynExp's core module as an interface between the UI and DynExp objects.
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
void SetLocalizedPositions(const DynExpProto::WidefieldLocalization::PositionsMessage &PositionsMsg)
const auto & GetLocalizedPositions() const noexcept
std::map< google::protobuf::uint32, QPoint > LocalizedPositions
virtual ~WidefieldLocalizationData()=default
void ResetImpl(dispatch_tag< gRPCInstrumentData >) override final
WidefieldLocalizationCellIDType CellID
virtual void ResetImpl(dispatch_tag< WidefieldLocalizationData >)
WidefieldLocalizationParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
virtual void ConfigureParamsImpl(dispatch_tag< WidefieldLocalizationParams >)
void ConfigureParamsImpl(dispatch_tag< gRPCInstrumentParams< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization > >) override final
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
void ExitFuncImpl(dispatch_tag< gRPCInstrumentTasks::ExitTask< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization > >, DynExp::InstrumentInstance &Instance) override final
DynExpProto::WidefieldLocalization::ImageMessage MakeImageMessage()
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
void InitFuncImpl(dispatch_tag< gRPCInstrumentTasks::InitTask< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization > >, DynExp::InstrumentInstance &Instance) override final
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
void UpdateFuncImpl(dispatch_tag< gRPCInstrumentTasks::UpdateTask< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization > >, DynExp::InstrumentInstance &Instance) override final
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
void ResetImpl(dispatch_tag< gRPCInstrument >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
virtual void AnalyzeDistortion(const QImage &Image, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
virtual void ResetImpl(dispatch_tag< WidefieldLocalization >)
virtual void RecallPositions(const QImage &Image, const WidefieldLocalizationCellIDType &CellID, std::string_view MeasureSavePath, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
virtual std::string GetName() const override
Returns the name of this Object type.
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
virtual void ReadCellID(const QImage &Image, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
virtual void AnalyzeWidefield(const QImage &Image, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
static constexpr auto Name() noexcept
Configurator class for gRPCInstrument.
Data class for gRPCInstrument.
Parameter class for gRPCInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Meta instrument template for transforming meta instruments into network instruments,...
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:813
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2303
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
Type owning a callback function which is invoked when a task has finished, failed,...
Definition Instrument.h:978
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition Instrument.h:929
CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a poin...
Defines the return type of task functions.
Definition Instrument.h:865
Defines a meta instrument template for transforming meta instruments into network instruments,...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
std::strong_ordering operator<=>(const WidefieldLocalizationCellIDType &lhs, const WidefieldLocalizationCellIDType &rhs)
std::ostream & operator<<(std::ostream &stream, const WidefieldLocalizationCellIDType &CellID)
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
Accumulates include statements to provide a precompiled header.
WidefieldLocalizationCellIDType SwapCoords() const