Commit f0e47019 authored by Kitware Robot's avatar Kitware Robot Committed by Ben Boeckel
Browse files

reformat: do another reformat sweep of the repository

It looks as though some files have slipped through.
parent 0ecb5572
......@@ -30,7 +30,8 @@
vtkStandardNewMacro(vtkElevationFilter);
namespace {
namespace
{
// The heart of the algorithm plus interface to the SMP tools.
template <class PointArrayT>
......@@ -45,16 +46,13 @@ struct vtkElevationAlgorithm
const double* V;
double L2;
vtkElevationAlgorithm(PointArrayT* pointArray,
vtkElevationFilter* filter,
float* scalars,
const double* v,
double l2)
: NumPts{pointArray->GetNumberOfTuples()}
, PointArray{pointArray}
, Scalars{scalars}
, V{v}
, L2{l2}
vtkElevationAlgorithm(
PointArrayT* pointArray, vtkElevationFilter* filter, float* scalars, const double* v, double l2)
: NumPts{ pointArray->GetNumberOfTuples() }
, PointArray{ pointArray }
, Scalars{ scalars }
, V{ v }
, L2{ l2 }
{
filter->GetLowPoint(this->LowPoint);
filter->GetHighPoint(this->HighPoint);
......@@ -74,8 +72,7 @@ struct vtkElevationAlgorithm
float* s = this->Scalars + begin;
// input points:
const auto pointRange = vtk::DataArrayTupleRange<3>(this->PointArray,
begin, end);
const auto pointRange = vtk::DataArrayTupleRange<3>(this->PointArray, begin, end);
for (const auto point : pointRange)
{
......@@ -87,7 +84,7 @@ struct vtkElevationAlgorithm
const double ns = vtkMath::ClampValue(vtkMath::Dot(vec, v) / l2, 0., 1.);
// Store the resulting scalar value.
*s = static_cast<float>(range[0] + ns*diffScalar);
*s = static_cast<float>(range[0] + ns * diffScalar);
++s;
}
}
......@@ -98,14 +95,11 @@ struct vtkElevationAlgorithm
struct Elevate
{
template <typename PointArrayT>
void operator()(PointArrayT* pointArray,
vtkElevationFilter* filter,
double* v,
double l2,
float* scalars)
void operator()(
PointArrayT* pointArray, vtkElevationFilter* filter, double* v, double l2, float* scalars)
{
// Okay now generate samples using SMP tools
vtkElevationAlgorithm<PointArrayT> algo{pointArray, filter, scalars, v, l2};
vtkElevationAlgorithm<PointArrayT> algo{ pointArray, filter, scalars, v, l2 };
vtkSMPTools::For(0, pointArray->GetNumberOfTuples(), algo);
}
};
......@@ -183,17 +177,16 @@ int vtkElevationFilter::RequestData(
vtkPointSet* ps = vtkPointSet::SafeDownCast(input);
if (ps)
{
float *scalars = newScalars->GetPointer(0);
vtkPoints *points = ps->GetPoints();
vtkDataArray *pointsArray = points->GetData();
float* scalars = newScalars->GetPointer(0);
vtkPoints* points = ps->GetPoints();
vtkDataArray* pointsArray = points->GetData();
Elevate worker; // Entry point to vtkElevationAlgorithm
// Generate an optimized fast-path for float/double
using FastValueTypes = vtkArrayDispatch::Reals;
using Dispatcher = vtkArrayDispatch::DispatchByValueType<FastValueTypes>;
if (!Dispatcher::Execute(pointsArray, worker, this, diffVector, length2,
scalars))
if (!Dispatcher::Execute(pointsArray, worker, this, diffVector, length2, scalars))
{ // fallback for unknown arrays and integral value types:
worker(pointsArray, this, diffVector, length2, scalars);
}
......
......@@ -82,14 +82,14 @@ vtkMTimeType vtkMarchingCubes::GetMTime()
return mTime;
}
namespace {
namespace
{
// Calculate the gradient using central difference.
// NOTE: We calculate the negative of the gradient for efficiency
template <class ScalarRangeT>
void vtkMarchingCubesComputePointGradient(int i, int j, int k,
const ScalarRangeT s, int dims[3],
vtkIdType sliceSize, double n[3])
void vtkMarchingCubesComputePointGradient(
int i, int j, int k, const ScalarRangeT s, int dims[3], vtkIdType sliceSize, double n[3])
{
double sp, sm;
......@@ -160,25 +160,18 @@ void vtkMarchingCubesComputePointGradient(int i, int j, int k,
struct ComputeGradientWorker
{
template <class ScalarArrayT>
void operator()(ScalarArrayT *scalarsArray,
vtkMarchingCubes *self,
int dims[3],
vtkIncrementalPointLocator *locator,
vtkDataArray *newScalars,
vtkDataArray *newGradients,
vtkDataArray *newNormals,
vtkCellArray *newPolys,
double *values,
vtkIdType numValues) const
void operator()(ScalarArrayT* scalarsArray, vtkMarchingCubes* self, int dims[3],
vtkIncrementalPointLocator* locator, vtkDataArray* newScalars, vtkDataArray* newGradients,
vtkDataArray* newNormals, vtkCellArray* newPolys, double* values, vtkIdType numValues) const
{
const auto scalars = vtk::DataArrayValueRange<1>(scalarsArray);
double s[8], value;
int i, j, k;
vtkIdType sliceSize;
static const int CASE_MASK[8] = {1,2,4,8,16,32,64,128};
static const int CASE_MASK[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
vtkMarchingCubesTriangleCases *triCase, *triCases;
EDGE_LIST *edge;
EDGE_LIST* edge;
int contNum, jOffset, ii, index, *vert;
vtkIdType kOffset, idx;
vtkIdType ptIds[3];
......@@ -189,30 +182,29 @@ struct ComputeGradientWorker
int extent[6];
double t, *x1, *x2, x[3], *n1, *n2, n[3], min, max;
double pts[8][3], gradients[8][3], xp, yp, zp;
static int edges[12][2] = { {0,1}, {1,2}, {3,2}, {0,3},
{4,5}, {5,6}, {7,6}, {4,7},
{0,4}, {1,5}, {3,7}, {2,6}};
static int edges[12][2] = { { 0, 1 }, { 1, 2 }, { 3, 2 }, { 0, 3 }, { 4, 5 }, { 5, 6 },
{ 7, 6 }, { 4, 7 }, { 0, 4 }, { 1, 5 }, { 3, 7 }, { 2, 6 } };
vtkInformation *inInfo = self->GetExecutive()->GetInputInformation(0, 0);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),extent);
vtkInformation* inInfo = self->GetExecutive()->GetInputInformation(0, 0);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
triCases = vtkMarchingCubesTriangleCases::GetCases();
triCases = vtkMarchingCubesTriangleCases::GetCases();
//
// Get min/max contour values
//
if ( numValues < 1 )
if (numValues < 1)
{
return;
}
for ( min=max=values[0], i=1; i < numValues; i++)
for (min = max = values[0], i = 1; i < numValues; i++)
{
if ( values[i] < min )
if (values[i] < min)
{
min = values[i];
}
if ( values[i] > max )
if (values[i] > max)
{
max = values[i];
}
......@@ -222,44 +214,44 @@ struct ComputeGradientWorker
// using marching cubes algorithm.
//
sliceSize = dims[0] * dims[1];
for ( k=0; k < (dims[2]-1); k++)
for (k = 0; k < (dims[2] - 1); k++)
{
self->UpdateProgress (k / static_cast<double>(dims[2] - 1));
self->UpdateProgress(k / static_cast<double>(dims[2] - 1));
if (self->GetAbortExecute())
{
break;
}
kOffset = k*sliceSize;
pts[0][2] = k+extent[4];
kOffset = k * sliceSize;
pts[0][2] = k + extent[4];
zp = pts[0][2] + 1;
for ( j=0; j < (dims[1]-1); j++)
for (j = 0; j < (dims[1] - 1); j++)
{
jOffset = j*dims[0];
pts[0][1] = j+extent[2];
jOffset = j * dims[0];
pts[0][1] = j + extent[2];
yp = pts[0][1] + 1;
for ( i=0; i < (dims[0]-1); i++)
for (i = 0; i < (dims[0] - 1); i++)
{
//get scalar values
// get scalar values
idx = i + jOffset + kOffset;
s[0] = scalars[idx];
s[1] = scalars[idx+1];
s[2] = scalars[idx+1 + dims[0]];
s[1] = scalars[idx + 1];
s[2] = scalars[idx + 1 + dims[0]];
s[3] = scalars[idx + dims[0]];
s[4] = scalars[idx + sliceSize];
s[5] = scalars[idx+1 + sliceSize];
s[6] = scalars[idx+1 + dims[0] + sliceSize];
s[5] = scalars[idx + 1 + sliceSize];
s[6] = scalars[idx + 1 + dims[0] + sliceSize];
s[7] = scalars[idx + dims[0] + sliceSize];
if ( (s[0] < min && s[1] < min && s[2] < min && s[3] < min &&
s[4] < min && s[5] < min && s[6] < min && s[7] < min) ||
(s[0] > max && s[1] > max && s[2] > max && s[3] > max &&
s[4] > max && s[5] > max && s[6] > max && s[7] > max) )
if ((s[0] < min && s[1] < min && s[2] < min && s[3] < min && s[4] < min && s[5] < min &&
s[6] < min && s[7] < min) ||
(s[0] > max && s[1] > max && s[2] > max && s[3] > max && s[4] > max && s[5] > max &&
s[6] > max && s[7] > max))
{
continue; // no contours possible
}
//create voxel points
pts[0][0] = i+extent[0];
// create voxel points
pts[0][0] = i + extent[0];
xp = pts[0][0] + 1;
pts[1][0] = xp;
......@@ -292,39 +284,46 @@ struct ComputeGradientWorker
NeedGradients = ComputeGradients || ComputeNormals;
//create gradients if needed
// create gradients if needed
if (NeedGradients)
{
vtkMarchingCubesComputePointGradient(i,j,k, scalars, dims, sliceSize, gradients[0]);
vtkMarchingCubesComputePointGradient(i+1,j,k, scalars, dims, sliceSize, gradients[1]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k, scalars, dims, sliceSize, gradients[2]);
vtkMarchingCubesComputePointGradient(i,j+1,k, scalars, dims, sliceSize, gradients[3]);
vtkMarchingCubesComputePointGradient(i,j,k+1, scalars, dims, sliceSize, gradients[4]);
vtkMarchingCubesComputePointGradient(i+1,j,k+1, scalars, dims, sliceSize, gradients[5]);
vtkMarchingCubesComputePointGradient(i+1,j+1,k+1, scalars, dims, sliceSize, gradients[6]);
vtkMarchingCubesComputePointGradient(i,j+1,k+1, scalars, dims, sliceSize, gradients[7]);
vtkMarchingCubesComputePointGradient(i, j, k, scalars, dims, sliceSize, gradients[0]);
vtkMarchingCubesComputePointGradient(
i + 1, j, k, scalars, dims, sliceSize, gradients[1]);
vtkMarchingCubesComputePointGradient(
i + 1, j + 1, k, scalars, dims, sliceSize, gradients[2]);
vtkMarchingCubesComputePointGradient(
i, j + 1, k, scalars, dims, sliceSize, gradients[3]);
vtkMarchingCubesComputePointGradient(
i, j, k + 1, scalars, dims, sliceSize, gradients[4]);
vtkMarchingCubesComputePointGradient(
i + 1, j, k + 1, scalars, dims, sliceSize, gradients[5]);
vtkMarchingCubesComputePointGradient(
i + 1, j + 1, k + 1, scalars, dims, sliceSize, gradients[6]);
vtkMarchingCubesComputePointGradient(
i, j + 1, k + 1, scalars, dims, sliceSize, gradients[7]);
}
for (contNum=0; contNum < numValues; contNum++)
for (contNum = 0; contNum < numValues; contNum++)
{
value = values[contNum];
// Build the case table
for ( ii=0, index = 0; ii < 8; ii++)
for (ii = 0, index = 0; ii < 8; ii++)
{
if ( s[ii] >= value )
if (s[ii] >= value)
{
index |= CASE_MASK[ii];
}
}
if ( index == 0 || index == 255 ) //no surface
if (index == 0 || index == 255) // no surface
{
continue;
}
triCase = triCases+ index;
triCase = triCases + index;
edge = triCase->edges;
for ( ; edge[0] > -1; edge += 3 )
for (; edge[0] > -1; edge += 3)
{
for (ii=0; ii<3; ii++) //insert triangle
for (ii = 0; ii < 3; ii++) // insert triangle
{
vert = edges[edge[ii]];
t = (value - s[vert[0]]) / (s[vert[1]] - s[vert[0]]);
......@@ -335,7 +334,7 @@ struct ComputeGradientWorker
x[2] = x1[2] + t * (x2[2] - x1[2]);
// check for a new point
if ( locator->InsertUniquePoint(x, ptIds[ii]) )
if (locator->InsertUniquePoint(x, ptIds[ii]))
{
if (NeedGradients)
{
......@@ -347,31 +346,29 @@ struct ComputeGradientWorker
}
if (ComputeScalars)
{
newScalars->InsertTuple(ptIds[ii],&value);
newScalars->InsertTuple(ptIds[ii], &value);
}
if (ComputeGradients)
{
newGradients->InsertTuple(ptIds[ii],n);
newGradients->InsertTuple(ptIds[ii], n);
}
if (ComputeNormals)
{
vtkMath::Normalize(n);
newNormals->InsertTuple(ptIds[ii],n);
newNormals->InsertTuple(ptIds[ii], n);
}
}
}
// check for degenerate triangle
if ( ptIds[0] != ptIds[1] &&
ptIds[0] != ptIds[2] &&
ptIds[1] != ptIds[2] )
if (ptIds[0] != ptIds[1] && ptIds[0] != ptIds[2] && ptIds[1] != ptIds[2])
{
newPolys->InsertNextCell(3,ptIds);
newPolys->InsertNextCell(3, ptIds);
}
}//for each triangle
}//for all contours
}//for i
}//for j
}//for k
} // for each triangle
} // for all contours
} // for i
} // for j
} // for k
}
};
......@@ -436,7 +433,7 @@ int vtkMarchingCubes::RequestData(vtkInformation* vtkNotUsed(request),
return 1;
}
if ( input->GetDataDimension() != 3 )
if (input->GetDataDimension() != 3)
{
vtkErrorMacro(<< "Cannot contour data of dimension != 3");
return 1;
......@@ -504,12 +501,11 @@ int vtkMarchingCubes::RequestData(vtkInformation* vtkNotUsed(request),
using Dispatcher = vtkArrayDispatch::Dispatch;
ComputeGradientWorker worker;
if (!Dispatcher::Execute(inScalars, worker, this, dims, this->Locator,
newScalars, newGradients, newNormals, newPolys,
values, numContours))
if (!Dispatcher::Execute(inScalars, worker, this, dims, this->Locator, newScalars, newGradients,
newNormals, newPolys, values, numContours))
{ // Fallback to slow path for unknown arrays:
worker(inScalars, this, dims, this->Locator, newScalars, newGradients,
newNormals, newPolys, values, numContours);
worker(inScalars, this, dims, this->Locator, newScalars, newGradients, newNormals, newPolys,
values, numContours);
}
vtkDebugMacro(<< "Created: " << newPts->GetNumberOfPoints() << " points, "
......
......@@ -101,7 +101,8 @@ vtkMTimeType vtkMarchingSquares::GetMTime()
return mTime;
}
namespace {
namespace
{
//
// Contouring filter specialized for images
......@@ -109,17 +110,9 @@ namespace {
struct ContourImageWorker
{
template <typename ScalarArrayT>
void operator()(ScalarArrayT *inScalars,
vtkDataArray *newScalars,
int roi[6],
int dir[3],
int start[2],
int end[2],
int offset[3],
double *values,
vtkIdType numValues,
vtkIncrementalPointLocator *p,
vtkCellArray *lines)
void operator()(ScalarArrayT* inScalars, vtkDataArray* newScalars, int roi[6], int dir[3],
int start[2], int end[2], int offset[3], double* values, vtkIdType numValues,
vtkIncrementalPointLocator* p, vtkCellArray* lines)
{
const auto scalars = vtk::DataArrayValueRange<1>(inScalars);
......@@ -128,61 +121,61 @@ struct ContourImageWorker
double t, x[3];
double min, max;
int contNum, jOffset, idx, ii, jj, index, *vert;
static const int CASE_MASK[4] = {1,2,8,4};
static const int CASE_MASK[4] = { 1, 2, 8, 4 };
vtkMarchingSquaresLineCases *lineCase, *lineCases;
static int edges[4][2] = { {0,1}, {1,3}, {2,3}, {0,2} };
EDGE_LIST *edge;
static int edges[4][2] = { { 0, 1 }, { 1, 3 }, { 2, 3 }, { 0, 2 } };
EDGE_LIST* edge;
double value, s[4];
lineCases = vtkMarchingSquaresLineCases::GetCases();
//
// Get min/max contour values
//
if ( numValues < 1 )
if (numValues < 1)
{
return;
}
for ( min=max=values[0], i=1; i < numValues; i++)
for (min = max = values[0], i = 1; i < numValues; i++)
{
if ( values[i] < min )
if (values[i] < min)
{
min = values[i];
}
if ( values[i] > max )
if (values[i] > max)
{
max = values[i];
}
}
//assign coordinate value to non-varying coordinate direction
x[dir[2]] = roi[dir[2]*2];
// assign coordinate value to non-varying coordinate direction
x[dir[2]] = roi[dir[2] * 2];
// Traverse all pixel cells, generating line segments using marching squares.
for ( j=roi[start[1]]; j < roi[end[1]]; j++ )
for (j = roi[start[1]]; j < roi[end[1]]; j++)
{
jOffset = j * offset[1];
pts[0][dir[1]] = j;
yp = j+1;
yp = j + 1;
for ( i=roi[start[0]]; i < roi[end[0]]; i++)
for (i = roi[start[0]]; i < roi[end[0]]; i++)
{
//get scalar values
// get scalar values
idx = i * offset[0] + jOffset + offset[2];
s[0] = scalars[idx];
s[1] = scalars[idx+offset[0]];
s[1] = scalars[idx + offset[0]];
s[2] = scalars[idx + offset[1]];
s[3] = scalars[idx+offset[0] + offset[1]];
s[3] = scalars[idx + offset[0] + offset[1]];
if ( (s[0] < min && s[1] < min && s[2] < min && s[3] < min) ||
(s[0] > max && s[1] > max && s[2] > max && s[3] > max) )
if ((s[0] < min && s[1] < min && s[2] < min && s[3] < min) ||
(s[0] > max && s[1] > max && s[2] > max && s[3] > max))
{
continue; // no contours possible
}
//create pixel points
// create pixel points
pts[0][dir[0]] = i;
xp = i+1;
xp = i + 1;
pts[1][dir[0]] = xp;
pts[1][dir[1]] = pts[0][dir[1]];
......@@ -194,53 +187,53 @@ struct ContourImageWorker
pts[3][dir[1]] = yp;
// Loop over contours in this pixel
for (contNum=0; contNum < numValues; contNum++)
for (contNum = 0; contNum < numValues; contNum++)
{
value = values[contNum];
// Build the case table
for ( ii=0, index = 0; ii < 4; ii++)
for (ii = 0, index = 0; ii < 4; ii++)
{
if ( s[ii] >= value )
if (s[ii] >= value)
{
index |= CASE_MASK[ii];
}
}
if ( index == 0 || index == 15 )
if (index == 0 || index == 15)
{
continue; //no lines
continue; // no lines
}
lineCase = lineCases + index;
edge = lineCase->edges;
for ( ; edge[0] > -1; edge += 2 )
for (; edge[0] > -1; edge += 2)
{
for (ii=0; ii<2; ii++) //insert line
for (ii = 0; ii < 2; ii++) // insert line
{
vert = edges[edge[ii]];
t = (value - s[vert[0]]) / (s[vert[1]] - s[vert[0]]);
x1 = pts[vert[0]];
x2 = pts[vert[1]];
for (jj=0; jj<2; jj++) //only need to interpolate two values
for (jj = 0; jj < 2; jj++) // only need to interpolate two values
{
x[dir[jj]] = x1[dir[jj]] + t * (x2[dir[jj]] - x1[dir[jj]]);
}
if ( p->InsertUniquePoint(x, ptIds[ii]) )
if (p->InsertUniquePoint(x, ptIds[ii]))
{
newScalars->InsertComponent(ptIds[ii],0,value);
newScalars->InsertComponent(ptIds[ii], 0, value);
}
}
if ( ptIds[0] != ptIds[1] ) //check for degenerate line
if (ptIds[0] != ptIds[1]) // check for degenerate line
{
lines->InsertNextCell(2,ptIds);
lines->InsertNextCell(2, ptIds);
}
}//for each line
}//for all contours
}//for i
}//for j
} // for each line
} // for all contours
} // for i
} // for j
}
};
......@@ -257,16 +250,16 @@ int vtkMarchingSquares::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformation* outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkImageData *input = vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPointData *pd;
vtkPoints *newPts;
vtkCellArray *newLines;
vtkDataArray *inScalars;
vtkDataArray *newScalars = nullptr;
int i, dims[3], roi[6], dim, plane=0;