Skip to content

Commit e3be9a4

Browse files
committed
[ObservationsEntity] fix bug to handle non-constructed views
1 parent a6e6cd7 commit e3be9a4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/qmlAlembic/ObservationsEntity.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ ObservationsEntity::ObservationsEntity(std::string source, Qt3DCore::QNode* pare
2727
using sfmDataIO::ESfMData;
2828

2929
// read relevant SfM data
30-
sfmDataIO::Load(_sfmData, _source, ESfMData(
31-
ESfMData::VIEWS | ESfMData::EXTRINSICS | ESfMData::STRUCTURE |
32-
ESfMData::OBSERVATIONS | ESfMData::OBSERVATIONS_WITH_FEATURES));
30+
sfmDataIO::Load(_sfmData, _source, ESfMData::ALL);
3331

3432
// populate _landmarksPerView from the read SfM data
3533
fillLandmarksPerViews();
@@ -70,7 +68,8 @@ void ObservationsEntity::update(const IndexT& viewId, const QVariantMap& viewer2
7068
size_t rcIndexCount = 0;
7169

7270
const auto& it = _landmarksPerView.find(viewId);
73-
if (it != _landmarksPerView.end())
71+
const auto& setValidViewIds = _sfmData.getValidViews();
72+
if (it != _landmarksPerView.end() && setValidViewIds.find(viewId) != setValidViewIds.end())
7473
{
7574
// 2D view bounds
7675
const float& scale = viewer2DInfo["scale"].toFloat();
@@ -137,7 +136,7 @@ void ObservationsEntity::fillBytesData(QByteArray& positionData)
137136
// -------------- read position data ----------------------
138137

139138
const auto& nLandmarks = _sfmData.getLandmarks().size();
140-
const auto& nViews = _sfmData.getViews().size();
139+
const auto& nViews = _sfmData.getValidViews().size();
141140
positionData.resize(static_cast<int>((nLandmarks + nViews) * 3 * sizeof(float)));
142141
size_t nObservations = 0;
143142
// copy positions of landmarks
@@ -160,10 +159,10 @@ void ObservationsEntity::fillBytesData(QByteArray& positionData)
160159
uint viewPosIdx = static_cast<uint>(nLandmarks);
161160
// view camera positions are added after landmarks'
162161
positionsIt += 3 * sizeof(float) * nLandmarks;
163-
for (const auto& viewIt : _sfmData.getViews())
162+
for (const auto& viewId : _sfmData.getValidViews())
164163
{
165-
_viewId2vertexPos[viewIt.first] = viewPosIdx++;
166-
aliceVision::Vec3f center = _sfmData.getPose(*viewIt.second).getTransform().center().cast<float>();
164+
_viewId2vertexPos[viewId] = viewPosIdx++;
165+
aliceVision::Vec3f center = _sfmData.getPose(_sfmData.getView(viewId)).getTransform().center().cast<float>();
167166
// graphics to open-gl coordinates system
168167
center.z() *= -1;
169168
center.y() *= -1;
@@ -188,7 +187,15 @@ void ObservationsEntity::fillBytesData(QByteArray& positionData)
188187
for (const auto& obsIt : landIt.second.observations)
189188
{
190189
*indices++ = landIt.first;
191-
*indices++ = _viewId2vertexPos.at(obsIt.first);
190+
const auto& pos = _viewId2vertexPos.find(obsIt.first);
191+
if (pos != _viewId2vertexPos.end())
192+
{
193+
*indices++ = pos->second;
194+
}
195+
else
196+
{
197+
*indices++ = landIt.first;
198+
}
192199
++obsGlobalIndex;
193200
}
194201
}

0 commit comments

Comments
 (0)