Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Reusing C++ code for use with .NET (WPF) Pin
Arivanna17-Oct-10 9:12
Arivanna17-Oct-10 9:12 
GeneralRe: Reusing C++ code for use with .NET (WPF) Pin
Paul Michalik18-Oct-10 7:28
Paul Michalik18-Oct-10 7:28 
GeneralRe: Reusing C++ code for use with .NET (WPF) Pin
Iain Clarke, Warrior Programmer17-Oct-10 10:06
Iain Clarke, Warrior Programmer17-Oct-10 10:06 
QuestionStrange Windows Timer Behavior Pin
softwaremonkey16-Oct-10 5:47
softwaremonkey16-Oct-10 5:47 
AnswerRe: Strange Windows Timer Behavior Pin
Cedric Moonen16-Oct-10 6:05
Cedric Moonen16-Oct-10 6:05 
GeneralRe: Strange Windows Timer Behavior Pin
softwaremonkey16-Oct-10 6:52
softwaremonkey16-Oct-10 6:52 
GeneralRe: Strange Windows Timer Behavior Pin
SAMZC16-Oct-10 23:55
SAMZC16-Oct-10 23:55 
QuestionQuestion on how to traverse this array Pin
Keith Vitali16-Oct-10 5:08
Keith Vitali16-Oct-10 5:08 
Hello everyone,

I am unable to figure how to code the following in C++. It is quite simple when the dimensions of the input array is preset. However, I am at a loss on how to do this when that is not the case.

So, just to explain I have an array which represent values in a multidimensional histogram. For the sake of argument, let us assume that the histogram is 3 dimensional and the x-dimension is of size 10, y dimension is of size 20 and z-dimension is of size 30.

Now, what I want to do is traverse through the histogram along each of the axes. So I want to go through the whole histogram along the rows, columns and the normal axes. If I hard-code the dimensions of the histogram it is quite easy to do so:

// histogram has 6000 elements (30*20*10)
void traverse_histogram(float *histogram)
{
   int index;

   // First traverse along the x-axes
   for (int z = 0; z < 30; ++z)
   {
       for (int y = 0; y < 20; ++y)
       {
           for (int x = 0; x < 10; ++x)
           {
               // Current index along the x-direction
               index = z * 20 * 10 + y * 10 + x;
           }
       }
   }

   // Traverse along y-axes
   for (int z = 0; z < 30; ++z)
   {
       for (int x = 0; x < 10; ++x)
       {
           for (int y = 0; y < 20; ++y)
           {
               // Current index along the y-direction
               index = z * 20 * 10 + y * 10 + x;
           }
       }
   }

   // Traverse along z-axes
   for (int y = 0; y < 20; ++y)
   {
       for (int x = 0; x < 10; ++x)
       {
           for (int z = 0; z < 30; ++z)
           {
               // Current index along the z-direction
               index = z * 20 * 10 + y * 10 + x;
           }
       }
   }   
}


Now, what I have is a situation where the dimensions are not hard-coded (they also can be more than 3) and what I need to do is generalize this somehow, so that it works when the number of dimensions and the dimension size are also dynamic. However, I am really struggling to figure out how this might work.

So, the new function signature is as follows:
// histogram: This is an array which will now have size dimensions[0] * dimensions[1] *....dimensions[num_dims-1]
// num_dims: Integer saying the number of dimensions in my histogram
// dimensions: The array of histogram dimension.

// Ex: dimensions[0] = 10, dimensions[1] = 20, dimensions[2] = 30;
// num_dims = 3;
void traverse_histogram(float *histogram, int num_dims, int *dimensions)
{}


I would be really grateful if someone can help me figure out a good way to do this. I am really stumped.

Thanks,

Keith
AnswerRe: Question on how to traverse this array Pin
Graham Shanks16-Oct-10 7:57
Graham Shanks16-Oct-10 7:57 
GeneralRe: Question on how to traverse this array Pin
Keith Vitali16-Oct-10 8:57
Keith Vitali16-Oct-10 8:57 
GeneralRe: Question on how to traverse this array Pin
Keith Vitali16-Oct-10 10:39
Keith Vitali16-Oct-10 10:39 
GeneralRe: Question on how to traverse this array Pin
Graham Shanks16-Oct-10 10:43
Graham Shanks16-Oct-10 10:43 
GeneralRe: Question on how to traverse this array Pin
Keith Vitali16-Oct-10 11:29
Keith Vitali16-Oct-10 11:29 
AnswerRe: Question on how to traverse this array Pin
Aescleal16-Oct-10 22:31
Aescleal16-Oct-10 22:31 
Questionhow can I learn?? Pin
AmbiguousName16-Oct-10 1:32
AmbiguousName16-Oct-10 1:32 
AnswerRe: how can I learn?? Pin
Niklas L16-Oct-10 3:01
Niklas L16-Oct-10 3:01 
GeneralRe: how can I learn?? Pin
AmbiguousName16-Oct-10 10:37
AmbiguousName16-Oct-10 10:37 
QuestionRe: how can I learn?? Pin
David Crow16-Oct-10 4:37
David Crow16-Oct-10 4:37 
AnswerRe: how can I learn?? Pin
AmbiguousName16-Oct-10 8:26
AmbiguousName16-Oct-10 8:26 
AnswerRe: how can I learn?? Pin
Maximilien16-Oct-10 8:35
Maximilien16-Oct-10 8:35 
AnswerRe: how can I learn?? Pin
Aescleal16-Oct-10 22:21
Aescleal16-Oct-10 22:21 
QuestionCEdit::GetLine return blank value when LineLength is 1. Pin
Le@rner15-Oct-10 23:51
Le@rner15-Oct-10 23:51 
AnswerRe: CEdit::GetLine return blank value when LineLength is 1. Pin
Richard MacCutchan16-Oct-10 0:56
mveRichard MacCutchan16-Oct-10 0:56 
AnswerRe: CEdit::GetLine return blank value when LineLength is 1. Pin
David Crow16-Oct-10 4:40
David Crow16-Oct-10 4:40 
QuestionHow can create thread pool? Pin
Le@rner15-Oct-10 23:23
Le@rner15-Oct-10 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.