Mercurial > hg > kwantix
view vtk/terrain_test.cpp @ 24:ad9e3d28ce9b
Implement op<< for bvp::interpolator
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Fri, 21 Aug 2009 16:19:58 -0500 |
parents | |
children | 6c6003bcad16 |
line wrap: on
line source
#include <vtkPoints.h> #include <vtkPointData.h> #include <vtkDelaunay2D.h> #include <vtkLookupTable.h> #include <vtkPolyData.h> #include <vtkPolyDataNormals.h> #include <vtkPolyDataMapper.h> #include <vtkWarpScalar.h> #include <vtkCamera.h> #include <vtkActor.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkRenderer.h> #include <vtkInteractorStyleTerrain.h> #include <vtkSmartPointer.h> #include <vtkDoubleArray.h> void TriangulateTerrain(); int main (int argc, char ** argv) { TriangulateTerrain(); return 0; } void TriangulateTerrain() { vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkDoubleArray> scalars = vtkSmartPointer<vtkDoubleArray>::New(); unsigned int GridSize = 50; for(double x = -3; x < 3; x += 6.0/GridSize) { for(double y = -3; y < 3; y += 6.0/GridSize) { double z = sin(x*y); vtkIdType idx = points->InsertNextPoint(x, y, z); scalars -> InsertTuple(idx, &z); } } //add the grid points to a polydata object vtkPolyData* polydata = vtkPolyData::New(); polydata->SetPoints(points); polydata->GetPointData() -> SetScalars(scalars); //triangulate the grid points vtkDelaunay2D* delaunay = vtkDelaunay2D::New(); delaunay->SetInput(polydata); delaunay->Update(); //Normals for Gourad shading vtkPolyDataNormals* normals = vtkPolyDataNormals::New(); normals -> SetInputConnection(delaunay ->GetOutputPort() ); normals -> SetFeatureAngle(60); //Set the colours for the rendering vtkLookupTable* lut = vtkLookupTable::New(); lut -> SetHueRange(0.66667, 0.0); lut -> SetNumberOfColors(256); lut -> SetRampToLinear(); lut -> Build(); // map the contours to graphical primitives vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New(); contMapper->SetInput(normals -> GetOutput() ); contMapper->SetScalarRange(0,1); contMapper->SetLookupTable(lut); contMapper->ImmediateModeRenderingOn(); // create an actor for the contours vtkActor *contActor = vtkActor::New(); contActor->SetMapper(contMapper); // a renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // an interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); //The style vtkInteractorStyleTerrain *terrain_style = vtkInteractorStyleTerrain::New(); // add the actors to the scene ren1->SetBackground(0.6,0.6,0.6); ren1->GetActiveCamera()->SetViewUp(0,0,1); ren1->GetActiveCamera()->SetParallelProjection(1); ren1->AddActor(contActor); iren -> SetInteractorStyle(terrain_style); ren1->ResetCamera(); // render an image (lights and cameras are created automatically) renWin->Render(); // begin mouse interaction iren->Start(); }