[vtkusers] Contours are not displayed..!! Why..??

David Doria daviddoria+vtk at gmail.com
Thu Dec 31 08:57:44 EST 2009


On Thu, Dec 31, 2009 at 4:48 AM, Rakesh Patil <rakeshthp at in.com> wrote:
> Hello,
>
> I'm very new to VTK. I went through few materials and I have successfully
> displayed a mesh (triangular grid), and scattered points using
> vtkUnstructuredGrid. Now I want to display line contours. I came to know
> that it can be done using vtkContourFilter class. I have written a small
> code. I guess it is correct. but Am not able to get the contours on the
> render window. Here is my code:
>
> vtkPoints *pts = vtkPoints::New();
> pts->SetData(scatter_data); // scatter_data is an instance of vtkDoubleArray
> with three components
>
> unsigned int num_ids = scatter_data->GetNumberOfTuples();
>
> vtkPolyVertex *poly = vtkPolyVertex::New();
> poly->GetPointIds()->SetNumberOfIds(num_ids);
>
> for ( unsigned int i = 0; i < num_ids; i++ )
> poly->GetPointIds()->SetId(i,i);
>
> vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
> ugrid->Allocate(1);
> ugrid->InsertNextCell (poly->GetCellType(), poly->GetP ointIds());
> ugrid->SetPoints(pts);
>
> vtkDelaunay2D *del = vtkDelaunay2D::New();
> del->SetInput(ugrid);
> del->SetTolerance(0.001);
>
> vtkContourFilter *cf = vtkContourFilter::New();
> cf->SetInputConnection(del->GetOutputPort());
> cf->GenerateValues(10, -5, 20);
>
> vtkPolyDataMapper *map = vtkPolyDataMapper::New();
> map->SetInputConnection( cf->GetOutputPort() );
> map->SetScalarRange(-5, 20);
>
> vtkActor *act = vtkActor::New();
> act->SetMapper(map);
>
> // pRenderer is an instance of vtkRenderer which is declared and initialized
> in the main function.
> pRenderer->AddActor(act);
> pRenderer->ResetCamera();
>
> THere is no syntax or compile time error shown. What may be wrong here..??
> in cf->GenerateValues(), function what values need to be passed..??
>
> Thanks in advance.
>
>

Welcome to VTK. I believe the problem may be you need to call Update()
on the vtkContourFilter:


vtkContourFilter *cf = vtkContourFilter::New();
cf->SetInputConnection(del->GetOutputPort());
cf->GenerateValues(10, -5, 20);
cf->Update();

Also, you should always use smart pointers:
#include <vtkSmartPointer.h>
vtkSmartPointer<vtkContourFilter> cf = vtkSmartPointer<vtkContourFilter>::New();

instead of

vtkContourFilter *cf = vtkContourFilter::New();

Doing this will allow you to remove all of your calls to Delete() for
VTK objects.

If updating the contourFilter does not fix the problem, can you
provide a small data file and the code you're using to read it
(scatter_data).

One more thing - I think if you're going to post 30 lines of code, you
might as well post 40 including the headers etc so we can simply copy,
paste and compile to see what is going on.

Hope that helps!

David



More information about the vtkusers mailing list