/// <summary> /// upon structure stored, update the structure vm collection /// </summary> /// <param name="methodID">the scan method invoke</param> /// <param name="response">response structure</param> void ImageStoredResponse_StructureStoredEvent(string methodID, Guid structureGuid) { LocalGeometryResourceManagerClient geometryResource = new LocalGeometryResourceManagerClient(); var sdc = geometryResource.GetStructure(structureGuid); _dispatcher.Invoke(() => { ICollectionView pgv = CollectionViewSource.GetDefaultView(_patientGroups); var pgvm = (PatientGroupViewModel)pgv.CurrentItem; if (pgvm != null && pgvm.PatientId.CompareTo(sdc.PatientId) == 0) { AddOrUpdate <StructureViewModel>(_structures, s => s.ROIName.CompareTo(sdc.ROIName) == 0, s => s.ROICount++, () => new StructureViewModel(sdc.Id, sdc.ROIName) { FrameOfReferenceUID = sdc.FrameOfReferenceUID, }); } }); if (sdc.Contours.Count < 2) { return; } }
private void UpdateStructures(PatientGroupViewModel patientGroupItem) { LocalGeometryResourceManagerClient gmsc1 = new LocalGeometryResourceManagerClient(); var sdcs = from guid in gmsc1.GetStructureResourceIds(patientGroupItem.PatientId) select gmsc1.GetStructure(guid); int countSeries = sdcs.Count(); foreach (var sdc in sdcs) { var smdc = gmsc1.GetSurfaceMeshByRelatedStructureId(sdc.Id); int meshVertices = smdc != null ? (int)smdc.VertexBuffer.ElementCount : 0; Dispatcher.Invoke(() => ImageSelectionManager.AddOrUpdate <StructureViewModel>( _imageSelectionManager._structures, s => s.ROIName.CompareTo(sdc.ROIName) == 0, s => { s.ROICount++; s.MeshStatus = (meshVertices > 0) ? string.Format("Meshed ({0} vertices)", meshVertices) : "<not meshed>"; }, () => new StructureViewModel(sdc.Id, sdc.ROIName) { FrameOfReferenceUID = sdc.FrameOfReferenceUID, MeshStatus = (meshVertices > 0) ? string.Format("Meshed ({0} vertices)", meshVertices) : "<not meshed>" })); } gmsc1.Close(); }
void pv_CurrentChanged(object sender, EventArgs e) { ICollectionView pv = CollectionViewSource.GetDefaultView(_imageDisplayManager._patientGroups); if (pv.CurrentItem == null) return; var patientGroupItem = (PatientGroupViewModel)pv.CurrentItem; _imageDisplayManager._series.Clear(); _imageDisplayManager._structures.Clear(); Task.Run(() => { LocalImageResourceManagerClient cmsc1 = new LocalImageResourceManagerClient(); cmsc1.ClearPrefetchStack(); var idcs = from guid in cmsc1.GetImageResourceIds(patientGroupItem.PatientId) select cmsc1.GetImage(guid); int count = idcs.Count(); foreach (var idc in idcs.Where(thisIdc => thisIdc != null)) { var ivdc = cmsc1.GetImageVolumeBySeriesInstanceUID(idc.SeriesInstanceUID); int volumeVoxels = 0; if (ivdc != null) { volumeVoxels = (int)ivdc.PixelBuffer.ElementCount; //cmsc1.PrefetchBuffer(ivdc.PixelBuffer); } Dispatcher.Invoke(() => ImageSelectionManager.AddOrUpdate<ImageSeriesViewModel>( _imageDisplayManager._series, s => s.SeriesInstanceUID.CompareTo(idc.SeriesInstanceUID) == 0, s => { s.InstanceCount++; s.ResampleStatus = (volumeVoxels > 0) ? string.Format("Resampled ({0} voxels)", volumeVoxels) : "<not resampled>"; }, () => { var isvm = ImageSeriesViewModel.Create(idc); isvm.ResampleStatus = (volumeVoxels > 0) ? string.Format("Resampled ({0} voxels)", volumeVoxels) : "<not resampled>"; return isvm; })); } var ivdcs = from guid in cmsc1.GetImageVolumeResourceIds(patientGroupItem.PatientId) select cmsc1.GetImageVolume(guid); count = ivdcs.Count(); foreach (var ivdc in ivdcs) { //int volumeVoxels = 0; //if (ivdc != null) //{ // volumeVoxels = (int)ivdc.PixelBuffer.ElementCount; // cmsc1.PrefetchBuffer(ivdc.PixelBuffer); //} Dispatcher.Invoke(() => ImageSelectionManager.AddOrUpdate<ImageSeriesViewModel>( _imageDisplayManager._series, s => s.SeriesInstanceUID.CompareTo(ivdc.Identity.SeriesInstanceUID) == 0, s => { s.ResampleStatus = (ivdc != null) ? string.Format("Resampled ({0} slices)", ivdc.Depth) : "<not resampled>"; }, () => { var isvm = ImageSeriesViewModel.Create(ivdc); isvm.ResampleStatus = (ivdc != null) ? string.Format("Resampled ({0} slices)", ivdc.Depth) : "<not resampled>"; return isvm; })); } cmsc1.Close(); }); Task.Run(() => { LocalGeometryResourceManagerClient cmsc1 = new LocalGeometryResourceManagerClient(); var sdcs = from guid in cmsc1.GetStructureResourceIds(patientGroupItem.PatientId) select cmsc1.GetStructure(guid); int countSeries = sdcs.Count(); foreach (var sdc in sdcs) { var smdc = cmsc1.GetSurfaceMeshByRelatedStructureId(sdc.Id); int meshVertices = smdc != null ? (int)smdc.VertexBuffer.ElementCount : 0; Dispatcher.Invoke(() => ImageSelectionManager.AddOrUpdate<StructureViewModel>( _imageDisplayManager._structures, s => s.ROIName.CompareTo(sdc.ROIName) == 0, s => { s.ROICount++; s.MeshStatus = (meshVertices > 0) ? string.Format("Meshed ({0} vertices)", meshVertices) : "<not meshed>"; }, () => new StructureViewModel(sdc.Id, sdc.ROIName) { FrameOfReferenceUID = sdc.FrameOfReferenceUID, MeshStatus = (meshVertices > 0) ? string.Format("Meshed ({0} vertices)", meshVertices) : "<not meshed>" })); } cmsc1.Close(); }); }
/// <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; }
/// <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); }