[vtkusers] Hole on Mesh(stl)

Aleph powerhak at naver.com
Fri Jan 5 00:07:42 EST 2018


Hello everybody,
The reason why i am posting now is because of a problem of making hole.

i thought that, for making hole i would use vtkCylinder(implicit function)
and vtkClipPolyData.
In addition, i wanted to control the position of hole with boxWidget.

I had finished to make boxWidget and it worked well(rotate, translate)
But i couldn't find out how to locate the implicit function(cylinder) to
boxWidget.

i will show you my codes.

-----------------------------------------------------------------------
void VTK_guide::LoadBoxWidgetWithCylinder()
{
   vtkSmartPointer<vtkTransform> t =
       vtkSmartPointer<vtkTransform>::New();

   vtkSmartPointer<vtkCylinder> cyl =
       vtkSmartPointer<vtkCylinder>::New();
   cyl->SetRadius(1);
   cyl->SetTransform(t);
   
   sample->SetSampleDimensions(10, 10, 10);
   sample->SetImplicitFunction(cyl);
   double value = 2.0;
   double xmin = -value, xmax = value, ymin = -value, ymax = value, zmin =
-value, zmax = value;
   sample->SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);
   
   vtkSmartPointer<vtkContourFilter> contours =
       vtkSmartPointer<vtkContourFilter>::New();
   contours->SetInputConnection(sample->GetOutputPort());
   contours->GenerateValues(1, 1, 1);

   vtkSmartPointer<vtkPolyDataMapper> contourMapper =
       vtkSmartPointer<vtkPolyDataMapper>::New();
   contourMapper->SetInputConnection(contours->GetOutputPort());

   vtkSmartPointer<vtkActor> contourActor =
       vtkSmartPointer<vtkActor>::New();
   contourActor->SetMapper(contourMapper);

   boxWidget2->SetInputConnection(contours->GetOutputPort());
   boxWidget2->SetInteractor(mpVtkMainRendering->GetInteractor());
   boxWidget2->SetProp3D(contourActor);
   boxWidget2->SetPlaceFactor(1.25);
   boxWidget2->PlaceWidget();
   boxWidget2->SetHandleSize(0.0025);

   vtkSmartPointer<BoxWidgetCallback> callback =
       vtkSmartPointer<BoxWidgetCallback>::New();
   boxWidget2->AddObserver(vtkCommand::InteractionEvent, callback);
   boxWidget2->On();

   mpVtkMainRendering->GetRenderer()->AddActor(contourActor);
   mpVtkMainRendering->GetInteractor()->Start();
}

------------------------------------------------------------------------------and

void VTK_guide::HoleMaking()
{
   vtkSmartPointer<vtkTransform> trans =
       vtkSmartPointer<vtkTransform>::New();
   trans->Translate(boxWidget2->GetProp3D()->GetPosition());
   trans->Update();

   vtkImplicitFunction *cyl2;
   cyl2 = sample->GetImplicitFunction();
   cyl2->SetTransform(trans);
   cyl2->Modified();

   vtkSmartPointer<vtkClipPolyData> clipper =
       vtkSmartPointer<vtkClipPolyData>::New();
   clipper->SetInputData(mpMeshData->GetPolyDataOutput());
   //clipper->SetClipFunction(sample->GetImplicitFunction());
   clipper->SetClipFunction(cyl2);
   clipper->SetValue(0.0);
   clipper->Update();

   vtkSmartPointer<vtkPolyData> polydata =
       vtkSmartPointer<vtkPolyData>::New();
   polydata = clipper->GetOutput();

   vtkSmartPointer<vtkDataSetMapper> clipMapper =
       vtkSmartPointer<vtkDataSetMapper>::New();
   clipMapper->SetInputData(polydata);

   vtkSmartPointer<vtkActor> clipActor =
       vtkSmartPointer<vtkActor>::New();
   clipActor->SetMapper(clipMapper);
   clipActor->GetProperty()->SetInterpolationToPhong();

   mpVtkMainRendering->GetRenderer()->AddActor(clipActor);
}

Could you please tell me why it doesn't work?
Thank you



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list