[Insight-users] TubeSpatialObject in groups

Gavin Baker gavinb+xtk at cs.mu.OZ.AU
Tue, 20 Jan 2004 15:30:39 +1100


--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hello,

On Tue, Jan 06, 2004 at 09:27:29AM -0500, Luis Ibanez wrote:
> 
> It seems that an attachement with source code
> is missing from your previous email.
> 
> Could you please send the message again ?

Oops - sorry about that.  I just got back from Linux.conf.au 2004, and
didn't realise I missed the attachment.  Take II...

I notice that Julien already fixed the problem, but I have included the test
below anyway, FWIW.

Julien: Thanks for the fix!  I will grab it out of CVS.

Regards,

  :: Gavin

-- 
Gavin Baker                                      Complex Systems Group
http://www.cs.mu.oz.au/~gavinb             The University of Melbourne

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gte.cxx"

#include <itkEllipseSpatialObject.h>
#include <itkSpatialObjectToImageFilter.h>
#include <itkImageFileWriter.h>
#include <itkGroupSpatialObject.h>
#include <itkTubeSpatialObject.h>

#include <iostream>

int main( int argc, char* argv[] )
{
    // Types

    typedef itk::EllipseSpatialObject<3>        EllipseType;
    typedef itk::GroupSpatialObject<3>          GroupType;
    typedef itk::TubeSpatialObject<3>           TubeType;
    typedef itk::TubeSpatialObjectPoint<3>      TubePointType;
    typedef TubePointType::CovariantVectorType  VectorType;
    typedef itk::Image<float,3>                 ImageType;
    typedef itk::ImageFileWriter<ImageType>     WriterType;
    typedef itk::SpatialObjectToImageFilter<
        GroupType,
        ImageType>                              SpatialFilterType;

    // Ellipses

    EllipseType::Pointer ellipse1 = EllipseType::New();
    EllipseType::Pointer ellipse2 = EllipseType::New();
    EllipseType::Pointer ellipse3 = EllipseType::New();

    ellipse1->SetRadius(5);
    ellipse2->SetRadius(5);
    ellipse3->SetRadius(5);

    EllipseType::TransformType::OffsetType offset;

    offset[0] = 40;
    offset[1] = 20;
    offset[2] = 20;

    ellipse1->GetObjectToParentTransform()->SetOffset( offset );
    ellipse1->ComputeObjectToWorldTransform();

    offset[0] = 20;
    offset[1] = 40;
    offset[2] = 20;

    ellipse2->GetObjectToParentTransform()->SetOffset( offset );
    ellipse2->ComputeObjectToWorldTransform();

    offset[0] = 10;
    offset[1] = 40;
    offset[2] = 20;

    ellipse3->GetObjectToParentTransform()->SetOffset( offset );
    ellipse3->ComputeObjectToWorldTransform();

    // Tube

    TubeType::Pointer tube = TubeType::New();
    TubeType::PointListType list;

    VectorType norm1;
    VectorType norm2;
    for ( unsigned j = 0; j < 3; j++ )
    {
        norm1[j] = j;
        norm2[j] = j*2;
    }

    double x1 = 20, y1 = 20, z1 = 0;
    double x2 = 20, y2 = 20, z2 = 50;

    double res = 50;

    for ( int i=0; i < res; i++ )
    {
        double x = x1+i/res*(x2-x1);
        double y = y1+i/res*(y2-y1);
        double z = z1+i/res*(z2-z1);

        TubePointType p;
        p.SetNormal1( norm1 );
        p.SetNormal2( norm2 );
        p.SetRadius( 5 );
        p.SetPosition( x, y, z );

        // std::cout << x << ',' << y << ',' << z << std::endl;

        list.push_back( p );
    }
    tube->SetPoints( list );
    tube->ComputeTangentAndNormals();

    std::cout
        << "\nMTime (before ComputeBB): "
        << "\nEllipse1:\t" << ellipse1->GetMTime()
        << "\nEllipse2:\t" << ellipse2->GetMTime()
        << "\nEllipse3:\t" << ellipse3->GetMTime()
        << "\nTube:\t\t"   << tube->GetMTime()
        << std::endl;

    // If any junk is supplied on the command line, do this...
    if ( argc > 1 )
    {
        tube->ComputeBoundingBox();

        std::cout
            << "\nMTime (after ComputeBB): "
            << "\nEllipse1:\t" << ellipse1->GetMTime()
            << "\nEllipse2:\t" << ellipse2->GetMTime()
            << "\nEllipse3:\t" << ellipse3->GetMTime()
            << "\nTube:\t\t"   << tube->GetMTime()
            << std::endl;
    }

    // Group

    GroupType::Pointer group = GroupType::New();

    std::cout
        << "\nMTime (after group create): "
        << "\nEllipse1:\t" << ellipse1->GetMTime()
        << "\nEllipse2:\t" << ellipse2->GetMTime()
        << "\nEllipse3:\t" << ellipse3->GetMTime()
        << "\nTube:\t\t"   << tube->GetMTime()
        << "\nGroup:\t\t"  << group->GetMTime()
        << std::endl;

    group->AddSpatialObject( ellipse1 );
    group->AddSpatialObject( ellipse2 );
    group->AddSpatialObject( ellipse3 );
    group->AddSpatialObject( tube );

    std::cout
        << "\nMTime (after add to group): "
        << "\nEllipse1:\t" << ellipse1->GetMTime()
        << "\nEllipse2:\t" << ellipse2->GetMTime()
        << "\nEllipse3:\t" << ellipse3->GetMTime()
        << "\nTube:\t\t"   << tube->GetMTime()
        << "\nGroup:\t\t"  << group->GetMTime()
        << std::endl;

    // Spatial Filter

    SpatialFilterType::Pointer filter = SpatialFilterType::New();

    filter->SetInsideValue( 100 );
    filter->SetInput( group );

    ImageType::SizeType size;
    size[0] = 50;
    size[1] = 50;
    size[2] = 50;

    filter->SetSize( size );

    // Writer

    WriterType::Pointer writer = WriterType::New();

    writer->SetInput( filter->GetOutput() );

    writer->SetFileName( "gte.mhd" );
    writer->Update();

    return 0;
}

--x+6KMIRAuhnl3hBn--