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 39 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c2c73d2
--remove eigen refs from viewer.
jturner65 Jan 12, 2024
ed4b6c4
--remove unused eigen typedefs
jturner65 Jan 12, 2024
6ecee86
--many refactors across system
jturner65 Jan 16, 2024
7211a63
--fix replicascene semantics load
jturner65 Jan 16, 2024
70717e6
--fix elementwise pathfinder min/max
jturner65 Jan 16, 2024
431a130
--return data array of quaternion in binding
jturner65 Jan 16, 2024
d576c77
--External Utils : datatool, scene loader and Mp3dInstanceMeshData tools
jturner65 Jan 16, 2024
59f1353
--update mesh joining
jturner65 Jan 16, 2024
86f51ba
--remove more unused Eigen typedefs
jturner65 Jan 16, 2024
f555486
--address obbs (change box3f to Magnum Range 3D)
jturner65 Jan 16, 2024
37786aa
--semantic bindings issue
jturner65 Jan 16, 2024
53029c4
--fix objectControls
jturner65 Jan 16, 2024
7201314
--fix agent
jturner65 Jan 16, 2024
514f77c
--more cleanup.
jturner65 Jan 16, 2024
2d3a616
--bugfixes
jturner65 Jan 16, 2024
91d2125
--bug fixes
jturner65 Jan 16, 2024
353f331
--more bugfixes
jturner65 Jan 16, 2024
ecc2eb0
--still more bugfixes
jturner65 Jan 16, 2024
8deadfc
--oops
jturner65 Jan 16, 2024
cef9d48
--reviewer suggestions
jturner65 Jan 16, 2024
2886439
--clang-tidy
jturner65 Jan 17, 2024
cfd0f0e
--reviewer comments
jturner65 Jan 17, 2024
0bac2c8
--missing include
jturner65 Jan 22, 2024
2b59f81
--reviewer suggestions
jturner65 Jan 25, 2024
3025a12
--fix an error - shouldn't normalize the cross product.
jturner65 Jan 26, 2024
6a2f1c9
--cleanup;
jturner65 Feb 5, 2024
c7e52f2
--use join function
jturner65 Feb 5, 2024
df7a39e
--fix bbox bindings issue
jturner65 Feb 6, 2024
b9ded19
--fix broken constructor
jturner65 Mar 5, 2024
9af18f6
--another ortho test mistake
jturner65 Jul 9, 2024
3641063
--replace quat rotation from 2 vectors function with magnum version
jturner65 Jul 9, 2024
8da2a32
--Specify rotations as Matrix3x3 instead of full 2D transformation ma…
jturner65 Jul 10, 2024
a688daf
--cleanup
jturner65 Jul 10, 2024
e78ad56
--missing include
jturner65 Jul 10, 2024
b0e4114
--cleanup
jturner65 Jul 10, 2024
d8d936d
--return to Matrix3
jturner65 Jul 11, 2024
8812d48
--remove call to obviated function
jturner65 Sep 6, 2024
36972e2
--remove unused include
jturner65 Sep 13, 2024
7aa2b31
--cleanup
jturner65 Sep 13, 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
4 changes: 2 additions & 2 deletions examples/web_apps/webxr_hand_demo/js/vr_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ export class VRDemo {

handInfo.push({
index: handIndex,
pos: Module.toVec3f(handPos),
rot: Module.toVec4f(handRot),
pos: handPos,
rot: handRot,
gripButton: buttonStates[0],
spawnButton: buttonStates[1]
});
Expand Down
28 changes: 13 additions & 15 deletions src/esp/agent/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@

#include "Agent.h"

#include <Magnum/EigenIntegration/GeometryIntegration.h>
#include <Magnum/EigenIntegration/Integration.h>

#include "esp/scene/ObjectControls.h"
#include "esp/sensor/Sensor.h"

using Magnum::EigenIntegration::cast;

namespace esp {
namespace agent {

namespace Mn = Magnum;

const std::set<std::string> Agent::BodyActions = {"moveRight", "moveLeft",
"moveForward", "moveBackward",
"turnLeft", "turnRight"};

Agent::Agent(scene::SceneNode& agentNode, const AgentConfiguration& cfg)
: Magnum::SceneGraph::AbstractFeature3D(agentNode),
: Mn::SceneGraph::AbstractFeature3D(agentNode),
configuration_(cfg),
controls_(scene::ObjectControls::create()) {
agentNode.setType(scene::SceneNodeType::AGENT);
Expand All @@ -45,9 +42,8 @@ bool Agent::act(const std::string& actionName) {
}
}
return true;
} else {
return false;
}
return false;
}

bool Agent::hasAction(const std::string& actionName) const {
Expand All @@ -61,20 +57,22 @@ void Agent::reset() {

void Agent::getState(const AgentState::ptr& state) const {
// TODO this should be done less hackishly
state->position = cast<vec3f>(node().absoluteTransformation().translation());
state->rotation = quatf(node().rotation()).coeffs();
state->position = node().absoluteTransformation().translation();
// doing this for x,y,z,w format of state's rotation.
auto rot = node().rotation();
state->rotation = Mn::Vector4(rot.vector(), rot.scalar());
// TODO other state members when implemented
}

void Agent::setState(const AgentState& state,
const bool resetSensors /*= true*/) {
node().setTranslation(Magnum::Vector3(state.position));
node().setTranslation(Mn::Vector3(state.position));

const Eigen::Map<const quatf> rot(state.rotation.data());
CORRADE_ASSERT(std::abs(rot.norm() - 1.0) <
2.0 * Magnum::Math::TypeTraits<float>::epsilon(),
const Mn::Quaternion rot =
Mn::Quaternion(state.rotation.xyz(), state.rotation.w());
CORRADE_ASSERT(rot.isNormalized(),
state.rotation << " not a valid rotation", );
node().setRotation(Magnum::Quaternion(quatf(rot)).normalized());
node().setRotation(rot);

if (resetSensors) {
for (auto& p : node().getNodeSensors()) {
Expand Down
9 changes: 4 additions & 5 deletions src/esp/agent/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>

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

namespace esp {
Expand All @@ -31,13 +30,13 @@ struct AgentState {
/**
* @brief the position of the agent
*/
vec3f position = {0, 0, 0};
Magnum::Vector3 position{0, 0, 0};
/**
* @brief the agent's rotation. TODO : This exposes the rotation quaternion
* x,y,z,w as vec4f for pybind11 interop, replace with quatf when we have
* custom pybind11 type conversion for quaternions
* x,y,z,w as Magnum Vector4 for pybind11 interop, replace with quatf when we
* have custom pybind11 type conversion for quaternions
*/
vec4f rotation = {0, 0, 0, 1};
Magnum::Vector4 rotation = {0, 0, 0, 1};
ESP_SMART_POINTERS(AgentState)
};

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 @@ -3486,8 +3481,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 @@ -3534,8 +3528,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
Loading