Some util function refactoring

parent 112f33d6
......@@ -388,10 +388,15 @@ namespace ITAGeo
inline double GetLength() const
{
double dLength = 0.0;
for (size_t i = 1; i < this->size(); i++)
{
//Add length of sub path
dLength += (at(i)->v3InteractionPoint - at(i - 1)->v3InteractionPoint).GetLength();
auto& v3From( at( i - 1 )->v3InteractionPoint );
auto& v3To( at( i )->v3InteractionPoint );
const double dSegmentLength = ( v3To - v3From ).GetLength();
// Add length of sub path
dLength += dSegmentLength;
}
return dLength;
......
......@@ -70,14 +70,15 @@ 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
//! Returns reflected direction of incident ray according to the principle of specular reflection (Snells law)
/**
* @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
* @param[in] pMesh Mesh of the scene
* @param[in] hFace Face handle for identifying the corresponding reflection face
* @param[in] rRay Incident ray which direction is to be changed
*
* @return Direction of specular reflection
*/
ITA_GEO_API void ReflectRayOnFace(VistaRay& rRay, CITAMesh *pMesh, CITAMesh::FaceHandle hFace, VistaVector3D& v3ReflectionPoint);
ITA_GEO_API VistaVector3D GetReflectedDirection( CITAMesh *pMesh, CITAMesh::FaceHandle hFace, const VistaRay& rRay );
//! Checks for intersection of a ray with a sphere
/**
......@@ -90,13 +91,13 @@ namespace ITAGeoUtils
//! 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]
* @param[out] fRandomAzimuthAngleRad: randomly distributed in the range [0, 2*pi]
* @param[out] fRandomElevationAngleRad: randomly distributed in the range [0, pi]
*/
ITA_GEO_API void SetUniformlyDistributedSphericalCoordinateAngles(float& fRandomAzimuthAngle, float& fRandomElevationAngle);
ITA_GEO_API void GetUniformlyDistributedSphericalCoordinateAngles(float& fRandomAzimuthAngleRad, float& fRandomElevationAngleRad);
//! 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 VistaVector3D GetUniformlyDistributedSphericalRandomDirection();
ITA_GEO_API ITAGeo::EIntersecting IsLineIntersectingFace(const VistaVector3D& v3StartPoint, const VistaVector3D& v3EndPoint, CITAMesh* pMesh, CITAMesh::FaceHandle hFace);
......
......@@ -427,7 +427,7 @@ bool ITAGeoUtils::RayDetectionSphereIntersectionTest(const VistaRay& rRay, std::
//return (abs(v3RayOrigin2RcvPos.GetLength() * sin(tDeviationAngle)) < fDetectionSphereRadius);
}
void ITAGeoUtils::ReflectRayOnFace(VistaRay& rRay, CITAMesh* pMesh, CITAMesh::FaceHandle hFace, VistaVector3D& v3ReflectionPoint)
VistaVector3D ITAGeoUtils::GetReflectedDirection( CITAMesh* pMesh, CITAMesh::FaceHandle hFace, const VistaRay& rRay )
{
assert(pMesh->has_face_normals());
......@@ -437,22 +437,21 @@ void ITAGeoUtils::ReflectRayOnFace(VistaRay& rRay, CITAMesh* pMesh, CITAMesh::Fa
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);
return rRay.GetDir() - 2 * v3OrthogonalComponent;
}
void ITAGeoUtils::SetUniformlyDistributedSphericalCoordinateAngles(float& fRandomAzimuthAngle, float& fRandomElevationAngle)
void ITAGeoUtils::GetUniformlyDistributedSphericalCoordinateAngles(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)
VistaVector3D ITAGeoUtils::GetUniformlyDistributedSphericalRandomDirection()
{
float fPhi, fTheta;
SetUniformlyDistributedSphericalCoordinateAngles(fPhi, fTheta);
GetUniformlyDistributedSphericalCoordinateAngles(fPhi, fTheta);
v3RandomDirection.SetValues(cos(fPhi) * sin(fTheta), sin(fPhi) * sin(fTheta), cos(fTheta));
return VistaVector3D(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 )
......
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