[vtkusers] Help changing view of structured grid

Lubos Brieda lbrieda at yahoo.com
Fri Dec 30 16:56:52 EST 2011


Heath,

vtkOutlineFilter will give you the outline, i.e. the bounding box for the mesh. To show the structured grid as a wireframe, simply do the following:

mapper->SetInputConnection(structuredGrid->GetProducerPort());
  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetRepresentationToWireframe();


The default representation is surface.


Also, under vtkStructuredGrid at http://www.vtk.org/Wiki/VTK/Examples/Cxx you will find few additional examples for visualizing structured grids.

--
Lubos Brieda
particleincell.com



________________________________
 From: Heath Johnson <heathbjohnson at gmail.com>
To: vtkusers at vtk.org 
Sent: Friday, December 30, 2011 3:35 PM
Subject: [vtkusers] Help changing view of structured grid
 
I am getting started with vtk-5.6 and am trying to make a very simple
example problem with a structured grid which can be viewed in
different ways - outline of edges, wireframe of connected points, and
simply the points themselves.  I started from the example problem
here:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/StructuredGrid/VisualizeStructuredGrid

The code below displays the outline of the structured grid (using
vtkStructuredGridOutlineFilter) but I am unable to update the view to
show the wireframe or points.  I can follow other examples which show
only the points or the wireframe, but I want to be able to change how
a structured grid is viewed.  I know I am missing something about how
VTK works, but I cannot figure out how to do it correctly.  Can
somebody please help?

------------------------------------
#include <vtkSmartPointer.h>
#include <vtkStructuredGrid.h>
#include <vtkMath.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkStructuredGridOutlineFilter.h>

int main(int, char *[])
{
  // Create a grid
  vtkSmartPointer<vtkStructuredGrid> structuredGrid =
    vtkSmartPointer<vtkStructuredGrid>::New();

  vtkSmartPointer<vtkPoints> points =
    vtkSmartPointer<vtkPoints>::New();
  unsigned int numi = 3;
  unsigned int numj = 5;
  unsigned int numk = 4;

  for(unsigned int k = 0; k < numk; k++)
    {
    for(unsigned int j = 0; j < numj; j++)
      {
      for(unsigned int i = 0; i < numi; i++)
        {
        points->InsertNextPoint(i, j, k);
        }
      }
    }

  //specify the dimensions of the grid
  structuredGrid->SetDimensions(numi, numj, numk);
  structuredGrid->SetPoints(points);

  std::cout << "There are " << structuredGrid->GetNumberOfPoints() <<
" points." << std::endl;
  std::cout << "There are " << structuredGrid->GetNumberOfCells() << "
cells." << std::endl;

  vtkSmartPointer<vtkStructuredGridOutlineFilter> outlineFilter =
    vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
  outlineFilter->SetInputConnection(structuredGrid->GetProducerPort());
  outlineFilter->Update();

  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(outlineFilter->GetOutputPort());
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  // Visualize
  vtkSmartPointer<vtkRenderer> renderer =
      vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(actor);

  renderWindow->Render();

  // --- Everything above is from the example.
  // --- The commands below are what I am trying to do ---

  // Change how structured grid is viewed

  // -- View grid as wireframe between connected points
  sleep(2);
  std::cout << "Changing to surface representation" << std::endl;
  actor->GetProperty()->SetRepresentationToSurface();
  renderWindow->Render();

  // View grid as points only
  sleep(2);
  std::cout << "Changing to points representation" << std::endl;
  actor->GetProperty()->SetRepresentationToPoints();
  renderWindow->Render();

  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}
------------------------------------
_______________________________________________
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

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111230/90b4c066/attachment.htm>


More information about the vtkusers mailing list