Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <uwsim/MultibeamSensor.h>
00014
00015 MultibeamSensor::MultibeamSensor(osg::Group *uwsim_root, std::string name, osg::Node *trackNode, double initAngle,
00016 double finalAngle, double alpha, double range) :
00017 VirtualCamera(uwsim_root, name, trackNode, fabs(finalAngle - initAngle) / alpha + 1, fabs(finalAngle - initAngle),
00018 range)
00019 {
00020
00021 this->numpixels = fabs(finalAngle - initAngle) / alpha + 1;
00022 this->range = range;
00023 this->initAngle = initAngle;
00024 this->finalAngle = finalAngle;
00025 this->angleIncr = alpha;
00026 preCalcTable();
00027 }
00028
00029 void MultibeamSensor::preCalcTable()
00030 {
00031
00032
00033 osg::Matrix *MVPW = new osg::Matrix(
00034 textureCamera->getViewMatrix() * textureCamera->getProjectionMatrix()
00035 * textureCamera->getViewport()->computeWindowMatrix());
00036 MVPW->invert(*MVPW);
00037
00038
00039 osg::Vec3d first = osg::Vec3d(0, 0, 1) * (*MVPW), last = osg::Vec3d(0, numpixels - 1, 1) * (*MVPW), center =
00040 osg::Vec3d(0, numpixels / 2, 1) * (*MVPW);
00041 double realfov = acos((first * last) / (last.length() * first.length()));
00042 double thetacenter = acos((first * center) / (center.length() * first.length()));
00043 double alpha = realfov / (numpixels);
00044
00045
00046
00047 remapVector.resize(numpixels);
00048 int current = 0;
00049 double lastTheta = 0;
00050 for (int i = 0; i < numpixels; i++)
00051 {
00052 osg::Vec3d point = osg::Vec3d(0, i, 1) * (*MVPW);
00053
00054 double theta = acos((first * point) / (first.length() * point.length()));
00055 while (theta >= alpha * current && current < numpixels)
00056 {
00057 if (theta == alpha * current)
00058 {
00059 remapVector[current].pixel1 = i;
00060 remapVector[current].weight1 = 0.50;
00061 remapVector[current].pixel2 = i;
00062 remapVector[current].weight2 = 0.50;
00063 }
00064 else
00065 {
00066 double dist = fabs(theta - alpha * current), prevdist = fabs(lastTheta - alpha * current);
00067 remapVector[current].pixel1 = i;
00068 remapVector[current].weight1 = prevdist / (dist + prevdist);
00069 remapVector[current].pixel2 = i - 1;
00070 remapVector[current].weight2 = dist / (dist + prevdist);
00071
00072 }
00073 remapVector[current].distort = 1 / cos(fabs(theta - thetacenter));
00074
00075 current++;
00076
00077
00078 }
00079 lastTheta = theta;
00080
00081 }
00082
00083 }