/////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Initializes a new instance of the <see cref="TextDocumentItemViewModel"/> class.
        /// </summary>
        public VTKDocumentItemViewModel(VTKDataModel dataModel)
        {
            this.Title = string.Format("VTK Doc {0}", counter++);
            this.Text = string.Format("Dynamically created at {0}", DateTime.Now);
            this.Description = "VTK document";
            this.vtkData = dataModel;

            this.CellAttributeArrayNames = new ObservableCollection<string>();
            this.CellAttributeArrayNames.Add(this.vtkData.CellIdsArrayName);
            this.CellAttributeArrayNames.Add(this.vtkData.CellTypeArrayName);
            this.cellColorArrayName = this.CellAttributeArrayNames[0];
            this.cellColorMapSpaceModel = ColorSpaceModel.HSV;

            // create a VTK output control and make the forms host point to it
            rwc = new RenderWindowControl();
            wfh = new WindowsFormsHost();
            wfh.Child = rwc;
            rwc.CreateGraphics();
            rwc.RenderWindow.SetCurrentCursor(9);

            vtkInteractorStyleSwitch istyle = vtkInteractorStyleSwitch.New();
            rwc.RenderWindow.GetInteractor().SetInteractorStyle(istyle);
            rwc.RenderWindow.GetInteractor().SetPicker(vtkCellPicker.New());
            (istyle).SetCurrentStyleToTrackballCamera();

            rwc.RenderWindow.GetInteractor().LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(leftMouseDown);

            // set up basic viewing
            ren = rwc.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkCamera camera = ren.GetActiveCamera();

            // background color
            ren.SetBackground(0.1, 0.1, 0.1);

            vtkSphereSource sph = vtkSphereSource.New();
            sph.SetThetaResolution(16);
            sph.SetPhiResolution(16);
            sph.SetRadius(0.02);

            vtkGlyph3D glyp = vtkGlyph3D.New();
            glyp.SetSourceConnection(sph.GetOutputPort(0));
            glyp.SetInputConnection(this.vtkData.OutputPort);
            glyp.ScalingOff();
            glyp.OrientOff();

            ctf = vtkColorTransferFunction.New();
            ctf_min_color = System.Windows.Media.Color.FromRgb(0, 128, 255);
            ctf_max_color = System.Windows.Media.Color.FromRgb(64, 255, 64);
            this.BuildCTF();

            //lut.SetValueRange(0.5, 1.0);
            //lut.SetSaturationRange(0.1, 1.0);
            //lut.SetHueRange(0.4, 0.6);
            //lut.SetAlphaRange(0.2, 1.0);
            //lut.SetRampToLinear();
            //lut.Build();

            mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(glyp.GetOutputPort());
            mapper.SetLookupTable(ctf);
            mapper.ScalarVisibilityOn();
            mapper.SetScalarModeToUsePointFieldData();
            mapper.SelectColorArray(this.cellColorArrayName);
            // scalar range doens't affect anything when using a ctf (instead of a lut)
            // mapper.SetScalarRange(0, this.vtkData.NumPoints - 1);

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            //actor.GetProperty().SetRepresentationToWireframe();
            actor.GetProperty().SetRepresentationToSurface();
            rwc.RenderWindow.GetRenderers().GetFirstRenderer().AddViewProp(actor);
            ren.ResetCamera();
        }
Пример #2
0
 /// <summary>
 /// Adds new TextDocument to documentItems.
 /// Only accessible internally or through command binding to NewDocumentCommand
 /// </summary>
 /// <param name="parameter">Sets type of document ("TextDocument" or "VTKDocument").</param>
 private void AddNewDocument(object parameter)
 {
     string doc_type = (string)parameter;
     if (doc_type != null)
     {
         if (doc_type == "TextDocument")
         {
             this.documentItems.Add(new TextDocumentItemViewModel());
         }
         else if (doc_type == "VTKDocument")
         {
             // Not creating VTKDataModel unless a window is open,
             // but I don't know how to get rid of it on last close...
             if (this.vtkModel == null)
             {
                 this.vtkModel = new VTKDataModel(this.simModel);
             }
             VTKDocumentItemViewModel vtk_mod = new VTKDocumentItemViewModel(this.vtkModel);
             // TODO: This should be done through messaging, not property changed events...
             // TODO: This type of thing probably leaks memory on VTK doc window closure...
             vtk_mod.PropertyChanged += this.VTKModelPropertyChanged;
             this.documentItems.Add(vtk_mod);
             // MessageBoxResult tmp = MessageBox.Show("Added a VTK view.");
         }
     }
 }