我目前正在不遗余力地制作一个 Win32 (.net) 程序来绘制来自串行端口的数据。我已经能够从串行端口获取数据,并设置 ilnumerics 绘图立方体等。但我不能做的是将 (x,y,z) 转换为一个 ILAray 以绘制点。
public void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (serialPort1.IsOpen == true)
{
Varriables.numberOfSerialBytes = serialPort1.BytesToRead;
if (Varriables.numberOfSerialBytes >= Varriables.numberOfSerialBytesPerLine) //change 13 to number of bytes, changes for number of stars (stars x3 x BytesPerInt)
{
string serialText = serialPort1.ReadExisting();
if (serialText != "") RecievedText(serialText);
else { }
}
}
}
public void RecievedText(string text)
{
if ( richTextBox1.InvokeRequired)
{
SetTextCallBack x = new SetTextCallBack(RecievedText);
this.Invoke(x, new object[] { text });
}
else
{
richTextBox1.Text = text;
try { CalculatePoints(text); }
catch { }
}
}
public void CalculatePoints(string positionsString)
{
string[] starpositionStringList = positionsString.Split(" ".ToCharArray());
List<float> starPositionFloatListX = new List<float>();
List<float> starPositionFloatListY = new List<float>();
List<float> starPositionFloatListZ = new List<float>();
System.Console.WriteLine(starpositionStringList.Count());
for (int i = 0; i < starpositionStringList.Count() / 3; i += 3)
{
int iy = i + 1;
int iz = i + 2;
float x = float.Parse(starpositionStringList[i]);
float y = float.Parse(starpositionStringList[iy]);
float z = float.Parse(starpositionStringList[iz]);
starPositionFloatListX.Add(x);
starPositionFloatListY.Add(y);
starPositionFloatListZ.Add(z);
}
float[] xArray = starPositionFloatListX.ToArray<float>();
float[] yArray = starPositionFloatListY.ToArray<float>();
float[] zArray = starPositionFloatListZ.ToArray<float>();
PlotPoints(xArray, yArray, zArray);
}
public void PlotPoints(float[] x, float[] y, float[] z)
{
//could send data through PlotPoints(x,y,z);
//or make a long array using a for loop and send that
//either way i still need to make an array to plot and use ilPlanel2.Scene = Scene to continue upadating the scene
ILArray<float> starPositionsX = x;
ILArray<float> starPositionsY = y;
ILArray<float> starPositionsZ = z;
ILArray<float> starPositions = ???????????????; //need to convert (x,y,z) to ILArray<float>
ilPanel2.Scene.First<ILPlotCube>().Animations.AsParallel();
if(Varriables.pointsPlotted == false)
{
//ilPanel2.Scene.First<ILPlotCube>(){ new ILPoints { Positions = starPositions, Colors } };
//Cube.Add(new ILPoints { Positions = starPositions });
ilPanel2.Scene.First<ILPlotCube>().Add<ILPoints>(new ILPoints{ Positions = starPositions });
Varriables.pointsPlotted = true;
}
else
{
ilPanel2.Scene.First<ILPoints>().Positions.Update(starPositions);
}
ilPanel2.Refresh();
}
有我可以用来执行此操作的 IL.Math 函数吗?