Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to visualize 3D scalar field with Helix.SharpDX Volume Rendering?

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?

like image 530
Aleksei Petrov Avatar asked Jun 24 '19 12:06

Aleksei Petrov


1 Answers

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

This is how Helixtoolkit used to implement the volume rendering.

like image 76
Lance H Avatar answered Nov 16 '22 15:11

Lance H