Commit d36c7e53 authored by Dhanannjay Deo's avatar Dhanannjay Deo Committed by Dhanannjay Deo

ADD: New Microscopy domain and vtkOpenSlideReader

parent da4e277a
Pipeline #10922 passed with stage
# OpenSlide required
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(OpenSlide REQUIRED)
mark_as_advanced(OPENSLIDE_INCLUDE_DIR OPENSLIDE_LIBRARY)
set(OPENSLIDE_SRCS vtkOpenSlideReader.cxx)
include_directories(${OPENSLIDE_INCLUDE_DIRS})
set_source_files_properties(vtkOPENSLIDE WRAP_EXCLUDE)
vtk_module_library(vtkDomainsMicroscopy ${OPENSLIDE_SRCS})
vtk_module_link_libraries(vtkDomainsMicroscopy LINK_PRIVATE ${OPENSLIDE_LIBRARY})
# A CMake find module for the OpenSlide microscopy file reader library.
#
# http://openslide.org
#
# Once done, this module will define
# OPENSLIDE_FOUND - system has OpenSlide
# OPENSLIDE_INCLUDE_DIRS - the OpenSlide include directory
# OPENSLIDE_LIBRARIES - link to these to use OpenSlide
# Look for the header.
find_path( OPENSLIDE_INCLUDE_DIR NAMES openslide.h PATHS /usr/local/include/openslide)
mark_as_advanced( OPENSLIDE_INCLUDE_DIR )
# Look for the library.
find_library( OPENSLIDE_LIBRARY NAMES openslide )
mark_as_advanced( OPENSLIDE_LIBRARY )
# Handle the QUIETLY and REQUIRED arguments and set OPENSLIDE_FOUND true if all
# the listed variables are TRUE.
find_package( PackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS( OPENSLIDE DEFAULT_MSG OPENSLIDE_LIBRARY OPENSLIDE_INCLUDE_DIR )
if( OPENSLIDE_FOUND )
set( OPENSLIDE_LIBRARIES ${OPENSLIDE_LIBRARY} )
set( OPENSLIDE_INCLUDE_DIRS ${OPENSLIDE_INCLUDE_DIR} )
endif()
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOpenSlideReader.cxx
"DATA{${VTK_TEST_INPUT_DIR}/Microscopy/Small.ndpi}"i
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests)
/*=========================================================================
Program: Visualization Toolkit
Module: TestOpenSlideReader.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 <vtkOpenSlideReader.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 TestOpenSlideReader(int argc, char** argv)
{
const char* rasterFileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/Microscopy/Small.ndpi");
std::cout << "Got Filename: " << rasterFileName << std::endl;
// Create reader to read shape file.
vtkNew<vtkOpenSlideReader> 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;
}
vtk_module(vtkDomainsMicroscopy
GROUPS
StandAlone
DEPENDS
vtkCommonDataModel
vtkCommonExecutionModel
vtkIOImage
PRIVATE_DEPENDS
vtkIOXML
vtkFiltersSources
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenSlideReader.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 "vtkOpenSlideReader.h"
#include "vtkDataArray.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkToolkits.h"
vtkStandardNewMacro(vtkOpenSlideReader);
void vtkOpenSlideReader::ExecuteInformation()
{
std::cout << this->GetFileName() << std::endl;
this->openslide_handle = openslide_open(this->GetFileName());
if(this->openslide_handle == NULL || openslide_get_error(this->openslide_handle) != NULL)
{
vtkErrorWithObjectMacro(this,
"Trying to read a JPEG image from "
"a zero-length memory buffer!");
return;
}
if (this->GetFileName() == NULL)
{
}
}
//----------------------------------------------------------------------------
// This function reads a data from a file. The datas extent/axes
// are assumed to be the same as the file extent/order.
void vtkOpenSlideReader::ExecuteDataWithInformation(vtkDataObject *output,
vtkInformation *outInfo)
{
vtkImageData *data = this->AllocateOutputData(output, outInfo);
//// Leverage openslide to read the region
//openslide_read_region(this->openslide_handle, data->GetPointer(), x, y, 0, w, h);
//assert(openslide_get_error(osr) == NULL);
//openslide_close(osr);
//if (this->InternalFileName == NULL)
//{
//vtkErrorMacro(<< "Either a FileName or FilePrefix must be specified.");
//return;
//}
//this->ComputeDataIncrements();
data->GetPointData()->GetScalars()->SetName("OpenSlideImage");
// No updating anything right now
}
int vtkOpenSlideReader::CanReadFile(const char* fname)
{
return 3;
}
//----------------------------------------------------------------------------
void vtkOpenSlideReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenSlideReader.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 vtkOpenSlideReader - read digital whole slide images supported by
// openslide library
// .SECTION Description
// vtkOpenSlideReader is a source object that uses openslide library to
// read multiple supported image formats used for whole slide images in
// microscopy community.
//
// .SECTION See Also
// vtkPTIFWriter
#ifndef vtkOpenSlideReader_h
#define vtkOpenSlideReader_h
#include "vtkIOImageModule.h" // For export macro
#include "vtkImageReader2.h"
extern "C" {
#include "openslide/openslide.h"
}
class VTKIOIMAGE_EXPORT vtkOpenSlideReader : public vtkImageReader2
{
public:
static vtkOpenSlideReader *New();
vtkTypeMacro(vtkOpenSlideReader,vtkImageReader2);
virtual void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Is the given file supported ?
int CanReadFile(const char* fname);
// Description:
// Get the file extensions for this format.
// Returns a string with a space separated list of extensions in
// the format .extension
virtual const char* GetFileExtensions()
{
return ".ndpi .svs";
}
// Description:
// Return a descriptive name for the file format that might be useful in a GUI.
virtual const char* GetDescriptiveName()
{
return "OpenSlide";
}
protected:
vtkOpenSlideReader() {}
~vtkOpenSlideReader() {}
virtual void ExecuteInformation();
virtual void ExecuteDataWithInformation(vtkDataObject *out, vtkInformation *outInfo);
private:
openslide_t *openslide_handle;
vtkOpenSlideReader(const vtkOpenSlideReader&); // Not implemented.
void operator=(const vtkOpenSlideReader&); // Not implemented.
};
#endif
f90e3de39f83b7b86cac190d4c9091f4
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