MATLAB command for exporting geometry from pdetool - matlab

I'm writing a MATLAB script which solves for the eigenmodes of a defined polygon. MATLAB's PDE toolbox lets me define the geometry using the command pdepoly() but I need to export the geometry description matrix manually to the workspace through the GUI before I can decompose, mesh, and solve the pde. Does anyone know either a command to export the geometry to the workspace or a better way to define this geometry description matrix in MATLAB?
Many Thanks

I am a little confused about what you are trying to do. pdepoly(x,y) expects two vectors x and y already, so perhaps you can simultaneously return those vectors instead of trying to extract them again from the geometry created by pdepoly.
If you are trying to export the geometry from MATLAB so that you can use it elsewhere check this documentation out:
[After calling pdepoly(x,y) t]he state of the Geometry Description matrix inside pdetool is updated to include the polygon. You can export the Geometry Description matrix from pdetool by using the Export Geometry Description option from the Draw menu.
That seems to sound like what you are up to. Best of luck!

Related

how to produce jet color in 2d scatterplot in MATLAB?

Basically, I have been trying to create a jet colored scatter plot in MATLAB.
Ref: Clayson et al. 2013
I have no z-value. Colormap is also not working. How exactly to do it? Thanks
What you are looking for is called a density scatter plot. You don't need a third dimension in order to create it, so don't worry for your missing z. The coloring algorithm is based on the density of the points.
Such plotting function is not included in the default Matlab packages and toolboxes, but after a quick search I probably found exactly what you are looking for. Take a look at this File Exchange release. It contains a full working function for creating density scatters together with a few illustrated usage examples:

Uploading 3D interactive MATLAB mesh plot to ShareLaTeX

I've been working on a project about magnetic fields for my university, and at some point in the MATLAB simulation code I'm creating an interactive mesh plot of the magnetic field at certain points in space. I was wondering as to how I should convert this MATLAB figure to something that I can integrate in a LaTeX pdf. I've read about the media9 package, and I think I'll manage to figure the inserting the file in my .tex file out once I get the figure in an "exportable" form, but I'm not sure as to what I should convert my plot to and how I can do that.
Thanks in advance!

Using inpolyhedron Matlab

I am trying to use the function inpolyhedron shown here: https://www.mathworks.com/matlabcentral/fileexchange/37856-inpolyhedron-are-points-inside-a-triangulated-volume-
However, I am having trouble creating the polyhedron the way the function wants it defined (a structure with fields 'vertices' and 'faces'). The raw data I have is a matrix of points x y z that are inside the polyhedron. So far, I have been using boundary() and trisurf() to plot the polyhedron.
Dependant on what kind of polyhedron you want, you can use alphashape, delaunay triangulation or convhull. So for example:
shp=alphaShape(x,y,z);
h=plot(shp);
You can access faces and vertices then like:
h.Vertices
h.Faces
It works the same way for trisurf:
tri=delaunay(x,y,z)
t=trisurf(tri,x,y,z)
To see which information is stored, you can use get(t).
For faces and vertices it is the same thing as before:
t.Vertices
t.Faces

Reading DICOM-RT files to create 3D binary matrix?

I'm currently working with DICOM-RT files (which contain DICOM along with dose delivery data and structure set files). I'm mainly interested in the "structure set" file (i.e. RTSS.dcm), which contains the set of contour points for an ROI of interest. In particular, the contour points surround a tumor volume. For instance, a tumor would have a set of 5 contours, each contour being a set of points that encircle that slice of the tumor.
I'm trying to use MatLab to use these contour points to construct a tumor volume in a binary 3D matrix (0 = nontumor, 1=tumor), and need help.
One possible approach is to fill each contour set as a binary slice, then interpolate the volume between slices. So far I've used the fill or patch function to create binary cross-sections of each contour slice, but I'm having difficulty figuring out how to interpolate these binary slices into a 3D volume. None of the built-in functions appear to apply to this particular problem (although maybe I'm just using them wrong?). A simple linear interpolation doesn't seem appropriate either, since the edges of one contour should blend into the adjacent contour in all directions.
Another option would be to take the points and tesselate them (without making slices first). However, I don't know how to make MatLab only tesselate the surface of the tumor and not intersecting the tumor volume. Currently it seems to find triangles within the tumor. If I could get it into just a surface, I'm not sure how to take that and convert it into a binary 3D matrix volume either.
Does anyone have experience with either 3D slice interpolation OR tesselation techniques that might apply here? Or perhaps any relevant toolkits that exist? I'm stuck... :(
I'm open to approaches in other languages as well: I'm somewhat familiar with C# and Python, although I assumed MatLab would handle the matrix operations a little easier.
Thanks in advance!
I'm not sure from what program you're exporting your dicom-rt structure files, but I believe I found a more elegant solution for you, already described in an open-source software (GDCM, CMake, ITK) in an Insight journal article.
I was discussing a similar problem with one of our physicists, and we saw your solution. It's fine if whatever structure you're attempting to binarize has no concavities, but if so, they'll be rendered inaccurately.
This method is verified for dicom-rt structure sets from Eclipse and Masterplan. Hope it helps.
http://www.midasjournal.org/download/viewpdf/701/4
I think I found an answer in another post (here). Rather than trying to interpolate the "missing slices" between the defined contours, treating the contour points as a point cloud and finding the convex hull might be a more efficient way of doing it. This method created the binary 3D volume that I was after.
Here is the code I used, hope it might be helpful to those who need to work with DICOM-RT files:
function mask = DicomRT2BinaryVol(file)
points = abs(getContourPoints(file));
%%NOTE: The getContourPoints function simply reads the file using
%%'dicominfo' method and organizes the contour points into an n-by-3
%%matrix, each column being the X,Y,Z coordinates.
DT = DelaunayTri(points);
[X,Y,Z] = meshgrid(1:50,1:50,1:50);
simplexIndex = pointLocation(DT, X(:), Y(:), Z(:));
mask = ~isnan(simplexIndex);
mask = reshape(mask,size(X));
end
This method is a slightly modified version of the method posted by #gnovice in the link above.
iTk is an excellent library for this sort of thing: http://www.itk.org/
HTH

Mesh Generation in MATLAB

Is there any subroutine, in MATLAB, that takes in a list of points, and return me a good mesh that I can use to show to my colleagues, such as this?
Actually, all I need is just a simple 2D mesh generator that takes in a series of X, Y coordinates (that defines the boundary of the area), and give me back a list of elements that can mesh that area well. I can do the rest by using MATLAB command to interpolate the Z value.
Edit : I am not interested to use MATLAB to produce the above looking plot. I am interested in using a MATLAB library to obtain a list of elements so that when I plot those element myself (not in MATLAB itself; but in my own C# program), I can obtain this meshed surface.
PS: I know there is this DistMesh, but I am looking for something simpler - something built-in direct in MATLAB perhaps. And no, meshgrid is not mesh generation.
It sounds like you want to create a finite element mesh, starting with a set of points defining a boundary of a region and then generating a triangular mesh that creates more points within that region. I don't think there's a "simple" solution for this problem.
The closest "built-in" solution would probably be the Partial Differential Equation Toolbox, specifically some of the Geometry Algorithms like INITMESH and REFINEMESH.
The link you gave to DistMesh appears to be another good solution. There are also a few submissions on the MathWorks File Exchange that you could take a look at:
MESH2D by Darren Engwirda
Finite Element Toolbox 2.1 by Rasmus Anthin
That picture looks exactly like the one from the griddata documentation. The example in there looks like what you want.
SFTOOL will easily make the picture that you show.
A thin-plate spline, e.g., TPAPS, should also do the job.
I think the user-created 'gridfit' is the best I've come across for a single surface, much better/prettier than griddata.
Mesh generation as in Delaunay Triangulation + Steiner Points? There is a builtin Delaunay function in MATLAB.
If your surface is the z=f(x,y) form you can use:
http://www.advancedmcode.org/how-to-plot-a-coloured-surface-from-3d-scatter.html
If your surface is concave look for surface reconstruction on the same website.