Beispiel #1
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
        }
Beispiel #2
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
		}