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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestProjectedTetrahedra.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* 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.
*/
#include "vtkProjectedTetrahedraMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPointsReader.h"
#include "vtkSLCReader.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkThreshold.h"
#include "vtkDataSetTriangleFilter.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRegressionTestImage.h"
#include "vtkStdString.h"
int TestProjectedTetrahedra(int argc, char *argv[])
{
int i;
// Need to get the data root.
const char *data_root = NULL;
for (i = 0; i < argc-1; i++)
{
if (strcmp("-D", argv[i]) == 0)
{
data_root = argv[i+1];
break;
}
}
if (!data_root)
{
cout << "Need to specify the directory to VTK_DATA_ROOT with -D <dir>." << endl;
return 1;
}
// Create the standard renderer, render window, and interactor.
vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkRenderer *ren1 = vtkRenderer::New();
renWin->AddRenderer(ren1);
ren1->Delete();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetDesiredUpdateRate(3);
renWin->Delete();
// check for driver support
renWin->Render();
vtkProjectedTetrahedraMapper *volumeMapper
= vtkProjectedTetrahedraMapper::New();
if (!volumeMapper->IsSupported(renWin))
{
volumeMapper->Delete();
iren->Delete();
vtkGenericWarningMacro("Projected tetrahedra is not supported. Skipping tests.");
return 0;
}
// Create the reader for the data.
// This is the data that will be volume rendered.
vtkStdString filename;
filename = data_root;
filename += "/Data/ironProt.vtk";
cout << "Loading " << filename.c_str() << endl;
vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
reader->SetFileName(filename.c_str());
// Create a reader for the other data that will be contoured and
// displayed as a polygonal mesh.
filename = data_root;
filename += "/Data/neghip.slc";
cout << "Loading " << filename.c_str() << endl;
vtkSLCReader *reader2 = vtkSLCReader::New();
reader2->SetFileName(filename.c_str());
// Convert from vtkImageData to vtkUnstructuredGrid.
// Remove any cells where all values are below 80.
vtkThreshold *thresh = vtkThreshold::New();
thresh->ThresholdByUpper(80);
thresh->AllScalarsOff();
thresh->SetInputConnection(reader->GetOutputPort());
// Make sure we have only tetrahedra.
vtkDataSetTriangleFilter *trifilter = vtkDataSetTriangleFilter::New();
trifilter->SetInputConnection(thresh->GetOutputPort());
// Create transfer mapping scalar value to opacity.
vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(80.0, 0.0);
opacityTransferFunction->AddPoint(120.0, 0.2);
opacityTransferFunction->AddPoint(255.0, 0.2);
// Create transfer mapping scalar value to color.
vtkColorTransferFunction *colorTransferFunction
= vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(80.0, 0.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(120.0, 0.0, 0.0, 1.0);
colorTransferFunction->AddRGBPoint(160.0, 1.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(200.0, 0.0, 1.0, 0.0);
colorTransferFunction->AddRGBPoint(255.0, 0.0, 1.0, 1.0);
// The property describes how the data will look.
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->ShadeOff();
volumeProperty->SetInterpolationTypeToLinear();
// The mapper that renders the volume data.
volumeMapper->SetInputConnection(trifilter->GetOutputPort());
// The volume holds the mapper and the property and can be used to
// position/orient the volume.
vtkVolume *volume = vtkVolume::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
// Contour the second dataset.
vtkContourFilter *contour = vtkContourFilter::New();
contour->SetValue(0, 80);
contour->SetInputConnection(reader2->GetOutputPort());
// Create a mapper for the polygonal data.
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(contour->GetOutputPort());
mapper->ScalarVisibilityOff();
// Create an actor for the polygonal data.
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
ren1->AddViewProp(actor);
ren1->AddVolume(volume);
renWin->SetSize(300, 300);
ren1->ResetCamera();
ren1->GetActiveCamera()->Azimuth(20.0);
ren1->GetActiveCamera()->Elevation(10.0);
ren1->GetActiveCamera()->Zoom(1.5);
renWin->Render();
int retVal = vtkTesting::Test(argc, argv, renWin, 75);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Clean up.
iren->Delete();
reader->Delete();
reader2->Delete();
thresh->Delete();
trifilter->Delete();
opacityTransferFunction->Delete();
colorTransferFunction->Delete();
volumeProperty->Delete();
volumeMapper->Delete();
volume->Delete();
contour->Delete();
mapper->Delete();
actor->Delete();
if ((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR))
{
return 0;
}
else
{
return 1;
}
}
|