2

I need to draw thousands of 3D lines per second for an industrial WPF app but WPF appears to have no native HW-accelerated line feature.

By "3D" I mean they can be rotated in 3 axes, shown in perspective, etc. By "lines" I mean just that - these are not a wireframe of a 3D object so I do not want a tesselation of a 3D surface and I do not want these lit or shaded.

Variations of this question have been asked on StackOverflow before. People have suggested:

  • XNA, but XNA is deprecated
  • Helix3D but its lines have weird, unacceptable rendering artifacts
  • OpenGL (e.g., OpenTK or SharpGL), but I've had lots of discussions with people on the OpenGL forums and all the OpenGL interfaces with WPF seem to have major issues interfacing with other WPF features and require hacks to work around.

I think my best bet is using DirectX or Direct3D. But I don't know how to integrate them with WPF. Also Direct3D also has no native line primitive (it uses textured triangles) see: https://msdn.microsoft.com/en-us/library/windows/desktop/bb323719%28v=vs.85%29.aspx

If necessary I'm willing to do 2D hardware accelerated lines and do my own 3D-2D mapping.

But the main thing is that this has to integrate smoothly with WPF so I can overlay the graphics with a transparent WPF Canvas on which I can draw markers, text, ROI's etc.

How do I do this?

Taterhead
  • 5,763
  • 4
  • 31
  • 40
user316117
  • 7,971
  • 20
  • 83
  • 158

1 Answers1

1

Direct3D can draw single-pixel lines natively with or without lighting with or without texture mapped bitmaps. What Direct3D cannot draw naively is 'styled lines' with camphored edges, etc. Direct2D can draw styled lines either via emitting texture triangles or using software rasterization.

The deprecated D3DX9 functionality for drawing 'styled lines' that is used by the legacy Managed DirectX 1.1 Microsoft.DirectX.Direct3D.Line class used textured triangles which is why MSND mentions that. Direct2D is far more advanced and has HW acceleration paths.

WPF provides the D3DImage class for interop with Direct3D, although it only supports Direct3D9 / Direct3D9Ex. You can use DXGI shared surface tricks to get it to work with DirectX 11. See this article which tells you how to do it with Direct3D 10. Direct3D 11 is the same.

The WPFDXInterop project on GitHub should be helpful as it implements a D3D11Image class.

For C# interop of DirectX, the best options are to use either SharpDX or SlimDX.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Do the "single-pixel lines natively with or without lighting with or without texture mapped bitmaps" exist in Direct3D9? If so is there any reason to not just use D3DImage? If WPF already has a D3DImage class, why do I need SharpDX or SlimDX? – user316117 Mar 25 '16 at 14:12
  • According to [this](http://stackoverflow.com/questions/19480373/sharpdx-render-in-wpf) SharpDX is deprecated. – user316117 Mar 25 '16 at 15:09
  • Read it more careful: [SharpDX Tool Kit](https://github.com/sharpdx/Toolkit) is deprecated, not [SharpDX](http://sharpdx.org/) itself. SharpDX Tool Kit might be useful for you, but you can use the SharpDX assemblies directly. – Chuck Walbourn Mar 28 '16 at 05:30