7

I have a task to visualize 3D field of scalars using Helix Toolkit. The input array contains double values without limitations, but usually somewhere between [-50000, +50000]. The scalar value affect a color of a cube: The minimum value have a blue color, 0 - white, maximum - red. All other colors values are interpolated corresponding the value.

Right now I'm trying to understand how Color Transfer Map works in HelixToolkit.Wpf.SharpDX. For that I've created a simple field of 2x2x1 scalars.

MainWindow.xaml

<hx:Viewport3DX
    Name="view1"
    Grid.Row="1"
    BackgroundColor="SkyBlue"
    Camera="{Binding Camera}"
    EffectsManager="{Binding EffectsManager}"
    EnableDesignModeRendering="True"
    UseDefaultGestures="False"
    CameraRotationMode="Trackball">
    <hx:Viewport3DX.InputBindings>
        <KeyBinding Key="B" Command="hx:ViewportCommands.BackView" />
        <KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" />
        <KeyBinding Key="U" Command="hx:ViewportCommands.TopView" />
        <KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" />
        <KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" />
        <KeyBinding Key="R" Command="hx:ViewportCommands.RightView" />
        <KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Control+E" />
        <MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" />
        <MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" />
        <MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" />
    </hx:Viewport3DX.InputBindings>
    <hx:VolumeTextureModel3D VolumeMaterial="{Binding VolumeMaterial}" />
</hx:Viewport3DX>

MainWindowViewModel.cs

public MainWindowViewModel()
{
    Nx = 2;
    Ny = 2;
    Nz = 1;

    var m = new VolumeTextureDiffuseMaterial();

    var data = new[] {0.0f, 0.25f, 0.5f, 1.0f};

    var gradients = VolumeDataHelper.GenerateGradients(data, Nx, Ny, Nz, 1);
    m.Texture = new VolumeTextureGradientParams(gradients, Nx, Ny, Nz);
    m.TransferMap = new[]
        {Colors.Red.ToColor4(), Colors.Blue.ToColor4(), Colors.Lime.ToColor4(), Color4.White};
    m.SampleDistance = 0.1;
    m.Freeze();

    VolumeMaterial = m;
}

I was expecting to have 4 distinct cubes with different colors, something like (maybe with gradient between cubes due to interpolation and sampling): Desired

But I keep getting this weird triangular color mix: Actual

How exactly color transfer map array works? How can I achieve the desired result with cubes using the volume rendering of HelixToolkit.SharpDX?

Aleksei Petrov
  • 936
  • 12
  • 31
  • Remember: if `Helix`, or any other package for that matter, gets way too heavy and complex for a relatively simple use case, you can always [do it yourself](https://imgur.com/NZvKu4S)...:O) – jsanalytics Jun 27 '19 at 22:35
  • And [HERE](https://youtu.be/kCifd38Sfrk) a sample 5x5x5 volume rendering using only alpha channel between layers, same color obviously. No 3rd party libs, just plain WPF. – jsanalytics Jun 29 '19 at 00:30
  • [9x9x9](https://youtu.be/TTz2W6oUiPc) five-colored layers. – jsanalytics Jun 29 '19 at 12:01
  • 15x15x15 [PIXELATED SPHERE](https://youtu.be/AqJf5ou3kgs). – jsanalytics Jun 29 '19 at 13:18
  • @jsanalytics, what are you trying to achieve with your demos? You don't provide any code or smth like that. Pure WPF3D requires to implement so many elementary things manually (like trackball mouse rotation and so on). Moreover, WPF3D struggles with high load (e.g. 1000x1000x1000 cubes). That's why HelixToolkit.SharpDX is used in our project. Many things are already implemented here and DirectX makes it possible to draw very complicated scenes at 60 fps. – Aleksei Petrov Jun 29 '19 at 18:18
  • In a 16GB RAM machine it crashes with Out-of-memory exception at 127x127x127. This 63x63x63 [PIXELATED DOUBLE-SPHERE](https://youtu.be/AAecuKX0DP8) is the max we could get. You should add the `supercomputers` tag to your question...:O) – jsanalytics Jun 30 '19 at 03:38

1 Answers1

3

You can try to refer to this tutorial. Tutorial 1 and Tutorial 2

This is how Helixtoolkit used to implement the volume rendering.

Lance H
  • 886
  • 1
  • 9
  • 14