[Insight-users] how to modify InsightApplications
John Drescher
drescherjm at gmail.com
Wed Jan 27 09:05:04 EST 2010
On Wed, Jan 27, 2010 at 8:29 AM, URI <zallen at wheelinghospital.com> wrote:
>
> Can somebody give me just a quick answer? I'm not looking for specific
> information on this particular program, I'm just asking what the proper
> method is in general for modifying open-source code like this. Do I modify
> the raw source code files and then run CMake, or do I first run CMake on the
> original source code files and then modify the resulting Visual Studio
> solution?
I take the ITK example code to my folder and create a new project for
that that is independent from ITK. I put it in my own cvs/svn server
so that I can have it anywhere I program. I have a small collection of
such examples for itk, cmake, and vtk.
Here is one from ITK:
CMakeLists.txt
PROJECT(DicomSeriesMetaDictionary)
IF(WIN32)
CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" )
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(WIN32)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all executables.")
FIND_PACKAGE( ITK REQUIRED )
INCLUDE( ${ITK_USE_FILE} )
SET( DICOM_SERIES_META_SRCS
./src/main.cxx
)
LINK_LIBRARIES ( DicomSeriesMetaDictionary ITKCommon ITKBasicFilters ITKIO )
ADD_EXECUTABLE( DicomSeriesMetaDictionary ${DICOM_SERIES_META_SRCS} )
now src/main.cxx
#define USE_GDCM
#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#ifdef USE_GDCM
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#else
#include "itkDICOMImageIO2.h"
#include "itkDICOMSeriesFileNames.h"
#endif //def USE_GDCM
#include <iostream>
int main(int argc, char *argv[])
{
if (argc > 2) {
typedef signed short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageFileReader< ImageType > ReaderMHDType;
#ifdef USE_GDCM
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
#else
typedef itk::DICOMImageIO2 ImageIOType;
typedef itk::DICOMSeriesFileNames SeriesFileNamesType;
typedef SeriesFileNamesType NamesGeneratorType;
#endif //def USE_GDCM
ImageIOType::Pointer gdcmIO = ImageIOType::New();
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
#ifdef USE_GDCM
namesGenerator->SetInputDirectory( argv[1] );
const ReaderType::FileNamesContainer & filenames =
namesGenerator->GetInputFileNames();
namesGenerator->SetInputDirectory( argv[1] );
#else
namesGenerator->SetDirectory( argv[1] );
const ReaderType::FileNamesContainer & filenames =
namesGenerator->GetFileNames();
#endif //def USE_GDCM
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO( gdcmIO );
reader->SetFileNames( filenames );
reader->Update();
reader->GenerateOutputInformation();
// BEGIN IMPORTANT CODE*
unsigned int nbSlices = filenames.size();
ReaderType::DictionaryRawPointer dictionary;
ReaderType::DictionaryArrayType outputArray;
for (unsigned int i = 0; i < nbSlices; i++)
{
dictionary = (*(reader->GetMetaDataDictionaryArray()))[i];
std::string entryId("0008|103e");
std::string value("MARTIN IS THE BEST"); // it was just a test ;-)*
itk::EncapsulateMetaData<std::string>( *dictionary, entryId, value
);
outputArray.push_back(dictionary);
}
// END*
typedef signed short OutputPixelType;
const unsigned int OutputDimension = 2;
typedef itk::Image< OutputPixelType, OutputDimension > Image2DType;
typedef itk::ImageSeriesWriter< ImageType, Image2DType >
SeriesWriterType;
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput( reader->GetOutput() );
seriesWriter->SetImageIO( gdcmIO );
#ifdef USE_GDCM
namesGenerator->SetOutputDirectory( argv[2] );
seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );
#else
namesGenerator->SetDirectory( argv[2] );
seriesWriter->SetFileNames( namesGenerator->GetFileNames() );
#endif //def USE_CDCM
// BEGIN IMPORTANT CODE*
seriesWriter->SetMetaDataDictionaryArray( &outputArray );
// instead of :
// seriesWriter->SetMetaDataDictionaryArray(
// reader->GetMetaDataDictionaryArray());
// END*
seriesWriter->Update();
}
else
{
std::cout << "Usage: "<< argv[0] << " <input folder> <output folder>
" << std::endl;
}
}
John
More information about the Insight-users
mailing list