works for all rois

This commit is contained in:
2025-06-27 17:17:19 +02:00
parent 3d4eaec178
commit ca3311da4c
4 changed files with 21 additions and 25 deletions

View File

@ -1809,15 +1809,16 @@ void DetectorImpl::convertGlobalRoiToPortLevel(
// Check if user ROI overlaps with this port ROI // Check if user ROI overlaps with this port ROI
if (userRoi.overlap(portRoi)) { if (userRoi.overlap(portRoi)) {
defs::ROI clipped{}; defs::ROI clipped{};
clipped.xmin = std::max(userRoi.xmin, portRoi.xmin); // Clip user ROI to port ROI
clipped.xmax = std::min(userRoi.xmax, portRoi.xmax); clipped.xmin = std::max(userRoi.xmin, portRoi.xmin) - portRoi.xmin;
clipped.xmax = std::min(userRoi.xmax, portRoi.xmax) - portRoi.xmin;
if (modSize.y > 1) { if (modSize.y > 1) {
clipped.ymin = std::max(userRoi.ymin, portRoi.ymin); clipped.ymin = std::max(userRoi.ymin, portRoi.ymin) - portRoi.ymin;
clipped.ymax = std::min(userRoi.ymax, portRoi.ymax); clipped.ymax = std::min(userRoi.ymax, portRoi.ymax) - portRoi.ymin;
} }
// Check if port ROI already exists for this port // Check if port ROI already exists for this port
if (!portRois[port].completeRoi()) { if (!portRois[port].completeRoi() && !portRois[port].noRoi()) {
throw RuntimeError( throw RuntimeError(
"Multiple ROIs specified for the same port " + "Multiple ROIs specified for the same port " +
std::to_string(port) + std::to_string(port) +

View File

@ -690,7 +690,7 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
} }
void DataProcessor::CropImage(size_t &size, char *data) { void DataProcessor::CropImage(size_t &size, char *data) {
LOG(logDEBUG) << "Cropping Image to ROI " << ToString(portRoi); LOG(logDEBUG1) << "Cropping Image to ROI " << ToString(portRoi);
int nPixelsX = generalData->nPixelsX; int nPixelsX = generalData->nPixelsX;
int xmin = portRoi.xmin; int xmin = portRoi.xmin;
int xmax = portRoi.xmax; int xmax = portRoi.xmax;
@ -702,7 +702,7 @@ void DataProcessor::CropImage(size_t &size, char *data) {
ywidth = 1; ywidth = 1;
ymin = 0; ymin = 0;
} }
// calculate total roi size // calculate total roi size
double bytesPerPixel = generalData->dynamicRange / 8.00; double bytesPerPixel = generalData->dynamicRange / 8.00;
int startOffset = (int)((nPixelsX * ymin + xmin) * bytesPerPixel); int startOffset = (int)((nPixelsX * ymin + xmin) * bytesPerPixel);

View File

@ -411,6 +411,19 @@ std::vector<slsDetectorDefs::ROI> Implementation::getPortROIs() const {
} }
void Implementation::setPortROIs(const std::vector<defs::ROI> &args) { void Implementation::setPortROIs(const std::vector<defs::ROI> &args) {
int nx = static_cast<int>(generalData->nPixelsX);
int ny = static_cast<int>(generalData->nPixelsY);
// validate rois
for (auto &it : args) {
if (it.completeRoi() || it.noRoi()) {
continue; // valid
}
if (it.xmin < 0 || it.ymin < 0 || it.xmax < 0 || it.ymax < 0 ||
it.xmin >= nx || it.xmax >= nx ||
it.ymin >= ny || it.ymax >= ny) {
throw RuntimeError("Invalid ROI coordinates: " + ToString(it));
}
}
portRois = args; portRois = args;
for (size_t i = 0; i != listener.size(); ++i) for (size_t i = 0; i != listener.size(); ++i)

View File

@ -249,8 +249,6 @@ std::string CreateVirtualHDF5File(
"version", H5::PredType::NATIVE_DOUBLE, dataspace_attr); "version", H5::PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue); attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue);
LOG(logINFORED) << "Rois:" << ToString(multiRoi);
for (size_t iRoi = 0; iRoi != multiRoi.size(); ++iRoi) { for (size_t iRoi = 0; iRoi != multiRoi.size(); ++iRoi) {
auto currentRoi = multiRoi[iRoi]; auto currentRoi = multiRoi[iRoi];
@ -279,16 +277,6 @@ std::string CreateVirtualHDF5File(
int numFiles = numImagesCaught / maxFramesPerFile; int numFiles = numImagesCaught / maxFramesPerFile;
if (numImagesCaught % maxFramesPerFile) if (numImagesCaught % maxFramesPerFile)
++numFiles; ++numFiles;
LOG(logINFORED) << "Current Roi: " << currentRoi
<< " detectorSize: " << ToString(detectorSize)
<< " portSize: " << ToString(portSize)
<< " nTotalPorts: " << nTotalPorts
<< " roiWidth: " << roiWidth
<< " roiHeight: " << roiHeight
<< " nPortsInRoi: " << nPortsInRoi
<< " nImages: " << nImages
<< " numFiles: " << numFiles
<< " maxFramesPerFile: " << maxFramesPerFile;
hsize_t vdsDims[DATA_RANK] = {nImages, roiHeight, roiWidth}; hsize_t vdsDims[DATA_RANK] = {nImages, roiHeight, roiWidth};
hsize_t vdsDimsPara[VDS_PARA_RANK] = {nImages, nPortsInRoi}; hsize_t vdsDimsPara[VDS_PARA_RANK] = {nImages, nPortsInRoi};
@ -354,12 +342,6 @@ std::string CreateVirtualHDF5File(
else { else {
++startLocation[2]; ++startLocation[2];
} }
LOG(logINFORED) << "iReadout: " << iReadout
<< " globalPortRoi: " << globalPortRoi
<< " startLocation: " << ToString(startLocation)
<< " blockSize: " << ToString(blockSize)
<< " portRoiHeight: " << portRoiHeight
<< " portRoiWidth: " << portRoiWidth;
vdsDataSpace.selectHyperslab( vdsDataSpace.selectHyperslab(
H5S_SELECT_SET, numBlocks, startLocation, H5S_SELECT_SET, numBlocks, startLocation,