WPF: Annotation interactor + zoom + pan

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
TDpeter
Posts: 1
Joined: Wed Apr 05, 2023 11:05 am

WPF: Annotation interactor + zoom + pan

Post by TDpeter »

Hello,

I want to create a basic DICOM viewer that has different interactors configured for different mouse buttons:

Mouse wheel (or middle mouse): zoom in or out
Left mouse: click and drag: pan the image (horizontal and vertical)
Right mouse: window width / window level

I also want to:
- remove the scroll bars from the viewer
- change the cursor for the width / level interactor to a half white / half black circle as is common in medical imaging.

Could you please show me the most basic way to achieve this?

Your examples are much too large to understand how to do basic things, they are complete applications and it takes a lot of time to wade through all the "extra" code that is not relevant to the specific task at hand.

I just would like to have a simple example that shows how to add interactors to a viewer, specify to which mouse button they listen, and what cursors they should use.

Thanks,
Peter
Alex
Site Admin
Posts: 2315
Joined: Thu Jul 10, 2008 2:21 pm

Re: WPF: Annotation interactor + zoom + pan

Post by Alex »

Hello Peter,

All necessary functionality except "pan the image in WPF viewer without scrolls" can be implemented using current version of SDK. We already improved our code and next minor version of SDK (will be released tomorrow) will allow to implement all necessary funtionality.

I will share a code snippet tomorrow when next minor version is available.

Best regards, Alexander
Alex
Site Admin
Posts: 2315
Joined: Thu Jul 10, 2008 2:21 pm

Re: WPF: Annotation interactor + zoom + pan

Post by Alex »

Hello Peter,

Please see below the source code of WPF window, which implements all necessary functionality. Source code will work correctly with VintaSoft Imaging .NET SDK 12.1.15.1 or higher.

Here is source codes of MainWindow.xaml file:

Code: Select all

<Window x:Class="DicomExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DicomExample" 
        xmlns:ImagingControls="clr-namespace:Vintasoft.Imaging.Wpf.UI;assembly=Vintasoft.Imaging.Wpf.UI"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>

        <ImagingControls:WpfImageViewer
                    Margin="194,17,160,17"
                    Background="Black"
                    Grid.Column="0"
                    SizeMode="BestFit"
                    CenterImage="True"
                    InputGestureCopy="{x:Null}"
                    InputGestureCut="{x:Null}"
                    InputGestureDelete="{x:Null}"
                    InputGestureInsert="{x:Null}"
                    IsKeyboardNavigationEnabled="True"
                    x:Name="imageViewer1" />
        <Button Content="Open image" HorizontalAlignment="Left" Margin="34,46,0,0" VerticalAlignment="Top" Height="32" Width="77" Click="Button_Click"/>

    </Grid>
</Window>
Here is source code of MainWindow.xaml.cs file:

Code: Select all

using Microsoft.Win32;
using System.Windows;
using System.Windows.Input;

using Vintasoft.Imaging.Dicom.Wpf.UI.VisualTools;
using Vintasoft.Imaging.UI;
using Vintasoft.Imaging.Wpf.UI.VisualTools;

namespace DicomExample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // create DICOM visual tool
            WpfDicomViewerTool dicomViewerTool = new WpfDicomViewerTool();

            // specify that DICOM visual tool should change window level in DICOM image when right mouse button is used
            dicomViewerTool.SetInteractionMode(VintasoftMouseButtons.Right, DicomViewerToolInteractionMode.WindowLevel);
            // specify that DICOM visual tool should zoom DICOM image when mouse wheel is used
            dicomViewerTool.MouseWheelInteractionMode = DicomViewerToolMouseWheelInteractionMode.Zoom;

            // set cursor for action that changes window level in DICOM image
            dicomViewerTool.WindowLevelCursor = Cursors.Pen;

            // create pan tool
            WpfPanTool panTool = new WpfPanTool();

            // create composite visual tool, which combines pan tool and DICOM viewer tool, and set visual tool as current visual tool of image viewer
            imageViewer1.VisualTool = new WpfCompositeVisualTool(panTool, dicomViewerTool);
            
            // disable scrolling in image viewer
            imageViewer1.AutoScroll = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openDicomFileDialog = new OpenFileDialog();

            if (openDicomFileDialog.ShowDialog() == true)
            {
                imageViewer1.Images.Add(openDicomFileDialog.FileName);
            }
        }
    }
}
Please let me know if you will have any question or problem.

Best regards, Alexander
Post Reply