Skip to content

Commit

Permalink
Add new functions and update CMakeLists.txt
Browse files Browse the repository at this point in the history
Updated CMakeLists.txt to include new source files for functions:
func_getmultichannelscalingtilecomposite, func_getinfo,
func_getmetadataxml, and func_getscaling. Adjusted lib_VERSION_EXT
for formatting consistency. In mexFunctions.cpp, added new include
directives and updated funcItems array with new functions. Added
implementations for new functions in respective .cpp and .h files.
  • Loading branch information
ptahmose committed Oct 6, 2024
1 parent 67002f2 commit 90a0dc9
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 6 deletions.
14 changes: 12 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ set (libSourceFiles
"src/implementation/CziWriterManager.cpp"
"src/implementation/CziWriterManager.h"
"src/functions/func_open.cpp"
"src/functions/func_open.h" "src/functions/func_getsubblockbitmap.cpp" "src/functions/func_getsubblockbitmap.h")
"src/functions/func_open.h"
"src/functions/func_getsubblockbitmap.cpp"
"src/functions/func_getsubblockbitmap.h"
"src/functions/func_getmultichannelscalingtilecomposite.cpp"
"src/functions/func_getmultichannelscalingtilecomposite.h"
"src/functions/func_getinfo.cpp"
"src/functions/func_getinfo.h"
"src/functions/func_getmetadataxml.cpp"
"src/functions/func_getmetadataxml.h"
"src/functions/func_getscaling.cpp"
"src/functions/func_getscaling.h")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(lib_ENABLE_LOGGING 1)
Expand All @@ -44,7 +54,7 @@ set(lib_LOGLEVEL 1)
set(lib_VERSION_MAJOR ${MEXCZI_MAJOR})
set(lib_VERSION_MINOR ${MEXCZI_MINOR})
set(lib_VERSION_PATCH ${MEXCZI_PATCH})
set(lib_VERSION_EXT ${MEXCZI_EXT})
set(lib_VERSION_EXT ${MEXCZI_EXT})

configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/lib_config.h.in"
Expand Down
29 changes: 29 additions & 0 deletions lib/src/functions/func_getinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "func_getinfo.h"
#include <memory>
#include "../implementation/argsutils.h"
#include "../implementation/utils.h"

using namespace std;

void MexFunction_GetInfo_CheckArguments(MatlabArgs* args)
{
if (args->nrhs < 2)
{
throw invalid_argument("not enough arguments");
}

if (!CArgsUtils::IsNumericArrayOfMinSize(args->prhs[1], 1, args->app_functions))
{
throw invalid_argument("2nd argument must be an integer");
}
}

void MexFunction_GetInfo_Execute(MatlabArgs* args)
{
int id;
bool b = CArgsUtils::TryGetInt32(args->prhs[1], &id, args->app_functions);
const std::shared_ptr<CziReader> reader = ::Utils::GetReaderOrThrow(id);

auto* info = reader->GetInfo(args->app_functions);
args->plhs[0] = info;
}
6 changes: 6 additions & 0 deletions lib/src/functions/func_getinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "../mexFunctions.h"

void MexFunction_GetInfo_CheckArguments(MatlabArgs* args);
void MexFunction_GetInfo_Execute(MatlabArgs* args);
30 changes: 30 additions & 0 deletions lib/src/functions/func_getmetadataxml.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "func_getmetadataxml.h"
#include <memory>
#include "../implementation/argsutils.h"
#include "../implementation/utils.h"

using namespace std;

// How to parse an XML-string with MATLAB -> http://undocumentedmatlab.com/articles/parsing-xml-strings

void MexFunction_GetMetadataXml_CheckArguments(MatlabArgs* args)
{
if (args->nrhs < 2)
{
throw invalid_argument("not enough arguments");
}

if (!CArgsUtils::IsNumericArrayOfMinSize(args->prhs[1], 1, args->app_functions))
{
throw invalid_argument("2nd argument must be an integer");
}
}

void MexFunction_GetMetadataXml_Execute(MatlabArgs* args)
{
int id;
bool b = CArgsUtils::TryGetInt32(args->prhs[1], &id, args->app_functions);
std::shared_ptr<CziReader> reader = ::Utils::GetReaderOrThrow(id);
auto* m = reader->GetMetadataXmlAsMxArray(args->app_functions);
args->plhs[0] = m;
}
6 changes: 6 additions & 0 deletions lib/src/functions/func_getmetadataxml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "../mexFunctions.h"

void MexFunction_GetMetadataXml_CheckArguments(MatlabArgs* args);
void MexFunction_GetMetadataXml_Execute(MatlabArgs* args);
68 changes: 68 additions & 0 deletions lib/src/functions/func_getmultichannelscalingtilecomposite.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "func_getmultichannelscalingtilecomposite.h"
#include "../implementation/CziReaderManager.h"
#include <vector>
#include <memory>
#include "../implementation/argsutils.h"
#include "../implementation/utils.h"

using namespace std;
using namespace libCZI;

void MexFunction_GetMultiChannelScalingTileComposite_CheckArguments(MatlabArgs* args)
{
// arguments:
// (1) handle
// (2) ROI -> array of >=4 numbers
// (3) plane-coordinate
// (4) zoom (number)
// (5) (optional) display-settings
if (args->nrhs < 5)
{
throw invalid_argument("not enough arguments");
}

if (!CArgsUtils::IsNumericArrayOfMinSize(args->prhs[1], 1, args->app_functions))
{
throw invalid_argument("1st argument must be an integer");
}

if (!CArgsUtils::IsNumericArrayOfMinSize(args->prhs[2], 4, args->app_functions))
{
throw invalid_argument("2nd argument must be a ROI");
}

if (!CArgsUtils::TryGetDimCoordinate(args->prhs[3], nullptr, args->app_functions))
{
throw invalid_argument("3nd argument must be a string (specifying a coordinate)");
}

if (!CArgsUtils::TryGetSingle(args->prhs[4], nullptr, args->app_functions))
{
throw invalid_argument("4th argument must be a number");
}
}

void MexFunction_GetMultiChannelScalingTileComposite_Execute(MatlabArgs* args)
{
int id;
bool b = CArgsUtils::TryGetInt32(args->prhs[1], &id, args->app_functions);

std::shared_ptr<CziReader> reader = ::Utils::GetReaderOrThrow(id);
IntRect rect;
b = CArgsUtils::TryGetIntRect(args->prhs[2], &rect, args->app_functions);

CDimCoordinate coord;
b = CArgsUtils::TryGetDimCoordinate(args->prhs[3], &coord, args->app_functions);

float zoom;
b = CArgsUtils::TryGetSingle(args->prhs[4], &zoom, args->app_functions);

auto* out = reader->GetMultiChannelScalingTileComposite(
rect,
&coord,
(float)zoom,
(const char*)nullptr/*displaySettingsString*/,
args->app_functions);

args->plhs[0] = out;
}
6 changes: 6 additions & 0 deletions lib/src/functions/func_getmultichannelscalingtilecomposite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "../mexFunctions.h"

void MexFunction_GetMultiChannelScalingTileComposite_CheckArguments(MatlabArgs* args);
void MexFunction_GetMultiChannelScalingTileComposite_Execute(MatlabArgs* args);
33 changes: 33 additions & 0 deletions lib/src/functions/func_getscaling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "func_getscaling.h"
#include <memory>
#include "../implementation/argsutils.h"
#include "../implementation/utils.h"

using namespace std;

void MexFunction_GetScaling_CheckArguments(MatlabArgs* args)
{
if (args->nrhs < 2)
{
throw invalid_argument("not enough arguments");
}

if (!CArgsUtils::IsNumericArrayOfMinSize(args->prhs[1], 1, args->app_functions))
{
throw invalid_argument("2nd argument must be an integer");
}
}

void MexFunction_GetScaling_Execute(MatlabArgs* args)
{
int id;
const bool b = CArgsUtils::TryGetInt32(args->prhs[1], &id, args->app_functions);
if (!b)
{
throw invalid_argument("2nd argument must be an integer");
}

std::shared_ptr<CziReader> reader = ::Utils::GetReaderOrThrow(id);
auto* m = reader->GetScalingAsMatlabStruct(args->app_functions);
args->plhs[0] = m;
}
6 changes: 6 additions & 0 deletions lib/src/functions/func_getscaling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "../mexFunctions.h"

void MexFunction_GetScaling_CheckArguments(MatlabArgs* args);
void MexFunction_GetScaling_Execute(MatlabArgs* args);
9 changes: 5 additions & 4 deletions lib/src/mexFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include "functions/func_getversion.h"
#include "functions/func_open.h"
#include "functions/func_getsubblockbitmap.h"
#include "functions/func_getmultichannelscalingtilecomposite.h"
#include "functions/func_getinfo.h"
#include "functions/func_getscaling.h"
#include "functions/func_getmetadataxml.h"
/*
#include "src/func_close.h"
#include "src/func_getmultichannelscalingtilecomposite.h"
#include "src/func_getinfo.h"
#include "src/func_getmetadataxml.h"
#include "src/func_getscaling.h"
#include "src/func_getsinglechannelscalingtilecomposite.h"
#include "src/func_getdefaultdisplaysettings.h"
#include "src/func_getsubblock.h"
Expand All @@ -23,11 +24,11 @@
{u8"GetVersion", {MexFunction_GetVersion_CheckArguments,MexFunction_GetVersion_Execute}},
{u8"Open", {MexFunction_Open_CheckArguments,MexFunction_Open_Execute}},
{u8"GetSubBlockBitmap", {MexFunction_GetSubBlockBitmap_CheckArguments,MexFunction_GetSubBlockBitmap_Execute}},
/*
{u8"GetMultiChannelScalingTileComposite", {MexFunction_GetMultiChannelScalingTileComposite_CheckArguments,MexFunction_GetMultiChannelScalingTileComposite_Execute}},
{u8"GetInfo", {MexFunction_GetInfo_CheckArguments,MexFunction_GetInfo_Execute}},
{u8"GetScaling", {MexFunction_GetScaling_CheckArguments,MexFunction_GetScaling_Execute}},
{u8"GetMetadataXml", {MexFunction_GetMetadataXml_CheckArguments,MexFunction_GetMetadataXml_Execute}},
/*
{u8"GetSingleChannelScalingTileComposite", {MexFunction_GetSingleChannelScalingTileComposite_CheckArguments,MexFunction_GetSingleChannelScalingTileComposite_Execute}},
{u8"Close", {MexFunction_Close_CheckArguments,MexFunction_Close_Execute}},
{u8"GetDefaultDisplaySettings", {MexFunction_GetDefaultDisplaySettings_CheckArguments,MexFunction_GetDefaultDisplaySettings_Execute}},
Expand Down

0 comments on commit 90a0dc9

Please sign in to comment.