Skip to content

Commit

Permalink
Merge branch 'SIMPLEITK-77_imshow_function' into next
Browse files Browse the repository at this point in the history
* SIMPLEITK-77_imshow_function:
  BUG: Working Windows implementation of itk::simple::show
  ENH: Added needed Windows flags
  DOC: Spelling fix
  ENH: Initial support under Linux for Show function
  • Loading branch information
blezek committed May 12, 2011
2 parents 75e7265 + 5c01f4b commit 877873b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ file( GLOB template_components
)
set ( template_components ${template_components} CACHE INTERNAL "" )

if (WIN32)
# /bigobj is required for windows builds because of the size of
# some object files (CastImage for instance)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj" )
# Avoid some warnings
add_definitions ( -D_SCL_SECURE_NO_WARNINGS )
endif()



subdirs ( Utilities Code Wrapping Examples )


Expand Down
1 change: 1 addition & 0 deletions Code/Common/SimpleITK.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sitkDetail.h"
#include "sitkMacro.h"
#include "sitkImage.h"
#include "sitkShow.h"

#include "sitkImageFilter.h"

Expand Down
2 changes: 1 addition & 1 deletion Code/Common/sitkImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace simple
std::string GetPixelIDTypeAsString( void ) const;
std::string ToString( void ) const;

/** Method called my certain constructors to convert ITK images
/** Method called by certain constructors to convert ITK images
* into simpleITK ones.
*/
template <typename TImageType>
Expand Down
94 changes: 94 additions & 0 deletions Code/Common/sitkShow.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "sitkShow.h"
#include "sitkMacro.h"
#include "sitkImageFileWriter.h"
#include <itksys/SystemTools.hxx>
#include <itksys/Process.h>
#include <stdlib.h>

namespace itk
{
namespace simple
{

static int ShowImageCount = 0;

static std::string FormatFileName ( std::string TempDirectory, std::string name )
{
std::string TempFile = TempDirectory;
if ( name != "" )
{
TempFile = TempFile + name + ".nii";
}
else
{
std::ostringstream tmp;
tmp << "TempFile-" << ShowImageCount;
ShowImageCount++;
TempFile = TempFile + tmp.str() + ".nii";
}
return TempFile;
}

void Show( const Image &image, const std::string name)
{
// Try to find ImageJ, write out a file and open
std::vector<std::string> paths;
std::string ExecutableName = "ImageJ";
std::string TempDirectory = "";
std::string TempFile = "";
std::ostringstream CommandLine;
#if defined(WIN32)
// Windows
// Create possible paths
ExecutableName = "ImageJ.exe";
std::string ProgramFiles;
if ( itksys::SystemTools::GetEnv ( "PROGRAMFILES", ProgramFiles ) )
{
paths.push_back ( ProgramFiles + "\\ImageJ\\" );
}

// Find the executable
ExecutableName = itksys::SystemTools::FindFile ( ExecutableName.c_str(), paths );
if ( ExecutableName == "" )
{
sitkExceptionMacro ( << "Can not find location of " << ExecutableName );
}

if ( !itksys::SystemTools::GetEnv ( "TMP", TempDirectory )
&& !itksys::SystemTools::GetEnv ( "TEMP", TempDirectory )
&& !itksys::SystemTools::GetEnv ( "USERPROFILE", TempDirectory )
&& !itksys::SystemTools::GetEnv ( "WINDIR", TempDirectory ) )
{
sitkExceptionMacro ( << "Can not find temporary directory. Tried TMP, TEMP, USERPROFILE, and WINDIR environment variables" );
}
TempDirectory = TempDirectory + "\\";
TempFile = FormatFileName ( TempDirectory, name );
CommandLine << "\"" + ExecutableName + "\" -o " + TempFile;
#else
// Handle Linux and Mac
TempDirectory = "/tmp/";
TempFile = FormatFileName ( TempDirectory, name );
#if defined(__APPLE__)
CommandLine << "open -a ImageJ " << TempFile;
#else
// Must be Linux
ExecutableName = itksys::SystemTools::FindFile ( "ImageJ" );
CommandLine << "\"" + ExecutableName + "\" -o " << TempFile << " &";
#endif
#endif

WriteImage ( image, TempFile );
system ( CommandLine.str().c_str() );
}

}
}

/*
i = SimpleITK.ReadImage ( '/home/blezek/Data/Fixed.nrrd' )
SimpleITK.Show ( i, "test" )
i = SimpleITK.ReadImage ( 'RA-Float.nrrd' )
SimpleITK.Show ( i )
*/
24 changes: 24 additions & 0 deletions Code/Common/sitkShow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef __sitkShow_h
#define __sitkShow_h


#include "sitkImage.h"

namespace itk
{
namespace simple
{

/** Display an image using ImageJ
*
* This function requires that ImageJ
* (\see http://rsb.info.nih.gov/ij/) be properly installed for Mac
* and Windows, and in the user's path for Linux. ImageJ must have
* a plugin for reading Nifti formatted files (\see
* http://www.loci.wisc.edu/bio-formats/imagej)
**/
void Show ( const Image &image, const std::string title = "" );
}
}

#endif
1 change: 1 addition & 0 deletions Wrapping/SimpleITK.i
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace std
// Any new classes need to have an "%include" statement to be wrapped.
%include "sitkPixelIDValues.h"
%include "sitkImage.h"
%include "sitkShow.h"
%include "sitkImageFilter.h"
%include "sitkImageFileWriter.h"
%include "sitkImageSeriesReader.h"
Expand Down

0 comments on commit 877873b

Please sign in to comment.