Problems with mesh in mmclab

215 views
Skip to first unread message

Valeriya Perekatova

unread,
Apr 29, 2016, 12:42:14 PM4/29/16
to iso2mesh-users
Dear Dr. Fang,

I am sorry, I am new to iso2mesh and mmc.

Having faced some problems with surfboolean, I followed your advise to use surf2vol() to convert each component of three surfaces into a volumetric image. Then I combined these volumetric masks into a multi-label volume. After this I called v2m to produce a mesh. Here is the code of mesh generation of 2 cylinders in the medium:
 
[latnode,latface,c0]=latticegrid([0,10],[0,10],[0,10]);
[node1,elem1,face1]=surf2mesh(latnode,latface,[],[],1,0.1,c0);

[node2,face2,elem2]=meshacylinder([0 2 5],[10,2,5],1,0.1,1);
[node4,face4,elem4]=meshacylinder([0 7 5],[10,7,5],1,0.1,1);

[node3,elem3]=mergemesh(node1,elem1,node2,elem2,node4,elem4);

img1=surf2vol(node1,face1,-11:0.1:11,-11:0.1:11,-11:0.1:11);
img2=surf2vol(node2,face2,-11:0.1:11,-11:0.1:11,-11:0.1:11);
img3=surf2vol(node4,face4,-11:0.1:11,-11:0.1:11,-11:0.1:11);
im1=imfill(img1,'holes');
im2=imfill(img2,'holes');
im3=imfill(img3,'holes');

im1=uint8(im1);
im2=uint8(im2);
im3=uint8(im3);
im2(im2==1)=2;
im3(im3==1)=3;
im=im1+im2+im3;

[node,elem]=v2m(im,[],8,50,'cgalmesh');

The resulted picture of plotmesh(node(:,1:3),elem) is attached. And it looks absolutelly perfect.

The problem arises when I try to use these 'node' and 'elem' in mmclab. I print the following parameters for mmclab:


cfg.node=node;

cfg.elemprop=elem(:,5);
cfg.elem=elem(:,1:4);

cfg.nphoton=1e7;
cfg.seed=1648335518;
cfg.srctype='pencil';
cfg.srcpos=[5.,5.,0];
cfg.srcdir=[0 0 1];

cfg.tstart=0;
cfg.tend=5e-9;
cfg.tstep=1e-10;
cfg.prop=[0 0 1 1;...
        0.001 10.0 0.01 1.0;...
        1.5 60 0.98 1.37;...
        1.5 60 0.98 1.37];
cfg.debuglevel='TP';
cfg.isreflect=0;


flux=mmclab(cfg);

But I found this error:

Error using horzcat
Dimensions of matrices being concatenated are not consistent.

Error in elemvolume (line 27)
e1=det([node(elem(i,:),2),node(elem(i,:),3),acol]);

Error in meshreorient (line 22)
vol=elemvolume(node,elem,'signed');

Error in mmclab (line 174)
        cfg(i).elem=meshreorient(cfg(i).node,cfg(i).elem(:,1:4));


Is it because the dimentions of 'node' is N*4, but for mmclab 'node' is needed to be N*3? Or am I wrong in coding?

Could you please tell me if I am wrong and how I may fix my error?

Thank you very much.

Valeriya.




mesh of 2 cylinders in the medium.png

Qianqian Fang

unread,
Apr 29, 2016, 1:14:43 PM4/29/16
to iso2mes...@googlegroups.com
On 4/29/2016 10:16 AM, Valeriya Perekatova wrote:
Dear Dr. Fang,

I am sorry, I am new to iso2mesh and mmc.

Having faced some problems with surfboolean, I followed your advise to use surf2vol() to convert each component of three surfaces into a volumetric image. Then I combined these volumetric masks into a multi-label volume. After this I called v2m to produce a mesh. Here is the code of mesh generation of 2 cylinders in the medium:
 ...

Is it because the dimentions of 'node' is N*4, but for mmclab 'node' is needed to be N*3? Or am I wrong in coding?

yes, you are correct. iso2mesh v2m('cgalmesh') outputs an additional
label column to the node coordinates. If you pass it to mmclab,
you need to remove the 4th column, i.e.

cfg.node=node(:,1:3);

give it a try and see if you can get through.

Qianqian

Could you please tell me if I am wrong and how I may fix my error?

Thank you very much.

Valeriya.




--
You received this message because you are subscribed to the Google Groups "iso2mesh-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iso2mesh-user...@googlegroups.com.
To post to this group, send email to iso2mes...@googlegroups.com.
Visit this group at https://groups.google.com/group/iso2mesh-users.
For more options, visit https://groups.google.com/d/optout.

Valeriya Perekatova

unread,
May 1, 2016, 12:49:26 PM5/1/16
to iso2mesh-users
Dear Qianqian,
Thank you for your help. Your advise was really helpful.
But I have one more quetion. Could you please tell me how to define source position in grid points obtained for node and elem after v2s? I could not choose appropriate coordinates when I want to place an isotropic source in the middle of upper side. As I understood I should determine the initial sourse position. For this purpose I should choose coordinates of 'node' in place what I want to stand a source. But everytime a matlab displays an error.

And could you please tell me if it is possible to stand focused optical illumination in your program?

Слава Пугавко

unread,
May 8, 2016, 10:45:59 AM5/8/16
to iso2mesh-users
Diar Dr. Fang.
I subscribe to the issue. Is it possible to create a source type as the drawing?
How to set the real sizes. Centimetre, millimetre ...
sorry for my English.
Thank you very much.


Mechislav.
2.jpg
1.jpg

Qianqian Fang

unread,
May 8, 2016, 11:08:30 AM5/8/16
to iso2mes...@googlegroups.com, mmc-...@googlegroups.com
On 05/08/2016 06:14 AM, Слава Пугавко wrote:
Diar Dr. Fang.

hi Mechislav

Since this is a mmc-specific problem, I am CCing this email to mmc-users
mailing list. Please send your replies to mmc-users as well.


I subscribe to the issue. Is it possible to create a source type as the drawing?

can you explain this drawing a little bit more? are you trying
to simulate two diverging beam profiles?


How to set the real sizes. Centimetre, millimetre ...

by default, mmc/mmclab assumes millimeter as all the length
unit (mesh node coordinates, absorption/scattering coeff, src/det coordinates).
if your physical unit is not in mm, you need to use cfg.unitinmm (in mcxlab)
or -u or --unitinmm (in command line) to set your length unit. For example,
if your node coordinates are in centermeters, you should set cfg.unitinmm=10;

let me know if this answers your questions.

Qianqian

sorry for my English.
Thank you very much.


Mechislav.

Qianqian Fang

unread,
May 8, 2016, 11:39:04 AM5/8/16
to iso2mes...@googlegroups.com, mmc-...@googlegroups.com
On 05/01/2016 12:49 PM, Valeriya Perekatova wrote:
> Dear Qianqian,
> Thank you for your help. Your advise was really helpful.
> But I have one more quetion. Could you please tell me how to define source position in grid points obtained for node and elem after v2s? I could not choose appropriate coordinates when I want to place an isotropic source in the middle of upper side. As I understood I should determine the initial sourse position. For this purpose I should choose coordinates of 'node' in place what I want to stand a source. But everytime a matlab displays an error.

not exactly sure I understood your question. are you saying you want to add
an isotropic source to the middle of the top face of the mesh?

if so, simply define cfg.srcpos to its physical coordinates (assuming your
mesh coordinates are also defined in the physical coordinates, otherwise
rescale with cfg.unitinmm), and undefine cfg.e0 (by calling
cfg=rmfield(cfg,'e0');)
mmclab will automatically recalculate the enclosing element index.

https://github.com/fangq/mmc/blob/master/mmc/trunk/mmclab/mmclab.m#L39-L46

if you were actually trying to approximate a pencil beam using an isotropic
for an scattering medium, please be aware that you should sink your
isotropic
src z coordinate by 1 transport mean free path l_tr=1/(mus' + mua) ~=
1/mus'.

if you meant to simulate an isotropic source exactly on the surface of
the mesh, I still recommend you to sinking the source slightly, so that
it is emerged inside the mesh. This will make ray-tracing less complicated,
otherwise, mmclab will have to retessellate the mesh to incorporate an
widefield source. Please see our latest paper for details

https://www.osapublishing.org/boe/abstract.cfm?uri=boe-7-1-171

> And could you please tell me if it is possible to stand focused optical illumination in your program?
let me know if I understood the question correctly.

Qianqian


PS: I also forward this message to the mmc-users mailing list because I
think your question is more relevant to that list.

Слава Пугавко

unread,
May 8, 2016, 2:38:45 PM5/8/16
to iso2mesh-users, mmc-...@googlegroups.com

Dear Dr Fang,
My task is to define the light distribution as the focused light beams oriented in angle of 37 degrees to the axis, as we can see in the picture.
In this configuration initial light source should be a ring at the surface.
This type of illumination correspondes to our measuring system. So this task is of great importance for me.
I will be really thankful to you if you help me.

Yours sincerely,
Mechislav

воскресенье, 8 мая 2016 г., 18:39:04 UTC+3 пользователь q.fang написал:

Valeriya Perekatova

unread,
May 8, 2016, 2:39:53 PM5/8/16
to iso2mesh-users
Dear Qianqian,
You are right. First of all I wanted to add an isotropic source to the middle of the top face of the mesh. But I had some problems with node coordinates. But now with "rmfield" it is not a problem already. Thank you very much. And I will try to sink the source a little bit in the tissue.
In my simulations I am trying to add the source as number of pencils oriented with an angle to the z axis. In this situation it correspondes to a ring of light at the top face of the mesh. So if you give me advice how to rotate the pencil illumination , I will be really glad.
Yours sincerely,
Lera.

Qianqian Fang

unread,
May 8, 2016, 5:36:32 PM5/8/16
to iso2mes...@googlegroups.com, mmc-...@googlegroups.com
On 05/08/2016 02:39 PM, Valeriya Perekatova wrote:
> Dear Qianqian,
> You are right. First of all I wanted to add an isotropic source to the middle of the top face of the mesh. But I had some problems with node coordinates. But now with "rmfield" it is not a problem already. Thank you very much. And I will try to sink the source a little bit in the tissue.

great

> In my simulations I am trying to add the source as number of pencils oriented with an angle to the z axis. In this situation it correspondes to a ring of light at the top face of the mesh.

is it actually a continuous uniform ring-shaped illumination? or a bunch
of pencil beams aligned in a ring-shape (non continuous)?

> So if you give me advice how to rotate the pencil illumination , I will be really glad.

can you explain what do you mean by rotate? rotate along with
what axis?

Qianqian

> Yours sincerely,
> Lera.
>

Qianqian Fang

unread,
May 8, 2016, 5:55:35 PM5/8/16
to iso2mes...@googlegroups.com, mmc-...@googlegroups.com
On 05/08/2016 02:38 PM, Слава Пугавко wrote:

Dear Dr Fang,
My task is to define the light distribution as the focused light beams oriented in angle of 37 degrees to the axis, as we can see in the picture.
In this configuration initial light source should be a ring at the surface.

hi Mechislav

is it a donut-shaped beam? or a circular/disk shaped beam?

if you want to define a converting beam, you can do so by
defining the 4th element in cfg.srcdir, such as

cfg.srcdir = [vx, vy, vz, focus];

where the first 3 numbers denote a unitary direction vector,
and the last number, focus, defines the convergence/divergence
of the beam, as if the src aperture is a lens:

- when focus=0, the beam is collimated
- when focus<0, the beam is diverging, where |focus| equals to
  the focal length of the lens, the beam diverges from an imaginary
  src at aperture center - |focus|*[vx vy vz];
- when focus>0, the beam is converging, where |focus| equals
  to the focal length of the lens, and the beam converges at
  aperture center + |focus|*[vx vy vz];

this feature works for all area-aperture sources, such as gaussian,
disk, planar, fourier etc.

if you need multiple sources of such patterns, just run
multiple mmc sessions and sum the solutions weighted
according to their relative strengths.

Qianqian

--

Valeriya Perekatova

unread,
May 16, 2016, 7:28:07 AM5/16/16
to iso2mesh-users, mmc-...@googlegroups.com
Dear Qianqian,

In my simulations I want to add a bunch of pencil beams aligned in a ring-shape. But each pencil should have a determined aperture, oriented with an angle to the z axis and a light from this pencil should spread with a determined angle. 

Am I right, for this purpose I can use  source type "cone" for each beam in my illumination, run mmclab for each beam and then sum over all simulations? 

But I faced a problem on the first step: how to define srcparam for "cone" source? 
Firstly, I tried to set one cone source in the centre of top bound I type this one:

cfg.srctype='cone';
cfg.srcparam1=[alpha 0 0 0]; // where alpha is a half-angle of cone illumination
cfg.srcparam2=[0 0 0 0]; 
cfg.srcdir=[0 0 1];

srcdef=struct('srctype',cfg.srctype,'srcpos',cfg.srcpos,'srcdir',cfg.srcdir,...
              'srcparam1',cfg.srcparam1, 'srcparam2',cfg.srcparam2);

[cfg.node,cfg.elem] = mmcaddsrc(cfg.node,[cfg.elem cfg.elemprop],...
     mmcsrcdomain(srcdef,[min(cfg.node);max(cfg.node)]));

But when I try to run mmclab it doesn't work. What am I doing wrong?

Yours sincerely,
Lera.

понедельник, 9 мая 2016 г., 1:36:32 UTC+4 пользователь q.fang написал:
Reply all
Reply to author
Forward
0 new messages