LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

3d graph

I have looked at all the examples and the CVI sample.

 

My code:

 

int main (int argc, char *argv[])
{
CAObjHandle plotsHandle = 0;

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "User Interface Application.uir", PANEL)) < 0)
return -1;

//Get Handle of Graph and first Plot from the ActiveX control
GetObjHandleFromActiveXCtrl (panelHandle, PANEL_CWGRAPH3D, &graphHandle);
CW3DGraphLib__DCWGraph3DGetPlots (graphHandle, NULL, &plotsHandle);
CW3DGraphLib_CWPlots3DItem (plotsHandle, NULL, CA_VariantInt(1),&plotHandle);

 

DisplayPanel (panelHandle);
RunUserInterface ();
CA_DiscardObjHandle (plotsHandle);
DiscardPanel (panelHandle);

}

 

int CVICALLBACK Start(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{

....

 

CA_VariantSetEmpty(&x);
CA_VariantSetEmpty(&y);
CA_VariantSetEmpty(&z);

 

CA_VariantSet1DArray (&x, CAVT_INT, DIM, distrib_init_x);
CA_VariantSet1DArray (&y, CAVT_INT, DIM, distrib_init_y);
CA_VariantSet1DArray (&z, CAVT_INT, DIM, distrib_init_z);

 

CW3DGraphLib_CWPlot3DPlot3DSurface(graphHandle,NULL,x,y,z,CA_DEFAULT_VAL);

 

........

 

Nothing shows in the graph. Eventually I need a multi plot but I would be happy with a single plot for now.

x,y,z are integer arrays of dimension (DIM) 250.

 

Thank you.

0 Kudos
Message 1 of 7
(3,719 Views)

I notice a couple things here that may help.

 

1. The z parameter of CW3DGraphLib_CWPlot3DPlot3DSurface needs to be a 2D array, not a 1D array. Use CA_VariantSet2DArray instead of CA_VariantSet1DArray. 

 

2. CW3DGraphLib_CWPlot3DPlot3DSurface should take plotHandle instead of graphHandle for the first parameter.

National Instruments
0 Kudos
Message 2 of 7
(3,698 Views)

Thank you.

 

I tried 2., its just that I am trying everything so forgot to change it back.

 

Concerning 1., I noticed it in the examples but I do not understand what it means. I have particle distributions in three axes, so a 3D view is basically a representation of a particle cloud. I do not understand how I can create a 2D array out of the z-axis data when its a 1D array.

0 Kudos
Message 3 of 7
(3,690 Views)

This can be a bit confusing and the reason the function is requiring a matrix for z this is a surface plot. Essentially, the xVector and the yVector are not really plotting data values, but instead they are specifying what coordinates in the x-y plane to plot. The zMatrix then assigns a z value to each of those coordinates.

 

This matrix here may help explain (the values here are arbitrary).

 

If you had a matrix like this, then you could actually just use the Plot3DSimpleSurface function which does not require a xVector or yVector since those are in linear order. But with the Plot3DSurface function, the values of your xVector and yVector do not need to be in a linear order and this allows you to plot surfaces like spheres or a torus.

 

If you are trying to plot a cloud of 3D points, then you may want to used the Plot3DMesh instead. This allows you to specify 3 vectors instead of 2 vectors and a matrix. The vectors will correspond to the coordinates of your data points and can actually be entered in any order. The Plot3DMesh function will find the simplest surface to cover the points.

 

National Instruments
Message 4 of 7
(3,669 Views)

Thank you for the answer. I have not found this explanation anywhere on the internet.

 

I have tried with:

 

GetObjHandleFromActiveXCtrl (panelHandle, PANEL_CWGRAPH3D, &graphHandle);
CW3DGraphLib__DCWGraph3DGetPlots (graphHandle, NULL, &plotsHandle);

CW3DGraphLib_CWPlots3DItem (plotsHandle, NULL, CA_VariantInt(1),&plotHandle);

 

.....

 

CA_VariantSetEmpty(&x);
CA_VariantSetEmpty(&y);
CA_VariantSetEmpty(&z);

 

CA_VariantSet1DArray (&x, CAVT_INT, DIMx, distrib_x);
CA_VariantSet1DArray (&y, CAVT_INT, DIMy, distrib_y);
CA_VariantSet1DArray (&z, CAVT_INT, DIMz, distrib_z);

 

CW3DGraphLib__DCWGraph3DPlot3DMesh (plotHandle, NULL, x, y, z, CA_DEFAULT_VAL);

 

-----

 

Does not work.

0 Kudos
Message 5 of 7
(3,661 Views)

I did not pay close enough attention to your original code. There are actually 2 Plot3DMesh functions: CW3DGraphLib__DCWGraph3DPlot3DMesh and CW3DGraphLib_CWPlot3DPlot3DMesh.

 

If you are using the DCWGraph3DPlot3DMesh function, then you will need to pass it the graphHandle. In that case you will also not need to gather the plots or plotHandle because the DCWGraph3DPlot3DMesh function will automatically use the first plot available. 

 

Alternatively, as I originally though you were doing, you can get the plot using the CW3DGraphLib__DCWGraph3DGetPlots and CW3DGraphLib_CWPlots3DItem functions, then pass the plotHandle the the CW3DGraphLib_CWPlot3DPlot3DMesh function to draw on that specific plot. 

 

National Instruments
0 Kudos
Message 6 of 7
(3,652 Views)

Thank you

0 Kudos
Message 7 of 7
(3,626 Views)