[vtkusers] Re:Displaying node numbers of a mesh
Yixun Liu
yxliu at fudan.edu.cn
Sat Jul 24 23:25:51 EDT 2004
Hi,
An example about displaying the cell id and point id of a sphere is shown below.
Hope it help!
Yixun Liu
//test VTK about Volume Render
//#include <STDIO.H>
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataNormals.h"
#include "vtkContourFilter.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkUnsignedCharArray.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkTiFFReader.h"
#include "vtkImageViewer.h"
#include "vtkImageFlip.h"
#include "vtkStructuredPointsReader.h"
#include "vtkImageCast.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkmath.h"
#include "vtkDelaunay2D.h"
#include "vtkExtractEdges.h"
#include "vtkTubeFilter.h"
#include "vtkSphereSource.h"
#include "vtkGlyph3D.h"
#include "vtkDelaunay3D.h"
#include "vtkShrinkFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkUnstructuredGrid.h"
#include "vtkCellTypes.h"
#include "vtkTetra.h"
#include "vtkIdList.h"
#include "vtkGenericCell.h"
#include "vtkMeshQuality.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkActor2D.h"
#include "vtkIdFilter.h"
#include "vtkSelectVisiblePoints.h"
#include "vtkLabeledDataMapper.h"
#include "vtkCellCenters.h"
#include "vtkTextProperty.h"
int main(int argc, char *argv[])
{
//# Create a selection window. We will display the point and cell ids that
//# lie within this window.
int xmin = 200;
int xLength = 100;
int xmax = xmin + xLength;
int ymin = 200;
int yLength = 100;
int ymax = ymin + yLength;
vtkPoints *pts = vtkPoints::New();
pts->InsertPoint(0, xmin, ymin, 0);
pts->InsertPoint(1, xmax, ymin, 0);
pts->InsertPoint(2, xmax, ymax, 0);
pts->InsertPoint(3, xmin, ymax, 0);
vtkCellArray *rect = vtkCellArray::New();
rect->InsertNextCell(5);
rect->InsertCellPoint(0);
rect->InsertCellPoint(1);
rect->InsertCellPoint(2);
rect->InsertCellPoint(3);
rect->InsertCellPoint(0);
vtkPolyData *selectRect = vtkPolyData::New();
selectRect->SetPoints(pts);
selectRect->SetLines(rect);
vtkPolyDataMapper2D *rectMapper = vtkPolyDataMapper2D::New();
rectMapper->SetInput(selectRect);
vtkActor2D *rectActor = vtkActor2D::New();
rectActor->SetMapper(rectMapper);
//# Create a sphere and its associated mapper and actor.
vtkSphereSource *sphere = vtkSphereSource::New();
vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInput(sphere->GetOutput());
sphereMapper->GlobalImmediateModeRenderingOn();
vtkActor *sphereActor = vtkActor::New();
sphereActor->SetMapper(sphereMapper);
//# Generate data arrays containing point and cell ids
vtkIdFilter *ids = vtkIdFilter::New();
ids->SetInput(sphere->GetOutput());
ids->PointIdsOn();
ids->CellIdsOn();
ids->FieldDataOn();
//# Create the renderer here because vtkSelectVisiblePoints needs it.
vtkRenderer *ren1 = vtkRenderer::New();
//# Create labels for points
vtkSelectVisiblePoints *visPts = vtkSelectVisiblePoints::New();
visPts->SetInput(ids->GetOutput());
visPts->SetRenderer(ren1);
visPts->SelectionWindowOn();
visPts->SetSelection(xmin, xmax, ymin, ymax);
//# Create the mapper to display the point ids. Specify the
//# format to use for the labels. Also create the associated actor.
vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
ldm->SetInput(visPts->GetOutput());
ldm->SetLabelFormat("%g");
ldm->SetLabelModeToLabelFieldData();
vtkActor2D *pointLabels = vtkActor2D::New();
pointLabels->SetMapper(ldm);
//# Create labels for cells
vtkCellCenters *cc = vtkCellCenters::New();
cc->SetInput(ids->GetOutput());
vtkSelectVisiblePoints *visCells = vtkSelectVisiblePoints::New();
visCells->SetInput(cc->GetOutput());
visCells->SetRenderer(ren1);
visCells->SelectionWindowOn();
visCells->SetSelection(xmin, xmax, ymin, ymax);
//# Create the mapper to display the cell ids. Specify the
//# format to use for the labels. Also create the associated actor.
vtkLabeledDataMapper *cellMapper = vtkLabeledDataMapper::New();
cellMapper->SetInput(visCells->GetOutput());
cellMapper->SetLabelFormat("%g");
cellMapper->SetLabelModeToLabelFieldData();
cellMapper->GetLabelTextProperty()->SetColor(0, 1, 0);
vtkActor2D *cellLabels = vtkActor2D::New();
cellLabels->SetMapper(cellMapper);
//# Create the RenderWindow and RenderWindowInteractor
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
//# Add the actors to the renderer; set the background and size;
ren1->AddActor(sphereActor);
ren1->AddActor2D(rectActor);
ren1->AddActor2D(pointLabels);
ren1->AddActor2D(cellLabels);
ren1->SetBackground(1, 1, 1);
renWin->SetSize(500, 500);
// renWin->Render();
iren->Initialize();
iren->Start();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040725/fcdbbde5/attachment.htm>
More information about the vtkusers
mailing list