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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestHyperOctreeDual.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.
=========================================================================*/
// This example demonstrates how to use a vtkHyperOctreeSampleFunction and
// apply a vtkHyperOctreeCutter filter on it.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
// -D <path> => path to the data; the data should be in <path>/Data/
// If WRITE_RESULT is defined, the result of the surface filter is saved.
//#define WRITE_RESULT
#include "vtkActor.h"
#include "vtkCellData.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include <cassert>
#include "vtkLookupTable.h"
#include "vtkPolyData.h"
#include "vtkXMLPolyDataWriter.h"
#include "vtkHyperOctreeDualGridContourFilter.h"
#include "vtkContourFilter.h"
#include "vtkProperty.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkTimerLog.h"
#include "vtkHyperOctreeFractalSource.h"
#include "vtkSphere.h"
#include "vtkCamera.h"
int TestHyperOctreeDual(int argc, char* argv[])
{
// Standard rendering classes
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetMultiSamples(0);
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkTimerLog *timer=vtkTimerLog::New();
// 3D
vtkHyperOctreeFractalSource* source3d = vtkHyperOctreeFractalSource::New();
source3d->SetMaximumNumberOfIterations(17);
source3d->SetMaximumLevel(7);
source3d->SetMinimumLevel(3);
cout<<"update source3d..."<<endl;
timer->StartTimer();
source3d->Update(); // Update now, make things easier with a debugger
timer->StopTimer();
cout<<"source updated3d"<<endl;
cout<<"source3d time="<<timer->GetElapsedTime()<<" s"<<endl;
vtkHyperOctreeDualGridContourFilter *contour3d;
contour3d = vtkHyperOctreeDualGridContourFilter::New();
contour3d->SetNumberOfContours(2);
contour3d->SetValue(0,4.5);
contour3d->SetValue(1,10.5);
contour3d->SetInputConnection(0,source3d->GetOutputPort(0));
cout<<"update contour3d..."<<endl;
timer->StartTimer();
contour3d->Update(); // Update now, make things easier with a debugger
timer->StopTimer();
cout<<"contour3d updated"<<endl;
cout<<"contour3d time="<<timer->GetElapsedTime()<<" s"<<endl;
// This creates a blue to red lut.
vtkLookupTable *lut3d = vtkLookupTable::New();
lut3d->SetHueRange (0.667, 0.0);
vtkPolyDataMapper *mapper3d = vtkPolyDataMapper::New();
mapper3d->SetInputConnection(0, contour3d->GetOutputPort(0) );
mapper3d->SetScalarRange(0, 17);
vtkActor *actor3d = vtkActor::New();
actor3d->SetMapper(mapper3d);
renderer->AddActor(actor3d);
#ifdef WRITE_RESULT
// Save the result of the filter in a file
vtkXMLPolyDataWriter *writer3d=vtkXMLPolyDataWriter::New();
writer3d->SetInputConnection(0,contour3d->GetOutputPort(0));
writer3d->SetFileName("contour3d.vtp");
writer3d->SetDataModeToAscii();
writer3d->Write();
writer3d->Delete();
#endif // #ifdef WRITE_RESULT
// 2D
vtkHyperOctreeFractalSource* source2d = vtkHyperOctreeFractalSource::New();
source2d->SetDimension(2);
source2d->SetMaximumNumberOfIterations(17);
source2d->SetMaximumLevel(7);
source2d->SetMinimumLevel(4);
cout<<"update source2d..."<<endl;
timer->StartTimer();
source2d->Update(); // Update now, make things easier with a debugger
timer->StopTimer();
cout<<"source updated2d"<<endl;
cout<<"source2d time="<<timer->GetElapsedTime()<<" s"<<endl;
// This creates a blue to red lut.
vtkLookupTable *lut2d = vtkLookupTable::New();
lut2d->SetHueRange (0.667, 0.0);
vtkDataSetMapper *mapper2d = vtkDataSetMapper::New();
mapper2d->SetInputConnection(0,source2d->GetOutputPort(0));
mapper2d->SetLookupTable(lut2d);
mapper2d->SetScalarRange(0, 17);
vtkActor *actor2d = vtkActor::New();
actor2d->SetPosition(2.5,0,0);
actor2d->SetOrientation(180,0,0);
actor2d->SetMapper(mapper2d);
actor2d->GetProperty()->SetRepresentationToWireframe();
actor2d->GetProperty()->SetAmbient(1.0);
actor2d->GetProperty()->SetDiffuse(0.0);
renderer->AddActor(actor2d);
#ifdef WRITE_RESULT
// Save the result of the filter in a file
vtkXMLPolyDataWriter *writer2d=vtkXMLPolyDataWriter::New();
writer2d->SetInputConnection(0,source2d->GetOutputPort(0));
writer2d->SetFileName("dual2d.vtp");
writer2d->SetDataModeToAscii();
writer2d->Write();
writer2d->Delete();
#endif // #ifdef WRITE_RESULT
vtkContourFilter *contourDS=vtkContourFilter::New();
contourDS->SetNumberOfContours(2);
contourDS->SetValue(0,4.5);
contourDS->SetValue(1,10.5);
contourDS->SetInputConnection(0,source3d->GetOutputPort(0));
cout<<"update contour data set..."<<endl;
timer->StartTimer();
contourDS->Update(); // Update now, make things easier with a debugger
timer->StopTimer();
cout<<"contour data set updated"<<endl;
cout<<"contour data set time="<<timer->GetElapsedTime()<<" s"<<endl;
// This creates a blue to red lut.
vtkLookupTable *lutDS = vtkLookupTable::New();
lutDS->SetHueRange (0.667, 0.0);
vtkPolyDataMapper *mapperDS = vtkPolyDataMapper::New();
mapperDS->SetInputConnection(0,contourDS->GetOutputPort(0));
mapperDS->SetLookupTable(lutDS);
mapperDS->SetScalarRange(0, 17);
vtkActor *actorDS = vtkActor::New();
actorDS->SetPosition(2.5,2.5,0);
actorDS->SetMapper(mapperDS);
renderer->AddActor(actorDS);
#ifdef WRITE_RESULT
// Save the result of the filter in a file
vtkXMLPolyDataWriter *writerDS=vtkXMLPolyDataWriter::New();
writerDS->SetInputConnection(0,contourDS->GetOutputPort(0));
writerDS->SetFileName("contourDS.vtp");
writerDS->SetDataModeToAscii();
writerDS->Write();
writerDS->Delete();
#endif // #ifdef WRITE_RESULT
// Standard testing code.
renderer->SetBackground(0.5,0.5,0.5);
renWin->SetSize(300,300);
vtkCamera *cam=renderer->GetActiveCamera();
renderer->ResetCamera();
cam->Azimuth(180);
cam->Zoom(1.35);
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Cleanup
renderer->Delete();
renWin->Delete();
iren->Delete();
contourDS->Delete();
lutDS->Delete();
mapperDS->Delete();
actorDS->Delete();
source3d->Delete();
contour3d->Delete();
mapper3d->Delete();
actor3d->Delete();
lut3d->Delete();
source2d->Delete();
mapper2d->Delete();
actor2d->Delete();
lut2d->Delete();
timer->Delete();
return !retVal;
}
|