]> Creatis software - gdcm.git/commitdiff
ENH: Adding two different viewer. One using vtkImageViewer and the other vtkImageView...
authormalaterre <malaterre>
Wed, 2 Feb 2005 20:10:50 +0000 (20:10 +0000)
committermalaterre <malaterre>
Wed, 2 Feb 2005 20:10:50 +0000 (20:10 +0000)
vtk/CMakeLists.txt
vtk/vtkgdcmViewer.cxx
vtk/vtkgdcmViewer2.cxx [new file with mode: 0644]

index 11e7e18b85e4e006c090190b464094d408aba117..6cb8cd04031f70f2806349138c260e9c5110a9c7 100644 (file)
@@ -46,6 +46,11 @@ TARGET_LINK_LIBRARIES(vtkgdcmViewer
   vtkgdcm
   vtkRendering
 )
+ADD_EXECUTABLE(vtkgdcmViewer2 vtkgdcmViewer2.cxx)
+TARGET_LINK_LIBRARIES(vtkgdcmViewer2
+  vtkgdcm
+  vtkRendering
+)
 
 #-----------------------------------------------------------------------------
 SET(vtkWriteDicom_SOURCES
index 9e1b6a5993dfbd0d69f4314b36f4d7166d06421f..6526c1753482d7afafc3bccfd37eda4ab7476788 100644 (file)
@@ -1,3 +1,20 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: vtkgdcmViewer.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/02/02 20:10:50 $
+  Version:   $Revision: 1.24 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html 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.
+                                                                                
+=========================================================================*/
 // This example illustrates how the vtkGdcmReader vtk class can be
 // used in order to:
 //  * produce a simple (vtk based) Dicom image STACK VIEWER.
@@ -12,8 +29,6 @@
 //  * the produced vtk file is named "foo.vtk" (in the invocation directory).
 // 
 //----------------------------------------------------------------------------
-#include <iostream>
-
 #include <vtkRenderWindowInteractor.h>
 #include <vtkImageViewer.h>
 #include <vtkStructuredPoints.h>
@@ -126,7 +141,7 @@ int main(int argc, char *argv[])
    writer->SetInput( reader->GetOutput());
    writer->SetFileName( "foo.vtk" );
    writer->SetFileTypeToBinary();
-   writer->Write();
+   //writer->Write();
 
    reader->Delete();
    iren->Delete();
diff --git a/vtk/vtkgdcmViewer2.cxx b/vtk/vtkgdcmViewer2.cxx
new file mode 100644 (file)
index 0000000..26b93bc
--- /dev/null
@@ -0,0 +1,152 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: vtkgdcmViewer2.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/02/02 20:10:50 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html 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.
+                                                                                
+=========================================================================*/
+// 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 <vtkRenderWindowInteractor.h>
+#include <vtkImageViewer2.h>
+#include <vtkStructuredPoints.h>
+#include <vtkStructuredPointsWriter.h>
+#include <vtkCommand.h>
+#include <vtkRenderer.h>
+#include <vtkImageMapToColors.h>
+#include <vtkLookupTable.h>
+
+#include "vtkGdcmReader.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+//----------------------------------------------------------------------------
+// Callback for the interaction
+class vtkgdcmObserver : public vtkCommand
+{
+public:
+   virtual char const *GetClassName() const 
+   { 
+      return "vtkgdcmObserver";
+   }
+   static vtkgdcmObserver *New() 
+   { 
+      return new vtkgdcmObserver; 
+   }
+   vtkgdcmObserver()
+   {
+      this->ImageViewer = NULL;
+   }
+   virtual void Execute(vtkObject *, unsigned long event, void* )
+   {
+      if ( this->ImageViewer )
+      {
+         if ( event == vtkCommand::CharEvent )
+         {
+            int max = ImageViewer->GetWholeZMax();
+            int slice = (ImageViewer->GetZSlice() + 1 ) % ++max;
+            ImageViewer->SetZSlice( slice );
+            ImageViewer->GetRenderer()->ResetCameraClippingRange();
+            ImageViewer->Render();
+         }
+      }
+   }
+   vtkImageViewer2 *ImageViewer;
+};
+
+
+int main(int argc, char *argv[])
+{
+   if( argc < 2 )
+      return 0;
+  
+   vtkGdcmReader *reader = vtkGdcmReader::New();
+   reader->AllowLookupTableOff();
+
+   if( argc == 2 )
+      reader->SetFileName( argv[1] );
+   else
+      for(int i=1; i< argc; i++)
+         reader->AddFileName( argv[i] );
+
+   reader->Update();
+
+   //print debug info:
+   reader->GetOutput()->Print( cout );
+
+   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
+
+   vtkImageViewer2 *viewer = vtkImageViewer2::New();
+
+   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
+   {
+      double *range = reader->GetOutput()->GetScalarRange();
+      viewer->SetColorLevel (0.5 * (range[1] + range[0]));
+      viewer->SetColorWindow (range[1] - range[0]);
+
+      viewer->SetInput ( reader->GetOutput() );
+   }
+   viewer->SetupInteractor (iren);
+  
+   //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();
+   obs->ImageViewer = viewer;
+   iren->AddObserver(vtkCommand::CharEvent,obs);
+   obs->Delete();
+
+   //viewer->Render();
+   iren->Initialize();
+   iren->Start();
+
+   //if you wish you can export dicom to a vtk file  
+   vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
+   writer->SetInput( reader->GetOutput());
+   writer->SetFileName( "foo.vtk" );
+   writer->SetFileTypeToBinary();
+   //writer->Write();
+
+   reader->Delete();
+   iren->Delete();
+   viewer->Delete();
+   writer->Delete();
+
+   return 0;
+}