[vtkusers] Problem with vtkPolyDataToImageStencil in 5.8

David Gobbi david.gobbi at gmail.com
Fri Mar 9 16:55:24 EST 2012


Hi Jothy,

Please, for my sake, give it a try it without the extruder.  In VTK
5.8 the extruder should not be necessary, and removing it will make
the process much more efficient.

If the DICOM reader is using the SliceThickness as the Z spacing,
then it is wrong.  It is not uncommon for a protocol to use a slice
thickness that is different from the Z spacing.

 - David


On Fri, Mar 9, 2012 at 2:26 PM, Jothybasu Selvaraj <jothybasu at gmail.com> wrote:
> And vtkDICOMImageReader depends on the slice thickness tag it seems, that's
> why the imageData->GetSpacing()
>
> give 3.0 mm, which is wrong in this case.
>
> Jothy
>
>
> On Fri, Mar 9, 2012 at 9:24 PM, Jothybasu Selvaraj <jothybasu at gmail.com>
> wrote:
>>
>> Hi David,
>>
>> Some stunning revelation here!
>>
>> The problem is because of the inconsistence between the DICOM tags Slice
>> thickness and ImagePositionPatient
>>
>> Slice thickness says it's 3mm, but the z difference between two slices
>> according to their IPP is 2.5 mm.
>>
>> If I set the extrude->SetVector(0,0,-2.5).
>>
>> It works perfectly!
>>
>> How can it happen in DICOM? Probably, that's the reason why other datasets
>> worked form me with the new vtkPolydataToImageStencil.
>>
>> Can someone shed light on this?
>>
>> Many thanks again
>>
>> Jothy
>>
>>
>>
>>
>> On Fri, Mar 9, 2012 at 8:36 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>>>
>>> Hi Jothy,
>>>
>>> Remove the extrude filter from the pipeline.
>>>
>>>  - David
>>>
>>>
>>> On Fri, Mar 9, 2012 at 1:29 PM, Jothybasu Selvaraj <jothybasu at gmail.com>
>>> wrote:
>>> > Hi David,
>>> >
>>> > I am still not able to fix this issue.
>>> >
>>> > This is how I create the polydata and other pipeline.
>>> >
>>> > vtkSmartPointer<vtkPoints> points =
>>> >
>>> >                        vtkSmartPointer<vtkPoints>::New();
>>> >
>>> >                  vtkSmartPointer<vtkCellArray> cells =
>>> >
>>> >                          vtkSmartPointer<vtkCellArray>::New();
>>> >
>>> >                points->SetNumberOfPoints(npts+1);
>>> >
>>> >                cells->InsertNextCell(npts+1);
>>> >
>>> >                for(int p=0;p<npts;p++)
>>> >
>>> >                {
>>> >
>>> >
>>> >
>>> >                    points->SetPoint( p, Xp, Yp,Zp );
>>> >
>>> >                    cells->InsertCellPoint( p );
>>> >
>>> >                }
>>> >
>>> >                cells->InsertCellPoint(npts);
>>> >
>>> >                points->SetPoint(npts,pts[0],pts[1],pts[2]);//close
>>> > contour
>>> >
>>> >
>>> >                vtkSmartPointer<vtkPolyData>polydataContour=
>>> >
>>> >                        vtkSmartPointer<vtkPolyData>::New();
>>> >
>>> >                polydataContour->Initialize();
>>> >
>>> >                polydataContour->SetLines(cells);
>>> >
>>> >                polydataContour->SetPoints(points);
>>> >
>>> >
>>> > //Here all contours are appended to vtkAppendPolydataFilter
>>> >
>>> >                vtkSmartPointer<vtkPolyDataToImageStencil> sts=
>>> >
>>> >  vtkSmartPointer<vtkPolyDataToImageStencil>::New();
>>> >               sts->SetTolerance(1e-6);//very important
>>> >                sts->SetInformationInput(binary_image);
>>> >                vtkSmartPointer<vtkLinearExtrusionFilter> extrude=
>>> >
>>> >  vtkSmartPointer<vtkLinearExtrusionFilter>::New();
>>> >                extrude->SetInput(appender->GetOutput());
>>> >                extrude->CappingOff();//also tried ON
>>> >                extrude->SetVector(0, 0,-zSpacing);//Correct Z spacing
>>> > is
>>> > important
>>> >                //qDebug()<<-zSpacing<<"-ve zSpacing";
>>> >                sts->SetInput(extrude->GetOutput());
>>> >
>>> >
>>> >                //qDebug()<<t->currentTime()<<"Stencil start";
>>> >                vtkSmartPointer<vtkImageStencil> stencil=
>>> >                        vtkSmartPointer<vtkImageStencil>::New();
>>> >                stencil->SetStencil(sts->GetOutput());
>>> >                stencil->SetInput(binary_image);
>>> >                stencil->ReverseStencilOn();
>>> >                stencil->Update();
>>> >
>>> >
>>> > I am able to visualize the contour by setting appendFilter->GetOutput()
>>> > to a
>>> > vtkPolyDataMapper.
>>> >
>>> > Is there any thing wrong.
>>> >
>>> > Thanks very much!
>>> >
>>> > Jothy
>>> >
>>> >
>>> >
>>> >
>>> > On Tue, Mar 6, 2012 at 3:48 PM, David Gobbi <david.gobbi at gmail.com>
>>> > wrote:
>>> >>
>>> >> You'd have to use SetLines() instead of SetPolys().  And for
>>> >> polylines, the final point in the polyline has to connect to the first
>>> >> line to create a closed loop, so polylines cell arrays need an extra
>>> >> entry as compared to polygon cell arrays.
>>> >>
>>> >> On Tue, Mar 6, 2012 at 8:36 AM, Jothybasu Selvaraj
>>> >> <jothybasu at gmail.com>
>>> >> wrote:
>>> >> > I ma creating the polydat per conoutr like this
>>> >> >
>>> >> > vtkSmartPointer<vtkPolyData>polydataContour=
>>> >> >
>>> >> >      vtkSmartPointer<vtkPolyData>::New();
>>> >> >
>>> >> > polydataContour->Initialize();
>>> >> >
>>> >> > polydataContour->SetPolys( cells );//vtkCellArray
>>> >> >
>>> >> > polydataContour->SetPoints( points);//vtkPoints
>>> >> >
>>> >> >
>>> >> > How should I do that?
>>> >> >
>>> >> > Thanks very much
>>> >> >
>>> >> > Jothy
>>> >> >
>>> >> >
>>> >> > On Tue, Mar 6, 2012 at 3:31 PM, David Gobbi <david.gobbi at gmail.com>
>>> >> > wrote:
>>> >> >>
>>> >> >> The contours must be polylines, not polygons, or it won't work.
>>> >> >>
>>> >> >> On Tue, Mar 6, 2012 at 6:29 AM, Jothybasu Selvaraj
>>> >> >> <jothybasu at gmail.com>
>>> >> >> wrote:
>>> >> >> > Yes, I have one contour for each z slice as a vtkPolyData. I will
>>> >> >> > try
>>> >> >> > removing that.
>>> >> >> >
>>> >> >> > Thanks
>>> >> >> >
>>> >> >> >
>>> >> >> > On Tue, Mar 6, 2012 at 1:26 PM, David Gobbi
>>> >> >> > <david.gobbi at gmail.com>
>>> >> >> > wrote:
>>> >> >> >>
>>> >> >> >> Do you have one contour for each Z slice?  If so, then try
>>> >> >> >> removing
>>> >> >> >> the Extrude filter from your pipeline.
>>> >> >> >>
>>> >> >> >>
>>> >> >> >> On Tue, Mar 6, 2012 at 2:51 AM, Jothybasu Selvaraj
>>> >> >> >> <jothybasu at gmail.com>
>>> >> >> >> wrote:
>>> >> >> >> > Another point here,
>>> >> >> >> >
>>> >> >> >> > I am creating a vtkPolyData for each contour and then adding
>>> >> >> >> > it to
>>> >> >> >> > the
>>> >> >> >> > vtkAppendPolydataFilter, then the output of
>>> >> >> >> > vtkAppenPolydataFilter
>>> >> >> >> > is
>>> >> >> >> > set as
>>> >> >> >> > input to vtkPolydataToImageStencil.
>>> >> >> >> >
>>> >> >> >> > Could this make any difference?
>>> >> >> >> >
>>> >> >> >> > Thanks
>>> >> >> >> >
>>> >> >> >> > Jothy
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> > On Mon, Mar 5, 2012 at 7:49 PM, Jothybasu Selvaraj
>>> >> >> >> > <jothybasu at gmail.com>
>>> >> >> >> > wrote:
>>> >> >> >> >>
>>> >> >> >> >> No, it doesn't fix the problem.
>>> >> >> >> >>
>>> >> >> >> >> But it seems to work fine for contours with z-spacing in
>>> >> >> >> >> steps of
>>> >> >> >> >> 1mm.
>>> >> >> >> >>
>>> >> >> >> >> It is working well for a dataset with 3mm spacing but fails
>>> >> >> >> >> for
>>> >> >> >> >> 2.5
>>> >> >> >> >> mm.
>>> >> >> >> >>
>>> >> >> >> >> Maybe I need to test it thoroughly. Can I use those cxx and
>>> >> >> >> >> .h
>>> >> >> >> >> from
>>> >> >> >> >> 5.6
>>> >> >> >> >> in
>>> >> >> >> >> 5.8, that would be a easy workaround.
>>> >> >> >> >>
>>> >> >> >> >> Thanks
>>> >> >> >> >>
>>> >> >> >> >> Jothy
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >> On Mon, Mar 5, 2012 at 4:01 PM, David Gobbi
>>> >> >> >> >> <david.gobbi at gmail.com>
>>> >> >> >> >> wrote:
>>> >> >> >> >>>
>>> >> >> >> >>> Hi Jothy,
>>> >> >> >> >>>
>>> >> >> >> >>> It underwent significant changes, but the only change I can
>>> >> >> >> >>> think
>>> >> >> >> >>> of that might have affected your pipeline is the way that it
>>> >> >> >> >>> does
>>> >> >> >> >>> rounding, it used to use a Floor() method that provided a
>>> >> >> >> >>> small
>>> >> >> >> >>> tolerance even if you did SetTolerance(0).  Try calling
>>> >> >> >> >>> SetTolerance(1e-6) on your PolyDataToImageStencil object, it
>>> >> >> >> >>> might help.
>>> >> >> >> >>>
>>> >> >> >> >>>  - David
>>> >> >> >> >>>
>>> >> >> >> >>> On Mon, Mar 5, 2012 at 3:17 AM, Jothybasu Selvaraj
>>> >> >> >> >>> <jothybasu at gmail.com>
>>> >> >> >> >>> wrote:
>>> >> >> >> >>> > Hi all,
>>> >> >> >> >>> >
>>> >> >> >> >>> > I was able to create a mesh using the following pipeline
>>> >> >> >> >>> > in
>>> >> >> >> >>> > 5.6
>>> >> >> >> >>> > and
>>> >> >> >> >>> > it
>>> >> >> >> >>> > worked well
>>> >> >> >> >>> >
>>> >> >> >> >>> >
>>> >> >> >> >>> >
>>> >> >> >> >>> >
>>> >> >> >> >>> >
>>> >> >> >> >>> >
>>> >> >> >> >>> > vtkPolyDataToImageStencil->vtkLinearExtrusionFilter->vtkImageStencil->vtkDiscreteMarchingCubes
>>> >> >> >> >>> >
>>> >> >> >> >>> > Now, I have updated vtk to 5.8 and I am getting gaps in
>>> >> >> >> >>> > the
>>> >> >> >> >>> > mesh
>>> >> >> >> >>> > along
>>> >> >> >> >>> > the z
>>> >> >> >> >>> > axis. I am really puzzled, I have tried with different
>>> >> >> >> >>> > data
>>> >> >> >> >>> > sets
>>> >> >> >> >>> > as
>>> >> >> >> >>> > well.
>>> >> >> >> >>> >
>>> >> >> >> >>> > I have read somewhere that vtkPolyDataToImageStencil had
>>> >> >> >> >>> > some
>>> >> >> >> >>> > changes
>>> >> >> >> >>> > in
>>> >> >> >> >>> > 5.8, does it has anything to do with this problem, or am I
>>> >> >> >> >>> > doing
>>> >> >> >> >>> > anything wrong?
>>> >> >> >> >>> >
>>> >> >> >> >>> > I have contours of constant z-spacing.
>>> >> >> >> >>> >
>>> >> >> >> >>> > Any hints?
>>> >> >> >> >>> >
>>> >> >> >> >>> > Thanks
>>> >> >> >> >>> >
>>> >> >> >> >>> > --
>>> >> >> >> >>> > Jothy
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >> --
>>> >> >> >> >> Jothy
>>> >> >> >> >>
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> > --
>>> >> >> >> > Jothy
>>> >> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> > --
>>> >> >> > Jothy
>>> >> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > Jothy
>>> >> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Jothy
>>> >
>>
>>
>>
>>
>> --
>> Jothy
>>
>
>
>
> --
> Jothy
>



More information about the vtkusers mailing list