Announcement

Collapse
No announcement yet.

High CPU usage with C# and WPF and multiple volumes on scene

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • High CPU usage with C# and WPF and multiple volumes on scene

    Hi,
    We have application written in C# and using Windows Forms for user interface. Currently I am working on implementing new user interface using WPF. While Windows Forms application works perfectly fine, I experience strange issue with WPF one. Application works fine until I load second volume to the scene. After loading second volume, application starts using about 100% of CPU and about 50-60% of GPU, and becomes unresponsive. If I start IvTune before loading second volume, I can remove or deactivate this volume. If I do this, application comes back to normal operation. I've also noticed two things. First thing is that if I load few copies of the same volume data, application works fine. Second thing is that if I use IvTune to remove volume, applications starts responding only if I remove bigger one (physical dimensions), no matter which one was loaded first. I use RenderAreaExaminer with WPF. I've also tried to use Windows Forms control under WPF, but I've got the same results. Do you have any idea what can cause this issue?

    Best regards,
    Peter

  • #2
    Hi,
    Sorry, I don't recognize that problem. We can try some experiments, but we'll need a little more info:
    • What version of Open Inventor?
    • Approximately what are the dimensions and data type of the volumes? (trying to get an idea of memory required)
    • How much memory is available on your GPU?
    • When you load the second volume, is it independent of the first volume?
      Or is it combined with the first volume using SoVolumeGroup, SoMultidataSeparator, etc.
    Regards,
    Mike

    Comment


    • #3
      Hi,
      Thank you for your response. I use Open Inventor 9.8.0 .NET Visual2015 x64. In attached video I've used two volumes:
      1. 512x512x35 (spacing 0.857422 0.857422 7.5)
      2. 512x512x361 (spacing 0.793 0.793 0.800049)
      Both volumes were 16-bits. I've tested it on two PCs, one with GTX950M 4GB, and second with Quadro P2000 5GB. On both computers I've got the same results. I've done some more tests and I've realised that high CPU usage is somehow related with camera position. I can find position when both volumes are visible and CPU usage is low, and on the other hand, position when only one volume is visible and CPU usage is high. I attach screen from scene graph with loaded volumes, and here is the video that shows the problem: https://youtu.be/siZGILi6yFM

      Regards,
      Peter
      Attached Files

      Comment


      • #4
        Originally posted by psperka View Post
        Hi,
        Thank you for your response. I use Open Inventor 9.8.0 .NET Visual2015 x64. In attached video I've used two volumes:
        Hi Peter,
        Thanks for detailed information. The video was very helpful. But...
        So far we are not able to reproduce the problem.

        I attach a simple C#/WPF test program that loads two volumes under an SoVolumeGroup node (actually the same volume twice, but effectively two volumes as far as VolumeViz is concerned). There is a bool in the test program that controls whether the two volumes overlap in 3D space. This is because SoVolumeGroup is smart enough to detect when the volumes do NOT overlap and do normal volume rendering. When the volumes actually overlap, SoVolumeGroup forces a special case to handle blending voxels that overlap. I tested with OIV 9.9, but I don't expect any significant difference from 9.8.

        WpfTestTwoVolumes.zip

        If you are able to reproduce the problem using this simple test case (with some modification if necessary), then we can investigate further. Hopefully you will see something significant about the scene graph structure that is different in your application compared to the test program.
        Best regards,
        Mike
        Attached Files
        Last edited by mikeheck; April 13, 2019, 01:46 AM.

        Comment


        • #5
          Hi,
          I've finally resolved the issue. The problem was caused by this line:
          Code:
          SoPreferences.SetValue("LDM_USE_IN_MEM_COMPRESSION", "0");
          After removing it, application works fine.

          Best regards,
          Peter

          Comment


          • #6
            Originally posted by psperka View Post
            Hi,
            I've finally resolved the issue. The problem was caused by this line:
            Code:
            SoPreferences.SetValue("LDM_USE_IN_MEM_COMPRESSION", "0");
            After removing it, application works fine.
            Hi Peter,
            Well... I can't explain that, but it's good news. :-)
            Thank you very much for letting us know!
            Regards,
            Mike

            Comment


            • #7
              Application works fine until I load second volume to the scene. After loading second volume, application starts using about 100% of CPU and about 50-60% of GPU, and becomes unresponsive.

              Comment


              • #8
                Originally posted by Rativohra View Post
                Application works fine until I load second volume to the scene. After loading second volume, application starts using about 100% of CPU and about 50-60% of GPU, and becomes unresponsive.
                Hi,
                Is it the same application that was previously discussed in this thread?
                If so, what changed since the issue was resolved in April 2019?
                If not, please provide more information.
                Regards,
                Mike

                Comment


                • #9
                  Hi mikeheck ,

                  I just spoke with your colleague regarding a development license. He mentioned you were more familiar with the WPF stuff. I've downloaded the sample app you provided Peter. Admittedly, I'm very new to OpenInventor but I'd like to think I'm somewhat proficient with C# + WPF. I've installed the Open Inventor toolkit (trial only) and then opened your solution file. However, it is not resolving the OIV references (Please see attached screen scrape). Is there anything I'm missing? Do I need to add these references explicitly or is there any type of NuGet URL that I can reference or perhaps something else?

                  Thanks,
                  Dennis

                  image.png
                  Last edited by mikeheck; October 13, 2022, 11:27 PM.

                  Comment


                  • #10
                    Sorry mikeheck, I forgot to include the error message when attempting to build your sample project. It is:

                    'Cannot resolve dependency to assembly 'OIV.Inventor.ViewerComponents, Version=10.12.1.0, Culture=neutral, PublicKeyToken=null' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event. Line 11 Position 75.' WpfRenderAreaExaminer D:\tmp\UW\CT\OpenInventor\WpfTest1\MainWindow.xaml 11

                    And my IDE is VS2019

                    Thanks :-)
                    Last edited by dknippel; October 6, 2022, 08:09 PM.

                    Comment


                    • #11
                      Originally posted by dknippel View Post
                      I just spoke with your colleague regarding a development license. He mentioned you were more familiar with the WPF stuff. I've downloaded the sample app you provided Peter. Admittedly, I'm very new to OpenInventor but I'd like to think I'm somewhat proficient with C# + WPF. I've installed the Open Inventor toolkit (trial only) and then opened your solution file. However, it is not resolving the OIV references (Please see attached screen scrape). Is there anything I'm missing? Do I need to add these references explicitly or is there any type of NuGet URL that I can reference or perhaps something else?
                      Hi Dennis,
                      There are a couple of very small issues with this example because it's old. Specifically, because the code and project were written for Open Inventor version 9.something and we're now on version 10.12. I attached an updated version. Here are the details of the two changes:

                      In the project file, there is (as you discovered) one reference missing. You just need to add the following lines in the "<ItemGroup>" section:
                      Code:
                          <Reference Include="OIV.Inventor.ViewerComponents">
                            <HintPath>$(OIVNETHOME)\assemblies\$(OIVARCH)\OIV.Inventor.ViewerComponents.dll</HintPath>
                          </Reference>
                      ​
                      In MainWindow.xaml.cs, querying the version from SoLicensesInfo used to be a function but it's now a property (which makes sense).
                      Code:
                            //old: string version = SoLicensesInfo.GetVersion();
                            string version = SoLicensesInfo.Version;
                            Debug.WriteLine("OIV version " + version);
                      ​
                      Since you have the Open Inventor .NET SDK, you probably already found the examples directory.
                      The WPF specific examples are a couple levels down in: $OIVHOME/examples/source/Inventor/ViewerComponents/Wpf
                      These do minimal rendering because they are just to show how to integrat OIV rendering in a WPF application.

                      The general volume visualization examples are in examples/source/VolumeViz and the medical related examples are in examples/source/Medical. In particular examples/source/Medical/Input/MedicalDicomReader is a DICOM volume viewer.
                      Most of these examples were written years ago and are embedded in a window using WinForms. That's not a big deal. You just need to copy/paste the visualization and interaction code into a WPF application.

                      Due to limited resources, not all the C++ examples have been converted to C#. If you don't see something you need, let me know and I may be able to point you to a C++ example. It's straightforward to convert code using the OIV classes.
                      Good luck with your project,
                      Mike​
                      Attached Files
                      Last edited by mikeheck; October 13, 2022, 11:27 PM.

                      Comment


                      • #12
                        Hi mikeheck,

                        Thank you for the updated project file. It is now compiling successfully. I am just waiting on a trial license from your colleague, Arash.

                        Will review the additional sample WPF projects you suggested...

                        Regards,
                        Dennis

                        Comment


                        • #13
                          Hi mikeheck, sorry to reach out to you like this, but I've tried several times to contact your colleague but still no response. Is there anyway you, or the appropriate resource, can contact me regarding some bid details, as well as a trial license to see whether or not the Open Inventor WPF tools will meet our needs. Thank you, Dennis.
                          Last edited by mikeheck; October 13, 2022, 11:27 PM.

                          Comment


                          • #14
                            Originally posted by dknippel View Post
                            Hi mikeheck, sorry to reach out to you like this, but I've tried several times to contact your colleague but still no response. Is there anyway you, or the appropriate resource, can contact me regarding some bid details, as well as a trial license to see whether or not the Open Inventor WPF tools will meet our needs. Thank you, Dennis.
                            Hi Dennis,
                            Sorry, I can't help you with those questions. But I forwarded your message.
                            Regards,
                            Mike
                            Last edited by mikeheck; October 13, 2022, 11:28 PM.

                            Comment

                            Working...
                            X