-
Notifications
You must be signed in to change notification settings - Fork 129
Add getBinning/setBinning methods to MMCore #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6f30d60
58d3e9c
7a5748b
e37129f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -106,7 +106,7 @@ namespace mmi = mmcore::internal; | |||||||||
| * (Keep the 3 numbers on one line to make it easier to look at diffs when | ||||||||||
| * merging/rebasing.) | ||||||||||
| */ | ||||||||||
| const int MMCore_versionMajor = 11, MMCore_versionMinor = 11, MMCore_versionPatch = 0; | ||||||||||
| const int MMCore_versionMajor = 11, MMCore_versionMinor = 12, MMCore_versionPatch = 0; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| /////////////////////////////////////////////////////////////////////////////// | ||||||||||
|
|
@@ -4407,6 +4407,210 @@ double CMMCore::getExposure(const char* label) MMCORE_LEGACY_THROW(CMMError) | |||||||||
| return 0.0; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Returns the current binning setting of the camera. | ||||||||||
| * Binning values in "NxN" format (e.g., "2x2") are parsed to return the integer factor (e.g., 2). | ||||||||||
| * @return the binning factor (1-100) | ||||||||||
| */ | ||||||||||
| int CMMCore::getBinning() MMCORE_LEGACY_THROW(CMMError) | ||||||||||
| { | ||||||||||
| std::shared_ptr<mmi::CameraInstance> camera = currentCameraDevice_.lock(); | ||||||||||
| if (!camera) | ||||||||||
| { | ||||||||||
| throw CMMError(getCoreErrorText(MMERR_CameraNotAvailable).c_str(), MMERR_CameraNotAvailable); | ||||||||||
nicost marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| } | ||||||||||
| else | ||||||||||
| { | ||||||||||
| std::string cameraName; | ||||||||||
| { | ||||||||||
| mmi::DeviceModuleLockGuard guard(camera); | ||||||||||
| cameraName = camera->GetLabel(); | ||||||||||
| } | ||||||||||
| return getBinning(cameraName.c_str()); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Returns the current binning setting of the specified camera. | ||||||||||
| * Binning values in "NxN" format (e.g., "2x2") are parsed to return the integer factor (e.g., 2). | ||||||||||
| * @param label the camera device label | ||||||||||
| * @return the binning factor (1-100) | ||||||||||
nicost marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| */ | ||||||||||
| int CMMCore::getBinning(const char* label) MMCORE_LEGACY_THROW(CMMError) | ||||||||||
| { | ||||||||||
| std::shared_ptr<mmi::CameraInstance> pCamera = | ||||||||||
| deviceManager_->GetDeviceOfType<mmi::CameraInstance>(label); | ||||||||||
|
|
||||||||||
| mmi::DeviceModuleLockGuard guard(pCamera); | ||||||||||
|
|
||||||||||
| if (!pCamera->HasProperty(MM::g_Keyword_Binning)) | ||||||||||
| { | ||||||||||
| throw CMMError("Camera does not support binning property"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| std::string binningValue = pCamera->GetProperty(MM::g_Keyword_Binning); | ||||||||||
|
|
||||||||||
| if (binningValue.empty()) | ||||||||||
| { | ||||||||||
| throw CMMError("Binning property returned empty value"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Parse the binning value - handle both integer ("2") and NxN ("2x2") formats | ||||||||||
| int binning; | ||||||||||
| size_t xPos = binningValue.find('x'); | ||||||||||
| if (xPos != std::string::npos) | ||||||||||
| { | ||||||||||
| // NxN format - parse both parts and verify they match | ||||||||||
| int binX = atoi(binningValue.c_str()); | ||||||||||
| int binY = atoi(binningValue.c_str() + xPos + 1); | ||||||||||
| if (binX != binY) | ||||||||||
| { | ||||||||||
| throw CMMError("Asymmetric binning not supported: " + binningValue); | ||||||||||
| } | ||||||||||
| binning = binX; | ||||||||||
| } | ||||||||||
| else | ||||||||||
| { | ||||||||||
| // Integer format | ||||||||||
| binning = atoi(binningValue.c_str()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (binning < 1 || binning > 100) | ||||||||||
| { | ||||||||||
| throw CMMError("Binning value out of valid range (1-100): " + binningValue); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return binning; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Sets the binning setting of the camera. | ||||||||||
| * Automatically handles both integer ("2") and "NxN" ("2x2") property formats. | ||||||||||
| * @param binning the binning factor (1-100) | ||||||||||
| */ | ||||||||||
| void CMMCore::setBinning(int binning) MMCORE_LEGACY_THROW(CMMError) | ||||||||||
| { | ||||||||||
| if (binning < 1 || binning > 100) | ||||||||||
| { | ||||||||||
| throw CMMError("Binning must be between 1 and 100"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| std::shared_ptr<mmi::CameraInstance> camera = currentCameraDevice_.lock(); | ||||||||||
| if (!camera) | ||||||||||
| { | ||||||||||
| throw CMMError(getCoreErrorText(MMERR_CameraNotAvailable).c_str(), MMERR_CameraNotAvailable); | ||||||||||
| } | ||||||||||
| else | ||||||||||
| { | ||||||||||
| std::string cameraName; | ||||||||||
| { | ||||||||||
| mmi::DeviceModuleLockGuard guard(camera); | ||||||||||
| cameraName = camera->GetLabel(); | ||||||||||
| } | ||||||||||
| setBinning(cameraName.c_str(), binning); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Sets the binning setting of the specified camera. | ||||||||||
| * Automatically handles both integer ("2") and "NxN" ("2x2") property formats. | ||||||||||
| * @param label the camera device label | ||||||||||
| * @param binning the binning factor (1-100) | ||||||||||
| */ | ||||||||||
| void CMMCore::setBinning(const char* label, int binning) MMCORE_LEGACY_THROW(CMMError) | ||||||||||
| { | ||||||||||
| if (binning < 1 || binning > 100) | ||||||||||
| { | ||||||||||
| throw CMMError("Binning must be between 1 and 100"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| std::shared_ptr<mmi::CameraInstance> pCamera = | ||||||||||
| deviceManager_->GetDeviceOfType<mmi::CameraInstance>(label); | ||||||||||
|
|
||||||||||
| { | ||||||||||
| mmi::DeviceModuleLockGuard guard(pCamera); | ||||||||||
| LOG_DEBUG(coreLogger_) << "Will set camera " << label << | ||||||||||
| " binning to " << binning; | ||||||||||
|
|
||||||||||
| if (!pCamera->HasProperty(MM::g_Keyword_Binning)) | ||||||||||
| { | ||||||||||
| throw CMMError("Camera does not support binning property"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Try to determine the format by checking the current property value | ||||||||||
| std::string currentValue; | ||||||||||
| bool useNxNFormat = false; | ||||||||||
|
|
||||||||||
| try | ||||||||||
| { | ||||||||||
| currentValue = pCamera->GetProperty(MM::g_Keyword_Binning); | ||||||||||
| // If current value contains 'x' and looks like NxN format, use that | ||||||||||
| size_t xPos = currentValue.find('x'); | ||||||||||
| if (!currentValue.empty() && xPos != std::string::npos) | ||||||||||
| { | ||||||||||
| // Validate that the current value has symmetric binning | ||||||||||
| int binX = atoi(currentValue.c_str()); | ||||||||||
| int binY = atoi(currentValue.c_str() + xPos + 1); | ||||||||||
| if (binX != binY) | ||||||||||
| { | ||||||||||
| throw CMMError("Asymmetric binning not supported: " + currentValue); | ||||||||||
| } | ||||||||||
| useNxNFormat = true; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| catch (...) | ||||||||||
| { | ||||||||||
| // If we can't get current value, we'll try integer format first | ||||||||||
|
||||||||||
| // If we can't get current value, we'll try integer format first | |
| // If we can't get current value, we'll try integer format first | |
| LOG_DEBUG(coreLogger_) << "Could not retrieve current binning value for camera " | |
| << label << "; will try integer format first."; |
Uh oh!
There was an error while loading. Please reload this page.