#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkImageMapper.h>
#include <vtkImageData.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[] )
{
vtkGdcmReader *reader = vtkGdcmReader::New();
if (argc < 2)
{
cerr << "Usage: " << argv[0] << " image.dcm\n";
return 0;
}
reader->SetFileName( argv[1] );
reader->UpdateWholeExtent();
vtkImageData* ima = reader->GetOutput();
int* Size = ima->GetDimensions();
cout << "Dimensions of the picture as read with gdcm: "
<< Size[0] << " x " << Size[1] << 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();
vtkTexture* VTKtexture = vtkTexture::New();
VTKtexture->SetInput(ima);
VTKtexture->InterpolateOn();
VTKtexture->SetLookupTable(VTKtable);
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);
vtkPolyDataMapper *VTKplaneMapper = vtkPolyDataMapper::New();
VTKplaneMapper->SetInput(VTKplane->GetOutput());
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();
reader->Delete();
VTKtable->Delete();
VTKtexture->Delete();
VTKplane->Delete();
VTKplaneMapper->Delete();
VTKplaneActor->Delete();
ren->Delete();
renwin->Delete();
iren->Delete();
return(0);
}
#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsWriter.h>
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkImageMapToColors.h>
#include <vtkLookupTable.h>
#include "vtkGdcmReader.h"
#include "gdcmDocument.h"
#ifndef vtkFloatingPointType
#define vtkFloatingPointType float
#endif
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();
}
}
}
vtkImageViewer *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->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOWSEQ);
reader->Update();
reader->GetOutput()->Print( cout );
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkImageViewer *viewer = vtkImageViewer::New();
if( reader->GetLookupTable() )
{
vtkImageMapToColors *map = vtkImageMapToColors::New ();
map->SetInput (reader->GetOutput());
map->SetLookupTable (reader->GetLookupTable());
map->SetOutputFormatToRGB();
viewer->SetInput ( map->GetOutput() );
map->Delete();
}
else
{
vtkFloatingPointType *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);
vtkgdcmObserver *obs = vtkgdcmObserver::New();
obs->ImageViewer = viewer;
iren->AddObserver(vtkCommand::CharEvent,obs);
obs->Delete();
iren->Initialize();
iren->Start();
vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
writer->SetInput( reader->GetOutput());
writer->SetFileName( "foo.vtk" );
writer->SetFileTypeToBinary();
reader->Delete();
iren->Delete();
viewer->Delete();
writer->Delete();
return 0;
}