Discussion:
[vtkusers] How to compute intersection between surface polydata in vtk?
Jean-Dominique Barnichon
2006-04-01 14:13:35 UTC
Permalink
Dear all,

I need to find the intersection between two surfaces, each one being
defined as a polydata (actually one surface is a vertical polyplane, and
the other one is a topographical surface).

Such intersection operation is already effective in other libraries such
as CGAL (http://www.cgal.org) and GTS (http://gts.sourceforge.net).
However, it is still not clear to me which approach i should follow to
perform such an operation with vtk.
Bill Lorensen
2006-04-01 22:11:31 UTC
Permalink
If one surface is a plane, you can use ClipPolyData and define an implicit
plane as the clipper.

Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces, each one being
defined as a polydata (actually one surface is a vertical polyplane, and
the other one is a topographical surface).
Such intersection operation is already effective in other libraries such
as CGAL (http://www.cgal.org) and GTS (http://gts.sourceforge.net).
However, it is still not clear to me which approach i should follow to
perform such an operation with vtk.
Jean-Dominique Barnichon
2006-04-02 06:20:15 UTC
Permalink
One of the surface is not a plane, it is a polyplane (i.e. a 2D (xy)
polyline extruded along the z direction.
Jean-Do
Post by Bill Lorensen
If one surface is a plane, you can use ClipPolyData and define an
implicit plane as the clipper.
Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces, each one being
defined as a polydata (actually one surface is a vertical polyplane,
and the other one is a topographical surface).
Such intersection operation is already effective in other libraries
such as CGAL (http://www.cgal.org) and GTS (http://gts.sourceforge.net).
However, it is still not clear to me which approach i should follow
to perform such an operation with vtk.
Jean-Dominique Barnichon
2006-04-06 20:42:22 UTC
Permalink
Michael,

thanks for pointing me there.
I gave it a try, but I'm actually stuck.
Config: winXp(SP2) + msvc7.0 + vtk5.0.
So I downloaded everything required from bioengineering web site
(vtkBioeng.zip), ran cmake and eventually built vtkBioeng library as a
shared library (vtkBioeng.dll). So far so good.
Then I translated most of the testCollisionDetection.tcl sample given
from tcl to c++ (see code below)
When I run it, I end up with an error located at the following line:
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
Trying to debug it, an access violation is reported in the constructor
of vtkCollisionDetectionFilter, at line #4 :
this->Inputs[0] = NULL;
Apparently, from what I understand, it looks like the array Inputs[]
(inherited from vtkPolyDataSource) is not initialized (value is 0x00000000).

In case you have you already tested this sample :
- did you experience similar problem?
- if no, was it in c++ or in tcl, with which vtk version 4.x or 5.x?

Thanks for helping
Jean-Do

File testCollisionDetection.cpp

#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkSphereSource.h"
#include "vtkMatrix4x4.h"
#include "vtkCollisionDetectionFilter.h"
#include "vtkGlyph3D.h"
#include "vtkInteractorStyleJoystickActor.h"
#include "vtkTextActor.h"

int _tmain(int argc, _TCHAR* argv[])
{
vtkSphereSource *sphere0 = vtkSphereSource::New();
sphere0->SetPhiResolution(30);
sphere0->SetThetaResolution(30);
sphere0->SetCenter(-0.7, 0, 0);
sphere0->Update();

vtkSphereSource *sphere1 = vtkSphereSource::New();
sphere1->SetPhiResolution(30);
sphere1->SetThetaResolution(30);
sphere1->Update();

vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();

vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
collide->SetInput(0, sphere0->GetOutput());
collide->SetMatrix(0, matrix0);
collide->SetInput(1, sphere1->GetOutput());
collide->SetMatrix(1, matrix1);
collide->SetBoxTolerance(0.0);
collide->SetCellTolerance(0.0);
collide->SetNumberOfCellsPerBucket(2);
//collide->SetCollisionModeToFirstContact();
collide->GeneratePolydataOutputOn();
// collide->AddObserver->EndEvent(cbCollision());

vtkTextActor *txt = vtkTextActor::New();

vtkSphereSource *point = vtkSphereSource::New();
point->SetRadius(0.01);
vtkPolyData *pointdata = vtkPolyData::New();
pointdata->SetPoints(collide->GetContactPoints());

vtkGlyph3D *points = vtkGlyph3D::New();
points->SetInput(pointdata);
points->SetSource(point->GetOutput());

vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(collide->GetOutput());
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
(actor1->GetProperty())->BackfaceCullingOn();
actor1->SetUserMatrix(matrix0);

vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInput(collide->GetOutput(1));
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
(actor2->GetProperty())->BackfaceCullingOn();
actor2->SetUserMatrix(matrix1);

vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New();
mapper3->SetInput(points->GetOutput());
vtkActor *actor3 = vtkActor::New();
actor3->SetMapper(mapper3);
(actor3->GetProperty())->SetColor(0,0,0);

vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor1);
ren->AddActor(actor2);
//ren AddObserver EndEvent ChangeOrigin
//ren AddActor actor3
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);

vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkInteractorStyleJoystickActor *istyle =
vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);

iren->Initialize();
renWin->Render();
iren->Start();
}
http://www.bioengineering-research.com/vtk/vtkCollisionDetectionFilter.htm
Post by Jean-Dominique Barnichon
One of the surface is not a plane, it is a polyplane (i.e. a 2D (xy)
polyline extruded along the z direction.
Jean-Do
Post by Bill Lorensen
If one surface is a plane, you can use ClipPolyData and define an
implicit plane as the clipper.
Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces, each one
being defined as a polydata (actually one surface is a vertical
polyplane, and the other one is a topographical surface).
Such intersection operation is already effective in other libraries
such as CGAL (http://www.cgal.org) and GTS
(http://gts.sourceforge.net).
However, it is still not clear to me which approach i should follow
to perform such an operation with vtk.
Goodwin Lawlor
2006-04-07 14:52:59 UTC
Permalink
Hi Jean-Do,

What vtk version are you using? I've updated the source files on the
bioengineering website for vtk5.0

The error is due to the old class code not being compatible with the new
pipeline (>vtk4.5 I think).

I'll send the updated class files to you, if you like.

hth

Goodwin

ps I'm updating all the code there soon... probably moving it to
sourceforge.
Post by Jean-Dominique Barnichon
Michael,
thanks for pointing me there.
I gave it a try, but I'm actually stuck.
Config: winXp(SP2) + msvc7.0 + vtk5.0.
So I downloaded everything required from bioengineering web site
(vtkBioeng.zip), ran cmake and eventually built vtkBioeng library as a
shared library (vtkBioeng.dll). So far so good.
Then I translated most of the testCollisionDetection.tcl sample given
from tcl to c++ (see code below)
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
Trying to debug it, an access violation is reported in the constructor
this->Inputs[0] = NULL;
Apparently, from what I understand, it looks like the array Inputs[]
(inherited from vtkPolyDataSource) is not initialized (value is 0x00000000).
- did you experience similar problem?
- if no, was it in c++ or in tcl, with which vtk version 4.x or 5.x?
Thanks for helping
Jean-Do
File testCollisionDetection.cpp
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkSphereSource.h"
#include "vtkMatrix4x4.h"
#include "vtkCollisionDetectionFilter.h"
#include "vtkGlyph3D.h"
#include "vtkInteractorStyleJoystickActor.h"
#include "vtkTextActor.h"
int _tmain(int argc, _TCHAR* argv[])
{
vtkSphereSource *sphere0 = vtkSphereSource::New();
sphere0->SetPhiResolution(30);
sphere0->SetThetaResolution(30);
sphere0->SetCenter(-0.7, 0, 0);
sphere0->Update();
vtkSphereSource *sphere1 = vtkSphereSource::New();
sphere1->SetPhiResolution(30);
sphere1->SetThetaResolution(30);
sphere1->Update();
vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
collide->SetInput(0, sphere0->GetOutput());
collide->SetMatrix(0, matrix0);
collide->SetInput(1, sphere1->GetOutput());
collide->SetMatrix(1, matrix1);
collide->SetBoxTolerance(0.0);
collide->SetCellTolerance(0.0);
collide->SetNumberOfCellsPerBucket(2);
//collide->SetCollisionModeToFirstContact();
collide->GeneratePolydataOutputOn();
// collide->AddObserver->EndEvent(cbCollision());
vtkTextActor *txt = vtkTextActor::New();
vtkSphereSource *point = vtkSphereSource::New();
point->SetRadius(0.01);
vtkPolyData *pointdata = vtkPolyData::New();
pointdata->SetPoints(collide->GetContactPoints());
vtkGlyph3D *points = vtkGlyph3D::New();
points->SetInput(pointdata);
points->SetSource(point->GetOutput());
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(collide->GetOutput());
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
(actor1->GetProperty())->BackfaceCullingOn();
actor1->SetUserMatrix(matrix0);
vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInput(collide->GetOutput(1));
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
(actor2->GetProperty())->BackfaceCullingOn();
actor2->SetUserMatrix(matrix1);
vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New();
mapper3->SetInput(points->GetOutput());
vtkActor *actor3 = vtkActor::New();
actor3->SetMapper(mapper3);
(actor3->GetProperty())->SetColor(0,0,0);
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor1);
ren->AddActor(actor2);
//ren AddObserver EndEvent ChangeOrigin
//ren AddActor actor3
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkInteractorStyleJoystickActor *istyle =
vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);
iren->Initialize();
renWin->Render();
iren->Start();
}
http://www.bioengineering-research.com/vtk/vtkCollisionDetectionFilter.htm
Post by Jean-Dominique Barnichon
One of the surface is not a plane, it is a polyplane (i.e. a 2D (xy)
polyline extruded along the z direction.
Jean-Do
Post by Bill Lorensen
If one surface is a plane, you can use ClipPolyData and define an
implicit plane as the clipper.
Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces, each one
being defined as a polydata (actually one surface is a vertical
polyplane, and the other one is a topographical surface).
Such intersection operation is already effective in other
libraries such as CGAL (http://www.cgal.org) and GTS
(http://gts.sourceforge.net).
However, it is still not clear to me which approach i should
follow to perform such an operation with vtk.
Jean-Dominique Barnichon
2006-04-07 17:51:29 UTC
Permalink
Well,
I'm using vtk5.0.
I've dowloaded again from the bioengineering website, and it does not
seem updated yet.
So yes, I would very much like if you could send me the new version that
is compatible with vtk5.0.
Thanks,
Jean-Do
Post by Goodwin Lawlor
Hi Jean-Do,
What vtk version are you using? I've updated the source files on the
bioengineering website for vtk5.0
The error is due to the old class code not being compatible with the
new pipeline (>vtk4.5 I think).
I'll send the updated class files to you, if you like.
hth
Goodwin
ps I'm updating all the code there soon... probably moving it to
sourceforge.
Post by Jean-Dominique Barnichon
Michael,
thanks for pointing me there.
I gave it a try, but I'm actually stuck.
Config: winXp(SP2) + msvc7.0 + vtk5.0.
So I downloaded everything required from bioengineering web site
(vtkBioeng.zip), ran cmake and eventually built vtkBioeng library as
a shared library (vtkBioeng.dll). So far so good.
Then I translated most of the testCollisionDetection.tcl sample given
from tcl to c++ (see code below)
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
Trying to debug it, an access violation is reported in the
this->Inputs[0] = NULL;
Apparently, from what I understand, it looks like the array Inputs[]
(inherited from vtkPolyDataSource) is not initialized (value is 0x00000000).
- did you experience similar problem?
- if no, was it in c++ or in tcl, with which vtk version 4.x or 5.x?
Thanks for helping
Jean-Do
File testCollisionDetection.cpp
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkSphereSource.h"
#include "vtkMatrix4x4.h"
#include "vtkCollisionDetectionFilter.h"
#include "vtkGlyph3D.h"
#include "vtkInteractorStyleJoystickActor.h"
#include "vtkTextActor.h"
int _tmain(int argc, _TCHAR* argv[])
{
vtkSphereSource *sphere0 = vtkSphereSource::New();
sphere0->SetPhiResolution(30);
sphere0->SetThetaResolution(30);
sphere0->SetCenter(-0.7, 0, 0);
sphere0->Update();
vtkSphereSource *sphere1 = vtkSphereSource::New();
sphere1->SetPhiResolution(30);
sphere1->SetThetaResolution(30);
sphere1->Update();
vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
collide->SetInput(0, sphere0->GetOutput());
collide->SetMatrix(0, matrix0);
collide->SetInput(1, sphere1->GetOutput());
collide->SetMatrix(1, matrix1);
collide->SetBoxTolerance(0.0);
collide->SetCellTolerance(0.0);
collide->SetNumberOfCellsPerBucket(2);
//collide->SetCollisionModeToFirstContact();
collide->GeneratePolydataOutputOn();
// collide->AddObserver->EndEvent(cbCollision());
vtkTextActor *txt = vtkTextActor::New();
vtkSphereSource *point = vtkSphereSource::New();
point->SetRadius(0.01);
vtkPolyData *pointdata = vtkPolyData::New();
pointdata->SetPoints(collide->GetContactPoints());
vtkGlyph3D *points = vtkGlyph3D::New();
points->SetInput(pointdata);
points->SetSource(point->GetOutput());
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(collide->GetOutput());
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
(actor1->GetProperty())->BackfaceCullingOn();
actor1->SetUserMatrix(matrix0);
vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInput(collide->GetOutput(1));
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
(actor2->GetProperty())->BackfaceCullingOn();
actor2->SetUserMatrix(matrix1);
vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New();
mapper3->SetInput(points->GetOutput());
vtkActor *actor3 = vtkActor::New();
actor3->SetMapper(mapper3);
(actor3->GetProperty())->SetColor(0,0,0);
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor1);
ren->AddActor(actor2);
//ren AddObserver EndEvent ChangeOrigin
//ren AddActor actor3
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkInteractorStyleJoystickActor *istyle =
vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);
iren->Initialize();
renWin->Render();
iren->Start();
}
http://www.bioengineering-research.com/vtk/vtkCollisionDetectionFilter.htm
Post by Jean-Dominique Barnichon
One of the surface is not a plane, it is a polyplane (i.e. a 2D
(xy) polyline extruded along the z direction.
Jean-Do
Post by Bill Lorensen
If one surface is a plane, you can use ClipPolyData and define an
implicit plane as the clipper.
Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces, each one
being defined as a polydata (actually one surface is a vertical
polyplane, and the other one is a topographical surface).
Such intersection operation is already effective in other
libraries such as CGAL (http://www.cgal.org) and GTS
(http://gts.sourceforge.net).
However, it is still not clear to me which approach i should
follow to perform such an operation with vtk.
Jean-Dominique Barnichon
2006-04-10 21:27:05 UTC
Permalink
To close this discussion, and for the record on the vtkusers list, in
case other people are interested.
Jean-Do
(Thanks Goodwin, and the best for your thesis...)
Post by Goodwin Lawlor
Hi Jean-Do,
- the classes you developed are really great, especially as there's
nothing comparable (as I know at least) in the standard vtk library.
Did you ever consider to make it part of the standard vtk library (I
can hardly believe people at Kitware are not interested)?
I'd have no problem if the class was a part of the standard lib...
though I wouldn't like to commit to long term support of the class.
- what's the deal if I want to develop a commercial application using
your vtkCollisionDetection class?
I'm putting the classes up on sourceforge.net under a BSD licence- "do
whatever you like with the code, free of charge, but don't blame me if
anything goes wrong"
I've got a vtk wrapper class of the RAPID CD library... it would use
more memory (since it has its own data structure for models) but is
probably quicker for large models. I've been meaning to write a quick
report comparing the two classes. I've got a thesis to write, so its
on the backburner...
Cheers anyway, and thanks again
You're welcome.
Regards,
Goodwin
Jean-Do
Post by Goodwin Lawlor
Hi Jean-Do,
I fixed the vtkCollisionDetectionFilter class over the weekend...
there was a check of the inputs that remained from the vtk4.x
version of the class. The updated classes are attached. Its strange
that the tcl test didn't pick up this bug...
The callback is just to print out the number of collisions as text
in the render window- its not really needed.
I tried interactively modifying the spheres' radius, using the right
mouse button, and it worked for me. How were you doing it?
Regards,
Goodwin
It's better now, apart that the GeneratePolydataOutputOn() does
not seem to exist anymore.
Yes - the filter always generates an output now. There's a new
switch GenerateScalarsOn/Off if you want to visualize the
collisions or not
Ok, I got that one
So in the testCollisionDetection sample translated to c++ (see
code in attached file) i commented off this line.
The point is that I now have two error messages when running the
Error in vtkCollisionDetectionFilter, line 150 : index 0 is
out of range in set matrix
Error in vtkCollisionDetectionFilter, line 150 : index 1 is
out of range in set matrix
Maybe this is because I did not translate the callback (as i
didn't know how to write them in c++).
I'll have a look at this
Thanks
Forgot to mention, when i run the test I obtain two spheres,
which radii can be modified interactively, but apparently without
intersection. I attached the c++ file in case you want to test it
yourself.
I guess I'm probably doing something wrong. Any idea?
I'll run it and see what's going on.
Thanks again
Thanks,
Jean-Do
Regards,
Goodwin
Post by Goodwin Lawlor
Hi Jean-Do,
I haven't updated the site... just the classes. I'll put them up
on sourceforge soon. The CD classes are attached.
hth
Goodwin
Post by Jean-Dominique Barnichon
Well,
I'm using vtk5.0.
I've dowloaded again from the bioengineering website, and it
does not seem updated yet.
So yes, I would very much like if you could send me the new
version that is compatible with vtk5.0.
Thanks,
Jean-Do
Post by Goodwin Lawlor
Hi Jean-Do,
What vtk version are you using? I've updated the source files
on the bioengineering website for vtk5.0
The error is due to the old class code not being compatible
with the new pipeline (>vtk4.5 I think).
I'll send the updated class files to you, if you like.
hth
Goodwin
ps I'm updating all the code there soon... probably moving it
to sourceforge.
Post by Jean-Dominique Barnichon
Michael,
thanks for pointing me there.
I gave it a try, but I'm actually stuck.
Config: winXp(SP2) + msvc7.0 + vtk5.0.
So I downloaded everything required from bioengineering web
site (vtkBioeng.zip), ran cmake and eventually built
vtkBioeng library as a shared library (vtkBioeng.dll). So far
so good.
Then I translated most of the testCollisionDetection.tcl
sample given from tcl to c++ (see code below)
When I run it, I end up with an error located at the
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
Trying to debug it, an access violation is reported in the
this->Inputs[0] = NULL;
Apparently, from what I understand, it looks like the array
Inputs[] (inherited from vtkPolyDataSource) is not
initialized (value is 0x00000000).
- did you experience similar problem?
- if no, was it in c++ or in tcl, with which vtk version 4.x or 5.x?
Thanks for helping
Jean-Do
File testCollisionDetection.cpp
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkSphereSource.h"
#include "vtkMatrix4x4.h"
#include "vtkCollisionDetectionFilter.h"
#include "vtkGlyph3D.h"
#include "vtkInteractorStyleJoystickActor.h"
#include "vtkTextActor.h"
int _tmain(int argc, _TCHAR* argv[])
{
vtkSphereSource *sphere0 = vtkSphereSource::New();
sphere0->SetPhiResolution(30);
sphere0->SetThetaResolution(30);
sphere0->SetCenter(-0.7, 0, 0);
sphere0->Update();
vtkSphereSource *sphere1 = vtkSphereSource::New();
sphere1->SetPhiResolution(30);
sphere1->SetThetaResolution(30);
sphere1->Update();
vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
collide->SetInput(0, sphere0->GetOutput());
collide->SetMatrix(0, matrix0);
collide->SetInput(1, sphere1->GetOutput());
collide->SetMatrix(1, matrix1);
collide->SetBoxTolerance(0.0);
collide->SetCellTolerance(0.0);
collide->SetNumberOfCellsPerBucket(2);
//collide->SetCollisionModeToFirstContact();
collide->GeneratePolydataOutputOn();
// collide->AddObserver->EndEvent(cbCollision());
vtkTextActor *txt = vtkTextActor::New();
vtkSphereSource *point = vtkSphereSource::New();
point->SetRadius(0.01);
vtkPolyData *pointdata = vtkPolyData::New();
pointdata->SetPoints(collide->GetContactPoints());
vtkGlyph3D *points = vtkGlyph3D::New();
points->SetInput(pointdata);
points->SetSource(point->GetOutput());
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(collide->GetOutput());
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
(actor1->GetProperty())->BackfaceCullingOn();
actor1->SetUserMatrix(matrix0);
vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInput(collide->GetOutput(1));
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
(actor2->GetProperty())->BackfaceCullingOn();
actor2->SetUserMatrix(matrix1);
vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New();
mapper3->SetInput(points->GetOutput());
vtkActor *actor3 = vtkActor::New();
actor3->SetMapper(mapper3);
(actor3->GetProperty())->SetColor(0,0,0);
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor1);
ren->AddActor(actor2);
//ren AddObserver EndEvent ChangeOrigin
//ren AddActor actor3
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkInteractorStyleJoystickActor *istyle =
vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);
iren->Initialize();
renWin->Render();
iren->Start();
}
http://www.bioengineering-research.com/vtk/vtkCollisionDetectionFilter.htm
Post by Jean-Dominique Barnichon
One of the surface is not a plane, it is a polyplane (i.e.
a 2D (xy) polyline extruded along the z direction.
Jean-Do
Post by Bill Lorensen
If one surface is a plane, you can use ClipPolyData and
define an implicit plane as the clipper.
Bill
Post by Jean-Dominique Barnichon
Dear all,
I need to find the intersection between two surfaces,
each one being defined as a polydata (actually one
surface is a vertical polyplane, and the other one is a
topographical surface).
Such intersection operation is already effective in other
libraries such as CGAL (http://www.cgal.org) and GTS
(http://gts.sourceforge.net).
However, it is still not clear to me which approach i
should follow to perform such an operation with vtk.
Loading...