Commit 883f6531 authored by Dhanannjay Deo's avatar Dhanannjay Deo Committed by Dhanannjay Deo

ENH: Working tests for Update

parent 0e647a2d
Pipeline #10920 passed with stage
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOpenSlideReader.cxx
"DATA{${VTK_TEST_INPUT_DIR}/Microscopy/Small.ndpi}"i
"DATA{${VTK_TEST_INPUT_DIR}/Microscopy/small2.ndpi}"
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests)
vtk_test_cxx_executable(${vtk-module}CxxTests tests RENDERING_FACTORY)
......@@ -12,26 +12,16 @@
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 <vtkOpenSlideReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkImageData.h>
#include <vtkPNGWriter.h>
// VTK includes
#include <vtkTestUtilities.h>
// C++ includes
......@@ -41,43 +31,44 @@
int TestOpenSlideReader(int argc, char** argv)
{
const char* rasterFileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/Microscopy/Small.ndpi");
"Data/Microscopy/small2.ndpi");
std::cout << "Got Filename: " << rasterFileName << std::endl;
//std::cout << "Got Filename: " << rasterFileName << std::endl;
// Create reader to read shape file.
vtkNew<vtkOpenSlideReader> reader;
reader->SetFileName(rasterFileName);
reader->Update();
reader->UpdateInformation();
delete [] rasterFileName;
// We need a renderer
vtkNew<vtkRenderer> renderer;
int extent[6] = {20,120,20,120,0,0};
// Get the data
vtkNew<vtkImageActor> actor;
actor->SetInputData(reader->GetOutput());
renderer->AddActor(actor.GetPointer());
reader->SetUpdateExtent(extent);
vtkNew<vtkPNGWriter> writer;
writer->SetInputConnection(reader->GetOutputPort());
writer->SetFileName("this.png");
writer->SetUpdateExtent(extent);
writer->Update();
writer->Write();
// 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();
}
// Visualize
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> window;
window->AddRenderer(renderer.GetPointer());
return !retVal;
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(window.GetPointer());
vtkNew<vtkImageViewer2> imageViewer;
imageViewer->SetInputConnection(reader->GetOutputPort());
//imageViewer->SetExtent(1000,1500,1000,1500,0,0);
imageViewer->SetupInteractor(renderWindowInteractor.GetPointer());
//imageViewer->SetSlice(0);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
renderWindowInteractor->Initialize();
imageViewer->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
25aeb8961484b982a7084adef0c37feb
d18e4f93432ba312aa7636f627f0d293
......@@ -11,4 +11,6 @@ vtk_module(vtkDomainsMicroscopy
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
vtkInteractionImage
vtkRenderingContext${VTK_RENDERING_BACKEND}
)
......@@ -19,27 +19,39 @@
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkToolkits.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkOpenSlideReader);
void vtkOpenSlideReader::ExecuteInformation()
{
std::cout << this->GetFileName() << std::endl;
//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!");
"File could not be opened by openslide"
);
return;
}
int64_t w, h;
openslide_get_level0_dimensions(this->openslide_handle, &w, &h);
//std::cout << "Dimensions: " << w << ", " << h << std::endl;
if (this->GetFileName() == NULL)
{
}
this->vtkImageReader2::ExecuteInformation();
this->DataExtent[0] = 0;
this->DataExtent[1] = w;
this->DataExtent[2] = 0;
this->DataExtent[3] = h;
this->DataExtent[4] = 0;
this->DataExtent[5] = 0;
this->SetNumberOfScalarComponents(3);
this->SetDataScalarTypeToUnsignedChar();
}
......@@ -49,25 +61,72 @@ void vtkOpenSlideReader::ExecuteInformation()
void vtkOpenSlideReader::ExecuteDataWithInformation(vtkDataObject *output,
vtkInformation *outInfo)
{
vtkImageData *data = this->AllocateOutputData(output, outInfo);
int inExtent[6];
//// 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);
vtkStreamingDemandDrivenPipeline::GetUpdateExtent(
outInfo,
inExtent);
cout << inExtent[0] << ", " << inExtent[1] << endl;
cout << inExtent[2] << ", " << inExtent[3] << endl;
//if (this->InternalFileName == NULL)
//{
//vtkErrorMacro(<< "Either a FileName or FilePrefix must be specified.");
//return;
//}
vtkImageData *data = this->AllocateOutputData(output, outInfo);
//data->GetExtent(this->OutputExtent);
//data->GetIncrements(this->OutputIncrements);
//this->ComputeDataIncrements();
if(this->openslide_handle == NULL)
{
std::cout << "In the data info update, file is not updated" << std::endl;
}
data->GetPointData()->GetScalars()->SetName("OpenSlideImage");
//std::cout << "Extents: " << data->GetExtent() << std::endl;
this->ComputeDataIncrements();
data->GetPointData()->GetScalars()->SetName("OpenSlideImage");
// No updating anything right now
//// Leverage openslide to read the region
//int inExtent[6];
//data->GetExtent(inExtent);
cout << inExtent[0] << ", " << inExtent[1] << endl;
cout << inExtent[2] << ", " << inExtent[3] << endl;
int w = inExtent[1] - inExtent[0];
int h = inExtent[3]- inExtent[2];
char * buffer = new char[w * h * 4];
openslide_read_region(this->openslide_handle, (unsigned int *) buffer,
inExtent[0],
inExtent[2],
0, // level
w,
h
);
if(openslide_get_error(this->openslide_handle) != NULL)
{
delete[] buffer;
vtkErrorWithObjectMacro(this,
"File could not be read by openslide"
);
return;
}
unsigned char* ptr = (unsigned char*)(data->GetScalarPointer());
unsigned char* filePtr = ((unsigned char*) buffer);
// Order = RGBA
for (long i = 0; i < w*h; i++)
{
ptr[0] = filePtr[0];
ptr[1] = filePtr[1];
ptr[2] = filePtr[2];
ptr += 3;
filePtr += 4;
}
delete[] buffer;
openslide_close(this->openslide_handle);
}
......
7a3a6d1db332aba39a61ee62414a5298
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