private void RenderVTK() { //Get rid of any props already there if (imgProp != null) { m_Renderer.RemoveActor(imgProp); imgProp.Dispose(); imgProp = null; } vtkDataSetReader dataReader = vtkDataSetReader.New(); vtkDataSetMapper dataMapper = vtkDataSetMapper.New(); imgProp = vtkActor.New(); dataReader.SetFileName(m_FileName); dataReader.Update(); dataMapper.SetInput(dataReader.GetOutput()); ((vtkActor)imgProp).SetMapper(dataMapper); dataMapper.Dispose(); dataMapper = null; dataReader.Dispose(); dataReader = null; m_Renderer.AddActor(imgProp); //Reset the camera to show the image //Equivilant of pressing 'r' m_Renderer.ResetCamera(); //Rerender the screen //NOTE: sometimes you have to drag the mouse //a little before the image shows up renderWindowControl1.RenderWindow.Render(); m_Renderer.Render(); }
/// <summary> /// Loads the Squirrel model and textures /// into the algorithms and textures /// </summary> public void loadSquirrel() { //Set a predefined position for the eyes //that matches the .blend file eyeX = 0.076; eyeY = -0.178; eyeZ = 0.675; //load the squirrel model and textures if //they are not already loaded if (!squirrelLoaded) { squirrelReader.SetFileName("../../../models/squirrel.vtk"); squirrelReader.Update(); squirrelEyeReader.SetFileName("../../../models/squirrel_eyeR.vtk"); squirrelEyeReader.Update(); squirrelEyeReader2.SetFileName("../../../models/squirrel_eyeL.vtk"); squirrelEyeReader2.Update(); squirrelColorReader.SetFileName("../../../textures/squirrel_skin_col.png"); squirrelColorReader.Update(); squirrelEyeColorReader.SetFileName("../../../textures/squirrel_eyeR.png"); squirrelEyeColorReader.Update(); squirrelEyeColorReader2.SetFileName("../../../textures/squirrel_eyeL.png"); squirrelEyeColorReader2.Update(); squirrelLoaded = true; } //Set the algorithms and textures to the //ouput of the readers eyeColorTexture1.InterpolateOn(); eyeColorTexture1.SetInputConnection(squirrelEyeColorReader.GetOutputPort()); deciEyeColorTexture1.InterpolateOn(); deciEyeColorTexture1.SetInputConnection(squirrelEyeColorReader.GetOutputPort()); eyeColorTexture2.InterpolateOn(); eyeColorTexture2.SetInputConnection(squirrelEyeColorReader2.GetOutputPort()); deciEyeColorTexture2.InterpolateOn(); deciEyeColorTexture2.SetInputConnection(squirrelEyeColorReader2.GetOutputPort()); animalColorTexture.InterpolateOn(); animalColorTexture.SetInputConnection(squirrelColorReader.GetOutputPort()); deciAnimalColorTexture.InterpolateOn(); deciAnimalColorTexture.SetInputConnection(squirrelColorReader.GetOutputPort()); eyeData2 = squirrelEyeReader2.GetOutputPort(); eyeData1 = squirrelEyeReader.GetOutputPort(); animalData = squirrelReader.GetOutputPort(); }
private vtkDataSet ReadVTKData(string path) { using (vtkDataSetReader reader = new vtkDataSetReader()) { reader.ReadAllScalarsOn(); reader.GetReadAllScalars(); reader.ReadAllVectorsOn(); reader.GetReadAllVectors(); reader.ReadAllColorScalarsOn(); reader.GetReadAllColorScalars(); reader.SetFileName(path); reader.Update(); return(reader.GetOutput()); } }
/// <summary> /// Loads the Chinchilla model and textures /// into the algorithms and textures /// </summary> public void loadChinchilla() { //Set a predefined position for the eyes //that matches the .blend file eyeX = 0.052; eyeY = -0.144; eyeZ = 0.424; //load the chinchilla model and textures if //they are not already loaded if (!chinchillaLoaded) { chinchillaReader.SetFileName("../../../models/chinchilla.vtk"); chinchillaReader.Update(); chinchillaEyeReader.SetFileName("../../../models/chinchilla_eye.vtk"); chinchillaEyeReader.Update(); chinchillaColorReader.SetFileName("../../../textures/chinchilla_skin_col.png"); chinchillaColorReader.Update(); chinchillaEyeColorReader.SetFileName("../../../textures/chinchilla_eye.png"); chinchillaEyeColorReader.Update(); chinchillaLoaded = true; } //Set the algorithms and textures to the //ouput of the readers animalData = chinchillaReader.GetOutputPort(); eyeData1 = chinchillaEyeReader.GetOutputPort(); eyeData2 = eyeData1; animalColorTexture.InterpolateOn(); animalColorTexture.SetInputConnection(chinchillaColorReader.GetOutputPort()); deciAnimalColorTexture.InterpolateOn(); deciAnimalColorTexture.SetInputConnection(chinchillaColorReader.GetOutputPort()); eyeColorTexture1.InterpolateOn(); eyeColorTexture1.SetInputConnection(chinchillaEyeColorReader.GetOutputPort()); deciEyeColorTexture1.InterpolateOn(); deciEyeColorTexture1.SetInputConnection(chinchillaEyeColorReader.GetOutputPort()); eyeColorTexture2.InterpolateOn(); eyeColorTexture2.SetInputConnection(chinchillaEyeColorReader.GetOutputPort()); deciEyeColorTexture2.InterpolateOn(); deciEyeColorTexture2.SetInputConnection(chinchillaEyeColorReader.GetOutputPort()); }
/// <summary> /// Loads the Flying Squirrel model and textures /// into the algorithms and textures /// </summary> public void loadFlyingSquirrel() { //Set a predefined position for the eyes //that matches the .blend file eyeX = 0.054; eyeY = -0.189; eyeZ = 0.427; //load the flyingsquirrel model and textures if //they are not already loaded if (!flyingSquirrelLoaded) { flyingSquirrelReader.SetFileName("../../../models/flyingsquirrel.vtk"); flyingSquirrelReader.Update(); flyingSquirreleyeReader.SetFileName("../../../models/flyingsquirrel_eye.vtk"); flyingSquirreleyeReader.Update(); flyingSquirrelColorReader.SetFileName("../../../textures/flyingsquirrel_skin_col.png"); flyingSquirrelColorReader.Update(); flyingSquirrelEyeColorReader.SetFileName("../../../textures/flyingsquirrel_eye.png"); flyingSquirrelEyeColorReader.Update(); flyingSquirrelLoaded = true; } //Set the algorithms and textures to the //ouput of the readers animalData = flyingSquirrelReader.GetOutputPort(); eyeData1 = flyingSquirreleyeReader.GetOutputPort(); eyeData2 = eyeData1; animalColorTexture.InterpolateOn(); animalColorTexture.SetInputConnection(flyingSquirrelColorReader.GetOutputPort()); deciAnimalColorTexture.InterpolateOn(); deciAnimalColorTexture.SetInputConnection(flyingSquirrelColorReader.GetOutputPort()); eyeColorTexture1.InterpolateOn(); eyeColorTexture1.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort()); deciEyeColorTexture1.InterpolateOn(); deciEyeColorTexture1.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort()); eyeColorTexture2.InterpolateOn(); eyeColorTexture2.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort()); deciEyeColorTexture2.InterpolateOn(); deciEyeColorTexture2.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort()); }
/// <summary> /// Loads the Rabbit model and textures /// into the algorithms and textures /// </summary> public void loadRabbit() { //Set a predefined position for the eyes //that matches the .blend file eyeX = 0.057; eyeY = -0.311; eyeZ = 1.879; //load the rabbit model and textures if //they are not already loaded if (!rabbitLoaded) { rabbitReader.SetFileName("../../../models/rabbit.vtk"); rabbitReader.Update(); eyeReader.SetFileName("../../../models/rabbit_eye.vtk"); eyeReader.Update(); rabbitColorReader.SetFileName("../../../textures/rabbit_skin_col.png"); rabbitColorReader.Update(); eyeColorReader.SetFileName("../../../textures/rabbit_eye.png"); eyeColorReader.Update(); rabbitLoaded = true; } //Set the algorithms and textures to the //ouput of the readers animalData = rabbitReader.GetOutputPort(); eyeData1 = eyeReader.GetOutputPort(); eyeData2 = eyeData1; animalColorTexture.InterpolateOn(); animalColorTexture.SetInputConnection(rabbitColorReader.GetOutputPort()); deciAnimalColorTexture.InterpolateOn(); deciAnimalColorTexture.SetInputConnection(rabbitColorReader.GetOutputPort()); eyeColorTexture1.InterpolateOn(); eyeColorTexture1.SetInputConnection(eyeColorReader.GetOutputPort()); deciEyeColorTexture1.InterpolateOn(); deciEyeColorTexture1.SetInputConnection(eyeColorReader.GetOutputPort()); eyeColorTexture2.InterpolateOn(); eyeColorTexture2.SetInputConnection(eyeColorReader.GetOutputPort()); deciEyeColorTexture2.InterpolateOn(); deciEyeColorTexture2.SetInputConnection(eyeColorReader.GetOutputPort()); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVRectOutline(String [] argv) { //Prefix Content is: "" // create pipeline[] //[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); reader.Update(); // here to force exact extent[] elev = new vtkElevationFilter(); elev.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); outline = new vtkRectilinearGridOutlineFilter(); outline.SetInput((vtkDataObject)elev.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineMapper.SetNumberOfPieces((int)2); outlineMapper.SetPiece((int)1); 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.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.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 AVRectOutline(String [] argv) { //Prefix Content is: "" // create pipeline[] //[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); reader.Update(); // here to force exact extent[] elev = new vtkElevationFilter(); elev.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); outline = new vtkRectilinearGridOutlineFilter(); outline.SetInput((vtkDataObject)elev.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineMapper.SetNumberOfPieces((int)2); outlineMapper.SetPiece((int)1); 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.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.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(); }
private void RenderVTK() { vtkDataSetReader dataReader = vtkDataSetReader.New(); vtkDataSetMapper dataMapper = vtkDataSetMapper.New(); vtkProp3D imgProp = vtkActor.New(); dataReader.SetFileName(m_FileName); dataReader.Update(); dataMapper.SetInput(dataReader.GetOutput()); ((vtkActor)imgProp).SetMapper(dataMapper); dataMapper.Dispose(); dataMapper = null; dataReader.Dispose(); dataReader = null; imgPropList.Add(imgProp); m_Renderer.AddActor(imgProp); //Reset the camera to show the image //Equivilant of pressing 'r' m_Renderer.ResetCamera(); //Rerender the screen m_RenderWindow.Render(); m_Renderer.Render(); }
public void ImportVTK() { if (openFileDialog1.ShowDialog() == DialogResult.OK) { // Get the name of the file you want to open from the dialog string fileName = openFileDialog1.FileName; vtkRenderer ren = (vtkRenderer)this.myRenderWindowControl.RenderWindow.GetRenderers().GetItemAsObject(0); //Get rid of any props already there if (imgProp != null) { ren.RemoveActor(imgProp); imgProp.Dispose(); imgProp = null; } //Look at known file types to see if they are readable if (fileName.Contains(".png") || fileName.Contains(".jpg") || fileName.Contains(".jpeg") || fileName.Contains(".tif") || fileName.Contains(".slc") || fileName.Contains(".dicom") || fileName.Contains(".minc") || fileName.Contains(".bmp") || fileName.Contains(".pmn")) { vtkImageReader2 rdr = vtkImageReader2Factory.CreateImageReader2(fileName); rdr.SetFileName(fileName); rdr.Update(); imgProp = vtkImageActor.New(); ((vtkImageActor)imgProp).SetInput(rdr.GetOutput()); rdr.Dispose(); } //.vtk files need a DataSetReader instead of a ImageReader2 //some .vtk files need a different kind of reader, but this //will read most and serve our purposes else if (fileName.Contains(".vtk") || fileName.Contains(".VTK")) { vtkDataSetReader dataReader = vtkDataSetReader.New(); dataReader.SetFileName(fileName); dataReader.Update(); vtkDataSetMapper dataMapper = vtkDataSetMapper.New(); dataMapper.SetInput(dataReader.GetOutput()); imgProp = vtkActor.New(); ((vtkActor)imgProp).SetMapper(dataMapper); dataMapper.Dispose(); dataMapper = null; dataReader.Dispose(); dataReader = null; } else { return; } ren.RemoveAllViewProps(); ren.AddActor(imgProp); ren.ResetCamera(); ren.SetBackground(0.0, 0.46, 0.5); //Rerender the screen //NOTE: sometimes you have to drag the mouse //a little before the image shows up ren.Render(); myRenderWindowControl.RenderWindow.Render(); myRenderWindowControl.Refresh(); } }
/// <summary> /// Load an image with an open dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { // Get the name of the file you want to open from the dialog string fileName = openFileDialog1.FileName; vtkRenderer ren = (vtkRenderer)this.renderWindowControl1.RenderWindow.GetRenderers().GetItemAsObject(0); //Get rid of any props already there if (imgProp != null) { ren.RemoveActor(imgProp); imgProp.Dispose(); imgProp = null; } //Look at known file types to see if they are readable if (fileName.Contains(".png") || fileName.Contains(".jpg") || fileName.Contains(".jpeg") || fileName.Contains(".tif") || fileName.Contains(".slc") || fileName.Contains(".dicom") || fileName.Contains(".minc") || fileName.Contains(".bmp") || fileName.Contains(".pmn")) { Kitware.VTK.vtkImageReader2 rdr = Kitware.VTK.vtkImageReader2Factory.CreateImageReader2(fileName); rdr.SetFileName(fileName); rdr.Update(); imgProp = vtkImageActor.New(); ((vtkImageActor)imgProp).SetInputConnection(rdr.GetOutputPort()); rdr.Dispose(); } //.vtk files need a DataSetReader instead of a ImageReader2 //some .vtk files need a different kind of reader, but this //will read most and serve our purposes else if (fileName.Contains(".vtk")) { vtkDataSetReader dataReader = vtkDataSetReader.New(); vtkDataSetMapper dataMapper = vtkDataSetMapper.New(); imgProp = vtkActor.New(); dataReader.SetFileName(fileName); dataReader.Update(); dataMapper.SetInputConnection(dataReader.GetOutputPort()); ((vtkActor)imgProp).SetMapper(dataMapper); dataMapper.Dispose(); dataMapper = null; dataReader.Dispose(); dataReader = null; } else { return; } ren.AddActor(imgProp); //Reset the camera to show the image //Equivilant of pressing 'r' ren.ResetCamera(); //Rerender the screen //NOTE: sometimes you have to drag the mouse //a little before the image shows up renderWindowControl1.RenderWindow.Render(); ren.Render(); } }
/// <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()); plane = new vtkRectilinearGridGeometryFilter(); plane.SetInput((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.SetInput((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.SetInput((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.SetInput((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.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 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(); }