Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
自动析构指针对象
修复ChannelColor不能索引的问题
  • Loading branch information
埃博拉酱 committed Aug 21, 2023
1 parent 2219aa8 commit 66844a7
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 55 deletions.
Binary file modified +Image5D/+internal/private/Image5DMex.mexw64
Binary file not shown.
46 changes: 31 additions & 15 deletions +Image5D/ChannelColor.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
%红色通道
R
end
methods(Access=private)
methods(Access=protected)
function obj=ChannelColor(Value)
obj@uint32(Value);
end
Expand Down Expand Up @@ -77,17 +77,17 @@
end
end
methods
function Value=get.A(obj)
Value=uint8(bitand(bitshift(uint32(obj),-0),0x000000ff));
function obj=get.A(obj)
obj=uint8(bitand(bitshift(uint32(obj),-0),0x000000ff));
end
function Value=get.B(obj)
Value=uint8(bitand(bitshift(uint32(obj),-8),0x000000ff));
function obj=get.B(obj)
obj=uint8(bitand(bitshift(uint32(obj),-8),0x000000ff));
end
function Value=get.G(obj)
Value=uint8(bitand(bitshift(uint32(obj),-16),0x000000ff));
function obj=get.G(obj)
obj=uint8(bitand(bitshift(uint32(obj),-16),0x000000ff));
end
function Value=get.R(obj)
Value=uint8(bitand(bitshift(uint32(obj),-24),0x000000ff));
function obj=get.R(obj)
obj=uint8(bitand(bitshift(uint32(obj),-24),0x000000ff));
end
function obj=set.A(obj,Value)
if isfloat(Value)
Expand All @@ -113,17 +113,33 @@
end
obj=Image5D.ChannelColor(bitand(uint32(obj),0x00ffffff)+bitshift(uint32(Value),24));
end
function C=horzcat(obj,varargin)
function obj=horzcat(obj,varargin)
varargin=cellfun(@uint32,varargin,UniformOutput=false);
C=Image5D.ChannelColor(horzcat(uint32(obj),varargin{:}));
obj=Image5D.ChannelColor(horzcat(uint32(obj),varargin{:}));
end
function C=vertcat(obj,varargin)
function obj=vertcat(obj,varargin)
varargin=cellfun(@uint32,varargin,UniformOutput=false);
C=Image5D.ChannelColor(vertcat(uint32(obj),varargin{:}));
obj=Image5D.ChannelColor(vertcat(uint32(obj),varargin{:}));
end
function C=cat(obj,dim,varargin)
function obj=cat(obj,dim,varargin)
varargin=cellfun(@uint32,varargin,UniformOutput=false);
C=Image5D.ChannelColor(cat(dim,uint32(obj),varargin{:}));
obj=Image5D.ChannelColor(cat(dim,uint32(obj),varargin{:}));
end
function obj=subsref(obj,S)
switch S.type
case "()"
obj=uint32(obj);
obj=Image5D.ChannelColor(obj(S.subs{:}));
case "."
obj=obj.(S.subs);
otherwise
Image5D.Image5DException.Unexpected_subsref_type.Throw;
end
end
function obj=subsasgn(obj,S,V)
obj=uint32(obj);
obj(S.subs{:})=V;
obj=Image5D.ChannelColor(obj);
end
end
end
1 change: 1 addition & 0 deletions +Image5D/Image5DException.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@

%MATLAB抛出的异常

Unexpected_subsref_type(253)
DEFAULT_PixelType_cannot_convert_to_MATLAB_datatypes(254)
Wrong_number_of_parameters(255)
end
Expand Down
2 changes: 1 addition & 1 deletion +Image5D/Version.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function V=Version
V.Me='v2.0.0';
V.Me='v2.1.0';
V.MatlabExtension=MATLAB.Version;
V.MATLAB='R2022b';
persistent NewVersion
Expand Down
14 changes: 0 additions & 14 deletions Image5D.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Image5DLib", "Image5DLib\Im
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Image5D测试", "Image5D测试\Image5D测试.vcxproj", "{0D661C84-7BE0-49EA-9B5D-9F1A9B3DC7EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mex工具", "..\..\..\source\repos\MexTools\Mex工具\Mex工具.vcxproj", "{CE6CE462-A955-46A7-BB11-895054EF51EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -57,18 +55,6 @@ Global
{0D661C84-7BE0-49EA-9B5D-9F1A9B3DC7EF}.Release|x64.Build.0 = Release|x64
{0D661C84-7BE0-49EA-9B5D-9F1A9B3DC7EF}.Release|x86.ActiveCfg = Release|Win32
{0D661C84-7BE0-49EA-9B5D-9F1A9B3DC7EF}.Release|x86.Build.0 = Release|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Debug|x64.ActiveCfg = Debug|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Debug|x64.Build.0 = Debug|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Debug|x86.ActiveCfg = Debug|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Debug|x86.Build.0 = Debug|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release.GL|x64.ActiveCfg = Release.GL|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release.GL|x64.Build.0 = Release.GL|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release.GL|x86.ActiveCfg = Release.GL|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release.GL|x86.Build.0 = Release.GL|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release|x64.ActiveCfg = Release|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release|x64.Build.0 = Release|x64
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release|x86.ActiveCfg = Release|Win32
{CE6CE462-A955-46A7-BB11-895054EF51EA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions Image5DLib/include/Image5D异常.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ namespace Image5D
缺少激光参数,
PMT电压未定义,
PMT设置不完整,
无效指针,
};
enum 内部异常类型
{
Expand Down
17 changes: 8 additions & 9 deletions Image5DMex/Image5DMex.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<Linkage-pugixml>dynamic</Linkage-pugixml>
<TargetExt>.mexw64</TargetExt>
<LibraryPath>$(SolutionDir)x64\$(Configuration);C:\Users\vhtmf\source\repos\MexTools\nuget\build\native\lib;$(LibraryPath)</LibraryPath>
<ExternalIncludePath>$(SolutionDir)Image5DLib\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);C:\Users\vhtmf\source\repos\MexTools\nuget\build\native\include</ExternalIncludePath>
<LibraryPath>$(SolutionDir)x64\$(Configuration);$(LibraryPath)</LibraryPath>
<ExternalIncludePath>$(SolutionDir)Image5DLib\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</ExternalIncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)+Image5D\+internal\private\</OutDir>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
<Linkage-pugixml>dynamic</Linkage-pugixml>
<TargetExt>.mexw64</TargetExt>
<LibraryPath>$(SolutionDir)x64\$(Configuration);C:\Users\vhtmf\source\repos\MexTools\nuget\build\native\lib;$(LibraryPath)</LibraryPath>
<ExternalIncludePath>$(SolutionDir)Image5DLib\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);C:\Users\vhtmf\source\repos\MexTools\nuget\build\native\include</ExternalIncludePath>
<LibraryPath>$(SolutionDir)x64\$(Configuration);$(LibraryPath)</LibraryPath>
<ExternalIncludePath>$(SolutionDir)Image5DLib\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</ExternalIncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -140,7 +140,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>Image5DLib.lib;Mex工具.$(PlatformToolsetVersion).$(Configuration).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Image5DLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>
Expand Down Expand Up @@ -171,7 +171,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>Image5DLib.lib;Mex工具.$(PlatformToolsetVersion).$(Configuration).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Image5DLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>
Expand All @@ -182,9 +182,6 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\source\repos\MexTools\Mex工具\Mex工具.vcxproj">
<Project>{ce6ce462-a955-46a7-bb11-895054ef51ea}</Project>
</ProjectReference>
<ProjectReference Include="..\Image5DLib\Image5DLib.vcxproj">
<Project>{f4e56848-cfcb-4f10-ae05-3be7e40423cb}</Project>
</ProjectReference>
Expand All @@ -205,11 +202,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\pugixml.1.13.0\build\native\pugixml.targets" Condition="Exists('..\packages\pugixml.1.13.0\build\native\pugixml.targets')" />
<Import Project="..\packages\MATLAB.MexTools.5.0.0\build\native\MATLAB.MexTools.targets" Condition="Exists('..\packages\MATLAB.MexTools.5.0.0\build\native\MATLAB.MexTools.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\pugixml.1.13.0\build\native\pugixml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\pugixml.1.13.0\build\native\pugixml.targets'))" />
<Error Condition="!Exists('..\packages\MATLAB.MexTools.5.0.0\build\native\MATLAB.MexTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MATLAB.MexTools.5.0.0\build\native\MATLAB.MexTools.targets'))" />
</Target>
</Project>
23 changes: 18 additions & 5 deletions Image5DMex/MexFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ API声明(Tiff_WriteFromPointer);
API声明(Tiff_WriteFromPointerI);
API声明(Tiff_Close);
using namespace Mex工具;
StructArray 异常转结构(const Image5D::Image5D异常& 异常)
using namespace Image5D;
StructArray 异常转结构(const Image5D异常& 异常)
{
StructArray 返回 = 数组工厂.createStructArray({ 1 }, { "ExceptionType","InnerException","ErrorCode" });
返回[0]["ExceptionType"] = 数组工厂.createScalar<uint8_t>(异常.异常类型);
返回[0]["InnerException"] = 数组工厂.createScalar<uint8_t>(异常.内部异常);
if (异常.内部异常 == Image5D::Image5D)
if (异常.内部异常 == 内部异常类型::Image5D)
返回[0]["ErrorCode"] = 异常转结构(*异常.内部Image5D异常);
else
返回[0]["ErrorCode"] = 数组工厂.createScalar(异常.错误代码);
Expand Down Expand Up @@ -113,14 +114,26 @@ struct MexFunction :public Function
try
{
API调用;
const StructArray 成功结构 = 异常转结构(Image5D::成功异常);
const StructArray 成功结构 = 异常转结构(成功异常);
outputs[0] = 成功结构;
}
catch (const Image5D::Image5D异常& 异常)
catch (const Image5D异常& 异常)
{
outputs[0] = 异常转结构(异常);
异常输出补全(outputs);
}
catch (...)
{
outputs[0] = 异常转结构(Image5D异常(无效指针));
异常输出补全(outputs);
}
}
};
Function* const 函数对象 = new MexFunction();
Function* 创建Mex函数()
{
return new MexFunction();//必须用new创建此对象指针,因为 clear mex 时将用delete析构
}
void 销毁Mex函数(Function* 函数指针)
{
delete 函数指针;
}
8 changes: 6 additions & 2 deletions Image5DMex/OirMex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ using namespace Mex工具;
API声明(Oir_CreateReader)
{
const String 文件路径 = 万能转码<String>(inputs[1]);
outputs[1] = 万能转码(new Oir读入器((LPCWSTR)文件路径.c_str()));
Oir读入器*const 对象指针 = new Oir读入器((LPCWSTR)文件路径.c_str());
outputs[1] = 万能转码(对象指针);
自动析构(对象指针);
}
API声明(Oir_DeleteReader)
{
Oir读入器*const 对象指针 = 万能转码<Oir读入器*>(inputs[1]);
手动析构(对象指针);
__try
{
delete 万能转码<Oir读入器*>(inputs[1]);
delete 对象指针;
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
Expand Down
19 changes: 14 additions & 5 deletions Image5DMex/TiffMex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,42 @@ constexpr Image5D异常 元素太少(输入数组元素太少);
API声明(Tiff_OpenRead)
{
const String 字符串 = 万能转码<String>(inputs[1]);
outputs[1] = 万能转码(IOmeTiff读写器::只读打开((wchar_t*)字符串.c_str()));
IOmeTiff读写器* const 对象指针 = IOmeTiff读写器::只读打开((wchar_t*)字符串.c_str());
outputs[1] = 万能转码(对象指针);
自动析构(对象指针);
}
API声明(Tiff_OpenRW)
{
const String 字符串 = 万能转码<String>(inputs[1]);
outputs[1] = 万能转码(IOmeTiff读写器::读写打开((wchar_t*)字符串.c_str()));
IOmeTiff读写器* const 对象指针 = IOmeTiff读写器::读写打开((wchar_t*)字符串.c_str());
outputs[1] = 万能转码(对象指针);
自动析构(对象指针);
}
API声明(Tiff_OpenCreate)
{
const String 字符串 = 万能转码<String>(inputs[1]);
IOmeTiff读写器* 对象指针;
switch (inputs.size())
{
case 3:
{
const std::string 图像描述 = 万能转码(std::move(inputs[2]));
outputs[1] = 万能转码(IOmeTiff读写器::覆盖创建((wchar_t*)字符串.c_str(), 图像描述.c_str()));
对象指针 = IOmeTiff读写器::覆盖创建((wchar_t*)字符串.c_str(), 图像描述.c_str());
}
break;
case 9:
{
TypedArray<uint32_t>颜色数组(std::move(inputs[5]));
const uint8_t SizeC = 颜色数组.getNumberOfElements();
const buffer_ptr_t<uint32_t> 颜色缓冲 = 颜色数组.release();
outputs[1] = 万能转码(IOmeTiff读写器::覆盖创建((wchar_t*)字符串.c_str(), (像素类型)万能转码<UINT8>(inputs[2]), 万能转码<UINT16>(inputs[3]), 万能转码<UINT16>(inputs[4]), SizeC, 万能转码<UINT8>(inputs[6]), 万能转码<uint32_t>(inputs[7]), (颜色*)颜色缓冲.get(), (维度顺序)万能转码<UINT8>(inputs[8])));
对象指针 = IOmeTiff读写器::覆盖创建((wchar_t*)字符串.c_str(), (像素类型)万能转码<UINT8>(inputs[2]), 万能转码<UINT16>(inputs[3]), 万能转码<UINT16>(inputs[4]), SizeC, 万能转码<UINT8>(inputs[6]), 万能转码<uint32_t>(inputs[7]), (颜色*)颜色缓冲.get(), (维度顺序)万能转码<UINT8>(inputs[8]));
}
break;
default:
throw 参数异常;
}
outputs[1] = 万能转码(对象指针);
自动析构(对象指针);
}
API声明(Tiff_PixelType)
{
Expand Down Expand Up @@ -388,9 +395,11 @@ API声明(Tiff_WriteFromPointerI)
}
API声明(Tiff_Close)
{
IOmeTiff读写器* const 对象指针 = 万能转码<IOmeTiff读写器*>(inputs[1]);
手动析构(对象指针);
__try
{
delete 万能转码<IOmeTiff读写器*>(inputs[1]);
delete 对象指针;
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
1 change: 1 addition & 0 deletions Image5DMex/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MATLAB.MexTools" version="5.0.0" targetFramework="native" />
<package id="pugixml" version="1.13.0" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion Image5D工具箱.prj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

依赖:pugixml,AVX2以上指令集,Windows系统(推荐Win11,低版本未测试)</param.description>
<param.screenshot>${PROJECT_ROOT}\工具箱图像.png</param.screenshot>
<param.version>2.0.0</param.version>
<param.version>2.1.0</param.version>
<param.output>${PROJECT_ROOT}\Image5D.mltbx</param.output>
<param.products.name />
<param.products.id />
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ classdef OirReader<handle
SizeT
%每个采样时点的间隔毫秒数
SeriesInterval
%图像元数据XML
LsmimageXml
%各Z层的激光透过率
LaserTransmissivity
%PMT电压,第1维通道,第2维Z层
PmtVoltage
%采样设备名称和通道颜色
DeviceColors
end
methods(Static)
function ConcatenateByRename(HeaderPaths)
Expand All @@ -79,9 +87,6 @@ classdef OirReader<handle
function obj=OirReader(HeaderPath)
%构造OirReader对象
end
function [Devices,Colors]=DeviceColors(obj)
%取各通道的采样设备和颜色信息
end
function Pixels=ReadPixels(obj,TStart,TSize,ZStart,ZSize,CStart,CSize)
%读入像素块值
end
Expand Down

0 comments on commit 66844a7

Please sign in to comment.