//普通模式_绘制
        private void DrawMode_Normal()
        {
            #region 体属性 vtkVolumeProperty
            //设定体数据的属性:不透明性和颜色值映射标量值
            vtkVolumeProperty volumeProperty = vtkVolumeProperty.New();
            volumeProperty.SetColor(m_ColorTransferFunction);
            volumeProperty.SetScalarOpacity(m_PiecewiseFunction);
            //设置插值类型
            volumeProperty.SetInterpolationTypeToNearest();
            volumeProperty.SetDiffuse(0.7);
            volumeProperty.SetAmbient(0.01);
            volumeProperty.SetSpecular(0.5);
            volumeProperty.SetSpecularPower(100);
            #endregion

            //绘制方法:体射线投射
            vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New();

            #region 体数据映射器 vtkVolumeRayCastMapper
            //体数据映射器
            vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New();
            volumeMapper.SetInput(m_ImageData);
            volumeMapper.SetVolumeRayCastFunction(compositeFunction);
            #endregion

            #region 体 vtkVolume
            //体
            vtkVolume volume = vtkVolume.New();
            volume.SetMapper(volumeMapper);
            volume.SetProperty(volumeProperty);
            #endregion

            //模型体放入Renerer
            m_Renderer.AddVolume(volume);
        }
Ejemplo n.º 2
0
        private static byte[] MipPixelDataFromVtkSlab(vtkImageData slabImageData)
        {
#if true // Do our own MIP, albeit slowly
            int[]  sliceDimensions = slabImageData.GetDimensions();
            int    sliceDataSize   = sliceDimensions[0] * sliceDimensions[1];
            IntPtr slabDataPtr     = slabImageData.GetScalarPointer();

            byte[] pixelData = MemoryManager.Allocate <byte>(sliceDataSize * sizeof(short));

            // Init with first slice
            Marshal.Copy(slabDataPtr, pixelData, 0, sliceDataSize * sizeof(short));

            // Walk through other slices, finding maximum
            unsafe
            {
                short *psSlab = (short *)slabDataPtr;

                fixed(byte *pbFrame = pixelData)
                {
                    short *psFrame = (short *)pbFrame;

                    for (int sliceIndex = 1; sliceIndex < sliceDimensions[2]; sliceIndex++)
                    {
                        for (int i = 0; i < sliceDataSize - 1; ++i)
                        {
                            int slabIndex = sliceIndex * sliceDataSize + i;
                            if (psSlab[slabIndex] > psFrame[i])
                            {
                                psFrame[i] = psSlab[slabIndex];
                            }
                        }
                    }
                }
            }

            return(pixelData);
#else // Ideally we'd use VTK to do the MIP (MinIP, Average...)
            vtkVolumeRayCastMIPFunction mip    = new vtkVolumeRayCastMIPFunction();
            vtkVolumeRayCastMapper      mapper = new vtkVolumeRayCastMapper();

            mapper.SetVolumeRayCastFunction(mip);
            mapper.SetInput(slabImageData);

            //TODO: Need to figure out how to use mapper to output vtkImageData

            vtkImageAlgorithm algo = new vtkImageAlgorithm();
            algo.SetInput(mapper.GetOutputDataObject(0));

            using (vtkExecutive exec = mapper.GetExecutive())
            {
                VtkHelper.RegisterVtkErrorEvents(exec);
                exec.Update();

                // Note: These report no output port, must have to do something else to get mapper to give us data
                //return exec.GetOutputData(0);
                return(mapper.GetOutputDataObject(0));
            }
#endif
        }
Ejemplo n.º 3
0
        private void Window_Activated(object sender, EventArgs e)
        {
            // 一定要先 vtkformhost.Child = vtkControl;下面三条顺序不能乱 否则报错 切记!
            vtkformhost.Child = vtkControl;
            vtkRenderWindow renWin    = vtkControl.RenderWindow;
            vtkRenderer     aRenderer = renWin.GetRenderers().GetFirstRenderer();

            renWin.AddRenderer(aRenderer);

            Marshal.Copy(ys1, 0, temp128, imgLine * imgPixel * imgNum);


            temp.SetArray(temp128, imgLine * imgPixel * imgNum, 1);

            testimgdata.SetDimensions(imgLine, imgPixel, imgNum);
            testimgdata.SetSpacing(1, 1, 4);
            testimgdata.SetScalarTypeToUnsignedChar();
            testimgdata.SetNumberOfScalarComponents(1);
            testimgdata.AllocateScalars();
            testimgdata.GetPointData().SetScalars(temp);
            testimgdata.Modified();

            VtkSetColor();
            VtkSetOpacity();

            volumeProperty.SetColor(colorTransferFunction);
            volumeProperty.SetScalarOpacity(opacityTransferFunction);
            volumeProperty.ShadeOn();
            volumeProperty.SetInterpolationTypeToLinear();

            volumeMapper.SetVolumeRayCastFunction(compositeFunction);
            volumeMapper.SetInput(testimgdata);

            volume.SetMapper(volumeMapper);
            volume.SetProperty(volumeProperty);

            aCamera.SetViewUp(0, -1, 0);
            aCamera.SetPosition(-1, 0, 1);
            aCamera.ComputeViewPlaneNormal();

            aRenderer.AddVolume(volume);
            aRenderer.SetBackground(0, 0, 0.6);
            aRenderer.SetActiveCamera(aCamera);
            aRenderer.ResetCamera();
            renWin.SetSize(800, 800);
            renWin.Render();
        }
Ejemplo n.º 4
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVcursor3D(String [] argv)
    {
        //Prefix Content is: ""

        // This little example shows how a cursor can be created in []
        // image viewers, and renderers.  The standard TkImageViewerWidget and[]
        // TkRenderWidget bindings are used.  There is a new binding:[]
        // middle button in the image viewer sets the position of the cursor.  []
        // First we include the VTK Tcl packages which will make available []
        // all of the vtk commands to Tcl[]
        // Global values[]
        CURSOR_X    = 20;
        CURSOR_Y    = 20;
        CURSOR_Z    = 20;
        IMAGE_MAG_X = 4;
        IMAGE_MAG_Y = 4;
        IMAGE_MAG_Z = 1;
        // Pipeline stuff[]
        reader = new vtkSLCReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/neghip.slc");
        // Cursor stuff[]
        magnify = new vtkImageMagnify();
        magnify.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        magnify.SetMagnificationFactors((int)IMAGE_MAG_X, (int)IMAGE_MAG_Y, (int)IMAGE_MAG_Z);
        image_cursor = new vtkImageCursor3D();
        image_cursor.SetInputConnection((vtkAlgorithmOutput)magnify.GetOutputPort());
        image_cursor.SetCursorPosition((double)CURSOR_X * IMAGE_MAG_X, (double)CURSOR_Y * IMAGE_MAG_Y, (double)CURSOR_Z * IMAGE_MAG_Z);
        image_cursor.SetCursorValue((double)255);
        image_cursor.SetCursorRadius((int)50 * IMAGE_MAG_X);
        axes = new vtkAxes();
        axes.SymmetricOn();
        axes.SetOrigin((double)CURSOR_X, (double)CURSOR_Y, (double)CURSOR_Z);
        axes.SetScaleFactor((double)50.0);
        axes_mapper = vtkPolyDataMapper.New();
        axes_mapper.SetInputConnection((vtkAlgorithmOutput)axes.GetOutputPort());
        axesActor = new vtkActor();
        axesActor.SetMapper((vtkMapper)axes_mapper);
        axesActor.GetProperty().SetAmbient((double)0.5);
        // Image viewer stuff[]
        viewer = new vtkImageViewer();
        viewer.SetInputConnection((vtkAlgorithmOutput)image_cursor.GetOutputPort());
        viewer.SetZSlice((int)CURSOR_Z * IMAGE_MAG_Z);
        viewer.SetColorWindow((double)256);
        viewer.SetColorLevel((double)128);
        //method moved
        //method moved
        //method moved
        // Create transfer functions for opacity and color[]
        opacity_transfer_function = new vtkPiecewiseFunction();
        opacity_transfer_function.AddPoint((double)20, (double)0.0);
        opacity_transfer_function.AddPoint((double)255, (double)0.2);
        color_transfer_function = new vtkColorTransferFunction();
        color_transfer_function.AddRGBPoint((double)0, (double)0, (double)0, (double)0);
        color_transfer_function.AddRGBPoint((double)64, (double)1, (double)0, (double)0);
        color_transfer_function.AddRGBPoint((double)128, (double)0, (double)0, (double)1);
        color_transfer_function.AddRGBPoint((double)192, (double)0, (double)1, (double)0);
        color_transfer_function.AddRGBPoint((double)255, (double)0, (double).2, (double)0);
        // Create properties, mappers, volume actors, and ray cast function[]
        volume_property = new vtkVolumeProperty();
        volume_property.SetColor((vtkColorTransferFunction)color_transfer_function);
        volume_property.SetScalarOpacity((vtkPiecewiseFunction)opacity_transfer_function);
        composite_function = new vtkVolumeRayCastCompositeFunction();
        volume_mapper      = new vtkVolumeRayCastMapper();
        volume_mapper.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        volume_mapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)composite_function);
        volume = new vtkVolume();
        volume.SetMapper((vtkAbstractVolumeMapper)volume_mapper);
        volume.SetProperty((vtkVolumeProperty)volume_property);
        // Create outline[]
        outline = new vtkOutlineFilter();
        outline.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        outline_mapper = vtkPolyDataMapper.New();
        outline_mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
        outlineActor = new vtkActor();
        outlineActor.SetMapper((vtkMapper)outline_mapper);
        outlineActor.GetProperty().SetColor((double)1, (double)1, (double)1);
        // Create the renderer[]
        ren1 = vtkRenderer.New();
        ren1.AddActor((vtkProp)axesActor);
        ren1.AddVolume((vtkProp)volume);
        ren1.SetBackground((double)0.1, (double)0.2, (double)0.4);
        renWin2 = vtkRenderWindow.New();
        renWin2.AddRenderer((vtkRenderer)ren1);
        renWin2.SetSize((int)256, (int)256);
        // Create the GUI: two renderer widgets and a quit button[]
        //tk window skipped..
        // Set the window manager (wm command) so that it registers a[]
        // command to handle the WM_DELETE_WINDOW protocal request. This[]
        // request is triggered when the widget is closed using the standard[]
        // window manager icons or buttons. In this case the exit callback[]
        // will be called and it will free up any objects we created then exit[]
        // the application.[]
        // Help label, frame and quit button[]
        //tk window skipped..
        //tk window skipped..
        //tk window skipped..

//deleteAllVTKObjects();
    }
Ejemplo n.º 5
0
		private static byte[] MipPixelDataFromVtkSlab(vtkImageData slabImageData)
		{
            VtkHelper.StaticInitializationHack();

#if true // Do our own MIP, albeit slowly
			int[] sliceDimensions = slabImageData.GetDimensions();
			int sliceDataSize = sliceDimensions[0] * sliceDimensions[1];
			IntPtr slabDataPtr = slabImageData.GetScalarPointer();

			byte[] pixelData = MemoryManager.Allocate<byte>(sliceDataSize * sizeof(short));

			// Init with first slice
			Marshal.Copy(slabDataPtr, pixelData, 0, sliceDataSize * sizeof(short));

			// Walk through other slices, finding maximum
			unsafe
			{
				short* psSlab = (short*) slabDataPtr;

				fixed (byte* pbFrame = pixelData)
				{
					short* psFrame = (short*)pbFrame;
					for (int sliceIndex = 1; sliceIndex < sliceDimensions[2]; sliceIndex++)
					{
						for (int i = 0; i < sliceDataSize-1; ++i)
						{
							int slabIndex = sliceIndex * sliceDataSize + i;
							if (psSlab[slabIndex] > psFrame[i])
								psFrame[i] = psSlab[slabIndex];
						}
					}
				}
			}

			return pixelData;

#else // Ideally we'd use VTK to do the MIP (MinIP, Average...)
				vtkVolumeRayCastMIPFunction mip = new vtkVolumeRayCastMIPFunction();
				vtkVolumeRayCastMapper mapper = new vtkVolumeRayCastMapper();

				mapper.SetVolumeRayCastFunction(mip);
				mapper.SetInput(slabImageData);

				//TODO: Need to figure out how to use mapper to output vtkImageData

				vtkImageAlgorithm algo = new vtkImageAlgorithm();
				algo.SetInput(mapper.GetOutputDataObject(0));
				
				using (vtkExecutive exec = mapper.GetExecutive())
				{
					VtkHelper.RegisterVtkErrorEvents(exec);
					exec.Update();

					// Note: These report no output port, must have to do something else to get mapper to give us data
					//return exec.GetOutputData(0);
					return mapper.GetOutputDataObject(0);
				}
#endif
		}
Ejemplo n.º 6
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVcursor3D(String [] argv)
    {
        //Prefix Content is: ""

          // This little example shows how a cursor can be created in []
          // image viewers, and renderers.  The standard TkImageViewerWidget and[]
          // TkRenderWidget bindings are used.  There is a new binding:[]
          // middle button in the image viewer sets the position of the cursor.  []
          // First we include the VTK Tcl packages which will make available []
          // all of the vtk commands to Tcl[]
          // Global values[]
          CURSOR_X = 20;
          CURSOR_Y = 20;
          CURSOR_Z = 20;
          IMAGE_MAG_X = 4;
          IMAGE_MAG_Y = 4;
          IMAGE_MAG_Z = 1;
          // Pipeline stuff[]
          reader = new vtkSLCReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/neghip.slc");
          // Cursor stuff[]
          magnify = new vtkImageMagnify();
          magnify.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          magnify.SetMagnificationFactors((int)IMAGE_MAG_X,(int)IMAGE_MAG_Y,(int)IMAGE_MAG_Z);
          image_cursor = new vtkImageCursor3D();
          image_cursor.SetInputConnection((vtkAlgorithmOutput)magnify.GetOutputPort());
          image_cursor.SetCursorPosition((double)CURSOR_X*IMAGE_MAG_X,(double)CURSOR_Y*IMAGE_MAG_Y,(double)CURSOR_Z*IMAGE_MAG_Z);
          image_cursor.SetCursorValue((double)255);
          image_cursor.SetCursorRadius((int)50*IMAGE_MAG_X);
          axes = new vtkAxes();
          axes.SymmetricOn();
          axes.SetOrigin((double)CURSOR_X,(double)CURSOR_Y,(double)CURSOR_Z);
          axes.SetScaleFactor((double)50.0);
          axes_mapper = vtkPolyDataMapper.New();
          axes_mapper.SetInputConnection((vtkAlgorithmOutput)axes.GetOutputPort());
          axesActor = new vtkActor();
          axesActor.SetMapper((vtkMapper)axes_mapper);
          axesActor.GetProperty().SetAmbient((double)0.5);
          // Image viewer stuff[]
          viewer = new vtkImageViewer();
          viewer.SetInputConnection((vtkAlgorithmOutput)image_cursor.GetOutputPort());
          viewer.SetZSlice((int)CURSOR_Z*IMAGE_MAG_Z);
          viewer.SetColorWindow((double)256);
          viewer.SetColorLevel((double)128);
          //method moved
          //method moved
          //method moved
          // Create transfer functions for opacity and color[]
          opacity_transfer_function = new vtkPiecewiseFunction();
          opacity_transfer_function.AddPoint((double)20,(double)0.0);
          opacity_transfer_function.AddPoint((double)255,(double)0.2);
          color_transfer_function = new vtkColorTransferFunction();
          color_transfer_function.AddRGBPoint((double)0,(double)0,(double)0,(double)0);
          color_transfer_function.AddRGBPoint((double)64,(double)1,(double)0,(double)0);
          color_transfer_function.AddRGBPoint((double)128,(double)0,(double)0,(double)1);
          color_transfer_function.AddRGBPoint((double)192,(double)0,(double)1,(double)0);
          color_transfer_function.AddRGBPoint((double)255,(double)0,(double).2,(double)0);
          // Create properties, mappers, volume actors, and ray cast function[]
          volume_property = new vtkVolumeProperty();
          volume_property.SetColor((vtkColorTransferFunction)color_transfer_function);
          volume_property.SetScalarOpacity((vtkPiecewiseFunction)opacity_transfer_function);
          composite_function = new vtkVolumeRayCastCompositeFunction();
          volume_mapper = new vtkVolumeRayCastMapper();
          volume_mapper.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          volume_mapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)composite_function);
          volume = new vtkVolume();
          volume.SetMapper((vtkAbstractVolumeMapper)volume_mapper);
          volume.SetProperty((vtkVolumeProperty)volume_property);
          // Create outline[]
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          outline_mapper = vtkPolyDataMapper.New();
          outline_mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outline_mapper);
          outlineActor.GetProperty().SetColor((double)1,(double)1,(double)1);
          // Create the renderer[]
          ren1 = vtkRenderer.New();
          ren1.AddActor((vtkProp)axesActor);
          ren1.AddVolume((vtkProp)volume);
          ren1.SetBackground((double)0.1,(double)0.2,(double)0.4);
          renWin2 = vtkRenderWindow.New();
          renWin2.AddRenderer((vtkRenderer)ren1);
          renWin2.SetSize((int)256,(int)256);
          // Create the GUI: two renderer widgets and a quit button[]
          //tk window skipped..
          // Set the window manager (wm command) so that it registers a[]
          // command to handle the WM_DELETE_WINDOW protocal request. This[]
          // request is triggered when the widget is closed using the standard[]
          // window manager icons or buttons. In this case the exit callback[]
          // will be called and it will free up any objects we created then exit[]
          // the application.[]
          // Help label, frame and quit button[]
          //tk window skipped..
          //tk window skipped..
          //tk window skipped..

        //deleteAllVTKObjects();
    }
Ejemplo n.º 7
0
    /// <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.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.SetInput((vtkDataObject)reader.GetGridOutput());
          readerSS.SetShift((double)min*-1);
          readerSS.SetScale((double)255/(max-min));
          readerSS.SetOutputScalarTypeToUnsignedChar();
          bounds = new vtkOutlineFilter();
          bounds.SetInput((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.SetInput((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.SetSource((vtkPolyData)Sphere.GetOutput());
          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();
    }
Ejemplo n.º 8
0
    /// <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();
    }