DynExp
Highly flexible laboratory automation for dynamically changing experiments.
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 
19 namespace 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; }
35  };
36 
37  std::strong_ordering operator<=>(const WidefieldLocalizationCellIDType& lhs, const WidefieldLocalizationCellIDType& rhs);
38  std::ostream& operator<<(std::ostream& stream, const WidefieldLocalizationCellIDType& CellID);
39 
40  namespace WidefieldLocalizationTasks
41  {
42  class InitTask : public gRPCInstrumentTasks::InitTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
43  {
45  virtual void InitFuncImpl(dispatch_tag<InitTask>, DynExp::InstrumentInstance& Instance) {}
46  };
47 
48  class ExitTask : public gRPCInstrumentTasks::ExitTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
49  {
51  virtual void ExitFuncImpl(dispatch_tag<ExitTask>, DynExp::InstrumentInstance& Instance) {}
52  };
53 
54  class UpdateTask : public gRPCInstrumentTasks::UpdateTask<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
55  {
57  virtual void UpdateFuncImpl(dispatch_tag<UpdateTask>, DynExp::InstrumentInstance& Instance) {}
58  };
59 
61  {
62  public:
63  ImageProcessingTaskBase(const QImage& Image) noexcept;
64 
65  // Consumes ImageData.
66  DynExpProto::WidefieldLocalization::ImageMessage MakeImageMessage();
67 
68  private:
69  const google::protobuf::uint32 ImageWidth;
70  const google::protobuf::uint32 ImageHeight;
71  const QImage::Format ImageFormat;
72  std::string ImageData;
73  };
74 
76  {
77  public:
78  ReadCellIDTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
79 
80  private:
82  };
83 
85  {
86  public:
87  AnalyzeWidefieldTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
88 
89  private:
91  };
92 
94  {
95  public:
96  AnalyzeDistortionTask(const QImage& Image, CallbackType CallbackFunc) noexcept;
97 
98  private:
100  };
101 
103  {
104  public:
105  RecallPositionsTask(const QImage& Image, const WidefieldLocalizationCellIDType& CellID,
106  std::string_view MeasureSavePath, CallbackType CallbackFunc) noexcept;
107 
108  private:
109  virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance& Instance) override;
110 
112  const std::string MeasureSavePath;
113  };
114  }
115 
116  class WidefieldLocalizationData : public gRPCInstrumentData<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
117  {
121 
122  public:
124  virtual ~WidefieldLocalizationData() = default;
125 
126  const auto& GetCellID() const noexcept { return CellID; }
127  const auto& GetLocalizedPositions() const noexcept { return LocalizedPositions; }
128 
129  private:
130  void ResetImpl(dispatch_tag<gRPCInstrumentData>) override final;
131  virtual void ResetImpl(dispatch_tag<WidefieldLocalizationData>) {};
132 
133  void SetLocalizedPositions(const DynExpProto::WidefieldLocalization::PositionsMessage& PositionsMsg);
134 
136  std::map<google::protobuf::uint32, QPoint> LocalizedPositions;
137  };
138 
139  class WidefieldLocalizationParams : public gRPCInstrumentParams<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
140  {
141  public:
143  virtual ~WidefieldLocalizationParams() = default;
144 
145  virtual const char* GetParamClassTag() const noexcept override { return "WidefieldLocalizationParams"; }
146 
147  private:
149  virtual void ConfigureParamsImpl(dispatch_tag<WidefieldLocalizationParams>) {}
150 
151  DummyParam Dummy = { *this };
152  };
153 
154  class WidefieldLocalizationConfigurator : public gRPCInstrumentConfigurator<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
155  {
156  public:
159 
162 
163  private:
164  virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<WidefieldLocalizationConfigurator>(ID, Core); }
165  };
166 
167  class WidefieldLocalization : public gRPCInstrument<DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization>
168  {
169  public:
173 
174  constexpr static auto Name() noexcept { return "Widefield Localization"; }
175 
178 
179  virtual std::string GetName() const override { return Name(); }
180 
181  virtual void ReadCellID(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::ReadCellIDTask>(Image, CallbackFunc); }
182  virtual void AnalyzeWidefield(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::AnalyzeWidefieldTask>(Image, CallbackFunc); }
183  virtual void AnalyzeDistortion(const QImage& Image, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const { MakeAndEnqueueTask<WidefieldLocalizationTasks::AnalyzeDistortionTask>(Image, CallbackFunc); }
184  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, CallbackFunc); }
185 
186  private:
187  void ResetImpl(dispatch_tag<gRPCInstrument>) override final;
189 
190  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::InitTask>(); }
191  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::ExitTask>(); }
192  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<WidefieldLocalizationTasks::UpdateTask>(); }
193  };
194 }
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)
std::map< google::protobuf::uint32, QPoint > LocalizedPositions
const auto & GetCellID() const noexcept
const auto & GetLocalizedPositions() const noexcept
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 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 void ConfigureParamsImpl(dispatch_tag< WidefieldLocalizationParams >)
void ConfigureParamsImpl(dispatch_tag< gRPCInstrumentParams< DynExp::InstrumentBase, 0, DynExpProto::WidefieldLocalization::WidefieldLocalization >>) override final
AnalyzeDistortionTask(const QImage &Image, CallbackType CallbackFunc) noexcept
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...
AnalyzeWidefieldTask(const QImage &Image, CallbackType CallbackFunc) noexcept
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...
ReadCellIDTask(const QImage &Image, CallbackType CallbackFunc) noexcept
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...
RecallPositionsTask(const QImage &Image, const WidefieldLocalizationCellIDType &CellID, std::string_view MeasureSavePath, CallbackType CallbackFunc) noexcept
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::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
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.
constexpr static auto Name() noexcept
WidefieldLocalization(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
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 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::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
Configurator class for gRPCInstrument.
Data class for gRPCInstrument.
Parameter class for gRPCInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
DynExp::ExitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
DynExp::InitTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for updating an instrument within an instrument inheritance hierarchy....
DynExp::UpdateTaskBase::dispatch_tag< Type > dispatch_tag
Refer to DynExp::ParamsBase::dispatch_tag.
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
Configurator class for InstrumentBase.
Definition: Instrument.h:435
Data structure to contain data which is synchronized in between different threads....
Definition: Instrument.h:135
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition: Instrument.h:772
Parameter class for InstrumentBase.
Definition: Instrument.h:401
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
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition: Instrument.h:892
std::function< void(const TaskBase &, ExceptionContainer &)> CallbackType
Type of a callback function which is invoked when a task has finished, failed or has been aborted....
Definition: Instrument.h:939
const CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a refe...
Definition: Instrument.h:1072
Defines the return type of task functions.
Definition: Instrument.h:824
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...
Definition: Instrument.h:1254
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.
constexpr bool HasCellShift() const noexcept