Adding a cylinder to a visualization

Here is a program that makes a VTK file that contains a cylinder that you can add to your visualization. You can use VisIt's Transform operator to scale, translate, and rotate the cylinder into the right position for your visualization. I was too lazy to add those features to this small program. You can create a visualization of this cylinder by creating a Pseudocolor plot of the "one" variable, which is a constant node-centered variable. If you make the Pseudocolor plot transparent, the plot will be all the same color and from there, you can edit color tables to make the cylinder be the desired color.

#include <vtkCylinderSource.h>
#include <vtkPolyDataWriter.h>
#include <vtkPointData.h>
#include <vtkFloatArray.h>

int
main(int argc, char *argv[])
{
    // cylinder parameters
    double radius = 1.;
    double h = 1.;

    // Create the cylinder
    vtkCylinderSource *c = vtkCylinderSource::New();
    c->SetCapping(1);
    c->SetRadius(radius);
    c->SetResolution(360); // 1 face per degree
    c->SetCenter(0.,0.,0.);
    c->SetHeight(h);

    // Could add transform code here

    // Add a variable to it so there's something to easily make transparent
    // in a Pseudocolor plot.
    c->Update();
    vtkPolyData *pd = c->GetOutput();
    vtkFloatArray *one = vtkFloatArray::New();
    one->SetNumberOfTuples(pd->GetNumberOfPoints());
    for(int i = 0; i < pd->GetNumberOfPoints(); ++i)
        one->SetTuple1(i, 1.);
    one->SetName("one");
    pd->GetPointData()->AddArray(one);

    // Write out the cylinder
    vtkPolyDataWriter *w = vtkPolyDataWriter::New();
    w->SetInput(pd);
    w->SetFileName("cylinder.vtk");
    w->Update();

    c->Delete();
    w->Delete();

    return 0;
}

Makefile

CXX=g++
CXXFLAGS=-O3
VISITDIR=/path/to/visit
VTKDIR=$(VISITDIR)/vtk/5.0.0c/i386-apple-darwin8
VTKLIBDIR=$(VTKDIR)/lib
MESADIR=$(VISITDIR)/mesa/6.4.2/i386-apple-darwin8
MESALIBDIR=$(MESADIR)/lib
CPPFLAGS=-I. -I$(MESADIR)/include -I$(VTKDIR) -I$(VTKDIR)/Common -I$(VTKDIR)/Filtering -I$(VTKDIR)/Graphics -I$(VTKDIR)/Hybrid -I$(VTKDIR)/IO -I$(VTKDIR)/Imaging -I$(VTKDIR)/Rendering -I/usr/local/include
LDFLAGS=-L$(VTKDIR)/lib -L$(MESADIR)/lib
IOLIBS=-lvtkIO -lvtkpng -lvtktiff -lvtkjpeg -lvtkDICOMParser -lvtkzlib -lvtkexpat -lvtkMPEG2Encode
LIBS=-lvtkCommon -lvtkGraphics -lvtkRendering -lvtkImaging -lvtkGenericFiltering -lvtkFiltering $(IOLIBS) -lvtkfreetype -lvtkftgl -lvtksys -lMesaGL -lOSMesa -framework OpenGL

SRC=main.cpp
OBJ=$(SRC:.cpp=.o)

all: cylinder

cylinder: $(OBJ)
	$(CXX) -o cylinder $(OBJ) $(CXXFLAGS) $(LDFLAGS) $(LIBS)

clean:
	$(RM) $(OBJ) cylinder 

.cpp.o:
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<