<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/290458</link>
    <title>MATLAB Central Newsreader - Cell array creation for Voronoi cells in C++</title>
    <description>Feed for thread: Cell array creation for Voronoi cells in C++</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.co.uk/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 29 Aug 2010 20:35:04 +0000</pubDate>
      <title>Cell array creation for Voronoi cells in C++</title>
      <link>http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/290458#775365</link>
      <author>Anthony Lamb</author>
      <description>Hi All,&lt;br&gt;
&lt;br&gt;
I'm preparing an interface to a C++ Voronoi library and I've gotten to the point where I have the vertices for each cell. Since I have a varying number of vertices for each Voronoi cell I've opted for the Cell array structure to store the data.&lt;br&gt;
So here is where I am...for each Voronoi cell I have the coordinates stored in Vpts which is initialized using the following lines:&lt;br&gt;
&lt;br&gt;
		Vpts = new double *[nVert];&lt;br&gt;
		for(i=0; i&amp;lt; nVert  ; i++) {Vpts[i] = new double [2];}&lt;br&gt;
&lt;br&gt;
where nVert is the number of vertices for each Voronoi Cell. I fill Vpts with the coordinates of each vertex with the following lines:&lt;br&gt;
&lt;br&gt;
		for (vPt=0;vPt&amp;lt;nVert;vPt++){&lt;br&gt;
			Vpts[vPt][1]= x;&lt;br&gt;
			Vpts[vPt][2]=y;   }&lt;br&gt;
&lt;br&gt;
My question here is how do I create and store these values into a Cell structure to send back to Matlab. The syntax I used for my Matlab function is:&lt;br&gt;
&lt;br&gt;
[vIndex nID] = nodes;&lt;br&gt;
&lt;br&gt;
I need vIndex in the form of a Matlab cell array, where vIndex{i}(n,2) represents the coordinates of the n vertices for the Voronoi cell i.&lt;br&gt;
&lt;br&gt;
Any help you can offer will be greatly appreciated.&lt;br&gt;
&lt;br&gt;
Many thanks in advance,&lt;br&gt;
&lt;br&gt;
Tony</description>
    </item>
    <item>
      <pubDate>Mon, 30 Aug 2010 02:26:03 +0000</pubDate>
      <title>Re: Cell array creation for Voronoi cells in C++</title>
      <link>http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/290458#775418</link>
      <author>James Tursa</author>
      <description>"Anthony Lamb" &amp;lt;alamb@mathworks.com&amp;gt; wrote in message &amp;lt;i5eg9o$k49$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi All,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm preparing an interface to a C++ Voronoi library and I've gotten to the point where I have the vertices for each cell. Since I have a varying number of vertices for each Voronoi cell I've opted for the Cell array structure to store the data.&lt;br&gt;
&amp;gt; So here is where I am...for each Voronoi cell I have the coordinates stored in Vpts which is initialized using the following lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 		Vpts = new double *[nVert];&lt;br&gt;
&amp;gt; 		for(i=0; i&amp;lt; nVert  ; i++) {Vpts[i] = new double [2];}&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; where nVert is the number of vertices for each Voronoi Cell. I fill Vpts with the coordinates of each vertex with the following lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 		for (vPt=0;vPt&amp;lt;nVert;vPt++){&lt;br&gt;
&amp;gt; 			Vpts[vPt][1]= x;&lt;br&gt;
&amp;gt; 			Vpts[vPt][2]=y;   }&lt;br&gt;
&lt;br&gt;
Error. Your indexing above should be 0 and 1, not 1 and 2.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My question here is how do I create and store these values into a Cell structure to send back to Matlab. The syntax I used for my Matlab function is:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [vIndex nID] = nodes;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need vIndex in the form of a Matlab cell array, where vIndex{i}(n,2) represents the coordinates of the n vertices for the Voronoi cell i.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any help you can offer will be greatly appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Many thanks in advance,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Tony&lt;br&gt;
&lt;br&gt;
Here is an outline code to get you started. Call it with no arguments and it will return a cell array that I think matches your requested format.&lt;br&gt;
&lt;br&gt;
#include "mex.h"&lt;br&gt;
#define NVERT 10&lt;br&gt;
#define NCELL 5&lt;br&gt;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])&lt;br&gt;
{&lt;br&gt;
	int j = 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int vPt, nVert = NVERT;&lt;br&gt;
	double Vpts[NVERT][2];&lt;br&gt;
	double *pr;&lt;br&gt;
	mxArray *mx;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for( vPt=0; vPt&amp;lt;nVert; vPt++ ){  // fill some sample data&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vpts[vPt][0] = j++;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vpts[vPt][1] = j++; &lt;br&gt;
	}&lt;br&gt;
	plhs[0] = mxCreateCellMatrix(NCELL, 1);  // create return cell array&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for( j=0; j&amp;lt;NCELL; j++ ){&lt;br&gt;
		mx = mxCreateDoubleMatrix(nVert, 2, mxREAL);&lt;br&gt;
		pr = mxGetPr(mx);&lt;br&gt;
		for( vPt=0; vPt&amp;lt;nVert; vPt++ ) { // fill in return cell&lt;br&gt;
			*pr++ = Vpts[vPt][0];&lt;br&gt;
		}&lt;br&gt;
		for( vPt=0; vPt&amp;lt;nVert; vPt++ ) { // fill in return cell&lt;br&gt;
			*pr++ = Vpts[vPt][1];&lt;br&gt;
		}&lt;br&gt;
		mxSetCell(plhs[0], j, mx); // attach it to cell array&lt;br&gt;
	}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Mon, 30 Aug 2010 14:41:06 +0000</pubDate>
      <title>Re: Cell array creation for Voronoi cells in C++</title>
      <link>http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/290458#775571</link>
      <author>Anthony Lamb</author>
      <description>Thanks James!!! &lt;br&gt;
&lt;br&gt;
It worked like a charm...&lt;br&gt;
I opted for the following format to store the vertex nodes &lt;br&gt;
*pr++ = x+0.5*vCell.pts[2*k];&lt;br&gt;
*pr++ = y+0.5*vCell.pts[2*k+1];&lt;br&gt;
which saved me the additional "for loop" but gives the vIndex in the form [2,nPts].&lt;br&gt;
I've sent you a separate email on another stumbling point in my code...&lt;br&gt;
&lt;br&gt;
Best wishes,&lt;br&gt;
Tony</description>
    </item>
  </channel>
</rss>
