LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Graphing Multiple 3D Graph Types with Spherical Data Points

I have data points that are in theta, phi and r (magnatude) that I would like to be able to 3D plot and change the text/contour to either wireframe or contoured or points on the fly.  I believe this is possible however, after looking at the NI examples, they are all done with xyz coordinates and have yet to see a 3D graph with spherical (NI, take this as a suggestion Smiley Happy).

 

Over a year ago, I was able to create data in spherical by giving it 3 1D arrays, but it only plotted it in the form of point or line.  The examples that have a torus use parametric plots?! although I am not entirely sure I understand how it works nor how to convert to it from spherical.

 

Attached is a sample input file/array.  Wanted to see if anyone had experience using the built in 3D libraries (CW 3D Graph

8.0) to achieve something similar.

 

Note: the Amplitude column is absolute and could be made positive for ease of use as well.

 

Thanks

0 Kudos
Message 1 of 9
(4,993 Views)

In addition, I am able to plot the "sample plot" while editing the settings in the control panel of the GUI when settings it to Spherical, shown below.  But I have no idea, nor had much luck trying to call the proper function or pass the correct variant to a function to be able to replicate the graph below.  I am also unclear what the difference of all the functions are such as ones starting with _DCW* or CW* or ending with _Cl

 

Clip1.jpg

0 Kudos
Message 2 of 9
(4,989 Views)

Can you not plot it with x=r*cos(theta), y=r*sin(theta), and z=r*cos(phi) values?

0 Kudos
Message 3 of 9
(4,973 Views)

I'm just trying the following in the main loop to get something to graph, and nothing is showing up but this error - 80020009

 

 

static int panelHandle;
static CAObjHandle  gGraph;

//==============================================================================
// Static functions

//==============================================================================
// Global variables

//==============================================================================
// Global functions

/// HIFN The main entry-point function.
int main (int argc, char *argv[])
{
    int error = 0;
	VARIANT	xVt, yVt, zVt;
	HRESULT	hr;
	int		i,j;
	char errCode[100];
    
	double  xData[50], yData[50], zData[50][50];
	
    /* initialize and load resources */
    nullChk (InitCVIRTE (0, argv, 0));
    errChk (panelHandle = LoadPanel (0, "3D Analysis.uir", PANEL));
    
    /* display the panel and run the user interface */
    errChk (DisplayPanel (panelHandle));
	
	CA_VariantSetEmpty(&xVt);
    CA_VariantSetEmpty(&yVt);
    CA_VariantSetEmpty(&zVt);
	
	for (i = 0; i < 50; i++) {
		xData[i] = yData[i] = i;
		for (j = 0; j < 50; j++) {
			zData[i][j] = i*j;	
		}
	}
	GetObjHandleFromActiveXCtrl(panelHandle, PANEL_CWGRAPH3D, &gGraph);
	errChk (CA_VariantSet1DArray(&xVt,CAVT_DOUBLE, 50, xData));
	errChk (CA_VariantSet1DArray(&yVt,CAVT_DOUBLE, 50, yData)); 
	errChk (CA_VariantSet2DArray(&xVt,CAVT_DOUBLE, 50,50,zData)); 
	errChk (CW3DGraphLib__DCWGraph3DPlot3DSurface(gGraph, NULL,xVt,yVt,zVt, CA_DEFAULT_VAL));
	//errChk (CW3DGraphLib_CWPlot3DPlot3DSurface (gGraph, NULL, xVt, yVt, zVt, CA_DEFAULT_VAL));
	
	
	
	
    errChk (RunUserInterface ());

Error:
    /* clean up */
	sprintf(errCode,"%X",error);
	MessagePopup("",errCode);
	CA_VariantSetEmpty(&xVt);
    CA_VariantSetEmpty(&yVt);
    CA_VariantSetEmpty(&zVt);
	CA_DiscardObjHandle(gGraph);
    DiscardPanel (panelHandle);
    return 0;
}

 

At this point, I am just trying to figure out which function to call and what to set the input Variants.  Seems somethings they are 1D and sometimes they are 2D.  Unfortunately the documentation is very slim and doesn't explain what the actual functions or variants represent.

 

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

I haven't looked into this very far yet, but I do notice something in your code at first glance.

 

 


...
VARIANT xVt, yVt, zVt;
HRESULT hr;
int i,j;
char errCode[100];

double xData[50], yData[50], zData[50][50];

...

CA_VariantSetEmpty(&xVt);
CA_VariantSetEmpty(&yVt);
CA_VariantSetEmpty(&zVt);

for (i = 0; i < 50; i++) {
xData[i] = yData[i] = i;
for (j = 0; j < 50; j++) {
zData[i][j] = i*j;
}
}
GetObjHandleFromActiveXCtrl(panelHandle, PANEL_CWGRAPH3D, &gGraph);
errChk (CA_VariantSet1DArray(&xVt,CAVT_DOUBLE, 50, xData));
errChk (CA_VariantSet1DArray(&yVt,CAVT_DOUBLE, 50, yData));
errChk (CA_VariantSet2DArray(&xVt,CAVT_DOUBLE, 50,50,zData));
errChk (CW3DGraphLib__DCWGraph3DPlot3DSurface(gGraph, NULL,xVt,yVt,zVt, CA_DEFAULT_VAL));
//errChk (CW3DGraphLib_CWPlot3DPlot3DSurface (gGraph, NULL, xVt, yVt, zVt, CA_DEFAULT_VAL));
...

 


It looks like you are overwritting xVt with the zData, and I think you meant to store the zData in &zVt. I am not sure if this is the cause of the error you are seeing, but change that and let us know what happens.

 

Jensen
National Instruments
Applications Engineer
Message 5 of 9
(4,957 Views)

That does fix the error and I am able to graph something! Woot!

 

Now I just need to figure out what each variant variable represents.  For example what the 1D x array means.  Or if the spot in the array represents something.  Or times I would want to use parametric varibales as opposed to 1D x, 1D y, and 2D z.

 

I am currently in the process of writing out my array and trying to convert my test file into a spherical looking shape on the graph.

0 Kudos
Message 6 of 9
(4,953 Views)

I've attempted to read in the data (brute force) and be able to plot it but with no prevail.  I am not sure how to format this info into the variants to get the desired shape.

 

Below is my code, but at this point, just figuring out how to draw a sphere would help.  At first glance, all the examples only use the parametric call to graph something that has multiple data points in the same axis.  So I guess I just need to figure

out how to go from my saved data into a graph.

 

With this function call, I am not sure what the expected behavior is if I set my graph to cartesian or to spherical, nor what are saved in all teh 2d arrays.

 

The below code doesn't work, but am able to retrieve data, so its a starting point.

 

 

 

 

int xSpot,ySpot;
	char buffer[300];
	
	double  xData[] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355};
	double yData[] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175};
	double	zData[360/5][180/5];
	
	FILE *fin = fopen("c:\\Documents and Settings\\gayn\\Desktop\\example.txt","r");
	char *token;
	fgets(buffer,300,fin); //skip first line
	while (fgets(buffer,300,fin) != NULL) {
		token = strtok(buffer,"\t");
		if (token != NULL && atoi(token)) {
			xSpot = atoi(token)/5-1;
			token = strtok(NULL,"\t");
			if (token != NULL && atoi(token)) {
				ySpot = atoi(token)/5-1;
				token = strtok(NULL,"\t");
				if (token != NULL && (ySpot+1)*5 < 180) {
					sscanf(token,"%lf",&zData[xSpot][ySpot]);
					//xData[xSpot] =  zData[xSpot][ySpot]*cos(DegToRad((xSpot+1)*5));
					//yData[ySpot] =  zData[xSpot][ySpot]*sin(DegToRad((xSpot+1)*5));
					//zData[xSpot][ySpot] = zData[xSpot][ySpot]*cos(DegToRad((ySpot+1)*5));
				}
			}	 
		}		 
	}

 

 

 

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

Any updates Jensen?

0 Kudos
Message 8 of 9
(4,926 Views)

Hello,


My name is Shawn and I will be handling this service request from here.   While Application Engineers do not write code for customers, I can definitely help point you in the right direction.  Have you checked out the 3DGraph.cws.

You can get it by opening LabWindows CVI and navigating to Help » Find Examples...  Next navigate to Fundamentals » Graphs and Charts » Graphs and Charts » 3DGraph.cws.  Once you have the workspace open for the shipping example, you should also have the National Instruments CW 3D Graph 8.0 Library Menu in the bottom left hand corner of the CVI application.  To answer your questions about the different fuctions.  When you double click the fucntion panel file (.fp) on the left in CVI, this will load the function panel, with boxes for each input.  If you right click anywhere on the grey background, you can get more detail on each function.  As far as you code is concerned, I would start with a simple surface that is easy to graph, and then work towards the more complex.

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 9 of 9
(4,868 Views)