Commit d195dad3 authored by Allison Vacanti's avatar Allison Vacanti Committed by Kitware Robot

Merge topic 'mask_points_msvc_ice'

f6b8528b Simplify dispatch functors in PResampleToImage.
e7d3e9c8 Workaround ICE in MSVC 2015 x64.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !6260
parents 4842efe4 f6b8528b
Pipeline #153546 running with stage
......@@ -127,31 +127,18 @@ inline void InitializeFieldData(
}
//----------------------------------------------------------------------------
class SerializeWorklet
struct SerializeWorklet
{
public:
SerializeWorklet(vtkIdType tuple, int numComponents, diy::MemoryBuffer& buffer)
: Tuple(tuple)
, NumComponents(numComponents)
, Buffer(&buffer)
{
}
template <typename ArrayType>
void operator()(ArrayType* array) const
void operator()(ArrayType* array, vtkIdType tupleIdx, diy::MemoryBuffer& buffer) const
{
using T = vtk::GetAPIType<ArrayType>;
const auto tuple = vtk::DataArrayTupleRange(array)[this->Tuple];
using T = vtk::GetAPIType<ArrayType>; // Need value type for diy::save template resolution
const auto tuple = vtk::DataArrayTupleRange(array)[tupleIdx];
for (const T comp : tuple)
{
diy::save(*this->Buffer, comp);
diy::save(buffer, comp);
}
}
private:
vtkIdType Tuple;
int NumComponents;
diy::MemoryBuffer* Buffer;
};
inline void SerializeFieldData(vtkFieldData* field, vtkIdType tuple, diy::MemoryBuffer& bb)
......@@ -160,44 +147,30 @@ inline void SerializeFieldData(vtkFieldData* field, vtkIdType tuple, diy::Memory
for (int i = 0; i < numFields; ++i)
{
vtkDataArray* da = field->GetArray(i);
int numComponents = da->GetNumberOfComponents();
SerializeWorklet worklet(tuple, numComponents, bb);
if (!vtkArrayDispatch::Dispatch::Execute(da, worklet))
if (!vtkArrayDispatch::Dispatch::Execute(da, SerializeWorklet{}, tuple, bb))
{
vtkGenericWarningMacro(<< "Dispatch failed, fallback to vtkDataArray Get/Set");
worklet(da);
SerializeWorklet{}(da, tuple, bb);
}
}
}
class DeserializeWorklet
struct DeserializeWorklet
{
public:
DeserializeWorklet(vtkIdType tuple, int numComponents, diy::MemoryBuffer& buffer)
: Tuple(tuple)
, NumComponents(numComponents)
, Buffer(&buffer)
{
}
template <typename ArrayType>
void operator()(ArrayType* array) const
void operator()(ArrayType* array, vtkIdType tupleIdx, diy::MemoryBuffer& buffer) const
{
auto tuple = vtk::DataArrayTupleRange(array)[this->Tuple];
auto tuple = vtk::DataArrayTupleRange(array)[tupleIdx];
using CompRefT = typename std::iterator_traits<decltype(tuple.begin())>::reference;
// Need value type for diy::load template resolution
using ValueT = typename std::iterator_traits<decltype(tuple.begin())>::value_type;
for (CompRefT compRef : tuple)
{
ValueT val;
diy::load(*this->Buffer, val);
diy::load(buffer, val);
compRef = val;
}
}
private:
vtkIdType Tuple;
int NumComponents;
diy::MemoryBuffer* Buffer;
};
inline void DeserializeFieldData(diy::MemoryBuffer& bb, vtkFieldData* field, vtkIdType tuple)
......@@ -206,12 +179,10 @@ inline void DeserializeFieldData(diy::MemoryBuffer& bb, vtkFieldData* field, vtk
for (int i = 0; i < numFields; ++i)
{
vtkDataArray* da = field->GetArray(i);
int numComponents = da->GetNumberOfComponents();
DeserializeWorklet worklet(tuple, numComponents, bb);
if (!vtkArrayDispatch::Dispatch::Execute(da, worklet))
if (!vtkArrayDispatch::Dispatch::Execute(da, DeserializeWorklet{}, tuple, bb))
{
vtkGenericWarningMacro(<< "Dispatch failed, fallback to vtkDataArray Get/Set");
worklet(da);
DeserializeWorklet{}(da, tuple, bb);
}
}
}
......
......@@ -38,7 +38,7 @@ struct ExtractPoints
{
template <typename PtArrayT>
void operator()(PtArrayT* ptArray, const unsigned char* mask, unsigned char emptyValue,
int dims[3], double origin[3], double spacing[3], vtkIdType* pointMap) const
const int dims[3], const double origin[3], const double spacing[3], vtkIdType* pointMap) const
{
const vtkIdType numPts = ptArray->GetNumberOfTuples();
......@@ -61,7 +61,10 @@ struct ExtractPoints
vtkIdType* map = pointMap + ptId;
std::transform(pts.cbegin(), pts.cend(), map, [&](PtCRefT pt) -> vtkIdType {
// MSVC 2015 x64 ICEs when this loop is written using std::transform,
// so we'll work around that by using a for-range loop:
for (PtCRefT pt : pts)
{
const int i = static_cast<int>(((pt[0] - bX) * fX));
const int j = static_cast<int>(((pt[1] - bY) * fY));
const int k = static_cast<int>(((pt[2] - bZ) * fZ));
......@@ -69,17 +72,17 @@ struct ExtractPoints
// If not inside image then skip
if (i < 0 || i >= xD || j < 0 || j >= yD || k < 0 || k >= zD)
{
return -1;
*map++ = -1;
}
else if (mask[i + j * xD + k * xyD] != emptyValue)
{
return 1;
*map++ = 1;
}
else
{
return -1;
*map++ = -1;
}
});
}
});
}
}; // ExtractPoints
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment