[vtkusers] Intersection of cylinders
Quang Tran
quangt.itbk at gmail.com
Wed Nov 16 10:57:22 EST 2011
Hello Peter,
You can do it as the following code:
// Set up a transformation for the first cylinder (for intersection
testing purpose)
vtkSmartPointer<vtkTransform> pTrans =
vtkSmartPointer<vtkTransform>::New();
pTrans->RotateZ(90);
vtkSmartPointer<vtkCylinder> pCylinder1 =
vtkSmartPointer<vtkCylinder>::New();
pCylinder1->SetCenter(0, 0, 0);
pCylinder1->SetRadius(30);
pCylinder1->SetTransform(pTrans);
// Sampling for the purpose to get the surface of cylinder1 later
vtkSmartPointer<vtkSampleFunction> cylinder1Sample =
vtkSmartPointer<vtkSampleFunction>::New();
cylinder1Sample->SetImplicitFunction(pCylinder1);
cylinder1Sample->SetModelBounds(-200, 200, -200, 200, -200, 200);
cylinder1Sample->SetSampleDimensions(100, 100, 100);
cylinder1Sample->ComputeNormalsOff();
cylinder1Sample->Update();
vtkSmartPointer<vtkContourFilter> pContourFilter =
vtkSmartPointer<vtkContourFilter>::New();
pContourFilter->SetInput(cylinder1Sample->GetOutput());
pContourFilter->SetValue(0, 0.0);
pContourFilter->Update();
vtkSmartPointer<vtkPolyData> pCylinderSurf =
vtkSmartPointer<vtkPolyData>::New();
pCylinderSurf = pContourFilter->GetOutput(); // surface of cylinder1
// Cylinder2 working with the role as an implicit function
vtkSmartPointer<vtkCylinder> pCylinder2 =
vtkSmartPointer<vtkCylinder>::New();
double aCenter[3];
pCylinder2->SetRadius(30);
// Clip cylinder1 here...
vtkSmartPointer<vtkClipPolyData> clipper =
vtkSmartPointer<vtkClipPolyData>::New();
clipper->SetInput(pCylinderSurf);
clipper->SetClipFunction(pCylinder2);
clipper->GenerateClipScalarsOn();
clipper->GenerateClippedOutputOn();
clipper->SetValue(0.0);
vtkSmartPointer<vtkPolyData> intersectSurf =
vtkSmartPointer<vtkPolyData>::New();
intersectSurf = clipper->GetClippedOutput(); // ==> this result is what
you need
--
/Quang
2011/11/6 Peter <peter-dpl at pre-dev.de>
> Hi Quang,
>
> thanks for your answer and sorry for my delayed response. I have to admit
> that I'm new to vtk so please apologize, that I don't understand everything.
>
> Do you mean, that I have to model both cylinders as vtkCylinder and also
> as vtkCylinderSource? And by using the vtkClipPolyData I will get the
> "correct" data I need as input for vtkImplicitBoolean?
>
> Greetings,
> Peter
>
> Am 01.11.2011 um 03:03 schrieb Quang Tran:
>
> > Hi,
> > You should use vtkImplicitBoolean and vtkClipPolyData to do this task.
> One of cylinder must be modeling to implicit function (you should use
> vtkCylinder and make any transform if necessary), set this implicit
> function as an input of the clipper (vtkClipPolydata), see SetClipFunction;
> the other cylinder is input parameter of SetInput function of clipper.
> After that you will have a result of this clipper as vtkPolyData. I think
> this result is what you need.
> >
> > You should use vtkCylinder rather than vtkCylinderSource because
> vtkCylinder is an implicit function and can use for clipping.
> >
> > /Quang
> >
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111116/71fa7ba7/attachment.htm>
More information about the vtkusers
mailing list