]> Creatis software - gdcm.git/commitdiff
* vtk subdir added. Contains vtkGdcmReader.[cxx|h] a vtk class
authorfrog <frog>
Mon, 5 May 2003 14:13:58 +0000 (14:13 +0000)
committerfrog <frog>
Mon, 5 May 2003 14:13:58 +0000 (14:13 +0000)
        inherinting from vtkImageReader and testvtkGdcmReader.cxx a small
        demo of the usage of this class.
        Compilation of this vtk part is only done when using the --enable-vtk
        at configure (or autogen.sh) stage.

13 files changed:
ChangeLog
Doc/DoxyInstallation.txt
INSTALL
Makefile.am
configure.in
src/gdcmDict.h
src/gdcmHeader.cxx
src/gdcmHeader.h
vtk/.cvsignore [new file with mode: 0644]
vtk/Makefile.am [new file with mode: 0644]
vtk/testvtkGdcmReader.cxx [new file with mode: 0644]
vtk/vtkGdcmReader.cxx [new file with mode: 0644]
vtk/vtkGdcmReader.h [new file with mode: 0644]

index c7ea5813adeb2182f4defcc07a6164b926f0aa4d..9deeb3673850f88345ce6bcd1fdccda59ece5eb1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-05-5  Eric Boix <Eric.Boix@creatis.insa-lyon.fr> with JPR
+      * vtk subdir added. Contains vtkGdcmReader.[cxx|h] a vtk class
+        inherinting from vtkImageReader and testvtkGdcmReader.cxx a small
+        demo of the usage of this class.
+        Compilation of this vtk part is only done when using the --enable-vtk
+        at configure (or autogen.sh) stage.
+
 2003-04-16  Eric Boix <Eric.Boix@creatis.insa-lyon.fr> with JPR
       * More memmory link related corrections and documentation fixes.
         Notes on valgrind:
index 5e90abe83e3c7a970de4b5412e2b0a75031ad716..3ba3bacac64ba34295c4642088d9e9ca8acc2c90 100644 (file)
  *       -# <TT>./autogen.sh --prefix=/where/ever/you/want</TT>
  *           to configure the script to force installation in a specified
  *            place.
- *       -# <TT>./autogen.sh --configure-python</TT> to generate the
+ *       -# <TT>./autogen.sh --enable-python</TT> to generate the
  *              python wrappers.
  *        .
  *     - <TT>make</TT> (or <TT>make 'CFLAGS=-g</TT>...)
  *     - <TT>make instal</TT>
- *     - As usual, you can optionnaly:
+ *     - As usual, you can optionnally:
  *       -# <TT>make clean</TT>
  *       -# <TT>make 'CFLAGS='</TT> if you are in hurry and want to omit
  *          "-g -O2" default flags
diff --git a/INSTALL b/INSTALL
index 2df8268570fecc2690632be754cc033fc4149e90..ecae1fa749fe4f7a8c5f34fb378b61847d7d2ad3 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -3,7 +3,7 @@
 ./autogen.sh
 ./configure (optional if just after autogen.sh)
 make
-make install
+make instal
 
 You can use the --prefix option of the configure script to force installation
 in some place (default is /usr/local/DCMlib):
index ea35b2203bc0c2e5be6ff4b0ca17b7545a5aefbd..aa38126c3e82ff32f51faa7ac8bdeb1cd0f86d46 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = src gdcmPython Test Dicts Doc
+SUBDIRS = src gdcmPython Test Dicts Doc vtk
 
 
 EXTRA_DIST = \
index df3c7c794c28c1d5c452b5217cd939b32ea26efa..cac0e468f41d686bdb3de27c5403e48345b3ad3f 100644 (file)
@@ -54,7 +54,7 @@ AM_CONDITIONAL(ENABLE_DOXYGEN, test x$enable_doxygen = xyes)
 
 dnl Checks for Python
 AC_ARG_ENABLE(python,
-        [  --enable-python          Enable Python language support (default=no).],,
+        [  --enable-python      Enable Python language support (default=no).],,
         [enable_python="no"])
 dnl AC_MSG_RESULT($enable_python)
 build_python=no
@@ -68,6 +68,12 @@ if test "yes" = "$enable_python"; then
 fi
 AM_CONDITIONAL(BUILD_PYTHON, test x$build_python = xyes)
 
+dnl Checks for vtk
+AC_ARG_ENABLE(vtk,
+        [  --enable-vtk      Enable vtk extensions support (default=no).],,
+        [enable_vtk="no"])
+AM_CONDITIONAL(BUILD_VTK, test x$enable_vtk = xyes)
+
 dnl produce Makefile.in files
 AC_OUTPUT([
 Makefile 
@@ -76,4 +82,5 @@ src/Makefile
 gdcmPython/Makefile
 Test/Makefile
 Dicts/Makefile
+vtk/Makefile
 Doc/Makefile])
index 5e56f3356eacb26d85376f0cecc2c939cb9b4920..77d837c9f0a3aa1cceb038b36f0fef1f8a251554 100644 (file)
@@ -1,8 +1,4 @@
-////////////////////////////////////////////////////////////////////////////
-// A single DICOM dictionary i.e. a container for a collection of dictionary
-// entries. There should be a single public dictionary (THE dictionary of
-// the actual DICOM v3) but as many shadow dictionaries as imagers 
-// combined with all software versions...
+// gdcmDict.h
 
 #ifndef GDCMDICT_H
 #define GDCMDICT_H
 typedef map<TagKey,  gdcmDictEntry*> TagKeyHT;
 typedef map<TagName, gdcmDictEntry*> TagNameHT;
 
-/// Build a memory representation of a dicom dictionary by parsing
-/// an ascii file
+/*
+ * \defgroup gdcmDict
+ * \brief    gdcmDict acts a memory representation of a dicom dictionary i.e.
+ *           it is a container for a collection of dictionary entries. The
+ *           dictionary is loaded from in an ascii file.
+ *           There should be a single public dictionary (THE dictionary of
+ *           the actual DICOM v3) but as many shadow dictionaries as imagers 
+ *           combined with all software versions...
+ * \see gdcmDictSet
+ */
 class GDCM_EXPORT gdcmDict {
        string name;
        string filename;
index a8c624052882827ca0e4cf952a363dba32c5aab2..631b038d98e0a3048f5b3050a47e128cbe46b55f 100644 (file)
@@ -1,4 +1,4 @@
-// gdcmHeader.cxx
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.61 2003/05/05 14:13:59 frog Exp $
 
 #include <stdio.h>
 #include <cerrno>
index 2fc8e8c491f6beba445f9519872768d145323300..3373b99a03d13f50f456c0933da8a9c448ea201f 100644 (file)
@@ -1,4 +1,4 @@
-// gdcmHeader.h
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.21 2003/05/05 14:13:59 frog Exp $
 
 #ifndef GDCMHEADER_H
 #define GDCMHEADER_H
diff --git a/vtk/.cvsignore b/vtk/.cvsignore
new file mode 100644 (file)
index 0000000..e8b184e
--- /dev/null
@@ -0,0 +1,5 @@
+.deps
+.libs
+Makefile.in
+Makefile
+vtkgdcmdemo
diff --git a/vtk/Makefile.am b/vtk/Makefile.am
new file mode 100644 (file)
index 0000000..38c18fc
--- /dev/null
@@ -0,0 +1,30 @@
+## Process this file with automake to produce Makefile.in
+LIBS_VTK=-L/usr/lib/vtk \
+         -lvtkCommon -lvtkIO -lvtkFiltering -lvtkRendering -lvtkGraphics \
+         -lvtkImaging -lvtkpng -lvtkzlib -lvtkjpeg -lvtkexpat -lvtktiff \
+         -lvtkftgl -lvtkfreetype
+INCLUDE_VTK=-I/usr/include/vtk
+
+LIBS_X11= -L/usr/X11R6/lib -lX11 -lXt -lSM -lICE -lXext -lGL
+##   $(x_ldflags)    
+##   $(x_libs)      
+
+INCLUDES =         \
+   -I.          \
+   -I$(top_srcdir)/src \
+   $(INCLUDE_VTK)
+
+LDADD =              \
+   $(top_builddir)/src/libgdcm.la \
+   $(LIBS_VTK) \
+   $(LIBS_X11)
+
+if BUILD_VTK
+noinst_PROGRAMS = vtkgdcmdemo
+vtkgdcmdemo_SOURCES = testvtkGdcmReader.cxx  vtkGdcmReader.cxx 
+
+else
+all:
+endif
+
+
diff --git a/vtk/testvtkGdcmReader.cxx b/vtk/testvtkGdcmReader.cxx
new file mode 100644 (file)
index 0000000..47a9ae8
--- /dev/null
@@ -0,0 +1,93 @@
+// $Header: /cvs/public/gdcm/vtk/Attic/testvtkGdcmReader.cxx,v 1.1 2003/05/05 14:13:59 frog Exp $
+
+#include "vtkRenderer.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderWindowInteractor.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkActor.h"
+#include "vtkImageMapper.h"
+#include "vtkImageViewer.h"
+#include "vtkMatrix4x4.h"
+#include "vtkLookupTable.h"
+#include "vtkMatrixToLinearTransform.h"
+#include "vtkTexture.h"
+#include "vtkPlaneSource.h"
+#include "vtkTextureMapToPlane.h"
+#include "vtkDataSetMapper.h"
+#include "vtkActor.h"
+#include "vtkImageCast.h"
+#include "vtkPNGWriter.h"
+#include "vtkTexture.h"
+
+#include "vtkGdcmReader.h"
+
+  
+int main( int argc, char *argv[] )
+{
+   char a;
+   int *taille;
+   int x,y;
+
+   // Lecture de l'image
+   vtkGdcmReader *reader = vtkGdcmReader::New();
+   reader->DebugOn();
+   // Alloc Used High
+   // 8 8 7 U : OK
+   // reader->SetFileName("../Data/CT-MONO2-8-abdo.dcm");
+   // 16 12 11 U : OK but saturated
+   // reader->SetFileName("../Data/CT-MONO2-12-lomb-an2.acr2");
+   // 16 12 11 U OK
+   //OKreader->SetFileName("../Data/MR-MONO2-12-an2.acr2");
+   // 16 10 9 U OK
+   //reader->SetFileName("../Data/CR-MONO1-10-chest.dcm");
+   //reader->Update();
+   // 16 16 15 S: OK saturation ?
+   // reader->SetFileName("../Data/CT-MONO2-16-ort.dcm");
+   // 16 16 15 S:
+   reader->SetFileName("../Data/CT-MONO2-16-ankle.dcm");
+   reader->UpdateWholeExtent();
+   vtkImageData *ima = reader->GetOutput();
+   taille=ima->GetDimensions();
+   x = taille[0];  y = taille[1];
+   cout << "Taille de l'image en X=" << x << " et en Y=" << y << endl;
+
+   vtkLookupTable *VTKtable = vtkLookupTable::New();
+   VTKtable->SetNumberOfColors(1000);
+   VTKtable->SetTableRange(0,1000);
+   VTKtable->SetSaturationRange(0,0);
+   VTKtable->SetHueRange(0,1);
+   VTKtable->SetValueRange(0,1);
+   VTKtable->SetAlphaRange(1,1);
+   VTKtable->Build();
+   // Texture
+   vtkTexture * VTKtexture = vtkTexture::New();
+   VTKtexture->SetInput(ima);
+   VTKtexture->InterpolateOn();
+   VTKtexture->SetLookupTable(VTKtable);
+   // PlaneSource
+   vtkPlaneSource *VTKplane = vtkPlaneSource::New();
+   VTKplane->SetOrigin( -0.5, -0.5, 0.0);
+   VTKplane->SetPoint1(  0.5, -0.5, 0.0);
+   VTKplane->SetPoint2( -0.5,  0.5, 0.0);
+   // PolyDataMapper
+   vtkPolyDataMapper *VTKplaneMapper = vtkPolyDataMapper::New();
+   VTKplaneMapper->SetInput(VTKplane->GetOutput());
+   // Actor
+   vtkActor* VTKplaneActor = vtkActor::New();
+   VTKplaneActor->SetTexture(VTKtexture);
+   VTKplaneActor->SetMapper(VTKplaneMapper);
+   VTKplaneActor->PickableOn();
+   //
+   vtkRenderer        *ren = vtkRenderer::New();
+   vtkRenderWindow *renwin = vtkRenderWindow::New();
+   renwin->AddRenderer(ren);
+   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
+   iren->SetRenderWindow(renwin);
+   ren->AddActor(VTKplaneActor);
+   ren->SetBackground(0,0,0.5);
+   renwin->Render();
+   iren->Start();
+
+   return(0);
+}
+
diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx
new file mode 100644 (file)
index 0000000..eaba22f
--- /dev/null
@@ -0,0 +1,191 @@
+// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.1 2003/05/05 14:13:59 frog Exp $
+#include "vtkGdcmReader.h"
+#include "vtkByteSwap.h"
+#include <stdio.h>
+#include "vtkObjectFactory.h"
+#include "vtkImageFlip.h"
+#include "gdcm.h"
+
+vtkGdcmReader::vtkGdcmReader()
+{
+  // Constructor
+}
+
+//----------------------------------------------------------------------------
+vtkGdcmReader::~vtkGdcmReader()
+{ 
+  // FIXME free memory
+}
+
+// Configure the output e.g. WholeExtent, spacing, origin, scalar type...
+void vtkGdcmReader::ExecuteInformation()
+{
+  //FIXME free any old memory
+      
+  // if the user has not set the extent, but has set the VOI
+  // set the zaxis extent to the VOI z axis
+  if (this->DataExtent[4]==0 && this->DataExtent[5] == 0 &&
+     (this->DataVOI[4] || this->DataVOI[5]))
+    {
+    this->DataExtent[4] = this->DataVOI[4];
+    this->DataExtent[5] = this->DataVOI[5];
+    }
+
+  this->ComputeInternalFileName(this->DataExtent[4]);
+  
+  // Check for file existence.
+  FILE *fp;
+  fp = fopen(this->InternalFileName,"rb");
+  if (!fp)
+    {
+    vtkErrorMacro("Unable to open file " << this->InternalFileName);
+    return;
+    }
+  fclose(fp);
+
+  // Check for Gdcm parsability
+  gdcmHeader GdcmHeader(this->InternalFileName);
+  if (!GdcmHeader.IsReadable())
+    {
+    vtkErrorMacro("Gdcm cannot parse file " << this->InternalFileName);
+    return;
+    }
+
+  int NX = GdcmHeader.GetXSize();
+  int NY = GdcmHeader.GetYSize();
+  int NZ = GdcmHeader.GetZSize();
+  vtkDebugMacro("Image dimension as read from Gdcm:" <<
+                NX << " " << NY << " " << NZ);
+
+  if(NZ>1) this->SetFileDimensionality(3);
+
+  // When the user has set the VOI, check it's coherence with the file content.
+  if (this->DataVOI[0] || this->DataVOI[1] || 
+      this->DataVOI[2] || this->DataVOI[3] ||
+      this->DataVOI[4] || this->DataVOI[5])
+    { 
+    if ((this->DataVOI[0] < 0) ||
+        (this->DataVOI[1] >= NX) ||
+        (this->DataVOI[2] < 0) ||
+        (this->DataVOI[3] >= NY) ||
+        (this->DataVOI[4] < 0) ||
+        (this->DataVOI[5] >= NZ))
+      {
+      vtkWarningMacro("The requested VOI is larger than the file's ("
+                      << this->InternalFileName << ") extent ");
+      this->DataVOI[0] = 0;
+      this->DataVOI[1] = NX - 1;
+      this->DataVOI[2] = 0;
+      this->DataVOI[3] = NY - 1;
+      this->DataVOI[4] = 0;
+      this->DataVOI[5] = NZ - 1;
+      }
+    }
+
+  // Positionate the Extent.
+  this->DataExtent[0] = 0;
+  this->DataExtent[1] = NX - 1;
+  this->DataExtent[2] = 0;
+  this->DataExtent[3] = NY - 1;
+  if(this->GetFileDimensionality()==3)
+    {
+      this->DataExtent[4] = 0;
+      this->DataExtent[5] = NZ - 1;
+    }
+  
+  // We don't need to positionate the Endian related stuff (by using
+  // this->SetDataByteOrderToBigEndian() or SetDataByteOrderToLittleEndian()
+  // since the // reading of the file is done by gdcm
+
+  // But we need to set up the data type for downstream filters:
+  string type = GdcmHeader.GetPixelType();
+  if      ( type == "8U" )
+    {
+    vtkDebugMacro("8 bits unsigned image");
+    this->SetDataScalarTypeToUnsignedChar(); 
+    }
+  else if ( type == "8S" )
+    {
+    vtkErrorMacro("Cannot handle 8 bit signed files");
+    return;
+    }
+  else if ( type == "16U" )
+    {
+    vtkDebugMacro("16 bits unsigned image");
+    this->SetDataScalarTypeToUnsignedShort();
+    }
+  else if ( type == "16S" )
+    {
+    vtkDebugMacro("16 bits signed image");
+    this->SetDataScalarTypeToShort();
+    //vtkErrorMacro("Cannot handle 16 bit signed files");
+    }
+  else if ( type == "32U" )
+    {
+    vtkDebugMacro("32 bits unsigned image");
+    vtkDebugMacro("WARNING: forced to signed int !");
+    this->SetDataScalarTypeToInt();
+    }
+  else if ( type == "32S" )
+    {
+    vtkDebugMacro("32 bits signed image");
+    this->SetDataScalarTypeToInt();
+    }
+  else
+    {
+    vtkErrorMacro("Bad File Type " << this->InternalFileName
+                                   << "Type " << type);
+    return;
+    }
+
+  vtkImageReader::ExecuteInformation();
+}
+
+// Update -> UpdateData -> Execute -> ExecuteData (see vtkSource.cxx for
+// last step.
+// This function (redefinition of vtkImageReader::ExecuteData, see 
+// VTK/IO/vtkImageReader.cxx) reads a data from a file. The datas
+// extent/axes are assumed to be the
+// same as the file extent/order.
+void vtkGdcmReader::ExecuteData(vtkDataObject *output)
+{
+  if (!this->FileName)
+    {
+    vtkErrorMacro("A valid FileName must be specified.");
+    return;
+    }
+
+  vtkImageData *data = this->AllocateOutputData(output);
+  data->SetExtent(this->DataExtent);
+  data->GetPointData()->GetScalars()->SetName("ImageFile");
+
+  int size =
+    (this->DataExtent[1] - this->DataExtent[0]+1) *
+    (this->DataExtent[3] - this->DataExtent[2]+1) *
+    (this->DataExtent[5] - this->DataExtent[4]+1) *
+    2;
+  gdcmFile GdcmFile(this->InternalFileName);
+  size = GdcmFile.GetImageDataSize();
+  unsigned char *mem = new unsigned char [size];
+  if ( size != GdcmFile.GetImageDataSize() )
+    {
+    vtkDebugMacro("Inconsistency with GetImageDataSize");
+    vtkDebugMacro("Number of scalar components"
+                  << this->NumberOfScalarComponents);
+    }
+  GdcmFile.GetImageDataIntoVector((void*)mem, size);
+  data->GetPointData()->GetScalars()->SetVoidArray(mem, size, 0);
+  //vtkImageFlip * Flip = vtkImageFlip::New();
+  //Flip->SetInput(data);
+  //Flip->Update();
+  //data = Flip->GetOutput();
+  //Flip->SetInput(NULL);
+  this->Modified();
+
+}
+
+void vtkGdcmReader::PrintSelf(ostream& os, vtkIndent indent)
+{
+  vtkImageReader::PrintSelf(os,indent);
+  //CLEANME os << indent << "TypeSize: " << this->TypeSize << "\n";
+}
diff --git a/vtk/vtkGdcmReader.h b/vtk/vtkGdcmReader.h
new file mode 100644 (file)
index 0000000..20eb484
--- /dev/null
@@ -0,0 +1,21 @@
+// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.h,v 1.1 2003/05/05 14:13:59 frog Exp $
+
+#ifndef __vtkGdcmReader_h
+#define __vtkGdcmReader_h
+
+#include "vtkImageReader.h"
+
+class VTK_EXPORT vtkGdcmReader : public vtkImageReader
+{
+public:
+  static vtkGdcmReader *New() {return new vtkGdcmReader;};
+  vtkTypeMacro(vtkGdcmReader, vtkImageReader);
+  void PrintSelf(ostream& os, vtkIndent indent);
+protected:
+  vtkGdcmReader();
+  ~vtkGdcmReader();
+  void ExecuteData(vtkDataObject *output);
+  virtual void ExecuteInformation();
+};
+#endif
+