X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vtk%2FvtkgdcmViewer.cxx;h=3f64b40b02ff95ccde180c0206b822613959b4c9;hb=05a31743c6545f03a9841531f2d54b7b1552e681;hp=66062c5844c931e1fca994cd7d16a6a2725c6113;hpb=a32db316616e02be295e4b5addca1e94f4a2c776;p=gdcm.git diff --git a/vtk/vtkgdcmViewer.cxx b/vtk/vtkgdcmViewer.cxx index 66062c58..3f64b40b 100644 --- a/vtk/vtkgdcmViewer.cxx +++ b/vtk/vtkgdcmViewer.cxx @@ -1,12 +1,34 @@ +// This example illustrates how the vtkGdcmReader vtk class can be +// used in order to: +// * produce a simple (vtk based) Dicom image STACK VIEWER. +// * dump the stack considered as a volume in a vtkStructuredPoints +// vtk file: the vtk gdcm wrappers can be seen as a simple way to convert +// a stack of Dicom images into a native vtk volume. +// +// Usage: +// * the filenames of the Dicom images constituting the stack should be +// given as command line arguments, +// * you can navigate through the stack by hitting any character key, +// * the produced vtk file is named "foo.vtk" (in the invocation directory). +// +//---------------------------------------------------------------------------- +#include + #include #include #include #include #include #include +#include +#include #include "vtkGdcmReader.h" +#ifndef vtkFloatingPointType +#define vtkFloatingPointType float +#endif + //---------------------------------------------------------------------------- // Callback for the interaction class vtkgdcmObserver : public vtkCommand @@ -19,7 +41,7 @@ class vtkgdcmObserver : public vtkCommand { this->ImageViewer = NULL; } - virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata) + virtual void Execute(vtkObject *, unsigned long event, void* ) { if ( this->ImageViewer ) { @@ -28,7 +50,7 @@ class vtkgdcmObserver : public vtkCommand int max = ImageViewer->GetWholeZMax(); int slice = (ImageViewer->GetZSlice() + 1 ) % ++max; ImageViewer->SetZSlice( slice ); - ImageViewer->GetRenderer()->ResetCameraClippingRange(); + ImageViewer->GetRenderer()->ResetCameraClippingRange(); ImageViewer->Render(); } } @@ -39,24 +61,47 @@ class vtkgdcmObserver : public vtkCommand int main(int argc, char *argv[]) { - + if( argc < 2 ) + return 0; + vtkGdcmReader *reader = vtkGdcmReader::New(); - reader->SetFileName( argv[1] ); + reader->AllowLookupTableOff(); + + if( argc == 2 ) + reader->SetFileName( argv[1] ); + else + for(int i=1; i< argc; i++) + reader->AddFileName( argv[i] ); + reader->DebugOn(); reader->Update(); //print debug info: - reader->GetOutput()->Print( std::cout ); + reader->GetOutput()->Print( cout ); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); vtkImageViewer2 *viewer = vtkImageViewer2::New(); - viewer->SetInput ( reader->GetOutput() ); + + if( reader->GetLookupTable() ) + { + //convert to color: + vtkImageMapToColors *map = vtkImageMapToColors::New (); + map->SetInput (reader->GetOutput()); + map->SetLookupTable (reader->GetLookupTable()); + map->SetOutputFormatToRGB(); + viewer->SetInput ( map->GetOutput() ); + map->Delete(); + } + else + { + viewer->SetInput ( reader->GetOutput() ); + } viewer->SetupInteractor (iren); -// float *range = reader->GetOutput()->GetScalarRange(); -// viewer->SetColorWindow (range[1] - range[0]); -// viewer->SetColorLevel (0.5 * (range[1] + range[0])); + //vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange(); + //viewer->SetColorWindow (range[1] - range[0]); + //viewer->SetColorLevel (0.5 * (range[1] + range[0])); // Here is where we setup the observer, vtkgdcmObserver *obs = vtkgdcmObserver::New();