[vtkusers] Filter update does not work.Easy mistake? (samplecode with cell normals)

David Doria daviddoria at gmail.com
Fri Jun 12 10:27:24 EDT 2009


On Fri, Jun 12, 2009 at 8:17 AM, vtklearny <msjean at gmx.de> wrote:

>
> Hello there,
>
> I just have started learning about vtk.
> Please have a look at this code and tell me what I'm doing wrong here.
> Thanks a lot
>
> vtkLearny
>
>
> Objectives:
> 1. load *.vtk //works
> 2. install normalFilter //computes normal data
> 3. change point data //works
> 4. filter update (recompute normals)// seems not to work
> 5. render //only original data is shown,not even points moved
> 6. enjoy the look in wireframe and surface mode  //far from it
> -------------------------------------
>

Your first few lines seem a bit odd to me. I generally update the reader
before I get it's output:

    vtkSmartPointer<vtkPolyDataReader> reader =
vtkSmartPointer<vtkPolyDataReader>::New();
    const char* filename="cube.vtk";
    reader->SetFileName(filename);
    reader->Update();
    vtkPolyData* polydata=reader->GetOutput();

I think it gets done automatically when you use the next filter, but I'd
suppose it's good practice to do it like this - can someone else let us know
if that's wrong?

You can update the points without getting a new instance of the vtkPoints or
"MappedPolyData" pointers, like this (operating directly on the original
data):

    vtkSmartPointer<vtkPolyDataReader> reader =
vtkSmartPointer<vtkPolyDataReader>::New();
    const char* filename="cube.vtk";
    reader->SetFileName(filename);
    reader->Update();
    vtkPolyData* polydata=reader->GetOutput();

    vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
    Mapper->ScalarVisibilityOff();
    Mapper->SetInput(polydata);

    vtkPoints* Points=polydata->GetPoints();
        unsigned int numOfMovedPoints=Points->GetNumberOfPoints();
//this just extends
        for (unsigned int i=0;i<numOfMovedPoints;i++)
    {
                           double point[3];
               Points->GetPoint(i,point);
        point[0] = point[0] * 1.6;
        point[1] = point[1] * 0.8;
        point[2] = point[2] * 0.91;
               Points->SetPoint(i,point);
        }

I have removed everything relating to the normals. I'm not sure how you are
expecting to see the normals in this example? Maybe you can be a bit more
clear on what you expect to see at each step?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090612/8f2c0476/attachment.htm>


More information about the vtkusers mailing list