Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Saturday, June 25, 2016

Reflection

Back in the old days, C++ templates were the highest level of code abstraction for me. I loved creating template classes. On the other hand, Reflection, when I first learned about it, it didn't raise such an emotional feeling in me. It seamed like a complicated way to do simple things. About a year ago I was lucky to work with John Volkar from Bayer Healthcare. His project used Reflection to transform between C# data members and DICOM data elements. Recently, while working on another project, this technique came in handy. It's a nice example of how to use the Attribute class to link between a data member and a DICOM tag. Here it is. Thanks John.

First, how to you use it. It's very simple. Use the Tag attribute above the class member like this:

[Tag(0x0010,0x0010)]
public string patient_name;


This just mapped the patient_name member to a DICOM Patient Name data element by using the tag (0010,0010).

Tuesday, April 10, 2012

Low (Resolution) and Order (of applying transformations)

I'm doing a project that involves taking huge images of 400,000,000 pixels, 20000 X 20000, 700 MB on disk, scaling them down and cutting them into reasonably sized tiles (512x512 pixels).


In this post I want to present how simple code re factoring involving merely changing the order of applying the same transformations rewarded an enormous X20 performance gain.


As a first step, I had to order extra 8GB RAM for my workstation. Once thay have arrived (eBay, 100$, 1 week) I could finally click the input file and display it on windows image preview. Before that, my workstation, initially having only 2GB, hang for 20 minutes every time I accidentally hovered over the file.

The next step was to realize that .NET 2.0 bitmap classes won't do the trick. But than I was surprised to discover that WPF BitmapSource and its sub-classes (System.Windows.Media.Imaging) are capable of handling these very large images so I built the code around them avoiding a native C++ bite-cruncher completely. This was a very good start. It made me very happy.

The third step was to wrap the cropped images in DICOM. This is a subject for a dedicated, yet to come, post about the new multi-frame objects and concatenations. Then came the last two steps that proved out to be challenging.

My initial code looked like this:

  1. Use ScaleTransform to down-scale the original image to the required resolution
  2. Loop over the down-scaled image on X and Y to do the tiling (The Cut function)
  3. Use CroppedBitmap to do the cropping (in the loop)

Here it is:

Monday, August 23, 2010

Registry free COM using Side By Side Assemblies

Registry Free COM
[update 24 March 2023: latest HRZ softwarecan be found on HRZ website - www.hrzkit.com]

Did you know that you don't have to register a COM object in order to use it?
Well, I didn't. Until recently, when I was searching for something in the internet and bumped into this article in the MSDN library.
What this means, to me at least, is that there's no need to register RZDCX and thus it can be used in many applications that require no installation, because, as you know, to register a COM object in the registry you need administrative rights but to run an application from a CD you don't have to.

So, this post is all about using RZDCX.DLL with no installation.
For this purpose, we'll use one of the sample applications, for example the C# example EchoSCUExample.
All the examples with their source code can be downloaded from the DICOM download page.


Download the complete package with RZDCX.DLL, The manifest files, C++ Example and C# example.


In order to eliminate the use of registry, we'll create a manifest file for EchoSCUExample.exe and name it EchoSCUExample.exe.manifest

Next, we need to create a manifest file for RZDCX.DLL as well, name it rzdcx.X.manifest and save it in the same folder. Note that this is the manifest of the comming version 2.0.0.0 of RZDCX so some of the interfaces in it are not yet available in version 1.0.1.7 that is currently available on the web site.

Copy all four files (rzdcx.dll, rzdcx.X.manifest, EchoSCUExample.exe and EchoSCUExample.exe.manifest)  to a single directory, unregister RZDCX.DLL (using regsvr32.exe -u rzdcx.dll) so that you are absolutely sure that no registry is involved and double click EchoSCUExample.exe.

Enjoy!

Thursday, February 18, 2010

"Hacking" HL7Kit Pro Runtime Service to work with multiple HL7 applications

I know that it's not very common to show how to hack your own application but since this issue has been circling for a while, I'd like to show a workaround that will allow you to use the kit to integrate with many HL7 applications simultaneously.

The kit original design is to communicate with one remote application.


The workaround is to have multiple instances of the HL7 service running. The services can connect to the same database but each mush have it's own queue table.
Each will have it's own configuration file and it's own mapping rules file and mapping definitions but they will all write to the same log file and there can be only one active tray icon.

Here's how to set this up step by step:

  1. Stop the HL7 Service.
  2. In windows explorer navigate to the installation folder (default is c:\program files\rz software services\hl7) and make a copy of the folder, so you have hl7 and hl72.
  3. Create a copy of the HL7_QUEUE table so you have two queue tables or if you prefer, use each service on a different database schema.
  4. Use the HL7ServiceConfiguration.exe application in each folder to configure the port settings, mapping files and queue table names. Alternatively you can edit the HL7Service.exe.config file manually.
  5. Test your setup by running "HL7Service.exe -run" from two separate command line windows.
  6. Configure the new service to run on system startup. This is a bit tricky but here's a way that works:
    1. Run regedit
    2. navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HL7Service and export it.
    3. Edit the reg file and replace all "HL7Service" with "HL7Service2"
    4. Save it and double click it to import it to the registry.
    5. In regedit change the ImagePath entry of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HL7Service2 to the copied HL7 Folder (hl72)
    6. Restart the computer.
Now you should have two services installed: HL7Service and HL7Service2. 
Of course, you can duplicate them as well.

I hope to have a new release soon that will allow multiple destinations and sources of messages.

Roni