Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

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

Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Do
Dear all:
I am trying to import stl files  -> perform Boolean operations -> calculate volume of final mesh

I've tried using the "Boolean Operations on Surfaces in VTK Without External Libraries"
http://www.insight-journal.org/browse/publication/797

but have failed. Does this work on arbitrary stl files or do I have to find a different method?

Also, after the Boolean, what will be the best way to evaluate the volume?

Thanks!

Doyoung



--------------------------------------------


vtkSTLReader *volumeReader = vtkSTLReader::New();
                volumeReader->SetFileName("test.stl");
vtkSTLReader *volumeReader2 = vtkSTLReader::New();
                volumeReader2->SetFileName("test2.stl");

vtkSmartPointer<vtkBooleanOperationPolyDataFilter> boolFilter =
    vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
  boolFilter->SetOperation( 0 );
  boolFilter->SetInputConnection( 0, volumeReader->GetOutputPort() );
  boolFilter->SetInputConnection( 1, volumeReader2->GetOutputPort() );

  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection( boolFilter->GetOutputPort( 0 ) );
  mapper->ScalarVisibilityOff();

  vtkActor *actor = vtkActor::New();
  actor->SetMapper( mapper );
        renderer->AddActor( actor );
        actor->Delete();

        volumeReader->Delete();
        volumeReader2->Delete();
  renWin->Render();
  renWinInteractor->Start();


               
Reply | Threaded
Open this post in threaded view
|

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

David Doria-2-3
On Mon, Aug 8, 2011 at 6:44 PM, louis10th <[hidden email]> wrote:

> Dear all:
> I am trying to import stl files  -> perform Boolean operations -> calculate
> volume of final mesh
>
> I've tried using the "Boolean Operations on Surfaces in VTK Without External
> Libraries"
> http://www.insight-journal.org/browse/publication/797
>
> but have failed. Does this work on arbitrary stl files or do I have to find
> a different method?
>
> Also, after the Boolean, what will be the best way to evaluate the volume?
>
> Thanks!
>
> Doyoung

Once you use the vtkSTLReader, the problem becomes boolean operations
on a vtkPolyData, nothing to do with STL anymore. The first thing I
would do is read your file and then immediately write it with
vtkXMLPolyData writer and load that file in Paraview and see if it
looks reasonable.

Also, what do you mean "you have failed"? Are there compiler errors?
Run time errors? Incorrect results? etc.

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

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

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Cory Quammen
In reply to this post by Do
The boolean operations filters only work on triangle meshes. If your
STL files do not contain triangle meshes, make sure to put a
vtkTriangleFilter between the STL reader and the boolean operations
filter.

Cory

On Mon, Aug 8, 2011 at 6:44 PM, louis10th <[hidden email]> wrote:

> Dear all:
> I am trying to import stl files  -> perform Boolean operations -> calculate
> volume of final mesh
>
> I've tried using the "Boolean Operations on Surfaces in VTK Without External
> Libraries"
> http://www.insight-journal.org/browse/publication/797
>
> but have failed. Does this work on arbitrary stl files or do I have to find
> a different method?
>
> Also, after the Boolean, what will be the best way to evaluate the volume?
>
> Thanks!
>
> Doyoung
>
>
>
> --------------------------------------------
>
>
> vtkSTLReader *volumeReader = vtkSTLReader::New();
>                volumeReader->SetFileName("test.stl");
> vtkSTLReader *volumeReader2 = vtkSTLReader::New();
>                volumeReader2->SetFileName("test2.stl");
>
> vtkSmartPointer<vtkBooleanOperationPolyDataFilter> boolFilter =
>    vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
>  boolFilter->SetOperation( 0 );
>  boolFilter->SetInputConnection( 0, volumeReader->GetOutputPort() );
>  boolFilter->SetInputConnection( 1, volumeReader2->GetOutputPort() );
>
>  vtkSmartPointer<vtkPolyDataMapper> mapper =
>    vtkSmartPointer<vtkPolyDataMapper>::New();
>  mapper->SetInputConnection( boolFilter->GetOutputPort( 0 ) );
>  mapper->ScalarVisibilityOff();
>
>  vtkActor *actor = vtkActor::New();
>  actor->SetMapper( mapper );
>        renderer->AddActor( actor );
>        actor->Delete();
>
>        volumeReader->Delete();
>        volumeReader2->Delete();
>  renWin->Render();
>  renWinInteractor->Start();
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Using-Boolean-Operations-on-Surfaces-on-arbitrary-mesh-stl-files-tp4680076p4680076.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



--
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
_______________________________________________
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

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

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Do
test.zip

Thanks for your prompt reply.

I do think that they are proper files but will try the vtkTriangleFilter.

I have attached the stl files just in case.

Thanks again!
Do
Reply | Threaded
Open this post in threaded view
|

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Do
In reply to this post by David Doria-2-3
The program compiles with no error :)
But when I execute the exe it crashes.

I did try the following and the file looks reasonable.
I will also try Paraview.

Thanks!

--------------------

        vtkSTLReader *volumeReader = vtkSTLReader::New();
                volumeReader->SetFileName("test.stl");
               
        vtkPolyDataMapper *stlMapper=vtkPolyDataMapper::New();
        stlMapper->SetInputConnection (volumeReader->GetOutputPort());
               
        vtkLODActor *stlActor=vtkLODActor::New();
        stlActor->SetMapper(stlMapper);
               
        renderer->AddActor( stlActor );
       
        volumeReader-> Delete(); stlMapper->Delete(); stlActor->Delete();

        renWin->Render();
        renWinInteractor->Start();


Reply | Threaded
Open this post in threaded view
|

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Bill Lorensen
You probably need to run vtkCleanPolyData on the output of the reader. I think the STL reader creates triangles that each have their own sets of points.

On Tue, Aug 9, 2011 at 12:13 AM, louis10th <[hidden email]> wrote:
The program compiles with no error :)
But when I execute the exe it crashes.

I did try the following and the file looks reasonable.
I will also try Paraview.

Thanks!

--------------------

       vtkSTLReader *volumeReader = vtkSTLReader::New();
               volumeReader->SetFileName("test.stl");

       vtkPolyDataMapper *stlMapper=vtkPolyDataMapper::New();
       stlMapper->SetInputConnection (volumeReader->GetOutputPort());

       vtkLODActor *stlActor=vtkLODActor::New();
       stlActor->SetMapper(stlMapper);

       renderer->AddActor( stlActor );

       volumeReader-> Delete(); stlMapper->Delete(); stlActor->Delete();

       renWin->Render();
       renWinInteractor->Start();




--
View this message in context: http://vtk.1045678.n5.nabble.com/Using-Boolean-Operations-on-Surfaces-on-arbitrary-mesh-stl-files-tp4680076p4680676.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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

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


_______________________________________________
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

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

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Cory Quammen
On Wed, Aug 10, 2011 at 8:56 AM, Bill Lorensen <[hidden email]> wrote:
> You probably need to run vtkCleanPolyData on the output of the reader. I
> think the STL reader creates triangles that each have their own sets of
> points.

Yes, the triangles in a surface need to be connected so that the
inside/outside tests works. This filter won't work on polygon soup.

- Cory

>
> On Tue, Aug 9, 2011 at 12:13 AM, louis10th <[hidden email]> wrote:
>>
>> The program compiles with no error :)
>> But when I execute the exe it crashes.
>>
>> I did try the following and the file looks reasonable.
>> I will also try Paraview.
>>
>> Thanks!
>>
>> --------------------
>>
>>        vtkSTLReader *volumeReader = vtkSTLReader::New();
>>                volumeReader->SetFileName("test.stl");
>>
>>        vtkPolyDataMapper *stlMapper=vtkPolyDataMapper::New();
>>        stlMapper->SetInputConnection (volumeReader->GetOutputPort());
>>
>>        vtkLODActor *stlActor=vtkLODActor::New();
>>        stlActor->SetMapper(stlMapper);
>>
>>        renderer->AddActor( stlActor );
>>
>>        volumeReader-> Delete(); stlMapper->Delete(); stlActor->Delete();
>>
>>        renWin->Render();
>>        renWinInteractor->Start();
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://vtk.1045678.n5.nabble.com/Using-Boolean-Operations-on-Surfaces-on-arbitrary-mesh-stl-files-tp4680076p4680676.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



--
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
_______________________________________________
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

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

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Cory Quammen
Doyoung,

I checked your STL files in ParaView, and it looks like it is a fully
connected triangle mesh, so I would expect the boolean filter to work.

It appears that one object is a translated version of the other
object, so there is no overlap. I think the filter works appropriately
in this case. I'll see if I can reproduce your error.

Thanks,
Cory

On Wed, Aug 10, 2011 at 10:09 AM, Cory Quammen <[hidden email]> wrote:

> On Wed, Aug 10, 2011 at 8:56 AM, Bill Lorensen <[hidden email]> wrote:
>> You probably need to run vtkCleanPolyData on the output of the reader. I
>> think the STL reader creates triangles that each have their own sets of
>> points.
>
> Yes, the triangles in a surface need to be connected so that the
> inside/outside tests works. This filter won't work on polygon soup.
>
> - Cory
>
>>
>> On Tue, Aug 9, 2011 at 12:13 AM, louis10th <[hidden email]> wrote:
>>>
>>> The program compiles with no error :)
>>> But when I execute the exe it crashes.
>>>
>>> I did try the following and the file looks reasonable.
>>> I will also try Paraview.
>>>
>>> Thanks!
>>>
>>> --------------------
>>>
>>>        vtkSTLReader *volumeReader = vtkSTLReader::New();
>>>                volumeReader->SetFileName("test.stl");
>>>
>>>        vtkPolyDataMapper *stlMapper=vtkPolyDataMapper::New();
>>>        stlMapper->SetInputConnection (volumeReader->GetOutputPort());
>>>
>>>        vtkLODActor *stlActor=vtkLODActor::New();
>>>        stlActor->SetMapper(stlMapper);
>>>
>>>        renderer->AddActor( stlActor );
>>>
>>>        volumeReader-> Delete(); stlMapper->Delete(); stlActor->Delete();
>>>
>>>        renWin->Render();
>>>        renWinInteractor->Start();
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://vtk.1045678.n5.nabble.com/Using-Boolean-Operations-on-Surfaces-on-arbitrary-mesh-stl-files-tp4680076p4680676.html
>>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>> _______________________________________________
>>> 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
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
>
>
> --
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
>



--
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
_______________________________________________
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

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

Re: Using "Boolean Operations on Surfaces" on arbitrary mesh (stl) files

Do
Thank you everyone.
I have solved the problem with the original stl files.
I have modified the example file provided as.

Thanks again.
Doyoung

--------------
 vtkSTLReader* test1= vtkSTLReader::New();
  test1->SetFileName("test1.stl");

  vtkSTLReader* test2= vtkSTLReader::New();
  test2->SetFileName("test2.stl");

  vtkSmartPointer<vtkBooleanOperationPolyDataFilter> boolFilter =
    vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
  boolFilter->SetOperation( operation );
  boolFilter->SetInputConnection( 0, test1->GetOutputPort() );
  boolFilter->SetInputConnection( 1, test2->GetOutputPort() );