Commit a98c954c authored by Daniel Filbert's avatar Daniel Filbert

added spherical uniform distribution to ITAGeoUtils

parent 848d3e13
......@@ -70,6 +70,34 @@ namespace ITAGeoUtils
//! Returns only true, if a ray casts through given mesh face, false otherwise
ITA_GEO_API bool RayFaceIntersectionTest(const VistaRay& rRay, CITAMesh* pMesh, CITAMesh::FaceHandle hFace, VistaVector3D & v3IntersectionPoint, ITAGeo::ECulling eFaceCulling = ITAGeo::ECulling::BACKFACE);
//! Changes direction of incident ray according to the principle of specular reflection
/**
* @param[out] rRay: Incident ray which direction is to be changed
* @param[in] pMesh: Mesh of the scene
* @param[in] hFace: Face handle for identifying the corresponding reflection face
* @param[in] v3ReflectionPoint: Point of specular reflection on the face
*/
ITA_GEO_API void ReflectRayOnFace(VistaRay& rRay, CITAMesh *pMesh, CITAMesh::FaceHandle hFace, VistaVector3D& v3ReflectionPoint);
//! Checks for intersection of a ray with a sphere
/**
* @return: true if an intersection is given
* @param[in] rRay: ray
* @param[in] pDetectionSphereCenter: center of detection sphere
* @param[in] fDetectionSphereRadius: radius of detection sphere
*/
ITA_GEO_API bool RayDetectionSphereIntersectionTest(const VistaRay& rRay, std::shared_ptr< ITAGeo::CPropagationAnchor > pDetectionSphereCenter, float fDetectionSphereRadius, VistaVector3D& v3DetectionPoint);
//! Sets random angles according to uniformly distributed PDF on the surface of the unity sphere
/**
* @param[out] fRandomAzimuthAngle: randomly distributed in the range [0, 2*pi]
* @param[out] fRandomElevationAngle: randomly distributed in the range [0, pi]
*/
ITA_GEO_API void SetUniformlyDistributedSphericalCoordinateAngles(float& fRandomAzimuthAngle, float& fRandomElevationAngle);
//! Creates vector which random direction is uniformly distributed on the surface of the unity sphere
ITA_GEO_API void SetUniformlyDistributedSphericalRandomDirection(VistaVector3D& v3RandomDirection);
ITA_GEO_API ITAGeo::EIntersecting IsLineIntersectingFace(const VistaVector3D& v3StartPoint, const VistaVector3D& v3EndPoint, CITAMesh* pMesh, CITAMesh::FaceHandle hFace);
//! Mirrors point over a plane
......
......@@ -4,6 +4,8 @@
#include <ITAException.h>
#include <ITAConstants.h>
#include <VistaCoreLibs/VistaTools/VistaRandomNumberGenerator.h>
#include <cassert>
bool ITAGeoUtils::CalculateDiffractionAperturePoint( const VistaRay& rInfiniteDiffractionEdge, const VistaVector3D& v3SourcePos, const VistaVector3D& v3TargetPos, VistaVector3D& v3AperturePoint )
......@@ -412,6 +414,47 @@ bool ITAGeoUtils::RayFaceIntersectionTest( const VistaRay& rRay, CITAMesh* pMesh
}
}
bool ITAGeoUtils::RayDetectionSphereIntersectionTest(const VistaRay& rRay, std::shared_ptr< ITAGeo::CPropagationAnchor > pDestination, float fDetectionSphereRadius, VistaVector3D& v3DetectionPoint)
{
const VistaVector3D v3RayOrigin2RcvPos = pDestination->v3InteractionPoint - rRay.GetOrigin();
// Nearest Point of ray to detection sphere origin
v3DetectionPoint = rRay.GetDir().Dot(v3RayOrigin2RcvPos) * rRay.GetDir() + rRay.GetOrigin();
return ((v3DetectionPoint - pDestination->v3InteractionPoint).GetLength() <= fDetectionSphereRadius);
//float tDeviationAngle = acos(rRay.GetDir().Dot(v3RayOrigin2RcvPos.GetNormalized()));
//return (abs(v3RayOrigin2RcvPos.GetLength() * sin(tDeviationAngle)) < fDetectionSphereRadius);
}
void ITAGeoUtils::ReflectRayOnFace(VistaRay& rRay, CITAMesh* pMesh, CITAMesh::FaceHandle hFace, VistaVector3D& v3ReflectionPoint)
{
assert(pMesh->has_face_normals());
CITAMesh::Normal normal(pMesh->normal(hFace));
const VistaVector3D v3FaceNormal(normal.data());
VistaVector3D v3OrthogonalComponent = rRay.GetDir().Dot(v3FaceNormal) * v3FaceNormal; // direction component of incident ray orthogonal to reflection face
//! Change direction of ray orthogonal to reflection wall into the opposite direction
rRay.SetDir(rRay.GetDir() - 2 * v3OrthogonalComponent);
rRay.SetOrigin(v3ReflectionPoint);
}
void ITAGeoUtils::SetUniformlyDistributedSphericalCoordinateAngles(float& fRandomAzimuthAngle, float& fRandomElevationAngle)
{
fRandomAzimuthAngle = 2 * ITAConstants::PI_F * VistaRandomNumberGenerator::GetStandardRNG()->GenerateFloat(0.0f, 1.0f);
fRandomElevationAngle = acos(1.0f - 2.0f * VistaRandomNumberGenerator::GetStandardRNG()->GenerateFloat(0.0f, 1.0f));
}
void ITAGeoUtils::SetUniformlyDistributedSphericalRandomDirection(VistaVector3D& v3RandomDirection)
{
float fPhi, fTheta;
SetUniformlyDistributedSphericalCoordinateAngles(fPhi, fTheta);
v3RandomDirection.SetValues(cos(fPhi) * sin(fTheta), sin(fPhi) * sin(fTheta), cos(fTheta));
}
ITAGeo::EIntersecting ITAGeoUtils::IsLineIntersectingFace( const VistaVector3D & v3StartPoint, const VistaVector3D & v3EndPoint, CITAMesh * pMesh, CITAMesh::FaceHandle hFace )
{
//The point of intersection in relation to the ray
......@@ -706,4 +749,4 @@ bool ITAGeoUtils::VistaRaysFromOpenMeshFaceHalfedges( CITAMesh* pMesh, CITAMesh:
vRays.push_back( VistaRay( oStartPoint, oEndPoint - oStartPoint ) );
}
return true;
}
}
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