Need to display a 3D cloud in a .NET window - Printable Version
+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9)
+--- Thread: Need to display a 3D cloud in a .NET window (/showthread.php?tid=4289)
Need to display a 3D cloud in a .NET window - jimmie - 10-02-2021
I have a VB.NET Windows Forms program which produces a 3D cloud of points. I need to add a window in the .NET Forms application to display these points, then I want to be able to rotate, pan and zoom that model (nothing fancy). I do not need shading etc. Which package do I need to do this?
Is it possible to see sample code on:
1) Displaying a point cloud stored in an array as X, Y, Z coordinates. (There is no connectivity between those points).
2) C# sample code to load and display a .XYZ file from disk?
Thanks in advance.
RE: Need to display a 3D cloud in a .NET window - abenedik - 10-04-2021
The Ab3d.PowerToys library does not provide an efficient way to show point clouds. It would be possible to show each position in a point cloud as a 3D box or a 3D sphere but this would be very inefficient.
To show a point cloud in a much more efficient way you should use Ab3d.DXEngine library that can render may 3D positions are pixels with custom size and color. This is done by using a PixelVisual3D object that can render millions of 3D positions (on a decent graphics card).
See an example:
You can also control the size and color of individual pixel:
What is more, there is also an OptimizedPointMesh class that can be used in case of even bigger points clouds. This class can optimized the number of pixels that are actually sent to the graphics card and can improve performance by reducing the number of rendered pixels:
Please check the Ab3d.DXEngine samples from more info - the samples can be get from GitHub: https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples
Note that for camera controls (rotation, zooming, etc.) you will also need a Ab3d.PowerToys library that provides camera and other helper functions.
Both Ab3d.PowerToys and Ab3d.DXEngine libraries are built for WPF applications. But you can also integrate both libraries into WinForms applications. See the following sample on how to do that: https://github.com/ab4d/Ab3d.DXEngine.WinForms.Sample
I do not know the exact structure of the .xyz file format, but if this is a text file where each 3D position is defined in one row, then you can use the following code:
For example, this can read the following file:
RE: Need to display a 3D cloud in a .NET window - jimmie - 10-05-2021
Thank you Andrej.
I read your code for the readXyzFile function. If I use this function within PowerToys, how can I display the array allPositions?
Do I still need the Ab3d.DXEngine library? I am asking because my point clouds are relatively small (< 100,000 points).
RE: Need to display a 3D cloud in a .NET window - abenedik - 10-06-2021
As I have written the Ab3d.PowerToys and WPF 3D do not support rendering individual positions. So you need to create an individual 3D object for each position - for example a BoxVisual3D or SphereVisual3D. With SphereVisual3D you can set a number of segments to a low number.
But I think that if you need to render 100.000 objects that this will be very slow.
I would advise you to test that option and then also check how is the performance with using Ab3d.DXEngine. Then you will be able to decide what to use.
RE: Need to display a 3D cloud in a .NET window - jimmie - 12-18-2021
I have tried to run the DXEngine examples (PictureBoxSample) but it crashes at the statement with the error below:
_dxScene = _dxDevice.CreateDXSceneWithSwapChain(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, preferedMultisampleCount: 4);
A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
A first chance exception of type 'System.NullReferenceException' occurred in Ab3d.DXEngine.WinForms.Sample.exe
Thanks in advance.
RE: Need to display a 3D cloud in a .NET window - abenedik - 01-03-2022
I cannot reproduce this exception.
Are you running the sample in a virtual machine that does not support hardware accelerated DirectX 11?
If you want to support that case, then add try ... catch around the CreateDXSceneWithSwapChain call and in case when _dxDevice is null or in case of an exception set the dxDeviceConfiguration.DriverType to DriverType.Software and then create the DXDevice again and call the CreateDXSceneWithSwapChain method; but this will work much slower.
If there is some other reason for the exception, please provide more information about the exception (full call stack) and check the values of parameters (is any of them null?).
RE: Need to display a 3D cloud in a .NET window - jimmie - 01-03-2022
I downloaded a fresh copy of the sample and this time used VS2019 and it worked.
I then converted the sample to VB.NET as I know it better. I am getting 3 compile errors (same error). Please see attached.
Can you help me with the correct syntax.
Thanks in advance.