Commit 945bbdea authored by David Gobbi's avatar David Gobbi

BUG: Fix bugs in vtkMNIObjectWriter, vtkMNITransformReader.

Fix the polyline output in vtkMNIObjectWriter, and fix a NAN
error (log of zero) in the vtkMNITransformReader.  Improve
test coverage.
parent 8ce80261
......@@ -37,6 +37,7 @@ IF (VTK_USE_RENDERING AND VTK_USE_DISPLAY)
#TestICPTransform --complex arrays
TestImageStencilWithPolydata
TestMNIObjects
TestMNITransforms
TestPCA
TestProcrustes
TestProjectedTerrainPath
......
......@@ -35,6 +35,7 @@ IF (VTK_USE_RENDERING AND VTK_USE_DISPLAY)
TestICPTransform
TestImageStencilWithPolydata
TestMNIObjects
TestMNITransforms
TestPCA
TestProcrustes
TestProcrustesRigidCentroid
......
......@@ -9,43 +9,114 @@ if {[info commands "rtTester"] == "rtTester"} {
set dir [rtTester GetTempDirectory]
}
vtkRenderer ren
vtkRenderer ren1
ren1 SetViewport 0 0 0.33 1
vtkRenderer ren2
ren2 SetViewport 0.33 0 0.67 1
vtkRenderer ren3
ren3 SetViewport 0.67 0 1 1
vtkRenderWindow renWin
renWin AddRenderer ren
renWin SetSize 600 200
renWin AddRenderer ren1
renWin AddRenderer ren2
renWin AddRenderer ren3
vtkProperty property1
property1 SetDiffuseColor 0.95 0.90 0.70
vtkProperty property0
property0 SetDiffuseColor 0.95 0.90 0.70
vtkMNIObjectReader reader1
reader1 SetFileName "$VTK_DATA_ROOT/Data/mni-surface-mesh.obj"
#reader1 SetFileName "coloured_object.obj"
vtkMNIObjectReader asciiReader
asciiReader SetFileName "$VTK_DATA_ROOT/Data/mni-surface-mesh.obj"
set property1 [asciiReader GetProperty]
vtkMNIObjectWriter writer
writer SetInputConnection [reader1 GetOutputPort]
writer SetFileName "$dir/mni-surface-mesh-binary.obj"
writer SetProperty property1
writer SetFileTypeToBinary
writer Write
# this is just to remove the normals, to increase coverage,
# i.e. by forcing the writer to generate normals
vtkClipClosedSurface removeNormals
removeNormals SetInputConnection [asciiReader GetOutputPort]
vtkMNIObjectReader reader
reader SetFileName "$dir/mni-surface-mesh-binary.obj"
set property [reader GetProperty]
# this is to make triangle strips, also to increase coverage,
# because it forces the writer to decompose the strips
vtkStripper stripper
stripper SetInputConnection [removeNormals GetOutputPort]
vtkDataSetMapper mapper
mapper SetInputConnection [reader GetOutputPort]
# test binary writing and reading for polygons
vtkMNIObjectWriter binaryWriter
binaryWriter SetInputConnection [stripper GetOutputPort]
binaryWriter SetFileName "$dir/mni-surface-mesh-binary.obj"
binaryWriter SetProperty property0
binaryWriter SetFileTypeToBinary
binaryWriter Write
vtkActor actor
actor SetMapper mapper
actor SetProperty $property
vtkMNIObjectReader binaryReader
binaryReader SetFileName "$dir/mni-surface-mesh-binary.obj"
set property2 [binaryReader GetProperty]
ren AddActor actor
# make a polyline object with color scalars
vtkCurvatures scalars
scalars SetInputConnection [asciiReader GetOutputPort]
vtkLookupTable colors
colors SetRange -14.5104 29.0208
colors SetAlphaRange 1.0 1.0
colors SetSaturationRange 1.0 1.0
colors SetValueRange 1.0 1.0
colors SetHueRange 0.0 1.0
colors Build
vtkExtractEdges edges
edges SetInputConnection [scalars GetOutputPort]
# test ascii writing and reading for lines
vtkMNIObjectWriter lineWriter
lineWriter SetLookupTable colors
lineWriter SetInputConnection [edges GetOutputPort]
lineWriter SetFileName "$dir/mni-wire-mesh-ascii.obj"
lineWriter Write
vtkMNIObjectReader lineReader
lineReader SetFileName "$dir/mni-wire-mesh-ascii.obj"
# display all the results
vtkDataSetMapper mapper1
mapper1 SetInputConnection [asciiReader GetOutputPort]
vtkDataSetMapper mapper2
mapper2 SetInputConnection [binaryReader GetOutputPort]
vtkDataSetMapper mapper3
mapper3 SetInputConnection [lineReader GetOutputPort]
vtkActor actor1
actor1 SetMapper mapper1
actor1 SetProperty $property1
vtkActor actor2
actor2 SetMapper mapper2
actor2 SetProperty $property2
vtkActor actor3
actor3 SetMapper mapper3
ren1 AddActor actor1
ren2 AddActor actor2
ren3 AddActor actor3
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
ren ResetCamera
[ren GetActiveCamera] Dolly 0.0
ren ResetCameraClippingRange
ren1 ResetCamera
[ren1 GetActiveCamera] Dolly 1.2
ren1 ResetCameraClippingRange
ren2 ResetCamera
[ren2 GetActiveCamera] Dolly 1.2
ren2 ResetCameraClippingRange
ren3 ResetCamera
[ren3 GetActiveCamera] Dolly 1.2
ren3 ResetCameraClippingRange
iren Render
# render the image
#
......
package require vtk
#
# write to the temp directory if possible, otherwise use .
#
set dir "."
if {[info commands "rtTester"] == "rtTester"} {
set dir [rtTester GetTempDirectory]
}
# first, create an image to warp
vtkImageGridSource imageGrid
imageGrid SetGridSpacing 16 16 0
imageGrid SetGridOrigin 0 0 0
imageGrid SetDataExtent 0 255 0 255 0 0
imageGrid SetDataScalarTypeToUnsignedChar
vtkLookupTable table
table SetTableRange 0 1
table SetValueRange 1.0 0.0
table SetSaturationRange 0.0 0.0
table SetHueRange 0.0 0.0
table SetAlphaRange 0.0 1.0
table Build
vtkImageMapToColors alpha
alpha SetInputConnection [imageGrid GetOutputPort]
alpha SetLookupTable table
vtkBMPReader reader1
reader1 SetFileName "$VTK_DATA_ROOT/Data/masonry.bmp"
vtkImageBlend blend
blend AddInput [reader1 GetOutput]
blend AddInput [alpha GetOutput]
# next, create a ThinPlateSpline transform
vtkPoints p1
p1 SetNumberOfPoints 8
p1 SetPoint 0 0 0 0
p1 SetPoint 1 0 255 0
p1 SetPoint 2 255 0 0
p1 SetPoint 3 255 255 0
p1 SetPoint 4 96 96 0
p1 SetPoint 5 96 159 0
p1 SetPoint 6 159 159 0
p1 SetPoint 7 159 96 0
vtkPoints p2
p2 SetNumberOfPoints 8
p2 SetPoint 0 0 0 0
p2 SetPoint 1 0 255 0
p2 SetPoint 2 255 0 0
p2 SetPoint 3 255 255 0
p2 SetPoint 4 96 159 0
p2 SetPoint 5 159 159 0
p2 SetPoint 6 159 96 0
p2 SetPoint 7 96 96 0
vtkThinPlateSplineTransform thinPlate0
thinPlate0 SetSourceLandmarks p1
thinPlate0 SetTargetLandmarks p2
thinPlate0 SetBasisToR2LogR
# write the tps to a file
vtkMNITransformWriter tpsWriter
tpsWriter SetFileName "$dir/mni-thinplatespline.xfm"
tpsWriter SetTransform thinPlate0
tpsWriter Write
# read it back
vtkMNITransformReader tpsReader
tpsReader SetFileName "$dir/mni-thinplatespline.xfm"
set thinPlate [tpsReader GetTransform]
# make a linear transform
vtkTransform linearTransform
linearTransform PostMultiply
linearTransform Translate -127.5 -127.5 0
linearTransform RotateZ 30
linearTransform Translate +127.5 +127.5 0
# remove the linear part of the thin plate
vtkGeneralTransform tpsGeneral
tpsGeneral SetInput $thinPlate
tpsGeneral PreMultiply
tpsGeneral Concatenate [[linearTransform GetInverse] GetMatrix]
# convert the thin plate spline into a grid
vtkTransformToGrid transformToGrid
transformToGrid SetInput tpsGeneral
transformToGrid SetGridSpacing 16 16 1
transformToGrid SetGridOrigin -64.5 -64.5 0
transformToGrid SetGridExtent 0 24 0 24 0 0
vtkGridTransform gridTransform
gridTransform SetDisplacementGrid [transformToGrid GetOutput]
gridTransform SetInterpolationModeToCubic
# add back the linear part
vtkGeneralTransform gridGeneral
gridGeneral SetInput gridTransform
gridGeneral PreMultiply
gridGeneral Concatenate [linearTransform GetMatrix]
# invert for reslice
gridGeneral Inverse
# write to a file
vtkMNITransformWriter gridWriter
gridWriter SetFileName "$dir/mni-grid.xfm"
gridWriter SetComments "TestMNITransforms output transform"
gridWriter SetTransform gridGeneral
gridWriter Write
# read it back
vtkMNITransformReader gridReader
gridReader SetFileName "$dir/mni-grid.xfm"
set transform [gridReader GetTransform]
# apply the grid warp to the image
vtkImageReslice reslice
reslice SetInputConnection [blend GetOutputPort]
reslice SetResliceTransform $transform
reslice SetInterpolationModeToLinear
# set the window/level to 255.0/127.5 to view full range
vtkImageViewer viewer
viewer SetInputConnection [reslice GetOutputPort]
viewer SetColorWindow 255.0
viewer SetColorLevel 127.5
viewer SetZSlice 0
viewer Render
......@@ -831,7 +831,7 @@ int vtkMNIObjectWriter::WriteLineObject(vtkPolyData *output)
}
// Write the cells
if (this->WriteCells(output, VTK_POLYGON) == 0)
if (this->WriteCells(output, VTK_POLY_LINE) == 0)
{
return 0;
}
......
......@@ -646,7 +646,7 @@ int vtkMNITransformReader::ReadThinPlateSplineTransform(
double dy = p[1] - q[j][1];
double dz = p[2] - q[j][2];
double r = sqrt(dx*dx + dy*dy + dz*dz);
double U = (numDimensions == 2 ? r*r*log(r) : r);
double U = ((numDimensions == 2 && r != 0) ? r*r*log(r) : r);
x += U*W[j][0];
y += U*W[j][1];
z += U*W[j][2];
......
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