This commit is contained in:
2020-10-19 15:18:16 +03:00
parent 2794d866fd
commit e0d46463ae
8 changed files with 60 additions and 121 deletions

View File

@@ -28,15 +28,6 @@
#include "picout.h" #include "picout.h"
#include "piintrospection_containers.h" #include "piintrospection_containers.h"
#ifdef PIP_DEBUG
# ifdef NDEBUG
# undef NDEBUG
# endif
# include <cassert>
#endif
#ifndef assert
# define assert(x)
#endif
#ifdef MAC_OS #ifdef MAC_OS
# include <stdlib.h> # include <stdlib.h>
#else #else

View File

@@ -234,6 +234,13 @@ public:
return *this; return *this;
} }
inline bool operator ==(const PIVector2D<T> & t) const {
if (cols_ != t.cols_ || rows_ != t.rows_)
return false;
return mat == t.mat;
}
inline bool operator !=(const PIVector2D<T> & t) const {return !(*this == t);}
PIVector<PIVector<T> > toVectors() const { PIVector<PIVector<T> > toVectors() const {
PIVector<PIVector<T> > ret; PIVector<PIVector<T> > ret;
ret.reserve(rows_); ret.reserve(rows_);

View File

@@ -155,6 +155,16 @@
extern char ** environ; extern char ** environ;
#endif #endif
#ifdef NDEBUG
# undef NDEBUG
#endif
#include <cassert>
#ifndef assert
# define assert(x)
# define assertm(exp, msg)
#else
# define assertm(exp, msg) assert(((void)msg, exp))
#endif
#ifdef CC_GCC #ifdef CC_GCC
# undef DEPRECATED # undef DEPRECATED

View File

@@ -28,6 +28,7 @@
#endif #endif
#include <atomic> #include <atomic>
class PIMutex; class PIMutex;
class PIMutexLocker; class PIMutexLocker;
class PIObject; class PIObject;

View File

@@ -203,10 +203,7 @@ double PIGeoPosition::height() const {
PIGeoPosition &PIGeoPosition::setGeodetic(double lat, double lon, double ht, PIEllipsoidModel ell) { PIGeoPosition &PIGeoPosition::setGeodetic(double lat, double lon, double ht, PIEllipsoidModel ell) {
if(lat > 90 || lat < -90) { assertm(lat <= 90 && lat >= -90, "Achtung! Invalid latitude in setGeodetic");
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in setGeodetic:" << lat;
assert(lat <= 90 && lat >= -90);
}
(*this)[0] = lat; (*this)[0] = lat;
(*this)[1] = lon; (*this)[1] = lon;
if((*this)[1] < 0) (*this)[1] += 360 * (1 + (unsigned long)((*this)[1]/360)); if((*this)[1] < 0) (*this)[1] += 360 * (1 + (unsigned long)((*this)[1]/360));
@@ -219,14 +216,8 @@ PIGeoPosition &PIGeoPosition::setGeodetic(double lat, double lon, double ht, PIE
PIGeoPosition &PIGeoPosition::setGeocentric(double lat, double lon, double rad) { PIGeoPosition &PIGeoPosition::setGeocentric(double lat, double lon, double rad) {
if(lat > 90 || lat < -90) { assertm(lat <= 90 && lat >= -90, "Achtung! Invalid latitude in setGeocentric");
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in setGeocentric:" << lat; assertm(rad >= 0, "Achtung! Invalid radius in setGeocentric");
assert(lat <= 90 && lat >= -90);
}
if(rad < 0) {
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in setGeocentric:" << rad;
assert(rad >= 0);
}
(*this)[0] = lat; (*this)[0] = lat;
(*this)[1] = lon; (*this)[1] = lon;
(*this)[2] = rad; (*this)[2] = rad;
@@ -238,14 +229,8 @@ PIGeoPosition &PIGeoPosition::setGeocentric(double lat, double lon, double rad)
PIGeoPosition &PIGeoPosition::setSpherical(double theta, double phi, double rad) { PIGeoPosition &PIGeoPosition::setSpherical(double theta, double phi, double rad) {
if(theta < 0 || theta > 180) { assertm(theta <= 180 && theta >= 0, "Achtung! Invalid theta in setSpherical");
piCout << "[PIGeoPosition]" << "Achtung! Invalid theta in setSpherical:" << theta; assertm(rad >= 0, "Achtung! Invalid radius in setSpherical");
assert(theta <= 180 && theta >= 0);
}
if(rad < 0) {
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in setSpherical:" << rad;
assert(rad >= 0);
}
(*this)[0] = theta; (*this)[0] = theta;
(*this)[1] = phi; (*this)[1] = phi;
(*this)[2] = rad; (*this)[2] = rad;
@@ -439,24 +424,15 @@ bool PIGeoPosition::operator==(const PIGeoPosition &right) const {
void PIGeoPosition::initialize(PIMathVectorT3d v, PIGeoPosition::CoordinateSystem sys, PIEllipsoidModel ell) { void PIGeoPosition::initialize(PIMathVectorT3d v, PIGeoPosition::CoordinateSystem sys, PIEllipsoidModel ell) {
double a(v[0]), b(v[1]), c(v[2]); double a(v[0]), b(v[1]), c(v[2]);
if(sys == Geodetic || sys==Geocentric) { if(sys == Geodetic || sys==Geocentric) {
if(a > 90 || a < -90) { assertm(a <= 90 && a >= -90, "Achtung! Invalid latitude in constructor");
piCout << "[PIGeoPosition]" << "Achtung! Invalid latitude in constructor:" << a;
assert(a <= 90 && a >= -90);
}
if(b < 0) b += 360*(1+(unsigned long)(b/360)); if(b < 0) b += 360*(1+(unsigned long)(b/360));
else if(b >= 360) b -= 360*(unsigned long)(b/360); else if(b >= 360) b -= 360*(unsigned long)(b/360);
} }
if(sys==Geocentric || sys==Spherical) { if(sys==Geocentric || sys==Spherical) {
if(c < 0) { assertm(c >= 0, "Achtung! Invalid radius in constructor");
piCout << "[PIGeoPosition]" << "Achtung! Invalid radius in constructor:" << c;
assert(c >= 0);
}
} }
if(sys==Spherical) { if(sys==Spherical) {
if(a < 0 || a > 180) { assertm(a >= 0 && a <= 180, "Achtung! Invalid theta in constructor");
piCout << "[PIGeoPosition]" << "Achtung! Invalid theta in constructor:" << a;
assert(a >= 0 && a <= 180);
}
if(b < 0) b += 360*(1+(unsigned long)(b/360)); if(b < 0) b += 360*(1+(unsigned long)(b/360));
else if(b >= 360) b -= 360*(unsigned long)(b/360); else if(b >= 360) b -= 360*(unsigned long)(b/360);
} }
@@ -493,10 +469,7 @@ double PIGeoPosition::elevationGeodetic(const PIGeoPosition &p) const {
r.transformTo(Cartesian); r.transformTo(Cartesian);
s.transformTo(Cartesian); s.transformTo(Cartesian);
PIMathVectorT3d z = s - r; PIMathVectorT3d z = s - r;
if (z.length() <= 1e-4) { // if the positions are within .1 millimeter assertm(z.length() > 1e-4, "Positions are within .1 millimeter");
piCout << "[PIGeoPosition]" << "Positions are within .1 millimeter" << z;
assert(z.length() > 1e-4);
}
PIMathVectorT3d kv; // Compute k vector in local North-East-Up (NEU) system PIMathVectorT3d kv; // Compute k vector in local North-East-Up (NEU) system
kv[0] = cos(lat) * cos(lng); kv[0] = cos(lat) * cos(lng);
kv[1] = cos(lat) * sin(lng); kv[1] = cos(lat) * sin(lng);
@@ -517,10 +490,7 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
xyz = xy + r[2] * r[2]; xyz = xy + r[2] * r[2];
xy = sqrt(xy); xy = sqrt(xy);
xyz = sqrt(xyz); xyz = sqrt(xyz);
if (xy <= 1e-14 || xyz <=1e-14) { assertm(xy > 1e-14 && xyz > 1e-14, "Divide by Zero Error");
piCout << "[PIGeoPosition]" << "Divide by Zero Error";
assert(xy > 1e-14 && xyz > 1e-14);
}
cosl = r[0] / xy; cosl = r[0] / xy;
sinl = r[1] / xy; sinl = r[1] / xy;
sint = r[2] / xyz; sint = r[2] / xyz;
@@ -535,10 +505,7 @@ double PIGeoPosition::azimuth(const PIGeoPosition &p) const {
p1 = (xn1 * z1) + (xn2 * z2) + (xn3 * z3) ; p1 = (xn1 * z1) + (xn2 * z2) + (xn3 * z3) ;
p2 = (xe1 * z1) + (xe2 * z2) ; p2 = (xe1 * z1) + (xe2 * z2) ;
test = piAbsd(p1) + piAbsd(p2); test = piAbsd(p1) + piAbsd(p2);
if (test < 1.0e-16) { assertm(test >= 1.0e-16, "azAngle(), failed p1+p2 test");
piCout << "[PIGeoPosition]" << "azAngle(), failed p1+p2 test" << test;
assert(test >= 1.0e-16);
}
alpha = 90 - atan2(p1, p2) * rad2deg; alpha = 90 - atan2(p1, p2) * rad2deg;
if (alpha < 0) return alpha + 360; if (alpha < 0) return alpha + 360;
else return alpha; else return alpha;
@@ -553,10 +520,7 @@ double PIGeoPosition::azimuthGeodetic(const PIGeoPosition &p) const {
s.transformTo(Cartesian); s.transformTo(Cartesian);
PIMathVectorT3d z; PIMathVectorT3d z;
z = s - r; z = s - r;
if (z.length() <= 1e-4) { // if the positions are within .1 millimeter assertm(z.length() > 1e-4, "Positions are within 0.1 millimeter");
piCout << "[PIGeoPosition]" << "Positions are within 0.1 millimeter" << z.length();
assert(z.length() > 1e-4);
}
PIMathVectorT3d iv; // Compute i vector in local North-East-Up (NEU) system PIMathVectorT3d iv; // Compute i vector in local North-East-Up (NEU) system
iv[0] = -sin(lat) * cos(lng); iv[0] = -sin(lat) * cos(lng);
iv[1] = -sin(lat) * sin(lng); iv[1] = -sin(lat) * sin(lng);

View File

@@ -177,17 +177,13 @@ void PIFFT_double::ftbasegeneratecomplexfftplan(uint n, ftplan * plan) {
curplan.plan.resize(planarraysize); curplan.plan.resize(planarraysize);
int ftbase_ftbasecffttask = 0; int ftbase_ftbasecffttask = 0;
ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr); ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr);
if (stackptr != 0) { assert(stackptr==0);
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
}
curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1)); curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1));
curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1)); curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1));
curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1)); curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1));
stackptr = 0; stackptr = 0;
ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr); ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr);
if (stackptr != 0) { assert(stackptr==0);
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
}
} }
@@ -1117,17 +1113,13 @@ void PIFFT_float::ftbasegeneratecomplexfftplan(uint n, ftplan * plan) {
curplan.plan.resize(planarraysize); curplan.plan.resize(planarraysize);
int ftbase_ftbasecffttask = 0; int ftbase_ftbasecffttask = 0;
ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr); ftbase_ftbasegenerateplanrec(n, ftbase_ftbasecffttask, plan, &plansize, &precomputedsize, &planarraysize, &tmpmemsize, &stackmemsize, stackptr);
if (stackptr != 0) { assertm(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan");
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
}
curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1)); curplan.stackbuf.resize(piMax<int>(stackmemsize, 1)); //ae_vector_set_length(&curplan.stackbuf, ae_maxint(stackmemsize, 1));
curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1)); curplan.tmpbuf.resize(piMax<int>(tmpmemsize, 1)); //ae_vector_set_length(&(curplan.tmpbuf), ae_maxint(tmpmemsize, 1));
curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1)); curplan.precomputed.resize(piMax<int>(precomputedsize, 1)); //ae_vector_set_length(&curplan.precomputed, ae_maxint(precomputedsize, 1));
stackptr = 0; stackptr = 0;
ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr); ftbase_ftbaseprecomputeplanrec(plan, 0, stackptr);
if (stackptr != 0) { assertm(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan");
return;//ae_assert(stackptr==0, "Internal error in FTBaseGenerateComplexFFTPlan: stack ptr!");
}
} }

View File

@@ -890,6 +890,11 @@ public:
return tm; return tm;
} }
static _CMatrix zero(const uint cols, const uint rows) {
_V2D::resize(rows, cols);
fill(Type(0));
}
/** /**
* @brief Creates a row matrix of every element that is equal to every element of the vector * @brief Creates a row matrix of every element that is equal to every element of the vector
* *
@@ -1002,49 +1007,27 @@ public:
*/ */
bool isValid() const { return !PIVector2D<Type>::isEmpty(); } bool isValid() const { return !PIVector2D<Type>::isEmpty(); }
/**
* @brief Matrix assignment to matrix "v"
*
* @param v matrix for the assigment
* @return matrix equal with v
*/
_CMatrix &operator=(const PIVector<PIVector<Type> > &v) {
*this = _CMatrix(v);
return *this;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are equal true, else false
*/
bool operator==(const _CMatrix &sm) const {
PIMM_FOR_A(i) if (_V2D::mat[i] != sm.mat[i]) return false;
return true;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are not equal true, else false
*/
bool operator!=(const _CMatrix &sm) const { return !(*this == sm); }
/** /**
* @brief Addition assignment with matrix "sm" * @brief Addition assignment with matrix "sm"
* *
* @param sm matrix for the addition assigment * @param sm matrix for the addition assigment
*/ */
void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } void operator+=(const _CMatrix &sm) {
assert(_V2D::rows() == sm.rows());
assert(_V2D::cols() == sm.cols());
PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];
}
/** /**
* @brief Subtraction assignment with matrix "sm" * @brief Subtraction assignment with matrix "sm"
* *
* @param sm matrix for the subtraction assigment * @param sm matrix for the subtraction assigment
*/ */
void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } void operator-=(const _CMatrix &sm) {
assert(_V2D::rows() == sm.rows());
assert(_V2D::cols() == sm.cols());
PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];
}
/** /**
* @brief Multiplication assignment with value "v" * @brief Multiplication assignment with value "v"
@@ -1079,6 +1062,8 @@ public:
*/ */
_CMatrix operator+(const _CMatrix &sm) const { _CMatrix operator+(const _CMatrix &sm) const {
_CMatrix tm(*this); _CMatrix tm(*this);
assert(tm.rows() == sm.rows());
assert(tm.cols() == sm.cols());
PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; PIMM_FOR_A(i) tm.mat[i] += sm.mat[i];
return tm; return tm;
} }
@@ -1091,6 +1076,8 @@ public:
*/ */
_CMatrix operator-(const _CMatrix &sm) const { _CMatrix operator-(const _CMatrix &sm) const {
_CMatrix tm(*this); _CMatrix tm(*this);
assert(tm.rows() == sm.rows());
assert(tm.cols() == sm.cols());
PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i];
return tm; return tm;
} }

View File

@@ -40,25 +40,12 @@ inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << ">>"
int main() { int main() {
PIByteArray ba; PIMathMatrixd m = PIMathMatrixd::identity(3,3);
MM m; m.fill(0);
m.e = 2; PIMathMatrixd m2 = PIMathMatrixd::identity(3,4);
m.y = 0.1; piCout << m;
PIVector<MM> v; piCout << m2;
//v.resize(1,2,m); piCout << m * m2;
v << m << m; piCout << m2 * m;
piCout << "m:";
ba << m;
piCout << ba;
ba >> m;
piCout << ba;
ba.clear();
piCout << "v:";
ba << v;
piCout << ba;
ba >> v;
piCout << ba;
return 0; return 0;
} }