1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
* Copyright 2004 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
// Simple test of vtkFastSplatter
#include "vtkImageData.h"
#include "vtkImageShiftScale.h"
#include "vtkFastSplatter.h"
#include "vtkImageViewer2.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRegressionTestImage.h"
#include "vtkSmartPointer.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#include <math.h>
const int SPLAT_IMAGE_SIZE = 100;
int FastSplatter(int argc, char *argv[])
{
// For the purposes of this example we'll build the splat image by
// hand.
VTK_CREATE(vtkImageData, SplatImage);
SplatImage->SetDimensions(SPLAT_IMAGE_SIZE, SPLAT_IMAGE_SIZE, 1);
SplatImage->AllocateScalars(VTK_FLOAT, 1);
for (int i = 0; i < SPLAT_IMAGE_SIZE; ++i)
{
for (int j = 0; j < SPLAT_IMAGE_SIZE; ++j)
{
double xCoord = 1 - fabs( (i - SPLAT_IMAGE_SIZE/2)
/ (SPLAT_IMAGE_SIZE/2.0) );
double yCoord = 1 - fabs( (j - SPLAT_IMAGE_SIZE/2)
/ (SPLAT_IMAGE_SIZE/2.0) );
SplatImage->SetScalarComponentFromDouble(i, j, 0, 0,
xCoord * yCoord );
}
}
VTK_CREATE(vtkPolyData, SplatPoints);
VTK_CREATE(vtkPoints, Points);
Points->SetNumberOfPoints( 5 );
double point[3];
point[0] = 0;
point[1] = 0;
point[2] = 0;
Points->SetPoint( 0, point );
point[0] = 1;
point[1] = 1;
point[2] = 0;
Points->SetPoint( 1, point );
point[0] = -1;
point[1] = 1;
point[2] = 0;
Points->SetPoint( 2, point );
point[0] = 1;
point[1] = -1;
point[2] = 0;
Points->SetPoint( 3, point );
point[0] = -1;
point[1] = -1;
point[2] = 0;
Points->SetPoint( 4, point );
SplatPoints->SetPoints(Points);
VTK_CREATE(vtkFastSplatter, splatter);
splatter->SetInputData( SplatPoints );
splatter->SetOutputDimensions( 2*SPLAT_IMAGE_SIZE,
2*SPLAT_IMAGE_SIZE,
1 );
splatter->SetInputData(1, SplatImage );
// The image viewers and writers are only happy with unsigned char
// images. This will convert the floats into that format.
VTK_CREATE(vtkImageShiftScale, resultScale);
resultScale->SetOutputScalarTypeToUnsignedChar();
resultScale->SetShift(0);
resultScale->SetScale(255);
resultScale->SetInputConnection( splatter->GetOutputPort() );
splatter->Update();
resultScale->Update();
// Set up a viewer for the image. vtkImageViewer and
// vtkImageViewer2 are convenient wrappers around vtkActor2D,
// vtkImageMapper, vtkRenderer, and vtkRenderWindow. All you need
// to supply is the interactor and hooray, Bob's your uncle.
VTK_CREATE(vtkImageViewer2, ImageViewer);
ImageViewer->SetInputConnection( resultScale->GetOutputPort() );
ImageViewer->SetColorLevel(127);
ImageViewer->SetColorWindow(255);
VTK_CREATE(vtkRenderWindowInteractor, iren);
ImageViewer->SetupInteractor(iren);
ImageViewer->Render();
ImageViewer->GetRenderer()->ResetCamera();
int retVal = vtkRegressionTestImage(ImageViewer->GetRenderWindow());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
ImageViewer->Render();
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return !retVal;
}
|