Commit 29f3adb9 authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

ART - RayGrid

- creating new vectors now allocates memory first
- get functions for vectors now return const references
parent 34071603
......@@ -51,15 +51,15 @@ namespace ITAPropagationPathSim
bool bCircularPhi = false; //< Indicates whether the azimuth vector is considered to be circular (phi covers full 360 degrees) or not.
private:
CRayGrid(const RayMatrix& rayMatrix, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool& circularPhi = false);
CRayGrid(const RayMatrix& rayMatrix, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool circularPhi = false);
public:
CRayGrid(const VistaVector3D& sourcePos, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool& circularPhi = false);
CRayGrid(const VistaVector3D& sourcePos, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool circularPhi = false);
protected:
CRayGrid() {}
void InitRayVectorFromRayMatrix();
private:
int IndexToThetaIndex(const int& idx) const;
int IndexToPhiIndex(const int& idx) const;
int IndexToThetaIndex(const int idx) const;
int IndexToPhiIndex(const int idx) const;
int GetIndex(const std::shared_ptr<CRay>& pRay) const;
void GetNeighboringAngleIndices(const std::shared_ptr<CRay>& pRay, std::vector<int>& thetaIdxVec, std::vector<int>& phiIdxVec) const;
bool HasPoleDirection(const std::shared_ptr<CRay>& pRay) const;
......@@ -68,13 +68,13 @@ namespace ITAPropagationPathSim
protected:
const std::vector<std::shared_ptr<CRay>>& ConstRayVectorReference() const { return vpRays; }
public:
std::vector<double> ThetaDeg() const { return vdThetaDeg; }
std::vector<double> PhiDeg() const { return vdPhiDeg; }
const std::vector<double>& ThetaDeg() const { return vdThetaDeg; }
const std::vector<double>& PhiDeg() const { return vdPhiDeg; }
int NTheta() const { return vdThetaDeg.size(); }
int NPhi() const { return vdPhiDeg.size(); }
int NRays() const { return vpRays.size(); }
VistaVector3D SourcePosition() const { return v3SourcePos; }
std::vector<std::shared_ptr<CRay>> Rays() const { return vpRays; }
const VistaVector3D& SourcePosition() const { return v3SourcePos; }
const std::vector<std::shared_ptr<CRay>>& Rays() const { return vpRays; }
bool IsEmpty() const { return NTheta() == 0 || NPhi() == 0; }
bool Contains(std::shared_ptr<CRay> pRay) const { return std::find(vpRays.cbegin(), vpRays.cend(), pRay) == vpRays.cend(); }
......@@ -97,8 +97,8 @@ namespace ITAPropagationPathSim
class ITA_PROPAGATION_PATH_SIM_API CEquiangularRayDistribution : public CRayGrid
{
public:
CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int& nAngles) : CEquiangularRayDistribution(sourcePos, nAngles, nAngles) {}
CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int& nTheta, const int& nPhi);
CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int nAngles) : CEquiangularRayDistribution(sourcePos, nAngles, nAngles) {}
CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int nTheta, const int nPhi);
};
}
}
......
......@@ -14,7 +14,7 @@ using namespace ITAPropagationPathSim::AtmosphericRayTracing;
// --------------------
#pragma region Constructors
CRayGrid::CRayGrid(const RayMatrix& rayMatrix, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool& circularPhi /*= false*/)
CRayGrid::CRayGrid(const RayMatrix& rayMatrix, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool circularPhi /*= false*/)
: vvpRayMatrix(rayMatrix), vdThetaDeg(thetaDeg), vdPhiDeg(phiDeg), bCircularPhi(circularPhi)
{
InitRayVectorFromRayMatrix();
......@@ -23,7 +23,7 @@ CRayGrid::CRayGrid(const RayMatrix& rayMatrix, const std::vector<double>& thetaD
v3SourcePos = vpRays.front()->SourcePoint();
}
CRayGrid::CRayGrid(const VistaVector3D& sourcePos, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool& circularPhi /*= false*/)
CRayGrid::CRayGrid(const VistaVector3D& sourcePos, const std::vector<double>& thetaDeg, const std::vector<double>& phiDeg, const bool circularPhi /*= false*/)
: v3SourcePos(sourcePos), vdThetaDeg(thetaDeg), vdPhiDeg(phiDeg), bCircularPhi(circularPhi)
{
std::sort(vdPhiDeg.begin(), vdPhiDeg.end());
......@@ -36,28 +36,31 @@ CRayGrid::CRayGrid(const VistaVector3D& sourcePos, const std::vector<double>& th
if ( (vdPhiDeg.back() - vdPhiDeg.front()) >= 360.0)
ITA_EXCEPT_INVALID_PARAMETER("Delta for azimuth angle phi is >= 360");
for (int idxTheta = 0; idxTheta < thetaDeg.size(); idxTheta++)
vvpRayMatrix.resize( NTheta() );
for (int idxTheta = 0; idxTheta < NTheta(); idxTheta++)
{
vvpRayMatrix.push_back(std::vector< std::shared_ptr<CRay>>());
bool isPoleDirection = (abs(thetaDeg[idxTheta]) < DBL_EPSILON || abs(thetaDeg[idxTheta] - 180.0) < DBL_EPSILON);
for (int idxPhi = 0; idxPhi < phiDeg.size(); idxPhi++)
vvpRayMatrix[idxTheta] = std::vector< std::shared_ptr<CRay>>( NPhi());
bool isPoleDirection = (abs(vdThetaDeg[idxTheta]) < DBL_EPSILON || abs(vdThetaDeg[idxTheta] - 180.0) < DBL_EPSILON);
for (int idxPhi = 0; idxPhi < NPhi(); idxPhi++)
{
if (isPoleDirection && idxPhi > 0) //At poles: Insert same ray multiple times
vvpRayMatrix[idxTheta].push_back( vvpRayMatrix[idxTheta].front() );
vvpRayMatrix[idxTheta][idxPhi] = vvpRayMatrix[idxTheta].front();
else
vvpRayMatrix[idxTheta].push_back( std::make_shared<CRay>(sourcePos, thetaDeg[idxTheta], phiDeg[idxPhi]) );
vvpRayMatrix[idxTheta][idxPhi] = std::make_shared<CRay>(sourcePos, vdThetaDeg[idxTheta], vdPhiDeg[idxPhi]);
}
}
InitRayVectorFromRayMatrix();
}
CEquiangularRayDistribution::CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int& nTheta, const int& nPhi)
CEquiangularRayDistribution::CEquiangularRayDistribution(const VistaVector3D& sourcePos, const int nTheta, const int nPhi)
{
vdThetaDeg.reserve(nTheta);
const double deltaTheta = 180.0 / (nTheta - 1);
for (int idx = 0; idx < nTheta - 1; idx++)
vdThetaDeg.push_back(idx * deltaTheta);
vdThetaDeg.push_back(180.0);
vdPhiDeg.reserve(nPhi);
const double deltaPhi = 360.0 / nPhi;
for (int idx = 0; idx < nPhi - 1; idx++)
vdPhiDeg.push_back(idx * deltaPhi);
......@@ -74,6 +77,7 @@ CEquiangularRayDistribution::CEquiangularRayDistribution(const VistaVector3D& so
void CRayGrid::InitRayVectorFromRayMatrix()
{
vpRays.clear();
vpRays.reserve( NTheta() * NPhi() );
for each (RayVector rayVector in vvpRayMatrix)
for each (RayPtr pRay in rayVector)
vpRays.push_back(pRay);
......@@ -94,18 +98,18 @@ CRayGrid CRayGrid::GetSurroundingGrid(const std::shared_ptr<CRay>& pRay) const
std::vector<int> phiIdxVec;
GetNeighboringAngleIndices(pRay, thetaIdxVec, phiIdxVec);
std::vector<double> newThetaDeg;
std::vector<double> newPhiDeg;
RayMatrix newRayMatrix;
auto newThetaDeg = std::vector<double>(thetaIdxVec.size());
auto newPhiDeg = std::vector<double>(phiIdxVec.size());
RayMatrix newRayMatrix = RayMatrix(thetaIdxVec.size(), RayVector(phiIdxVec.size()));
for each (int idxPhi in phiIdxVec)
newPhiDeg[idxPhi] = vdPhiDeg[idxPhi];
for each (int idxTheta in thetaIdxVec)
{
newThetaDeg.push_back(vdThetaDeg[idxTheta]);
newRayMatrix.push_back(RayVector());
newThetaDeg[idxTheta] = vdThetaDeg[idxTheta];
for each (int idxPhi in phiIdxVec)
{
newPhiDeg.push_back(vdPhiDeg[idxPhi]);
newRayMatrix[idxTheta].push_back(vvpRayMatrix[idxTheta][idxPhi]);
}
newRayMatrix[idxTheta][idxPhi] = vvpRayMatrix[idxTheta][idxPhi];
}
const bool newGridHasCircularPhi = bCircularPhi && HasPoleDirection(pRay);
......@@ -127,14 +131,14 @@ CRayGrid CRayGrid::CopyWithNewRays() const
// --- PROTECTED HELPERS ---
// -------------------------
#pragma region INDICING
int CRayGrid::IndexToThetaIndex(const int& idx) const
int CRayGrid::IndexToThetaIndex(const int idx) const
{
if (idx < 0 || idx >= vpRays.size())
return -1;
return idx / NPhi(); //Integer-division (floor-function)
}
int CRayGrid::IndexToPhiIndex(const int& idx) const
int CRayGrid::IndexToPhiIndex(const int idx) const
{
if (idx < 0 || idx >= vpRays.size())
return -1;
......
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