/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestFixedPointRayCasterNearest(String [] argv) { //Prefix Content is: "" // Create a gaussian[] gs = new vtkImageGaussianSource(); gs.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs.SetMaximum((double)255.0); gs.SetStandardDeviation((double)5); gs.SetCenter((double)15, (double)15, (double)15); // threshold to leave a gap that should show up for[] // gradient opacity[] t = new vtkImageThreshold(); t.SetInputConnection((vtkAlgorithmOutput)gs.GetOutputPort()); t.ReplaceInOn(); t.SetInValue((double)0); t.ThresholdBetween((double)150, (double)200); // Use a shift scale to convert to unsigned char[] ss = new vtkImageShiftScale(); ss.SetInputConnection((vtkAlgorithmOutput)t.GetOutputPort()); ss.SetOutputScalarTypeToUnsignedChar(); // grid will be used for two component dependent[] grid0 = new vtkImageGridSource(); grid0.SetDataScalarTypeToUnsignedChar(); grid0.SetGridSpacing((int)10, (int)10, (int)10); grid0.SetLineValue((double)200); grid0.SetFillValue((double)10); grid0.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); // use dilation to thicken the grid[] d = new vtkImageContinuousDilate3D(); d.SetInputConnection((vtkAlgorithmOutput)grid0.GetOutputPort()); d.SetKernelSize((int)3, (int)3, (int)3); // Now make a two component dependent[] iac = new vtkImageAppendComponents(); iac.AddInputConnection(d.GetOutputPort()); iac.AddInputConnection(ss.GetOutputPort()); // Some more gaussians for the four component indepent case[] gs1 = new vtkImageGaussianSource(); gs1.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs1.SetMaximum((double)255.0); gs1.SetStandardDeviation((double)4); gs1.SetCenter((double)5, (double)5, (double)5); t1 = new vtkImageThreshold(); t1.SetInputConnection((vtkAlgorithmOutput)gs1.GetOutputPort()); t1.ReplaceInOn(); t1.SetInValue((double)0); t1.ThresholdBetween((double)150, (double)256); gs2 = new vtkImageGaussianSource(); gs2.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs2.SetMaximum((double)255.0); gs2.SetStandardDeviation((double)4); gs2.SetCenter((double)12, (double)12, (double)12); gs3 = new vtkImageGaussianSource(); gs3.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs3.SetMaximum((double)255.0); gs3.SetStandardDeviation((double)4); gs3.SetCenter((double)19, (double)19, (double)19); t3 = new vtkImageThreshold(); t3.SetInputConnection((vtkAlgorithmOutput)gs3.GetOutputPort()); t3.ReplaceInOn(); t3.SetInValue((double)0); t3.ThresholdBetween((double)150, (double)256); gs4 = new vtkImageGaussianSource(); gs4.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs4.SetMaximum((double)255.0); gs4.SetStandardDeviation((double)4); gs4.SetCenter((double)26, (double)26, (double)26); //tk window skipped.. iac1 = new vtkImageAppendComponents(); iac1.AddInputConnection(t1.GetOutputPort()); iac1.AddInputConnection(gs2.GetOutputPort()); iac2 = new vtkImageAppendComponents(); iac2.AddInputConnection(iac1.GetOutputPort()); iac2.AddInputConnection(t3.GetOutputPort()); iac3 = new vtkImageAppendComponents(); iac3.AddInputConnection(iac2.GetOutputPort()); iac3.AddInputConnection(gs4.GetOutputPort()); // create the four component dependend - [] // use lines in x, y, z for colors[] gridR = new vtkImageGridSource(); gridR.SetDataScalarTypeToUnsignedChar(); gridR.SetGridSpacing((int)10, (int)100, (int)100); gridR.SetLineValue((double)250); gridR.SetFillValue((double)100); gridR.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dR = new vtkImageContinuousDilate3D(); dR.SetInputConnection((vtkAlgorithmOutput)gridR.GetOutputPort()); dR.SetKernelSize((int)2, (int)2, (int)2); gridG = new vtkImageGridSource(); gridG.SetDataScalarTypeToUnsignedChar(); gridG.SetGridSpacing((int)100, (int)10, (int)100); gridG.SetLineValue((double)250); gridG.SetFillValue((double)100); gridG.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dG = new vtkImageContinuousDilate3D(); dG.SetInputConnection((vtkAlgorithmOutput)gridG.GetOutputPort()); dG.SetKernelSize((int)2, (int)2, (int)2); gridB = new vtkImageGridSource(); gridB.SetDataScalarTypeToUnsignedChar(); gridB.SetGridSpacing((int)100, (int)100, (int)10); gridB.SetLineValue((double)0); gridB.SetFillValue((double)250); gridB.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dB = new vtkImageContinuousDilate3D(); dB.SetInputConnection((vtkAlgorithmOutput)gridB.GetOutputPort()); dB.SetKernelSize((int)2, (int)2, (int)2); // need some appending[] iacRG = new vtkImageAppendComponents(); iacRG.AddInputConnection(dR.GetOutputPort()); iacRG.AddInputConnection(dG.GetOutputPort()); iacRGB = new vtkImageAppendComponents(); iacRGB.AddInputConnection(iacRG.GetOutputPort()); iacRGB.AddInputConnection(dB.GetOutputPort()); iacRGBA = new vtkImageAppendComponents(); iacRGBA.AddInputConnection(iacRGB.GetOutputPort()); iacRGBA.AddInputConnection(ss.GetOutputPort()); // We need a bunch of opacity functions[] // this one is a simple ramp to .2[] rampPoint2 = new vtkPiecewiseFunction(); rampPoint2.AddPoint((double)0, (double)0.0); rampPoint2.AddPoint((double)255, (double)0.2); // this one is a simple ramp to 1[] ramp1 = new vtkPiecewiseFunction(); ramp1.AddPoint((double)0, (double)0.0); ramp1.AddPoint((double)255, (double)1.0); // this one shows a sharp surface[] surface = new vtkPiecewiseFunction(); surface.AddPoint((double)0, (double)0.0); surface.AddPoint((double)10, (double)0.0); surface.AddPoint((double)50, (double)1.0); surface.AddPoint((double)255, (double)1.0); // this one is constant 1[] constant1 = new vtkPiecewiseFunction(); constant1.AddPoint((double)0, (double)1.0); constant1.AddPoint((double)255, (double)1.0); // this one is used for gradient opacity[] gop = new vtkPiecewiseFunction(); gop.AddPoint((double)0, (double)0.0); gop.AddPoint((double)20, (double)0.0); gop.AddPoint((double)60, (double)1.0); gop.AddPoint((double)255, (double)1.0); // We need a bunch of color functions[] // This one is a simple rainbow[] rainbow = new vtkColorTransferFunction(); rainbow.SetColorSpaceToHSV(); rainbow.HSVWrapOff(); rainbow.AddHSVPoint((double)0, (double)0.1, (double)1.0, (double)1.0); rainbow.AddHSVPoint((double)255, (double)0.9, (double)1.0, (double)1.0); // this is constant red[] red = new vtkColorTransferFunction(); red.AddRGBPoint((double)0, (double)1, (double)0, (double)0); red.AddRGBPoint((double)255, (double)1, (double)0, (double)0); // this is constant green[] green = new vtkColorTransferFunction(); green.AddRGBPoint((double)0, (double)0, (double)1, (double)0); green.AddRGBPoint((double)255, (double)0, (double)1, (double)0); // this is constant blue[] blue = new vtkColorTransferFunction(); blue.AddRGBPoint((double)0, (double)0, (double)0, (double)1); blue.AddRGBPoint((double)255, (double)0, (double)0, (double)1); // this is constant yellow[] yellow = new vtkColorTransferFunction(); yellow.AddRGBPoint((double)0, (double)1, (double)1, (double)0); yellow.AddRGBPoint((double)255, (double)1, (double)1, (double)0); ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)500, (int)500); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ren1.GetCullers().InitTraversal(); culler = (vtkFrustumCoverageCuller)ren1.GetCullers().GetNextItem(); culler.SetSortingStyleToBackToFront(); // We need 25 mapper / actor pairs which we will render[] // in a grid. Going down we will vary the input data[] // with the top row unsigned char, then float, then[] // two dependent components, then four dependent components[] // then four independent components. Going across we[] // will vary the rendering method with MIP, Composite,[] // Composite Shade, Composite GO, and Composite GO Shade.[] j = 0; while ((j) < 5) { i = 0; while ((i) < 5) { volumeProperty[i, j] = new vtkVolumeProperty(); volumeMapper[i, j] = new vtkFixedPointVolumeRayCastMapper(); volumeMapper[i, j].SetSampleDistance((float)0.25); volume[i, j] = new vtkVolume(); volume[i, j].SetMapper((vtkAbstractVolumeMapper)volumeMapper[i, j]); volume[i, j].SetProperty((vtkVolumeProperty)volumeProperty[i, j]); volume[i, j].AddPosition((double)i * 30, (double)j * 30, (double)0); ren1.AddVolume((vtkProp)volume[i, j]); i = i + 1; } j = j + 1; } i = 0; while ((i) < 5) { volumeMapper[0, i].SetInputConnection(t.GetOutputPort()); volumeMapper[1, i].SetInputConnection(ss.GetOutputPort()); volumeMapper[2, i].SetInputConnection(iac.GetOutputPort()); volumeMapper[3, i].SetInputConnection(iac3.GetOutputPort()); volumeMapper[4, i].SetInputConnection(iacRGBA.GetOutputPort()); volumeMapper[i, 0].SetBlendModeToMaximumIntensity(); volumeMapper[i, 1].SetBlendModeToComposite(); volumeMapper[i, 2].SetBlendModeToComposite(); volumeMapper[i, 3].SetBlendModeToComposite(); volumeMapper[i, 4].SetBlendModeToComposite(); volumeProperty[0, i].IndependentComponentsOn(); volumeProperty[1, i].IndependentComponentsOn(); volumeProperty[2, i].IndependentComponentsOff(); volumeProperty[3, i].IndependentComponentsOn(); volumeProperty[4, i].IndependentComponentsOff(); volumeProperty[0, i].SetColor(rainbow); volumeProperty[0, i].SetScalarOpacity(rampPoint2); volumeProperty[0, i].SetGradientOpacity(constant1); volumeProperty[1, i].SetColor(rainbow); volumeProperty[1, i].SetScalarOpacity(rampPoint2); volumeProperty[1, i].SetGradientOpacity(constant1); volumeProperty[2, i].SetColor(rainbow); volumeProperty[2, i].SetScalarOpacity(rampPoint2); volumeProperty[2, i].SetGradientOpacity(constant1); volumeProperty[3, i].SetColor(0, red); volumeProperty[3, i].SetColor(1, green); volumeProperty[3, i].SetColor(2, blue); volumeProperty[3, i].SetColor(3, yellow); volumeProperty[3, i].SetScalarOpacity(0, rampPoint2); volumeProperty[3, i].SetScalarOpacity(1, rampPoint2); volumeProperty[3, i].SetScalarOpacity(2, rampPoint2); volumeProperty[3, i].SetScalarOpacity(3, rampPoint2); volumeProperty[3, i].SetGradientOpacity(0, constant1); volumeProperty[3, i].SetGradientOpacity(1, constant1); volumeProperty[3, i].SetGradientOpacity(2, constant1); volumeProperty[3, i].SetGradientOpacity(3, constant1); volumeProperty[3, i].SetComponentWeight(0, 1); volumeProperty[3, i].SetComponentWeight(1, 1); volumeProperty[3, i].SetComponentWeight(2, 1); volumeProperty[3, i].SetComponentWeight(3, 1); volumeProperty[4, i].SetColor(rainbow); volumeProperty[4, i].SetScalarOpacity(rampPoint2); volumeProperty[4, i].SetGradientOpacity(constant1); volumeProperty[i, 2].ShadeOn(); volumeProperty[i, 4].ShadeOn((int)0); volumeProperty[i, 4].ShadeOn((int)1); volumeProperty[i, 4].ShadeOn((int)2); volumeProperty[i, 4].ShadeOn((int)3); i = i + 1; } volumeProperty[0, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[1, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[2, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[3, 0].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[0, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetGradientOpacity((int)0, (vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetGradientOpacity((int)2, (vtkPiecewiseFunction)gop); volumeProperty[4, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetScalarOpacity((int)0, (vtkPiecewiseFunction)ramp1); volumeProperty[3, 3].SetScalarOpacity((int)2, (vtkPiecewiseFunction)ramp1); volumeProperty[0, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 4].SetGradientOpacity((int)0, (vtkPiecewiseFunction)gop); volumeProperty[3, 4].SetGradientOpacity((int)2, (vtkPiecewiseFunction)gop); volumeProperty[4, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); renWin.Render(); ren1.GetActiveCamera().Dolly((double)1.3); ren1.GetActiveCamera().Azimuth((double)15); ren1.GetActiveCamera().Elevation((double)5); ren1.ResetCameraClippingRange(); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestBranchExtentTranslator(String [] argv) { //Prefix Content is: "" gauss = new vtkImageGaussianSource(); gauss.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)2); gauss.SetCenter((double)18, (double)12, (double)0); gauss.SetMaximum((double)1.0); gauss.SetStandardDeviation((double)6.0); gauss.Update(); translator = new vtkBranchExtentTranslator(); translator.SetOriginalSource((vtkImageData)gauss.GetOutput()); gauss.GetOutput().SetExtentTranslator((vtkExtentTranslator)translator); clip1 = new vtkImageClip(); clip1.SetOutputWholeExtent((int)7, (int)28, (int)0, (int)15, (int)1, (int)1); clip1.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf1 = new vtkDataSetSurfaceFilter(); surf1.SetInputConnection((vtkAlgorithmOutput)clip1.GetOutputPort()); tf1 = new vtkTriangleFilter(); tf1.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort()); mapper1 = vtkPolyDataMapper.New(); mapper1.SetInputConnection((vtkAlgorithmOutput)tf1.GetOutputPort()); mapper1.SetScalarRange((double)0, (double)1); mapper1.SetNumberOfPieces((int)4); mapper1.SetPiece((int)1); actor1 = new vtkActor(); actor1.SetMapper((vtkMapper)mapper1); actor1.SetPosition((double)0, (double)0, (double)0); // For coverage, a case where all four sides get clipped by the whole extent.[] clip2 = new vtkImageClip(); clip2.SetOutputWholeExtent((int)16, (int)18, (int)3, (int)10, (int)0, (int)0); clip2.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf2 = new vtkDataSetSurfaceFilter(); surf2.SetInputConnection((vtkAlgorithmOutput)clip2.GetOutputPort()); tf2 = new vtkTriangleFilter(); tf2.SetInputConnection((vtkAlgorithmOutput)surf2.GetOutputPort()); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)tf2.GetOutputPort()); mapper2.SetScalarRange((double)0, (double)1); mapper2.SetNumberOfPieces((int)4); mapper2.SetPiece((int)1); actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)15, (double)0, (double)0); // nothing in intersection (empty case)[] clip3 = new vtkImageClip(); clip3.SetOutputWholeExtent((int)1, (int)10, (int)0, (int)15, (int)0, (int)2); clip3.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf3 = new vtkDataSetSurfaceFilter(); surf3.SetInputConnection((vtkAlgorithmOutput)clip3.GetOutputPort()); tf3 = new vtkTriangleFilter(); tf3.SetInputConnection((vtkAlgorithmOutput)surf3.GetOutputPort()); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)tf3.GetOutputPort()); mapper3.SetScalarRange((double)0, (double)1); mapper3.SetNumberOfPieces((int)4); mapper3.SetPiece((int)1); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)30, (double)0, (double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor1); ren.AddActor((vtkProp)actor2); ren.AddActor((vtkProp)actor3); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); //set cam [ren GetActiveCamera][] //ren ResetCamera[] iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); renWin.Render(); // break loop to avoid a memory leak.[] translator.SetOriginalSource(null); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestBranchExtentTranslator(String [] argv) { //Prefix Content is: "" gauss = new vtkImageGaussianSource(); gauss.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)2); gauss.SetCenter((double)18,(double)12,(double)0); gauss.SetMaximum((double)1.0); gauss.SetStandardDeviation((double)6.0); gauss.Update(); translator = new vtkBranchExtentTranslator(); translator.SetOriginalSource((vtkImageData)gauss.GetOutput()); gauss.GetOutput().SetExtentTranslator((vtkExtentTranslator)translator); clip1 = new vtkImageClip(); clip1.SetOutputWholeExtent((int)7,(int)28,(int)0,(int)15,(int)1,(int)1); clip1.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf1 = new vtkDataSetSurfaceFilter(); surf1.SetInputConnection((vtkAlgorithmOutput)clip1.GetOutputPort()); tf1 = new vtkTriangleFilter(); tf1.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort()); mapper1 = vtkPolyDataMapper.New(); mapper1.SetInputConnection((vtkAlgorithmOutput)tf1.GetOutputPort()); mapper1.SetScalarRange((double)0,(double)1); mapper1.SetNumberOfPieces((int)4); mapper1.SetPiece((int)1); actor1 = new vtkActor(); actor1.SetMapper((vtkMapper)mapper1); actor1.SetPosition((double)0,(double)0,(double)0); // For coverage, a case where all four sides get clipped by the whole extent.[] clip2 = new vtkImageClip(); clip2.SetOutputWholeExtent((int)16,(int)18,(int)3,(int)10,(int)0,(int)0); clip2.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf2 = new vtkDataSetSurfaceFilter(); surf2.SetInputConnection((vtkAlgorithmOutput)clip2.GetOutputPort()); tf2 = new vtkTriangleFilter(); tf2.SetInputConnection((vtkAlgorithmOutput)surf2.GetOutputPort()); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)tf2.GetOutputPort()); mapper2.SetScalarRange((double)0,(double)1); mapper2.SetNumberOfPieces((int)4); mapper2.SetPiece((int)1); actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)15,(double)0,(double)0); // nothing in intersection (empty case)[] clip3 = new vtkImageClip(); clip3.SetOutputWholeExtent((int)1,(int)10,(int)0,(int)15,(int)0,(int)2); clip3.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort()); surf3 = new vtkDataSetSurfaceFilter(); surf3.SetInputConnection((vtkAlgorithmOutput)clip3.GetOutputPort()); tf3 = new vtkTriangleFilter(); tf3.SetInputConnection((vtkAlgorithmOutput)surf3.GetOutputPort()); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)tf3.GetOutputPort()); mapper3.SetScalarRange((double)0,(double)1); mapper3.SetNumberOfPieces((int)4); mapper3.SetPiece((int)1); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)30,(double)0,(double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor1); ren.AddActor((vtkProp)actor2); ren.AddActor((vtkProp)actor3); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); //set cam [ren GetActiveCamera][] //ren ResetCamera[] iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); renWin.Render(); // break loop to avoid a memory leak.[] translator.SetOriginalSource(null); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestFixedPointRayCasterNearest(String [] argv) { //Prefix Content is: "" // Create a gaussian[] gs = new vtkImageGaussianSource(); gs.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs.SetMaximum((double)255.0); gs.SetStandardDeviation((double)5); gs.SetCenter((double)15,(double)15,(double)15); // threshold to leave a gap that should show up for[] // gradient opacity[] t = new vtkImageThreshold(); t.SetInputConnection((vtkAlgorithmOutput)gs.GetOutputPort()); t.ReplaceInOn(); t.SetInValue((double)0); t.ThresholdBetween((double)150,(double)200); // Use a shift scale to convert to unsigned char[] ss = new vtkImageShiftScale(); ss.SetInputConnection((vtkAlgorithmOutput)t.GetOutputPort()); ss.SetOutputScalarTypeToUnsignedChar(); // grid will be used for two component dependent[] grid0 = new vtkImageGridSource(); grid0.SetDataScalarTypeToUnsignedChar(); grid0.SetGridSpacing((int)10,(int)10,(int)10); grid0.SetLineValue((double)200); grid0.SetFillValue((double)10); grid0.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); // use dilation to thicken the grid[] d = new vtkImageContinuousDilate3D(); d.SetInputConnection((vtkAlgorithmOutput)grid0.GetOutputPort()); d.SetKernelSize((int)3,(int)3,(int)3); // Now make a two component dependent[] iac = new vtkImageAppendComponents(); iac.AddInput((vtkDataObject)d.GetOutput()); iac.AddInput((vtkDataObject)ss.GetOutput()); // Some more gaussians for the four component indepent case[] gs1 = new vtkImageGaussianSource(); gs1.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs1.SetMaximum((double)255.0); gs1.SetStandardDeviation((double)4); gs1.SetCenter((double)5,(double)5,(double)5); t1 = new vtkImageThreshold(); t1.SetInputConnection((vtkAlgorithmOutput)gs1.GetOutputPort()); t1.ReplaceInOn(); t1.SetInValue((double)0); t1.ThresholdBetween((double)150,(double)256); gs2 = new vtkImageGaussianSource(); gs2.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs2.SetMaximum((double)255.0); gs2.SetStandardDeviation((double)4); gs2.SetCenter((double)12,(double)12,(double)12); gs3 = new vtkImageGaussianSource(); gs3.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs3.SetMaximum((double)255.0); gs3.SetStandardDeviation((double)4); gs3.SetCenter((double)19,(double)19,(double)19); t3 = new vtkImageThreshold(); t3.SetInputConnection((vtkAlgorithmOutput)gs3.GetOutputPort()); t3.ReplaceInOn(); t3.SetInValue((double)0); t3.ThresholdBetween((double)150,(double)256); gs4 = new vtkImageGaussianSource(); gs4.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs4.SetMaximum((double)255.0); gs4.SetStandardDeviation((double)4); gs4.SetCenter((double)26,(double)26,(double)26); //tk window skipped.. iac1 = new vtkImageAppendComponents(); iac1.AddInput((vtkDataObject)t1.GetOutput()); iac1.AddInput((vtkDataObject)gs2.GetOutput()); iac2 = new vtkImageAppendComponents(); iac2.AddInput((vtkDataObject)iac1.GetOutput()); iac2.AddInput((vtkDataObject)t3.GetOutput()); iac3 = new vtkImageAppendComponents(); iac3.AddInput((vtkDataObject)iac2.GetOutput()); iac3.AddInput((vtkDataObject)gs4.GetOutput()); // create the four component dependend - [] // use lines in x, y, z for colors[] gridR = new vtkImageGridSource(); gridR.SetDataScalarTypeToUnsignedChar(); gridR.SetGridSpacing((int)10,(int)100,(int)100); gridR.SetLineValue((double)250); gridR.SetFillValue((double)100); gridR.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dR = new vtkImageContinuousDilate3D(); dR.SetInputConnection((vtkAlgorithmOutput)gridR.GetOutputPort()); dR.SetKernelSize((int)2,(int)2,(int)2); gridG = new vtkImageGridSource(); gridG.SetDataScalarTypeToUnsignedChar(); gridG.SetGridSpacing((int)100,(int)10,(int)100); gridG.SetLineValue((double)250); gridG.SetFillValue((double)100); gridG.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dG = new vtkImageContinuousDilate3D(); dG.SetInputConnection((vtkAlgorithmOutput)gridG.GetOutputPort()); dG.SetKernelSize((int)2,(int)2,(int)2); gridB = new vtkImageGridSource(); gridB.SetDataScalarTypeToUnsignedChar(); gridB.SetGridSpacing((int)100,(int)100,(int)10); gridB.SetLineValue((double)0); gridB.SetFillValue((double)250); gridB.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dB = new vtkImageContinuousDilate3D(); dB.SetInputConnection((vtkAlgorithmOutput)gridB.GetOutputPort()); dB.SetKernelSize((int)2,(int)2,(int)2); // need some appending[] iacRG = new vtkImageAppendComponents(); iacRG.AddInput((vtkDataObject)dR.GetOutput()); iacRG.AddInput((vtkDataObject)dG.GetOutput()); iacRGB = new vtkImageAppendComponents(); iacRGB.AddInput((vtkDataObject)iacRG.GetOutput()); iacRGB.AddInput((vtkDataObject)dB.GetOutput()); iacRGBA = new vtkImageAppendComponents(); iacRGBA.AddInput((vtkDataObject)iacRGB.GetOutput()); iacRGBA.AddInput((vtkDataObject)ss.GetOutput()); // We need a bunch of opacity functions[] // this one is a simple ramp to .2[] rampPoint2 = new vtkPiecewiseFunction(); rampPoint2.AddPoint((double)0,(double)0.0); rampPoint2.AddPoint((double)255,(double)0.2); // this one is a simple ramp to 1[] ramp1 = new vtkPiecewiseFunction(); ramp1.AddPoint((double)0,(double)0.0); ramp1.AddPoint((double)255,(double)1.0); // this one shows a sharp surface[] surface = new vtkPiecewiseFunction(); surface.AddPoint((double)0,(double)0.0); surface.AddPoint((double)10,(double)0.0); surface.AddPoint((double)50,(double)1.0); surface.AddPoint((double)255,(double)1.0); // this one is constant 1[] constant1 = new vtkPiecewiseFunction(); constant1.AddPoint((double)0,(double)1.0); constant1.AddPoint((double)255,(double)1.0); // this one is used for gradient opacity[] gop = new vtkPiecewiseFunction(); gop.AddPoint((double)0,(double)0.0); gop.AddPoint((double)20,(double)0.0); gop.AddPoint((double)60,(double)1.0); gop.AddPoint((double)255,(double)1.0); // We need a bunch of color functions[] // This one is a simple rainbow[] rainbow = new vtkColorTransferFunction(); rainbow.SetColorSpaceToHSV(); rainbow.HSVWrapOff(); rainbow.AddHSVPoint((double)0,(double)0.1,(double)1.0,(double)1.0); rainbow.AddHSVPoint((double)255,(double)0.9,(double)1.0,(double)1.0); // this is constant red[] red = new vtkColorTransferFunction(); red.AddRGBPoint((double)0,(double)1,(double)0,(double)0); red.AddRGBPoint((double)255,(double)1,(double)0,(double)0); // this is constant green[] green = new vtkColorTransferFunction(); green.AddRGBPoint((double)0,(double)0,(double)1,(double)0); green.AddRGBPoint((double)255,(double)0,(double)1,(double)0); // this is constant blue[] blue = new vtkColorTransferFunction(); blue.AddRGBPoint((double)0,(double)0,(double)0,(double)1); blue.AddRGBPoint((double)255,(double)0,(double)0,(double)1); // this is constant yellow[] yellow = new vtkColorTransferFunction(); yellow.AddRGBPoint((double)0,(double)1,(double)1,(double)0); yellow.AddRGBPoint((double)255,(double)1,(double)1,(double)0); ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)500,(int)500); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ren1.GetCullers().InitTraversal(); culler = (vtkFrustumCoverageCuller)ren1.GetCullers().GetNextItem(); culler.SetSortingStyleToBackToFront(); // We need 25 mapper / actor pairs which we will render[] // in a grid. Going down we will vary the input data[] // with the top row unsigned char, then float, then[] // two dependent components, then four dependent components[] // then four independent components. Going across we[] // will vary the rendering method with MIP, Composite,[] // Composite Shade, Composite GO, and Composite GO Shade.[] j = 0; while((j) < 5) { i = 0; while((i) < 5) { volumeProperty[i,j] = new vtkVolumeProperty(); volumeMapper[i,j] = new vtkFixedPointVolumeRayCastMapper(); volumeMapper[i,j].SetSampleDistance((float)0.25); volume[i,j] = new vtkVolume(); volume[i,j].SetMapper((vtkAbstractVolumeMapper)volumeMapper[i,j]); volume[i,j].SetProperty((vtkVolumeProperty)volumeProperty[i,j]); volume[i,j].AddPosition((double)i*30,(double)j*30,(double)0); ren1.AddVolume((vtkProp)volume[i,j]); i = i + 1; } j = j + 1; } i = 0; while((i) < 5) { volumeMapper[0,i].SetInputConnection(t.GetOutputPort()); volumeMapper[1,i].SetInputConnection(ss.GetOutputPort()); volumeMapper[2,i].SetInputConnection(iac.GetOutputPort()); volumeMapper[3,i].SetInputConnection(iac3.GetOutputPort()); volumeMapper[4,i].SetInputConnection(iacRGBA.GetOutputPort()); volumeMapper[i,0].SetBlendModeToMaximumIntensity(); volumeMapper[i,1].SetBlendModeToComposite(); volumeMapper[i,2].SetBlendModeToComposite(); volumeMapper[i,3].SetBlendModeToComposite(); volumeMapper[i,4].SetBlendModeToComposite(); volumeProperty[0,i].IndependentComponentsOn(); volumeProperty[1,i].IndependentComponentsOn(); volumeProperty[2,i].IndependentComponentsOff(); volumeProperty[3,i].IndependentComponentsOn(); volumeProperty[4,i].IndependentComponentsOff(); volumeProperty[0,i].SetColor(rainbow); volumeProperty[0,i].SetScalarOpacity(rampPoint2); volumeProperty[0,i].SetGradientOpacity(constant1); volumeProperty[1,i].SetColor(rainbow); volumeProperty[1,i].SetScalarOpacity(rampPoint2); volumeProperty[1,i].SetGradientOpacity(constant1); volumeProperty[2,i].SetColor(rainbow); volumeProperty[2,i].SetScalarOpacity(rampPoint2); volumeProperty[2,i].SetGradientOpacity(constant1); volumeProperty[3,i].SetColor(0, red); volumeProperty[3,i].SetColor(1, green); volumeProperty[3,i].SetColor(2, blue ); volumeProperty[3,i].SetColor(3, yellow); volumeProperty[3,i].SetScalarOpacity(0,rampPoint2); volumeProperty[3,i].SetScalarOpacity(1,rampPoint2); volumeProperty[3,i].SetScalarOpacity(2,rampPoint2); volumeProperty[3,i].SetScalarOpacity(3,rampPoint2); volumeProperty[3,i].SetGradientOpacity(0,constant1); volumeProperty[3,i].SetGradientOpacity(1,constant1); volumeProperty[3,i].SetGradientOpacity(2,constant1); volumeProperty[3,i].SetGradientOpacity(3,constant1); volumeProperty[3,i].SetComponentWeight(0,1); volumeProperty[3,i].SetComponentWeight(1,1); volumeProperty[3,i].SetComponentWeight(2,1); volumeProperty[3,i].SetComponentWeight(3,1); volumeProperty[4,i].SetColor(rainbow); volumeProperty[4,i].SetScalarOpacity(rampPoint2); volumeProperty[4,i].SetGradientOpacity(constant1); volumeProperty[i,2].ShadeOn(); volumeProperty[i,4].ShadeOn((int)0); volumeProperty[i,4].ShadeOn((int)1); volumeProperty[i,4].ShadeOn((int)2); volumeProperty[i,4].ShadeOn((int)3); i = i + 1; } volumeProperty[0,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[1,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[2,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[3,0].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[0,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,3].SetGradientOpacity((int)0,(vtkPiecewiseFunction)gop); volumeProperty[3,3].SetGradientOpacity((int)2,(vtkPiecewiseFunction)gop); volumeProperty[4,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,3].SetScalarOpacity((int)0,(vtkPiecewiseFunction)ramp1); volumeProperty[3,3].SetScalarOpacity((int)2,(vtkPiecewiseFunction)ramp1); volumeProperty[0,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,4].SetGradientOpacity((int)0,(vtkPiecewiseFunction)gop); volumeProperty[3,4].SetGradientOpacity((int)2,(vtkPiecewiseFunction)gop); volumeProperty[4,4].SetGradientOpacity((vtkPiecewiseFunction)gop); renWin.Render(); ren1.GetActiveCamera().Dolly((double)1.3); ren1.GetActiveCamera().Azimuth((double)15); ren1.GetActiveCamera().Elevation((double)5); ren1.ResetCameraClippingRange(); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestCutMaterial(String [] argv) { //Prefix Content is: "" // Lets create a data set.[] data = new vtkImageData(); data.SetExtent((int)0,(int)31,(int)0,(int)31,(int)0,(int)31); data.SetScalarTypeToFloat(); // First the data array:[] gauss = new vtkImageGaussianSource(); gauss.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gauss.SetCenter((double)18,(double)12,(double)20); gauss.SetMaximum((double)1.0); gauss.SetStandardDeviation((double)10.0); gauss.Update(); a = gauss.GetOutput().GetPointData().GetScalars(); a.SetName((string)"Gauss"); data.GetCellData().SetScalars((vtkDataArray)a); //skipping Delete gauss // Now the material array:[] ellipse = new vtkImageEllipsoidSource(); ellipse.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); ellipse.SetCenter((double)11,(double)12,(double)13); ellipse.SetRadius((double)5,(double)9,(double)13); ellipse.SetInValue((double)1); ellipse.SetOutValue((double)0); ellipse.SetOutputScalarTypeToInt(); ellipse.Update(); m = ellipse.GetOutput().GetPointData().GetScalars(); m.SetName((string)"Material"); data.GetCellData().AddArray((vtkAbstractArray)m); //skipping Delete ellipse cut = new vtkCutMaterial(); cut.SetInput((vtkDataObject)data); cut.SetMaterialArrayName((string)"Material"); cut.SetMaterial((int)1); cut.SetArrayName((string)"Gauss"); cut.SetUpVector((double)1,(double)0,(double)0); cut.Update(); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)cut.GetOutputPort()); mapper2.SetScalarRange((double)0,(double)1); //apper2 SetScalarModeToUseCellFieldData[] //apper2 SetColorModeToMapScalars [] //apper2 ColorByArrayComponent "vtkGhostLevels" 0[] actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)1.5,(double)0,(double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor2); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); p = cut.GetCenterPoint(); n = cut.GetNormal(); cam = ren.GetActiveCamera(); cam.SetFocalPoint(p[0],p[1],p[2]); cam.SetViewUp(cut.GetUpVector()[0], cut.GetUpVector()[1], cut.GetUpVector()[2]); cam.SetPosition( (double)(lindex(n,0))+(double)(lindex(p,0)), (double)(lindex(n,1))+(double)(lindex(p,1)), (double)(lindex(n,2))+(double)(lindex(p,2))); ren.ResetCamera(); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestCutMaterial(String [] argv) { //Prefix Content is: "" // Lets create a data set.[] data = new vtkImageData(); data.SetExtent((int)0, (int)31, (int)0, (int)31, (int)0, (int)31); data.SetScalarTypeToFloat(); // First the data array:[] gauss = new vtkImageGaussianSource(); gauss.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gauss.SetCenter((double)18, (double)12, (double)20); gauss.SetMaximum((double)1.0); gauss.SetStandardDeviation((double)10.0); gauss.Update(); a = gauss.GetOutput().GetPointData().GetScalars(); a.SetName((string)"Gauss"); data.GetCellData().SetScalars((vtkDataArray)a); //skipping Delete gauss // Now the material array:[] ellipse = new vtkImageEllipsoidSource(); ellipse.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); ellipse.SetCenter((double)11, (double)12, (double)13); ellipse.SetRadius((double)5, (double)9, (double)13); ellipse.SetInValue((double)1); ellipse.SetOutValue((double)0); ellipse.SetOutputScalarTypeToInt(); ellipse.Update(); m = ellipse.GetOutput().GetPointData().GetScalars(); m.SetName((string)"Material"); data.GetCellData().AddArray((vtkAbstractArray)m); //skipping Delete ellipse cut = new vtkCutMaterial(); cut.SetInput((vtkDataObject)data); cut.SetMaterialArrayName((string)"Material"); cut.SetMaterial((int)1); cut.SetArrayName((string)"Gauss"); cut.SetUpVector((double)1, (double)0, (double)0); cut.Update(); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)cut.GetOutputPort()); mapper2.SetScalarRange((double)0, (double)1); //apper2 SetScalarModeToUseCellFieldData[] //apper2 SetColorModeToMapScalars [] //apper2 ColorByArrayComponent "vtkGhostLevels" 0[] actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)1.5, (double)0, (double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor2); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); p = cut.GetCenterPoint(); n = cut.GetNormal(); cam = ren.GetActiveCamera(); cam.SetFocalPoint(p[0], p[1], p[2]); cam.SetViewUp(cut.GetUpVector()[0], cut.GetUpVector()[1], cut.GetUpVector()[2]); cam.SetPosition( (double)(lindex(n, 0)) + (double)(lindex(p, 0)), (double)(lindex(n, 1)) + (double)(lindex(p, 1)), (double)(lindex(n, 2)) + (double)(lindex(p, 2))); ren.ResetCamera(); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); iren.Initialize(); //deleteAllVTKObjects(); }