예제 #1
0
        /// <summary>
        /// one-way call to resample an image volume
        /// </summary>
        /// <param name="seriesInstanceUID"></param>
        public void ResampleImageVolume(ImageVolumeResampleRequest request)
        {
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            ResampleEngineClient re = new ResampleEngineClient();

            ImageVolumeResampleResponse response = re.ResampleImageVolume(request);
            System.Diagnostics.Trace.Assert(response.ResampledImageVolumeGuid.CompareTo(Guid.Empty) != 0);

            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            ResampleResponseProxy proxy = new ResampleResponseProxy(binding, _responseAddress);

            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                proxy.OnResampleDone(response);
            }

            proxy.Close();
        }
예제 #2
0
        /// <summary>
        /// TODO: return response, not contract
        /// </summary>
        /// <param name="seriesInstanceUID"></param>
        /// <returns></returns>        
        public ImageVolumeResampleResponse ResampleImageVolume(ImageVolumeResampleRequest request)
        {
            LocalImageResourceManagerClient cmsc1 =
                new LocalImageResourceManagerClient();

            var imageIds = cmsc1.GetImageIdsBySeries(request.SeriesInstanceUID);
            if (imageIds.Count() == 0)
                return null;

            var imagesInSeries = (from guid in imageIds 
                                  select cmsc1.GetImage(guid)
                                  ).OrderBy(idc => -idc.ImagePosition.Z);

            var ivdc = new UniformImageVolumeDataContract();
            ivdc.Identity.SeriesInstanceUID = request.SeriesInstanceUID;
            ivdc.Identity.Label = imagesInSeries.First().Label;
            ivdc.Identity.PatientId = imagesInSeries.First().PatientId;
            ivdc.FrameOfReferenceUID = imagesInSeries.First().FrameOfReferenceUID;

            ivdc.Width = imagesInSeries.First().Width;
            ivdc.Height = imagesInSeries.First().Height;
            ivdc.Depth = imagesInSeries.Count();

            var imageOrientation = imagesInSeries.First().ImageOrientation;
            ivdc.VolumeOrientation = new VolumeOrientation()
            {
                Row = imageOrientation.Row,
                Column = imageOrientation.Column,
            };

            var voxelSpacing = new VoxelSize()
             {
                 X = imagesInSeries.First().PixelSpacing.X,
                 Y = imagesInSeries.First().PixelSpacing.Y,
                 Z = Math.Abs(imagesInSeries.First().ImagePosition.Z
                     - imagesInSeries.Last().ImagePosition.Z) / imagesInSeries.Count()
             };
            ivdc.VoxelSpacing = voxelSpacing;

            // take cross product
            // ivdc.DirectionZ = 

            ivdc = cmsc1.AddImageVolume(ivdc);

            var outVoxelHandle = ivdc.PixelBuffer.GetHandle();
            ushort[] frame = new ushort[imagesInSeries.First().PixelBuffer.ElementCount];
            ulong currentVoxelOffset = 0;
            foreach (var idc in imagesInSeries)
            {
                // get access to the buffer
                var inPixelHandle = idc.PixelBuffer.GetHandle();
                inPixelHandle.ReadArray<ushort>(0, frame, 0, frame.Length);
                outVoxelHandle.WriteArray<ushort>(currentVoxelOffset,
                    frame, 0, frame.Length);
                idc.PixelBuffer.ReleaseHandle();
                idc.PixelBuffer.CloseMapping();

                currentVoxelOffset += (ulong)(idc.PixelBuffer.ElementCount * sizeof(ushort));
            }

            ivdc.PixelBuffer.ReleaseHandle();
            ivdc.PixelBuffer.CloseMapping();

            cmsc1.Close();

            System.Diagnostics.Trace.Assert(ivdc != null);
            System.Diagnostics.Trace.Assert(ivdc.Identity != null);
            System.Diagnostics.Trace.Assert(ivdc.Identity.Guid.CompareTo(Guid.Empty) != 0);
            return new ImageVolumeResampleResponse()
            {
                SeriesInstanceUID = request.SeriesInstanceUID,
                ResampledImageVolumeGuid = ivdc.Identity.Guid
            };
        }
        /// <summary>
        /// performs resampling on a series
        /// </summary>
        /// <param name="seriesInstanceUID">the series UID to be used</param>
        static void ResampleVolumeForSeries(string seriesInstanceUID)
        {
            var resampleManager = new ResampleManagerClient();
            using (OperationContextScope contextScope = 
                new OperationContextScope(resampleManager.InnerChannel))
            {
                var methodId = Guid.NewGuid();
                ResampleDoneResponse.SetupResponseHeader(methodId);

                // create the request object
                ImageVolumeResampleRequest request = new ImageVolumeResampleRequest();
                request.SeriesInstanceUID = seriesInstanceUID;

                // and queue the request
                resampleManager.ResampleImageVolume(request);
            }
            resampleManager.Close();
        }