RigCell: Added faceIndices and faceNormal methods

This commit is contained in:
Jacob Støren 2013-12-10 22:36:57 +01:00
parent df411efe3f
commit 81176258bc
2 changed files with 33 additions and 1 deletions

View File

@ -229,10 +229,12 @@ cvf::Vec3d RigCell::faceCenter(cvf::StructGridInterface::FaceType face) const
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(face, faceVertexIndices);
const std::vector<cvf::Vec3d>& nodeCoords = m_hostGrid->mainGrid()->nodes();
size_t i;
for (i = 0; i < 4; i++)
{
avg += m_hostGrid->mainGrid()->nodes()[m_cornerIndices[faceVertexIndices[i]]];
avg += nodeCoords[m_cornerIndices[faceVertexIndices[i]]];
}
avg /= 4.0;
@ -240,6 +242,19 @@ cvf::Vec3d RigCell::faceCenter(cvf::StructGridInterface::FaceType face) const
return avg;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RigCell::faceNormal(cvf::StructGridInterface::FaceType face) const
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(face, faceVertexIndices);
const std::vector<cvf::Vec3d>& nodeCoords = m_hostGrid->mainGrid()->nodes();
return ( nodeCoords[m_cornerIndices[faceVertexIndices[2]]] - nodeCoords[m_cornerIndices[faceVertexIndices[0]]]) ^
( nodeCoords[m_cornerIndices[faceVertexIndices[3]]] - nodeCoords[m_cornerIndices[faceVertexIndices[1]]]);
}
//--------------------------------------------------------------------------------------------------
/// Find the intersection between the cell and the ray. The point closest to the ray origin is returned
/// in \a intersectionPoint, while the return value is the total number of intersections with the 24 triangles
@ -291,3 +306,17 @@ int RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectio
return intersectionCount;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCell::faceIndices(cvf::StructGridInterface::FaceType face, caf::SizeTArray4* indices) const
{
cvf::ubyte faceVertexIndices[4];
cvf::StructGridInterface::cellFaceVertexIndices(face, faceVertexIndices);
(*indices)[0] = m_cornerIndices[faceVertexIndices[0]];
(*indices)[1] = m_cornerIndices[faceVertexIndices[1]];
(*indices)[2] = m_cornerIndices[faceVertexIndices[2]];
(*indices)[3] = m_cornerIndices[faceVertexIndices[3]];
}

View File

@ -36,6 +36,7 @@ public:
caf::SizeTArray8& cornerIndices() { return m_cornerIndices;}
const caf::SizeTArray8& cornerIndices() const { return m_cornerIndices;}
void faceIndices(cvf::StructGridInterface::FaceType face, caf::SizeTArray4 * faceIndices) const ;
bool isInvalid() const { return m_isInvalid; }
void setInvalid( bool val ) { m_isInvalid = val; }
@ -62,6 +63,8 @@ public:
cvf::Vec3d center() const;
cvf::Vec3d faceCenter(cvf::StructGridInterface::FaceType face) const;
cvf::Vec3d faceNormal(cvf::StructGridInterface::FaceType face) const;
int firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectionPoint) const;
bool isLongPyramidCell(double maxHeightFactor = 5, double nodeNearTolerance = 1e-3 ) const;
private: