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
|
/*=========================================================================
Program: Visualization Toolkit
Module: UnitTestPMaskPoints.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 "vtkSmartPointer.h"
#include "vtkPMaskPoints.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkMPIController.h"
#include "vtkCommand.h"
#include "vtkTestErrorObserver.h"
#include "vtkMathUtilities.h"
// MPI include
#include <mpi.h>
#include <cstdio>
#include <sstream>
#include <algorithm>
#define CHECK_ERROR_MSG(errorObserver, msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error.. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()
static vtkSmartPointer<vtkPolyData> MakePolyData(
unsigned int numPoints);
int UnitTestPMaskPoints (int argc, char* argv[])
{
int status = 0;
// Test empty input
// std::cout << "Testing empty input...";
std::ostringstream print0;
vtkSmartPointer<vtkPMaskPoints> mask0 =
vtkSmartPointer<vtkPMaskPoints>::New();
// For coverage
mask0->SetController(NULL); mask0->SetController(NULL);
mask0->Print(print0);
vtkMPIController* cntrl = vtkMPIController::New();
cntrl->Initialize( &argc, &argv, 0 );
vtkMultiProcessController::SetGlobalController( cntrl );
mask0->SetController(vtkMultiProcessController::GetGlobalController());
mask0->SetInputData(MakePolyData(10000));
mask0->GenerateVerticesOn();
mask0->SetMaximumNumberOfPoints(99);
mask0->ProportionalMaximumNumberOfPointsOn();
mask0->SetOutputPointsPrecision(vtkAlgorithm::DEFAULT_PRECISION);
mask0->Update();
mask0->RandomModeOn();
mask0->SetRandomModeType(0);
mask0->Update();
mask0->SetRandomModeType(1);
mask0->Update();
mask0->SetRandomModeType(2);
mask0->SetOutputPointsPrecision(vtkAlgorithm::DOUBLE_PRECISION);
mask0->Update();
mask0->SetOutputPointsPrecision(vtkAlgorithm::DEFAULT_PRECISION);
mask0->Update();
mask0->SetRandomModeType(3);
mask0->SetOutputPointsPrecision(vtkAlgorithm::SINGLE_PRECISION);
mask0->SingleVertexPerCellOn();
mask0->Update();
mask0->Print(print0);
cntrl->Finalize();
cntrl->Delete();
if (status)
{
return EXIT_FAILURE;
}
else
{
return EXIT_SUCCESS;
}
}
vtkSmartPointer<vtkPolyData> MakePolyData(unsigned int numPoints)
{
vtkSmartPointer<vtkPolyData> polyData =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
std::vector<double> line;
for (unsigned int i = 0; i < numPoints; ++i)
{
line.push_back(static_cast<double>(i));
}
std::random_shuffle ( line.begin(), line.end() );
for (unsigned int i = 0; i < numPoints; ++i)
{
points->InsertNextPoint(line[i], 0.0, 0.0);
}
polyData->SetPoints(points);
return polyData;
}
|