/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVPlot3DVectors(String [] argv) { //Prefix Content is: "" //[] // All Plot3D vector functions[] //[] // Create the RenderWindow, Renderer and both Actors[] //[] renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); ren1 = vtkRenderer.New(); ren1.SetBackground((double).8, (double).8, (double).2); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); vectorLabels = "Velocity Vorticity Momentum Pressure_Gradient"; vectorFunctions = "200 201 202 210"; camera = new vtkCamera(); light = new vtkLight(); // All text actors will share the same text prop[] textProp = new vtkTextProperty(); textProp.SetFontSize((int)10); textProp.SetFontFamilyToArial(); textProp.SetColor((double).3, (double)1, (double)1); i = 0; foreach (string vectorFunction in vectorFunctions.Split(new char[] { ' ' })) { pl3d[getArrayIndex(vectorFunction)] = new vtkMultiBlockPLOT3DReader(); pl3d[getArrayIndex(vectorFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin"); pl3d[getArrayIndex(vectorFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin"); pl3d[getArrayIndex(vectorFunction)].SetVectorFunctionNumber((int)(int)(getArrayIndex(vectorFunction))); pl3d[getArrayIndex(vectorFunction)].Update(); plane[getArrayIndex(vectorFunction)] = new vtkStructuredGridGeometryFilter(); plane[getArrayIndex(vectorFunction)].SetInputData((vtkDataSet)pl3d[getArrayIndex(vectorFunction)].GetOutput().GetBlock(0)); plane[getArrayIndex(vectorFunction)].SetExtent((int)25, (int)25, (int)0, (int)100, (int)0, (int)100); hog[getArrayIndex(vectorFunction)] = new vtkHedgeHog(); hog[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(vectorFunction)].GetOutputPort()); maxnorm = ((vtkDataSet)pl3d[getArrayIndex(vectorFunction)].GetOutput().GetBlock(0)).GetPointData().GetVectors().GetMaxNorm(); hog[getArrayIndex(vectorFunction)].SetScaleFactor((double)1.0 / maxnorm); mapper[getArrayIndex(vectorFunction)] = vtkPolyDataMapper.New(); mapper[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)hog[getArrayIndex(vectorFunction)].GetOutputPort()); actor[getArrayIndex(vectorFunction)] = new vtkActor(); actor[getArrayIndex(vectorFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(vectorFunction)]); ren[getArrayIndex(vectorFunction)] = vtkRenderer.New(); ren[getArrayIndex(vectorFunction)].SetBackground((double)0.5, (double).5, (double).5); ren[getArrayIndex(vectorFunction)].SetActiveCamera((vtkCamera)camera); ren[getArrayIndex(vectorFunction)].AddLight((vtkLight)light); renWin.AddRenderer(ren[getArrayIndex(vectorFunction)]); ren[getArrayIndex(vectorFunction)].AddActor((vtkProp)actor[getArrayIndex(vectorFunction)]); textMapper[getArrayIndex(vectorFunction)] = new vtkTextMapper(); textMapper[getArrayIndex(vectorFunction)].SetInput(vectorLabels.Split(new char[] { ' ' })[i]); textMapper[getArrayIndex(vectorFunction)].SetTextProperty((vtkTextProperty)textProp); text[getArrayIndex(vectorFunction)] = new vtkActor2D(); text[getArrayIndex(vectorFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(vectorFunction)]); text[getArrayIndex(vectorFunction)].SetPosition((double)2, (double)5); ren[getArrayIndex(vectorFunction)].AddActor2D((vtkProp)text[getArrayIndex(vectorFunction)]); i = i + 1; } //[] // now layout renderers[] column = 1; row = 1; deltaX = 1.0 / 2.0; deltaY = 1.0 / 2.0; foreach (string vectorFunction in vectorFunctions.Split(new char[] { ' ' })) { ren[getArrayIndex(vectorFunction)].SetViewport((double)(column - 1) * deltaX + (deltaX * .05), (double)(row - 1) * deltaY + (deltaY * .05), (double)column * deltaX - (deltaX * .05), (double)row * deltaY - (deltaY * .05)); column = column + 1; if ((column) > 2) { column = 1; row = row + 1; } } camera.SetViewUp((double)1, (double)0, (double)0); camera.SetFocalPoint((double)0, (double)0, (double)0); camera.SetPosition((double).4, (double)-.5, (double)-.75); ren[200].ResetCamera(); camera.Dolly((double)1.25); ren[200].ResetCameraClippingRange(); ren[201].ResetCameraClippingRange(); ren[202].ResetCameraClippingRange(); ren[210].ResetCameraClippingRange(); light.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]); light.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]); renWin.SetSize(350, 350); renWin.Render(); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/* * In this function, first need to build the color table, * and then add the text */ public void VTKInfoBuilder(ref vtkActor2D actor) { vtkActor2D colorTextActor = new vtkActor2D(); vtkTextMapper colorText = new vtkTextMapper(); colorTextActor.SetMapper(colorText); //Generate the string: string outPutChartString = ""; outPutChartString += "[Model Details]\n"; outPutChartString += "Phase: " + WorkSpaceInstance.Env.GetModelGeneratingPhase() + "\n"; outPutChartString += "ModelType: " + WorkSpaceInstance.Env.GetModelTypeString() + "\n"; outPutChartString += "Model Name: " + WorkSpaceInstance.Env.GetCurrentTowerModelName() + "\n"; outPutChartString += "\n"; outPutChartString += "Min: " + TowerModelInstance.GetColorGenColorTableMinvalue().ToString() + " Max: " + TowerModelInstance.GetColorGenColorTableMaxValue().ToString() + "\n"; colorText.SetInput(outPutChartString); colorText.GetTextProperty().SetFontSize(12); colorText.GetTextProperty().SetFontFamilyToArial(); //colorText.GetTextProperty().SetColor(225, 39, 39); colorTextActor.SetDisplayPosition(20, 50); actor = colorTextActor; }
void Test() { foreach (var actor in m_actorDict.Keys) { int xmin = 0; int xlength = 1000; int xmax = xmin + xlength; int ymin = 0; int ylength = 1000; int ymax = ymin + ylength; int[] pos = { xmin, xmin + xlength, ymin, ymin + ylength }; #region RECT vtkPoints pts = vtkPoints.New(); pts.InsertPoint(0, xmin, ymin, 0); pts.InsertPoint(1, xmax, ymin, 0); pts.InsertPoint(2, xmax, ymax, 0); pts.InsertPoint(3, xmin, ymax, 0); vtkCellArray rect = vtkCellArray.New(); rect.InsertNextCell(5); rect.InsertCellPoint(0); rect.InsertCellPoint(1); rect.InsertCellPoint(2); rect.InsertCellPoint(3); rect.InsertCellPoint(0); vtkPolyData selectRect = vtkPolyData.New(); selectRect.SetPoints(pts); selectRect.SetLines(rect); vtkPolyDataMapper2D rectMapper = vtkPolyDataMapper2D.New(); rectMapper.SetInput(selectRect); vtkActor2D rectActor = vtkActor2D.New(); rectActor.SetMapper(rectMapper); m_render.AddActor(rectActor); #endregion vtkIdFilter ids = vtkIdFilter.New(); ids.SetInput(actor.GetMapper().GetInput()); //ids.SetInputConnection( actor.GetMapper().GetOutputPort()); ids.PointIdsOn(); ids.FieldDataOn(); vtkSelectVisiblePoints visPts = vtkSelectVisiblePoints.New(); visPts.SetInput(ids.GetOutput()); visPts.SetRenderer(m_render); visPts.SelectInvisibleOn(); visPts.SelectionWindowOn(); //visPts.SelectInvisibleOff(); visPts.SetSelection(pos[0], pos[1], pos[2], pos[3]); vtkLabeledDataMapper labelMapper = vtkLabeledDataMapper.New(); labelMapper.SetInputConnection(visPts.GetOutputPort()); // labelMapper.SetInput(visPts.GetInput()); labelMapper.SetLabelModeToLabelFieldData(); vtkActor2D actor2d = vtkActor2D.New(); actor2d.SetMapper(labelMapper); m_render.AddActor(actor2d); } m_render.Render(); }
private void CreateViewportBorder(vtkRenderer renderer, double[] color) { ModelLoaded = false; // points start at upper right and proceed anti-clockwise vtkPoints points = vtkPoints.New(); points.SetNumberOfPoints(4); points.InsertPoint(0, 1, 1, 0); points.InsertPoint(1, 1e-3, 1, 0); points.InsertPoint(2, 1e-3, 1e-3, 0); points.InsertPoint(3, 1, 1e-3, 0); // create cells, and lines vtkCellArray cells = vtkCellArray.New(); cells.Initialize(); vtkPolyLine lines = vtkPolyLine.New(); lines.GetPointIds().SetNumberOfIds(5); for (int i = 0; i < 4; ++i) { lines.GetPointIds().SetId(i, i); } lines.GetPointIds().SetId(4, 0); cells.InsertNextCell(lines); // now make tge polydata and display it vtkPolyData poly = vtkPolyData.New(); poly.Initialize(); poly.SetPoints(points); poly.SetLines(cells); // use normalized viewport coordinates since // they are independent of window size vtkCoordinate coordinate = vtkCoordinate.New(); coordinate.SetCoordinateSystemToNormalizedViewport(); vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New(); mapper.SetInput(poly); mapper.SetTransformCoordinate(coordinate); vtkActor2D actor = vtkActor2D.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(color[0], color[1], color[2]); // line width should be at least 2 to be visible at extremes actor.GetProperty().SetLineWidth((float)2.0); // Line Width renderer.AddViewProp(actor); }
private vtkActor2D VirtualHeaterVTKBuilder() { vtkActor2D actor = vtkActor2D.New(); vtkPoints pointSource = vtkPoints.New(); vtkStringArray labels = vtkStringArray.New(); vtkCellArray verts = vtkCellArray.New(); TowerModelInstance.VTKLabelGetter(ref pointSource, ref labels, ref verts, paras, WorkSpaceInstance); //MessageBox.Show(labels.ToString()); vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(pointSource); polyData.SetVerts(verts); polyData.GetPointData().AddArray(labels); vtkTextProperty textProp = vtkTextProperty.New(); textProp.SetFontSize(12); //textProp.SetColor(1.0, 1.0, 0.5); textProp.SetFontFamilyToArial(); vtkPointSetToLabelHierarchy hie = vtkPointSetToLabelHierarchy.New(); hie.SetInput(polyData); hie.SetMaximumDepth(15); hie.SetLabelArrayName("111"); hie.SetTargetLabelCount(100); hie.SetTextProperty(textProp); vtkLabelPlacementMapper labelMapper = new vtkLabelPlacementMapper(); labelMapper.SetInputConnection(hie.GetOutputPort()); vtkFreeTypeLabelRenderStrategy strategy = new vtkFreeTypeLabelRenderStrategy(); labelMapper.SetRenderStrategy(strategy); labelMapper.UseDepthBufferOn(); labelMapper.SetShapeToNone(); labelMapper.SetStyleToOutline(); //labelMapper.UseUnicodeStringsOff(); actor.SetMapper(labelMapper); return(actor); }
//vtkPoints points = vtkPoints.New(); //points.InsertNextPoint(0.0, 0.0, 0.0); //points.InsertNextPoint(200.0, 0.0, 0.0); //points.InsertNextPoint(200.0, 200.0, 0.0); //points.InsertNextPoint(0.0, 200.0, 0.0); //points.InsertNextPoint(0.0, 0.0, 0.0); //vtkPolygon polygon = vtkPolygon.New(); //polygon.GetPointIds().SetNumberOfIds(5); //for (int i = 0; i < 5; i++) //{ // polygon.GetPointIds().SetId(i, i); //} public vtkActor2D AddMarkerLine(double[] startCoords, double[] endCoords, Color color) { vtkPoints points = vtkPoints.New(); points.InsertNextPoint(startCoords[0], startCoords[1], 0.0); points.InsertNextPoint(endCoords[0], endCoords[1], 0.0); vtkPolyLine line = vtkPolyLine.New(); line.GetPointIds().SetNumberOfIds(2); for (int i = 0; i < 2; i++) { line.GetPointIds().SetId(i, i); } vtkCellArray cellArray = vtkCellArray.New(); cellArray.InsertNextCell(line); vtkPolyData polyData = vtkPolyData.New(); polyData.SetPoints(points); polyData.SetLines(cellArray); vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New(); mapper.SetInputData(polyData); vtkActor2D actor = vtkActor2D.New(); actor.SetMapper(mapper); actor.GetProperty().SetOpacity((float)color.A / 255); actor.GetProperty().SetColor((float)color.R / 255, (float)color.G / 255, (float)color.B / 255); _markerLayerRenderer.AddActor(actor); return(actor); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVPlot3DVectors(String [] argv) { //Prefix Content is: "" //[] // All Plot3D vector functions[] //[] // Create the RenderWindow, Renderer and both Actors[] //[] renWin = vtkRenderWindow.New(); ren1 = vtkRenderer.New(); ren1.SetBackground((double).8,(double).8,(double).2); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); vectorLabels = "Velocity Vorticity Momentum Pressure_Gradient"; vectorFunctions = "200 201 202 210"; camera = new vtkCamera(); light = new vtkLight(); // All text actors will share the same text prop[] textProp = new vtkTextProperty(); textProp.SetFontSize((int)10); textProp.SetFontFamilyToArial(); textProp.SetColor((double).3,(double)1,(double)1); i = 0; foreach (string vectorFunction in vectorFunctions.Split(new char[]{' '})) { pl3d[getArrayIndex(vectorFunction)] = new vtkPLOT3DReader(); pl3d[getArrayIndex(vectorFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin"); pl3d[getArrayIndex(vectorFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin"); pl3d[getArrayIndex(vectorFunction)].SetVectorFunctionNumber((int)(int)(getArrayIndex(vectorFunction))); pl3d[getArrayIndex(vectorFunction)].Update(); plane[getArrayIndex(vectorFunction)] = new vtkStructuredGridGeometryFilter(); plane[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)pl3d[getArrayIndex(vectorFunction)].GetOutputPort()); plane[getArrayIndex(vectorFunction)].SetExtent((int)25,(int)25,(int)0,(int)100,(int)0,(int)100); hog[getArrayIndex(vectorFunction)] = new vtkHedgeHog(); hog[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(vectorFunction)].GetOutputPort()); maxnorm = pl3d[getArrayIndex(vectorFunction)].GetOutput().GetPointData().GetVectors().GetMaxNorm(); hog[getArrayIndex(vectorFunction)].SetScaleFactor((double)1.0/maxnorm); mapper[getArrayIndex(vectorFunction)] = vtkPolyDataMapper.New(); mapper[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)hog[getArrayIndex(vectorFunction)].GetOutputPort()); actor[getArrayIndex(vectorFunction)] = new vtkActor(); actor[getArrayIndex(vectorFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(vectorFunction)]); ren[getArrayIndex(vectorFunction)] = vtkRenderer.New(); ren[getArrayIndex(vectorFunction)].SetBackground((double)0.5,(double).5,(double).5); ren[getArrayIndex(vectorFunction)].SetActiveCamera((vtkCamera)camera); ren[getArrayIndex(vectorFunction)].AddLight((vtkLight)light); renWin.AddRenderer(ren[getArrayIndex(vectorFunction)]); ren[getArrayIndex(vectorFunction)].AddActor((vtkProp)actor[getArrayIndex(vectorFunction)]); textMapper[getArrayIndex(vectorFunction)] = new vtkTextMapper(); textMapper[getArrayIndex(vectorFunction)].SetInput(vectorLabels.Split(new char[] { ' ' })[i]); textMapper[getArrayIndex(vectorFunction)].SetTextProperty((vtkTextProperty)textProp); text[getArrayIndex(vectorFunction)] = new vtkActor2D(); text[getArrayIndex(vectorFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(vectorFunction)]); text[getArrayIndex(vectorFunction)].SetPosition((double)2,(double)5); ren[getArrayIndex(vectorFunction)].AddActor2D((vtkProp)text[getArrayIndex(vectorFunction)]); i = i + 1; } //[] // now layout renderers[] column = 1; row = 1; deltaX = 1.0/2.0; deltaY = 1.0/2.0; foreach (string vectorFunction in vectorFunctions.Split(new char[]{' '})) { ren[getArrayIndex(vectorFunction)].SetViewport((double)(column - 1) * deltaX + (deltaX * .05), (double)(row - 1) * deltaY + (deltaY * .05), (double)column * deltaX - (deltaX * .05), (double)row * deltaY - (deltaY * .05)); column = column + 1; if ((column) > 2) { column = 1; row = row + 1; } } camera.SetViewUp((double)1,(double)0,(double)0); camera.SetFocalPoint((double)0,(double)0,(double)0); camera.SetPosition((double).4,(double)-.5,(double)-.75); ren[200].ResetCamera(); camera.Dolly((double)1.25); ren[200].ResetCameraClippingRange(); ren[201].ResetCameraClippingRange(); ren[202].ResetCameraClippingRange(); ren[210].ResetCameraClippingRange(); light.SetPosition(camera.GetPosition()[0],camera.GetPosition()[1],camera.GetPosition()[2]); light.SetFocalPoint(camera.GetFocalPoint()[0],camera.GetFocalPoint()[1],camera.GetFocalPoint()[2]); renWin.SetSize(350,350); renWin.Render(); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Settext(vtkActor2D[] toSet) { text = toSet; }
/// <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(); }
static void ReadSupport(string Spath) { vtkJPEGReader reader = vtkJPEGReader.New(); reader.SetFileName(Spath); reader.Update(); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInputConnection(reader.GetOutputPort()); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); vtkRenderWindow renderWindow = vtkRenderWindow.New(); //Display in full screen renderWindow.SetFullScreen(1); vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while ((ren = renderWindow.GetRenderers().GetNextItem()) != null) { renderWindow.AddRenderer(ren); } _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.SetSlice(_SupportSlice); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renderWindow); renderWindow.Render(); _ColorLevel = 60; _ImageViewer.SetColorLevel(_BlackLevel); _ImageViewer.Render(); Down(_period, 170); Backward(_period, 1); for (int i = 0; i < _SupportLayers; i++) { System.Threading.Thread.Sleep(_layertime); // delay Backward(_period, 1); } _ImageViewer.SetColorLevel(_BlackLevel); _ImageViewer.Render(); Forward(_period, _MovedLayers); Console.WriteLine(_MovedLayers); if (reader != null) { reader.Dispose(); } if (_ImageViewer != null) { _ImageViewer.Dispose(); } if (_SliceStatusMapper != null) { _SliceStatusMapper.Dispose(); } if (sliceStatusActor != null) { sliceStatusActor.Dispose(); } if (renderWindow != null) { renderWindow.Dispose(); } if (interactorStyle != null) { interactorStyle.Dispose(); } if (ren != null) { ren.Dispose(); } if (iren != null) { iren.Dispose(); } }
///<summary> A Set Method for Static Variables </summary> public static void SetcontourLabels(vtkActor2D toSet) { contourLabels = toSet; }
/// <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(); }
private void ReadDICOMSeries() { // 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(); // Read all the DICOM files in the specified directory. // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip //string folder = Path.Combine(root, @"Data\DicomTestImages"); string folder = @"provaDicom/" + studyUID; Console.WriteLine(folder); vtkDICOMImageReader reader = vtkDICOMImageReader.New(); reader.SetDirectoryName(folder); reader.Update(); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); // get range of slices (min is the first index, max is the last index) _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice); Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString()); // slice status message vtkTextProperty sliceTextProp = vtkTextProperty.New(); sliceTextProp.SetFontFamilyToCourier(); sliceTextProp.SetFontSize(20); sliceTextProp.SetVerticalJustificationToBottom(); sliceTextProp.SetJustificationToLeft(); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInput("Slice No " + (_Slice + 1).ToString() + "/" + (_MaxSlice + 1).ToString()); _SliceStatusMapper.SetTextProperty(sliceTextProp); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); sliceStatusActor.SetPosition(15, 10); // usage hint message vtkTextProperty usageTextProp = vtkTextProperty.New(); usageTextProp.SetFontFamilyToCourier(); usageTextProp.SetFontSize(14); usageTextProp.SetVerticalJustificationToTop(); usageTextProp.SetJustificationToLeft(); vtkTextMapper usageTextMapper = vtkTextMapper.New(); usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key"); usageTextMapper.SetTextProperty(usageTextProp); vtkActor2D usageTextActor = vtkActor2D.New(); usageTextActor.SetMapper(usageTextMapper); usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay(); usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); // NOTA:non funziona la rotellina del mouse per cambiare slice <-------------------------------------- // l'errore è causato dalla funzione DicomCFindRequest(della sorgente di FellowOak) //in QueryFellowOak.cs, in particolare dal costruttore // DicomCFindRequest(DicomQueryRetrieveLevel level) // interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt); // interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt); renderWindow.GetInteractor().SetInteractorStyle(interactorStyle); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while ((ren = renderWindow.GetRenderers().GetNextItem()) != null) { ren.SetBackground(0.0, 0.0, 0.0); } _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.GetRenderer().AddActor2D(usageTextActor); _ImageViewer.SetSlice(_MinSlice); _ImageViewer.Render(); }
void Test2() { int xmin = 0; int xlength = 1000; int xmax = xmin + xlength; int ymin = 0; int ylength = 1000; int ymax = ymin + ylength; #region 定义显示的rectActor vtkPoints pts = vtkPoints.New(); pts.InsertPoint(0, xmin, ymin, 0); pts.InsertPoint(1, xmax, ymin, 0); pts.InsertPoint(2, xmax, ymax, 0); pts.InsertPoint(3, xmin, ymax, 0); vtkCellArray rect = vtkCellArray.New(); rect.InsertNextCell(5); rect.InsertCellPoint(0); rect.InsertCellPoint(1); rect.InsertCellPoint(2); rect.InsertCellPoint(3); rect.InsertCellPoint(0); vtkPolyData selectRect = vtkPolyData.New(); selectRect.SetPoints(pts); selectRect.SetLines(rect); vtkPolyDataMapper2D rectMapper = vtkPolyDataMapper2D.New(); rectMapper.SetInput(selectRect); vtkActor2D rectActor = vtkActor2D.New(); rectActor.SetMapper(rectMapper); #endregion vtkSphereSource sphere = vtkSphereSource.New(); vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInputConnection(sphere.GetOutputPort()); // sphereMapper.SetImmediateModeRendering(1); vtkActor sphereActor = vtkActor.New(); sphereActor.SetMapper(sphereMapper); vtkIdFilter ids = vtkIdFilter.New(); ids.SetInputConnection(sphere.GetOutputPort()); ids.PointIdsOn(); ids.CellIdsOn(); ids.FieldDataOn(); #region 设置要显示的点的及其label vtkSelectVisiblePoints visPts = vtkSelectVisiblePoints.New(); visPts.SetInputConnection(ids.GetOutputPort()); visPts.SetRenderer(m_render); visPts.SelectionWindowOn(); visPts.SetSelection(xmin, xmin + xlength, ymin, ymin + ylength); vtkLabeledDataMapper pointsMapper = vtkLabeledDataMapper.New(); pointsMapper.SetInputConnection(visPts.GetOutputPort()); pointsMapper.SetLabelModeToLabelFieldData(); pointsMapper.GetLabelTextProperty().SetColor(0, 255, 0); pointsMapper.GetLabelTextProperty().BoldOff(); vtkActor2D pointLabels = vtkActor2D.New(); pointLabels.SetMapper(pointsMapper); #endregion #region 设置要显示的cell的id及其label vtkCellCenters cc = vtkCellCenters.New(); cc.SetInputConnection(ids.GetOutputPort()); vtkSelectVisiblePoints visCells = vtkSelectVisiblePoints.New(); visCells.SetInputConnection(cc.GetOutputPort()); visCells.SetRenderer(m_render); visCells.SelectionWindowOn(); visCells.SetSelection(xmin, xmin + xlength, ymin, ymin + ylength); ///显示每个Cell的id vtkLabeledDataMapper cellMapper = vtkLabeledDataMapper.New(); cellMapper.SetInputConnection(visCells.GetOutputPort()); cellMapper.SetLabelModeToLabelFieldData(); cellMapper.GetLabelTextProperty().SetColor(255, 0, 0); vtkActor2D cellLabels = vtkActor2D.New(); cellLabels.SetMapper(cellMapper); #endregion m_render.AddActor(sphereActor); m_render.AddActor2D(rectActor); m_render.AddActor2D(pointLabels); // m_render.AddActor2D(cellLabels); }
private void Subdivision(string filePath) { vtkPolyData originalMesh; if (filePath != null) { vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); // Subdivision filters only work on triangles vtkTriangleFilter triangles = vtkTriangleFilter.New(); triangles.SetInputConnection(reader.GetOutputPort()); triangles.Update(); originalMesh = triangles.GetOutput(); } else { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); originalMesh = sphereSource.GetOutput(); } Debug.WriteLine("Before subdivision"); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPoints() + " points."); Debug.WriteLine(" There are " + originalMesh.GetNumberOfPolys() + " triangles."); int numberOfViewports = 3; vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(200 * numberOfViewports + 12, 252); this.Text += " - Subdivision"; Random rnd = new Random(2); int numberOfSubdivisions = 2; // Create one text property for all vtkTextProperty textProperty = vtkTextProperty.New(); textProperty.SetFontSize(14); textProperty.SetJustificationToCentered(); for (int i = 0; i < numberOfViewports; i++) { // Note: Here we create a superclass pointer (vtkPolyDataAlgorithm) so that we can easily instantiate different // types of subdivision filters. Typically you would not want to do this, but rather create the pointer to be the type // filter you will actually use, e.g. // <vtkLinearSubdivisionFilter> subdivisionFilter = <vtkLinearSubdivisionFilter>.New(); vtkPolyDataAlgorithm subdivisionFilter; switch (i) { case 0: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 1: subdivisionFilter = vtkLoopSubdivisionFilter.New(); ((vtkLoopSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; case 2: subdivisionFilter = vtkButterflySubdivisionFilter.New(); ((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; default: subdivisionFilter = vtkLinearSubdivisionFilter.New(); ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions); break; } #if VTK_MAJOR_VERSION_5 subdivisionFilter.SetInputConnection(originalMesh.GetProducerPort()); #else subdivisionFilter.SetInputData(originalMesh); #endif subdivisionFilter.Update(); vtkRenderer renderer = vtkRenderer.New(); renderWindow.AddRenderer(renderer); renderer.SetViewport((float)i / numberOfViewports, 0, (float)(i + 1) / numberOfViewports, 1); renderer.SetBackground(.2 + rnd.NextDouble() / 8, .3 + rnd.NextDouble() / 8, .4 + rnd.NextDouble() / 8); vtkTextMapper textMapper = vtkTextMapper.New(); vtkActor2D textActor = vtkActor2D.New(); textMapper.SetInput(subdivisionFilter.GetClassName()); textMapper.SetTextProperty(textProperty); textActor.SetMapper(textMapper); textActor.SetPosition(100, 16); //Create a mapper and actor vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(subdivisionFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); renderer.AddActor(actor); renderer.AddActor(textActor); renderer.ResetCamera(); } renderWindow.Render(); }
static void PrintImage(string Ipath) { vtkDICOMImageReader reader = vtkDICOMImageReader.New(); reader.SetDirectoryName(Ipath); reader.Update(); X = reader.GetWidth(); Y = reader.GetHeight(); Z = reader.GetPixelSpacing(); Console.WriteLine(X * Z[0]); Console.WriteLine(Y * Z[1]); Console.WriteLine(Z[2]); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); // Get range of slices (min is the first index, max is the last index) _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice); Console.WriteLine(_MinSlice); Console.WriteLine(_MaxSlice); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInputConnection(reader.GetOutputPort()); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); vtkRenderWindow renderWindow = vtkRenderWindow.New(); //Display in full screen renderWindow.SetFullScreen(1); vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while ((ren = renderWindow.GetRenderers().GetNextItem()) != null) { renderWindow.AddRenderer(ren); } _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.SetSlice(_Slice); _ColorLevel = 500; _ImageViewer.SetColorLevel(_BlackLevel); _ImageViewer.Render(); Down(_period, 62); Backward(_period, 1); _ImageViewer.SetColorLevel(_ColorLevel); _ImageViewer.Render(); System.Threading.Thread.Sleep(_layertime); // delay iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renderWindow); renderWindow.Render(); //Start Timer InitTimer(); iren.Start(); if (reader != null) { reader.Dispose(); } if (_ImageViewer != null) { _ImageViewer.Dispose(); } if (_SliceStatusMapper != null) { _SliceStatusMapper.Dispose(); } if (sliceStatusActor != null) { sliceStatusActor.Dispose(); } if (renderWindow != null) { renderWindow.Dispose(); } if (interactorStyle != null) { interactorStyle.Dispose(); } if (ren != null) { ren.Dispose(); } if (iren != null) { iren.Dispose(); } }
private void renderWindowControl1_Load(object sender, EventArgs e) { // Create components of the rendering subsystem // vtkRenderer ren1 = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); vtkRenderWindow renWin = renderWindowControl1.RenderWindow; renWin.SetSize((int)paras.Height, (int)paras.Width); // Add the actors to the renderer, set the window size // vtkPoints points = vtkPoints.New(); vtkCellArray polys = vtkCellArray.New(); vtkFloatArray scalars = vtkFloatArray.New(); vtkLookupTable Luk = vtkLookupTable.New(); if (paras.Using3DTower == 1) { vtkActor actor1 = new vtkActor(); vtkActor2D actor2D = new vtkActor2D(); if (paras.StageID != -1) { if (paras.UsingEdges == 1) { MessageBox.Show("单元显示无法使用"); } else { BasicVTKBuilder(ref actor1, ref points, ref polys, ref scalars, ref Luk, ref actor2D); ren1.AddActor(actor1); ren1.AddActor2D(actor2D); vtkActor2D textActor = new vtkActor2D(); VTKInfoBuilder(ref textActor); ren1.AddActor2D(textActor); } } else { if (paras.UsingEdges == 1) { ExtractEdgesVTKBuilderWithoutRunning(ref actor1, ref points, ref polys, ref scalars, ref Luk); } else { BasicVTKBuilderWithoutRunning(ref actor1, ref points, ref polys, ref scalars, ref Luk); } ren1.AddActor(actor1); } } if (paras.UsingVirtualHeater == 1) { //MessageBox.Show("!"); vtkActor2D actor2 = VirtualHeaterVTKBuilder(); ren1.AddActor(actor2); } renWin.Render(); vtkCamera camera = ren1.GetActiveCamera(); //camera.ParallelProjectionOn(); //camera.Elevation(20); int[] camera_pos = new int[3]; if (paras.globalEnv == 1) { camera_pos[1] = -70; } else { camera_pos[1] = -80; } if (paras.RotateAngle == 0) { camera_pos[1] = -camera_pos[1]; camera_pos[0] = camera_pos[2] = 0; camera.SetRoll(-2); } else if (paras.RotateAngle == 180) { camera_pos[0] = camera_pos[2] = 0; camera.SetRoll(180); } else if (paras.RotateAngle == 90) { double r = (double)Math.Abs(camera_pos[1]); camera_pos[0] = (int)(-r * 0.707); camera_pos[1] = (int)(-r * 0.707); camera_pos[2] = 0; camera.SetRoll(225); } else if (paras.RotateAngle == 270) { double r = (double)Math.Abs(camera_pos[1]); camera_pos[0] = (int)(r * 0.707); camera_pos[1] = (int)(-r * 0.707); camera_pos[2] = 0; camera.SetRoll(135); } camera.SetPosition((double)camera_pos[0], (double)camera_pos[1], (double)camera_pos[2]); //camera.Yaw(10); camera.Elevation(1); camera.ParallelProjectionOn(); camera.Zoom(0.9); StoredViewCamera = new List <vtkCamera>(); for (int i = 0; i < 3; i++) { vtkCamera ViewCamera = new vtkCamera(); if (i == 0) { ViewCamera.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]); ViewCamera.SetRoll(camera.GetRoll()); } else if (i == 1) { ViewCamera.SetPosition(80, 0, 0); ViewCamera.SetRoll(180); } else if (i == 2) { ViewCamera.SetPosition(0, 0, -80); ViewCamera.SetRoll(camera.GetRoll()); } ViewCamera.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]); ViewCamera.SetViewUp(camera.GetViewUp()[0], camera.GetViewUp()[1], camera.GetViewUp()[2]); StoredViewCamera.Add(ViewCamera); } //camera.Zoom(1.5); }
//Parameters for building a model private void BasicVTKBuilder(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys, ref vtkFloatArray scalars, ref vtkLookupTable Luk, ref vtkActor2D actor2D) { int pointsNum = 0; TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras); vtkPolyData profile = vtkPolyData.New(); profile.SetPoints(points); profile.SetPolys(polys); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (paras.RotateAngle == 0) { profile.GetCellData().SetScalars(scalars); mapper.SetInput(profile); } else { vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New(); profile.Update(); profile.GetCellData().SetScalars(scalars); //profile.GetPointData().SetScalars(scalars); refilter.SetInput(profile); refilter.SetResolution(50); refilter.SetAngle(paras.RotateAngle); refilter.SetTranslation(0); refilter.SetDeltaRadius(0); mapper.SetInputConnection(refilter.GetOutputPort()); } mapper.SetScalarRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); actor.SetMapper(mapper); // This text property is for scalarBar vtkTextProperty textProperty = vtkTextProperty.New(); //textProperty.SetFontFamilyToCourier(); //textProperty.SetColor(1.0, 1.0, 0.5); textProperty.SetFontSize(10); vtkScalarBarActor scalarBar = vtkScalarBarActor.New(); scalarBar.SetLookupTable(mapper.GetLookupTable()); scalarBar.SetTitle("Color Table"); scalarBar.SetNumberOfLabels(TowerModelInstance.GetColorGenColorTableSize()); scalarBar.SetTitleTextProperty(textProperty); scalarBar.SetLabelTextProperty(textProperty); scalarBar.SetWidth(0.07); scalarBar.SetHeight(0.6); //scalarBar.SetDrawFrame(1); vtkLookupTable hueLut = vtkLookupTable.New(); hueLut.SetTableRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); hueLut.SetHueRange(0.667, 0); hueLut.SetSaturationRange(1, 1); hueLut.SetValueRange(1, 1); hueLut.SetNumberOfTableValues(TowerModelInstance.GetColorGenColorTableSize()); hueLut.Build(); mapper.SetLookupTable(hueLut); scalarBar.SetLookupTable(hueLut); // The actor links the data pipeline to the rendering subsystem actor2D = scalarBar; //actor.GetProperty().SetColor(0.388, 0.388, 0.388); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVPlot3DScalars(String[] argv) { //Prefix Content is: "" //[] // All Plot3D scalar functions[] //[] // Create the RenderWindow, Renderer and both Actors[] //[] renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); scalarLabels = "Density Pressure Temperature Enthalpy Internal_Energy Kinetic_Energy Velocity_Magnitude Stagnation_Energy Entropy Swirl"; scalarFunctions = "100 110 120 130 140 144 153 163 170 184"; camera = new vtkCamera(); light = new vtkLight(); math = new vtkMath(); // All text actors will share the same text prop[] textProp = new vtkTextProperty(); textProp.SetFontSize((int)10); textProp.SetFontFamilyToArial(); textProp.SetColor((double)0, (double)0, (double)0); i = 0; foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' })) { pl3d[getArrayIndex(scalarFunction)] = new vtkMultiBlockPLOT3DReader(); pl3d[getArrayIndex(scalarFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin"); pl3d[getArrayIndex(scalarFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin"); pl3d[getArrayIndex(scalarFunction)].SetScalarFunctionNumber((int)(int)(Int32.Parse(scalarFunction))); pl3d[getArrayIndex(scalarFunction)].Update(); plane[getArrayIndex(scalarFunction)] = new vtkStructuredGridGeometryFilter(); plane[getArrayIndex(scalarFunction)].SetInputData((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)); plane[getArrayIndex(scalarFunction)].SetExtent((int)25, (int)25, (int)0, (int)100, (int)0, (int)100); mapper[getArrayIndex(scalarFunction)] = vtkPolyDataMapper.New(); mapper[getArrayIndex(scalarFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(scalarFunction)].GetOutputPort()); mapper[getArrayIndex(scalarFunction)].SetScalarRange((double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]); actor[getArrayIndex(scalarFunction)] = new vtkActor(); actor[getArrayIndex(scalarFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(scalarFunction)]); ren[getArrayIndex(scalarFunction)] = vtkRenderer.New(); ren[getArrayIndex(scalarFunction)].SetBackground((double)0, (double)0, (double).5); ren[getArrayIndex(scalarFunction)].SetActiveCamera((vtkCamera)camera); ren[getArrayIndex(scalarFunction)].AddLight((vtkLight)light); renWin.AddRenderer(ren[getArrayIndex(scalarFunction)]); ren[getArrayIndex(scalarFunction)].SetBackground((double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1)); ren[getArrayIndex(scalarFunction)].AddActor((vtkProp)actor[getArrayIndex(scalarFunction)]); textMapper[getArrayIndex(scalarFunction)] = new vtkTextMapper(); textMapper[getArrayIndex(scalarFunction)].SetInput(scalarLabels.Split(new char[] { ' ' })[i]); textMapper[getArrayIndex(scalarFunction)].SetTextProperty((vtkTextProperty)textProp); text[getArrayIndex(scalarFunction)] = new vtkActor2D(); text[getArrayIndex(scalarFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(scalarFunction)]); text[getArrayIndex(scalarFunction)].SetPosition((double)2, (double)3); ren[getArrayIndex(scalarFunction)].AddActor2D(text[getArrayIndex(scalarFunction)]); i = i + 1; } //[] // now layout renderers[] column = 1; row = 1; deltaX = 1.0 / 5.0; deltaY = 1.0 / 2.0; foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' })) { ren[getArrayIndex(scalarFunction)].SetViewport((double)(column - 1) * deltaX, (double)(row - 1) * deltaY, (double)column * deltaX, (double)row * deltaY); column = column + 1; if ((column) > 5) { column = 1; row = row + 1; } } camera.SetViewUp((double)0, (double)1, (double)0); camera.SetFocalPoint((double)0, (double)0, (double)0); camera.SetPosition((double)1, (double)0, (double)0); ren[100].ResetCamera(); camera.Dolly((double)1.25); ren[100].ResetCameraClippingRange(); ren[110].ResetCameraClippingRange(); ren[120].ResetCameraClippingRange(); ren[130].ResetCameraClippingRange(); ren[140].ResetCameraClippingRange(); ren[144].ResetCameraClippingRange(); ren[153].ResetCameraClippingRange(); ren[163].ResetCameraClippingRange(); ren[170].ResetCameraClippingRange(); ren[184].ResetCameraClippingRange(); light.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]); light.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]); renWin.SetSize(600, 180); renWin.Render(); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
static void Main(string[] args) { // create a sphere source, mapper, and actor vtkSphereSource sphere = new vtkSphereSource(); vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper(); sphereMapper.SetInputConnection(sphere.GetOutputPort()); vtkPolyDataMapper.GlobalImmediateModeRenderingOn(); vtkLODActor sphereActor = new vtkLODActor(); sphereActor.SetMapper(sphereMapper); // create the spikes by glyphing the sphere with a cone. Create the // mapper and actor for the glyphs. vtkConeSource cone = new vtkConeSource(); vtkGlyph3D glyph = new vtkGlyph3D(); glyph.SetInputConnection(sphere.GetOutputPort()); glyph.SetSource(cone.GetOutput()); glyph.SetVectorModeToUseNormal(); glyph.SetScaleModeToScaleByVector(); glyph.SetScaleFactor(0.25); vtkPolyDataMapper spikeMapper = new vtkPolyDataMapper(); spikeMapper.SetInputConnection(glyph.GetOutputPort()); vtkLODActor spikeActor = new vtkLODActor(); spikeActor.SetMapper(spikeMapper); // Create a text mapper and actor to display the results of picking. vtkTextMapper textMapper = new vtkTextMapper(); vtkTextProperty tprop = textMapper.GetTextProperty(); tprop.SetFontFamilyToArial(); tprop.SetFontSize(10); tprop.BoldOn(); tprop.ShadowOn(); tprop.SetColor(1, 0, 0); vtkActor2D textActor = new vtkActor2D(); textActor.VisibilityOff(); textActor.SetMapper(textMapper); // Create a cell picker. vtkCellPicker picker = new vtkCellPicker(); PickData pd = new PickData(); pd.textActor = textActor; pd.textMapper = textMapper; vtkDotNetCallback cb = new vtkDotNetCallback(pd.annotatePickCallback); // Now at the end of the pick event call the above function. picker.AddObserver((uint) EventIds.EndPickEvent, cb); // Create the Renderer, RenderWindow, etc. and set the Picker. vtkRenderer ren = new vtkRenderer(); vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer(ren); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); iren.SetPicker(picker); // Add the actors to the renderer, set the background and size ren.AddActor2D(textActor); ren.AddActor(sphereActor); ren.AddActor(spikeActor); ren.SetBackground(1, 1, 1); renWin.SetSize(300, 300); // Get the camera and zoom in closer to the image. ren.ResetCamera(); vtkCamera cam1 = ren.GetActiveCamera(); cam1.Zoom(1.4); iren.Initialize(); // Initially pick the cell at this location. picker.Pick(85, 126, 0, ren); renWin.Render(); iren.Start(); vtkWin32OpenGLRenderWindow win32win = vtkWin32OpenGLRenderWindow.SafeDownCast(renWin); if (null != win32win) win32win.Clean(); }
private void DrawTest() { vtkProp3D prop3D; vtkActor actor = vtkActor.New(); vtkActor2D actor2D = vtkActor2D.New(); vtkLODActor lODActor = vtkLODActor.New(); vtkLODProp3D lodProp3d = vtkLODProp3D.New(); vtkCamera camera = vtkCamera.New(); vtkCameraActor cameraActor = vtkCameraActor.New(); vtkLight light = vtkLight.New(); vtkLightActor lightActor = vtkLightActor.New(); vtkPicker picker = vtkPicker.New(); vtkPointPicker pointPicker = vtkPointPicker.New(); vtkCellPicker cellPicker = vtkCellPicker.New(); vtkAreaPicker areaPicker = vtkAreaPicker.New(); vtkAssembly assembly = vtkAssembly.New(); vtkConeSource coneSource = vtkConeSource.New(); vtkCone cone = vtkCone.New(); vtkArcSource arcSource = vtkArcSource.New(); vtkLineSource lineSource = vtkLineSource.New(); vtkPointSource pointSource = vtkPointSource.New(); vtkPolyData polyData = vtkPolyData.New(); vtkArrayReader arrayReader = vtkArrayReader.New(); vtkArrayDataReader arrayDataReader = vtkArrayDataReader.New(); vtkArrayWriter arrayWriter = vtkArrayWriter.New(); vtkRenderWindowInteractor renderWindowInteractor = vtkRenderWindowInteractor.New(); vtkRenderWindowInteractor3D renderWindowInteractor3D = vtkRenderWindowInteractor3D.New(); vtkInteractorStyle interactorStyle = vtkInteractorStyle.New(); vtkInteractorStyle3D interactorStyle3D = vtkInteractorStyle3D.New(); vtkInteractorStyleFlight interactorStyleFlight = vtkInteractorStyleFlight.New(); vtkInteractorStyleTrackball interactorStyleTrackball = vtkInteractorStyleTrackball.New(); vtkVolume volume = vtkVolume.New(); vtkVolumeMapper volumeMapper; vtkSmartVolumeMapper smartVolumeMapper = vtkSmartVolumeMapper.New(); vtkUnstructuredGridVolumeMapper unstructuredGridVolumeMapper; vtkUnstructuredGridVolumeRayCastMapper unstructuredGridVolumeRayCastMapper = vtkUnstructuredGridVolumeRayCastMapper.New(); vtkGPUVolumeRayCastMapper gPUVolumeRayCastMapper = vtkGPUVolumeRayCastMapper.New(); vtkVolumeRayCastMapper volumeRayCastMapper = vtkVolumeRayCastMapper.New(); vtkFixedPointVolumeRayCastMapper pointVolumeRayCastMapper = vtkFixedPointVolumeRayCastMapper.New(); vtkOpenGLGPUVolumeRayCastMapper openGLGPUVolumeRayCastMapper = vtkOpenGLGPUVolumeRayCastMapper.New(); vtkVolumeProperty volumeProperty = vtkVolumeProperty.New(); vtkTexture texture = vtkTexture.New(); vtkCoordinate coordinate = vtkCoordinate.New(); vtkImageData vtkImage = vtkImageData.New(); vtkBMPReader bMPReader = vtkBMPReader.New(); vtkJPEGReader jPEGReader = vtkJPEGReader.New(); vtkPNGReader pNGReader = vtkPNGReader.New(); vtkTIFFReader tIFFReader = vtkTIFFReader.New(); vtkOBJReader oBJReader = vtkOBJReader.New(); vtkContourFilter contourFilter = vtkContourFilter.New(); vtkSynchronizedTemplates2D synchronizedTemplates2D = vtkSynchronizedTemplates2D.New(); vtkSynchronizedTemplates3D synchronizedTemplates3D = vtkSynchronizedTemplates3D.New(); vtkSynchronizedTemplatesCutter3D synchronizedTemplatesCutter3D = vtkSynchronizedTemplatesCutter3D.New(); vtkImageMapper imageMapper = vtkImageMapper.New(); vtkImageSliceMapper imageSliceMapper = vtkImageSliceMapper.New(); vtkImageResliceMapper imageResliceMapper = vtkImageResliceMapper.New(); vtkStructuredGridReader structuredGridReader = vtkStructuredGridReader.New(); vtkRungeKutta4 integ = vtkRungeKutta4.New(); vtkStreamTracer streamer = vtkStreamTracer.New(); vtkTubeFilter streamTube = vtkTubeFilter.New(); vtkRuledSurfaceFilter ruledSurfaceFilter = vtkRuledSurfaceFilter.New(); vtkPlane plane = vtkPlane.New(); vtkCutter cutter = new vtkCutter(); vtkMergeFilter mergeFilter = vtkMergeFilter.New(); vtkImageLuminance imageLuminance = vtkImageLuminance.New(); vtkImageDataGeometryFilter imageDataGeometryFilter = vtkImageDataGeometryFilter.New(); vtkWarpScalar warpScalar = vtkWarpScalar.New(); vtkWarpVector warpVector = vtkWarpVector.New(); }