Commit e08997ed authored by Zhanping Liu's avatar Zhanping Liu
Browse files

ENH: Added LIC files, SurfaceLIC plugin, LIC examples, and

LIC tests. Also added were the datasets and baseline images
used by the LICtests.
parent 9ae5a641
......@@ -19,6 +19,7 @@ IF(VTK_USE_RENDERING)
MultiBlock/Cxx
GUI/Motif
DataManipulation/Cxx
Hybrid/Cxx
ImageProcessing/Cxx
IO/Cxx
Medical/Cxx
......
PROJECT (Hybrid)
IF(NOT VTK_BINARY_DIR)
FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})
ENDIF(NOT VTK_BINARY_DIR)
INCLUDE_DIRECTORIES(
# ImageDataLIC2DDemo and StructuredGridLIC2DDemo include
# TestImageDataLIC2D.h and TestStructuredGridLIC2DSlice
# from the dir below
${VTK_SOURCE_DIR}/Hybrid/Testing/Cxx
)
SET(HYBRID_EXAMPLES_SRCS
ImageDataLIC2DDemo
StructuredGridLIC2DDemo
)
IF(APPLE)
SET(EXECUTABLE_FLAG MACOSX_BUNDLE)
ENDIF(APPLE)
FOREACH(name ${HYBRID_EXAMPLES_SRCS})
ADD_EXECUTABLE(${name} ${EXECUTABLE_FLAG} ${name}.cxx)
TARGET_LINK_LIBRARIES(${name} vtkHybrid )
ENDFOREACH(name)
/*=========================================================================
Program: Visualization Toolkit
Module: ImageDataLIC2DDemo.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 "TestImageDataLIC2D.h"
int main( int argc, char * argv[] )
{
return ImageDataLIC2D( argc, argv );
}
/*=========================================================================
Program: Visualization Toolkit
Module: StructuredGridLIC2DDemo.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 "TestStructuredGridLIC2DSlice.h"
int main( int argc, char * argv[] )
{
RenderingMode = STRUCTURED_GRID_LIC2D_SLICE_DEMO;
return StructuredGridLIC2DSlice( argc, argv );
}
......@@ -8,12 +8,19 @@ ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})
ENDIF(NOT VTK_BINARY_DIR)
INCLUDE_DIRECTORIES(
# in support of SurfaceLICDemo that includes
# TestSurfaceLIC.h from the dir below
${VTK_SOURCE_DIR}/Rendering/Testing/Cxx
)
SET(RENDERING_EXAMPLES_SRCS
Cylinder
SpecularSpheres
DiffuseSpheres
AmbientSpheres
MaterialObjects
SurfaceLICDemo
)
IF(APPLE)
......
/*=========================================================================
Program: Visualization Toolkit
Module: SurfaceLICDemo.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 "TestSurfaceLIC.h"
int main( int argc, char * argv[] )
{
RenderingMode = SURFACE_LIC_DEMO;
return SurfaceLIC( argc, argv );
}
......@@ -25,6 +25,9 @@ IF (WIN32)
ENDIF (VTK_USE_MATROX_IMAGING)
ENDIF (WIN32)
# for vtkImageDataLIC2D and vtkStructuredGridLIC2D
SET( KIT_LIBS ${KIT_LIBS} vtkftgl )
SET ( Kit_SRCS
vtkExodusIIReaderParser.cxx
vtk3DSImporter.cxx
......@@ -42,6 +45,8 @@ vtkEarthSource.cxx
vtkFacetReader.cxx
vtkGreedyTerrainDecimation.cxx
vtkGridTransform.cxx
vtkImageDataLIC2D.cxx
vtkImageDataLIC2DExtentTranslator.cxx
vtkImageToPolyDataFilter.cxx
vtkImplicitModeller.cxx
vtkIterativeClosestPointTransform.cxx
......@@ -60,6 +65,8 @@ vtkRIBLight.cxx
vtkRIBProperty.cxx
vtkRenderLargeImage.cxx
vtkSpiderPlotActor.cxx
vtkStructuredExtent.cxx
vtkStructuredGridLIC2D.cxx
vtkTemporalDataSetCache.cxx
vtkTemporalInterpolator.cxx
vtkTemporalShiftScale.cxx
......@@ -108,6 +115,7 @@ IF (WIN32)
ENDIF (WIN32)
SET_SOURCE_FILES_PROPERTIES(
vtkStructuredGridLIC2D
vtkVRML
vtkX3D
vtkX3DExporterWriter
......@@ -116,6 +124,11 @@ vtkX3DExporterXMLWriter
vtkExodusIIReaderParser
WRAP_EXCLUDE)
# for vtkStructuredGridLIC2D
SET( glsl_files
vtkStructuredGridLIC2D_fs
)
SET(Kit_EXTRA_SRCS)
SET(Kit_EXTRA_CMDS)
SET(Kit_TCL_EXTRA_SRCS)
......@@ -125,6 +138,22 @@ SET(KIT_TCL_DEPS)
SET(KIT_PYTHON_DEPS)
SET(KIT_JAVA_DEPS)
# for vtkStructuredGridLIC2D
SET( glsl_h_files )
FOREACH( file ${glsl_files} )
SET( src ${VTK_SOURCE_DIR}/Hybrid/${file}.glsl )
SET( res ${VTK_BINARY_DIR}/Hybrid/${file}.cxx )
SET( resh ${VTK_BINARY_DIR}/Hybrid/${file}.h )
SET( glsl_h_files ${glsl_h_files} "${resh}" )
ADD_CUSTOM_COMMAND(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND ${VTK_ENCODESTRING_EXE}
ARGS ${res} ${src} ${file} --build-header VTK_HYBRID_EXPORT vtkSystemIncludes.h
)
SET( Kit_EXTRA_SRCS ${Kit_EXTRA_SRCS} ${res} )
ENDFOREACH( file )
#-----------------------------------------------------------------------------
# Include CMake code common to all kits.
INCLUDE(${VTK_CMAKE_DIR}/KitCommonBlock.cmake)
......
......@@ -9,10 +9,14 @@ IF (VTK_DATA_ROOT)
SET(MyTests ${MyTests}
TestBarChartActor.cxx
TestExodusImplicitArrays.cxx
TestImageDataLIC2D.cxx
#TestLabelPlacerExodus.cxx
TestLegendScaleActor.cxx
TestPieChartActor.cxx
TestSpiderPlotActor.cxx
TestStructuredGridLIC2DXSlice.cxx
TestStructuredGridLIC2DYSlice.cxx
TestStructuredGridLIC2DZSlice.cxx
)
ENDIF (VTK_DATA_ROOT)
......@@ -24,14 +28,14 @@ IF(NOT VTK_USE_DISPLAY)
TestPieChartActor.cxx
TestSpiderPlotActor.cxx
X3DTest.cxx
)
)
ENDIF(NOT VTK_USE_DISPLAY)
CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx ${MyTests}
EXTRA_INCLUDE vtkTestDriver.h)
ADD_EXECUTABLE(${KIT}CxxTests ${Tests})
TARGET_LINK_LIBRARIES(${KIT}CxxTests vtkHybrid)
TARGET_LINK_LIBRARIES(${KIT}CxxTests vtkHybrid vtkRendering vtkImaging vtkIO )
SET (TestsToRun ${Tests})
REMOVE (TestsToRun ${KIT}CxxTests.cxx TestImageStencilData.cxx)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageDataLIC2D.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 "TestImageDataLIC2D.h"
#include <vtksys/SystemTools.hxx>
int TestImageDataLIC2D(int argc, char* argv[])
{
char* fname =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/SurfaceVectors.vtk");
vtkstd::string filename = fname;
filename = "--data=" + filename;
fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/noise.png");
vtkstd::string noise = fname;
noise = "--noise=" + noise;
char** new_argv = new char*[argc+10];
for (int cc=0; cc < argc; cc++)
{
new_argv[cc] = vtksys::SystemTools::DuplicateString(argv[cc]);
}
new_argv[argc++] = vtksys::SystemTools::DuplicateString(filename.c_str());
new_argv[argc++] = vtksys::SystemTools::DuplicateString(noise.c_str());
new_argv[argc++] = vtksys::SystemTools::DuplicateString("--mag=5");
new_argv[argc++] = vtksys::SystemTools::DuplicateString("--partitions=5");
int status = ImageDataLIC2D(argc, new_argv);
for (int kk=0; kk < argc; kk++)
{
delete [] new_argv[kk];
}
delete [] new_argv;
return status;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageDataLIC2D.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.
=========================================================================*/
#ifndef __TestImageDataLIC2D_h
#define __TestImageDataLIC2D_h
#include "vtkGenericDataObjectReader.h"
#include "vtkImageDataLIC2D.h"
#include "vtkImageData.h"
#include "vtkImageIterator.h"
#include "vtkImagePermute.h"
#include "vtkImageShiftScale.h"
#include "vtkPNGReader.h"
#include "vtkPNGWriter.h"
#include "vtkProbeFilter.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredData.h"
#include "vtkTimerLog.h"
#include "vtkUnstructuredGrid.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkTesting.h"
#include <vtksys/CommandLineArguments.hxx>
#include "vtkImageMapToColors.h"
#include "vtkLookupTable.h"
#define CREATE_NEW(var, class) vtkSmartPointer<class> var = vtkSmartPointer<class>::New();
//-----------------------------------------------------------------------------
void Merge(vtkImageData* dest, vtkImageData* src)
{
if (!src || !dest)
{
return;
}
if (src->GetScalarType() != dest->GetScalarType())
{
cout << src->GetScalarTypeAsString() << ", " << dest->GetScalarTypeAsString() << endl;
abort();
}
vtkImageIterator<unsigned char> inIt(src, src->GetExtent());
int outextent[6];
src->GetExtent(outextent);
vtkImageIterator<unsigned char> outIt(dest, outextent);
while (!outIt.IsAtEnd() && !inIt.IsAtEnd())
{
unsigned char* spanOut = outIt.BeginSpan();
unsigned char* spanIn = inIt.BeginSpan();
unsigned char* outSpanEnd = outIt.EndSpan();
unsigned char* inSpanEnd = inIt.EndSpan();
if (outSpanEnd != spanOut && inSpanEnd != spanIn)
{
size_t minO = outSpanEnd - spanOut;
size_t minI = inSpanEnd - spanIn;
memcpy(spanOut, spanIn, (minO < minI)? minO : minI);
}
inIt.NextSpan();
outIt.NextSpan();
}
}
// * Example demonstrating use of vtkImageDataLIC2D filter.
// * Typical usage:
// ./bin/ImageDataLIC2D --data=<vtk file> --output=<png file>
int ImageDataLIC2D(int argc, char* argv[])
{
vtkstd::string filename;
vtkstd::string noise_filename;
int resolution = 10;
int magnification = 1;
vtkstd::string outputpath;
int num_partitions = 1;
int num_steps = 40;
vtksys::CommandLineArguments arg;
arg.StoreUnusedArguments(1);
arg.Initialize(argc, argv);
typedef vtksys::CommandLineArguments argT;
arg.AddArgument("--data", argT::EQUAL_ARGUMENT, &filename,
"(required) Enter dataset to load (currently only *.vtk files are supported");
arg.AddArgument("--res", argT::EQUAL_ARGUMENT, &resolution,
"(optional: default 10) Number of sample per unit distance");
arg.AddArgument("--mag", argT::EQUAL_ARGUMENT, &magnification,
"(optional: default 1) Magnification");
arg.AddArgument("--output", argT::EQUAL_ARGUMENT, &outputpath,
"(optional) Output png image");
arg.AddArgument("--partitions", argT::EQUAL_ARGUMENT, &num_partitions,
"(optional: default 1) Number of partitions");
arg.AddArgument("--num-steps", argT::EQUAL_ARGUMENT, &num_steps,
"(optional: default 40) Number of steps in each direction");
arg.AddArgument("--noise", argT::EQUAL_ARGUMENT, &noise_filename,
"(optional) Specify the filename to a png image file to use as the noise texture.");
if (!arg.Parse() || filename=="")
{
cerr << "Problem parsing arguments." << endl;
cerr << arg.GetHelp() << endl;
return 1;
}
if (magnification < 1)
{
cout << "WARNING: Magnification \'" << magnification << "\' is invalid."
" Forcing a magnification of 1.";
magnification = 1;
}
if (num_steps < 1)
{
cout << "WARNING: Number of steps cannot be less than 1. Forcing 10.";
num_steps = 10;
}
CREATE_NEW(reader,vtkGenericDataObjectReader);
reader->SetFileName(filename.c_str());
reader->Update();
double bounds[6];
vtkDataSet::SafeDownCast(reader->GetOutput())->GetBounds(bounds);
// If 3D use XY slice, otherwise use non-trivial slice.
int dataDesc = VTK_XY_PLANE;
if (bounds[0] == bounds[1])
{
dataDesc = VTK_YZ_PLANE;
}
else if (bounds[2] == bounds[3])
{
dataDesc = VTK_XZ_PLANE;
}
else if (bounds[4] == bounds[5])
{
dataDesc = VTK_XY_PLANE;
}
CREATE_NEW(probeData,vtkImageData);
probeData->SetOrigin(bounds[0], bounds[2], bounds[4]);
int width = 0;
int height = 0;
switch (dataDesc)
{
case VTK_XY_PLANE:
width = static_cast<int>(ceil((bounds[1]-bounds[0]) * resolution));
height = static_cast<int>(ceil((bounds[3]-bounds[2]) * resolution));
probeData->SetDimensions(width, height, 1);
probeData->SetSpacing(
(bounds[1]-bounds[0])/double(width), (bounds[3]-bounds[2])/double(height), 1);
break;
case VTK_YZ_PLANE:
width = static_cast<int>(ceil((bounds[3]-bounds[2]) * resolution));
height = static_cast<int>(ceil((bounds[5]-bounds[4]) * resolution));
probeData->SetDimensions(1, width, height);
probeData->SetSpacing(
1, (bounds[3]-bounds[2])/double(width), (bounds[5]-bounds[4])/double(height));
break;
case VTK_XZ_PLANE:
width = static_cast<int>(ceil((bounds[1]-bounds[0]) * resolution));
height = static_cast<int>(ceil((bounds[5]-bounds[4]) * resolution));
probeData->SetDimensions(width, 1, height);
probeData->SetSpacing(
(bounds[1]-bounds[0])/double(width), 1, (bounds[5]-bounds[4])/double(height));
break;
}
CREATE_NEW(probe,vtkProbeFilter);
probe->SetSource(reader->GetOutput());
probe->SetInput(probeData);
probe->Update();
CREATE_NEW(renWin, vtkRenderWindow);
renWin->Render();
CREATE_NEW(output, vtkImageData);
output->SetDimensions(width * magnification, height * magnification, 1);
output->SetSpacing(probeData->GetSpacing());
output->SetOrigin(probeData->GetOrigin());
output->SetScalarTypeToUnsignedChar();
output->SetNumberOfScalarComponents(3);
output->AllocateScalars();
CREATE_NEW(filter, vtkImageDataLIC2D);
filter->SetContext(renWin);
filter->SetInputConnection(0, probe->GetOutputPort(0));
if (noise_filename != "")
{
CREATE_NEW(pngReader,vtkPNGReader);
pngReader->SetFileName(noise_filename.c_str());
filter->SetInputConnection(1, pngReader->GetOutputPort(0));
}
filter->SetSteps(num_steps);
filter->SetStepSize(0.8/magnification);
filter->SetMagnification(magnification);
filter->UpdateInformation();
int original_extents[6];
probeData->GetExtent(original_extents);
for (int kk=0; kk < num_partitions; kk++)
{
vtkStreamingDemandDrivenPipeline* sddp = vtkStreamingDemandDrivenPipeline::SafeDownCast(
filter->GetExecutive());
sddp->SetUpdateExtent(0, kk, num_partitions, 0);
vtkTimerLog* timer = vtkTimerLog::New();
timer->StartTimer();
filter->Update();
timer->StopTimer();
//cout << "Time: " << timer->GetElapsedTime() << endl;
timer->Delete();
CREATE_NEW(clone, vtkImageData);
clone->ShallowCopy(filter->GetOutput());
// input is double between 0.0 and 1.0. Cast it between [0, 255].
CREATE_NEW(caster, vtkImageShiftScale);
caster->SetInput(clone);
caster->SetShift(0.0);
caster->SetScale(255.0);
caster->SetOutputScalarTypeToUnsignedChar();
CREATE_NEW(permuter, vtkImagePermute);
permuter->SetInputConnection(caster->GetOutputPort());
switch (dataDesc)
{
case VTK_XY_PLANE:
permuter->SetFilteredAxes(0, 1, 2);
break;
case VTK_YZ_PLANE:
permuter->SetFilteredAxes(1, 2, 0);
break;
case VTK_XZ_PLANE:
permuter->SetFilteredAxes(0, 2, 1);
break;
}
permuter->Update();
::Merge(output, permuter->GetOutput());
}
CREATE_NEW(tester, vtkTesting);
for (int cc=0; cc < argc; cc++)
{
tester->AddArgument(argv[cc]);
}
if (outputpath != "")
{
CREATE_NEW(writer, vtkPNGWriter);
writer->SetFileName(outputpath.c_str());
writer->SetInput(output);
writer->Write();
}
return (!tester->IsValidImageSpecified() ||
(tester->RegressionTest(output, 10) == vtkTesting::PASSED))? /*success*/ 0 : /*failure*/ 1;
}
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: TestStructuredGridLIC2DSlice.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.
=========================================================================*/
#ifndef __TestStructuredGridLIC2DSlice_h
#define __TestStructuredGridLIC2DSlice_h
#include "vtkStructuredGridLIC2D.h"
#include "vtkPNGReader.h"
#include "vtkXMLStructuredGridReader.h"
#include "vtkExtractGrid.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkActor.h"
#include "vtkTexture.h"
#include "vtkDataSetMapper.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkPNGWriter.h"
#include "vtkImageShiftScale.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkImageExtractComponents.h"
#include "vtkTestUtilities.h"
#include "vtkCamera.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTimerLog.h"
#include <vtksys/CommandLineArguments.hxx>
#include <vtkstd/string>
enum { STRUCTURED_GRID_LIC2D_SLICE_DEMO = 0, STRUCTURED_GRID_LIC2D_SLICE_TEST = 1 };
static int RenderingMode