Skip to content

Commit

Permalink
Clone and sfmData clean
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Feb 11, 2025
1 parent 5716cee commit 281ea17
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 32 deletions.
8 changes: 6 additions & 2 deletions src/aliceVision/camera/IntrinsicBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace camera {
*/
class IntrinsicBase
{
public:
using sptr = std::shared_ptr<IntrinsicBase>;
using ptr = IntrinsicBase*;

public:
explicit IntrinsicBase(unsigned int width, unsigned int height, const std::string& serialNumber = "")
: _w(width),
Expand Down Expand Up @@ -375,7 +379,7 @@ class IntrinsicBase
/**
* @brief Return true if this ray should be visible in the image
* @param ray input ray to check for visibility
* @return True if this ray is visible theoretically
* @return True if this ray is visible theorically
*/
virtual bool isVisibleRay(const Vec3& ray) const = 0;

Expand Down Expand Up @@ -482,7 +486,7 @@ class IntrinsicBase
* @brief Apply intrinsic and extrinsic parameters to unit vector
* from the cameras focus to a point on the camera plane
* @param[in] pose Extrinsic pose
* @param[in] intrinsic Intrinsic camera parameters
* @param[in] intrinsic Intrinsic camera paremeters
* @param[in] x Point in image
* @return The unit vector in 3D space pointing out from the camera to the point
*/
Expand Down
116 changes: 102 additions & 14 deletions src/aliceVision/sfmData/SfMData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,59 @@ using namespace aliceVision::image;

namespace fs = std::filesystem;

SfMData::SfMData(const SfMData & other, bool unused)
{
//First copy all the non pointers
_landmarks = other._landmarks;
_constraints2d = other._constraints2d;
_constraintsPoint = other._constraintsPoint;
_rotationpriors = other._rotationpriors;
_absolutePath = other._absolutePath;
_featuresFolders = other._featuresFolders;
_matchesFolders = other._matchesFolders;
_poses = other._poses;
_rigs = other._rigs;
_posesUncertainty = other._posesUncertainty;
_landmarksUncertainty = other._landmarksUncertainty;

for (const auto & [idView, pView]: other._views)
{
sfmData::View::sptr pOutView(pView->clone());
_views[idView] = pOutView;
}

for (const auto & [idIntrinsic, pIntrinsic]: other._intrinsics)
{
camera::IntrinsicBase::sptr pOutIntrinsic(pIntrinsic->clone());
_intrinsics[idIntrinsic] = pOutIntrinsic;
}
}

SfMData::SfMData(const SfMData & other, const Eigen::Vector3d & bbMin, const Eigen::Vector3d & bbMax)
{
_views = other._views;
_intrinsics = other._intrinsics;
constraints2d = other.constraints2d;
rotationpriors = other.rotationpriors;
//First copy all the non pointers
_constraints2d = other._constraints2d;
_constraintsPoint = other._constraintsPoint;
_rotationpriors = other._rotationpriors;
_absolutePath = other._absolutePath;
_featuresFolders = other._featuresFolders;
_matchesFolders = other._matchesFolders;
_poses = other._poses;
_rigs = other._rigs;
_posesUncertainty = other._posesUncertainty;
_landmarksUncertainty = other._landmarksUncertainty;

for (const auto & [idView, pView]: other._views)
{
sfmData::View::sptr pOutView(pView->clone());
_views[idView] = pOutView;
}

for (const auto & [idIntrinsic, pIntrinsic]: other._intrinsics)
{
camera::IntrinsicBase::sptr pOutIntrinsic(pIntrinsic->clone());
_intrinsics[idIntrinsic] = pOutIntrinsic;
}

for (const auto & pl : other._landmarks)
{
Expand All @@ -52,63 +94,85 @@ bool SfMData::operator==(const SfMData& other) const
{
// Views
if (_views.size() != other._views.size())
{
return false;
}

for (Views::const_iterator it = _views.begin(); it != _views.end(); ++it)
{
const View& view1 = *(it->second.get());
const View& view2 = *(other._views.at(it->first).get());
if (view1 != view2)
{
return false;
}

// Image paths
if (view1.getImage().getImagePath() != view2.getImage().getImagePath())
{
return false;
}
}

// Ancestors
if (_ancestors.size() != other._ancestors.size())
{
return false;
}

for (ImageInfos::const_iterator it = _ancestors.begin(); it != _ancestors.end(); ++it)
{
const ImageInfo& ancestor1 = *(it->second);
const ImageInfo& ancestor2 = *(other._ancestors.at(it->first));

if (ancestor1 != ancestor2)
{
return false;
}
}

// Poses
if ((_poses != other._poses))
{
return false;
}

// Rigs
if (_rigs != other._rigs)
{
return false;
}

// Intrinsics
if (_intrinsics.size() != other._intrinsics.size())
{
return false;
}

Intrinsics::const_iterator it = _intrinsics.begin();
Intrinsics::const_iterator otherIt = other._intrinsics.begin();
for (; it != _intrinsics.end() && otherIt != other._intrinsics.end(); ++it, ++otherIt)
{
// Index
if (it->first != otherIt->first)
{
return false;
}

// Intrinsic
camera::IntrinsicBase& intrinsic1 = *(it->second.get());
camera::IntrinsicBase& intrinsic2 = *(otherIt->second.get());
if (intrinsic1 != intrinsic2)
{
return false;
}
}

// Points IDs are not preserved
if (_landmarks.size() != other._landmarks.size())
{
return false;
}

Landmarks::const_iterator landMarkIt = _landmarks.begin();
Landmarks::const_iterator otherLandmarkIt = other._landmarks.begin();
Expand All @@ -119,21 +183,42 @@ bool SfMData::operator==(const SfMData& other) const
const Landmark& landmark1 = landMarkIt->second;
const Landmark& landmark2 = otherLandmarkIt->second;
if (landmark1 != landmark2)
{
return false;
}
}

if (constraints2d.size() != other.constraints2d.size())
if (_constraints2d.size() != other._constraints2d.size())
{
return false;
}

Constraints2D::const_iterator constraint2dIt = constraints2d.begin();
Constraints2D::const_iterator otherconstraint2dIt = other.constraints2d.begin();
for (; constraint2dIt != constraints2d.end() && otherconstraint2dIt != other.constraints2d.end(); ++constraint2dIt, ++otherconstraint2dIt)
Constraints2D::const_iterator constraint2dIt = _constraints2d.begin();
Constraints2D::const_iterator otherconstraint2dIt = other._constraints2d.begin();
for (; constraint2dIt != _constraints2d.end() && otherconstraint2dIt != other._constraints2d.end(); ++constraint2dIt, ++otherconstraint2dIt)
{
if (*constraint2dIt != *otherconstraint2dIt)
{
return false;
}
}

if (_constraintsPoint.size() != other._constraintsPoint.size())
{
return false;
}

// Root path can be reset during exports
ConstraintsPoint::const_iterator constraintPointIt = _constraintsPoint.begin();
ConstraintsPoint::const_iterator otherconstraintPointIt = other._constraintsPoint.begin();
for (; constraintPointIt != _constraintsPoint.end() && otherconstraintPointIt != other._constraintsPoint.end(); ++constraintPointIt, ++otherconstraintPointIt)
{
if (*constraintPointIt != *otherconstraintPointIt)
{
return false;
}
}

// Root path can be reseted during exports
return true;
}

Expand Down Expand Up @@ -250,7 +335,7 @@ void SfMData::setPose(const View& view, const CameraPose& absolutePose)
// const bool knownPose = existsPose(view);
CameraPose& viewPose = _poses[view.getPoseId()];

// Pose dedicated for this view (independent from rig, even if it is potentially part of a rig)
// Pose dedicated for this view (independant from rig, even if it is potentially part of a rig)
if (view.isPoseIndependant())
{
viewPose = absolutePose;
Expand Down Expand Up @@ -303,7 +388,10 @@ void SfMData::combine(const SfMData& sfmData)
_landmarks.insert(sfmData._landmarks.begin(), sfmData._landmarks.end());

// constraints
constraints2d.insert(constraints2d.end(), sfmData.constraints2d.begin(), sfmData.constraints2d.end());
_constraints2d.insert(_constraints2d.end(), sfmData._constraints2d.begin(), sfmData._constraints2d.end());

// constraints
_constraintsPoint.insert(sfmData._constraintsPoint.begin(), sfmData._constraintsPoint.end());
}

void SfMData::clear()
Expand All @@ -313,9 +401,9 @@ void SfMData::clear()
_landmarks.clear();
_posesUncertainty.clear();
_landmarksUncertainty.clear();
constraints2d.clear();
rotationpriors.clear();

_constraints2d.clear();
_constraintsPoint.clear();
_rotationpriors.clear();
_absolutePath.clear();
_featuresFolders.clear();
_matchesFolders.clear();
Expand Down
37 changes: 22 additions & 15 deletions src/aliceVision/sfmData/SfMData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,24 @@ class SfMData
PosesUncertainty _posesUncertainty;
/// Uncertainty per landmark
LandmarksUncertainty _landmarksUncertainty;
/// 2D Constraints
Constraints2D constraints2d;
/// Point constraints
ConstraintsPoint constraintsPoint;
/// Rotation priors
RotationPriors rotationpriors;

SfMData() = default;

/**
* @brief Copy constructor
* @param other the copied sfmData
* @param unused a parameter to make sure we explicitely want this copy (for legacy)
*
*/
SfMData(const SfMData & other, bool unused);

/**
* Copy constructor
* @brief Copy constructor
* Use a bounding box to restrict the copied landmarks to the selected region
*/
SfMData(const SfMData & other, const Eigen::Vector3d & bbMin, const Eigen::Vector3d & bbMax);

// Operators

bool operator==(const SfMData& other) const;

inline bool operator!=(const SfMData& other) const { return !(*this == other); }
Expand Down Expand Up @@ -137,22 +138,22 @@ class SfMData
* @brief Get Constraints2D
* @return Constraints2D
*/
const Constraints2D& getConstraints2D() const { return constraints2d; }
Constraints2D& getConstraints2D() { return constraints2d; }
const Constraints2D& getConstraints2D() const { return _constraints2d; }
Constraints2D& getConstraints2D() { return _constraints2d; }

/**
* @brief Get ConstraintsPoints
* @return ConstraintsPoints
*/
const ConstraintsPoint& getConstraintsPoint() const { return constraintsPoint; }
ConstraintsPoint& getConstraintsPoint() { return constraintsPoint; }
const ConstraintsPoint& getConstraintsPoint() const { return _constraintsPoint; }
ConstraintsPoint& getConstraintsPoint() { return _constraintsPoint; }

/**
* @brief Get RotationPriors
* @return RotationPriors
*/
const RotationPriors& getRotationPriors() const { return rotationpriors; }
RotationPriors& getRotationPriors() { return rotationpriors; }
const RotationPriors& getRotationPriors() const { return _rotationpriors; }
RotationPriors& getRotationPriors() { return _rotationpriors; }

/**
* @brief Get relative features folder paths
Expand Down Expand Up @@ -584,7 +585,7 @@ class SfMData
void setAbsolutePose(IndexT poseId, const CameraPose& pose) { _poses[poseId] = pose; }

/**
* @brief Erase the pose for the given poseId
* @brief Erase yhe pose for the given poseId
* @param[in] poseId The given poseId
* @param[in] noThrow If false, throw exception if no pose found
*/
Expand Down Expand Up @@ -654,6 +655,12 @@ class SfMData
Poses _poses;
/// Considered rigs
Rigs _rigs;
/// 2D Constraints
Constraints2D _constraints2d;
/// Point constraints
ConstraintsPoint _constraintsPoint;
/// Rotation priors
RotationPriors _rotationpriors;

/**
* @brief Get Rig pose of a given camera view
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/sfmData/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class View
* @brief Deep View Copy
* return a pointer to a new View
*/
View* clone()
View* clone() const
{
View* v = new View(*this);
v->_image = std::make_shared<ImageInfo>(*this->_image);
Expand Down

0 comments on commit 281ea17

Please sign in to comment.