Surface resource construction examplesΒΆ

Example 1: Create a basic triangulated Steno3D Surface

sfc = steno3d.core.Surface;
verts = rand(100, 3);
tris = convhull(verts(:, 1), verts(:, 2), verts(:, 3));
mesh = steno3d.core.Mesh2D;
mesh.Vertices = verts;
mesh.Triangles = tris;
sfc.Mesh = mesh;
example1 = steno3d.core.Project;
example1.Resources = sfc;
clear sfc tris verts mesh;

Example 2: Create a basic grid Surface resource and set display options

sfc = steno3d.core.Surface;
sfc.Title = 'Example 2 Grid';
sfc.Description = 'This Surface will be yellow';
heights = peaks(20);
mesh = steno3d.core.Mesh2DGrid;
mesh.H1 = ones(19, 1);
mesh.H2 = ones(19, 1);
mesh.Z = heights(:);
sfc.Mesh = mesh;
sfc.Opts.Color = 'y';
sfc.Opts.Opacity = 0.75;
sfc.Mesh.Opts.Wireframe = true;
example2 = steno3d.core.Project;
example2.Title = 'Example 2';
example2.Description = 'Project with a surface';
example2.Resources = sfc;
clear sfc mesh heights;

Example 3: Create a Surface resource with cell-centered data

Note

This constructor encapsulates all the features of sfc (and more) from Example 1.

v = rand(100, 3);
t = convhull(v(:, 1), v(:, 2), v(:, 3));
sfc = steno3d.core.Surface(                                  ...
    'Title', 'Example 3 Surface',                            ...
    'Description', 'This Surface resource will have data',   ...
    'Mesh', steno3d.core.Mesh2D(                             ...
        'Vertices', v,                                       ...
        'Triangles', t,                                      ...
        'Opts', {'Wireframe', true}                          ...
    ),                                                       ...
    'Opts', {'Color', 'y', 'Opacity', 0.75}                  ...
);
trixloc = mean(reshape(v(t, 1), size(t)), 2);
xdata = steno3d.core.DataArray(                              ...
    'Title', 'X-Location',                                   ...
    'Array', trixloc                                         ...
);
sfc.Data = {'Location', 'CC', 'Data', xdata};
example3 = steno3d.core.Project(                             ...
    'Title', 'Example 3',                                    ...
    'Description', 'Project with a surface',                 ...
    'Resources', sfc                                         ...
);
clear sfc xdata v t;

Example 4: Create a Surface resource with an image projected onto it

v = rand(100, 3);
sfc = steno3d.core.Surface(                                  ...
    'Title', 'Example 4 Surface',                            ...
    'Description', 'This Surface resource has an image',     ...
    'Mesh', steno3d.core.Mesh2D(                             ...
        'Vertices', v,                                       ...
        'Triangles', convhull(v(:, 1), v(:, 2), v(:, 3)),    ...
        'Opts', {'Wireframe', true}                          ...
    ),                                                       ...
    'Opts', {'Color', 'y'}                                   ...
);
pngFile = [tempname '.png'];
imwrite(imread('ngc6543a.jpg'), pngFile, 'png');
tex = steno3d.core.Texture2DImage(                           ...
    'Image', pngFile,                                        ...
    'O', [-1 -1 0],                                          ...
    'U', [3 0 0],                                            ...
    'V', [0 3 0]                                             ...
);
sfc.Textures = tex;
example4 = steno3d.core.Project(                             ...
    'Title', 'Example 4',                                    ...
    'Description', 'Project with a surface',                 ...
    'Resources', sfc                                         ...
);
clear sfc tex pngFile v;

Example 5: Create a Surface resource with multiple datasets/textures

Note

There are several new features introduced in this highly consolidated construction. (1) Multiple datasets and textures are assigned as a cell array. (2) Passing cell arrays of parameters (e.g. for Mesh) implicitly calls the correct constructor. (3) Specifying O, U, and V in the Mesh2DGrid moves it away from the origin and rotates/skews the axes. (4) The texture attempts to coerce a JPG file to PNG.

pks = peaks(20);
sfc = steno3d.core.Surface(                                  ...
    'Title', 'Example 5 Grid',                               ...
    'Description', 'This Surface resource will have data',   ...
    'Mesh', {                                                ...
        'H1', 2*ones(19, 1),                                 ...
        'H2', 3*ones(19, 1),                                 ...
        'O', [-19 0 -28.5],                                  ...
        'U', [1 0 0],                                        ...
        'V', [.5 0 sqrt(3)/2],                               ...
        'Z', pks(:)                                          ...
    },                                                       ...
    'Opts', {'Color', 'y', 'Opacity', 0.75},                 ...
    'Data', {{                                               ...
        'Location', 'N',                                     ...
        'Data', {'Title', 'Peaks Data', 'Array', pks(:)}     ...
    }, {                                                     ...
        'Location', 'CC',                                    ...
        'Data', {'Title', 'Random', 'Array', rand(19*19, 1)} ...
    }},                                                      ...
    'Textures', {{                                           ...
        'Title', 'Aligned image',                            ...
        'Image', 'ngc6543a.jpg',                             ...
        'U', 38*[1 0 0],                                     ...
        'V', 57*[.5 0 sqrt(3)/2],                            ...
        'O', [-19 0 -28.5]                                   ...
    }, {                                                     ...
        'Title', 'Small square image',                       ...
        'Image', 'ngc6543a.jpg',                             ...
        'O', [-.5 0 -20],                                    ...
        'U', 'X',                                            ...
        'V', 'Z'                                             ...
    }}                                                       ...
);
example5 = steno3d.core.Project(                             ...
    'Title', 'Example 5',                                    ...
    'Description', 'Project with a surface',                 ...
    'Resources', sfc                                         ...
);
clear sfc;

You can run the above examples with:

steno3d.examples.core.surface

Then plot the projects with:

example1.plot(); % etc...

See also steno3d.core.Surface, steno3d.core.Mesh2D, steno3d.core.Mesh2DGrid, steno3d.core.Project, steno3d.core.DataArray, steno3d.core.Texture2DImage