DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
DummyCamera.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "DummyCamera.h"
5
6namespace DynExpInstr
7{
9 {
10 {
11 auto InstrParams = DynExp::dynamic_Params_cast<DummyCamera>(Instance.ParamsGetter());
12 auto InstrData = DynExp::dynamic_InstrumentData_cast<DummyCamera>(Instance.InstrumentDataGetter());
13
14 InstrData->DummyImage = QImage(QString::fromStdString(InstrParams->ImagePath.GetPath().string()));
15 if (InstrData->DummyImage.isNull())
16 throw Util::InvalidDataException("Could not load image from \"" + InstrParams->ImagePath.Get() + "\"");
17 } // InstrParams and InstrData unlocked here.
18
20 }
21
23 {
24 QImage Image;
25 CameraData::ImageTransformationType ImageTransformation;
26 {
27 auto InstrData = DynExp::dynamic_InstrumentData_cast<DummyCamera>(Instance.InstrumentDataGetter());
28
29 Image = InstrData->DummyImage;
30 ImageTransformation = InstrData->GetImageTransformation();
31 } // InstrData unlocked here.
32
33 if (ImageTransformation.IsEnabled)
34 {
35 auto ImageBlobPtr = Image.bits();
36
37 long long MaxIndex = 0;
38 switch (Image.format())
39 {
40 case QImage::Format::Format_ARGB32:
41 case QImage::Format::Format_RGB32:
42 MaxIndex = Image.width() * Image.height() * 4;
43 break;
44 case QImage::Format::Format_Grayscale8:
45 case QImage::Format::Format_Grayscale16:
46 MaxIndex = Image.width() * Image.height();
47 break;
48 default:
49 throw Util::NotImplementedException("An image format with the given format cannot be manipulated.");
50 }
51
52 for (long long i = 0; i < MaxIndex; ++i)
53 if (Image.format() == QImage::Format::Format_Grayscale16)
54 {
55 uint16_t Pixel = *(ImageBlobPtr) | (*(ImageBlobPtr + 1) << 8);
56 Pixel = TransformPixel(Pixel, ImageTransformation);
57
58 // Write back
59 *(ImageBlobPtr) = Pixel & 0xff;
60 *(ImageBlobPtr + 1) = (Pixel & 0xff00) >> 8;
61
62 ImageBlobPtr += 2;
63 }
64 else
65 {
66 *ImageBlobPtr = TransformPixel(*ImageBlobPtr, ImageTransformation);
67 ImageBlobPtr++;
68 }
69 }
70
71 return Image;
72 }
73
75 {
76 DummyImage = QImage();
77
79 }
80
81 DummyCamera::DummyCamera(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
82 : Camera(OwnerThreadID, std::move(Params))
83 {
84 }
85
90}
Implementation of a camera instrument without any related physical hardware loading image files from ...
bool IsEnabled
Determines whether the image transformation is to be applied (enabled).
Definition Camera.h:96
Type describing an image transformation.
Definition Camera.h:82
Meta instrument for an image capturing (camera) device.
Definition Camera.h:313
void ResetImpl(dispatch_tag< CameraData >) override final
void InitFuncImpl(dispatch_tag< CameraTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
virtual QImage ObtainImage(DynExp::InstrumentInstance &Instance) override
Retrieves the current image from the underlying hardware device, applies image transformations (e....
void ResetImpl(dispatch_tag< Camera >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
DummyCamera(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to ParamsBase::dispatch_tag.
Definition Instrument.h:146
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:772
const InstrumentBase::InstrumentDataGetterType InstrumentDataGetter
Getter for instrument's data. Refer to InstrumentBase::InstrumentDataGetterType.
Definition Instrument.h:791
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
Definition Object.h:3671
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition Exception.h:163
Thrown when a requested feature is either under development and thus not implemented yet or when a sp...
Definition Exception.h:299
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
T TransformPixel(T Pixel, const CameraData::ImageTransformationType &ImageTransformation)
Applies an image transformation to a single pixel.
Definition Camera.h:431
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition Object.h:1807
Accumulates include statements to provide a precompiled header.