Graphics-VTK
view release on metacpan or search on metacpan
examples/old_examples/imaging/ViewerApp.pl view on Meta::CPAN
#!/usr/local/bin/perl -w
#
use Graphics::VTK;
use Tk;
use Graphics::VTK::Tk;
$MW = Tk::MainWindow->new;
# For the purposes of this exercise, you only need to make changes in
# four places. These are labeled with "#1", "#2", "#3", and "#4".
# This exercise allows you to create a small image processing application.
# You can add filters to the pipeline and turn them on an off via a user
# interface.
# Try adding a vtkImageGradient and a vtkImageMagnitude after the default
# vtkImageGaussianSmooth. Time permitting, you might want to try a FlipFilter
# of a PadFilter as well.
# Default event bindings:
# Mouse motion - Probes the input data, displaying pixel position and value
# Left Mouse Button - Window/Level (Contrast/Brightness)
# Right Mouse Button - Changes slices when mouse moved up/down
# Keypress "r" - Resets the window/level to a default setting
$VTK_DATA = 0;
$VTK_DATA = $ENV{VTK_DATA};
#source vtkImageInclude.tcl
$source->ViewerAppTkImageViewerInteractor_tcl;
# Begin by setting up the Tk portion of the application
$MW->withdraw;
$MW->{'.top'} = $MW->Toplevel('-visual','best');
$MW->{'.top'}->title("Viz'99 VTK Imaging Exercise");
# menus
# menu .top.menu -type menubar
# menu .top.menu.file -tearoff 0
# menu .top.menu.filters -title "Filters"
# menu .top.menu.help -tearoff 0
$MW->{'.top.menu'}->cascade('-label',"File",'-menu','.top.menu.file');
$MW->{'.top.menu'}->cascade('-label',"Filters",'-menu','.top.menu.filters');
$MW->{'.top.menu'}->cascade('-label',"Help",'-menu','.top.menu.help');
$MW->{'.top.menu.file'}->command('-label',"Quit",'-command',
sub
{
exit();
}
);
$MW->{'.top.menu.help'}->command('-label',"User Interface",'-command',
sub
{
HelpUI();
}
);
# Helper proc
#
sub AddFilterMenuItem
{
my $labelString = shift;
my $command = shift;
$MW->{'.top.menu.filters'}->checkbutton('-onvalue','on','-label',$labelString,'-offvalue','off','-command',"ActivateFilter $command",'-variable',\$$command);
}
# #1 -- To add a filter to the menu, call AddFilterMenuItem passing
# the "label" to use for the menu item and the name of your filter's
# instance. Example: Below is a filter called "gaussian" so we call
# AddFilterMenuItem Smoothing gaussian
AddFilterMenuItem('Smoothing','gaussian');
AddFilterMenuItem("Edge Directions",'gradient');
AddFilterMenuItem('Magnitude','magnitude');
AddFilterMenuItem("Flip Y",'flipY');
AddFilterMenuItem("Flip X",'flipX');
$MW->{'.top'}->configure('-menu','.top.menu');
# viewer frame
$MW->{'.top.f1'} = $MW->{'.top'}->Frame;
$viewer = Graphics::VTK::ImageViewer->new;
$MW->{'.top.f1.v1'} = $MW->{'.top.f1'}->vtkImageViewer('-width',512,'-height',512,'-iv',$viewer);
$MW->{'.top.f1.v1'}->pack('-padx',3,'-pady',3,'-side','left','-fill','both','-expand','t');
# annotation frames
$MW->{'.top.f2'} = $MW->{'.top'}->Frame;
$MW->{'.top.f2.f1'} = $MW->{'.top.f2'}->Frame;
$MW->{'.top.f2.f2'} = $MW->{'.top.f2'}->Frame;
$MW->{'.top.f2.f3'} = $MW->{'.top.f2'}->Frame;
$MW->{'.top.f2.f4'} = $MW->{'.top.f2'}->Frame;
$MW->{'.top.f2.f1.label'} = $MW->{'.top.f2.f1'}->Label('-relief','sunken');
$MW->{'.top.f2.f2.label'} = $MW->{'.top.f2.f2'}->Label('-relief','sunken');
$MW->{'.top.f2.f3.label'} = $MW->{'.top.f2.f3'}->Label('-relief','sunken');
$MW->{'.top.f2.f4.label'} = $MW->{'.top.f2.f4'}->Label('-relief','sunken');
$MW->{'.top.f2.f1.label'}->pack('-fill','x');
$MW->{'.top.f2.f2.label'}->pack('-fill','x');
$MW->{'.top.f2.f3.label'}->pack('-fill','x');
$MW->{'.top.f2.f4.label'}->pack('-fill','x');
foreach $_ (($MW->{'.top.f2.f1'},$MW->{'.top.f2.f2'},$MW->{'.top.f2.f3'},$MW->{'.top.f2.f4'}))
{
$_->pack('-fill','x','-side','left','-expand','t');
}
$MW->{'.top.f1'}->pack('-fill','both','-expand','t');
$MW->{'.top.f2'}->pack('-fill','x');
# Set up the vtk imaging pipeline
$reader = Graphics::VTK::ImageReader->new;
$reader->SetDataByteOrderToLittleEndian;
$reader->SetDataExtent(0,255,0,255,1,93);
$reader->SetFilePrefix("$VTK_DATA/fullHead/headsq");
( run in 1.608 second using v1.01-cache-2.11-cpan-df04353d9ac )