Skip to content

Instantly share code, notes, and snippets.

@thewtex
Created September 27, 2010 02:16
Show Gist options
  • Save thewtex/598512 to your computer and use it in GitHub Desktop.
Save thewtex/598512 to your computer and use it in GitHub Desktop.
colormap min/max FLTK ImageViewer
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ImageViewer.cxx,v $
Language: C++
Date: $Date: 2008-05-10 19:56:09 $
Version: $Revision: 1.4 $
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <metaCommand.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_File_Chooser.H>
#include <GLSliceView.h>
#include "ImageViewerGUI.h"
Fl_Window *form;
int usage(void)
{
std::cout << "ImageViewer" << std::endl;
std::cout << std::endl;
std::cout << "ImageViewer <Filename>" << std::endl;
std::cout << std::endl;
return 1;
}
int main(int argc, char **argv)
{
typedef itk::Image< float, 3 > ImageType;
MetaCommand command;
command.SetDescription( "FLTK based image viewer." );
command.AddField( "image", "Image to view.", MetaCommand::STRING, MetaCommand::DATA_IN );
command.SetOption( "iwMin", "p", false, "Colormap window minimum." );
command.SetOptionLongTag( "iwMin", "iwmin" );
command.AddOptionField( "iwMin", "iwMin", MetaCommand::FLOAT, true );
command.SetOption( "iwMax", "q", false, "Colormap window maximum." );
command.SetOptionLongTag( "iwMax", "iwmax" );
command.AddOptionField( "iwMax", "iwMax", MetaCommand::FLOAT, true );
if( !command.Parse( argc, argv ) )
{
std::cerr << "Problem parsing arguments." << std::endl;
return 1;
}
if( !command.GetOptionWasSet( "image" ) )
{
std::cerr << "Please specify an image to view." << std::endl;
return 1;
}
std::string fName = command.GetValueAsString( "image" );
std::cout << "Loading File: " << fName << std::endl;
typedef itk::ImageFileReader< ImageType > VolumeReaderType;
VolumeReaderType::Pointer reader = VolumeReaderType::New();
reader->SetFileName(fName);
ImageType::Pointer imP;
imP = reader->GetOutput();
try
{
reader->Update();
}
catch( ... )
{
std::cout << "Problems reading file format" << std::endl;
return 1;
}
std::cout << "...Done Loading File" << std::endl;
char mainName[255];
sprintf(mainName, "metaView: %s", fName.c_str());
std::cout << std::endl;
std::cout << "For directions on interacting with the window," << std::endl;
std::cout << " type 'h' within the window" << std::endl;
form = make_window();
tkMain->label(mainName);
tkWin->SetInputImage(imP);
tkWin->flipY(true);
form->show();
tkWin->show();
tkWin->update();
if( command.GetOptionWasSet( "iwMin" ) )
{
tkWin->iwMin( command.GetValueAsFloat( "iwMin", "iwMin" ) );
}
if( command.GetOptionWasSet( "iwMax" ) )
{
tkWin->iwMax( command.GetValueAsFloat( "iwMax", "iwMax" ) );
}
// force a first redraw
Fl::check();
tkWin->update();
Fl::run();
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment