Skip to content

Commit

Permalink
Fix test-visualization.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Sep 13, 2024
1 parent 6b027e1 commit 9ea1f08
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 189 deletions.
10 changes: 9 additions & 1 deletion erdblick_app/app/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import MainModuleFactory, {MainModule as ErdblickCore, SharedUint8Array} from '../../build/libs/core/erdblick-core';
import {core} from "@angular/compiler";

interface ErdblickCore_ extends ErdblickCore {
export interface ErdblickCore_ extends ErdblickCore {
HEAPU8: Uint8Array
}

Expand Down Expand Up @@ -67,3 +68,10 @@ export async function uint8ArrayToWasmAsync(fun: (d: SharedUint8Array)=>any, inp
sharedGlbArray.delete();
return (result === false) ? null : result;
}

/** Memory usage log. */
export function logFreeMemory() {
let avail = coreLib!.getFreeMemory()/1024/1024;
let total = coreLib!.getTotalMemory()/1024/1024;
console.log(`Free memory: ${Math.round(avail*1000)/1000} MiB (${avail/total}%)`)
}
16 changes: 8 additions & 8 deletions libs/core/include/erdblick/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <iostream>

using namespace mapget;
namespace m = mapget;

namespace erdblick
{
Expand All @@ -12,44 +12,44 @@ namespace erdblick
* Function to calculate the "side" (or relative position)
* of a point to a line defined by a start point and a direction vector.
*/
double pointSideOfLine(Point const& lineVector, Point const& lineStart, Point const& p);
double pointSideOfLine(m::Point const& lineVector, m::Point const& lineStart, m::Point const& p);

/**
* Function to check if a triangle intersects with an infinite 2D line,
* using start point and direction vector for the line
*/
bool checkIfTriangleIntersectsWithInfinite2dLine(Point const& lineStart, Point const& lineVector, Point const& triA, Point const& triB, Point const& triC);
bool checkIfTriangleIntersectsWithInfinite2dLine(m::Point const& lineStart, m::Point const& lineVector, m::Point const& triA, m::Point const& triB, m::Point const& triC);

/**
* Returns true if the given point is inside the given 2d triangle.
*/
bool isPointInsideTriangle(Point const& p, Point const& p0, Point const& p1, Point const& p2);
bool isPointInsideTriangle(m::Point const& p, m::Point const& p0, m::Point const& p1, m::Point const& p2);

/**
* Calculate a reasonable center point for the given geometry.
* This is used as a location for labels, and as the origin
* for relation vectors.
*/
Point geometryCenter(model_ptr<Geometry> const& g);
m::Point geometryCenter(m::model_ptr<m::Geometry> const& g);

/**
* Calculate a point furthest from the center for the given geometry.
* Used to properly scale the camera in the viewer
* relative to the feature's bounding sphere.
*/
Point boundingRadiusEndPoint(model_ptr<Geometry> const& g);
m::Point boundingRadiusEndPoint(m::model_ptr<m::Geometry> const& g);

/**
* Get type of the geometry.
*/
GeomType getGeometryType(model_ptr<Geometry> const& g);
m::GeomType getGeometryType(m::model_ptr<m::Geometry> const& g);

/**
* Calculate a local WGS84 coordinate system for the geometry.
* The axes are scaled, such that each represents approx. 1m
* in real-world length. The y-axis will point in the direction
* (first-point -> last-point). The x-axis is perpendicular.
*/
glm::dmat3x3 localWgs84UnitCoordinateSystem(const model_ptr<Geometry>& g);
glm::dmat3x3 localWgs84UnitCoordinateSystem(const m::model_ptr<m::Geometry>& g);

} // namespace erdblick
5 changes: 3 additions & 2 deletions libs/core/include/erdblick/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "cesium-interface/object.h"
#include "mapget/model/featurelayer.h"
#include "mapget/model/sourcedatalayer.h"
#include "layer.h"

namespace erdblick
{
Expand All @@ -31,12 +32,12 @@ class TileLayerParser
/**
* Parse a TileFeatureLayer from a buffer as returned by writeTileFeatureLayer.
*/
mapget::TileFeatureLayer::Ptr readTileFeatureLayer(SharedUint8Array const& buffer);
TileFeatureLayer readTileFeatureLayer(SharedUint8Array const& buffer);

/**
* Parse a TileSourceDataLayer from a buffer.
*/
mapget::TileSourceDataLayer::Ptr readTileSourceDataLayer(SharedUint8Array const& buffer);
TileSourceDataLayer readTileSourceDataLayer(SharedUint8Array const& buffer);

/**
* Parse only the stringified MapTileKey and tile id from the tile layer blob.
Expand Down
6 changes: 3 additions & 3 deletions libs/core/include/erdblick/search.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "mapget/model/featurelayer.h"
#include "cesium-interface/object.h"
#include "layer.h"

namespace erdblick
{
Expand All @@ -16,7 +16,7 @@ std::string anyWrap(std::string_view const& q);
class FeatureLayerSearch
{
public:
explicit FeatureLayerSearch(mapget::TileFeatureLayer& tfl);
explicit FeatureLayerSearch(TileFeatureLayer& tfl);

/** Returns a list of Tuples of (Map Tile Key, Feature ID). */
NativeJsValue filter(std::string const& q);
Expand All @@ -25,7 +25,7 @@ class FeatureLayerSearch
NativeJsValue traceResults();

private:
mapget::TileFeatureLayer& tfl_;
TileFeatureLayer& tfl_;
};

}
17 changes: 0 additions & 17 deletions libs/core/include/erdblick/sourcedata.hpp

This file was deleted.

10 changes: 8 additions & 2 deletions libs/core/include/erdblick/visualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cesium-interface/labels.h"
#include "style.h"
#include "simfil/overlay.h"
#include "layer.h"

namespace erdblick
{
Expand Down Expand Up @@ -86,11 +87,16 @@ class FeatureLayerVisualization
FeatureStyleRule::HighlightMode const& highlightMode = FeatureStyleRule::NoHighlight,
NativeJsValue const& rawFeatureIdSubset = {});

/**
* Destructor for memory diagnostics.
*/
~FeatureLayerVisualization();

/**
* Add a tile which is considered for visualization. All tiles added after
* the first one are only considered to resolve external relations.
*/
void addTileFeatureLayer(std::shared_ptr<mapget::TileFeatureLayer> tile);
void addTileFeatureLayer(TileFeatureLayer const& tile);

/**
* Run visualization for the added tile feature layers.
Expand Down Expand Up @@ -272,7 +278,7 @@ class FeatureLayerVisualization

FeatureLayerStyle const& style_;
mapget::TileFeatureLayer::Ptr tile_;
std::vector<std::shared_ptr<mapget::TileFeatureLayer>> allTiles_;
std::vector<mapget::TileFeatureLayer::Ptr> allTiles_;
std::set<std::string> featureIdSubset_;
std::shared_ptr<simfil::StringPool> internalStringPoolCopy_;
std::map<std::string, simfil::Value> optionValues_;
Expand Down
2 changes: 2 additions & 0 deletions libs/core/src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "geometry.h"
#include "cesium-interface/point-conversion.h"

using namespace mapget;

Point erdblick::geometryCenter(const model_ptr<Geometry>& g)
{
if (!g) {
Expand Down
28 changes: 10 additions & 18 deletions libs/core/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,47 +84,39 @@ NativeJsValue TileLayerParser::getFieldDictOffsets()

void TileLayerParser::reset()
{
// Note: The reader is only ever used to read field dict updates.
// For this, it does not need a layer info provider or onParsedLayer callback.
reader_ = std::make_unique<TileLayerStream::Reader>(
[this](auto&& mapId, auto&& layerId)
{
return resolveMapLayerInfo(std::string(mapId), std::string(layerId));
},
[this](auto&& layer){
const auto type = layer->layerInfo()->type_;
if (type != LayerType::Features)
return;

if (tileParsedFun_)
tileParsedFun_(std::static_pointer_cast<TileFeatureLayer>(layer));
},
[](auto&& mapId, auto&& layerId){return nullptr;},
[](auto&& layer){},
cachedStrings_);
}

mapget::TileFeatureLayer::Ptr TileLayerParser::readTileFeatureLayer(const SharedUint8Array& buffer)
TileFeatureLayer TileLayerParser::readTileFeatureLayer(const SharedUint8Array& buffer)
{
std::stringstream inputStream;
inputStream << buffer.toString();
auto result = std::make_shared<TileFeatureLayer>(
auto result = TileFeatureLayer(std::make_shared<mapget::TileFeatureLayer>(
inputStream,
[this](auto&& mapId, auto&& layerId)
{
return resolveMapLayerInfo(std::string(mapId), std::string(layerId));
},
[this](auto&& nodeId) { return cachedStrings_->getStringPool(nodeId); });
[this](auto&& nodeId) { return cachedStrings_->getStringPool(nodeId); }));
return result;
}

mapget::TileSourceDataLayer::Ptr TileLayerParser::readTileSourceDataLayer(SharedUint8Array const& buffer)
TileSourceDataLayer TileLayerParser::readTileSourceDataLayer(SharedUint8Array const& buffer)
{
std::stringstream inputStream;
inputStream << buffer.toString();
auto result = std::make_shared<TileSourceDataLayer>(
auto result = TileSourceDataLayer(std::make_shared<mapget::TileSourceDataLayer>(
inputStream,
[this](auto&& mapId, auto&& layerId)
{
return resolveMapLayerInfo(std::string(mapId), std::string(layerId));
},
[this](auto&& nodeId) { return cachedStrings_->getStringPool(nodeId); });
[this](auto&& nodeId) { return cachedStrings_->getStringPool(nodeId); }));
return result;
}

Expand Down
9 changes: 5 additions & 4 deletions libs/core/src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#include "geometry.h"
#include "cesium-interface/point-conversion.h"

erdblick::FeatureLayerSearch::FeatureLayerSearch(mapget::TileFeatureLayer& tfl) : tfl_(tfl)
erdblick::FeatureLayerSearch::FeatureLayerSearch(TileFeatureLayer& tfl) : tfl_(tfl)
{}

erdblick::NativeJsValue erdblick::FeatureLayerSearch::filter(const std::string& q)
{
auto results = JsValue::List();
auto mapTileKey = tfl_.id().toString();
auto mapTileKey = tfl_.id();

for (const auto& feature : tfl_) {
auto evalResult = tfl_.evaluate(anyWrap(q), *feature);
for (const auto& feature : *tfl_.model_) {
auto evalResult = tfl_.model_->evaluate(anyWrap(q), *feature);
if (evalResult.empty())
continue;
auto& firstEvalResult = evalResult[0];
Expand Down Expand Up @@ -42,3 +42,4 @@ std::string erdblick::anyWrap(const std::string_view& q)
{
return fmt::format("any({})", q);
}

Loading

0 comments on commit 9ea1f08

Please sign in to comment.