private void ReadPLOT3D() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); string filePathXYZ = System.IO.Path.Combine(root, @"Data\bluntfinxyz.bin"); string filePathQ = System.IO.Path.Combine(root, @"Data\bluntfinq.bin"); //string filePathXYZ = System.IO.Path.Combine(root, @"Data\combxyz.bin"); //string filePathQ = System.IO.Path.Combine(root, @"Data\combq.bin"); vtkMultiBlockPLOT3DReader reader = vtkMultiBlockPLOT3DReader.New(); reader.SetXYZFileName(filePathXYZ); reader.SetQFileName(filePathQ); // Specify the scalar function to extract. If ==(-1), then no scalar function is extracted. int scalarFctNo = reader.GetScalarFunctionNumber(); int vectorFctNo = reader.GetVectorFunctionNumber(); if(scalarFctNo != -1) reader.SetScalarFunctionNumber(scalarFctNo); // Specify the vector function to extract. If ==(-1), then no vector function is extracted. if(vectorFctNo != -1) reader.SetVectorFunctionNumber(vectorFctNo); reader.Update(); //// geometry filter //// This filter is multi-block aware and will request blocks from the //// input. These blocks will be processed by simple processes as if they //// are the whole dataset //vtkCompositeDataGeometryFilter geom1 = vtkCompositeDataGeometryFilter.New(); //geom1.SetInputConnection(0, reader.GetOutputPort(0)); vtkStructuredGridGeometryFilter geometryFilter = vtkStructuredGridGeometryFilter.New(); geometryFilter.SetInput(reader.GetOutput().GetBlock(0)); //geometryFilter.SetInputConnection(geom1.GetOutputPort(0)); geometryFilter.Update(); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(geometryFilter.GetOutputPort()); //mapper.SetInputConnection(geom1.GetOutputPort()); mapper.ScalarVisibilityOn(); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(actor); }
private void ReadPDB() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); string filePath = System.IO.Path.Combine(root, @"Data\caffeine.pdb"); vtkPDBReader pdb = vtkPDBReader.New(); pdb.SetFileName(filePath); pdb.SetHBScale(1.0); pdb.SetBScale(1.0); pdb.Update(); Debug.WriteLine("# of atoms is: " + pdb.GetNumberOfAtoms()); // if molecule contains a lot of atoms, reduce the resolution of the sphere (represents an atom) for faster rendering int resolution = (int)Math.Floor(Math.Sqrt(300000.0 / pdb.GetNumberOfAtoms())); // 300000.0 is an empriric value if (resolution > 20) { resolution = 20; } else if (resolution < 4) { resolution = 4; } Debug.WriteLine("Resolution is: " + resolution); vtkSphereSource sphere = vtkSphereSource.New(); sphere.SetCenter(0, 0, 0); sphere.SetRadius(1); sphere.SetThetaResolution(resolution); sphere.SetPhiResolution(resolution); vtkGlyph3D glyph = vtkGlyph3D.New(); glyph.SetInputConnection(pdb.GetOutputPort()); glyph.SetOrient(1); glyph.SetColorMode(1); // glyph.ScalingOn(); glyph.SetScaleMode(2); glyph.SetScaleFactor(.25); glyph.SetSourceConnection(sphere.GetOutputPort()); vtkPolyDataMapper atomMapper = vtkPolyDataMapper.New(); atomMapper.SetInputConnection(glyph.GetOutputPort()); atomMapper.UseLookupTableScalarRangeOff(); atomMapper.ScalarVisibilityOn(); atomMapper.SetScalarModeToDefault(); vtkLODActor atom = vtkLODActor.New(); atom.SetMapper(atomMapper); atom.GetProperty().SetRepresentationToSurface(); atom.GetProperty().SetInterpolationToGouraud(); atom.GetProperty().SetAmbient(0.15); atom.GetProperty().SetDiffuse(0.85); atom.GetProperty().SetSpecular(0.1); atom.GetProperty().SetSpecularPower(30); atom.GetProperty().SetSpecularColor(1, 1, 1); atom.SetNumberOfCloudPoints(30000); vtkTubeFilter tube = vtkTubeFilter.New(); tube.SetInputConnection(pdb.GetOutputPort()); tube.SetNumberOfSides(resolution); tube.CappingOff(); tube.SetRadius(0.2); // turn off variation of tube radius with scalar values tube.SetVaryRadius(0); tube.SetRadiusFactor(10); vtkPolyDataMapper bondMapper = vtkPolyDataMapper.New(); bondMapper.SetInputConnection(tube.GetOutputPort()); bondMapper.UseLookupTableScalarRangeOff(); bondMapper.ScalarVisibilityOff(); bondMapper.SetScalarModeToDefault(); vtkLODActor bond = vtkLODActor.New(); bond.SetMapper(bondMapper); bond.GetProperty().SetRepresentationToSurface(); bond.GetProperty().SetInterpolationToGouraud(); bond.GetProperty().SetAmbient(0.15); bond.GetProperty().SetDiffuse(0.85); bond.GetProperty().SetSpecular(0.1); bond.GetProperty().SetSpecularPower(30); bond.GetProperty().SetSpecularColor(1, 1, 1); bond.GetProperty().SetDiffuseColor(1.0000, 0.8941, 0.70981); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(atom); renderer.AddActor(bond); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVlabeledContours(String [] argv) { //Prefix Content is: "" // demonstrate labeling of contour with scalar value[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Read a slice and contour it[] v16 = new vtkVolume16Reader(); v16.SetDataDimensions((int)64,(int)64); v16.GetOutput().SetOrigin((double)0.0,(double)0.0,(double)0.0); v16.SetDataByteOrderToLittleEndian(); v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter"); v16.SetImageRange((int)45,(int)45); v16.SetDataSpacing((double)3.2,(double)3.2,(double)1.5); iso = new vtkContourFilter(); iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort()); iso.GenerateValues((int)6,(double)500,(double)1150); iso.Update(); numPts = iso.GetOutput().GetNumberOfPoints(); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); isoMapper.ScalarVisibilityOn(); isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); // Subsample the points and label them[] mask = new vtkMaskPoints(); mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); mask.SetOnRatio((int)(numPts/50)); mask.SetMaximumNumberOfPoints((int)50); mask.RandomModeOn(); // Create labels for points - only show visible points[] visPts = new vtkSelectVisiblePoints(); visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); visPts.SetRenderer((vtkRenderer)ren1); ldm = new vtkLabeledDataMapper(); ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort()); // ldm SetLabelFormat "%g"[] ldm.SetLabelModeToLabelScalars(); tprop = ldm.GetLabelTextProperty(); tprop.SetFontFamilyToArial(); tprop.SetFontSize((int)10); tprop.SetColor((double)1,(double)0,(double)0); contourLabels = new vtkActor2D(); contourLabels.SetMapper((vtkMapper2D)ldm); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor2D((vtkProp)isoActor); ren1.AddActor2D((vtkProp)contourLabels); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)500,(int)500); renWin.Render(); ren1.GetActiveCamera().Zoom((double)1.5); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // 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(); }
public void ScalarVisibilityOn() { _polyDataMapper.ScalarVisibilityOn(); _polyDataMapper.Modified(); actor.Modified(); }