Nd cell array

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Nd cell array

Philipp.Batchelor
Hi,

sorry, trying to reformulate, I posted to help-octave, maybe it is more
for this list.

I am trying to read 3d volume data using another c++ library (vtk), and
load it into Octave, I thought I would return a cell array,
i.e. in an *.m file, the syntax would correspond to

for slice = 1:n
   volume{slice} = ...% some 2d array, say a Matrix
   ...etc

but I can't work out what the syntax in C++ would be.
How would I create an array with say 128 elements which are each a 2D
Matrix, and assign to elements, (and return this cell array) in a
dynamically loadable C++ file?

Ph. Batchelor


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

David Bateman-3
What about something like

#include <octave/oct.h>
#include <octave/Cell.h>

DEFUN_DLD (myvol, args, ,
  "-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{v} =} myvol (@var{n})\n\
\n\
Create @var{n} by 1 cell array of matrices\n\
@end deftypefn\n")

{
  octave_value retval;
  int n = args(0).nint_value ();
  Cell c (n,1);

  // Just fill with empty matrices for this test
  for (int i = 0; i <n; i++)
      c (i) = octave_value (Matrix (2, 2, 0));

  retval = c;
  return retval;
}


According to Philipp.Batchelor <[hidden email]> (on 03/04/04):

> Hi,
>
> sorry, trying to reformulate, I posted to help-octave, maybe it is more
> for this list.
>
> I am trying to read 3d volume data using another c++ library (vtk), and
> load it into Octave, I thought I would return a cell array,
> i.e. in an *.m file, the syntax would correspond to
>
> for slice = 1:n
>   volume{slice} = ...% some 2d array, say a Matrix
>   ...etc
>
> but I can't work out what the syntax in C++ would be.
> How would I create an array with say 128 elements which are each a 2D
> Matrix, and assign to elements, (and return this cell array) in a
> dynamically loadable C++ file?
>
> Ph. Batchelor

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

David Bateman-3
In reply to this post by Philipp.Batchelor
According to Philipp.Batchelor <[hidden email]> (on 03/04/04):
> Hi,
>
> sorry, trying to reformulate, I posted to help-octave, maybe it is more
> for this list.
>
> I am trying to read 3d volume data using another c++ library (vtk), and
> load it into Octave, I thought I would return a cell array,
> i.e. in an *.m file, the syntax would correspond to

Rereading your problem, why not just return a 3d arrays, which you can do
in versions of octave 2.1.51 and later..... Not, to completely rewrite
my previous example, but something like

   dim_vector dv; // Size of 3d array
   NDArray m;

   // Probe size of array
   dv.resize (3);
   dv(0) = ...; dv(1) = ...; dv(2) = ...;

   // Resize array
   m.resize (dv);

   for (int i=0; i < dv(0); i++)
     for (int j=0; j < dv(1); j++)
       for (int k=0; k < dv(2); k++)
         m (i, j, k) = ...;

   retval = m;

>
> for slice = 1:n
>   volume{slice} = ...% some 2d array, say a Matrix
>   ...etc
>
> but I can't work out what the syntax in C++ would be.
> How would I create an array with say 128 elements which are each a 2D
> Matrix, and assign to elements, (and return this cell array) in a
> dynamically loadable C++ file?
>
> Ph. Batchelor

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

David Bateman-3
According to David Bateman <[hidden email]> (on 03/04/04):
>    for (int i=0; i < dv(0); i++)
>      for (int j=0; j < dv(1); j++)
>        for (int k=0; k < dv(2); k++)
>          m (i, j, k) = ...;

of course that should read

    for (int i=0; i < dv.numel (); i++)
      m(i) = ...;

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

Philipp.Batchelor
David,
great, thanks a lot for the answers! it's exactly what I needed.
I didn't know that 3D arrays were available in the newest version, I'll
download and install asap then.



Maybe I can give a bit of background on what I'm trying to do.
vtk (Visualisation Toolkit) http://www.vtk.org is a quite popular
computer graphics C++ library, traditionally used with Tcl, Python, or
recently Java, wrapping. I came across instructions for using the Java
wrapping to load vtk classes into Matlab, (cf
http://www.cns.bu.edu/~speech/VTK.php) which sounded like the 'best of
both wolrds' for me. So the issue became, how does one load vtk into
Matlab, and as I just bought a laptop and put Redhat 9 on it, which came
with Octave, I the same question arises for Octave.

There are different possibilities:
1) Matlab can use a java virtual machine, hence can read any java class,
hence without too much effort (actually it wa a lot, but wel...), one
can load any vtk class into Matlab. As far as I can see, this solution
doesn't extend yet to Octave. There are problems with memory management.
2) The same person who created the java solution was unhappy with it, so
created a 'vtkmexifier' which I had adapted to Octave, but this is
limited to vtk pipelines I think.

3) Writing directly C++ code which links to vtk, and loads into Octave,
(this would be much harder in Matlab I suppose). I will try to write a
volume renderer as a test.

Thanks again
Ph


David Bateman wrote:

> According to David Bateman <[hidden email]> (on 03/04/04):
>
>>   for (int i=0; i < dv(0); i++)
>>     for (int j=0; j < dv(1); j++)
>>       for (int k=0; k < dv(2); k++)
>>         m (i, j, k) = ...;
>
>
> of course that should read
>
>     for (int i=0; i < dv.numel (); i++)
>       m(i) = ...;
>


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

Paul Kienzle

On Mar 5, 2004, at 11:31 AM, Philipp.Batchelor wrote:

> Maybe I can give a bit of background on what I'm trying to do.
> vtk (Visualisation Toolkit) http://www.vtk.org is a quite popular
> computer graphics C++ library, traditionally used with Tcl, Python, or
> recently Java, wrapping.

Have you investigate Dragan Tubic's vtk class bindings for Octave?

You can get it from http://octaviz.sourceforge.net.

Paul Kienzle
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Nd cell array

Philipp.Batchelor
Paul
I had looked around a bit, and read sth about vtk and octave, but hadn't
realised it was that advanced. In a sense it's lucky I got stuck that
early on the cell arrays, otherwise I wouldnt have realised all this. I
think it's exactly much better than what I was trying to do!

Cheers for the info
Ph

Paul Kienzle wrote:

>
> On Mar 5, 2004, at 11:31 AM, Philipp.Batchelor wrote:
>
>> Maybe I can give a bit of background on what I'm trying to do.
>> vtk (Visualisation Toolkit) http://www.vtk.org is a quite popular
>> computer graphics C++ library, traditionally used with Tcl, Python, or
>> recently Java, wrapping.
>
>
> Have you investigate Dragan Tubic's vtk class bindings for Octave?
>
> You can get it from http://octaviz.sourceforge.net.
>
> Paul Kienzle
> [hidden email]
>