Esempio n. 1
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();
        }
Esempio n. 2
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();
        }