/*========================================================================= 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 "vtkCamera.h" #include "vtkCellArray.h" #include "vtkClipPolyData.h" #include "vtkDebugLeaks.h" #include "vtkElevationFilter.h" #include "vtkIdTypeArray.h" #include "vtkLight.h" #include "vtkLightCollection.h" #include "vtkNew.h" #include "vtkPlane.h" #include "vtkPlaneSource.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkProbePolyhedron.h" #include "vtkProperty.h" #include "vtkRegressionTestImage.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkSmartPointer.h" #include "vtkSphereSource.h" int TestMeanValueCoordinatesInterpolation1(int argc, char* argv[]) { vtkSmartPointer renderer = vtkSmartPointer::New(); vtkSmartPointer renderer1 = vtkSmartPointer::New(); renderer->SetViewport(0, 0, 0.5, 1); vtkSmartPointer renWin = vtkSmartPointer::New(); renWin->SetMultiSamples(0); renWin->AddRenderer(renderer); renWin->AddRenderer(renderer1); renderer1->SetViewport(0.5, 0, 1, 1); vtkSmartPointer iren = vtkSmartPointer::New(); iren->SetRenderWindow(renWin); // // Case 0: triangle meshes // // Create a sphere vtkSmartPointer sphere = vtkSmartPointer::New(); sphere->SetThetaResolution(51); sphere->SetPhiResolution(17); // Generate some scalars on the sphere vtkSmartPointer ele = vtkSmartPointer::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 plane = vtkSmartPointer::New(); plane->SetOrigin(0, 0, 0); plane->SetNormal(0, 0, 1); vtkSmartPointer clip = vtkSmartPointer::New(); clip->SetInputConnection(ele->GetOutputPort()); clip->SetClipFunction(plane); vtkSmartPointer sphereMapper = vtkSmartPointer::New(); sphereMapper->SetInputConnection(clip->GetOutputPort()); vtkSmartPointer sphereActor = vtkSmartPointer::New(); sphereActor->SetMapper(sphereMapper); // Okay now sample the sphere mesh with a plane and see how it interpolates vtkSmartPointer pSource = vtkSmartPointer::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 interp = vtkSmartPointer::New(); interp->SetInputConnection(pSource->GetOutputPort()); interp->SetSourceConnection(ele->GetOutputPort()); vtkSmartPointer interpMapper = vtkSmartPointer::New(); interpMapper->SetInputConnection(interp->GetOutputPort()); vtkSmartPointer interpActor = vtkSmartPointer::New(); interpActor->SetMapper(interpMapper); // // Case 1: general meshes // // Create a sphere vtkSmartPointer sphere1 = vtkSmartPointer::New(); sphere1->SetThetaResolution(51); sphere1->SetPhiResolution(17); // Generate some scalars on the sphere vtkSmartPointer ele1 = vtkSmartPointer::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. vtkNew legacyArray; polys->ExportLegacyFormat(legacyArray); vtkIdType* p = legacyArray->GetPointer(0); vtkIdType pids[4] = { p[1], p[2], p[6], p[3] }; vtkSmartPointer newPolys = vtkSmartPointer::New(); 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 plane1 = vtkSmartPointer::New(); plane1->SetOrigin(0, 0, 0); plane1->SetNormal(0, 0, 1); vtkSmartPointer clip1 = vtkSmartPointer::New(); clip1->SetInputData(spherePoly); clip1->SetClipFunction(plane1); vtkSmartPointer sphereMapper1 = vtkSmartPointer::New(); sphereMapper1->SetInputConnection(clip1->GetOutputPort()); vtkSmartPointer sphereActor1 = vtkSmartPointer::New(); sphereActor1->SetMapper(sphereMapper1); // Okay now sample the sphere mesh with a plane and see how it interpolates vtkSmartPointer pSource1 = vtkSmartPointer::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 interp1 = vtkSmartPointer::New(); interp1->SetInputConnection(pSource1->GetOutputPort()); interp1->SetSourceConnection(ele1->GetOutputPort()); vtkSmartPointer interpMapper1 = vtkSmartPointer::New(); interpMapper1->SetInputConnection(interp1->GetOutputPort()); vtkSmartPointer interpActor1 = vtkSmartPointer::New(); interpActor1->SetMapper(interpMapper1); // // add actors to renderer // vtkSmartPointer lightProperty = vtkSmartPointer::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; }