Skip to content

Commit

Permalink
bug fixes, missing API implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
nenada committed Dec 18, 2024
1 parent 2c88b7f commit 79d06e9
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 16 deletions.
61 changes: 48 additions & 13 deletions MMCore/Devices/StorageInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int StorageInstance::Create(const char* path, const char* name, const std::vecto
RequireInitialized(__func__);

char cHandle[MM::MaxStrLength];
memset(cHandle, 0, MM::MaxStrLength);
int ret = GetImpl()->Create(path, name, (int)shape.size(), &shape[0], pixType, meta, cHandle);
if (ret != DEVICE_OK)
return ret;
Expand Down Expand Up @@ -60,6 +61,7 @@ int StorageInstance::Load(const char* path, std::string& handle)
RequireInitialized(__func__);

char cHandle[MM::MaxStrLength];
memset(cHandle, 0, MM::MaxStrLength);
int ret = GetImpl()->Load(path, cHandle);
if (ret != DEVICE_OK)
return ret;
Expand Down Expand Up @@ -139,19 +141,21 @@ int StorageInstance::AddImage(const char* handle, int sizeInBytes, unsigned char

int StorageInstance::GetSummaryMeta(const char* handle, std::string& meta)
{
char cMeta[MM::MaxMetadataLength];
memset(cMeta, 0, MM::MaxMetadataLength);
RequireInitialized(__func__);
std::vector<char> metaCharArray(MM::MaxMetadataLength);
int ret = GetImpl()->GetSummaryMeta(handle, &metaCharArray[0], MM::MaxMetadataLength);
meta = std::string(metaCharArray.begin(), metaCharArray.end());
int ret = GetImpl()->GetSummaryMeta(handle, cMeta, MM::MaxMetadataLength);
meta = cMeta;
return ret;
}

int StorageInstance::GetImageMeta(const char* handle, const std::vector<int>& coordinates, std::string& meta)
{
char cMeta[MM::MaxMetadataLength];
memset(cMeta, 0, MM::MaxMetadataLength);
RequireInitialized(__func__);
std::vector<char> metaCharArray(MM::MaxMetadataLength);
int ret = GetImpl()->GetImageMeta(handle, const_cast<int*>(&coordinates[0]), coordinates.size(), &metaCharArray[0], MM::MaxMetadataLength);
meta = std::string(metaCharArray.begin(), metaCharArray.end());
int ret = GetImpl()->GetImageMeta(handle, const_cast<int*>(&coordinates[0]), coordinates.size(), cMeta, MM::MaxMetadataLength);
meta = cMeta;
return ret;
}

Expand All @@ -169,17 +173,48 @@ int StorageInstance::GetNumberOfDimensions(const char* handle, int& numDim)

int StorageInstance::GetDimension(const char* handle, int dimension, std::string& name, std::string& meaning)
{
std::vector<char> nameStr(MM::MaxStrLength), meaningStr(MM::MaxMetadataLength);
int ret = GetImpl()->GetDimension(handle, dimension, &nameStr[0], nameStr.size(), &meaningStr[0], meaningStr.size());
name = std::string(nameStr.begin(), nameStr.end());
meaning = std::string(meaningStr.begin(), meaningStr.end());
char nameStr[MM::MaxStrLength];
char meaningStr[MM::MaxStrLength];
memset(nameStr, 0, MM::MaxStrLength);
memset(meaningStr, 0, MM::MaxStrLength);
int ret = GetImpl()->GetDimension(handle, dimension, nameStr, MM::MaxStrLength, meaningStr, MM::MaxStrLength);
name = nameStr;
meaning = meaningStr;
return ret;
}

int StorageInstance::GetCoordinate(const char* handle, int dimension, int coordinate, std::string& name)
{
std::vector<char> nameStr(MM::MaxStrLength);
int ret = GetImpl()->GetCoordinate(handle, dimension, coordinate, &nameStr[0], nameStr.size());
name = std::string(nameStr.begin(), nameStr.end());
char cName[MM::MaxStrLength];
memset(cName, 0, MM::MaxStrLength);
int ret = GetImpl()->GetCoordinate(handle, dimension, coordinate, cName, MM::MaxStrLength);
name = cName;
return ret;
}

int StorageInstance::GetImageCount(const char* handle, int& imgcount)
{
RequireInitialized(__func__);
return GetImpl()->GetImageCount(handle, imgcount);
}

int StorageInstance::GetPath(const char* handle, std::string& path)
{
char cPath[MM::MaxStrLength];
memset(cPath, 0, MM::MaxStrLength);
int ret = GetImpl()->GetPath(handle, cPath, MM::MaxStrLength);
path = cPath;
return ret;
}

bool StorageInstance::IsOpen(const char* handle)
{
RequireInitialized(__func__);
return GetImpl()->IsOpen(handle);
}

bool StorageInstance::IsReadOnly(const char* handle)
{
RequireInitialized(__func__);
return GetImpl()->IsReadOnly(handle);
}
5 changes: 4 additions & 1 deletion MMCore/Devices/StorageInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class StorageInstance : public DeviceInstanceBase<MM::Storage>
int Create(const char* path, const char* name, const std::vector<int>& shape, MM::StorageDataType pixType, const char* meta, std::string& handle);
int ConfigureDimension(const char* handle, int dimension, const char* name, const char* meaning);
int ConfigureCoordinate(const char* handle, int dimension, int coordinate, const char* name);
int GetPath(const char* handle, std::string& path);
int Close(const char* handle);
int Load(const char* path, std::string& handle);
int GetShape(const char* handle, std::vector<long>& shape);
Expand All @@ -52,5 +53,7 @@ class StorageInstance : public DeviceInstanceBase<MM::Storage>
int GetNumberOfDimensions(const char* handle, int& numDimensions);
int GetDimension(const char* handle, int dimension, std::string& name, std::string& meaning);
int GetCoordinate(const char* handle, int dimension, int coordinate, std::string& name);

int GetImageCount(const char* handle, int& imgcnt);
bool IsOpen(const char* handle);
bool IsReadOnly(const char* handle);
};
1 change: 1 addition & 0 deletions MMCore/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
#define MMERR_PropertyNotInCache 51
#define MMERR_BadAffineTransform 52
#define MMERR_StorageNotAvailable 53
#define MMERR_StorageImageNotAvailable 54
#endif //_ERRORCODES_H_
157 changes: 155 additions & 2 deletions MMCore/MMCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7101,6 +7101,7 @@ void CMMCore::InitializeErrorMessages()
errorText_[MMERR_CreatePeripheralFailed] = "Hub failed to create specified peripheral device.";
errorText_[MMERR_BadAffineTransform] = "Bad affine transform. Affine transforms need to have 6 numbers; 2 rows of 3 column.";
errorText_[MMERR_StorageNotAvailable] = "Storage not loaded or initialized.";
errorText_[MMERR_StorageImageNotAvailable] = "Image not available at specified coordinates.";
}

void CMMCore::CreateCoreProperties()
Expand Down Expand Up @@ -7676,14 +7677,64 @@ std::string CMMCore::getDeviceNameToOpen(const char* path)
return std::string();
}

/**
* Get dataset path
*
* \param handle - handle to the open dataset
* \return - Full dataset path
*/
std::string CMMCore::getDatasetPath(const char* handle) throw(CMMError)
{
return std::string();
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::string path = "";
int ret = storage->GetPath(handle, path);
if(ret != DEVICE_OK)
{
logError(getDeviceName(storage).c_str(), getDeviceErrorText(ret, storage).c_str());
throw CMMError(getDeviceErrorText(ret, storage).c_str(), MMERR_DEVICE_GENERIC);
}
return path;
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Check if dataset is open
*
* \param handle - handle to the open dataset
* \return - Dataset is open
*/
bool CMMCore::isDatasetOpen(const char* handle)
{
return false;
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::vector<long> shape;
return storage->IsOpen(handle);
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Check if dataset is read-only (or in WRITE mode)
*
* \param handle - handle to the open dataset
* \return - Dataset is read-only
*/
bool CMMCore::isDatasetReadOnly(const char* handle)
{
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::vector<long> shape;
return storage->IsReadOnly(handle);
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

std::vector<long> CMMCore::getDatasetShape(const char* handle) throw (CMMError)
Expand Down Expand Up @@ -7831,6 +7882,102 @@ void CMMCore::configureCoordinate(const char* handle, int dimension, int coordin
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Obtain a dataset dimension name
*
* \param handle - dataset handle
* \param dimension - dimension index
*/
std::string CMMCore::getDimensionName(const char* handle, int dimension) throw (CMMError)
{
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::string name = "", meaning = "";
int ret = storage->GetDimension(handle, dimension, name, meaning);
if(ret != DEVICE_OK)
{
logError(getDeviceName(storage).c_str(), getDeviceErrorText(ret, storage).c_str());
throw CMMError(getDeviceErrorText(ret, storage).c_str(), MMERR_DEVICE_GENERIC);
}
return name;
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Obtain a dataset dimension physical meaning (Z,T,C, etc)
*
* \param handle - dataset handle
* \param dimension - dimension index
*/
std::string CMMCore::getDimensionMeaning(const char* handle, int dimension) throw (CMMError)
{
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::string name = "", meaning = "";
int ret = storage->GetDimension(handle, dimension, name, meaning);
if(ret != DEVICE_OK)
{
logError(getDeviceName(storage).c_str(), getDeviceErrorText(ret, storage).c_str());
throw CMMError(getDeviceErrorText(ret, storage).c_str(), MMERR_DEVICE_GENERIC);
}
return meaning;
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Obtain dataset coordinate name
*
* \param handle - dataset handle
* \param dimension - dimension index
* \param coordinate - coordinate index
*/
std::string CMMCore::getCoordinateName(const char* handle, int dimension, int coordinate) throw (CMMError)
{
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
std::string name = "";
int ret = storage->GetCoordinate(handle, dimension, coordinate, name);
if(ret != DEVICE_OK)
{
logError(getDeviceName(storage).c_str(), getDeviceErrorText(ret, storage).c_str());
throw CMMError(getDeviceErrorText(ret, storage).c_str(), MMERR_DEVICE_GENERIC);
}
return name;
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Get dataset actual image count
*
* \param handle - dataset handle
*/
int CMMCore::getImageCount(const char* handle) throw (CMMError)
{
std::shared_ptr<StorageInstance> storage = currentStorage_.lock();
if(storage)
{
mm::DeviceModuleLockGuard guard(storage);
int imgcount = 0;
int ret = storage->GetImageCount(handle, imgcount);
if(ret != DEVICE_OK)
{
logError(getDeviceName(storage).c_str(), getDeviceErrorText(ret, storage).c_str());
throw CMMError(getDeviceErrorText(ret, storage).c_str(), MMERR_DEVICE_GENERIC);
}
return imgcount;
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Returns summary metadata serialized as a string
*
Expand Down Expand Up @@ -7880,6 +8027,7 @@ std::string CMMCore::getImageMeta(const char* handle, const std::vector<long>& c
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
}

/**
* Returns image pixels at specified coordinates
* \param handle - dataset handle
Expand All @@ -7894,6 +8042,11 @@ STORAGEIMGOUT CMMCore::getImage(const char* handle, const std::vector<long>& coo
mm::DeviceModuleLockGuard guard(storage);
std::vector<int> coords(coordinates.begin(), coordinates.end());
const unsigned char* img = storage->GetImage(handle, coords);
if (!img)
{
logError("CMMCore::getImage()", getCoreErrorText(MMERR_StorageImageNotAvailable).c_str());
throw CMMError(getCoreErrorText(MMERR_StorageImageNotAvailable).c_str(), MMERR_StorageImageNotAvailable);
}
return const_cast<unsigned char*>(img);
}
throw CMMError(getCoreErrorText(MMERR_StorageNotAvailable).c_str(), MMERR_StorageNotAvailable);
Expand Down
5 changes: 5 additions & 0 deletions MMCore/MMCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,17 @@ class CMMCore
std::string getDeviceNameToOpen(const char* path);
std::string getDatasetPath(const char* handle) throw (CMMError);
bool isDatasetOpen(const char* handle);
bool isDatasetReadOnly(const char* handle);
std::vector<long> getDatasetShape(const char* handle) throw (CMMError);
MM::StorageDataType getDatasetPixelType(const char* handle) throw (CMMError);
void addImage(const char* handle, int sizeinBytes, const STORAGEIMG pixels, const std::vector<long>& coordinates, const char* imageMeta) throw (CMMError);
void addImage(const char* handle, int sizeinShorts, const STORAGEIMG16 pixels, const std::vector<long>& coordinates, const char* imageMeta) throw (CMMError);
void configureDimension(const char* handle, int dimension, const char* name, const char* meaning) throw (CMMError);
void configureCoordinate(const char* handle, int dimension, int coordinate, const char* name) throw (CMMError);
std::string getDimensionName(const char* handle, int dimension) throw (CMMError);
std::string getDimensionMeaning(const char* handle, int dimension) throw (CMMError);
std::string getCoordinateName(const char* handle, int dimension, int coordinate) throw (CMMError);
int getImageCount(const char* handle) throw (CMMError);
std::string getSummaryMeta(const char* handle) throw (CMMError);
std::string getImageMeta(const char* handle, const std::vector<long>& coordinates) throw (CMMError);
STORAGEIMGOUT getImage(const char* handle, const std::vector<long>& coordinates) throw (CMMError);
Expand Down

0 comments on commit 79d06e9

Please sign in to comment.