Skip to content

Commit 078c4c6

Browse files
Fabien Servantcbentejac
authored andcommitted
Add observation depth
1 parent 33aa4e7 commit 078c4c6

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

src/aliceVision/sfmData/Observation.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,97 @@ class Observation
3131
_scale(scale_)
3232
{}
3333

34+
/**
35+
* @brief Comparison operator
36+
* @return true if both featureId and coordinates are equal in both observations
37+
*/
3438
bool operator==(const Observation& other) const;
3539

40+
/**
41+
* @brief Return the coordinates of the observation in pixels
42+
* @return The coordinates in pixels
43+
*/
3644
const Vec2& getCoordinates() const { return _coordinates; }
3745

46+
/**
47+
* @brief Return the coordinates of the observation in pixels
48+
* @return The coordinates in pixels
49+
*/
3850
Vec2& getCoordinates() { return _coordinates; }
3951

52+
/**
53+
* @brief Return the X coordinate of the observation in pixels
54+
* @return The column coordinates in pixels
55+
*/
4056
double getX() const { return _coordinates.x(); }
4157

58+
/**
59+
* @brief Return the Y coordinate of the observation in pixels
60+
* @return The row coordinates in pixels
61+
*/
4262
double getY() const { return _coordinates.y(); }
4363

64+
/**
65+
* @brief Set the image coordinates of the observation
66+
* @param coordinates the 2d vector with pixel coordinates
67+
*/
4468
void setCoordinates(const Vec2& coordinates) { _coordinates = coordinates; }
4569

70+
/**
71+
* @brief Set the image coordinates of the observation
72+
* @param x the x coordinates in the image (column)
73+
* @param y the x coordinates in the image (row)
74+
*/
4675
void setCoordinates(double x, double y)
4776
{
4877
_coordinates(0) = x;
4978
_coordinates(1) = y;
5079
}
5180

81+
/**
82+
* @brief An observation should be associated to a feature. This is the id of the feature.
83+
* @return featureId an id of the feature (view specific)
84+
*/
5285
IndexT getFeatureId() const { return _idFeature; }
5386

87+
/**
88+
* @brief An observation should be associated to a feature. This is the id of the feature.
89+
* @param featureId an id of the feature (view specific)
90+
*/
5491
void setFeatureId(IndexT featureId) { _idFeature = featureId; }
5592

93+
/**
94+
* @brief Get the measured scale of the feature (Scale of the source image)
95+
* @return the scale by which the image has been zoomed or 0 if unknown
96+
*/
5697
double getScale() const { return _scale; }
5798

99+
/**
100+
* @brief Set the measured scale of the feature (Scale of the source image)
101+
* @param scale the scale by which the image has been zoomed or 0 if unknown
102+
*/
58103
void setScale(double scale) { _scale = scale; }
59104

105+
/**
106+
* @brief Get the measured depth (Depth meaning is camera type dependent)
107+
* @return The optional measured depth, or less than 0 if non used
108+
*/
109+
double getDepth() const { return _depth; }
110+
111+
/**
112+
* @brief Set the measured point depth (Depth meaning is camera type dependent)
113+
* @param depth the point depth
114+
*/
115+
void setDepth(double depth) { _depth = depth; }
116+
117+
60118
private:
61119
Vec2 _coordinates = { 0.0, 0.0 };
62120
IndexT _idFeature = UndefinedIndexT;
63121
double _scale = 0.0;
122+
123+
//Optional measured 'depth'
124+
double _depth = -1.0;
64125
};
65126

66127
/// Observations are indexed by their View_id

src/aliceVision/sfmDataIO/AlembicExporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,13 @@ void AlembicExporter::addLandmarks(const sfmData::Landmarks& landmarks,
567567

568568
std::vector<float> featPos2d;
569569
std::vector<float> featScale;
570+
std::vector<float> featDepth;
570571
if (withFeatures)
571572
{
572573
featPos2d.reserve(nbObservations * 2);
573574
visibilityFeatId.reserve(nbObservations);
574575
featScale.reserve(nbObservations);
576+
featDepth.reserve(nbObservations);
575577
}
576578

577579
for (const auto& landmark : landmarks)
@@ -594,6 +596,7 @@ void AlembicExporter::addLandmarks(const sfmData::Landmarks& landmarks,
594596
featPos2d.emplace_back(obs.getY());
595597

596598
featScale.emplace_back(obs.getScale());
599+
featDepth.emplace_back(obs.getDepth());
597600
}
598601
}
599602
}
@@ -606,6 +609,7 @@ void AlembicExporter::addLandmarks(const sfmData::Landmarks& landmarks,
606609
OUInt32ArrayProperty(userProps, "mvg_visibilityFeatId").set(visibilityFeatId);
607610
OFloatArrayProperty(userProps, "mvg_visibilityFeatPos").set(featPos2d); // feature position (x,y)
608611
OFloatArrayProperty(userProps, "mvg_visibilityFeatScale").set(featScale);
612+
OFloatArrayProperty(userProps, "mvg_visibilityFeatDepth").set(featDepth);
609613
}
610614
}
611615
if (!landmarksUncertainty.empty())

src/aliceVision/sfmDataIO/AlembicImporter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ bool readPointCloud(const Version& abcVersion, IObject iObj, M44d mat, sfmData::
314314
AV_UInt32ArraySamplePtr sampleVisibilityFeatId;
315315
FloatArraySamplePtr sampleVisibilityFeatPos;
316316
FloatArraySamplePtr sampleVisibilityFeatScale;
317+
FloatArraySamplePtr sampleVisibilityFeatDepth;
317318

318319
if (userProps.getPropertyHeader("mvg_visibilityFeatId") && userProps.getPropertyHeader("mvg_visibilityFeatPos") &&
319320
flags_part & ESfMData::OBSERVATIONS_WITH_FEATURES)
@@ -329,6 +330,12 @@ bool readPointCloud(const Version& abcVersion, IObject iObj, M44d mat, sfmData::
329330
propVisibilityFeatScale.get(sampleVisibilityFeatScale);
330331
}
331332

333+
if (userProps && userProps.getPropertyHeader("mvg_visibilityFeatDepth"))
334+
{
335+
IFloatArrayProperty propVisibilityFeatDepth(userProps, "mvg_visibilityFeatDepth");
336+
propVisibilityFeatDepth.get(sampleVisibilityFeatDepth);
337+
}
338+
332339
if (sampleVisibilityViewId.size() != sampleVisibilityFeatId.size() ||
333340
2 * sampleVisibilityViewId.size() != sampleVisibilityFeatPos->size())
334341
{
@@ -382,6 +389,11 @@ bool readPointCloud(const Version& abcVersion, IObject iObj, M44d mat, sfmData::
382389
{
383390
observation.setScale((*sampleVisibilityFeatScale)[obsGlobalIndex]);
384391
}
392+
393+
if (sampleVisibilityFeatDepth)
394+
{
395+
observation.setDepth((*sampleVisibilityFeatDepth)[obsGlobalIndex]);
396+
}
385397
}
386398
else
387399
{

src/aliceVision/sfmDataIO/jsonIO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ void saveLandmark(const std::string& name,
527527
obsTree.put("featureId", observation.getFeatureId());
528528
saveMatrix("x", observation.getCoordinates(), obsTree);
529529
obsTree.put("scale", observation.getScale());
530+
obsTree.put("depth", observation.getDepth());
530531
}
531532

532533
observationsTree.push_back(std::make_pair("", obsTree));
@@ -561,6 +562,7 @@ void loadLandmark(IndexT& landmarkId, sfmData::Landmark& landmark, bpt::ptree& l
561562
observation.setFeatureId(obsTree.get<IndexT>("featureId"));
562563
loadMatrix("x", observation.getCoordinates(), obsTree);
563564
observation.setScale(obsTree.get<double>("scale", 0.0));
565+
observation.setDepth(obsTree.get<double>("depth", -1.0));
564566
}
565567

566568
landmark.getObservations().emplace(obsTree.get<IndexT>("observationId"), observation);

src/aliceVision/sfmDataIO/sfmDataIO.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define ALICEVISION_SFMDATAIO_VERSION_MAJOR 1
1414
#define ALICEVISION_SFMDATAIO_VERSION_MINOR 2
15-
#define ALICEVISION_SFMDATAIO_VERSION_REVISION 12
15+
#define ALICEVISION_SFMDATAIO_VERSION_REVISION 13
1616

1717
// AliceVision version as a string; for example "0.9.0".
1818
#define ALICEVISION_SFMDATAIO_VERSION_STRING \

0 commit comments

Comments
 (0)