public CloudView() { ActiveWorkspace = new Workspace(); InitializeComponent(); kinectStreamer = KinectStreamer.Instance; }
public void SetRealVertices(Workspace workspace) { Vector<double> fittedPlaneVector = GeometryHelper.FitPlaneToPoints(workspace.PointCloud.ToArray()); if (fittedPlaneVector == null) { return; } Point3D projectedPoint = GeometryHelper.ProjectPoint3DToPlane(workspace.PointCloud.First(), fittedPlaneVector); Vector<double> planeNormal = new DenseVector(new[] { fittedPlaneVector[0], fittedPlaneVector[1], fittedPlaneVector[2] }); CameraSpacePoint[] csps = { new CameraSpacePoint() }; Point[] vertices = workspace.Vertices.ToArray(); for (int i = 0; i < vertices.Length; i++) { Point vertex = vertices[i]; kinectStreamer.CoordinateMapper.MapDepthPointsToCameraSpace( new[] { new DepthSpacePoint { X = (float)vertex.X, Y = (float)vertex.Y } }, new ushort[] { 1 }, csps); Vector<double> pointOnPlane = new DenseVector(new[] { projectedPoint.X, projectedPoint.Y, projectedPoint.Z }); Vector<double> pointOnLine = new DenseVector(new double[] { csps[0].X, csps[0].Y, csps[0].Z }); double d = (pointOnPlane.Subtract(pointOnLine)).DotProduct(planeNormal) / (pointOnLine.DotProduct(planeNormal)); Vector<double> intersection = pointOnLine + pointOnLine.Multiply(d); workspace.FittedVertices[i] = new Point3D(intersection[0], intersection[1], intersection[2]); } workspace.PlaneVector = fittedPlaneVector; }
private void SetWorkspaceCloudAndCenter(Workspace workspace) { AllCameraSpacePoints = kinectStreamer.GenerateFullPointCloud(); Polygon polygon = new Polygon(); PointCollection pointCollection = new PointCollection(); foreach (Point p in workspace.Vertices) { pointCollection.Add(p); } polygon.Points = pointCollection; polygon.Stroke = Brushes.Black; polygon.Fill = Brushes.LightSeaGreen; polygon.StrokeThickness = 2; int height = (int)polygon.ActualHeight; int width = (int)polygon.ActualWidth; double sumX = 0; double sumY = 0; double sumZ = 0; double numberOfPoints = 0; List<Point3D> cameraSpacePoints = new List<Point3D>(); List<DepthSpacePoint> dspList = new List<DepthSpacePoint>(); foreach (CameraSpacePoint csp in AllCameraSpacePoints) { if (GeometryHelper.IsValidCameraPoint(csp)) { DepthSpacePoint dsp = kinectStreamer.CoordinateMapper.MapCameraPointToDepthSpace(csp); dspList.Add(dsp); if (GeometryHelper.InsidePolygon(polygon, new Point(dsp.X, dsp.Y))) { double x = csp.X; double y = csp.Y; double z = csp.Z; sumX += x; sumY += y; sumZ += z; numberOfPoints += 1; cameraSpacePoints.Add(new Point3D(csp.X, csp.Y, csp.Z)); } } } workspace.Center = new Point3D(sumX / numberOfPoints, sumY / numberOfPoints, sumZ / numberOfPoints); workspace.PointCloud = new ObservableCollection<Point3D>(cameraSpacePoints); }
private void SetCameraCenterAndShowCloud(Viewport3D viewport, Workspace workspace) { ClearScreen(); foreach (Point3D point in workspace.PointCloud) { DrawTriangle(viewport, point, Colors.Black); } Point3D center = workspace.Center; XRotation.CenterX = center.X; XRotation.CenterY = center.Y; XRotation.CenterZ = center.Z; YRotation.CenterX = center.X; YRotation.CenterY = center.Y; YRotation.CenterZ = center.Z; Scale.CenterX = center.X; Scale.CenterY = center.Y; Scale.CenterZ = center.Z; Camera.Position = new Point3D(center.X, center.Y, -3); }
public void SetWorkspace(Workspace workspaceSource) { ActiveWorkspace = workspaceSource; if (ActiveWorkspace.PointCloud == null) { SetWorkspaceCloudAndCenter(ActiveWorkspace); } SetCameraCenterAndShowCloud(MainViewPort, ActiveWorkspace); SetRealVertices(ActiveWorkspace); DrawFittedPlane(); }
private void WorkspaceList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if ((Workspace)WorkspaceList.SelectedItem == null) { return; } activeWorkspace = (Workspace)WorkspaceList.SelectedItem; EditWorkspace.DataContext = activeWorkspace; cloudView.SetWorkspace(activeWorkspace); }
private void RemoveWorkspace(object sender, RoutedEventArgs e) { workspaceList.Remove((Workspace)WorkspaceList.SelectedItem); activeWorkspace = new Workspace(); cloudView.ClearScreen(); }
private void AddWorkspace(object sender, RoutedEventArgs e) { if (!workspaceList.Contains(activeWorkspace)) { workspaceList.Add(activeWorkspace); } activeWorkspace = new Workspace(); EditWorkspace.DataContext = activeWorkspace; WorkspaceList.Items.Refresh(); }