Lack of precision ImageData finding procedures
Odet Christophe
christophe.odet at creatis.insa-lyon.fr
Fri May 19 03:40:38 EDT 2000
I think that there is a problem with the function vtkImageData::ComputeStructuredCoordinates
because the
ijk[i] = (int) floatLoc
statement rounds towards zero the floatLoc value. When the floatLoc equals -0.5, for example,
it is rounded to 0 and the x point seems to belongs to the cell beginning at point 0,0,0. The
problem arises when dealing with x values greater or lower than than the extent.
I suggest to change some reference to ijk[i] with floatLoc in the code lines:
######### OLD CODE
if ( ijk[i] >= this->Extent[i*2] && ijk[i] < this->Extent[i*2 + 1] )
{
pcoords[i] = floatLoc - (float)ijk[i];
}
else if ( ijk[i] < this->Extent[i*2] || ijk[i] > this->Extent[i*2+1] )
{
return 0;
}
########## END OF OLD CODE
to obtain
######### NEW PROPOSED CODE
if ( floatLoc >= this->Extent[i*2] && floatLoc < this->Extent[i*2 + 1] )
{
pcoords[i] = floatLoc - (float)ijk[i];
}
else if ( floatLoc < this->Extent[i*2] || floatLoc > this->Extent[i*2+1] )
{
return 0;
}
########## END OF NEW CODE
It test the patch with the following little tcl/tk script and it seems to work well. The dataset implicit
clipping is more precise with the new code (this is visible with small objects as used in the script).
In the original version a too large piece of the sphere is selected. In the new version, only some
part of the cells clipped by the dataset are selected. I hope this will help, but I think that the same problem
could appear in some other functions of the VTK library (FindCells, FindPoints....).
##########
# Object to be cut. A simple little sphere
vtkSphereSource sphe
sphe SetRadius 2
vtkPolyDataMapper spheMapper
spheMapper SetInput [sphe GetOutput]
spheMapper ScalarVisibilityOff
vtkActor spheActor
spheActor SetMapper spheMapper
# The cutter... a simple parallelogram
vtkStructuredPoints sp
sp SetDimensions 2 2 2
sp SetSpacing 5 0.1 2
sp AllocateScalars
set spsc [[sp GetPointData] GetScalars]
for {set i 0} {$i<8} { incr i } {
$spsc SetScalar $i 1
}
vtkDataSetMapper spMapper
spMapper SetInput sp
vtkActor spActor
spActor SetMapper spMapper
vtkImplicitVolume spds
spds SetVolume sp
spds SetOutValue 0
spds SetOutGradient 1 0 0
# Cutting...
vtkClipPolyData clipper
clipper SetInput [sphe GetOutput]
clipper SetClipFunction spds
clipper GenerateClipScalarsOn
clipper SetValue 0.5
vtkPolyDataMapper clipMapper
clipMapper SetInput [clipper GetOutput]
vtkActor clipActor
clipActor SetMapper clipMapper
# Create graphics stuff
#
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
# Add the actors to the renderer, set the background and size
ren1 AddActor spheActor
[spheActor GetProperty] SetRepresentationToWireframe
ren1 AddActor spActor
#spActor AddPosition -3 0 0
ren1 AddActor clipActor
#clipActor AddPosition 0 3 0
ren1 SetBackground 0 0 0
[ren1 GetActiveCamera] Azimuth 30
[ren1 GetActiveCamera] Elevation 30
[ren1 GetActiveCamera] Dolly 1.5
ren1 ResetCameraClippingRange
renWin SetSize 400 400
iren Initialize
# render the image
#
iren SetUserMethod {wm deiconify .vtkInteract}
scale .c
proc toto { val } { clipper SetValue $val; renWin Render }
pack .c
.c configure -from 0 -to 1 -resolution 0.1 -command toto
.c set 0.5
--
********************************************************************
ODET Christophe
CREATIS, INSA 502, F-69621 Villeurbanne cedex (France)
tel 04 72 43 85 62
Fax 04 72 43 85 26
Email: christophe.odet at creatis.insa-lyon.fr
URL :http://www.creatis.insa-lyon.fr
********************************************************************
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------
More information about the vtkusers
mailing list