示例#1
0
 public void OnDrop(object sender, DragEventArgs e)
 {
     if (!e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         return;
     }
     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     if (files != null)
     {
         foreach (string file in files)
         {
             string extension = Path.GetExtension(file)?.ToLower();
             //判斷當前的檔案副檔名是否為stl,不是的話則跳過
             if (extension != null && !extension.Equals(".stl"))
             {
                 continue;
             }
             BoneModel model = new BoneModel
             {
                 FilePath         = file,
                 MarkerId         = "",
                 BoneDiffuseColor = System.Windows.Media.Color.FromArgb(255, 40, 181, 187),
                 Transform        = new MatrixTransform3D()
             };
             model.LoadModel();
             MultiAngleViewModel.NormalModelCollection.Add(model);
         }
     }
     MultiAngleViewModel.ResetCameraPosition();
 }
示例#2
0
 public MultiAngleView()
 {
     InitializeComponent();
     MultiAngleViewModel = new MultiAngleViewModel(this);
     this.DataContext    = MultiAngleViewModel; //將_multiAngleViewModel的資料環境傳給此DataContext
 }
示例#3
0
 private void Reset(object o)
 {
     MultiAngleViewModel.ResetCameraPosition();
 }
示例#4
0
        /// <summary>
        /// 開啟儲存的專案
        /// </summary>
        public void ImportProject(string filename)
        {
            string fullFilePath = filename;

            switch (System.IO.Path.GetExtension(fullFilePath).ToLower())
            {
            case ".nart":
            {
                string projectName   = System.IO.Path.GetFileNameWithoutExtension(fullFilePath); //檔名不包含副檔名
                string filePath      = System.IO.Path.GetDirectoryName(fullFilePath);            //路徑
                string tempDirectory = System.IO.Path.Combine(filePath, projectName);            //路徑+檔名(不包含副檔名)

                Directory.CreateDirectory(tempDirectory);
                ZipFile.ExtractToDirectory(fullFilePath, tempDirectory);

                string xmlFilePath = System.IO.Path.Combine(tempDirectory, projectName + ".xml");
                if (!File.Exists(xmlFilePath))
                {
                    return;
                }

                ProjectData projectData;
                using (FileStream myFileStream = new FileStream(xmlFilePath, FileMode.Open))
                {
                    SoapFormatter soapFormatter = new SoapFormatter();
                    projectData = (ProjectData)soapFormatter.Deserialize(myFileStream);
                    myFileStream.Close();
                }

                //尋訪每個BoneModel
                foreach (BoneModel boneModel in projectData.BoneCollection)
                {
                    //BoneModel boneModel = projectData.BoneCollection[i];
                    boneModel.FilePath = System.IO.Path.Combine(tempDirectory, boneModel.SafeFileName);
                    boneModel.LoadModel();
                    //取得當前為MovedMaxilla的模型
                    if (boneModel.ModelType == ModelType.MovedMaxilla)
                    {
                        foreach (BoneModel targetModel in projectData.TargetCollection)
                        {
                            if (targetModel.ModelType == ModelType.TargetMaxilla)
                            {
                                targetModel.FilePath = boneModel.FilePath;
                                targetModel.LoadModel();
                            }
                        }

                        foreach (BallModel ballModel in projectData.BallCollection)
                        {
                            if (ballModel.ModelType == ModelType.MovedMaxilla)
                            {
                                ballModel.Transform = boneModel.Transform;
                            }
                        }
                    }
                    else if (boneModel.ModelType == ModelType.MovedMandible)
                    {
                        foreach (BoneModel targetModel in projectData.TargetCollection)
                        {
                            if (targetModel.ModelType == ModelType.TargetMandible)
                            {
                                targetModel.FilePath = boneModel.FilePath;
                                targetModel.LoadModel();
                            }
                        }

                        foreach (BallModel ballModel in projectData.BallCollection)
                        {
                            if (ballModel.ModelType == ModelType.MovedMandible)
                            {
                                ballModel.Transform = boneModel.Transform;
                            }
                        }
                    }
                }



                MainViewModel.ProjData.UpdateData(projectData);
                MultiAngleViewModel.ResetCameraPosition();
                System.IO.Directory.Delete(tempDirectory, true);

                if (MainViewModel.ProjData.IsNavDone)
                {
                    ShowFinalInfo();
                }

                break;
            }
            }
        }
示例#5
0
        public void LoadSettingModel(object o)
        {
            MainViewModel.ProjData.TargetCollection.Clear();
            MainViewModel.ProjData.BoneCollection.Clear();
            MultiAngleViewModel.OspModelCollection.Clear();
            MultiAngleViewModel.TriangleModelCollection.Clear();



            //讀取原始上下顎 加上 規劃後的轉移矩陣
            Matrix    plannedMatrix = ReadMatrixFile(_plannedMaxillaMatrix);
            BoneModel targetMaxilla = new BoneModel
            {
                FilePath         = MaxillaModel,
                IsRendering      = false,
                MarkerId         = "",
                ModelType        = ModelType.TargetMaxilla,
                BoneDiffuseColor = Color.FromArgb(255, 100, 100, 100),
                Transform        = new MatrixTransform3D(plannedMatrix.ToMatrix3D())
            };

            targetMaxilla.LoadModel();

            Matrix    plannedMandible = ReadMatrixFile(_plannedMandibleMatrix);
            BoneModel targetMandible  = new BoneModel
            {
                FilePath         = MandibleModel,
                IsRendering      = false,
                MarkerId         = "",
                ModelType        = ModelType.TargetMandible,
                BoneDiffuseColor = Color.FromArgb(255, 100, 100, 100),
                Transform        = new MatrixTransform3D(plannedMandible.ToMatrix3D())
            };

            targetMandible.LoadModel();

            //MainViewModel.Data.TargetCollection.Add(head);
            MainViewModel.ProjData.TargetCollection.Add(targetMaxilla);
            MainViewModel.ProjData.TargetCollection.Add(targetMandible);

            BoneModel head = new BoneModel
            {
                FilePath         = HeadModel,
                MarkerId         = "Head",
                ModelType        = ModelType.Head,
                BoneDiffuseColor = HeadDiffuseColor
            };

            head.LoadModel();
            BoneModel oriMaxilla = new BoneModel
            {
                FilePath         = MaxillaModel,
                ModelType        = ModelType.MovedMaxilla,
                MarkerId         = "Splint",
                BoneDiffuseColor = MaxillaDiffuseColor
            };

            oriMaxilla.LoadModel();
            BoneModel oriMandible = new BoneModel
            {
                FilePath         = MandibleModel,
                ModelType        = ModelType.MovedMandible,
                MarkerId         = "Splint",
                BoneDiffuseColor = MandibleDiffuseColor
            };

            oriMandible.LoadModel();

            MainViewModel.ProjData.BoneCollection.Add(head);
            MainViewModel.ProjData.BoneCollection.Add(oriMaxilla);
            MainViewModel.ProjData.BoneCollection.Add(oriMandible);

            //載入OSP模型
            OspModel headOsp = new OspModel
            {
                MarkerId     = "Head",
                FilePath     = HeadOsp,
                DiffuseColor = Color.FromArgb(50, 11, 243, 243)
            };

            headOsp.LoadOsp();

            OspModel mandibleOsp = new OspModel
            {
                MarkerId     = "C",
                FilePath     = MandibleOsp,
                DiffuseColor = Color.FromArgb(50, 2, 231, 2)
            };

            mandibleOsp.LoadOsp();

            //綁定下顎對稱面到下顎模型
            SetBinding(oriMandible, mandibleOsp, "Transform", HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, BindingMode.OneWay);
            MultiAngleViewModel.OspModelCollection.Add(headOsp);
            MultiAngleViewModel.OspModelCollection.Add(mandibleOsp);

            //標記屬於上顎的ID,綁定到目標上顎
            DraggableTriangle maxillaTargetTriangle = new DraggableTriangle(targetMaxilla.ModelCenter)
            {
                MarkerId    = "Maxilla",
                IsRendering = false,
                Transform   = targetMaxilla.Transform,
                ModelType   = ModelType.TargetMaxillaTriangle,
            };

            //標記屬於下顎的ID,綁定到目標下顎
            DraggableTriangle mandibleTargetTriangle = new DraggableTriangle(targetMandible.ModelCenter)
            {
                MarkerId    = "Mandible",
                IsRendering = false,
                Transform   = targetMandible.Transform,
                ModelType   = ModelType.TargetMandibleTriangle,
            };



            //將導航三角形綁定到導航的上顎
            DraggableTriangle maxillaTriangle = new DraggableTriangle(oriMaxilla.ModelCenter)
            {
                MarkerId     = "Maxilla",
                Transparency = 0.5f,
                IsRendering  = false,
                ModelType    = ModelType.MovedMaxillaTriangle,
            };

            SetBinding(oriMaxilla, maxillaTriangle, "Transform", HelixToolkit.Wpf.SharpDX.GroupModel3D.TransformProperty, BindingMode.OneWay);



            //將導航三角形綁定到導航的下顎
            DraggableTriangle mandibleTriangle = new DraggableTriangle(oriMandible.ModelCenter)
            {
                MarkerId     = "Mandible",
                Transparency = 0.5f,
                IsRendering  = false,
                ModelType    = ModelType.MovedMandibleTriangle,
            };

            SetBinding(oriMandible, mandibleTriangle, "Transform", HelixToolkit.Wpf.SharpDX.GroupModel3D.TransformProperty, BindingMode.OneWay);

            MultiAngleViewModel.TriangleModelCollection.Add(maxillaTargetTriangle);
            MultiAngleViewModel.TriangleModelCollection.Add(mandibleTargetTriangle);
            MultiAngleViewModel.TriangleModelCollection.Add(maxillaTriangle);
            MultiAngleViewModel.TriangleModelCollection.Add(mandibleTriangle);



            MultiAngleViewModel.ResetCameraPosition();

            MainViewModel.ProjData.IsNavSet = true;

            _navigateView.Hide();
        }
示例#6
0
        /// <summary>
        ///將設置清單的每個Item Load進檔案,並轉成模型清單
        /// </summary>
        public void LoadSettingModel(object o)
        {
            //確保所有模型資訊都有set進去ModelInfo的資料
            for (int i = 0; i < ModelSettingCollection.Count; i++)
            {
                //Load模型檔,內部有防呆防止重複Load
                ModelSettingCollection[i].Load();

                OspModel  ospModel  = ModelSettingCollection[i].Osp;
                BoneModel boneModel = ModelSettingCollection[i].Bone;

                //確認有Load過且有沒有被加進去modelDataCollection
                if (ospModel.IsLoaded && !ospModel.IsAdded)
                {
                    MultiAngleViewModel.OspModelCollection.Add(ModelSettingCollection[i].Osp);
                    ModelSettingCollection[i].Osp.IsAdded = true;
                }
                //確認有Load過且有沒有被加進去modelDataCollection
                if (boneModel.IsLoaded && !boneModel.IsAdded)
                {
                    MainViewModel.ProjData.BoneCollection.Add(ModelSettingCollection[i].Bone);
                    ModelSettingCollection[i].Bone.IsAdded = true;
                    //除了頭部以外需要guide
                    if (!boneModel.MarkerId.Equals("Head") && !boneModel.MarkerId.Equals("C"))
                    {
                        ModelSettingCollection[i].Guide = new DraggableTriangle(boneModel.ModelCenter);

                        MultiAngleViewModel.TriangleModelCollection.Add(ModelSettingCollection[i].Guide);
                    }
                }
                //做bone 跟 osp transform的binding
                if (boneModel.IsLoaded && ospModel.IsAdded)
                {
                    var binding = new Binding("Transform");
                    binding.Source = boneModel;
                    binding.Mode   = BindingMode.OneWay;
                    BindingOperations.SetBinding(ospModel, Model3D.TransformProperty, binding);
                }
                //做bone 的轉移矩陣綁到 DraggableTriangle的ModelTransform上面
                if (boneModel.IsLoaded && ModelSettingCollection[i].Guide != null)
                {
                    var binding = new Binding("Transform");
                    binding.Source = boneModel;
                    binding.Mode   = BindingMode.OneWay;
                    BindingOperations.SetBinding(ModelSettingCollection[i].Guide, HelixToolkit.Wpf.SharpDX.GroupModel3D.TransformProperty, binding);
                }
            }
            //刪除modelDataCollection中已經從ModelInfoCollection移除的模型,
            for (int i = 0; i < MainViewModel.ProjData.BoneCollection.Count; i++)
            {
                BoneModel boneModel = MainViewModel.ProjData.BoneCollection[i] as BoneModel;
                //模型如果透過 - 移除 或是 因為換錯誤檔名造成IsLoaded 為false則直接移除
                if (boneModel.IsRemoved || !boneModel.IsLoaded)
                {
                    MainViewModel.ProjData.BoneCollection.RemoveAt(i);
                    boneModel.IsAdded = false;
                    i--;
                }
            }


            //刪除modelDataCollection中已經從ModelInfoCollection移除的模型,
            for (int i = 0; i < MultiAngleViewModel.OspModelCollection.Count; i++)
            {
                OspModel ospModel = MultiAngleViewModel.OspModelCollection[i] as OspModel;
                //模型如果透過 - 移除 或是 因為換錯誤檔名造成IsLoaded 為false則直接移除
                if (ospModel.IsRemoved || !ospModel.IsLoaded)
                {
                    MultiAngleViewModel.OspModelCollection.RemoveAt(i);
                    ospModel.IsAdded = false;
                    i--;
                }
            }

            Console.WriteLine("OSP 數量:" + MultiAngleViewModel.OspModelCollection.Count);
            Console.WriteLine("Bone  數量:" + MainViewModel.ProjData.BoneCollection.Count);



            MultiAngleViewModel.ResetCameraPosition();

            _modelSettingView.Hide();
        }