Commit 6950c8c6 authored by George Zagaris's avatar George Zagaris
Browse files

STYLE: Fix code identation + style

Change-Id: I9615c458407d09bc2da68ea97a64aa03f919ec08
parent 9cda4ca7
......@@ -33,12 +33,16 @@ double SafeDivision( const double a, const double b )
{
// Catch overflow
if( (b < 1) && (a > ( b*std::numeric_limits<double>::max() ) ) )
{
return std::numeric_limits<double>::max();
}
// Catch underflow
if( (a == static_cast<double>(0.0)) ||
( (b > 1) && (a < b*std::numeric_limits<double>::max() ) ) )
return( static_cast<double>( 0.0 ) );
{
return( static_cast<double>( 0.0 ) );
}
return( a/b );
}
......@@ -52,7 +56,9 @@ bool FloatNumberEquals( double a, double b, double TOL )
double d1 = SafeDivision( adiff,std::abs(a) );
double d2 = SafeDivision( adiff,std::abs(b) );
if( (d1 <= TOL) || (d2 <= TOL) )
{
return true;
}
return false;
}
......@@ -62,8 +68,10 @@ bool ArePointsEqual( double a[3], double b[3], double TOL=1e-9 )
{
for( int i=0; i < 3; ++i )
{
if( !FloatNumberEquals( a[i], b[i], TOL ) )
return false;
if( !FloatNumberEquals( a[i], b[i], TOL ) )
{
return false;
}
}
return true;
}
......@@ -87,8 +95,8 @@ vtkUniformGrid* GetGrid( double *origin, double *spacing, int *ndim )
double node[3];
for( int pntIdx=0; pntIdx < grd->GetNumberOfPoints(); ++pntIdx )
{
grd->GetPoint( pntIdx, node );
pntData->SetValue(pntIdx, (node[0]+node[1]+node[2]) );
grd->GetPoint( pntIdx, node );
pntData->SetValue(pntIdx, (node[0]+node[1]+node[2]) );
} // END for all points
grd->GetPointData()->AddArray( pntData );
pntData->Delete();
......@@ -101,32 +109,31 @@ vtkUniformGrid* GetGrid( double *origin, double *spacing, int *ndim )
for( int cellIdx=0; cellIdx < grd->GetNumberOfCells(); ++cellIdx )
{
vtkCell* myCell = grd->GetCell( cellIdx);
vtkPoints *cellPoints = myCell->GetPoints();
double xyzCenter[3];
xyzCenter[0] = 0.0;
xyzCenter[1] = 0.0;
xyzCenter[2] = 0.0;
for( int cp=0; cp < cellPoints->GetNumberOfPoints(); ++cp )
{
double pnt[3];
cellPoints->GetPoint( cp, pnt );
xyzCenter[0] += pnt[0];
xyzCenter[1] += pnt[1];
xyzCenter[2] += pnt[2];
} // END for all cell points
xyzCenter[0] = xyzCenter[0] / (cellPoints->GetNumberOfPoints());
xyzCenter[1] = xyzCenter[1] / (cellPoints->GetNumberOfPoints());
xyzCenter[2] = xyzCenter[2] / (cellPoints->GetNumberOfPoints());
double f = xyzCenter[0]*xyzCenter[0] +
xyzCenter[1]*xyzCenter[1] + xyzCenter[2]*xyzCenter[2];
xyz->SetTuple1(cellIdx,f);
vtkCell* myCell = grd->GetCell( cellIdx);
vtkPoints *cellPoints = myCell->GetPoints();
double xyzCenter[3];
xyzCenter[0] = 0.0;
xyzCenter[1] = 0.0;
xyzCenter[2] = 0.0;
for( int cp=0; cp < cellPoints->GetNumberOfPoints(); ++cp )
{
double pnt[3];
cellPoints->GetPoint( cp, pnt );
xyzCenter[0] += pnt[0];
xyzCenter[1] += pnt[1];
xyzCenter[2] += pnt[2];
} // END for all cell points
xyzCenter[0] = xyzCenter[0] / (cellPoints->GetNumberOfPoints());
xyzCenter[1] = xyzCenter[1] / (cellPoints->GetNumberOfPoints());
xyzCenter[2] = xyzCenter[2] / (cellPoints->GetNumberOfPoints());
double f = xyzCenter[0]*xyzCenter[0] +
xyzCenter[1]*xyzCenter[1] + xyzCenter[2]*xyzCenter[2];
xyz->SetTuple1(cellIdx,f);
} // END for all cells
grd->GetCellData()->AddArray(xyz);
......@@ -145,60 +152,85 @@ bool DataSetsEqual( vtkImageData* img, vtkStructuredGrid* sg )
sg->GetDimensions( sgdim );
for( int i=0; i < 3; ++i )
{
if( imgdim[i] != sgdim[i] )
return false;
if( imgdim[i] != sgdim[i] )
{
return false;
}
}
// 1. Check Number of elements
if( img->GetNumberOfCells() != sg->GetNumberOfCells() )
{
return false;
}
// 2. Check Number of points
if( img->GetNumberOfPoints() != sg->GetNumberOfPoints() )
{
return false;
}
// 3. Check Point equality
double pnt1[3]; double pnt2[3];
for( int pntIdx=0; pntIdx < img->GetNumberOfPoints(); ++pntIdx )
{
img->GetPoint( pntIdx, pnt1 );
sg->GetPoint( pntIdx,pnt2 );
if( !ArePointsEqual( pnt1, pnt2 ) )
return false;
img->GetPoint( pntIdx, pnt1 );
sg->GetPoint( pntIdx,pnt2 );
if( !ArePointsEqual( pnt1, pnt2 ) )
{
return false;
}
}
// 4. Check Point data equality
if( img->GetPointData()->GetNumberOfArrays() !=
sg->GetPointData()->GetNumberOfArrays() )
{
return false;
}
int dataArrayIdx = 0;
for(;dataArrayIdx<img->GetPointData()->GetNumberOfArrays();++dataArrayIdx )
{
vtkDataArray* array1 = img->GetPointData()->GetArray( dataArrayIdx );
vtkDataArray* array2 = sg->GetPointData()->GetArray( dataArrayIdx );
if( array1->GetNumberOfComponents() != array2->GetNumberOfComponents() )
return false;
if( array1->GetNumberOfTuples() != array2->GetNumberOfTuples() )
return false;
if( std::strcmp( array1->GetName(), array2->GetName() ) != 0 )
return false;
vtkDataArray* array1 = img->GetPointData()->GetArray( dataArrayIdx );
vtkDataArray* array2 = sg->GetPointData()->GetArray( dataArrayIdx );
if( array1->GetNumberOfComponents() != array2->GetNumberOfComponents() )
{
return false;
}
if( array1->GetNumberOfTuples() != array2->GetNumberOfTuples() )
{
return false;
}
if( std::strcmp( array1->GetName(), array2->GetName() ) != 0 )
{
return false;
}
} // END for all point arrays
// 5. Check Cell data equality
if( img->GetCellData()->GetNumberOfArrays() !=
sg->GetCellData()->GetNumberOfArrays() )
{
return false;
}
dataArrayIdx = 0;
for(;dataArrayIdx<img->GetCellData()->GetNumberOfArrays();++dataArrayIdx)
{
vtkDataArray* array1 = img->GetCellData()->GetArray( dataArrayIdx );
vtkDataArray* array2 = sg->GetCellData()->GetArray( dataArrayIdx );
if( array1->GetNumberOfComponents() != array2->GetNumberOfComponents() )
return false;
if( array1->GetNumberOfTuples() != array2->GetNumberOfTuples() )
return false;
if( std::strcmp( array1->GetName(), array2->GetName() ) != 0 )
return false;
vtkDataArray* array1 = img->GetCellData()->GetArray( dataArrayIdx );
vtkDataArray* array2 = sg->GetCellData()->GetArray( dataArrayIdx );
if( array1->GetNumberOfComponents() != array2->GetNumberOfComponents() )
{
return false;
}
if( array1->GetNumberOfTuples() != array2->GetNumberOfTuples() )
{
return false;
}
if( std::strcmp( array1->GetName(), array2->GetName() ) != 0 )
{
return false;
}
} // END for all cell arrays
return true;
......@@ -220,7 +252,9 @@ int TestImageDataToStructuredGrid(int,char *[])
vtkStructuredGrid* sg1 = myFilter->GetOutput();
if( !DataSetsEqual( img1, sg1 ) )
rval = 1;
{
rval = 1;
}
myFilter->Delete();
return( rval );
......
Supports Markdown
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