Improved creating ResourceDictionaries from svg files in new version of Ab2d.ReaderSvg

by abenedik 28. January 2015 20:31

I am happy to announce that the best svg reader for .Net has been improved.

I am also happy that I have not received any svg file that would not be read correctly for very long time. This means that the reader very accurately converts the files to WPF object. So this part of the ReaderSvg did not get any upgrade.

The improvements in this update are focused on what you can do when you have the svg file in WPF objects tree. 

The main new improvement is better support for creating ResourceDictionaries from multiple svg files. ResourceDictionaries can be created with using ResourceDictionaryWriter application. The application is available with full source code and therefore it can be fully customized. The following is a screenshot of the new version of the application:

That screenshot was created after we have added two svg files for ResourceDictionary – one was home6.svg and the second was birthday_cake.svg. This can be seen from the left panel where images of both read files are seen. On the right side you can see the ResourceDictionary XAML.

As you see the SolidColorBrushes and Pens have been also specified as resources. This means that you can simple change the brush or pen with changing the resource value.

With the new version of ResourceDictionaryWriter application it is possible to specify when the SolidColorBrushe or Pen are written to resources and when they are defined as attributed for the elements. The screenshot shows an option that specifies that SolidColorBrushes and Pens are written to resources when they are used 2 times or more. So for example in the pre-last line of the XAML you can see that the GeometryDrawing is using a White brush. Because this brush is still defined as attribute, this means that this brush is used only once. If it would be used 2 times, it would be specified as resource. The application allows you to specify to always use resource, to never use resources and also allows you to specify a few options in between (with changing the source code you can use any possible option).

An improvement of the new version is that when importing objects as Shapes it is also possible to write Brushes are resources (before this was possible only for Geometries).

It is also possible to specify whether the objects will be written as Shapes (Canvas, Path, Rectangle, Ellipse, etc.) or as Geometry objects (as shown in the screenshot). Advantage of Shapes is that they are simpler to use and manipulate. The Geometry objects on the other hand are much lower lever objects and are harder to manipulate but have better performance and use less memory.

ResourceDictionaries are a very useful concept in WPF and I hope that with the improvements in this version it will be easier to create them.

 

Another improvement of the new version is with using RenderToBitmap method. Now it is possible to also specify custom dpi settings for the created bitmap. I have also fixed an issue where all objects were scaled to the border of the image the svg file was read with AutoSize set to false and we specified a custom sized bitmap.

After adding dpi support to RenderToBitmap method I have also improved SvgToPngConverter (sample console application) and added dpi and some other settings to it.

Also the main ReaderSvg samples have been improved. They now use custom control (TextBlockEx) to show information about each section of samples. The TextBlockEx allows you to very quickly define the text with new lines, bold regions, bullets and some other special formatting (for example hyperlinks). It replaced the clumsy DocumentViewer that require a lot of XAML for simple text and also produces annoying handled exceptions. Also the Frame element was replaced by custom DynamicContentControl that can be bind to UserControl type name to show the correct UserControl. Both new classes are part of the sample and can be freely used for your projects also.

 

In the following days I will also update the ResourceDictionaryWriter that comes with ReaderWmf library. It will provide similar improvements as the one that comes with ReaderSvg.

 

I hope you are satisfied with improvements. As always, if you find a svg file that is not correctly read, please send it to me. Also if you are missing a special functionality and think that it could be also beneficial to others, please let know and maybe I will implement it for you – usually after a day or two you can already get a pre-released version with new functionality.

Tags: ,

ReaderSvg

Improved multi-touch support in new version of ZoomPanel

by abenedik 13. January 2015 15:44

I am happy to announce that a new version of ZoomPanel has been just released.

The new version brings improved support for touch and multi-touch.

The previous version of ZoomPanel already has touch support. But for that you need to use a custom MultiTouchZoomPanel control that was available in a separate project.

The reason for that separation was that the ZoomPanel library was built with .Net 3.5 framework that do not have support for touch. The MultiTouchZoomPanel was built on .Net 4 framework and was able to use touch events.

In the new version the code from MultiTouchZoomPanel is integrated into the core ZoomPanel control. The trick is that ZoomPanel comes with two builds: one .Net 3.5 and one .Net 4.0. This allows us to implement all the touch manipulation in the .Net build. The .Net 3.5 build preserves all the new properties that control the touch behaviour but an error is thrown if user wants to enable touch support.

So if you want to use touch controls all you need to do is to use the .Net 4 build of ZoomPanel. Touch controls are already enabled by default.

 

What is more, this version improves the pinch to zoom behavior with improving the position where the zoom occurs - now the center of zoom is between the fingers that do the pinch.

Tags:

ZoomPanel

Import 3D models from almost any 3D file with new major update of Ab3d.PowerToys library

by abenedik 27. November 2014 23:43

I am really happy that after a long development all great new features of Ab3d.PowerToys library are now available.

The biggest new feature is that now it is possible to import 3D models into WPF or WinForms application from almost any 3D file – including Collada, fbx, blend, dxf, ase, lwg and many more (see http://assimp.sourceforge.net/main_features_formats.html).

This is possible with help of Open Source Assimp importer library and a new Ab3d.PowerToys.Assimp helper library that converts Assimp’s Scene object into WPF 3D objects.

For example the following XAML imports a Collada duck.dae file:

<assimpVisuals:AssimpModelVisual3D Source="/Resources/duck.dae" 
                            Position="0 0 0" PositionType="Center"
                            SizeX="100"//>

And the result is of course the standard Collada duck 3D model:

Collada duck model opened with Ab3d.PowerToys.Assimp

And what is more, just as Assimp importer is free to use, the new Ab3d.PowerToys.Assimp library is also free to use without need to purchase a commercial version of Ab3d.PowerToys (when not used with commercial version of Ab3d.PowerToys, Ab3d.PowerToys.Assimp is distributed under MIT license).

 

And today I have many other very good news for you.

 

Let’s continue with presenting you a whole new sample project – Ab3d.PowerToys.AssimpViewer.

This project uses Assimp library to import 3D models from file and show 3D model in the application. What makes it very interesting is that it has some advanced features like:

  • Shows objects names and hierarchies 
  • Shows detailed information about 3D objects
  • Allows object selection with mouse
  • Showing bounding box, normals and triangles for selected object.

For example the following image shows selected duck model with bounding box, triangles and normals:

AssimpViewer with shown bounding box, normals and triangles

This makes it similar to what is possible with Viewer3ds application. The main difference is that for AssimpViewer you can see the whole source code.

This application also demonstrates a new ModelDecoratorVisual3D class that makes showing selected object incredibly simple – for example:

<visuals1:ModelDecoratorVisual3D x:Name="SelectedModelDecorator" 
                                     ShowBoundingBox="False" BoundingBoxLineColor="Red" BoundingBoxLineThickness="2"
                                     ShowNormals="True" NormalsLineColor="Blue" NormalsLineThickness="1"
                                     ShowTriangles="True" TrianglesLineColor="Green" TrianglesLineThickness="1"
                                     TargetModel3D="{Binding ElementName=MyModel3D}"
                                     RootModelVisual3D="{Binding ElementName=ContentRootVisual3D}"/>

As you can see, we just set the target model (selected model), parent Visual and then decide how we want to decorate the selected model – with bounding box, with normal or with triangles. Super simple.

Another improvement from the new version of Ab3d.PowerToys library is a better and nicer CameraAxisPanel – as seen in the lower right corner the new version now shows real 3D arrows instead of 3D lines with arrows. This looks much nicer.

This sample is still under construction (version 0.8). I have big plans with it. I want to turn it into a simple 3D editor where you will be able to add multiple 3D objects from multiple files, move the models around, scale and rotate them. I know that many customers are working on some similar applications. Creating such sample application could mean a huge development time saving for many of them.

 

And now to some other new features.

Many customers are concerned about WPF 3D performance when they need to show very complex 3D models with a lot of 3D parts. One reason for performance problem can be that WPF is using DirectX 9 rendering and that it does not have an optimal rendering pipeline. But many times the reason for slow rendering is that simply too many GeometryModel3D objects are rendered.

This can cause problems because each GeometryModel3D is rendered with using its own DirectX draw call. Draw call is a low level command, that instructs graphics driver and graphics card how to draw one object. Because graphics drivers need to prepare many things before the data from draw call can be send to graphics card, draw calls are very expensive operations. This is also true for DirectX and high end 3D games – usually games tend to keep number of draw calls per frame under 3000. Higher numbers can slow down rendering regardless of the hardware.

With Ab3d.PowerToys we cannot improve the WPF 3D rendering pipeline, but with a new ModelOptimizer it is possible to significantly reduce the number of required draw calls and therefore improve rendering performance. This is done with analyzing the model and combing all models that have the same material into one model – so that only one draw call is needed instead of many.

The following image shows the ModelOptimizer sample that shows (marked with red arrow) that ModelOptimizer has reduces number of objects from 3381 to only 30. 

ModelOptimized sample

This had significant impact on performance. With optimized model the frame rate was easily at 60 FPS (on i7 3770 CPU and GeForce 560 Ti). But when the original model was shown, the FPS dropped to 14.

A drawback of using ModelOptimizer is that you loose the original object structure (but this can be solved with saving the hierarchy and individual objects data into some custom data structure before optimizing the model).

 

There have been some other improvements. 

For example showing 3D models from obj files has been simplified with adding ObjModelVisual3D that can be used in XAML. MaterialTypeConverter has also been improved so that it now Visual Studio 2013 designer can show textures on 3D models. Updating 3D lines has also been improved to allow more flexibility when the lines are updates and when not.

To simplify debugging there are now many extension methods that can be called from Visual Studio Immediate Window to show you many details of the 3D object (see “Dump and Name sample” for more info).

Now it is also very easy to set name to any Model3D object, Visual3D, MeshGeometry or Material – this can be simply done with new extension method: SetName. To get the name, you just call GetName method.

The whole list of improvements and fixes is really long. You can see it on the PowerToys web page (scroll down to versions history).

 

Finally I would like describe my future plans. I have already mentioned that I want to improve AssimpViewer sample. To do that I will add new helper objects that will make moving, rotating and scaling selected object very easy. I am also planning to add support for reading compiled 3D model files (Visual Studio 2013 can compile 3D models from fbx, dae and obj files into its own file format). This would remove the need to use Assimp importer in your projects.

And I am also working hard on a new DirectX 11 rendering engine that should eradicate rendering performance problems and will also bring improved rendering quality to WPF 3D world. I hope that I will be able to release a first open beta version in the beginning of the next year.

 

As always, the existing customers can get the latest version of Ab3d.PowerToys (and Ab3d.PowerToys.Assimp library) from their User Account pages. Others please install the new evaluation version form our Downloads page.

 

And the final great news is a reward to all of you that have read this blog post to the end – to get the reward check out our web site today!

Tags:

Ab3d.PowerToys

WPF trends in Windows UI technologies

by abenedik 1. October 2014 11:16

I have just stumbled upon Google trends web site that can show how the search terms change over time.

I thought it would be very useful to check how WPF is working (is it really dead?).

The results were very interesting. Therefore I have decided to share them with:

Google trends for WPF, XAML, WinRT and WinForms

 

As you can see the worldwide search amount for WPF has decreased a little bit in the last 2 years, but it is still very high. Also its comparison with WinForms and WinRT shows that is used very much. Especially WinRT search volume shows that this was a big fail for Microsoft.

The differences between the countries are also interesting - the decrease of WPF usage was quite high in US, but in Germany WPF search indicates that is still used as much as in its best times.

In the previous image I have excluded Silverlight from the graph. The reason for that is that Silverlight is still getting much more search terms that WPF and would therefore worsen the clarity of the results. Let's see:

Google trends for WPF, XAML, WinRT, WinForms and Silverlight

For me this is very surprising. I was not expecting so much search volume for Silverlight. Maybe the reason for that is that users how build WPF or WinForms applications are many times searching for with .Net or c# search term, but when they search for Silverlight, they use this keyword more times because of the differences between standard .Net and Silverlight's version of .Net.

 

The Google trends web site is very interesting and can show many insights into what is in. Check it by yourself - the following link shows the last graph with Silverlight included: https://www.google.com/trends/explore#q=WPF%2C%20WinRT%2C%20XAML%2C%20WinForms%2C%20Silverlight&cmpt=q

Tags:

General

New version of best svg reader for .Net comes with new WinForms samples

by abenedik 30. September 2014 22:24

I am happy to announce that a new version of Ab2d.ReaderSvg has been published.

Read svg files in WinForms application

Let's start with a screenshot:

read svg file in WinForms application

As seen from the title of the window, this screenshot shows the new sample application that show how to read svg files in WinForms application with Ab2d.ReaderSvg library.

On the right side the image shows a scaled part of svg image – notice the nicely antialiazed scaled vector graphics where all the details are preserved when scaling. This part is shown with using an ElementHost control that can host WPF content in WinForms application. The content of the ElementHost control is set to a ZoomPanel control that allows users to zoom and pan the svg content.

The sample also shows a GDI+ bitmap in the lower left part of the application. It was created with reading the svg file with Ab2d.ReaderSvg library, then calling RenderToBitmap method (implemented in this version) to get WPF's bitmap and then converting the WPF's bitmap to GDI+ bitmap.

To summarize, the sample shows that it is very easy to read svg files in WinForms applications with Ab2d.ReaderSvg library. The recommended way is to use ElementHost control to preserve the vector graphics drawn by WPF. This way it is also possible to use the ZoomPanel control. When using ElementHost is not an option, it is also possible to convert the read svg file into GDI+ bitmap and show it inside PictureBox control.

 

Svg to png converter

This release also comes with a SvgToPngConverter console application. It can be used to batch convert many svg files into png files. It allows users to specify the bitmap size. Because the application comes with source code, it is possible to adjust it in any way. With uncommenting a few lines of code, the application can be changed to svg to jpg converter.

One possible usage of the SvgToPngConverter is to use it for online svg to png converter. The reason for that is that it is not recommended to use WPF objects inside web server (because potentially there can be some memory leaks that can become problematic when the web server is running for weeks or months). To overcome this problem, it is recommended to create WPF objects in a separate AppDomain or process. And the easiest way to do that is to use console application. So in our case, when the user (or Silverlight or some other client application) would upload svg file to the web server, the web server would call the SvgToPngConverter and provide the client with the created png file.

 

Those two samples should convince you that Ab2d.ReaderSvg can very successfully used to be read svg file in non WPF platforms also.

 

New features of Ab2d.ReaderSvg v5.5

Of course, there are also some other improvements and new features in the library.

The following is the full list:

  • Added RenderToBitmap method to render the read svg image to bitmap. The method allows users to render to custom bitmap size and to specify custom background brush.
  • Added FlattenHierarchy method that flattens the hierarchy of the read svg objects so that all the objects are children on one root Canvas.
  • Correctly handle "stroke-width" attribute in text element. Also does not convert text to path when stroke is set to some value but stroke-width is set to 0.
  • Fixed using some very small values for stroke thickness and values written in scientific format (1.23E-12).
  • Improved ReaderSvg startup and reading performance with optimizing Regex objects creation.

 

As always, if you find any svg files that do not open correctly or have any feature requests, please fill free to contact me.

Tags:

ReaderSvg

Improved performance and WinForms sample in new version of Ab3d.PowerToys

by abenedik 14. September 2014 22:52

I am happy to announce that a new version of Ab3d.PowerToys has been published.

The new version has the following new features:

  • Greatly improved performance of SphereVisual3D and BoxVisual3D.
  • Fixed updating 3D lines when Viewport3D is inside TabControl or when the Viewport3D is moved from one control to another (for example in Avalon dock when the docking of Viewport3D is changed)
  • Optimized LinesUpdater to minimize the number of newly created object each rendering frame.
  • Added WinForms sample that shows how easy is to show 3D graphics in WinForms with embedded WPF and Ab3d.PowerToys

The biggest new feature is performance improvement that is achieved by caching the MeshGeometry3D for the sphere and box models. Before each time the position or size of the sphere or box was changed, the whole MeshGeometry3D was regenerated. Now all the spheres (with the same segment count) and boxes share the same MeshGeometry3D. To create the sphere and box at the specified position and size, a MatrixTransform is used.

The biggest performance gain of the new rendering is get when the spheres and boxes are animated – when the position or size is changed. Because now it is not needed to recreate the whole MeshGeometry3D the animation can be much smoother – on some computers even more than 20 times faster.

Because the new model generation algorithm reuses the MeshGeometry3D, much less data is sent to graphics card and therefore the models can be rendered much faster. On some computers more than 5 times better frame rate can be achieved. 

To test the new functionality a new sample was added to the Ab3d.PowerToys samples. The following screenshot shows the sample running and showing the number of spheres, triangles and positions and the current frame rate (on Intel i7 3770 and a more than 2 years old NVidia 560 GTX Ti):

WPF 3D performance with Ab3d.PowerToys

 

Sceptics of WPF 3D can see that when WPF 3D is used property it can have quite decent performance – animating (changing size) for 3375 spheres (more than 3 million triangles and more than 17 million positions) runs at 33 frames per second.

The new sample can be also very appealing visually – the following image shows one of such interesting screenshots (animated version is even better):

WPF 3D performance with Ab3d.PowerToys

 

Delivering the best possible performance for WPF 3D graphics have always been our goal. Therefore I am planning to add some additional performance improvement to the next version – this time improving performance of complex 3D models read with Reader3ds or some other model importer.

I would also like to say a few more things about using WPF 3D inside WinForms application. 

And now to WinForms. Surprisingly a lot of .Net developers are still using WinForms. For them I have prepared two samples that shows how easy is to add 3D graphics to WinForms. It is not needed to spend half a year to learn DirectX or some other game engine. With using ElementHost control the developers can enjoy in using the easiest 3D API: WPF 3D with Ab3d.PowerToys.

The first sample that comes with the new version of Ab3d.PowerToys library show that with a little bit more than 200 lines of c# code, it is possible to create an interesting 3D scene with dynamic objects that change color on mouse actions. The following image shows a screenshot of the sample:

WPF 3D inside WinForms

 

WinForms developer will be glad to hear that that do not need to use XAML, binding or any other new concept that is introduced by WPF. 

On the other hand the second sample shows that it is also possible to define the whole 3D scene in XAML. When using WinForms designer this scenario is very well supported: after adding ElementHost to the form, it is possible to click on a small right arrow in the upper right corner and from a drop down menu select from all the WPF’s UserControls in the solution. This way it is possible to design the scene in XAML and use Visual studio designer to preview the 3D scene.

 

I would like to conclude this blog post with the following announcement: I am already working on next major released of Ab3d.PowerToys. It will contains the already mentioned functionality to optimize the 3D models for best performance. But the biggest new feature will be added support for importing 3D models from almost all 3D file formats.

Tags:

Ab3d.PowerToys

New major release of Ab2d.ReaderWmf (metafile importer for WPF) is available

by abenedik 12. July 2014 15:56

I am happy to announce that I have just released a new major release of Ab2d.ReaderWmf library. This adds some great new features to the best metafile importer for WPF.

Metafiles are usually rendered with GDI+ rendering engine. Because there are many differences between GDI+ and WPF, some metafile features cannot be rendered in WPF. Until now such a problematic feature was usage of patterns and specific bitmap function (dwRop) in metafiles. They were used many times to darken or lighten the color of shapes. The following image shows how such metafile can look when it is imported into WPF:

Until now, this could be prevented by disabling patterns. This showed the shapes with using the original color:

But the results were quite far from the original colors. 

The new version of ReaderWmf analyzes the pattern and the used bitmap function and determines how the original color should be changed. Using this new logic produces the accurate results:

The following is another example of using pattern brushes with shadows in some Word shapes:

With new version of ReaderWmf the result is correct:

As always the new version also brings some other new features and fixes. Here is the full list:

  • Added ConvertPatternBrushesToColor to ReaderWmf - use data from pattern brush to change the color of the shape
  • Added DisableTextScaling property - in case text is wrongly scaled, user can disable scaling of text
  • Improved reading geometries when rectangle or ellipse have both Canvas position (Canvas.Left or Canvas.Top) and transformation set.
  • Improved xaml writer to prevent writing Canvas.Left = "0" and Canvas.Top = "0" (zero values can be skipped).
  • Prevented writing "Canvas.Left" and "Canvas.Top" properties in XAML two times.
  • Added IgnoreRootElementSize property to GeometrySetting - added possibility to remove the transformations or RectangleGeometry based on the size or root element.
  • Fixed problems where some separate lines were connected with additional line but they should not be.
  • Improve reading metafiles that have negative width or height specified in metafile header
  • Prevented throwing "The method or property is only available in Professional version!" under some circumstances.
  • Fixed not showing some texts under some circumstances.

Tags:

ReaderWmf