Skip to content

Commit b52a4ee

Browse files
committed
[ObservationsEntity] use SfMData instead of Alembic
also remove include .cpp
1 parent 3bbc0fe commit b52a4ee

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/qmlAlembic/AlembicEntity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void AlembicEntity::visitAbcObject(const Alembic::Abc::IObject& iObj, QEntity* p
241241
entity0->fillUserProperties(points.getSchema().getUserProperties());
242242
entities[0] = entity0;
243243
ObservationsEntity* entity1 = new ObservationsEntity(_source.toLocalFile().toStdString(), parent);
244-
entity1->setData(iObj);
244+
entity1->setData();
245245
entity1->fillArbProperties(points.getSchema().getArbGeomParams());
246246
entity1->fillUserProperties(points.getSchema().getUserProperties());
247247
entities[1] = entity1;

src/qmlAlembic/ObservationsEntity.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Qt3DRender/QBuffer>
55
#include <Qt3DExtras/QPhongAlphaMaterial>
66

7-
#include <aliceVision/sfmDataIO/AlembicImporter.cpp>
7+
#include <aliceVision/sfmDataIO/sfmDataIO.hpp>
88

99
using namespace Qt3DRender;
1010
using namespace aliceVision;
@@ -55,14 +55,14 @@ ObservationsEntity::ObservationsEntity(std::string source, Qt3DCore::QNode* pare
5555
fillLandmarksPerViews();
5656
}
5757

58-
void ObservationsEntity::setData(const Alembic::Abc::IObject& iObj)
58+
void ObservationsEntity::setData()
5959
{
6060
// contains the 3D coordinates of vertices in space in the following order:
6161
// - the landmarks
6262
// - the view cameras
6363
QByteArray positionData;
6464

65-
fillBytesData(iObj, positionData);
65+
fillBytesData(positionData);
6666

6767
// contains the connections between the selected view and its corresponding
6868
// observed landmarks
@@ -152,64 +152,64 @@ void ObservationsEntity::fillLandmarksPerViews()
152152
}
153153
}
154154

155-
void ObservationsEntity::fillBytesData(const Alembic::Abc::IObject& iObj, QByteArray& positionData)
155+
void ObservationsEntity::fillBytesData(QByteArray& positionData)
156156
{
157-
using namespace Alembic::Abc;
158-
using namespace Alembic::AbcGeom;
159-
using sfmDataIO::AV_UInt32ArraySamplePtr;
160-
161-
IPoints points(iObj, kWrapExisting);
162-
IPointsSchema schema = points.getSchema();
163-
164157
// -------------- read position data ----------------------
165158

166-
P3fArraySamplePtr positionsLandmarks = schema.getValue().getPositions();
167-
const auto& nLandmarks = positionsLandmarks->size();
159+
const auto& nLandmarks = _sfmData.getLandmarks().size();
168160
const auto& nViews = _sfmData.getViews().size();
169161
positionData.resize(static_cast<int>((nLandmarks + nViews) * 3 * sizeof(float)));
162+
size_t nObservations = 0;
170163
// copy positions of landmarks
171-
memcpy(positionData.data(), (const char*)positionsLandmarks->get(), nLandmarks * 3 * sizeof(float));
164+
{
165+
auto* positionsIt = positionData.data();
166+
for (const auto& landIt : _sfmData.getLandmarks())
167+
{
168+
aliceVision::Vec3f x = landIt.second.X.cast<float>();
169+
// graphics to open-gl coordinates system
170+
x.z() *= -1;
171+
x.y() *= -1;
172+
memcpy(positionsIt, reinterpret_cast<char*>(x.data()), 3 * sizeof(float));
173+
positionsIt += 3 * sizeof(float);
174+
nObservations += landIt.second.observations.size();
175+
}
176+
}
172177
// copy positions of view cameras and construct _viewId2vertexPos
173178
{
174-
auto* positionsIt = positionData.data();
175-
uint viewPosIdx = static_cast<uint>(nLandmarks);
176-
// view camera positions are added after landmarks'
177-
positionsIt += 3 * sizeof(float) * nLandmarks;
178-
for (const auto& viewIt : _sfmData.getViews())
179-
{
179+
auto* positionsIt = positionData.data();
180+
uint viewPosIdx = static_cast<uint>(nLandmarks);
181+
// view camera positions are added after landmarks'
182+
positionsIt += 3 * sizeof(float) * nLandmarks;
183+
for (const auto& viewIt : _sfmData.getViews())
184+
{
180185
_viewId2vertexPos[viewIt.first] = viewPosIdx++;
181186
aliceVision::Vec3f center = _sfmData.getPose(*viewIt.second).getTransform().center().cast<float>();
182187
// graphics to open-gl coordinates system
183188
center.z() *= -1;
184189
center.y() *= -1;
185190
memcpy(positionsIt, reinterpret_cast<char*>(center.data()), 3 * sizeof(float));
186191
positionsIt += 3 * sizeof(float);
187-
}
192+
}
188193
}
189194

190195
// -------------- read Tc index data ----------------------
191196

192197
{
193-
ICompoundProperty userProps = aliceVision::sfmDataIO::getAbcUserProperties(schema);
194-
AV_UInt32ArraySamplePtr sampleVisibilitySize(userProps, "mvg_visibilitySize");
195-
AV_UInt32ArraySamplePtr sampleVisibilityViewId(userProps, "mvg_visibilityViewId");
196-
197-
_indexBytesByLandmark.resize(static_cast<int>(2 * sizeof(uint) * sampleVisibilityViewId.size()));
198-
_landmarkId2IndexRange.resize(sampleVisibilityViewId.size());
198+
_indexBytesByLandmark.resize(static_cast<int>(2 * sizeof(uint) * nObservations));
199+
_landmarkId2IndexRange.resize(nLandmarks);
199200
uint* indices = reinterpret_cast<uint*>(_indexBytesByLandmark.data());
200201
uint offset = 0;
201202
size_t obsGlobalIndex = 0;
202-
for (uint point3d_i = 0; point3d_i < sampleVisibilitySize.size(); ++point3d_i)
203+
for (const auto& landIt : _sfmData.getLandmarks())
203204
{
204-
// Number of observation for this 3d point
205-
const size_t visibilitySize = sampleVisibilitySize[point3d_i];
206-
const auto& delta = static_cast<uint>(visibilitySize * 2);
207-
_landmarkId2IndexRange[point3d_i] = std::pair<uint, uint>(offset, delta);
205+
const auto& delta = static_cast<uint>(landIt.second.observations.size() * 2);
206+
_landmarkId2IndexRange[landIt.first] = std::pair<uint, uint>(offset, delta);
208207
offset += delta;
209-
for (size_t obs_i = 0; obs_i < visibilitySize; ++obs_i, ++obsGlobalIndex)
208+
for (const auto& obsIt : landIt.second.observations)
210209
{
211-
*indices++ = point3d_i;
212-
*indices++ = _viewId2vertexPos.at(static_cast<IndexT>(sampleVisibilityViewId[obsGlobalIndex]));
210+
*indices++ = landIt.first;
211+
*indices++ = _viewId2vertexPos.at(obsIt.first);
212+
++obsGlobalIndex;
213213
}
214214
}
215215
}

src/qmlAlembic/ObservationsEntity.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class ObservationsEntity : public BaseAlembicObject
1717
explicit ObservationsEntity(std::string source, Qt3DCore::QNode* parent = nullptr);
1818
~ObservationsEntity() override = default;
1919

20-
void setData(const Alembic::Abc::IObject&);
20+
void setData();
2121
void update(const aliceVision::IndexT& viewId, const QVariantMap& viewer2DInfo);
2222

2323
private:
2424

25-
void fillBytesData(const Alembic::Abc::IObject& iObj, QByteArray& positionData);
25+
void fillBytesData(QByteArray& positionData);
2626
void fillLandmarksPerViews();
2727

2828
// file path to SfM data

0 commit comments

Comments
 (0)