Is there an easy way to have synchronized Front/Left/Right/3D views of the same scene in matlab

26 Views Asked by At

I'm wondering if there is an easy way to visualize/manipulate objects in a 3D scene in matlab using classical Front/Left/Top/3D view quadrants but manipulating the scene only once (programmatically and/or from mouse interaction) so that all quadrants would update accordingly (i.e. without having to manually update individual graphic handles in each view) ?

SceneViewer

So far I came out with a manual solution (using a hgtransform over objects I intend to move in the scene and using copyobj and linkprop to synchronize the views. As I intend to put more objects in the scene, there may be a more "ready-to-go" solution ?

function [] = Tests3D()
%[
    % Create figure
    fig = figure(42); clf;

    % Subdivide in Front/Left/Right/3D views
    ax = subplot(2,2,1); ax.Clipping = 'off'; ax.Visible = 'off'; daspect([1 1 1]); view(ax, 0, 0); axtoolbar({'pan', 'zoomin', 'zoomout', 'restoreview'}); axFront = ax; 
    ax = subplot(2,2,2); ax.Clipping = 'off'; ax.Visible = 'off'; daspect([1 1 1]); view(ax, 90, 0); axtoolbar({'pan', 'zoomin', 'zoomout', 'restoreview'}); axLeft = ax;
    ax = subplot(2,2,3); ax.Clipping = 'off'; ax.Visible = 'off'; daspect([1 1 1]); view(ax, 0, 90); axtoolbar({'pan', 'zoomin', 'zoomout', 'restoreview'}); axTop = ax;
    ax = subplot(2,2,4); ax.Clipping = 'off'; ax.Visible = 'off'; daspect([1 1 1]);view(ax, 45, 45); ax3D = ax;

    % Add object in 3D scene
    [verts, faces, cindex] = teapotGeometry();
    xrange = [min(verts(:,1)), max(verts(:,1))];
    yrange = [min(verts(:,2)), max(verts(:,2))];
    zrange = [min(verts(:,3)), max(verts(:,3))];
    axes(ax3D);
    t = hgtransform();
    p = patch('Faces',faces,'Vertices',verts,'FaceVertexCData',cindex,'FaceColor','interp');
    p.Parent = t;

    % Init front view
    axes(axFront);
    xlim(xrange); ylim(yrange); zlim(zrange);
    tFront = copyobj(t, axFront);
    
    % Init left view
    axes(axLeft);
    rotate3d off;
    xlim(xrange); ylim(yrange); zlim(zrange);
    tLeft = copyobj(t, axLeft);
    
    % Init top view
    axes(axTop);
    xlim(xrange); ylim(yrange); zlim(zrange);
    tTop = copyobj(t, axTop);
    
    % Link views
    linkprop([tFront, tLeft, tTop, t], 'Matrix');

    % Test object detection from mouse gesture
    objToDetect = findobj(fig, 'Type', 'patch'); 
    fig.WindowButtonMotionFcn = @onMouseMove;
    function [] = onMouseMove(~, ~)
    %[       
        ht = hittest();
        if (any(ht == objToDetect))
            set(objToDetect, 'FaceColor', 'r');
        else
            set(objToDetect, 'FaceColor', 'interp');
        end
    %]
    end

    % Test transform
    for ki = 0:360
        t.Matrix = makehgtform('zrotate', ki*pi/180);
        pause(0.01); drawnow nocallbacks;    
    end
%]
end

Regarding manipulating objects from mouse gesture I already made other tests with hittest, overobj, WindowButtonMotionFcn, to highlight and drag objects easily, seems ok, but again there may be more efficient solutions to interact with objects (eventually individual faces of objects) in the scene from the mouse.

I'm not planning to recreate a full autocad in matlab, just autoplace an object (from known mesh-model + icp algorithm) in a lidar scene (and eventually extra manual adjustments from mouse gesture).

0

There are 0 best solutions below