[vtkusers] RectilinearGrid into vtkContourFilter

ThinkFlow neto at caltech.edu
Thu Aug 29 17:39:09 EDT 2013


Hi,

It was outputting zero points at the end of the contour filter.

Burlen helped me fix it in the end. I needed a SetInputArrayToProcess, and
also my rectilineargrid data was  formatted incorrectly. Since there aren't
many examples of this online, here is my code:

    vtkRectilinearGridReader *reader = vtkRectilinearGridReader::New();

    reader->SetFileName(prefix_suffix);
    reader->Update();

    // Create a grid
    vtkSmartPointer<vtkRectilinearGrid> grid = reader->GetOutput();

    vtkDataArray* dim;

    vtkPointData* pointdata = grid->GetPointData();

    double* range;

    pointdata->GetArray("grad")->GetRange(range);

    vtkContourFilter* contour = vtkContourFilter::New();

    // name of array is "grad"
    contour->SetInputArrayToProcess(0, 0, 0,
vtkDataObject::FIELD_ASSOCIATION_POINTS, "grad");

    // better than setinput
    contour->SetInputConnection(grid->GetProducerPort());

    // woo 50 contours
    contour->GenerateValues(50, range);

    contour->ComputeNormalsOn();

    contour->Update();

    vtkPolyData *smoothed_polys = contour->GetOutput();

    // calc cell normal
    vtkPolyDataNormals *triangleCellNormals= vtkPolyDataNormals::New();

    #if VTK_MAJOR_VERSION <= 5
        triangleCellNormals->SetInput(smoothed_polys);
    #else
        triangleCellNormals->SetInputData(smoothed_polys);   
    #endif

    triangleCellNormals->ComputeCellNormalsOn();
    triangleCellNormals->ComputePointNormalsOff();
    triangleCellNormals->ConsistencyOn();
    triangleCellNormals->AutoOrientNormalsOn();
    triangleCellNormals->Update(); // creates vtkPolyData

    // send the vtkPolyData to the master process
    #if VTK_MAJOR_VERSION <= 5
        procController->Send(triangleCellNormals->GetOutput(), 0, 101);
    #else
        procController->Send(triangleCellNormals->GetOutputPort(), 0, 101);  
    #endif

    vtkPolyDataMapper* contourMapper = vtkPolyDataMapper::New();
    contourMapper->SetInput(triangleCellNormals->GetOutput());

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

    // Create a renderer, render window, and interactor
    vtkRenderer* renderer = vtkRenderer::New();
    vtkRenderWindow *renderWindow = vtkRenderWindow::New();
    vtkRenderWindowInteractor *renderWindowInteractor =
vtkRenderWindowInteractor::New();

    // Add the actors to the scene
    renderWindow->AddRenderer(renderer);
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderer->AddActor(contourActor);

    // Render and interact
    renderWindow->Render();
    renderWindowInteractor->Start();

Thanks!



--
View this message in context: http://vtk.1045678.n5.nabble.com/RectilinearGrid-into-vtkContourFilter-tp5723107p5723148.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list