C++ with VTK
/*****************************************************************************
* Suo Xiaoyuan
* CSC 6730 Spring 2005 TTh 1445 - 1630 Ying Zhu
* Project 1
* Turnin Date: 2005-March-31
* Filename: project1.cxx
*
* Title: Crater Lake and Mt. St. Helens Visualization
*
* Program Description: This is the main program file for the visualization.
* It will be responsible for setting up the UI and calling on the other
* classes to perform the necessary actions.
*
* About the visualization: This program will allow the user to visualize two
* images. One is of Mt. St. Helens and the other is of Crater Lake (in the
* State of Oregon). There will be two visualizations that the user can
* perform.
*
* The first is a 3D height field. This will allow the user to see the
* landscape in 3D. There are three ways this can be presented: grayscale
* elevation, color map, and texture map.
*
* The second style will be done with contour lines. There will be 4 2D
* contour lines in 3D space. The user will be able to set the contour values
* with a slider (one slider for each color). This will allow the user to
* limit the range of data.
*
****************************************************************************/
/* VTK Includes */
//#include <iostream.h>
#include
"vtkActor.h"#include
"vtkCamera.h"#include
"vtkPNGReader.h"#include
"vtkPolyDataMapper.h"#include
"vtkRenderer.h"#include
"vtkRenderWindow.h"#include
"vtkImageActor.h"#include
"vtkImageShiftScale.h"#include
"vtkImageLuminance.h"#include
"vtkRenderWindowInteractor.h"#include
"vtkInteractorStyleTrackballCamera.h"#include
"vtkWarpScalar.h"#include
"vtkImageDataGeometryFilter.h"#include
"vtkWindowLevelLookupTable.h"#include
"vtkPointSet.h"#include
"vtkImageShrink3D.h"#include
"vtkTexture.h"#include
"vtkTextureMapToPlane.h"#include
"vtkLookupTable.h"#include
<vtkPlaneSource.h>/*
* Setup the filenames that will be used: these will be global constants.
* Note: The files must exist within the current working directory.
*/
/*main funtion*/
int
main ( int argc, char *argv[] ) { int grayScale = 1.0; int hueScale = 1.0; static char crater_elevation[] = "crater_elevation.PNG"; static char helens_elevation[] = "helens_elevation.PNG"; static char crater_texture[] = "Crater_Lake_texture.PNG"; static char helens_texture[] = "helens_texture.PNG"; /** Create Renderer and Render Window. Add Renderer to Render Window
*/
cout << "@@@NOTICE: this program is pretty fragile, don't test it with "
<< "fancy input, integer only, please"<< endl;
cout << "please enter the gray scale: "<< endl;
cin >> grayScale;
cout << "please enter the hue scale: "<< endl;
cin >> hueScale;
vtkRenderWindow *renwin = vtkRenderWindow::New();
vtkRenderer *ren1 = vtkRenderer::New ();
/*read in the texture*/vtkPNGReader *textureImage = vtkPNGReader::New();
textureImage->SetFileName(
/*crater_texture*/helens_texture);vtkImageShrink3D *shrinkT = vtkImageShrink3D::New();
shrinkT->SetInput(textureImage->GetOutput());
shrinkT->SetShrinkFactors(4,4,4);
vtkLookupTable* VTKtable = vtkLookupTable::New();
VTKtable->SetNumberOfColors(2000);
VTKtable->SetTableRange(0,1000);
VTKtable->SetSaturationRange(0,0);
VTKtable->SetHueRange(0,hueScale);
VTKtable->SetValueRange(0,grayScale);
VTKtable->SetAlphaRange(1,1);
VTKtable->Build();
vtkTexture *texture = vtkTexture::New();
texture->SetInput(shrinkT->GetOutput());
texture->InterpolateOn();
texture->SetLookupTable(VTKtable);
/*read in the data source*/vtkPNGReader *PNGReaderElevation = vtkPNGReader::New();
PNGReaderElevation->SetFileName (
/*crater_elevation*/helens_elevation);vtkImageShrink3D *shrink = vtkImageShrink3D::New();
shrink->SetInput(PNGReaderElevation->GetOutput());
shrink->SetShrinkFactors(4,4,4);
vtkImageDataGeometryFilter *geometry = vtkImageDataGeometryFilter::New();
geometry->SetInput(
/*luminance*/shrink->GetOutput());vtkWarpScalar *warp = vtkWarpScalar::New ();
warp->SetInput ((vtkPointSet*)geometry->GetOutput ());
warp->SetScaleFactor (0.7);
vtkLookupTable* w1 = vtkLookupTable::New();
w1->SetNumberOfColors(2000);
w1->SetTableRange(0,2000);
w1->SetSaturationRange(0,0);
w1->SetHueRange(0,1);
w1->SetValueRange(0,1);
w1->SetAlphaRange(1,1);
w1->Build();
vtkPolyDataMapper *imageMapper = vtkPolyDataMapper::New();
imageMapper->SetInput(warp->GetPolyDataOutput());
imageMapper->SetLookupTable(w1);
// imageMapper->SetScalarRange (0, 2000);
//texture->SetLookupTable(w1); //vtkTextureMapToPlane *texture = vtkTextureMapToPlane::New(); //texture->SetInput(shrinkT->GetOutput()); //vtkWindowLevelLookupTable *w1 = vtkWindowLevelLookupTable::New();//vtkPolyDataMapper *imageMapperT = vtkPolyDataMapper::New();
//imageMapperT->SetInput(texture->GetPolyDataOutput());
//vtkPlaneSource *plane = vtkPlaneSource::New();
// vtkImageLuminance *luminance = vtkImageLuminance::New();
// luminance->SetInput (/*PNGReaderElevation*/shrink->GetOutput ());
//vtkPNGReader *PNGReaderHelenElevation = vtkPNGReader::New (); //PNGReaderHelenElevation->SetFileName (helens_elevation);
/*
* Create Image Actor and Image Shift Scale. These will be used to
* manipulate the image.
*/
//vtkImageActor *pngActor = vtkImageActor::New ();vtkActor *pngActor = vtkActor::New();
pngActor->SetMapper(imageMapper);
pngActor->SetTexture(texture);
// vtkImageShiftScale *shiftScale = vtkImageShiftScale::New ();
/** Setup shiftScale. Make sure it reads our PNGReader and sets the
* shift and scale. Also, we need it to set the output to Unsigned
* Char so that the Image Actor can use it.
*/
/*
shiftScale->SetInput (PNGReaderElevation->GetOutput ());
shiftScale->SetShift (0);
shiftScale->SetScale (1.0);
shiftScale->SetOutputScalarTypeToUnsignedChar ();
*/
/* Add shiftScale to the Image Actor. */// pngActor->SetInput (shiftScale->GetOutput ());
/** Add Image Actor to the Renderer and set the size of the Rendering
* Window. Also, add renderer to rendering window.
*/
ren1->AddActor (pngActor);
ren1->SetBackground (1.0, 1.0, 1.0);
renwin->AddRenderer (ren1);
renwin->SetSize (1024, 768);
/** Setup Interactor. Use the default interactor (left mouse rotates
* Actor, right mouse zooms in/out, middle mouse moves Actor).
*/
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New ();
iren->SetRenderWindow (renwin);
/** Setup interactor style. We'll be using the default style (see the
* comments for the setup of the interactor).
*/
/*
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New ();
iren->SetInteractorStyle (style);
*/
/** Render the window and wait until 'q' or 'e' is pressed to exit.
*/
iren->Initialize ();
iren->Start ();
/*
* Delete variables and free up memory
*/
textureImage->Delete ();
shrinkT->Delete ();
VTKtable->Delete ();
texture->Delete ();
PNGReaderElevation->Delete ();
shrink->Delete();
geometry->Delete();
warp->Delete();
w1->Delete();
imageMapper->Delete();
pngActor->Delete ();
ren1->Delete ();
renwin->Delete ();
iren->Delete ();
return (0);}
//end function main (int, char *[])