Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--[BE][WIP] Remove Eigen dependency #2301

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8d12875
--remove eigen refs from viewer.
jturner65 Jan 12, 2024
bb27eac
--remove unused eigen typedefs
jturner65 Jan 12, 2024
955ea52
--many refactors across system
jturner65 Jan 16, 2024
a2aa806
--fix replicascene semantics load
jturner65 Jan 16, 2024
b2c4c9d
--fix elementwise pathfinder min/max
jturner65 Jan 16, 2024
655dd5a
--return data array of quaternion in binding
jturner65 Jan 16, 2024
8b43de1
--External Utils : datatool, scene loader and Mp3dInstanceMeshData tools
jturner65 Jan 16, 2024
ede000c
--update mesh joining
jturner65 Jan 16, 2024
d813a1f
--remove more unused Eigen typedefs
jturner65 Jan 16, 2024
6949ae4
--address obbs (change box3f to Magnum Range 3D)
jturner65 Jan 16, 2024
ed8847a
--semantic bindings issue
jturner65 Jan 16, 2024
87a77ec
--more cleanup.
jturner65 Jan 16, 2024
7cdf3e1
--bugfixes
jturner65 Jan 16, 2024
2f1042c
--bug fixes
jturner65 Jan 16, 2024
a1ad0b0
--more bugfixes
jturner65 Jan 16, 2024
bf39c7f
--still more bugfixes
jturner65 Jan 16, 2024
f523cca
--oops
jturner65 Jan 16, 2024
c54b151
--reviewer suggestions
jturner65 Jan 16, 2024
2fcccdf
--clang-tidy
jturner65 Jan 17, 2024
7705442
--reviewer comments
jturner65 Jan 17, 2024
f5c376f
--missing include
jturner65 Jan 22, 2024
f489497
--reviewer suggestions
jturner65 Jan 25, 2024
75baa67
--fix an error - shouldn't normalize the cross product.
jturner65 Jan 26, 2024
2e3ee8e
--cleanup;
jturner65 Feb 5, 2024
8eeda7b
--use join function
jturner65 Feb 5, 2024
afe9cd1
--fix bbox bindings issue
jturner65 Feb 6, 2024
0d952ff
--fix broken constructor
jturner65 Mar 5, 2024
9f4b7c6
--another ortho test mistake
jturner65 Jul 9, 2024
b1347d1
--replace quat rotation from 2 vectors function with magnum version
jturner65 Jul 9, 2024
89f4a84
--Specify rotations as Matrix3x3 instead of full 2D transformation ma…
jturner65 Jul 10, 2024
6a9c3dd
--cleanup
jturner65 Jul 10, 2024
27b34cd
--missing include
jturner65 Jul 10, 2024
b85dda5
--cleanup
jturner65 Jul 10, 2024
f6feabe
--return to Matrix3
jturner65 Jul 11, 2024
f4b3609
--remove call to obviated function
jturner65 Sep 6, 2024
69564ae
--remove unused include
jturner65 Sep 13, 2024
a70ca1e
--cleanup
jturner65 Sep 13, 2024
4defdec
--fix test
jturner65 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/demo_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,21 @@ def do_time_steps(self):
def print_semantic_scene(self):
if self._sim_settings["print_semantic_scene"]:
scene = self._sim.semantic_scene
print(f"House center:{scene.aabb.center} dims:{scene.aabb.sizes}")
print(f"House center:{scene.aabb.center} dims:{scene.aabb.size}")
for level in scene.levels:
print(
f"Level id:{level.id}, center:{level.aabb.center},"
f" dims:{level.aabb.sizes}"
f" dims:{level.aabb.size}"
)
for region in level.regions:
print(
f"Region id:{region.id}, category:{region.category.name()},"
f" center:{region.aabb.center}, dims:{region.aabb.sizes}"
f" center:{region.aabb.center}, dims:{region.aabb.size}"
)
for obj in region.objects:
print(
f"Object id:{obj.id}, category:{obj.category.name()},"
f" center:{obj.aabb.center}, dims:{obj.aabb.sizes}"
f" center:{obj.aabb.center}, dims:{obj.aabb.size}"
)
input("Press Enter to continue...")

Expand Down
8 changes: 4 additions & 4 deletions examples/tutorials/nb_python/ECCV_2020_Navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,23 @@ def print_scene_recur(scene, limit_output=10):
print(
f"House has {len(scene.levels)} levels, {len(scene.regions)} regions and {len(scene.objects)} objects"
)
print(f"House center:{scene.aabb.center} dims:{scene.aabb.sizes}")
print(f"House center:{scene.aabb.center} dims:{scene.aabb.size}")

count = 0
for level in scene.levels:
print(
f"Level id:{level.id}, center:{level.aabb.center},"
f" dims:{level.aabb.sizes}"
f" dims:{level.aabb.size}"
)
for region in level.regions:
print(
f"Region id:{region.id}, category:{region.category.name()},"
f" center:{region.aabb.center}, dims:{region.aabb.sizes}"
f" center:{region.aabb.center}, dims:{region.aabb.size}"
)
for obj in region.objects:
print(
f"Object id:{obj.id}, category:{obj.category.name()},"
f" center:{obj.aabb.center}, dims:{obj.aabb.sizes}"
f" center:{obj.aabb.center}, dims:{obj.aabb.size}"
)
count += 1
if count >= limit_output:
Expand Down
8 changes: 4 additions & 4 deletions examples/tutorials/notebooks/ECCV_2020_Navigation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -450,23 +450,23 @@
" print(\n",
" f\"House has {len(scene.levels)} levels, {len(scene.regions)} regions and {len(scene.objects)} objects\"\n",
" )\n",
" print(f\"House center:{scene.aabb.center} dims:{scene.aabb.sizes}\")\n",
" print(f\"House center:{scene.aabb.center} dims:{scene.aabb.size}\")\n",
"\n",
" count = 0\n",
" for level in scene.levels:\n",
" print(\n",
" f\"Level id:{level.id}, center:{level.aabb.center},\"\n",
" f\" dims:{level.aabb.sizes}\"\n",
" f\" dims:{level.aabb.size}\"\n",
" )\n",
" for region in level.regions:\n",
" print(\n",
" f\"Region id:{region.id}, category:{region.category.name()},\"\n",
" f\" center:{region.aabb.center}, dims:{region.aabb.sizes}\"\n",
" f\" center:{region.aabb.center}, dims:{region.aabb.size}\"\n",
" )\n",
" for obj in region.objects:\n",
" print(\n",
" f\"Object id:{obj.id}, category:{obj.category.name()},\"\n",
" f\" center:{obj.aabb.center}, dims:{obj.aabb.sizes}\"\n",
" f\" center:{obj.aabb.center}, dims:{obj.aabb.size}\"\n",
" )\n",
" count += 1\n",
" if count >= limit_output:\n",
Expand Down
6 changes: 3 additions & 3 deletions src/esp/assets/GenericSemanticMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Magnum/PixelFormat.h>
#include <Magnum/Shaders/GenericGL.h>

#include "esp/core/Utility.h"
#include "esp/geo/Geo.h"
#include "esp/scene/SemanticScene.h"

Expand Down Expand Up @@ -65,8 +66,7 @@ GenericSemanticMeshData::buildSemanticMeshData(
if (semanticFilename.find(".ply") != std::string::npos) {
// Generic Semantic PLY meshes have -Z gravity
const auto T_esp_scene =
Mn::Quaternion{quatf::FromTwoVectors(-vec3f::UnitZ(), geo::ESP_GRAVITY)}
.toMatrix();
Mn::Quaternion::rotation(geo::ESP_FRONT, geo::ESP_GRAVITY).toMatrix();
for (auto& xyz : semanticMeshData->cpu_vbo_) {
xyz = T_esp_scene * xyz;
}
Expand Down Expand Up @@ -307,7 +307,7 @@ GenericSemanticMeshData::buildSemanticMeshData(
// display or save report denoting presence of semantic object-defined colors
// in mesh
return semanticMeshData;
} // GenericSemanticMeshData::buildSemanticMeshData
} // namespace assets

std::vector<std::unique_ptr<GenericSemanticMeshData>>
GenericSemanticMeshData::partitionSemanticMeshData(
Expand Down
9 changes: 4 additions & 5 deletions src/esp/assets/MeshData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
#include <vector>

#include "esp/core/Esp.h"
#include "esp/core/EspEigen.h"

namespace esp {
namespace assets {

//! Raw mesh data storage
struct MeshData {
//! Vertex positions
std::vector<vec3f> vbo;
std::vector<Magnum::Vector3> vbo;
//! Vertex normals
std::vector<vec3f> nbo;
std::vector<Magnum::Vector3> nbo;
//! Texture coordinates
std::vector<vec2f> tbo;
std::vector<Magnum::Vector2> tbo;
//! Vertex colors
std::vector<vec3f> cbo;
std::vector<Magnum::Vector3> cbo;
//! Index buffer
std::vector<uint32_t> ibo;

Expand Down
6 changes: 3 additions & 3 deletions src/esp/assets/MeshMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ struct MeshMetaData {
* @param frame target frame in world space
*/
void setRootFrameOrientation(const geo::CoordinateFrame& frame) {
const quatf& transform = frame.rotationFrameToWorld();
Magnum::Matrix4 R = Magnum::Matrix4::from(
Magnum::Quaternion(transform).toMatrix(), Magnum::Vector3());
const Magnum::Quaternion& transform = frame.rotationFrameToWorld();
Magnum::Matrix4 R =
Magnum::Matrix4::from(transform.toMatrix(), Magnum::Vector3());
root.transformFromLocalToParent = R * root.transformFromLocalToParent;
}
};
Expand Down
15 changes: 4 additions & 11 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/Resource.h>
#include <Corrade/Utility/String.h>
#include <Magnum/EigenIntegration/GeometryIntegration.h>
#include <Magnum/EigenIntegration/Integration.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/Extensions.h>
#include <Magnum/GL/TextureFormat.h>
Expand Down Expand Up @@ -686,11 +684,8 @@ esp::geo::CoordinateFrame ResourceManager::buildFrameFromAttributes(
const Mn::Vector3& up,
const Mn::Vector3& front,
const Mn::Vector3& origin) {
const vec3f upEigen{Mn::EigenIntegration::cast<vec3f>(up)};
const vec3f frontEigen{Mn::EigenIntegration::cast<vec3f>(front)};
if (upEigen.isOrthogonal(frontEigen)) {
const vec3f originEigen{Mn::EigenIntegration::cast<vec3f>(origin)};
esp::geo::CoordinateFrame frame{upEigen, frontEigen, originEigen};
if (abs(Mn::Math::dot(up, front)) < Mn::Math::TypeTraits<float>::epsilon()) {
esp::geo::CoordinateFrame frame{up, front, origin};
return frame;
}
ESP_DEBUG(Mn::Debug::Flag::NoSpace)
Expand Down Expand Up @@ -3470,8 +3465,7 @@ void ResourceManager::joinHierarchy(
<< "` so skipping join.";
} else {
for (const auto& pos : meshData.positions) {
mesh.vbo.push_back(Mn::EigenIntegration::cast<vec3f>(
transformFromLocalToWorld.transformPoint(pos)));
mesh.vbo.push_back(transformFromLocalToWorld.transformPoint(pos));
}
for (const auto& index : meshData.indices) {
mesh.ibo.push_back(index + lastIndex);
Expand Down Expand Up @@ -3518,8 +3512,7 @@ void ResourceManager::joinSemanticHierarchy(

// Save the vertices
for (const auto& pos : vertices) {
mesh.vbo.push_back(Mn::EigenIntegration::cast<vec3f>(
transformFromLocalToWorld.transformPoint(pos)));
mesh.vbo.push_back(transformFromLocalToWorld.transformPoint(pos));
}

// Save the indices
Expand Down
12 changes: 0 additions & 12 deletions src/esp/bindings/Bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
namespace py = pybind11;
using py::literals::operator""_a;

namespace esp {

void initEspBindings(py::module& m) {
// ==== box3f ====
py::class_<box3f>(m, "BBox")
.def_property_readonly("sizes", &box3f::sizes)
.def_property_readonly("center", &box3f::center);
}

} // namespace esp

PYBIND11_MODULE(habitat_sim_bindings, m) {
m.attr("cuda_enabled") =
#ifdef ESP_BUILD_WITH_CUDA
Expand Down Expand Up @@ -59,7 +48,6 @@ PYBIND11_MODULE(habitat_sim_bindings, m) {

py::bind_map<std::map<std::string, std::string>>(m, "MapStringString");

esp::initEspBindings(m);
esp::core::config::initConfigBindings(m);
esp::core::initCoreBindings(m);
esp::geo::initGeoBindings(m);
Expand Down
29 changes: 15 additions & 14 deletions src/esp/bindings/GeoBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "esp/geo/Geo.h"
#include "esp/geo/OBB.h"

#include <Magnum/EigenIntegration/GeometryIntegration.h>

namespace Mn = Magnum;
namespace py = pybind11;
using py::literals::operator""_a;
Expand All @@ -23,18 +21,17 @@ void initGeoBindings(py::module& m) {
geo.attr("GRAVITY") = ESP_GRAVITY;
geo.attr("FRONT") = ESP_FRONT;
geo.attr("BACK") = ESP_BACK;
geo.attr("LEFT") = ESP_FRONT.cross(ESP_GRAVITY);
geo.attr("RIGHT") = ESP_FRONT.cross(ESP_UP);
geo.attr("LEFT") = Mn::Math::cross(ESP_FRONT, ESP_GRAVITY);
geo.attr("RIGHT") = Mn::Math::cross(ESP_FRONT, ESP_UP);

// ==== OBB ====
py::class_<OBB>(m, "OBB", R"(This is an OBB.)")
.def(py::init([](const vec3f& center, const vec3f& dimensions,
.def(py::init([](const Mn::Vector3& center, const Mn::Vector3& dimensions,
const Mn::Quaternion& rotation) {
return OBB(center, dimensions,
Mn::EigenIntegration::cast<quatf>(rotation));
return OBB(center, dimensions, rotation);
}),
"center"_a, "dimensions"_a, "rotation"_a)
.def(py::init<box3f&>())
.def(py::init<Mn::Range3D&>())
.def(
"contains", &OBB::contains,
R"(Returns whether world coordinate point p is contained in this OBB within threshold distance epsilon.)")
Expand All @@ -48,7 +45,7 @@ void initGeoBindings(py::module& m) {
.def(
"rotate",
[](OBB& self, const Mn::Quaternion& rotation) {
return self.rotate(Mn::EigenIntegration::cast<quatf>(rotation));
return self.rotate(rotation);
},
R"(Rotate this OBB by the given rotation and return reference to self.)")
.def_property_readonly("center", &OBB::center, R"(Centroid of this OBB.)")
Expand All @@ -59,15 +56,19 @@ void initGeoBindings(py::module& m) {
.def_property_readonly("half_extents", &OBB::halfExtents,
R"(Half-extents of this OBB (dimensions).)")
.def_property_readonly(
"rotation", [](const OBB& self) { return self.rotation().coeffs(); },
// Return as an array of format [x,y,z,w] to retain existing
// expectations
"rotation",
[](const OBB& self) {
const Mn::Quaternion q = self.rotation();
return Mn::Vector4(q.vector(), q.scalar());
},
R"(Quaternion representing rotation of this OBB.)")
.def_property_readonly(
"local_to_world",
[](const OBB& self) { return self.localToWorld().matrix(); },
"local_to_world", [](const OBB& self) { return self.localToWorld(); },
R"(Transform from local [0,1]^3 coordinates to world coordinates.)")
.def_property_readonly(
"world_to_local",
[](const OBB& self) { return self.worldToLocal().matrix(); },
"world_to_local", [](const OBB& self) { return self.worldToLocal(); },
R"(Transform from world coordinates to local [0,1]^3 coordinates.)");

geo.def(
Expand Down
6 changes: 3 additions & 3 deletions src/esp/bindings/SceneBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ void initSceneBindings(
.def_static(
"load_mp3d_house",
[](const std::string& filename, SemanticScene& scene,
const vec4f& rotation) {
const Mn::Vector4& rotation) {
// numpy doesn't have a quaternion equivalent, use vec4
// instead
return SemanticScene::loadMp3dHouse(
filename, scene, Eigen::Map<const quatf>(rotation.data()));
return SemanticScene::loadMp3dHouse(filename, scene,
{rotation.xyz(), rotation.w()});
},
R"(
Loads a SemanticScene from a Matterport3D House format file into passed
Expand Down
13 changes: 7 additions & 6 deletions src/esp/bindings/ShortestPathBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,25 @@ void initShortestPathBindings(py::module& m) {
R"(Finds the shortest path between a start point and the closest of a set of end points (in geodesic distance) on the navigation mesh using MultiGoalShortestPath module. Path variable is filled if successful. Returns boolean success.)")
.def("try_step", &PathFinder::tryStep<Magnum::Vector3>, "start"_a,
"end"_a)
.def("try_step", &PathFinder::tryStep<vec3f>, "start"_a, "end"_a)
.def("try_step", &PathFinder::tryStep<Magnum::Vector3>, "start"_a,
"end"_a)
.def("try_step_no_sliding",
&PathFinder::tryStepNoSliding<Magnum::Vector3>, "start"_a, "end"_a)
.def("try_step_no_sliding",
&PathFinder::tryStepNoSliding<Magnum::Vector3>, "start"_a, "end"_a)
.def("try_step_no_sliding", &PathFinder::tryStepNoSliding<vec3f>,
"start"_a, "end"_a)
.def("snap_point", &PathFinder::snapPoint<Magnum::Vector3>, "point"_a,
"island_index"_a = ID_UNDEFINED)
.def("snap_point", &PathFinder::snapPoint<vec3f>, "point"_a,
.def("snap_point", &PathFinder::snapPoint<Magnum::Vector3>, "point"_a,
"island_index"_a = ID_UNDEFINED)
.def(
"get_island", &PathFinder::getIsland<Magnum::Vector3>, "point"_a,
R"(Query the island closest to a point. Snaps the point to the NavMesh first, so check the snap distance also if unsure.)")
.def(
"get_island", &PathFinder::getIsland<vec3f>, "point"_a,
"get_island", &PathFinder::getIsland<Magnum::Vector3>, "point"_a,
R"(Query the island closest to a point. Snaps the point to the NavMesh first, so check the snap distance also if unsure.)")
.def(
"island_radius",
[](PathFinder& self, const vec3f& pt) {
[](PathFinder& self, const Magnum::Vector3& pt) {
return self.islandRadius(pt);
},
"pt"_a,
Expand Down
Loading