Commit 2de16eeb authored by Aashish Chaudhary's avatar Aashish Chaudhary

Added GDAL based raster reader

Co-authored by Jacob Becker <jacob.becker@kitware.com>. This reader support
a variety of rster formats using GDAL library

Change-Id: I9bc4dac89e271f307de70e86f0b50604d6229926
parent 088ff85d
find_package(GDAL REQUIRED)
mark_as_advanced(GDAL_INCLUDE_DIR GDAL_LIBRARY)
set(GDAL_SRCS vtkGDALVectorReader.cxx)
set(GDAL_SRCS vtkGDALVectorReader.cxx vtkGDALRasterReader.cxx)
include_directories(${GDAL_INCLUDE_DIRS})
......
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestGDALVectorReader.cxx
TestGDALRasterReader.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests)
/*=========================================================================
Program: Visualization Toolkit
Module: TestGDALRasterReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.
=========================================================================*/
#include <vtkGDALRasterReader.h>
// VTK includes
#include <vtkImageActor.h>
#include <vtkCellData.h>
#include <vtkCompositePolyDataMapper.h>
#include <vtkDataSetAttributes.h>
#include <vtkDoubleArray.h>
#include <vtkLookupTable.h>
#include <vtkMapper.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkTestUtilities.h>
// C++ includes
#include <sstream>
// Main program
int TestGDALRasterReader(int argc, char** argv)
{
const char* rasterFileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/GIS/raster.tiff");
// Create reader to read shape file.
vtkNew<vtkGDALRasterReader> reader;
reader->SetFileName(rasterFileName);
reader->Update();
delete [] rasterFileName;
// We need a renderer
vtkNew<vtkRenderer> renderer;
// Get the data
vtkNew<vtkImageActor> actor;
actor->SetInputData(reader->GetOutput());
renderer->AddActor(actor.GetPointer());
// Create a render window, and an interactor
vtkNew<vtkRenderWindow> renderWindow;
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindow->AddRenderer(renderer.GetPointer());
renderWindowInteractor->SetRenderWindow(renderWindow.GetPointer());
//Add the actor to the scene
renderer->SetBackground(1.0, 1.0, 1.0);
renderWindow->SetSize(400, 400);
renderWindow->Render();
renderer->ResetCamera();
renderWindow->Render();
int retVal = vtkRegressionTestImage(renderWindow.GetPointer());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
renderWindowInteractor->Start();
}
return !retVal;
}
......@@ -2,6 +2,7 @@ vtk_module(vtkIOGDAL
DEPENDS
vtkCommonDataModel
vtkCommonExecutionModel
vtkIOImage
TEST_DEPENDS
vtkTestingCore
vtkRendering${VTK_RENDERING_BACKEND}
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGDALRasterReader.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.
=========================================================================*/
// .NAME vtkGDALRasterReader - Read raster file formats using GDAL.
// .SECTION Description
// vtkGDALRasterReader is a source object that reads raster files and uses
// GDAL as the underlying library for the task. GDAL is required for this
// reader. The output of the reader is a vtkUniformGrid instead of vtkImageData
// to support blanking.
//
//
// .SECTION See Also
// vtkUniformGrid
#ifndef __vtkGDALRasterReader_h
#define __vtkGDALRasterReader_h
#include <vtkImageReader2.h>
#include <vtkIOGDALModule.h> // For export macro
// C++ includes
#include <string> // string is required
#include <vector> // vector is required
class VTKIOGDAL_EXPORT vtkGDALRasterReader : public vtkImageReader2
{
public:
static vtkGDALRasterReader* New();
vtkTypeMacro(vtkGDALRasterReader, vtkImageReader2);
vtkGDALRasterReader();
virtual ~vtkGDALRasterReader();
// Description:
// Set input file name
vtkSetStringMacro(FileName);
// Get input file name
vtkGetStringMacro(FileName);
// Description:
// Return proj4 spatial reference
const char* GetProjectionString() const;
// Description:
// Return geo-referenced corner points (Upper left,
// lower left, lower right, upper right)
const double* GetGeoCornerPoints();
// Description:
// Set desired width and height of the image
vtkSetVector2Macro(TargetDimensions, int);
vtkGetVector2Macro(TargetDimensions, int);
// Description:
// Get raster width and heigth
vtkGetVector2Macro(RasterDimensions, int);
//BTX
// Description:
// Return metadata as reported by GDAL
const std::vector<std::string>& GetMetaData();
//ETX
// Description:
// Return the invalid value for a pixel (for blanking purposes)
double GetInvalidValue();
//BTX
// Description:
// Return domain metadata
std::vector<std::string> GetDomainMetaData(const std::string& domain);
//ETX
// Description:
// Return driver name which was used to read the current data
const std::string& GetDriverShortName();
const std::string& GetDriverLongName();
protected:
virtual int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
virtual int RequestInformation(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
virtual int FillOutputPortInformation(int port,
vtkInformation* info);
protected:
char* FileName;
double DataSpacing[3];
double DataOrigin[3];
int DataExtents[6];
int TargetDimensions[2];
int RasterDimensions[2];
std::string Projection;
std::string DomainMetaData;
std::string DriverShortName;
std::string DriverLongName;
std::vector<std::string> Domains;
std::vector<std::string> MetaData;
class vtkGDALRasterReaderInternal;
vtkGDALRasterReaderInternal* Implementation;
private:
vtkGDALRasterReader(const vtkGDALRasterReader&); // Not implemented.
vtkGDALRasterReader& operator=(const vtkGDALRasterReader&); // Not implemented.
};
#endif // __vtkGDALRasterReader_h
32bff5999e082f95fa4277923dd99cf5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment