Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visualisation mode for landmarks observations #42

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Currently available:
- [X] Alembic 3D visualization
- Point clouds
- Cameras
- Landmark observations
- [X] OIIO backend
- Read RAW images from DSLRs
- Read intermediate files of the [AliceVision](https://github.com/alicevision/AliceVision) framework stored in EXR format
Expand Down
87 changes: 72 additions & 15 deletions src/qmlAlembic/AlembicEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "IOThread.hpp"
#include "CameraLocatorEntity.hpp"
#include "PointCloudEntity.hpp"
#include "ObservationsEntity.hpp"
#include <Qt3DRender/QEffect>
#include <Qt3DRender/QTechnique>
#include <Qt3DRender/QRenderPass>
Expand All @@ -24,6 +25,11 @@ AlembicEntity::AlembicEntity(Qt3DCore::QNode* parent)
{
connect(_ioThread.get(), &IOThread::finished, this, &AlembicEntity::onIOThreadFinished);
createMaterials();

// trigger display repaint events of observations
connect(this, &AlembicEntity::viewIdChanged, this, &AlembicEntity::updateObservations);
connect(this, &AlembicEntity::displayObservationsChanged, this, &AlembicEntity::updateObservations);
connect(this, &AlembicEntity::viewer2DInfoChanged, this, &AlembicEntity::updateObservations);
}

void AlembicEntity::setSource(const QUrl& value)
Expand Down Expand Up @@ -54,6 +60,30 @@ void AlembicEntity::setLocatorScale(const float& value)
Q_EMIT locatorScaleChanged();
}

void AlembicEntity::setViewId(const int& value)
{
if (_viewId == value)
return;
_viewId = value;
Q_EMIT viewIdChanged();
}

void AlembicEntity::setDisplayObservations(const bool& value)
{
if (_displayObservations == value)
return;
_displayObservations = value;
Q_EMIT displayObservationsChanged();
}

void AlembicEntity::setViewer2DInfo(const QVariantMap& value)
{
if (_viewer2DInfo == value)
return;
_viewer2DInfo = value;
Q_EMIT viewer2DInfoChanged();
}

void AlembicEntity::scaleLocators() const
{
for(auto* entity : _cameras)
Expand All @@ -63,6 +93,16 @@ void AlembicEntity::scaleLocators() const
}
}

void AlembicEntity::updateObservations() const
{
for (auto* entity : _observations)
{
entity->update(static_cast<aliceVision::IndexT>(_viewId), _viewer2DInfo);
if (entity->isEnabled() != _displayObservations)
entity->setEnabled(_displayObservations);
}
}

// private
void AlembicEntity::createMaterials()
{
Expand Down Expand Up @@ -129,6 +169,7 @@ void AlembicEntity::clear()
removeComponent(component);
_cameras.clear();
_pointClouds.clear();
_observations.clear();
}

// private
Expand Down Expand Up @@ -160,10 +201,13 @@ void AlembicEntity::onIOThreadFinished()
// store pointers to cameras and point clouds
_cameras = findChildren<CameraLocatorEntity*>();
_pointClouds = findChildren<PointCloudEntity*>();
_observations = findChildren<ObservationsEntity*>();

// perform initial locator scaling
scaleLocators();

updateObservations();

setStatus(AlembicEntity::Ready);
}
catch(...)
Expand All @@ -174,6 +218,7 @@ void AlembicEntity::onIOThreadFinished()
_ioThread->clear();
Q_EMIT camerasChanged();
Q_EMIT pointCloudsChanged();
Q_EMIT observationsChanged();
}

// private
Expand All @@ -182,18 +227,25 @@ void AlembicEntity::visitAbcObject(const Alembic::Abc::IObject& iObj, QEntity* p
using namespace Alembic::Abc;
using namespace Alembic::AbcGeom;

const auto createEntity = [&](const IObject&) -> BaseAlembicObject* {
const auto createEntities = [&](const IObject&) -> std::vector<BaseAlembicObject*> {
const MetaData& md = iObj.getMetaData();

if(IPoints::matches(md))
{
std::vector<BaseAlembicObject*> entities(2);
IPoints points(iObj, Alembic::Abc::kWrapExisting);
PointCloudEntity* entity = new PointCloudEntity(parent);
entity->setData(iObj);
entity->addComponent(_cloudMaterial);
entity->fillArbProperties(points.getSchema().getArbGeomParams());
entity->fillUserProperties(points.getSchema().getUserProperties());
return entity;
PointCloudEntity* entity0 = new PointCloudEntity(parent);
entity0->setData(iObj);
entity0->addComponent(_cloudMaterial);
entity0->fillArbProperties(points.getSchema().getArbGeomParams());
entity0->fillUserProperties(points.getSchema().getUserProperties());
entities[0] = entity0;
ObservationsEntity* entity1 = new ObservationsEntity(_source.toLocalFile().toStdString(), parent);
entity1->setData();
entity1->fillArbProperties(points.getSchema().getArbGeomParams());
entity1->fillUserProperties(points.getSchema().getUserProperties());
entities[1] = entity1;
return entities;
}
else if(IXform::matches(md))
{
Expand All @@ -204,7 +256,7 @@ void AlembicEntity::visitAbcObject(const Alembic::Abc::IObject& iObj, QEntity* p
entity->setTransform(xs.getMatrix());
entity->fillArbProperties(xform.getSchema().getArbGeomParams());
entity->fillUserProperties(xform.getSchema().getUserProperties());
return entity;
return {entity};
}
else if(ICamera::matches(md))
{
Expand All @@ -213,12 +265,12 @@ void AlembicEntity::visitAbcObject(const Alembic::Abc::IObject& iObj, QEntity* p
entity->addComponent(_cameraMaterial);
entity->fillArbProperties(cam.getSchema().getArbGeomParams());
entity->fillUserProperties(cam.getSchema().getUserProperties());
return entity;
return {entity};
}
else
{
// fallback: create empty object to preserve hierarchy
return new BaseAlembicObject(parent);
return {new BaseAlembicObject(parent)};
}
};

Expand All @@ -235,12 +287,17 @@ void AlembicEntity::visitAbcObject(const Alembic::Abc::IObject& iObj, QEntity* p
}
}

BaseAlembicObject* entity = createEntity(iObj);
entity->setObjectName(iObj.getName().c_str());
std::vector<BaseAlembicObject*> entities = createEntities(iObj);

// visit children
for(size_t i = 0; i < iObj.getNumChildren(); i++)
visitAbcObject(iObj.getChild(i), entity);
for (size_t j = 0; j < entities.size(); j++)
{
auto entity = entities[j];
entity->setObjectName((iObj.getName() + std::to_string(j)).c_str());

// visit children
for (size_t i = 0; i < iObj.getNumChildren(); i++)
visitAbcObject(iObj.getChild(i), entity);
}
}

} // namespace
26 changes: 26 additions & 0 deletions src/qmlAlembic/AlembicEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace abcentity
{
class CameraLocatorEntity;
class PointCloudEntity;
class ObservationsEntity;
class IOThread;

class AlembicEntity : public Qt3DCore::QEntity
Expand All @@ -22,8 +23,13 @@ class AlembicEntity : public Qt3DCore::QEntity
Q_PROPERTY(bool skipHidden MEMBER _skipHidden NOTIFY skipHiddenChanged)
Q_PROPERTY(float pointSize READ pointSize WRITE setPointSize NOTIFY pointSizeChanged)
Q_PROPERTY(float locatorScale READ locatorScale WRITE setLocatorScale NOTIFY locatorScaleChanged)
Q_PROPERTY(int viewId READ viewId WRITE setViewId NOTIFY viewIdChanged)
Q_PROPERTY(QVariantMap viewer2DInfo READ viewer2DInfo WRITE setViewer2DInfo NOTIFY viewer2DInfoChanged)
Q_PROPERTY(bool displayObservations READ displayObservations WRITE setDisplayObservations NOTIFY displayObservationsChanged)
Q_PROPERTY(QQmlListProperty<abcentity::CameraLocatorEntity> cameras READ cameras NOTIFY camerasChanged)
Q_PROPERTY(QQmlListProperty<abcentity::PointCloudEntity> pointClouds READ pointClouds NOTIFY pointCloudsChanged)
Q_PROPERTY(
QQmlListProperty<abcentity::ObservationsEntity> observations READ observations NOTIFY observationsChanged)

Q_PROPERTY(Status status READ status NOTIFY statusChanged)

Expand All @@ -43,9 +49,15 @@ class AlembicEntity : public Qt3DCore::QEntity
Q_SLOT const QUrl& source() const { return _source; }
Q_SLOT float pointSize() const { return _pointSize; }
Q_SLOT float locatorScale() const { return _locatorScale; }
Q_SLOT int viewId() const { return _viewId; }
Q_SLOT bool displayObservations() const { return _displayObservations; }
Q_SLOT QVariantMap viewer2DInfo() const { return _viewer2DInfo; }
Q_SLOT void setSource(const QUrl& source);
Q_SLOT void setPointSize(const float& value);
Q_SLOT void setLocatorScale(const float& value);
Q_SLOT void setViewId(const int& value);
Q_SLOT void setDisplayObservations(const bool& value);
Q_SLOT void setViewer2DInfo(const QVariantMap& value);

Status status() const { return _status; }
void setStatus(Status status) {
Expand All @@ -70,12 +82,20 @@ class AlembicEntity : public Qt3DCore::QEntity
return {this, &_pointClouds};
}

QQmlListProperty<ObservationsEntity> observations() {
return {this, &_observations};
}

public:
Q_SIGNAL void sourceChanged();
Q_SIGNAL void camerasChanged();
Q_SIGNAL void pointSizeChanged();
Q_SIGNAL void pointCloudsChanged();
Q_SIGNAL void observationsChanged();
Q_SIGNAL void locatorScaleChanged();
Q_SIGNAL void viewIdChanged();
Q_SIGNAL void viewer2DInfoChanged();
Q_SIGNAL void displayObservationsChanged();
Q_SIGNAL void objectPicked(Qt3DCore::QTransform* transform);
Q_SIGNAL void statusChanged(Status status);
Q_SIGNAL void skipHiddenChanged();
Expand All @@ -84,6 +104,8 @@ class AlembicEntity : public Qt3DCore::QEntity
/// Scale child locators
void scaleLocators() const;

void updateObservations() const;

void onIOThreadFinished();

private:
Expand All @@ -92,11 +114,15 @@ class AlembicEntity : public Qt3DCore::QEntity
bool _skipHidden = false;
float _pointSize = 0.5f;
float _locatorScale = 1.0f;
int _viewId = 0;
bool _displayObservations = false;
QVariantMap _viewer2DInfo;
Qt3DRender::QParameter* _pointSizeParameter;
Qt3DRender::QMaterial* _cloudMaterial;
Qt3DRender::QMaterial* _cameraMaterial;
QList<CameraLocatorEntity*> _cameras;
QList<PointCloudEntity*> _pointClouds;
QList<ObservationsEntity*> _observations;
std::unique_ptr<IOThread> _ioThread;
};

Expand Down
5 changes: 4 additions & 1 deletion src/qmlAlembic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(PLUGIN_SOURCES
CameraLocatorEntity.cpp
IOThread.cpp
PointCloudEntity.cpp
ObservationsEntity.cpp
)

set(PLUGIN_HEADERS
Expand All @@ -13,6 +14,7 @@ set(PLUGIN_HEADERS
CameraLocatorEntity.hpp
IOThread.hpp
PointCloudEntity.hpp
ObservationsEntity.hpp
plugin.hpp
)

Expand Down Expand Up @@ -49,8 +51,9 @@ target_link_libraries(alembicEntityQmlPlugin
Qt5::3DCore
Qt5::3DRender
Alembic::Alembic
PRIVATE
Qt5::3DExtras
aliceVision_sfmData
aliceVision_sfmDataIO
)

set_target_properties(alembicEntityQmlPlugin
Expand Down
Loading