/// <summary>
        /// queues up meshing for a structure
        /// </summary>
        /// <param name="structureGuid">guid of structure to be meshed</param>
        static void MeshStructure(Guid structureGuid)
        {
            var meshingManager = new MeshingManagerClient();
            using (OperationContextScope contextScope = 
                new OperationContextScope(meshingManager.InnerChannel))
            {
                var methodId = Guid.NewGuid();
                MeshingManagerHelper.SetupResponseHeader(methodId);

                // create the request object
                MeshingRequest request = new MeshingRequest();
                request.StructureGuid = structureGuid;

                // and queue the request
                meshingManager.MeshStructure(request);
            }
            meshingManager.Close();
        }
Example #2
0
        /// <summary>
        /// begin meshing for a particular structure
        /// </summary>
        /// <param name="request"></param>
        public void MeshStructure(MeshingRequest request)
        {
            // store the return address
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            // notify that we are performing a meshing
            System.Diagnostics.Trace.WriteLine(
                string.Format("Meshing for structure {0} ({1} contours)",
                    request.StructureGuid,
                    request.ContourGuids != null 
                        ? request.ContourGuids.Count.ToString() : "?"));

            // create the engine
            MeshingEngineClient meshingEngine = new MeshingEngineClient();

            // synchronous call to perform meshing
            MeshingResponse response = meshingEngine.MeshStructure(request);
            meshingEngine.Close();

            // now construct the response proxy based on the return address
            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            MeshingResponseProxy proxy = new MeshingResponseProxy(binding, _responseAddress);

            // and set up the operation context to relay response info
            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                // send the response
                proxy.OnMeshingDone(response);
            }

            proxy.Close();
        }
Example #3
0
        /// <summary>
        /// synchronous call in to the meshing
        /// </summary>
        /// <param name="request">the request contract describing the meshing to be performed</param>
        /// <returns></returns>
        public MeshingResponse MeshStructure(MeshingRequest request)
        {
            // set up a resource accessor
            LocalGeometryResourceManagerClient cmsc1 =
                new LocalGeometryResourceManagerClient();

            // and get the designated structure
            StructureDataContract sdc = cmsc1.GetStructure(request.StructureGuid);

            System.Diagnostics.Trace.WriteLine(string.Format("Meshing for structure {0} {1} {2}",
                sdc.SeriesInstanceUID,
                sdc.SOPInstanceUID,
                sdc.Id.ToString(),
                sdc.Contours.Count));

            // System.Threading.Thread.Sleep(1000);

            // get the contours for the strucutre
            var contours = from guid in sdc.Contours
                           select cmsc1.GetPolygon(guid);

            // TODO: check that contours match those in the request contract

            // create the resulting surface mesh data contract
            SurfaceMeshDataContract smdc = new SurfaceMeshDataContract();

            // set up and calculate sizes
            smdc.FrameOfReferenceUID = sdc.FrameOfReferenceUID;
            smdc.RelatedStructureId = sdc.Id;
            smdc.VertexCount = contours.Sum(c => c.VertexCount);
            smdc.TriangleCount = smdc.VertexCount / 3;

            // create the mesh object, to allocate the buffers
            smdc = cmsc1.AddSurfaceMesh(smdc);

            // get a handle to the vertices
            var meshVertexHandle = smdc.VertexBuffer.GetHandle();
            ulong currentMeshOffset = 0;

            // now iterate over the the contours
            foreach (var contour in contours)
            {
                Vector3D[] vertices = new Vector3D[contour.VertexBuffer.ElementCount];

                // get access to the buffer
                var contourHandle = contour.VertexBuffer.GetHandle();

                // and copy from the contour...
                contourHandle.ReadArray<Vector3D>(0, vertices, 0, vertices.Length);

                // to the mesh vertex buffer
                meshVertexHandle.WriteArray<Vector3D>(currentMeshOffset, 
                    vertices, 0, vertices.Length);

                // and release
                contour.VertexBuffer.ReleaseHandle();
                contour.VertexBuffer.CloseMapping();

                // increment to the next position
                currentMeshOffset += (ulong)(vertices.Length 
                    * Marshal.SizeOf(typeof(Vector3D)));
            }

            // done with vertex buffer
            smdc.VertexBuffer.ReleaseHandle();
            smdc.VertexBuffer.CloseMapping();

            cmsc1.Close();

            // construct the response
            MeshingResponse response = new MeshingResponse();
            response.StructureGuid = sdc.Id;
            response.SurfaceMeshGuid = smdc.Id;
            return response;
        }