Commit 0e775c88 authored by George Zagaris's avatar George Zagaris
Browse files

BUGFIX: Full 2-D/3-D AMR box intersection

Change-Id: I4dfb70d42ca0e93253e1ccd339d6f6e9d7dee8e7
parent d9c0d955
......@@ -1047,6 +1047,24 @@ bool vtkAMRBox::operator==(const vtkAMRBox &other)
return false;
}
//-----------------------------------------------------------------------------
bool vtkAMRBox::DoesBoxIntersectAlongDimension(
const vtkAMRBox &other, const int q)
{
int minVal = 0;
int maxVal = 0;
minVal = (this->LoCorner[q] < other.LoCorner[q]) ?
other.LoCorner[q] : this->LoCorner[q];
maxVal = (this->HiCorner[q] > other.HiCorner[q]) ?
other.HiCorner[q] : this->HiCorner[q];
if (minVal >= maxVal)
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------
bool vtkAMRBox::DoesIntersect(const vtkAMRBox &other)
{
......@@ -1069,18 +1087,69 @@ bool vtkAMRBox::DoesIntersect(const vtkAMRBox &other)
// Compare each coordinate of the corners. Stop if at
// anytime the box becomes invalid - i.e. there is no intersection
int minVal, maxVal;
for (int q=0; q<this->Dimension; ++q)
switch( this->Dimension )
{
minVal =
(this->LoCorner[q] < other.LoCorner[q]) ? other.LoCorner[q] : this->LoCorner[q];
maxVal =
(this->HiCorner[q] > other.HiCorner[q]) ? other.HiCorner[q] : this->HiCorner[q];
if (minVal >= maxVal)
{
case 2:
switch( this->GridDescription )
{
case VTK_XY_PLANE:
if( !this->DoesBoxIntersectAlongDimension(other,0) ||
!this->DoesBoxIntersectAlongDimension(other,1) )
{
return false;
}
break;
case VTK_XZ_PLANE:
if( !this->DoesBoxIntersectAlongDimension(other,0) ||
!this->DoesBoxIntersectAlongDimension(other,2) )
{
return false;
}
break;
case VTK_YZ_PLANE:
if( !this->DoesBoxIntersectAlongDimension(other,1) ||
!this->DoesBoxIntersectAlongDimension(other,2) )
{
return false;
}
break;
default:
std::cerr << "Invalid 2-D topoly for AMR box!\n";
std::cerr << "FILE: " << __FILE__ << std::endl;
std::cerr << "LINE: " << __LINE__ << std::endl;
std::cerr.flush();
}
break;
case 3:
if( !this->DoesBoxIntersectAlongDimension(other,0) ||
!this->DoesBoxIntersectAlongDimension(other,1) ||
!this->DoesBoxIntersectAlongDimension(other,2) )
{
return false;
}
break;
default:
vtkGenericWarningMacro( "Can't operate on a " << this->Dimension );
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
bool vtkAMRBox::IntersectBoxAlongDimension(const vtkAMRBox &other, const int q)
{
assert( "pre: dimension is out-of-bounds!" && (q >= 0) && (q <= 2) );
if( this->LoCorner[q] <= other.LoCorner[q] )
{
this->LoCorner[q] = other.LoCorner[q];
}
if (this->HiCorner[q] >= other.HiCorner[q])
{
this->HiCorner[q] = other.HiCorner[q];
}
if (this->LoCorner[q] >= this->HiCorner[q])
{
return false;
}
return true;
}
......@@ -1108,20 +1177,50 @@ bool vtkAMRBox::Intersect(const vtkAMRBox &other)
// Compare each coordinate of the corners. Stop if at
// anytime the box becomes invalid - i.e. there is no intersection
for (int q=0; q<this->Dimension; ++q)
switch( this->Dimension )
{
if (this->LoCorner[q] < other.LoCorner[q])
{
this->LoCorner[q] = other.LoCorner[q];
}
if (this->HiCorner[q] > other.HiCorner[q])
{
this->HiCorner[q] = other.HiCorner[q];
}
if (this->LoCorner[q] >= this->HiCorner[q])
{
case 2:
switch( this->GridDescription )
{
case VTK_XY_PLANE:
if( !this->IntersectBoxAlongDimension(other,0) ||
!this->IntersectBoxAlongDimension(other,1) )
{
return false;
}
break;
case VTK_XZ_PLANE:
if( !this->IntersectBoxAlongDimension(other,0) ||
!this->IntersectBoxAlongDimension(other,2) )
{
return false;
}
break;
case VTK_YZ_PLANE:
if( !this->IntersectBoxAlongDimension(other,1) ||
!this->IntersectBoxAlongDimension(other,2) )
{
return false;
}
break;
default:
std::cerr << "Invalid 2-D topoly for AMR box!\n";
std::cerr << "FILE: " << __FILE__ << std::endl;
std::cerr << "LINE: " << __LINE__ << std::endl;
std::cerr.flush();
}
break;
case 3:
if( !this->IntersectBoxAlongDimension(other,0) ||
!this->IntersectBoxAlongDimension(other,1) ||
!this->IntersectBoxAlongDimension(other,2) )
{
return false;
}
break;
default:
vtkGenericWarningMacro( "Can't operate on a " << this->Dimension );
return false;
}
}
return true;
}
......
......@@ -364,6 +364,19 @@ private:
int RealExtent[6]; // Extent of the all the real nodes, i.e., not the ghosts
int GridDescription; // Defines whether the box is on the XY,YZ planes.
// Description:
// Checks if this instance of vtkAMRBox intersects with the box passed through
// the argument list along the given dimension q. True is returned iff the box
// intersects successfully. Otherwise, there is no intersection along the
// given dimension and false is returned.
bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q);
// Description:
// Intersects this instance of vtkAMRbox with box passed through the argument
// list along the given dimension q. True is returned iff the box intersects
// successfully. Otherwise, false is returned if there is no intersection at
// the given dimension.
bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q);
// Description:
// This method builds the AMR box with the given dimensions.
......
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