From 56a0128d0a235b69bf89231b80834d31aedc61c1 Mon Sep 17 00:00:00 2001 From: robin92 Date: Fri, 15 May 2020 16:40:34 +0200 Subject: [PATCH 01/43] multichannelGrabber: added dummyMultiChannelGrabber plugin --- CMakeLists.txt | 6 + DummyMultiChannelGrabber/CMakeLists.txt | 95 ++ .../DummyMultiChannelGrabber.cpp | 993 ++++++++++++++++++ .../DummyMultiChannelGrabber.h | 98 ++ .../dialogDummyMultiChannelGrabber.cpp | 288 +++++ .../dialogDummyMultiChannelGrabber.h | 66 ++ .../dialogDummyMultiChannelGrabber.ui | 623 +++++++++++ .../dockWidgetDummyMultiChannelGrabber.cpp | 113 ++ .../dockWidgetDummyMultiChannelGrabber.h | 58 + .../dockWidgetDummyMultiChannelGrabber.ui | 392 +++++++ .../docs/dummyMultiChannelGrabber.rst | 53 + DummyMultiChannelGrabber/pluginVersion.h | 45 + 12 files changed, 2830 insertions(+) create mode 100644 DummyMultiChannelGrabber/CMakeLists.txt create mode 100644 DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp create mode 100644 DummyMultiChannelGrabber/DummyMultiChannelGrabber.h create mode 100644 DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp create mode 100644 DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h create mode 100644 DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.ui create mode 100644 DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp create mode 100644 DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h create mode 100644 DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.ui create mode 100644 DummyMultiChannelGrabber/docs/dummyMultiChannelGrabber.rst create mode 100644 DummyMultiChannelGrabber/pluginVersion.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e206bd4d6..fdbf86969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,6 +140,12 @@ if(PLUGIN_DummyGrabber) add_subdirectory(DummyGrabber) endif(PLUGIN_DummyGrabber) +# DummyMultiChannelGrabber +option(PLUGIN_DummyMultiChannelGrabber "Build with this plugin." ON) +if(PLUGIN_DummyMultiChannelGrabber) + add_subdirectory(DummyMultiChannelGrabber) +endif(PLUGIN_DummyMultiChannelGrabber) + # DummyMotor option(PLUGIN_DummyMotor "Build with this plugin." ON) if(PLUGIN_DummyMotor) diff --git a/DummyMultiChannelGrabber/CMakeLists.txt b/DummyMultiChannelGrabber/CMakeLists.txt new file mode 100644 index 000000000..e77db8b32 --- /dev/null +++ b/DummyMultiChannelGrabber/CMakeLists.txt @@ -0,0 +1,95 @@ +set(target_name DummyMultiChannelGrabber) + + +cmake_minimum_required(VERSION 3.1...3.15) + +option(BUILD_TARGET64 "Build for 64 bit target if set to ON or 32 bit if set to OFF." ON) +set(ITOM_SDK_DIR NOTFOUND CACHE PATH "path of SDK subfolder of itom root (build) directory") + +#this is to automatically detect the SDK subfolder of the itom build directory. +find_path(ITOM_SDK_DIR "cmake/itom_sdk.cmake" + HINTS "C:/itom/build/itom/SDK" + "${CMAKE_CURRENT_BINARY_DIR}/../../itom/SDK" + DOC "path of SDK subfolder of itom root (build) directory") + +if(NOT ITOM_SDK_DIR) + message(SEND_ERROR "ITOM_SDK_DIR is invalid. Provide itom SDK directory path first") +endif() + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${ITOM_SDK_DIR}/cmake) + +include(ItomBuildMacros) +itom_init_cmake_policy(3.12) +itom_init_plugin_library(${target_name}) #Start the project, init compiler settings and set default configurations for plugins + + +find_package(ITOM_SDK COMPONENTS dataobject itomCommonLib itomCommonQtLib itomWidgets REQUIRED) +itom_find_package_qt(ON Core Widgets LinguistTools) + +find_package(OpenCV COMPONENTS core REQUIRED) + + + + + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${ITOM_SDK_INCLUDE_DIRS} + ) + +set(PLUGIN_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/DummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/pluginVersion.h + ${CMAKE_CURRENT_BINARY_DIR}/gitVersion.h +) + +set(PLUGIN_UI + ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.ui + ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.ui +) + +set(PLUGIN_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/DummyMultiChannelGrabber.cpp +) + +#Add version information to the plugIn-dll unter MSVC +if(MSVC) + list(APPEND PLUGIN_SOURCES ${ITOM_SDK_INCLUDE_DIR}/../pluginLibraryVersion.rc) +endif() + +################################################################# +# Qt related pre-processing of the files above +# (These methods create the moc, rcc and uic process.) +################################################################# + + +add_library(${target_name} SHARED ${PLUGIN_SOURCES} ${PLUGIN_HEADERS} ${PLUGIN_UI} ${PLUGIN_RCC}) + +# Qt: enable all automoc, autouic and autorcc. +set_target_properties(${target_name} PROPERTIES AUTOMOC ON AUTORCC ON AUTOUIC ON) + +target_link_libraries(${target_name} ${ITOM_SDK_LIBRARIES} ${QT5_LIBRARIES} ${VISUALLEAKDETECTOR_LIBRARIES} ${QT_LIBRARIES}) + + + +#translation +set(FILES_TO_TRANSLATE ${PLUGIN_SOURCES} ${PLUGIN_HEADERS} ${PLUGIN_UI}) +itom_library_translation(QM_FILES TARGET ${target_name} FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE}) + +itom_configure_plugin_documentation(${target_name} DummyMultiChannelGrabber) + +# COPY SECTION +set(COPY_SOURCES "") +set(COPY_DESTINATIONS "") + +itom_add_pluginlibrary_to_copy_list(${target_name} COPY_SOURCES COPY_DESTINATIONS) + +itom_add_plugin_qm_files_to_copy_list(${target_name} QM_FILES COPY_SOURCES COPY_DESTINATIONS) +itom_post_build_copy_files(${target_name} COPY_SOURCES COPY_DESTINATIONS) \ No newline at end of file diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp new file mode 100644 index 000000000..98d3348ac --- /dev/null +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -0,0 +1,993 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2020, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#define ITOM_IMPORT_API +#define ITOM_IMPORT_PLOTAPI + +#include "DummyMultiChannelGrabber.h" + +#define _USE_MATH_DEFINES // needs to be defined to enable standard declartions of PI constant +#include "math.h" + +#ifndef WIN32 + #include +#endif +#include +#include +#include +#include + +#include +#include +#include +#include "dockWidgetDummyMultiChannelGrabber.h" + +#include "pluginVersion.h" +#include "gitVersion.h" +#include "common/helperCommon.h" +#include "common/paramMeta.h" + +#ifdef WIN32 +#include +#endif + +//---------------------------------------------------------------------------------------------------------------------------------- +/** @func fastrand +* @brief function for pseudo random values +* +* This function delivers the noise for the image. +*/ +template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) +{ + return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +/** @func fastrand +* @brief function for pseudo random values +* +* This function delivers the noise for the image. +*/ +template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) +{ + ito::uint32 val = 0; + + for (ito::uint8 i = 0; i < numMeans; ++i) + { + val += ((ito::uint32)rng.next()) & maxval; + } + + return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +/*! + \class DummyMultiChannelGrabberInterface + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to + create one or more new instances of DummyMultiChannelGrabber. +*/ + +//---------------------------------------------------------------------------------------------------------------------------------- +//! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. +/*! + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst + \return retOk + \sa DummyMultiChannelGrabber +*/ +ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **addInInst) +{ + NEW_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. +/*! + \param [in] double pointer to the instance which should be deleted. + \return retOk + \sa DummyMultiChannelGrabber +*/ +ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **addInInst) +{ + REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! constructor for interace +/*! + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must + be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand + and m_initParamsOpt within this constructor. +*/ +DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() +{ + m_autoLoadPolicy = ito::autoLoadKeywordDefined; + m_autoSavePolicy = ito::autoSaveAlways; + + m_type = ito::typeDataIO | ito::typeGrabber; + setObjectName("DummyMultiChannelGrabber"); + + //for the docstring, please don't set any spaces at the beginning of the line. +/* char docstring[] = \ +"The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ +\n\ +The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ +The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ +image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ +\n\ +You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ +\n\ +This plugin can also be used as template for other grabber.";*/ + + m_description = QObject::tr("A virtual white noise grabber"); +// m_detaildescription = QObject::tr(docstring); + m_detaildescription = QObject::tr( +"The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ +\n\ +The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ +The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ +image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ +\n\ +You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ +\n\ +This plugin can also be used as template for other grabber."); + + m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; + m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; + m_minItomVer = CREATEVERSION(1,4,0); + m_maxItomVer = MAXVERSION; + m_license = QObject::tr("Licensed under LPGL."); + m_aboutThis = tr(GITVERSION); + + m_initParamsMand.clear(); + + ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2), tr("Bits per Pixel, usually 8-16bit grayvalues").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); + m_initParamsOpt.append(param); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! destructor +/*! + clears both vectors m_initParamsMand and m_initParamsOpt. +*/ +DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() +{ + m_initParamsMand.clear(); + m_initParamsOpt.clear(); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +// this makro registers the class DummyMultiChannelGrabberInterface with the name DummyMultiChannelGrabberinterface as plugin for the Qt-System (see Qt-DOC) + + +//---------------------------------------------------------------------------------------------------------------------------------- + +/*! + \class DummyMultiChannelGrabber + \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. + + Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the + main (GUI) thread. +*/ + +//---------------------------------------------------------------------------------------------------------------------------------- +//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the addIn-Manager. +/*! + creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog + is closed, reads the new parameter set and deletes the dialog. + + \return retOk + \sa dialogDummyMultiChannelGrabber +*/ +const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) +{ + return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! constructor for DummyMultiChannelGrabber +/*! + In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. + Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. + + \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance + \sa ito::tParam, createDockWidget, setParam, getParam +*/ +DummyMultiChannelGrabber::DummyMultiChannelGrabber() : + AddInMultiChannelGrabber(), + m_isgrabbing(false), + m_totalBinning(1), + m_lineCamera(false) +{ + ito::DoubleMeta *dm; + + ito::Param paramVal("name", ito::ParamBase::String | ito::ParamBase::Readonly, "DummyMultiChannelGrabber", "GrabberName"); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::String, "General"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("defaultChannel", ito::ParamBase::String, "", tr("indicates the current default channel").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, tr("size in x (cols) [px]").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, tr("size in y (rows) [px]").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + m_params.insert(paramVal.getName(), paramVal); + + int roi[] = {0, 0, 2048, 2048}; + paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); + ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + paramVal.setMeta(rm, true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2, "ImageFormatControl"), tr("bitdepth of images").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm->addItem("mode 2"); + sm->addItem("mode 3"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String); + sm->setCategory("DemoParameters"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + + if (hasGuiSupport()) + { + //now create dock widget for this plugin + DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); + Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + } +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! destructor +/*! + \sa ~AddInBase +*/ +DummyMultiChannelGrabber::~DummyMultiChannelGrabber() +{ +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! init method which is called by the addInManager after the initiation of a new instance of DummyMultiChannelGrabber. +/*! + This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the + internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. + + \param [in] paramsMand is a pointer to the vector of mandatory tParams. + \param [in] paramsOpt is a pointer to the vector of optional tParams. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk +*/ +ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + + ito::RetVal retVal; + + int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth + int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels + if (sizeY > 1 && sizeY % 4 != 0) + { + retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); + } + else + { + int bpp = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel + m_params["bpp"].setVal(bpp); + + m_params["sizex"].setVal(sizeX); + m_params["sizex"].setMeta(new ito::IntMeta(4, sizeX, 4), true); + + m_params["sizey"].setVal(sizeY); + if (sizeY == 1) + { + m_lineCamera = true; + m_params["sizey"].setMeta(new ito::IntMeta(1, 1, 1), true); + } + else + { + m_lineCamera = false; + m_params["sizey"].setMeta(new ito::IntMeta(4, sizeY, 4), true); + } + QString tempName; + //add channels to map + for (int i = 0; i < numChannel; ++i) + { + tempName = QString("Channel_%1").arg(i); + m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"]); + } + m_params["defaultChannel"].setVal("Channel_0"); + int roi[] = {0, 0, sizeX, sizeY}; + m_params["roi"].setVal(roi, 4); + if (sizeY == 1) + { + m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); + } + else + { + m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); + } + } + + if (!retVal.containsError()) + { + checkData(); //check if image must be reallocated + + emit parametersChanged(m_params); + } + + setIdentifier(QString::number(getID())); + + if (waitCond) + { + waitCond->returnValue = retVal; + waitCond->release(); + } + + setInitialized(true); //init method has been finished (independent on retval) + return retVal; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! close method which is called before that this instance is deleted by the DummyMultiChannelGrabberInterface +/*! + notice that this method is called in the actual thread of this instance. + + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk + \sa ItomSharedSemaphore +*/ +ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + + if (m_timerID > 0) + { + killTimer(m_timerID); + m_timerID = 0; + } + + if (waitCond) + { + waitCond->returnValue = ito::retOk; + waitCond->release(); + + return waitCond->returnValue; + } + else + { + return ito::retOk; + } +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! returns parameter of m_params with key name. +/*! + This method copies val of the corresponding parameter value. + + \param [in,out] val is a shared-pointer of ito::Param. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore +*/ +ito::RetVal DummyMultiChannelGrabber::getParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue; + QString key; + bool hasIndex = false; + int index; + QString suffix; + ParamMapIterator it; + + //parse the given parameter-name (if you support indexed or suffix-based parameters) + retValue += apiParseParamName(val->getName(), key, hasIndex, index, suffix); + + if (retValue == ito::retOk) + { + //gets the parameter key from m_params map (read-only is allowed, since we only want to get the value). + retValue += apiGetParamFromMapByKey(m_params, key, it, false); + } + + if (!retValue.containsError()) + { + *val = it.value(); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! sets parameter of m_params with key name. +/*! + This method copies the given value to the m_params-parameter. + + \param [in] val is the ito::ParamBase value to set. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore +*/ +ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue; + QString key; + int running = 0; // Used to check if grabber was running bevor + + bool hasIndex; + int index; + QString suffix; + ParamMapIterator it; + + retValue += ito::parseParamName(val->getName(), key, hasIndex, index, suffix); + + if (!retValue.containsError()) + { + //gets the parameter key from m_params map (read-only is not allowed and leads to ito::retError). + retValue += apiGetParamFromMapByKey(m_params, key, it, true); + } + + if (!retValue.containsError()) + { + retValue += apiValidateParam(*it, *val, false, true); + } + + if (!retValue.containsError()) + { + //first check parameters that influence the size or data type of m_data + if (key == "roi" || key == "binning" || key == "bpp") + { + if (!retValue.containsError()) + { + if (grabberStartedCount() > 0) + { + running = grabberStartedCount(); + setGrabberStarted(1); + retValue += stopDevice(NULL); + } + } + + if (key == "bpp") + { + retValue += it->copyValueFrom(&(*val)); + } + else if (key == "roi") + { + if (!hasIndex) + { + retValue += it->copyValueFrom(&(*val)); + m_params["sizex"].setVal(it->getVal()[2]); + m_params["sizey"].setVal(it->getVal()[3]); + } + else + { + it->getVal()[index] = val->getVal(); + m_params["sizex"].setVal(it->getVal()[2]); + m_params["sizey"].setVal(it->getVal()[3]); + } + } + else if (key == "binning") + { + int oldval = it->getVal(); + + int ival = val->getVal(); + int newY = ival % 100; + int newX = (ival - newY) / 100; + + if (m_lineCamera && (newY != 1)) + { + retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); + } + else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) + { + retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); + } + else + { + m_totalBinning = newX * newY; + + retValue += it->copyValueFrom(&(*val)); + + if (oldval != ival) + { + int oldY = oldval % 100; + int oldX = (oldval - oldY) / 100; + float factorX = (float)oldX / (float)newX; + float factorY = (float)oldY / (float)newY; + + int width = m_params["sizex"].getVal() * factorX; + int height = m_params["sizey"].getVal() * factorY; + + int maxWidth = m_params["sizex"].getMax(); + int maxHeight = m_params["sizey"].getMax(); + + m_params["sizex"].setVal(width); + m_params["sizex"].setMeta(new ito::IntMeta(4/newX, maxWidth * factorX, 4/newX), true); + + m_params["sizey"].setVal(height); + m_params["sizey"].setMeta(new ito::IntMeta(4/newY, maxHeight * factorY, 4/newY), true); + + int sizeX = m_params["roi"].getVal()[2] * factorX; + int sizeY = m_params["roi"].getVal()[3] * factorY; + int offsetX = m_params["roi"].getVal()[0] * factorX; + int offsetY = m_params["roi"].getVal()[1] * factorY; + int roi[] = {offsetX, offsetY, sizeX, sizeY}; + m_params["roi"].setVal(roi, 4); + m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1,4/newX,4/newX,maxWidth * factorX,4/newX), ito::RangeMeta(0, height - 1,4/newY,4/newY,maxHeight * factorY,4/newY)), true); + } + } + } + + retValue += checkData(); //check if image must be reallocated + + if (running) + { + retValue += startDevice(NULL); + setGrabberStarted(running); + } + } + else + { + retValue += it->copyValueFrom(&(*val)); + } + } + + if (!retValue.containsError()) + { + emit parametersChanged(m_params); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! With startDevice this camera is initialized. +/*! + In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. + + \note This method is similar to VideoCapture::open() of openCV + + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. +*/ +ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + checkData(); //this will be reallocated in this method. + + incGrabberStarted(); + + if (grabberStartedCount() == 1) + { + m_startOfLastAcquisition = 0; + m_isgrabbing = false; + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! With stopDevice the camera device is stopped (opposite to startDevice) +/*! + In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this method. + + \note This method is similar to VideoCapture::release() of openCV + + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera wasn't started before + \sa startDevice +*/ +ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + decGrabberStarted(); + if (grabberStartedCount() < 0) + { + retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + setGrabberStarted(0); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! Call this method to trigger a new image. +/*! + By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. + The new image is then stored either in internal camera memory or in internal memory of this class. + + \note This method is similar to VideoCapture::grab() of openCV + + \param [in] trigger may describe the trigger parameter (unused here) + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. + \sa getVal +*/ +ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + double frame_time = m_params["frame_time"].getVal(); + double integration_time = m_params["integration_time"].getVal(); + int bpp = m_params["bpp"].getVal(); + float gain = m_params["gain"].getVal(); + float offset = m_params["offset"].getVal(); + + + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + if (bpp < 8 || bpp >= 32) + { + retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); + } + else if (grabberStartedCount() <= 0) + { + retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + } + else + { + m_isgrabbing = true; + + if (frame_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < frame_time) + { + Sleep((frame_time - diff) * 1000.0); + } + } + + m_startOfLastAcquisition = cv::getTickCount(); + //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); + cv::RNG &rng = cv::theRNG(); + + if (m_totalBinning == 1) + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::uint8 *linePtr; + char* a = m_params["defaultChannel"].getVal(); + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::uint16 *linePtr; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::int32 *linePtr; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + else + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::uint8 *linePtr; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::uint16 *linePtr; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt,m_totalBinning, offset, gain); + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); + ito::int32 *linePtr; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + + if (integration_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < integration_time) + { + Sleep((integration_time - diff) * 1000.0); + } + } + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! Returns the grabbed camera frame as a shallow copy. +/*! + This method copies the recently grabbed camera frame to the given DataObject-handle + + \note This method is similar to VideoCapture::retrieve() of openCV + + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire +*/ +ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + ito::RetVal retValue(ito::retOk); + + retValue += retrieveData(); + + if (!retValue.containsError()) + { + if (dObj == NULL) + { + retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + } + else + { + retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + + (*dObj) = this->m_data[m_params["defaultChannel"].getVal()].data; + } + } + + if (waitCond) + { + waitCond->returnValue=retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! Returns the grabbed camera frame as a deep copy. +/*! + This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the + DataObject. + + \note This method is similar to VideoCapture::retrieve() of openCV + + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire +*/ +ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) +{ + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue(ito::retOk); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + if (!dObj) + { + retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + } + else + { + retValue += checkData(dObj); + } + + if (!retValue.containsError()) + { + retValue += retrieveData(dObj); + } + + if (!retValue.containsError()) + { + sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalDataObject) +{ + ito::RetVal retValue(ito::retOk); + + if (m_isgrabbing == false) + { + retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + } + else + { + if (externalDataObject) + { + m_data[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + } + + m_isgrabbing = false; + } + + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) +{ + if (getDockWidget()) + { + QWidget *widget = getDockWidget()->widget(); + if (visible) + { + connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + emit parametersChanged(m_params); + } + else + { + disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + } + } +} diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h new file mode 100644 index 000000000..b11ddf505 --- /dev/null +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -0,0 +1,98 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#ifndef DUMMYMULTICHANNELGRABBER_H +#define DUMMYMULTICHANNELGRABBER_H + +#include "common/addInGrabber.h" +#include "common/typeDefs.h" +#include "dialogDummyMultiChannelGrabber.h" + +#include +#include + +//---------------------------------------------------------------------------------------------------------------------------------- +class DummyMultiChannelGrabberInterface : public ito::AddInInterfaceBase +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "ito.AddInInterfaceBase" ) + Q_INTERFACES(ito::AddInInterfaceBase) /*!< this DummyMultiChannelGrabberInterface implements the ito::AddInInterfaceBase-interface, which makes it available as plugin in itom */ + PLUGIN_ITOM_API + + public: + DummyMultiChannelGrabberInterface(); /*!< Constructor */ + ~DummyMultiChannelGrabberInterface(); /*!< Destructor */ + ito::RetVal getAddInInst(ito::AddInBase **addInInst); /*!< creates new instance of DummyMultiChannelGrabber and returns this instance */ + + private: + ito::RetVal closeThisInst(ito::AddInBase **addInInst); /*!< closes any specific instance of DummyMultiChannelGrabber, given by *addInInst */ + +}; + +//---------------------------------------------------------------------------------------------------------------------------------- +class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber +{ + Q_OBJECT + + protected: + ~DummyMultiChannelGrabber(); + DummyMultiChannelGrabber(); + + ito::RetVal retrieveData(ito::DataObject *externalDataObject = NULL); + + public: + friend class DummyMultiChannelGrabberInterface; + const ito::RetVal showConfDialog(void); + int hasConfDialog(void) { return 1; }; //!< indicates that this plugin has got a configuration dialog + + private: + bool m_isgrabbing; + int64 m_startOfLastAcquisition; + ito::uint8 m_totalBinning; + bool m_lineCamera; + + signals: + + public slots: + ito::RetVal getParam(QSharedPointer val, ItomSharedSemaphore *waitCond = NULL); + ito::RetVal setParam(QSharedPointer val, ItomSharedSemaphore *waitCond = NULL); + + ito::RetVal init(QVector *paramsMand, QVector *paramsOpt, ItomSharedSemaphore *waitCond = NULL); + ito::RetVal close(ItomSharedSemaphore *waitCond); + + ito::RetVal startDevice(ItomSharedSemaphore *waitCond); + ito::RetVal stopDevice(ItomSharedSemaphore *waitCond); + ito::RetVal acquire(const int trigger, ItomSharedSemaphore *waitCond = NULL); + ito::RetVal getVal(void *dObj, ItomSharedSemaphore *waitCond); + ito::RetVal copyVal(void *vpdObj, ItomSharedSemaphore *waitCond); + + private slots: + void dockWidgetVisibilityChanged(bool visible); + + +}; + + + +//---------------------------------------------------------------------------------------------------------------------------------- + +#endif // DummyMultiChannelGrabber_H diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp new file mode 100644 index 000000000..837011134 --- /dev/null +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp @@ -0,0 +1,288 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#include "dialogDummyMultiChannelGrabber.h" + +#include +#include +#include + + +//---------------------------------------------------------------------------------------------------------------------------------- +DialogDummyMultiChannelGrabber::DialogDummyMultiChannelGrabber(ito::AddInBase *grabber) : + AbstractAddInConfigDialog(grabber), + m_firstRun(true) +{ + ui.setupUi(this); + + //disable dialog, since no parameters are known. Parameters will immediately be sent by the slot parametersChanged. + enableDialog(false); +}; + + +//---------------------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::parametersChanged(QMap params) +{ + m_currentParameters = params; + + if (m_firstRun) + { + setWindowTitle(QString((params)["name"].getVal()) + " - " + tr("Configuration Dialog")); + + ito::IntMeta *bppMeta = static_cast(params["bpp"].getMeta()); + ui.combo_bpp->clear(); + int count = 0; + for (int i = bppMeta->getMin(); i <= bppMeta->getMax(); i += bppMeta->getStepSize()) + { + ui.combo_bpp->addItem(QString::number(i)); + ui.combo_bpp->setItemData(count++, i, Qt::UserRole); + } + + ui.comboBinningX->clear(); + ui.comboBinningX->addItem(QString::number(1), 1); + ui.comboBinningX->addItem(QString::number(2), 2); + ui.comboBinningX->addItem(QString::number(4), 4); + + ui.comboBinningY->clear(); + ui.comboBinningY->addItem(QString::number(1), 1); + ui.comboBinningY->addItem(QString::number(2), 2); + ui.comboBinningY->addItem(QString::number(4), 4); + + ui.doubleSpinBox_integration_time->setDisabled( params["integration_time"].getFlags() & ito::ParamBase::Readonly ); + ui.doubleSpinBox_frame_time->setDisabled( params["frame_time"].getFlags() & ito::ParamBase::Readonly ); + + m_firstRun = false; + } + + ito::RectMeta *rm = static_cast(params["roi"].getMeta()); + ui.rangeX01->setLimitsFromIntervalMeta(rm->getWidthRangeMeta()); + ui.rangeY01->setLimitsFromIntervalMeta(rm->getHeightRangeMeta()); + + int *roi = params["roi"].getVal(); + ui.rangeX01->setValues(roi[0], roi[0] + roi[2] - 1); + ui.rangeY01->setValues(roi[1], roi[1] + roi[3] - 1); + ui.rangeX01->setEnabled(! (params["roi"].getFlags() & ito::ParamBase::Readonly)); + ui.rangeY01->setEnabled((!(params["roi"].getFlags() & ito::ParamBase::Readonly)) && params["sizey"].getMax() > 1); + + ui.spinSizeX->setValue(params["sizex"].getVal()); + ui.spinSizeY->setValue(params["sizey"].getVal()); + + double dval = params["gain"].getVal(); + ui.sliderGain->setValue(dval*100.0); + ui.sliderGain->setEnabled(!(params["gain"].getFlags() & ito::ParamBase::Readonly)); + ui.spinBox_gain->setEnabled(!(params["gain"].getFlags() & ito::ParamBase::Readonly)); + + dval = params["offset"].getVal(); + ui.sliderOffset->setValue(dval*100.0); + ui.sliderOffset->setEnabled(!(params["offset"].getFlags() & ito::ParamBase::Readonly)); + ui.spinBox_offset->setEnabled(!(params["gain"].getFlags() & ito::ParamBase::Readonly)); + + ui.combo_bpp->setEnabled(!(params["bpp"].getFlags() & ito::ParamBase::Readonly)); + + for (int i = 0; i < ui.combo_bpp->count(); ++i) + { + if (ui.combo_bpp->itemData(i, Qt::UserRole).toInt() == params["bpp"].getVal()) + { + ui.combo_bpp->setCurrentIndex(i); + break; + } + } + + int ival = params["binning"].getVal(); + int ivalY = ival % 100; + int ivalX = (ival - ivalY) / 100; + ui.comboBinningX->setEnabled(!(params["binning"].getFlags() & ito::ParamBase::Readonly)); + ui.comboBinningY->setEnabled(!(params["binning"].getFlags() & ito::ParamBase::Readonly)); + + int idx = ui.comboBinningX->findData(ivalX, Qt::UserRole); + if (idx >= 0) + { + ui.comboBinningX->setCurrentIndex(idx); + } + + idx = ui.comboBinningY->findData(ivalY, Qt::UserRole); + if (idx >= 0) + { + ui.comboBinningY->setCurrentIndex(idx); + } + + ui.doubleSpinBox_integration_time->setMaximum(params["integration_time"].getMax() *1000.0); + ui.doubleSpinBox_integration_time->setMinimum(params["integration_time"].getMin() *1000.0); + ui.doubleSpinBox_integration_time->setSingleStep(1.0); + ui.doubleSpinBox_integration_time->setValue(params["integration_time"].getVal() *1000.0); + + ui.doubleSpinBox_frame_time->setMaximum(params["frame_time"].getMax() *1000.0); + ui.doubleSpinBox_frame_time->setMinimum(params["frame_time"].getMin() *1000.0); + ui.doubleSpinBox_frame_time->setSingleStep(1.0); + ui.doubleSpinBox_frame_time->setValue(params["frame_time"].getVal() *1000.0); + + + //now activate group boxes, since information is available now (at startup, information is not available, since parameters are sent by a signal) + enableDialog(true); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +ito::RetVal DialogDummyMultiChannelGrabber::applyParameters() +{ + ito::RetVal retValue(ito::retOk); + QVector > values; + bool success = false; + + if (ui.rangeX01->isEnabled() || ui.rangeY01->isEnabled()) + { + int x0, x1, y0, y1; + ui.rangeX01->values(x0,x1); + if (ui.rangeY01->isEnabled()) + { + ui.rangeY01->values(y0,y1); + } + else + { + y0 = 0; + y1 = 0; + } + + int roi[] = {0,0,0,0}; + memcpy(roi, m_currentParameters["roi"].getVal(), 4*sizeof(int)); + + if (roi[0] != x0 || roi[1] != y0 || roi[2] != (x1-x0+1) || roi[3] != (y1-y0+1)) + { + roi[0] = x0; + roi[1] = y0; + roi[2] = x1-x0+1; + roi[3] = y1-y0+1; + values.append(QSharedPointer(new ito::ParamBase("roi", ito::ParamBase::IntArray, 4, roi))); + } + } + + if (ui.comboBinningX->isEnabled() && ui.comboBinningY->isEnabled()) + { + int bin = ui.comboBinningX->currentText().toInt() * 100 + ui.comboBinningY->currentText().toInt(); + if (m_currentParameters["binning"].getVal() != bin) + { + values.append(QSharedPointer(new ito::ParamBase("binning", ito::ParamBase::Int, bin))); + } + } + + if (ui.sliderGain->isEnabled()) + { + double dval = ui.sliderGain->value()/100.0; + if (qAbs(m_currentParameters["gain"].getVal() - dval) >= std::numeric_limits::epsilon()) + { + values.append(QSharedPointer(new ito::ParamBase("gain", ito::ParamBase::Double, dval))); + } + } + + if (ui.sliderOffset->isEnabled()) + { + double dval = ui.sliderOffset->value()/100.0; + if (qAbs(m_currentParameters["offset"].getVal() - dval) >= std::numeric_limits::epsilon()) + { + values.append(QSharedPointer(new ito::ParamBase("offset", ito::ParamBase::Double, dval))); + } + } + + if (ui.doubleSpinBox_integration_time->isEnabled()) + { + double dval = ui.doubleSpinBox_integration_time->value(); + if (qAbs(m_currentParameters["integration_time"].getVal() - dval) >= 0.00001) //the smallest range is 1musec, given by the number of decimals of the spin box. //std::numeric_limits::epsilon()) + { + values.append(QSharedPointer(new ito::ParamBase("integration_time", ito::ParamBase::Double, dval))); + } + } + + if (ui.doubleSpinBox_frame_time->isEnabled()) + { + double dval = ui.doubleSpinBox_frame_time->value(); + if (qAbs(m_currentParameters["frame_time"].getVal() - dval) >= 0.00001) //the smallest range is 1musec, given by the number of decimals of the spin box. //std::numeric_limits::epsilon()) + { + values.append(QSharedPointer(new ito::ParamBase("frame_time", ito::ParamBase::Double, dval))); + } + } + + if (ui.combo_bpp->isEnabled()) + { + int bpp = ui.combo_bpp->itemData(ui.combo_bpp->currentIndex()).toInt(); + + if (m_currentParameters["bpp"].getVal() != bpp) + { + values.append(QSharedPointer(new ito::ParamBase("bpp", ito::ParamBase::Int, bpp))); + } + } + + + + retValue += setPluginParameters(values, msgLevelWarningAndError); + + return retValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::on_buttonBox_clicked(QAbstractButton* btn) +{ + ito::RetVal retValue(ito::retOk); + + QDialogButtonBox::ButtonRole role = ui.buttonBox->buttonRole(btn); + + if (role == QDialogButtonBox::RejectRole) + { + reject(); //close dialog with reject + } + else if (role == QDialogButtonBox::AcceptRole) + { + accept(); //AcceptRole + } + else + { + applyParameters(); //ApplyRole + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::enableDialog(bool enabled) +{ + ui.groupBoxBinning->setEnabled(enabled); + ui.groupBoxIntegration->setEnabled(enabled); + ui.groupBoxSize->setEnabled(enabled); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::on_rangeX01_valuesChanged(int minValue, int maxValue) +{ + ui.spinSizeX->setValue(maxValue - minValue + 1); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::on_rangeY01_valuesChanged(int minValue, int maxValue) +{ + ui.spinSizeY->setValue(maxValue - minValue + 1); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DialogDummyMultiChannelGrabber::on_btnFullROI_clicked() +{ + if (m_currentParameters.contains("sizex") && m_currentParameters.contains("sizey")) + { + ui.rangeX01->setValues(0, m_currentParameters["sizex"].getMax()); + ui.rangeY01->setValues(0, m_currentParameters["sizey"].getMax()); + } +} \ No newline at end of file diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h new file mode 100644 index 000000000..bf7e08c58 --- /dev/null +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h @@ -0,0 +1,66 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#ifndef DIALOGDummyMultiChannelGrabber_H +#define DIALOGDummyMultiChannelGrabber_H + +#include "common/param.h" +#include "common/retVal.h" +#include "common/sharedStructuresQt.h" +#include "common/abstractAddInConfigDialog.h" + +#include "ui_dialogDummyMultiChannelGrabber.h" + +namespace ito +{ + class AddInBase; //forward declaration +} + +class DialogDummyMultiChannelGrabber : public ito::AbstractAddInConfigDialog +{ + Q_OBJECT + + public: + DialogDummyMultiChannelGrabber(ito::AddInBase *grabber); + ~DialogDummyMultiChannelGrabber() {}; + + ito::RetVal applyParameters(); + private: + void enableDialog(bool enabled); + + Ui::dialogDummyMultiChannelGrabber ui; + bool m_firstRun; + + signals: + + public slots: + + void parametersChanged(QMap params); + + private slots: + void on_buttonBox_clicked(QAbstractButton* btn); + void on_rangeX01_valuesChanged(int minValue, int maxValue); + void on_rangeY01_valuesChanged(int minValue, int maxValue); + void on_btnFullROI_clicked(); +}; + +#endif diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.ui b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.ui new file mode 100644 index 000000000..7aba086f5 --- /dev/null +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.ui @@ -0,0 +1,623 @@ + + + dialogDummyMultiChannelGrabber + + + + 0 + 0 + 606 + 498 + + + + Dialog + + + + + + + + true + + + Buffer + + + + + + + + + 0 + 0 + + + + Binning X + + + + + + + + 1 + + + + + 2 + + + + + 4 + + + + + + + + + 0 + 0 + + + + Binning Y + + + + + + + + 1 + + + + + 2 + + + + + 4 + + + + + + + + + + + + Bits per Pixel + + + + + + + false + + + -1 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + true + + + Integration + + + + + + Offset + + + + + + + false + + + 100 + + + false + + + Qt::Horizontal + + + + + + + false + + + % + + + 0 + + + 100 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 20 + + + + + + + + Gain + + + + + + + false + + + 100 + + + false + + + Qt::Horizontal + + + + + + + false + + + % + + + 0 + + + 100 + + + + + + + Integrationtime + + + + + + + false + + + + + + ms + + + 1 + + + 0.000000000000000 + + + 65.000000000000000 + + + 1.000000000000000 + + + 10.000000000000000 + + + + + + + Frametime + + + + + + + false + + + + + + ms + + + 1 + + + 0.000000000000000 + + + 65.000000000000000 + + + 1.000000000000000 + + + 10.000000000000000 + + + + + + + + + + true + + + Size + + + + + + + + x0 + + + + + + + 2048 + + + 99 + + + + + + + + + 5 + + + true + + + false + + + 0 + + + + + + + x1 + + + + + + + y0 + + + + + + + 2 + + + 2048 + + + 99 + + + + + + + + + 5 + + + true + + + false + + + 0 + + + + + + + y1 + + + + + + + + + + + x-size + + + + + + + true + + + true + + + QAbstractSpinBox::NoButtons + + + false + + + px + + + 10000 + + + 666 + + + + + + + y-size + + + + + + + true + + + true + + + QAbstractSpinBox::NoButtons + + + px + + + 10000 + + + 666 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + full ROI + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Qt::Vertical + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + RangeWidget + QWidget +
rangeWidget.h
+
+
+ + sliderOffset + spinBox_offset + sliderGain + spinBox_gain + doubleSpinBox_integration_time + doubleSpinBox_frame_time + + + + + sliderOffset + valueChanged(int) + spinBox_offset + setValue(int) + + + 137 + 135 + + + 294 + 143 + + + + + sliderGain + valueChanged(int) + spinBox_gain + setValue(int) + + + 117 + 162 + + + 294 + 172 + + + + + spinBox_offset + valueChanged(int) + sliderOffset + setValue(int) + + + 275 + 132 + + + 154 + 136 + + + + + spinBox_gain + valueChanged(int) + sliderGain + setValue(int) + + + 268 + 163 + + + 189 + 167 + + + + +
diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp new file mode 100644 index 000000000..bfd432ff0 --- /dev/null +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp @@ -0,0 +1,113 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#include "dockWidgetDummyMultiChannelGrabber.h" + +//---------------------------------------------------------------------------------------------------------------------------------- +DockWidgetDummyMultiChannelGrabber::DockWidgetDummyMultiChannelGrabber(ito::AddInDataIO *grabber) : + AbstractAddInDockWidget(grabber), + m_inEditing(false), + m_firstRun(true) +{ + ui.setupUi(this); +} + +//---------------------------------------------------------------------------------------------------------------------------------- + void DockWidgetDummyMultiChannelGrabber::parametersChanged(QMap params) + { + ui.spinBpp->setValue(params["bpp"].getVal()); + ui.spinWidth->setValue(params["sizex"].getVal()); + ui.spinHeight->setValue(params["sizey"].getVal()); + + if (m_firstRun) + { + ui.spinBox_gain->setDisabled( params["gain"].getFlags() & ito::ParamBase::Readonly ); + ui.horizontalSlider_gain->setDisabled( params["gain"].getFlags() & ito::ParamBase::Readonly ); + + ui.spinBox_offset->setDisabled( params["offset"].getFlags() & ito::ParamBase::Readonly ); + ui.horizontalSlider_offset->setDisabled( params["offset"].getFlags() & ito::ParamBase::Readonly ); + + ui.doubleSpinBox_integration_time->setDisabled( params["integration_time"].getFlags() & ito::ParamBase::Readonly ); + + m_firstRun = false; + } + + if (!m_inEditing) + { + m_inEditing = true; + + ui.doubleSpinBox_integration_time->setMaximum(params["integration_time"].getMax() *1000.0); + ui.doubleSpinBox_integration_time->setMinimum(params["integration_time"].getMin() *1000.0); + ui.doubleSpinBox_integration_time->setSingleStep(1); + ui.doubleSpinBox_integration_time->setValue(params["integration_time"].getVal() *1000.0); + + ui.spinBox_offset->setValue((int)(params["offset"].getVal()*100.0+0.5)); + ui.spinBox_gain->setValue((int)(params["gain"].getVal()*100.0+0.5)); + + m_inEditing = false; + } + } + +//---------------------------------------------------------------------------------------------------------------------------------- +void DockWidgetDummyMultiChannelGrabber::identifierChanged(const QString &identifier) +{ + ui.lblID->setText(identifier); +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DockWidgetDummyMultiChannelGrabber::on_spinBox_gain_valueChanged(int d) +{ + if (!m_inEditing) + { + m_inEditing = true; + QSharedPointer p(new ito::ParamBase("gain",ito::ParamBase::Double,d/100.0)); + setPluginParameter(p, msgLevelWarningAndError); + m_inEditing = false; + } +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DockWidgetDummyMultiChannelGrabber::on_spinBox_offset_valueChanged(int d) +{ + if (!m_inEditing) + { + m_inEditing = true; + QSharedPointer p(new ito::ParamBase("offset",ito::ParamBase::Double,d/100.0)); + setPluginParameter(p, msgLevelWarningAndError); + m_inEditing = false; + } +} + +//---------------------------------------------------------------------------------------------------------------------------------- +void DockWidgetDummyMultiChannelGrabber::on_doubleSpinBox_integration_time_valueChanged(double d) +{ + if (!m_inEditing) + { + m_inEditing = true; + QSharedPointer p(new ito::ParamBase("integration_time",ito::ParamBase::Double,d/1000.0)); + setPluginParameter(p, msgLevelWarningAndError); + m_inEditing = false; + } +} + + + diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h new file mode 100644 index 000000000..5c252176a --- /dev/null +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h @@ -0,0 +1,58 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#ifndef DOCKWIDGETDummyMultiChannelGrabber_H +#define DOCKWIDGETDummyMultiChannelGrabber_H + +#include "common/abstractAddInDockWidget.h" +#include "common/addInGrabber.h" + +#include +#include + +#include "ui_dockWidgetDummyMultiChannelGrabber.h" + +class DockWidgetDummyMultiChannelGrabber : public ito::AbstractAddInDockWidget +{ + Q_OBJECT + + public: + DockWidgetDummyMultiChannelGrabber(ito::AddInDataIO *grabber); + ~DockWidgetDummyMultiChannelGrabber() {}; + + private: + Ui::DockWidgetDummyMultiChannelGrabber ui; + bool m_inEditing; + bool m_firstRun; + + public slots: + void parametersChanged(QMap params); + void identifierChanged(const QString &identifier); + + + private slots: + void on_spinBox_offset_valueChanged(int d); + void on_spinBox_gain_valueChanged(int d); + void on_doubleSpinBox_integration_time_valueChanged(double d); +}; + +#endif diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.ui b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.ui new file mode 100644 index 000000000..646bfe943 --- /dev/null +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.ui @@ -0,0 +1,392 @@ + + + DockWidgetDummyMultiChannelGrabber + + + + 0 + 0 + 374 + 290 + + + + Form + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + General Information + + + + 8 + + + 1 + + + 8 + + + 6 + + + + + + 0 + 0 + + + + [ID] + + + + + + + ID: + + + + + + + + + + + 0 + 0 + + + + Image Dimensions + + + + 8 + + + 1 + + + 8 + + + 8 + + + + + Width: + + + + + + + Height: + + + + + + + Bits per Pixel: + + + + + + + false + + + px + + + 1 + + + 2048 + + + 1024 + + + + + + + false + + + px + + + 1 + + + 2048 + + + 1024 + + + + + + + false + + + bits + + + 8 + + + 64 + + + 8 + + + + + + + + + + Integration + + + + 8 + + + 1 + + + 8 + + + 8 + + + + + Offset + + + + + + + 100 + + + false + + + Qt::Horizontal + + + + + + + % + + + 0 + + + 100 + + + + + + + Gain + + + + + + + 100 + + + false + + + Qt::Horizontal + + + + + + + % + + + 0 + + + 100 + + + + + + + Integrationtime + + + + + + + + + + ms + + + 1 + + + 0.000000000000000 + + + 65.000000000000000 + + + 1.000000000000000 + + + 10.000000000000000 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + spinWidth + spinHeight + spinBpp + horizontalSlider_offset + spinBox_offset + horizontalSlider_gain + spinBox_gain + doubleSpinBox_integration_time + + + + + horizontalSlider_offset + valueChanged(int) + spinBox_offset + setValue(int) + + + 130 + 204 + + + 254 + 214 + + + + + horizontalSlider_gain + valueChanged(int) + spinBox_gain + setValue(int) + + + 112 + 236 + + + 257 + 240 + + + + + spinBox_offset + valueChanged(int) + horizontalSlider_offset + setValue(int) + + + 229 + 200 + + + 161 + 207 + + + + + spinBox_gain + valueChanged(int) + horizontalSlider_gain + setValue(int) + + + 255 + 234 + + + 128 + 239 + + + + + diff --git a/DummyMultiChannelGrabber/docs/dummyMultiChannelGrabber.rst b/DummyMultiChannelGrabber/docs/dummyMultiChannelGrabber.rst new file mode 100644 index 000000000..0673adef0 --- /dev/null +++ b/DummyMultiChannelGrabber/docs/dummyMultiChannelGrabber.rst @@ -0,0 +1,53 @@ +=================== + DummyMultiChannelGrabber +=================== + +=============== ======================================================================================================== +**Summary**: :pluginsummary:`DummyMultiChannelGrabber` +**Type**: :plugintype:`DummyMultiChannelGrabber` +**License**: :pluginlicense:`DummyMultiChannelGrabber` +**Platforms**: Windows, Linux +**Devices**: Virtual camera providing random noise images +**Author**: :pluginauthor:`DummyMultiChannelGrabber` +=============== ======================================================================================================== + +Overview +======== + +.. pluginsummaryextended:: + :plugin: DummyMultiChannelGrabber + +Initialization +============== + +The following parameters are mandatory or optional for initializing an instance of this plugin: + + .. plugininitparams:: + :plugin: DummyMultiChannelGrabber + +Parameters +=========== + +An instance of this plugin has the following parameters: + +**binning**: {int} + Binning of different pixel, binning = x-factor * 100 + y-factor (binning in y only possible if height of sensor >= 4. +**bpp**: {int} + bitdepth of images +**frame_time**: {float} + Minimum time between the start of two consecutive acquisitions [s], default: 0.0. +**gain**: {float} + Virtual gain +**integration_time**: {float} + Minimum integration time for on acquisition [s], default: 0.0 (as fast as possible). +**name**: {str}, read-only + GrabberName +**offset**: {float} + Virtual offset +**roi**: {int rect [x0,y0,width,height]} + ROI (x,y,width,height) +**sizex**: {int}, read-only + size in x (cols) [px] +**sizey**: {int}, read-only + size in y (rows) [px] + diff --git a/DummyMultiChannelGrabber/pluginVersion.h b/DummyMultiChannelGrabber/pluginVersion.h new file mode 100644 index 000000000..e4739d268 --- /dev/null +++ b/DummyMultiChannelGrabber/pluginVersion.h @@ -0,0 +1,45 @@ +/* ******************************************************************** + itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of itom and its software development toolkit (SDK). + + itom is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + In addition, as a special exception, the Institut fuer Technische + Optik (ITO) gives you certain additional rights. + These rights are described in the ITO LGPL Exception version 1.0, + which can be found in the file LGPL_EXCEPTION.txt in this package. + + itom is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#ifndef PLUGINVERSION_H +#define PLUGINVERSION_H + +#include "itom_sdk.h" + +#define PLUGIN_VERSION_MAJOR 1 +#define PLUGIN_VERSION_MINOR 5 +#define PLUGIN_VERSION_PATCH 0 +#define PLUGIN_VERSION_REVISION 0 +#define PLUGIN_VERSION CREATE_VERSION(PLUGIN_VERSION_MAJOR,PLUGIN_VERSION_MINOR,PLUGIN_VERSION_PATCH) +#define PLUGIN_VERSION_STRING CREATE_VERSION_STRING(PLUGIN_VERSION_MAJOR,PLUGIN_VERSION_MINOR,PLUGIN_VERSION_PATCH) +#define PLUGIN_COMPANY "Institut fuer Technische Optik, University Stuttgart" +#define PLUGIN_COPYRIGHT "(C) 2017, ITO, University Stuttgart" +#define PLUGIN_NAME "DummyMultiChannelGrabber" + +//---------------------------------------------------------------------------------------------------------------------------------- + +#endif // PLUGINVERSION_H From 6fca55a084368640f8281ab576648e093f88cee4 Mon Sep 17 00:00:00 2001 From: robin92 Date: Wed, 8 Jul 2020 16:20:37 +0200 Subject: [PATCH 02/43] implemented setParam for channel specific params multiChannelGrabber --- .../DummyMultiChannelGrabber.cpp | 140 +++++++++++------- .../DummyMultiChannelGrabber.h | 1 + 2 files changed, 86 insertions(+), 55 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 98d3348ac..08ea0a94a 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -170,8 +170,8 @@ This plugin can also be used as template for other grabber."); param = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2), tr("Bits per Pixel, usually 8-16bit grayvalues").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); + m_initParamsOpt.append(param); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -259,9 +259,9 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : dm->setCategory("AcquisitionControl"); dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("defaultChannel", ito::ParamBase::String, "", tr("indicates the current default channel").toLatin1().data()); - m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("defaultChannel", ito::ParamBase::String, "", tr("indicates the current default channel").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); @@ -306,14 +306,14 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : m_params.insert(paramVal.getName(), paramVal); - if (hasGuiSupport()) - { - //now create dock widget for this plugin - DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); - Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); - } + if (hasGuiSupport()) + { + //now create dock widget for this plugin + DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); + Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + } } //---------------------------------------------------------------------------------------------------------------------------------- @@ -344,7 +344,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels + int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels if (sizeY > 1 && sizeY % 4 != 0) { retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); @@ -368,16 +368,17 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan m_lineCamera = false; m_params["sizey"].setMeta(new ito::IntMeta(4, sizeY, 4), true); } - QString tempName; - //add channels to map - for (int i = 0; i < numChannel; ++i) - { - tempName = QString("Channel_%1").arg(i); - m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"]); - } - m_params["defaultChannel"].setVal("Channel_0"); + QString tempName; + + m_params["defaultChannel"].setVal("Channel_0"); int roi[] = {0, 0, sizeX, sizeY}; m_params["roi"].setVal(roi, 4); + //add channels to map + for (int i = 0; i < numChannel; ++i) + { + tempName = QString("Channel_%1").arg(i); + m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"], m_params["roi"]); + } if (sizeY == 1) { m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); @@ -519,6 +520,19 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va if (!retValue.containsError()) { + if (key == "defaultChannel") + { + retValue += it->copyValueFrom(&(*val)); + if (m_data.find(it->getVal()) != m_data.end()) + { + m_params["defaultChannel"].setVal(it->getVal()); + syncMultiChannelParams(); + } + else + { + retValue += ito::RetVal(ito::retError, 0, tr("Unknown channel: %1").arg(it->getVal()).toLatin1().data()); + } + } //first check parameters that influence the size or data type of m_data if (key == "roi" || key == "binning" || key == "bpp") { @@ -541,14 +555,18 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va if (!hasIndex) { retValue += it->copyValueFrom(&(*val)); - m_params["sizex"].setVal(it->getVal()[2]); - m_params["sizey"].setVal(it->getVal()[3]); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); + /*m_params["sizex"].setVal(it->getVal()[2]); + m_params["sizey"].setVal(it->getVal()[3]);*/ } else { it->getVal()[index] = val->getVal(); - m_params["sizex"].setVal(it->getVal()[2]); - m_params["sizey"].setVal(it->getVal()[3]); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); + /*m_params["sizex"].setVal(it->getVal()[2]); + m_params["sizey"].setVal(it->getVal()[3]);*/ } } else if (key == "binning") @@ -579,30 +597,32 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va int oldX = (oldval - oldY) / 100; float factorX = (float)oldX / (float)newX; float factorY = (float)oldY / (float)newY; - - int width = m_params["sizex"].getVal() * factorX; - int height = m_params["sizey"].getVal() * factorY; - - int maxWidth = m_params["sizex"].getMax(); - int maxHeight = m_params["sizey"].getMax(); - - m_params["sizex"].setVal(width); - m_params["sizex"].setMeta(new ito::IntMeta(4/newX, maxWidth * factorX, 4/newX), true); - - m_params["sizey"].setVal(height); - m_params["sizey"].setMeta(new ito::IntMeta(4/newY, maxHeight * factorY, 4/newY), true); - - int sizeX = m_params["roi"].getVal()[2] * factorX; - int sizeY = m_params["roi"].getVal()[3] * factorY; - int offsetX = m_params["roi"].getVal()[0] * factorX; - int offsetY = m_params["roi"].getVal()[1] * factorY; - int roi[] = {offsetX, offsetY, sizeX, sizeY}; - m_params["roi"].setVal(roi, 4); - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1,4/newX,4/newX,maxWidth * factorX,4/newX), ito::RangeMeta(0, height - 1,4/newY,4/newY,maxHeight * factorY,4/newY)), true); + ChannelContainer iterParam; + int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; + foreach(iterParam, m_data) + { + width = m_params["sizex"].getVal() * factorX; + height = m_params["sizey"].getVal() * factorY; + + maxWidth = m_params["sizex"].getMax(); + maxHeight = m_params["sizey"].getMax(); + iterParam.m_channelParam["sizex"].setVal(width); + iterParam.m_channelParam["sizex"].setMeta(new ito::IntMeta(4 / newX, maxWidth * factorX, 4 / newX), true); + iterParam.m_channelParam["sizey"].setVal(height); + iterParam.m_channelParam["sizey"].setMeta(new ito::IntMeta(4 / newY, maxHeight * factorY, 4 / newY), true); + + int sizeX = m_params["roi"].getVal()[2] * factorX; + int sizeY = m_params["roi"].getVal()[3] * factorY; + int offsetX = m_params["roi"].getVal()[0] * factorX; + int offsetY = m_params["roi"].getVal()[1] * factorY; + int roi[] = { offsetX, offsetY, sizeX, sizeY }; + iterParam.m_channelParam["roi"].setVal(roi, 4); + iterParam.m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); + } } } } - + syncMultiChannelParams(); retValue += checkData(); //check if image must be reallocated if (running) @@ -761,8 +781,8 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::uint8 *linePtr; - char* a = m_params["defaultChannel"].getVal(); - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + char* a = m_params["defaultChannel"].getVal(); + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint8*)channelObj.rowPtr(0, m); @@ -776,7 +796,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::uint16 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint16*)channelObj.rowPtr(0, m); @@ -790,7 +810,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::int32 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::int32*)channelObj.rowPtr(0, m); @@ -807,7 +827,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::uint8 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint8*)channelObj.rowPtr(0, m); @@ -821,7 +841,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::uint16 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint16*)channelObj.rowPtr(0, m); @@ -835,7 +855,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); ito::int32 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; + ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::int32*)channelObj.rowPtr(0, m); @@ -965,7 +985,7 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalData { if (externalDataObject) { - m_data[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + m_data[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); } m_isgrabbing = false; @@ -991,3 +1011,13 @@ void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) } } } +//---------------------------------------------------------------------------------------------------------------------------------- +void DummyMultiChannelGrabber::syncMultiChannelParams() +{ + m_params["sizex"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].getVal()); + m_params["sizey"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].getVal()); + m_params["bpp"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["bpp"].getVal()); + m_params["roi"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].getVal()); + +} + diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index b11ddf505..d0e1438d6 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -87,6 +87,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber private slots: void dockWidgetVisibilityChanged(bool visible); + void syncMultiChannelParams(); }; From ec1e57a4e4efeb45f5ed30a72233d996aad6162c Mon Sep 17 00:00:00 2001 From: robin92 Date: Fri, 10 Jul 2020 13:26:48 +0200 Subject: [PATCH 03/43] DummyMultiChannelGrabber:adapted setParam --- .../DummyMultiChannelGrabber.cpp | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 08ea0a94a..184077ba3 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -373,20 +373,23 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan m_params["defaultChannel"].setVal("Channel_0"); int roi[] = {0, 0, sizeX, sizeY}; m_params["roi"].setVal(roi, 4); + //add channels to map for (int i = 0; i < numChannel; ++i) { tempName = QString("Channel_%1").arg(i); m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"], m_params["roi"]); + if (sizeY == 1) + { + m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); + } + else + { + m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); + } + } - if (sizeY == 1) - { - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); - } - else - { - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); - } + } if (!retVal.containsError()) @@ -554,7 +557,8 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va { if (!hasIndex) { - retValue += it->copyValueFrom(&(*val)); + //retValue += it->copyValueFrom(&(*val)); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); /*m_params["sizex"].setVal(it->getVal()[2]); @@ -562,7 +566,8 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va } else { - it->getVal()[index] = val->getVal(); + //it->getVal()[index] = val->getVal(); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); /*m_params["sizex"].setVal(it->getVal()[2]); @@ -597,27 +602,27 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va int oldX = (oldval - oldY) / 100; float factorX = (float)oldX / (float)newX; float factorY = (float)oldY / (float)newY; - ChannelContainer iterParam; int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; - foreach(iterParam, m_data) + QMap::iterator i; + for(i=m_data.begin(); i != m_data.end(); ++i) { - width = m_params["sizex"].getVal() * factorX; - height = m_params["sizey"].getVal() * factorY; - - maxWidth = m_params["sizex"].getMax(); - maxHeight = m_params["sizey"].getMax(); - iterParam.m_channelParam["sizex"].setVal(width); - iterParam.m_channelParam["sizex"].setMeta(new ito::IntMeta(4 / newX, maxWidth * factorX, 4 / newX), true); - iterParam.m_channelParam["sizey"].setVal(height); - iterParam.m_channelParam["sizey"].setMeta(new ito::IntMeta(4 / newY, maxHeight * factorY, 4 / newY), true); - - int sizeX = m_params["roi"].getVal()[2] * factorX; - int sizeY = m_params["roi"].getVal()[3] * factorY; - int offsetX = m_params["roi"].getVal()[0] * factorX; - int offsetY = m_params["roi"].getVal()[1] * factorY; + width = i.value().m_channelParam["sizex"].getVal() * factorX; + height = i.value().m_channelParam["sizey"].getVal() * factorY; + + maxWidth = i.value().m_channelParam["sizex"].getMax(); + maxHeight = i.value().m_channelParam["sizey"].getMax(); + i.value().m_channelParam["sizex"].setVal(width); + i.value().m_channelParam["sizex"].setMeta(new ito::IntMeta(4 / newX, maxWidth * factorX, 4 / newX), true); + i.value().m_channelParam["sizey"].setVal(height); + i.value().m_channelParam["sizey"].setMeta(new ito::IntMeta(4 / newY, maxHeight * factorY, 4 / newY), true); + + int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; int roi[] = { offsetX, offsetY, sizeX, sizeY }; - iterParam.m_channelParam["roi"].setVal(roi, 4); - iterParam.m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); + i.value().m_channelParam["roi"].setVal(roi, 4); + i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); } } } @@ -1014,10 +1019,11 @@ void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) //---------------------------------------------------------------------------------------------------------------------------------- void DummyMultiChannelGrabber::syncMultiChannelParams() { - m_params["sizex"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].getVal()); - m_params["sizey"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].getVal()); - m_params["bpp"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["bpp"].getVal()); - m_params["roi"].setVal(m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].getVal()); - + //todo: check if meta is also copied or if it gets deleted + m_params["sizex"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"]; + m_params["sizey"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"]; + m_params["bpp"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["bpp"]; + m_params["roi"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"]; + } From 49e8f6bb0d70b1b2f994bd5c5ea6e7cd67391228 Mon Sep 17 00:00:00 2001 From: robin92 Date: Fri, 10 Jul 2020 13:48:32 +0200 Subject: [PATCH 04/43] DummyMultiChannelGrabber: added ROI as a channel specific parameter --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 184077ba3..605a54b8f 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -378,7 +378,8 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan for (int i = 0; i < numChannel; ++i) { tempName = QString("Channel_%1").arg(i); - m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"], m_params["roi"]); + m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"]); + m_data[tempName].m_channelParam.insert("roi", m_params["roi"]); if (sizeY == 1) { m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); From 797ec918c10a11aa979d257dbb7f4891b619bc4d Mon Sep 17 00:00:00 2001 From: robin92 Date: Wed, 23 Sep 2020 12:59:14 +0200 Subject: [PATCH 05/43] DummyMultichannelGrabber: bugfix --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 605a54b8f..44da01cfe 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -560,10 +560,8 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va { //retValue += it->copyValueFrom(&(*val)); m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); - /*m_params["sizex"].setVal(it->getVal()[2]); - m_params["sizey"].setVal(it->getVal()[3]);*/ + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(val->getVal()[2]); + m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(val->getVal()[3]); } else { From 097cf291822d63d745d9ece5b25b4c84b1426034 Mon Sep 17 00:00:00 2001 From: robin92 Date: Thu, 24 Sep 2020 11:25:26 +0200 Subject: [PATCH 06/43] DummyMultiChannelGrabber: started implementation of pixelFormat --- .../DummyMultiChannelGrabber.cpp | 30 +++++++++++++------ .../dialogDummyMultiChannelGrabber.cpp | 10 +++---- .../dockWidgetDummyMultiChannelGrabber.cpp | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 44da01cfe..1227af17d 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -167,8 +167,14 @@ This plugin can also be used as template for other grabber."); param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2), tr("Bits per Pixel, usually 8-16bit grayvalues").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + m->addItem("mono10"); + m->addItem("mono12"); + m->addItem("mono16"); + m->addItem("rgb32"); + param.setMeta(m, true); + m_initParamsOpt.append(param); param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); m_initParamsOpt.append(param); @@ -281,7 +287,13 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : paramVal.setMeta(rm, true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2, "ImageFormatControl"), tr("bitdepth of images").toLatin1().data()); + ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + m->addItem("mono10"); + m->addItem("mono12"); + m->addItem("mono16"); + m->addItem("rgb32"); + paramVal = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("bitdepth of images: mono8, mono10, mono12, mono16, rgb32").toLatin1().data()); + paramVal.setMeta(m, true); m_params.insert(paramVal.getName(), paramVal); paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); @@ -352,7 +364,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan else { int bpp = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel - m_params["bpp"].setVal(bpp); + m_params["pixelFormat"].setVal(bpp); m_params["sizex"].setVal(sizeX); m_params["sizex"].setMeta(new ito::IntMeta(4, sizeX, 4), true); @@ -378,7 +390,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan for (int i = 0; i < numChannel; ++i) { tempName = QString("Channel_%1").arg(i); - m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["bpp"]); + m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["pixelFormat"]); m_data[tempName].m_channelParam.insert("roi", m_params["roi"]); if (sizeY == 1) { @@ -538,7 +550,7 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va } } //first check parameters that influence the size or data type of m_data - if (key == "roi" || key == "binning" || key == "bpp") + if (key == "roi" || key == "binning" || key == "pixelFormat") { if (!retValue.containsError()) { @@ -550,7 +562,7 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va } } - if (key == "bpp") + if (key == "pixelFormat") { retValue += it->copyValueFrom(&(*val)); } @@ -741,7 +753,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS double frame_time = m_params["frame_time"].getVal(); double integration_time = m_params["integration_time"].getVal(); - int bpp = m_params["bpp"].getVal(); + int bpp = m_params["pixelFormat"].getVal(); float gain = m_params["gain"].getVal(); float offset = m_params["offset"].getVal(); @@ -1021,7 +1033,7 @@ void DummyMultiChannelGrabber::syncMultiChannelParams() //todo: check if meta is also copied or if it gets deleted m_params["sizex"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"]; m_params["sizey"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"]; - m_params["bpp"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["bpp"]; + m_params["pixelFormat"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["pixelFormat"]; m_params["roi"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"]; } diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp index 837011134..5cb55eac1 100644 --- a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp @@ -48,7 +48,7 @@ void DialogDummyMultiChannelGrabber::parametersChanged(QMap { setWindowTitle(QString((params)["name"].getVal()) + " - " + tr("Configuration Dialog")); - ito::IntMeta *bppMeta = static_cast(params["bpp"].getMeta()); + ito::IntMeta *bppMeta = static_cast(params["pixelFormat"].getMeta()); ui.combo_bpp->clear(); int count = 0; for (int i = bppMeta->getMin(); i <= bppMeta->getMax(); i += bppMeta->getStepSize()) @@ -96,11 +96,11 @@ void DialogDummyMultiChannelGrabber::parametersChanged(QMap ui.sliderOffset->setEnabled(!(params["offset"].getFlags() & ito::ParamBase::Readonly)); ui.spinBox_offset->setEnabled(!(params["gain"].getFlags() & ito::ParamBase::Readonly)); - ui.combo_bpp->setEnabled(!(params["bpp"].getFlags() & ito::ParamBase::Readonly)); + ui.combo_bpp->setEnabled(!(params["pixelFormat"].getFlags() & ito::ParamBase::Readonly)); for (int i = 0; i < ui.combo_bpp->count(); ++i) { - if (ui.combo_bpp->itemData(i, Qt::UserRole).toInt() == params["bpp"].getVal()) + if (ui.combo_bpp->itemData(i, Qt::UserRole).toInt() == params["pixelFormat"].getVal()) { ui.combo_bpp->setCurrentIndex(i); break; @@ -223,9 +223,9 @@ ito::RetVal DialogDummyMultiChannelGrabber::applyParameters() { int bpp = ui.combo_bpp->itemData(ui.combo_bpp->currentIndex()).toInt(); - if (m_currentParameters["bpp"].getVal() != bpp) + if (m_currentParameters["pixelFormat"].getVal() != bpp) { - values.append(QSharedPointer(new ito::ParamBase("bpp", ito::ParamBase::Int, bpp))); + values.append(QSharedPointer(new ito::ParamBase("pixelFormat", ito::ParamBase::Int, bpp))); } } diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp index bfd432ff0..fe59d6492 100644 --- a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp @@ -34,7 +34,7 @@ DockWidgetDummyMultiChannelGrabber::DockWidgetDummyMultiChannelGrabber(ito::AddI //---------------------------------------------------------------------------------------------------------------------------------- void DockWidgetDummyMultiChannelGrabber::parametersChanged(QMap params) { - ui.spinBpp->setValue(params["bpp"].getVal()); + ui.spinBpp->setValue(params["pixelFormat"].getVal()); ui.spinWidth->setValue(params["sizex"].getVal()); ui.spinHeight->setValue(params["sizey"].getVal()); From 5493022e72bd9ad86a4d5aa3b5f9729fae9956d3 Mon Sep 17 00:00:00 2001 From: robin92 Date: Wed, 30 Sep 2020 13:13:35 +0200 Subject: [PATCH 07/43] DummyMultiChannelGrabber: further work done --- .../DummyMultiChannelGrabber.cpp | 98 ++++++------------- 1 file changed, 29 insertions(+), 69 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 1227af17d..7fa24fc97 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -236,11 +236,7 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : { ito::DoubleMeta *dm; - ito::Param paramVal("name", ito::ParamBase::String | ito::ParamBase::Readonly, "DummyMultiChannelGrabber", "GrabberName"); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::String, "General"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); @@ -265,37 +261,11 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : dm->setCategory("AcquisitionControl"); dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("defaultChannel", ito::ParamBase::String, "", tr("indicates the current default channel").toLatin1().data()); - m_params.insert(paramVal.getName(), paramVal); paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, tr("size in x (cols) [px]").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, tr("size in y (rows) [px]").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - m_params.insert(paramVal.getName(), paramVal); - - int roi[] = {0, 0, 2048, 2048}; - paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); - ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); - paramVal.setMeta(rm, true); - m_params.insert(paramVal.getName(), paramVal); - - ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); - m->addItem("mono10"); - m->addItem("mono12"); - m->addItem("mono16"); - m->addItem("rgb32"); - paramVal = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("bitdepth of images: mono8, mono10, mono12, mono16, rgb32").toLatin1().data()); - paramVal.setMeta(m, true); - m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); m_params.insert(paramVal.getName(), paramVal); @@ -318,6 +288,8 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : m_params.insert(paramVal.getName(), paramVal); + + if (hasGuiSupport()) { //now create dock widget for this plugin @@ -351,7 +323,6 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) { ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retVal; int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width @@ -363,35 +334,31 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan } else { - int bpp = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel - m_params["pixelFormat"].setVal(bpp); + char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel + m_params["pixelFormat"].setVal(format); + + int roi[] = { 0, 0, sizeX, sizeY }; + m_params["roi"].setVal(roi, 4); + ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + m_params["roi"].setMeta(rm, true); + if (sizeY == 1) + { + m_lineCamera = true; + } + else + { + m_lineCamera = false; + } - m_params["sizex"].setVal(sizeX); - m_params["sizex"].setMeta(new ito::IntMeta(4, sizeX, 4), true); - - m_params["sizey"].setVal(sizeY); - if (sizeY == 1) - { - m_lineCamera = true; - m_params["sizey"].setMeta(new ito::IntMeta(1, 1, 1), true); - } - else - { - m_lineCamera = false; - m_params["sizey"].setMeta(new ito::IntMeta(4, sizeY, 4), true); - } QString tempName; m_params["defaultChannel"].setVal("Channel_0"); - int roi[] = {0, 0, sizeX, sizeY}; - m_params["roi"].setVal(roi, 4); //add channels to map for (int i = 0; i < numChannel; ++i) { tempName = QString("Channel_%1").arg(i); - m_data[tempName] = ChannelContainer(m_params["sizex"], m_params["sizey"], m_params["pixelFormat"]); - m_data[tempName].m_channelParam.insert("roi", m_params["roi"]); + addChannel(tempName); if (sizeY == 1) { m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); @@ -400,6 +367,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan { m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); } + updateRelatedBaseParams(); } @@ -407,7 +375,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan if (!retVal.containsError()) { - checkData(); //check if image must be reallocated + retVal += checkData(); //check if image must be reallocated emit parametersChanged(m_params); } @@ -572,15 +540,11 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va { //retValue += it->copyValueFrom(&(*val)); m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(val->getVal()[2]); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(val->getVal()[3]); } else { //it->getVal()[index] = val->getVal(); m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"].setVal(it->getVal()[2]); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"].setVal(it->getVal()[3]); /*m_params["sizex"].setVal(it->getVal()[2]); m_params["sizey"].setVal(it->getVal()[3]);*/ } @@ -615,17 +579,13 @@ ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer va float factorY = (float)oldY / (float)newY; int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; QMap::iterator i; - for(i=m_data.begin(); i != m_data.end(); ++i) - { - width = i.value().m_channelParam["sizex"].getVal() * factorX; - height = i.value().m_channelParam["sizey"].getVal() * factorY; - - maxWidth = i.value().m_channelParam["sizex"].getMax(); - maxHeight = i.value().m_channelParam["sizey"].getMax(); - i.value().m_channelParam["sizex"].setVal(width); - i.value().m_channelParam["sizex"].setMeta(new ito::IntMeta(4 / newX, maxWidth * factorX, 4 / newX), true); - i.value().m_channelParam["sizey"].setVal(height); - i.value().m_channelParam["sizey"].setMeta(new ito::IntMeta(4 / newY, maxHeight * factorY, 4 / newY), true); + for (i = m_data.begin(); i != m_data.end(); ++i) + { + width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; + height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; + + maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); + maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; @@ -753,7 +713,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS double frame_time = m_params["frame_time"].getVal(); double integration_time = m_params["integration_time"].getVal(); - int bpp = m_params["pixelFormat"].getVal(); + int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); float gain = m_params["gain"].getVal(); float offset = m_params["offset"].getVal(); From d4d23596d46f822f66770f428709ef3e6f010077 Mon Sep 17 00:00:00 2001 From: robin92 Date: Tue, 13 Oct 2020 19:04:02 +0200 Subject: [PATCH 08/43] DummyMultiChannelGrabber: any intermediate state --- .../DummyMultiChannelGrabber.cpp | 1365 ++++++++--------- .../DummyMultiChannelGrabber.h | 3 +- 2 files changed, 648 insertions(+), 720 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 7fa24fc97..5816e2c74 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -1,23 +1,23 @@ /* ******************************************************************** - Plugin "DummyMultiChannelGrabber" for itom software - URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2020, Institut fuer Technische Optik (ITO), - Universitaet Stuttgart, Germany - - This file is part of a plugin for the measurement software itom. - - This itom-plugin is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public Licence as published by - the Free Software Foundation; either version 2 of the Licence, or (at - your option) any later version. - - itom and its plugins are distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - General Public Licence for more details. - - You should have received a copy of the GNU Library General Public License - along with itom. If not, see . + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2020, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . *********************************************************************** */ #define ITOM_IMPORT_API @@ -29,7 +29,7 @@ #include "math.h" #ifndef WIN32 - #include +#include #endif #include #include @@ -58,7 +58,7 @@ */ template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) { - return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); + return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -69,65 +69,65 @@ template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offse */ template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) { - ito::uint32 val = 0; + ito::uint32 val = 0; - for (ito::uint8 i = 0; i < numMeans; ++i) - { - val += ((ito::uint32)rng.next()) & maxval; - } + for (ito::uint8 i = 0; i < numMeans; ++i) + { + val += ((ito::uint32)rng.next()) & maxval; + } - return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); + return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); } //---------------------------------------------------------------------------------------------------------------------------------- /*! - \class DummyMultiChannelGrabberInterface - \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to - create one or more new instances of DummyMultiChannelGrabber. + \class DummyMultiChannelGrabberInterface + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to + create one or more new instances of DummyMultiChannelGrabber. */ //---------------------------------------------------------------------------------------------------------------------------------- //! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. /*! - \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst - \return retOk - \sa DummyMultiChannelGrabber + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst + \return retOk + \sa DummyMultiChannelGrabber */ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **addInInst) { - NEW_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + NEW_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. /*! - \param [in] double pointer to the instance which should be deleted. - \return retOk - \sa DummyMultiChannelGrabber + \param [in] double pointer to the instance which should be deleted. + \return retOk + \sa DummyMultiChannelGrabber */ ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **addInInst) { - REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for interace /*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must - be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand - and m_initParamsOpt within this constructor. + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must + be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand + and m_initParamsOpt within this constructor. */ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() { - m_autoLoadPolicy = ito::autoLoadKeywordDefined; - m_autoSavePolicy = ito::autoSaveAlways; + m_autoLoadPolicy = ito::autoLoadKeywordDefined; + m_autoSavePolicy = ito::autoSaveAlways; - m_type = ito::typeDataIO | ito::typeGrabber; - setObjectName("DummyMultiChannelGrabber"); + m_type = ito::typeDataIO | ito::typeGrabber; + setObjectName("DummyMultiChannelGrabber"); - //for the docstring, please don't set any spaces at the beginning of the line. + //for the docstring, please don't set any spaces at the beginning of the line. /* char docstring[] = \ "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ @@ -138,11 +138,11 @@ image is controlled using the parameter 'roi' if the sizes stay within the limit You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ \n\ This plugin can also be used as template for other grabber.";*/ - - m_description = QObject::tr("A virtual white noise grabber"); -// m_detaildescription = QObject::tr(docstring); - m_detaildescription = QObject::tr( -"The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + + m_description = QObject::tr("A virtual white noise grabber"); + // m_detaildescription = QObject::tr(docstring); + m_detaildescription = QObject::tr( + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ @@ -152,22 +152,22 @@ You can initialize this camera either as a 2D sensor with a width and height >= \n\ This plugin can also be used as template for other grabber."); - m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; - m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; - m_minItomVer = CREATEVERSION(1,4,0); - m_maxItomVer = MAXVERSION; - m_license = QObject::tr("Licensed under LPGL."); - m_aboutThis = tr(GITVERSION); - - m_initParamsMand.clear(); + m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; + m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; + m_minItomVer = CREATEVERSION(1, 4, 0); + m_maxItomVer = MAXVERSION; + m_license = QObject::tr("Licensed under LPGL."); + m_aboutThis = tr(GITVERSION); - ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); - m_initParamsOpt.append(param); + m_initParamsMand.clear(); + + ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); + m_initParamsOpt.append(param); - param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); + m_initParamsOpt.append(param); - param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); m->addItem("mono10"); m->addItem("mono12"); @@ -176,19 +176,19 @@ This plugin can also be used as template for other grabber."); param.setMeta(m, true); m_initParamsOpt.append(param); - param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); + m_initParamsOpt.append(param); } //---------------------------------------------------------------------------------------------------------------------------------- //! destructor /*! - clears both vectors m_initParamsMand and m_initParamsOpt. + clears both vectors m_initParamsMand and m_initParamsOpt. */ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() { - m_initParamsMand.clear(); - m_initParamsOpt.clear(); + m_initParamsMand.clear(); + m_initParamsOpt.clear(); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -198,112 +198,112 @@ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() //---------------------------------------------------------------------------------------------------------------------------------- /*! - \class DummyMultiChannelGrabber - \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. + \class DummyMultiChannelGrabber + \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. - Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the - main (GUI) thread. + Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the + main (GUI) thread. */ //---------------------------------------------------------------------------------------------------------------------------------- //! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the addIn-Manager. /*! - creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog - is closed, reads the new parameter set and deletes the dialog. + creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog + is closed, reads the new parameter set and deletes the dialog. - \return retOk - \sa dialogDummyMultiChannelGrabber + \return retOk + \sa dialogDummyMultiChannelGrabber */ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) { - return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); + return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); } //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for DummyMultiChannelGrabber /*! - In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. - Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. + In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. + Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. - \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance - \sa ito::tParam, createDockWidget, setParam, getParam + \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance + \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber(), - m_isgrabbing(false), - m_totalBinning(1), - m_lineCamera(false) + AddInMultiChannelGrabber(), + m_isgrabbing(false), + m_totalBinning(1), + m_lineCamera(false) { - ito::DoubleMeta *dm; - - ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); - sm->addItem("mode 2"); - sm->addItem("mode 3"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String); - sm->setCategory("DemoParameters"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - - - - if (hasGuiSupport()) - { - //now create dock widget for this plugin - DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); - Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); - } + ito::DoubleMeta *dm; + + ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm->addItem("mode 2"); + sm->addItem("mode 3"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String); + sm->setCategory("DemoParameters"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + + + + if (hasGuiSupport()) + { + //now create dock widget for this plugin + DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); + Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + } } //---------------------------------------------------------------------------------------------------------------------------------- //! destructor /*! - \sa ~AddInBase + \sa ~AddInBase */ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() { @@ -312,30 +312,30 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() //---------------------------------------------------------------------------------------------------------------------------------- //! init method which is called by the addInManager after the initiation of a new instance of DummyMultiChannelGrabber. /*! - This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the - internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. + This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the + internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. - \param [in] paramsMand is a pointer to the vector of mandatory tParams. - \param [in] paramsOpt is a pointer to the vector of optional tParams. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk + \param [in] paramsMand is a pointer to the vector of mandatory tParams. + \param [in] paramsOpt is a pointer to the vector of optional tParams. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk */ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retVal; - - int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels - if (sizeY > 1 && sizeY % 4 != 0) - { - retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); - } - else - { - char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel - m_params["pixelFormat"].setVal(format); + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retVal; + + int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth + int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels + if (sizeY > 1 && sizeY % 4 != 0) + { + retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); + } + else + { + char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel + m_params["pixelFormat"].setVal(format); int roi[] = { 0, 0, sizeX, sizeY }; m_params["roi"].setVal(roi, 4); @@ -350,651 +350,580 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan m_lineCamera = false; } - QString tempName; + QString tempName; - m_params["defaultChannel"].setVal("Channel_0"); + m_params["defaultChannel"].setVal("Channel_0"); - //add channels to map - for (int i = 0; i < numChannel; ++i) - { - tempName = QString("Channel_%1").arg(i); + //add channels to map + for (int i = 0; i < numChannel; ++i) + { + tempName = QString("Channel_%1").arg(i); addChannel(tempName); - if (sizeY == 1) - { - m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); - } - else - { - m_data[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); - } - updateRelatedBaseParams(); + if (sizeY == 1) + { + m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); + } + else + { + m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); + } - } + } - } + } - if (!retVal.containsError()) - { - retVal += checkData(); //check if image must be reallocated + if (!retVal.containsError()) + { + retVal += checkData(); //check if image must be reallocated - emit parametersChanged(m_params); - } + emit parametersChanged(m_params); + } - setIdentifier(QString::number(getID())); + setIdentifier(QString::number(getID())); - if (waitCond) - { - waitCond->returnValue = retVal; - waitCond->release(); - } + if (waitCond) + { + waitCond->returnValue = retVal; + waitCond->release(); + } - setInitialized(true); //init method has been finished (independent on retval) - return retVal; + setInitialized(true); //init method has been finished (independent on retval) + return retVal; } //---------------------------------------------------------------------------------------------------------------------------------- //! close method which is called before that this instance is deleted by the DummyMultiChannelGrabberInterface /*! - notice that this method is called in the actual thread of this instance. + notice that this method is called in the actual thread of this instance. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk - \sa ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk + \sa ItomSharedSemaphore */ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - - if (m_timerID > 0) - { - killTimer(m_timerID); - m_timerID = 0; - } - - if (waitCond) - { - waitCond->returnValue = ito::retOk; - waitCond->release(); - - return waitCond->returnValue; - } - else - { - return ito::retOk; - } + ItomSharedSemaphoreLocker locker(waitCond); + + if (m_timerID > 0) + { + killTimer(m_timerID); + m_timerID = 0; + } + + if (waitCond) + { + waitCond->returnValue = ito::retOk; + waitCond->release(); + + return waitCond->returnValue; + } + else + { + return ito::retOk; + } } //---------------------------------------------------------------------------------------------------------------------------------- //! returns parameter of m_params with key name. /*! - This method copies val of the corresponding parameter value. + This method copies val of the corresponding parameter value. - \param [in,out] val is a shared-pointer of ito::Param. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in,out] val is a shared-pointer of ito::Param. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore */ ito::RetVal DummyMultiChannelGrabber::getParam(QSharedPointer val, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue; - QString key; - bool hasIndex = false; - int index; - QString suffix; - ParamMapIterator it; - - //parse the given parameter-name (if you support indexed or suffix-based parameters) - retValue += apiParseParamName(val->getName(), key, hasIndex, index, suffix); - - if (retValue == ito::retOk) - { - //gets the parameter key from m_params map (read-only is allowed, since we only want to get the value). - retValue += apiGetParamFromMapByKey(m_params, key, it, false); - } - - if (!retValue.containsError()) - { - *val = it.value(); - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue; + QString key; + bool hasIndex = false; + int index; + QString suffix; + ParamMapIterator it; + + //parse the given parameter-name (if you support indexed or suffix-based parameters) + retValue += apiParseParamName(val->getName(), key, hasIndex, index, suffix); + + if (retValue == ito::retOk) + { + //gets the parameter key from m_params map (read-only is allowed, since we only want to get the value). + retValue += apiGetParamFromMapByKey(m_params, key, it, false); + } + + if (!retValue.containsError()) + { + *val = it.value(); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! sets parameter of m_params with key name. /*! - This method copies the given value to the m_params-parameter. + This method copies the given value to the m_params-parameter. - \param [in] val is the ito::ParamBase value to set. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] val is the ito::ParamBase value to set. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::setParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue; - QString key; - int running = 0; // Used to check if grabber was running bevor - - bool hasIndex; - int index; - QString suffix; - ParamMapIterator it; - - retValue += ito::parseParamName(val->getName(), key, hasIndex, index, suffix); - - if (!retValue.containsError()) - { - //gets the parameter key from m_params map (read-only is not allowed and leads to ito::retError). - retValue += apiGetParamFromMapByKey(m_params, key, it, true); - } - - if (!retValue.containsError()) - { - retValue += apiValidateParam(*it, *val, false, true); - } - - if (!retValue.containsError()) - { - if (key == "defaultChannel") - { - retValue += it->copyValueFrom(&(*val)); - if (m_data.find(it->getVal()) != m_data.end()) - { - m_params["defaultChannel"].setVal(it->getVal()); - syncMultiChannelParams(); - } - else - { - retValue += ito::RetVal(ito::retError, 0, tr("Unknown channel: %1").arg(it->getVal()).toLatin1().data()); - } - } - //first check parameters that influence the size or data type of m_data - if (key == "roi" || key == "binning" || key == "pixelFormat") - { - if (!retValue.containsError()) - { - if (grabberStartedCount() > 0) - { - running = grabberStartedCount(); - setGrabberStarted(1); - retValue += stopDevice(NULL); - } - } - - if (key == "pixelFormat") - { - retValue += it->copyValueFrom(&(*val)); - } - else if (key == "roi") - { - if (!hasIndex) - { - //retValue += it->copyValueFrom(&(*val)); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); - } - else - { - //it->getVal()[index] = val->getVal(); - m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"].setVal(val->getVal(),4); - /*m_params["sizex"].setVal(it->getVal()[2]); - m_params["sizey"].setVal(it->getVal()[3]);*/ - } - } - else if (key == "binning") - { - int oldval = it->getVal(); - - int ival = val->getVal(); - int newY = ival % 100; - int newX = (ival - newY) / 100; - - if (m_lineCamera && (newY != 1)) - { - retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); - } - else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) - { - retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); - } - else - { - m_totalBinning = newX * newY; - - retValue += it->copyValueFrom(&(*val)); - - if (oldval != ival) - { - int oldY = oldval % 100; - int oldX = (oldval - oldY) / 100; - float factorX = (float)oldX / (float)newX; - float factorY = (float)oldY / (float)newY; - int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; - QMap::iterator i; - for (i = m_data.begin(); i != m_data.end(); ++i) - { - width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; - height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; - - maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); - maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); - - int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; - int roi[] = { offsetX, offsetY, sizeX, sizeY }; - i.value().m_channelParam["roi"].setVal(roi, 4); - i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); - } - } - } - } - syncMultiChannelParams(); - retValue += checkData(); //check if image must be reallocated - - if (running) - { - retValue += startDevice(NULL); - setGrabberStarted(running); - } - } - else - { - retValue += it->copyValueFrom(&(*val)); - } - } - - if (!retValue.containsError()) - { - emit parametersChanged(m_params); - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ito::RetVal retValue; + int running = 0; // Used to check if grabber was running bevor + + //first check parameters that influence the size or data type of m_channels + if (key == "binning") + { + if (!retValue.containsError()) + { + if (grabberStartedCount() > 0) + { + running = grabberStartedCount(); + setGrabberStarted(1); + retValue += stopDevice(NULL); + } + } + else + { + int oldval = it->getVal(); + + int ival = val->getVal(); + int newY = ival % 100; + int newX = (ival - newY) / 100; + + if (m_lineCamera && (newY != 1)) + { + retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); + } + else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) + { + retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); + } + else + { + m_totalBinning = newX * newY; + + retValue += it->copyValueFrom(&(*val)); + + if (oldval != ival) + { + int oldY = oldval % 100; + int oldX = (oldval - oldY) / 100; + float factorX = (float)oldX / (float)newX; + float factorY = (float)oldY / (float)newY; + int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; + QMap::iterator i; + for (i = m_channels.begin(); i != m_channels.end(); ++i) + { + width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; + height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; + + maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); + maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); + + int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + int roi[] = { offsetX, offsetY, sizeX, sizeY }; + i.value().m_channelParam["roi"].setVal(roi, 4); + i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); + } + } + } + pendingUpdate << "binning" << "roi"; + } + retValue += checkData(); //check if image must be reallocated + + if (running) + { + retValue += startDevice(NULL); + setGrabberStarted(running); + } + ok = true; + } + else + { + ok = false; // set ok to false to let setParam process the parameter + } + + + if (!retValue.containsError()) + { + emit parametersChanged(m_params); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! With startDevice this camera is initialized. /*! - In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. + In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. - \note This method is similar to VideoCapture::open() of openCV + \note This method is similar to VideoCapture::open() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. */ ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; - checkData(); //this will be reallocated in this method. + checkData(); //this will be reallocated in this method. - incGrabberStarted(); + incGrabberStarted(); - if (grabberStartedCount() == 1) - { - m_startOfLastAcquisition = 0; - m_isgrabbing = false; - } + if (grabberStartedCount() == 1) + { + m_startOfLastAcquisition = 0; + m_isgrabbing = false; + } - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } - return retValue; + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! With stopDevice the camera device is stopped (opposite to startDevice) /*! - In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this method. + In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this method. - \note This method is similar to VideoCapture::release() of openCV + \note This method is similar to VideoCapture::release() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera wasn't started before - \sa startDevice + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera wasn't started before + \sa startDevice */ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; - - decGrabberStarted(); - if (grabberStartedCount() < 0) - { - retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); - setGrabberStarted(0); - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + decGrabberStarted(); + if (grabberStartedCount() < 0) + { + retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + setGrabberStarted(0); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Call this method to trigger a new image. /*! - By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. - The new image is then stored either in internal camera memory or in internal memory of this class. + By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. + The new image is then stored either in internal camera memory or in internal memory of this class. - \note This method is similar to VideoCapture::grab() of openCV + \note This method is similar to VideoCapture::grab() of openCV - \param [in] trigger may describe the trigger parameter (unused here) - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. - \sa getVal + \param [in] trigger may describe the trigger parameter (unused here) + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. + \sa getVal */ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; - - double frame_time = m_params["frame_time"].getVal(); - double integration_time = m_params["integration_time"].getVal(); - int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); - float gain = m_params["gain"].getVal(); - float offset = m_params["offset"].getVal(); - - - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - if (bpp < 8 || bpp >= 32) - { - retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); - } - else if (grabberStartedCount() <= 0) - { - retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); - } - else - { - m_isgrabbing = true; - - if (frame_time > 0.0) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < frame_time) - { - Sleep((frame_time - diff) * 1000.0); - } - } - - m_startOfLastAcquisition = cv::getTickCount(); - //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); - cv::RNG &rng = cv::theRNG(); - - if (m_totalBinning == 1) - { - if (bpp < 9) - { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint8 *linePtr; - char* a = m_params["defaultChannel"].getVal(); - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - else if (bpp < 17) - { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint16 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::int32 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - } - else - { - if (bpp < 9) - { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint8 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - else if (bpp < 17) - { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint16 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt,m_totalBinning, offset, gain); - } - } - } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::int32 *linePtr; - ito::DataObject &channelObj = m_data[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - } - - if (integration_time > 0.0) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < integration_time) - { - Sleep((integration_time - diff) * 1000.0); - } - } - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + double frame_time = m_params["frame_time"].getVal(); + double integration_time = m_params["integration_time"].getVal(); + int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); + float gain = m_params["gain"].getVal(); + float offset = m_params["offset"].getVal(); + + + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + if (bpp < 8 || bpp >= 32) + { + retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); + } + else if (grabberStartedCount() <= 0) + { + retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + } + else + { + m_isgrabbing = true; + + if (frame_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < frame_time) + { + Sleep((frame_time - diff) * 1000.0); + } + } + + m_startOfLastAcquisition = cv::getTickCount(); + //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); + cv::RNG &rng = cv::theRNG(); + + if (m_totalBinning == 1) + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8 *linePtr; + char* a = m_params["defaultChannel"].getVal(); + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 *linePtr; + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32 *linePtr; + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + else + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8 *linePtr; + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 *linePtr; + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32 *linePtr; + ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + + if (integration_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < integration_time) + { + Sleep((integration_time - diff) * 1000.0); + } + } + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a shallow copy. /*! - This method copies the recently grabbed camera frame to the given DataObject-handle + This method copies the recently grabbed camera frame to the given DataObject-handle - \note This method is similar to VideoCapture::retrieve() of openCV + \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::DataObject *dObj = reinterpret_cast(vpdObj); - - ito::RetVal retValue(ito::retOk); - - retValue += retrieveData(); - - if (!retValue.containsError()) - { - if (dObj == NULL) - { - retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); - } - else - { - retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. - - (*dObj) = this->m_data[m_params["defaultChannel"].getVal()].data; - } - } - - if (waitCond) - { - waitCond->returnValue=retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + ito::RetVal retValue(ito::retOk); + + retValue += retrieveData(); + + if (!retValue.containsError()) + { + if (dObj == NULL) + { + retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + } + else + { + retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + + (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; + } + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! - This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the - DataObject. + This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the + DataObject. - \note This method is similar to VideoCapture::retrieve() of openCV + \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue(ito::retOk); - ito::DataObject *dObj = reinterpret_cast(vpdObj); - - if (!dObj) - { - retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); - } - else - { - retValue += checkData(dObj); - } - - if (!retValue.containsError()) - { - retValue += retrieveData(dObj); - } - - if (!retValue.containsError()) - { - sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue(ito::retOk); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + if (!dObj) + { + retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + } + else + { + retValue += checkData(dObj); + } + + if (!retValue.containsError()) + { + retValue += retrieveData(dObj); + } + + if (!retValue.containsError()) + { + sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalDataObject) { - ito::RetVal retValue(ito::retOk); - - if (m_isgrabbing == false) - { - retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); - } - else - { - if (externalDataObject) - { - m_data[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); - } - - m_isgrabbing = false; - } - - return retValue; + ito::RetVal retValue(ito::retOk); + + if (m_isgrabbing == false) + { + retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + } + else + { + if (externalDataObject) + { + m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + } + + m_isgrabbing = false; + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) { - if (getDockWidget()) - { - QWidget *widget = getDockWidget()->widget(); - if (visible) - { - connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); - emit parametersChanged(m_params); - } - else - { - disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); - } - } -} -//---------------------------------------------------------------------------------------------------------------------------------- -void DummyMultiChannelGrabber::syncMultiChannelParams() -{ - //todo: check if meta is also copied or if it gets deleted - m_params["sizex"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizex"]; - m_params["sizey"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["sizey"]; - m_params["pixelFormat"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["pixelFormat"]; - m_params["roi"] = m_data[m_params["defaultChannel"].getVal()].m_channelParam["roi"]; - + if (getDockWidget()) + { + QWidget *widget = getDockWidget()->widget(); + if (visible) + { + connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + emit parametersChanged(m_params); + } + else + { + disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + } + } } diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index d0e1438d6..6017e665b 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -74,7 +74,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber public slots: ito::RetVal getParam(QSharedPointer val, ItomSharedSemaphore *waitCond = NULL); - ito::RetVal setParam(QSharedPointer val, ItomSharedSemaphore *waitCond = NULL); + ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate); ito::RetVal init(QVector *paramsMand, QVector *paramsOpt, ItomSharedSemaphore *waitCond = NULL); ito::RetVal close(ItomSharedSemaphore *waitCond); @@ -87,7 +87,6 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber private slots: void dockWidgetVisibilityChanged(bool visible); - void syncMultiChannelParams(); }; From 03398b72c7b9a729abfeda31953b70c92b64b229 Mon Sep 17 00:00:00 2001 From: robin92 Date: Thu, 18 Feb 2021 19:20:37 +0100 Subject: [PATCH 09/43] DummyMultiChannelGrabber: small changes --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 5816e2c74..52a378667 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -552,6 +552,11 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer Date: Fri, 19 Feb 2021 15:27:56 +0100 Subject: [PATCH 10/43] DummyMultiChannelGrabber: implemeted getParameter which replaces getParam. getParam is moved to AddInMultiChannelGrabber. --- .../DummyMultiChannelGrabber.cpp | 35 +++---------------- .../DummyMultiChannelGrabber.h | 2 +- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 52a378667..f118c19bf 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -433,39 +433,12 @@ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) \return retOk in case that everything is ok, else retError \sa ito::tParam, ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::getParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue; - QString key; - bool hasIndex = false; - int index; - QString suffix; - ParamMapIterator it; - - //parse the given parameter-name (if you support indexed or suffix-based parameters) - retValue += apiParseParamName(val->getName(), key, hasIndex, index, suffix); - - if (retValue == ito::retOk) - { - //gets the parameter key from m_params map (read-only is allowed, since we only want to get the value). - retValue += apiGetParamFromMapByKey(m_params, key, it, false); - } - - if (!retValue.containsError()) - { - *val = it.value(); - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + return ito::retOk; } + //---------------------------------------------------------------------------------------------------------------------------------- //! sets parameter of m_params with key name. /*! @@ -493,7 +466,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointergetVal(); diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 6017e665b..47c6a7e69 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -73,7 +73,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber signals: public slots: - ito::RetVal getParam(QSharedPointer val, ItomSharedSemaphore *waitCond = NULL); + ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok); ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate); ito::RetVal init(QVector *paramsMand, QVector *paramsOpt, ItomSharedSemaphore *waitCond = NULL); From 6d3b68de9c7ec6dbea61fcec13e08063db4ff6c5 Mon Sep 17 00:00:00 2001 From: robin92 Date: Fri, 19 Feb 2021 17:36:51 +0100 Subject: [PATCH 11/43] DummyMultiChannelGrabber: added a channel-specific parameter for a channel for testing purposes --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index f118c19bf..785c249bc 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -287,7 +287,9 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : paramVal.setMeta(sm, true); m_params.insert(paramVal.getName(), paramVal); - + paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); + paramVal.getMetaT()->setCategory("DemoParameters"); + m_params.insert(paramVal.getName(), paramVal); if (hasGuiSupport()) @@ -359,6 +361,10 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan { tempName = QString("Channel_%1").arg(i); addChannel(tempName); + if (i == 0) + { + m_channels[tempName].m_channelParam.insert("channelSpecificParameter", m_params["channelSpecificParameter"]); //this is a parameter only for channel_0 + } if (sizeY == 1) { m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); From 58fef3c5725843b108c71e97ed5a0862b8e2affa Mon Sep 17 00:00:00 2001 From: robin92 Date: Mon, 10 May 2021 21:16:48 +0200 Subject: [PATCH 12/43] added DummyMultiChannelGrabber/translation/DummyMultiChannelGrabber_de.ts --- .../translation/DummyMultiChannelGrabber_de.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 DummyMultiChannelGrabber/translation/DummyMultiChannelGrabber_de.ts diff --git a/DummyMultiChannelGrabber/translation/DummyMultiChannelGrabber_de.ts b/DummyMultiChannelGrabber/translation/DummyMultiChannelGrabber_de.ts new file mode 100644 index 000000000..3c69befd3 --- /dev/null +++ b/DummyMultiChannelGrabber/translation/DummyMultiChannelGrabber_de.ts @@ -0,0 +1,4 @@ + + + + From 4bbee51bc58b3cf442c7e275b0fb9e25a83094e5 Mon Sep 17 00:00:00 2001 From: robin92 Date: Tue, 8 Jun 2021 16:26:24 +0200 Subject: [PATCH 13/43] capture images for all channels regardless of the defaultChannel --- .../DummyMultiChannelGrabber.cpp | 1323 +++++++++-------- 1 file changed, 670 insertions(+), 653 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 785c249bc..38cabbcd3 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -1,23 +1,23 @@ /* ******************************************************************** - Plugin "DummyMultiChannelGrabber" for itom software - URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2020, Institut fuer Technische Optik (ITO), - Universitaet Stuttgart, Germany + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2020, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany - This file is part of a plugin for the measurement software itom. + This file is part of a plugin for the measurement software itom. - This itom-plugin is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public Licence as published by - the Free Software Foundation; either version 2 of the Licence, or (at - your option) any later version. + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. - itom and its plugins are distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library - General Public Licence for more details. + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. - You should have received a copy of the GNU Library General Public License - along with itom. If not, see . + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . *********************************************************************** */ #define ITOM_IMPORT_API @@ -58,7 +58,7 @@ */ template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) { - return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); + return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -69,65 +69,65 @@ template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offse */ template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) { - ito::uint32 val = 0; + ito::uint32 val = 0; - for (ito::uint8 i = 0; i < numMeans; ++i) - { - val += ((ito::uint32)rng.next()) & maxval; - } + for (ito::uint8 i = 0; i < numMeans; ++i) + { + val += ((ito::uint32)rng.next()) & maxval; + } - return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); + return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); } //---------------------------------------------------------------------------------------------------------------------------------- /*! - \class DummyMultiChannelGrabberInterface - \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to - create one or more new instances of DummyMultiChannelGrabber. + \class DummyMultiChannelGrabberInterface + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to + create one or more new instances of DummyMultiChannelGrabber. */ //---------------------------------------------------------------------------------------------------------------------------------- //! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. /*! - \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst - \return retOk - \sa DummyMultiChannelGrabber + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst + \return retOk + \sa DummyMultiChannelGrabber */ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **addInInst) { - NEW_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + NEW_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. /*! - \param [in] double pointer to the instance which should be deleted. - \return retOk - \sa DummyMultiChannelGrabber + \param [in] double pointer to the instance which should be deleted. + \return retOk + \sa DummyMultiChannelGrabber */ ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **addInInst) { - REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for interace /*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must - be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand - and m_initParamsOpt within this constructor. + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must + be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand + and m_initParamsOpt within this constructor. */ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() { - m_autoLoadPolicy = ito::autoLoadKeywordDefined; - m_autoSavePolicy = ito::autoSaveAlways; + m_autoLoadPolicy = ito::autoLoadKeywordDefined; + m_autoSavePolicy = ito::autoSaveAlways; - m_type = ito::typeDataIO | ito::typeGrabber; - setObjectName("DummyMultiChannelGrabber"); + m_type = ito::typeDataIO | ito::typeGrabber; + setObjectName("DummyMultiChannelGrabber"); - //for the docstring, please don't set any spaces at the beginning of the line. + //for the docstring, please don't set any spaces at the beginning of the line. /* char docstring[] = \ "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ @@ -139,10 +139,10 @@ You can initialize this camera either as a 2D sensor with a width and height >= \n\ This plugin can also be used as template for other grabber.";*/ - m_description = QObject::tr("A virtual white noise grabber"); - // m_detaildescription = QObject::tr(docstring); - m_detaildescription = QObject::tr( - "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + m_description = QObject::tr("A virtual white noise grabber"); + // m_detaildescription = QObject::tr(docstring); + m_detaildescription = QObject::tr( + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ @@ -152,43 +152,43 @@ You can initialize this camera either as a 2D sensor with a width and height >= \n\ This plugin can also be used as template for other grabber."); - m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; - m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; - m_minItomVer = CREATEVERSION(1, 4, 0); - m_maxItomVer = MAXVERSION; - m_license = QObject::tr("Licensed under LPGL."); - m_aboutThis = tr(GITVERSION); + m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; + m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; + m_minItomVer = CREATEVERSION(1, 4, 0); + m_maxItomVer = MAXVERSION; + m_license = QObject::tr("Licensed under LPGL."); + m_aboutThis = tr(GITVERSION); - m_initParamsMand.clear(); + m_initParamsMand.clear(); - ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); - m_initParamsOpt.append(param); + ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); + m_initParamsOpt.append(param); - param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); + m_initParamsOpt.append(param); - param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); - ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); - m->addItem("mono10"); - m->addItem("mono12"); - m->addItem("mono16"); - m->addItem("rgb32"); - param.setMeta(m, true); - m_initParamsOpt.append(param); + param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + m->addItem("mono10"); + m->addItem("mono12"); + m->addItem("mono16"); + m->addItem("rgb32"); + param.setMeta(m, true); + m_initParamsOpt.append(param); - param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); - m_initParamsOpt.append(param); + param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); + m_initParamsOpt.append(param); } //---------------------------------------------------------------------------------------------------------------------------------- //! destructor /*! - clears both vectors m_initParamsMand and m_initParamsOpt. + clears both vectors m_initParamsMand and m_initParamsOpt. */ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() { - m_initParamsMand.clear(); - m_initParamsOpt.clear(); + m_initParamsMand.clear(); + m_initParamsOpt.clear(); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -198,114 +198,114 @@ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() //---------------------------------------------------------------------------------------------------------------------------------- /*! - \class DummyMultiChannelGrabber - \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. + \class DummyMultiChannelGrabber + \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. - Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the - main (GUI) thread. + Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the + main (GUI) thread. */ //---------------------------------------------------------------------------------------------------------------------------------- //! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the addIn-Manager. /*! - creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog - is closed, reads the new parameter set and deletes the dialog. + creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog + is closed, reads the new parameter set and deletes the dialog. - \return retOk - \sa dialogDummyMultiChannelGrabber + \return retOk + \sa dialogDummyMultiChannelGrabber */ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) { - return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); + return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); } //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for DummyMultiChannelGrabber /*! - In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. - Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. + In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. + Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. - \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance - \sa ito::tParam, createDockWidget, setParam, getParam + \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance + \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber(), - m_isgrabbing(false), - m_totalBinning(1), - m_lineCamera(false) + AddInMultiChannelGrabber(), + m_isgrabbing(false), + m_totalBinning(1), + m_lineCamera(false) { - ito::DoubleMeta *dm; - - ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); - sm->addItem("mode 2"); - sm->addItem("mode 3"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String); - sm->setCategory("DemoParameters"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); - paramVal.getMetaT()->setCategory("DemoParameters"); - m_params.insert(paramVal.getName(), paramVal); - - - if (hasGuiSupport()) - { - //now create dock widget for this plugin - DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); - Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); - } + ito::DoubleMeta *dm; + + ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm->addItem("mode 2"); + sm->addItem("mode 3"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String); + sm->setCategory("DemoParameters"); + paramVal.setMeta(sm, true); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); + paramVal.getMetaT()->setCategory("DemoParameters"); + m_params.insert(paramVal.getName(), paramVal); + + + if (hasGuiSupport()) + { + //now create dock widget for this plugin + DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); + Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + } } //---------------------------------------------------------------------------------------------------------------------------------- //! destructor /*! - \sa ~AddInBase + \sa ~AddInBase */ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() { @@ -314,600 +314,617 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() //---------------------------------------------------------------------------------------------------------------------------------- //! init method which is called by the addInManager after the initiation of a new instance of DummyMultiChannelGrabber. /*! - This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the - internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. + This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the + internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. - \param [in] paramsMand is a pointer to the vector of mandatory tParams. - \param [in] paramsOpt is a pointer to the vector of optional tParams. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk + \param [in] paramsMand is a pointer to the vector of mandatory tParams. + \param [in] paramsOpt is a pointer to the vector of optional tParams. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk */ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retVal; - - int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels - if (sizeY > 1 && sizeY % 4 != 0) - { - retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); - } - else - { - char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel - m_params["pixelFormat"].setVal(format); - - int roi[] = { 0, 0, sizeX, sizeY }; - m_params["roi"].setVal(roi, 4); - ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); - m_params["roi"].setMeta(rm, true); - if (sizeY == 1) - { - m_lineCamera = true; - } - else - { - m_lineCamera = false; - } - - QString tempName; - - m_params["defaultChannel"].setVal("Channel_0"); - - //add channels to map - for (int i = 0; i < numChannel; ++i) - { - tempName = QString("Channel_%1").arg(i); - addChannel(tempName); - if (i == 0) - { - m_channels[tempName].m_channelParam.insert("channelSpecificParameter", m_params["channelSpecificParameter"]); //this is a parameter only for channel_0 - } - if (sizeY == 1) - { - m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); - } - else - { - m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); - } - - } - - } - - if (!retVal.containsError()) - { - retVal += checkData(); //check if image must be reallocated - - emit parametersChanged(m_params); - } - - setIdentifier(QString::number(getID())); - - if (waitCond) - { - waitCond->returnValue = retVal; - waitCond->release(); - } - - setInitialized(true); //init method has been finished (independent on retval) - return retVal; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retVal; + + int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth + int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels + if (sizeY > 1 && sizeY % 4 != 0) + { + retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); + } + else + { + char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel + m_params["pixelFormat"].setVal(format); + + int roi[] = { 0, 0, sizeX, sizeY }; + m_params["roi"].setVal(roi, 4); + ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + m_params["roi"].setMeta(rm, true); + if (sizeY == 1) + { + m_lineCamera = true; + } + else + { + m_lineCamera = false; + } + + QString tempName; + + m_params["defaultChannel"].setVal("Channel_0"); + + //add channels to map + for (int i = 0; i < numChannel; ++i) + { + tempName = QString("Channel_%1").arg(i); + addChannel(tempName); + if (i == 0) + { + m_channels[tempName].m_channelParam.insert("channelSpecificParameter", m_params["channelSpecificParameter"]); //this is a parameter only for channel_0 + } + if (sizeY == 1) + { + m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); + } + else + { + m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); + } + + } + + } + + if (!retVal.containsError()) + { + retVal += checkData(); //check if image must be reallocated + + emit parametersChanged(m_params); + } + + setIdentifier(QString::number(getID())); + + if (waitCond) + { + waitCond->returnValue = retVal; + waitCond->release(); + } + + setInitialized(true); //init method has been finished (independent on retval) + return retVal; } //---------------------------------------------------------------------------------------------------------------------------------- //! close method which is called before that this instance is deleted by the DummyMultiChannelGrabberInterface /*! - notice that this method is called in the actual thread of this instance. + notice that this method is called in the actual thread of this instance. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk - \sa ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk + \sa ItomSharedSemaphore */ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - - if (m_timerID > 0) - { - killTimer(m_timerID); - m_timerID = 0; - } - - if (waitCond) - { - waitCond->returnValue = ito::retOk; - waitCond->release(); - - return waitCond->returnValue; - } - else - { - return ito::retOk; - } + ItomSharedSemaphoreLocker locker(waitCond); + + if (m_timerID > 0) + { + killTimer(m_timerID); + m_timerID = 0; + } + + if (waitCond) + { + waitCond->returnValue = ito::retOk; + waitCond->release(); + + return waitCond->returnValue; + } + else + { + return ito::retOk; + } } //---------------------------------------------------------------------------------------------------------------------------------- //! returns parameter of m_params with key name. /*! - This method copies val of the corresponding parameter value. + This method copies val of the corresponding parameter value. - \param [in,out] val is a shared-pointer of ito::Param. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in,out] val is a shared-pointer of ito::Param. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore */ ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok) { - return ito::retOk; + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! sets parameter of m_params with key name. /*! - This method copies the given value to the m_params-parameter. + This method copies the given value to the m_params-parameter. - \param [in] val is the ito::ParamBase value to set. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] val is the ito::ParamBase value to set. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk in case that everything is ok, else retError + \sa ito::tParam, ItomSharedSemaphore */ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate) { - ito::RetVal retValue; - int running = 0; // Used to check if grabber was running bevor - - //first check parameters that influence the size or data type of m_channels - if (key == "binning") - { - if (!retValue.containsError()) - { - if (grabberStartedCount() > 0) - { - running = grabberStartedCount(); - setGrabberStarted(1); - retValue += stopDevice(NULL); - } - } - if(!retValue.containsError()) - { - int oldval = it->getVal(); - - int ival = val->getVal(); - int newY = ival % 100; - int newX = (ival - newY) / 100; - - if (m_lineCamera && (newY != 1)) - { - retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); - } - else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) - { - retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); - } - else - { - m_totalBinning = newX * newY; - - retValue += it->copyValueFrom(&(*val)); - - if (oldval != ival) - { - int oldY = oldval % 100; - int oldX = (oldval - oldY) / 100; - float factorX = (float)oldX / (float)newX; - float factorY = (float)oldY / (float)newY; - int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; - QMap::iterator i; - for (i = m_channels.begin(); i != m_channels.end(); ++i) - { - width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; - height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; - - maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); - maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); - - int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; - int roi[] = { offsetX, offsetY, sizeX, sizeY }; - i.value().m_channelParam["roi"].setVal(roi, 4); - i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); - } - } - } - pendingUpdate << "binning" << "roi"; - } - retValue += checkData(); //check if image must be reallocated - - if (running) - { - retValue += startDevice(NULL); - setGrabberStarted(running); - } - ok = true; - } - if (key == "roi") - { - m_isgrabbing = false; //we need to trigger again since the roi changed - ok = false; //we want to further process the parameter by setParam - } - else - { - ok = false; // set ok to false to let setParam process the parameter - } - - - if (!retValue.containsError()) - { - emit parametersChanged(m_params); - } - - return retValue; + ito::RetVal retValue; + int running = 0; // Used to check if grabber was running bevor + + //first check parameters that influence the size or data type of m_channels + if (key == "binning") + { + if (!retValue.containsError()) + { + if (grabberStartedCount() > 0) + { + running = grabberStartedCount(); + setGrabberStarted(1); + retValue += stopDevice(NULL); + } + } + if(!retValue.containsError()) + { + int oldval = it->getVal(); + + int ival = val->getVal(); + int newY = ival % 100; + int newX = (ival - newY) / 100; + + if (m_lineCamera && (newY != 1)) + { + retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); + } + else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) + { + retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); + } + else + { + m_totalBinning = newX * newY; + + retValue += it->copyValueFrom(&(*val)); + + if (oldval != ival) + { + int oldY = oldval % 100; + int oldX = (oldval - oldY) / 100; + float factorX = (float)oldX / (float)newX; + float factorY = (float)oldY / (float)newY; + int width, height, maxWidth, maxHeight, sizex, sizey, offsetx, offsety; + QMap::iterator i; + for (i = m_channels.begin(); i != m_channels.end(); ++i) + { + width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; + height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; + + maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); + maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); + + int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + int roi[] = { offsetX, offsetY, sizeX, sizeY }; + i.value().m_channelParam["roi"].setVal(roi, 4); + i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); + } + } + } + pendingUpdate << "binning" << "roi"; + } + retValue += checkData(); //check if image must be reallocated + + if (running) + { + retValue += startDevice(NULL); + setGrabberStarted(running); + } + ok = true; + } + if (key == "roi") + { + m_isgrabbing = false; //we need to trigger again since the roi changed + ok = false; //we want to further process the parameter by setParam + } + else + { + ok = false; // set ok to false to let setParam process the parameter + } + + + if (!retValue.containsError()) + { + emit parametersChanged(m_params); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! With startDevice this camera is initialized. /*! - In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. + In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. - \note This method is similar to VideoCapture::open() of openCV + \note This method is similar to VideoCapture::open() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. */ ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; - checkData(); //this will be reallocated in this method. + checkData(); //this will be reallocated in this method. - incGrabberStarted(); + incGrabberStarted(); - if (grabberStartedCount() == 1) - { - m_startOfLastAcquisition = 0; - m_isgrabbing = false; - } + if (grabberStartedCount() == 1) + { + m_startOfLastAcquisition = 0; + m_isgrabbing = false; + } - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } - return retValue; + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! With stopDevice the camera device is stopped (opposite to startDevice) /*! - In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this method. + In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this method. - \note This method is similar to VideoCapture::release() of openCV + \note This method is similar to VideoCapture::release() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera wasn't started before - \sa startDevice + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera wasn't started before + \sa startDevice */ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; - - decGrabberStarted(); - if (grabberStartedCount() < 0) - { - retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); - setGrabberStarted(0); - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + decGrabberStarted(); + if (grabberStartedCount() < 0) + { + retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + setGrabberStarted(0); + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Call this method to trigger a new image. /*! - By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. - The new image is then stored either in internal camera memory or in internal memory of this class. + By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. + The new image is then stored either in internal camera memory or in internal memory of this class. - \note This method is similar to VideoCapture::grab() of openCV + \note This method is similar to VideoCapture::grab() of openCV - \param [in] trigger may describe the trigger parameter (unused here) - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. - \sa getVal + \param [in] trigger may describe the trigger parameter (unused here) + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. + \sa getVal */ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; - - double frame_time = m_params["frame_time"].getVal(); - double integration_time = m_params["integration_time"].getVal(); - int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); - float gain = m_params["gain"].getVal(); - float offset = m_params["offset"].getVal(); - - - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - if (bpp < 8 || bpp >= 32) - { - retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); - } - else if (grabberStartedCount() <= 0) - { - retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); - } - else - { - m_isgrabbing = true; - - if (frame_time > 0.0) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < frame_time) - { - Sleep((frame_time - diff) * 1000.0); - } - } - - m_startOfLastAcquisition = cv::getTickCount(); - //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); - cv::RNG &rng = cv::theRNG(); - - if (m_totalBinning == 1) - { - if (bpp < 9) - { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::uint8 *linePtr; - char* a = m_params["defaultChannel"].getVal(); - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - else if (bpp < 17) - { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::uint16 *linePtr; - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::int32 *linePtr; - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - } - else - { - if (bpp < 9) - { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::uint8 *linePtr; - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - else if (bpp < 17) - { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::uint16 *linePtr; - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::int32 *linePtr; - ito::DataObject &channelObj = m_channels[m_params["defaultChannel"].getVal()].data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - } - - if (integration_time > 0.0) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < integration_time) - { - Sleep((integration_time - diff) * 1000.0); - } - } - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue = ito::retOk; + + double frame_time = m_params["frame_time"].getVal(); + double integration_time = m_params["integration_time"].getVal(); + int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); + float gain = m_params["gain"].getVal(); + float offset = m_params["offset"].getVal(); + + + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + if (bpp < 8 || bpp >= 32) + { + retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); + } + else if (grabberStartedCount() <= 0) + { + retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + } + else + { + m_isgrabbing = true; + + if (frame_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < frame_time) + { + Sleep((frame_time - diff) * 1000.0); + } + } + + m_startOfLastAcquisition = cv::getTickCount(); + //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); + cv::RNG &rng = cv::theRNG(); + + if (m_totalBinning == 1) + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + } + else + { + if (bpp < 9) + { + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + else if (bpp < 17) + { + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + else if (bpp < 32) + { + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32 *linePtr; + foreach(ChannelContainer container, m_channels) + { + ito::DataObject &channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::int32*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + } + + if (integration_time > 0.0) + { + double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); + + if (diff < integration_time) + { + Sleep((integration_time - diff) * 1000.0); + } + } + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a shallow copy. /*! - This method copies the recently grabbed camera frame to the given DataObject-handle + This method copies the recently grabbed camera frame to the given DataObject-handle - \note This method is similar to VideoCapture::retrieve() of openCV + \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::DataObject *dObj = reinterpret_cast(vpdObj); - - ito::RetVal retValue(ito::retOk); - - retValue += retrieveData(); - - if (!retValue.containsError()) - { - if (dObj == NULL) - { - retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); - } - else - { - retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. - - (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; - } - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + ito::RetVal retValue(ito::retOk); + + retValue += retrieveData(); + + if (!retValue.containsError()) + { + if (dObj == NULL) + { + retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + } + else + { + retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + + (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; + } + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! - This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the - DataObject. + This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the + DataObject. - \note This method is similar to VideoCapture::retrieve() of openCV + \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. + \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) { - ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue(ito::retOk); - ito::DataObject *dObj = reinterpret_cast(vpdObj); - - if (!dObj) - { - retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); - } - else - { - retValue += checkData(dObj); - } - - if (!retValue.containsError()) - { - retValue += retrieveData(dObj); - } - - if (!retValue.containsError()) - { - sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; + ItomSharedSemaphoreLocker locker(waitCond); + ito::RetVal retValue(ito::retOk); + ito::DataObject *dObj = reinterpret_cast(vpdObj); + + if (!dObj) + { + retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + } + else + { + retValue += checkData(dObj); + } + + if (!retValue.containsError()) + { + retValue += retrieveData(dObj); + } + + if (!retValue.containsError()) + { + sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + } + + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalDataObject) { - ito::RetVal retValue(ito::retOk); - - if (m_isgrabbing == false) - { - retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); - } - else - { - if (externalDataObject) - { - m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); - } - - m_isgrabbing = false; - } - - return retValue; + ito::RetVal retValue(ito::retOk); + + if (m_isgrabbing == false) + { + retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + } + else + { + if (externalDataObject) + { + m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + } + + m_isgrabbing = false; + } + + return retValue; } //---------------------------------------------------------------------------------------------------------------------------------- void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) { - if (getDockWidget()) - { - QWidget *widget = getDockWidget()->widget(); - if (visible) - { - connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); - emit parametersChanged(m_params); - } - else - { - disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); - } - } + if (getDockWidget()) + { + QWidget *widget = getDockWidget()->widget(); + if (visible) + { + connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + emit parametersChanged(m_params); + } + else + { + disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + } + } } From 7e683326bb90da78187763be508f3b58f92f8cf4 Mon Sep 17 00:00:00 2001 From: robin92 Date: Mon, 21 Jun 2021 17:56:29 +0200 Subject: [PATCH 14/43] small adaptation for test purposes --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 38cabbcd3..24ec6e98d 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -229,7 +229,7 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber(), + AddInMultiChannelGrabber("testtest"), m_isgrabbing(false), m_totalBinning(1), m_lineCamera(false) From 006cb5cb806ad13949b8204b7ee2c274924201fa Mon Sep 17 00:00:00 2001 From: robin92 Date: Wed, 30 Jun 2021 16:58:00 +0200 Subject: [PATCH 15/43] DummyMultiChannelGrabber: adapted Plugin --- .../DummyMultiChannelGrabber.cpp | 187 +++++++++--------- .../DummyMultiChannelGrabber.h | 2 +- 2 files changed, 100 insertions(+), 89 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 24ec6e98d..cdf5895d7 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -234,64 +234,6 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : m_totalBinning(1), m_lineCamera(false) { - ito::DoubleMeta *dm; - - ito::Param paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); - sm->addItem("mode 2"); - sm->addItem("mode 3"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String); - sm->setCategory("DemoParameters"); - paramVal.setMeta(sm, true); - m_params.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); - paramVal.getMetaT()->setCategory("DemoParameters"); - m_params.insert(paramVal.getName(), paramVal); - - if (hasGuiSupport()) { //now create dock widget for this plugin @@ -336,13 +278,107 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan } else { - char* format = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel - m_params["pixelFormat"].setVal(format); - int roi[] = { 0, 0, sizeX, sizeY }; - m_params["roi"].setVal(roi, 4); + + QMap standardParam; + ito::Param paramVal; + int roi[] = { 0, 0, 2048, 2048 }; + paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); - m_params["roi"].setMeta(rm, true); + paramVal.setMeta(rm, true); + standardParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, tr("size in x (cols) [px]").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + standardParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, tr("size in y (rows) [px]").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + standardParam.insert(paramVal.getName(), paramVal); + + ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + m->addItem("mono10"); + m->addItem("mono12"); + m->addItem("mono16"); + paramVal = ito::Param("pixelFormat", ito::ParamBase::String, paramsOpt->at(2).getVal(), tr("bitdepth of images: mono8, mono10, mono12, mono16, rgb32").toLatin1().data()); + paramVal.setMeta(m, true); + standardParam.insert(paramVal.getName(), paramVal); + + + QMap channelMap; + for (int i = 0; i < numChannel; i++) + { + channelMap.insert(QString("channel_%1").arg(i), ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], standardParam["sizex"], standardParam["sizey"])); + } + + channelMap["channel_1"].m_channelParam.insert("channelSpecificParam", ito::Param("channelSpecificParam", ito::ParamBase::Int, 0, 1, 1, tr("this is a channel specific parameter").toLatin1().data())); + + + // global params + QMap globalParam; + globalParam.insert("globalParam", ito::Param("globalParam", ito::ParamBase::Int, 0, 1, 1, tr("this is a global parameter").toLatin1().data())); + + + + ito::DoubleMeta *dm; + paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm->addItem("mode 2"); + sm->addItem("mode 3"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String); + sm->setCategory("DemoParameters"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); + paramVal.getMetaT()->setCategory("DemoParameters"); + globalParam.insert(paramVal.getName(), paramVal); + + + initializeDefaultConfiguration(channelMap, globalParam); + if (sizeY == 1) { m_lineCamera = true; @@ -351,31 +387,6 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan { m_lineCamera = false; } - - QString tempName; - - m_params["defaultChannel"].setVal("Channel_0"); - - //add channels to map - for (int i = 0; i < numChannel; ++i) - { - tempName = QString("Channel_%1").arg(i); - addChannel(tempName); - if (i == 0) - { - m_channels[tempName].m_channelParam.insert("channelSpecificParameter", m_params["channelSpecificParameter"]); //this is a parameter only for channel_0 - } - if (sizeY == 1) - { - m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); - } - else - { - m_channels[tempName].m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); - } - - } - } if (!retVal.containsError()) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 47c6a7e69..371006bbf 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -23,7 +23,7 @@ #ifndef DUMMYMULTICHANNELGRABBER_H #define DUMMYMULTICHANNELGRABBER_H -#include "common/addInGrabber.h" +#include "common/addInMultiChannelGrabber.h" #include "common/typeDefs.h" #include "dialogDummyMultiChannelGrabber.h" From 33d9cfb43c057f30845d57ba08cd2a95c9c4eea3 Mon Sep 17 00:00:00 2001 From: robin92 Date: Thu, 1 Jul 2021 22:00:29 +0200 Subject: [PATCH 16/43] DummyMultiChannelGrabber: small fixes --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index cdf5895d7..c54a3507b 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -311,8 +311,8 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan channelMap.insert(QString("channel_%1").arg(i), ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], standardParam["sizex"], standardParam["sizey"])); } - channelMap["channel_1"].m_channelParam.insert("channelSpecificParam", ito::Param("channelSpecificParam", ito::ParamBase::Int, 0, 1, 1, tr("this is a channel specific parameter").toLatin1().data())); - + channelMap["channel_1"].m_channelParam.insert("channelSpecificParameter", ito::Param("channelSpecificParameter", ito::ParamBase::Int, 0, 1, 1, tr("this is a channel specific parameter").toLatin1().data())); + channelMap["channel_1"].m_channelParam["channelSpecificParameter"].getMetaT()->setCategory("DemoParameters"); // global params QMap globalParam; @@ -372,10 +372,6 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("channelSpecificParameter", ito::ParamBase::Int, 101, 404, 101, tr("channelSpecificParameter only available at Channel_0").toLatin1().data()); - paramVal.getMetaT()->setCategory("DemoParameters"); - globalParam.insert(paramVal.getName(), paramVal); - initializeDefaultConfiguration(channelMap, globalParam); From b93418a286c277cd63d886a04300ee1e6056c6bf Mon Sep 17 00:00:00 2001 From: robin92 Date: Tue, 2 Aug 2022 11:28:39 +0200 Subject: [PATCH 17/43] DummyMultiChannelGrabber: Adjustments to the latest changes of the interface :lipstick: --- .../DummyMultiChannelGrabber.cpp | 451 ++++++++++-------- 1 file changed, 239 insertions(+), 212 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index c54a3507b..41b0c2910 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -25,26 +25,26 @@ #include "DummyMultiChannelGrabber.h" -#define _USE_MATH_DEFINES // needs to be defined to enable standard declartions of PI constant +#define _USE_MATH_DEFINES // needs to be defined to enable standard declartions of PI constant #include "math.h" #ifndef WIN32 #include #endif -#include -#include #include #include +#include +#include +#include "dockWidgetDummyMultiChannelGrabber.h" #include -#include #include -#include "dockWidgetDummyMultiChannelGrabber.h" +#include -#include "pluginVersion.h" -#include "gitVersion.h" #include "common/helperCommon.h" #include "common/paramMeta.h" +#include "gitVersion.h" +#include "pluginVersion.h" #ifdef WIN32 #include @@ -52,22 +52,23 @@ //---------------------------------------------------------------------------------------------------------------------------------- /** @func fastrand -* @brief function for pseudo random values -* -* This function delivers the noise for the image. -*/ -template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) { return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } //---------------------------------------------------------------------------------------------------------------------------------- /** @func fastrand -* @brief function for pseudo random values -* -* This function delivers the noise for the image. -*/ -template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template +inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) { ito::uint32 val = 0; @@ -82,21 +83,20 @@ template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::u //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyMultiChannelGrabberInterface - \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about DummyMultiChannelGrabber as is able to - create one or more new instances of DummyMultiChannelGrabber. + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about + DummyMultiChannelGrabber as is able to create one or more new instances of DummyMultiChannelGrabber. */ //---------------------------------------------------------------------------------------------------------------------------------- //! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. /*! - \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyMultiChannelGrabber-instance is stored in *addInInst - \return retOk - \sa DummyMultiChannelGrabber + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created + DummyMultiChannelGrabber-instance is stored in *addInInst \return retOk \sa DummyMultiChannelGrabber */ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **addInInst) { NEW_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- @@ -109,15 +109,15 @@ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **add ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **addInInst) { REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; + return ito::retOk; } //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for interace /*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyMultiChannelGrabber) should or must - be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand - and m_initParamsOpt within this constructor. + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: + DummyMultiChannelGrabber) should or must be initialized (e.g. by a Python call) with mandatory or optional + parameters, please initialize both vectors m_initParamsMand and m_initParamsOpt within this constructor. */ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() { @@ -127,22 +127,26 @@ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() m_type = ito::typeDataIO | ito::typeGrabber; setObjectName("DummyMultiChannelGrabber"); - //for the docstring, please don't set any spaces at the beginning of the line. -/* char docstring[] = \ -"The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ -\n\ -The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ -The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ -image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ -\n\ -You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ -\n\ -This plugin can also be used as template for other grabber.";*/ + // for the docstring, please don't set any spaces at the beginning of the line. + /* char docstring[] = \ + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + \n\ + The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple + of 4). \ + The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of + the camera \ + image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera + chip.\n\ + \n\ + You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is + equal to 1. \n\ + \n\ + This plugin can also be used as template for other grabber.";*/ m_description = QObject::tr("A virtual white noise grabber"); // m_detaildescription = QObject::tr(docstring); - m_detaildescription = QObject::tr( - "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + m_detaildescription = + QObject::tr("The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ @@ -152,7 +156,7 @@ You can initialize this camera either as a 2D sensor with a width and height >= \n\ This plugin can also be used as template for other grabber."); - m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; + m_author = "R. Hahn, ITO, University Stuttgart"; m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; m_minItomVer = CREATEVERSION(1, 4, 0); m_maxItomVer = MAXVERSION; @@ -161,22 +165,28 @@ This plugin can also be used as template for other grabber."); m_initParamsMand.clear(); - ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); + ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), + tr("Width of virtual sensor chip").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); + param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), + tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value " + "dividable by 4 for a 2D camera.") + .toLatin1() + .data()); m_initParamsOpt.append(param); - param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", + tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); m->addItem("mono10"); m->addItem("mono12"); m->addItem("mono16"); - m->addItem("rgb32"); param.setMeta(m, true); m_initParamsOpt.append(param); - param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), tr("Number of channels").toLatin1().data()); + param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), + tr("Number of channels").toLatin1().data()); m_initParamsOpt.append(param); } @@ -192,24 +202,26 @@ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() } //---------------------------------------------------------------------------------------------------------------------------------- -// this makro registers the class DummyMultiChannelGrabberInterface with the name DummyMultiChannelGrabberinterface as plugin for the Qt-System (see Qt-DOC) - +// this makro registers the class DummyMultiChannelGrabberInterface with the name DummyMultiChannelGrabberinterface as +// plugin for the Qt-System (see Qt-DOC) //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyMultiChannelGrabber - \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. + \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or + simulate a typical WLI or confocal image signal. - Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the - main (GUI) thread. + Usually every method in this class can be executed in an own thread. Only the constructor, destructor, + showConfDialog will be executed by the main (GUI) thread. */ //---------------------------------------------------------------------------------------------------------------------------------- -//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the addIn-Manager. +//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the +//! addIn-Manager. /*! - creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog - is closed, reads the new parameter set and deletes the dialog. + creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, + starts the execution loop and if the dialog is closed, reads the new parameter set and deletes the dialog. \return retOk \sa dialogDummyMultiChannelGrabber @@ -223,23 +235,22 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) //! constructor for DummyMultiChannelGrabber /*! In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. - Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by createDockWidget. + Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by + createDockWidget. \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance \sa ito::tParam, createDockWidget, setParam, getParam */ -DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber("testtest"), - m_isgrabbing(false), - m_totalBinning(1), - m_lineCamera(false) +DummyMultiChannelGrabber::DummyMultiChannelGrabber() + : AddInMultiChannelGrabber("testtest"), m_isgrabbing(false), m_totalBinning(1), m_lineCamera(false) { if (hasGuiSupport()) { - //now create dock widget for this plugin + // now create dock widget for this plugin DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + QDockWidget::DockWidgetFeatures features = + QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } } @@ -256,22 +267,25 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() //---------------------------------------------------------------------------------------------------------------------------------- //! init method which is called by the addInManager after the initiation of a new instance of DummyMultiChannelGrabber. /*! - This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the - internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. + This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given + parameters to the internal m_params-vector. Notice that this method is called after that this instance has been moved + to its own (non-gui) thread. \param [in] paramsMand is a pointer to the vector of mandatory tParams. \param [in] paramsOpt is a pointer to the vector of optional tParams. \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated \return retOk */ -ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, + ItomSharedSemaphore *waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retVal; - int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); //third optional parameter, corresponding to the number of channels + int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth + int numChannel = paramsOpt->at(3).getVal(); // third optional parameter, corresponding to the number of + // channels if (sizeY > 1 && sizeY % 4 != 0) { retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); @@ -279,20 +293,23 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan else { - QMap standardParam; ito::Param paramVal; - int roi[] = { 0, 0, 2048, 2048 }; - paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); - ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + int roi[] = {0, 0, 2048, 2048}; + paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, + tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); + ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), + ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); paramVal.setMeta(rm, true); standardParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, tr("size in x (cols) [px]").toLatin1().data()); + paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, + tr("size in x (cols) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); standardParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, tr("size in y (rows) [px]").toLatin1().data()); + paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, + tr("size in y (rows) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); standardParam.insert(paramVal.getName(), paramVal); @@ -300,79 +317,92 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan m->addItem("mono10"); m->addItem("mono12"); m->addItem("mono16"); - paramVal = ito::Param("pixelFormat", ito::ParamBase::String, paramsOpt->at(2).getVal(), tr("bitdepth of images: mono8, mono10, mono12, mono16, rgb32").toLatin1().data()); + paramVal = ito::Param("pixelFormat", ito::ParamBase::String, paramsOpt->at(2).getVal(), + tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); paramVal.setMeta(m, true); standardParam.insert(paramVal.getName(), paramVal); - QMap channelMap; for (int i = 0; i < numChannel; i++) { - channelMap.insert(QString("channel_%1").arg(i), ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], standardParam["sizex"], standardParam["sizey"])); + channelMap.insert(QString("channel_%1").arg(i), + ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], + standardParam["sizex"], standardParam["sizey"])); } - - channelMap["channel_1"].m_channelParam.insert("channelSpecificParameter", ito::Param("channelSpecificParameter", ito::ParamBase::Int, 0, 1, 1, tr("this is a channel specific parameter").toLatin1().data())); - channelMap["channel_1"].m_channelParam["channelSpecificParameter"].getMetaT()->setCategory("DemoParameters"); + + channelMap["channel_1"].m_channelParam.insert( + "channelSpecificParameter", ito::Param("channelSpecificParameter", ito::ParamBase::Int, 0, 1, 1, + tr("this is a channel specific parameter").toLatin1().data())); + channelMap["channel_1"].m_channelParam["channelSpecificParameter"].getMetaT()->setCategory( + "DemoParameters"); // global params QMap globalParam; - globalParam.insert("globalParam", ito::Param("globalParam", ito::ParamBase::Int, 0, 1, 1, tr("this is a global parameter").toLatin1().data())); - - - + globalParam.insert("globalParam", ito::Param("globalParam", ito::ParamBase::Int, 0, 1, 1, + tr("this is a global parameter").toLatin1().data())); + ito::DoubleMeta *dm; - paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + paramVal = ito::Param( + "frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, + tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, + tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).") + .toLatin1() + .data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, + tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); + paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", + tr("matches strings without whitespaces").toLatin1().data()); paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", + tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", + tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); sm->addItem("mode 2"); sm->addItem("mode 3"); paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", + tr("any string allowed").toLatin1().data()); sm = new ito::StringMeta(ito::StringMeta::String); sm->setCategory("DemoParameters"); paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); - initializeDefaultConfiguration(channelMap, globalParam); if (sizeY == 1) @@ -387,7 +417,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan if (!retVal.containsError()) { - retVal += checkData(); //check if image must be reallocated + retVal += checkData(); // check if image must be reallocated emit parametersChanged(m_params); } @@ -400,7 +430,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan waitCond->release(); } - setInitialized(true); //init method has been finished (independent on retval) + setInitialized(true); // init method has been finished (independent on retval) return retVal; } @@ -446,12 +476,13 @@ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) \return retOk in case that everything is ok, else retError \sa ito::tParam, ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok) +ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer val, const ParamMapIterator &it, + const QString &suffix, const QString &key, int index, bool hasIndex, + bool &ok) { return ito::retOk; } - //---------------------------------------------------------------------------------------------------------------------------------- //! sets parameter of m_params with key name. /*! @@ -462,12 +493,14 @@ ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer va \return retOk in case that everything is ok, else retError \sa ito::tParam, ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate) +ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer val, const ParamMapIterator &it, + const QString &suffix, const QString &key, int index, bool hasIndex, + bool &ok, QStringList &pendingUpdate) { ito::RetVal retValue; int running = 0; // Used to check if grabber was running bevor - //first check parameters that influence the size or data type of m_channels + // first check parameters that influence the size or data type of m_channels if (key == "binning") { if (!retValue.containsError()) @@ -479,7 +512,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointergetVal(); @@ -493,7 +526,9 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer::iterator i; for (i = m_channels.begin(); i != m_channels.end(); ++i) { - width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0])*factorX; - height = (i.value().m_channelParam["roi"].getVal()[3] - i.value().m_channelParam["roi"].getVal()[2]) * factorY; - - maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta())->getWidthRangeMeta().getSizeMax(); - maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta())->getHeightRangeMeta().getSizeMax(); - - int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; - int roi[] = { offsetX, offsetY, sizeX, sizeY }; - i.value().m_channelParam["roi"].setVal(roi, 4); - i.value().m_channelParam["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), true); + width = (i.value().m_channelParam["roi"].getVal()[1] - + i.value().m_channelParam["roi"].getVal()[0]) * + factorX; + height = (i.value().m_channelParam["roi"].getVal()[3] - + i.value().m_channelParam["roi"].getVal()[2]) * + factorY; + + maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta()) + ->getWidthRangeMeta() + .getSizeMax(); + maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta()) + ->getHeightRangeMeta() + .getSizeMax(); + + int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + int roi[] = {offsetX, offsetY, sizeX, sizeY}; + i.value().m_channelParam["roi"].setVal(roi, 4); + i.value().m_channelParam["roi"].setMeta( + new ito::RectMeta( + ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), + ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), + true); } } } - pendingUpdate << "binning" << "roi"; + pendingUpdate << "binning" + << "roi"; } - retValue += checkData(); //check if image must be reallocated + retValue += checkData(); // check if image must be reallocated if (running) { @@ -538,17 +586,16 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer(); double integration_time = m_params["integration_time"].getVal(); - int bpp = pixelFormatStringToBpp(m_params["pixelFormat"].getVal()); float gain = m_params["gain"].getVal(); float offset = m_params["offset"].getVal(); - - - + int min, max = 0; + bool ok = false; + AddInAbstractGrabber::integerPixelFormatStringToMinMaxValue(m_params["pixelFormat"].getVal(), min, max, ok); + if (!ok) + { + retValue += ito::RetVal(ito::retError, 0, tr("pixel format is not a integer format").toLatin1().data()); + } if (waitCond) { waitCond->returnValue = retValue; waitCond->release(); } - if (bpp < 8 || bpp >= 32) - { - retValue += ito::RetVal(ito::retError, 0, tr("wrong bit depth").toLatin1().data()); - } - else if (grabberStartedCount() <= 0) + if (grabberStartedCount() <= 0) { - retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, 1002, + tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.") + .toLatin1() + .data()); } else { @@ -678,21 +735,21 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } m_startOfLastAcquisition = cv::getTickCount(); - //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); + // ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); cv::RNG &rng = cv::theRNG(); if (m_totalBinning == 1) { - if (bpp < 9) + if (max < 256) { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::uint8 *linePtr; - foreach(ChannelContainer container, m_channels) + ito::uint8 maxInt = cv::saturate_cast(max); + ito::uint8 *linePtr; + foreach (ChannelContainer container, m_channels) { ito::DataObject &channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + linePtr = (ito::uint8 *)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -700,16 +757,16 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } } } - else if (bpp < 17) + else if (max < 65536) { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 maxInt = cv::saturate_cast(max); ito::uint16 *linePtr; - foreach(ChannelContainer container, m_channels) + foreach (ChannelContainer container, m_channels) { ito::DataObject &channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + linePtr = (ito::uint16 *)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -717,36 +774,19 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } } } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::int32 *linePtr; - foreach(ChannelContainer container, m_channels) - { - ito::DataObject &channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - } } else { - if (bpp < 9) + if (max < 256) { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8 maxInt = cv::saturate_cast(max); ito::uint8 *linePtr; - foreach(ChannelContainer container, m_channels) + foreach (ChannelContainer container, m_channels) { ito::DataObject &channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + linePtr = (ito::uint8 *)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); @@ -754,16 +794,16 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } } } - else if (bpp < 17) + else if (max < 65536) { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16 maxInt = cv::saturate_cast(max); ito::uint16 *linePtr; - foreach(ChannelContainer container, m_channels) + foreach (ChannelContainer container, m_channels) { ito::DataObject &channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + linePtr = (ito::uint16 *)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); @@ -771,23 +811,6 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } } } - else if (bpp < 32) - { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - ito::int32 *linePtr; - foreach(ChannelContainer container, m_channels) - { - ito::DataObject &channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::int32*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); - } - } - } - } } if (integration_time > 0.0) @@ -811,10 +834,10 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where + the acquired image is shallow-copied to. \param [in] waitCond is the semaphore (default: NULL), which is released if + this method has been terminated \return retOk if everything is ok, retError is camera has not been started or no + image has been acquired by the method acquire. \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) { @@ -829,13 +852,15 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore * { if (dObj == NULL) { - retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + retValue += + ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); } else { - retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + retValue += sendDataToListeners( + 0); // don't wait for live image, since user should get the image as fast as possible. - (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; + (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; } } @@ -851,15 +876,15 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore * //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! - This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the - DataObject. + This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to + the data structure of the DataObject. \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where + the acquired image is deep copied to. \param [in] waitCond is the semaphore (default: NULL), which is released if + this method has been terminated \return retOk if everything is ok, retError is camera has not been started or no + image has been acquired by the method acquire. \sa DataObject, acquire */ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) { @@ -883,7 +908,7 @@ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore if (!retValue.containsError()) { - sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. } if (waitCond) @@ -902,13 +927,14 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalData if (m_isgrabbing == false) { - retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + retValue += ito::RetVal(ito::retError, 1002, + tr("image could not be obtained since no image has been acquired.").toLatin1().data()); } else { if (externalDataObject) { - m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); } m_isgrabbing = false; @@ -925,13 +951,14 @@ void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) QWidget *widget = getDockWidget()->widget(); if (visible) { - connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + connect(this, SIGNAL(parametersChanged(QMap)), widget, + SLOT(parametersChanged(QMap))); emit parametersChanged(m_params); } else { - disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + disconnect(this, SIGNAL(parametersChanged(QMap)), widget, + SLOT(parametersChanged(QMap))); } } } - From db5820dbca8e4a73699e82f0b6bd539382fff8e8 Mon Sep 17 00:00:00 2001 From: robin92 Date: Tue, 18 Oct 2022 09:49:03 +0200 Subject: [PATCH 18/43] first implementation of getValByMap --- .../DummyMultiChannelGrabber.cpp | 27 +++++++++++++++++++ .../DummyMultiChannelGrabber.h | 5 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 41b0c2910..dc3b65b86 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -873,6 +873,33 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore * return retValue; } +ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointer> dataObjMap) +{ + ito::RetVal retValue(ito::retOk); + + retValue += retrieveData(); + + if (!retValue.containsError()) + { + if (dataObjMap == NULL) + { + retValue += + ito::RetVal(ito::retError, 1004, tr("QMap of getVal is NULL").toLatin1().data()); + } + else + { + retValue += sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. + QMap::iterator it = (*dataObjMap).begin(); + while (it != (*dataObjMap).end()) + { + *(it.value()) = this->m_channels[it.key()].data; + ++it; + } + } + } + return retValue; +} + //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 371006bbf..99e21eab6 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -58,6 +58,9 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber DummyMultiChannelGrabber(); ito::RetVal retrieveData(ito::DataObject *externalDataObject = NULL); + ito::RetVal getValByMap(QSharedPointer> dataObjMap); + ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); + ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); public: friend class DummyMultiChannelGrabberInterface; @@ -73,8 +76,6 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber signals: public slots: - ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok); - ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool &ok, QStringList &pendingUpdate); ito::RetVal init(QVector *paramsMand, QVector *paramsOpt, ItomSharedSemaphore *waitCond = NULL); ito::RetVal close(ItomSharedSemaphore *waitCond); From f4eb6c03f4e00469b96e74f7bdddea65ab5cabd8 Mon Sep 17 00:00:00 2001 From: robin92 Date: Tue, 25 Oct 2022 11:38:57 +0200 Subject: [PATCH 19/43] Multichannelgrabber: added a QMap based version of copyVal --- .../DummyMultiChannelGrabber.cpp | 56 +++++++++++++++++++ .../DummyMultiChannelGrabber.h | 2 + 2 files changed, 58 insertions(+) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index dc3b65b86..14ab04ece 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -899,6 +899,62 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointer> dataObjMap) +{ + ito::RetVal retValue(ito::retOk); + + if (m_isgrabbing == false) + { + retValue += ito::RetVal(ito::retError, 1002, + tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + } + else + { + if (dataObjMap) + { + QMap::const_iterator it = (*dataObjMap).constBegin(); + while (it != (*dataObjMap).constEnd()) + { + m_channels[it.key()].data.deepCopyPartial(*it.value()); + ++it; + } + + } + + m_isgrabbing = false; + } + + return retValue; +} +ito::RetVal DummyMultiChannelGrabber::copyValByMap(QSharedPointer> dataObjMap) +{ + + ito::RetVal retValue(ito::retOk); + + retValue += checkData(*dataObjMap); + retValue += retrieveData(dataObjMap); + + if (!retValue.containsError()) + { + if (dataObjMap == NULL) + { + retValue += + ito::RetVal(ito::retError, 1004, tr("QMap of getVal is NULL").toLatin1().data()); + } + else + { + retValue += sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. + QMap::iterator it = (*dataObjMap).begin(); + while (it != (*dataObjMap).end()) + { + *(it.value()) = this->m_channels[it.key()].data; + ++it; + } + } + } + return retValue; +} //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 99e21eab6..37ca6f2ad 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -58,7 +58,9 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber DummyMultiChannelGrabber(); ito::RetVal retrieveData(ito::DataObject *externalDataObject = NULL); + ito::RetVal retrieveData(QSharedPointer> dataObjMap); ito::RetVal getValByMap(QSharedPointer> dataObjMap); + ito::RetVal copyValByMap(QSharedPointer> dataObjMap); ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); From bf3914edcb545623c94be9ad9ca7a6e09a34d24d Mon Sep 17 00:00:00 2001 From: Robin Hahn Date: Sat, 21 Jan 2023 17:10:36 +0100 Subject: [PATCH 20/43] first work for a true freerun mode using the new newGrabberData signal --- .../DummyMultiChannelGrabber.cpp | 137 ++++++++++++------ .../DummyMultiChannelGrabber.h | 1 + 2 files changed, 94 insertions(+), 44 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 14ab04ece..6cc0d8236 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -373,6 +373,17 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); + paramVal = ito::Param( + "triggerMode", + ito::ParamBase::String, + "software", + tr("trigger mode of the camera (freerun or software)").toLatin1().data()); + ito::StringMeta* sm = + new ito::StringMeta(ito::StringMeta::String, "software", "AcquisitionControl"); + sm->addItem("freerun"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); @@ -390,12 +401,14 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); sm->addItem("mode 2"); sm->addItem("mode 3"); paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); sm = new ito::StringMeta(ito::StringMeta::String); @@ -676,51 +689,33 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- -//! Call this method to trigger a new image. -/*! - By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, - this method is called. The new image is then stored either in internal camera memory or in internal memory of this - class. - - \note This method is similar to VideoCapture::grab() of openCV - - \param [in] trigger may describe the trigger parameter (unused here) - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which - has not be fetched by getVal, yet. \sa getVal -*/ -ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::generateImageData() { - ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue = ito::retOk; - double frame_time = m_params["frame_time"].getVal(); double integration_time = m_params["integration_time"].getVal(); float gain = m_params["gain"].getVal(); float offset = m_params["offset"].getVal(); int min, max = 0; bool ok = false; - AddInAbstractGrabber::integerPixelFormatStringToMinMaxValue(m_params["pixelFormat"].getVal(), min, max, ok); + AddInAbstractGrabber::integerPixelFormatStringToMinMaxValue( + m_params["pixelFormat"].getVal(), min, max, ok); if (!ok) { - retValue += ito::RetVal(ito::retError, 0, tr("pixel format is not a integer format").toLatin1().data()); - } - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); + retValue += ito::RetVal( + ito::retError, 0, tr("pixel format is not a integer format").toLatin1().data()); } - if (grabberStartedCount() <= 0) { retValue += ito::RetVal( - ito::retError, 1002, - tr("Acquire of DummyMultiChannelGrabber can not be executed, since camera has not been started.") + ito::retError, + 1002, + tr("Can not acquire image, since camera has not been " + "started.") .toLatin1() .data()); } - else + if (!retValue.containsError()) { m_isgrabbing = true; @@ -736,20 +731,20 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS m_startOfLastAcquisition = cv::getTickCount(); // ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); - cv::RNG &rng = cv::theRNG(); + cv::RNG& rng = cv::theRNG(); if (m_totalBinning == 1) { if (max < 256) { ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8 *linePtr; + ito::uint8* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject &channelObj = container.data; + ito::DataObject& channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint8 *)channelObj.rowPtr(0, m); + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -760,13 +755,13 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS else if (max < 65536) { ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16 *linePtr; + ito::uint16* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject &channelObj = container.data; + ito::DataObject& channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint16 *)channelObj.rowPtr(0, m); + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -780,16 +775,17 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS if (max < 256) { ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8 *linePtr; + ito::uint8* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject &channelObj = container.data; + ito::DataObject& channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint8 *)channelObj.rowPtr(0, m); + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); } } } @@ -797,16 +793,17 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS else if (max < 65536) { ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16 *linePtr; + ito::uint16* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject &channelObj = container.data; + ito::DataObject& channelObj = container.data; for (int m = 0; m < channelObj.getSize(0); ++m) { - linePtr = (ito::uint16 *)channelObj.rowPtr(0, m); + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); for (int n = 0; n < channelObj.getSize(1); ++n) { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); } } } @@ -823,6 +820,58 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } } } + ////pack all channel images to a QMap + QSharedPointer > returnMap(new QMap); + QMap::iterator it = m_channels.begin(); + while (it != m_channels.end()) + { + (*returnMap)[it.key()] = it.value().data; + ++it; + } + emit newGrabberData(returnMap); + return retValue; +} + +//---------------------------------------------------------------------------------------------------------------------------------- +//! Call this method to trigger a new image. +/*! + By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, + this method is called. The new image is then stored either in internal camera memory or in internal memory of this + class. + + \note This method is similar to VideoCapture::grab() of openCV + + \param [in] trigger may describe the trigger parameter (unused here) + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated + \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which + has not be fetched by getVal, yet. \sa getVal +*/ +ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) +{ + ito::RetVal retValue = ito::retOk; + ItomSharedSemaphoreLocker locker(waitCond); + if (strcmp(m_params["triggerMode"].getVal(), "software")==0) + { + retValue += generateImageData(); + + } + else + { + retValue += ito::RetVal( + ito::retWarning, + 0, + tr("The trigger mode of the camera is set to freerun therefore calling acquire is " + "useless.") + .toLatin1() + .data()); + } + if (waitCond) + { + waitCond->returnValue = retValue; + waitCond->release(); + } + + return retValue; } diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 37ca6f2ad..33a11819c 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -74,6 +74,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber int64 m_startOfLastAcquisition; ito::uint8 m_totalBinning; bool m_lineCamera; + ito::RetVal generateImageData(); signals: From 43c4a9f9532d644ddde5116d94162dcc3d556ce5 Mon Sep 17 00:00:00 2001 From: Robin Hahn Date: Sun, 22 Jan 2023 18:55:46 +0100 Subject: [PATCH 21/43] DummyMultiChannelGrabber: added freerun mode --- .../DummyMultiChannelGrabber.cpp | 50 +++++++++++++++---- .../DummyMultiChannelGrabber.h | 4 +- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 6cc0d8236..dcfd88f95 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -241,8 +241,9 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance \sa ito::tParam, createDockWidget, setParam, getParam */ -DummyMultiChannelGrabber::DummyMultiChannelGrabber() - : AddInMultiChannelGrabber("testtest"), m_isgrabbing(false), m_totalBinning(1), m_lineCamera(false) +DummyMultiChannelGrabber::DummyMultiChannelGrabber() : + AddInMultiChannelGrabber("testtest"), m_isgrabbing(false), m_totalBinning(1), + m_lineCamera(false), m_freerunTimer(this) { if (hasGuiSupport()) { @@ -253,6 +254,7 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } + connect(&m_freerunTimer, &QTimer::timeout, this, &DummyMultiChannelGrabber::generateImageData); } //---------------------------------------------------------------------------------------------------------------------------------- @@ -351,8 +353,8 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, - tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).") + paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.001, + tr("Minimum integration time for an acquisition [s], default: 0.001.") .toLatin1() .data()); dm = paramVal.getMetaT(); @@ -604,6 +606,28 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointergetVal() + m_params["frame_time"].getVal()) * 1000.0)); + if (timerIsRunning) + { + m_freerunTimer.start(); + } + } + if (key == "frame_time") + { + bool timerIsRunning = m_freerunTimer.isActive(); + m_freerunTimer.stop(); + m_freerunTimer.setInterval( + int((val->getVal() + m_params["integration_time"].getVal()) * 1000.0)); + if (timerIsRunning) + { + m_freerunTimer.start(); + } + } else { ok = false; // set ok to false to let setParam process the parameter @@ -642,7 +666,10 @@ ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore *waitCond) m_startOfLastAcquisition = 0; m_isgrabbing = false; } - + if (strcmp(m_params["triggerMode"].getVal(), "freerun") == 0) + { + m_freerunTimer.start(int((m_params["frame_time"].getVal()+m_params["integration_time"].getVal()) * 1000.0)); + } if (waitCond) { waitCond->returnValue = retValue; @@ -679,7 +706,10 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) .data()); setGrabberStarted(0); } - + else + { + m_freerunTimer.stop(); + } if (waitCond) { waitCond->returnValue = retValue; @@ -718,8 +748,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() if (!retValue.containsError()) { m_isgrabbing = true; - - if (frame_time > 0.0) + if (strcmp(m_params["triggerMode"].getVal(), "software") == 0 && (frame_time > 0.0)) { double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); @@ -810,7 +839,8 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() } } - if (integration_time > 0.0) + if((strcmp(m_params["triggerMode"].getVal(), "software") == 0) && + (integration_time > 0.0)) { double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); @@ -827,7 +857,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() { (*returnMap)[it.key()] = it.value().data; ++it; - } + } emit newGrabberData(returnMap); return retValue; } diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 33a11819c..0c60c4c3e 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -74,7 +74,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber int64 m_startOfLastAcquisition; ito::uint8 m_totalBinning; bool m_lineCamera; - ito::RetVal generateImageData(); + QTimer m_freerunTimer; signals: @@ -91,6 +91,8 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber private slots: void dockWidgetVisibilityChanged(bool visible); + ito::RetVal generateImageData(); + }; From deba3718814456706e67ebc442c0148446cdafba Mon Sep 17 00:00:00 2001 From: Robin Hahn Date: Mon, 30 Jan 2023 19:43:00 +0100 Subject: [PATCH 22/43] DummyMultiChannelGrabber: some adaptions to the new default parameters axisScale and axisOffset. --- .../DummyMultiChannelGrabber.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index dcfd88f95..9ec229a2c 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -323,13 +323,33 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); paramVal.setMeta(m, true); standardParam.insert(paramVal.getName(), paramVal); + + double axisOffset[] = {0.0, 0.0}; + paramVal = ito::Param( + "axisOffset", + ito::ParamBase::DoubleArray, + 2, + axisOffset, + tr("axis offset").toLatin1().data()); + standardParam.insert(paramVal.getName(), paramVal); + + double axisScale[] = {1.0, 1.0}; + paramVal = ito::Param( + "axisScale", + ito::ParamBase::DoubleArray, + 2, + axisScale, + tr("axis scale").toLatin1().data()); + standardParam.insert(paramVal.getName(), paramVal); QMap channelMap; for (int i = 0; i < numChannel; i++) { channelMap.insert(QString("channel_%1").arg(i), ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], - standardParam["sizex"], standardParam["sizey"])); + standardParam["sizex"], + standardParam["sizey"], + standardParam["axisOffset"], standardParam["axisScale"])); } channelMap["channel_1"].m_channelParam.insert( From bc0fdb4912eacb54beb38c7e3ad0b552a885851d Mon Sep 17 00:00:00 2001 From: Robin Hahn Date: Sun, 26 Feb 2023 16:47:35 +0100 Subject: [PATCH 23/43] DummyMultiChannelGrabber: some further adaptions --- .../DummyMultiChannelGrabber.cpp | 28 ++++++++++--------- .../DummyMultiChannelGrabber.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 9ec229a2c..6079a36c3 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -515,6 +515,7 @@ ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer va const QString &suffix, const QString &key, int index, bool hasIndex, bool &ok) { + ok = false; return ito::retOk; } @@ -528,9 +529,7 @@ ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer va \return retOk in case that everything is ok, else retError \sa ito::tParam, ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer val, const ParamMapIterator &it, - const QString &suffix, const QString &key, int index, bool hasIndex, - bool &ok, QStringList &pendingUpdate) +ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate) { ito::RetVal retValue; int running = 0; // Used to check if grabber was running bevor @@ -579,7 +578,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer::iterator i; - for (i = m_channels.begin(); i != m_channels.end(); ++i) + for (i = m_channels.begin(); i != m_channels.end(); ++i) //we need to adapt the roi for each channel { width = (i.value().m_channelParam["roi"].getVal()[1] - i.value().m_channelParam["roi"].getVal()[0]) * @@ -606,14 +605,20 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer()) + { + m_params["roi"].setVal(roi, 4); + m_params["roi"].setMeta( + new ito::RectMeta( + ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), + ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), + true); + } } + pendingUpdate << "roi" << "binning"; //add roi to update list to trigger a update of sizey and sizey } } - pendingUpdate << "binning" - << "roi"; } - retValue += checkData(); // check if image must be reallocated - if (running) { retValue += startDevice(NULL); @@ -636,6 +641,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer> dataObjMap); ito::RetVal copyValByMap(QSharedPointer> dataObjMap); ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); - ito::RetVal setParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); + ito::RetVal setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); public: friend class DummyMultiChannelGrabberInterface; From df64c42d527107122ccda0785f1727a11519a522 Mon Sep 17 00:00:00 2001 From: Robin Hahn Date: Tue, 28 Feb 2023 14:55:47 +0100 Subject: [PATCH 24/43] DummyMultiChannelGrabber: renamed signal --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 6079a36c3..d93bad9b8 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -880,7 +880,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() (*returnMap)[it.key()] = it.value().data; ++it; } - emit newGrabberData(returnMap); + emit newData(returnMap); return retValue; } From 01bf11a9202e6abfb35a0e9a353a8bcd2b5c69a9 Mon Sep 17 00:00:00 2001 From: Krauter Date: Sat, 10 Jun 2023 21:09:14 +0200 Subject: [PATCH 25/43] fix in variable names --- .../DummyMultiChannelGrabber.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index d93bad9b8..fd34e1bdf 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -323,7 +323,7 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); paramVal.setMeta(m, true); standardParam.insert(paramVal.getName(), paramVal); - + double axisOffset[] = {0.0, 0.0}; paramVal = ito::Param( "axisOffset", @@ -576,7 +576,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer::iterator i; for (i = m_channels.begin(); i != m_channels.end(); ++i) //we need to adapt the roi for each channel { @@ -594,10 +594,10 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointergetHeightRangeMeta() .getSizeMax(); - int sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - int sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - int offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - int offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; int roi[] = {offsetX, offsetY, sizeX, sizeY}; i.value().m_channelParam["roi"].setVal(roi, 4); i.value().m_channelParam["roi"].setMeta( @@ -922,7 +922,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS waitCond->returnValue = retValue; waitCond->release(); } - + return retValue; @@ -995,7 +995,7 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointerm_channels[it.key()].data; ++it; - } + } } } return retValue; From 4906ff619bd136e0698bfdb4f052c7f578516191 Mon Sep 17 00:00:00 2001 From: photoniker Date: Sat, 10 Jun 2023 21:57:50 +0200 Subject: [PATCH 26/43] fixed Warnung in CMakeLists.txt --- DummyMultiChannelGrabber/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DummyMultiChannelGrabber/CMakeLists.txt b/DummyMultiChannelGrabber/CMakeLists.txt index e77db8b32..13e9da3a8 100644 --- a/DummyMultiChannelGrabber/CMakeLists.txt +++ b/DummyMultiChannelGrabber/CMakeLists.txt @@ -1,7 +1,6 @@ -set(target_name DummyMultiChannelGrabber) - +cmake_minimum_required(VERSION 3.12...3.24) -cmake_minimum_required(VERSION 3.1...3.15) +set(target_name DummyMultiChannelGrabber) option(BUILD_TARGET64 "Build for 64 bit target if set to ON or 32 bit if set to OFF." ON) set(ITOM_SDK_DIR NOTFOUND CACHE PATH "path of SDK subfolder of itom root (build) directory") From 248277ae86a79e5597d09acfcbdc3b1bc27cbac6 Mon Sep 17 00:00:00 2001 From: Krauter Date: Wed, 14 Jun 2023 13:24:34 +0200 Subject: [PATCH 27/43] implemented GaussianSpot, GaussianSpotArray to DummyMultiChannelGrabber --- DummyGrabber/DummyGrabber.cpp | 671 ++++++++------ .../DummyMultiChannelGrabber.cpp | 859 ++++++++++++------ .../DummyMultiChannelGrabber.h | 10 +- 3 files changed, 968 insertions(+), 572 deletions(-) diff --git a/DummyGrabber/DummyGrabber.cpp b/DummyGrabber/DummyGrabber.cpp index 7566305a5..2801ddc57 100644 --- a/DummyGrabber/DummyGrabber.cpp +++ b/DummyGrabber/DummyGrabber.cpp @@ -25,26 +25,16 @@ #include "DummyGrabber.h" -#define _USE_MATH_DEFINES // needs to be defined to enable standard declartions of PI constant -#include "math.h" - #ifndef WIN32 - #include +#include #endif -#include -#include -#include -#include - -#include -#include -#include + #include "dockWidgetDummyGrabber.h" -#include "pluginVersion.h" -#include "gitVersion.h" #include "common/helperCommon.h" #include "common/paramMeta.h" +#include "gitVersion.h" +#include "pluginVersion.h" #ifdef WIN32 #include @@ -52,22 +42,23 @@ //---------------------------------------------------------------------------------------------------------------------------------- /** @func fastrand -* @brief function for pseudo random values -* -* This function delivers the noise for the image. -*/ -template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template inline _Tp fastrand(cv::RNG& rng, _Tp maxval, float offset, float gain) { return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } //---------------------------------------------------------------------------------------------------------------------------------- /** @func fastrand -* @brief function for pseudo random values -* -* This function delivers the noise for the image. -*/ -template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template +inline _Tp fastrand_mean(cv::RNG& rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) { ito::uint32 val = 0; @@ -81,11 +72,11 @@ template inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::u //---------------------------------------------------------------------------------------------------------------------------------- /** @func gaussFunc -* @brief function for 2d Gaussian function -* -* This function delivers a 2d dataObject with a Gaussian function -*/ -template ito::RetVal gaussFunc(cv::RNG &rng, ito::DataObject dObj, float amplitude) + * @brief function for 2d Gaussian function + * + * This function delivers a 2d dataObject with a Gaussian function + */ +template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject dObj, float amplitude) { int width = dObj.getSize(1); int height = dObj.getSize(0); @@ -103,11 +94,13 @@ template ito::RetVal gaussFunc(cv::RNG &rng, ito::DataObject dObj, for (int y = 0; y < height; y++) { rowPtr = dObj.rowPtr<_Tp>(planeID, y); - yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / (2.0f * sigmaY * sigmaY); + yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / + (2.0f * sigmaY * sigmaY); for (int x = 0; x < width; x++) { - xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / (2.0f * sigmaX * sigmaX); + xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / + (2.0f * sigmaX * sigmaX); rowPtr[x] = (float)(amplitude - aRandOfset) * exp(-(xval + yval)); } } @@ -118,18 +111,17 @@ template ito::RetVal gaussFunc(cv::RNG &rng, ito::DataObject dObj, //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyGrabberInterface - \brief Small interface class for class DummyGrabber. This class contains basic information about DummyGrabber as is able to - create one or more new instances of DummyGrabber. + \brief Small interface class for class DummyGrabber. This class contains basic information about + DummyGrabber as is able to create one or more new instances of DummyGrabber. */ //---------------------------------------------------------------------------------------------------------------------------------- //! creates new instance of DummyGrabber and returns the instance-pointer. /*! - \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created DummyGrabber-instance is stored in *addInInst - \return retOk - \sa DummyGrabber + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created + DummyGrabber-instance is stored in *addInInst \return retOk \sa DummyGrabber */ -ito::RetVal DummyGrabberInterface::getAddInInst(ito::AddInBase **addInInst) +ito::RetVal DummyGrabberInterface::getAddInInst(ito::AddInBase** addInInst) { NEW_PLUGININSTANCE(DummyGrabber) return ito::retOk; @@ -142,7 +134,7 @@ ito::RetVal DummyGrabberInterface::getAddInInst(ito::AddInBase **addInInst) \return retOk \sa DummyGrabber */ -ito::RetVal DummyGrabberInterface::closeThisInst(ito::AddInBase **addInInst) +ito::RetVal DummyGrabberInterface::closeThisInst(ito::AddInBase** addInInst) { REMOVE_PLUGININSTANCE(DummyGrabber) return ito::retOk; @@ -151,9 +143,10 @@ ito::RetVal DummyGrabberInterface::closeThisInst(ito::AddInBase **addInInst) //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for interace /*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: DummyGrabber) should or must - be initialized (e.g. by a Python call) with mandatory or optional parameters, please initialize both vectors m_initParamsMand - and m_initParamsOpt within this constructor. + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real + plugin (here: DummyGrabber) should or must be initialized (e.g. by a Python call) with mandatory + or optional parameters, please initialize both vectors m_initParamsMand and m_initParamsOpt + within this constructor. */ DummyGrabberInterface::DummyGrabberInterface() { @@ -163,22 +156,26 @@ DummyGrabberInterface::DummyGrabberInterface() m_type = ito::typeDataIO | ito::typeGrabber; setObjectName("DummyGrabber"); - //for the docstring, please don't set any spaces at the beginning of the line. -/* char docstring[] = \ -"The DummyGrabber is a virtual camera which emulates a camera with white noise. \n\ -\n\ -The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ -The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ -image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ -\n\ -You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ -\n\ -This plugin can also be used as template for other grabber.";*/ + // for the docstring, please don't set any spaces at the beginning of the line. + /* char docstring[] = \ + "The DummyGrabber is a virtual camera which emulates a camera with white noise. \n\ + \n\ + The camera is initialized with a maximum width and height of the simulated camera chip (both + need to be a multiple of 4). \ + The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per + pixel). The real size of the camera \ + image is controlled using the parameter 'roi' if the sizes stay within the limits given by the + size of the camera chip.\n\ + \n\ + You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line + camera whose height is equal to 1. \n\ + \n\ + This plugin can also be used as template for other grabber.";*/ m_description = QObject::tr("A virtual white noise grabber"); -// m_detaildescription = QObject::tr(docstring); + // m_detaildescription = QObject::tr(docstring); m_detaildescription = QObject::tr( -"The DummyGrabber is a virtual camera which emulates a camera with white noise. \n\ + "The DummyGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ You can choose between different image types (noise, GaussianSpot). \ @@ -192,23 +189,47 @@ This plugin can also be used as template for other grabber."); m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; - m_minItomVer = CREATEVERSION(1,4,0); + m_minItomVer = CREATEVERSION(1, 4, 0); m_maxItomVer = MAXVERSION; m_license = QObject::tr("Licensed under LPGL."); m_aboutThis = tr(GITVERSION); m_initParamsMand.clear(); - ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), tr("Width of virtual sensor chip").toLatin1().data()); + ito::Param param( + "maxXSize", + ito::ParamBase::Int, + 640, + new ito::IntMeta(4, 4096, 4), + tr("Width of virtual sensor chip").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value dividable by 4 for a 2D camera.").toLatin1().data()); + param = ito::Param( + "maxYSize", + ito::ParamBase::Int, + 480, + new ito::IntMeta(1, 4096, 1), + tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value " + "dividable by 4 for a 2D camera.") + .toLatin1() + .data()); m_initParamsOpt.append(param); - param = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2), tr("Bits per Pixel, usually 8-16bit grayvalues").toLatin1().data()); + param = ito::Param( + "bpp", + ito::ParamBase::Int, + 8, + new ito::IntMeta(8, 30, 2), + tr("Bits per Pixel, usually 8-16bit grayvalues").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("imageType", ito::ParamBase::String | ito::ParamBase::In, "noise", tr("Available dummy image types: noise (default), gaussianSpot").toLatin1().data()); + param = ito::Param( + "imageType", + ito::ParamBase::String | ito::ParamBase::In, + "noise", + tr("Available dummy image types: noise (default), gaussianSpot, gaussianSpotArray") + .toLatin1() + .data()); ito::StringMeta sm(ito::StringMeta::String, "noise"); sm.addItem("gaussianSpot"); sm.addItem("gaussianSpotArray"); @@ -228,24 +249,28 @@ DummyGrabberInterface::~DummyGrabberInterface() } //---------------------------------------------------------------------------------------------------------------------------------- -// this makro registers the class DummyGrabberInterface with the name DummyGrabberinterface as plugin for the Qt-System (see Qt-DOC) +// this makro registers the class DummyGrabberInterface with the name DummyGrabberinterface as +// plugin for the Qt-System (see Qt-DOC) //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyGrabber - \brief Class for the DummyGrabber. The DummyGrabber is able to create noisy images or simulate a typical WLI or confocal image signal. + \brief Class for the DummyGrabber. The DummyGrabber is able to create noisy images or simulate a + typical WLI or confocal image signal. - Usually every method in this class can be executed in an own thread. Only the constructor, destructor, showConfDialog will be executed by the - main (GUI) thread. + Usually every method in this class can be executed in an own thread. Only the constructor, + destructor, showConfDialog will be executed by the main (GUI) thread. */ //---------------------------------------------------------------------------------------------------------------------------------- -//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the addIn-Manager. +//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is +//! usually called by the addIn-Manager. /*! - creates new instance of dialogDummyGrabber, calls the method setVals of dialogDummyGrabber, starts the execution loop and if the dialog - is closed, reads the new parameter set and deletes the dialog. + creates new instance of dialogDummyGrabber, calls the method setVals of dialogDummyGrabber, + starts the execution loop and if the dialog is closed, reads the new parameter set and deletes + the dialog. \return retOk \sa dialogDummyGrabber @@ -258,88 +283,159 @@ const ito::RetVal DummyGrabber::showConfDialog(void) //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for DummyGrabber /*! - In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. - Additionally the optional docking widget for the DummyGrabber's toolbar is instantiated and created by createDockWidget. + In this constructor the m_params-vector with all parameters, which are accessible by getParam or + setParam, is built. Additionally the optional docking widget for the DummyGrabber's toolbar is + instantiated and created by createDockWidget. \param [in] uniqueID is an unique identifier for this DummyGrabber-instance \sa ito::tParam, createDockWidget, setParam, getParam */ DummyGrabber::DummyGrabber() : - AddInGrabber(), - m_isgrabbing(false), - m_totalBinning(1), - m_lineCamera(false), + AddInGrabber(), m_isgrabbing(false), m_totalBinning(1), m_lineCamera(false), + m_startOfLastAcquisition(0), m_imageType(imgTypeNoise) { - ito::DoubleMeta *dm; + ito::DoubleMeta* dm; - ito::Param paramVal("name", ito::ParamBase::String | ito::ParamBase::Readonly, "DummyGrabber", "GrabberName"); + ito::Param paramVal( + "name", ito::ParamBase::String | ito::ParamBase::Readonly, "DummyGrabber", "GrabberName"); paramVal.setMeta(new ito::StringMeta(ito::StringMeta::String, "General"), true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + paramVal = ito::Param( + "frame_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.0, + tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.") + .toLatin1() + .data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).").toLatin1().data()); + paramVal = ito::Param( + "integration_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.0, + tr("Minimum integration time for an acquisition [s], default: 0.0 (as fast as possible).") + .toLatin1() + .data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + paramVal = ito::Param( + "gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + paramVal = ito::Param( + "offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); //show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal = ito::Param( + "binning", + ito::ParamBase::Int, + 101, + 404, + 101, + tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, tr("size in x (cols) [px]").toLatin1().data()); + paramVal = ito::Param( + "sizex", + ito::ParamBase::Int | ito::ParamBase::Readonly, + 4, + 4096, + 4096, + tr("size in x (cols) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, tr("size in y (rows) [px]").toLatin1().data()); + paramVal = ito::Param( + "sizey", + ito::ParamBase::Int | ito::ParamBase::Readonly, + 1, + 4096, + 4096, + tr("size in y (rows) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); m_params.insert(paramVal.getName(), paramVal); int roi[] = {0, 0, 2048, 2048}; - paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); - ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + paramVal = ito::Param( + "roi", + ito::ParamBase::IntArray, + 4, + roi, + tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); + ito::RectMeta* rm = new ito::RectMeta( + ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), + ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), + "ImageFormatControl"); paramVal.setMeta(rm, true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("bpp", ito::ParamBase::Int, 8, new ito::IntMeta(8, 30, 2, "ImageFormatControl"), tr("bitdepth of images").toLatin1().data()); + paramVal = ito::Param( + "bpp", + ito::ParamBase::Int, + 8, + new ito::IntMeta(8, 30, 2, "ImageFormatControl"), + tr("bitdepth of images").toLatin1().data()); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + paramVal = ito::Param( + "demoRegexpString", + ito::ParamBase::String, + "", + tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + paramVal = ito::Param( + "demoWildcardString", + ito::ParamBase::String, + "test.bmp", + tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - ito::StringMeta *sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + paramVal = ito::Param( + "demoEnumString", + ito::ParamBase::String, + "mode 1", + tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + ito::StringMeta* sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); sm->addItem("mode 2"); sm->addItem("mode 3"); paramVal.setMeta(sm, true); m_params.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", tr("any string allowed").toLatin1().data()); + paramVal = ito::Param( + "demoArbitraryString", + ito::ParamBase::String, + "any string", + tr("any string allowed").toLatin1().data()); sm = new ito::StringMeta(ito::StringMeta::String); sm->setCategory("DemoParameters"); paramVal.setMeta(sm, true); @@ -365,11 +461,12 @@ DummyGrabber::DummyGrabber() : if (hasGuiSupport()) { - //now create dock widget for this plugin - DockWidgetDummyGrabber *dw = new DockWidgetDummyGrabber(this); + // now create dock widget for this plugin + DockWidgetDummyGrabber* dw = new DockWidgetDummyGrabber(this); Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | + QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } } @@ -383,24 +480,32 @@ DummyGrabber::~DummyGrabber() } //---------------------------------------------------------------------------------------------------------------------------------- -//! init method which is called by the addInManager after the initiation of a new instance of DummyGrabber. +//! init method which is called by the addInManager after the initiation of a new instance of +//! DummyGrabber. /*! - This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given parameters to the - internal m_params-vector. Notice that this method is called after that this instance has been moved to its own (non-gui) thread. + This init method gets the mandatory and optional parameter vectors of type tParam and must copy + these given parameters to the internal m_params-vector. Notice that this method is called after + that this instance has been moved to its own (non-gui) thread. \param [in] paramsMand is a pointer to the vector of mandatory tParams. \param [in] paramsOpt is a pointer to the vector of optional tParams. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk */ -ito::RetVal DummyGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::init( + QVector* /*paramsMand*/, + QVector* paramsOpt, + ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retVal; - int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth + int sizeX = paramsOpt->at(0) + .getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = + paramsOpt->at(1) + .getVal(); // second optional parameter, corresponding to the grabber heigth if (sizeY > 1 && sizeY % 4 != 0) { @@ -408,7 +513,8 @@ ito::RetVal DummyGrabber::init(QVector * /*paramsMand*/, QVector } else { - int bpp = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the grabber bit depth per pixel + int bpp = paramsOpt->at(2).getVal(); // third optional parameter, corresponding to the + // grabber bit depth per pixel m_params["bpp"].setVal(bpp); m_params["sizex"].setVal(sizeX); @@ -430,17 +536,24 @@ ito::RetVal DummyGrabber::init(QVector * /*paramsMand*/, QVector m_params["roi"].setVal(roi, 4); if (sizeY == 1) { - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), true); + m_params["roi"].setMeta( + new ito::RectMeta( + ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, 0, 1)), + true); } else { - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), true); + m_params["roi"].setMeta( + new ito::RectMeta( + ito::RangeMeta(0, sizeX - 1, 4, 4, sizeX, 4), + ito::RangeMeta(0, sizeY - 1, 4, 4, sizeY, 4)), + true); } } if (!retVal.containsError()) { - checkData(); //check if image must be reallocated + checkData(); // check if image must be reallocated emit parametersChanged(m_params); } @@ -469,7 +582,7 @@ ito::RetVal DummyGrabber::init(QVector * /*paramsMand*/, QVector waitCond->release(); } - setInitialized(true); //init method has been finished (independent on retval) + setInitialized(true); // init method has been finished (independent on retval) return retVal; } @@ -478,11 +591,10 @@ ito::RetVal DummyGrabber::init(QVector * /*paramsMand*/, QVector /*! notice that this method is called in the actual thread of this instance. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk - \sa ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk \sa ItomSharedSemaphore */ -ito::RetVal DummyGrabber::close(ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::close(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); @@ -511,11 +623,11 @@ ito::RetVal DummyGrabber::close(ItomSharedSemaphore *waitCond) This method copies val of the corresponding parameter value. \param [in,out] val is a shared-pointer of ito::Param. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk in case that everything is ok, else retError \sa ito::tParam, + ItomSharedSemaphore */ -ito::RetVal DummyGrabber::getParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::getParam(QSharedPointer val, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue; @@ -525,24 +637,25 @@ ito::RetVal DummyGrabber::getParam(QSharedPointer val, ItomSharedSem QString suffix; ParamMapIterator it; - //parse the given parameter-name (if you support indexed or suffix-based parameters) + // parse the given parameter-name (if you support indexed or suffix-based parameters) retValue += apiParseParamName(val->getName(), key, hasIndex, index, suffix); if (retValue == ito::retOk) { - //gets the parameter key from m_params map (read-only is allowed, since we only want to get the value). - retValue += apiGetParamFromMapByKey(m_params, key, it, false); + // gets the parameter key from m_params map (read-only is allowed, since we only want to get + // the value). + retValue += apiGetParamFromMapByKey(m_params, key, it, false); } if (!retValue.containsError()) { - *val = it.value(); + *val = it.value(); } if (waitCond) { - waitCond->returnValue = retValue; - waitCond->release(); + waitCond->returnValue = retValue; + waitCond->release(); } return retValue; @@ -554,11 +667,12 @@ ito::RetVal DummyGrabber::getParam(QSharedPointer val, ItomSharedSem This method copies the given value to the m_params-parameter. \param [in] val is the ito::ParamBase value to set. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk in case that everything is ok, else retError \sa ito::tParam, + ItomSharedSemaphore */ -ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::setParam( + QSharedPointer val, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue; @@ -574,7 +688,8 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare if (!retValue.containsError()) { - //gets the parameter key from m_params map (read-only is not allowed and leads to ito::retError). + // gets the parameter key from m_params map (read-only is not allowed and leads to + // ito::retError). retValue += apiGetParamFromMapByKey(m_params, key, it, true); } @@ -585,7 +700,7 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare if (!retValue.containsError()) { - //first check parameters that influence the size or data type of m_data + // first check parameters that influence the size or data type of m_data if (key == "roi" || key == "binning" || key == "bpp") { if (!retValue.containsError()) @@ -627,11 +742,17 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare if (m_lineCamera && (newY != 1)) { - retValue += ito::RetVal(ito::retError, 0, "the vertical binning for a line camera must be 1"); + retValue += ito::RetVal( + ito::retError, 0, "the vertical binning for a line camera must be 1"); } - else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) + else if ( + (newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) { - retValue += ito::RetVal(ito::retError, 0, "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + horizontal)"); + retValue += ito::RetVal( + ito::retError, + 0, + "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + " + "horizontal)"); } else { @@ -653,10 +774,12 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare int maxHeight = m_params["sizey"].getMax(); m_params["sizex"].setVal(width); - m_params["sizex"].setMeta(new ito::IntMeta(4/newX, maxWidth * factorX, 4/newX), true); + m_params["sizex"].setMeta( + new ito::IntMeta(4 / newX, maxWidth * factorX, 4 / newX), true); m_params["sizey"].setVal(height); - m_params["sizey"].setMeta(new ito::IntMeta(4/newY, maxHeight * factorY, 4/newY), true); + m_params["sizey"].setMeta( + new ito::IntMeta(4 / newY, maxHeight * factorY, 4 / newY), true); int sizeX = m_params["roi"].getVal()[2] * factorX; int sizeY = m_params["roi"].getVal()[3] * factorY; @@ -664,12 +787,23 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare int offsetY = m_params["roi"].getVal()[1] * factorY; int roi[] = {offsetX, offsetY, sizeX, sizeY}; m_params["roi"].setVal(roi, 4); - m_params["roi"].setMeta(new ito::RectMeta(ito::RangeMeta(0, width - 1,4/newX,4/newX,maxWidth * factorX,4/newX), ito::RangeMeta(0, height - 1,4/newY,4/newY,maxHeight * factorY,4/newY)), true); + m_params["roi"].setMeta( + new ito::RectMeta( + ito::RangeMeta( + 0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), + ito::RangeMeta( + 0, + height - 1, + 4 / newY, + 4 / newY, + maxHeight * factorY, + 4 / newY)), + true); } } } - retValue += checkData(); //check if image must be reallocated + retValue += checkData(); // check if image must be reallocated if (running) { @@ -700,19 +834,21 @@ ito::RetVal DummyGrabber::setParam(QSharedPointer val, ItomShare //---------------------------------------------------------------------------------------------------------------------------------- //! With startDevice this camera is initialized. /*! - In the DummyGrabber, this method does nothing. In general, the hardware camera should be intialized in this method and necessary memory should be allocated. + In the DummyGrabber, this method does nothing. In general, the hardware camera should be + intialized in this method and necessary memory should be allocated. \note This method is similar to VideoCapture::open() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if starting was successfull, retWarning if startDevice has been calling at least twice. + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk if starting was successfull, retWarning if startDevice has been calling + at least twice. */ -ito::RetVal DummyGrabber::startDevice(ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::startDevice(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue = ito::retOk; - checkData(); //this will be reallocated in this method. + checkData(); // this will be reallocated in this method. incGrabberStarted(); @@ -734,15 +870,16 @@ ito::RetVal DummyGrabber::startDevice(ItomSharedSemaphore *waitCond) //---------------------------------------------------------------------------------------------------------------------------------- //! With stopDevice the camera device is stopped (opposite to startDevice) /*! - In this DummyGrabber, this method does nothing. In general, the hardware camera should be closed in this method. + In this DummyGrabber, this method does nothing. In general, the hardware camera should be closed + in this method. \note This method is similar to VideoCapture::release() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera wasn't started before - \sa startDevice + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk if everything is ok, retError if camera wasn't started before \sa + startDevice */ -ito::RetVal DummyGrabber::stopDevice(ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::stopDevice(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue = ito::retOk; @@ -750,7 +887,12 @@ ito::RetVal DummyGrabber::stopDevice(ItomSharedSemaphore *waitCond) decGrabberStarted(); if (grabberStartedCount() < 0) { - retValue += ito::RetVal(ito::retWarning, 1001, tr("stopDevice of DummyGrabber can not be executed, since camera has not been started.").toLatin1().data()); + retValue += ito::RetVal( + ito::retWarning, + 1001, + tr("stopDevice of DummyGrabber can not be executed, since camera has not been started.") + .toLatin1() + .data()); setGrabberStarted(0); } @@ -766,17 +908,18 @@ ito::RetVal DummyGrabber::stopDevice(ItomSharedSemaphore *waitCond) //---------------------------------------------------------------------------------------------------------------------------------- //! Call this method to trigger a new image. /*! - By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, this method is called. - The new image is then stored either in internal camera memory or in internal memory of this class. + By this method a new image is trigger by the camera, that means the acquisition of the image + starts in the moment, this method is called. The new image is then stored either in internal + camera memory or in internal memory of this class. \note This method is similar to VideoCapture::grab() of openCV \param [in] trigger may describe the trigger parameter (unused here) - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which has not be fetched by getVal, yet. - \sa getVal + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk if everything is ok, retError if camera has not been started or an older + image lies in memory which has not be fetched by getVal, yet. \sa getVal */ -ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue = ito::retOk; @@ -800,7 +943,12 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa } else if (grabberStartedCount() <= 0) { - retValue += ito::RetVal(ito::retError, 1002, tr("Acquire of DummyGrabber can not be executed, since camera has not been started.").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1002, + tr("Acquire of DummyGrabber can not be executed, since camera has not been started.") + .toLatin1() + .data()); } else { @@ -817,19 +965,18 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa } m_startOfLastAcquisition = cv::getTickCount(); - //ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); - cv::RNG &rng = cv::theRNG(); + // ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); + cv::RNG& rng = cv::theRNG(); if (m_imageType == imgTypeNoise) { - if (m_totalBinning == 1) { if (bpp < 9) { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint8 *linePtr; + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -843,8 +990,8 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa } else if (bpp < 17) { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint16 *linePtr; + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -858,8 +1005,8 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa } else if (bpp < 32) { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::int32 *linePtr; + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -876,8 +1023,8 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa { if (bpp < 9) { - ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint8 *linePtr; + ito::uint8 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint8* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -885,14 +1032,15 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa for (int n = 0; n < m_data.getSize(1); ++n) { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); } } } else if (bpp < 17) { - ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::uint16 *linePtr; + ito::uint16 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::uint16* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -900,14 +1048,15 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa for (int n = 0; n < m_data.getSize(1); ++n) { - *linePtr++ = fastrand_mean(rng, maxInt,m_totalBinning, offset, gain); + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); } } } else if (bpp < 32) { - ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp)-1); - ito::int32 *linePtr; + ito::int32 maxInt = cv::saturate_cast(cv::pow(2.0, bpp) - 1); + ito::int32* linePtr; for (int m = 0; m < m_data.getSize(0); ++m) { @@ -915,18 +1064,15 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa for (int n = 0; n < m_data.getSize(1); ++n) { - *linePtr++ = fastrand_mean(rng, maxInt, m_totalBinning, offset, gain); + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); } } } } - } - else if(m_imageType == imgTypeGaussianSpot) //create dummy Gaussian image + else if (m_imageType == imgTypeGaussianSpot) // create dummy Gaussian image { - - cv::RNG& rng = cv::theRNG(); - if (bpp < 9) { ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); @@ -943,10 +1089,9 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa gaussFunc(rng, m_data, amplitude); } } - else if (m_imageType == imgTypeGaussianSpotArray) //create dummy Gaussian image + else if (m_imageType == imgTypeGaussianSpotArray) // create dummy Gaussian image { ito::DataObject droi; - cv::RNG& rng = cv::theRNG(); int width = m_data.getSize(1); int height = m_data.getSize(0); @@ -954,10 +1099,11 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa int roiwidth = (int)width / 2; int roiheight = (int)height / 2; - int roi[4][4] = { { -0, -roiheight, -roiwidth, 0 }, - { -0, -roiheight, 0, -roiwidth }, - { -roiheight, 0, -roiwidth, 0 }, - { -roiheight, 0, 0, -roiwidth } }; + int roi[4][4] = { + {-0, -roiheight, -roiwidth, 0}, + {-0, -roiheight, 0, -roiwidth}, + {-roiheight, 0, -roiwidth, 0}, + {-roiheight, 0, 0, -roiwidth}}; for (int cnt = 0; cnt < 4; cnt++) { @@ -980,92 +1126,6 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa gaussFunc(rng, droi, amplitude); } } - - - - - //// take 1 rechts oben - //droi = droi.adjustROI(- 0, - roiheight, -roiwidth, 0); // rechts unten - - //if (bpp < 9) - //{ - // ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 17) - //{ - // ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 32) - //{ - // ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - - //// take 2 - //droi = m_data; - //droi = droi.adjustROI(-0, -roiheight, 0, - roiwidth); // links unten - - //if (bpp < 9) - //{ - // ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 17) - //{ - // ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 32) - //{ - // ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - - //// take 3 - //droi = m_data; - //droi = droi.adjustROI(- roiheight, 0, - roiwidth, 0); // rechts oben - - //if (bpp < 9) - //{ - // ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 17) - //{ - // ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 32) - //{ - // ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - - //// take 4 - //droi = m_data; - //droi = droi.adjustROI(-roiheight, 0, 0, -roiwidth); // links oben - - //if (bpp < 9) - //{ - // ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 17) - //{ - // ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - //else if (bpp < 32) - //{ - // ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, bpp) - 1); - // gaussFunc(rng, droi, amplitude); - //} - - - - } if (integration_time > 0.0) @@ -1089,15 +1149,16 @@ ito::RetVal DummyGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *wa \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is shallow-copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to + ito::DataObject*) where the acquired image is shallow-copied to. \param [in] waitCond is the + semaphore (default: NULL), which is released if this method has been terminated \return retOk if + everything is ok, retError is camera has not been started or no image has been acquired by the + method acquire. \sa DataObject, acquire */ -ito::RetVal DummyGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::getVal(void* vpdObj, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); - ito::DataObject *dObj = reinterpret_cast(vpdObj); + ito::DataObject* dObj = reinterpret_cast(vpdObj); ito::RetVal retValue(ito::retOk); @@ -1107,11 +1168,15 @@ ito::RetVal DummyGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) { if (dObj == NULL) { - retValue += ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1004, + tr("data object of getVal is NULL or cast failed").toLatin1().data()); } else { - retValue += sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + retValue += sendDataToListeners(0); // don't wait for live image, since user should get + // the image as fast as possible. (*dObj) = this->m_data; } @@ -1119,7 +1184,7 @@ ito::RetVal DummyGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) if (waitCond) { - waitCond->returnValue=retValue; + waitCond->returnValue = retValue; waitCond->release(); } @@ -1129,25 +1194,27 @@ ito::RetVal DummyGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) //---------------------------------------------------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! - This method copies the recently grabbed camera frame to the given DataObject. Therefore this camera size must fit to the data structure of the - DataObject. + This method copies the recently grabbed camera frame to the given DataObject. Therefore this + camera size must fit to the data structure of the DataObject. \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where the acquired image is deep copied to. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError is camera has not been started or no image has been acquired by the method acquire. - \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to + ito::DataObject*) where the acquired image is deep copied to. \param [in] waitCond is the + semaphore (default: NULL), which is released if this method has been terminated \return retOk if + everything is ok, retError is camera has not been started or no image has been acquired by the + method acquire. \sa DataObject, acquire */ -ito::RetVal DummyGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) +ito::RetVal DummyGrabber::copyVal(void* vpdObj, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue(ito::retOk); - ito::DataObject *dObj = reinterpret_cast(vpdObj); + ito::DataObject* dObj = reinterpret_cast(vpdObj); if (!dObj) { - retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); } else { @@ -1161,7 +1228,8 @@ ito::RetVal DummyGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) if (!retValue.containsError()) { - sendDataToListeners(0); //don't wait for live image, since user should get the image as fast as possible. + sendDataToListeners( + 0); // don't wait for live image, since user should get the image as fast as possible. } if (waitCond) @@ -1174,13 +1242,16 @@ ito::RetVal DummyGrabber::copyVal(void *vpdObj, ItomSharedSemaphore *waitCond) } //---------------------------------------------------------------------------------------------------------------------------------- -ito::RetVal DummyGrabber::retrieveData(ito::DataObject *externalDataObject) +ito::RetVal DummyGrabber::retrieveData(ito::DataObject* externalDataObject) { ito::RetVal retValue(ito::retOk); if (m_isgrabbing == false) { - retValue += ito::RetVal(ito::retError, 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1002, + tr("image could not be obtained since no image has been acquired.").toLatin1().data()); } else { @@ -1200,15 +1271,23 @@ void DummyGrabber::dockWidgetVisibilityChanged(bool visible) { if (getDockWidget()) { - QWidget *widget = getDockWidget()->widget(); + QWidget* widget = getDockWidget()->widget(); if (visible) { - connect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + connect( + this, + SIGNAL(parametersChanged(QMap)), + widget, + SLOT(parametersChanged(QMap))); emit parametersChanged(m_params); } else { - disconnect(this, SIGNAL(parametersChanged(QMap)), widget, SLOT(parametersChanged(QMap))); + disconnect( + this, + SIGNAL(parametersChanged(QMap)), + widget, + SLOT(parametersChanged(QMap))); } } } diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index fd34e1bdf..052c45b70 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -25,24 +25,14 @@ #include "DummyMultiChannelGrabber.h" -#define _USE_MATH_DEFINES // needs to be defined to enable standard declartions of PI constant -#include "math.h" - #ifndef WIN32 #include #endif + #include -#include -#include -#include #include "dockWidgetDummyMultiChannelGrabber.h" -#include -#include -#include -#include "common/helperCommon.h" -#include "common/paramMeta.h" #include "gitVersion.h" #include "pluginVersion.h" @@ -56,7 +46,7 @@ * * This function delivers the noise for the image. */ -template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offset, float gain) +template inline _Tp fastrand(cv::RNG& rng, _Tp maxval, float offset, float gain) { return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } @@ -68,7 +58,7 @@ template inline _Tp fastrand(cv::RNG &rng, _Tp maxval, float offs * This function delivers the noise for the image. */ template -inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) +inline _Tp fastrand_mean(cv::RNG& rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) { ito::uint32 val = 0; @@ -80,20 +70,60 @@ inline _Tp fastrand_mean(cv::RNG &rng, _Tp maxval, ito::uint8 numMeans, float of return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); } +//---------------------------------------------------------------------------------------------------------------------------------- +/** @func gaussFunc + * @brief function for 2d Gaussian function + * + * This function delivers a 2d dataObject with a Gaussian function + */ +template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject dObj, float amplitude) +{ + int width = dObj.getSize(1); + int height = dObj.getSize(0); + _Tp* rowPtr; + float xval, yval; + int planeID = dObj.seekMat(0); + + float yRandOffset = rng.uniform(0.f, 20.f); + float xRandOffset = rng.uniform(0.f, 20.f); + float aRandOfset = rng.uniform(0.f, 20.f); + + float sigmaX = width * rng.uniform(0.09f, 0.11f); + float sigmaY = height * rng.uniform(0.09f, 0.11f); + + for (int y = 0; y < height; y++) + { + rowPtr = dObj.rowPtr<_Tp>(planeID, y); + yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / + (2.0f * sigmaY * sigmaY); + + for (int x = 0; x < width; x++) + { + xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / + (2.0f * sigmaX * sigmaX); + rowPtr[x] = (float)(amplitude - aRandOfset) * exp(-(xval + yval)); + } + } + + return ito::retOk; +} + //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyMultiChannelGrabberInterface - \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic information about - DummyMultiChannelGrabber as is able to create one or more new instances of DummyMultiChannelGrabber. + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic + information about DummyMultiChannelGrabber as is able to create one or more new instances of + DummyMultiChannelGrabber. */ //---------------------------------------------------------------------------------------------------------------------------------- //! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. /*! \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created - DummyMultiChannelGrabber-instance is stored in *addInInst \return retOk \sa DummyMultiChannelGrabber + DummyMultiChannelGrabber-instance is stored in *addInInst \return retOk \sa + DummyMultiChannelGrabber */ -ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **addInInst) +ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase** addInInst) { NEW_PLUGININSTANCE(DummyMultiChannelGrabber) return ito::retOk; @@ -106,7 +136,7 @@ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase **add \return retOk \sa DummyMultiChannelGrabber */ -ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **addInInst) +ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase** addInInst) { REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) return ito::retOk; @@ -115,9 +145,10 @@ ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase **ad //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for interace /*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real plugin (here: - DummyMultiChannelGrabber) should or must be initialized (e.g. by a Python call) with mandatory or optional - parameters, please initialize both vectors m_initParamsMand and m_initParamsOpt within this constructor. + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real + plugin (here: DummyMultiChannelGrabber) should or must be initialized (e.g. by a Python call) + with mandatory or optional parameters, please initialize both vectors m_initParamsMand and + m_initParamsOpt within this constructor. */ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() { @@ -131,22 +162,26 @@ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() /* char docstring[] = \ "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ - The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple + The camera is initialized with a maximum width and height of the simulated camera chip (both + need to be a multiple of 4). \ - The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of + The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per + pixel). The real size of the camera \ - image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera + image is controlled using the parameter 'roi' if the sizes stay within the limits given by the + size of the camera chip.\n\ \n\ - You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is + You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line + camera whose height is equal to 1. \n\ \n\ This plugin can also be used as template for other grabber.";*/ m_description = QObject::tr("A virtual white noise grabber"); // m_detaildescription = QObject::tr(docstring); - m_detaildescription = - QObject::tr("The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + m_detaildescription = QObject::tr( + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ @@ -165,28 +200,57 @@ This plugin can also be used as template for other grabber."); m_initParamsMand.clear(); - ito::Param param("maxXSize", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), - tr("Width of virtual sensor chip").toLatin1().data()); + ito::Param param( + "maxXSize", + ito::ParamBase::Int, + 640, + new ito::IntMeta(4, 4096, 4), + tr("Width of virtual sensor chip").toLatin1().data()); m_initParamsOpt.append(param); - param = ito::Param("maxYSize", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), - tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value " - "dividable by 4 for a 2D camera.") - .toLatin1() - .data()); + param = ito::Param( + "maxYSize", + ito::ParamBase::Int, + 480, + new ito::IntMeta(1, 4096, 1), + tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value " + "dividable by 4 for a 2D camera.") + .toLatin1() + .data()); m_initParamsOpt.append(param); - param = ito::Param("pixelFormat", ito::ParamBase::String, "mono8", - tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); - ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + param = ito::Param( + "pixelFormat", + ito::ParamBase::String, + "mono8", + tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); m->addItem("mono10"); m->addItem("mono12"); m->addItem("mono16"); param.setMeta(m, true); m_initParamsOpt.append(param); - param = ito::Param("numberOfChannels", ito::ParamBase::Int, 2, new ito::IntMeta(2, 30, 1), - tr("Number of channels").toLatin1().data()); + param = ito::Param( + "numberOfChannels", + ito::ParamBase::Int, + 2, + new ito::IntMeta(2, 30, 1), + tr("Number of channels").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param( + "imageType", + ito::ParamBase::String | ito::ParamBase::In, + "noise", + tr("Available dummy image types: noise (default), gaussianSpot, gaussianSpotArray") + .toLatin1() + .data()); + ito::StringMeta sm(ito::StringMeta::String, "noise"); + sm.addItem("gaussianSpot"); + sm.addItem("gaussianSpotArray"); + param.setMeta(&sm, false); + m_initParamsOpt.append(param); } @@ -202,26 +266,27 @@ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() } //---------------------------------------------------------------------------------------------------------------------------------- -// this makro registers the class DummyMultiChannelGrabberInterface with the name DummyMultiChannelGrabberinterface as -// plugin for the Qt-System (see Qt-DOC) +// this makro registers the class DummyMultiChannelGrabberInterface with the name +// DummyMultiChannelGrabberinterface as plugin for the Qt-System (see Qt-DOC) //---------------------------------------------------------------------------------------------------------------------------------- /*! \class DummyMultiChannelGrabber - \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create noisy images or - simulate a typical WLI or confocal image signal. + \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create + noisy images or simulate a typical WLI or confocal image signal. - Usually every method in this class can be executed in an own thread. Only the constructor, destructor, - showConfDialog will be executed by the main (GUI) thread. + Usually every method in this class can be executed in an own thread. Only the constructor, + destructor, showConfDialog will be executed by the main (GUI) thread. */ //---------------------------------------------------------------------------------------------------------------------------------- -//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is usually called by the -//! addIn-Manager. +//! shows the configuration dialog. This method must be executed in the main (GUI) thread and is +//! usually called by the addIn-Manager. /*! - creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of dialogDummyMultiChannelGrabber, - starts the execution loop and if the dialog is closed, reads the new parameter set and deletes the dialog. + creates new instance of dialogDummyMultiChannelGrabber, calls the method setVals of + dialogDummyMultiChannelGrabber, starts the execution loop and if the dialog is closed, reads the + new parameter set and deletes the dialog. \return retOk \sa dialogDummyMultiChannelGrabber @@ -234,25 +299,26 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) //---------------------------------------------------------------------------------------------------------------------------------- //! constructor for DummyMultiChannelGrabber /*! - In this constructor the m_params-vector with all parameters, which are accessible by getParam or setParam, is built. - Additionally the optional docking widget for the DummyMultiChannelGrabber's toolbar is instantiated and created by - createDockWidget. + In this constructor the m_params-vector with all parameters, which are accessible by getParam or + setParam, is built. Additionally the optional docking widget for the DummyMultiChannelGrabber's + toolbar is instantiated and created by createDockWidget. \param [in] uniqueID is an unique identifier for this DummyMultiChannelGrabber-instance \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber("testtest"), m_isgrabbing(false), m_totalBinning(1), - m_lineCamera(false), m_freerunTimer(this) + AddInMultiChannelGrabber("DummyMultiChannelGrabber"), m_isgrabbing(false), m_totalBinning(1), + m_startOfLastAcquisition(0), m_lineCamera(false), m_freerunTimer(this), + m_imageType(imgTypeNoise) { if (hasGuiSupport()) { // now create dock widget for this plugin - DockWidgetDummyMultiChannelGrabber *dw = new DockWidgetDummyMultiChannelGrabber(this); + DockWidgetDummyMultiChannelGrabber* dw = new DockWidgetDummyMultiChannelGrabber(this); Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; - QDockWidget::DockWidgetFeatures features = - QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | + QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } connect(&m_freerunTimer, &QTimer::timeout, this, &DummyMultiChannelGrabber::generateImageData); } @@ -267,60 +333,84 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() } //---------------------------------------------------------------------------------------------------------------------------------- -//! init method which is called by the addInManager after the initiation of a new instance of DummyMultiChannelGrabber. +//! init method which is called by the addInManager after the initiation of a new instance of +//! DummyMultiChannelGrabber. /*! - This init method gets the mandatory and optional parameter vectors of type tParam and must copy these given - parameters to the internal m_params-vector. Notice that this method is called after that this instance has been moved - to its own (non-gui) thread. + This init method gets the mandatory and optional parameter vectors of type tParam and must copy + these given parameters to the internal m_params-vector. Notice that this method is called after + that this instance has been moved to its own (non-gui) thread. \param [in] paramsMand is a pointer to the vector of mandatory tParams. \param [in] paramsOpt is a pointer to the vector of optional tParams. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk */ -ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMand*/, QVector *paramsOpt, - ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::init( + QVector* /*paramsMand*/, + QVector* paramsOpt, + ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retVal; - int sizeX = paramsOpt->at(0).getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = paramsOpt->at(1).getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); // third optional parameter, corresponding to the number of - // channels + int sizeX = paramsOpt->at(0) + .getVal(); // first optional parameter, corresponding to the grabber width + int sizeY = + paramsOpt->at(1) + .getVal(); // second optional parameter, corresponding to the grabber heigth + int numChannel = paramsOpt->at(3).getVal(); // third optional parameter, corresponding to + // the number of channels if (sizeY > 1 && sizeY % 4 != 0) { retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); } else { - QMap standardParam; ito::Param paramVal; int roi[] = {0, 0, 2048, 2048}; - paramVal = ito::Param("roi", ito::ParamBase::IntArray, 4, roi, - tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); - ito::RectMeta *rm = new ito::RectMeta(ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), - ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), "ImageFormatControl"); + paramVal = ito::Param( + "roi", + ito::ParamBase::IntArray, + 4, + roi, + tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); + ito::RectMeta* rm = new ito::RectMeta( + ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), + ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), + "ImageFormatControl"); paramVal.setMeta(rm, true); standardParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 4, 4096, 4096, - tr("size in x (cols) [px]").toLatin1().data()); + paramVal = ito::Param( + "sizex", + ito::ParamBase::Int | ito::ParamBase::Readonly, + 4, + 4096, + 4096, + tr("size in x (cols) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); standardParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 1, 4096, 4096, - tr("size in y (rows) [px]").toLatin1().data()); + paramVal = ito::Param( + "sizey", + ito::ParamBase::Int | ito::ParamBase::Readonly, + 1, + 4096, + 4096, + tr("size in y (rows) [px]").toLatin1().data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); standardParam.insert(paramVal.getName(), paramVal); - ito::StringMeta *m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); m->addItem("mono10"); m->addItem("mono12"); m->addItem("mono16"); - paramVal = ito::Param("pixelFormat", ito::ParamBase::String, paramsOpt->at(2).getVal(), - tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); + paramVal = ito::Param( + "pixelFormat", + ito::ParamBase::String, + paramsOpt->at(2).getVal(), + tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); paramVal.setMeta(m, true); standardParam.insert(paramVal.getName(), paramVal); @@ -345,54 +435,95 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan QMap channelMap; for (int i = 0; i < numChannel; i++) { - channelMap.insert(QString("channel_%1").arg(i), - ChannelContainer(standardParam["roi"], standardParam["pixelFormat"], + channelMap.insert( + QString("channel_%1").arg(i), + ChannelContainer( + standardParam["roi"], + standardParam["pixelFormat"], standardParam["sizex"], standardParam["sizey"], - standardParam["axisOffset"], standardParam["axisScale"])); + standardParam["axisOffset"], + standardParam["axisScale"])); } channelMap["channel_1"].m_channelParam.insert( - "channelSpecificParameter", ito::Param("channelSpecificParameter", ito::ParamBase::Int, 0, 1, 1, - tr("this is a channel specific parameter").toLatin1().data())); - channelMap["channel_1"].m_channelParam["channelSpecificParameter"].getMetaT()->setCategory( - "DemoParameters"); + "channelSpecificParameter", + ito::Param( + "channelSpecificParameter", + ito::ParamBase::Int, + 0, + 1, + 1, + tr("this is a channel specific parameter").toLatin1().data())); + channelMap["channel_1"] + .m_channelParam["channelSpecificParameter"] + .getMetaT() + ->setCategory("DemoParameters"); // global params QMap globalParam; - globalParam.insert("globalParam", ito::Param("globalParam", ito::ParamBase::Int, 0, 1, 1, - tr("this is a global parameter").toLatin1().data())); - - ito::DoubleMeta *dm; + globalParam.insert( + "globalParam", + ito::Param( + "globalParam", + ito::ParamBase::Int, + 0, + 1, + 1, + tr("this is a global parameter").toLatin1().data())); + + ito::DoubleMeta* dm; paramVal = ito::Param( - "frame_time", ito::ParamBase::Double, 0.0, 60.0, 0.0, - tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.").toLatin1().data()); + "frame_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.0, + tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.") + .toLatin1() + .data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("integration_time", ito::ParamBase::Double, 0.0, 60.0, 0.001, - tr("Minimum integration time for an acquisition [s], default: 0.001.") - .toLatin1() - .data()); + paramVal = ito::Param( + "integration_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.001, + tr("Minimum integration time for an acquisition [s], default: 0.001.") + .toLatin1() + .data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); dm->setUnit("s"); - dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + paramVal = ito::Param( + "gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("offset", ito::ParamBase::Double, 0.0, 1.0, 0.0, tr("Virtual offset").toLatin1().data()); + paramVal = ito::Param( + "offset", + ito::ParamBase::Double, + 0.0, + 1.0, + 0.0, + tr("Virtual offset").toLatin1().data()); dm = paramVal.getMetaT(); dm->setCategory("AcquisitionControl"); - dm->setRepresentation(ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... globalParam.insert(paramVal.getName(), paramVal); paramVal = ito::Param( @@ -406,33 +537,52 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("binning", ito::ParamBase::Int, 101, 404, 101, - tr("Binning of different pixel, binning = x-factor * 100 + y-factor").toLatin1().data()); + paramVal = ito::Param( + "binning", + ito::ParamBase::Int, + 101, + 404, + 101, + tr("Binning of different pixel, binning = x-factor * 100 + y-factor") + .toLatin1() + .data()); paramVal.getMetaT()->setCategory("ImageFormatControl"); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoRegexpString", ito::ParamBase::String, "", - tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + paramVal = ito::Param( + "demoRegexpString", + ito::ParamBase::String, + "", + tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoWildcardString", ito::ParamBase::String, "test.bmp", - tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta(new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + paramVal = ito::Param( + "demoWildcardString", + ito::ParamBase::String, + "test.bmp", + tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); globalParam.insert(paramVal.getName(), paramVal); - paramVal = ito::Param("demoEnumString", ito::ParamBase::String, "mode 1", - tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + paramVal = ito::Param( + "demoEnumString", + ito::ParamBase::String, + "mode 1", + tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); sm->addItem("mode 2"); sm->addItem("mode 3"); paramVal.setMeta(sm, true); globalParam.insert(paramVal.getName(), paramVal); - - - paramVal = ito::Param("demoArbitraryString", ito::ParamBase::String, "any string", - tr("any string allowed").toLatin1().data()); + paramVal = ito::Param( + "demoArbitraryString", + ito::ParamBase::String, + "any string", + tr("any string allowed").toLatin1().data()); sm = new ito::StringMeta(ito::StringMeta::String); sm->setCategory("DemoParameters"); paramVal.setMeta(sm, true); @@ -457,6 +607,22 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan emit parametersChanged(m_params); } + // get type of dummy image + QString type = paramsOpt->at(4).getVal(); + + if (type == "noise") + { + m_imageType = imgTypeNoise; + } + else if (type == "gaussianSpot") + { + m_imageType = imgTypeGaussianSpot; + } + else if (type == "gaussianSpotArray") + { + m_imageType = imgTypeGaussianSpotArray; + } + setIdentifier(QString::number(getID())); if (waitCond) @@ -470,15 +636,15 @@ ito::RetVal DummyMultiChannelGrabber::init(QVector * /*paramsMan } //---------------------------------------------------------------------------------------------------------------------------------- -//! close method which is called before that this instance is deleted by the DummyMultiChannelGrabberInterface +//! close method which is called before that this instance is deleted by the +//! DummyMultiChannelGrabberInterface /*! notice that this method is called in the actual thread of this instance. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk - \sa ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk \sa ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); @@ -507,13 +673,18 @@ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore *waitCond) This method copies val of the corresponding parameter value. \param [in,out] val is a shared-pointer of ito::Param. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk in case that everything is ok, else retError \sa ito::tParam, + ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer val, const ParamMapIterator &it, - const QString &suffix, const QString &key, int index, bool hasIndex, - bool &ok) +ito::RetVal DummyMultiChannelGrabber::getParameter( + QSharedPointer val, + const ParamMapIterator& it, + const QString& suffix, + const QString& key, + int index, + bool hasIndex, + bool& ok) { ok = false; return ito::retOk; @@ -525,11 +696,19 @@ ito::RetVal DummyMultiChannelGrabber::getParameter(QSharedPointer va This method copies the given value to the m_params-parameter. \param [in] val is the ito::ParamBase value to set. - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk in case that everything is ok, else retError - \sa ito::tParam, ItomSharedSemaphore + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk in case that everything is ok, else retError \sa ito::tParam, + ItomSharedSemaphore */ -ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate) +ito::RetVal DummyMultiChannelGrabber::setParameter( + QSharedPointer& val, + const ParamMapIterator& it, + const QString& suffix, + const QString& key, + int index, + bool hasIndex, + bool& ok, + QStringList& pendingUpdate) { ito::RetVal retValue; int running = 0; // Used to check if grabber was running bevor @@ -556,13 +735,16 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer::iterator i; - for (i = m_channels.begin(); i != m_channels.end(); ++i) //we need to adapt the roi for each channel + for (i = m_channels.begin(); i != m_channels.end(); + ++i) // we need to adapt the roi for each channel { - width = (i.value().m_channelParam["roi"].getVal()[1] - - i.value().m_channelParam["roi"].getVal()[0]) * - factorX; - height = (i.value().m_channelParam["roi"].getVal()[3] - - i.value().m_channelParam["roi"].getVal()[2]) * - factorY; - - maxWidth = static_cast(i.value().m_channelParam["roi"].getMeta()) - ->getWidthRangeMeta() - .getSizeMax(); - maxHeight = static_cast(i.value().m_channelParam["roi"].getMeta()) - ->getHeightRangeMeta() - .getSizeMax(); - - sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + width = (i.value().m_channelParam["roi"].getVal()[1] - + i.value().m_channelParam["roi"].getVal()[0]) * + factorX; + height = (i.value().m_channelParam["roi"].getVal()[3] - + i.value().m_channelParam["roi"].getVal()[2]) * + factorY; + + maxWidth = + static_cast(i.value().m_channelParam["roi"].getMeta()) + ->getWidthRangeMeta() + .getSizeMax(); + maxHeight = + static_cast(i.value().m_channelParam["roi"].getMeta()) + ->getHeightRangeMeta() + .getSizeMax(); + + sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; + sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; + offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; + offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; int roi[] = {offsetX, offsetY, sizeX, sizeY}; - i.value().m_channelParam["roi"].setVal(roi, 4); + i.value().m_channelParam["roi"].setVal(roi, 4); i.value().m_channelParam["roi"].setMeta( new ito::RectMeta( - ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), - ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), + ito::RangeMeta( + 0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), + ito::RangeMeta( + 0, + height - 1, + 4 / newY, + 4 / newY, + maxHeight * factorY, + 4 / newY)), true); if (i.key() == m_params["defaultChannel"].getVal()) { m_params["roi"].setVal(roi, 4); m_params["roi"].setMeta( new ito::RectMeta( - ito::RangeMeta(0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), - ito::RangeMeta(0, height - 1, 4 / newY, 4 / newY, maxHeight * factorY, 4 / newY)), + ito::RangeMeta( + 0, + width - 1, + 4 / newX, + 4 / newX, + maxWidth * factorX, + 4 / newX), + ito::RangeMeta( + 0, + height - 1, + 4 / newY, + 4 / newY, + maxHeight * factorY, + 4 / newY)), true); } } - pendingUpdate << "roi" << "binning"; //add roi to update list to trigger a update of sizey and sizey + pendingUpdate << "roi" + << "binning"; // add roi to update list to trigger a update of + // sizey and sizey } } } @@ -629,7 +835,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter(QSharedPointer(), "freerun") == 0) { - m_freerunTimer.start(int((m_params["frame_time"].getVal()+m_params["integration_time"].getVal()) * 1000.0)); + m_freerunTimer.start( + int((m_params["frame_time"].getVal() + + m_params["integration_time"].getVal()) * + 1000.0)); } if (waitCond) { @@ -704,16 +914,16 @@ ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore *waitCond) //---------------------------------------------------------------------------------------------------------------------------------- //! With stopDevice the camera device is stopped (opposite to startDevice) /*! - In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera should be closed in this - method. + In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera + should be closed in this method. \note This method is similar to VideoCapture::release() of openCV - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera wasn't started before - \sa startDevice + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk if everything is ok, retError if camera wasn't started before \sa + startDevice */ -ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue = ito::retOk; @@ -722,8 +932,10 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore *waitCond) if (grabberStartedCount() < 0) { retValue += ito::RetVal( - ito::retWarning, 1001, - tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not been started.") + ito::retWarning, + 1001, + tr("stopDevice of DummyMultiChannelGrabber can not be executed, since camera has not " + "been started.") .toLatin1() .data()); setGrabberStarted(0); @@ -770,7 +982,8 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() if (!retValue.containsError()) { m_isgrabbing = true; - if (strcmp(m_params["triggerMode"].getVal(), "software") == 0 && (frame_time > 0.0)) + if (strcmp(m_params["triggerMode"].getVal(), "software") == 0 && + (frame_time > 0.0)) { double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); @@ -784,85 +997,159 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() // ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); cv::RNG& rng = cv::theRNG(); - if (m_totalBinning == 1) + if (m_imageType == imgTypeNoise) { - if (max < 256) + if (m_totalBinning == 1) { - ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8* linePtr; - foreach (ChannelContainer container, m_channels) + if (max < 256) { - ito::DataObject& channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) + ito::uint8 maxInt = cv::saturate_cast(max); + ito::uint8* linePtr; + foreach (ChannelContainer container, m_channels) { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) + ito::DataObject& channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) { - *linePtr++ = fastrand(rng, maxInt, offset, gain); + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } + } + } + } + else if (max < 65536) + { + ito::uint16 maxInt = cv::saturate_cast(max); + ito::uint16* linePtr; + foreach (ChannelContainer container, m_channels) + { + ito::DataObject& channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand(rng, maxInt, offset, gain); + } } } } } - else if (max < 65536) + else { - ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16* linePtr; - foreach (ChannelContainer container, m_channels) + if (max < 256) { - ito::DataObject& channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) + ito::uint8 maxInt = cv::saturate_cast(max); + ito::uint8* linePtr; + foreach (ChannelContainer container, m_channels) { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) + ito::DataObject& channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) { - *linePtr++ = fastrand(rng, maxInt, offset, gain); + linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); + } + } + } + } + else if (max < 65536) + { + ito::uint16 maxInt = cv::saturate_cast(max); + ito::uint16* linePtr; + foreach (ChannelContainer container, m_channels) + { + ito::DataObject& channelObj = container.data; + for (int m = 0; m < channelObj.getSize(0); ++m) + { + linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) + { + *linePtr++ = fastrand_mean( + rng, maxInt, m_totalBinning, offset, gain); + } } } } } } - else + else if (m_imageType == imgTypeGaussianSpot) // create dummy Gaussian image { if (max < 256) { - ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8* linePtr; + ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, 8) - 1); foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean( - rng, maxInt, m_totalBinning, offset, gain); - } - } + gaussFunc(rng, container.data, amplitude); } } else if (max < 65536) { - ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16* linePtr; + ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, 16) - 1); + foreach (ChannelContainer container, m_channels) + { + gaussFunc(rng, container.data, amplitude); + } + } + else if (max < 2147483647) + { + ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, 32) - 1); + foreach (ChannelContainer container, m_channels) + { gaussFunc(rng, container.data, amplitude); + } + } + } + else if (m_imageType == imgTypeGaussianSpotArray) + { + ito::DataObject droi; + + int width = + this->m_channels[m_params["defaultChannel"].getVal()].data.getSize(1); + int height = + this->m_channels[m_params["defaultChannel"].getVal()].data.getSize(0); + + int roiwidth = (int)width / 2; + int roiheight = (int)height / 2; + + int roi[4][4] = { + {-0, -roiheight, -roiwidth, 0}, + {-0, -roiheight, 0, -roiwidth}, + {-roiheight, 0, -roiwidth, 0}, + {-roiheight, 0, 0, -roiwidth}}; + + for (int cnt = 0; cnt < 4; cnt++) + { foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; - for (int m = 0; m < channelObj.getSize(0); ++m) + droi = container.data; + droi = droi.adjustROI(roi[cnt][0], roi[cnt][1], roi[cnt][2], roi[cnt][3]); + + if (max < 256) { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean( - rng, maxInt, m_totalBinning, offset, gain); - } + ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, 8) - 1); + gaussFunc(rng, droi, amplitude); + } + else if (max < 65536) + { + ito::uint16 amplitude = + cv::saturate_cast(cv::pow(2.0, 16) - 1); + gaussFunc(rng, droi, amplitude); + } + else if (max < 2147483647) + { + ito::uint32 amplitude = + cv::saturate_cast(cv::pow(2.0, 32) - 1); + gaussFunc(rng, droi, amplitude); } } } } - if((strcmp(m_params["triggerMode"].getVal(), "software") == 0) && - (integration_time > 0.0)) + if ((strcmp(m_params["triggerMode"].getVal(), "software") == 0) && + (integration_time > 0.0)) { double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); @@ -873,7 +1160,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() } } ////pack all channel images to a QMap - QSharedPointer > returnMap(new QMap); + QSharedPointer> returnMap(new QMap); QMap::iterator it = m_channels.begin(); while (it != m_channels.end()) { @@ -887,25 +1174,24 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() //---------------------------------------------------------------------------------------------------------------------------------- //! Call this method to trigger a new image. /*! - By this method a new image is trigger by the camera, that means the acquisition of the image starts in the moment, - this method is called. The new image is then stored either in internal camera memory or in internal memory of this - class. + By this method a new image is trigger by the camera, that means the acquisition of the image + starts in the moment, this method is called. The new image is then stored either in internal + camera memory or in internal memory of this class. \note This method is similar to VideoCapture::grab() of openCV \param [in] trigger may describe the trigger parameter (unused here) - \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been terminated - \return retOk if everything is ok, retError if camera has not been started or an older image lies in memory which - has not be fetched by getVal, yet. \sa getVal + \param [in] waitCond is the semaphore (default: NULL), which is released if this method has been + terminated \return retOk if everything is ok, retError if camera has not been started or an older + image lies in memory which has not be fetched by getVal, yet. \sa getVal */ -ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedSemaphore* waitCond) { ito::RetVal retValue = ito::retOk; ItomSharedSemaphoreLocker locker(waitCond); - if (strcmp(m_params["triggerMode"].getVal(), "software")==0) + if (strcmp(m_params["triggerMode"].getVal(), "software") == 0) { retValue += generateImageData(); - } else { @@ -924,7 +1210,6 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS } - return retValue; } @@ -935,15 +1220,16 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to ito::DataObject*) where - the acquired image is shallow-copied to. \param [in] waitCond is the semaphore (default: NULL), which is released if - this method has been terminated \return retOk if everything is ok, retError is camera has not been started or no - image has been acquired by the method acquire. \sa DataObject, acquire + \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to + ito::DataObject*) where the acquired image is shallow-copied to. \param [in] waitCond is the + semaphore (default: NULL), which is released if this method has been terminated \return retOk if + everything is ok, retError is camera has not been started or no image has been acquired by the + method acquire. \sa DataObject, acquire */ -ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore *waitCond) +ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); - ito::DataObject *dObj = reinterpret_cast(vpdObj); + ito::DataObject* dObj = reinterpret_cast(vpdObj); ito::RetVal retValue(ito::retOk); @@ -953,15 +1239,17 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore * { if (dObj == NULL) { - retValue += - ito::RetVal(ito::retError, 1004, tr("data object of getVal is NULL or cast failed").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1004, + tr("data object of getVal is NULL or cast failed").toLatin1().data()); } else { - retValue += sendDataToListeners( - 0); // don't wait for live image, since user should get the image as fast as possible. + retValue += sendDataToListeners(0); // don't wait for live image, since user should get + // the image as fast as possible. - (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; + (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; } } @@ -974,7 +1262,8 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void *vpdObj, ItomSharedSemaphore * return retValue; } -ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointer> dataObjMap) +ito::RetVal DummyMultiChannelGrabber::getValByMap( + QSharedPointer> dataObjMap) { ito::RetVal retValue(ito::retOk); @@ -984,12 +1273,15 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointer of getVal is NULL").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1004, + tr("QMap of getVal is NULL").toLatin1().data()); } else { - retValue += sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. + retValue += sendDataToListeners(0); // don't wait for live image, since user should get + // the image as fast as possible. QMap::iterator it = (*dataObjMap).begin(); while (it != (*dataObjMap).end()) { @@ -1001,13 +1293,16 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap(QSharedPointer> dataObjMap) +ito::RetVal DummyMultiChannelGrabber::retrieveData( + QSharedPointer> dataObjMap) { ito::RetVal retValue(ito::retOk); if (m_isgrabbing == false) { - retValue += ito::RetVal(ito::retError, 1002, + retValue += ito::RetVal( + ito::retError, + 1002, tr("image could not be obtained since no image has been acquired.").toLatin1().data()); } else @@ -1020,7 +1315,6 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData(QSharedPointer> dataObjMap) +ito::RetVal DummyMultiChannelGrabber::copyValByMap( + QSharedPointer> dataObjMap) { - ito::RetVal retValue(ito::retOk); retValue += checkData(*dataObjMap); @@ -1040,12 +1334,15 @@ ito::RetVal DummyMultiChannelGrabber::copyValByMap(QSharedPointer of getVal is NULL").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1004, + tr("QMap of getVal is NULL").toLatin1().data()); } else { - retValue += sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. + retValue += sendDataToListeners(0); // don't wait for live image, since user should get + // the image as fast as possible. QMap::iterator it = (*dataObjMap).begin(); while (it != (*dataObjMap).end()) { @@ -1060,25 +1357,27 @@ ito::RetVal DummyMultiChannelGrabber::copyValByMap(QSharedPointer(vpdObj); + ito::DataObject* dObj = reinterpret_cast(vpdObj); if (!dObj) { - retValue += ito::RetVal(ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); } else { @@ -1092,7 +1391,8 @@ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore if (!retValue.containsError()) { - sendDataToListeners(0); // don't wait for live image, since user should get the image as fast as possible. + sendDataToListeners( + 0); // don't wait for live image, since user should get the image as fast as possible. } if (waitCond) @@ -1105,20 +1405,23 @@ ito::RetVal DummyMultiChannelGrabber::copyVal(void *vpdObj, ItomSharedSemaphore } //---------------------------------------------------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject *externalDataObject) +ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalDataObject) { ito::RetVal retValue(ito::retOk); if (m_isgrabbing == false) { - retValue += ito::RetVal(ito::retError, 1002, - tr("image could not be obtained since no image has been acquired.").toLatin1().data()); + retValue += ito::RetVal( + ito::retError, + 1002, + tr("image could not be obtained since no image has been acquired.").toLatin1().data()); } else { if (externalDataObject) { - m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial(*externalDataObject); + m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial( + *externalDataObject); } m_isgrabbing = false; @@ -1132,17 +1435,23 @@ void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) { if (getDockWidget()) { - QWidget *widget = getDockWidget()->widget(); + QWidget* widget = getDockWidget()->widget(); if (visible) { - connect(this, SIGNAL(parametersChanged(QMap)), widget, - SLOT(parametersChanged(QMap))); + connect( + this, + SIGNAL(parametersChanged(QMap)), + widget, + SLOT(parametersChanged(QMap))); emit parametersChanged(m_params); } else { - disconnect(this, SIGNAL(parametersChanged(QMap)), widget, - SLOT(parametersChanged(QMap))); + disconnect( + this, + SIGNAL(parametersChanged(QMap)), + widget, + SLOT(parametersChanged(QMap))); } } } diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index d1c6873fe..c0886221c 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -5,7 +5,7 @@ Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. - + This itom-plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at @@ -75,6 +75,14 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber ito::uint8 m_totalBinning; bool m_lineCamera; QTimer m_freerunTimer; + int m_imageType; + + enum dummyImageType + { + imgTypeNoise, + imgTypeGaussianSpot, + imgTypeGaussianSpotArray, + }; signals: From 29b55ac849f76b209f6c3e5f6767f3595b875fef Mon Sep 17 00:00:00 2001 From: photoniker Date: Sun, 18 Jun 2023 00:43:31 +0200 Subject: [PATCH 28/43] data meta information for liveImage --- DummyGrabber/DummyGrabber.cpp | 55 +++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/DummyGrabber/DummyGrabber.cpp b/DummyGrabber/DummyGrabber.cpp index 2801ddc57..db96a2f24 100644 --- a/DummyGrabber/DummyGrabber.cpp +++ b/DummyGrabber/DummyGrabber.cpp @@ -172,13 +172,13 @@ DummyGrabberInterface::DummyGrabberInterface() \n\ This plugin can also be used as template for other grabber.";*/ - m_description = QObject::tr("A virtual white noise grabber"); + m_description = QObject::tr("A virtual grabber with white noise or a Gaussian spot."); // m_detaildescription = QObject::tr(docstring); m_detaildescription = QObject::tr( - "The DummyGrabber is a virtual camera which emulates a camera with white noise. \n\ + "The DummyGrabber is a virtual camera which emulates a camera with white noise or a Gaussian spot like a laser beam. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ -You can choose between different image types (noise, GaussianSpot). \ +You can choose between different image types (noise, GaussianSpot, GaussianSpotArray). \ The value range is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). \ The gaussianSpot has some random noise for the position and amplitude to move around a bit. The real size of the camera \ image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ @@ -458,6 +458,55 @@ DummyGrabber::DummyGrabber() : paramVal.setMeta(sm, true); m_params.insert(paramVal.getName(), paramVal); + ito::float64 offset[2] = {0.0, 0.0}; + paramVal = ito::Param( + "axisOffset", + ito::ParamBase::DoubleArray, + 2, + offset, + new ito::DoubleArrayMeta( + std::numeric_limits::min(), std::numeric_limits::max(), 0, 2, 2), + tr("axis offset").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); + + ito::float64 scale[2] = {1.0e-3, 1.0e-3}; + paramVal = ito::Param( + "axisScale", + ito::ParamBase::DoubleArray, + 2, + scale, + new ito::DoubleArrayMeta( + std::numeric_limits::min(), std::numeric_limits::max(), 0, 2, 2), + tr("axis scale").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param("axisUnit", ito::ParamBase::StringList, nullptr, "axis unit"); + ito::ByteArray axisUnit[] = {ito::ByteArray("mm"), ito::ByteArray("mm")}; + paramVal.setVal(axisUnit, 2); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "axisDescription", + ito::ParamBase::StringList, + nullptr, + "axis description"); + ito::ByteArray axisDescription[] = {ito::ByteArray("y axis"), ito::ByteArray("x axis")}; + paramVal.setVal(axisDescription, 2); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "valueDescription", + ito::ParamBase::String, + "counts", + tr("camera chip counts").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "valueUnit", + ito::ParamBase::String, + "a.u.", + tr("unit of counts").toLatin1().data()); + m_params.insert(paramVal.getName(), paramVal); if (hasGuiSupport()) { From 1c5f248222e72ff88cf11fc635771cbb88f135ef Mon Sep 17 00:00:00 2001 From: photoniker Date: Sun, 18 Jun 2023 00:44:12 +0200 Subject: [PATCH 29/43] cleaned up header --- .../DummyMultiChannelGrabber.cpp | 4 ++-- .../DummyMultiChannelGrabber.h | 2 +- .../dialogDummyMultiChannelGrabber.cpp | 14 +++++++------- .../dialogDummyMultiChannelGrabber.h | 6 +++--- .../dockWidgetDummyMultiChannelGrabber.cpp | 9 +++------ .../dockWidgetDummyMultiChannelGrabber.h | 4 ++-- DummyMultiChannelGrabber/pluginVersion.h | 6 +++--- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 052c45b70..4cdca67d6 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -1,7 +1,7 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2020, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. @@ -181,7 +181,7 @@ DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() m_description = QObject::tr("A virtual white noise grabber"); // m_detaildescription = QObject::tr(docstring); m_detaildescription = QObject::tr( - "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with multiple channels with white noise. \n\ \n\ The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index c0886221c..e5b55294d 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -1,7 +1,7 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp index 5cb55eac1..629376073 100644 --- a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.cpp @@ -1,11 +1,11 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. - + This itom-plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at @@ -93,11 +93,11 @@ void DialogDummyMultiChannelGrabber::parametersChanged(QMap dval = params["offset"].getVal(); ui.sliderOffset->setValue(dval*100.0); - ui.sliderOffset->setEnabled(!(params["offset"].getFlags() & ito::ParamBase::Readonly)); + ui.sliderOffset->setEnabled(!(params["offset"].getFlags() & ito::ParamBase::Readonly)); ui.spinBox_offset->setEnabled(!(params["gain"].getFlags() & ito::ParamBase::Readonly)); ui.combo_bpp->setEnabled(!(params["pixelFormat"].getFlags() & ito::ParamBase::Readonly)); - + for (int i = 0; i < ui.combo_bpp->count(); ++i) { if (ui.combo_bpp->itemData(i, Qt::UserRole).toInt() == params["pixelFormat"].getVal()) @@ -222,14 +222,14 @@ ito::RetVal DialogDummyMultiChannelGrabber::applyParameters() if (ui.combo_bpp->isEnabled()) { int bpp = ui.combo_bpp->itemData(ui.combo_bpp->currentIndex()).toInt(); - + if (m_currentParameters["pixelFormat"].getVal() != bpp) { values.append(QSharedPointer(new ito::ParamBase("pixelFormat", ito::ParamBase::Int, bpp))); } } - + retValue += setPluginParameters(values, msgLevelWarningAndError); @@ -285,4 +285,4 @@ void DialogDummyMultiChannelGrabber::on_btnFullROI_clicked() ui.rangeX01->setValues(0, m_currentParameters["sizex"].getMax()); ui.rangeY01->setValues(0, m_currentParameters["sizey"].getMax()); } -} \ No newline at end of file +} diff --git a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h index bf7e08c58..6c3746faf 100644 --- a/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/dialogDummyMultiChannelGrabber.h @@ -1,11 +1,11 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. - + This itom-plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at @@ -35,7 +35,7 @@ namespace ito class AddInBase; //forward declaration } -class DialogDummyMultiChannelGrabber : public ito::AbstractAddInConfigDialog +class DialogDummyMultiChannelGrabber : public ito::AbstractAddInConfigDialog { Q_OBJECT diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp index fe59d6492..992158dc0 100644 --- a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.cpp @@ -1,11 +1,11 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. - + This itom-plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at @@ -50,7 +50,7 @@ DockWidgetDummyMultiChannelGrabber::DockWidgetDummyMultiChannelGrabber(ito::AddI m_firstRun = false; } - + if (!m_inEditing) { m_inEditing = true; @@ -108,6 +108,3 @@ void DockWidgetDummyMultiChannelGrabber::on_doubleSpinBox_integration_time_value m_inEditing = false; } } - - - diff --git a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h index 5c252176a..11452cb20 100644 --- a/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/dockWidgetDummyMultiChannelGrabber.h @@ -1,11 +1,11 @@ /* ******************************************************************** Plugin "DummyMultiChannelGrabber" for itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of a plugin for the measurement software itom. - + This itom-plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at diff --git a/DummyMultiChannelGrabber/pluginVersion.h b/DummyMultiChannelGrabber/pluginVersion.h index e4739d268..18cabac3b 100644 --- a/DummyMultiChannelGrabber/pluginVersion.h +++ b/DummyMultiChannelGrabber/pluginVersion.h @@ -1,7 +1,7 @@ /* ******************************************************************** itom software URL: http://www.uni-stuttgart.de/ito - Copyright (C) 2018, Institut fuer Technische Optik (ITO), + Copyright (C) 2023, Institut fuer Technische Optik (ITO), Universitaet Stuttgart, Germany This file is part of itom and its software development toolkit (SDK). @@ -10,7 +10,7 @@ under the terms of the GNU Library General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at your option) any later version. - + In addition, as a special exception, the Institut fuer Technische Optik (ITO) gives you certain additional rights. These rights are described in the ITO LGPL Exception version 1.0, @@ -37,7 +37,7 @@ #define PLUGIN_VERSION CREATE_VERSION(PLUGIN_VERSION_MAJOR,PLUGIN_VERSION_MINOR,PLUGIN_VERSION_PATCH) #define PLUGIN_VERSION_STRING CREATE_VERSION_STRING(PLUGIN_VERSION_MAJOR,PLUGIN_VERSION_MINOR,PLUGIN_VERSION_PATCH) #define PLUGIN_COMPANY "Institut fuer Technische Optik, University Stuttgart" -#define PLUGIN_COPYRIGHT "(C) 2017, ITO, University Stuttgart" +#define PLUGIN_COPYRIGHT "(C) 2023, ITO, University Stuttgart" #define PLUGIN_NAME "DummyMultiChannelGrabber" //---------------------------------------------------------------------------------------------------------------------------------- From e8704ae96fc02ce2cb294f307c1358a40b27884f Mon Sep 17 00:00:00 2001 From: photoniker Date: Sun, 18 Jun 2023 21:05:02 +0200 Subject: [PATCH 30/43] added checkData for updating m_data after setParams call --- DummyGrabber/DummyGrabber.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/DummyGrabber/DummyGrabber.cpp b/DummyGrabber/DummyGrabber.cpp index db96a2f24..4145df3a6 100644 --- a/DummyGrabber/DummyGrabber.cpp +++ b/DummyGrabber/DummyGrabber.cpp @@ -868,6 +868,7 @@ ito::RetVal DummyGrabber::setParam( if (!retValue.containsError()) { + checkData(); emit parametersChanged(m_params); } From f12a9f9cdf4e9a0a2684a1938b82ca5d82daccd2 Mon Sep 17 00:00:00 2001 From: photoniker Date: Tue, 20 Jun 2023 08:42:35 +0200 Subject: [PATCH 31/43] updated DummyGrabber docu *.rst --- DummyGrabber/DummyGrabber.cpp | 6 +++--- DummyGrabber/docs/dummyGrabber.rst | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/DummyGrabber/DummyGrabber.cpp b/DummyGrabber/DummyGrabber.cpp index 4145df3a6..2932b9300 100644 --- a/DummyGrabber/DummyGrabber.cpp +++ b/DummyGrabber/DummyGrabber.cpp @@ -187,7 +187,7 @@ You can initialize this camera either as a 2D sensor with a width and height >= \n\ This plugin can also be used as template for other grabber."); - m_author = "C. Kohler, W. Lyda, ITO, University Stuttgart"; + m_author = "C. Kohler, W. Lyda, J. Krauter; ITO, University Stuttgart"; m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; m_minItomVer = CREATEVERSION(1, 4, 0); m_maxItomVer = MAXVERSION; @@ -465,7 +465,7 @@ DummyGrabber::DummyGrabber() : 2, offset, new ito::DoubleArrayMeta( - std::numeric_limits::min(), std::numeric_limits::max(), 0, 2, 2), + -std::numeric_limits::max(), std::numeric_limits::max(), 0.0, 2, 2), tr("axis offset").toLatin1().data()); m_params.insert(paramVal.getName(), paramVal); @@ -476,7 +476,7 @@ DummyGrabber::DummyGrabber() : 2, scale, new ito::DoubleArrayMeta( - std::numeric_limits::min(), std::numeric_limits::max(), 0, 2, 2), + -std::numeric_limits::max(), std::numeric_limits::max(), 0, 2, 2), tr("axis scale").toLatin1().data()); m_params.insert(paramVal.getName(), paramVal); diff --git a/DummyGrabber/docs/dummyGrabber.rst b/DummyGrabber/docs/dummyGrabber.rst index 9334b69bc..1c413c1dd 100644 --- a/DummyGrabber/docs/dummyGrabber.rst +++ b/DummyGrabber/docs/dummyGrabber.rst @@ -30,6 +30,18 @@ Parameters An instance of this plugin has the following parameters: +**axisDescription**: Sequence[str] + axis description +**axisOffset**: Sequence[float] + axis offset + + *2 values required, All values allowed, Default: [0, 0]* +**axisScale**: Sequence[float] + axis scale + + *2 values required, All values allowed, Default: [0.001, 0.001]* +**axisUnit**: Sequence[str] + axis unit **binning**: int Binning of different pixel, binning = x-factor * 100 + y-factor @@ -54,7 +66,7 @@ An instance of this plugin has the following parameters: **demoRegexpString**: str matches strings without whitespaces - *RegExp: "^\S+$", Default: * + *RegularExpression: "^\S+$", Default: * **demoWildcardString**: str dummy filename of a bmp file, pattern: *.bmp @@ -82,12 +94,16 @@ An instance of this plugin has the following parameters: **roi**: Tuple[int,int,int,int] (rect [x0,y0,width,height]) ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1] - *Height: Value range: [0:4:479], Default: [0, 0, 640, 480]* + *Height: Value range: [0:4:479], Default: [100, 40, 400, 300]* **sizex**: int, read-only size in x (cols) [px] - *Value range: [4:4:640], Default: 640* + *Value range: [4:4:640], Default: 400* **sizey**: int, read-only size in y (rows) [px] - *Value range: [4:4:480], Default: 480* + *Value range: [4:4:480], Default: 300* +**valueDescription**: str + camera chip counts +**valueUnit**: str + unit of counts From f0f0aa25f1865194c50f5e0be3ca342dfabd444d Mon Sep 17 00:00:00 2001 From: photoniker Date: Fri, 23 Jun 2023 14:53:47 +0200 Subject: [PATCH 32/43] added dataObject meta information to addInMultiChannelGrabber similiar to addInGrabber --- .../DummyMultiChannelGrabber.cpp | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 4cdca67d6..411c4739b 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -432,6 +432,28 @@ ito::RetVal DummyMultiChannelGrabber::init( tr("axis scale").toLatin1().data()); standardParam.insert(paramVal.getName(), paramVal); + paramVal = ito::Param("axisUnit", ito::ParamBase::StringList, nullptr, "axis unit"); + ito::ByteArray axisUnit[] = {ito::ByteArray("mm"), ito::ByteArray("mm")}; + paramVal.setVal(axisUnit, 2); + standardParam.insert(paramVal.getName(), paramVal); + + paramVal = + ito::Param("axisDescription", ito::ParamBase::StringList, nullptr, "axis description"); + ito::ByteArray axisDescription[] = {ito::ByteArray("y axis"), ito::ByteArray("x axis")}; + paramVal.setVal(axisDescription, 2); + standardParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "valueDescription", + ito::ParamBase::String, + "counts", + tr("camera chip counts").toLatin1().data()); + standardParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "valueUnit", ito::ParamBase::String, "a.u.", tr("unit of counts").toLatin1().data()); + standardParam.insert(paramVal.getName(), paramVal); + QMap channelMap; for (int i = 0; i < numChannel; i++) { @@ -443,7 +465,11 @@ ito::RetVal DummyMultiChannelGrabber::init( standardParam["sizex"], standardParam["sizey"], standardParam["axisOffset"], - standardParam["axisScale"])); + standardParam["axisScale"], + standardParam["axisDescription"], + standardParam["axisUnit"], + standardParam["valueDescription"], + standardParam["valueUnit"])); } channelMap["channel_1"].m_channelParam.insert( @@ -832,11 +858,13 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( } ok = true; } + if (key == "roi") { m_isgrabbing = false; // we need to trigger again since the roi changed ok = false; // we want to further process the parameter by setParam to set the size etc. } + if (key == "integration_time") { bool timerIsRunning = m_freerunTimer.isActive(); @@ -849,6 +877,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( } ok = false; } + if (key == "frame_time") { bool timerIsRunning = m_freerunTimer.isActive(); @@ -866,6 +895,8 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( ok = false; // set ok to false to let setParam process the parameter } + sendDataToListeners(0); + return retValue; } @@ -953,6 +984,7 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) return retValue; } +//---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::generateImageData() { ito::RetVal retValue = ito::retOk; @@ -1262,6 +1294,7 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* return retValue; } +//---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::getValByMap( QSharedPointer> dataObjMap) { @@ -1292,6 +1325,7 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap( } return retValue; } + //---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::retrieveData( QSharedPointer> dataObjMap) @@ -1322,6 +1356,8 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData( return retValue; } + +//---------------------------------------------------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::copyValByMap( QSharedPointer> dataObjMap) { From 26317f3bae6e14d54854ba48817f650157b2087d Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sun, 25 Jun 2023 22:40:49 +0200 Subject: [PATCH 33/43] fix in DummyMultiChannelGrabber due to modifications in addInMultiChannelGrabber --- .../DummyMultiChannelGrabber.cpp | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 411c4739b..7495125eb 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -1039,10 +1039,12 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint8* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; + ito::DataObject& channelObj = container.m_data; + for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -1056,10 +1058,12 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint16* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; + ito::DataObject& channelObj = container.m_data; + for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand(rng, maxInt, offset, gain); @@ -1076,10 +1080,12 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint8* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; + ito::DataObject& channelObj = container.m_data; + for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint8*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand_mean( @@ -1094,10 +1100,12 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint16* linePtr; foreach (ChannelContainer container, m_channels) { - ito::DataObject& channelObj = container.data; + ito::DataObject& channelObj = container.m_data; + for (int m = 0; m < channelObj.getSize(0); ++m) { linePtr = (ito::uint16*)channelObj.rowPtr(0, m); + for (int n = 0; n < channelObj.getSize(1); ++n) { *linePtr++ = fastrand_mean( @@ -1115,7 +1123,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, 8) - 1); foreach (ChannelContainer container, m_channels) { - gaussFunc(rng, container.data, amplitude); + gaussFunc(rng, container.m_data, amplitude); } } else if (max < 65536) @@ -1123,14 +1131,14 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, 16) - 1); foreach (ChannelContainer container, m_channels) { - gaussFunc(rng, container.data, amplitude); + gaussFunc(rng, container.m_data, amplitude); } } else if (max < 2147483647) { ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, 32) - 1); foreach (ChannelContainer container, m_channels) - { gaussFunc(rng, container.data, amplitude); + { gaussFunc(rng, container.m_data, amplitude); } } } @@ -1139,9 +1147,9 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() ito::DataObject droi; int width = - this->m_channels[m_params["defaultChannel"].getVal()].data.getSize(1); + this->m_channels[m_params["defaultChannel"].getVal()].m_data.getSize(1); int height = - this->m_channels[m_params["defaultChannel"].getVal()].data.getSize(0); + this->m_channels[m_params["defaultChannel"].getVal()].m_data.getSize(0); int roiwidth = (int)width / 2; int roiheight = (int)height / 2; @@ -1156,7 +1164,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() { foreach (ChannelContainer container, m_channels) { - droi = container.data; + droi = container.m_data; droi = droi.adjustROI(roi[cnt][0], roi[cnt][1], roi[cnt][2], roi[cnt][3]); if (max < 256) @@ -1196,7 +1204,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() QMap::iterator it = m_channels.begin(); while (it != m_channels.end()) { - (*returnMap)[it.key()] = it.value().data; + (*returnMap)[it.key()] = it.value().m_data; ++it; } emit newData(returnMap); @@ -1281,7 +1289,7 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* retValue += sendDataToListeners(0); // don't wait for live image, since user should get // the image as fast as possible. - (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].data; + (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].m_data; } } @@ -1318,7 +1326,7 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap( QMap::iterator it = (*dataObjMap).begin(); while (it != (*dataObjMap).end()) { - *(it.value()) = this->m_channels[it.key()].data; + *(it.value()) = this->m_channels[it.key()].m_data; ++it; } } @@ -1346,7 +1354,7 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData( QMap::const_iterator it = (*dataObjMap).constBegin(); while (it != (*dataObjMap).constEnd()) { - m_channels[it.key()].data.deepCopyPartial(*it.value()); + m_channels[it.key()].m_data.deepCopyPartial(*it.value()); ++it; } } @@ -1382,7 +1390,7 @@ ito::RetVal DummyMultiChannelGrabber::copyValByMap( QMap::iterator it = (*dataObjMap).begin(); while (it != (*dataObjMap).end()) { - *(it.value()) = this->m_channels[it.key()].data; + *(it.value()) = this->m_channels[it.key()].m_data; ++it; } } @@ -1456,7 +1464,7 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalData { if (externalDataObject) { - m_channels[m_params["defaultChannel"].getVal()].data.deepCopyPartial( + m_channels[m_params["defaultChannel"].getVal()].m_data.deepCopyPartial( *externalDataObject); } From 12daeb36c8ed0eebb99ed118326ee583bdd23cd6 Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:04:21 +0200 Subject: [PATCH 34/43] multigrabber refactoring --- DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 7495125eb..93edf1988 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -994,8 +994,8 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() float offset = m_params["offset"].getVal(); int min, max = 0; bool ok = false; - AddInAbstractGrabber::integerPixelFormatStringToMinMaxValue( - m_params["pixelFormat"].getVal(), min, max, ok); + AbstractAddInGrabber::minMaxBoundariesFromIntegerPixelFormat( + m_params["pixelFormat"].getVal(), min, max, ok); if (!ok) { retValue += ito::RetVal( From 84a0b85547aaddda120e9bd98e4c2f516f2a3f7b Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:40:59 +0200 Subject: [PATCH 35/43] updates concerning multi channel grabber, not finished yet --- .../DummyMultiChannelGrabber.cpp | 584 ++++++++---------- .../DummyMultiChannelGrabber.h | 137 ++-- 2 files changed, 334 insertions(+), 387 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 93edf1988..2fb83bb5a 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -40,7 +40,7 @@ #include #endif -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- /** @func fastrand * @brief function for pseudo random values * @@ -51,7 +51,7 @@ template inline _Tp fastrand(cv::RNG& rng, _Tp maxval, float offs return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- /** @func fastrand * @brief function for pseudo random values * @@ -70,7 +70,7 @@ inline _Tp fastrand_mean(cv::RNG& rng, _Tp maxval, ito::uint8 numMeans, float of return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- /** @func gaussFunc * @brief function for 2d Gaussian function * @@ -108,7 +108,7 @@ template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject dObj return ito::retOk; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- /*! \class DummyMultiChannelGrabberInterface \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic @@ -116,7 +116,7 @@ template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject dObj DummyMultiChannelGrabber. */ -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. /*! \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created @@ -129,7 +129,7 @@ ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase** add return ito::retOk; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. /*! \param [in] double pointer to the instance which should be deleted. @@ -142,7 +142,7 @@ ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase** ad return ito::retOk; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! constructor for interace /*! defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real @@ -189,7 +189,7 @@ image is controlled using the parameter 'roi' if the sizes stay within the limit \n\ You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ \n\ -This plugin can also be used as template for other grabber."); +This plugin can also be used as template for other grabbers."); m_author = "R. Hahn, ITO, University Stuttgart"; m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; @@ -201,29 +201,28 @@ This plugin can also be used as template for other grabber."); m_initParamsMand.clear(); ito::Param param( - "maxXSize", + "sensorWidth", ito::ParamBase::Int, 640, new ito::IntMeta(4, 4096, 4), - tr("Width of virtual sensor chip").toLatin1().data()); + tr("Width of sensor chip. In this demo, the width of the sensor is the same for " + "all channels (could be different, if implemented).").toLatin1().data()); m_initParamsOpt.append(param); param = ito::Param( - "maxYSize", + "sensorHeight", ito::ParamBase::Int, 480, new ito::IntMeta(1, 4096, 1), - tr("Height of virtual sensor chip, please set this value to 1 (line camera) or a value " - "dividable by 4 for a 2D camera.") - .toLatin1() - .data()); + tr("Height of sensor chip. In this demo, the height is the same for all " + "channels. However, it could also be different, if implemented.").toLatin1().data()); m_initParamsOpt.append(param); param = ito::Param( - "pixelFormat", + "pixelFormatChannel1", ito::ParamBase::String, "mono8", - tr("Bits per Pixel, usually mono8, mono10, mono12, mono16 or rgb32").toLatin1().data()); + tr("Pixel format for the 1st channel (here: a grayscale intensity image).").toLatin1().data()); ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); m->addItem("mono10"); m->addItem("mono12"); @@ -232,11 +231,23 @@ This plugin can also be used as template for other grabber."); m_initParamsOpt.append(param); param = ito::Param( - "numberOfChannels", - ito::ParamBase::Int, - 2, - new ito::IntMeta(2, 30, 1), - tr("Number of channels").toLatin1().data()); + "pixelFormatChannel2", + ito::ParamBase::String, + "float32", + tr("Pixel format for the 2nd channel (here: a float32 or float64 disparity image).").toLatin1().data()); + ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "float32"); + m->addItem("float64"); + param.setMeta(m, true); + m_initParamsOpt.append(param); + + param = ito::Param( + "pixelFormatChannel3", + ito::ParamBase::String, + "rgba8", + tr("Pixel format for the 3nd channel (here: color image with or without alpha channel).").toLatin1().data()); + ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "rgba8"); + m->addItem("rgb8"); + param.setMeta(m, true); m_initParamsOpt.append(param); param = ito::Param( @@ -254,23 +265,15 @@ This plugin can also be used as template for other grabber."); m_initParamsOpt.append(param); } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! destructor /*! - clears both vectors m_initParamsMand and m_initParamsOpt. + */ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() { - m_initParamsMand.clear(); - m_initParamsOpt.clear(); } -//---------------------------------------------------------------------------------------------------------------------------------- -// this makro registers the class DummyMultiChannelGrabberInterface with the name -// DummyMultiChannelGrabberinterface as plugin for the Qt-System (see Qt-DOC) - -//---------------------------------------------------------------------------------------------------------------------------------- - /*! \class DummyMultiChannelGrabber \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create @@ -280,7 +283,7 @@ DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() destructor, showConfDialog will be executed by the main (GUI) thread. */ -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! shows the configuration dialog. This method must be executed in the main (GUI) thread and is //! usually called by the addIn-Manager. /*! @@ -296,7 +299,7 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) return apiShowConfigurationDialog(this, new DialogDummyMultiChannelGrabber(this)); } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! constructor for DummyMultiChannelGrabber /*! In this constructor the m_params-vector with all parameters, which are accessible by getParam or @@ -307,8 +310,8 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber("DummyMultiChannelGrabber"), m_isgrabbing(false), m_totalBinning(1), - m_startOfLastAcquisition(0), m_lineCamera(false), m_freerunTimer(this), + AddInMultiChannelGrabber("DummyMultiChannelGrabber"), m_isgrabbing(false), + m_startOfLastAcquisition(0), m_freerunTimer(this), m_imageType(imgTypeNoise) { if (hasGuiSupport()) @@ -318,12 +321,12 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : Qt::DockWidgetAreas areas = Qt::AllDockWidgetAreas; QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; - createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); + createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } connect(&m_freerunTimer, &QTimer::timeout, this, &DummyMultiChannelGrabber::generateImageData); } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! destructor /*! \sa ~AddInBase @@ -332,7 +335,7 @@ DummyMultiChannelGrabber::~DummyMultiChannelGrabber() { } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! init method which is called by the addInManager after the initiation of a new instance of //! DummyMultiChannelGrabber. /*! @@ -353,278 +356,221 @@ ito::RetVal DummyMultiChannelGrabber::init( ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retVal; - int sizeX = paramsOpt->at(0) - .getVal(); // first optional parameter, corresponding to the grabber width - int sizeY = - paramsOpt->at(1) - .getVal(); // second optional parameter, corresponding to the grabber heigth - int numChannel = paramsOpt->at(3).getVal(); // third optional parameter, corresponding to - // the number of channels - if (sizeY > 1 && sizeY % 4 != 0) + // get all arguments + int sensorWidth = paramsOpt->at(0).getVal(); + int sensorHeight = paramsOpt->at(1).getVal(); + + // A multi grabber camera plugin consists of >= 1 channels. Every channel + // can have individual parameters, where a basic set of parameters are mandatory + // (like sizex, sizey, pixelFormat...). + // The channel parameters have a corresponding parameter in the m_params map + // of the overall plugin. This item in m_params is like a proxy to the underlying + // channel parameters, where the parameter 'channelSelector' defines which of + // the more than one channels is used as current proxy. + + // create the channel parameters, that are the same for all channels + ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, tr("sensor width of the channel").toLatin1().data()); + ito::Param paramSizeY("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, tr("sensor height of the channel").toLatin1().data()); + int roi[] = { 0, 0, sensorWidth, sensorHeight }; + ito::Param paramRoi("roi", ito::ParamBase::IntArray, 4, roi, tr("current region of interest of the channel (x, y, width, height)").toLatin1().data()); + + // initialize the first channel + ito::Param pixelFormat1("pixelFormat", ito::ParamBase::String, paramsOpt->at(2).getVal(), tr("pixel format of the 1st channel").toLatin1().data()); + auto pixelFormat1Meta = new ito::StringMeta(ito::StringMeta::String, "ImageFormatControl"); + pixelFormat1Meta->addItem("mono8"); + pixelFormat1Meta->addItem("mono10"); + pixelFormat1Meta->addItem("mono12"); + pixelFormat1Meta->addItem("mono16"); + pixelFormat1.setMeta(pixelFormat1Meta, true); + + ito::Param pixelFormat2("pixelFormat", ito::ParamBase::String, paramsOpt->at(3).getVal(), tr("pixel format of the 2nd channel").toLatin1().data()); + auto pixelFormat2Meta = new ito::StringMeta(ito::StringMeta::String, "ImageFormatControl"); + pixelFormat2Meta->addItem("float32"); + pixelFormat2Meta->addItem("float64"); + pixelFormat2.setMeta(pixelFormat2Meta, true); + + ito::Param pixelFormat3("pixelFormat", ito::ParamBase::String, paramsOpt->at(4).getVal(), tr("pixel format of the 3rd channel").toLatin1().data()); + auto pixelFormat3Meta = new ito::StringMeta(ito::StringMeta::String, "ImageFormatControl"); + pixelFormat3Meta->addItem("rgba8"); + pixelFormat3Meta->addItem("rgb8"); + pixelFormat3.setMeta(pixelFormat3Meta, true); + + ChannelContainer channel1(paramRoi, pixelFormat1, paramSizeX, paramSizeY); + channel1.m_channelParam["valueDescription"].setVal("intensity"); + + + ChannelContainer channel2(paramRoi, pixelFormat2, paramSizeX, paramSizeY); + channel2.m_channelParam["valueDescription"].setVal("topography"); + double axisScales[] = {0.05, 0.05}; + channel2.m_channelParam["axisScales"].setVal(axisScales, 2); + ito::ByteArray axisUnits[] = { "mm", "mm" }; + channel2.m_channelParam["axisUnits"].setVal(axisUnits, 2); + + ChannelContainer channel3(paramRoi, pixelFormat3, paramSizeX, paramSizeY); + channel3.m_channelParam["valueDescription"].setVal("color"); + + + QMap channelMap; + for (int i = 0; i < numChannel; i++) { - retVal += ito::RetVal(ito::retError, 0, "maxYSize must be 1 or dividable by 4"); + channelMap.insert( + QString("channel_%1").arg(i), + ChannelContainer( + standardParam["roi"], + standardParam["pixelFormat"], + standardParam["sizex"], + standardParam["sizey"], + standardParam["axisOffset"], + standardParam["axisScale"], + standardParam["axisDescription"], + standardParam["axisUnit"], + standardParam["valueDescription"], + standardParam["valueUnit"])); } - else - { - QMap standardParam; - ito::Param paramVal; - int roi[] = {0, 0, 2048, 2048}; - paramVal = ito::Param( - "roi", - ito::ParamBase::IntArray, - 4, - roi, - tr("ROI (x,y,width,height) [this replaces the values x0,x1,y0,y1]").toLatin1().data()); - ito::RectMeta* rm = new ito::RectMeta( - ito::RangeMeta(roi[0], roi[0] + roi[2] - 1), - ito::RangeMeta(roi[1], roi[1] + roi[3] - 1), - "ImageFormatControl"); - paramVal.setMeta(rm, true); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "sizex", - ito::ParamBase::Int | ito::ParamBase::Readonly, - 4, - 4096, - 4096, - tr("size in x (cols) [px]").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "sizey", - ito::ParamBase::Int | ito::ParamBase::Readonly, - 1, - 4096, - 4096, - tr("size in y (rows) [px]").toLatin1().data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - standardParam.insert(paramVal.getName(), paramVal); - - ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); - m->addItem("mono10"); - m->addItem("mono12"); - m->addItem("mono16"); - paramVal = ito::Param( - "pixelFormat", - ito::ParamBase::String, - paramsOpt->at(2).getVal(), - tr("bitdepth of images: mono8, mono10, mono12, mono16").toLatin1().data()); - paramVal.setMeta(m, true); - standardParam.insert(paramVal.getName(), paramVal); - - double axisOffset[] = {0.0, 0.0}; - paramVal = ito::Param( - "axisOffset", - ito::ParamBase::DoubleArray, - 2, - axisOffset, - tr("axis offset").toLatin1().data()); - standardParam.insert(paramVal.getName(), paramVal); - - double axisScale[] = {1.0, 1.0}; - paramVal = ito::Param( - "axisScale", - ito::ParamBase::DoubleArray, - 2, - axisScale, - tr("axis scale").toLatin1().data()); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param("axisUnit", ito::ParamBase::StringList, nullptr, "axis unit"); - ito::ByteArray axisUnit[] = {ito::ByteArray("mm"), ito::ByteArray("mm")}; - paramVal.setVal(axisUnit, 2); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = - ito::Param("axisDescription", ito::ParamBase::StringList, nullptr, "axis description"); - ito::ByteArray axisDescription[] = {ito::ByteArray("y axis"), ito::ByteArray("x axis")}; - paramVal.setVal(axisDescription, 2); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "valueDescription", - ito::ParamBase::String, - "counts", - tr("camera chip counts").toLatin1().data()); - standardParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "valueUnit", ito::ParamBase::String, "a.u.", tr("unit of counts").toLatin1().data()); - standardParam.insert(paramVal.getName(), paramVal); - - QMap channelMap; - for (int i = 0; i < numChannel; i++) - { - channelMap.insert( - QString("channel_%1").arg(i), - ChannelContainer( - standardParam["roi"], - standardParam["pixelFormat"], - standardParam["sizex"], - standardParam["sizey"], - standardParam["axisOffset"], - standardParam["axisScale"], - standardParam["axisDescription"], - standardParam["axisUnit"], - standardParam["valueDescription"], - standardParam["valueUnit"])); - } - channelMap["channel_1"].m_channelParam.insert( + channelMap["channel_1"].m_channelParam.insert( + "channelSpecificParameter", + ito::Param( "channelSpecificParameter", - ito::Param( - "channelSpecificParameter", - ito::ParamBase::Int, - 0, - 1, - 1, - tr("this is a channel specific parameter").toLatin1().data())); - channelMap["channel_1"] - .m_channelParam["channelSpecificParameter"] - .getMetaT() - ->setCategory("DemoParameters"); - - // global params - QMap globalParam; - globalParam.insert( + ito::ParamBase::Int, + 0, + 1, + 1, + tr("this is a channel specific parameter").toLatin1().data())); + channelMap["channel_1"] + .m_channelParam["channelSpecificParameter"] + .getMetaT() + ->setCategory("DemoParameters"); + + // global params + ParamMap globalParam; + globalParam.insert( + "globalParam", + ito::Param( "globalParam", - ito::Param( - "globalParam", - ito::ParamBase::Int, - 0, - 1, - 1, - tr("this is a global parameter").toLatin1().data())); - - ito::DoubleMeta* dm; - paramVal = ito::Param( - "frame_time", - ito::ParamBase::Double, - 0.0, - 60.0, - 0.0, - tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.") - .toLatin1() - .data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "integration_time", - ito::ParamBase::Double, - 0.0, - 60.0, - 0.001, - tr("Minimum integration time for an acquisition [s], default: 0.001.") - .toLatin1() - .data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "offset", - ito::ParamBase::Double, - 0.0, - 1.0, - 0.0, - tr("Virtual offset").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "triggerMode", - ito::ParamBase::String, - "software", - tr("trigger mode of the camera (freerun or software)").toLatin1().data()); - ito::StringMeta* sm = - new ito::StringMeta(ito::StringMeta::String, "software", "AcquisitionControl"); - sm->addItem("freerun"); - paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "binning", ito::ParamBase::Int, - 101, - 404, - 101, - tr("Binning of different pixel, binning = x-factor * 100 + y-factor") - .toLatin1() - .data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "demoRegexpString", - ito::ParamBase::String, - "", - tr("matches strings without whitespaces").toLatin1().data()); - paramVal.setMeta( - new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "demoWildcardString", - ito::ParamBase::String, - "test.bmp", - tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); - paramVal.setMeta( - new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "demoEnumString", - ito::ParamBase::String, - "mode 1", - tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); - sm->addItem("mode 2"); - sm->addItem("mode 3"); - paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "demoArbitraryString", - ito::ParamBase::String, - "any string", - tr("any string allowed").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String); - sm->setCategory("DemoParameters"); - paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); - - initializeDefaultConfiguration(channelMap, globalParam); - - if (sizeY == 1) - { - m_lineCamera = true; - } - else - { - m_lineCamera = false; - } - } + 0, + 1, + 1, + tr("this is a global parameter").toLatin1().data())); + + ito::DoubleMeta* dm; + paramVal = ito::Param( + "frame_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.0, + tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.") + .toLatin1() + .data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "integration_time", + ito::ParamBase::Double, + 0.0, + 60.0, + 0.001, + tr("Minimum integration time for an acquisition [s], default: 0.001.") + .toLatin1() + .data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setUnit("s"); + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "offset", + ito::ParamBase::Double, + 0.0, + 1.0, + 0.0, + tr("Virtual offset").toLatin1().data()); + dm = paramVal.getMetaT(); + dm->setCategory("AcquisitionControl"); + dm->setRepresentation( + ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "triggerMode", + ito::ParamBase::String, + "software", + tr("trigger mode of the camera (freerun or software)").toLatin1().data()); + ito::StringMeta* sm = + new ito::StringMeta(ito::StringMeta::String, "software", "AcquisitionControl"); + sm->addItem("freerun"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "binning", + ito::ParamBase::Int, + 101, + 404, + 101, + tr("Binning of different pixel, binning = x-factor * 100 + y-factor") + .toLatin1() + .data()); + paramVal.getMetaT()->setCategory("ImageFormatControl"); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "demoRegexpString", + ito::ParamBase::String, + "", + tr("matches strings without whitespaces").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "demoWildcardString", + ito::ParamBase::String, + "test.bmp", + tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); + paramVal.setMeta( + new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "demoEnumString", + ito::ParamBase::String, + "mode 1", + tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + sm->addItem("mode 2"); + sm->addItem("mode 3"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + + paramVal = ito::Param( + "demoArbitraryString", + ito::ParamBase::String, + "any string", + tr("any string allowed").toLatin1().data()); + sm = new ito::StringMeta(ito::StringMeta::String); + sm->setCategory("DemoParameters"); + paramVal.setMeta(sm, true); + globalParam.insert(paramVal.getName(), paramVal); + + initializeDefaultConfiguration(channelMap, globalParam); if (!retVal.containsError()) { @@ -661,7 +607,7 @@ ito::RetVal DummyMultiChannelGrabber::init( return retVal; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! close method which is called before that this instance is deleted by the //! DummyMultiChannelGrabberInterface /*! @@ -693,7 +639,7 @@ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore* waitCond) } } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! returns parameter of m_params with key name. /*! This method copies val of the corresponding parameter value. @@ -716,7 +662,7 @@ ito::RetVal DummyMultiChannelGrabber::getParameter( return ito::retOk; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! sets parameter of m_params with key name. /*! This method copies the given value to the m_params-parameter. @@ -900,7 +846,7 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! With startDevice this camera is initialized. /*! In the DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera @@ -942,7 +888,7 @@ ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore* waitCond) return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! With stopDevice the camera device is stopped (opposite to startDevice) /*! In this DummyMultiChannelGrabber, this method does nothing. In general, the hardware camera @@ -984,7 +930,7 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::generateImageData() { ito::RetVal retValue = ito::retOk; @@ -1211,7 +1157,7 @@ ito::RetVal DummyMultiChannelGrabber::generateImageData() return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! Call this method to trigger a new image. /*! By this method a new image is trigger by the camera, that means the acquisition of the image @@ -1253,7 +1199,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a shallow copy. /*! This method copies the recently grabbed camera frame to the given DataObject-handle @@ -1302,7 +1248,7 @@ ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::getValByMap( QSharedPointer> dataObjMap) { @@ -1334,7 +1280,7 @@ ito::RetVal DummyMultiChannelGrabber::getValByMap( return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::retrieveData( QSharedPointer> dataObjMap) { @@ -1365,7 +1311,7 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData( return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::copyValByMap( QSharedPointer> dataObjMap) { @@ -1398,7 +1344,7 @@ ito::RetVal DummyMultiChannelGrabber::copyValByMap( return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- //! Returns the grabbed camera frame as a deep copy. /*! This method copies the recently grabbed camera frame to the given DataObject. Therefore this @@ -1448,7 +1394,7 @@ ito::RetVal DummyMultiChannelGrabber::copyVal(void* vpdObj, ItomSharedSemaphore* return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalDataObject) { ito::RetVal retValue(ito::retOk); @@ -1474,7 +1420,7 @@ ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalData return retValue; } -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) { if (getDockWidget()) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index e5b55294d..302b35590 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -20,8 +20,7 @@ along with itom. If not, see . *********************************************************************** */ -#ifndef DUMMYMULTICHANNELGRABBER_H -#define DUMMYMULTICHANNELGRABBER_H +#pragma once #include "common/addInMultiChannelGrabber.h" #include "common/typeDefs.h" @@ -30,83 +29,85 @@ #include #include -//---------------------------------------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------- class DummyMultiChannelGrabberInterface : public ito::AddInInterfaceBase { Q_OBJECT - Q_PLUGIN_METADATA(IID "ito.AddInInterfaceBase" ) - Q_INTERFACES(ito::AddInInterfaceBase) /*!< this DummyMultiChannelGrabberInterface implements the ito::AddInInterfaceBase-interface, which makes it available as plugin in itom */ - PLUGIN_ITOM_API + Q_PLUGIN_METADATA(IID "ito.AddInInterfaceBase") - public: - DummyMultiChannelGrabberInterface(); /*!< Constructor */ - ~DummyMultiChannelGrabberInterface(); /*!< Destructor */ - ito::RetVal getAddInInst(ito::AddInBase **addInInst); /*!< creates new instance of DummyMultiChannelGrabber and returns this instance */ + /*!< this DummyMultiChannelGrabberInterface implements the + ito::AddInInterfaceBase-interface, which makes it available as plugin in itom */ + Q_INTERFACES(ito::AddInInterfaceBase) - private: - ito::RetVal closeThisInst(ito::AddInBase **addInInst); /*!< closes any specific instance of DummyMultiChannelGrabber, given by *addInInst */ + PLUGIN_ITOM_API -}; - -//---------------------------------------------------------------------------------------------------------------------------------- -class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber -{ - Q_OBJECT - - protected: - ~DummyMultiChannelGrabber(); - DummyMultiChannelGrabber(); - - ito::RetVal retrieveData(ito::DataObject *externalDataObject = NULL); - ito::RetVal retrieveData(QSharedPointer> dataObjMap); - ito::RetVal getValByMap(QSharedPointer> dataObjMap); - ito::RetVal copyValByMap(QSharedPointer> dataObjMap); - ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); - ito::RetVal setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); - - public: - friend class DummyMultiChannelGrabberInterface; - const ito::RetVal showConfDialog(void); - int hasConfDialog(void) { return 1; }; //!< indicates that this plugin has got a configuration dialog - - private: - bool m_isgrabbing; - int64 m_startOfLastAcquisition; - ito::uint8 m_totalBinning; - bool m_lineCamera; - QTimer m_freerunTimer; - int m_imageType; - - enum dummyImageType - { - imgTypeNoise, - imgTypeGaussianSpot, - imgTypeGaussianSpotArray, - }; +public: + /*!< Constructor */ + DummyMultiChannelGrabberInterface(); - signals: + /*!< Destructor */ + ~DummyMultiChannelGrabberInterface(); - public slots: - - ito::RetVal init(QVector *paramsMand, QVector *paramsOpt, ItomSharedSemaphore *waitCond = NULL); - ito::RetVal close(ItomSharedSemaphore *waitCond); - - ito::RetVal startDevice(ItomSharedSemaphore *waitCond); - ito::RetVal stopDevice(ItomSharedSemaphore *waitCond); - ito::RetVal acquire(const int trigger, ItomSharedSemaphore *waitCond = NULL); - ito::RetVal getVal(void *dObj, ItomSharedSemaphore *waitCond); - ito::RetVal copyVal(void *vpdObj, ItomSharedSemaphore *waitCond); - - private slots: - void dockWidgetVisibilityChanged(bool visible); - ito::RetVal generateImageData(); + /*!< creates new instance of DummyMultiChannelGrabber and returns this instance */ + ito::RetVal getAddInInst(ito::AddInBase** addInInst); +private: + /*!< closes any specific instance of DummyMultiChannelGrabber, given by *addInInst */ + ito::RetVal closeThisInst(ito::AddInBase** addInInst); }; +//------------------------------------------------------------------------------------- +class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber +{ + Q_OBJECT - -//---------------------------------------------------------------------------------------------------------------------------------- - -#endif // DummyMultiChannelGrabber_H +protected: + ~DummyMultiChannelGrabber(); + DummyMultiChannelGrabber(); + + ito::RetVal retrieveData(ito::DataObject* externalDataObject = NULL); + ito::RetVal retrieveData(QSharedPointer> dataObjMap); + ito::RetVal getValByMap(QSharedPointer> dataObjMap); + ito::RetVal copyValByMap(QSharedPointer> dataObjMap); + ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); + ito::RetVal setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); + +public: + friend class DummyMultiChannelGrabberInterface; + const ito::RetVal showConfDialog(void); + + //!< indicates that this plugin has got a configuration dialog + int hasConfDialog(void) { return 1; }; + +private: + bool m_isgrabbing; + int64 m_startOfLastAcquisition; + QTimer m_freerunTimer; + int m_imageType; + + enum dummyImageType + { + imgTypeNoise, + imgTypeGaussianSpot, + imgTypeGaussianSpotArray, + }; + +signals: + +public slots: + + ito::RetVal init(QVector* paramsMand, QVector* paramsOpt, ItomSharedSemaphore* waitCond = NULL); + ito::RetVal close(ItomSharedSemaphore* waitCond); + + ito::RetVal startDevice(ItomSharedSemaphore* waitCond); + ito::RetVal stopDevice(ItomSharedSemaphore* waitCond); + ito::RetVal acquire(const int trigger, ItomSharedSemaphore* waitCond = NULL); + ito::RetVal getVal(void* dObj, ItomSharedSemaphore* waitCond); + ito::RetVal copyVal(void* vpdObj, ItomSharedSemaphore* waitCond); + +private slots: + void dockWidgetVisibilityChanged(bool visible); + ito::RetVal generateImageData(); +}; From 8a0b16d1f69f11f3b02a9ee07c6e96990bc3cffb Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Thu, 20 Jul 2023 00:04:17 +0200 Subject: [PATCH 36/43] some more improvements for DummyMultiChannelGrabber --- .../DummyMultiChannelGrabber.cpp | 167 +++++------------- 1 file changed, 47 insertions(+), 120 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 2fb83bb5a..0df627135 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -367,6 +367,7 @@ ito::RetVal DummyMultiChannelGrabber::init( // of the overall plugin. This item in m_params is like a proxy to the underlying // channel parameters, where the parameter 'channelSelector' defines which of // the more than one channels is used as current proxy. + QMap channels; // create the channel parameters, that are the same for all channels ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, tr("sensor width of the channel").toLatin1().data()); @@ -398,6 +399,24 @@ ito::RetVal DummyMultiChannelGrabber::init( ChannelContainer channel1(paramRoi, pixelFormat1, paramSizeX, paramSizeY); channel1.m_channelParam["valueDescription"].setVal("intensity"); + // every channel can also further additional parameters. + // Rules: + /* 1. If 1 or more channels have a parameter with a specific name, no + * global parameter with this name must exist. + * 2. Not every channel must have the same parameter, with the same name, + * however in initChannelsAndGlobalParameters it is verified, that + * any channel parameter is available in all channels with the same type flags. + * If a channel does not have a parameter, it is created (with default arguments) + * and the "not-available" flag. + * 3. Channel parameters of the same name must have the same type flag + * (checked in initChannelsAndGlobalParamters). + */ + channel1.addChannelParam(ito::Param( + "gammaCorrection", + ito::ParamBase::Double, 0.0, 1.0, 1.0, "gamma correction value (channelColour and channelMono only)")); + + // add channel1 to the preliminary channel map. The channel name is 'channelMono' as an example. + channels["channelMono"] = channel1; ChannelContainer channel2(paramRoi, pixelFormat2, paramSizeX, paramSizeY); channel2.m_channelParam["valueDescription"].setVal("topography"); @@ -406,47 +425,32 @@ ito::RetVal DummyMultiChannelGrabber::init( ito::ByteArray axisUnits[] = { "mm", "mm" }; channel2.m_channelParam["axisUnits"].setVal(axisUnits, 2); + // add channel2 to the preliminary channel map. The channel name is 'channelTopo' as an example. + channels["channelTopo"] = channel2; + ChannelContainer channel3(paramRoi, pixelFormat3, paramSizeX, paramSizeY); channel3.m_channelParam["valueDescription"].setVal("color"); + channel3.addChannelParam(ito::Param( + "gammaCorrection", + ito::ParamBase::Double, 0.0, 1.0, 0.8, "gamma correction value (channelColour and channelMono only)")); - QMap channelMap; - for (int i = 0; i < numChannel; i++) - { - channelMap.insert( - QString("channel_%1").arg(i), - ChannelContainer( - standardParam["roi"], - standardParam["pixelFormat"], - standardParam["sizex"], - standardParam["sizey"], - standardParam["axisOffset"], - standardParam["axisScale"], - standardParam["axisDescription"], - standardParam["axisUnit"], - standardParam["valueDescription"], - standardParam["valueUnit"])); - } + // add channel3 to the preliminary channel map. The channel name is 'channelColour' as an example. + channels["channelColour"] = channel3; - channelMap["channel_1"].m_channelParam.insert( - "channelSpecificParameter", - ito::Param( - "channelSpecificParameter", - ito::ParamBase::Int, - 0, - 1, - 1, - tr("this is a channel specific parameter").toLatin1().data())); - channelMap["channel_1"] - .m_channelParam["channelSpecificParameter"] - .getMetaT() - ->setCategory("DemoParameters"); - - // global params - ParamMap globalParam; - globalParam.insert( - "globalParam", - ito::Param( + // global parameters: + /* Other than in other plugins, global parameters, that are the same for all + channels will be added to a temporary list of Param and then given to initChannelsAndGlobalParameters. + + Internally, after some checks, they will be added to m_params, like in any other plugin. + + Due to the base class "addInMultiChannelGrabber", three default global parameters are + created and initialized: defaultChannel, channelSelector, availableChannels. + */ + + QList globalParams; + + globalParams << ito::Param( "globalParam", ito::ParamBase::Int, 0, @@ -454,91 +458,14 @@ ito::RetVal DummyMultiChannelGrabber::init( 1, tr("this is a global parameter").toLatin1().data())); - ito::DoubleMeta* dm; - paramVal = ito::Param( - "frame_time", - ito::ParamBase::Double, - 0.0, - 60.0, - 0.0, - tr("Minimum time between the start of two consecutive acquisitions [s], default: 0.0.") - .toLatin1() - .data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "integration_time", - ito::ParamBase::Double, - 0.0, - 60.0, - 0.001, - tr("Minimum integration time for an acquisition [s], default: 0.001.") - .toLatin1() - .data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setUnit("s"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "gain", ito::ParamBase::Double, 0.0, 1.0, 1.0, tr("Virtual gain").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "offset", - ito::ParamBase::Double, - 0.0, - 1.0, - 0.0, - tr("Virtual offset").toLatin1().data()); - dm = paramVal.getMetaT(); - dm->setCategory("AcquisitionControl"); - dm->setRepresentation( - ito::ParamMeta::Linear); // show a linear slider in generic paramEditorWidget... - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "triggerMode", - ito::ParamBase::String, - "software", - tr("trigger mode of the camera (freerun or software)").toLatin1().data()); - ito::StringMeta* sm = - new ito::StringMeta(ito::StringMeta::String, "software", "AcquisitionControl"); - sm->addItem("freerun"); - paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( - "binning", - ito::ParamBase::Int, - 101, - 404, - 101, - tr("Binning of different pixel, binning = x-factor * 100 + y-factor") - .toLatin1() - .data()); - paramVal.getMetaT()->setCategory("ImageFormatControl"); - globalParam.insert(paramVal.getName(), paramVal); - - paramVal = ito::Param( + auto paramVal = ito::Param( "demoRegexpString", ito::ParamBase::String, "", tr("matches strings without whitespaces").toLatin1().data()); paramVal.setMeta( new ito::StringMeta(ito::StringMeta::RegExp, "^\\S+$", "DemoParameters"), true); - globalParam.insert(paramVal.getName(), paramVal); + globalParams << paramVal; paramVal = ito::Param( "demoWildcardString", @@ -547,18 +474,18 @@ ito::RetVal DummyMultiChannelGrabber::init( tr("dummy filename of a bmp file, pattern: *.bmp").toLatin1().data()); paramVal.setMeta( new ito::StringMeta(ito::StringMeta::Wildcard, "*.bmp", "DemoParameters"), true); - globalParam.insert(paramVal.getName(), paramVal); + globalParams << paramVal; paramVal = ito::Param( "demoEnumString", ito::ParamBase::String, "mode 1", tr("enumeration string (mode 1, mode 2, mode 3)").toLatin1().data()); - sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); + auto sm = new ito::StringMeta(ito::StringMeta::String, "mode 1", "DemoParameters"); sm->addItem("mode 2"); sm->addItem("mode 3"); paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); + globalParams << paramVal; paramVal = ito::Param( "demoArbitraryString", @@ -568,9 +495,9 @@ ito::RetVal DummyMultiChannelGrabber::init( sm = new ito::StringMeta(ito::StringMeta::String); sm->setCategory("DemoParameters"); paramVal.setMeta(sm, true); - globalParam.insert(paramVal.getName(), paramVal); + globalParams << paramVal; - initializeDefaultConfiguration(channelMap, globalParam); + initChannelsAndGlobalParameters(channels, globalParam); if (!retVal.containsError()) { From 69ca6a05c7778b918b74799bbc698a3b71a0968d Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Wed, 2 Aug 2023 23:56:35 +0200 Subject: [PATCH 37/43] updates of dummyMultiChannelGrabber --- .../DummyMultiChannelGrabber.cpp | 42 +++++++++++++------ .../DummyMultiChannelGrabber.h | 21 +++++++++- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index 0df627135..fd7e988af 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -235,7 +235,7 @@ This plugin can also be used as template for other grabbers."); ito::ParamBase::String, "float32", tr("Pixel format for the 2nd channel (here: a float32 or float64 disparity image).").toLatin1().data()); - ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "float32"); + m = new ito::StringMeta(ito::StringMeta::String, "float32"); m->addItem("float64"); param.setMeta(m, true); m_initParamsOpt.append(param); @@ -245,7 +245,7 @@ This plugin can also be used as template for other grabbers."); ito::ParamBase::String, "rgba8", tr("Pixel format for the 3nd channel (here: color image with or without alpha channel).").toLatin1().data()); - ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "rgba8"); + m = new ito::StringMeta(ito::StringMeta::String, "rgba8"); m->addItem("rgb8"); param.setMeta(m, true); m_initParamsOpt.append(param); @@ -367,11 +367,11 @@ ito::RetVal DummyMultiChannelGrabber::init( // of the overall plugin. This item in m_params is like a proxy to the underlying // channel parameters, where the parameter 'channelSelector' defines which of // the more than one channels is used as current proxy. - QMap channels; + ChannelContainerMap channels; // create the channel parameters, that are the same for all channels - ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, tr("sensor width of the channel").toLatin1().data()); - ito::Param paramSizeY("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, tr("sensor height of the channel").toLatin1().data()); + ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, 1280, tr("sensor width of the channel").toLatin1().data()); + ito::Param paramSizeY("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, 1024, tr("sensor height of the channel").toLatin1().data()); int roi[] = { 0, 0, sensorWidth, sensorHeight }; ito::Param paramRoi("roi", ito::ParamBase::IntArray, 4, roi, tr("current region of interest of the channel (x, y, width, height)").toLatin1().data()); @@ -456,7 +456,7 @@ ito::RetVal DummyMultiChannelGrabber::init( 0, 1, 1, - tr("this is a global parameter").toLatin1().data())); + tr("this is a global parameter").toLatin1().data()); auto paramVal = ito::Param( "demoRegexpString", @@ -497,7 +497,7 @@ ito::RetVal DummyMultiChannelGrabber::init( paramVal.setMeta(sm, true); globalParams << paramVal; - initChannelsAndGlobalParameters(channels, globalParam); + retVal += initChannelsAndGlobalParameters(channels, "channelMono", globalParams); if (!retVal.containsError()) { @@ -506,6 +506,8 @@ ito::RetVal DummyMultiChannelGrabber::init( emit parametersChanged(m_params); } + setIdentifier(QString::number(getID())); + // get type of dummy image QString type = paramsOpt->at(4).getVal(); @@ -522,8 +524,6 @@ ito::RetVal DummyMultiChannelGrabber::init( m_imageType = imgTypeGaussianSpotArray; } - setIdentifier(QString::number(getID())); - if (waitCond) { waitCond->returnValue = retVal; @@ -579,13 +579,30 @@ ito::RetVal DummyMultiChannelGrabber::close(ItomSharedSemaphore* waitCond) ito::RetVal DummyMultiChannelGrabber::getParameter( QSharedPointer val, const ParamMapIterator& it, - const QString& suffix, const QString& key, + const QString& suffix, int index, bool hasIndex, bool& ok) { - ok = false; + // just as a demo. If a specific parameter requires more actions than + // just returning its value, can be handled in this method. Else set ok to false, + // such that the returned parameter is the corresponding value in m_params and this + // is handled by AddInMultiChannelGrabber::getParam. + + if (key == "demoArbitraryString") + { + // do anything special, for instance request a current value from a hardware + // device, update the internal parameter and return this updated value. + *val = it.value(); + ok = true; + } + else + { + // let the calling method return the current value in m_params. + ok = false; + } + return ito::retOk; } @@ -621,9 +638,10 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( { running = grabberStartedCount(); setGrabberStarted(1); - retValue += stopDevice(NULL); + retValue += stopDevice(nullptr); } } + if (!retValue.containsError()) { int oldval = it->getVal(); diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 302b35590..c08485464 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -71,8 +71,25 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber ito::RetVal retrieveData(QSharedPointer> dataObjMap); ito::RetVal getValByMap(QSharedPointer> dataObjMap); ito::RetVal copyValByMap(QSharedPointer> dataObjMap); - ito::RetVal getParameter(QSharedPointer val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok); - ito::RetVal setParameter(QSharedPointer& val, const ParamMapIterator& it, const QString& suffix, const QString& key, int index, bool hasIndex, bool& ok, QStringList& pendingUpdate); + + ito::RetVal getParameter( + QSharedPointer val, + const ParamMapIterator& it, + const QString& key, + const QString& suffix, + int index, + bool hasIndex, + bool& ok); + + ito::RetVal setParameter( + QSharedPointer& val, + const ParamMapIterator& it, + const QString& suffix, + const QString& key, + int index, + bool hasIndex, + bool& ok, + QStringList& pendingUpdate); public: friend class DummyMultiChannelGrabberInterface; From 9d69054e01e267f4bc9994a3de3810e768eb3942 Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sun, 13 Aug 2023 00:35:28 +0200 Subject: [PATCH 38/43] more work for multi channel grabber demo plugin --- .../DummyMultiChannelGrabber.cpp | 330 ++++++++++++------ .../DummyMultiChannelGrabber.h | 11 +- 2 files changed, 225 insertions(+), 116 deletions(-) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index fd7e988af..e2b80774b 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -397,7 +397,7 @@ ito::RetVal DummyMultiChannelGrabber::init( pixelFormat3.setMeta(pixelFormat3Meta, true); ChannelContainer channel1(paramRoi, pixelFormat1, paramSizeX, paramSizeY); - channel1.m_channelParam["valueDescription"].setVal("intensity"); + channel1.m_channelParams["valueDescription"].setVal("intensity"); // every channel can also further additional parameters. // Rules: @@ -419,17 +419,17 @@ ito::RetVal DummyMultiChannelGrabber::init( channels["channelMono"] = channel1; ChannelContainer channel2(paramRoi, pixelFormat2, paramSizeX, paramSizeY); - channel2.m_channelParam["valueDescription"].setVal("topography"); + channel2.m_channelParams["valueDescription"].setVal("topography"); double axisScales[] = {0.05, 0.05}; - channel2.m_channelParam["axisScales"].setVal(axisScales, 2); + channel2.m_channelParams["axisScales"].setVal(axisScales, 2); ito::ByteArray axisUnits[] = { "mm", "mm" }; - channel2.m_channelParam["axisUnits"].setVal(axisUnits, 2); + channel2.m_channelParams["axisUnits"].setVal(axisUnits, 2); // add channel2 to the preliminary channel map. The channel name is 'channelTopo' as an example. channels["channelTopo"] = channel2; ChannelContainer channel3(paramRoi, pixelFormat3, paramSizeX, paramSizeY); - channel3.m_channelParam["valueDescription"].setVal("color"); + channel3.m_channelParams["valueDescription"].setVal("color"); channel3.addChannelParam(ito::Param( "gammaCorrection", @@ -680,29 +680,29 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( for (i = m_channels.begin(); i != m_channels.end(); ++i) // we need to adapt the roi for each channel { - width = (i.value().m_channelParam["roi"].getVal()[1] - - i.value().m_channelParam["roi"].getVal()[0]) * + width = (i.value().m_channelParams["roi"].getVal()[1] - + i.value().m_channelParams["roi"].getVal()[0]) * factorX; - height = (i.value().m_channelParam["roi"].getVal()[3] - - i.value().m_channelParam["roi"].getVal()[2]) * + height = (i.value().m_channelParams["roi"].getVal()[3] - + i.value().m_channelParams["roi"].getVal()[2]) * factorY; maxWidth = - static_cast(i.value().m_channelParam["roi"].getMeta()) + static_cast(i.value().m_channelParams["roi"].getMeta()) ->getWidthRangeMeta() .getSizeMax(); maxHeight = - static_cast(i.value().m_channelParam["roi"].getMeta()) + static_cast(i.value().m_channelParams["roi"].getMeta()) ->getHeightRangeMeta() .getSizeMax(); - sizeX = i.value().m_channelParam["roi"].getVal()[2] * factorX; - sizeY = i.value().m_channelParam["roi"].getVal()[3] * factorY; - offsetX = i.value().m_channelParam["roi"].getVal()[0] * factorX; - offsetY = i.value().m_channelParam["roi"].getVal()[1] * factorY; + sizeX = i.value().m_channelParams["roi"].getVal()[2] * factorX; + sizeY = i.value().m_channelParams["roi"].getVal()[3] * factorY; + offsetX = i.value().m_channelParams["roi"].getVal()[0] * factorX; + offsetY = i.value().m_channelParams["roi"].getVal()[1] * factorY; int roi[] = {offsetX, offsetY, sizeX, sizeY}; - i.value().m_channelParam["roi"].setVal(roi, 4); - i.value().m_channelParam["roi"].setMeta( + i.value().m_channelParams["roi"].setVal(roi, 4); + i.value().m_channelParams["roi"].setMeta( new ito::RectMeta( ito::RangeMeta( 0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), @@ -1120,6 +1120,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS { ito::RetVal retValue = ito::retOk; ItomSharedSemaphoreLocker locker(waitCond); + if (strcmp(m_params["triggerMode"].getVal(), "software") == 0) { retValue += generateImageData(); @@ -1134,6 +1135,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS .toLatin1() .data()); } + if (waitCond) { waitCond->returnValue = retValue; @@ -1144,54 +1146,102 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS return retValue; } -//------------------------------------------------------------------------------------- -//! Returns the grabbed camera frame as a shallow copy. -/*! - This method copies the recently grabbed camera frame to the given DataObject-handle - - \note This method is similar to VideoCapture::retrieve() of openCV - - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to - ito::DataObject*) where the acquired image is shallow-copied to. \param [in] waitCond is the - semaphore (default: NULL), which is released if this method has been terminated \return retOk if - everything is ok, retError is camera has not been started or no image has been acquired by the - method acquire. \sa DataObject, acquire -*/ -ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* waitCond) -{ - ItomSharedSemaphoreLocker locker(waitCond); - ito::DataObject* dObj = reinterpret_cast(vpdObj); - - ito::RetVal retValue(ito::retOk); - - retValue += retrieveData(); - - if (!retValue.containsError()) - { - if (dObj == NULL) - { - retValue += ito::RetVal( - ito::retError, - 1004, - tr("data object of getVal is NULL or cast failed").toLatin1().data()); - } - else - { - retValue += sendDataToListeners(0); // don't wait for live image, since user should get - // the image as fast as possible. - - (*dObj) = this->m_channels[m_params["defaultChannel"].getVal()].m_data; - } - } - - if (waitCond) - { - waitCond->returnValue = retValue; - waitCond->release(); - } - - return retValue; -} +////------------------------------------------------------------------------------------- +////! Returns the grabbed camera frame as a shallow copy. +///*! +// This method copies the recently grabbed camera frame to the given DataObject-handle +// +// \note This method is similar to VideoCapture::retrieve() of openCV +// +// \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to +// ito::DataObject*) where the acquired image is shallow-copied to. \param [in] waitCond is the +// semaphore (default: NULL), which is released if this method has been terminated \return retOk if +// everything is ok, retError is camera has not been started or no image has been acquired by the +// method acquire. \sa DataObject, acquire +//*/ +//ito::RetVal DummyMultiChannelGrabber::getVal(void* vpdObj, ItomSharedSemaphore* waitCond) +//{ +// ItomSharedSemaphoreLocker locker(waitCond); +// ito::RetVal retValue(ito::retOk); +// ito::DataObject* dObj = reinterpret_cast(vpdObj); +// +// if (!dObj) +// { +// retValue += ito::RetVal( +// ito::retError, 0, tr("Empty dataObject handle retrieved from caller").toLatin1().data()); +// } +// +// if (!retValue.containsError()) +// { +// retValue += retrieveData(); +// } +// +// if (!retValue.containsError()) +// { +// // don't wait for live image, since user should get the image as fast as possible. +// sendDataToListeners(0); +// +// (*dObj) = m_channels[m_params["defaultChannel"].getVal()].m_data; +// } +// +// if (waitCond) +// { +// waitCond->returnValue = retValue; +// waitCond->release(); +// } +// +// return retValue; +//} +// +////------------------------------------------------------------------------------------- +////! Returns the grabbed camera frame as a deep copy. +///*! +// This method copies the recently grabbed camera frame to the given DataObject. Therefore this +// camera size must fit to the data structure of the DataObject. +// +// \note This method is similar to VideoCapture::retrieve() of openCV +// +// \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to +// ito::DataObject*) where the acquired image is deep copied to. \param [in] waitCond is the +// semaphore (default: NULL), which is released if this method has been terminated \return retOk if +// everything is ok, retError is camera has not been started or no image has been acquired by the +// method acquire. \sa DataObject, acquire +//*/ +//ito::RetVal DummyMultiChannelGrabber::copyVal(void* vpdObj, ItomSharedSemaphore* waitCond) +//{ +// ItomSharedSemaphoreLocker locker(waitCond); +// ito::RetVal retValue(ito::retOk); +// ito::DataObject* dObj = reinterpret_cast(vpdObj); +// +// if (!dObj) +// { +// retValue += ito::RetVal( +// ito::retError, 0, tr("Empty dataObject handle retrieved from caller").toLatin1().data()); +// } +// else +// { +// retValue += checkData(dObj); +// } +// +// if (!retValue.containsError()) +// { +// retValue += retrieveData(dObj); +// } +// +// if (!retValue.containsError()) +// { +// don't wait for live image, since user should get the image as fast as possible. +// sendDataToListeners(0); +// } +// +// if (waitCond) +// { +// waitCond->returnValue = retValue; +// waitCond->release(); +// } +// +// return retValue; +//} //------------------------------------------------------------------------------------- ito::RetVal DummyMultiChannelGrabber::getValByMap( @@ -1289,80 +1339,138 @@ ito::RetVal DummyMultiChannelGrabber::copyValByMap( return retValue; } -//------------------------------------------------------------------------------------- -//! Returns the grabbed camera frame as a deep copy. -/*! - This method copies the recently grabbed camera frame to the given DataObject. Therefore this - camera size must fit to the data structure of the DataObject. - \note This method is similar to VideoCapture::retrieve() of openCV - \param [in,out] vpdObj is the pointer to a given dataObject (this pointer should be cast to - ito::DataObject*) where the acquired image is deep copied to. \param [in] waitCond is the - semaphore (default: NULL), which is released if this method has been terminated \return retOk if - everything is ok, retError is camera has not been started or no image has been acquired by the - method acquire. \sa DataObject, acquire -*/ -ito::RetVal DummyMultiChannelGrabber::copyVal(void* vpdObj, ItomSharedSemaphore* waitCond) +//------------------------------------------------------------------------------------- +ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalDataObject) { - ItomSharedSemaphoreLocker locker(waitCond); ito::RetVal retValue(ito::retOk); - ito::DataObject* dObj = reinterpret_cast(vpdObj); - if (!dObj) + if (m_isgrabbing == false) { retValue += ito::RetVal( - ito::retError, 0, tr("Empty object handle retrieved from caller").toLatin1().data()); + ito::retError, + 1002, + tr("image could not be obtained since no image has been acquired.").toLatin1().data()); } else { - retValue += checkData(dObj); - } + if (externalDataObject) + { + auto internalImage = getCurrentDefaultChannel().m_data; + internalImage.deepCopyPartial(*externalDataObject); + } - if (!retValue.containsError()) - { - retValue += retrieveData(dObj); + m_isgrabbing = false; } - if (!retValue.containsError()) + return retValue; +} + +//------------------------------------------------------------------------------------- +ito::Rgba32 hsv2rgb(float hue, float saturation, float intensity, ito::uint8 alpha) +{ + double hh, p, q, t, ff; + long i; + ito::Rgba32 out; + + out.a = alpha; + + if (saturation <= 0.0) { - sendDataToListeners( - 0); // don't wait for live image, since user should get the image as fast as possible. + // < is bogus, just shuts up warnings + out.r = intensity * 255; + out.g = out.b = out.r; + return out; } - if (waitCond) + hh = hue * 360; + + if (hh >= 360.0) { - waitCond->returnValue = retValue; - waitCond->release(); + hh = 0.0; } - return retValue; + hh /= 60.0; + + i = (long)hh; + ff = hh - i; + p = intensity * (1.0 - saturation); + q = intensity * (1.0 - (saturation * ff)); + t = intensity * (1.0 - (saturation * (1.0 - ff))); + + switch (i) { + case 0: + out.r = intensity; + out.g = t; + out.b = p; + break; + case 1: + out.r = q; + out.g = intensity; + out.b = p; + break; + case 2: + out.r = p; + out.g = intensity; + out.b = t; + break; + + case 3: + out.r = p; + out.g = q; + out.b = intensity; + break; + case 4: + out.r = t; + out.g = p; + out.b = intensity; + break; + case 5: + default: + out.r = intensity; + out.g = p; + out.b = q; + break; + } + return out; } //------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalDataObject) +void DummyMultiChannelGrabber::fillColorImage(ito::DataObject& img, const cv::Point2f& centerPixel, const float radius, bool hasAlpha) const { - ito::RetVal retValue(ito::retOk); + Q_ASSERT_X(img.getType() == ito::tRGBA32, "fillNextColorImage", "img must be of type rgba32"); - if (m_isgrabbing == false) - { - retValue += ito::RetVal( - ito::retError, - 1002, - tr("image could not be obtained since no image has been acquired.").toLatin1().data()); - } - else + int height = img.getSize()[0]; + int width = img.getSize()[1]; + float hue, saturation, intensity, alpha; + float dx, dy, r_square; + float sigma_square = radius * radius; + + alpha = 1.0; + intensity = 1.0; + + for (int i = 0; i < height; ++i) { - if (externalDataObject) + ito::Rgba32* ptr = img.rowPtr(0, i); + + for (int j = 0; j < width; ++j) { - m_channels[m_params["defaultChannel"].getVal()].m_data.deepCopyPartial( - *externalDataObject); - } + dx = j - centerPixel.x; + dy = i - centerPixel.y; + r_square = dx * dx + dy * dy; - m_isgrabbing = false; - } + hue = cv::fastAtan2(dy, dx) / 360.0; + saturation = cv::exp(-0.5 * r_square / sigma_square); - return retValue; + if (hasAlpha) + { + alpha = saturation; + } + + ptr[j] = hsv2rgb(hue, saturation, intensity, alpha * 255); + } + } } //------------------------------------------------------------------------------------- diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index c08485464..3feeb665c 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -67,8 +67,7 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber ~DummyMultiChannelGrabber(); DummyMultiChannelGrabber(); - ito::RetVal retrieveData(ito::DataObject* externalDataObject = NULL); - ito::RetVal retrieveData(QSharedPointer> dataObjMap); + ito::RetVal getValByMap(QSharedPointer> dataObjMap); ito::RetVal copyValByMap(QSharedPointer> dataObjMap); @@ -111,6 +110,9 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber imgTypeGaussianSpotArray, }; + // fills a rgba32 dataObject with a color image + void fillColorImage(ito::DataObject& img, const cv::Point2f& centerPixel, const float radius, bool hasAlpha) const; + signals: public slots: @@ -120,9 +122,8 @@ public slots: ito::RetVal startDevice(ItomSharedSemaphore* waitCond); ito::RetVal stopDevice(ItomSharedSemaphore* waitCond); - ito::RetVal acquire(const int trigger, ItomSharedSemaphore* waitCond = NULL); - ito::RetVal getVal(void* dObj, ItomSharedSemaphore* waitCond); - ito::RetVal copyVal(void* vpdObj, ItomSharedSemaphore* waitCond); + ito::RetVal acquire(const int trigger, ItomSharedSemaphore* waitCond = nullptr); + private slots: void dockWidgetVisibilityChanged(bool visible); From ed69e5bd215979e31421781f87bb0442f768ee94 Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:12:46 +0200 Subject: [PATCH 39/43] more steps for running DummyMultiChannelGrabber --- DummyMultiChannelGrabber/CMakeLists.txt | 15 +- .../DummyMultiChannelGrabber.cpp | 898 +++++------------- .../DummyMultiChannelGrabber.h | 26 +- DummyMultiChannelGrabber/cameraEmulator.cpp | 242 +++++ DummyMultiChannelGrabber/cameraEmulator.h | 57 ++ 5 files changed, 538 insertions(+), 700 deletions(-) create mode 100644 DummyMultiChannelGrabber/cameraEmulator.cpp create mode 100644 DummyMultiChannelGrabber/cameraEmulator.h diff --git a/DummyMultiChannelGrabber/CMakeLists.txt b/DummyMultiChannelGrabber/CMakeLists.txt index 13e9da3a8..cedea5296 100644 --- a/DummyMultiChannelGrabber/CMakeLists.txt +++ b/DummyMultiChannelGrabber/CMakeLists.txt @@ -30,9 +30,6 @@ itom_find_package_qt(ON Core Widgets LinguistTools) find_package(OpenCV COMPONENTS core REQUIRED) - - - include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} @@ -42,7 +39,8 @@ include_directories( set(PLUGIN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.h ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.h - ${CMAKE_CURRENT_SOURCE_DIR}/DummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/cameraEmulator.h ${CMAKE_CURRENT_SOURCE_DIR}/pluginVersion.h ${CMAKE_CURRENT_BINARY_DIR}/gitVersion.h ) @@ -52,10 +50,11 @@ set(PLUGIN_UI ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.ui ) -set(PLUGIN_SOURCES +set(PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/DummyMultiChannelGrabber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cameraEmulator.cpp ) #Add version information to the plugIn-dll unter MSVC @@ -89,6 +88,6 @@ set(COPY_SOURCES "") set(COPY_DESTINATIONS "") itom_add_pluginlibrary_to_copy_list(${target_name} COPY_SOURCES COPY_DESTINATIONS) - + itom_add_plugin_qm_files_to_copy_list(${target_name} QM_FILES COPY_SOURCES COPY_DESTINATIONS) -itom_post_build_copy_files(${target_name} COPY_SOURCES COPY_DESTINATIONS) \ No newline at end of file +itom_post_build_copy_files(${target_name} COPY_SOURCES COPY_DESTINATIONS) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp index e2b80774b..2f0ae04e8 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp @@ -23,7 +23,7 @@ #define ITOM_IMPORT_API #define ITOM_IMPORT_PLOTAPI -#include "DummyMultiChannelGrabber.h" +#include "dummyMultiChannelGrabber.h" #ifndef WIN32 #include @@ -40,73 +40,7 @@ #include #endif -//------------------------------------------------------------------------------------- -/** @func fastrand - * @brief function for pseudo random values - * - * This function delivers the noise for the image. - */ -template inline _Tp fastrand(cv::RNG& rng, _Tp maxval, float offset, float gain) -{ - return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); -} - -//------------------------------------------------------------------------------------- -/** @func fastrand - * @brief function for pseudo random values - * - * This function delivers the noise for the image. - */ -template -inline _Tp fastrand_mean(cv::RNG& rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) -{ - ito::uint32 val = 0; - - for (ito::uint8 i = 0; i < numMeans; ++i) - { - val += ((ito::uint32)rng.next()) & maxval; - } - return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); -} - -//------------------------------------------------------------------------------------- -/** @func gaussFunc - * @brief function for 2d Gaussian function - * - * This function delivers a 2d dataObject with a Gaussian function - */ -template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject dObj, float amplitude) -{ - int width = dObj.getSize(1); - int height = dObj.getSize(0); - _Tp* rowPtr; - float xval, yval; - int planeID = dObj.seekMat(0); - - float yRandOffset = rng.uniform(0.f, 20.f); - float xRandOffset = rng.uniform(0.f, 20.f); - float aRandOfset = rng.uniform(0.f, 20.f); - - float sigmaX = width * rng.uniform(0.09f, 0.11f); - float sigmaY = height * rng.uniform(0.09f, 0.11f); - - for (int y = 0; y < height; y++) - { - rowPtr = dObj.rowPtr<_Tp>(planeID, y); - yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / - (2.0f * sigmaY * sigmaY); - - for (int x = 0; x < width; x++) - { - xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / - (2.0f * sigmaX * sigmaX); - rowPtr[x] = (float)(amplitude - aRandOfset) * exp(-(xval + yval)); - } - } - - return ito::retOk; -} //------------------------------------------------------------------------------------- /*! @@ -249,20 +183,6 @@ This plugin can also be used as template for other grabbers."); m->addItem("rgb8"); param.setMeta(m, true); m_initParamsOpt.append(param); - - param = ito::Param( - "imageType", - ito::ParamBase::String | ito::ParamBase::In, - "noise", - tr("Available dummy image types: noise (default), gaussianSpot, gaussianSpotArray") - .toLatin1() - .data()); - ito::StringMeta sm(ito::StringMeta::String, "noise"); - sm.addItem("gaussianSpot"); - sm.addItem("gaussianSpotArray"); - param.setMeta(&sm, false); - - m_initParamsOpt.append(param); } //------------------------------------------------------------------------------------- @@ -310,9 +230,7 @@ const ito::RetVal DummyMultiChannelGrabber::showConfDialog(void) \sa ito::tParam, createDockWidget, setParam, getParam */ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : - AddInMultiChannelGrabber("DummyMultiChannelGrabber"), m_isgrabbing(false), - m_startOfLastAcquisition(0), m_freerunTimer(this), - m_imageType(imgTypeNoise) + AddInMultiChannelGrabber("DummyMultiChannelGrabber") { if (hasGuiSupport()) { @@ -323,7 +241,6 @@ DummyMultiChannelGrabber::DummyMultiChannelGrabber() : QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable; createDockWidget(QString(m_params["name"].getVal()), features, areas, dw); } - connect(&m_freerunTimer, &QTimer::timeout, this, &DummyMultiChannelGrabber::generateImageData); } //------------------------------------------------------------------------------------- @@ -397,7 +314,7 @@ ito::RetVal DummyMultiChannelGrabber::init( pixelFormat3.setMeta(pixelFormat3Meta, true); ChannelContainer channel1(paramRoi, pixelFormat1, paramSizeX, paramSizeY); - channel1.m_channelParams["valueDescription"].setVal("intensity"); + channel1.m_channelParams["valueDescription"].setVal("intensity"); // every channel can also further additional parameters. // Rules: @@ -419,7 +336,7 @@ ito::RetVal DummyMultiChannelGrabber::init( channels["channelMono"] = channel1; ChannelContainer channel2(paramRoi, pixelFormat2, paramSizeX, paramSizeY); - channel2.m_channelParams["valueDescription"].setVal("topography"); + channel2.m_channelParams["valueDescription"].setVal("topography"); double axisScales[] = {0.05, 0.05}; channel2.m_channelParams["axisScales"].setVal(axisScales, 2); ito::ByteArray axisUnits[] = { "mm", "mm" }; @@ -429,7 +346,7 @@ ito::RetVal DummyMultiChannelGrabber::init( channels["channelTopo"] = channel2; ChannelContainer channel3(paramRoi, pixelFormat3, paramSizeX, paramSizeY); - channel3.m_channelParams["valueDescription"].setVal("color"); + channel3.m_channelParams["valueDescription"].setVal("color"); channel3.addChannelParam(ito::Param( "gammaCorrection", @@ -458,6 +375,16 @@ ito::RetVal DummyMultiChannelGrabber::init( 1, tr("this is a global parameter").toLatin1().data()); + ito::Param exposureTime( + "exposureTime", + ito::ParamBase::Double, + 1.e-6, + 0.5, + 10.e-3, + tr("the exposure time for all channels. This is the time that is used to acquire one frame.").toLatin1().data()); + exposureTime.getMetaT()->setRepresentation(ito::ParamMeta::Logarithmic); + globalParams << exposureTime; + auto paramVal = ito::Param( "demoRegexpString", ito::ParamBase::String, @@ -508,22 +435,6 @@ ito::RetVal DummyMultiChannelGrabber::init( setIdentifier(QString::number(getID())); - // get type of dummy image - QString type = paramsOpt->at(4).getVal(); - - if (type == "noise") - { - m_imageType = imgTypeNoise; - } - else if (type == "gaussianSpot") - { - m_imageType = imgTypeGaussianSpot; - } - else if (type == "gaussianSpotArray") - { - m_imageType = imgTypeGaussianSpotArray; - } - if (waitCond) { waitCond->returnValue = retVal; @@ -630,165 +541,186 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( int running = 0; // Used to check if grabber was running bevor // first check parameters that influence the size or data type of m_channels - if (key == "binning") - { - if (!retValue.containsError()) - { - if (grabberStartedCount() > 0) - { - running = grabberStartedCount(); - setGrabberStarted(1); - retValue += stopDevice(nullptr); - } - } + //if (key == "binning") + //{ + // if (!retValue.containsError()) + // { + // if (grabberStartedCount() > 0) + // { + // running = grabberStartedCount(); + // setGrabberStarted(1); + // retValue += stopDevice(nullptr); + // } + // } + + // if (!retValue.containsError()) + // { + // int oldval = it->getVal(); + + // int ival = val->getVal(); + // int newY = ival % 100; + // int newX = (ival - newY) / 100; + + // if (m_lineCamera && (newY != 1)) + // { + // retValue += ito::RetVal( + // ito::retError, 0, "the vertical binning for a line camera must be 1"); + // } + // else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) + // { + // retValue += ito::RetVal( + // ito::retError, + // 0, + // "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + " + // "horizontal)"); + // } + // else + // { + // m_totalBinning = newX * newY; + + // retValue += it->copyValueFrom(&(*val)); + + // if (oldval != ival) + // { + // int oldY = oldval % 100; + // int oldX = (oldval - oldY) / 100; + // float factorX = (float)oldX / (float)newX; + // float factorY = (float)oldY / (float)newY; + // int width, height, maxWidth, maxHeight, sizeX, sizeY, offsetX, offsetY; + // QMap::iterator i; + // for (i = m_channels.begin(); i != m_channels.end(); + // ++i) // we need to adapt the roi for each channel + // { + // width = (i.value().m_channelParams["roi"].getVal()[1] - + // i.value().m_channelParams["roi"].getVal()[0]) * + // factorX; + // height = (i.value().m_channelParams["roi"].getVal()[3] - + // i.value().m_channelParams["roi"].getVal()[2]) * + // factorY; + + // maxWidth = + // static_cast(i.value().m_channelParams["roi"].getMeta()) + // ->getWidthRangeMeta() + // .getSizeMax(); + // maxHeight = + // static_cast(i.value().m_channelParams["roi"].getMeta()) + // ->getHeightRangeMeta() + // .getSizeMax(); + + // sizeX = i.value().m_channelParams["roi"].getVal()[2] * factorX; + // sizeY = i.value().m_channelParams["roi"].getVal()[3] * factorY; + // offsetX = i.value().m_channelParams["roi"].getVal()[0] * factorX; + // offsetY = i.value().m_channelParams["roi"].getVal()[1] * factorY; + // int roi[] = {offsetX, offsetY, sizeX, sizeY}; + // i.value().m_channelParams["roi"].setVal(roi, 4); + // i.value().m_channelParams["roi"].setMeta( + // new ito::RectMeta( + // ito::RangeMeta( + // 0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), + // ito::RangeMeta( + // 0, + // height - 1, + // 4 / newY, + // 4 / newY, + // maxHeight * factorY, + // 4 / newY)), + // true); + // if (i.key() == m_params["defaultChannel"].getVal()) + // { + // m_params["roi"].setVal(roi, 4); + // m_params["roi"].setMeta( + // new ito::RectMeta( + // ito::RangeMeta( + // 0, + // width - 1, + // 4 / newX, + // 4 / newX, + // maxWidth * factorX, + // 4 / newX), + // ito::RangeMeta( + // 0, + // height - 1, + // 4 / newY, + // 4 / newY, + // maxHeight * factorY, + // 4 / newY)), + // true); + // } + // } + // pendingUpdate << "roi" + // << "binning"; // add roi to update list to trigger a update of + // // sizey and sizey + // } + // } + // } + // if (running) + // { + // retValue += startDevice(NULL); + // setGrabberStarted(running); + // } + // ok = true; + //} + + //if (key == "roi") + //{ + // m_isgrabbing = false; // we need to trigger again since the roi changed + // ok = false; // we want to further process the parameter by setParam to set the size etc. + //} + + //if (key == "integration_time") + //{ + // bool timerIsRunning = m_freerunTimer.isActive(); + // m_freerunTimer.stop(); + // m_freerunTimer.setInterval( + // int((val->getVal() + m_params["frame_time"].getVal()) * 1000.0)); + // if (timerIsRunning) + // { + // m_freerunTimer.start(); + // } + // ok = false; + //} + + //if (key == "frame_time") + //{ + // bool timerIsRunning = m_freerunTimer.isActive(); + // m_freerunTimer.stop(); + // m_freerunTimer.setInterval( + // int((val->getVal() + m_params["integration_time"].getVal()) * 1000.0)); + // if (timerIsRunning) + // { + // m_freerunTimer.start(); + // } + // ok = false; + //} + //else + //{ + // ok = false; // set ok to false to let setParam process the parameter + // + //} + + ok = false; // set ok to false to let setParam process the parameter - if (!retValue.containsError()) - { - int oldval = it->getVal(); - - int ival = val->getVal(); - int newY = ival % 100; - int newX = (ival - newY) / 100; - - if (m_lineCamera && (newY != 1)) - { - retValue += ito::RetVal( - ito::retError, 0, "the vertical binning for a line camera must be 1"); - } - else if ((newX != 1 && newX != 2 && newX != 4) || (newY != 1 && newY != 2 && newY != 4)) - { - retValue += ito::RetVal( - ito::retError, - 0, - "horizontal and vertical binning must be 1, 2 or 4 (hence vertical * 100 + " - "horizontal)"); - } - else - { - m_totalBinning = newX * newY; - - retValue += it->copyValueFrom(&(*val)); - - if (oldval != ival) - { - int oldY = oldval % 100; - int oldX = (oldval - oldY) / 100; - float factorX = (float)oldX / (float)newX; - float factorY = (float)oldY / (float)newY; - int width, height, maxWidth, maxHeight, sizeX, sizeY, offsetX, offsetY; - QMap::iterator i; - for (i = m_channels.begin(); i != m_channels.end(); - ++i) // we need to adapt the roi for each channel - { - width = (i.value().m_channelParams["roi"].getVal()[1] - - i.value().m_channelParams["roi"].getVal()[0]) * - factorX; - height = (i.value().m_channelParams["roi"].getVal()[3] - - i.value().m_channelParams["roi"].getVal()[2]) * - factorY; - - maxWidth = - static_cast(i.value().m_channelParams["roi"].getMeta()) - ->getWidthRangeMeta() - .getSizeMax(); - maxHeight = - static_cast(i.value().m_channelParams["roi"].getMeta()) - ->getHeightRangeMeta() - .getSizeMax(); - - sizeX = i.value().m_channelParams["roi"].getVal()[2] * factorX; - sizeY = i.value().m_channelParams["roi"].getVal()[3] * factorY; - offsetX = i.value().m_channelParams["roi"].getVal()[0] * factorX; - offsetY = i.value().m_channelParams["roi"].getVal()[1] * factorY; - int roi[] = {offsetX, offsetY, sizeX, sizeY}; - i.value().m_channelParams["roi"].setVal(roi, 4); - i.value().m_channelParams["roi"].setMeta( - new ito::RectMeta( - ito::RangeMeta( - 0, width - 1, 4 / newX, 4 / newX, maxWidth * factorX, 4 / newX), - ito::RangeMeta( - 0, - height - 1, - 4 / newY, - 4 / newY, - maxHeight * factorY, - 4 / newY)), - true); - if (i.key() == m_params["defaultChannel"].getVal()) - { - m_params["roi"].setVal(roi, 4); - m_params["roi"].setMeta( - new ito::RectMeta( - ito::RangeMeta( - 0, - width - 1, - 4 / newX, - 4 / newX, - maxWidth * factorX, - 4 / newX), - ito::RangeMeta( - 0, - height - 1, - 4 / newY, - 4 / newY, - maxHeight * factorY, - 4 / newY)), - true); - } - } - pendingUpdate << "roi" - << "binning"; // add roi to update list to trigger a update of - // sizey and sizey - } - } - } - if (running) - { - retValue += startDevice(NULL); - setGrabberStarted(running); - } - ok = true; - } + sendDataToListeners(0); - if (key == "roi") - { - m_isgrabbing = false; // we need to trigger again since the roi changed - ok = false; // we want to further process the parameter by setParam to set the size etc. - } + return retValue; +} - if (key == "integration_time") - { - bool timerIsRunning = m_freerunTimer.isActive(); - m_freerunTimer.stop(); - m_freerunTimer.setInterval( - int((val->getVal() + m_params["frame_time"].getVal()) * 1000.0)); - if (timerIsRunning) - { - m_freerunTimer.start(); - } - ok = false; - } +//------------------------------------------------------------------------------------- +ito::RetVal DummyMultiChannelGrabber::retrieveData(const QStringList& channels /*= QStringList()*/) +{ + ito::RetVal retVal; - if (key == "frame_time") - { - bool timerIsRunning = m_freerunTimer.isActive(); - m_freerunTimer.stop(); - m_freerunTimer.setInterval( - int((val->getVal() + m_params["integration_time"].getVal()) * 1000.0)); - if (timerIsRunning) - { - m_freerunTimer.start(); - } - ok = false; - } - else - { - ok = false; // set ok to false to let setParam process the parameter - } + return retVal; +} - sendDataToListeners(0); +//------------------------------------------------------------------------------------- +QRect roiParamToRect(const ito::ParamBase& roiParam) +{ + const int* roi = roiParam.getVal(); + // int roi[] = { 0, 0, sensorWidth, sensorHeight }; - return retValue; + QRect r(roi[0], roi[1], roi[2], roi[3]); + return r; } //------------------------------------------------------------------------------------- @@ -806,24 +738,35 @@ ito::RetVal DummyMultiChannelGrabber::setParameter( ito::RetVal DummyMultiChannelGrabber::startDevice(ItomSharedSemaphore* waitCond) { ItomSharedSemaphoreLocker locker(waitCond); - ito::RetVal retValue = ito::retOk; - checkData(); // this will be reallocated in this method. + ito::RetVal retValue; incGrabberStarted(); if (grabberStartedCount() == 1) { - m_startOfLastAcquisition = 0; - m_isgrabbing = false; - } - if (strcmp(m_params["triggerMode"].getVal(), "freerun") == 0) - { - m_freerunTimer.start( - int((m_params["frame_time"].getVal() + - m_params["integration_time"].getVal()) * - 1000.0)); + // the grabber is started for the first time + retValue += checkData(); + + if (retValue == ito::retOk) + { + // configure emulator for mono image + QByteArray pixelFormatMono = m_channels["channelMono"].m_channelParams["pixelFormat"].getVal(); + QRect roiMono = roiParamToRect(m_channels["channelMono"].m_channelParams["roi"]); + m_camEmulator.configureImageMono(roiMono, pixelFormatMono.mid(4 /*mono*/).toInt()); + + // configure emulator for topography image (here: float) + QByteArray pixelFormatTopo = m_channels["channelTopo"].m_channelParams["pixelFormat"].getVal(); + QRect roiTopo = roiParamToRect(m_channels["channelTopo"].m_channelParams["roi"]); + m_camEmulator.configureImageTopography(roiTopo, pixelFormatTopo.mid(5 /*float*/).toInt() == 32); + + // configure emulator for colour image + QByteArray pixelFormatColour = m_channels["channelColour"].m_channelParams["pixelFormat"].getVal(); + QRect roiColour = roiParamToRect(m_channels["channelColour"].m_channelParams["roi"]); + m_camEmulator.configureImageColor(roiColour, pixelFormatColour == "rgba32"); + } } + if (waitCond) { waitCond->returnValue = retValue; @@ -851,6 +794,7 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) ito::RetVal retValue = ito::retOk; decGrabberStarted(); + if (grabberStartedCount() < 0) { retValue += ito::RetVal( @@ -862,10 +806,7 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) .data()); setGrabberStarted(0); } - else - { - m_freerunTimer.stop(); - } + if (waitCond) { waitCond->returnValue = retValue; @@ -875,232 +816,6 @@ ito::RetVal DummyMultiChannelGrabber::stopDevice(ItomSharedSemaphore* waitCond) return retValue; } -//------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::generateImageData() -{ - ito::RetVal retValue = ito::retOk; - double frame_time = m_params["frame_time"].getVal(); - double integration_time = m_params["integration_time"].getVal(); - float gain = m_params["gain"].getVal(); - float offset = m_params["offset"].getVal(); - int min, max = 0; - bool ok = false; - AbstractAddInGrabber::minMaxBoundariesFromIntegerPixelFormat( - m_params["pixelFormat"].getVal(), min, max, ok); - if (!ok) - { - retValue += ito::RetVal( - ito::retError, 0, tr("pixel format is not a integer format").toLatin1().data()); - } - if (grabberStartedCount() <= 0) - { - retValue += ito::RetVal( - ito::retError, - 1002, - tr("Can not acquire image, since camera has not been " - "started.") - .toLatin1() - .data()); - } - if (!retValue.containsError()) - { - m_isgrabbing = true; - if (strcmp(m_params["triggerMode"].getVal(), "software") == 0 && - (frame_time > 0.0)) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < frame_time) - { - Sleep((frame_time - diff) * 1000.0); - } - } - - m_startOfLastAcquisition = cv::getTickCount(); - // ito::uint32 seed = m_startOfLastAcquisition % std::numeric_limits::max(); - cv::RNG& rng = cv::theRNG(); - - if (m_imageType == imgTypeNoise) - { - if (m_totalBinning == 1) - { - if (max < 256) - { - ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8* linePtr; - foreach (ChannelContainer container, m_channels) - { - ito::DataObject& channelObj = container.m_data; - - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - } - else if (max < 65536) - { - ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16* linePtr; - foreach (ChannelContainer container, m_channels) - { - ito::DataObject& channelObj = container.m_data; - - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand(rng, maxInt, offset, gain); - } - } - } - } - } - else - { - if (max < 256) - { - ito::uint8 maxInt = cv::saturate_cast(max); - ito::uint8* linePtr; - foreach (ChannelContainer container, m_channels) - { - ito::DataObject& channelObj = container.m_data; - - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint8*)channelObj.rowPtr(0, m); - - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean( - rng, maxInt, m_totalBinning, offset, gain); - } - } - } - } - else if (max < 65536) - { - ito::uint16 maxInt = cv::saturate_cast(max); - ito::uint16* linePtr; - foreach (ChannelContainer container, m_channels) - { - ito::DataObject& channelObj = container.m_data; - - for (int m = 0; m < channelObj.getSize(0); ++m) - { - linePtr = (ito::uint16*)channelObj.rowPtr(0, m); - - for (int n = 0; n < channelObj.getSize(1); ++n) - { - *linePtr++ = fastrand_mean( - rng, maxInt, m_totalBinning, offset, gain); - } - } - } - } - } - } - else if (m_imageType == imgTypeGaussianSpot) // create dummy Gaussian image - { - if (max < 256) - { - ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, 8) - 1); - foreach (ChannelContainer container, m_channels) - { - gaussFunc(rng, container.m_data, amplitude); - } - } - else if (max < 65536) - { - ito::uint16 amplitude = cv::saturate_cast(cv::pow(2.0, 16) - 1); - foreach (ChannelContainer container, m_channels) - { - gaussFunc(rng, container.m_data, amplitude); - } - } - else if (max < 2147483647) - { - ito::uint32 amplitude = cv::saturate_cast(cv::pow(2.0, 32) - 1); - foreach (ChannelContainer container, m_channels) - { gaussFunc(rng, container.m_data, amplitude); - } - } - } - else if (m_imageType == imgTypeGaussianSpotArray) - { - ito::DataObject droi; - - int width = - this->m_channels[m_params["defaultChannel"].getVal()].m_data.getSize(1); - int height = - this->m_channels[m_params["defaultChannel"].getVal()].m_data.getSize(0); - - int roiwidth = (int)width / 2; - int roiheight = (int)height / 2; - - int roi[4][4] = { - {-0, -roiheight, -roiwidth, 0}, - {-0, -roiheight, 0, -roiwidth}, - {-roiheight, 0, -roiwidth, 0}, - {-roiheight, 0, 0, -roiwidth}}; - - for (int cnt = 0; cnt < 4; cnt++) - { - foreach (ChannelContainer container, m_channels) - { - droi = container.m_data; - droi = droi.adjustROI(roi[cnt][0], roi[cnt][1], roi[cnt][2], roi[cnt][3]); - - if (max < 256) - { - ito::uint8 amplitude = cv::saturate_cast(cv::pow(2.0, 8) - 1); - gaussFunc(rng, droi, amplitude); - } - else if (max < 65536) - { - ito::uint16 amplitude = - cv::saturate_cast(cv::pow(2.0, 16) - 1); - gaussFunc(rng, droi, amplitude); - } - else if (max < 2147483647) - { - ito::uint32 amplitude = - cv::saturate_cast(cv::pow(2.0, 32) - 1); - gaussFunc(rng, droi, amplitude); - } - } - } - } - - if ((strcmp(m_params["triggerMode"].getVal(), "software") == 0) && - (integration_time > 0.0)) - { - double diff = (cv::getTickCount() - m_startOfLastAcquisition) / cv::getTickFrequency(); - - if (diff < integration_time) - { - Sleep((integration_time - diff) * 1000.0); - } - } - } - ////pack all channel images to a QMap - QSharedPointer> returnMap(new QMap); - QMap::iterator it = m_channels.begin(); - while (it != m_channels.end()) - { - (*returnMap)[it.key()] = it.value().m_data; - ++it; - } - emit newData(returnMap); - return retValue; -} //------------------------------------------------------------------------------------- //! Call this method to trigger a new image. @@ -1121,20 +836,7 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS ito::RetVal retValue = ito::retOk; ItomSharedSemaphoreLocker locker(waitCond); - if (strcmp(m_params["triggerMode"].getVal(), "software") == 0) - { - retValue += generateImageData(); - } - else - { - retValue += ito::RetVal( - ito::retWarning, - 0, - tr("The trigger mode of the camera is set to freerun therefore calling acquire is " - "useless.") - .toLatin1() - .data()); - } + double exposureTimeS = m_params["exposureTime"].getVal(); if (waitCond) { @@ -1142,6 +844,18 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS waitCond->release(); } + // the emulator + if (m_camEmulator.grabImages(true, true, true, exposureTimeS * 1000.0)) + { + m_camEmulator.imageMono().deepCopyPartial(m_channels["channelMono"].m_data); + m_camEmulator.imageTopography().deepCopyPartial(m_channels["channelTopo"].m_data); + m_camEmulator.imageColor().deepCopyPartial(m_channels["channelColour"].m_data); + } + else + { + // todo + } + return retValue; } @@ -1243,129 +957,6 @@ ito::RetVal DummyMultiChannelGrabber::acquire(const int /*trigger*/, ItomSharedS // return retValue; //} -//------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::getValByMap( - QSharedPointer> dataObjMap) -{ - ito::RetVal retValue(ito::retOk); - - retValue += retrieveData(); - - if (!retValue.containsError()) - { - if (dataObjMap == NULL) - { - retValue += ito::RetVal( - ito::retError, - 1004, - tr("QMap of getVal is NULL").toLatin1().data()); - } - else - { - retValue += sendDataToListeners(0); // don't wait for live image, since user should get - // the image as fast as possible. - QMap::iterator it = (*dataObjMap).begin(); - while (it != (*dataObjMap).end()) - { - *(it.value()) = this->m_channels[it.key()].m_data; - ++it; - } - } - } - return retValue; -} - -//------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::retrieveData( - QSharedPointer> dataObjMap) -{ - ito::RetVal retValue(ito::retOk); - - if (m_isgrabbing == false) - { - retValue += ito::RetVal( - ito::retError, - 1002, - tr("image could not be obtained since no image has been acquired.").toLatin1().data()); - } - else - { - if (dataObjMap) - { - QMap::const_iterator it = (*dataObjMap).constBegin(); - while (it != (*dataObjMap).constEnd()) - { - m_channels[it.key()].m_data.deepCopyPartial(*it.value()); - ++it; - } - } - - m_isgrabbing = false; - } - - return retValue; -} - -//------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::copyValByMap( - QSharedPointer> dataObjMap) -{ - ito::RetVal retValue(ito::retOk); - - retValue += checkData(*dataObjMap); - retValue += retrieveData(dataObjMap); - - if (!retValue.containsError()) - { - if (dataObjMap == NULL) - { - retValue += ito::RetVal( - ito::retError, - 1004, - tr("QMap of getVal is NULL").toLatin1().data()); - } - else - { - retValue += sendDataToListeners(0); // don't wait for live image, since user should get - // the image as fast as possible. - QMap::iterator it = (*dataObjMap).begin(); - while (it != (*dataObjMap).end()) - { - *(it.value()) = this->m_channels[it.key()].m_data; - ++it; - } - } - } - return retValue; -} - - - -//------------------------------------------------------------------------------------- -ito::RetVal DummyMultiChannelGrabber::retrieveData(ito::DataObject* externalDataObject) -{ - ito::RetVal retValue(ito::retOk); - - if (m_isgrabbing == false) - { - retValue += ito::RetVal( - ito::retError, - 1002, - tr("image could not be obtained since no image has been acquired.").toLatin1().data()); - } - else - { - if (externalDataObject) - { - auto internalImage = getCurrentDefaultChannel().m_data; - internalImage.deepCopyPartial(*externalDataObject); - } - - m_isgrabbing = false; - } - - return retValue; -} //------------------------------------------------------------------------------------- ito::Rgba32 hsv2rgb(float hue, float saturation, float intensity, ito::uint8 alpha) @@ -1436,43 +1027,6 @@ ito::Rgba32 hsv2rgb(float hue, float saturation, float intensity, ito::uint8 alp return out; } -//------------------------------------------------------------------------------------- -void DummyMultiChannelGrabber::fillColorImage(ito::DataObject& img, const cv::Point2f& centerPixel, const float radius, bool hasAlpha) const -{ - Q_ASSERT_X(img.getType() == ito::tRGBA32, "fillNextColorImage", "img must be of type rgba32"); - - int height = img.getSize()[0]; - int width = img.getSize()[1]; - float hue, saturation, intensity, alpha; - float dx, dy, r_square; - float sigma_square = radius * radius; - - alpha = 1.0; - intensity = 1.0; - - for (int i = 0; i < height; ++i) - { - ito::Rgba32* ptr = img.rowPtr(0, i); - - for (int j = 0; j < width; ++j) - { - dx = j - centerPixel.x; - dy = i - centerPixel.y; - r_square = dx * dx + dy * dy; - - hue = cv::fastAtan2(dy, dx) / 360.0; - saturation = cv::exp(-0.5 * r_square / sigma_square); - - if (hasAlpha) - { - alpha = saturation; - } - - ptr[j] = hsv2rgb(hue, saturation, intensity, alpha * 255); - } - } -} - //------------------------------------------------------------------------------------- void DummyMultiChannelGrabber::dockWidgetVisibilityChanged(bool visible) { diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h index 3feeb665c..411881e36 100644 --- a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h @@ -25,6 +25,7 @@ #include "common/addInMultiChannelGrabber.h" #include "common/typeDefs.h" #include "dialogDummyMultiChannelGrabber.h" +#include "cameraEmulator.h" #include #include @@ -67,10 +68,6 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber ~DummyMultiChannelGrabber(); DummyMultiChannelGrabber(); - - ito::RetVal getValByMap(QSharedPointer> dataObjMap); - ito::RetVal copyValByMap(QSharedPointer> dataObjMap); - ito::RetVal getParameter( QSharedPointer val, const ParamMapIterator& it, @@ -90,34 +87,24 @@ class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber bool& ok, QStringList& pendingUpdate); + ito::RetVal retrieveData(const QStringList& channels = QStringList()); + public: friend class DummyMultiChannelGrabberInterface; + const ito::RetVal showConfDialog(void); //!< indicates that this plugin has got a configuration dialog int hasConfDialog(void) { return 1; }; private: - bool m_isgrabbing; - int64 m_startOfLastAcquisition; - QTimer m_freerunTimer; - int m_imageType; - - enum dummyImageType - { - imgTypeNoise, - imgTypeGaussianSpot, - imgTypeGaussianSpotArray, - }; - - // fills a rgba32 dataObject with a color image - void fillColorImage(ito::DataObject& img, const cv::Point2f& centerPixel, const float radius, bool hasAlpha) const; + CameraEmulator m_camEmulator; signals: public slots: - ito::RetVal init(QVector* paramsMand, QVector* paramsOpt, ItomSharedSemaphore* waitCond = NULL); + ito::RetVal init(QVector* paramsMand, QVector* paramsOpt, ItomSharedSemaphore* waitCond = nullptr); ito::RetVal close(ItomSharedSemaphore* waitCond); ito::RetVal startDevice(ItomSharedSemaphore* waitCond); @@ -127,5 +114,4 @@ public slots: private slots: void dockWidgetVisibilityChanged(bool visible); - ito::RetVal generateImageData(); }; diff --git a/DummyMultiChannelGrabber/cameraEmulator.cpp b/DummyMultiChannelGrabber/cameraEmulator.cpp new file mode 100644 index 000000000..9048a7fe2 --- /dev/null +++ b/DummyMultiChannelGrabber/cameraEmulator.cpp @@ -0,0 +1,242 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2023, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#include "cameraEmulator.h" + +#include +#include + +//------------------------------------------------------------------------------------- +/** @func fastrand + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template inline _Tp fastrand(cv::RNG& rng, _Tp maxval, float offset, float gain) +{ + return cv::saturate_cast<_Tp>(offset * maxval + gain * (((ito::uint32)rng.next()) & maxval)); +} + +//------------------------------------------------------------------------------------- +/** @func fastrand + * @brief function for pseudo random values + * + * This function delivers the noise for the image. + */ +template +inline _Tp fastrand_mean(cv::RNG& rng, _Tp maxval, ito::uint8 numMeans, float offset, float gain) +{ + ito::uint32 val = 0; + + for (ito::uint8 i = 0; i < numMeans; ++i) + { + val += ((ito::uint32)rng.next()) & maxval; + } + + return cv::saturate_cast<_Tp>(offset * maxval + (gain / (float)numMeans) * val); +} + +//------------------------------------------------------------------------------------- +/** @func gaussFunc + * @brief function for 2d Gaussian function + * + * This function delivers a 2d dataObject with a Gaussian function + */ +template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject &dObj, float amplitude) +{ + int width = dObj.getSize(1); + int height = dObj.getSize(0); + _Tp* rowPtr; + float xval, yval; + int planeID = dObj.seekMat(0); + + float yRandOffset = rng.uniform(0.f, 20.f); + float xRandOffset = rng.uniform(0.f, 20.f); + float aRandOfset = rng.uniform(0.f, 20.f); + + float sigmaX = width * rng.uniform(0.09f, 0.11f); + float sigmaY = height * rng.uniform(0.09f, 0.11f); + + for (int y = 0; y < height; y++) + { + rowPtr = dObj.rowPtr<_Tp>(planeID, y); + yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / + (2.0f * sigmaY * sigmaY); + + for (int x = 0; x < width; x++) + { + xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / + (2.0f * sigmaX * sigmaX); + rowPtr[x] = (float)(amplitude - aRandOfset) * exp(-(xval + yval)); + } + } + + return ito::retOk; +} + + + +//------------------------------------------------------------------------------------- +CameraEmulator::CameraEmulator() : + m_imageColorAlpha(false), + m_imageMonoBpp(8) +{ + +} + +//------------------------------------------------------------------------------------- +void CameraEmulator::configureImageMono(const QRect& roi, int bpp) +{ + int h = roi.height(); + int w = roi.width(); + + switch (bpp) + { + case 8: + m_imageMonoBpp = 8; + m_imageMono = ito::DataObject(h, w, ito::tUInt8); + break; + case 10: + m_imageMonoBpp = 10; + m_imageMono = ito::DataObject(h, w, ito::tUInt16); + break; + case 12: + m_imageMonoBpp = 12; + m_imageMono = ito::DataObject(h, w, ito::tUInt16); + break; + case 16: + m_imageMonoBpp = 16; + m_imageMono = ito::DataObject(h, w, ito::tUInt16); + default: + break; + } +} + +//------------------------------------------------------------------------------------- +void CameraEmulator::configureImageTopography(const QRect& roi, bool singlePrecision) +{ + int h = roi.height(); + int w = roi.width(); + + if (singlePrecision) + { + m_imageTopography = ito::DataObject(h, w, ito::tFloat32); + } + else + { + m_imageTopography = ito::DataObject(h, w, ito::tFloat64); + } +} + +//------------------------------------------------------------------------------------- +void CameraEmulator::configureImageColor(const QRect& roi, bool alpha) +{ + int h = roi.height(); + int w = roi.width(); + m_imageColorAlpha = alpha; + + m_imageColor = ito::DataObject(h, w, ito::tRGBA32); +} + +//------------------------------------------------------------------------------------- +bool CameraEmulator::grabImages(bool imgMono, bool imgFloat, bool imgColor, float exposureTimeMs) +{ + bool result = true; + QElapsedTimer timer; + timer.start(); + + if (imgMono) + { + result &= grabMono(); + } + + if (imgFloat) + { + result &= grabTopography(); + } + + if (imgColor) + { + result &= grabColor(); + } + + exposureTimeMs -= timer.elapsed(); + + if (exposureTimeMs > 0) + { + QThread::usleep(1000 * exposureTimeMs); + } + + return result; +} + +//------------------------------------------------------------------------------------- +bool CameraEmulator::grabMono() +{ + const unsigned int low = 0; + const unsigned int high = std::pow(m_imageMonoBpp, 2) - 1; + + cv::randu(*(m_imageMono.getCvPlaneMat(0)), low, high); + + return true; +} + +//------------------------------------------------------------------------------------- +bool CameraEmulator::grabTopography() +{ + cv::RNG& rng = cv::theRNG(); + + if (m_imageTopography.getType() == ito::tFloat32) + { + gaussFunc(rng, m_imageTopography, 10.0); + } + else + { + gaussFunc(rng, m_imageTopography, 10.0); + } + + return true; +} + +//------------------------------------------------------------------------------------- +bool CameraEmulator::grabColor() +{ + cv::Mat* mat = m_imageColor.getCvPlaneMat(0); + ito::uint32* rowPtr; + + for (int r = 0; r < mat->rows; ++r) + { + rowPtr = mat->ptr(r); + + for (int c = 0; c < mat->cols; ++c) + { + rowPtr[c] = cv::randu(); + + if (!m_imageColorAlpha) + { + ((ito::Rgba32*)rowPtr)[c].a = 255; + } + } + } + + return true; +} diff --git a/DummyMultiChannelGrabber/cameraEmulator.h b/DummyMultiChannelGrabber/cameraEmulator.h new file mode 100644 index 000000000..489e48f67 --- /dev/null +++ b/DummyMultiChannelGrabber/cameraEmulator.h @@ -0,0 +1,57 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2023, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#pragma once + +#include +#include +#include "DataObject/dataobj.h" + +class CameraEmulator : public QObject +{ +public: + explicit CameraEmulator(); + + const ito::DataObject& imageMono() const { return m_imageMono; } + const ito::DataObject& imageTopography() const { return m_imageTopography; } + const ito::DataObject& imageColor() const { return m_imageColor; } + + void configureImageMono(const QRect &roi, int bpp); + void configureImageTopography(const QRect& roi, bool singlePrecision); + void configureImageColor(const QRect& roi, bool alpha); + + bool grabImages(bool imgMono, bool imgFloat, bool imgColor, float exposureTimeMs); + +private: + bool grabMono(); + bool grabTopography(); + bool grabColor(); + + QRect m_roiMono; + QRect m_roiTopography; + QRect m_roiColor; + ito::DataObject m_imageMono; + ito::DataObject m_imageTopography; + ito::DataObject m_imageColor; + int m_imageMonoBpp; + bool m_imageColorAlpha; +}; From b98213cb3a3c9058f600d7a8ae427b3110a4b7bb Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:14:30 +0200 Subject: [PATCH 40/43] files renamed --- ...{DummyMultiChannelGrabber.cpp => dummyMultiChannelGrabber.cpp} | 0 .../{DummyMultiChannelGrabber.h => dummyMultiChannelGrabber.h} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename DummyMultiChannelGrabber/{DummyMultiChannelGrabber.cpp => dummyMultiChannelGrabber.cpp} (100%) rename DummyMultiChannelGrabber/{DummyMultiChannelGrabber.h => dummyMultiChannelGrabber.h} (100%) diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp similarity index 100% rename from DummyMultiChannelGrabber/DummyMultiChannelGrabber.cpp rename to DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp diff --git a/DummyMultiChannelGrabber/DummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.h similarity index 100% rename from DummyMultiChannelGrabber/DummyMultiChannelGrabber.h rename to DummyMultiChannelGrabber/dummyMultiChannelGrabber.h From c19cc7cd1e2d8b3a898aa163102d620144cd0059 Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:57:43 +0200 Subject: [PATCH 41/43] more work on DummyMultiChannelGrabber --- DummyMultiChannelGrabber/CMakeLists.txt | 2 + .../dummyMultiChannelGrabber.cpp | 155 +-------------- .../dummyMultiChannelGrabber.h | 28 --- .../dummyMultiChannelGrabberInterface.cpp | 182 ++++++++++++++++++ .../dummyMultiChannelGrabberInterface.h | 58 ++++++ 5 files changed, 243 insertions(+), 182 deletions(-) create mode 100644 DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.cpp create mode 100644 DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.h diff --git a/DummyMultiChannelGrabber/CMakeLists.txt b/DummyMultiChannelGrabber/CMakeLists.txt index cedea5296..8a244dfd7 100644 --- a/DummyMultiChannelGrabber/CMakeLists.txt +++ b/DummyMultiChannelGrabber/CMakeLists.txt @@ -40,6 +40,7 @@ set(PLUGIN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.h ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.h ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabber.h + ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabberInterface.h ${CMAKE_CURRENT_SOURCE_DIR}/cameraEmulator.h ${CMAKE_CURRENT_SOURCE_DIR}/pluginVersion.h ${CMAKE_CURRENT_BINARY_DIR}/gitVersion.h @@ -54,6 +55,7 @@ set(PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dialogDummyMultiChannelGrabber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dockWidgetDummyMultiChannelGrabber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/dummyMultiChannelGrabberInterface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cameraEmulator.cpp ) diff --git a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp index 2f0ae04e8..28c5fb24a 100644 --- a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp @@ -41,159 +41,6 @@ #endif - -//------------------------------------------------------------------------------------- -/*! - \class DummyMultiChannelGrabberInterface - \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic - information about DummyMultiChannelGrabber as is able to create one or more new instances of - DummyMultiChannelGrabber. -*/ - -//------------------------------------------------------------------------------------- -//! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. -/*! - \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created - DummyMultiChannelGrabber-instance is stored in *addInInst \return retOk \sa - DummyMultiChannelGrabber -*/ -ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase** addInInst) -{ - NEW_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; -} - -//------------------------------------------------------------------------------------- -//! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. -/*! - \param [in] double pointer to the instance which should be deleted. - \return retOk - \sa DummyMultiChannelGrabber -*/ -ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase** addInInst) -{ - REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) - return ito::retOk; -} - -//------------------------------------------------------------------------------------- -//! constructor for interace -/*! - defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real - plugin (here: DummyMultiChannelGrabber) should or must be initialized (e.g. by a Python call) - with mandatory or optional parameters, please initialize both vectors m_initParamsMand and - m_initParamsOpt within this constructor. -*/ -DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() -{ - m_autoLoadPolicy = ito::autoLoadKeywordDefined; - m_autoSavePolicy = ito::autoSaveAlways; - - m_type = ito::typeDataIO | ito::typeGrabber; - setObjectName("DummyMultiChannelGrabber"); - - // for the docstring, please don't set any spaces at the beginning of the line. - /* char docstring[] = \ - "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ - \n\ - The camera is initialized with a maximum width and height of the simulated camera chip (both - need to be a multiple - of 4). \ - The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per - pixel). The real size of - the camera \ - image is controlled using the parameter 'roi' if the sizes stay within the limits given by the - size of the camera - chip.\n\ - \n\ - You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line - camera whose height is - equal to 1. \n\ - \n\ - This plugin can also be used as template for other grabber.";*/ - - m_description = QObject::tr("A virtual white noise grabber"); - // m_detaildescription = QObject::tr(docstring); - m_detaildescription = QObject::tr( - "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with multiple channels with white noise. \n\ -\n\ -The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ -The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ -image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ -\n\ -You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ -\n\ -This plugin can also be used as template for other grabbers."); - - m_author = "R. Hahn, ITO, University Stuttgart"; - m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; - m_minItomVer = CREATEVERSION(1, 4, 0); - m_maxItomVer = MAXVERSION; - m_license = QObject::tr("Licensed under LPGL."); - m_aboutThis = tr(GITVERSION); - - m_initParamsMand.clear(); - - ito::Param param( - "sensorWidth", - ito::ParamBase::Int, - 640, - new ito::IntMeta(4, 4096, 4), - tr("Width of sensor chip. In this demo, the width of the sensor is the same for " - "all channels (could be different, if implemented).").toLatin1().data()); - m_initParamsOpt.append(param); - - param = ito::Param( - "sensorHeight", - ito::ParamBase::Int, - 480, - new ito::IntMeta(1, 4096, 1), - tr("Height of sensor chip. In this demo, the height is the same for all " - "channels. However, it could also be different, if implemented.").toLatin1().data()); - m_initParamsOpt.append(param); - - param = ito::Param( - "pixelFormatChannel1", - ito::ParamBase::String, - "mono8", - tr("Pixel format for the 1st channel (here: a grayscale intensity image).").toLatin1().data()); - ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); - m->addItem("mono10"); - m->addItem("mono12"); - m->addItem("mono16"); - param.setMeta(m, true); - m_initParamsOpt.append(param); - - param = ito::Param( - "pixelFormatChannel2", - ito::ParamBase::String, - "float32", - tr("Pixel format for the 2nd channel (here: a float32 or float64 disparity image).").toLatin1().data()); - m = new ito::StringMeta(ito::StringMeta::String, "float32"); - m->addItem("float64"); - param.setMeta(m, true); - m_initParamsOpt.append(param); - - param = ito::Param( - "pixelFormatChannel3", - ito::ParamBase::String, - "rgba8", - tr("Pixel format for the 3nd channel (here: color image with or without alpha channel).").toLatin1().data()); - m = new ito::StringMeta(ito::StringMeta::String, "rgba8"); - m->addItem("rgb8"); - param.setMeta(m, true); - m_initParamsOpt.append(param); -} - -//------------------------------------------------------------------------------------- -//! destructor -/*! - -*/ -DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() -{ -} - /*! \class DummyMultiChannelGrabber \brief Class for the DummyMultiChannelGrabber. The DummyMultiChannelGrabber is able to create @@ -433,7 +280,7 @@ ito::RetVal DummyMultiChannelGrabber::init( emit parametersChanged(m_params); } - setIdentifier(QString::number(getID())); + setIdentifier(tr("Camera %1").arg(getID())); if (waitCond) { diff --git a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.h b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.h index 411881e36..36564ff93 100644 --- a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.h +++ b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.h @@ -30,34 +30,6 @@ #include #include -//------------------------------------------------------------------------------------- -class DummyMultiChannelGrabberInterface : public ito::AddInInterfaceBase -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "ito.AddInInterfaceBase") - - /*!< this DummyMultiChannelGrabberInterface implements the - ito::AddInInterfaceBase-interface, which makes it available as plugin in itom */ - Q_INTERFACES(ito::AddInInterfaceBase) - - PLUGIN_ITOM_API - -public: - /*!< Constructor */ - DummyMultiChannelGrabberInterface(); - - /*!< Destructor */ - ~DummyMultiChannelGrabberInterface(); - - /*!< creates new instance of DummyMultiChannelGrabber and returns this instance */ - ito::RetVal getAddInInst(ito::AddInBase** addInInst); - -private: - - /*!< closes any specific instance of DummyMultiChannelGrabber, given by *addInInst */ - ito::RetVal closeThisInst(ito::AddInBase** addInInst); - -}; //------------------------------------------------------------------------------------- class DummyMultiChannelGrabber : public ito::AddInMultiChannelGrabber diff --git a/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.cpp b/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.cpp new file mode 100644 index 000000000..e2192daf2 --- /dev/null +++ b/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.cpp @@ -0,0 +1,182 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2023, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#include "dummyMultiChannelGrabberInterface.h" + +#include + +#include "gitVersion.h" +#include "pluginVersion.h" +#include "dummyMultiChannelGrabber.h" + + +//------------------------------------------------------------------------------------- +/*! + \class DummyMultiChannelGrabberInterface + \brief Small interface class for class DummyMultiChannelGrabber. This class contains basic + information about DummyMultiChannelGrabber as is able to create one or more new instances of + DummyMultiChannelGrabber. +*/ + +//------------------------------------------------------------------------------------- +//! creates new instance of DummyMultiChannelGrabber and returns the instance-pointer. +/*! + \param [in,out] addInInst is a double pointer of type ito::AddInBase. The newly created + DummyMultiChannelGrabber-instance is stored in *addInInst \return retOk \sa + DummyMultiChannelGrabber +*/ +ito::RetVal DummyMultiChannelGrabberInterface::getAddInInst(ito::AddInBase** addInInst) +{ + NEW_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; +} + +//------------------------------------------------------------------------------------- +//! deletes instance of DummyMultiChannelGrabber. This instance is given by parameter addInInst. +/*! + \param [in] double pointer to the instance which should be deleted. + \return retOk + \sa DummyMultiChannelGrabber +*/ +ito::RetVal DummyMultiChannelGrabberInterface::closeThisInst(ito::AddInBase** addInInst) +{ + REMOVE_PLUGININSTANCE(DummyMultiChannelGrabber) + return ito::retOk; +} + +//------------------------------------------------------------------------------------- +//! constructor for interace +/*! + defines the plugin type (dataIO and grabber) and sets the plugins object name. If the real + plugin (here: DummyMultiChannelGrabber) should or must be initialized (e.g. by a Python call) + with mandatory or optional parameters, please initialize both vectors m_initParamsMand and + m_initParamsOpt within this constructor. +*/ +DummyMultiChannelGrabberInterface::DummyMultiChannelGrabberInterface() +{ + m_autoLoadPolicy = ito::autoLoadKeywordDefined; + m_autoSavePolicy = ito::autoSaveAlways; + + m_type = ito::typeDataIO | ito::typeGrabber; + setObjectName("DummyMultiChannelGrabber"); + + // for the docstring, please don't set any spaces at the beginning of the line. + /* char docstring[] = \ + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with white noise. \n\ + \n\ + The camera is initialized with a maximum width and height of the simulated camera chip (both + need to be a multiple + of 4). \ + The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per + pixel). The real size of + the camera \ + image is controlled using the parameter 'roi' if the sizes stay within the limits given by the + size of the camera + chip.\n\ + \n\ + You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line + camera whose height is + equal to 1. \n\ + \n\ + This plugin can also be used as template for other grabber.";*/ + + m_description = QObject::tr("A virtual white noise grabber"); + // m_detaildescription = QObject::tr(docstring); + m_detaildescription = QObject::tr( + "The DummyMultiChannelGrabber is a virtual camera which emulates a camera with multiple channels with white noise. \n\ +\n\ +The camera is initialized with a maximum width and height of the simulated camera chip (both need to be a multiple of 4). \ +The noise is always scaled in the range between 0 and the current bitdepth (bpp - bit per pixel). The real size of the camera \ +image is controlled using the parameter 'roi' if the sizes stay within the limits given by the size of the camera chip.\n\ +\n\ +You can initialize this camera either as a 2D sensor with a width and height >= 4 or as line camera whose height is equal to 1. \n\ +\n\ +This plugin can also be used as template for other grabbers."); + + m_author = "R. Hahn, ITO, University Stuttgart"; + m_version = (PLUGIN_VERSION_MAJOR << 16) + (PLUGIN_VERSION_MINOR << 8) + PLUGIN_VERSION_PATCH; + m_minItomVer = CREATEVERSION(1, 4, 0); + m_maxItomVer = MAXVERSION; + m_license = QObject::tr("Licensed under LPGL."); + m_aboutThis = tr(GITVERSION); + + m_initParamsMand.clear(); + + ito::Param param( + "sensorWidth", + ito::ParamBase::Int, + 640, + new ito::IntMeta(4, 4096, 4), + tr("Width of sensor chip. In this demo, the width of the sensor is the same for " + "all channels (could be different, if implemented).").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param( + "sensorHeight", + ito::ParamBase::Int, + 480, + new ito::IntMeta(1, 4096, 1), + tr("Height of sensor chip. In this demo, the height is the same for all " + "channels. However, it could also be different, if implemented.").toLatin1().data()); + m_initParamsOpt.append(param); + + param = ito::Param( + "pixelFormatChannel1", + ito::ParamBase::String, + "mono8", + tr("Pixel format for the 1st channel (here: a grayscale intensity image).").toLatin1().data()); + ito::StringMeta* m = new ito::StringMeta(ito::StringMeta::String, "mono8"); + m->addItem("mono10"); + m->addItem("mono12"); + m->addItem("mono16"); + param.setMeta(m, true); + m_initParamsOpt.append(param); + + param = ito::Param( + "pixelFormatChannel2", + ito::ParamBase::String, + "float32", + tr("Pixel format for the 2nd channel (here: a float32 or float64 disparity image).").toLatin1().data()); + m = new ito::StringMeta(ito::StringMeta::String, "float32"); + m->addItem("float64"); + param.setMeta(m, true); + m_initParamsOpt.append(param); + + param = ito::Param( + "pixelFormatChannel3", + ito::ParamBase::String, + "rgba8", + tr("Pixel format for the 3nd channel (here: color image with or without alpha channel).").toLatin1().data()); + m = new ito::StringMeta(ito::StringMeta::String, "rgba8"); + m->addItem("rgb8"); + param.setMeta(m, true); + m_initParamsOpt.append(param); +} + +//------------------------------------------------------------------------------------- +//! destructor +/*! + +*/ +DummyMultiChannelGrabberInterface::~DummyMultiChannelGrabberInterface() +{ +} diff --git a/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.h b/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.h new file mode 100644 index 000000000..c83f1cf4b --- /dev/null +++ b/DummyMultiChannelGrabber/dummyMultiChannelGrabberInterface.h @@ -0,0 +1,58 @@ +/* ******************************************************************** + Plugin "DummyMultiChannelGrabber" for itom software + URL: http://www.uni-stuttgart.de/ito + Copyright (C) 2023, Institut fuer Technische Optik (ITO), + Universitaet Stuttgart, Germany + + This file is part of a plugin for the measurement software itom. + + This itom-plugin is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public Licence as published by + the Free Software Foundation; either version 2 of the Licence, or (at + your option) any later version. + + itom and its plugins are distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library + General Public Licence for more details. + + You should have received a copy of the GNU Library General Public License + along with itom. If not, see . +*********************************************************************** */ + +#pragma once + +#include "common/addInMultiChannelGrabber.h" +#include "common/typeDefs.h" + +#include +#include + +//------------------------------------------------------------------------------------- +class DummyMultiChannelGrabberInterface : public ito::AddInInterfaceBase +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "ito.AddInInterfaceBase") + + /*!< this DummyMultiChannelGrabberInterface implements the + ito::AddInInterfaceBase-interface, which makes it available as plugin in itom */ + Q_INTERFACES(ito::AddInInterfaceBase) + + PLUGIN_ITOM_API + +public: + /*!< Constructor */ + DummyMultiChannelGrabberInterface(); + + /*!< Destructor */ + ~DummyMultiChannelGrabberInterface(); + + /*!< creates new instance of DummyMultiChannelGrabber and returns this instance */ + ito::RetVal getAddInInst(ito::AddInBase** addInInst); + +private: + + /*!< closes any specific instance of DummyMultiChannelGrabber, given by *addInInst */ + ito::RetVal closeThisInst(ito::AddInBase** addInInst); + +}; From a634f963b38c2205b126c6f1dbcd6f9904a7f2ba Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:07:48 +0200 Subject: [PATCH 42/43] improvements in dummyMultiChannelGrabber --- DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp index 28c5fb24a..b91ab355e 100644 --- a/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp +++ b/DummyMultiChannelGrabber/dummyMultiChannelGrabber.cpp @@ -134,8 +134,8 @@ ito::RetVal DummyMultiChannelGrabber::init( ChannelContainerMap channels; // create the channel parameters, that are the same for all channels - ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, 1280, tr("sensor width of the channel").toLatin1().data()); - ito::Param paramSizeY("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, 1024, tr("sensor height of the channel").toLatin1().data()); + ito::Param paramSizeX("sizex", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, sensorWidth, tr("sensor width of the channel").toLatin1().data()); + ito::Param paramSizeY("sizey", ito::ParamBase::Int | ito::ParamBase::Readonly, 16, 4096, sensorHeight, tr("sensor height of the channel").toLatin1().data()); int roi[] = { 0, 0, sensorWidth, sensorHeight }; ito::Param paramRoi("roi", ito::ParamBase::IntArray, 4, roi, tr("current region of interest of the channel (x, y, width, height)").toLatin1().data()); @@ -275,7 +275,8 @@ ito::RetVal DummyMultiChannelGrabber::init( if (!retVal.containsError()) { - retVal += checkData(); // check if image must be reallocated + // check if image must be reallocated + retVal += checkDataFromAllChannels(); emit parametersChanged(m_params); } From 527e27ff63efe7190b1712a73c8d993669b5960e Mon Sep 17 00:00:00 2001 From: "M. Gronle" <2607303+magro11@users.noreply.github.com> Date: Sat, 21 Oct 2023 00:11:37 +0200 Subject: [PATCH 43/43] next steps for MultiChannelGrabber --- DummyMultiChannelGrabber/cameraEmulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DummyMultiChannelGrabber/cameraEmulator.cpp b/DummyMultiChannelGrabber/cameraEmulator.cpp index 9048a7fe2..e705dc12d 100644 --- a/DummyMultiChannelGrabber/cameraEmulator.cpp +++ b/DummyMultiChannelGrabber/cameraEmulator.cpp @@ -71,7 +71,7 @@ template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject &dOb float yRandOffset = rng.uniform(0.f, 20.f); float xRandOffset = rng.uniform(0.f, 20.f); - float aRandOfset = rng.uniform(0.f, 20.f); + float aRandOfset = rng.uniform(-amplitude * 0.1, amplitude * 0.1); float sigmaX = width * rng.uniform(0.09f, 0.11f); float sigmaY = height * rng.uniform(0.09f, 0.11f); @@ -79,12 +79,12 @@ template ito::RetVal gaussFunc(cv::RNG& rng, ito::DataObject &dOb for (int y = 0; y < height; y++) { rowPtr = dObj.rowPtr<_Tp>(planeID, y); - yval = ((y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / + yval = (((float)y - height / 2 + yRandOffset) * ((float)y - height / 2 + yRandOffset)) / (2.0f * sigmaY * sigmaY); for (int x = 0; x < width; x++) { - xval = ((x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / + xval = (((float)x - width / 2 + xRandOffset) * ((float)x - width / 2 + xRandOffset)) / (2.0f * sigmaX * sigmaX); rowPtr[x] = (float)(amplitude - aRandOfset) * exp(-(xval + yval)); }