<br>Hi Somi,<br><br><br>The problem is that a Mesh Spatial object assumes<br>that &quot;inside&quot; means: <br><br>          &quot;in the 2D manifold of its surface&quot;<br><br>So, the points of space that are &quot;inside&quot; your mesh<br>
are the ones &quot;close enough to the mesh surface&quot;.<br><br><br>If you look at the source code implementation of this<br>class, the test is done by checking whether a given<br>point is inside any of the triangles of the Mesh.<br>
<br><br>--<br><br><br>You probably should use the itkEllipseSpatialObject<br>along with the SpatialObjectToImageFilter<br><br>as illustrated in the example:<br><br>     Insight/Examples/Filtering/<br>                     SpatialObjectToImage1.cxx<br>
<br><br>This example shows you how to generate a rasterized<br>Sphere.  (you probably would like to remove the cylinder<br>that is also used in that source code example).<br><br><br><br>    Regards,<br><br><br>          Luis<br>
<br><br>-------------------------------------------------------------------------<br><div class="gmail_quote">On Thu, Apr 8, 2010 at 6:32 PM, somi <span dir="ltr">&lt;<a href="mailto:seesomi@gmail.com">seesomi@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Luis,<br>Thanks for your reply.   itkTubeSpatialObject worked for me, I feed stupid not to think of this before :)<br>
I took the following approach:<br>vtkConeSource-&gt;VtkPolyData -&gt; ITKMesh -&gt; ITKMeshSpatialObject-&gt;ITKSpatialObjectToImage<br>
<br>While working on this I got an unexpected behavior as described below:<br>I used the follow pipeline:<br><br>vtkShrereSource-&gt;VtkPolyData -&gt; ITKMesh -&gt; ITKMeshSpatialObject-&gt;ITKSpatialObjectToImage<br>
<br><br>I expected to get a solid spherical object in the final image, but I got a hollow sphere (see attached screenshot).<br>Is this expected behavior ?<br><br>I used the following code:<br>///////<br>//Code Starts<br>

////<br>#include &lt;iostream&gt;<br>#include &lt;iomanip&gt;<br>#include &lt;itkBinaryMask3DMeshSource.h&gt;<br>#include &lt;itkMesh.h&gt;<br>#include &lt;itkMeshSpatialObject.h&gt;<br>#include &lt;vtkPolyData.h&gt;<br>
#include &lt;vtkCellArray.h&gt;<br>
#include &lt;vtkSphereSource.h&gt;<br>#include &lt;vtkCellLinks.h&gt;<br>#include &lt;itkImage.h&gt;<br><br>#include &lt;iostream&gt;<br>#include &lt;iomanip&gt;<br>#include &lt;vtkSmartPointer.h&gt;<br>#include &lt;itkSpatialObjectToImageFilter.h&gt;<br>

#include &lt;itkImageFileWriter.h&gt;<br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#ifdef __BORLANDC__<br>#define ITK_LEAN_AND_MEAN<br>#endif<br><br><br><br><br>int main( int argc, char *argv[] )<br>

{<br><br>    // Generate a Sphere in VTK<br>    vtkSmartPointer&lt;vtkSphereSource&gt; polyData = vtkSmartPointer&lt;vtkSphereSource&gt;::New();<br>    polyData-&gt;SetRadius(10);<br>    polyData-&gt;SetThetaResolution(10);<br>

    polyData-&gt;SetPhiResolution(10);<br>    polyData-&gt;SetCenter(80,50,50);<br>    polyData-&gt;Update();<br><br>#ifndef vtkFloatingPointType<br>#define vtkFloatingPointType float<br>#endif<br><br><br><br>    //<br>    // Convert VTK polydata to ITK Mesh<br>

    //<br><br>    const unsigned int PointDimension   = 3;<br>    const unsigned int MaxCellDimension = 2;<br><br>    typedef itk::DefaultStaticMeshTraits&lt;<br>            vtkFloatingPointType,<br>            PointDimension,<br>

            MaxCellDimension,<br>            vtkFloatingPointType,<br>            vtkFloatingPointType  &gt;       MeshTraits;<br><br><br>    typedef itk::Mesh&lt;<br>            vtkFloatingPointType,<br>            PointDimension,<br>

            MeshTraits              &gt;     MeshType;<br><br><br>    MeshType::Pointer  mesh = MeshType::New();<br><br>    //<br>    // Transfer the points from the vtkPolyData into the itk::Mesh<br>    //<br>    const unsigned int numberOfPoints = polyData-&gt;GetOutput()-&gt;GetNumberOfPoints();<br>

<br>    vtkPoints * vtkpoints = polyData-&gt;GetOutput()-&gt;GetPoints();<br><br>    mesh-&gt;GetPoints()-&gt;Reserve( numberOfPoints );<br><br>    for(unsigned int p =0; p &lt; numberOfPoints; p++)<br>    {<br><br>        vtkFloatingPointType * apoint = vtkpoints-&gt;GetPoint( p );<br>

<br>        mesh-&gt;SetPoint( p, MeshType::PointType( apoint ));<br><br>    }<br><br><br>    //<br>    // Transfer the cells from the vtkPolyData into the itk::Mesh<br>    //<br>    vtkCellArray * triangleStrips = polyData-&gt;GetOutput()-&gt;GetStrips();<br>

<br><br>    vtkIdType  * cellPoints;<br>    vtkIdType    numberOfCellPoints;<br><br>    //<br>    // First count the total number of triangles from all the triangle strips.<br>    //<br>    unsigned int numberOfTriangles = 0;<br>

<br>    triangleStrips-&gt;InitTraversal();<br><br>    while( triangleStrips-&gt;GetNextCell( numberOfCellPoints, cellPoints ) )<br>    {<br>        numberOfTriangles += numberOfCellPoints-2;<br>    }<br><br><br>    vtkCellArray * polygons = polyData-&gt;GetOutput()-&gt;GetPolys();<br>

<br>    polygons-&gt;InitTraversal();<br><br>    while( polygons-&gt;GetNextCell( numberOfCellPoints, cellPoints ) )<br>    {<br>        if( numberOfCellPoints == 3 )<br>        {<br>            numberOfTriangles ++;<br>
        }<br>
    }<br><br><br><br>    //<br>    // Reserve memory in the itk::Mesh for all those triangles<br>    //<br>    mesh-&gt;GetCells()-&gt;Reserve( numberOfTriangles );<br><br><br>    //<br>    // Copy the triangles from vtkPolyData into the itk::Mesh<br>

    //<br>    //<br><br>    typedef MeshType::CellType   CellType;<br><br>    typedef itk::TriangleCell&lt; CellType &gt; TriangleCellType;<br><br>    int cellId = 0;<br><br>    // first copy the triangle strips<br>    triangleStrips-&gt;InitTraversal();<br>

    while( triangleStrips-&gt;GetNextCell( numberOfCellPoints, cellPoints ) )<br>    {<br><br>        unsigned int numberOfTrianglesInStrip = numberOfCellPoints - 2;<br><br>        unsigned long pointIds[3];<br>        pointIds[0] = cellPoints[0];<br>

        pointIds[1] = cellPoints[1];<br>        pointIds[2] = cellPoints[2];<br><br>        for( unsigned int t=0; t &lt; numberOfTrianglesInStrip; t++ )<br>        {<br>            MeshType::CellAutoPointer c;<br>            TriangleCellType * tcell = new TriangleCellType;<br>

            tcell-&gt;SetPointIds( pointIds );<br>            c.TakeOwnership( tcell );<br>            mesh-&gt;SetCell( cellId, c );<br>            cellId++;<br>            pointIds[0] = pointIds[1];<br>            pointIds[1] = pointIds[2];<br>

            pointIds[2] = cellPoints[t+3];<br>        }<br><br><br>    }<br><br><br>    // then copy the normal triangles<br>    polygons-&gt;InitTraversal();<br>    while( polygons-&gt;GetNextCell( numberOfCellPoints, cellPoints ) )<br>

    {<br>        if( numberOfCellPoints !=3 ) // skip any non-triangle.<br>        {<br>            continue;<br>        }<br>        MeshType::CellAutoPointer c;<br>        TriangleCellType * t = new TriangleCellType;<br>

        t-&gt;SetPointIds( (unsigned long*)cellPoints );<br>        c.TakeOwnership( t );<br>        mesh-&gt;SetCell( cellId, c );<br>        cellId++;<br>    }<br><br><br><br>    std::cout &lt;&lt; &quot;Mesh  &quot; &lt;&lt; std::endl;<br>

    std::cout &lt;&lt; &quot;Number of Points =   &quot; &lt;&lt; mesh-&gt;GetNumberOfPoints() &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;Number of Cells  =   &quot; &lt;&lt; mesh-&gt;GetNumberOfCells()  &lt;&lt; std::endl;<br>

<br><br><br><br>    //<br>    // Convert  ITK Mesh to ITK Mesh spatial object<br>    //<br><br>    typedef itk::MeshSpatialObject&lt; MeshType &gt; SpatialObjectType;<br>    SpatialObjectType::Pointer meshSpa = SpatialObjectType::New();<br>

    meshSpa-&gt;SetMesh( mesh);<br>    meshSpa-&gt;Update();<br><br><br><br>    typedef unsigned char  PixelType;<br>    const unsigned int    Dimension = 3;<br>    typedef itk::Image&lt; PixelType, Dimension &gt;       ImageType;<br>

    <br>    typedef itk::SpatialObjectToImageFilter&lt;<br>            SpatialObjectType, ImageType &gt;   SpatialObjectToImageFilterType;<br><br>    SpatialObjectToImageFilterType::Pointer imageFilter =<br>            SpatialObjectToImageFilterType::New();<br>

    ImageType::SizeType size;<br>    size[ 0 ] =  100;<br>    size[ 1 ] =  100;<br>    size[ 2 ] = 100;<br>    imageFilter-&gt;SetSize( size );<br>    ImageType::SpacingType spacing;<br>    spacing[0] =  100.0 / size[0];<br>

    spacing[1] =  100.0 / size[1];<br>    spacing[2] =  100.0 / size[2];<br><br>    imageFilter-&gt;SetSpacing( spacing );<br>    imageFilter-&gt;SetInput( meshSpa );<br><br>    ImageType::PointType origin;<br>    origin[0]=0;origin[1]=0;origin[2]=0;<br>

    imageFilter-&gt;SetOrigin(origin);<br>    const PixelType outValue  = 0;<br>    const PixelType inValue =  1;<br>    meshSpa-&gt;SetDefaultInsideValue(  inValue );<br>    meshSpa-&gt;SetDefaultOutsideValue(  outValue );<br>

<br>    imageFilter-&gt;SetUseObjectValue( true );<br>    imageFilter-&gt;SetOutsideValue( airHounsfieldUnits );<br><br>    // Write the image<br>    typedef itk::ImageFileWriter&lt; ImageType &gt;     WriterType;<br>    WriterType::Pointer writer = WriterType::New();<br>

<br>    writer-&gt;SetFileName(&quot;Output.nii&quot;);<br>    writer-&gt;SetInput( imageFilter-&gt;GetOutput() );<br>    try<br>    {<br>        imageFilter-&gt;Update();<br>        writer-&gt;Update();<br>    }<br>    catch( itk::ExceptionObject &amp; excp )<br>

    {<br>        std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>        return EXIT_FAILURE;<br>    }<br><br><br><br>    return EXIT_SUCCESS;<br>}<br>/////////<br>///code ends<br>/////<br><br>Thanks,<div><div></div><div class="h5">
<br><br><div class="gmail_quote">
On Thu, Apr 8, 2010 at 2:51 PM, Luis Ibanez <span dir="ltr">&lt;<a href="mailto:luis.ibanez@kitware.com" target="_blank">luis.ibanez@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div>Hi Somi,<br>
<br>
<br>
Nope, there is no ConeSpatialObject.<br>
<br>
<br>
However, you could easily create this new class by reusing the<br>
code of the CylinderSpatialObject.<br>
<br>
or<br>
<br>
you could fake one by using the<br>
<br>
                 itkTubeSpatialObject<br>
<br>
with only two points, one of them having Radius == 0.<br>
<br>
<br>
     Regards,<br>
<br>
<br>
          Luis<br>
<br>
<br>
-------------------------------------------------------------<br>
On Mon, Apr 5, 2010 at 1:56 PM, somi &lt;<a href="mailto:seesomi@gmail.com" target="_blank">seesomi@gmail.com</a>&gt; wrote:<br>
</div><div><div></div><div>&gt; Hi,<br>
&gt; Does a cone spatial object exist in ITK ?<br>
&gt; In my application a user interactively places a cone over an ITK image<br>
&gt; volume.<br>
&gt;<br>
&gt; I then have to voxelize the cone. However volexiling in VTK takes a lot of<br>
&gt; time (I tried  vtkImplicitModeller,vtkSelectEnclosedPoints they were too<br>
&gt; slow).<br>
&gt; So is it possible to pass the parameters of the cone to itk and generate it<br>
&gt; using some spatial object ?<br>
&gt;<br>
&gt; Regards,<br>
&gt; Somesh<br>
&gt;<br>
&gt;<br>
</div></div><div><div></div><div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>