mirror of
https://github.com/OpenFOAM/ThirdParty-6.git
synced 2025-12-08 06:57:43 +00:00
ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file
Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
13
ParaView-5.0.1/VTK/IO/Image/Testing/Python/CMakeLists.txt
Normal file
13
ParaView-5.0.1/VTK/IO/Image/Testing/Python/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
vtk_add_test_python(
|
||||
TestBMPReader.py
|
||||
TestImageWriters.py
|
||||
TestJPEGReader.py
|
||||
TestMHD.py
|
||||
TestTIFFReader.py
|
||||
dem.py
|
||||
TestMetaImage2D.py
|
||||
TestNIFTIReaderWriter.py
|
||||
TestPNGTextChunks.py,NO_VALID
|
||||
TestSetFileNames.py
|
||||
TestImageJSONWriter.py,NO_VALID
|
||||
)
|
||||
23
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestBMPReader.py
Executable file
23
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestBMPReader.py
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# this test is designed to check the operation of the 8bit
|
||||
# export of BMPs
|
||||
# Image pipeline
|
||||
reader = vtk.vtkBMPReader()
|
||||
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp")
|
||||
reader.SetAllow8BitBMP(1)
|
||||
map = vtk.vtkImageMapToColors()
|
||||
map.SetInputConnection(reader.GetOutputPort())
|
||||
map.SetLookupTable(reader.GetLookupTable())
|
||||
map.SetOutputFormatToRGB()
|
||||
viewer = vtk.vtkImageViewer()
|
||||
viewer.SetInputConnection(map.GetOutputPort())
|
||||
viewer.SetColorWindow(256)
|
||||
viewer.SetColorLevel(127.5)
|
||||
#make interface
|
||||
viewer.Render()
|
||||
# --- end of script --
|
||||
66
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestImageJSONWriter.py
Executable file
66
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestImageJSONWriter.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
import os, json, sys
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
|
||||
args = sys.argv[1:]
|
||||
temp_dir = args[args.index("-T") + 1]
|
||||
|
||||
# Always use / to prevent windows/python issue with backslash
|
||||
tmp_file = temp_dir + '/wavelet_slice_3.json'
|
||||
|
||||
expected_first_values = [75.9335, 102.695, 91.2387, 115.507, 105.995, 125.724, 118.773, 132.24, 128.255, 134.254, 133.446, 131.431, 133.843, 123.998, 129.505]
|
||||
|
||||
# Image pipeline
|
||||
image1 = vtk.vtkRTAnalyticSource()
|
||||
image1.Update()
|
||||
output = image1.GetOutput()
|
||||
dim_ref = [value for value in output.GetDimensions()]
|
||||
origin_ref = [value for value in output.GetOrigin()]
|
||||
spacing_ref = [value for value in output.GetSpacing()]
|
||||
|
||||
print(dim_ref)
|
||||
print(origin_ref)
|
||||
print(spacing_ref)
|
||||
|
||||
writer = vtk.vtkJSONImageWriter()
|
||||
writer.SetInputData(image1.GetOutput())
|
||||
writer.SetFileName(tmp_file)
|
||||
writer.SetArrayName("RTData")
|
||||
writer.SetSlice(3)
|
||||
writer.Write()
|
||||
|
||||
# Try to load JSON file and compare with dumped data
|
||||
print("Writing file:", tmp_file)
|
||||
json_file = open(tmp_file, "r")
|
||||
json_obj = json.load(json_file)
|
||||
json_file.close()
|
||||
|
||||
slice = json_obj['RTData']
|
||||
if json_obj["dimensions"] != dim_ref:
|
||||
print("Dimension ERROR")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Dimension OK")
|
||||
if json_obj["origin"] != origin_ref:
|
||||
print("Origin ERROR")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Origin OK")
|
||||
if json_obj["spacing"] != spacing_ref:
|
||||
print("Spacing ERROR")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Spacing OK")
|
||||
if len(slice) == 441:
|
||||
print("Slice size OK")
|
||||
else:
|
||||
print("Slice size ERROR - Size of ", str(len(slice)))
|
||||
sys.exit(1)
|
||||
|
||||
for i in range(len(expected_first_values)):
|
||||
if expected_first_values[i] != slice[i]:
|
||||
sys.exit(1)
|
||||
|
||||
print("All good...")
|
||||
sys.exit()
|
||||
93
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestImageWriters.py
Executable file
93
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestImageWriters.py
Executable file
@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Image pipeline
|
||||
image1 = vtk.vtkTIFFReader()
|
||||
image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif")
|
||||
# "beach.tif" image contains ORIENTATION tag which is
|
||||
# ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF
|
||||
# reader parses this tag and sets the internal TIFF image
|
||||
# orientation accordingly. To overwrite this orientation with a vtk
|
||||
# convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke
|
||||
# SetOrientationType method with parameter value of 4.
|
||||
image1.SetOrientationType(4)
|
||||
image1.Update()
|
||||
|
||||
sp = vtk.vtkStructuredPoints()
|
||||
sp.SetDimensions(image1.GetOutput().GetDimensions())
|
||||
sp.SetExtent(image1.GetOutput().GetExtent())
|
||||
sp.SetScalarType(
|
||||
image1.GetOutput().GetScalarType(), image1.GetOutputInformation(0))
|
||||
sp.SetNumberOfScalarComponents(
|
||||
image1.GetOutput().GetNumberOfScalarComponents(),
|
||||
image1.GetOutputInformation(0))
|
||||
sp.GetPointData().SetScalars(image1.GetOutput().GetPointData().GetScalars())
|
||||
|
||||
luminance = vtk.vtkImageLuminance()
|
||||
luminance.SetInputData(sp)
|
||||
|
||||
# Let's create a dictionary to test the writers, the key will be the writer
|
||||
# and the value the file name used by the writer.
|
||||
filenames = ["tiff1.tif", "tiff2.tif", "bmp1.bmp", "bmp2.bmp",
|
||||
"pnm1.pnm", "pnm2.pnm", "psw1.ps", "psw2.ps",
|
||||
"pngw1.png", "pngw2.png", "jpgw1.jpg", "jpgw2.jpg"]
|
||||
writerObjects = list()
|
||||
writerObjectTypes = ["vtk.vtkTIFFWriter()", "vtk.vtkBMPWriter()",
|
||||
"vtk.vtkPNMWriter()", "vtk.vtkPostScriptWriter()",
|
||||
"vtk.vtkPNGWriter()", "vtk.vtkJPEGWriter()" ]
|
||||
idx = 0
|
||||
for fn in filenames:
|
||||
# Create the writer object
|
||||
exec(fn.split(".")[0] + " = " + writerObjectTypes[int(idx / 2)])
|
||||
# Append the writer object to the list called writerObjects
|
||||
writerObjects.append(eval(fn.split(".")[0]))
|
||||
idx += 1
|
||||
|
||||
# Now create the dictionary.
|
||||
writers = dict()
|
||||
for idx in range(len(writerObjects)):
|
||||
writers.update({writerObjects[idx]: filenames[idx]})
|
||||
|
||||
#
|
||||
# If the current directory is writable, then test the writers
|
||||
#
|
||||
try:
|
||||
for writer in writers:
|
||||
# The file name
|
||||
fn = writers[writer]
|
||||
# Use the file name to determine whether we are working
|
||||
# with the image or luninance.
|
||||
il = int(fn.split(".")[0][-1:])
|
||||
|
||||
# Can we write to the directory?
|
||||
channel = open(fn, "wb")
|
||||
channel.close()
|
||||
|
||||
if il == 1:
|
||||
writer.SetInputConnection(image1.GetOutputPort())
|
||||
elif il == 2:
|
||||
writer.SetInputConnection(luminance.GetOutputPort())
|
||||
else:
|
||||
continue
|
||||
writer.SetFileName(fn)
|
||||
writer.Write()
|
||||
|
||||
# cleanup
|
||||
#
|
||||
try:
|
||||
os.remove(fn)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
viewer = vtk.vtkImageViewer()
|
||||
viewer.SetInputConnection(luminance.GetOutputPort())
|
||||
viewer.SetColorWindow(255)
|
||||
viewer.SetColorLevel(127.5)
|
||||
viewer.Render()
|
||||
|
||||
except IOError:
|
||||
print("Unable to test the writers.")
|
||||
18
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestJPEGReader.py
Executable file
18
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestJPEGReader.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Image pipeline
|
||||
createReader = vtk.vtkImageReader2Factory()
|
||||
reader = createReader.CreateImageReader2("" + str(VTK_DATA_ROOT) + "/Data/beach.jpg")
|
||||
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.jpg")
|
||||
viewer = vtk.vtkImageViewer()
|
||||
viewer.SetInputConnection(reader.GetOutputPort())
|
||||
viewer.SetColorWindow(256)
|
||||
viewer.SetColorLevel(127.5)
|
||||
#make interface
|
||||
viewer.Render()
|
||||
reader.UnRegister(viewer) # not needed in python
|
||||
# --- end of script --
|
||||
63
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestMHD.py
Executable file
63
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestMHD.py
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
Ren1 = vtk.vtkRenderer()
|
||||
Ren1.SetBackground(0.33,0.35,0.43)
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(Ren1)
|
||||
renWin.SetSize(300,300)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
reader = vtk.vtkImageReader()
|
||||
reader.SetDataByteOrderToLittleEndian()
|
||||
reader.SetDataExtent(0,63,0,63,1,93)
|
||||
reader.SetDataSpacing(3.2,3.2,1.5)
|
||||
reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
|
||||
reader.SetDataMask(0x7fff)
|
||||
reader.Update()
|
||||
pvTemp200 = vtk.vtkMetaImageWriter()
|
||||
pvTemp200.SetFileName("mhdWriter.mhd")
|
||||
pvTemp200.SetInputData(reader.GetOutput())
|
||||
pvTemp200.Write()
|
||||
pvTemp90 = vtk.vtkMetaImageReader()
|
||||
pvTemp90.SetFileName("mhdWriter.mhd")
|
||||
pvTemp90.Update()
|
||||
pvTemp109 = vtk.vtkLookupTable()
|
||||
pvTemp109.SetNumberOfTableValues(256)
|
||||
pvTemp109.SetHueRange(0.6667,0)
|
||||
pvTemp109.SetSaturationRange(1,1)
|
||||
pvTemp109.SetValueRange(1,1)
|
||||
pvTemp109.SetTableRange(37.3531,260)
|
||||
pvTemp109.SetVectorComponent(0)
|
||||
pvTemp109.Build()
|
||||
pvTemp110 = vtk.vtkContourFilter()
|
||||
pvTemp110.SetInputData(pvTemp90.GetOutput(0))
|
||||
pvTemp110.SetValue(0,1150)
|
||||
pvTemp110.SetComputeNormals(1)
|
||||
pvTemp110.SetComputeGradients(0)
|
||||
pvTemp110.SetComputeScalars(0)
|
||||
pvTemp114 = vtk.vtkPolyDataMapper()
|
||||
pvTemp114.SetInputConnection(pvTemp110.GetOutputPort())
|
||||
pvTemp114.SetImmediateModeRendering(1)
|
||||
pvTemp114.SetScalarRange(0,1)
|
||||
pvTemp114.UseLookupTableScalarRangeOn()
|
||||
pvTemp114.SetScalarVisibility(1)
|
||||
pvTemp114.SetScalarModeToUsePointFieldData()
|
||||
pvTemp114.SelectColorArray("ImageFile")
|
||||
pvTemp114.SetLookupTable(pvTemp109)
|
||||
pvTemp115 = vtk.vtkActor()
|
||||
pvTemp115.SetMapper(pvTemp114)
|
||||
pvTemp115.GetProperty().SetRepresentationToSurface()
|
||||
pvTemp115.GetProperty().SetInterpolationToGouraud()
|
||||
pvTemp115.GetProperty().SetAmbient(0)
|
||||
pvTemp115.GetProperty().SetDiffuse(1)
|
||||
pvTemp115.GetProperty().SetSpecular(0)
|
||||
pvTemp115.GetProperty().SetSpecularPower(1)
|
||||
pvTemp115.GetProperty().SetSpecularColor(1,1,1)
|
||||
Ren1.AddActor(pvTemp115)
|
||||
iren.Initialize()
|
||||
# prevent the tk window from showing up then start the event loop
|
||||
# --- end of script --
|
||||
22
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestMetaImage2D.py
Executable file
22
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestMetaImage2D.py
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# This scripts shows a compressed spectrum of an image.
|
||||
# Image pipeline
|
||||
reader = vtk.vtkMetaImageReader()
|
||||
reader.SetFileName(VTK_DATA_ROOT + "/Data/foot/foot.mha")
|
||||
|
||||
viewer = vtk.vtkImageViewer2()
|
||||
viewer.SetInputConnection(reader.GetOutputPort())
|
||||
viewer.SetColorWindow(255)
|
||||
viewer.SetColorLevel(127.5)
|
||||
|
||||
viewInt = vtk.vtkRenderWindowInteractor()
|
||||
viewer.SetupInteractor(viewInt)
|
||||
viewer.Render()
|
||||
|
||||
# This is needed if you want to interact with the image.
|
||||
# viewInt.Start()
|
||||
@ -0,0 +1,154 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
"""
|
||||
Test NIFTI support in VTK by reading a file, writing it, and
|
||||
then re-reading it to ensure that the contents are identical.
|
||||
"""
|
||||
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
from vtk.util.misc import vtkGetTempDir
|
||||
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
VTK_TEMP_DIR = vtkGetTempDir()
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
testfiles = [
|
||||
["minimal.nii.gz", "out_minimal.nii.gz"],
|
||||
["minimal.img.gz", "out_minimal.hdr"]
|
||||
]
|
||||
|
||||
dispfile = "avg152T1_RL_nifti.nii.gz"
|
||||
|
||||
def TestDisplay(file1):
|
||||
"""Display the output"""
|
||||
|
||||
inpath = os.path.join(str(VTK_DATA_ROOT), "Data", file1)
|
||||
|
||||
reader = vtk.vtkNIFTIImageReader()
|
||||
reader.SetFileName(inpath)
|
||||
reader.Update()
|
||||
|
||||
size = reader.GetOutput().GetDimensions()
|
||||
center = reader.GetOutput().GetCenter()
|
||||
spacing = reader.GetOutput().GetSpacing()
|
||||
center1 = (center[0], center[1], center[2])
|
||||
center2 = (center[0], center[1], center[2])
|
||||
if size[2] % 2 == 1:
|
||||
center1 = (center[0], center[1], center[2] + 0.5*spacing[2])
|
||||
if size[0] % 2 == 1:
|
||||
center2 = (center[0] + 0.5*spacing[0], center[1], center[2])
|
||||
vrange = reader.GetOutput().GetScalarRange()
|
||||
|
||||
map1 = vtk.vtkImageSliceMapper()
|
||||
map1.BorderOn()
|
||||
map1.SliceAtFocalPointOn()
|
||||
map1.SliceFacesCameraOn()
|
||||
map1.SetInputConnection(reader.GetOutputPort())
|
||||
map2 = vtk.vtkImageSliceMapper()
|
||||
map2.BorderOn()
|
||||
map2.SliceAtFocalPointOn()
|
||||
map2.SliceFacesCameraOn()
|
||||
map2.SetInputConnection(reader.GetOutputPort())
|
||||
|
||||
slice1 = vtk.vtkImageSlice()
|
||||
slice1.SetMapper(map1)
|
||||
slice1.GetProperty().SetColorWindow(vrange[1]-vrange[0])
|
||||
slice1.GetProperty().SetColorLevel(0.5*(vrange[0]+vrange[1]))
|
||||
slice2 = vtk.vtkImageSlice()
|
||||
slice2.SetMapper(map2)
|
||||
slice2.GetProperty().SetColorWindow(vrange[1]-vrange[0])
|
||||
slice2.GetProperty().SetColorLevel(0.5*(vrange[0]+vrange[1]))
|
||||
|
||||
ratio = size[0]*1.0/(size[0]+size[2])
|
||||
|
||||
ren1 = vtk.vtkRenderer()
|
||||
ren1.SetViewport(0,0,ratio,1.0)
|
||||
ren2 = vtk.vtkRenderer()
|
||||
ren2.SetViewport(ratio,0.0,1.0,1.0)
|
||||
ren1.AddViewProp(slice1)
|
||||
ren2.AddViewProp(slice2)
|
||||
|
||||
cam1 = ren1.GetActiveCamera()
|
||||
cam1.ParallelProjectionOn()
|
||||
cam1.SetParallelScale(0.5*spacing[1]*size[1])
|
||||
cam1.SetFocalPoint(center1[0], center1[1], center1[2])
|
||||
cam1.SetPosition(center1[0], center1[1], center1[2] - 100.0)
|
||||
|
||||
cam2 = ren2.GetActiveCamera()
|
||||
cam2.ParallelProjectionOn()
|
||||
cam2.SetParallelScale(0.5*spacing[1]*size[1])
|
||||
cam2.SetFocalPoint(center2[0], center2[1], center2[2])
|
||||
cam2.SetPosition(center2[0] + 100.0, center2[1], center2[2])
|
||||
|
||||
if "-I" in sys.argv:
|
||||
style = vtk.vtkInteractorStyleImage()
|
||||
style.SetInteractionModeToImageSlicing()
|
||||
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetInteractorStyle(style)
|
||||
|
||||
renwin = vtk.vtkRenderWindow()
|
||||
renwin.SetSize(size[0] + size[2], size[1])
|
||||
renwin.AddRenderer(ren1)
|
||||
renwin.AddRenderer(ren2)
|
||||
|
||||
renwin.Render()
|
||||
|
||||
if "-I" in sys.argv:
|
||||
renwin.SetInteractor(iren)
|
||||
iren.Initialize()
|
||||
iren.Start()
|
||||
|
||||
return renwin
|
||||
|
||||
def TestReadWriteRead(infile, outfile):
|
||||
"""Read, write, and re-read a file, return difference."""
|
||||
|
||||
inpath = os.path.join(str(VTK_DATA_ROOT), "Data", infile)
|
||||
outpath = os.path.join(str(VTK_TEMP_DIR), outfile)
|
||||
|
||||
# read a NIFTI file
|
||||
reader = vtk.vtkNIFTIImageReader()
|
||||
reader.SetFileName(inpath)
|
||||
reader.TimeAsVectorOn()
|
||||
reader.Update()
|
||||
|
||||
writer = vtk.vtkNIFTIImageWriter()
|
||||
writer.SetInputConnection(reader.GetOutputPort())
|
||||
writer.SetFileName(outpath)
|
||||
# copy most information directoy from the header
|
||||
writer.SetNIFTIHeader(reader.GetNIFTIHeader())
|
||||
# this information will override the reader's header
|
||||
writer.SetQFac(reader.GetQFac())
|
||||
writer.SetTimeDimension(reader.GetTimeDimension())
|
||||
writer.SetQFormMatrix(reader.GetQFormMatrix())
|
||||
writer.SetSFormMatrix(reader.GetSFormMatrix())
|
||||
writer.Write()
|
||||
|
||||
reader2 = vtk.vtkNIFTIImageReader()
|
||||
reader2.SetFileName(outpath)
|
||||
reader2.TimeAsVectorOn()
|
||||
reader2.Update()
|
||||
|
||||
diff = vtk.vtkImageMathematics()
|
||||
diff.SetOperationToSubtract()
|
||||
diff.SetInputConnection(0,reader.GetOutputPort())
|
||||
diff.SetInputConnection(1,reader2.GetOutputPort())
|
||||
diff.Update()
|
||||
diffrange = diff.GetOutput().GetScalarRange()
|
||||
differr = diffrange[0]**2 + diffrange[1]**2
|
||||
|
||||
return differr
|
||||
|
||||
for infile, outfile in testfiles:
|
||||
err = TestReadWriteRead(infile, outfile)
|
||||
if err:
|
||||
sys.stderr.write(
|
||||
"Input " + infile + " differs from outfile " + outfile)
|
||||
sys.exit(1)
|
||||
|
||||
renWin = TestDisplay(dispfile)
|
||||
98
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestPNGTextChunks.py
Executable file
98
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestPNGTextChunks.py
Executable file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot, vtkGetTempDir
|
||||
|
||||
gotWarning = False
|
||||
gotError = False
|
||||
|
||||
def WarningCallback(obj, evt):
|
||||
global gotWarning
|
||||
gotWarning = True
|
||||
|
||||
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
VTK_TEMP_DIR = vtkGetTempDir()
|
||||
|
||||
# Image pipeline
|
||||
image1 = vtk.vtkTIFFReader()
|
||||
image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif")
|
||||
# "beach.tif" image contains ORIENTATION tag which is
|
||||
# ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF
|
||||
# reader parses this tag and sets the internal TIFF image
|
||||
# orientation accordingly. To overwrite this orientation with a vtk
|
||||
# convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke
|
||||
# SetOrientationType method with parameter value of 4.
|
||||
image1.SetOrientationType(4)
|
||||
image1.Update()
|
||||
|
||||
filename = VTK_TEMP_DIR + "/" + "pngw1.png"
|
||||
testKey = "test key"
|
||||
testValue = "test value"
|
||||
longKey = "0123456789012345678901234567890123456789"\
|
||||
"0123456789012345678901234567890123456789"
|
||||
longKeyValue = "this also prints a warning"
|
||||
|
||||
try:
|
||||
# Can we write to the directory?
|
||||
channel = open(filename, "wb")
|
||||
channel.close()
|
||||
|
||||
writer = vtk.vtkPNGWriter()
|
||||
writer.SetInputConnection(image1.GetOutputPort())
|
||||
writer.SetFileName(filename)
|
||||
writer.AddText(testKey, testValue);
|
||||
# this is fine
|
||||
writer.AddText(testKey, testValue);
|
||||
observerId = writer.AddObserver(vtk.vtkCommand.WarningEvent, WarningCallback)
|
||||
# this prints a warning and does not add the text chunk
|
||||
writer.AddText("", "this prints a warning")
|
||||
if (not gotWarning):
|
||||
print("Error: expect warning when adding a text chunk with empty key")
|
||||
gotError = True
|
||||
gotWarning = False
|
||||
# this prints a warning and add a text chunk with a truncated key
|
||||
writer.AddText(longKey, longKeyValue)
|
||||
if (not gotWarning):
|
||||
print("Error: expect warning when adding a text chunk "\
|
||||
"with key length bigger than 79 characters")
|
||||
gotError = True
|
||||
writer.RemoveObserver(observerId)
|
||||
writer.Write()
|
||||
|
||||
reader = vtk.vtkPNGReader()
|
||||
reader.SetFileName(filename);
|
||||
reader.Update();
|
||||
if (reader.GetNumberOfTextChunks() != 3):
|
||||
print("Error: Expecting three text chunks in the PNG file but got",\
|
||||
reader.GetNumberOfTextChunks())
|
||||
gotError = True
|
||||
beginEnd = [0, 0]
|
||||
reader.GetTextChunks(testKey,beginEnd)
|
||||
# the key starting with 0 comes in first.
|
||||
if (beginEnd[0] != 1 and beginEnd[1] != 3):
|
||||
print("Error: expect \"%s\" at index 1 and 2 but got "\
|
||||
"them at positions %d and %d" % (testKey, beginEnd[0], beginEnd[1]))
|
||||
gotError = True
|
||||
if (reader.GetTextKey(1) != testKey or reader.GetTextKey(2) != testKey):
|
||||
print("Error: expecting key \"%s\" at index 1 and 2 but got \"%s\"" % \
|
||||
(testKey, reader.GetTextKey(1)))
|
||||
gotError = True
|
||||
if (reader.GetTextValue(1) != testValue or reader.GetTextValue(2) != testValue):
|
||||
print("Error: expecting value \"%s\" at index 1 and 2 but got \"%s\"" % \
|
||||
(testValue, reader.GetTextValue(1)))
|
||||
gotError = True
|
||||
if (reader.GetTextKey(0) != longKey[:-1]):
|
||||
print("Error: expecting value \"%s\" at index but got \"%s\"" % \
|
||||
(longKey[:-1], reader.GetTextKey(0)))
|
||||
gotError = True
|
||||
if (gotError):
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(0)
|
||||
|
||||
except IOError:
|
||||
print("Error: Unable to test PNG write/read of text chunks.")
|
||||
sys.exit(1)
|
||||
27
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestSetFileNames.py
Executable file
27
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestSetFileNames.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
globFileNames = vtk.vtkGlobFileNames()
|
||||
globFileNames.AddFileNames(VTK_DATA_ROOT + "/Data/headsq/quarter.*[0-9]")
|
||||
|
||||
sortFileNames = vtk.vtkSortFileNames()
|
||||
sortFileNames.SetInputFileNames(globFileNames.GetFileNames())
|
||||
sortFileNames.NumericSortOn()
|
||||
|
||||
reader = vtk.vtkImageReader2()
|
||||
reader.SetFileNames(sortFileNames.GetFileNames())
|
||||
reader.SetDataExtent(0, 63, 0, 63, 1, 1)
|
||||
reader.SetDataByteOrderToLittleEndian()
|
||||
|
||||
# set Z slice to 2: if output is not numerically sorted, the wrong
|
||||
# slice will be shown
|
||||
viewer = vtk.vtkImageViewer()
|
||||
viewer.SetInputConnection(reader.GetOutputPort())
|
||||
viewer.SetZSlice(2)
|
||||
viewer.SetColorWindow(2000)
|
||||
viewer.SetColorLevel(1000)
|
||||
viewer.GetRenderer().SetBackground(0, 0, 0)
|
||||
viewer.Render()
|
||||
25
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestTIFFReader.py
Executable file
25
ParaView-5.0.1/VTK/IO/Image/Testing/Python/TestTIFFReader.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Image pipeline
|
||||
createReader = vtk.vtkImageReader2Factory()
|
||||
reader = createReader.CreateImageReader2("" + str(VTK_DATA_ROOT) + "/Data/beach.tif")
|
||||
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.tif")
|
||||
# "beach.tif" image contains ORIENTATION tag which is
|
||||
# ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF
|
||||
# reader parses this tag and sets the internal TIFF image
|
||||
# orientation accordingly. To overwrite this orientation with a vtk
|
||||
# convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke
|
||||
# SetOrientationType method with parameter value of 4.
|
||||
reader.SetOrientationType(4)
|
||||
viewer = vtk.vtkImageViewer()
|
||||
viewer.SetInputConnection(reader.GetOutputPort())
|
||||
viewer.SetColorWindow(256)
|
||||
viewer.SetColorLevel(127.5)
|
||||
#make interface
|
||||
viewer.Render()
|
||||
reader.UnRegister(viewer) # not needed in python
|
||||
# --- end of script --
|
||||
101
ParaView-5.0.1/VTK/IO/Image/Testing/Python/dem.py
Executable file
101
ParaView-5.0.1/VTK/IO/Image/Testing/Python/dem.py
Executable file
@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python
|
||||
import vtk
|
||||
from vtk.test import Testing
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Create the RenderWindow, Renderer and both Actors
|
||||
#
|
||||
ren1 = vtk.vtkRenderer()
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren1)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
|
||||
Scale = 5
|
||||
|
||||
lut = vtk.vtkLookupTable()
|
||||
lut.SetHueRange(0.6, 0)
|
||||
lut.SetSaturationRange(1.0, 0)
|
||||
lut.SetValueRange(0.5, 1.0)
|
||||
|
||||
demModel = vtk.vtkDEMReader()
|
||||
demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
|
||||
demModel.Update()
|
||||
|
||||
lo = Scale * demModel.GetElevationBounds()[0]
|
||||
hi = Scale * demModel.GetElevationBounds()[1]
|
||||
demActor = vtk.vtkLODActor()
|
||||
|
||||
# create a pipeline for each lod mapper
|
||||
lods = ["4", "8", "16"]
|
||||
for lod in lods:
|
||||
exec("shrink" + lod + " = vtk.vtkImageShrink3D()")
|
||||
eval("shrink" + lod).SetShrinkFactors(int(lod), int(lod), 1)
|
||||
eval("shrink" + lod).SetInputConnection(demModel.GetOutputPort())
|
||||
eval("shrink" + lod).AveragingOn()
|
||||
|
||||
exec("geom" + lod + " = vtk.vtkImageDataGeometryFilter()")
|
||||
eval("geom" + lod).SetInputConnection(eval("shrink" + lod).GetOutputPort())
|
||||
eval("geom" + lod).ReleaseDataFlagOn()
|
||||
|
||||
exec("warp" + lod + " = vtk.vtkWarpScalar()")
|
||||
eval("warp" + lod).SetInputConnection(eval("geom" + lod).GetOutputPort())
|
||||
eval("warp" + lod).SetNormal(0, 0, 1)
|
||||
eval("warp" + lod).UseNormalOn()
|
||||
eval("warp" + lod).SetScaleFactor(Scale)
|
||||
eval("warp" + lod).ReleaseDataFlagOn()
|
||||
|
||||
exec("elevation" + lod + " = vtk.vtkElevationFilter()")
|
||||
eval("elevation" + lod).SetInputConnection(
|
||||
eval("warp" + lod).GetOutputPort())
|
||||
eval("elevation" + lod).SetLowPoint(0, 0, lo)
|
||||
eval("elevation" + lod).SetHighPoint(0, 0, hi)
|
||||
eval("elevation" + lod).SetScalarRange(lo, hi)
|
||||
eval("elevation" + lod).ReleaseDataFlagOn()
|
||||
|
||||
exec("toPoly" + lod + " = vtk.vtkCastToConcrete()")
|
||||
eval("toPoly" + lod).SetInputConnection(
|
||||
eval("elevation" + lod).GetOutputPort())
|
||||
|
||||
exec("normals" + lod + " = vtk.vtkPolyDataNormals()")
|
||||
eval("normals" + lod).SetInputConnection(
|
||||
eval("toPoly" + lod).GetOutputPort())
|
||||
eval("normals" + lod).SetFeatureAngle(60)
|
||||
eval("normals" + lod).ConsistencyOff()
|
||||
eval("normals" + lod).SplittingOff()
|
||||
eval("normals" + lod).ReleaseDataFlagOn()
|
||||
|
||||
exec("demMapper" + lod + " = vtk.vtkPolyDataMapper()")
|
||||
eval("demMapper" + lod).SetInputConnection(
|
||||
eval("normals" + lod).GetOutputPort())
|
||||
eval("demMapper" + lod).SetScalarRange(lo, hi)
|
||||
eval("demMapper" + lod).SetLookupTable(lut)
|
||||
eval("demMapper" + lod).ImmediateModeRenderingOn()
|
||||
eval("demMapper" + lod).Update()
|
||||
|
||||
demActor.AddLODMapper(eval("demMapper" + lod))
|
||||
|
||||
# Add the actors to the renderer, set the background and size
|
||||
#
|
||||
ren1.AddActor(demActor)
|
||||
ren1.SetBackground(.4, .4, .4)
|
||||
iren.SetDesiredUpdateRate(1)
|
||||
|
||||
def TkCheckAbort (object_binding, event_name):
|
||||
foo = renWin.GetEventPending()
|
||||
if (foo != 0):
|
||||
renWin.SetAbortRender(1)
|
||||
|
||||
renWin.AddObserver("AbortCheckEvent", TkCheckAbort)
|
||||
|
||||
ren1.GetActiveCamera().SetViewUp(0, 0, 1)
|
||||
ren1.GetActiveCamera().SetPosition(-99900, -21354, 131801)
|
||||
ren1.GetActiveCamera().SetFocalPoint(41461, 41461, 2815)
|
||||
ren1.ResetCamera()
|
||||
ren1.GetActiveCamera().Dolly(1.2)
|
||||
ren1.ResetCameraClippingRange()
|
||||
|
||||
renWin.Render()
|
||||
|
||||
#iren.Start()
|
||||
Reference in New Issue
Block a user