Skip to content

Commit

Permalink
Support VTK 9, drop support for VTK <6, fix CI test build on macOS (#733
Browse files Browse the repository at this point in the history
)

* fix: Support VTK 9

* enh: Drop support for VTK<6

* fix: Replace deprecated bind2nd

* fix: Missing include in Viewer source file

* fixup: Missing include of vtkIdList.h

* fixup: Add missing include of vtkNew.h

* fix: Download URL of VTK, use curl -L flag to follow redirects

* enh: Use VTK 8.2.0 for CI test build on macOS

* fix: Use Homebrew to install VTK 8.2 or 9.0 on macOS

* fixup: Use keg-only [email protected] Homebrew installation if available

* fixup: brew install [email protected] has no —without-python flag

* fixup: Homebrew vtk formula has no —without-python flag

* fixup: travis.sh script syntax

* enh: Remove vtk_prefix before building VTK from source files

* tmp: Enable verbose Bash output for install_depends.sh

* fixup: Use VTK 8.2.0 build from source files

* enh: Add Travis CI environment variable DEBUG_VTK_BUILD

* fix: Set CMake policy CMP0057 to NEW for Boost installed by homebrew [email protected]

* tmp

* fix: install_depends.sh renamed VTK 9 cache variables

* fix: VTK 9 CMake cache variable options

* ci: Use VTK 9.0 installed with Homebrew

* fix: Remove unused variable from install_depends.h

* fix: Prefix rm command with “run”

* fixup: Add missing include of vtkVersionMacros.h

* fix: member access into incomplete type 'vtkIdTypeArray'
  • Loading branch information
schuhschuh authored Sep 20, 2020
1 parent c21910e commit 7dfb4b6
Show file tree
Hide file tree
Showing 50 changed files with 827 additions and 811 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
# - On Ubuntu, use default version installed by apt-get
# - On macOS, build recent VTK version from sources and cache installation
- LINUX_VTK_VERSION=6.0.0
- MACOS_VTK_VERSION=8.1.0
- MACOS_VTK_VERSION=9.0 # Homebrew versions: 8.2, 9.0; otherwise build from sources
- WITH_CCACHE=ON # speed up MIRTK build itself using ccache
- WITH_ARPACK=OFF # requires time consuming build of gcc on macOS
- WITH_UMFPACK=OFF # ARPACK & UMFPACK dependencies come in pairs
Expand Down
4 changes: 2 additions & 2 deletions Applications/config/Depends.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@
if (MIRTK_Image_FOUND)
# command: calculate
if (MIRTK_Image_WITH_VTK)
basis_find_package(VTK 8|7|6 REQUIRED COMPONENTS vtkCommonCore vtkCommonDataModel)
basis_find_package(VTK REQUIRED COMPONENTS vtkCommonCore vtkCommonDataModel)
endif ()
endif ()

# ----------------------------------------------------------------------------
# Dependencies of point set commands
if (MIRTK_PointSet_FOUND)
# command: all point set commands, info
basis_find_package(VTK 8|7|6 REQUIRED
basis_find_package(VTK REQUIRED
COMPONENTS
vtkCommonCore
vtkCommonDataModel
Expand Down
4 changes: 2 additions & 2 deletions Applications/src/aggregate-images.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ double GiniCoefficient(Array<T> &samples)
if (shift <= static_cast<T>(0)) {
if (numeric_limits<T>::is_integer) shift -= static_cast<T>(1);
else shift -= static_cast<T>(1e-6);
Transform(samples, bind2nd(minus<T>(), shift));
Transform(samples, bind(minus<T>(), std::placeholders::_1, shift));
}
Sort(samples);
for (int i = 0; i < n; ++i) {
Expand Down Expand Up @@ -408,7 +408,7 @@ double EntropyIndex(Array<T> &samples, int alpha = 1)
if (shift <= static_cast<T>(0)) {
if (numeric_limits<T>::is_integer) shift -= static_cast<T>(1);
else shift -= static_cast<T>(1e-6);
Transform(samples, bind2nd(minus<T>(), shift));
Transform(samples, bind(minus<T>(), std::placeholders::_1, shift));
}
// Compute mean value
double mean = 0.;
Expand Down
30 changes: 14 additions & 16 deletions Applications/src/calculate-surface-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,17 @@ BorderPointMask(vtkPolyData *surface, vtkDataArray *point_labels,
mask = NewVtkDataArray(VTK_UNSIGNED_CHAR, surface->GetNumberOfPoints(), 1, "BorderMask");
double label;
if (cell_labels) {
vtkPolyDataGetPointCellsNumCellsType ncells;
vtkIdType *cells;
vtkNew<vtkIdList> cellIds;
for (vtkIdType ptId = 0; ptId < surface->GetNumberOfPoints(); ++ptId) {
surface->GetPointCells(ptId, ncells, cells);
if (ncells == 1) {
surface->GetPointCells(ptId, cellIds.GetPointer());
if (cellIds->GetNumberOfIds() == 1) {
mask->SetComponent(ptId, 0, 1.);
} else {
mask->SetComponent(ptId, 0, 0.);
if (ncells > 0) {
label = cell_labels->GetComponent(cells[0], 0);
for (vtkPolyDataGetPointCellsNumCellsType i = 1; i < ncells; ++i) {
if (cell_labels->GetComponent(cells[i], 0) != label) {
if (cellIds->GetNumberOfIds() > 0) {
label = cell_labels->GetComponent(cellIds->GetId(0), 0);
for (vtkIdType i = 1; i < cellIds->GetNumberOfIds(); ++i) {
if (cell_labels->GetComponent(cellIds->GetId(i), 0) != label) {
mask->SetComponent(ptId, 0, 1.);
break;
}
Expand Down Expand Up @@ -307,18 +306,17 @@ BorderCellMask(vtkPolyData *surface, vtkDataArray *cell_labels, bool edge_nbrs =
}
}
} else {
vtkPolyDataGetPointCellsNumCellsType ncells;
vtkIdType npts, *pts, *cells;
vtkNew<vtkIdList> cellIds, ptIds;
for (vtkIdType cellId = 0; cellId < surface->GetNumberOfCells(); ++cellId) {
mask->SetComponent(cellId, 0, 0.);
label = cell_labels->GetComponent(cellId, 0);
surface->GetCellPoints(cellId, npts, pts);
for (vtkIdType i = 0; i < npts; ++i) {
surface->GetPointCells(pts[i], ncells, cells);
for (vtkPolyDataGetPointCellsNumCellsType j = 0; j < ncells; ++j) {
if (cell_labels->GetComponent(cells[j], 0) != label) {
surface->GetCellPoints(cellId, ptIds.GetPointer());
for (vtkIdType i = 0; i < ptIds->GetNumberOfIds(); ++i) {
surface->GetPointCells(ptIds->GetId(i), cellIds.GetPointer());
for (vtkIdType j = 0; j < cellIds->GetNumberOfIds(); ++j) {
if (cell_labels->GetComponent(cellIds->GetId(j), 0) != label) {
mask->SetComponent(cellId, 0, 1.);
i = npts; // break all inner loops
i = ptIds->GetNumberOfIds(); // break all inner loops
break;
}
}
Expand Down
9 changes: 6 additions & 3 deletions Applications/src/convert-pointset-to-mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "mirtk/PointSetIO.h"
#include "mirtk/PointSetUtils.h"

#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
Expand Down Expand Up @@ -172,9 +173,11 @@ int main(int argc, char *argv[])
vtkIdType i = 0;
vtkCellArray *cells = polydata->GetPolys();
cells->InitTraversal();
vtkIdType npts, *pts;
while (cells->GetNextCell(npts, pts)) {
F(i, 0) = pts[0]+1, F(i, 1) = pts[1]+1, F(i, 2) = pts[2]+1;
vtkNew<vtkIdList> ptIds;
while (cells->GetNextCell(ptIds.GetPointer())) {
F(i, 0) = ptIds->GetId(0) + 1;
F(i, 1) = ptIds->GetId(1) + 1;
F(i, 2) = ptIds->GetId(2) + 1;
++i;
}
mxArray *var = MatrixToMxArray(F);
Expand Down
1 change: 1 addition & 0 deletions Applications/src/convert-pointset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mirtk/PointSetUtils.h"
#include "mirtk/EuclideanDistanceTransform.h"

#include "vtkNew.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkImageData.h"
Expand Down
17 changes: 9 additions & 8 deletions Applications/src/copy-pointset-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mirtk/PointSetIO.h"
#include "mirtk/PointSetUtils.h"

#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkPointSet.h"
#include "vtkPointData.h"
Expand Down Expand Up @@ -249,9 +250,9 @@ ConvertPointToCellLabels(vtkPointSet *pset, vtkDataArray *labels,
double label;
OrderedMap<double, int> hist;
OrderedMap<double, int>::iterator bin;
vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
vtkNew<vtkIdList> ptIds;
for (vtkIdType cellId = 0; cellId < pset->GetNumberOfCells(); ++cellId) {
pset->GetCellPoints(cellId, ptIds);
pset->GetCellPoints(cellId, ptIds.GetPointer());
for (int j = 0; j < labels->GetNumberOfComponents(); ++j) {
hist.clear();
for (vtkIdType i = 0; i < ptIds->GetNumberOfIds(); ++i) {
Expand All @@ -274,9 +275,9 @@ ConvertPointToCellLabels(vtkPointSet *pset, vtkDataArray *labels,
case UnanimousVote: {
const double invalid = NaN;
double label;
vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
vtkNew<vtkIdList> ptIds;
for (vtkIdType cellId = 0; cellId < pset->GetNumberOfCells(); ++cellId) {
pset->GetCellPoints(cellId, ptIds);
pset->GetCellPoints(cellId, ptIds.GetPointer());
for (int j = 0; j < labels->GetNumberOfComponents(); ++j) {
if (ptIds->GetNumberOfIds() == 0) {
label = invalid;
Expand Down Expand Up @@ -319,9 +320,9 @@ ConvertCellToPointLabels(vtkPointSet *pset, vtkDataArray *labels,
double label;
OrderedMap<double, int> hist;
OrderedMap<double, int>::iterator bin;
vtkSmartPointer<vtkIdList> cellIds = vtkSmartPointer<vtkIdList>::New();
vtkNew<vtkIdList> cellIds;
for (vtkIdType ptId = 0; ptId < pset->GetNumberOfPoints(); ++ptId) {
pset->GetPointCells(ptId, cellIds);
pset->GetPointCells(ptId, cellIds.GetPointer());
for (int j = 0; j < labels->GetNumberOfComponents(); ++j) {
hist.clear();
for (vtkIdType i = 0; i < cellIds->GetNumberOfIds(); ++i) {
Expand All @@ -344,9 +345,9 @@ ConvertCellToPointLabels(vtkPointSet *pset, vtkDataArray *labels,
case UnanimousVote: {
double label;
const double invalid = NaN;
vtkSmartPointer<vtkIdList> cellIds = vtkSmartPointer<vtkIdList>::New();
vtkNew<vtkIdList> cellIds;
for (vtkIdType ptId = 0; ptId < pset->GetNumberOfPoints(); ++ptId) {
pset->GetPointCells(ptId, cellIds);
pset->GetPointCells(ptId, cellIds.GetPointer());
for (int j = 0; j < labels->GetNumberOfComponents(); ++j) {
if (cellIds->GetNumberOfIds() == 0) {
label = invalid;
Expand Down
5 changes: 2 additions & 3 deletions Applications/src/evaluate-distance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,14 @@ int main(int argc, char *argv[])
vtkNew<vtkCellLocator> locator;
locator->SetDataSet(target);
locator->BuildLocator();
vtkSmartPointer<vtkIdList> ptIds;
ptIds = vtkSmartPointer<vtkIdList>::New();
vtkNew<vtkIdList> ptIds;

for (vtkIdType ptId = 0; ptId < target->GetNumberOfPoints(); ++ptId) {
source->GetPoint(ptId, a);
locator->FindClosestPoint(a, b, cellId, subId, dist);
dist = sqrt(dist);
if (mask) {
target->GetCellPoints(cellId, ptIds);
target->GetCellPoints(cellId, ptIds.GetPointer());
for (vtkIdType i = 0; i < ptIds->GetNumberOfIds(); ++i) {
if (mask->GetComponent(ptIds->GetId(i), 0) != 0.) {
if (dist > hausdorff_dist) hausdorff_dist = dist;
Expand Down
42 changes: 22 additions & 20 deletions Applications/src/evaluate-distortion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,20 @@ enum DistortionMeasure
// -----------------------------------------------------------------------------
double Angle(vtkPolyData *mesh, vtkIdType cellId, vtkIdType ptId)
{
vtkIdType npts, *pts, i[3] = {0, 1, 2};
mesh->GetCellPoints(cellId, npts, pts);
for (vtkIdType j = 0; j < npts; ++j) {
if (pts[j] == ptId) {
vtkIdType i[3] = {0, 1, 2};
vtkNew<vtkIdList> ptIds;
mesh->GetCellPoints(cellId, ptIds.GetPointer());
for (vtkIdType j = 0; j < ptIds->GetNumberOfIds(); ++j) {
if (ptIds->GetId(j) == ptId) {
i[0] = i[j];
i[j] = 0;
break;
}
}
double p[3][3], ab, ac, bc;
mesh->GetPoint(pts[0], p[i[0]]);
mesh->GetPoint(pts[1], p[i[1]]);
mesh->GetPoint(pts[2], p[i[2]]);
mesh->GetPoint(ptIds->GetId(0), p[i[0]]);
mesh->GetPoint(ptIds->GetId(1), p[i[1]]);
mesh->GetPoint(ptIds->GetId(2), p[i[2]]);
ab = pow(p[1][0] - p[0][0], 2) + pow(p[1][1] - p[0][1], 2) + pow(p[1][2] - p[0][2], 2);
ac = pow(p[2][0] - p[0][0], 2) + pow(p[2][1] - p[0][1], 2) + pow(p[2][2] - p[0][2], 2);
bc = pow(p[2][0] - p[1][0], 2) + pow(p[2][1] - p[1][1], 2) + pow(p[2][2] - p[1][2], 2);
Expand All @@ -131,37 +132,38 @@ AngularDistortion(vtkPolyData *orig, vtkPolyData *mesh)
array->SetNumberOfComponents(2);
array->SetNumberOfTuples(npoints);

vtkPolyDataGetPointCellsNumCellsType ncells1, ncells2;
vtkIdType *cells1, *cells2;
vtkNew<vtkIdList> cellIds1, cellIds2;

double sum1, sum2;
Array<double> angles1, angles2;
double ratio, avg_ratio, max_ratio;

for (vtkIdType ptId = 0; ptId < npoints; ++ptId) {
orig->GetPointCells(ptId, ncells1, cells1);
mesh->GetPointCells(ptId, ncells2, cells2);
if (ncells1 != ncells2) {
orig->GetPointCells(ptId, cellIds1.GetPointer());
mesh->GetPointCells(ptId, cellIds2.GetPointer());
if (cellIds1->GetNumberOfIds() != cellIds2->GetNumberOfIds()) {
FatalError("AngularDistortion: Point " << ptId << " belongs to different number of cells in the two meshes!");
}
angles1.resize(ncells1);
angles2.resize(ncells2);
for (vtkPolyDataGetPointCellsNumCellsType i = 0; i < ncells1; ++i) {
if (cells1[i] != cells2[i]) {
const vtkIdType ncells = cellIds1->GetNumberOfIds();
angles1.resize(ncells);
angles2.resize(ncells);
for (vtkIdType i = 0; i < ncells; ++i) {
if (cellIds1->GetId(i) != cellIds2->GetId(i)) {
FatalError("AngularDistortion: Lists of cell IDs to which point " << ptId << " belongs differ!");
}
angles1[i] = Angle(orig, cells1[i], ptId);
angles2[i] = Angle(mesh, cells2[i], ptId);
angles1[i] = Angle(orig, cellIds1->GetId(i), ptId);
angles2[i] = Angle(mesh, cellIds2->GetId(i), ptId);
}
sum1 = Accumulate(angles1);
sum2 = Accumulate(angles2);
avg_ratio = .0;
max_ratio = .0;
for (vtkPolyDataGetPointCellsNumCellsType i = 0; i < ncells1; ++i) {
for (vtkIdType i = 0; i < ncells; ++i) {
ratio = (angles1[i] / sum1) / (angles2[i] / sum2);
max_ratio = max(max_ratio, ratio);
avg_ratio += ratio;
}
avg_ratio /= ncells1;
avg_ratio /= ncells;
array->SetComponent(ptId, 0, avg_ratio);
array->SetComponent(ptId, 1, max_ratio);
}
Expand Down
22 changes: 11 additions & 11 deletions Applications/src/evaluate-surface-mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,17 @@ int main(int argc, char *argv[])
surface.TakeReference(input->NewInstance());
surface->SetPoints(input->GetPoints());
surface->Allocate(input->GetNumberOfCells());
vtkIdType cellId, npts, *pts;
vtkIdType cellId;
vtkNew<vtkIdList> ptIds;
vtkSmartPointer<vtkIdTypeArray> origCellIds;
origCellIds = vtkSmartPointer<vtkIdTypeArray>::New();
origCellIds->SetName("OriginalIds");
origCellIds->SetNumberOfComponents(1);
origCellIds->SetNumberOfTuples(selection.size());
surface->GetCellData()->AddArray(origCellIds);
for (auto origCellId : selection) {
input->GetCellPoints(origCellId, npts, pts);
cellId = surface->InsertNextCell(input->GetCellType(origCellId), npts, pts);
input->GetCellPoints(origCellId, ptIds.GetPointer());
cellId = surface->InsertNextCell(input->GetCellType(origCellId), ptIds.GetPointer());
origCellIds->SetValue(cellId, origCellId);
}
surface->BuildLinks();
Expand Down Expand Up @@ -442,14 +443,14 @@ int main(int argc, char *argv[])
input->GetPointData()->RemoveArray(pointIds->GetName());
input->GetPointData()->AddArray(pointIds);
// Add surface component IDs cell data
vtkIdType npts, *pts;
vtkNew<vtkIdList> ptIds;
output->BuildLinks();
cellIds = NewVtkDataArray(ncomp < 256 ? VTK_UNSIGNED_CHAR :
(ncomp < 65535 ? VTK_UNSIGNED_SHORT : VTK_INT),
surface->GetNumberOfCells(), 1, COMPONENT_ID);
for (vtkIdType cellId = 0; cellId < output->GetNumberOfCells(); ++cellId) {
output->GetCellPoints(cellId, npts, pts);
cellIds->SetComponent(cellId, 0, (npts == 0 ? 0. : compIds->GetComponent(pts[0], 0)));
output->GetCellPoints(cellId, ptIds.GetPointer());
cellIds->SetComponent(cellId, 0, (ptIds->GetNumberOfIds() == 0 ? 0. : compIds->GetComponent(ptIds->GetId(0), 0)));
}
AddCellData(input, surface, cellIds);
}
Expand Down Expand Up @@ -601,15 +602,14 @@ int main(int argc, char *argv[])
collisions.Run();

if (output_name) {
vtkIdType *cells;
vtkPolyDataGetPointCellsNumCellsType ncells;
vtkNew<vtkIdList> cellIds;
vtkSmartPointer<vtkDataArray> mask;
mask = NewVtkDataArray(VTK_UNSIGNED_CHAR, surface->GetNumberOfPoints(), 1, "CollisionMask");
for (vtkIdType ptId = 0; ptId < surface->GetNumberOfPoints(); ++ptId) {
mask->SetComponent(ptId, 0, 0.);
surface->GetPointCells(ptId, ncells, cells);
for (vtkPolyDataGetPointCellsNumCellsType i = 0; i < ncells; ++i) {
if (collisions.GetCollisionType(cells[i]) != SurfaceCollisions::NoCollision) {
surface->GetPointCells(ptId, cellIds.GetPointer());
for (vtkIdType i = 0; i < cellIds->GetNumberOfIds(); ++i) {
if (collisions.GetCollisionType(cellIds->GetId(i)) != SurfaceCollisions::NoCollision) {
mask->SetComponent(ptId, 0, 1.);
break;
}
Expand Down
1 change: 1 addition & 0 deletions Applications/src/extract-connected-points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "vtkPolyDataWriter.h"
#include "vtkPolyDataConnectivityFilter.h"
#include "vtkCleanPolyData.h"
#include "vtkIdTypeArray.h"

using namespace mirtk;

Expand Down
10 changes: 5 additions & 5 deletions Applications/src/info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ struct CountTriangleTriangleIntersections
vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
vtkSmartPointer<vtkIdList> cellIds = vtkSmartPointer<vtkIdList>::New();

vtkPolyDataGetPointCellsNumCellsType ncells;
vtkIdType *cells, cellId2;
vtkIdType cellId2;
vtkNew<vtkIdList> ptCellIds;
double r1, c1[3], v1[3], v2[3], v3[3], u1[3], u2[3], u3[3];

for (vtkIdType cellId1 = re.begin(); cellId1 != re.end(); ++cellId1) {
Expand All @@ -215,9 +215,9 @@ struct CountTriangleTriangleIntersections
_PointLocator->FindPointsWithinRadius(3.0 * r1, c1, ptIds);
cellIds->Reset();
for (vtkIdType i = 0; i < ptIds->GetNumberOfIds(); ++i) {
_DataSet->GetPointCells(ptIds->GetId(i), ncells, cells);
for (vtkPolyDataGetPointCellsNumCellsType j = 0; j < ncells; ++j) {
cellIds->InsertUniqueId(cells[j]);
_DataSet->GetPointCells(ptIds->GetId(i), ptCellIds.GetPointer());
for (vtkIdType j = 0; j < ptCellIds->GetNumberOfIds(); ++j) {
cellIds->InsertUniqueId(ptCellIds->GetId(j));
}
}
for (vtkIdType i = 0; i < cellIds->GetNumberOfIds(); ++i) {
Expand Down
Loading

0 comments on commit 7dfb4b6

Please sign in to comment.