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
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestMeanValueCoordinatesInterpolation.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.
=========================================================================*/
#include "vtkActor.h"
#include "vtkDebugLeaks.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkClipPolyData.h"
#include "vtkElevationFilter.h"
#include "vtkPlane.h"
#include "vtkPlaneSource.h"
#include "vtkProbePolyhedron.h"
#include "vtkLightCollection.h"
#include "vtkLight.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkSmartPointer.h"
int TestMeanValueCoordinatesInterpolation1( int argc, char *argv[] )
{
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> renderer1 =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetViewport(0, 0, 0.5, 1);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->SetMultiSamples(0);
renWin->AddRenderer(renderer);
renWin->AddRenderer(renderer1);
renderer1->SetViewport(0.5, 0, 1, 1);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
//
// Case 0: triangle meshes
//
// Create a sphere
vtkSmartPointer<vtkSphereSource> sphere =
vtkSmartPointer<vtkSphereSource>::New();
sphere->SetThetaResolution(51);
sphere->SetPhiResolution(17);
// Generate some scalars on the sphere
vtkSmartPointer<vtkElevationFilter> ele =
vtkSmartPointer<vtkElevationFilter>::New();
ele->SetInputConnection(sphere->GetOutputPort());
ele->SetLowPoint(-0.5,0,0);
ele->SetHighPoint(0.5,0,0);
ele->Update();
// Now clip the sphere in half and display it
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(0,0,0);
plane->SetNormal(0,0,1);
vtkSmartPointer<vtkClipPolyData> clip =
vtkSmartPointer<vtkClipPolyData>::New();
clip->SetInputConnection(ele->GetOutputPort());
clip->SetClipFunction(plane);
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(clip->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
//Okay now sample the sphere mesh with a plane and see how it interpolates
vtkSmartPointer<vtkPlaneSource> pSource =
vtkSmartPointer<vtkPlaneSource>::New();
pSource->SetOrigin(-1.0,-1.0,0);
pSource->SetPoint1(1.0,-1.0,0);
pSource->SetPoint2(-1.0, 1.0,0);
pSource->SetXResolution(50);
pSource->SetYResolution(50);
// interpolation 0: use the faster MVC algorithm specialized for triangle meshes.
vtkSmartPointer<vtkProbePolyhedron> interp =
vtkSmartPointer<vtkProbePolyhedron>::New();
interp->SetInputConnection(pSource->GetOutputPort());
interp->SetSourceConnection(ele->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> interpMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
interpMapper->SetInputConnection(interp->GetOutputPort());
vtkSmartPointer<vtkActor> interpActor = vtkSmartPointer<vtkActor>::New();
interpActor->SetMapper(interpMapper);
//
// Case 1: general meshes
//
// Create a sphere
vtkSmartPointer<vtkSphereSource> sphere1 =
vtkSmartPointer<vtkSphereSource>::New();
sphere1->SetThetaResolution(51);
sphere1->SetPhiResolution(17);
// Generate some scalars on the sphere
vtkSmartPointer<vtkElevationFilter> ele1 =
vtkSmartPointer<vtkElevationFilter>::New();
ele1->SetInputConnection(sphere1->GetOutputPort());
ele1->SetLowPoint(-0.5,0,0);
ele1->SetHighPoint(0.5,0,0);
ele1->Update();
// create a cell with 4 points
vtkPolyData* spherePoly = vtkPolyData::SafeDownCast(ele1->GetOutput());
vtkCellArray *polys = spherePoly->GetPolys();
// merge the first two cell, this will make vtkProbePolyhedron select the
// more general MVC algorithm.
vtkIdType * p = polys->GetPointer();
vtkIdType pids[4] = {p[1], p[2], p[6], p[3]};
vtkSmartPointer<vtkCellArray> newPolys = vtkSmartPointer<vtkCellArray>::New();
newPolys->SetNumberOfCells(polys->GetNumberOfCells()-1);
newPolys->Initialize();
for (int i = 2; i < polys->GetNumberOfCells(); i++)
{
pids[0] = p[4*i+1];
pids[1] = p[4*i+2];
pids[2] = p[4*i+3];
newPolys->InsertNextCell(3,pids);
}
spherePoly->SetPolys(newPolys);
// Now clip the sphere in half and display it
vtkSmartPointer<vtkPlane> plane1 = vtkSmartPointer<vtkPlane>::New();
plane1->SetOrigin(0,0,0);
plane1->SetNormal(0,0,1);
vtkSmartPointer<vtkClipPolyData> clip1 =
vtkSmartPointer<vtkClipPolyData>::New();
clip1->SetInput(spherePoly);
clip1->SetClipFunction(plane1);
vtkSmartPointer<vtkPolyDataMapper> sphereMapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper1->SetInputConnection(clip1->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor1 = vtkSmartPointer<vtkActor>::New();
sphereActor1->SetMapper(sphereMapper1);
//Okay now sample the sphere mesh with a plane and see how it interpolates
vtkSmartPointer<vtkPlaneSource> pSource1 =
vtkSmartPointer<vtkPlaneSource>::New();
pSource1->SetOrigin(-1.0,-1.0,0);
pSource1->SetPoint1(1.0,-1.0,0);
pSource1->SetPoint2(-1.0, 1.0,0);
pSource1->SetXResolution(50);
pSource1->SetYResolution(50);
// interpolation 1: use the more general but slower MVC algorithm.
vtkSmartPointer<vtkProbePolyhedron> interp1 =
vtkSmartPointer<vtkProbePolyhedron>::New();
interp1->SetInputConnection(pSource1->GetOutputPort());
interp1->SetSourceConnection(ele1->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> interpMapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
interpMapper1->SetInputConnection(interp1->GetOutputPort());
vtkSmartPointer<vtkActor> interpActor1 = vtkSmartPointer<vtkActor>::New();
interpActor1->SetMapper(interpMapper1);
//
// add actors to renderer
//
vtkSmartPointer<vtkProperty> lightProperty =
vtkSmartPointer<vtkProperty>::New();
lightProperty->LightingOff();
sphereActor->SetProperty(lightProperty);
interpActor->SetProperty(lightProperty);
interpActor1->SetProperty(lightProperty);
renderer->AddActor(sphereActor);
renderer->AddActor(interpActor);
renderer->ResetCamera();
renderer->SetBackground(1,1,1);
renderer1->AddActor(sphereActor);
renderer1->AddActor(interpActor1);
renderer1->ResetCamera();
renderer1->SetBackground(1,1,1);
renWin->SetSize(600,300);
// interact with data
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
|