0

我在更新我的情节时遇到问题。基本上,我有一个函数可以创建一个带有 3 个子图的图形。然后我有另一个函数运行 create figure 函数,然后更新绘图。仅更新很重要,因此我不会在每个循环中创建一个新图形,因为它是 3d 数据并且需要一段时间才能加载。

问题在于我的第二个子情节。我使用 slice() 加载 3 个图像(3 个切片),然后还想绘制一个位置向量。我最初将我的位置向量设置为(0,0,0),然后我想我可以通过将'XData','YData'......设置为它们各自的值来在我的循环中更新它。由于某种原因,它无法正常工作,并且正在吐出错误“未定义函数'XData'用于'double'类型的输入参数。” 请帮忙,下面是代码,谢谢!!!

注意---错误在于“%refresh plot”之后的更新绘图功能

初始情节

function [Fig] = EndoSliceViewer_createFigure(Figindex,DICOMparam)
%This function creates and returns a Figure object to visualizes DICOM data
%in the plane orthogonal to the endoscopic view, the RGB view of the camera
%and the orientation of the navigation

%set resolution for Endo Slice Plot
Fig.resolEndoSlice=300; 
Fig.resolEndoRGB=[720 1280]; 
Fig.resolEndoNavi=[500 500 500]; 

%init figure on screen
Fig.fig=figure(Figindex); gcf;
set(Fig.fig,'Position',[50 500 1500 500],'Name','Endo Slice Viewer');
%set(Fig.fig,'KeyPressFcn','global kpressed; global Fig; kpressed = get(Fig.fig,''CurrentChar'');');

Fig.sub1=subplot(1,3,1);
Fig.sub1im=image(uint8(zeros(Fig.resolEndoRGB(1), Fig.resolEndoRGB(2),3)));
title('Endo Camera View');
daspect([1 1 1]);

Fig.sub2=subplot(1,3,2);
Fig.sub2im=plot3(0,0,0);
h=slice(DICOMparam.Vd,DICOMparam.Cx,DICOMparam.Cy,DICOMparam.Cz);
colormap bone;
set(h,'FaceColor','interp',...
    'EdgeColor','none',...
    'DiffuseStrength',.8)
title('Navigation View');
xlim([-0.2*Fig.resolEndoNavi(1),  1.2*Fig.resolEndoNavi(1)]);
ylim([-0.2*Fig.resolEndoNavi(2),  1.2*Fig.resolEndoNavi(2)]);
zlim([-0.2*Fig.resolEndoNavi(3),  1.2*Fig.resolEndoNavi(3)]);
xlabel('X [vox]');
ylabel('Y [vox]');
zlabel('Z [vox]');
daspect([1 1 1]);

Fig.sub3=subplot(1,3,3);
Fig.sub3im=imagesc(zeros(Fig.resolEndoSlice, Fig.resolEndoSlice));
title('Endo Slice View');
xlim([0 Fig.resolEndoSlice]);
ylim([0 Fig.resolEndoSlice]);
xlabel('Xendo [vox]');
ylabel('Yendo [vox]');
daspect([1 1 1]);
colormap bone
drawnow;

%potentially: add subplot for navigation position display later
end

更新情节

function [  ] = EndoSliceViewerJP( Naviparam,  DICOMparam)
%RGBparam should be included later - add +1 to nargin values 

%visualizes: 
%1st: RGB camera Live view 
%2nd: Orientation and Position of Navigation System
%3rd: DICOM Slice relative to navigated Endoscope in a and its orientation
%in a Slice perpendicular to the endoscope
%assumes Navigation system running with referenced tool (Naviparam.tool=4 or Naviparam.tool=5)

%currently this plots slices according to Endoscope position, could add
%vector in plot that shows orientation of the scope...
disp('Endo Slice Viewer');
disp('" ": exit on space key');
global kpressed;
kpressed = 0;

global Fig
Fig=EndoSliceViewer_createFigure(1,DICOMparam);
set(Fig.fig,'KeyPressFcn','global kpressed; global Fig; kpressed = get(Fig.fig,''CurrentChar'');');

%create matrices and filter for smoothing of Endo Slice Data
xrel=-(ones(Fig.resolEndoSlice,1)*(1:Fig.resolEndoSlice)-Fig.resolEndoSlice/2)';
yrel=-(ones(Fig.resolEndoSlice,1)*(1:Fig.resolEndoSlice)-Fig.resolEndoSlice/2);
SLimage=zeros(Fig.resolEndoSlice,Fig.resolEndoSlice);
PosVec=zeros(Fig.resolEndoSlice,Fig.resolEndoSlice,3);
gfilt = fspecial('gaussian',5,1.5);
depth = 50;


exitflag = 0;
while (exitflag == 0)
     %check on keyboard input
     if kpressed ~= 0
        switch kpressed
            case 'r'
                depth=depth+2
            case 'f'
                depth=depth-2
            case ' '
                exitflag = 1;
                disp('**** Exit Endo Slice Viewer ****')

        end
        kpressed = 0;
     end

if (nargin>=1) %Naviparam is passed - update Navigation View
     %capture new navigation data
     Naviparam=Navi_acquire(Naviparam);
     Naviparam=Navi_calc_data(Naviparam);

     %refreshN avigation View
     %NOT YET IMPLEMENTED: UPDATE NAVIGATION PLOT 

     if (nargin==2) %DICOMparam is also passed - update EndoSlice View
         EndoVecX=inv(DICOMparam.calib.navi2dicom(1:3,1:3))*inv(Naviparam.data.Endo_RefHomMat(1:3,1:3))*[1;0;0];
         EndoVecY=inv(DICOMparam.calib.navi2dicom(1:3,1:3))*inv(Naviparam.data.Endo_RefHomMat(1:3,1:3))*[0;1;0];
         EndoVecZ=inv(DICOMparam.calib.navi2dicom(1:3,1:3))*inv(Naviparam.data.Endo_RefHomMat(1:3,1:3))*[0;0;-1];
         disp(Naviparam.data.Endo_RefHomMat(1:3,1:3));
         EndoVecX=EndoVecX/norm(EndoVecX);
         EndoVecY=EndoVecY/norm(EndoVecY);
         EndoVecZ=EndoVecZ/norm(EndoVecZ);
         mask=ones(Fig.resolEndoSlice,Fig.resolEndoSlice);
         S=[DICOMparam.Sx; DICOMparam.Sy; DICOMparam.Sz];

         DICOMPos = DICOMparam.calib.navi2dicom*[Naviparam.data.Endo_RefOffsetPosVec;1];

         for i=1:3
             %Point on Plane defined by Endo Position plus distance*Viewing direction vector
             PosVec(:,:,i)=(DICOMPos(i)+depth*EndoVecZ(i))+xrel*EndoVecX(i)+yrel*EndoVecY(i);
             %limit positions to integer values inside DICOM data cube
             PosVec(:,:,i)=round(PosVec(:,:,i));
             PosVec(:,:,i)=min(max(PosVec(:,:,i),1),S(i));
             %create mask to set Points outside the data cube to 0
             mask=double(PosVec(:,:,i)>1).*double(PosVec(:,:,i)<S(i).*mask(:,:));
         end
         %access data cube via indexed labelling
         XposTemp=PosVec(:,:,1); YposTemp=PosVec(:,:,2); ZposTemp=PosVec(:,:,3);
         indexTemp=sub2ind(size(DICOMparam.Vd), XposTemp(:), YposTemp(:),ZposTemp(:));
         SLimage(:)=DICOMparam.Vd(indexTemp(:));

         SLimage=SLimage.*mask;
         SLimage=imfilter(SLimage,gfilt);

         %refresh plot
         set(Fig.sub3im, 'cdata', SLimage);
     axes(Fig.sub2);
     set(lineseries, 'XData', DICOMPos(1), 'YData', DICOMPos(2), 'ZData', DICOMPos(3));
     set(lineseries, 'Marker', '*', 'Color', 'b');
     disp(DICOMPos);
     end
end

%RGBparam is always passed - update RGB camera View
%capture new RGB data
%handles.RGBparam=RGB_acquire(handles.RGBparam);
%refresh RGB camera View
%set(Fig.sub1im, 'CData', imresize(handles.RGBparam.image,[Fig.resolEndoRGB(1) Fig.resolEndoRGB(2)]));  


drawnow;
end

close(Fig.fig);
clear global;


end
4

3 回答 3

2

函数set调用方式如下

set(ObjectHandle, 'PropertyName_1', PropertyValue_1, 'PropertyName_2', PropertyValue_2);

添加更多适合的名称-值对。在你的情况下,那将是

set(LineHandle, 'XData', DICOMPos(1), 'YData', DICOMPos(2), 'ZData', DICOMPos(3));

用于更改位置数据。请注意,所有这些属性都属于线,而不是轴,因此您需要获取要更新的线的句柄。假设轴只包含一行,这可以通过在循环之前添加以下代码来临时完成:

LineHandle = findobj(Fig.sub2, 'type', 'line');

此外,您不能以这种方式更改线型:set(LineHandle, 'b*'). 这就是错误“无效的参数/值对参数”的原因。

首先,您需要在每个属性值之前有一个属性名称,其次,线型实际上没有属性名称。您必须分别更改颜色和标记,例如:

set(LineHandle, 'Marker', '*', 'Color', 'b');
于 2013-07-23T08:38:05.363 回答
0

该错误告诉您您在某处使用 XData 之类的函数,而您没有该函数。当你打电话时会发生这种情况

XData(DICOMPos(1))

你对 Y 和 Z 数据做同样的事情。这不是您使用该功能的方式。我猜你正在编辑别人的代码?您要替换到轴中的数据是什么?DICOMPos(1)?

于 2013-07-23T08:28:12.783 回答
-1

这段代码错误的原因有点棘手……或者至少不是我预期的那样。我试图访问 Fig.sub2,它定义了 Fig.sub2im 的轴,而不是直接访问 Fig.sub2im。我试图为 Fig.sub2 定义新的“XData”的原因是因为 Fig.sub2im MATLAB 一直告诉我句柄被删除或无效。这是因为我的 slice() 在我的初始绘图设置中覆盖了我的 plot3(),因此 Fig.sub2im 不再是我想要的那样。

为了解决这个问题,我所要做的就是将 Fig.sub2 编辑为 Fig.sub2im,然后等待;在我的情节3之后。

于 2013-07-23T10:25:26.797 回答