// selection public override void Select(ViewportRect rect, TransformMatrix matrix, Viewport3D viewport3d) { int nDotNo = GetDataNo(); if (nDotNo == 0) { return; } double xMin = rect.XMin(); double xMax = rect.XMax(); double yMin = rect.YMin(); double yMax = rect.YMax(); for (int i = 0; i < nDotNo; i++) { ScatterPlotItem plotItem = Get(i); Point pt = matrix.VertexToViewportPt(new Point3D(plotItem.x, plotItem.y, plotItem.z), viewport3d); if ((pt.X > xMin) && (pt.X < xMax) && (pt.Y > yMin) && (pt.Y < yMax)) { m_vertices[i].selected = true; } else { m_vertices[i].selected = false; } } }
// convert the 3D scatter plot into a array of Mesh3D object public ArrayList GetMeshes() { int nDotNo = GetDataNo(); if (nDotNo == 0) { return(null); } ArrayList meshs = new ArrayList(); int nVertIndex = 0; for (int i = 0; i < nDotNo; i++) { ScatterPlotItem plotItem = Get(i); int nType = plotItem.shape % Chart3D.SHAPE_NO; float w = plotItem.w; float h = plotItem.h; Mesh3D dot; m_vertices[i].nMinI = nVertIndex; switch (nType) { case (int)SHAPE.BAR: dot = new Bar3D(0, 0, 0, w, w, h); break; case (int)SHAPE.CONE: dot = new Cone3D(w, w, h, 7); break; case (int)SHAPE.CYLINDER: dot = new Cylinder3D(w, w, h, 7); break; case (int)SHAPE.ELLIPSE: dot = new Ellipse3D(w, w, h, 7); break; case (int)SHAPE.PYRAMID: dot = new Pyramid3D(w, w, h); break; default: dot = new Bar3D(0, 0, 0, w, w, h); break; } nVertIndex += dot.GetVertexNo(); m_vertices[i].nMaxI = nVertIndex - 1; TransformMatrix.Transform(dot, new Point3D(plotItem.x, plotItem.y, plotItem.z), 0, 0); dot.SetColor(plotItem.color); meshs.Add(dot); } AddAxesMeshes(meshs); return(meshs); }
public void TestSimpleScatterPlot() { var mainWindow = (MainWindow)Application.Current.MainWindow; string columnNameX = comboBoxX.SelectedItem.ToString(); string columnNameY = comboBoxY.SelectedItem.ToString(); string columnNameZ = comboBoxZ.SelectedItem.ToString(); var valuesX = (from row in mainWindow.gridData.AsEnumerable() select Convert.ToDouble(row.Field <string>(columnNameX))).ToList(); var valuesY = (from row in mainWindow.gridData.AsEnumerable() select Convert.ToDouble(row.Field <string>(columnNameY))).ToList(); var valuesZ = (from row in mainWindow.gridData.AsEnumerable() select Convert.ToDouble(row.Field <string>(columnNameZ))).ToList(); int nDotNo = mainWindow.gridData.Rows.Count; // 1. set the scatter plot size m_3dChart = new ScatterChart3D(); m_3dChart.SetDataNo(nDotNo); // 2. set the properties of each dot Random randomObject = new Random(); for (int i = 0; i < nDotNo; i++) { ScatterPlotItem plotItem = new ScatterPlotItem(); plotItem.w = (float)0.1; plotItem.h = (float)0.1; plotItem.x = (float)valuesX[i]; plotItem.y = (float)valuesY[i]; plotItem.z = (float)valuesZ[i]; plotItem.shape = (int)Chart3D.SHAPE.ELLIPSE; plotItem.nMaxI = 1; Byte nR = (Byte)randomObject.Next(256); Byte nG = (Byte)randomObject.Next(256); Byte nB = (Byte)randomObject.Next(256); plotItem.color = Color.FromRgb(255, 0, 0); ((ScatterChart3D)m_3dChart).SetVertex(i, plotItem); } // 3. set axes m_3dChart.GetDataRange(); m_3dChart.SetAxes(); // 4. Get Mesh3D array from scatter plot ArrayList meshs = ((ScatterChart3D)m_3dChart).GetMeshes(); // 5. display vertex no and triangle no. UpdateModelSizeInfo(meshs); // 6. show 3D scatter plot in Viewport3d SWD.Model3D model3d = new SWD.Model3D(); m_nChartModelIndex = model3d.UpdateModel(meshs, null, m_nChartModelIndex, this.mainViewport); // 7. set projection matrix float viewRange = 5; m_transformMatrix.CalculateProjectionMatrix(0, viewRange, 0, viewRange, 0, viewRange, 0.5); TransformChart(); }