tag:blogger.com,1999:blog-75198343185449590832024-03-06T02:53:09.544+01:00Outcome CountsLessons learned from being a Cureos person.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.comBlogger56125tag:blogger.com,1999:blog-7519834318544959083.post-75574600672052122852015-09-10T09:18:00.000+02:002015-09-10T09:20:40.928+02:00Vote for the fo-dicom logo!<script>(function(e,t,s,c){var n,o,a;e.SMCX=e.SMCX||[],t.getElementById(c)||(n=t.getElementsByTagName(s),o=n[n.length-1],a=t.createElement(s),a.type="text/javascript",a.async=!0,a.id=c,a.src=["https:"===location.protocol?"https://":"http://","widget.surveymonkey.com/collect/website/js/WKHV05DlYufX9WckxZwfDb03ITZ_2F4EFUYpGsUByy4V7DII0NVHQZHqueSaAW0s8x.js"].join(""),o.parentNode.insertBefore(a,o))})(window,document,"script","smcx-sdk");</script><a style="font: 12px Helvetica, sans-serif; color: #999; text-decoration: none;" href=https://sv.surveymonkey.com/mp/customer-satisfaction-surveys/> Create your own user feedback survey </a>Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-7265902582036531172015-01-29T21:34:00.000+01:002015-04-01T17:47:04.150+02:00Portable AForge and Accord libraries - Now on NuGet!I have finally taken the step and published the <a href="https://github.com/cureos/aforge" target="_blank">Portable AForge.NET</a> and <a href="https://github.com/cureos/accord/" target="_blank">Portable Accord.NET</a> libraries on <a href="https://www.nuget.org/profiles/cureos" target="_blank">NuGet</a>!<br />
<br />
This means that it has now become a no-brainer to effortlessly include these libraries in your mobile or tablet application, regardless of whether you are developing with <i>Visual Studio</i> or <i>Xamarin Studio</i>.<br />
<br />
As a bonus teaser, I have also included evaluation builds of <i>Shim.Drawing</i> (the bridging library between the <i>Bitmap</i> class representation in <i>AForge</i> and <i>Accord</i> with the platform specific image classes) for <i>Xamarin Android</i>, <i>Xamarin iOS</i>, <i>Windows Phone 8.1</i> (non-Silverlight) and <i>Windows 8.1</i>. For <i>Xamarin iOS</i>, both the <i>Unified</i> and <i>Classic</i> <i>API</i>s are supported.<br />
<br />
The evaluation builds offer all functionality of the full version, but a watermark is added to images processed by <i>Shim.Drawing</i>. This means that it has now become extremely easy to test the <i>AForge.NET</i> and <i>Accord.NET</i> functionality on all relevant mobile and tablet platforms. After successful evaluation, the full version (without watermarks) of the <i>Shim.Drawing</i> library is available for purchase from <a href="mailto:licenses@cureos.com" target="_blank">Cureos</a>. The license cost as of January 29, 2015 is $100 for one platform (<i>Android</i>, <i>iOS</i>, <i>Windows Phone</i> or <i>Windows 8.1</i>), $150 for two platforms and $200 for all supported platforms.<br />
<br />
I have also updated the <a href="https://github.com/cureos/accord-samples" target="_blank">samples repository</a> on <i>Github</i> to use <i>NuGet</i>. In the samples repository you'll currently find an image stitching application for <i>Windows Phone Silverlight 8</i> and a <i>Xamarin Forms</i> face detection application for <i>Android</i>, <i>iOS</i> and <i>Windows Phone Silverlight 8</i>. The face detection application has recently been presented in more detail in <a href="http://cureos.blogspot.se/2014/10/smartphone-image-processing-development.html" target="_blank">this blog post</a>. More examples to get you started will be published soon.<br />
<br />
<h4>
Link summary</h4>
<ul>
<li>To purchase full versions of <i>Shim.Drawing</i> for one or more platforms, click on one button in the right-hand ad.</li>
<li><a href="https://github.com/cureos/aforge" target="_blank">Portable AForge.NET</a></li>
<li><a href="https://github.com/cureos/accord/" target="_blank">Portable Accord.NET</a></li>
<li><a href="https://www.nuget.org/profiles/cureos" target="_blank">Cureos' packages on NuGet</a></li>
<li><a href="https://github.com/cureos/accord-samples" target="_blank">Samples repository</a></li>
<li><a href="https://github.com/cureos/aforge/issues" target="_blank">Issue reporting for Shim.Drawing and Portable AForge.NET</a></li>
<li><a href="https://github.com/cureos/accord/issues" target="_blank">Issue reporting for Portable Accord.NET</a></li>
</ul>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com2tag:blogger.com,1999:blog-7519834318544959083.post-34489383873025199212014-10-22T22:57:00.002+02:002014-10-23T11:18:13.314+02:00Smartphone image processing development made easy!A very popular open source C# project for image processing, neural networks, machine learning etc. is the <a href="http://www.aforgenet.com/framework/" target="_blank">AForge.NET Framework</a>, developed by Andrew Kirillow. <i>AForge.NET</i> has been used in <a href="http://www.aforgenet.com/framework/projects.html" target="_blank">numerous applications</a>. It also forms the basis for the <a href="http://accord-framework.net/" target="_blank">Accord.NET Framework</a>, developed by César de Souza, which substantially extends <i>AForge.NET</i> with additional image processing filters, machine learning algorithms, statistical distributions and much much more. Numerous examples of what Accord.NET Framework is capable of are available <a href="http://accord-framework.net/samples.html" target="_blank">here</a>.<br />
<br />
<i>AForge.NET</i> was developed to run on the <i>.NET Framework</i> and uses the <i>System.Drawing</i> assembly as basis for image manipulation and processing. In particular the dependency on <i>System.Drawing</i> heavily limits the applicability of <i>AForge.NET</i> (and subsequently, <i>Accord.NET</i>) to more modern platforms, like <i>WPF</i>, <i>Windows </i>(for tablet and desktop, as opposed to desktop-only applications), and <i>Windows Phone</i>.<br />
<br />
It seemed like a terrible waste that these frameworks would only be available to the outdated range of <i>Windows Forms</i> applications. So, to enable the invaluable functionality of <i>AForge.NET</i> and <i>Accord.NET</i> for modern Microsoft platforms, I started the project of porting these frameworks into <i>Portable Class Libraries</i>, PCL. These efforts are also open sourced and are available on Github: <a href="https://github.com/cureos/aforge" target="_blank">Portable AForge</a> and <a href="https://github.com/cureos/accord" target="_blank">Portable Accord</a>.<br />
<br />
It should be noted that <i>Portable AForge</i> and <i>Portable Accord</i> cover a subset of the assemblies in the pure .NET based frameworks. Video and robotics support is not included, and audio support is limited. <i>Windows Forms</i> UI controls have not been ported. Nevertheless, practically all image processing and scientific computing functionality is included in the portable frameworks.<br />
<br />
To facilitate continuous inclusion of updated code for the two frameworks, I have striven to keep the original <i>AForge.NET</i> and <i>Accord.NET</i> code bases as untouched as realistically possible. To cover up for those parts of the framework codes that are not applicable in the portable class libraries, I have therefore developed two support assemblies called <i>Shim</i> and <i>Shim.Drawing</i>.<br />
<i><br /></i>
<i>Shim</i>, which contains simple implementations of non-UI types and methods unavailable in the PCL profiles, is maintained in a <a href="https://github.com/cureos/shim" target="_blank">separate Github repository</a>, since this assembly is also immediately applicable as a legacy code bridge in other modern target adaptations, such as the port of the <i>fo-dicom</i> library to the (modern) <i>Windows</i> and <i>Windows Phone</i> platforms.<br />
<i><br /></i>
<i>Shim.Drawing</i> is internal to the <i>Portable AForge</i> and <i>Accord</i> assemblies, and is contained in the <i>Portable AForge</i> Github repository. It provides a down-scaled replacement for the <i>System.Drawing</i> assembly. Along with the platforms of primary interest, <i>Shim.Drawing</i> can also be contained in a .NET Framework <i>WPF</i> project as long as <i>System.Drawing</i> is not simultaneously referenced. <i>Portable AForge</i> and <i>Accord </i>is thus a also shortcut to using <i>AForge.NET</i> and <i>Accord.NET</i> in <i>WPF </i>applications.<br />
<br />
To enable the portable framework assemblies on a specific target platform, the <i>Shim</i> and <i>Shim.Drawing</i> assemblies come in various flavors. There are for example specific <i>Windows Phone (Silverlight)</i> 8 versions of <i>Shim </i>and <i>Shim.Drawing</i> that should be referenced in a <i>WP8 </i>application using the <i>Portable AForge</i> and <i>Accord </i>assemblies.<br />
<br />
Currently, <i>Portable AForge</i> and <i>Portable Accord</i> are available for the following target platforms:<br />
<br />
<ul>
<li>.NET Framework 4.5 and higher (for <i>WPF </i>applications)</li>
<li>Windows 8 and higher (modern tablet/desktop applications)</li>
<li>Windows Phone Silverlight 8 and higher</li>
<li>Universal applications, i.e. Windows Phone 8.1 + Windows 8.1</li>
<li>Xamarin.iOS</li>
<li>Xamarin.Android</li>
</ul>
<div>
<br />
Yes, you read it right! My most recent developments also incorporate the ability to target the <i>Xamarin.iOS</i> and <i>Xamarin.Android</i> platforms. The <i>Xamarin </i>assemblies are however not available as open source. If you are interested in developing <i>AForge </i>and <i>Accord </i>based applications for <i>Xamarin.iOS</i> and/or <i>Xamarin.Android</i>, please contact me directly at <a href="mailto:licenses@cureos.com" target="_blank">licenses@cureos.com</a>.</div>
<div>
<br /></div>
<div>
And now, with <i>AForge </i>and <i>Accord </i>available on the three mobile platforms, cross-platform development using <a href="http://xamarin.com/forms" target="_blank">Xamarin.Forms</a> has also become a reality! This means that it is practically possible to contain an entire C# code base in a PCL core library that uses <i>AForge </i>and <i>Accord</i>, and consume this core library from end applications for all three mobile platforms, <i>Windows Phone</i>, <i>Xamarin.iOS</i> and <i>Xamarin.Android</i>.</div>
<div>
<br /></div>
<div>
Just to show what can now be very quickly done, I copied the functionality of the <a href="http://accord-framework.net/samples.html" target="_blank">Face Detection (Haar Object Selector) sample application</a> from the <i>Accord.NET</i> samples and contained it in a <i>Xamarin.Forms</i> project. All application code, including setting up the graphical layout and the face detection operation, is contained in the PCL core project. The platform specific end application projects only wrap the core assembly.</div>
<div>
<br /></div>
<div>
And this is what the face detection sample application looks like on the three mobile platforms:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ48l0wstvzhNCh22cItQBGcinXbsXVcar-g8IEhH78wBJP9OefQLN_WMatJj0t5s7JFWedbW0o1vkWYTy-NTVgvzXQ-pydSuyELIrb46b-lPUe7pd9NIyLQHA0scVv6Vk-4OdKKcryqWA/s1600/facedetection.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ48l0wstvzhNCh22cItQBGcinXbsXVcar-g8IEhH78wBJP9OefQLN_WMatJj0t5s7JFWedbW0o1vkWYTy-NTVgvzXQ-pydSuyELIrb46b-lPUe7pd9NIyLQHA0scVv6Vk-4OdKKcryqWA/s1600/facedetection.png" height="387" width="640" /></a></div>
<div>
<br /></div>
<div>
A first small step, perhaps, but the possibilities that have now been opened up are practically infinite :-)</div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com57tag:blogger.com,1999:blog-7519834318544959083.post-17399630786257411172014-08-18T09:44:00.000+02:002014-08-18T09:44:02.640+02:00PCL Tips and Tricks: String sbyte* constructor<i>The introduction of Portable Class Libraries, PCL, considerably facilitates the sharing of functionality across managed Microsoft and Xamarin platforms. I am very enthusiastic about the PCL concept, and I have ported several .NET Framework open source projects to Portable Class Libraries. Along the way I have stumbled across various issues of making .NET Framework source code PCL compliant. In this mini-series I'll share my experiences and workarounds to facilitate the transfer to PCL for other developers.</i><br />
<br />
Some of the PCL profiles do support <i>unsafe</i> code, in particular those profiles targeting <i>Windows 8</i> and <i>Windows Phone 8.1</i> (non-Silverlight). This means that it is possible to include for example pointers in the PCL code. On the other hand, methods dealing with unsafe code are rare in the <i>.NET Portable Subset</i>.<br />
<br />
One case I ran into the other day is the <span style="font-family: Courier New, Courier, monospace;">String</span> constructor. In .NET Framework, there are a few constructors taking an <span style="font-family: Courier New, Courier, monospace;">sbyte</span> pointer as an argument, <a href="http://msdn.microsoft.com/en-us/library/ezh7k8d5.aspx" target="_blank">for example</a>:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">public String(sbyte* value, int startIndex, int length)</span><br />
<br />
This constructor is not available in the <i>.NET Portable Subset</i>, so I had to come up with a replacement. And I came up with this portable method:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">static unsafe String NewString(</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> sbyte* value, int startIndex, int length)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> var chars = new char[length];</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> for (var i = 0; i < length; ++i)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> chars[i] = (char)value[startIndex + i];</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> return new String(chars);</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">}</span><br />
<br />
So, instead of calling <span style="font-family: Courier New, Courier, monospace;">new String(...)</span>, the calls were changed to <span style="font-family: Courier New, Courier, monospace;">NewString(...)</span>.<br />
<br />
I am still not entirely pleased with this approach of adding a new method to solve the issue. If any blog reader has a leaner solution to this issue, I am all ears.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-76792757530691093722014-06-07T17:06:00.000+02:002014-06-09T10:06:43.963+02:00Upgrading Caliburn Micro from 1.5 to 2.0 for a WPF applicationI am happy to see that the Model-View-View Model (MVVM) framework <a href="http://caliburnmicro.com/" target="_blank">Caliburn Micro</a> is adopting the Portable Class Library approach in version 2.0, and I thought that now would also be a good time to upgrade some of my existing applications from <i>Caliburn Micro</i> 1.5 to version 2.0.<br />
<br />
So far, this seems to be a painless experience, but I ran to a few issues after upgrading to 2.0 via NuGet. I'd thought I share these experiences in case someone else is facing the same issues.<br />
<br />
The application in question is a WPF application, and it is using the <i>Managed Extensibility Framework</i> (MEF) for bootstrapping the application.<br />
<br />
When trying to build the application immediately after the upgrade, I ran into a compilation error in the class definition line of my MEF bootstrapper class:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><strike>public MefBootstrapper : Bootstrapper<IShell></strike></span><br />
<br />
<i>error CS0246: The type or namespace name 'Bootstrapper' could not be found (are you missing a using directive or an assembly reference?)</i><br />
<br />
Searching the Caliburn Micro documentation, I found that the bootstrapper base class is now called ... <span style="font-family: Courier New, Courier, monospace;">BootstrapperBase</span>! And it is non-generic.<br />
<br />
OK, this change seems easy:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">public MefBootstrapper : BootstrapperBase</span><br />
<br />
Hooray, the application builds! Let's run it. And wait ... and wait ... and wait ... but it never starts?<br />
<br />
Of course! Since the bootstrapper base class is now non-generic, there is no way for the bootstrapper to know which <i>View</i> it should start displaying, unless it is explicitly being told which <i>View</i> it should display. And according to <a href="https://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper" target="_blank">this</a> documentation page, the fix is easy; just add<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">DisplayRootViewFor<IShell>();</span><br />
<br />
to the overridden <span style="font-family: Courier New, Courier, monospace;">OnStartup</span> method.<br />
<br />
Let's try to run the application again. Still no sight of the root window. What is missing?<br />
<br />
Looking more closely into the bootstrapper implementation example <a href="https://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper" target="_blank">here</a>, the constructor also seems to perform some initialization operation. This was not necessary with the pre-2.0 <i>Caliburn Micro</i> versions, most likely because the base class constructor performed this operation instead. But with 2.0 it seems to be necessary to also implement the bootstrapper constructor explicitly. According to the migration instructions <a href="http://caliburnmicro.com/documentation/migrating-to-2.0.0" target="_blank">here</a> it also seems like the <span style="font-family: Courier New, Courier, monospace;">Start</span> method has been renamed <span style="font-family: Courier New, Courier, monospace;">Initialize</span>. So, here goes:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">public MefBootstrapper() { Initialize(); }</span><br />
<br />
Run the application, and ... <i>Yes</i>! The start-up window appears!<br />
<br />
To summarize: when upgrading a WPF/MEF application from using <i>Caliburn Micro</i> version 1.5 or earlier to version 2.0, make sure the following details are in place:<br />
<br />
<ul>
<li>The MEF based bootstrapper class should inherit from <span style="font-family: Courier New, Courier, monospace;">BootstrapperBase</span>.</li>
<li>The root view will be displayed by calling <span style="font-family: Courier New, Courier, monospace;">DisplayRootViewFor<></span> in the overridden <span style="font-family: Courier New, Courier, monospace;">OnStartup</span> method.</li>
<li>The bootstrapper default constructor must be explicitly defined, and call the <span style="font-family: Courier New, Courier, monospace;">Initialize()</span> method.</li>
</ul>
<div>
<b><br /></b>
<b>EDIT</b><br />
<br />
Ironically, when I started upgrading my second application I faced a completely different compilation error:<br />
<br />
<i>error CS1501: No overload for method 'Publish' takes 1 arguments</i><br />
<br />
But this issue has a quick and easy fix, as pointed out in the <a href="http://caliburnmicro.com/documentation/migrating-to-2.0.0" target="_blank">migration instructions</a>:<br />
<span style="white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span>
<span style="white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">EventAggregator.Publish</span></span><span style="font-family: inherit; font-style: italic; white-space: pre-wrap;"> now takes an action to marshal the event. Use </span><span style="white-space: pre-wrap;"><span style="font-family: Courier New, Courier, monospace;">EventAggregator.PublishOnUIThread</span></span><span style="font-family: inherit; font-style: italic; white-space: pre-wrap;"> for the existing behaviour.</span><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com10tag:blogger.com,1999:blog-7519834318544959083.post-71003967194847639322014-06-05T22:08:00.000+02:002014-06-05T22:08:40.826+02:00PCL Tips and Tricks: Extension methods to the rescue<i>The introduction of Portable Class Libraries, PCL, considerably facilitates the sharing of functionality across managed Microsoft and Xamarin platforms. I am very enthusiastic about the PCL concept, and I have ported several .NET Framework open source projects to Portable Class Libraries. Along the way I have stumbled across various issues of making .NET Framework source code PCL compliant. In this mini-series I'll share my experiences and workarounds to facilitate the transfer to PCL for other developers.</i><br />
<br />
Now, here is a very common scenario when porting .NET class libraries to PCL:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">public class SomeClassToPort</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public static byte[] SomeMethodToPort()</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> var stream = new MemoryStream();</span><br />
<span style="font-family: Courier New, Courier, monospace;"> var writer = new StreamWriter(stream);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> writer.Write("Result: {0}, {1}", 10, "Hello");</span><br />
<span style="font-family: Courier New, Courier, monospace;"> // some more writer operations ...</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;"> writer.Close(); // Non-existent in PCL</span><br />
<span style="font-family: Courier New, Courier, monospace;"> stream.Close(); // Non-existent in PCL</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> return stream.ToArray();</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<div>
<br /></div>
<div>
Correct, the <span style="font-family: Courier New, Courier, monospace;">Close()</span> method is not available for streams, readers or writers in Portable Class Libraries! <a href="http://referencesource.microsoft.com/#mscorlib/system/io/stream.cs#240" target="_blank">Since the method in practice only executes <span style="font-family: Courier New, Courier, monospace;">Dispose()</span></a>, the <span style="font-family: Courier New, Courier, monospace;">Close()</span> method has been excluded from PCL. Trying to build this code yields the following error:</div>
<div>
<br /></div>
<div>
<i>error CS1061: 'System.IO.MemoryStream' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'System.IO.MemoryStream' could be found (are you missing a using directive or an assembly reference?)</i></div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">Dispose()</span> is generally available in PCL, so one solution is to replace all <span style="font-family: Courier New, Courier, monospace;">Close()</span> calls with <span style="font-family: Courier New, Courier, monospace;">Dispose()</span>. For those wanting to avoid the hassle and maintenance issues of replacing (potentially numerous) Close() calls, there is however a workaround.</div>
<div>
<br /></div>
<div>
Enter <a href="http://msdn.microsoft.com/en-us//library/bb383977.aspx" target="_blank">Extension Methods</a>!</div>
<div>
<br /></div>
<div>
Extension methods are a perfect fit for dealing with a scenario like the above. You can just add a static class with an arbitrary name to the PCL library, with code similar to this:</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">public static class CloseExtensions</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">{</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public static void Close(this Stream stream)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> {</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> stream.Dispose();</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public static void Close(this TextWriter writer)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> {</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> writer.Dispose();</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">}</span></div>
</div>
<div>
<br /></div>
<div>
Now, the compiler will "translate" <span style="font-family: Courier New, Courier, monospace;">stream.Close()</span> into the call <span style="font-family: Courier New, Courier, monospace;">CloseExtensions.Close(stream)</span> (analogously for the <span style="font-family: Courier New, Courier, monospace;">StreamWriter</span> object) and the Portable Class Library can then build successfully. The extension methods perform practically the same operations as the <span style="font-family: Courier New, Courier, monospace;">Close()</span> methods in the .NET Framework. Subsequent calls to <span style="font-family: Courier New, Courier, monospace;">Dispose()</span> have no effect, so this implementation should be fail-safe. </div>
<div>
<br /></div>
<div>
There is also no risk of name clashes; even when the PCL library is used in a .NET application the original <span style="font-family: Courier New, Courier, monospace;">Close()</span> methods and the corresponding extension methods have completely different signatures (they can just be expressed equivalently in the code).</div>
<div>
<br /></div>
<div>
The <span style="font-family: Courier New, Courier, monospace;">Close()</span> methods are probably the most obvious examples where this extension method technique can be applied, but whenever a PCL profile is not including an <i>instance</i> method of one type, the same technique may be applied. Other examples from the top of my head are:</div>
<div>
<ul>
<li>several methods from the <span style="font-family: Courier New, Courier, monospace;">Type</span> class which are not available for Windows 8 (f.k.a. Store or Metro apps); much of this functionality has been replaced by <span style="font-family: Courier New, Courier, monospace;">TypeInfo</span> instance and extension methods,</li>
<li><span style="font-family: Courier New, Courier, monospace;">Stream.BeginRead</span>, <span style="font-family: Courier New, Courier, monospace;">Stream.EndRead</span>, <span style="font-family: Courier New, Courier, monospace;">Stream.BeginWrite</span> and <span style="font-family: Courier New, Courier, monospace;">Stream.EndWrite</span>; again not available for Windows 8 but can be simulated using extension methods.</li>
</ul>
</div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-41431619789514988312014-05-22T20:10:00.000+02:002014-05-22T20:10:25.738+02:00BioSuite and DICOMA few years ago Dr. Julian Uzan together with Professor Alan Nahum developed a comprehensive research tool for radiobiological evaluation and optimization, called <a href="http://www.birpublications.org/doi/full/10.1259/bjr/20476567" target="_blank">BioSuite</a>. The tool has continuously evolved and has been made available at no extra cost for the participants of the <a href="http://www.clatterbridgecc.nhs.uk/professionals/education_courses/radiobiologycourse2013.html" target="_blank">Clatterbridge Radiobiological Modeling course</a> that is being held (more or less) annually.<br />
<br />
<i>BioSuite</i> uses input from treatment planning systems in the form of differential dose-volume histograms (DVHs). More specifically, the tool supports DVHs exported from <a href="http://www.healthcare.philips.com/main/products/ros/products/pinnacle3/" target="_blank">Philips Pinnacle³</a> and <a href="http://www.varian.com/euen/oncology/radiation_oncology/eclipse/" target="_blank">Varian Eclipse</a>. One format <i>BioSuite</i> does not support though, is <a href="http://medical.nema.org/" target="_blank">DICOM</a>!<br />
<br />
To overcome this limitation, I have developed a simple preprocessing tool called the <i>BioSuite Exporter</i>. This tool allows the user to import DICOM RT Plans, RT Structure Sets and RT Doses,<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMvpx4ETGzaoSNPuMKqZ2cit3tR7U5M5JZ16y86YSUYF68iYTzcrCHObPFEI_IQ8Lz8FyMKUIIutLpCULOZAeQ3brTsEwU3tq8H3_9gZjh3zZgHoii1QiLQTKD6yJPn8Emth4I8wCUpJvc/s1600/biosuite-import.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMvpx4ETGzaoSNPuMKqZ2cit3tR7U5M5JZ16y86YSUYF68iYTzcrCHObPFEI_IQ8Lz8FyMKUIIutLpCULOZAeQ3brTsEwU3tq8H3_9gZjh3zZgHoii1QiLQTKD6yJPn8Emth4I8wCUpJvc/s1600/biosuite-import.png" height="160" width="320" /></a></div>
<br />
and based on this data the tool computes the resulting dose volume-histograms associated with each RT Plan for the regions of interest in the RT Structure Set. The user can view the dose-volume histograms and select a subset of the DVHs for export.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEJigKjgB6B_RByzeucaUEahy1XlrBm6o4Jya6aCNJltH2ozWssG9tF7B5rDcNtcQTxH3-qpEXXItSIYo5dO4200LBN3n1BtKs19IvkrMnyvN1F-kyd5p8HwAHczo8J7WkGbYWWslDM45W/s1600/biosuite-export.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEJigKjgB6B_RByzeucaUEahy1XlrBm6o4Jya6aCNJltH2ozWssG9tF7B5rDcNtcQTxH3-qpEXXItSIYo5dO4200LBN3n1BtKs19IvkrMnyvN1F-kyd5p8HwAHczo8J7WkGbYWWslDM45W/s1600/biosuite-export.png" height="173" width="320" /></a></div>
<br />
Upon export, <i>BioSuite Exporter</i> writes absolute volume, differential dose-volume histograms for each of the selected regions-of-interest in a comma-separated value (CSV) format that can be imported by <i>BioSuite</i>.<br />
<br />
For <i>BioSuite</i> users and others interested in obtaining a free copy of this tool, please contact me at <a href="mailto:biosuite@cureos.com">biosuite@cureos.com</a>.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com1tag:blogger.com,1999:blog-7519834318544959083.post-31890483824540135512014-05-21T19:27:00.002+02:002014-05-21T19:46:36.071+02:00Arrays are bound to get you into troubleA few days ago I read <a href="http://blogs.msdn.com/b/ericlippert/archive/2008/09/22/arrays-considered-somewhat-harmful.aspx" target="_blank">this old yet informative blog post</a> by Eric Lippert, about why it is good practice to avoid arrays as much as possible in your C# code. Since I am working a lot with numerical computations, I <i>do</i> use arrays quite a lot since they tend to be faster than class-based collections such as <span style="font-family: Courier New, Courier, monospace;">List<T></span> etc. for my particular purposes. Nevertheless, Eric's article is a good eye-opener on the caveats associated with arrays.<br />
<br />
Ironically, I today stumbled into a serious problem involving arrays and multiple threads. It was not obvious from the start that it would lead to problems, but it certainly did.<br />
<br />
Somewhat simplified, I had one <i>pre-sorted</i> key array with no duplicate entries and a collection of value arrays. The value arrays were subject to some operation from a 3rd-party library that involved sorting based on the <i>key</i> array. The operation on one value array would be independent of the operations on the other arrays, so I decided to parallelize the process to gain time. Schematically, the code looked like this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">double[] x = GetSortedKeyArray();</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">var y = new double[samples][];</span><br />
<span style="font-family: Courier New, Courier, monospace;">for (var i = 0; i < samples; ++i) y[i] = GetValueArray(i);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Parallel.For(</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 0,</span><br />
<span style="font-family: Courier New, Courier, monospace;"> samples,</span><br />
<span style="font-family: Courier New, Courier, monospace;"> i =></span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ThirdPartyLibMethodUsingArraySort(x, y[i]);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> });</span><br />
<div>
<br /></div>
<div>
And in the 3rd-party library:</div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">public void ThirdPartyLibMethodUsingArraySort(</span><br />
<span style="font-family: Courier New, Courier, monospace;"> double[] x, </span><br />
<span style="font-family: Courier New, Courier, monospace;"> double[] y)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">{</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> ...</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> Array.Sort(x, y);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> ...</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">}</span></div>
<div>
<br /></div>
<div>
Since the <i>key</i> array was already sorted before the first call to the 3rd-party library method, I never imagined that the <span style="font-family: Courier New, Courier, monospace;">Array.Sort</span> call would cause any trouble. As long as the number of items in the key and value arrays were no more than 16, it did not either. But for 17 items and above, chaos!</div>
<div>
<br /></div>
<div>
If the number of items in the key and value arrays exceeded 16 and the number of value arrays were large enough (of the order of hundreds on my machine), the <span style="font-family: Courier New, Courier, monospace;">Array.Sort</span> method would on some calls return duplicates in the key array <span style="font-family: Courier New, Courier, monospace;">x</span>. Of course, once this error started appearing, it would continue to propagate and completely run havoc with the supposedly immutable key array.</div>
<div>
<br /></div>
<div>
Reading the MSDN documentation on <a href="http://msdn.microsoft.com/en-us/library/85y6y2d3.aspx" target="_blank">Array.Sort</a>, it seems like array size 16 is an important limit, where the sorting internally switch from an <a href="http://en.wikipedia.org/wiki/Insertion_sort" target="_blank">insertion sort</a> algorithm to a <a href="http://en.wikipedia.org/wiki/Quicksort" target="_blank">Quicksort</a> algorithm. The Quicksort algorithm apparently does not account for the fact that the incoming array might already be sorted and shuffles around the data. When the same array is then entering <span style="font-family: Courier New, Courier, monospace;">Array.Sort</span> from another thread before the previous thread is finished, things are bound to go wrong.</div>
<div>
<br /></div>
<div>
What I had to do in the end was to copy the contents of <span style="font-family: Courier New, Courier, monospace;">x</span> to a temporary array before each call to the 3rd-party library method, and call the method using the temporary array instead:</div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> var tmp = new double[x.Length];</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Array.Copy(x, tmp, x.Length);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ThirdPartyLibMethodUsingArraySort(tmp, y[i]);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<br /></div>
<div>
Take-home message: you can never be <i>too</i> careful with array immutability in a multi-threaded context.</div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-79340582513230427232014-05-19T22:36:00.000+02:002014-05-20T08:24:22.884+02:003D scatter plots for WPF and Windows 8A few years ago I was searching for an open source solution for creating 3-D scatter plots with WPF. Googling around eventually led me to <a href="http://www.codeproject.com/Articles/42174/High-performance-WPF-D-Chart" target="_blank">this solution</a> on CodeProject.<br />
<br />
I have used this solution in a few of my projects since, but as far as I have been able to tell, the library has not evolved at all since the article was published in 2009.<br />
<br />
Recently, I came across a newer 3-D drawing and charting project for WPF, namely the <a href="https://helixtoolkit.codeplex.com/" target="_blank">Helix 3D Toolkit</a>. This project is actively developed, mainly by Øystein Bjørke, it has a vibrant user community and it is also available for Windows 8 applications (i.e. "Metro")!<br />
<br />
First glancing at the library, I could not find any 3-D scatter plot solution. Fortunately, Øystein <a href="https://helixtoolkit.codeplex.com/discussions/542536" target="_blank">proposed a solution</a> based on one of the surface plot examples in one of the sample applications. Based on Øystein's suggestion I today created a very simple 3-D scatter plot example for <i>Helix 3D Toolkit</i>. It looks like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRx7NB8y5LqmX16Yuvi8D1LGlgN57o9ET9aHZlqmIp_wRqbjUN6tCs7JZh_NMJMVK3gI0QBrZMGVUSAy1cCZWHC7mH73ndosOEvC39oG1x1d6Tlw-Su0KZs7v-5GTVLfezVtfTzC6BOigR/s1600/ScatterPlotDemo_small.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRx7NB8y5LqmX16Yuvi8D1LGlgN57o9ET9aHZlqmIp_wRqbjUN6tCs7JZh_NMJMVK3gI0QBrZMGVUSAy1cCZWHC7mH73ndosOEvC39oG1x1d6Tlw-Su0KZs7v-5GTVLfezVtfTzC6BOigR/s1600/ScatterPlotDemo_small.png" height="240" width="320" /></a></div>
<br />
Nothing fancy, just a proof of concept. Anyway, I made <a href="https://helixtoolkit.codeplex.com/SourceControl/network/forks/cureos/Issue10039/contribution/6841" target="_blank">a pull request</a> that Øystein kindly accepted, and my example is <a href="https://helixtoolkit.codeplex.com/SourceControl/latest#Source/Examples/WPF/ExampleBrowser/Examples/ScatterPlot/" target="_blank">now included</a> in the <i>Helix 3D Toolkit</i> example collection.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com2tag:blogger.com,1999:blog-7519834318544959083.post-34710871178942617182014-05-16T11:52:00.001+02:002014-05-16T12:33:28.716+02:00What does the _ in lambda expressions stand for?While reading <a href="http://blog.stephencleary.com/2014/05/a-tour-of-task-part-1-constructors.html" target="_blank">this interesting blog post</a> by Stephen Cleary, I noticed that he used the following lambda construct in some of the code:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">_ => action()</span><br />
<br />
At first, I couldn't figure out what it meant, but like so many times before, Google search came to the rescue (<a href="http://stackoverflow.com/q/424775" target="_blank">here</a> and <a href="http://charlieflowers.wordpress.com/2009/04/02/nice-c-idiom-for-parameterless-lambdas/" target="_blank">here</a>).<br />
<br />
It turns out that this is a C# idiom. Since _ (underscore) is a valid C# identifier, it is applied here to represent an <i>ignored</i> identifier in a <i>single-input-parameter</i> lambda expression. It is the same as writing for example:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">x => action()</span><br />
<br />
or<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">(x) => action()</span><br />
<br />
but it is thought to be more obvious that the parameter on the left-hand-side of the lambda expression will be ignored if an underscore identifier is used.<br />
<br />
Now, the <a href="http://stackoverflow.com/a/680681" target="_blank">accepted answer</a> on StackOverflow and the <a href="http://charlieflowers.wordpress.com/2009/04/02/nice-c-idiom-for-parameterless-lambdas/" target="_blank">associated blog post</a> is a little careless with the wording: this idiom is actually <b><i>not</i></b> applicable to parameter-less lambdas, i.e. the empty parentheses <span style="font-family: Courier New, Courier, monospace;">()</span> in<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">() => action()</span><br />
<br />
<b><i>cannot</i></b> be replaced with <span style="font-family: Courier New, Courier, monospace;">_</span><span style="font-family: inherit;">.</span> This would imply a mismatch between the number of input parameters in the <span style="font-family: Courier New, Courier, monospace;">()</span> lambda expression (0), and <span style="font-family: Courier New, Courier, monospace;">_</span> (1). Trying to use <span style="font-family: Courier New, Courier, monospace;">_</span> with parameter-less lambdas will inevitably lead to compilation errors.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-3226779497969897052014-05-16T07:44:00.002+02:002014-05-16T11:52:55.356+02:00PCL Tips and Tricks: List.ForEach<i>The introduction of Portable Class Libraries, PCL, considerably facilitates the sharing of functionality across managed Microsoft and Xamarin platforms. I am very enthusiastic about the PCL concept, and I have ported several .NET Framework open source projects to Portable Class Libraries. Along the way I have stumbled across various issues of making .NET Framework source code PCL compliant. In this mini-series I'll share my experiences and workarounds to facilitate the transfer to PCL for other developers.</i><br />
<br />
The <a href="http://msdn.microsoft.com/en-us/library/bwabdf9z.aspx" target="_blank">List<T>.ForEach</a> method is available on all managed Microsoft platforms, except one: <i>Windows 8</i> (f.k.a. <i>Windows Store</i> or <i>Metro</i>). Possibly as a consequence of this, it is also <b><i>not</i></b> available in the <i>Portable Class Libraries</i>, not even when <i>Windows 8</i> is not targeted.<br />
<br />
The exact reasons for leaving out <span style="font-family: Courier New, Courier, monospace;">List<T>.ForEach</span> from <i>Windows 8</i> and <i>PCL</i> is unknown to me, but maybe the library maintainers want to discourage developers from using this method since it allows for side effects in a functional context (thanks Vagif Abilov for pointing this out). Fortunately, there is a simple replacement that should work practically always: use <span style="font-family: Courier New, Courier, monospace;">foreach</span> instead!<br />
<br />
So, instead of:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">List<string> strs = ...;</span><br />
<span style="font-family: Courier New, Courier, monospace;">strs.ForEach(str => DoSometing(str));</span><br />
<br />
Use this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">List<string> strs = ...;</span><br />
<span style="font-family: Courier New, Courier, monospace;">foreach (var str in strs) { DoSomething(str); }</span><br />
<br />
I recently looked into the <a href="http://www.angusj.com/delphi/clipper.php" target="_blank">Clipper</a> project, which is an open source library for clipping and offseting 2D polygons, available in several languages. I examined the C# source code, and it turned out that the author had used the <span style="font-family: Courier New, Courier, monospace;">List<T>.ForEach</span> construct in his code. This was in fact the only issue preventing the C# <i>Clipper</i> code from being truly portable. Therefore, as a feature request I asked him to use <span style="font-family: Courier New, Courier, monospace;">foreach</span> instead. This feature request was later implemented, and it is now possible to take the entire <a href="https://sourceforge.net/p/polyclipping/code/HEAD/tree/trunk/C%23/clipper_library/clipper.cs" target="_blank">clipper.cs</a> file and include it in any <i>Portable Class Library</i>.<br />
<br />
Here are a few links about <span style="font-family: Courier New, Courier, monospace;">List<T>.ForEach</span> vs. <span style="font-family: Courier New, Courier, monospace;">foreach</span>:<br />
<br />
<ul>
<li><a href="http://stackoverflow.com/q/225937/650012" target="_blank">StackOverflow question and answers</a></li>
<li><a href="https://msmvps.com/blogs/jon_skeet/archive/2006/01/20/foreachperf.aspx" target="_blank">Jon Skeet blog post on performance</a></li>
</ul>
<br />
<br />Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-87588965026341176962014-05-14T21:47:00.003+02:002014-05-14T21:47:59.760+02:00Open source project of the day: Meta.Numerics<i>Over the last four years I have contributed a fair amount of code to the open source community. Some of these projects I have initiated myself, other projects are forks of existing projects that I have adapted to Portable Class Libraries or new target platforms. The projects range from optimization and scientific computing, over medical imaging and image processing to utility libraries. In this mini-series I intend to give a short introduction to each of these open source projects.</i><br />
<div>
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/t1.0-1/p160x160/183082_169502093097331_3996728_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/t1.0-1/p160x160/183082_169502093097331_3996728_n.jpg" /></a></div>
<div>
<i><br /></i></div>
<div>
<i>Meta.Numerics</i> is an open source <span style="font-family: inherit;"><span style="font-size: 15px;">library for advanced scientific computation in the .NET Framework, with a bias towards statistical computations. The main web site is located <a href="http://www.meta-numerics.net/" target="_blank">here</a>, whereas the library source code is available on <a href="https://metanumerics.codeplex.com/" target="_blank">CodePlex</a>. The library has less functionality than another open source library for scientific computation, <a href="http://numerics.mathdotnet.com/" target="_blank">Math.NET Numerics</a>, but at the same time it also has a substantially smaller footprint and a simple-to-use API.</span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;"><br /></span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;">Today, I stumbled across a </span></span><i style="font-size: 15px;">Meta.Numerics</i><span style="font-size: 15px;"> </span><span style="font-family: inherit;"><span style="font-size: 15px;"><a href="https://metanumerics.codeplex.com/releases/view/110664#ReviewsAnchor" target="_blank">review</a> and noticed that one potential user was disappointed that the library did not seem to be available for <i>Windows Store</i>/<i>Metro</i>/<i>WinRT</i> applications. </span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;"><br /></span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;">However, <i>Meta.Numerics</i> <i><b>is</b></i> available for this platform target, and for <i>Windows Phone</i>, <i>Silverlight</i>, <i>Xamarin.Android</i> and <i>Xamarin.iOS</i> applications as well, which I have also reported to the previously disappointed developer. </span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;"><br /></span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;">It so happens, that <i>Meta.Numerics</i> is one of the projects that I have adapted to a <i>Portable Class Library</i>! Originally, I ported the library to <i>Silverlight</i> only and these changes were eventually merged into the original source code. When <i>PCL</i> showed up it was however a simple task to continue the adaptation to the entire <i>PCL</i> range of targets.</span></span></div>
<div>
<span style="font-family: inherit;"><span style="font-size: 15px;"><br /></span></span></div>
<div>
<span style="font-size: 15px;">Since the library primarily is concerned with mathematical computations, it was fairly simple to port it to a wide-ranging <i>PCL</i> library. The only functionality I have not been able to port is the binary serialization of a few classes, and some ADO.NET based methods for initializing statistical samples.</span></div>
<div>
<span style="font-size: 15px;"><br /></span></div>
<div>
<span style="font-size: 15px;">I have done my best to update the <i>PCL</i> library whenever new source code is committed to the original .NET library. The <i>PCL</i> version of <i>Meta.Numerics</i> is available on <a href="https://github.com/cureos/metanumerics" target="_blank">Github</a>.</span></div>
<div>
<i><br /></i></div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com6tag:blogger.com,1999:blog-7519834318544959083.post-48082648626554738562014-05-13T21:30:00.001+02:002014-05-14T08:15:39.668+02:00PCL Tips and Tricks: Hashtable<i>The introduction of Portable Class Libraries, PCL, considerably facilitates the sharing of functionality across managed Microsoft and Xamarin platforms. I am very enthusiastic about the PCL concept, and I have ported several .NET Framework open source projects to Portable Class Libraries. Along the way I have stumbled across various issues of making .NET Framework source code PCL compliant. In this mini-series I'll share my experiences and workarounds to facilitate the transfer to PCL for other developers.</i><br />
<br />
C# code that has its roots in pre-generic time (.NET Framework 1.x, that is) often tend to contain non-generic collections such as <span style="font-family: Courier New, Courier, monospace;">ArrayList</span> and <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx" target="_blank">Hashtable</a>. In the Portable Class Libraries however, non-generic collections are avoided to the largest possible extent, and <span style="font-family: Courier New, Courier, monospace;">Hashtable</span> is one of the missing classes.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Hashtable</span> is simply a non-generic dictionary (it implements <a href="http://msdn.microsoft.com/en-us/library/system.collections.idictionary.aspx" target="_blank">IDictionary</a>) and it also shares the main methods and properties with the generic <a href="http://msdn.microsoft.com/en-us/library/vstudio/xfhwa508.aspx" target="_blank">Dictionary<TKey, TValue></a> class, which is available across all PCL profiles.<br />
<br />
It is thus actually quite straightforward to replace all <span style="font-family: Courier New, Courier, monospace;">Hashtable</span> instances with <span style="font-family: Courier New, Courier, monospace;">Dictionary<TKey, TValue></span> instances. And as an added benefit, the dictionary can often be specialized as well, i.e. instead of replacing <span style="font-family: Courier New, Courier, monospace;">Hashtable</span> with <span style="font-family: Courier New, Courier, monospace;">Dictionary<object, object></span> you can apply the actual key and value types.<br />
<br />
Here is one example from the <i>CSJ2K</i> project, which is a C# class library for JPEG2000 encoding and decoding. In the .NET Framework-only project on <a href="https://csj2k.codeplex.com/" target="_blank">Codeplex</a>, in the <a href="https://csj2k.codeplex.com/SourceControl/latest#CSJ2K/CSJ2K/Color/boxes/ChannelDefinitionBox.cs" target="_blank">ChannelDefinitionBox</a> class, the field definitions is declared as a <span style="font-family: Courier New, Courier, monospace;">Hashtable</span> where <span style="font-family: Courier New, Courier, monospace;">int</span> is always used as keys and <span style="font-family: Courier New, Courier, monospace;">int[]</span> as values.So, in my PCL adaptation of the <i>CSJ2K</i> project on <a href="https://github.com/cureos/csj2k" target="_blank">Github</a>, I have happily replaced <span style="font-family: Courier New, Courier, monospace;">Hashtable</span> with <span style="font-family: Courier New, Courier, monospace;">Dictionary<int, int[]></span> in the adapted <a href="https://github.com/cureos/csj2k/blob/master/CSJ2K/Color/boxes/ChannelDefinitionBox.cs#L41" target="_blank">ChannelDefinitionBox</a> class.<br />
<br />
One additional comment is in place: in the aforementioned project <i>CSJ2K</i>, the hash tables are consistently created using the <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.synchronized.aspx" target="_blank">Synchronized</a> method to ensure that the hash table is thread-safe. <span style="font-family: Courier New, Courier, monospace;">Dictionary<TKey, TValue></span> on the other hand does not guarantee thread-safety. A solution to this problem would be to instead use <span style="font-family: Courier New, Courier, monospace;">ConcurrentDictionary<TKey, TValue></span>, but this specialized dictionary is available in substantially fewer PCL profiles. If your PCL is targeting Windows Phone 8 or earlier, or Silverlight for that matter, <span style="font-family: Courier New, Courier, monospace;">ConcurrentDictionary</span> will not be available. There is another workaround to this issue, but I'll save that for a subsequent post...Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-65217958357550677702014-05-09T17:20:00.001+02:002014-05-13T13:54:25.679+02:00PCL Tips and tricks: ASCIIEncoding<i>The introduction of Portable Class Libraries, PCL, considerably facilitates the sharing of functionality across managed Microsoft and Xamarin platforms. I am very enthusiastic about the PCL concept, and I have ported several .NET Framework open source projects to Portable Class Libraries. Along the way I have stumbled across various issues of making .NET Framework source code PCL compliant. In this mini-series I'll share my experiences and workarounds to facilitate the transfer to PCL for other developers.</i><br />
<br />
It appears to be very common that <i>.NET Framework</i> class libraries containing some kind of text processing relies on the <a href="http://msdn.microsoft.com/en-us/library/system.text.asciiencoding.aspx" target="_blank">ASCIIEncoding</a> class, or alternatively the <a href="http://msdn.microsoft.com/en-us/library/system.text.encoding.ascii.aspx" target="_blank">Encoding.ASCII</a> static property.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">ASCIIEncoding</span> is not portable, but fortunately it can very easily replaced with another encoding that is available in (I think) all PCL profiles, namely <a href="http://msdn.microsoft.com/en-us/library/system.text.utf8encoding.aspx" target="_blank">UTF8Encoding</a>. The UTF-8 encoding contains the ASCII character set as a sub-set, and it is even stated in the MSDN documentation for <span style="font-family: Courier New, Courier, monospace;">Encoding.</span><span style="font-family: 'Courier New', Courier, monospace;">ASCII</span><span style="font-family: inherit;"> </span>that:<br />
<span style="color: #2a2a2a; line-height: 18px;"><span style="font-family: inherit;"><i><br /></i></span></span>
<span style="color: #2a2a2a; line-height: 18px;"><span style="font-family: inherit;"><i>If your application requires 8-bit encoding (which is sometimes incorrectly referred to as "ASCII"), the UTF-8 encoding is recommended over the ASCII encoding. For the characters 0-7F, the results are identical, but use of UTF-8 avoids data loss by allowing representation of all Unicode characters that are representable. Note that the ASCII encoding has an 8th bit ambiguity that can allow malicious use, but the UTF-8 encoding removes ambiguity about the 8th bit.</i></span></span><br />
<br />
So, whenever encountering <span style="font-family: Courier New, Courier, monospace;">ASCIIEncoding</span> or <span style="font-family: Courier New, Courier, monospace;">Encoding.ASCII</span> in source code that you are porting to PCL, simply replace it with <span style="font-family: Courier New, Courier, monospace;">UTF8Encoding</span> and <span style="font-family: Courier New, Courier, monospace;">Encoding.UTF8</span>, respectively.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com1tag:blogger.com,1999:blog-7519834318544959083.post-32258674319884181092014-05-08T18:40:00.003+02:002014-05-09T19:53:39.912+02:00Open source project of the day: Evil DICOM<i>Over the last four years I have contributed a fair amount of code to the open source community. Some of these projects I have initiated myself, other projects are forks of existing projects that I have adapted to Portable Class Libraries or new target platforms. The projects range from optimization and scientific computing, over medical imaging and image processing to utility libraries. In this mini-series I intend to give a short introduction to each of these open source projects.</i><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://evildicom.rexcardan.com/images/evilDICOMlogo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://evildicom.rexcardan.com/images/evilDICOMlogo.png" height="193" width="320" /></a></div>
<br />
A while back, Rex Cardan published his <a href="http://medical.nema.org/" target="_blank">DICOM</a> toolkit <a href="http://evildicom.rexcardan.com/" target="_blank">Evil DICOM</a>. <b>Evil DICOM</b> is a <i>.NET Framework</i> based light-weight toolkit primarily for parsing and manipulating DICOM files. Network communication is barely included, and the toolkit does not contain any imaging functionality.<br />
<br />
The lack of network and imaging functionality makes <b>Evil DICOM</b> a suitable candidate for turning into a <i>Portable Class Library</i>, and thereby substantially broadening the platforms on which <b>Evil DICOM</b> can be utilized.<br />
<br />
When I first came in contact with <b>Evil DICOM</b>, my initial idea was to adapt the toolkit to <i>Windows 8</i> (formerly known as <i>Metro</i>) applications. Few changes were required, it was practically only the file I/O that had to be adapted to <i>Windows 8</i>/<i>Metro</i>. One of the very early commits in <a href="https://github.com/cureos/Evil-DICOM" target="_blank">my Evil DICOM fork</a> on Github contains this solution. My work also led Rex Cardan to look in the same direction, and he has later published his own <i>Windows 8</i>/<i>Metro </i>application based on <b>Evil DICOM</b> in the <a href="http://apps.microsoft.com/windows/en-us/app/evil-dicom-explorer/6739c1b3-4ee3-4cef-85fb-d1af845224d1" target="_blank">Windows Store</a>.<br />
<br />
Rex later made a large revision of the <b>Evil DICOM</b> class library, and I then decided to take a step further and attempt to adapt the library to a <i>Portable Class Library</i> targeting as many platforms as possible.<br />
<br />
The result of this adaptation is available in <a href="https://github.com/cureos/Evil-DICOM" target="_blank">my Evil DICOM fork</a> on Github. This PCL version of the library provides all functionality of the original class library except one class for reading DICOM files via sockets. This specific functionality has instead been made available as a separate <i>.NET Framework</i> only class library. The <i>Portable Class Library</i> currently targets these platforms:<br />
<br />
<ul>
<li>.NET Framework 4.5 and higher</li>
<li>Windows 8 and higher (formerly known as Metro)</li>
<li>Windows Phone 8 and higher (Silverlight)</li>
<li>Silverlight 5</li>
<li>Xamarin.Android</li>
<li>Xamarin.iOS</li>
</ul>
<div>
As I mentioned in the beginning, <b>Evil DICOM</b> is extremely light-weight and in principle limited to DICOM <i>file</i> textual manipulation. A substantially wider ranging C# DICOM toolkit is <a href="https://github.com/rcd/fo-dicom" target="_blank">fo-dicom</a>. It so happens that I have also extended this toolkit to other <i>Microsoft</i> and <i>Xamarin</i> platforms. However, this will be the issue of a subsequent post in this series. Stay tuned...</div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-64141058098568913652014-05-07T20:26:00.001+02:002014-05-09T19:54:13.986+02:00Open source project of the day: YAMP<i>Over the last four years I have contributed a fair amount of code to the open source community. Some of these projects I have initiated myself, other projects are forks of existing projects that I have adapted to Portable Class Libraries or new target platforms. The projects range from optimization and scientific computing, over medical imaging and image processing to utility libraries. In this mini-series I intend to give a short introduction to each of these open source projects.</i><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://raw.githubusercontent.com/FlorianRappl/YAMP/master/logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://raw.githubusercontent.com/FlorianRappl/YAMP/master/logo.png" /></a></div>
<br />
Since I have just recommended the project on <a href="http://stackoverflow.com/q/23475255/650012" target="_blank">StackOverflow</a>, I thought I'd start with <a href="https://github.com/FlorianRappl/YAMP" target="_blank">YAMP</a>. <b>YAMP</b> is short for <i>Yet Another Math Parser</i>. It is written mainly by <a href="http://www.florian-rappl.de/" target="_blank">Florian Rappl</a>, and is a high-performing parser of mathematical expressions including scalar, vector and matrix algebra, a vast set of mathematical and statistical functions, variable management and so on. The parser is relatively fast compared to other mathematical parsers available, and it is written entirely in managed C# code; it has no dependencies towards native libraries.<br />
<br />
Originally, <b>YAMP</b> was targeted solely at the .NET Framework. However, since <b>YAMP</b> is written entirely in C# and is only using a limited set of non-portable classes and methods, I took on the challenge of porting YAMP to a <a href="http://msdn.microsoft.com/en-us/library/gg597391.aspx" target="_blank">Portable Class Library</a>, PCL, targeting as many of the Microsoft (Windows 8/Metro, Windows Phone, Silverlight) and <a href="http://xamarin.com/" target="_blank">Xamarin</a> (iOS, Android) platforms as possible. It was a relatively simple task to adapt <b>YAMP</b> to PCL. The original code made use of some non-portable methods that could be easily replaced with corresponding calls to portable equivalents. The main issue turned out to be the inclusion of file I/O operations in the vanilla <b>YAMP</b> version. Fortunately, these classes were isolated and could easily be excluded from the PCL class library.<br />
<br />
I published my adaptations in a Github fork of the original <b>YAMP</b> library; my fork is available <a href="https://github.com/cureos/YAMP" target="_blank">here</a>.<br />
<br />
My work was appreciated by the main author Florian Rappl, and I have continuously collaborated with him to merge all PCL adaptations into the main <b>YAMP</b> repository.<br />
<br />
Now, <b>YAMP</b> is avaliable as a .NET Framework only NuGet package <a href="http://www.nuget.org/packages/YAMP" target="_blank">here</a>, and a PCL enabled NuGet package <b>YAMP.Portable</b> is available <a href="http://www.nuget.org/packages/YAMP.Portable" target="_blank">here</a>.<br />
<br />
To learn more about <b>YAMP</b>, you may also have a look at <a href="http://www.codeproject.com/Articles/462180/Yet-Another-Math-Parser-YAMP" target="_blank">this</a> CodeProject article by Florian Rappl.Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-86910526782100826052014-05-06T22:20:00.005+02:002014-05-06T22:20:52.072+02:00Copying a project resource image to a WriteableBitmap in a Windows Store applicationIt seems like the <i>Windows Store</i> application projects in <b>Visual Studio 2013 Update 2</b> do not like embedded resources:<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">Build action 'EmbeddedResource' is not supported by projects with an output type of 'appcontainerexe'.</span></div>
</div>
<div>
<br /></div>
<div>
So far I have used embedded resources to include image files that I programmatically assign to <span style="font-family: Courier New, Courier, monospace;">WriteableBitmap</span> objects for example in my <i>Windows Store</i> applications, but now this approach does not seem so fruitful any longer.</div>
<div>
<br /></div>
<div>
Here is what I did instead.</div>
<div>
<br /></div>
<div>
a) Set the image file <i>Build Action</i> to <b>Content</b>, and <b>Copy Always</b> to <i>Output Directory</i>:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIPUQISqCt_OYpUx_32w-TirUrGqvzJ5Ux3_WwsX1N-4H4JFJU3aCfj31dQ8EK7RSLgnGKvOCR_fSWTQHa6wJHWqYTGH6MNjSxD0y9UbiN-ty-FQSnNe85vvVAv0ALtlQR-1BqCfAzi2cB/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIPUQISqCt_OYpUx_32w-TirUrGqvzJ5Ux3_WwsX1N-4H4JFJU3aCfj31dQ8EK7RSLgnGKvOCR_fSWTQHa6wJHWqYTGH6MNjSxD0y9UbiN-ty-FQSnNe85vvVAv0ALtlQR-1BqCfAzi2cB/s1600/1.png" height="180" width="320" /></a></div>
<div>
<br /></div>
<div>
b) Reference the <a href="https://writeablebitmapex.codeplex.com/" target="_blank">WriteableBitmapEx</a> library, most easily via <a href="http://www.nuget.org/packages/WriteableBitmapEx" target="_blank">NuGet</a>.</div>
<div>
<br /></div>
<div>
c) Use the <span style="font-family: Courier New, Courier, monospace;">FromContent</span> extension method in the <i>WriteableBitmapEx</i> library to load the image via its <i>URI</i>:</div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">var tmp = BitmapFactory.New(1, 1);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">var wbm = await tmp.FromContent(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> new Uri("ms-appx:///Assets/image.jpg"));</span></div>
<div>
<br /></div>
<div>
And voilá! Now the image file resource is sufficiently loaded into <span style="font-family: Courier New, Courier, monospace;">wbm</span>.</div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">BitmapFactory.New</span> is a method in <i>WriteableBitmapEx</i> which can be used portably to create a <span style="font-family: Courier New, Courier, monospace;">WriteableBitmap</span> object across different targets such as <i>Windows Store</i>, <i>Windows Phone</i>, <i>.NET Framework</i> etc.</div>
<div>
<br /></div>
<div>
Otherwise, practically all methods in <i>WriteableBitmapEx</i> are extension methods, and therefore the <span style="font-family: Courier New, Courier, monospace;">FromContent</span> method a little awkwardly requires an incoming <span style="font-family: Courier New, Courier, monospace;">WriteableBitmap</span> object, that it ignores.</div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">ms-appx:///</span> is the root or base URI (Uniform Resource Identifier) of the application, and <span style="font-family: Courier New, Courier, monospace;">Assets/image.jpg</span> is the path relative to the base URI.</div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-77125682186788395742014-05-05T20:13:00.002+02:002014-05-05T21:18:47.080+02:00The revival of a blogIt's been practically two years since I last posted an entry on this blog. It's not that I have not had things to write about (on the contrary). However, there has been a little bit of mismatch between the blog format and my ambitions, and therefore I have rather focused my presence to forums like <a href="http://stackoverflow.com/users/650012/anders-gustafsson" target="_blank">StackOverflow</a> and <a href="https://twitter.com/cureos" target="_blank">Twitter</a>.<br />
<br />
At the same time, I continuously make new experiences in the field of software development and radiation therapy that I believe are worthwhile sharing, so I now think it is time to revive the blog. This time I will try to keep the posts shorter and appearing more frequently.<br />
<br />
To really mark the beginning of this new era, the blog is also receiving a new name:<br />
<br />
<b>Outcome counts - Lessons learned from being a Cureos person.</b><br />
<br />
Welcome to the new ride :-)Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-86977306307791823642014-05-05T14:54:00.002+02:002014-05-05T14:54:45.239+02:00Upgrading to VS 2013 Update 2 - One word (or a few) of caution...I have recently adapted <a href="https://code.google.com/p/aforge/" target="_blank">AForge.NET Framework</a> and <a href="https://github.com/accord-net/framework" target="_blank">Accord.NET Framework</a> to Portable Class Libraries (<a href="https://github.com/cureos/aforge" target="_blank">here</a> and <a href="https://github.com/cureos/accord" target="_blank">here</a>), targeting <i>.NET Framework 4.5</i> and higher, <i>Windows Store</i> applications (Windows 8 and higher) and <i>Windows Phone 8</i> and higher.<br />
<br />
Both <i>AForge.NET</i> and <i>Accord.NET</i> make extensive use of <span style="font-family: Courier New, Courier, monospace;">unsafe</span> code. This feature has not been officially available for <i>Windows Phone 8</i>, but by manually editing the project file of the Portable Class Libraries in question, I have been able to successfully circumvent this limitation.<br />
<br />
After upgrading to <b>Visual Studio 2013 Update 2</b> last week, it seems like this loophole of mine is now at least detected. When trying to compile the libraries containing <span style="font-family: Courier New, Courier, monospace;">unsafe</span> code, I get error messages like the following:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Error<span class="Apple-tab-span" style="white-space: pre;"> </span>1<span class="Apple-tab-span" style="white-space: pre;"> </span>'Allow unsafe code' is not supported by one or more of the project's targets.<span class="Apple-tab-span" style="white-space: pre;"> </span>[...]\accord\Sources\Accord.Math\Portable.Accord.Math.csproj<span class="Apple-tab-span" style="white-space: pre;"> </span>0<span class="Apple-tab-span" style="white-space: pre;"> </span>0<span class="Apple-tab-span" style="white-space: pre;"> </span>Portable.Accord.Math</span><br />
<div>
<br /></div>
<div>
For some reason, the libraries still appear to be successfully built, but I am currently not sure of their applicability. Further testing is obviously necessary.</div>
<div>
<br /></div>
<div>
<i>Note:</i> no error is reported when I build the libraries using <b>Visual Studio 2012</b>. For my own peace of mind, maybe I should revert to the previous VS version, then...</div>
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-45981625955940472902014-04-25T22:39:00.000+02:002014-05-05T15:27:35.572+02:00Nick saved my dayFor a couple of days now I have developed a new data fitting algorithm. Normally I commit my work to a remote <em>Git</em> repository, but because of the works-in-progress status of the code, I have not tried to upload anything until today.<br />
<br />
Today the code was in a good enough state, so I decided to commit locally and to the remote repository. Using <em>Github for Windows</em>, I first committed and then pressed the <em>Sync</em> button ... and to my complete dismay the synchronization failed <em>AND</em> my local commit disappeared!<br />
<br />
At first, I foresaw numerous hours trying to reproduce what I had carefully developed, but fortunately I found the life-saver here:<br />
<br />
<a data-mce-href="http://gitready.com/advanced/2009/01/17/restoring-lost-commits.html" href="http://gitready.com/advanced/2009/01/17/restoring-lost-commits.html" style="color: #444444;" target="_blank">Git Ready: Restoring Lost Commits</a><br />
<br />
My gratefulness goes to the author of that page, Nick Quaranto. He saved my day today.
Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-72842997892967959962012-05-03T22:49:00.003+02:002012-05-04T09:17:21.689+02:00Derivative-free nonlinear optimization for .NET and JavaOptimization of non-linear objective functions and potentially also non-linear constraints is a common problem in for example radiation therapy.<br />
<div>
<br /></div>
<div>
More often than not, the objective and constraint functions are not easily differentiable, which limits the possibility of applying the more efficient derivative-based optimization algorithms (of which <a href="https://projects.coin-or.org/Ipopt" target="_blank">IPOPT</a> is a prominent open-source example).</div>
<div>
<br /></div>
<div>
There are several more or less time-efficient ways of solving (constrained) non-linear optimization problems, including simulated annealing, genetic algorithms and direct search methods such as the Nelder-Mead method (a good overview of mathematical optimization with several links is provided <a href="http://en.wikipedia.org/wiki/Mathematical_optimization" target="_blank">here</a>.)</div>
<div>
<br /></div>
<div>
One rather popular code for solving non-linear optimization problems involving (potentially nonlinear) constraints is the COBYLA2 method. Originally formulated and implemented in <a href="http://plato.asu.edu/ftp/other_software/COBYLA2.tar.gz" target="">Fortran 77</a> by Michael Powell, this method has been ported to both <a href="http://plato.asu.edu/ftp/other_software/cobyla_f90.tar.gz">Fortran 90</a> and <a href="http://plato.asu.edu/ftp/other_software/COBYLA_C.tar.gz">C</a> (through f2c conversion), and it has also been integrated into the Python scientific calculations library <a href="http://www.scipy.org/doc/api_docs/SciPy.optimize.cobyla.html">scipy</a>. COBYLA2 is simple to use, but it exhibits a rather slow convergence rate; the number of function and constraint evaluations required to locate an optimum that meets the constraints is often very large. As a first-attempt solver when objective and constraint function gradients are complex or time-consuming to derive, COBYLA2 is however often a good choice.</div>
<div>
<br /></div>
<div>
Being primarily a .NET developer, it has until recently not been straightforward to incorporate COBYLA2 though. It has of course been possible to build a native DLL and call COBYLA2 via P/Invoke. This works relatively well in a full .NET Framework environment, but it is only barely applicable in Silverlight applications and completely inapplicable in Windows Phone applications. On the other hand, the Fortran code is relatively well structured and well documented, so I recently decided to port COBYLA2 to C#.</div>
<div>
<br /></div>
<div>
I based the porting on the Fortran 90 code, since this implementation already utilizes more C/C++/C# like constructs. The porting has been successful and I have released the end result as an open-source project <a href="https://github.com/cureos/cscobyla" target="_blank">cscobyla</a> on Github. Included in this project are unit tests demonstrating the use of COBYLA2 in C# applications. The C# code is very straightforward and does not make use of any advanced functions, so it should be possible to incorporate the code in Silverlight and Windows Phone applications just as easy as it can be incorporated in regular .NET applications. When built into a C# class library, it should be straightforward to reference the COBYLA2 optimization from any other .NET language as well.</div>
<div>
<br /></div>
<div>
Encouraged by the successful porting to C#, I then embarked on a Java porting experience! I have not been able to find a pure Java implementation of COBYLA2, so I considered this a good Java development exercise. Java does not provide delegates, multidimensional arrays can only be represented as jagged arrays, and Java does not support the <i>goto</i> statement, so I was forced to make some design changes. Nevertheless, the Java porting effort also succeeded, and I have also made this result available as open source on Github, the <a href="https://github.com/cureos/jcobyla" target="_blank">jcobyla</a> project.</div>
<div>
<br /></div>
<div>
And this is not all there is! As mentioned, COBYLA2 converges slowly. Michael Powell has made several efforts to overcome this issue for specialized cases by making use of a local quadratic approximation rather than a linear approximation that is being used in COBYLA2. These improvements have been made available in the <a href="http://plato.asu.edu/ftp/other_software/newuoa.zip">NEWUOA</a> code for unconstrained optimization of nonlinear objective functions, and more recently for bound constrained optimization of nonlinear objective functions in the <a href="http://plato.asu.edu/ftp/other_software/bobyqa.zip">BOBYQA</a> (Bound Optimization BY Quadratic Approximation) code. These codes exhibits substantially improved convergence properties compared to COBYLA2, albeit for unconstrained or bound constrained problems only.</div>
<div>
<br /></div>
<div>
In particular, I consider the BOBYQA being a very interesting development, as many problems encountered in for example radiation therapy can be formulated as bound constrained problems. BOBYQA has not been available for the .NET platform other than through P/Invoke, so again I decided to port Fortran code to C#. This time I had to rely on the Fortran 77 implementation, since I have not been able to identify any Fortran 90 port of BOBYQA. It took some additional effort, but even BOBYQA is now available as open source in C#. I have denoted this project <a href="https://github.com/cureos/csbobyqa" target="_blank">csbobyqa</a> and made it available on Github. Also written using standard C# constructs, the code should be easily incorporated in any .NET, Silverlight or Windows Phone application.</div>
<div>
<br /></div>
<div>
In the case of BOBYQA, there actually already is an open-source Java implementation available as part of the <a href="http://commons.apache.org/math/" target="_blank">Apache Commons Math</a> project. The API for this Java class can be found <a href="http://commons.apache.org/math/apidocs/org/apache/commons/math3/optimization/direct/BOBYQAOptimizer.html" target="_blank">here</a>. </div>
<div>
<br /></div>
<div>
To confirm that my C# implementation is sufficiently efficient, I have also identified the longest-running unit test (bound-constrained Rosen with varying number of interpolation points) in the Java implementation and implemented the corresponding unit test in the C# unit test library. On my laptop, the C# unit test takes around 15 seconds in each consecutive run, whereas the corresponding unit test on the Java implementation ranges from 15 to 40 seconds. I am not sure why the Java timing varies this much, but it is however encouraging that the C# implementation consistently performs equal to or better than the Java implementation in this case.</div>
<div>
<br /></div>
<div>
To re-iterate, here are the links to my most recent open-source optimization projects:</div>
<div>
<br /></div>
<div>
.NET COBYLA2: <a href="https://github.com/cureos/cscobyla">https://github.com/cureos/cscobyla</a></div>
<div>
.NET BOBYQA: <a href="https://github.com/cureos/csbobyqa">https://github.com/cureos/csbobyqa</a></div>
<div>
Java COBYLA2: <a href="https://github.com/cureos/jcobyla">https://github.com/cureos/jcobyla</a></div>
<div>
<br /></div>
<div>
Good luck with the derivative-free optimization!</div>Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com12tag:blogger.com,1999:blog-7519834318544959083.post-12463784348323156142011-12-19T22:46:00.002+01:002011-12-20T07:31:03.826+01:00Ipopt + Silverlight = True!Today I have released a new version 0.9.5 of csipopt, the .NET interface to the <a href="https://projects.coin-or.org/Ipopt">Ipopt</a> large-scale non-linear constrained optimization algorithm.<br />
<br />
Compiled libraries can be downloaded here: <a href="http://code.google.com/p/csipopt/downloads/list">http://code.google.com/p/csipopt/downloads/list</a><br />
The source code is available here: <a href="https://github.com/cureos/csipopt/tags">https://github.com/cureos/csipopt/tags</a><br />
<br />
A detailed description of the improvements and usage is provided here: <a href="https://github.com/cureos/csipopt/wiki/Substantially-extended-API">https://github.com/cureos/csipopt/wiki/Substantially-extended-API</a><br />
<br />
Highlights include:<br />
<br />
<ul>
<li>Unsafe directive requirement removed</li>
<li>IpoptProblem sub-classable, yielding cleaner instantiation of the optimization problems</li>
<li>Native Ipopt methods publicly available</li>
<li>Silverlight 5 supported in elevated-trust, out-of-browser applications</li>
</ul>
<div>
Do not hesitate to discuss or report experiences and problems in the <a href="https://groups.google.com/forum/#!forum/csipopt">csipopt forum</a>!</div>Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-70503888041869252362011-10-30T20:38:00.001+01:002011-10-30T20:39:55.720+01:00Silverlight mdcm merged into Colby Dillion's main fork!<br />
Yesterday, I was excited to see that my Silverlight and WPF fork of <a href="https://github.com/cureos/mdcm">mdcm</a> was merged, in its entirety, into Colby Dillion's <a href="https://github.com/rcd/mdcm">main mdcm</a> fork.<br />
<br />
Since my efforts have now become more "official", I think it could be worth recalling some of the specific issues that are currently applicable in particular to the Silverlight library of mdcm:<br />
<br />
<ul>
<li>The Silverlight class library is currently using <a href="http://www.silverlight.net/learn/overview/what's-new-in-silverlight-5">Silverlight version 5 Release Candidate</a>. It should be fairly straightforward to revert to <a href="http://www.microsoft.com/download/en/details.aspx?id=18149">Silverlight 4</a>, but there may be some incompatibilities especially with respect to network access.</li>
<li>I have tried to implement managed support for JPEG codecs in the Silverlight project, but I have so far stumbled on 12 (and 16) bit support. The available open source JPEG codec libraries (<a href="http://code.google.com/p/fjcore/">FluxJpeg.Core</a> and <a href="http://bitmiracle.com/libjpeg/">LibJpeg.Net</a>) only support 8 bit images, and <a href="https://github.com/cureos/FluxJpeg.Core">I have not yet been able</a> to extend either of the libraries to 12 bit support. Furthermore, these libraries only support lossy compression.</li>
<li>Silverlight 5 will open up new possibilities for the mdcm Silverlight library, since <a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2011/09/05/silverlight-5-rc-platform-invocation.aspx">P/Invoke</a> is now supported when running in so called <a href="http://msdn.microsoft.com/en-us/library/ee721083(v=vs.96).aspx">"elevated trust" mode</a>. In particular, it should be possible to implement network server and full image codec support through calls to native libraries. So far, I have not implemented any of these ideas.</li>
<li>I have not made any extensive efforts with the <a href="http://xamarin.com/monotouch">MonoTouch</a> project yet; in particular, no image support is implemented. Basic functionality is there though, DICOM file parsing and network client for example works out-of-the-box.</li>
</ul>
<div>
<br /></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0tag:blogger.com,1999:blog-7519834318544959083.post-46535609864032388202011-10-12T22:13:00.000+02:002011-10-12T22:13:15.369+02:00LINQ and Dictionaries<a href="http://msdn.microsoft.com/en-us/library/bb397676.aspx">LINQ</a> is a very powerful technique for operating on collections of objects in .NET. If you for example have a collection of integers, it is a simple task to pick the even numbers from the collection using LINQ:<br />
<br />
<code>int[] ints = new[] { 1, 3, 6, 8, 9, 10 };<br />
IEnumerable<int> evens = ints.Where(i => i % 2 == 0);</code><br />
<br />
Similarly for dictionaries:<br />
<br />
<code>Dictionary<int, int> intDict = new Dictionary<int, int> </code><br />
<code> { { 2, 3 }, { 3, 5 }, { 6, 7}};<br />
<span class="Apple-style-span" style="color: #cc0000;">Dictionary<int, int> evenKeys = intMap.Where(kv => kv.Key % 2 == 0);</span></code><br />
<br />
What? Compilation error?!?<br />
<br />
In fact, the <i>intDict.Where()</i> statement is not entirely correct. From the LINQ point of view, <i>Dictionary<,></i> and other classes implementing the <a href="http://msdn.microsoft.com/en-us/library/s4ys34ea.aspx">IDictionary<TKey, TValue></a> interface are actually regarded as implementations of the <i>IEnumerable<KeyValuePair<TKey, TValue>></i> interface. Thus (ignoring for a moment that we could also have used the <a href="http://msdn.microsoft.com/en-us/library/bb383973.aspx">var</a> keyword), the correct <i>evenKeys</i> assignment should read:<br />
<br />
<code>IEnumerable<KeyValuePair<int, int>> evenKeys = </code><br />
<code> intMap.Where(kv => kv.Key % 2 == 0);</code><br />
<br />
Now, my guess is that in the normal case one would rather have the above assignment to return a <i>Dictionary</i>. Fortunately, LINQ also provides a number of <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.todictionary.aspx">ToDictionary</a> method overloads. So for the <i>evenKeys</i> assignment to return a <i>Dictionary</i> we simply type:<br />
<br />
<code><span class="Apple-style-span" style="color: #cc0000;">Dictionary<int, int> evenKeys = intMap.Where(</span></code><br />
<code><span class="Apple-style-span" style="color: #cc0000;"> kv => kv.Key % 2 == 0).ToDictionary();</span></code><br />
<br />
What?! Compilation error again?<br />
<br />
Yes, because the <i>ToDictionary</i> method also operates on <i>IEnumerable<T></i> objects. You need to tell the compiler how you want to design your <i>Dictionary</i> based on this arbitrary type <i>T</i>. For correctness, our <i>evenKeys</i> assignment has to be expressed as follows:<br />
<br />
<code>Dictionary<int, int> evenKeys = intMap.Where(kv => kv.Key % 2 == 0).<br />
ToDictionary(kv => kv.Key, kv => kv.Value);</code><br />
<div>
<br /></div>
<div>
For dictionaries, this explicitness may appear quite counter-intuitive, and there are several forum questions on the Internet indicating that this API design indeed has caused confusion (<a href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/4c4022ee-b0a8-4340-b74e-94b5004bd4db/">here</a>, <a href="http://stackoverflow.com/questions/627867/linq-query-to-return-a-dictionarystring-string">here</a> and <a href="http://stackoverflow.com/questions/897038/when-using-a-linq-where-clause-on-a-dictionary-how-can-i-return-a-dictionary-of">here</a> for example).<br />
<br />
After giving this issue some thought, I believe I have come up with an approach to bypass this hurdle of confusion. I have implemented the following extension method in a static utility class:<br />
<br />
<code>public static Dictionary<TKey, TValue>
ToDictionary<TKey, TValue>(</code></div>
<code>
</code><br />
<div>
<code> this IEnumerable<KeyValuePair<TKey, TValue>> source)</code></div>
<code>
</code><br />
<div>
<code>{</code></div>
<code>
</code><br />
<div>
<code> return source.ToDictionary(kv => kv.Key, kv => kv.Value);</code></div>
<code>
</code><br />
<div>
<code>
}
</code><br />
<br />
This overload of <i>ToDictionary</i> takes any object that implements the <i>IEnumerable<KeyValuePair<TKey, TValue>></i> interface, which is a common return type when invoking LINQ operations on dictionaries, and returns a <i>Dictionary<TKey, TValue></i> object using the same keys and values as the dictionary in the argument list. With this extension method defined, I now actually <i>can </i>enter:</div>
<div>
<br /></div>
<div>
<code><span class="Apple-style-span" style="color: blue;">Dictionary<int, int> evenKeys = intMap.Where(</span></code><br />
<code><span class="Apple-style-span" style="color: blue;"> kv => kv.Key % 2 == 0).ToDictionary();</span></code></div>
<div>
<code><span class="Apple-style-span" style="color: #cc0000;"><br /></span></code></div>
<div>
without getting the annoying compilation error.<br />
<br />
Now this is all good and well, but I then decided to take the issue even one step further. <a href="http://www.youtube.com/watch?v=SvC2LRTR8UI">Wouldn't it be good</a> if for example the <i>Where()</i> extension method when operating on a <i>Dictionary</i> by default returned a <i>Dictionary</i> with the same keys and values?<br />
<br />
Well, it can of course be done! And here is the solution:<br />
<div>
<br /></div>
<code>public static Dictionary<TKey, TValue> Where<TKey, TValue>(</code></div>
<code>
</code><br />
<div>
<code> this IDictionary<TKey, TValue> source, </code></div>
<code>
</code><br />
<div>
<code> Func<KeyValuePair<TKey, TValue>, bool> predicate)</code></div>
<code>
<div>
{</div>
<div>
return Enumerable.Where(source, predicate).</div>
<div>
ToDictionary(kv => kv.Key, kv => kv.Value);</div>
</code><br />
<div>
<code>
}</code><br />
<br />
When this method is defined, it effectively hides the general <i>Where(IEnumerable<T>, Func<>)</i> extension method when the <i>IEnumerable<T></i> object also implements the <i>IDictionary<TKey, TValue></i> interface. Having the above <i>Where()</i> extension method defined now even makes it possible for us to apply our first dictionary LINQ attempt without compilation error:<br />
<br />
<span class="Apple-style-span" style="font-family: monospace;"><span class="Apple-style-span" style="color: blue;">Dictionary<int, int> evenKeys = intMap.Where(kv => kv.Key % 2 == 0);</span></span><br />
<br />
Unfortunately, this method will always return a <i>Dictionary</i> object, regardless of whether <i>intDict</i> is a <a href="http://msdn.microsoft.com/en-us/library/f7fta44c.aspx">SortedDictionary</a> or <a href="http://msdn.microsoft.com/en-us/library/ms132319.aspx">SortedList</a> or another object implementing the <i>IDictionary<TKey, TValue></i> interface. At this point, I have no viable solution for returning the same dictionary type that was used as input to the specialized <i>Where</i> method. The quest for a solution will continue nonetheless.<br />
<br />
<span class="Apple-style-span" style="background-color: #ffd966;">I have also collected a few more similar LINQ extension method overloads in a <a href="https://github.com/">Github</a> project that I have chosen to call ... <a href="https://github.com/cureos/dictionarylinq">dictionarylinq</a>! </span><br />
<br />
In this project you may find dictionary overloads for the <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx">Except</a>, <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.intersect.aspx">Intersect</a> and <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx">Union</a> extension methods. Due to their signatures, for these methods it has actually been possible to implement a specialized overload that returns the true input dictionary type, together with a designated overload with better performance for the <i>Dictionary<TKey, TValue></i> class.<br />
<br />
Included are also method overloads for the <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.select.aspx">Select</a> method when the return type of the <i>Func<TSource, TResult></i> object is a <i>KeyValuePair<TKey, TValue></i>. It would be relatively easy to add more method overloads to <i>dictionarylinq</i>, but for now this is what there is.<br />
<br />
When the extension methods from the <i>dictionarylinq</i> utility class are included in your application, these methods will effectively hide the general extension methods in the <a href="http://msdn.microsoft.com/en-us/library/bb345746.aspx">System.Linq.Enumerable</a> class. If you <i>do</i> want to fall back on the general methods in a certain scenario, either make an explicit cast to the <i>IEnumerable<></i> interface:<br />
<br />
<code>IEnumerable<KeyValuePair<int, int>> output = </code></div>
<code>
</code><br />
<div>
<code>
((IEnumerable<KeyValuePair<int, int>>)input).Where(kv => kv.Key > 3);</code><br />
<br />
or invoke the static method explicitly:</div>
<div>
<br /></div>
<div>
<div>
<code>IEnumerable<KeyValuePair<int, int>> output = </code><br />
<code> Enumerable.Where(input, kv => kv.Key > 3);</code></div>
</div>
<div>
<br />
Please also note that the <i>dictionarylinq</i> class library in the Visual Studio solution is a <a href="http://msdn.microsoft.com/en-us/library/gg597391.aspx">Portable Class Library</a>. This means that the library uses the "least common denominator" of .NET Framework 4, Silverlight and Windows Phone 7 base class libraries. The library can be built once and consumed by all three .NET technologies without rebuilding. If you have not installed the <a href="http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/">Portable Library Tools</a>, simply create a new designated class library project and include the source code from the <i>dictionarylinq</i> class library, or include the source code directly in your own class library or application.<br />
<br />
I hope that this effort can be useful also to others than myself. For questions and comments on this work, please do not hesitate to contact me for example via a blog comment. If you are a Github user, please feel free to report code issues via the project's <a href="https://github.com/cureos/dictionarylinq/issues">Issues</a> tab.<br />
<br />
Good luck with Dictionary and LINQ!</div>Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com1tag:blogger.com,1999:blog-7519834318544959083.post-12194200904142273302011-10-07T14:15:00.002+02:002011-10-07T14:31:54.033+02:00Getting the grip on your version controlI have recently been working with several different open-source projects that are available on <a href="http://code.google.com/hosting/">Google Code</a>, <a href="https://github.com/">Github</a>, <a href="http://www.codeplex.com/">CodePlex</a> etc. The projects tend to use different software for managing version control, which in turn requires multiple <a href="http://en.wikipedia.org/wiki/Source_Code_Management">SCM</a> clients to be installed on the development system.<br />
<br />
Version control software commonly used in open-source projects today include <a href="http://subversion.apache.org/">Subversion</a>, <a href="http://git-scm.com/">Git</a> and <a href="http://mercurial.selenic.com/">Mercurial</a>. By default, the version control software is accessed through command-line interfaces. However, there are several different GUI wrappers available to facilitate the version control management. On Windows, different flavors of Tortoise are predominantly used. These tools are primarily shell extensions, enabling version control management inside Windows Explorer. <a href="http://tortoisecvs.sourceforge.net/">TortoiseCVS</a> for <a href="http://savannah.nongnu.org/projects/cvs">CVS</a> version control was first in line, and it has inspired or formed the basis to followers like <a href="http://tortoisesvn.net/">TortoiseSVN</a>, <a href="http://code.google.com/p/tortoisegit/">TortoiseGit</a> and <a href="http://tortoisehg.bitbucket.org/">TortoiseHg</a>.<br />
<br />
The various Tortoise tools makes version control management much easier and more efficient, and there is normally no problem having several of these tools installed at once on the same computer.<br />
<br />
There is one annoying issue though: all the above tools use the same icons and icon overlays in Windows Explorer. It is therefore not immediately possible in Windows Explorer to determine which version control software that is being used to manage a specific folder.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdInjGubw1QPBpBmo8zKZDqBSWjLmzKwoQRlAy_cQE9yr2R2vCdQPGLDGlJo45ZSjl_p4ZfXGtN_4Si2gU_dGJ7n36AXOj_PGOw9ImS90ke6Dvhr7Kgv670RRC_8BbQQ2HKrC9puXCaZAy/s1600/no-decoration.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="101" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdInjGubw1QPBpBmo8zKZDqBSWjLmzKwoQRlAy_cQE9yr2R2vCdQPGLDGlJo45ZSjl_p4ZfXGtN_4Si2gU_dGJ7n36AXOj_PGOw9ImS90ke6Dvhr7Kgv670RRC_8BbQQ2HKrC9puXCaZAy/s320/no-decoration.png" width="320" /></a></div>
<br />
Of course, if you enter the folder the version control administration sub-folders (.svn, .git, .hg, etc.) will be listed if you have configured Windows Explorer to display hidden folders. But this is a sub-optimal behavior; ideally the version control software should be detectable through some indication in the Windows Explorer list, or when hovering the mouse over the folder in question.<br />
<br />
In case someone had experienced the same annoyance as I and found a workaround for it, I posted a question on the subject at <a href="http://stackoverflow.com/questions/7659658/tortoisexxx-knowing-which-scm-software-is-used-in-a-specific-development-project">StackOverflow</a>. I got a few answers primarily explaining <i>why</i> the same icon overlays are used, but then I also got an eye-opening answer from <a href="http://stackoverflow.com/users/48003/stefan">Stefan Küng</a>, lead developer of TortoiseSVN. Stefan suggested me to customize the version controlled top folder using the approach described <a href="http://msdn.microsoft.com/en-us/library/cc144102%28v=VS.85%29.aspx">here</a>. This was exactly what I had looked for: a method for customizing the folder layout <i>and</i> provide explanatory text in the tool-tip when hovering over the folder with the mouse pointer!<br />
<br />
My only remaining concern now was that I would have to do this customization manually for each version controlled folder, which would be quite tedious and error-prone when a large number of projects are involved.<br />
<br />
But then, what do developers do, if not implementing solutions to repetitive problems?<br />
<br />
Thus, I took the bull by the horns and came up with a simple yet efficient console application for managing the folder customization. The application identifies the version control software used in the specified folder, adds a tool-tip and sets the folder icon to indicate which software that is being used to version control the folder. Currently, the application identifies Subversion, Git and Mercurial, but if the conditions are right (version control administration files in a sub-folder with a fix name) it is a straightforward task to extend this list of software. The application source code is available under an open-source license (<a href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License version 1.0</a>) and can be obtained from <a href="https://github.com/cureos/scmdecorator">here</a>.<br />
<br />
After running the application on the version-controlled folders in the image above, Windows Explorer will (after a few refreshes) provide the following display:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcCDbDZLpEHqOaIOHgd8MDQPFvtZcB0D_nuUOBckjOygaxksCGO9OOwLLA1rUmYsG55VFYfHFLh0t2xkS0bN4-D7z7JKwxUVw02JefLr6FnIi6bL_3uDYq54ngcX09700owYgzQl_hTaAI/s1600/decoration.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="97" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcCDbDZLpEHqOaIOHgd8MDQPFvtZcB0D_nuUOBckjOygaxksCGO9OOwLLA1rUmYsG55VFYfHFLh0t2xkS0bN4-D7z7JKwxUVw02JefLr6FnIi6bL_3uDYq54ngcX09700owYgzQl_hTaAI/s320/decoration.png" width="320" /></a></div>
<br />
Hovering with the mouse pointer over a version control decorated folder will clearly indicate the version control software being used:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiici0kTNJuyzSN3Vk2KgKLUf1vZ2CrbxQpbxatOFcdrfux12hrhgG_zvcSXFSBhzV_kXbGIeaXwqmlyE3X0KKqT7j7O9X_9YUA_8ceNVCnfWTNNBZPUDVgXEznmcIQuPF5fLzEtRYBooEO/s1600/tooltip.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiici0kTNJuyzSN3Vk2KgKLUf1vZ2CrbxQpbxatOFcdrfux12hrhgG_zvcSXFSBhzV_kXbGIeaXwqmlyE3X0KKqT7j7O9X_9YUA_8ceNVCnfWTNNBZPUDVgXEznmcIQuPF5fLzEtRYBooEO/s1600/tooltip.png" /></a></div>
<br />
It is even possible to run the folder decorator application without changing the folder icons. If the icons are not available in the same directory as the folder decorator application, the classic folder icon will be maintained but the tool-tip will still be updated.<br />
<br />
The icons have been obtained from the <a href="http://openiconlibrary.sourceforge.net/">Open Icon Library</a>. The Subversion icon is "Sub-optimal"; I was not able to find a better <i>redistributable</i> Subversion icon. For personal, non-redistributable use, a more identifiable Subversion icon is available <a href="http://www.veryicon.com/icons/system/smoothicons-12/subversion.html">here</a>. If you so wish, download this Subversion icon file instead, rename it to <i>svn.ico</i> and replace the existing Subversion icon in the Visual Studio project with the downloaded one.<br />
<br />
Happy version-controlling!Anonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.com0