[vtkusers] Extracting a sphere with vtkSphereWidget
TJ Corona
tj.corona at kitware.com
Tue Jun 5 08:28:33 EDT 2018
Hello Tomas,
> I'm quite surprised by the lack of information to learn this tool.
There are quite a few sources information out there on how to use VTK: a wiki <https://www.vtk.org/Wiki/VTK>, a user’s guide <https://www.kitware.com/products/books/VTKUsersGuide.pdf>, a textbook <https://www.kitware.com/products/books/VTKTextbook.pdf>, generated documentation <https://www.vtk.org/doc/release/7.1/html/>, and archives of this mailing list <https://vtk.markmail.org/> to name a few.
> My task is to extract a sphere from a model using vtkSphereWidget and visualize its scalar atrribute distribution using vtkGlyphs.
So, you have a dataset and you wish to clip a sphere from it and draw glyphs on this sphere’s surface? There are several ways you could try this, but here’s one off the top of my head: import your dataset, construct a sphere source, use vtkProbeFilter to sample your first dataset onto your sphere, and then glyph the resulting fields on your sphere polydata. You probably could use vtkCutter to accomplish this as well. Good luck, and welcome to VTK!
Sincerely,
T.J.
> On Jun 5, 2018, at 2:59 AM, TomasKiniulis <tkiniulis at gmail.com> wrote:
>
> Hey folks, have a course in university to study The Visualization Toolkit. I'm a complete newbie and I'm quite surprised by the lack of information to learn this tool. So I hope you can help me here. My task is to extract a sphere from a model using vtkSphereWidget and visualize its scalar atrribute distribution using vtkGlyphs. How can I use a vtkSphereWidget to extract a sphere? Do I need to create a sphere that follows around the widget? Any examples you could suggest of such task? Found this useful example, but it's using a plane to cut. How would I use this with a sphere? https://www.vtk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/Cutter This is my messy code, my attempt here was to make box cut instead of a plane one. But instead it throws me an error that "there is no suitable conversion function from "vtkSmartPointer to "vtkImplicitFunction *" exists. //Cutter code #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class SphereCallback : public vtkCommand { public: static SphereCallback *New() { return new SphereCallback; } SphereCallback() {} virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkSphereWidget *sphereWidget = reinterpret_cast<vtkSphereWidget*>(caller); double center[3]; sphereWidget->GetCenter(center); std::cout << "Center: " << center[0] << " " << center[1] << " " << center[2] << std::endl; } }; int main(int, char *[]) { //nuskaitymas vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName("Models\\carotid.vtk"); reader->Update(); vtkSmartPointer carotidMapper = vtkSmartPointer::New(); carotidMapper->SetInputConnection(reader->GetOutputPort()); //Create carotid actor vtkSmartPointer carotidActor = vtkSmartPointer::New(); carotidActor->GetProperty()->SetOpacity(0.5); carotidActor->SetMapper(carotidMapper); //Creating plane to cut this majestic peace of model vtkSmartPointer sphereC = vtkSmartPointer::New(); sphereC->SetXLength(40); sphereC->SetYLength(30); sphereC->SetZLength(20); sphereC->SetOrigin(20, 0, 0); // Create carotid cutter vtkSmartPointer cutterC = vtkSmartPointer::New(); cutterC->SetCutFunction(sphereC); cutterC->SetInputConnection(reader->GetOutputPort()); cutterC->Update(); vtkSmartPointer cutterMapperC = vtkSmartPointer::New(); cutterMapperC->SetInputConnection(cutterC->GetOutputPort()); // vtkSmartPointer cube = vtkSmartPointer::New(); cube->SetXLength(40); cube->SetYLength(30); cube->SetZLength(20); vtkSmartPointer cubeMapper = vtkSmartPointer::New(); cubeMapper->SetInputConnection(cube->GetOutputPort()); // Create a plane to cut,here it cuts in the XZ direction (xz normal=(1,0,0);XY =(0,0,1),YZ =(0,1,0) vtkSmartPointer plane = vtkSmartPointer::New(); plane->SetOrigin(10, 0, 0); plane->SetNormal(1, 0, 0); // Create cutter vtkSmartPointer cutter = vtkSmartPointer::New(); cutter->SetCutFunction(plane); cutter->SetInputConnection(cube->GetOutputPort()); cutter->Update(); vtkSmartPointer cutterMapper = vtkSmartPointer::New(); cutterMapper->SetInputConnection(cutter->GetOutputPort()); // Create plane actor vtkSmartPointer planeActor = vtkSmartPointer::New(); planeActor->GetProperty()->SetColor(1.0, 1, 0); planeActor->GetProperty()->SetLineWidth(2); planeActor->SetMapper(cutterMapper); //Create second plane actor vtkSmartPointer planeActor2 = vtkSmartPointer::New(); planeActor2->GetProperty()->SetColor(1.0, 1, 0); planeActor2->GetProperty()->SetLineWidth(2); planeActor2->SetMapper(cutterMapper2); //Create carotid actor vtkSmartPointer carotidPlaneActor = vtkSmartPointer::New(); carotidPlaneActor ->GetProperty()->SetColor(1.0, 1, 0); carotidPlaneActor->GetProperty()->SetLineWidth(2); carotidPlaneActor->SetMapper(cutterMapperC); // Create cube actor vtkSmartPointer cubeActor = vtkSmartPointer::New(); cubeActor->GetProperty()->SetColor(0.5, 1, 0.5); cubeActor->GetProperty()->SetOpacity(0.5); cubeActor->SetMapper(cubeMapper); // Create renderers and add actors of plane and cube vtkSmartPointer renderer = vtkSmartPointer::New(); renderer->AddActor(planeActor); //display the rectangle resulting from the cut renderer->AddActor(cubeActor); //display the cube renderer->AddActor(carotidActor); //display carotid renderer->AddActor(planeActor2); //display rectangle of second cut renderer->AddActor(carotidPlaneActor); //display rectangle of carotid cut // Add renderer to renderwindow and render vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->AddRenderer(renderer); //Sphere widget interactor // An interactor vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); vtkSmartPointer sphereWidget = vtkSmartPointer::New(); sphereWidget->SetInteractor(renderWindowInteractor); sphereWidget->SetRepresentationToWireframe(); sphereWidget->SetProp3D(carotidActor); sphereWidget->SetPlaceFactor(0.5); sphereWidget->PlaceWidget(); vtkSmartPointer cutter2 = vtkSmartPointer::New(); cutter2->SetCutFunction(sphereWidget); cutter2->SetInputConnection(cube->GetOutputPort()); cutter2->Update(); vtkSmartPointer cutterMapper2 = vtkSmartPointer::New(); cutterMapper2->SetInputConnection(cutter2->GetOutputPort()); sphereWidget->SetInteractor(renderWindowInteractor); sphereWidget->SetRepresentationToSurface(); vtkSmartPointer sphereCallback = vtkSmartPointer::New(); sphereWidget->AddObserver(vtkCommand::InteractionEvent, sphereCallback); renderWindow->SetSize(600, 600); renderWindowInteractor->SetRenderWindow(renderWindow); renderer->SetBackground(0, 0, 0); renderWindow->Render(); //sphere widget interactor renderWindowInteractor->Initialize(); renderWindow->Render(); sphereWidget->On(); renderWindowInteractor->Start(); return EXIT_SUCCESS; } Any suggestions would be highly appreciated.
> Sent from the VTK - Users mailing list archive <http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180605/229cf28b/attachment.html>
More information about the vtkusers
mailing list