Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing arrays in C++ CT reconstruction algorithm
    text
    copied!<p>I'm developing a CT reconstruction algorithm using C++. I'm using C++ because I need to use a library written in C++ that will let me read/write a specific file format. </p> <p>This reconstruction algorithm involves working with 3D and 2D images. I've written similar algorithms in C and MATLAB using arrays. However, I've read that, in C++, arrays are "evil" (see <a href="http://www.parashift.com/c++-faq-lite/containers.html" rel="nofollow">http://www.parashift.com/c++-faq-lite/containers.html</a>). The way I use arrays to manipulate images (in C) is the following (this creates a 3D array that will be used as a 3D image):</p> <pre><code>int i,j; int *** image; /* another way to make a 5x12x27 array */ image = (int ***) malloc(depth * sizeof(int **)); for (i = 0; i &lt; depth; ++i) { image[i] = (int **) malloc(height * sizeof(int *)); for (j = 0; j &lt; height; ++j) { image[i][j] = (int *) malloc(width * sizeof(int)); } } </code></pre> <p>or I use 1-dimensional arrays and do index arithmetic to simulate 3D data. At the end, I free the necessary memory. I have read that there are equivalent ways of doing this in C++. I've seen that I could create my own matrix class that uses vectors of vectors (from STL) or that I could use the boost-matrix library. The problem is that this makes my code look bloated.</p> <p>My questions are:</p> <p>1) Is there a reason to not use arrays for this purpose? Why should I use the more complicated data structures?</p> <p>2) I don't think I'll use the advantages of containers (as seen in the C++ FAQ lite link I posted). Is there something I'm not seeing? </p> <p>3) The C++ FAQ lite mentions that arrays will make me less productive. I don't really see how that applies to my case. What do you guys think?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload