[Insight-users] Cylinder SpatialObject & Image.

Julien Jomier julien.jomier at kitware.com
Thu Aug 28 22:43:14 EDT 2008


Hi Kent,

Could you try to change the line:

    cylinder->ComputeObjectToWorldTransform();

by

    cylinder->ComputeObjectToParentTransform();

If you set the ObjectToWorldTransform, you should recompute the 
ObjectToParentTransform and vice versa.

Julien

kent williams wrote:
> We want to highlight a cylinder centered on a particular location in a
> 3D volume.  I've written the function given below to do this.  As it
> stands, it looks as though setting the offset in the transform doesn't
> work -- the cylinder shows up in only the last slice in the lower left
> corner of the view, i.e. 0,0 in voxel space.  It should be somewhere
> near the center of the image.
> 
> Apparently, something is screwy -- either the SpatialObject's IsInside
> function isn't taking the ObjectToWorld tranform into account, or the
> itk::OrientedImage::TransformIndexToPhysicalPoint doesn't the work as
> I think it should.
> 
> Any ideas what I'm doing wrong?
> 
> typedef itk::OrientedImage<short,3> SImageType;
> typedef itk::RGBPixel<unsigned char> RGBPixelType;
> typedef itk::Image<RGBPixelType,3> RGBImageType;
> 
> RGBImageType::Pointer
> MakeBrandedDebugImage(SImageType::Pointer &in,
>                       acpcmodelDefinition &mDef,
>                       const PointType &pt,
>                       double height,radius,
>                       const char *fname)
> {
>   itk::CylinderSpatialObject::Pointer cylinder =
>     itk::CylinderSpatialObject::New();
>   cylinder->SetHeight(mDef.GetRPHeight());
>   cylinder->SetRadius(mDef.GetRPRadius());
>   cylinder->SetHeight(height);
>   cylinder->SetRadius(radius);
> 
>   itk::CylinderSpatialObject::TransformType::OutputVectorType v;
>   v[0] = pt[0]; v[1] = pt[1]; v[2] = pt[2];
>   cylinder->GetObjectToWorldTransform()->SetOffset(v);
>   cylinder->ComputeObjectToWorldTransform();
> 
>   RGBImageType::Pointer rgbImage =
>     itkUtil::AllocateImageFromRegionAndSpacing<SImageType,RGBImageType>
>     (in->GetLargestPossibleRegion(),in->GetSpacing());
>   rgbImage->SetDirection(in->GetDirection());
>   rgbImage->SetOrigin(in->GetOrigin());
> 
>   itk::ImageRegionIterator<RGBImageType>
>     rgbIt(rgbImage,rgbImage->GetLargestPossibleRegion());
>   itk::ImageRegionIterator<SImageType>
>     sIt(in,in->GetLargestPossibleRegion());
> 
>   for(;!sIt.IsAtEnd(); ++rgbIt,++sIt)
>     {
>     SImageType::IndexType index = sIt.GetIndex();
>     SImageType::PointType p;
>     in->TransformIndexToPhysicalPoint(index,p);
>     RGBPixelType pixel;
>     unsigned char charVal(ShortToUChar(sIt.Value(),minPixel,maxPixel));
>     if(cylinder->IsInside(p))
>       {
>       pixel.SetRed(255);
>       }
>     else
>       {
>       pixel.SetRed(charVal);
>       }
>     pixel.SetGreen(charVal);
>     pixel.SetBlue(charVal);
>     rgbIt.Set(pixel);
>     }
>   return rgbImage;
> }
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list