Wiki

Clone wiki

geomIO / Basic2Dtutorial

[Home] [Basic 2D tutorial] [Basic 3D tutorial] [VaryGeom2D tutorial] [VaryGeom3D tutorial]

geomIO_logo


Summary 2D basics

Adding attributes with XML editor

We start with an empty SVG file that can be named arbitrarily. Add a shape with the Bezièr tool or another tool. Path shapes may be open, but it's more convenient to close the path immediately.

Select the shape and and open the XML editor. Add new attributes to assign a label (string) and a phase ID (optional). This can be done by clicking on the '+' button. Assign an attribute name and value and confirm with the 'Set' button. That's about it. Save the SVG file and switch to MATLAB.

Assigning phase information to markers

In MATLAB, initialize geomIO and extract the coordinates:

opt                 = geomIO_Options(); 
opt.inputFileName   = ['./Input/LapinouAndFriends.svg'];
[PathCoord]         = run_geomIO(opt,'2D'); 

geomIO_Options() is a class containing information about the svg file, coordinate system, and various options. More details [here]. Here, opt has been assigned a set of default values. In this example, only opt.inputFileName needs to be specified, all other options can keep their default value.

PathCoord is a struct that stores relevant information about the drawn shapes such as coordinates, style (color, stroke, etc ...), phase, label. A complete description of PathCoord can be found [here].

Next, define a set of markers as a set of three matrices containing X coordinate, Y coordinate and phase number of all markers, respectively. Here we will use the "paper sheet" from the svg file as our box.

xmin = 0; xmax = opt.svg.width; 
ymin = 0; ymax = opt.svg.height;
[Xp,Yp]      = ndgrid(xmin:15:xmax,ymin:15:ymax);
Phase        = zeros(size(Xp));

Then assign a phase to each marker according to your drawing.

Phase = assignPhase2Markers(PathCoord, opt, Xp, Yp, Phase)

Multiple shapes

Draw multiples shapes. Don't forget to add a phase and a label (optional) to each one of them (See section 1).

The code shown in the previous section works for multiple shapes as well!

Note: transparency is taken into account by svgPlot by specifying the Alpha value of the fill color in Inkscape. (The opacity value set with the Opacity slider is however not read).

Plotting in Matlab

You can check if your file was read properly by reproducing your drawing in matlab.

figure(1)
plotSVG(PathCoord,opt)

Then you can check if the phases were assigned properly.

figure(2)
scatter(Xp(:),Yp(:),10,Phase(:),'filled');
% imagesc(Xp(:,1),Yp(1,:),Phase'); % alternative plot
axis equal
axis([xmin xmax ymin ymax])

You can plot the contours of the drawing on top using:

    hold on
    plotSVG(PathCoord,opt,0)

You can also create a colormap according to the filling colors used in your drawing.

     % the second argument is optional and specifies to RGB color of phase 0 (if no shape with phase 0 is found), it is white by default 
    [CMAP, PhaseMax] = getColormapFromPathCoord(PathCoord,[.8 .8 .8]);
    colormap(CMAP)
    caxis([-.5 PhaseMax+.5]);  colorbar('YTick',0:PhaseMax)

The figure above shows the result of the function svgPlot (A) and a scatter plot of markers (B) with colors coding for the phase number.

Creating a body-fitted mesh

An example of the creation of a body-fitted mesh can be found here.

Note on compatibility

All present tutorials are specific to Inkscape. Illustrator is also supported by geomIO, however, due to the impossibility to edit the XML files directly in Illustrator, a few steps differ. See [this page] for details. geomIO has been tested with MATLAB2013a and more recent versions. All or part of geomIO might also be compatible with Octave, however this has not been tested. geomIO uses MATLAB mex-files (C compiled code) for performance intensive operations. Mex-files would give lower performance in Octave.

Updated