[vtkusers] Extract isosurfaces from a point cloud polydata with contourfilter
Bill Lorensen
bill.lorensen at gmail.com
Sun Jan 18 07:47:26 EST 2015
VertexGlyphFilter generates vertex cells. These cells are points. You
cannot contour vertices. You need to create cells that have area or
volume. In your case, it your points are defined on a uniform lattice,
you can create an ImageData that you can contour.
On Sun, Jan 18, 2015 at 7:01 AM, Daniel Coelho <1danielcoelho at gmail.com> wrote:
> Hello everyone!
>
> I have a point cloud in the form of a polydata, where I build vertices with
> vtkVertexGlyphFilter.
>
> That polydata has pointdata with scalars ranging from 0 to 255, and I'm
> trying to use vtkContourFilter to extract 5 planes, that ideally should cut
> through the data at the values corresponding to each plane.
>
> Just to make it clearer: The expected output should be 5 parallel planes,
> equidistant to each other, where each is an isosurface of a certain value,
> with respect to the scalars of the pointcloud.
>
> The problem is: I get absolutely no output. No points, no cell, nada. I've
> looked at every example I could find and the mailing list archive, but
> couldn't pinpoint the problem.
>
> Here is a short compilable example that shows this problem. You can also see
> outputs from print statements as comments:
> OBS: I use VTK 5.8 for some reasons, this is non-negotiable
>
> #include <vtkSmartPointer.h>
>
> #include <vtkContourFilter.h>
>
> #include <vtkTypeUInt8Array.h>
>
> #include <vtkVertexGlyphFilter.h>
>
> #include <vtkPolyDataMapper.h>
>
> #include <vtkActor.h>
>
> #include <vtkRenderer.h>
>
> #include <vtkRenderWindow.h>
>
> #include <vtkRenderWindowInteractor.h>
>
>
> #define VTK_NEW(type, instance) \
>
> ; \
>
> vtkSmartPointer<type> instance = vtkSmartPointer<type>::New();
>
>
> int main(int argc, char *argv[]) {
>
>
> VTK_NEW(vtkPoints, points);
>
> points->Allocate(100 * 100 * 100);
>
>
> VTK_NEW(vtkTypeUInt8Array, data_array);
>
> data_array->Allocate(100 * 100 * 100);
>
>
> for (int x = 0; x < 100; x++) {
>
> for (int y = 0; y < 100; ++y) {
>
> for (int z = 0; z < 100; ++z) {
>
> points->InsertNextPoint(x, y, z);
>
> data_array->InsertNextValue(z % 256);
>
> }
>
> }
>
> }
>
>
> VTK_NEW(vtkPolyData, polydata);
>
> polydata->SetPoints(points);
>
> polydata->GetPointData()->SetScalars(data_array);
>
>
> VTK_NEW(vtkVertexGlyphFilter, glyph_filter);
>
> glyph_filter->SetInput(polydata);
>
> glyph_filter->Update();
>
> glyph_filter->GetOutput()->Print(std::cout << "Glyph filter: \n");
>
> //Output here:
>
> //Number Of Points: 1000000
>
> //Number Of Cells: 1000000
>
> //Bounds look good, all good
>
>
> VTK_NEW(vtkContourFilter, cont_filt);
>
> cont_filt->SetInputConnection(glyph_filter->GetOutputPort());
>
> double scalarRange[2];
>
> polydata->GetPointData()->GetScalars()->GetRange(scalarRange);
>
> cont_filt->GenerateValues(5, scalarRange[0], scalarRange[1]);
>
> cont_filt->Update();
>
>
> // Print the contours
>
> int num_contours = cont_filt->GetNumberOfContours();
>
> double cont_values[num_contours];
>
> cont_filt->GetValues(cont_values);
>
> std::cout << "Contours: ";
>
> for (int var = 0; var < num_contours; ++var) {
>
> std::cout << cont_values[var] << " ";
>
> }
>
> std::cout << std::endl;
>
> //Output here:
>
> //Contours: 0 24.75 49.5 74.25 99
>
>
> cont_filt->GetOutput()->Print(std::cout << "Contour filter: \n");
>
> //Output here:
>
> //No points, no cells, default bounds, no nothing
>
>
> VTK_NEW(vtkPolyDataMapper, mapper);
>
> mapper->SetInputConnection(cont_filt->GetOutputPort());
>
> mapper->SetScalarVisibility(1);
>
>
> VTK_NEW(vtkActor, actor);
>
> actor->SetMapper(mapper);
>
>
> VTK_NEW(vtkRenderer, renderer);
>
> renderer->AddActor(actor);
>
>
> VTK_NEW(vtkRenderWindow, render_window)
>
> render_window->AddRenderer(renderer);
>
> render_window->SetSize(600, 600);
>
>
> VTK_NEW(vtkRenderWindowInteractor, interactor);
>
> interactor->SetRenderWindow(render_window);
>
>
> renderer->ResetCamera();
>
> render_window->Render();
>
> interactor->Start();
>
> }
>
>
> _______________________________________________
> 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:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
--
Unpaid intern in BillsBasement at noware dot com
More information about the vtkusers
mailing list