-
-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66baf28
commit 6555cf5
Showing
12 changed files
with
527 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This file is part of the AliceVision project. | ||
// Copyright (c) 2024 AliceVision contributors. | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, | ||
// v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "MeshIntersection.hpp" | ||
|
||
#include <geogram/basic/geometry.h> | ||
#include <geogram/mesh/mesh_io.h> | ||
#include <geogram/mesh/mesh_geometry.h> | ||
|
||
namespace aliceVision { | ||
namespace mesh { | ||
|
||
|
||
bool MeshIntersection::initialize(const std::string & pathToModel) | ||
{ | ||
GEO::initialize(); | ||
if (!GEO::mesh_load(pathToModel, _mesh)) | ||
{ | ||
ALICEVISION_LOG_ERROR("Impossible to load object file at " << pathToModel); | ||
return false; | ||
} | ||
|
||
_aabb.initialize(_mesh); | ||
|
||
return true; | ||
} | ||
|
||
bool MeshIntersection::peek(Vec3 & output, const camera::IntrinsicBase & intrinsic, const Vec2 & imageCoords) | ||
{ | ||
const Vec3 posCamera = _pose.center(); | ||
const Vec3 wdir = intrinsic.backproject(imageCoords, true, _pose, 1.0); | ||
const Vec3 dir = (wdir - posCamera).normalized(); | ||
|
||
//Create geogram ray from alicevision ray | ||
GEO::Ray ray; | ||
ray.origin.x = posCamera.x(); | ||
ray.origin.y = -posCamera.y(); | ||
ray.origin.z = -posCamera.z(); | ||
ray.direction.x = dir.x(); | ||
ray.direction.y = -dir.y(); | ||
ray.direction.z = -dir.z(); | ||
|
||
GEO::MeshFacetsAABB::Intersection intersection; | ||
if (!_aabb.ray_nearest_intersection(ray, intersection)) | ||
{ | ||
return false; | ||
} | ||
|
||
const GEO::vec3 p = ray.origin + intersection.t * ray.direction; | ||
|
||
output.x() = p.x; | ||
output.y() = -p.y; | ||
output.z() = -p.z; | ||
|
||
return true; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This file is part of the AliceVision project. | ||
// Copyright (c) 2024 AliceVision contributors. | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, | ||
// v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include <aliceVision/sfmData/SfMData.hpp> | ||
|
||
#include <geogram/mesh/mesh.h> | ||
#include <geogram/mesh/mesh_AABB.h> | ||
|
||
namespace aliceVision { | ||
namespace mesh { | ||
|
||
class MeshIntersection | ||
{ | ||
public: | ||
/** | ||
* @brief initialize object. to be called before any other methodd | ||
* @param pathToModel path to obj file to use as mesh | ||
*/ | ||
bool initialize(const std::string & pathToModel); | ||
|
||
/** | ||
* @brief Update pose to use for peeking | ||
* @param pose transformation to use (in aliceVision standard form) | ||
*/ | ||
void setPose(const geometry::Pose3 & pose) | ||
{ | ||
_pose = pose; | ||
} | ||
|
||
/** | ||
* @brief peek a point on the mesh given a input camera observation | ||
* @param output the output measured point | ||
* @param intrinsic the camera intrinsics to use for ray computation | ||
* @param imageCoords the camera observation we want to use to estimate its 'depth' | ||
* @return true if the ray intersect the mesh. | ||
*/ | ||
bool peek(Vec3 & output, const camera::IntrinsicBase & intrinsic, const Vec2 & imageCoords); | ||
|
||
private: | ||
GEO::Mesh _mesh; | ||
GEO::MeshFacetsAABB _aabb; | ||
geometry::Pose3 _pose; | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.