filling in a sphere's intersection with a plane

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

filling in a sphere's intersection with a plane

The Merper
Hi all,
  I have a set of spheres in a volume that I visualize in 2D slices. When the plane of a 2D slice intersects a sphere, I want the interior of the sphere to be filled. It appears that there three different ways to do this:

1) Use vtkContourTriangulator as recommended here:
https://vtk.org/pipermail/vtkusers/2015-May/090826.html
with this example as a basis:

2) Use PolyDataToImageData:

3) Use PolyDataContourToImageData:

I've tried Option 1 without success.  Did I do something wrong or should I try one of the other options.
  any wisdom would be helpful,
     -Merps


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

David Gobbi
On Thu, Jan 10, 2019 at 12:13 PM The Merper <[hidden email]> wrote:

  I have a set of spheres in a volume that I visualize in 2D slices. When the plane of a 2D slice intersects a sphere, I want the interior of the sphere to be filled.

How are the spheres defined?  Do you already have them as vtkPolyData objects, or do you just have a list of "center and radius" values to describe the spheres?
 
When you say "visualize in 2D slices" do you mean that you are already visualizing slices of something (e.g. of an image) and you want to display the sphere cuts as an overlay on the image?  For your application, does it matter whether the sphere cuts are displayed as voxels (i.e. a vtkImageData) vs polygons?

Also, for context, what is the general purpose of your application?

Cheers,
  David



_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

David Gobbi
If you already have the spheres as polydata, and if they are already in your volume coord system, then the simplest approach is probably to use these two filters:
- vtkCutter, to cut the sphere (this generates a polyline contour of the intersection)
- vtkContourTriangulator to fill the polyline contour with triangles

When rendering the result on the image, the polydata and your image slice will be coincident in the z-buffer.  It might be possible to fix this by calling SetResolveCoincidentTopologyToPolygonOffset() on the polydata mapper.

Rendering the filled spheres with voxels would be more complicated.  The vtkPolyDataToImageStencil class works volumetrically, i.e. it would be used to fill the entire sphere and produce a binary volume.  Then the desired slice of that volume would be rendered as an overlay.

   David


On Fri, Jan 11, 2019 at 8:02 AM The Merper <[hidden email]> wrote:
Thanks for the speedy reply, David.
The application is a GUI that allows users to mark points in a 3D MRI volume. The user browses the volume and marks the points in 2D slices of the volume, which are rendered via a vtkImageViewer2. Once a point is marked, I represent the location with a sphere. I use vtkSphereSource via vtkPolyDataMapper to render the spheres.

I'd be happy using polygons or voxels.
   thanks again,
      -Merps




On Thu, Jan 10, 2019 at 5:08 PM David Gobbi <[hidden email]> wrote:
On Thu, Jan 10, 2019 at 12:13 PM The Merper <[hidden email]> wrote:

  I have a set of spheres in a volume that I visualize in 2D slices. When the plane of a 2D slice intersects a sphere, I want the interior of the sphere to be filled.

How are the spheres defined?  Do you already have them as vtkPolyData objects, or do you just have a list of "center and radius" values to describe the spheres?
 
When you say "visualize in 2D slices" do you mean that you are already visualizing slices of something (e.g. of an image) and you want to display the sphere cuts as an overlay on the image?  For your application, does it matter whether the sphere cuts are displayed as voxels (i.e. a vtkImageData) vs polygons?

Also, for context, what is the general purpose of your application?

Cheers,
  David



_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

Andras Lasso

In general, vtkCutter returns a random (unordered, non-continuous) list of line segments.

 

Can vtkContourTriangulator deal with that (merge points and order line segments to form closed contours)?

 

Usually we apply vtkStripper with a very large MaximumLength on vtkCutter output to create polygons that can be triangulated and rendered. This works well almost every time, but in some cases (cutting very complex geometries with hundreds of thousand of points) stripping does not find closed polygons. It would be nice to have a somewhat simpler and more robust solution.

 

Andras

 

From: vtkusers <[hidden email]> On Behalf Of David Gobbi
Sent: Friday, January 11, 2019 11:38 AM
To: The Merper <[hidden email]>; VTK Users <[hidden email]>
Subject: Re: [vtkusers] filling in a sphere's intersection with a plane

 

If you already have the spheres as polydata, and if they are already in your volume coord system, then the simplest approach is probably to use these two filters:

- vtkCutter, to cut the sphere (this generates a polyline contour of the intersection)

- vtkContourTriangulator to fill the polyline contour with triangles

 

When rendering the result on the image, the polydata and your image slice will be coincident in the z-buffer.  It might be possible to fix this by calling SetResolveCoincidentTopologyToPolygonOffset() on the polydata mapper.

 

Rendering the filled spheres with voxels would be more complicated.  The vtkPolyDataToImageStencil class works volumetrically, i.e. it would be used to fill the entire sphere and produce a binary volume.  Then the desired slice of that volume would be rendered as an overlay.

 

   David

 

 

On Fri, Jan 11, 2019 at 8:02 AM The Merper <[hidden email]> wrote:

Thanks for the speedy reply, David.

The application is a GUI that allows users to mark points in a 3D MRI volume. The user browses the volume and marks the points in 2D slices of the volume, which are rendered via a vtkImageViewer2. Once a point is marked, I represent the location with a sphere. I use vtkSphereSource via vtkPolyDataMapper to render the spheres.

 

I'd be happy using polygons or voxels.

   thanks again,

      -Merps

 

 

 

 

On Thu, Jan 10, 2019 at 5:08 PM David Gobbi <[hidden email]> wrote:

On Thu, Jan 10, 2019 at 12:13 PM The Merper <[hidden email]> wrote:

 

  I have a set of spheres in a volume that I visualize in 2D slices. When the plane of a 2D slice intersects a sphere, I want the interior of the sphere to be filled.

 

How are the spheres defined?  Do you already have them as vtkPolyData objects, or do you just have a list of "center and radius" values to describe the spheres?

 

When you say "visualize in 2D slices" do you mean that you are already visualizing slices of something (e.g. of an image) and you want to display the sphere cuts as an overlay on the image?  For your application, does it matter whether the sphere cuts are displayed as voxels (i.e. a vtkImageData) vs polygons?

 

Also, for context, what is the general purpose of your application?

 

Cheers,

  David

 

 


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

David Gobbi
On Fri, Jan 11, 2019 at 11:04 AM Andras Lasso <[hidden email]> wrote:

In general, vtkCutter returns a random (unordered, non-continuous) list of line segments.

 

Can vtkContourTriangulator deal with that (merge points and order line segments to form closed contours)?


Yes.  If given unordered line segments, vtkContourTriangulator will sort them.  The nightly tests cover this feature.

Usually we apply vtkStripper with a very large MaximumLength on vtkCutter output to create polygons that can be triangulated and rendered. This works well almost every time, but in some cases (cutting very complex geometries with hundreds of thousand of points) stripping does not find closed polygons. It would be nice to have a somewhat simpler and more robust solution.


The vtkCountourTriangulator code has checks to deal with bad geometry.  It's not perfect, but it's much better than vtkPolygon::Triangulate().  I've avoided vtkDelaunay2D because certain geometries will cause it to crash.

I wrote vtkClipClosedSurface specifically to deal with complex 3D geometries (it uses vtkContourTriangulator as its final stage).  I had meant to write a similar filter called vtkCutClosedSurface filter for cutting (instead of clipping) but that never happened.

  David

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

The Merper
In reply to this post by David Gobbi

Thank you David,
    I tried to do as you suggested with the following code:

                    // Use vtkCutter to derive the contour of the intersection with the Z-plane
                    var Origin=_ZPlaneSource.GetOrigin();
                    var Normal= _ZPlaneSource.GetNormal();
                    var TempPlane = vtkPlane.New();
                    TempPlane.SetOrigin(Origin[0], Origin[1], Origin[2]);
                    TempPlane.SetNormal(Normal[0], Normal[1], Normal[2]);
                    var Cutter = vtkCutter.New();
                    Cutter.SetCutFunction(TempPlane);
                    Cutter.SetInputConnection(SphereSource.GetOutputPort());
                    Cutter.Update();
                    var CutterMapper = vtkPolyDataMapper.New();
                    CutterMapper.SetInputConnection(Cutter.GetOutputPort());

                    // Use vtkContourTriangulator to fill the polyline contour with traingles
                    vtkContourTriangulator Poly = vtkContourTriangulator.New();
                    Poly.SetInputConnection(Cutter.GetOutputPort());
                    var PolyMapper = vtkDataSetMapper.New();
                    PolyMapper.SetInputConnection(Poly.GetOutputPort());
                    PolyMapper.ScalarVisibilityOff();
                    var PolyActor = vtkActor.New();
                    PolyActor.GetProperty().SetColor(((double)_LandmarkColors[i].R) / 255,
                        ((double)_LandmarkColors[i].G) / 255, ((double)_LandmarkColors[i].B) / 255);
                    PolyActor.SetMapper(PolyMapper);
                    Ren.AddActor(PolyActor);

And it renders a circle in the slice that intersects the center of the sphere (i.e., the attached slice91.png). However, when you go below or above that slice, you just see the outline of the sphere (e.g., slice90.jpg). When you go down one or more slices further you see the bottom of the sphere with 3D shading (e.g., slice89.jpg), until it goes out of view.

Did I do something wrong? My PolyMapper instance of vtkDataSetMaper does not have a method SetResolveCoincidentTopologyToPolygonOffset().
     thanks again,
        -M

On Fri, Jan 11, 2019 at 11:38 AM David Gobbi <[hidden email]> wrote:
If you already have the spheres as polydata, and if they are already in your volume coord system, then the simplest approach is probably to use these two filters:
- vtkCutter, to cut the sphere (this generates a polyline contour of the intersection)
- vtkContourTriangulator to fill the polyline contour with triangles

When rendering the result on the image, the polydata and your image slice will be coincident in the z-buffer.  It might be possible to fix this by calling SetResolveCoincidentTopologyToPolygonOffset() on the polydata mapper.

Rendering the filled spheres with voxels would be more complicated.  The vtkPolyDataToImageStencil class works volumetrically, i.e. it would be used to fill the entire sphere and produce a binary volume.  Then the desired slice of that volume would be rendered as an overlay.

   David


On Fri, Jan 11, 2019 at 8:02 AM The Merper <[hidden email]> wrote:
Thanks for the speedy reply, David.
The application is a GUI that allows users to mark points in a 3D MRI volume. The user browses the volume and marks the points in 2D slices of the volume, which are rendered via a vtkImageViewer2. Once a point is marked, I represent the location with a sphere. I use vtkSphereSource via vtkPolyDataMapper to render the spheres.

I'd be happy using polygons or voxels.
   thanks again,
      -Merps




On Thu, Jan 10, 2019 at 5:08 PM David Gobbi <[hidden email]> wrote:
On Thu, Jan 10, 2019 at 12:13 PM The Merper <[hidden email]> wrote:

  I have a set of spheres in a volume that I visualize in 2D slices. When the plane of a 2D slice intersects a sphere, I want the interior of the sphere to be filled.

How are the spheres defined?  Do you already have them as vtkPolyData objects, or do you just have a list of "center and radius" values to describe the spheres?
 
When you say "visualize in 2D slices" do you mean that you are already visualizing slices of something (e.g. of an image) and you want to display the sphere cuts as an overlay on the image?  For your application, does it matter whether the sphere cuts are displayed as voxels (i.e. a vtkImageData) vs polygons?

Also, for context, what is the general purpose of your application?

Cheers,
  David



_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

slice90.png (82K) Download Attachment
slice89.png (82K) Download Attachment
slice91.png (82K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

Andras Lasso
In reply to this post by David Gobbi

Thanks David, I’ve tried replacing stripper+cleaner+triangulator by  your vtkContourTriangulator and it worked very well. Need to do some more testing but probably will switch permanently.

 

Andras

 

From: David Gobbi <[hidden email]>
Sent: Friday, January 11, 2019 1:27 PM
To: Andras Lasso <[hidden email]>
Cc: The Merper <[hidden email]>; VTK Users <[hidden email]>
Subject: Re: [vtkusers] filling in a sphere's intersection with a plane

 

On Fri, Jan 11, 2019 at 11:04 AM Andras Lasso <[hidden email]> wrote:

In general, vtkCutter returns a random (unordered, non-continuous) list of line segments.

 

Can vtkContourTriangulator deal with that (merge points and order line segments to form closed contours)?

 

Yes.  If given unordered line segments, vtkContourTriangulator will sort them.  The nightly tests cover this feature.

 

Usually we apply vtkStripper with a very large MaximumLength on vtkCutter output to create polygons that can be triangulated and rendered. This works well almost every time, but in some cases (cutting very complex geometries with hundreds of thousand of points) stripping does not find closed polygons. It would be nice to have a somewhat simpler and more robust solution.

 

The vtkCountourTriangulator code has checks to deal with bad geometry.  It's not perfect, but it's much better than vtkPolygon::Triangulate().  I've avoided vtkDelaunay2D because certain geometries will cause it to crash.

 

I wrote vtkClipClosedSurface specifically to deal with complex 3D geometries (it uses vtkContourTriangulator as its final stage).  I had meant to write a similar filter called vtkCutClosedSurface filter for cutting (instead of clipping) but that never happened.

 

  David


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

David Gobbi
In reply to this post by The Merper
Hi M,

From the images (especially slice89) it looks like your program still renders the whole sphere, in addition to rendering the cross-section.  Remove or disable the code that renders the whole sphere.

I'm pretty sure that the problem is that you haven't yet written code that updates the origin of your cut plane when the user changes the slice.

Even then, as I mentioned before, there are likely to be rendering problems due to coincident geometry (e.g. the image might get rendered on top of the polydata and thus obscure it).  It's possible that the SetResolveCoincidentTopologyToPolygonOffset method isn't available in the language you are using.  I know there are other ways of ensuring that the polydata is drawn on top (e.g. move it slightly closer to the camera) but right now I can't recall a simple way to do this in VTK (only complicated ways).

  David


On Fri, Jan 11, 2019 at 9:30 PM The Merper <[hidden email]> wrote:

Thank you David,
    I tried to do as you suggested with the following code:

                    // Use vtkCutter to derive the contour of the intersection with the Z-plane
                    var Origin=_ZPlaneSource.GetOrigin();
                    var Normal= _ZPlaneSource.GetNormal();
                    var TempPlane = vtkPlane.New();
                    TempPlane.SetOrigin(Origin[0], Origin[1], Origin[2]);
                    TempPlane.SetNormal(Normal[0], Normal[1], Normal[2]);
                    var Cutter = vtkCutter.New();
                    Cutter.SetCutFunction(TempPlane);
                    Cutter.SetInputConnection(SphereSource.GetOutputPort());
                    Cutter.Update();
                    var CutterMapper = vtkPolyDataMapper.New();
                    CutterMapper.SetInputConnection(Cutter.GetOutputPort());

                    // Use vtkContourTriangulator to fill the polyline contour with traingles
                    vtkContourTriangulator Poly = vtkContourTriangulator.New();
                    Poly.SetInputConnection(Cutter.GetOutputPort());
                    var PolyMapper = vtkDataSetMapper.New();
                    PolyMapper.SetInputConnection(Poly.GetOutputPort());
                    PolyMapper.ScalarVisibilityOff();
                    var PolyActor = vtkActor.New();
                    PolyActor.GetProperty().SetColor(((double)_LandmarkColors[i].R) / 255,
                        ((double)_LandmarkColors[i].G) / 255, ((double)_LandmarkColors[i].B) / 255);
                    PolyActor.SetMapper(PolyMapper);
                    Ren.AddActor(PolyActor);

And it renders a circle in the slice that intersects the center of the sphere (i.e., the attached slice91.png). However, when you go below or above that slice, you just see the outline of the sphere (e.g., slice90.jpg). When you go down one or more slices further you see the bottom of the sphere with 3D shading (e.g., slice89.jpg), until it goes out of view.

Did I do something wrong? My PolyMapper instance of vtkDataSetMaper does not have a method SetResolveCoincidentTopologyToPolygonOffset().
     thanks again,
        -M

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: filling in a sphere's intersection with a plane

David Gobbi
On Mon, Jan 14, 2019 at 8:46 AM The Merper <[hidden email]> wrote:

Does anyone know why the method SetResolveCoincidentTopologyToPolygonOffset is not available to instances of vtkMapper (vtkDataMapper,vtkPolyDataMapper, etc..) in Activiz.NET?

The only thing special about that method is that it is static.  You could check to see if other static methods are missing.

   David 

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers