private void IsoContours() { vtkImageData data = vtkImageData.New(); CreateData(ref data); // Create an isosurface _ContourFilter = vtkContourFilter.New(); #if VTK_MAJOR_VERSION_5 _ContourFilter.SetInput(data); #else contourFilter.SetInputData(data); #endif _ContourFilter.GenerateValues(1, 10, 10); // (numContours, rangeStart, rangeEnd) // Map the contours to graphical primitives vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 contourMapper.SetInputConnection(_ContourFilter.GetOutputPort()); #else contourMapper.SetInputData(contourFilter); #endif // Create an actor for the contours vtkActor contourActor = vtkActor.New(); contourActor.SetMapper(contourMapper); // Create the outline vtkOutlineFilter outlineFilter = vtkOutlineFilter.New(); vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 outlineFilter.SetInput(data); outlineMapper.SetInputConnection(outlineFilter.GetOutputPort()); #else outlineFilter.SetInputData(data); outlineMapper.SetInputData(outlineFilter); #endif vtkActor outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); // get a reference to the renderwindow of our renderWindowControl1 _RenderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = _RenderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); // add our actor to the renderer renderer.AddActor(contourActor); renderer.AddActor(outlineActor); }
private void SampleFunction() { vtkSphere sphere = vtkSphere.New(); // Sample the function vtkSampleFunction sample = vtkSampleFunction.New(); sample.SetSampleDimensions(50, 50, 50); sample.SetImplicitFunction(sphere); double value = 2.0; double xmin = -value, xmax = value, ymin = -value, ymax = value, zmin = -value, zmax = value; sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax); // Create the 0 isosurface vtkContourFilter contours = vtkContourFilter.New(); #if VTK_MAJOR_VERSION_5 contours.SetInputConnection(sample.GetOutputPort()); #else contours.SetInputData(sample); #endif contours.GenerateValues(1, 1, 1); // Map the contours to graphical primitives vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 contourMapper.SetInputConnection(contours.GetOutputPort()); #else contourMapper.SetInputData(contours); #endif contourMapper.SetScalarRange(0.0, 1.2); // Create an actor for the contours vtkActor contourActor = vtkActor.New(); contourActor.SetMapper(contourMapper); // -- create a box around the function to indicate the sampling volume -- // Create outline vtkOutlineFilter outline = vtkOutlineFilter.New(); #if VTK_MAJOR_VERSION_5 outline.SetInputConnection(sample.GetOutputPort()); #else outline.SetInputData(sample); #endif // Map it to graphics primitives vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 outlineMapper.SetInputConnection(outline.GetOutputPort()); #else outlineMapper.SetInputData(outline); #endif // Create an actor for it vtkActor outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); outlineActor.GetProperty().SetColor(0, 0, 0); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(1.0, 1.0, 1.0); // add our actor to the renderer renderer.AddActor(contourActor); renderer.AddActor(outlineActor); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToRGrid(String [] argv) { //Prefix Content is: "" //# Generate a rectilinear grid from a field.[] //#[] // get the interactor ui[] // Create a reader and write out the field[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); try { channel = new StreamWriter("RGridField.vtk"); tryCatchError = "NOERROR"; } catch(Exception) {tryCatchError = "ERROR";} if(tryCatchError.Equals("NOERROR")) { channel.Close(); writer = new vtkDataObjectWriter(); writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); writer.SetFileName((string)"RGridField.vtk"); writer.Write(); // Read the field[] //[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"RGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToRectilinearGrid(); do2ds.SetDimensionsComponent((string)"Dimensions",(int)0); do2ds.SetPointComponent((int)0,(string)"XCoordinates",(int)0); do2ds.SetPointComponent((int)1,(string)"YCoordinates",(int)0); do2ds.SetPointComponent((int)2,(string)"ZCoordinates",(int)0); do2ds.Update(); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInputData((vtkDataObject)do2ds.GetRectilinearGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0,(string)"vectors",(int)0); fd2ad.SetVectorComponent((int)1,(string)"vectors",(int)1); fd2ad.SetVectorComponent((int)2,(string)"vectors",(int)2); fd2ad.SetScalarComponent((int)0,(string)"scalars",(int)0); fd2ad.Update(); // create pipeline[] //[] plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813,(double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0],fd2ad.GetOutput().GetCenter()[1],fd2ad.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1,(double)0,(double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); iso.SetValue((int)0,(double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 ); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort()); streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadiusToVaryRadiusByVector(); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 ); // Graphics stuff[] // 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); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); ren1.GetActiveCamera().SetPosition((double)0.0390893,(double)0.184813,(double)-3.94026); ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326,(double)0,(double)0.701967); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0.00850257,(double)0.999169,(double)0.0398605); ren1.GetActiveCamera().SetClippingRange((double)3.08127,(double)6.62716); iren.Initialize(); // render the image[] //[] File.Delete("RGridField.vtk"); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVrectGrid(String [] argv) { //Prefix Content is: "" VTK_VARY_RADIUS_BY_VECTOR = 2; // create pipeline[] //[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); reader.Update(); toRectilinearGrid = new vtkCastToConcrete(); toRectilinearGrid.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); toRectilinearGrid.Update(); plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813, (double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(reader.GetOutput().GetCenter()[0], reader.GetOutput().GetCenter()[1], reader.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1, (double)0, (double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); iso.SetValue((int)0, (double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000); // Graphics stuff[] // 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); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)400, (int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.76213, (double)10.712); cam1.SetFocalPoint((double)-0.0842503, (double)-0.136905, (double)0.610234); cam1.SetPosition((double)2.53813, (double)2.2678, (double)-5.22172); cam1.SetViewUp((double)-0.241047, (double)0.930635, (double)0.275343); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVrectGrid(String [] argv) { //Prefix Content is: "" VTK_VARY_RADIUS_BY_VECTOR = 2; // create pipeline[] //[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); reader.Update(); toRectilinearGrid = new vtkCastToConcrete(); toRectilinearGrid.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); toRectilinearGrid.Update(); plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813,(double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(reader.GetOutput().GetCenter()[0],reader.GetOutput().GetCenter()[1],reader.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1,(double)0,(double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); iso.SetValue((int)0,(double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 ); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 ); // Graphics stuff[] // 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); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)400,(int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.76213,(double)10.712); cam1.SetFocalPoint((double)-0.0842503,(double)-0.136905,(double)0.610234); cam1.SetPosition((double)2.53813,(double)2.2678,(double)-5.22172); cam1.SetViewUp((double)-0.241047,(double)0.930635,(double)0.275343); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVHyper(String [] argv) { //Prefix Content is: "" // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); VTK_INTEGRATE_BOTH_DIRECTIONS = 2; //[] // generate tensors[] ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)20,(int)20,(int)20); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10); //[] // If the current directory is writable, then test the witers[] //[] try { channel = new StreamWriter("test.tmp"); tryCatchError = "NOERROR"; } catch(Exception) {tryCatchError = "ERROR";} if(tryCatchError.Equals("NOERROR")) { channel.Close(); File.Delete("test.tmp"); wSP = new vtkDataSetWriter(); wSP.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); wSP.SetFileName((string)"wSP.vtk"); wSP.SetTensorsName((string)"pointload"); wSP.SetScalarsName((string)"effective_stress"); wSP.Write(); rSP = new vtkDataSetReader(); rSP.SetFileName((string)"wSP.vtk"); rSP.SetTensorsName((string)"pointload"); rSP.SetScalarsName((string)"effective_stress"); rSP.Update(); input = rSP.GetOutput(); File.Delete("wSP.vtk"); } else { input = ptLoad.GetOutput(); } // Generate hyperstreamlines[] s1 = new vtkHyperStreamline(); s1.SetInputData((vtkDataObject)input); s1.SetStartPosition((double)9,(double)9,(double)-9); s1.IntegrateMinorEigenvector(); s1.SetMaximumPropagationDistance((double)18.0); s1.SetIntegrationStepLength((double)0.1); s1.SetStepLength((double)0.01); s1.SetRadius((double)0.25); s1.SetNumberOfSides((int)18); s1.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s1.Update(); // Map hyperstreamlines[] lut = new vtkLogLookupTable(); lut.SetHueRange((double).6667,(double)0.0); s1Mapper = vtkPolyDataMapper.New(); s1Mapper.SetInputConnection((vtkAlgorithmOutput)s1.GetOutputPort()); s1Mapper.SetLookupTable((vtkScalarsToColors)lut); ptLoad.Update(); //force update for scalar range[] s1Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]); s1Actor = new vtkActor(); s1Actor.SetMapper((vtkMapper)s1Mapper); s2 = new vtkHyperStreamline(); s2.SetInputData((vtkDataObject)input); s2.SetStartPosition((double)-9,(double)-9,(double)-9); s2.IntegrateMinorEigenvector(); s2.SetMaximumPropagationDistance((double)18.0); s2.SetIntegrationStepLength((double)0.1); s2.SetStepLength((double)0.01); s2.SetRadius((double)0.25); s2.SetNumberOfSides((int)18); s2.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s2.Update(); s2Mapper = vtkPolyDataMapper.New(); s2Mapper.SetInputConnection((vtkAlgorithmOutput)s2.GetOutputPort()); s2Mapper.SetLookupTable((vtkScalarsToColors)lut); s2Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]); s2Actor = new vtkActor(); s2Actor.SetMapper((vtkMapper)s2Mapper); s3 = new vtkHyperStreamline(); s3.SetInputData((vtkDataObject)input); s3.SetStartPosition((double)9,(double)-9,(double)-9); s3.IntegrateMinorEigenvector(); s3.SetMaximumPropagationDistance((double)18.0); s3.SetIntegrationStepLength((double)0.1); s3.SetStepLength((double)0.01); s3.SetRadius((double)0.25); s3.SetNumberOfSides((int)18); s3.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s3.Update(); s3Mapper = vtkPolyDataMapper.New(); s3Mapper.SetInputConnection((vtkAlgorithmOutput)s3.GetOutputPort()); s3Mapper.SetLookupTable((vtkScalarsToColors)lut); s3Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0], (double)((vtkDataSet)input).GetScalarRange()[1]); s3Actor = new vtkActor(); s3Actor.SetMapper((vtkMapper)s3Mapper); s4 = new vtkHyperStreamline(); s4.SetInputData((vtkDataObject)input); s4.SetStartPosition((double)-9,(double)9,(double)-9); s4.IntegrateMinorEigenvector(); s4.SetMaximumPropagationDistance((double)18.0); s4.SetIntegrationStepLength((double)0.1); s4.SetStepLength((double)0.01); s4.SetRadius((double)0.25); s4.SetNumberOfSides((int)18); s4.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s4.Update(); s4Mapper = vtkPolyDataMapper.New(); s4Mapper.SetInputConnection((vtkAlgorithmOutput)s4.GetOutputPort()); s4Mapper.SetLookupTable((vtkScalarsToColors)lut); s4Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]); s4Actor = new vtkActor(); s4Actor.SetMapper((vtkMapper)s4Mapper); // plane for context[] //[] g = new vtkImageDataGeometryFilter(); g.SetInputData((vtkDataObject)input); g.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0); g.Update(); //for scalar range[] gm = vtkPolyDataMapper.New(); gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort()); gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); ga = new vtkActor(); ga.SetMapper((vtkMapper)gm); // Create outline around data[] //[] outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)input); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); // Create cone indicating application of load[] //[] coneSrc = new vtkConeSource(); coneSrc.SetRadius((double).5); coneSrc.SetHeight((double)2); coneMap = vtkPolyDataMapper.New(); coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort()); coneActor = new vtkActor(); coneActor.SetMapper((vtkMapper)coneMap); coneActor.SetPosition((double)0,(double)0,(double)11); coneActor.RotateY((double)90); coneActor.GetProperty().SetColor((double)1,(double)0,(double)0); camera = new vtkCamera(); camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919); camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807); camera.SetViewAngle((double)24.4617); camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879); camera.SetClippingRange((double)1,(double)100); ren1.AddActor((vtkProp)s1Actor); ren1.AddActor((vtkProp)s2Actor); ren1.AddActor((vtkProp)s3Actor); ren1.AddActor((vtkProp)s4Actor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.AddActor((vtkProp)ga); ren1.SetBackground((double)1.0,(double)1.0,(double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)300,(int)300); renWin.Render(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVgaussian(String [] argv) { //Prefix Content is: "" ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)300, (int)300); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); camera = new vtkCamera(); camera.ParallelProjectionOn(); camera.SetViewUp((double)0, (double)1, (double)0); camera.SetFocalPoint((double)12, (double)10.5, (double)15); camera.SetPosition((double)-70, (double)15, (double)34); camera.ComputeViewPlaneNormal(); ren1.SetActiveCamera((vtkCamera)camera); // Create the reader for the data[] //vtkStructuredPointsReader reader[] reader = new vtkGaussianCubeReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube"); reader.SetHBScale((double)1.1); reader.SetBScale((double)10); reader.Update(); range = reader.GetGridOutput().GetPointData().GetScalars().GetRange(); min = (double)(lindex(range, 0)); max = (double)(lindex(range, 1)); readerSS = new vtkImageShiftScale(); readerSS.SetInputData((vtkDataObject)reader.GetGridOutput()); readerSS.SetShift((double)min * -1); readerSS.SetScale((double)255 / (max - min)); readerSS.SetOutputScalarTypeToUnsignedChar(); bounds = new vtkOutlineFilter(); bounds.SetInputData((vtkDataObject)reader.GetGridOutput()); boundsMapper = vtkPolyDataMapper.New(); boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort()); boundsActor = new vtkActor(); boundsActor.SetMapper((vtkMapper)boundsMapper); boundsActor.GetProperty().SetColor((double)0, (double)0, (double)0); contour = new vtkContourFilter(); contour.SetInputData((vtkDataObject)reader.GetGridOutput()); contour.GenerateValues((int)5, (double)0, (double).05); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)0, (double).1); ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32, 0); contourActor = new vtkActor(); contourActor.SetMapper((vtkMapper)contourMapper); contourActor.GetProperty().SetOpacity((double).5); // Create transfer mapping scalar value to opacity[] opacityTransferFunction = new vtkPiecewiseFunction(); opacityTransferFunction.AddPoint((double)0, (double)0.01); opacityTransferFunction.AddPoint((double)255, (double)0.35); opacityTransferFunction.ClampingOn(); // Create transfer mapping scalar value to color[] colorTransferFunction = new vtkColorTransferFunction(); colorTransferFunction.AddHSVPoint((double)0.0, (double)0.66, (double)1.0, (double)1.0); colorTransferFunction.AddHSVPoint((double)50.0, (double)0.33, (double)1.0, (double)1.0); colorTransferFunction.AddHSVPoint((double)100.0, (double)0.00, (double)1.0, (double)1.0); // The property describes how the data will look[] volumeProperty = new vtkVolumeProperty(); volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction); volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); // The mapper / ray cast function know how to render the data[] compositeFunction = new vtkVolumeRayCastCompositeFunction(); volumeMapper = new vtkVolumeRayCastMapper(); //vtkVolumeTextureMapper2D volumeMapper[] volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction); volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort()); // The volume holds the mapper and the property and[] // can be used to position/orient the volume[] volume = new vtkVolume(); volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper); volume.SetProperty((vtkVolumeProperty)volumeProperty); ren1.AddVolume((vtkProp)volume); //ren1 AddActor contourActor[] ren1.AddActor((vtkProp)boundsActor); //#####################################################################[] Sphere = new vtkSphereSource(); Sphere.SetCenter((double)0, (double)0, (double)0); Sphere.SetRadius((double)1); Sphere.SetThetaResolution((int)16); Sphere.SetStartTheta((double)0); Sphere.SetEndTheta((double)360); Sphere.SetPhiResolution((int)16); Sphere.SetStartPhi((double)0); Sphere.SetEndPhi((double)180); Glyph = new vtkGlyph3D(); Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Glyph.SetOrient((int)1); Glyph.SetColorMode((int)1); //Glyph ScalingOn[] Glyph.SetScaleMode((int)2); Glyph.SetScaleFactor((double).6); Glyph.SetSourceConnection(Sphere.GetOutputPort()); AtomsMapper = vtkPolyDataMapper.New(); AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort()); AtomsMapper.SetImmediateModeRendering((int)1); AtomsMapper.UseLookupTableScalarRangeOff(); AtomsMapper.SetScalarVisibility((int)1); AtomsMapper.SetScalarModeToDefault(); Atoms = new vtkActor(); Atoms.SetMapper((vtkMapper)AtomsMapper); Atoms.GetProperty().SetRepresentationToSurface(); Atoms.GetProperty().SetInterpolationToGouraud(); Atoms.GetProperty().SetAmbient((double)0.15); Atoms.GetProperty().SetDiffuse((double)0.85); Atoms.GetProperty().SetSpecular((double)0.1); Atoms.GetProperty().SetSpecularPower((double)100); Atoms.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Atoms.GetProperty().SetColor((double)1, (double)1, (double)1); Tube = new vtkTubeFilter(); Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Tube.SetNumberOfSides((int)16); Tube.SetCapping((int)0); Tube.SetRadius((double)0.2); Tube.SetVaryRadius((int)0); Tube.SetRadiusFactor((double)10); BondsMapper = vtkPolyDataMapper.New(); BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort()); BondsMapper.SetImmediateModeRendering((int)1); BondsMapper.UseLookupTableScalarRangeOff(); BondsMapper.SetScalarVisibility((int)1); BondsMapper.SetScalarModeToDefault(); Bonds = new vtkActor(); Bonds.SetMapper((vtkMapper)BondsMapper); Bonds.GetProperty().SetRepresentationToSurface(); Bonds.GetProperty().SetInterpolationToGouraud(); Bonds.GetProperty().SetAmbient((double)0.15); Bonds.GetProperty().SetDiffuse((double)0.85); Bonds.GetProperty().SetSpecular((double)0.1); Bonds.GetProperty().SetSpecularPower((double)100); Bonds.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Bonds.GetProperty().SetColor((double)1, (double)1, (double)1); ren1.AddActor((vtkProp)Bonds); ren1.AddActor((vtkProp)Atoms); //###################################################[] ren1.SetBackground((double)1, (double)1, (double)1); ren1.ResetCamera(); renWin.Render(); //method moved renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVHyper(String [] argv) { //Prefix Content is: "" // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); VTK_INTEGRATE_BOTH_DIRECTIONS = 2; //[] // generate tensors[] ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)20, (int)20, (int)20); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10, (double)10, (double)-10, (double)10, (double)-10, (double)10); //[] // If the current directory is writable, then test the witers[] //[] try { channel = new StreamWriter("test.tmp"); tryCatchError = "NOERROR"; } catch (Exception) { tryCatchError = "ERROR"; } if (tryCatchError.Equals("NOERROR")) { channel.Close(); File.Delete("test.tmp"); wSP = new vtkDataSetWriter(); wSP.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); wSP.SetFileName((string)"wSP.vtk"); wSP.SetTensorsName((string)"pointload"); wSP.SetScalarsName((string)"effective_stress"); wSP.Write(); rSP = new vtkDataSetReader(); rSP.SetFileName((string)"wSP.vtk"); rSP.SetTensorsName((string)"pointload"); rSP.SetScalarsName((string)"effective_stress"); rSP.Update(); input = rSP.GetOutput(); File.Delete("wSP.vtk"); } else { input = ptLoad.GetOutput(); } // Generate hyperstreamlines[] s1 = new vtkHyperStreamline(); s1.SetInputData((vtkDataObject)input); s1.SetStartPosition((double)9, (double)9, (double)-9); s1.IntegrateMinorEigenvector(); s1.SetMaximumPropagationDistance((double)18.0); s1.SetIntegrationStepLength((double)0.1); s1.SetStepLength((double)0.01); s1.SetRadius((double)0.25); s1.SetNumberOfSides((int)18); s1.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s1.Update(); // Map hyperstreamlines[] lut = new vtkLogLookupTable(); lut.SetHueRange((double).6667, (double)0.0); s1Mapper = vtkPolyDataMapper.New(); s1Mapper.SetInputConnection((vtkAlgorithmOutput)s1.GetOutputPort()); s1Mapper.SetLookupTable((vtkScalarsToColors)lut); ptLoad.Update(); //force update for scalar range[] s1Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]); s1Actor = new vtkActor(); s1Actor.SetMapper((vtkMapper)s1Mapper); s2 = new vtkHyperStreamline(); s2.SetInputData((vtkDataObject)input); s2.SetStartPosition((double)-9, (double)-9, (double)-9); s2.IntegrateMinorEigenvector(); s2.SetMaximumPropagationDistance((double)18.0); s2.SetIntegrationStepLength((double)0.1); s2.SetStepLength((double)0.01); s2.SetRadius((double)0.25); s2.SetNumberOfSides((int)18); s2.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s2.Update(); s2Mapper = vtkPolyDataMapper.New(); s2Mapper.SetInputConnection((vtkAlgorithmOutput)s2.GetOutputPort()); s2Mapper.SetLookupTable((vtkScalarsToColors)lut); s2Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0], (double)((vtkDataSet)input).GetScalarRange()[1]); s2Actor = new vtkActor(); s2Actor.SetMapper((vtkMapper)s2Mapper); s3 = new vtkHyperStreamline(); s3.SetInputData((vtkDataObject)input); s3.SetStartPosition((double)9, (double)-9, (double)-9); s3.IntegrateMinorEigenvector(); s3.SetMaximumPropagationDistance((double)18.0); s3.SetIntegrationStepLength((double)0.1); s3.SetStepLength((double)0.01); s3.SetRadius((double)0.25); s3.SetNumberOfSides((int)18); s3.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s3.Update(); s3Mapper = vtkPolyDataMapper.New(); s3Mapper.SetInputConnection((vtkAlgorithmOutput)s3.GetOutputPort()); s3Mapper.SetLookupTable((vtkScalarsToColors)lut); s3Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0], (double)((vtkDataSet)input).GetScalarRange()[1]); s3Actor = new vtkActor(); s3Actor.SetMapper((vtkMapper)s3Mapper); s4 = new vtkHyperStreamline(); s4.SetInputData((vtkDataObject)input); s4.SetStartPosition((double)-9, (double)9, (double)-9); s4.IntegrateMinorEigenvector(); s4.SetMaximumPropagationDistance((double)18.0); s4.SetIntegrationStepLength((double)0.1); s4.SetStepLength((double)0.01); s4.SetRadius((double)0.25); s4.SetNumberOfSides((int)18); s4.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS); s4.Update(); s4Mapper = vtkPolyDataMapper.New(); s4Mapper.SetInputConnection((vtkAlgorithmOutput)s4.GetOutputPort()); s4Mapper.SetLookupTable((vtkScalarsToColors)lut); s4Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0], (double)((vtkDataSet)input).GetScalarRange()[1]); s4Actor = new vtkActor(); s4Actor.SetMapper((vtkMapper)s4Mapper); // plane for context[] //[] g = new vtkImageDataGeometryFilter(); g.SetInputData((vtkDataObject)input); g.SetExtent((int)0, (int)100, (int)0, (int)100, (int)0, (int)0); g.Update(); //for scalar range[] gm = vtkPolyDataMapper.New(); gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort()); gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); ga = new vtkActor(); ga.SetMapper((vtkMapper)gm); // Create outline around data[] //[] outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)input); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0); // Create cone indicating application of load[] //[] coneSrc = new vtkConeSource(); coneSrc.SetRadius((double).5); coneSrc.SetHeight((double)2); coneMap = vtkPolyDataMapper.New(); coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort()); coneActor = new vtkActor(); coneActor.SetMapper((vtkMapper)coneMap); coneActor.SetPosition((double)0, (double)0, (double)11); coneActor.RotateY((double)90); coneActor.GetProperty().SetColor((double)1, (double)0, (double)0); camera = new vtkCamera(); camera.SetFocalPoint((double)0.113766, (double)-1.13665, (double)-1.01919); camera.SetPosition((double)-29.4886, (double)-63.1488, (double)26.5807); camera.SetViewAngle((double)24.4617); camera.SetViewUp((double)0.17138, (double)0.331163, (double)0.927879); camera.SetClippingRange((double)1, (double)100); ren1.AddActor((vtkProp)s1Actor); ren1.AddActor((vtkProp)s2Actor); ren1.AddActor((vtkProp)s3Actor); ren1.AddActor((vtkProp)s4Actor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.AddActor((vtkProp)ga); ren1.SetBackground((double)1.0, (double)1.0, (double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)300, (int)300); renWin.Render(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToRGrid(String [] argv) { //Prefix Content is: "" //# Generate a rectilinear grid from a field.[] //#[] // get the interactor ui[] // Create a reader and write out the field[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); try { channel = new StreamWriter("RGridField.vtk"); tryCatchError = "NOERROR"; } catch (Exception) { tryCatchError = "ERROR"; } if (tryCatchError.Equals("NOERROR")) { channel.Close(); writer = new vtkDataObjectWriter(); writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); writer.SetFileName((string)"RGridField.vtk"); writer.Write(); // Read the field[] //[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"RGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToRectilinearGrid(); do2ds.SetDimensionsComponent((string)"Dimensions", (int)0); do2ds.SetPointComponent((int)0, (string)"XCoordinates", (int)0); do2ds.SetPointComponent((int)1, (string)"YCoordinates", (int)0); do2ds.SetPointComponent((int)2, (string)"ZCoordinates", (int)0); do2ds.Update(); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInputData((vtkDataObject)do2ds.GetRectilinearGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0, (string)"vectors", (int)0); fd2ad.SetVectorComponent((int)1, (string)"vectors", (int)1); fd2ad.SetVectorComponent((int)2, (string)"vectors", (int)2); fd2ad.SetScalarComponent((int)0, (string)"scalars", (int)0); fd2ad.Update(); // create pipeline[] //[] plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813, (double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0], fd2ad.GetOutput().GetCenter()[1], fd2ad.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1, (double)0, (double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); iso.SetValue((int)0, (double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort()); streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadiusToVaryRadiusByVector(); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000); // Graphics stuff[] // 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); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)300, (int)300); ren1.GetActiveCamera().SetPosition((double)0.0390893, (double)0.184813, (double)-3.94026); ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326, (double)0, (double)0.701967); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0.00850257, (double)0.999169, (double)0.0398605); ren1.GetActiveCamera().SetClippingRange((double)3.08127, (double)6.62716); iren.Initialize(); // render the image[] //[] File.Delete("RGridField.vtk"); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
private void MarchingSquares() { // 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(); vtkVolume16Reader v16 = vtkVolume16Reader.New(); v16.SetDataDimensions(64, 64); v16.GetOutput().SetOrigin(0.0, 0.0, 0.0); v16.SetDataByteOrderToLittleEndian(); v16.SetFilePrefix(System.IO.Path.Combine(root, @"Data\headsq\quarter")); v16.SetImageRange(1, 93); v16.SetDataSpacing(3.2, 3.2, 1.5); v16.Update(); vtkMergePoints myLocator = vtkMergePoints.New(); vtkMarchingSquares isoXY = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoXY.SetInputConnection(v16.GetOutputPort()); #else isoXY.SetInputData(v16); #endif isoXY.GenerateValues(2, 600, 1200); isoXY.SetImageRange(0, 32, 32, 63, 45, 45); isoXY.SetLocator(myLocator); vtkPolyDataMapper isoXYMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoXYMapper.SetInputConnection(isoXY.GetOutputPort()); #else isoXYMapper.SetInputData(isoXY); #endif isoXYMapper.SetScalarRange(600, 1200); vtkActor isoXYActor = vtkActor.New(); isoXYActor.SetMapper(isoXYMapper); vtkMarchingSquares isoYZ = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoYZ.SetInputConnection(v16.GetOutputPort()); #else isoYZ.SetInputData(v16); #endif isoYZ.GenerateValues(2, 600, 1200); isoYZ.SetImageRange(32, 32, 32, 63, 46, 92); vtkPolyDataMapper isoYZMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoYZMapper.SetInputConnection(isoYZ.GetOutputPort()); #else isoYZMapper.SetInputData(isoYZ); #endif isoYZMapper.SetScalarRange(600, 1200); vtkActor isoYZActor = vtkActor.New(); isoYZActor.SetMapper(isoYZMapper); vtkMarchingSquares isoXZ = vtkMarchingSquares.New(); #if VTK_MAJOR_VERSION_5 isoXZ.SetInputConnection(v16.GetOutputPort()); #else isoXZ.SetInputData(v16); #endif isoXZ.GenerateValues(2, 600, 1200); isoXZ.SetImageRange(0, 32, 32, 32, 0, 46); vtkPolyDataMapper isoXZMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 isoXZMapper.SetInputConnection(isoXZ.GetOutputPort()); #else isoXZMapper.SetInputData(isoXZ); #endif isoXZMapper.SetScalarRange(600, 1200); vtkActor isoXZActor = vtkActor.New(); isoXZActor.SetMapper(isoXZMapper); vtkOutlineFilter outline = vtkOutlineFilter.New(); #if VTK_MAJOR_VERSION_5 outline.SetInputConnection(v16.GetOutputPort()); #else outline.SetInputData(v16); #endif vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 outlineMapper.SetInputConnection(outline.GetOutputPort()); #else outlineMapper.SetInputData(outline); #endif vtkActor outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); outlineActor.VisibilityOff(); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(1.0, 1.0, 1.0); //Add the actors to the renderer, set the background and size renderer.AddActor(outlineActor); renderer.AddActor(isoXYActor); renderer.AddActor(isoYZActor); renderer.AddActor(isoXZActor); renderer.GetActiveCamera().SetPosition(324.368, 284.266, -19.3293); renderer.GetActiveCamera().SetFocalPoint(73.5683, 120.903, 70.7309); renderer.GetActiveCamera().SetViewAngle(30); renderer.GetActiveCamera().SetViewUp(-0.304692, -0.0563843, -0.950781); }