LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help writing to a TD2 struct

Hello everyone.
 
I´m kinda new to the world of LabView.
I´m using a LabView program to create a 3d classification model. The main program is written in Visual C++ (native)
I got this struct
 

typedef

struct {

long dimSizes[3];

unsigned char Numeric[1];

} TD2;

typedef

TD2 **TD2Hdl;

A classification model created by using

static

BOOL bCreateClassification3DModel()

{

hClassification3DModel_g = (TD2**)DSNewHandle(

sizeof(TD2) + (sizeof(BYTE) * ((lSizeA_g * lSizeB_g * lSizeC_g) - 1)));

if (hClassification3DModel_g == NULL)

      return FALSE;

(*hClassification3DModel_g)->dimSizes[0] = lSizeA_g;

(*hClassification3DModel_g)->dimSizes[1] = lSizeB_g;

(*hClassification3DModel_g)->dimSizes[2] = lSizeB_g;

return TRUE;

}

 

Now i want to write to the model. How do I set values into this model?
Is (*hClassification3DModel_g)->Numeric = 4; the rigth way to go?

0 Kudos
Message 1 of 9
(4,086 Views)
Anyone?
0 Kudos
Message 2 of 9
(4,062 Views)


Kresh wrote:
Hello everyone.
 
I´m kinda new to the world of LabView.
I´m using a LabView program to create a 3d classification model. The main program is written in Visual C++ (native)
I got this struct
 

typedef

struct {

long dimSizes[3];

unsigned char Numeric[1];

} TD2;

typedef

TD2 **TD2Hdl;

A classification model created by using

static

BOOL bCreateClassification3DModel()

{

hClassification3DModel_g = (TD2**)DSNewHandle(

sizeof(TD2) + (sizeof(BYTE) * ((lSizeA_g * lSizeB_g * lSizeC_g) - 1)));

if (hClassification3DModel_g == NULL)

      return FALSE;

(*hClassification3DModel_g)->dimSizes[0] = lSizeA_g;

(*hClassification3DModel_g)->dimSizes[1] = lSizeB_g;

(*hClassification3DModel_g)->dimSizes[2] = lSizeB_g;

return TRUE;

}

 

Now i want to write to the model. How do I set values into this model?
Is (*hClassification3DModel_g)->Numeric = 4; the rigth way to go?



Ouch, 3D arrays! And now what you suggest is ABSOLUTELY bad.
 
(*hClassification3DModel_g)->Numeric is the pointer to the data area and not a number in itself. This tells me that your understanding of C and pointers is at best unsufficient.
 
You will have to do something along the lines of
 
a, b, c  are the variables that define the current indices into the 3D array ranging between 0 and lSizeA_g -1 , lSizeB_g - 1 , lSizeC_g - 1 respectively.
 
(*hClassification3DModel_g)->Numeric[a + lSizeA_g * b + (lSizeA_g + lSizeB_g) * c] = whatever;
 
Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 9
(4,052 Views)

Thanks.

I´m new at this company and I´ve got this project from the guy developing before me. So I´m stuck since its already in production, but lets see if we can get some changes into the code.

0 Kudos
Message 4 of 9
(4,049 Views)
So if I want to iterate over the entire structure. Is this somewhat the right way to do it.

for

(k = 0; k < lSizeC_g; k++){
  
for (i = 0; i < lSizeA_g; i++){
    
for (j = 0; j < lSizeB_g; j++) {
         
(*hClassification3DModel_g)->Numeric[i + lSizeA_g * j + (lSizeA_g + lSizeB_g) * k] = 4;
   
}}}

 

0 Kudos
Message 5 of 9
(4,046 Views)


Kresh wrote:
So if I want to iterate over the entire structure. Is this somewhat the right way to do it.

for

(k = 0; k < lSizeC_g; k++){
  
for (i = 0; i < lSizeA_g; i++){
    
for (j = 0; j < lSizeB_g; j++) {
         
(*hClassification3DModel_g)->Numeric[i + lSizeA_g * j + (lSizeA_g + lSizeB_g) * k] = 4;
   
}}}

Would seem quite right to me. Could be optimized with pointer auto increment depending on the dimension order you have. Also there is always a good chance that you have to fiddle with the order of the dimensions anyhow (what size of the three sizes does correspond with i, j, k, and how you want them in LabVIEW. But that is something I never can wrap my head around and always end up with trieal and error.
 
Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 9
(4,040 Views)

hmmm shouldnt it be

(*hClassification3DModel_g)->Numeric[i + lSizeA_g * j + (lSizeA_g + lSizeB_g) * k] = 4;

changed to

(*hClassification3DModel_g)->Numeric[j + (lSizeA_g * i) + ((lSizeA_g * lSizeB_g) * k)] = 4;

And due to the numeric beeing a unsigned char, do I need to typecast the values?
I´m doing a learning by burning but all help whould be awsome.

0 Kudos
Message 7 of 9
(4,037 Views)


Kresh wrote:

hmmm shouldnt it be

(*hClassification3DModel_g)->Numeric[i + lSizeA_g * j + (lSizeA_g + lSizeB_g) * k] = 4;

changed to

(*hClassification3DModel_g)->Numeric[j + (lSizeA_g * i) + ((lSizeA_g * lSizeB_g) * k)] = 4;

And due to the numeric beeing a unsigned char, do I need to typecast the values?
I´m doing a learning by burning but all help whould be awsome.



Sorry, missed the multiplication sign and you are rright there. As to the order of the integers in relation to the sizes, no!
 
i is the integer that belongs to lSizeA_g and so on. Assuming lSizeA_g is the first dimension there is no multiplication necessary with any size. The seconnd dimension would be lSizeB_g and its integer is j, so it must be multiplicated by lSizeA_g to jump over the 1 dimension and so on. If that is the right assumption about what is 1st dimension and so on you will have to find out by experimenting.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 9
(4,034 Views)

ok, it seems to work.
The reason I asked about the i, j, k was cuz I´ve got this line that reads from the struct

data = pMtrxA + ((

sizeof(unsigned char) * lSizeA_g * lSizeB_g *  k) + (i * sizeof(unsigned char) * lSizeB_g) + (sizeof(unsigned char) *j));

So I thought I´d map the i,j,k to resp. lSize in my writing to the struct.

Thanks for all the help with this.
I cant in all the world figure out why the guy choose to do 3d-modeling in LabView. But I just have to put up a smile and work with what i got.

0 Kudos
Message 9 of 9
(4,027 Views)