从NI Labview里提取一个3d控件cw3dgrph.ocx画三维波形图的

By admin at 2021-09-17 • 0人收藏 • 274人看过

简单调用实例

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add()
/*}}*/

var dataX = {};
var dataY = {};
var dataZ = {};
var color = {};
// Parametric curve
for (t = 0; 50; 0.001) {
    var x = (1 + 0.25 * math.cos(75 * t)) * math.cos(t);
    var y = (1 + 0.25 * math.cos(75 * t)) * math.sin(t);
    var z = t + 2.0 * math.sin(75 * t);
    table.push(dataX,x);
    table.push(dataY,y);
    table.push(dataZ,z);
    table.push(color,t);
} 

 
var d3d = winform.createEmbed("CW3DGraphLib.CWGraph3D.1")._object;
with d3d{
    Caption = "demo"
    Enabled = true;//图形使能
    FastDraw = true;//快速绘制
    //ImmediateUpdates = false;
    Use3DHardwareAcceleration = true;
    Windowless = true;
    //ViewMode = 0;//视角:0=XYPlane,1=XZPlane,2=YZPlane,3=UserDefined
    //GridXY = false;
    //GridXZ = false;
    //GridYZ = false;
    AmbientLightColor = 0xcccccc;
    BackColor = 0xcc5577;
    GridSmoothing = true;
    GridFrameColor = 0xccdd77; 
    GraphFrameVisible = false;//画框边框
    GraphFrameColor = 0x33cc77; 
    //PlotAreaColor = 0x778899;
    Plot3DCurve( dataX , dataY, dataZ,color );
    //Plot3DMesh(  dataX , dataY, dataZ,color );
	//ClearData();
}
 
winform.show();
win.loopMessage();

cw3dgrph.zip


消除[试用版]提示的方法: 注册表中添加下面项即可.

import win.reg;
regLic = win.reg("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Licenses\C6429907-9DBF-438C-B904-BC632CE9EA13");
if(! regLic.queryValue("") ) regLic.setSzValue("","pooglhnjlgcnabnoiegdmlpobiogoipdblpjklgmfabnnlgcikknbalipoblhffo");

或者, 直接运行下面压缩包里的do.reg在注册表中注册.

do.zip

详细示例看楼下三楼.


image.png

image.png

image.png

image.png

3 个回复 | 最后更新于 2021-09-19
2021-09-17   #1

好像echarts也能画,而且模型库更全面。

echarts是纯js生成的,aardio可以直接通过js调用,我记得好像之前有人写过的

https://echarts.apache.org/examples/zh/editor.html?c=scatter3d-scatter&gl=1

screenshot.jpeg

2021-09-17   #2

回复#1 @jerryxjr1220 :

echart的3d需要webgl支持,数据量大了卡的厉害

2021-09-19   #3

移植的示例:

GIF.gif

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=784;bottom=641)
winform.add(
AUTOSCALE={cls="checkbox";text="Autoscale";left=608;top=62;right=710;bottom=76;z=4};
AXIS={cls="combobox";left=595;top=13;right=731;bottom=33;edge=1;items={"XAxis";"YAxis";"ZAxis"};mode="dropdown";z=3};
AutoscaleNow={cls="button";text="Autoscale Now";left=581;top=81;right=750;bottom=111;z=5};
AutoscalePlot={cls="checkbox";text="Autoscale Plot";left=445;top=528;right=555;bottom=546;z=31};
CAPTION={cls="edit";left=621;top=265;right=719;bottom=287;edge=1;z=15};
CWGRAPH3D1={cls="picturebox";left=0;top=0;right=559;bottom=512;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=2};
ColorMapStyle={cls="combobox";left=677;top=582;right=772;bottom=602;edge=1;items={"cwNone";"cwShaded";"cwColorSpectrum";"cwGrayScale";"cwCustom"};mode="dropdown";z=36};
GRID_MAJOR={cls="checkbox";text="Major";left=582;top=527;right=665;bottom=545;z=29};
GRID_MINOR={cls="checkbox";text="Minor";left=682;top=527;right=765;bottom=545;z=30};
GenetatePlot={cls="button";text="Genetate Plot";left=13;top=518;right=142;bottom=552;z=32};
INVERTED={cls="checkbox";text="Inverted";left=582;top=211;right=665;bottom=229;z=12};
LABELS_NORMAL={cls="checkbox";text="Normal";left=582;top=356;right=665;bottom=374;z=19};
LABELS_OPPOSITE={cls="checkbox";text="Opposite";left=682;top=356;right=765;bottom=374;z=20};
LOG={cls="checkbox";text="Log";left=682;top=211;right=765;bottom=229;z=13};
MAXIMUM={cls="edit";text="10";left=652;top=145;right=750;bottom=167;edge=1;z=9};
MINIMUM={cls="edit";text="0";left=651;top=119;right=749;bottom=141;edge=1;z=7};
NORMAL={cls="checkbox";text="Normal";left=581;top=297;right=664;bottom=315;z=16};
Opposite={cls="checkbox";text="Opposite";left=681;top=297;right=764;bottom=315;z=17};
RemovePlot={cls="button";text="Remove Plot";left=178;top=517;right=303;bottom=551;z=33};
SetMax={cls="button";text="Set max";left=680;top=173;right=762;bottom=201;z=11};
SetMin={cls="button";text="Set min";left=580;top=173;right=662;bottom=201;z=10};
TICKS_INSIDE={cls="checkbox";text="Inside";left=583;top=438;right=666;bottom=456;z=24};
TICKS_MAJOR={cls="checkbox";text="Major";left=583;top=465;right=666;bottom=483;z=26};
TICKS_MINOR={cls="checkbox";text="Minor";left=681;top=465;right=766;bottom=484;z=27};
TICKS_NORMAL={cls="checkbox";text="Normal";left=582;top=413;right=665;bottom=431;z=22};
TICKS_OPPOSITE={cls="checkbox";text="Opposite";left=680;top=413;right=765;bottom=432;z=23};
TICKS_OUTSIDE={cls="checkbox";text="Outside";left=681;top=438;right=766;bottom=457;z=25};
button={cls="button";text="Genetate Plot3";left=15;top=599;right=142;bottom=642;z=39};
button2={cls="button";text="Genetate Plot2";left=15;top=553;right=142;bottom=596;z=34};
button3={cls="button";text="标记";left=431;top=567;right=554;bottom=601;z=38};
groupbox={cls="groupbox";text="scaling";left=563;top=44;right=778;bottom=240;edge=1;z=1};
groupbox2={cls="groupbox";text="caption";left=564;top=252;right=779;bottom=324;edge=1;z=14};
groupbox3={cls="groupbox";text="Labels";left=565;top=332;right=780;bottom=384;edge=1;z=18};
groupbox4={cls="groupbox";text="Ticks";left=565;top=389;right=780;bottom=495;edge=1;z=21};
groupbox5={cls="groupbox";text="Grid";left=565;top=503;right=780;bottom=555;edge=1;z=28};
groupbox6={cls="groupbox";text="style";left=565;top=560;right=780;bottom=612;edge=1;z=37};
plotstyle={cls="combobox";left=574;top=582;right=669;bottom=602;edge=1;items={"cwLine";"cwPoint";"cwLinePoint";"cwHiddenLine";"cwSurface";"cwSurfaceLine";"cwSurfaceNormal";"cwContourLine";"cwSurfaceContour"};mode="dropdown";z=35};
static={cls="static";text="Minimum";left=582;top=115;right=644;bottom=139;center=1;transparent=1;z=6};
static2={cls="static";text="Maximum";left=583;top=141;right=645;bottom=165;center=1;transparent=1;z=8}
)
/*}}*/

import console
console.open()

winform.AXIS.selIndex = 1;
var m_graph = winform.CWGRAPH3D1.createEmbed("CW3DGraphLib.CWGraph3D.1")._object;
var m_Axis3D = m_graph.Axes.Item(1);


var RefreshControls = function(){
	if(m_graph.Plots.getCount() > 0)
	winform.AutoscalePlot.checked = m_graph.Plots.Item(1).getAutoScale();
	
	winform.AUTOSCALE.checked = m_Axis3D.getAutoScale();

	winform.MINIMUM.text = m_Axis3D.getMinimum();
	winform.MAXIMUM.text = m_Axis3D.getMaximum();
	
	winform.INVERTED.checked = m_Axis3D.getInverted();
	winform.LOG.checked = m_Axis3D.getLog();
	winform.CAPTION.text = m_Axis3D.getCaption();
	winform.NORMAL.checked = m_Axis3D.getCaptionNormal();
	winform.Opposite.checked = m_Axis3D.getCaptionOpposite();
	winform.LABELS_NORMAL.checked = m_Axis3D.Labels.getNormal();
	winform.LABELS_OPPOSITE.checked = m_Axis3D.Labels.getOpposite();
	winform.TICKS_NORMAL.checked = m_Axis3D.Ticks.getNormal();
	winform.TICKS_OPPOSITE.checked = m_Axis3D.Ticks.getOpposite();
	winform.TICKS_INSIDE.checked = m_Axis3D.Ticks.getInside();
	winform.TICKS_OUTSIDE.checked = m_Axis3D.Ticks.getOutside();
	
	winform.TICKS_MAJOR.checked = m_Axis3D.Ticks.getMajorTicks();
	winform.TICKS_MINOR.checked = m_Axis3D.Ticks.getMinorTicks();
	winform.GRID_MAJOR.checked = m_Axis3D.Ticks.getMajorGrid();
	winform.GRID_MINOR.checked = m_Axis3D.Ticks.getMinorGrid();
	
}


RefreshControls();


winform.GenetatePlot.oncommand = function(id,event){
	// Generate data
	var t={};
	var xData=table.array( 41/*行*/,41/*列*/,0 );
	var yData=table.array( 41/*行*/,41/*列*/,0 );
	var zData=table.array( 41/*行*/,41/*列*/,0 );

	for (i = 1; 41; 1){
		t[i] = (i - 20)/20 * 3.14;
	}
	//console.dump(t)
	for (i = 1; 41; 1){
		for (j = 1; 41; 1) 
		{
			xData[j][i] = (math.cos(t[j]) + 3) * math.cos(t[i]);
			yData[j][i] = (math.cos(t[j]) + 3) * math.sin(t[i]);
			zData[j][i] = math.sin(t[j]);
		}
	}
	//console.dump(xData)
	// Plot the data
	m_graph.Plot3DParametricSurface(xData, yData, zData,zData);
	RefreshControls();
}

winform.RemovePlot.oncommand = function(id,event){
	// Remove all the plots
	m_graph.Plots.RemoveAll();
	RefreshControls();
}

winform.SetMax.oncommand = function(id,event){
	var maximum = tonumber(winform.MAXIMUM.text);
	m_Axis3D.setMaximum(maximum);
	RefreshControls();
}

winform.SetMin.oncommand = function(id,event){
	var minimum = tonumber(winform.MINIMUM.text);
	m_Axis3D.setMinimum(minimum);
	RefreshControls();
}


winform.AutoscaleNow.oncommand = function(id,event){
	m_Axis3D.setAutoScale(winform.AUTOSCALE.checked ? true : false);
	RefreshControls();
}

winform.AutoscalePlot.oncommand = function(id,event){
	m_graph.Plots.Item(1).setAutoScale(winform.AutoscalePlot.checked ? true : false);
	RefreshControls();
}

winform.NORMAL.oncommand = function(id,event){
	m_Axis3D.setCaptionNormal(winform.NORMAL.checked ? true : false);
}

winform.Opposite.oncommand = function(id,event){
	m_Axis3D.setCaptionOpposite(winform.Opposite.checked ? true : false);
}

winform.TICKS_MAJOR.oncommand = function(id,event){
	m_Axis3D.Ticks.setMajorGrid(winform.TICKS_MAJOR.checked ? true : false);
}

winform.TICKS_MINOR.oncommand = function(id,event){
	m_Axis3D.Ticks.setMinorGrid(winform.TICKS_MINOR.checked ? true : false);
}

winform.INVERTED.oncommand = function(id,event){
	m_Axis3D.setInverted(winform.INVERTED.checked ? true : false);
}

winform.LABELS_NORMAL.oncommand = function(id,event){
	m_Axis3D.Labels.setNormal(winform.LABELS_NORMAL.checked ? true : false);
}

winform.LABELS_OPPOSITE.oncommand = function(id,event){
	m_Axis3D.Labels.setOpposite(winform.LABELS_OPPOSITE.checked ? true : false);
}

winform.LOG.oncommand = function(id,event){
	m_Axis3D.setLog(winform.LOG.checked ? true : false);
	RefreshControls();
}

winform.TICKS_INSIDE.oncommand = function(id,event){
	m_Axis3D.Ticks.setInside(winform.TICKS_INSIDE.checked ? true : false);
}

winform.TICKS_OUTSIDE.oncommand = function(id,event){
	m_Axis3D.Ticks.setOutside(winform.TICKS_OUTSIDE.checked ? true : false);
}

winform.TICKS_NORMAL.oncommand = function(id,event){
	m_Axis3D.Ticks.setNormal(winform.TICKS_NORMAL.checked ? true : false);
}

winform.TICKS_OPPOSITE.oncommand = function(id,event){
	m_Axis3D.Ticks.setOpposite(winform.TICKS_OPPOSITE.checked ? true : false);
}

winform.AXIS.onListChange= function(){ 
	select(winform.AXIS.find(winform.AXIS.selText)) {
		case 3 {
			m_Axis3D = m_graph.Axes.Item(3);
		}
		case 1 {
			m_Axis3D = m_graph.Axes.Item(1);
		}
		case 2 {
			m_Axis3D = m_graph.Axes.Item(2);
		}
	}
	RefreshControls();
}

winform.CAPTION.onChange = function(){ 
	m_Axis3D.setCaption(winform.CAPTION.text);	
}


winform.button2.oncommand = function(id,event){
	// Generate data
	var xData={};
	var yData={};
	var zData=table.array( 41/*行*/,41/*列*/,0 );

	//console.dump(t)
	for (i = 1; 41; 1){
		xData[i] = ((i - 20.0) / 20.0) * 3.14;
		yData[i] = ((i - 20.0) / 20.0) * 3.14;
	}
	
	for(i=1;41;1){
		for(j=1;41;1){
			zData[j][i] = math.sin(xData[i]) * math.cos(yData[j]) + 2.0;
		}
	}
	
	// Plot the data
	m_graph.Plot3DSurface(xData, yData, zData,zData);
	RefreshControls();
}

winform.plotstyle.selIndex = 5;
winform.plotstyle.onOk= function(){ 
	var plot = m_graph.Plots.Item(1);
	plot.Style = winform.plotstyle.selIndex;
}

winform.ColorMapStyle.onOk = function(){
	var plot = m_graph.Plots.Item(1);
	plot.ColorMapStyle = winform.ColorMapStyle.selIndex-1;
	if(winform.ColorMapStyle.selIndex==5){

    	var axis = plot.ZAxis;
    	var interval = (axis.Maximum - axis.Minimum) / 5;
	
    	var mapValues={};
    	for ( i = 1; 5; 1)
        	mapValues[i] = axis.Minimum + (i * interval);
	
    	var mapColors={};
    	mapColors[5] = 0x0000E6;
    	mapColors[4] = 0xE6E600;
    	mapColors[3] = 0x00E6E6;
    	mapColors[2] = 0x76A112;
    	mapColors[1] = 0xE6E6E6;
	
    	plot.setColorMapValues(mapValues);
    	plot.setColorMapColors(mapColors);
	}
}

winform.button3.oncommand = function(id,event){
	var m_Cursor = m_graph.Cursors.Add();
    m_Cursor.Name ="Cursor 1";
    m_Cursor.Enabled = true;
    m_Cursor.Visible = true;
    m_Cursor.NameVisible = true;
    m_Cursor.TextColor = 0x000000;

    m_Cursor.XPosition = 5.0;
    m_Cursor.YPosition = 5.0;
    m_Cursor.ZPosition = 5.0;
    m_Cursor.PositionVisible = true;
    m_Cursor.SnapMode = 1;

    m_Cursor.PointSize = 10.0;
    m_Cursor.PointColor = 0x0000ff;
    m_Cursor.PointStyle = 6;

    m_Cursor.LineWidth = 1.0;
    m_Cursor.LineColor = 0xff0000;
    m_Cursor.LineStyle = 1;

    m_Cursor.Transparency = 75;
    m_Cursor.PlaneColor = 0x00ff00;
    m_Cursor.XYPlaneVisible = false;
    m_Cursor.XZPlaneVisible = false;
    m_Cursor.YZPlaneVisible = false;
}

winform.button.oncommand = function(id,event){
	var zData=table.array( 81/*行*/,81/*列*/,0 );

	//console.dump(t)
	for (i = 1; 81; 1){
		for(j=1;81;1){
			zData[j][i] = math.sin(i / 4.0) * math.cos(j / 4.0) * math.sin(j / 13.0) * math.cos(i / 9.0);
		}
	}
	// Plot the data
	m_graph.Plot3DSimpleSurface(zData,zData);
	
}



winform.show();
win.loopMessage();


vc2008的原版示例包:

MStudio 2009 3DGraph CPP Examples.zip


登录后方可回帖

登 录
信息栏
本站永久域名:HtmLayout.Cn
纯私人站,当笔记本用的,学到哪写到哪,目前在学aardio+halcon机器视觉.
AARDIO语言QQ群:70517368
Aardio 官方站:Aardio官方
Aardio最新功能:Aardio官方更新日志
C大Aardio论坛:Aar爱好者论坛
本 站 主 站:Stm32cube中文网
Sciter中文在线文档Sciter在线学习文档
赞助商:才仁机械




Loading...