[vtkusers] vtkusers Digest, Vol 75, Issue 22

6dgis at 163.com 6dgis at 163.com
Thu Jul 15 14:19:00 EDT 2010


Hi David, 

	Thanks a lot!

	The following is basic code of volume rendering. Could you point out where to add 
vtkImageStencil? And what kind of color transfer function should be given to make black 
voxels appear to be transparent?  Could you give me some sample code for explaining
in detail? 

	vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
	reader->SetDataScalarTypeToShort();
	reader->SetDirectoryName(name);
	reader->Update();

	// Create a transfer function mapping scalar value to opacity
	vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
	oTFun->AddSegment(...);

	// Create a transfer function mapping scalar value to color (color)
	vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();
	cTFun->AddRGBPoint(...);

	vtkVolumeProperty *prop;
	prop = vtkVolumeProperty::New();
	prop->SetColor( cTFun );
	prop->SetScalarOpacity(oTFun);
	prop->SetInterpolationTypeToLinear();
	        
	// Create compositing ray functions
	vtkVolumeRayCastCompositeFunction *compositeFunction1 = 
	vtkVolumeRayCastCompositeFunction::New();
	compositeFunction1->SetCompositeMethodToInterpolateFirst();

	vtkFiniteDifferenceGradientEstimator *gradest = 
	vtkFiniteDifferenceGradientEstimator::New();

	pvtkVolumeMapper->SetInput(reader->GetOutput());
	pvtkVolumeMapper->SetGradientEstimator(gradest);
	pvtkVolumeMapper->SetVolumeRayCastFunction( compositeFunction1);
	
	this->pvtkVolume->SetMapper( pvtkVolumeMapper );
	this->pvtkVolume->SetProperty( prop );
	
	this->pvtkRenderer->AddActor(this->pvtkVolume);

	this->pvtkRenderer->ResetCamera();
	this->pvtkMFCWindow->GetRenderWindow()->Render();

Best Regards!
------------------				 
6dgis at 163.com
2010-07-16

-------------------------------------------------------------
FROM:David Gobbi
DATE:2010-07-16 01:48:01
TO:6dgis at 163.com
CC:vtkusers
SUBJECT:Re: vtkusers Digest, Vol 75, Issue 22

Yes, you can do that.  Just reverse the stencil, and apply it to the
image before you volume-render it.  You can also use a stencil with
vtkImageReslice (i.e. instead of vtkImageStencil) if you need to
resample the volume before rendering it.

The thing to watch out for is that this will only make the
outside-stencil parts black, it won't make them transparent.  So you
still need a color transfer function that will make black voxels
appear to be transparent when you render them.

   David


2010/7/15 6dgis at 163.com <6dgis at 163.com>:
> Hi david,
>
> I am not sure that the following problem is same as this subject
>
>        "I have a series of CT Images and render them in Volume by
>  vtkVolumeRayCastMapper. Now given a polygon by user clicking
>  on the screen, how to clip the volume with the inner objects removed?
>  I just want the "hole" effect for displaying."
>
> BTW, after rotating the scene, I want the hole also exist. Could I use
> vtkImageStencil to reach the  goal? Thanks in advance.
>
> Best Regards!
> ------------------
> 6dgis at 163.com
> 2010-07-16
>
> Date: Wed, 14 Jul 2010 16:31:13 -0600
> From: David Gobbi <david.gobbi at gmail.com>
> Subject: Re: [vtkusers] best way to clip vtkImageData using
>        vtkPloyData
> To: Prathamesh Kulkarni <prathameshmkulkarni at gmail.com>
> Cc: VTK Mailing List <vtkusers at vtk.org>
> Message-ID:
>        <AANLkTilNAcpAgK_gWTrZapFYogkvbmD6RgnoMRgjeQMn at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Prathamesh,
>
> You should use either vtkClipVolume or vtkImageStencil, based on what
> you want as an output. The vtkClipVolume filter will output an
> unstructured grid, i.e. it will produce a geometric data set
> consisting of voxel cells (each voxel cell will be a little cube with
> eight points at its corners).  If you want the output to be an actual
> image, with the background set to black or to transparent, then you
> should use vtkImageStencil.
>
> In either case, the best place to start is vtkImplicitLoop, which
> takes a contour and produces an "implicit function", which in
> VTK-speak, is a function used to define the inside vs. the outside of
> a selection area.  Then the vtkImplicitLoop can be used as an input to
> vtkImplicitFunctionToImageStencil.  The output of
> vtkImplicitFunctionToImageStencil can then be used as an input to e.g.
> vtkImageBlend (for pasting a cut-out image onto another image),
> vtkImageStencil (for blacking out the non-selected region of the
> image), or vtkImageAccumulate (for computing the average value,
> standard deviation, or the histogram of the image area inside the
> stencil).
>
>   David
>
>
>
>
> On Wed, Jul 14, 2010 at 4:13 PM, Prathamesh Kulkarni
> <prathameshmkulkarni at gmail.com> wrote:
>>
>> Hello all,
>>
>> I want to extract a sub-image from vtkImageData given a closed set of points
>> forming any arbitrary shape (may be a vtkPolyData).
>>
>> I have been looking at vtk classes like vtkClipVolume, vtkExtractVOI,
>> vtkImageStencil. I am no able to understand which way should be preferred
>> over which to do my task. Also, I am not able to figure out the exact
>> pipeline structure for these clipping methods.
>>
>> Could someone please throw some light on this?
>>
>> Thanks,
>> Prathamesh
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
>
> ------------------------------
>
> _______________________________________________
> vtkusers mailing list
> vtkusers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> End of vtkusers Digest, Vol 75, Issue 22
> ****************************************
>
>
>


More information about the vtkusers mailing list