Skip to content

Commit 1abbbcb

Browse files
committed
visualizer: don't push synthetic coordinates through the map projection
Once a GeoMapCanvasVisualizer attaches an equirectangular map projection to the shared canvas projection, computeCanvasPoint() reinterprets every coordinate as geographic (ECEF). The scene axis visualizer and the medium heat-map fed it synthetic basis vectors (Coord::ZERO, unit axes), which then mapped to garbage. Add applyMapProjection parameter (default true) to computeCanvasPoint() (for affine transform only) and use it at those synthetic-coordinate sites.
1 parent a0c21d1 commit 1abbbcb

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

src/inet/common/geometry/common/CanvasProjection.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ CanvasProjection::~CanvasProjection()
2020
{
2121
}
2222

23-
cFigure::Point CanvasProjection::computeCanvasPoint(const Coord& point) const
23+
cFigure::Point CanvasProjection::computeCanvasPoint(const Coord& point, bool applyMapProjection) const
2424
{
2525
double depth;
26-
return computeCanvasPoint(point, depth);
26+
return computeCanvasPoint(point, depth, applyMapProjection);
2727
}
2828

29-
cFigure::Point CanvasProjection::computeCanvasPoint(const Coord& point, double& depth) const
29+
cFigure::Point CanvasProjection::computeCanvasPoint(const Coord& point, double& depth, bool applyMapProjection) const
3030
{
31-
// optional first projection stage (e.g. equirectangular), then the affine view transform
32-
Coord projected = mapProjection ? mapProjection->applyForward(point) : point;
31+
// optional first projection stage (e.g. equirectangular), then the affine view transform; pass
32+
// applyMapProjection = false to skip the first stage (see the header)
33+
Coord projected = (applyMapProjection && mapProjection) ? mapProjection->applyForward(point) : point;
3334
Coord rotatedPoint = rotation.rotateVector(projected);
3435
depth = rotatedPoint.z;
3536
return cFigure::Point(rotatedPoint.x * scale.x + translation.x, rotatedPoint.y * scale.y + translation.y);

src/inet/common/geometry/common/CanvasProjection.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ class INET_API CanvasProjection
6767
const cFigure::Point& getTranslation() const { return translation; }
6868
void setTranslation(const cFigure::Point& translation) { this->translation = translation; }
6969

70-
cFigure::Point computeCanvasPoint(const Coord& point) const;
71-
cFigure::Point computeCanvasPoint(const Coord& point, double& depth) const;
70+
// Pass applyMapProjection = false to skip the optional map-projection first stage and run the affine
71+
// view transform only. For callers that pass synthetic scene coordinates (axis basis vectors, a
72+
// heat-map grid origin) which must not be reinterpreted as geographic positions when a map projection
73+
// is attached to this shared projection.
74+
cFigure::Point computeCanvasPoint(const Coord& point, bool applyMapProjection = true) const;
75+
cFigure::Point computeCanvasPoint(const Coord& point, double& depth, bool applyMapProjection = true) const;
7276
Coord computeCanvasPointInverse(const cFigure::Point& point, double depth) const;
7377

7478
// Projects a direction (tangent) vector anchored at the given scene point to a canvas-space vector.

src/inet/visualizer/canvas/physicallayer/MediumCanvasVisualizer.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ void MediumCanvasVisualizer::initialize(int stage)
7171
const IMediumLimitCache *mediumLimitCache = radioMedium->getMediumLimitCache();
7272
Coord min = mediumLimitCache->getMinConstraintArea();
7373
Coord max = mediumLimitCache->getMaxConstraintArea();
74-
cFigure::Point o = canvasProjection->computeCanvasPoint(Coord::ZERO);
75-
cFigure::Point x = canvasProjection->computeCanvasPoint(Coord(1, 0, 0));
76-
cFigure::Point y = canvasProjection->computeCanvasPoint(Coord(0, 1, 0));
74+
// synthetic basis vectors for the heat-map affine; use the affine-only transform so they are
75+
// not reinterpreted as geographic positions when a map projection is attached to the canvas
76+
cFigure::Point o = canvasProjection->computeCanvasPoint(Coord::ZERO, false);
77+
cFigure::Point x = canvasProjection->computeCanvasPoint(Coord(1, 0, 0), false);
78+
cFigure::Point y = canvasProjection->computeCanvasPoint(Coord(0, 1, 0), false);
7779
double t1 = o.x;
7880
double t2 = o.y;
7981
double a = x.x - t1;

src/inet/visualizer/canvas/scene/SceneCanvasVisualizer.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ void SceneCanvasVisualizer::refreshAxis(double axisLength)
8787
auto xLabel = check_and_cast<cLabelFigure *>(axisLayer->getFigure(3));
8888
auto yLabel = check_and_cast<cLabelFigure *>(axisLayer->getFigure(4));
8989
auto zLabel = check_and_cast<cLabelFigure *>(axisLayer->getFigure(5));
90-
xAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO));
91-
yAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO));
92-
zAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO));
93-
xAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(axisLength, 0, 0)));
94-
yAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(0, axisLength, 0)));
95-
zAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(0, 0, axisLength)));
96-
xLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(axisLength, 0, 0)));
97-
yLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(0, axisLength, 0)));
98-
zLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(0, 0, axisLength)));
90+
xAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO, false));
91+
yAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO, false));
92+
zAxis->setStart(canvasProjection->computeCanvasPoint(Coord::ZERO, false));
93+
xAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(axisLength, 0, 0), false));
94+
yAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(0, axisLength, 0), false));
95+
zAxis->setEnd(canvasProjection->computeCanvasPoint(Coord(0, 0, axisLength), false));
96+
xLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(axisLength, 0, 0), false));
97+
yLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(0, axisLength, 0), false));
98+
zLabel->setPosition(canvasProjection->computeCanvasPoint(Coord(0, 0, axisLength), false));
9999
}
100100

101101
void SceneCanvasVisualizer::handleParameterChange(const char *name)

0 commit comments

Comments
 (0)