//普通模式_绘制 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); }
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 }
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(); }
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 }