/// <summary>
        /// Create a visible model of the STL file
        /// </summary>
        /// <param name="filename">The STL file with full extension</param>
        public void ViewNewStl(string filename)
        {
            // WTF!! No file
            if (!File.Exists(filename)) return;

            // Check the file extension to be STL
            FileInfo fileInfo = new FileInfo(filename);
            if (fileInfo.Extension.ToLower() != ".stl") return;

            ModelColor = configuration.STLcolor;

            Filename = filename;

            // Create a model of the STL file

            ModelImporter modellImporter = new ModelImporter();
            modellImporter.DefaultMaterial =
                new DiffuseMaterial(
                    new SolidColorBrush((Color)ColorConverter.ConvertFromString(modellColor)));
            Model3DGroup model3DGroup = modellImporter.Load(filename);

            StlModel.Content = model3DGroup;

            myViewPort3D.CameraController.ResetCamera();
            myViewPort3D.CameraController.ZoomExtents(0);
        }
        public void Load_TestObj_ValidNumberOfVertices()
        {
            var importer = new ModelImporter();
            var model = importer.Load(@"Models\obj\test.obj");
            int countVertices = 0;
            model.Traverse<GeometryModel3D>((geometryModel, transform) =>
                {
                    var mesh = (MeshGeometry3D)geometryModel.Geometry;
                    countVertices += mesh.Positions.Count;
                });

            Assert.AreEqual(8, countVertices);
        }
Beispiel #3
0
        public Poke3D(string path_to_3d)
        {
            InitializeComponent();

            var importer = new HelixToolkit.Wpf.ModelImporter();

            try
            {
                Model3D MyModel = importer.Load(AppDomain.CurrentDomain.BaseDirectory + path_to_3d);
                model.Content = MyModel;
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
            }
        }
        public VirtualRobot()
        {
            InitializeComponent();
            this.TypeName = "Virtual Robot";

            Inputs.Add("RightUpperBevel", new ViewModel.InputSignalViewModel("RightUpperBevel", this.InstanceName));
            Inputs.Add("RightLowerBevel", new ViewModel.InputSignalViewModel("RightLowerBevel", this.InstanceName));
            Inputs.Add("RightElbow", new ViewModel.InputSignalViewModel("RightElbow", this.InstanceName));
            Inputs.Add("LeftUpperBevel", new ViewModel.InputSignalViewModel("LeftUpperBevel", this.InstanceName));
            Inputs.Add("LeftLowerBevel", new ViewModel.InputSignalViewModel("LeftLowerBevel", this.InstanceName));
            Inputs.Add("LeftElbow", new ViewModel.InputSignalViewModel("LeftElbow", this.InstanceName));
            Inputs.Add("GrasperOpen", new ViewModel.InputSignalViewModel("GrasperOpen", this.InstanceName));
            Inputs.Add("GrasperTwist", new ViewModel.InputSignalViewModel("GrasperTwist", this.InstanceName));
            Inputs.Add("CauteryTwist", new ViewModel.InputSignalViewModel("CauteryTwist", this.InstanceName));

            PostLoadSetup();

            string startupPath = System.IO.Directory.GetCurrentDirectory();
            startupPath = startupPath + "\\3D Models\\";
            this.dispatcher = Dispatcher.CurrentDispatcher;

            string shoulderPath = startupPath + "Shoulder.stl";
            string upperRightPath = startupPath + "upperRight.stl";
            string upperLeftPath = startupPath + "upperLeft.stl";
            string foreRightPath = startupPath + "cauteryFore.stl";
            string rightTipPath = startupPath + "cauteryHook.stl";
            string foreLeftPath = startupPath + "grasperFore.stl";
            string yolkPath = startupPath + "grasperYolk.stl";
            string jaw1Path = startupPath + "grasperJaw1.stl";
            string jaw2Path = startupPath + "grasperJaw2.stl";
            string rightSpacePath = startupPath + "RightWorkspace.stl";
            string leftSpacePath = startupPath + "LeftWorkspace.stl";
            string needlePath = startupPath + "needle2.stl";

            // Import *.stl files
            var up = new ModelImporter();
            var shoulder = up.Load(shoulderPath, this.dispatcher);
            var upperRightArm = up.Load(upperRightPath, this.dispatcher);
            var upperLeftArm = up.Load(upperLeftPath, this.dispatcher);
            var foreRightArm = up.Load(foreRightPath, this.dispatcher);
            var tipRightArm = up.Load(rightTipPath, this.dispatcher);
            var foreLeftArm = up.Load(foreLeftPath, this.dispatcher);
            var grasperYolk = up.Load(yolkPath, this.dispatcher);
            var grasperJaw1 = up.Load(jaw1Path, this.dispatcher);
            var grasperJaw2 = up.Load(jaw2Path, this.dispatcher);
            var rightSpace = up.Load(rightSpacePath, this.dispatcher);
            var leftSpace = up.Load(leftSpacePath, this.dispatcher);
            var needle = up.Load(needlePath, this.dispatcher);

            // Convert to GeometryModel3d so we can rotate models
            GeometryModel3D SHmodel = shoulder.Children[0] as GeometryModel3D;
            GeometryModel3D URmodel = upperRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D ULmodel = upperLeftArm.Children[0] as GeometryModel3D;
            GeometryModel3D FRmodel = foreRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D FLmodel = foreLeftArm.Children[0] as GeometryModel3D;
            GeometryModel3D TRmodel = tipRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D GYmodel = grasperYolk.Children[0] as GeometryModel3D;
            GeometryModel3D GJ1model = grasperJaw1.Children[0] as GeometryModel3D;
            GeometryModel3D GJ2model = grasperJaw2.Children[0] as GeometryModel3D;
            GeometryModel3D RWSmodel = rightSpace.Children[0] as GeometryModel3D;
            GeometryModel3D LWSmodel = leftSpace.Children[0] as GeometryModel3D;
            GeometryModel3D Nmodel = needle.Children[0] as GeometryModel3D;

            // GHOST WHITE // Set model color
            DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Colors.GhostWhite));
            SHmodel.Material = material;
            SHmodel.BackMaterial = material;
            // RED // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
            FRmodel.Material = material;
            FRmodel.BackMaterial = material;
            TRmodel.Material = material;
            TRmodel.BackMaterial = material;
            // DARK RED // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.DarkRed));
            URmodel.Material = material;
            URmodel.BackMaterial = material;
            Nmodel.Material = material;
            // GREEN // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Green));
            // BLUE // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Blue));
            GYmodel.Material = material;
            GYmodel.BackMaterial = material;
            GJ1model.Material = material;
            GJ1model.BackMaterial = material;
            GJ2model.Material = material;
            GJ2model.BackMaterial = material;
            FLmodel.Material = material;
            FLmodel.BackMaterial = material;
            // DARK BLUE // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.DarkBlue));
            ULmodel.Material = material;
            ULmodel.BackMaterial = material;
            // BLACK // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Black));
            // TRANSPARENT RED // Set model color
            SolidColorBrush brushOne = new SolidColorBrush();
            brushOne.Opacity = 0.50;
            brushOne.Color = Colors.Red;
            material = new DiffuseMaterial(brushOne);
            RWSmodel.Material = material;
            RWSmodel.BackMaterial = material;
            // TRANSPARENT BLUE // Set model color
            SolidColorBrush brushTwo = new SolidColorBrush();
            brushTwo.Opacity = 0.50;
            brushTwo.Color = Colors.Blue;
            material = new DiffuseMaterial(brushTwo);
            LWSmodel.Material = material;
            LWSmodel.BackMaterial = material;

            // right shoulder rotations
            rsyTransform.CenterX = 0;
            rsyTransform.CenterY = 0;
            rsyTransform.CenterZ = 0;
            rightShoulderRotY.Axis = new Vector3D(0, 1, 0);
            rsxTransform.CenterX = 0;
            rsxTransform.CenterY = 0;
            rsxTransform.CenterZ = 0;
            rightShoulderRotX.Axis = new Vector3D(1, 0, 0);
            // right elbow rotations
            relTransform.CenterX = -13.386;
            relTransform.CenterY = 5;
            relTransform.CenterZ = 74.684;
            rightElbow.Axis = new Vector3D(0, 1, 0);
            // right tip rotations
            rTipTransform.CenterX = -15.111;
            rTipTransform.CenterY = 9.515;
            rTipTransform.CenterZ = 0;
            rightTip.Axis = new Vector3D(0, 0, 1);
            //left shoulder rotations
            lsyTransform.CenterX = 14.478;
            lsyTransform.CenterY = 0;
            lsyTransform.CenterZ = 0;
            leftShoulderRotY.Axis = new Vector3D(0, 1, 0);
            lsxTransform.CenterX = 0;
            lsxTransform.CenterY = 0;
            lsxTransform.CenterZ = 0;
            leftShoulderRotX.Axis = new Vector3D(1, 0, 0);
            // left elbow rotations
            lelTransform.CenterX = 27.864;
            lelTransform.CenterY = 0;
            lelTransform.CenterZ = 74.684;
            leftElbow.Axis = new Vector3D(0, 1, 0);
            // grasper rotations
            graspTransform.CenterX = 27.864;
            graspTransform.CenterY = 13.624;
            graspTransform.CenterZ = 0;
            graspOrient1.Axis = new Vector3D(0, 0, 1);
            jaw1Transform.CenterX = 27.864;
            jaw1Transform.CenterZ = 160.284;
            jawAngle1.Axis = new Vector3D(0, 1, 0);
            jaw2Transform.CenterX = 27.864;
            jaw2Transform.CenterZ = 160.284;
            jawAngle2.Axis = new Vector3D(0, 1, 0);

            // Define cautery tip
            rightTipVisual.Content = TRmodel;

            rightTipVisual2.Content = TRmodel;

            rightTipVisual3.Content = TRmodel;
            // Define right forearm group
            rightForeBodyVisual.Content = FRmodel;
            rightForeVisual.Children.Clear();
            rightForeVisual.Children.Add(rightForeBodyVisual);
            rightForeVisual.Children.Add(rightTipVisual);

            rightForeBodyVisual2.Content = FRmodel;
            rightForeVisual2.Children.Clear();
            rightForeVisual2.Children.Add(rightForeBodyVisual2);
            rightForeVisual2.Children.Add(rightTipVisual2);

            rightForeBodyVisual3.Content = FRmodel;
            rightForeVisual3.Children.Clear();
            rightForeVisual3.Children.Add(rightForeBodyVisual3);
            rightForeVisual3.Children.Add(rightTipVisual3);
            // Define right arm group
            rightUpperVisual.Content = URmodel;
            rightVisual.Children.Clear();
            rightVisual.Children.Add(rightUpperVisual);
            rightVisual.Children.Add(rightForeVisual);

            rightUpperVisual2.Content = URmodel;
            rightVisual2.Children.Clear();
            rightVisual2.Children.Add(rightUpperVisual2);
            rightVisual2.Children.Add(rightForeVisual2);

            rightUpperVisual3.Content = URmodel;
            rightVisual3.Children.Clear();
            rightVisual3.Children.Add(rightUpperVisual3);
            rightVisual3.Children.Add(rightForeVisual3);
            // Left grasper open/close
            jawOneVisual.Content = GJ1model;
            jawTwoVisual.Content = GJ2model;
            needleVisual.Content = Nmodel;

            jawOneVisual2.Content = GJ1model;
            jawTwoVisual2.Content = GJ2model;
            needleVisual2.Content = Nmodel;

            jawOneVisual3.Content = GJ1model;
            jawTwoVisual3.Content = GJ2model;
            needleVisual3.Content = Nmodel;

            // Define grasper group
            yolkVisual.Content = GYmodel;
            grasperVisual.Children.Clear();
            grasperVisual.Children.Add(yolkVisual);
            grasperVisual.Children.Add(jawOneVisual);
            grasperVisual.Children.Add(jawTwoVisual);
            grasperVisual.Children.Add(needleVisual);

            yolkVisual2.Content = GYmodel;
            grasperVisual2.Children.Clear();
            grasperVisual2.Children.Add(yolkVisual2);
            grasperVisual2.Children.Add(jawOneVisual2);
            grasperVisual2.Children.Add(jawTwoVisual2);
            grasperVisual2.Children.Add(needleVisual2);

            yolkVisual3.Content = GYmodel;
            grasperVisual3.Children.Clear();
            grasperVisual3.Children.Add(yolkVisual3);
            grasperVisual3.Children.Add(jawOneVisual3);
            grasperVisual3.Children.Add(jawTwoVisual3);
            grasperVisual3.Children.Add(needleVisual3);

            // Define left forearm group
            leftForeBodyVisual.Content = FLmodel;
            leftForeVisual.Children.Clear();
            leftForeVisual.Children.Add(leftForeBodyVisual);
            leftForeVisual.Children.Add(grasperVisual);

            leftForeBodyVisual2.Content = FLmodel;
            leftForeVisual2.Children.Clear();
            leftForeVisual2.Children.Add(leftForeBodyVisual2);
            leftForeVisual2.Children.Add(grasperVisual2);

            leftForeBodyVisual3.Content = FLmodel;
            leftForeVisual3.Children.Clear();
            leftForeVisual3.Children.Add(leftForeBodyVisual3);
            leftForeVisual3.Children.Add(grasperVisual3);
            // Define left arm group
            leftUpperVisual.Content = ULmodel;
            leftVisual.Children.Clear();
            leftVisual.Children.Add(leftUpperVisual);
            leftVisual.Children.Add(leftForeVisual);

            leftUpperVisual2.Content = ULmodel;
            leftVisual2.Children.Clear();
            leftVisual2.Children.Add(leftUpperVisual2);
            leftVisual2.Children.Add(leftForeVisual2);

            leftUpperVisual3.Content = ULmodel;
            leftVisual3.Children.Clear();
            leftVisual3.Children.Add(leftUpperVisual3);
            leftVisual3.Children.Add(leftForeVisual3);
            // workspace
            rightSpaceVisual.Content = RWSmodel;
            leftSpaceVisual.Content = LWSmodel;
            needleVisual.Content = Nmodel;
            staticVisual.Children.Clear();
            staticVisual.Children.Add(rightSpaceVisual);
            staticVisual.Children.Add(leftSpaceVisual);

            // Add left and right arms to full model
            wholeModel.Content = SHmodel;
            wholeModel.Children.Clear();
            wholeModel.Children.Add(rightVisual);
            wholeModel.Children.Add(leftVisual);
            //            wholeModel.Children.Add(staticVisual);

            wholeModel2.Content = SHmodel;
            wholeModel2.Children.Clear();
            wholeModel2.Children.Add(rightVisual2);
            wholeModel2.Children.Add(leftVisual2);

            wholeModel3.Content = SHmodel;
            wholeModel3.Children.Clear();
            wholeModel3.Children.Add(rightVisual3);
            wholeModel3.Children.Add(leftVisual3);

            DisplayModel();
        }
Beispiel #5
0
 private void Load_Click(object sender, RoutedEventArgs e)
 {
     var loader = new ModelImporter();
     Model3D currentModel = loader.Load("T6_S1.stl", Dispatcher.CurrentDispatcher);
     HelixView.Children.Add(new ModelVisual3D { Content = currentModel });
 }
Beispiel #6
0
 /// <summary>
 /// Called when the source or default material changed.
 /// </summary>
 protected virtual void SourceChanged()
 {
     var importer = new ModelImporter { DefaultMaterial = this.DefaultMaterial };
     this.Visual3DModel = this.Source != null ? importer.Load(this.Source) : null;
     this.OnModelLoaded();
 }
        public GraphicalView()
        {
            this.DataContext = this;
            InitializeComponent();
            Sinks = new ObservableDictionary<string, InputSignalViewModel>();

            Sinks.Add("RightUpperBevel", new InputSignalViewModel("RightUpperBevel", "GraphicalView"));
            Sinks.Add("RightLowerBevel", new InputSignalViewModel("RightLowerBevel", "GraphicalView"));
            Sinks.Add("RightElbow", new InputSignalViewModel("RightElbow", "GraphicalView"));
            Sinks.Add("LeftUpperBevel", new InputSignalViewModel("LeftUpperBevel", "GraphicalView"));
            Sinks.Add("LeftLowerBevel", new InputSignalViewModel("LeftLowerBevel", "GraphicalView"));
            Sinks.Add("LeftElbow", new InputSignalViewModel("LeftElbow", "GraphicalView"));
            Sinks.Add("GrasperOpen", new InputSignalViewModel("GrasperOpen", "GraphicalView"));
            Sinks.Add("GrasperTwist", new InputSignalViewModel("GrasperTwist", "GraphicalView"));
            Sinks.Add("CauteryTwist", new InputSignalViewModel("CauteryTwist", "GraphicalView"));
            Sinks.Add("LeftGrasperForce", new InputSignalViewModel("LeftGrasperForce", "GraphicalView"));

            SetupMessenger();

            Random R = new Random();
            for (int i = 0; i < line_colour_array.Length; i++)
            {
                line_colour_array[i] = new Bgr(R.Next(0, 255), R.Next(0, 255), R.Next(0, 255));
            }
            //Run();
            Write_BTN.IsEnabled = false;
            Main_Picturebox.Size = new System.Drawing.Size(820, 820);

            DeviceNames = new ObservableCollection<string>();
            SettingNames = new ObservableCollection<string>();
            _deviceList = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            // Get a list of all video capture source names
            for (int i = 0; i < _deviceList.Count; i++)
            {
                DeviceNames.Add(_deviceList[i].Name);
            }

            // paths to *.stl files
            string startupPath = System.IO.Directory.GetCurrentDirectory();
            startupPath = startupPath + "\\3D Models\\";
            this.dispatcher = Dispatcher.CurrentDispatcher;

            string shoulderPath = startupPath + "Shoulder.stl";
            string upperRightPath = startupPath + "upperRight.stl";
            string upperLeftPath = startupPath + "upperLeft.stl";
            string foreRightPath = startupPath + "cauteryFore.stl";
            string rightTipPath = startupPath + "cauteryHook.stl";
            string foreLeftPath = startupPath + "grasperFore.stl";
            string yolkPath = startupPath + "grasperYolk.stl";
            string jaw1Path = startupPath + "grasperJaw1.stl";
            string jaw2Path = startupPath + "grasperJaw2.stl";
            string rightSpacePath = startupPath + "RightWorkspace.stl";
            string leftSpacePath = startupPath + "LeftWorkspace.stl";

            // Import *.stl files
            var up = new ModelImporter();
            var shoulder = up.Load(shoulderPath, this.dispatcher);
            var upperRightArm = up.Load(upperRightPath, this.dispatcher);
            var upperLeftArm = up.Load(upperLeftPath, this.dispatcher);
            var foreRightArm = up.Load(foreRightPath, this.dispatcher);
            var tipRightArm = up.Load(rightTipPath, this.dispatcher);
            var foreLeftArm = up.Load(foreLeftPath, this.dispatcher);
            var grasperYolk = up.Load(yolkPath, this.dispatcher);
            var grasperJaw1 = up.Load(jaw1Path, this.dispatcher);
            var grasperJaw2 = up.Load(jaw2Path, this.dispatcher);
            var rightSpace = up.Load(rightSpacePath, this.dispatcher);
            var leftSpace = up.Load(leftSpacePath, this.dispatcher);

            // Convert to GeometryModel3d so we can rotate models
            GeometryModel3D SHmodel = shoulder.Children[0] as GeometryModel3D;
            GeometryModel3D URmodel = upperRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D ULmodel = upperLeftArm.Children[0] as GeometryModel3D;
            GeometryModel3D FRmodel = foreRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D FLmodel = foreLeftArm.Children[0] as GeometryModel3D;
            GeometryModel3D TRmodel = tipRightArm.Children[0] as GeometryModel3D;
            GeometryModel3D GYmodel = grasperYolk.Children[0] as GeometryModel3D;
            GeometryModel3D GJ1model = grasperJaw1.Children[0] as GeometryModel3D;
            GeometryModel3D GJ2model = grasperJaw2.Children[0] as GeometryModel3D;
            GeometryModel3D RWSmodel = rightSpace.Children[0] as GeometryModel3D;
            GeometryModel3D LWSmodel = leftSpace.Children[0] as GeometryModel3D;

            // GHOST WHITE // Set model color
            DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Colors.GhostWhite));
            SHmodel.Material = material;
            SHmodel.BackMaterial = material;
            // RED // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
            FRmodel.Material = material;
            FRmodel.BackMaterial = material;
            TRmodel.Material = material;
            TRmodel.BackMaterial = material;
            // DARK RED // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.DarkRed));
            URmodel.Material = material;
            URmodel.BackMaterial = material;
            // GREEN // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Green));
            // BLUE // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Blue));
            GYmodel.Material = material;
            GYmodel.BackMaterial = material;
            GJ1model.Material = material;
            GJ1model.BackMaterial = material;
            GJ2model.Material = material;
            GJ2model.BackMaterial = material;
            FLmodel.Material = material;
            FLmodel.BackMaterial = material;
            // DARK BLUE // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.DarkBlue));
            ULmodel.Material = material;
            ULmodel.BackMaterial = material;
            // BLACK // Set model color
            material = new DiffuseMaterial(new SolidColorBrush(Colors.Black));
            // TRANSPARENT RED // Set model color
            SolidColorBrush brushOne = new SolidColorBrush();
            brushOne.Opacity = 0.50;
            brushOne.Color = Colors.Red;
            material = new DiffuseMaterial(brushOne);
            RWSmodel.Material = material;
            RWSmodel.BackMaterial = material;
            // TRANSPARENT BLUE // Set model color
            SolidColorBrush brushTwo = new SolidColorBrush();
            brushTwo.Opacity = 0.50;
            brushTwo.Color = Colors.Blue;
            material = new DiffuseMaterial(brushTwo);
            LWSmodel.Material = material;
            LWSmodel.BackMaterial = material;

            // right shoulder rotations
            rsyTransform.CenterX = 0;
            rsyTransform.CenterY = 0;
            rsyTransform.CenterZ = 0;
            rightShoulderRotY.Axis = new Vector3D(0, 1, 0);
            rsxTransform.CenterX = 0;
            rsxTransform.CenterY = 0;
            rsxTransform.CenterZ = 0;
            rightShoulderRotX.Axis = new Vector3D(1, 0, 0);
            // right elbow rotations
            relTransform.CenterX = -13.386;
            relTransform.CenterY = 5;
            relTransform.CenterZ = 74.684;
            rightElbow.Axis = new Vector3D(0, 1, 0);
            // right tip rotations
            rTipTransform.CenterX = -15.111;
            rTipTransform.CenterY = 9.515;
            rTipTransform.CenterZ = 0;
            rightTip.Axis = new Vector3D(0, 0, 1);
            //left shoulder rotations
            lsyTransform.CenterX = 14.478;
            lsyTransform.CenterY = 0;
            lsyTransform.CenterZ = 0;
            leftShoulderRotY.Axis = new Vector3D(0, 1, 0);
            lsxTransform.CenterX = 0;
            lsxTransform.CenterY = 0;
            lsxTransform.CenterZ = 0;
            leftShoulderRotX.Axis = new Vector3D(1, 0, 0);
            // left elbow rotations
            lelTransform.CenterX = 27.864;
            lelTransform.CenterY = 0;
            lelTransform.CenterZ = 74.684;
            leftElbow.Axis = new Vector3D(0, 1, 0);
            // grasper rotations
            graspTransform.CenterX = 27.864;
            graspTransform.CenterY = 13.624;
            graspTransform.CenterZ = 0;
            graspOrient1.Axis = new Vector3D(0, 0, 1);
            jaw1Transform.CenterX = 27.864;
            jaw1Transform.CenterZ = 160.284;
            jawAngle1.Axis = new Vector3D(0, 1, 0);
            jaw2Transform.CenterX = 27.864;
            jaw2Transform.CenterZ = 160.284;
            jawAngle2.Axis = new Vector3D(0, 1, 0);

            // Define cautery tip
            rightTipVisual.Content = TRmodel;
            // Define right forearm group
            rightForeBodyVisual.Content = FRmodel;
            rightForeVisual.Children.Clear();
            rightForeVisual.Children.Add(rightForeBodyVisual);
            rightForeVisual.Children.Add(rightTipVisual);
            // Define right arm group
            rightUpperVisual.Content = URmodel;
            rightVisual.Children.Clear();
            rightVisual.Children.Add(rightUpperVisual);
            rightVisual.Children.Add(rightForeVisual);
            // Left grasper open/close
            jawOneVisual.Content = GJ1model;
            jawTwoVisual.Content = GJ2model;
            // Define grasper group
            yolkVisual.Content = GYmodel;
            grasperVisual.Children.Clear();
            grasperVisual.Children.Add(yolkVisual);
            grasperVisual.Children.Add(jawOneVisual);
            grasperVisual.Children.Add(jawTwoVisual);
            // Define left forearm group
            leftForeBodyVisual.Content = FLmodel;
            leftForeVisual.Children.Clear();
            leftForeVisual.Children.Add(leftForeBodyVisual);
            leftForeVisual.Children.Add(grasperVisual);
            // Define left arm group
            leftUpperVisual.Content = ULmodel;
            leftVisual.Children.Clear();
            leftVisual.Children.Add(leftUpperVisual);
            leftVisual.Children.Add(leftForeVisual);
            // workspace
            rightSpaceVisual.Content = RWSmodel;
            leftSpaceVisual.Content = LWSmodel;
            staticVisual.Children.Clear();
            staticVisual.Children.Add(rightSpaceVisual);
            staticVisual.Children.Add(leftSpaceVisual);

            // Add left and right arms to full model
            wholeModel.Content = SHmodel;
            wholeModel.Children.Clear();
            wholeModel.Children.Add(rightVisual);
            wholeModel.Children.Add(leftVisual);
            //            wholeModel.Children.Add(staticVisual);
            DisplayModel();
        }
Beispiel #8
0
        /// <summary>
        /// Called when the source changed.
        /// </summary>
        protected virtual void OnSourceChanged()
        {
            this.Visual3DModel = this.Source != null?ModelImporter.Load(this.Source) : null;

            this.OnModelLoaded();
        }
        public void LoadModel(string path, bool transformYup, double scale)
        {
            var importer = new ModelImporter();
            var mod = importer.Load(path);

            if (mod == null || mod.Children.Count == 0)
                return;

            var model = (mod.Children[0] as GeometryModel3D);
            if (model == null)
                return;

            var mesh = model.Geometry as MeshGeometry3D;
            if (mesh == null)
                return;

            var transform = new Transform3DGroup();
            if (transformYup)
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            for (int i = 0; i < mesh.Positions.Count; i++)
                mesh.Positions[i] = transform.Transform(mesh.Positions[i]);

            ScaleHeightOnly = false;
            Geometry = mesh;
        }
Beispiel #10
0
        private async Task<Model3DGroup> LoadAsync(string model3DPath, bool freeze)
        {
            return await Task.Factory.StartNew(() =>
            {
                var mi = new ModelImporter();

                    // Alt 1. - freeze the model 
                    return mi.Load(model3DPath, null, true);

            });
        }
        private async Task<Model3DGroup> LoadAsync(string model3DPath, bool freeze)
        {
            return await Task.Factory.StartNew(() =>
            {
                var mi = new ModelImporter();
                
                if (freeze)
                {
                    // Alt 1. - freeze the model 
                    return mi.Load(model3DPath, null, true);
                }

                // Alt. 2 - create the model on the UI dispatcher
                return mi.Load(model3DPath, this.dispatcher);
            });
        }
Beispiel #12
0
 public MainViewModel(IFileDialogService fileDialogService, HelixViewport3D viewport)
 {
     this.fileDialogService = fileDialogService;
     this.viewport = viewport;
     modelImporter = new ModelImporter();
 }
        private void Load3DModel(object sender, RoutedEventArgs e)
        {
            Model3DGroup modelgroup = null;

            try
            {
                //Adding a gesture here
                //viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);

                //Import 3D model file
                HelixToolkit.Wpf.ModelImporter import = new HelixToolkit.Wpf.ModelImporter();

                //Load the 3D model file
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "3D files (*.3ds)|*.3ds|All files (*.*)|*.*";
                if (openFileDialog.ShowDialog() == true)
                {
                    modelgroup = import.Load(openFileDialog.FileName);
                    ModelVisual3D model = new ModelVisual3D();
                    model.Content = modelgroup;

                    Vector3D position             = new Vector3D(600, 0, 0);
                    Vector3D axis                 = new Vector3D(1, 0, 0);         //In case you want to rotate it about the x-axis
                    Matrix3D transformationMatrix = model.Content.Transform.Value; //Gets the matrix indicating the current transformation value
                    transformationMatrix.Rotate(new Quaternion(axis, 0));          //Makes a rotation transformation over this matrix
                    //transformationMatrix.RotateAt(new Quaternion(axis, angle), modelCenter); //modelCenter is the Point3D variable indicating the center
                    transformationMatrix.Translate(position);
                    model.Content.Transform = new MatrixTransform3D(transformationMatrix); //Applies the transformation to your model

                    helix_viewport3d.Children.Add(model);

                    Rect3D bounds = model.Content.Bounds;

                    /*
                     * HelixToolkit.Wpf.CombinedManipulator manipulator = new HelixToolkit.Wpf.CombinedManipulator();
                     * manipulator.CanTranslateX = true;
                     * manipulator.CanTranslateY = true;
                     * manipulator.CanTranslateZ = true;
                     * manipulator.CanRotateX = true;
                     * manipulator.CanRotateY = true;
                     * manipulator.CanRotateZ = true;
                     * manipulator.Diameter = Math.Max(bounds.SizeX, Math.Max(bounds.SizeY, bounds.SizeZ)) * 1.2;
                     * manipulator.Position = new Point3D(position.X,position.Y,position.Z);
                     * manipulator.Pivot = new Point3D(position.X, position.Y, position.Z);
                     * manipulator.TargetTransform = model.Transform;
                     * manipulator.Transform = model.Transform;
                     * manipulator.Bind(model);
                     * helix_viewport3d.Children.Add(manipulator);
                     */
                    HelixToolkit.Wpf.TranslateManipulator man_x = new HelixToolkit.Wpf.TranslateManipulator();
                    HelixToolkit.Wpf.TranslateManipulator man_y = new HelixToolkit.Wpf.TranslateManipulator();
                    HelixToolkit.Wpf.TranslateManipulator man_z = new HelixToolkit.Wpf.TranslateManipulator();

                    man_x.Direction       = new Vector3D(1, 0, 0);
                    man_x.Length          = 200;
                    man_x.Diameter        = 20;
                    man_x.Color           = Colors.Red;
                    man_x.Offset          = new Vector3D(30, 0, 0);
                    man_x.Position        = new Point3D(position.X, position.Y, position.Z);
                    man_x.Transform       = model.Transform;
                    man_x.TargetTransform = model.Transform;
                    man_x.Bind(model);

                    man_y.Direction       = new Vector3D(0, 1, 0);
                    man_y.Length          = 200;
                    man_y.Diameter        = 20;
                    man_y.Color           = Colors.Green;
                    man_y.Offset          = new Vector3D(0, 30, 0);
                    man_y.Position        = new Point3D(position.X, position.Y, position.Z);
                    man_y.Transform       = model.Transform;
                    man_y.TargetTransform = model.Transform;
                    man_y.Bind(model);

                    man_z.Direction       = new Vector3D(0, 0, 1);
                    man_z.Length          = 200;
                    man_z.Diameter        = 20;
                    man_z.Color           = Colors.Blue;
                    man_z.Offset          = new Vector3D(0, 0, 30);
                    man_z.Position        = new Point3D(position.X, position.Y, position.Z);
                    man_z.Transform       = model.Transform;
                    man_z.TargetTransform = model.Transform;
                    man_z.Bind(model);

                    helix_viewport3d.Children.Add(man_x);
                    helix_viewport3d.Children.Add(man_y);
                    helix_viewport3d.Children.Add(man_z);
                }
            }
            catch (Exception ex)
            {
                // Handle exception in case can not find the 3D model file
                MessageBox.Show("Exception Error : " + ex.StackTrace);
            }
        }