1#ifndef __JACOUSTICS__JGEOMETRY__
2#define __JACOUSTICS__JGEOMETRY__
11#include "JLang/JException.hh"
12#include "JLang/JPredicate.hh"
13#include "JLang/JComparator.hh"
14#include "JLang/JManip.hh"
16#include "JGeometry2D/JPosition2D.hh"
17#include "JGeometry3D/JPosition3D.hh"
19#include "JTools/JHashMap.hh"
21#include "JDetector/JLocation.hh"
22#include "JDetector/JHydrophone.hh"
23#include "JDetector/JDetector.hh"
24#include "JDetector/JModuleSupportkit.hh"
43 using JLANG::JValueOutOfRange;
44 using JLANG::JNoValue;
45 using JGEOMETRY2D::JVector2D;
46 using JGEOMETRY3D::JVector3D;
47 using JGEOMETRY3D::JPosition3D;
48 using JTOOLS::JHashMap;
49 using JDETECTOR::JLocation;
50 using JDETECTOR::JHydrophone;
118 return out << FIXED(7,2) << floor.
getHeight();
142 public std::vector<JFloor>
144 using JPosition3D::getPosition;
145 using JPosition3D::getDistance;
146 using std::vector<
JFloor>::operator[];
184 const size_t MAXIMUM_NUMBER_OF_ITERATIONS = 10;
190 for (
size_t i = 0; i != MAXIMUM_NUMBER_OF_ITERATIONS; ++i) {
194 if (fabs(ls) <= precision) {
200 z -= ls / (1.0 + 0.5*T2 * vs*vs);
219 const double h1 = height * (1.0 + parameters.
vs);
222 return JPosition3D(parameters.
tx * z1 + parameters.
tx2 * h1*h1,
223 parameters.
ty * z1 + parameters.
ty2 * h1*h1,
247 JPosition3D(position),
279 JPosition3D(position),
283 for (T i = __begin; i != __end; ++i) {
284 (*this)[i->getFloor()] =
JFloor(this->
getDistance(i->getPosition() + JDETECTOR::getPiezoPosition()),
285 JVector2D(i->getX() - this->getX(),
286 i->getY() - this->getY()));
310 if (floor >= this->size()) {
311 this->resize(floor + 1);
314 return static_cast<std::vector<JFloor>&
>(*this)[floor];
329 return (floor < this->size());
342 THROW(JValueOutOfRange,
"Invalid floor " << floor);
348 return (*
this)[floor].getHeight();
360 const size_t floor)
const
363 THROW(JValueOutOfRange,
"Invalid floor " << floor);
382 THROW(JValueOutOfRange,
"Invalid floor " << floor);
388 return this->
getPosition() + JPosition3D(0.0, 0.0, (*
this)[floor].
getHeight()) + (*this)[floor].getPosition();
401 const JVector3D& position,
402 const size_t floor)
const
404 return this->
getPosition(parameters, floor).getDistance(position);
417 const JVector3D& position,
418 const size_t floor)
const
424 }
else if (floor < this->size()) {
426 const JPosition3D pos = this->
getPosition(parameters, floor);
427 const double height = (*this)[floor].getHeight();
428 const double h1 = height * (1.0 + parameters.
vs);
431 const double tx = parameters.
tx;
432 const double ty = parameters.
ty;
433 const double tz = sqrt(1.0 - tx*tx - ty*ty);
435 const double dx = pos.getX() - position.getX();
436 const double dy = pos.getY() - position.getY();
437 const double dz = pos.getZ() - position.getZ();
439 const double D = sqrt(dx*dx + dy*dy + dz*dz);
444 z1 * dy / D - height * (ty / tz) * dz / D,
447 height * vw * (tx * dx + ty * dy) / D + h1 * (dz / vs) / D);
451 THROW(JValueOutOfRange,
"Invalid floor " << floor);
467 for (
size_t i = 0; i !=
string.size(); ++i) {
469 out << setw(2) << i <<
' '
470 << FIXED(7,3) <<
string[i] <<
" | "
471 <<
string.getPosition(i) <<
' '
472 <<
string.mechanics << endl;
500 public JHashMap<int, JString>
525 const std::vector<JHydrophone>& hydrophones = std::vector<JHydrophone>())
530 map<int, vector<module_type> > buffer;
532 for (JDETECTOR::JDetector::const_iterator module = detector.begin();
module != detector.end(); ++module) {
533 buffer[
module->getString()].push_back(module_type(module->getLocation(), module->getPosition()));
536 for (map<
int, vector<module_type> >::iterator i = buffer.begin(); i != buffer.end(); ++i) {
538 sort(i->second.begin(), i->second.end(), make_comparator(&module_type::getFloor));
540 if (i->second[0].getFloor() == 0) {
542 JString&
string = (*this)[i->first];
544 vector<module_type>::iterator p = i->second.begin();
552 string.hydrophone =
getPosition(hydrophones.begin(),
554 make_predicate(&JHydrophone::getString, i->first));
556 string.has_hydrophone =
true;
558 catch(
const exception&) {
559 string.has_hydrophone =
false;
564 THROW(JNoValue,
"No floor 0 in string " << i->first <<
"; use e.g. JDetectorDB -W.");
578 return this->has(
string);
590 return this->
hasString(location.getString()) && (*this)[location.getString()].hasFloor(location.getFloor());
605 for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
606 out << setw(4) << i->first << endl << i->second;
627 const JPosition3D& position) :
628 JLocation (location),
629 JPosition3D(position)
Model for fit to acoutsics data.
Mechanical modelling of string.
Auxiliary classes and methods for acoustic position calibration.
JVector3D getPosition(T __begin, T __end, const JPredicate< JTypename_t, JComparator_t > &predicate)
Get position from element in data which corresponds to given predicate.
JGEOMETRY::JDetector JGeometry
Type definition of detector geometry.
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Auxiliary data structure for module location and position.
module_type(const JLocation &location, const JPosition3D &position)
Constructor.
JDetector(const JDETECTOR::JDetector &detector, const std::vector< JHydrophone > &hydrophones=std::vector< JHydrophone >())
Constructor.
bool hasLocation(const JLocation &location) const
Check if this detector has given location.
bool hasString(int string) const
Check if this detector has given string.
friend std::ostream & operator<<(std::ostream &out, const JDetector &detector)
Write detector parameters to output stream.
JDetector()
Default constructor.
friend std::ostream & operator<<(std::ostream &out, const JFloor &floor)
Write floor parameters to output stream.
JFloor()
Default constructor.
double getHeight() const
Get height of this floor.
JFloor(const double height, const JVector2D &position=JVector2D())
Constructor.
const JVector3D & getPosition() const
Get position of this floor.
JPosition3D hydrophone
Hydrophone.
static double getHeight(const JMODEL::JString ¶meters, const JMechanics &mechanics, const double length, const double precision=PRECISION_M)
Get approximate height of string.
double getDistance(const JMODEL::JString ¶meters, const JVector3D &position, const size_t floor) const
Get distance between given position and floor according to given string model parameters.
JMODEL::JString getGradient(const JMODEL::JString ¶meters, const JVector3D &position, const size_t floor) const
Get model gradient of distance between given position and floor according to given string model param...
static JPosition3D getPosition(const JMODEL::JString ¶meters, const JMechanics &mechanics, const double height)
Get position at given height according to given string model parameters and mechanics.
double getHeight(const size_t floor) const
Get height of receiver at given floor with respect to reference position.
JFloor & operator[](size_t floor)
Get floor data.
JString()
Default constructor.
const JMechanics & getMechanics() const
Get mechanical model parameters.
JString(const JVector3D &position, const JMechanics &mechanics)
Constructor.
bool hasFloor(size_t floor) const
Check if this string has receiver at given floor.
JPosition3D getPosition(const JMODEL::JString ¶meters, const size_t floor) const
Get position of receiver at given floor according to given string model parameters.
friend std::ostream & operator<<(std::ostream &out, const JString &string)
Write string parameters to output stream.
static constexpr double PRECISION_M
precision of height evaluation [m]
JMechanics mechanics
Mechanical data.
JString(const JVector3D &position, const JMechanics &mechanics, T __begin, T __end)
Constructor.
static double getLength(const JMODEL::JString ¶meters, const JMechanics &mechanics, const double height)
Get approximate length of string.
JPosition3D getPosition(const size_t floor) const
Get position of receiver at given floor.
double getLengthSquared() const
Get length squared.
Auxiliary data structure for parameters of mechanical model.
double a
0 <= a < (maximal height)⁻1; [m^-1]
double getHeight(const double height) const
Get effective height for given actual height.