mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 20:30:46 -06:00
#4683 clang-format on all files in ApplicationCode
This commit is contained in:
1 parent
3a317504bb
commit
fe9e567825
2092 files changed
+117952
-111846
No files matched your search
@@ -41,24 +41,24 @@ RicExportToSharingServerScheduler* RicExportToSharingServerScheduler::instance()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportToSharingServerScheduler::scheduleUpdateSession()
|
||||
{
|
||||
startTimer(0);
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportToSharingServerScheduler::startTimer(int msecs)
|
||||
void RicExportToSharingServerScheduler::startTimer( int msecs )
|
||||
{
|
||||
if (!m_timer)
|
||||
if ( !m_timer )
|
||||
{
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTriggerUpdateSessionWhenReady()));
|
||||
m_timer = new QTimer( this );
|
||||
connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotTriggerUpdateSessionWhenReady() ) );
|
||||
}
|
||||
|
||||
if (!m_timer->isActive())
|
||||
if ( !m_timer->isActive() )
|
||||
{
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->start(msecs);
|
||||
m_timer->setSingleShot( true );
|
||||
m_timer->start( msecs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ void RicExportToSharingServerScheduler::startTimer(int msecs)
|
||||
void RicExportToSharingServerScheduler::triggerUpdateSession()
|
||||
{
|
||||
auto* cmdFeature = dynamic_cast<RicHoloLensAutoExportToSharingServerFeature*>(
|
||||
caf::CmdFeatureManager::instance()->getCommandFeature("RicHoloLensAutoExportToSharingServerFeature"));
|
||||
if (cmdFeature)
|
||||
caf::CmdFeatureManager::instance()->getCommandFeature( "RicHoloLensAutoExportToSharingServerFeature" ) );
|
||||
if ( cmdFeature )
|
||||
{
|
||||
cmdFeature->triggerUpdateSession();
|
||||
}
|
||||
@@ -80,9 +80,9 @@ void RicExportToSharingServerScheduler::triggerUpdateSession()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportToSharingServerScheduler::slotTriggerUpdateSessionWhenReady()
|
||||
{
|
||||
if (caf::ProgressState::isActive())
|
||||
if ( caf::ProgressState::isActive() )
|
||||
{
|
||||
startTimer(100);
|
||||
startTimer( 100 );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,16 +38,16 @@ private slots:
|
||||
|
||||
private:
|
||||
RicExportToSharingServerScheduler()
|
||||
: m_timer(nullptr)
|
||||
: m_timer( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
~RicExportToSharingServerScheduler() override;
|
||||
|
||||
RicExportToSharingServerScheduler(const RicExportToSharingServerScheduler& o) = delete;
|
||||
void operator=(const RicExportToSharingServerScheduler& o) = delete;
|
||||
RicExportToSharingServerScheduler( const RicExportToSharingServerScheduler& o ) = delete;
|
||||
void operator=( const RicExportToSharingServerScheduler& o ) = delete;
|
||||
|
||||
void startTimer(int msecs);
|
||||
void startTimer( int msecs );
|
||||
void triggerUpdateSession();
|
||||
|
||||
private:
|
||||
|
||||
+20
-20
@@ -27,20 +27,20 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensAutoExportToSharingServerFeature, "RicHoloLensAutoExportToSharingServerFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensAutoExportToSharingServerFeature, "RicHoloLensAutoExportToSharingServerFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensAutoExportToSharingServerFeature::RicHoloLensAutoExportToSharingServerFeature()
|
||||
: m_isActive(false)
|
||||
: m_isActive( false )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensAutoExportToSharingServerFeature::setActive(bool enable)
|
||||
void RicHoloLensAutoExportToSharingServerFeature::setActive( bool enable )
|
||||
{
|
||||
m_isActive = enable;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ void RicHoloLensAutoExportToSharingServerFeature::setActive(bool enable)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensAutoExportToSharingServerFeature::isActive() const
|
||||
{
|
||||
if (isSessionValid())
|
||||
if ( isSessionValid() )
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
@@ -63,18 +63,18 @@ bool RicHoloLensAutoExportToSharingServerFeature::isActive() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensAutoExportToSharingServerFeature::triggerUpdateSession()
|
||||
{
|
||||
if (m_isActive && isSessionValid())
|
||||
if ( m_isActive && isSessionValid() )
|
||||
{
|
||||
RimGridView* activeView = RiaApplication::instance()->activeGridView();
|
||||
if (!activeView)
|
||||
if ( !activeView )
|
||||
{
|
||||
RiaLogging::error("No active view");
|
||||
RiaLogging::error( "No active view" );
|
||||
return;
|
||||
}
|
||||
|
||||
RicHoloLensSession* session = RicHoloLensSessionManager::instance()->session();
|
||||
|
||||
session->updateSessionDataFromView(*activeView);
|
||||
session->updateSessionDataFromView( *activeView );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,24 +89,24 @@ bool RicHoloLensAutoExportToSharingServerFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensAutoExportToSharingServerFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensAutoExportToSharingServerFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
m_isActive = !m_isActive;
|
||||
|
||||
if (!isSessionValid())
|
||||
|
||||
if ( !isSessionValid() )
|
||||
{
|
||||
RiaLogging::error("No valid HoloLens session present");
|
||||
RiaLogging::error( "No valid HoloLens session present" );
|
||||
m_isActive = false;
|
||||
}
|
||||
|
||||
RimGridView* activeView = RiaApplication::instance()->activeGridView();
|
||||
if (!activeView)
|
||||
if ( !activeView )
|
||||
{
|
||||
RiaLogging::error("No active view");
|
||||
RiaLogging::error( "No active view" );
|
||||
m_isActive = false;
|
||||
}
|
||||
|
||||
if (m_isActive)
|
||||
if ( m_isActive )
|
||||
{
|
||||
triggerUpdateSession();
|
||||
}
|
||||
@@ -115,12 +115,12 @@ void RicHoloLensAutoExportToSharingServerFeature::onActionTriggered(bool isCheck
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensAutoExportToSharingServerFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensAutoExportToSharingServerFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/HoloLensSendContinously24x24.png"));
|
||||
actionToSetup->setIcon( QIcon( ":/HoloLensSendContinously24x24.png" ) );
|
||||
|
||||
actionToSetup->setText("Export to HoloLens Server Continuously");
|
||||
actionToSetup->setCheckable(true);
|
||||
actionToSetup->setText( "Export to HoloLens Server Continuously" );
|
||||
actionToSetup->setCheckable( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -137,7 +137,7 @@ bool RicHoloLensAutoExportToSharingServerFeature::isCommandChecked()
|
||||
bool RicHoloLensAutoExportToSharingServerFeature::isSessionValid() const
|
||||
{
|
||||
RicHoloLensSession* session = RicHoloLensSessionManager::instance()->session();
|
||||
if (session && session->isSessionValid())
|
||||
if ( session && session->isSessionValid() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-3
@@ -30,15 +30,15 @@ class RicHoloLensAutoExportToSharingServerFeature : public caf::CmdFeature
|
||||
public:
|
||||
RicHoloLensAutoExportToSharingServerFeature();
|
||||
|
||||
void setActive(bool enable);
|
||||
void setActive( bool enable );
|
||||
bool isActive() const;
|
||||
|
||||
void triggerUpdateSession();
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
bool isCommandChecked() override;
|
||||
|
||||
bool isSessionValid() const;
|
||||
|
||||
+6
-6
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensCreateDummyFiledBackedSessionFeature, "RicHoloLensCreateDummyFiledBackedSessionFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensCreateDummyFiledBackedSessionFeature, "RicHoloLensCreateDummyFiledBackedSessionFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -35,19 +35,19 @@ bool RicHoloLensCreateDummyFiledBackedSessionFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensCreateDummyFiledBackedSessionFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensCreateDummyFiledBackedSessionFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RicHoloLensSessionManager::instance()->createDummyFileBackedSession();
|
||||
|
||||
|
||||
RicHoloLensSessionManager::refreshToolbarState();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensCreateDummyFiledBackedSessionFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensCreateDummyFiledBackedSessionFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/HoloLensConnect24x24.png"));
|
||||
actionToSetup->setIcon( QIcon( ":/HoloLensConnect24x24.png" ) );
|
||||
|
||||
actionToSetup->setText("Create File-Backed Dummy-Session");
|
||||
actionToSetup->setText( "Create File-Backed Dummy-Session" );
|
||||
}
|
||||
+2
-2
@@ -29,6 +29,6 @@ class RicHoloLensCreateDummyFiledBackedSessionFeature : public caf::CmdFeature
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <QAction>
|
||||
#include <QPushButton>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensCreateSessionFeature, "RicHoloLensCreateSessionFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensCreateSessionFeature, "RicHoloLensCreateSessionFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -43,26 +43,30 @@ bool RicHoloLensCreateSessionFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensCreateSessionFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensCreateSessionFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RicHoloLensCreateSessionUi createSessionUi;
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &createSessionUi, "HoloLens - Create Session", "");
|
||||
propertyDialog.resize(QSize(400, 330));
|
||||
caf::PdmUiPropertyViewDialog propertyDialog( RiuMainWindow::instance(),
|
||||
&createSessionUi,
|
||||
"HoloLens - Create Session",
|
||||
"" );
|
||||
propertyDialog.resize( QSize( 400, 330 ) );
|
||||
|
||||
{
|
||||
QDialogButtonBox* dialogButtonBox = propertyDialog.dialogButtonBox();
|
||||
dialogButtonBox->clear();
|
||||
|
||||
QPushButton* pushButton = dialogButtonBox->addButton("Create Session", QDialogButtonBox::ActionRole);
|
||||
connect(pushButton, SIGNAL(clicked()), &propertyDialog, SLOT(accept()));
|
||||
QPushButton* pushButton = dialogButtonBox->addButton( "Create Session", QDialogButtonBox::ActionRole );
|
||||
connect( pushButton, SIGNAL( clicked() ), &propertyDialog, SLOT( accept() ) );
|
||||
}
|
||||
|
||||
int ret = propertyDialog.exec();
|
||||
if (ret == QDialog::Accepted)
|
||||
if ( ret == QDialog::Accepted )
|
||||
{
|
||||
RicHoloLensSessionManager::instance()->createSession(
|
||||
createSessionUi.serverUrl(), createSessionUi.sessionName(), createSessionUi.sessionPinCode());
|
||||
RicHoloLensSessionManager::instance()->createSession( createSessionUi.serverUrl(),
|
||||
createSessionUi.sessionName(),
|
||||
createSessionUi.sessionPinCode() );
|
||||
}
|
||||
|
||||
RicHoloLensSessionManager::refreshToolbarState();
|
||||
@@ -71,9 +75,9 @@ void RicHoloLensCreateSessionFeature::onActionTriggered(bool isChecked)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensCreateSessionFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensCreateSessionFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/HoloLensConnect24x24.png"));
|
||||
actionToSetup->setIcon( QIcon( ":/HoloLensConnect24x24.png" ) );
|
||||
|
||||
actionToSetup->setText("Connect to HoloLens Server");
|
||||
actionToSetup->setText( "Connect to HoloLens Server" );
|
||||
}
|
||||
@@ -29,6 +29,6 @@ class RicHoloLensCreateSessionFeature : public caf::CmdFeature
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
@@ -27,22 +27,22 @@
|
||||
#include "cafPdmSettings.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicHoloLensCreateSessionUi, "RicHoloLensCreateSessionUi");
|
||||
CAF_PDM_SOURCE_INIT( RicHoloLensCreateSessionUi, "RicHoloLensCreateSessionUi" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensCreateSessionUi::RicHoloLensCreateSessionUi()
|
||||
{
|
||||
CAF_PDM_InitObject("HoloLens Create Session", "", "", "");
|
||||
CAF_PDM_InitObject( "HoloLens Create Session", "", "", "" );
|
||||
|
||||
CAF_PDM_InitField(&m_sessionName, "SessionName", QString("DummySessionName"), "Session Name", "", "", "");
|
||||
CAF_PDM_InitField(&m_sessionPinCode, "SessionPinCode", QString("1234"), "Session Pin Code", "", "", "");
|
||||
CAF_PDM_InitField( &m_sessionName, "SessionName", QString( "DummySessionName" ), "Session Name", "", "", "" );
|
||||
CAF_PDM_InitField( &m_sessionPinCode, "SessionPinCode", QString( "1234" ), "Session Pin Code", "", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_serverSettings, "ServerSettings", "Server Settings", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault( &m_serverSettings, "ServerSettings", "Server Settings", "", "", "" );
|
||||
m_serverSettings = new RicHoloLensServerSettings;
|
||||
|
||||
caf::PdmSettings::readFieldsFromApplicationStore(m_serverSettings);
|
||||
caf::PdmSettings::readFieldsFromApplicationStore( m_serverSettings );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -50,30 +50,29 @@ RicHoloLensCreateSessionUi::RicHoloLensCreateSessionUi()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensCreateSessionUi::~RicHoloLensCreateSessionUi()
|
||||
{
|
||||
caf::PdmSettings::writeFieldsToApplicationStore(m_serverSettings);
|
||||
caf::PdmSettings::writeFieldsToApplicationStore( m_serverSettings );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensCreateSessionUi::serverUrl() const
|
||||
{
|
||||
CVF_ASSERT(m_serverSettings());
|
||||
CVF_ASSERT( m_serverSettings() );
|
||||
|
||||
return m_serverSettings->serverUrl();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensCreateSessionUi::sessionName() const
|
||||
{
|
||||
return m_sessionName;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensCreateSessionUi::sessionPinCode() const
|
||||
{
|
||||
@@ -83,18 +82,18 @@ QString RicHoloLensCreateSessionUi::sessionPinCode() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensCreateSessionUi::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
void RicHoloLensCreateSessionUi::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Server Configuration");
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Server Configuration" );
|
||||
|
||||
m_serverSettings->uiOrdering(uiConfigName, *group);
|
||||
m_serverSettings->uiOrdering( uiConfigName, *group );
|
||||
}
|
||||
|
||||
{
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Create Session");
|
||||
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Create Session" );
|
||||
|
||||
group->add(&m_sessionName);
|
||||
group->add(&m_sessionPinCode);
|
||||
group->add( &m_sessionName );
|
||||
group->add( &m_sessionPinCode );
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
QString sessionPinCode() const;
|
||||
|
||||
protected:
|
||||
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
private:
|
||||
caf::PdmChildField<RicHoloLensServerSettings*> m_serverSettings;
|
||||
|
||||
@@ -56,160 +56,161 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<VdeExportPart> RicHoloLensExportImpl::partsForExport(const RimGridView& view)
|
||||
std::vector<VdeExportPart> RicHoloLensExportImpl::partsForExport( const RimGridView& view )
|
||||
{
|
||||
std::vector<VdeExportPart> exportParts;
|
||||
|
||||
RimEclipseCase* rimEclipseCase = nullptr;
|
||||
view.firstAncestorOrThisOfType(rimEclipseCase);
|
||||
view.firstAncestorOrThisOfType( rimEclipseCase );
|
||||
|
||||
if (view.viewer())
|
||||
if ( view.viewer() )
|
||||
{
|
||||
auto visibleParts = view.viewer()->visibleParts();
|
||||
|
||||
for (auto& visiblePart : visibleParts)
|
||||
for ( auto& visiblePart : visibleParts )
|
||||
{
|
||||
if (RicHoloLensExportImpl::isGrid(visiblePart.p()))
|
||||
if ( RicHoloLensExportImpl::isGrid( visiblePart.p() ) )
|
||||
{
|
||||
VdeExportPart exportPart(visiblePart.p());
|
||||
exportPart.setSourceObjectType(VdeExportPart::OBJ_TYPE_GRID);
|
||||
VdeExportPart exportPart( visiblePart.p() );
|
||||
exportPart.setSourceObjectType( VdeExportPart::OBJ_TYPE_GRID );
|
||||
|
||||
if (rimEclipseCase && rimEclipseCase->mainGrid())
|
||||
if ( rimEclipseCase && rimEclipseCase->mainGrid() )
|
||||
{
|
||||
if (rimEclipseCase->mainGrid()->isFaceNormalsOutwards())
|
||||
if ( rimEclipseCase->mainGrid()->isFaceNormalsOutwards() )
|
||||
{
|
||||
exportPart.setWinding(VdeExportPart::COUNTERCLOCKWISE);
|
||||
exportPart.setWinding( VdeExportPart::COUNTERCLOCKWISE );
|
||||
}
|
||||
else
|
||||
{
|
||||
exportPart.setWinding(VdeExportPart::CLOCKWISE);
|
||||
exportPart.setWinding( VdeExportPart::CLOCKWISE );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto* sourceInfo = dynamic_cast<RivSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (sourceInfo)
|
||||
auto* sourceInfo = dynamic_cast<RivSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( sourceInfo )
|
||||
{
|
||||
RimFaultInView* faultInView = dynamic_cast<RimFaultInView*>(sourceInfo->object());
|
||||
if (faultInView)
|
||||
RimFaultInView* faultInView = dynamic_cast<RimFaultInView*>( sourceInfo->object() );
|
||||
if ( faultInView )
|
||||
{
|
||||
exportPart.setSourceObjectName(faultInView->name());
|
||||
exportPart.setColor(faultInView->faultColor());
|
||||
exportPart.setSourceObjectName( faultInView->name() );
|
||||
exportPart.setColor( faultInView->faultColor() );
|
||||
}
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(sourceInfo->object());
|
||||
if (eclipseCase)
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( sourceInfo->object() );
|
||||
if ( eclipseCase )
|
||||
{
|
||||
QString nameOfObject = rimEclipseCase->gridFileName();
|
||||
auto gridSourceInfo = dynamic_cast<const RivSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (gridSourceInfo)
|
||||
auto gridSourceInfo = dynamic_cast<const RivSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( gridSourceInfo )
|
||||
{
|
||||
size_t gridIndex = gridSourceInfo->gridIndex();
|
||||
|
||||
nameOfObject += " Grid " + QString::number(gridIndex);
|
||||
nameOfObject += " Grid " + QString::number( gridIndex );
|
||||
}
|
||||
|
||||
const RimEclipseView* eclipseView = dynamic_cast<const RimEclipseView*>(&view);
|
||||
if (eclipseView)
|
||||
const RimEclipseView* eclipseView = dynamic_cast<const RimEclipseView*>( &view );
|
||||
if ( eclipseView )
|
||||
{
|
||||
cvf::Color4f color = eclipseView->colorFromCellCategory(sourceInfo->cellSetType());
|
||||
exportPart.setColor(color.toColor3f());
|
||||
exportPart.setOpacity(color.a());
|
||||
cvf::Color4f color = eclipseView->colorFromCellCategory( sourceInfo->cellSetType() );
|
||||
exportPart.setColor( color.toColor3f() );
|
||||
exportPart.setOpacity( color.a() );
|
||||
|
||||
QString text = RicHoloLensExportImpl::gridCellSetTypeText(sourceInfo->cellSetType());
|
||||
exportPart.setSourceObjectCellSetType(text);
|
||||
QString text = RicHoloLensExportImpl::gridCellSetTypeText( sourceInfo->cellSetType() );
|
||||
exportPart.setSourceObjectCellSetType( text );
|
||||
}
|
||||
|
||||
exportPart.setSourceObjectName(nameOfObject);
|
||||
exportPart.setSourceObjectName( nameOfObject );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto femPartPickInfo = dynamic_cast<RivFemPickSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (femPartPickInfo)
|
||||
auto femPartPickInfo = dynamic_cast<RivFemPickSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( femPartPickInfo )
|
||||
{
|
||||
exportPart.setColor(RivGeoMechVizLogic::staticCellColor());
|
||||
exportPart.setColor( RivGeoMechVizLogic::staticCellColor() );
|
||||
}
|
||||
}
|
||||
|
||||
if (visiblePart->effect())
|
||||
if ( visiblePart->effect() )
|
||||
{
|
||||
const cvf::RenderStateCullFace* renderStateCullFace = dynamic_cast<const cvf::RenderStateCullFace*>(
|
||||
visiblePart->effect()->renderStateOfType(cvf::RenderState::CULL_FACE));
|
||||
if (renderStateCullFace)
|
||||
visiblePart->effect()->renderStateOfType( cvf::RenderState::CULL_FACE ) );
|
||||
if ( renderStateCullFace )
|
||||
{
|
||||
// The logic below that inverts the culling mode simply does not make sense. We should be able to just utilize the cull mode set
|
||||
// in the render state. The proper solution is probably to put more effort into correctly determining the winding in further up
|
||||
// in this function, but currently there is no clear way to accomplish this.
|
||||
if (renderStateCullFace->mode() == cvf::RenderStateCullFace::BACK)
|
||||
// The logic below that inverts the culling mode simply does not make sense. We should be able
|
||||
// to just utilize the cull mode set in the render state. The proper solution is probably to put
|
||||
// more effort into correctly determining the winding in further up in this function, but
|
||||
// currently there is no clear way to accomplish this.
|
||||
if ( renderStateCullFace->mode() == cvf::RenderStateCullFace::BACK )
|
||||
{
|
||||
exportPart.setCullFace(VdeExportPart::CF_FRONT);
|
||||
exportPart.setCullFace( VdeExportPart::CF_FRONT );
|
||||
}
|
||||
else if (renderStateCullFace->mode() == cvf::RenderStateCullFace::FRONT)
|
||||
else if ( renderStateCullFace->mode() == cvf::RenderStateCullFace::FRONT )
|
||||
{
|
||||
exportPart.setCullFace(VdeExportPart::CF_BACK);
|
||||
exportPart.setCullFace( VdeExportPart::CF_BACK );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appendTextureImage(exportPart, visiblePart.p());
|
||||
appendTextureImage( exportPart, visiblePart.p() );
|
||||
|
||||
exportParts.push_back(exportPart);
|
||||
exportParts.push_back( exportPart );
|
||||
}
|
||||
else if (RicHoloLensExportImpl::isPipe(visiblePart.p()))
|
||||
else if ( RicHoloLensExportImpl::isPipe( visiblePart.p() ) )
|
||||
{
|
||||
VdeExportPart exportPart(visiblePart.p());
|
||||
exportPart.setSourceObjectType(VdeExportPart::OBJ_TYPE_PIPE);
|
||||
VdeExportPart exportPart( visiblePart.p() );
|
||||
exportPart.setSourceObjectType( VdeExportPart::OBJ_TYPE_PIPE );
|
||||
|
||||
auto simWellSourceInfo = dynamic_cast<const RivSimWellPipeSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (simWellSourceInfo)
|
||||
auto simWellSourceInfo = dynamic_cast<const RivSimWellPipeSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( simWellSourceInfo )
|
||||
{
|
||||
auto simWell = simWellSourceInfo->well();
|
||||
if (simWell)
|
||||
if ( simWell )
|
||||
{
|
||||
exportPart.setSourceObjectName(simWell->name());
|
||||
exportPart.setColor(simWell->wellPipeColor());
|
||||
exportPart.setSourceObjectName( simWell->name() );
|
||||
exportPart.setColor( simWell->wellPipeColor() );
|
||||
}
|
||||
}
|
||||
|
||||
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (wellPathSourceInfo)
|
||||
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( wellPathSourceInfo )
|
||||
{
|
||||
RimWellPath* wellPath = wellPathSourceInfo->wellPath();
|
||||
if (wellPath)
|
||||
if ( wellPath )
|
||||
{
|
||||
exportPart.setSourceObjectName(wellPath->name());
|
||||
exportPart.setColor(wellPath->wellPathColor());
|
||||
exportPart.setSourceObjectName( wellPath->name() );
|
||||
exportPart.setColor( wellPath->wellPathColor() );
|
||||
}
|
||||
}
|
||||
|
||||
appendTextureImage(exportPart, visiblePart.p());
|
||||
appendTextureImage( exportPart, visiblePart.p() );
|
||||
|
||||
exportParts.push_back(exportPart);
|
||||
exportParts.push_back( exportPart );
|
||||
}
|
||||
else if (RicHoloLensExportImpl::isMeshLines(visiblePart.p()))
|
||||
else if ( RicHoloLensExportImpl::isMeshLines( visiblePart.p() ) )
|
||||
{
|
||||
VdeExportPart exportPart(visiblePart.p());
|
||||
exportPart.setSourceObjectType(VdeExportPart::OBJ_TYPE_GRID);
|
||||
VdeExportPart exportPart( visiblePart.p() );
|
||||
exportPart.setSourceObjectType( VdeExportPart::OBJ_TYPE_GRID );
|
||||
|
||||
cvf::Color3f lineColor = RiaApplication::instance()->preferences()->defaultGridLineColors();
|
||||
|
||||
auto linesSourceInfo = dynamic_cast<const RivMeshLinesSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (linesSourceInfo)
|
||||
auto linesSourceInfo = dynamic_cast<const RivMeshLinesSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( linesSourceInfo )
|
||||
{
|
||||
if (dynamic_cast<RimFaultInView*>(linesSourceInfo->object()))
|
||||
if ( dynamic_cast<RimFaultInView*>( linesSourceInfo->object() ) )
|
||||
{
|
||||
lineColor = RiaApplication::instance()->preferences()->defaultFaultGridLineColors();
|
||||
}
|
||||
}
|
||||
|
||||
exportPart.setColor(lineColor);
|
||||
exportPart.setRole(VdeExportPart::MESH_LINES);
|
||||
exportPart.setColor( lineColor );
|
||||
exportPart.setRole( VdeExportPart::MESH_LINES );
|
||||
|
||||
appendTextureImage(exportPart, visiblePart.p());
|
||||
appendTextureImage( exportPart, visiblePart.p() );
|
||||
|
||||
exportParts.push_back(exportPart);
|
||||
exportParts.push_back( exportPart );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,18 +221,18 @@ std::vector<VdeExportPart> RicHoloLensExportImpl::partsForExport(const RimGridVi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::pair<cvf::Vec3f, cvf::String>> RicHoloLensExportImpl::labelsForExport(const RimGridView& view)
|
||||
std::vector<std::pair<cvf::Vec3f, cvf::String>> RicHoloLensExportImpl::labelsForExport( const RimGridView& view )
|
||||
{
|
||||
std::vector<std::pair<cvf::Vec3f, cvf::String>> labelAndPositions;
|
||||
|
||||
auto visibleParts = view.viewer()->visibleParts();
|
||||
|
||||
for (auto& visiblePart : visibleParts)
|
||||
for ( auto& visiblePart : visibleParts )
|
||||
{
|
||||
const RivTextLabelSourceInfo* textLabel = dynamic_cast<const RivTextLabelSourceInfo*>(visiblePart->sourceInfo());
|
||||
if (textLabel)
|
||||
const RivTextLabelSourceInfo* textLabel = dynamic_cast<const RivTextLabelSourceInfo*>( visiblePart->sourceInfo() );
|
||||
if ( textLabel )
|
||||
{
|
||||
labelAndPositions.push_back(std::make_pair(textLabel->textPositionDisplayCoord(), textLabel->text()));
|
||||
labelAndPositions.push_back( std::make_pair( textLabel->textPositionDisplayCoord(), textLabel->text() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,34 +242,34 @@ std::vector<std::pair<cvf::Vec3f, cvf::String>> RicHoloLensExportImpl::labelsFor
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportImpl::appendTextureImage(VdeExportPart& exportPart, cvf::Part* part)
|
||||
void RicHoloLensExportImpl::appendTextureImage( VdeExportPart& exportPart, cvf::Part* part )
|
||||
{
|
||||
if (part && part->effect())
|
||||
if ( part && part->effect() )
|
||||
{
|
||||
{
|
||||
auto textureBindings = dynamic_cast<cvf::RenderStateTextureBindings*>(
|
||||
part->effect()->renderStateOfType(cvf::RenderState::TEXTURE_BINDINGS));
|
||||
part->effect()->renderStateOfType( cvf::RenderState::TEXTURE_BINDINGS ) );
|
||||
|
||||
if (textureBindings && textureBindings->bindingCount() > 0)
|
||||
if ( textureBindings && textureBindings->bindingCount() > 0 )
|
||||
{
|
||||
cvf::Texture* textureBinding = textureBindings->texture(0);
|
||||
if (textureBinding)
|
||||
cvf::Texture* textureBinding = textureBindings->texture( 0 );
|
||||
if ( textureBinding )
|
||||
{
|
||||
exportPart.setTextureImage(textureBinding->image());
|
||||
exportPart.setTextureImage( textureBinding->image() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto textureMappingFF = dynamic_cast<cvf::RenderStateTextureMapping_FF*>(
|
||||
part->effect()->renderStateOfType(cvf::RenderState::TEXTURE_MAPPING_FF));
|
||||
part->effect()->renderStateOfType( cvf::RenderState::TEXTURE_MAPPING_FF ) );
|
||||
|
||||
if (textureMappingFF && textureMappingFF->texture())
|
||||
if ( textureMappingFF && textureMappingFF->texture() )
|
||||
{
|
||||
auto* texture = textureMappingFF->texture();
|
||||
if (texture)
|
||||
if ( texture )
|
||||
{
|
||||
exportPart.setTextureImage(texture->image());
|
||||
exportPart.setTextureImage( texture->image() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,9 +279,9 @@ void RicHoloLensExportImpl::appendTextureImage(VdeExportPart& exportPart, cvf::P
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensExportImpl::gridCellSetTypeText(RivCellSetEnum cellSetType)
|
||||
QString RicHoloLensExportImpl::gridCellSetTypeText( RivCellSetEnum cellSetType )
|
||||
{
|
||||
switch (cellSetType)
|
||||
switch ( cellSetType )
|
||||
{
|
||||
case OVERRIDDEN_CELL_VISIBILITY:
|
||||
return "OVERRIDDEN_CELL_VISIBILITY";
|
||||
@@ -334,40 +335,40 @@ QString RicHoloLensExportImpl::gridCellSetTypeText(RivCellSetEnum cellSetType)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensExportImpl::isGrid(const cvf::Part* part)
|
||||
bool RicHoloLensExportImpl::isGrid( const cvf::Part* part )
|
||||
{
|
||||
if (!part) return false;
|
||||
if ( !part ) return false;
|
||||
|
||||
auto sourceInfo = part->sourceInfo();
|
||||
|
||||
{
|
||||
{
|
||||
auto sourceInfoOfType = dynamic_cast<const RivSourceInfo*>(sourceInfo);
|
||||
if (sourceInfoOfType)
|
||||
auto sourceInfoOfType = dynamic_cast<const RivSourceInfo*>( sourceInfo );
|
||||
if ( sourceInfoOfType )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto sourceInfoOfType = dynamic_cast<const RivIntersectionSourceInfo*>(sourceInfo);
|
||||
if (sourceInfoOfType)
|
||||
auto sourceInfoOfType = dynamic_cast<const RivIntersectionSourceInfo*>( sourceInfo );
|
||||
if ( sourceInfoOfType )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto sourceInfoOfType = dynamic_cast<const RivIntersectionBoxSourceInfo*>(sourceInfo);
|
||||
if (sourceInfoOfType)
|
||||
auto sourceInfoOfType = dynamic_cast<const RivIntersectionBoxSourceInfo*>( sourceInfo );
|
||||
if ( sourceInfoOfType )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto sourceInfoOfType = dynamic_cast<const RivFemPickSourceInfo*>(sourceInfo);
|
||||
if (sourceInfoOfType)
|
||||
auto sourceInfoOfType = dynamic_cast<const RivFemPickSourceInfo*>( sourceInfo );
|
||||
if ( sourceInfoOfType )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -380,23 +381,23 @@ bool RicHoloLensExportImpl::isGrid(const cvf::Part* part)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensExportImpl::isPipe(const cvf::Part* part)
|
||||
bool RicHoloLensExportImpl::isPipe( const cvf::Part* part )
|
||||
{
|
||||
if (!part) return false;
|
||||
if ( !part ) return false;
|
||||
|
||||
auto sourceInfo = part->sourceInfo();
|
||||
|
||||
{
|
||||
auto simWellSourceInfo = dynamic_cast<const RivSimWellPipeSourceInfo*>(sourceInfo);
|
||||
if (simWellSourceInfo)
|
||||
auto simWellSourceInfo = dynamic_cast<const RivSimWellPipeSourceInfo*>( sourceInfo );
|
||||
if ( simWellSourceInfo )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(sourceInfo);
|
||||
if (wellPathSourceInfo)
|
||||
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>( sourceInfo );
|
||||
if ( wellPathSourceInfo )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -408,15 +409,15 @@ bool RicHoloLensExportImpl::isPipe(const cvf::Part* part)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensExportImpl::isMeshLines(const cvf::Part* part)
|
||||
bool RicHoloLensExportImpl::isMeshLines( const cvf::Part* part )
|
||||
{
|
||||
if (!part) return false;
|
||||
if ( !part ) return false;
|
||||
|
||||
auto sourceInfo = part->sourceInfo();
|
||||
|
||||
{
|
||||
auto linesSourceInfo = dynamic_cast<const RivMeshLinesSourceInfo*>(sourceInfo);
|
||||
if (linesSourceInfo)
|
||||
auto linesSourceInfo = dynamic_cast<const RivMeshLinesSourceInfo*>( sourceInfo );
|
||||
if ( linesSourceInfo )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "VdeExportPart.h"
|
||||
|
||||
|
||||
#include "cvfCollection.h"
|
||||
|
||||
class QString;
|
||||
@@ -39,14 +38,14 @@ class Part;
|
||||
class RicHoloLensExportImpl
|
||||
{
|
||||
public:
|
||||
static std::vector<VdeExportPart> partsForExport(const RimGridView& view);
|
||||
static std::vector<std::pair<cvf::Vec3f, cvf::String>> labelsForExport(const RimGridView& view);
|
||||
static std::vector<VdeExportPart> partsForExport( const RimGridView& view );
|
||||
static std::vector<std::pair<cvf::Vec3f, cvf::String>> labelsForExport( const RimGridView& view );
|
||||
|
||||
private:
|
||||
static void appendTextureImage(VdeExportPart& exportPart, cvf::Part* part);
|
||||
static QString gridCellSetTypeText(RivCellSetEnum cellSetType);
|
||||
static void appendTextureImage( VdeExportPart& exportPart, cvf::Part* part );
|
||||
static QString gridCellSetTypeText( RivCellSetEnum cellSetType );
|
||||
|
||||
static bool isGrid(const cvf::Part* part);
|
||||
static bool isPipe(const cvf::Part* part);
|
||||
static bool isMeshLines(const cvf::Part* part);
|
||||
static bool isGrid( const cvf::Part* part );
|
||||
static bool isPipe( const cvf::Part* part );
|
||||
static bool isMeshLines( const cvf::Part* part );
|
||||
};
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensExportToFolderFeature, "RicHoloLensExportToFolderFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensExportToFolderFeature, "RicHoloLensExportToFolderFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -52,17 +52,21 @@ bool RicHoloLensExportToFolderFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToFolderFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensExportToFolderFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RimGridView* activeView = RiaApplication::instance()->activeGridView();
|
||||
|
||||
RicHoloLensExportToFolderUi* featureUi = RiaApplication::instance()->project()->dialogData()->holoLensExportToFolderData();
|
||||
featureUi->setViewForExport(activeView);
|
||||
featureUi->setViewForExport( activeView );
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog(nullptr, featureUi, "HoloLens - Export Data Folder", "", QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
propertyDialog.resize(QSize(400, 330));
|
||||
caf::PdmUiPropertyViewDialog propertyDialog( nullptr,
|
||||
featureUi,
|
||||
"HoloLens - Export Data Folder",
|
||||
"",
|
||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
|
||||
propertyDialog.resize( QSize( 400, 330 ) );
|
||||
|
||||
if (propertyDialog.exec() == QDialog::Accepted && !featureUi->exportFolder().isEmpty())
|
||||
if ( propertyDialog.exec() == QDialog::Accepted && !featureUi->exportFolder().isEmpty() )
|
||||
{
|
||||
/*
|
||||
cvf::Collection<cvf::Part> allPartsColl;
|
||||
@@ -106,23 +110,22 @@ void RicHoloLensExportToFolderFeature::onActionTriggered(bool isChecked)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
RimGridView* viewForExport = featureUi->viewForExport();
|
||||
if (!viewForExport) return;
|
||||
if ( !viewForExport ) return;
|
||||
|
||||
QDir dir(featureUi->exportFolder());
|
||||
QDir dir( featureUi->exportFolder() );
|
||||
const QString absOutputFolder = dir.absolutePath();
|
||||
|
||||
VdeFileExporter exporter(absOutputFolder);
|
||||
exporter.exportViewContents(*viewForExport);
|
||||
VdeFileExporter exporter( absOutputFolder );
|
||||
exporter.exportViewContents( *viewForExport );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToFolderFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensExportToFolderFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/Save.png"));
|
||||
actionToSetup->setText("HoloLens : Export to Folder");
|
||||
actionToSetup->setIcon( QIcon( ":/Save.png" ) );
|
||||
actionToSetup->setText( "HoloLens : Export to Folder" );
|
||||
}
|
||||
@@ -29,6 +29,6 @@ class RicHoloLensExportToFolderFeature : public caf::CmdFeature
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
@@ -28,25 +28,25 @@
|
||||
#include "cafPdmUiFilePathEditor.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicHoloLensExportToFolderUi, "RicHoloLensExportToFolderUi");
|
||||
CAF_PDM_SOURCE_INIT( RicHoloLensExportToFolderUi, "RicHoloLensExportToFolderUi" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensExportToFolderUi::RicHoloLensExportToFolderUi()
|
||||
{
|
||||
CAF_PDM_InitObject("Resample LAS curves for export", "", "", "");
|
||||
CAF_PDM_InitObject( "Resample LAS curves for export", "", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_viewForExport, "ViewForExport", "View", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault( &m_viewForExport, "ViewForExport", "View", "", "", "" );
|
||||
|
||||
CAF_PDM_InitField(&m_exportFolder, "ExportFolder", QString(), "Export Folder", "", "", "");
|
||||
m_exportFolder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitField( &m_exportFolder, "ExportFolder", QString(), "Export Folder", "", "", "" );
|
||||
m_exportFolder.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToFolderUi::setViewForExport(RimGridView* view)
|
||||
void RicHoloLensExportToFolderUi::setViewForExport( RimGridView* view )
|
||||
{
|
||||
m_viewForExport = view;
|
||||
}
|
||||
@@ -70,19 +70,20 @@ RimGridView* RicHoloLensExportToFolderUi::viewForExport() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RicHoloLensExportToFolderUi::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly)
|
||||
QList<caf::PdmOptionItemInfo>
|
||||
RicHoloLensExportToFolderUi::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly )
|
||||
{
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
if (fieldNeedingOptions == &m_viewForExport)
|
||||
if ( fieldNeedingOptions == &m_viewForExport )
|
||||
{
|
||||
std::vector<RimGridView*> visibleViews;
|
||||
RiaApplication::instance()->project()->allVisibleGridViews(visibleViews);
|
||||
RiaApplication::instance()->project()->allVisibleGridViews( visibleViews );
|
||||
|
||||
for (RimGridView* v : visibleViews)
|
||||
for ( RimGridView* v : visibleViews )
|
||||
{
|
||||
RiaOptionItemFactory::appendOptionItemFromViewNameAndCaseName(v, &options);
|
||||
RiaOptionItemFactory::appendOptionItemFromViewNameAndCaseName( v, &options );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +93,14 @@ QList<caf::PdmOptionItemInfo> RicHoloLensExportToFolderUi::calculateValueOptions
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToFolderUi::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute)
|
||||
void RicHoloLensExportToFolderUi::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if (field == &m_exportFolder)
|
||||
if ( field == &m_exportFolder )
|
||||
{
|
||||
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>(attribute);
|
||||
if (myAttr)
|
||||
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>( attribute );
|
||||
if ( myAttr )
|
||||
{
|
||||
myAttr->m_selectDirectory = true;
|
||||
}
|
||||
|
||||
@@ -34,17 +34,17 @@ class RicHoloLensExportToFolderUi : public caf::PdmObject
|
||||
public:
|
||||
RicHoloLensExportToFolderUi();
|
||||
|
||||
void setViewForExport(RimGridView* view);
|
||||
void setViewForExport( RimGridView* view );
|
||||
|
||||
QString exportFolder() const;
|
||||
RimGridView* viewForExport() const;
|
||||
|
||||
private:
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly) override;
|
||||
void defineEditorAttribute(const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
private:
|
||||
caf::PdmPtrField<RimGridView*> m_viewForExport;
|
||||
|
||||
+12
-13
@@ -17,8 +17,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicHoloLensExportToSharingServerFeature.h"
|
||||
#include "RicHoloLensSessionManager.h"
|
||||
#include "RicHoloLensSession.h"
|
||||
#include "RicHoloLensSessionManager.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensExportToSharingServerFeature, "RicHoloLensExportToSharingServerFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensExportToSharingServerFeature, "RicHoloLensExportToSharingServerFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -35,7 +35,7 @@ CAF_CMD_SOURCE_INIT(RicHoloLensExportToSharingServerFeature, "RicHoloLensExportT
|
||||
bool RicHoloLensExportToSharingServerFeature::isCommandEnabled()
|
||||
{
|
||||
RicHoloLensSession* session = RicHoloLensSessionManager::instance()->session();
|
||||
if (session && session->isSessionValid())
|
||||
if ( session && session->isSessionValid() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -48,32 +48,31 @@ bool RicHoloLensExportToSharingServerFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToSharingServerFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensExportToSharingServerFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RicHoloLensSession* session = RicHoloLensSessionManager::instance()->session();
|
||||
if (!session || !session->isSessionValid())
|
||||
if ( !session || !session->isSessionValid() )
|
||||
{
|
||||
RiaLogging::error("No valid HoloLens session present");
|
||||
RiaLogging::error( "No valid HoloLens session present" );
|
||||
return;
|
||||
}
|
||||
|
||||
RimGridView* activeView = RiaApplication::instance()->activeGridView();
|
||||
if (!activeView)
|
||||
if ( !activeView )
|
||||
{
|
||||
RiaLogging::error("No active view");
|
||||
RiaLogging::error( "No active view" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
session->updateSessionDataFromView(*activeView);
|
||||
session->updateSessionDataFromView( *activeView );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensExportToSharingServerFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensExportToSharingServerFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/HoloLensSendOnce24x24.png"));
|
||||
actionToSetup->setIcon( QIcon( ":/HoloLensSendOnce24x24.png" ) );
|
||||
|
||||
actionToSetup->setText("Send to HoloLens Server Once");
|
||||
actionToSetup->setText( "Send to HoloLens Server Once" );
|
||||
}
|
||||
@@ -29,6 +29,6 @@ class RicHoloLensExportToSharingServerFeature : public caf::CmdFeature
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
@@ -18,27 +18,24 @@
|
||||
|
||||
#include "RicHoloLensRestClient.h"
|
||||
|
||||
|
||||
#include "cvfTrace.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSslConfiguration>
|
||||
#include <QDateTime>
|
||||
|
||||
// For getting time stamps for round-trip timing
|
||||
#if defined (__linux__)
|
||||
#include <sys/time.h>
|
||||
#if defined( __linux__ )
|
||||
#include <ctime>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Uncomment to enable experimental SSL support
|
||||
// The experimental support must be revised before shipping
|
||||
#define EXPERIMENTAL_SSL_SUPPORT
|
||||
#endif
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -48,11 +45,13 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensRestClient::RicHoloLensRestClient(QString serverUrl, QString sessionName, RicHoloLensRestResponseHandler* responseHandler)
|
||||
: m_serverUrl(serverUrl),
|
||||
m_sessionName(sessionName),
|
||||
m_responseHandler(responseHandler),
|
||||
m_dbgDisableCertificateVerification(false)
|
||||
RicHoloLensRestClient::RicHoloLensRestClient( QString serverUrl,
|
||||
QString sessionName,
|
||||
RicHoloLensRestResponseHandler* responseHandler )
|
||||
: m_serverUrl( serverUrl )
|
||||
, m_sessionName( sessionName )
|
||||
, m_responseHandler( responseHandler )
|
||||
, m_dbgDisableCertificateVerification( false )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -75,16 +74,15 @@ void RicHoloLensRestClient::dbgDisableCertificateVerification()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::createSession(const QByteArray& sessionPinCode)
|
||||
void RicHoloLensRestClient::createSession( const QByteArray& sessionPinCode )
|
||||
{
|
||||
const QString url = m_serverUrl + "/sessions/create/" + m_sessionName;
|
||||
cvf::Trace::show("createSession: POST on url: %s", url.toLatin1().constData());
|
||||
|
||||
QNetworkRequest request(url);
|
||||
//request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
|
||||
request.setRawHeader("PinCode", sessionPinCode);
|
||||
cvf::Trace::show( "createSession: POST on url: %s", url.toLatin1().constData() );
|
||||
|
||||
QNetworkRequest request( url );
|
||||
// request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/x-www-form-urlencoded" ) );
|
||||
request.setRawHeader( "PinCode", sessionPinCode );
|
||||
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
// NOTE !!!
|
||||
@@ -93,22 +91,22 @@ void RicHoloLensRestClient::createSession(const QByteArray& sessionPinCode)
|
||||
// This will have to be investigated further, SP 20180924
|
||||
QSslConfiguration sslConf = request.sslConfiguration();
|
||||
|
||||
// Needed this one to be able to connect to sharing server
|
||||
sslConf.setProtocol(QSsl::AnyProtocol);
|
||||
// Needed this one to be able to connect to sharing server
|
||||
sslConf.setProtocol( QSsl::AnyProtocol );
|
||||
|
||||
if (m_dbgDisableCertificateVerification)
|
||||
if ( m_dbgDisableCertificateVerification )
|
||||
{
|
||||
sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
sslConf.setPeerVerifyMode( QSslSocket::VerifyNone );
|
||||
}
|
||||
|
||||
request.setSslConfiguration(sslConf);
|
||||
request.setSslConfiguration( sslConf );
|
||||
#endif
|
||||
|
||||
QNetworkReply* reply = m_accessManager.post(request, QByteArray());
|
||||
connect(reply, SIGNAL(finished()), SLOT(slotCreateSessionFinished()));
|
||||
QNetworkReply* reply = m_accessManager.post( request, QByteArray() );
|
||||
connect( reply, SIGNAL( finished() ), SLOT( slotCreateSessionFinished() ) );
|
||||
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(slotSslErrors(const QList<QSslError>&)));
|
||||
connect( reply, SIGNAL( sslErrors( const QList<QSslError>& ) ), SLOT( slotSslErrors( const QList<QSslError>& ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -117,13 +115,13 @@ void RicHoloLensRestClient::createSession(const QByteArray& sessionPinCode)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotCreateSessionFinished()
|
||||
{
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>(sender());
|
||||
if (!reply)
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if ( !reply )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (detectAndHandleErrorReply("createSession", reply))
|
||||
if ( detectAndHandleErrorReply( "createSession", reply ) )
|
||||
{
|
||||
reply->deleteLater();
|
||||
|
||||
@@ -133,19 +131,20 @@ void RicHoloLensRestClient::slotCreateSessionFinished()
|
||||
}
|
||||
|
||||
const QByteArray serverData = reply->readAll();
|
||||
//cvf::Trace::show(" serverResponse: %s", serverData.constData());
|
||||
// cvf::Trace::show(" serverResponse: %s", serverData.constData());
|
||||
|
||||
// Currently we get the bearer token back in the response wholesale
|
||||
// The format we get is typically: "Bearer <the token>"
|
||||
// For example: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
|
||||
// Presumably the format of the response will change, but for now just strip away the starting "Bearer " string and consider the rest as the actual token
|
||||
// Presumably the format of the response will change, but for now just strip away the starting "Bearer " string and
|
||||
// consider the rest as the actual token
|
||||
m_bearerToken = serverData;
|
||||
m_bearerToken.replace("Bearer ", "");
|
||||
m_bearerToken.replace( "Bearer ", "" );
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
cvf::Trace::show("createSession OK");
|
||||
if (m_responseHandler)
|
||||
cvf::Trace::show( "createSession OK" );
|
||||
if ( m_responseHandler )
|
||||
{
|
||||
m_responseHandler->handleSuccessfulCreateSession();
|
||||
}
|
||||
@@ -157,18 +156,18 @@ void RicHoloLensRestClient::slotCreateSessionFinished()
|
||||
void RicHoloLensRestClient::deleteSession()
|
||||
{
|
||||
const QString url = m_serverUrl + "/sessions/delete/" + m_sessionName;
|
||||
cvf::Trace::show("deleteSession: DELETE on url: %s", url.toLatin1().constData());
|
||||
cvf::Trace::show( "deleteSession: DELETE on url: %s", url.toLatin1().constData() );
|
||||
|
||||
QNetworkRequest request(url);
|
||||
//request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
|
||||
addBearerAuthenticationHeaderToRequest(&request);
|
||||
QNetworkRequest request( url );
|
||||
// request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/x-www-form-urlencoded" ) );
|
||||
addBearerAuthenticationHeaderToRequest( &request );
|
||||
|
||||
QNetworkReply* reply = m_accessManager.deleteResource(request);
|
||||
connect(reply, SIGNAL(finished()), SLOT(slotDeleteSessionFinished()));
|
||||
QNetworkReply* reply = m_accessManager.deleteResource( request );
|
||||
connect( reply, SIGNAL( finished() ), SLOT( slotDeleteSessionFinished() ) );
|
||||
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(slotSslErrors(const QList<QSslError>&)));
|
||||
connect( reply, SIGNAL( sslErrors( const QList<QSslError>& ) ), SLOT( slotSslErrors( const QList<QSslError>& ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -177,13 +176,13 @@ void RicHoloLensRestClient::deleteSession()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotDeleteSessionFinished()
|
||||
{
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>(sender());
|
||||
if (!reply)
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if ( !reply )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (detectAndHandleErrorReply("deleteSession", reply))
|
||||
if ( detectAndHandleErrorReply( "deleteSession", reply ) )
|
||||
{
|
||||
reply->deleteLater();
|
||||
return;
|
||||
@@ -191,33 +190,35 @@ void RicHoloLensRestClient::slotDeleteSessionFinished()
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
cvf::Trace::show("deleteSession OK");
|
||||
cvf::Trace::show( "deleteSession OK" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::sendMetaData(int metaDataSequenceNumber, const QString& jsonMetaDataString)
|
||||
void RicHoloLensRestClient::sendMetaData( int metaDataSequenceNumber, const QString& jsonMetaDataString )
|
||||
{
|
||||
const QString url = m_serverUrl + "/sessions/" + m_sessionName + "/metadata";
|
||||
cvf::Trace::show("sendMetaData (metaDataSequenceNumber=%d): POST on url: %s", metaDataSequenceNumber, url.toLatin1().constData());
|
||||
cvf::Trace::show( "sendMetaData (metaDataSequenceNumber=%d): POST on url: %s",
|
||||
metaDataSequenceNumber,
|
||||
url.toLatin1().constData() );
|
||||
|
||||
const qint64 sendStartTimeStamp_ms = getCurrentTimeStamp_ms();
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
|
||||
addBearerAuthenticationHeaderToRequest(&request);
|
||||
QNetworkRequest request( url );
|
||||
request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/json" ) );
|
||||
addBearerAuthenticationHeaderToRequest( &request );
|
||||
|
||||
const QByteArray jsonByteArr = jsonMetaDataString.toLatin1();
|
||||
|
||||
QNetworkReply* reply = m_accessManager.post(request, jsonByteArr);
|
||||
reply->setProperty("holo_metaDataSequenceNumber", QVariant(metaDataSequenceNumber));
|
||||
reply->setProperty("holo_sendStartTimeStamp_ms", QVariant(sendStartTimeStamp_ms));
|
||||
QNetworkReply* reply = m_accessManager.post( request, jsonByteArr );
|
||||
reply->setProperty( "holo_metaDataSequenceNumber", QVariant( metaDataSequenceNumber ) );
|
||||
reply->setProperty( "holo_sendStartTimeStamp_ms", QVariant( sendStartTimeStamp_ms ) );
|
||||
|
||||
connect(reply, SIGNAL(finished()), SLOT(slotSendMetaDataFinished()));
|
||||
connect( reply, SIGNAL( finished() ), SLOT( slotSendMetaDataFinished() ) );
|
||||
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(slotSslErrors(const QList<QSslError>&)));
|
||||
connect( reply, SIGNAL( sslErrors( const QList<QSslError>& ) ), SLOT( slotSslErrors( const QList<QSslError>& ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -226,13 +227,13 @@ void RicHoloLensRestClient::sendMetaData(int metaDataSequenceNumber, const QStri
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotSendMetaDataFinished()
|
||||
{
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>(sender());
|
||||
if (!reply)
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if ( !reply )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (detectAndHandleErrorReply("sendMetaData", reply))
|
||||
if ( detectAndHandleErrorReply( "sendMetaData", reply ) )
|
||||
{
|
||||
reply->deleteLater();
|
||||
return;
|
||||
@@ -240,8 +241,8 @@ void RicHoloLensRestClient::slotSendMetaDataFinished()
|
||||
|
||||
int metaDataSequenceNumber = -1;
|
||||
{
|
||||
QVariant var = reply->property("holo_metaDataSequenceNumber");
|
||||
if (var.type() == QVariant::Int)
|
||||
QVariant var = reply->property( "holo_metaDataSequenceNumber" );
|
||||
if ( var.type() == QVariant::Int )
|
||||
{
|
||||
metaDataSequenceNumber = var.toInt();
|
||||
}
|
||||
@@ -249,51 +250,53 @@ void RicHoloLensRestClient::slotSendMetaDataFinished()
|
||||
|
||||
double elapsedTime_s = -1;
|
||||
{
|
||||
QVariant var = reply->property("holo_sendStartTimeStamp_ms");
|
||||
if (var.type() == QVariant::LongLong)
|
||||
QVariant var = reply->property( "holo_sendStartTimeStamp_ms" );
|
||||
if ( var.type() == QVariant::LongLong )
|
||||
{
|
||||
const qint64 startTimeStamp_ms = var.toLongLong();
|
||||
elapsedTime_s = (getCurrentTimeStamp_ms() - startTimeStamp_ms)/1000.0;
|
||||
elapsedTime_s = ( getCurrentTimeStamp_ms() - startTimeStamp_ms ) / 1000.0;
|
||||
}
|
||||
}
|
||||
|
||||
const QByteArray serverData = reply->readAll();
|
||||
//cvf::Trace::show(" serverResponse: %s", serverData.constData());
|
||||
// cvf::Trace::show(" serverResponse: %s", serverData.constData());
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
cvf::Trace::show("sendMetaData (metaDataSequenceNumber=%d) OK, elapsedTime=%.2fs", metaDataSequenceNumber, elapsedTime_s);
|
||||
if (m_responseHandler)
|
||||
cvf::Trace::show( "sendMetaData (metaDataSequenceNumber=%d) OK, elapsedTime=%.2fs",
|
||||
metaDataSequenceNumber,
|
||||
elapsedTime_s );
|
||||
if ( m_responseHandler )
|
||||
{
|
||||
m_responseHandler->handleSuccessfulSendMetaData(metaDataSequenceNumber, serverData);
|
||||
m_responseHandler->handleSuccessfulSendMetaData( metaDataSequenceNumber, serverData );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::sendBinaryData(const QByteArray& binaryDataArr, QByteArray dbgTagString)
|
||||
void RicHoloLensRestClient::sendBinaryData( const QByteArray& binaryDataArr, QByteArray dbgTagString )
|
||||
{
|
||||
const QString url = m_serverUrl + "/sessions/" + m_sessionName + "/data";
|
||||
cvf::Trace::show("sendBinaryData(%s): POST on url: %s", dbgTagString.constData(), url.toLatin1().constData());
|
||||
cvf::Trace::show( "sendBinaryData(%s): POST on url: %s", dbgTagString.constData(), url.toLatin1().constData() );
|
||||
|
||||
const qint64 sendStartTimeStamp_ms = getCurrentTimeStamp_ms();
|
||||
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||
addBearerAuthenticationHeaderToRequest(&request);
|
||||
QNetworkRequest request( url );
|
||||
request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant( "application/octet-stream" ) );
|
||||
addBearerAuthenticationHeaderToRequest( &request );
|
||||
|
||||
QNetworkReply* reply = m_accessManager.post(request, binaryDataArr);
|
||||
reply->setProperty("holo_sendStartTimeStamp_ms", QVariant(sendStartTimeStamp_ms));
|
||||
reply->setProperty("holo_dbgTagString", QVariant(dbgTagString));
|
||||
QNetworkReply* reply = m_accessManager.post( request, binaryDataArr );
|
||||
reply->setProperty( "holo_sendStartTimeStamp_ms", QVariant( sendStartTimeStamp_ms ) );
|
||||
reply->setProperty( "holo_dbgTagString", QVariant( dbgTagString ) );
|
||||
|
||||
connect(reply, SIGNAL(finished()), SLOT(slotSendBinaryDataFinished()));
|
||||
connect( reply, SIGNAL( finished() ), SLOT( slotSendBinaryDataFinished() ) );
|
||||
|
||||
// Debugging!
|
||||
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(slotDbgUploadProgress(qint64, qint64)));
|
||||
connect( reply, SIGNAL( uploadProgress( qint64, qint64 ) ), SLOT( slotDbgUploadProgress( qint64, qint64 ) ) );
|
||||
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(slotSslErrors(const QList<QSslError>&)));
|
||||
connect( reply, SIGNAL( sslErrors( const QList<QSslError>& ) ), SLOT( slotSslErrors( const QList<QSslError>& ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -302,13 +305,13 @@ void RicHoloLensRestClient::sendBinaryData(const QByteArray& binaryDataArr, QByt
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotSendBinaryDataFinished()
|
||||
{
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>(sender());
|
||||
if (!reply)
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if ( !reply )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (detectAndHandleErrorReply("sendBinaryData", reply))
|
||||
if ( detectAndHandleErrorReply( "sendBinaryData", reply ) )
|
||||
{
|
||||
reply->deleteLater();
|
||||
return;
|
||||
@@ -316,18 +319,18 @@ void RicHoloLensRestClient::slotSendBinaryDataFinished()
|
||||
|
||||
double elapsedTime_s = -1;
|
||||
{
|
||||
QVariant var = reply->property("holo_sendStartTimeStamp_ms");
|
||||
if (var.type() == QVariant::LongLong)
|
||||
QVariant var = reply->property( "holo_sendStartTimeStamp_ms" );
|
||||
if ( var.type() == QVariant::LongLong )
|
||||
{
|
||||
const qint64 startTimeStamp_ms = var.toLongLong();
|
||||
elapsedTime_s = (getCurrentTimeStamp_ms() - startTimeStamp_ms)/1000.0;
|
||||
elapsedTime_s = ( getCurrentTimeStamp_ms() - startTimeStamp_ms ) / 1000.0;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray dbgTagString;
|
||||
{
|
||||
QVariant var = reply->property("holo_dbgTagString");
|
||||
if (var.type() == QVariant::ByteArray)
|
||||
QVariant var = reply->property( "holo_dbgTagString" );
|
||||
if ( var.type() == QVariant::ByteArray )
|
||||
{
|
||||
dbgTagString = var.toByteArray();
|
||||
}
|
||||
@@ -335,46 +338,51 @@ void RicHoloLensRestClient::slotSendBinaryDataFinished()
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
cvf::Trace::show("sendBinaryData(%s) OK, elapsedTime=%.2fs", dbgTagString.constData(), elapsedTime_s);
|
||||
cvf::Trace::show( "sendBinaryData(%s) OK, elapsedTime=%.2fs", dbgTagString.constData(), elapsedTime_s );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotDbgUploadProgress(qint64 bytesSent, qint64 bytesTotal)
|
||||
void RicHoloLensRestClient::slotDbgUploadProgress( qint64 bytesSent, qint64 bytesTotal )
|
||||
{
|
||||
static int sl_lastPct = -1;
|
||||
int pct = 0;
|
||||
if (bytesTotal > 0)
|
||||
int pct = 0;
|
||||
if ( bytesTotal > 0 )
|
||||
{
|
||||
pct = static_cast<int>(100*(bytesSent/static_cast<double>(bytesTotal)));
|
||||
pct = static_cast<int>( 100 * ( bytesSent / static_cast<double>( bytesTotal ) ) );
|
||||
}
|
||||
|
||||
if (pct % 10 == 0 && pct != sl_lastPct)
|
||||
if ( pct % 10 == 0 && pct != sl_lastPct )
|
||||
{
|
||||
double elapsedTime_s = -1;
|
||||
QByteArray dbgTagString;
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>(sender());
|
||||
if (reply)
|
||||
double elapsedTime_s = -1;
|
||||
QByteArray dbgTagString;
|
||||
QNetworkReply* reply = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if ( reply )
|
||||
{
|
||||
{
|
||||
QVariant var = reply->property("holo_sendStartTimeStamp_ms");
|
||||
if (var.type() == QVariant::LongLong)
|
||||
QVariant var = reply->property( "holo_sendStartTimeStamp_ms" );
|
||||
if ( var.type() == QVariant::LongLong )
|
||||
{
|
||||
const qint64 startTimeStamp_ms = var.toLongLong();
|
||||
elapsedTime_s = (getCurrentTimeStamp_ms() - startTimeStamp_ms)/1000.0;
|
||||
elapsedTime_s = ( getCurrentTimeStamp_ms() - startTimeStamp_ms ) / 1000.0;
|
||||
}
|
||||
}
|
||||
{
|
||||
QVariant var = reply->property("holo_dbgTagString");
|
||||
if (var.type() == QVariant::ByteArray)
|
||||
QVariant var = reply->property( "holo_dbgTagString" );
|
||||
if ( var.type() == QVariant::ByteArray )
|
||||
{
|
||||
dbgTagString = var.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cvf::Trace::show("Progress sendBinaryData(%s): %3d%%, %.2f/%.2fMB (elapsedTime=%.2fs)", dbgTagString.constData(), pct, bytesSent/(1024.0*1024.0), bytesTotal/(1024.0*1024.0), elapsedTime_s);
|
||||
cvf::Trace::show( "Progress sendBinaryData(%s): %3d%%, %.2f/%.2fMB (elapsedTime=%.2fs)",
|
||||
dbgTagString.constData(),
|
||||
pct,
|
||||
bytesSent / ( 1024.0 * 1024.0 ),
|
||||
bytesTotal / ( 1024.0 * 1024.0 ),
|
||||
elapsedTime_s );
|
||||
sl_lastPct = pct;
|
||||
}
|
||||
}
|
||||
@@ -382,13 +390,13 @@ void RicHoloLensRestClient::slotDbgUploadProgress(qint64 bytesSent, qint64 bytes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::slotSslErrors(const QList<QSslError>& errors)
|
||||
void RicHoloLensRestClient::slotSslErrors( const QList<QSslError>& errors )
|
||||
{
|
||||
#ifdef EXPERIMENTAL_SSL_SUPPORT
|
||||
cvf::Trace::show("RicHoloLensRestClient::slotSslErrors()");
|
||||
for (int i = 0; i < errors.size(); i++)
|
||||
cvf::Trace::show( "RicHoloLensRestClient::slotSslErrors()" );
|
||||
for ( int i = 0; i < errors.size(); i++ )
|
||||
{
|
||||
cvf::Trace::show(" %s", errors[i].errorString().toLatin1().constData());
|
||||
cvf::Trace::show( " %s", errors[i].errorString().toLatin1().constData() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -396,53 +404,57 @@ void RicHoloLensRestClient::slotSslErrors(const QList<QSslError>& errors)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensRestClient::addBearerAuthenticationHeaderToRequest(QNetworkRequest* request) const
|
||||
void RicHoloLensRestClient::addBearerAuthenticationHeaderToRequest( QNetworkRequest* request ) const
|
||||
{
|
||||
CVF_ASSERT(request);
|
||||
CVF_ASSERT( request );
|
||||
|
||||
request->setRawHeader("Authorization", "Bearer " + m_bearerToken);
|
||||
request->setRawHeader( "Authorization", "Bearer " + m_bearerToken );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensRestClient::detectAndHandleErrorReply(QString operationName, QNetworkReply* reply)
|
||||
bool RicHoloLensRestClient::detectAndHandleErrorReply( QString operationName, QNetworkReply* reply )
|
||||
{
|
||||
CVF_ASSERT(reply);
|
||||
CVF_ASSERT( reply );
|
||||
|
||||
const QNetworkReply::NetworkError nwErrCode = reply->error();
|
||||
const int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (nwErrCode == QNetworkReply::NoError && httpStatusCode == 200)
|
||||
const int httpStatusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
||||
if ( nwErrCode == QNetworkReply::NoError && httpStatusCode == 200 )
|
||||
{
|
||||
// No error detected
|
||||
return false;
|
||||
}
|
||||
|
||||
QString mainErrMsg = operationName + " FAILED";
|
||||
if (nwErrCode != QNetworkReply::NoError)
|
||||
if ( nwErrCode != QNetworkReply::NoError )
|
||||
{
|
||||
const QString nwErrCodeAsString = networkErrorCodeAsString(nwErrCode);
|
||||
const QString errText = reply->errorString();
|
||||
mainErrMsg += QString(" [nwErr='%1'(%2) httpStatus=%3]: %4").arg(nwErrCodeAsString).arg(nwErrCode).arg(httpStatusCode).arg(errText);
|
||||
const QString nwErrCodeAsString = networkErrorCodeAsString( nwErrCode );
|
||||
const QString errText = reply->errorString();
|
||||
mainErrMsg += QString( " [nwErr='%1'(%2) httpStatus=%3]: %4" )
|
||||
.arg( nwErrCodeAsString )
|
||||
.arg( nwErrCode )
|
||||
.arg( httpStatusCode )
|
||||
.arg( errText );
|
||||
}
|
||||
else
|
||||
{
|
||||
mainErrMsg += QString(" [httpStatus=%1]").arg(httpStatusCode);
|
||||
mainErrMsg += QString( " [httpStatus=%1]" ).arg( httpStatusCode );
|
||||
}
|
||||
|
||||
cvf::Trace::show(mainErrMsg.toLatin1().constData());
|
||||
cvf::Trace::show( mainErrMsg.toLatin1().constData() );
|
||||
|
||||
reply->errorString();
|
||||
|
||||
const QString url = reply->url().toString();
|
||||
cvf::Trace::show(" url: %s", url.toLatin1().constData());
|
||||
cvf::Trace::show( " url: %s", url.toLatin1().constData() );
|
||||
|
||||
const QByteArray serverData = reply->readAll();
|
||||
cvf::Trace::show(" serverResponse: %s", serverData.constData());
|
||||
cvf::Trace::show( " serverResponse: %s", serverData.constData() );
|
||||
|
||||
if (m_responseHandler)
|
||||
if ( m_responseHandler )
|
||||
{
|
||||
m_responseHandler->handleError(mainErrMsg, url, serverData);
|
||||
m_responseHandler->handleError( mainErrMsg, url, serverData );
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -451,38 +463,61 @@ bool RicHoloLensRestClient::detectAndHandleErrorReply(QString operationName, QNe
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensRestClient::networkErrorCodeAsString(QNetworkReply::NetworkError nwErr)
|
||||
QString RicHoloLensRestClient::networkErrorCodeAsString( QNetworkReply::NetworkError nwErr )
|
||||
{
|
||||
switch (nwErr)
|
||||
switch ( nwErr )
|
||||
{
|
||||
case QNetworkReply::NoError: return "NoError";
|
||||
case QNetworkReply::NoError:
|
||||
return "NoError";
|
||||
|
||||
case QNetworkReply::ConnectionRefusedError: return "ConnectionRefusedError";
|
||||
case QNetworkReply::RemoteHostClosedError: return "RemoteHostClosedError";
|
||||
case QNetworkReply::HostNotFoundError: return "HostNotFoundError";
|
||||
case QNetworkReply::TimeoutError: return "TimeoutError";
|
||||
case QNetworkReply::OperationCanceledError: return "OperationCanceledError";
|
||||
case QNetworkReply::SslHandshakeFailedError: return "SslHandshakeFailedError";
|
||||
//case QNetworkReply::TemporaryNetworkFailureError: return "TemporaryNetworkFailureError";
|
||||
case QNetworkReply::UnknownNetworkError: return "UnknownNetworkError";
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
return "ConnectionRefusedError";
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
return "RemoteHostClosedError";
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
return "HostNotFoundError";
|
||||
case QNetworkReply::TimeoutError:
|
||||
return "TimeoutError";
|
||||
case QNetworkReply::OperationCanceledError:
|
||||
return "OperationCanceledError";
|
||||
case QNetworkReply::SslHandshakeFailedError:
|
||||
return "SslHandshakeFailedError";
|
||||
// case QNetworkReply::TemporaryNetworkFailureError: return "TemporaryNetworkFailureError";
|
||||
case QNetworkReply::UnknownNetworkError:
|
||||
return "UnknownNetworkError";
|
||||
|
||||
case QNetworkReply::ProxyConnectionRefusedError: return "ProxyConnectionRefusedError";
|
||||
case QNetworkReply::ProxyConnectionClosedError: return "ProxyConnectionClosedError";
|
||||
case QNetworkReply::ProxyNotFoundError: return "ProxyNotFoundError";
|
||||
case QNetworkReply::ProxyTimeoutError: return "ProxyTimeoutError";
|
||||
case QNetworkReply::ProxyAuthenticationRequiredError: return "ProxyAuthenticationRequiredError";
|
||||
case QNetworkReply::UnknownProxyError: return "UnknownProxyError";
|
||||
case QNetworkReply::ProxyConnectionRefusedError:
|
||||
return "ProxyConnectionRefusedError";
|
||||
case QNetworkReply::ProxyConnectionClosedError:
|
||||
return "ProxyConnectionClosedError";
|
||||
case QNetworkReply::ProxyNotFoundError:
|
||||
return "ProxyNotFoundError";
|
||||
case QNetworkReply::ProxyTimeoutError:
|
||||
return "ProxyTimeoutError";
|
||||
case QNetworkReply::ProxyAuthenticationRequiredError:
|
||||
return "ProxyAuthenticationRequiredError";
|
||||
case QNetworkReply::UnknownProxyError:
|
||||
return "UnknownProxyError";
|
||||
|
||||
case QNetworkReply::ContentAccessDenied: return "ContentAccessDenied";
|
||||
case QNetworkReply::ContentOperationNotPermittedError: return "ContentOperationNotPermittedError";
|
||||
case QNetworkReply::ContentNotFoundError: return "ContentNotFoundError";
|
||||
case QNetworkReply::AuthenticationRequiredError: return "AuthenticationRequiredError";
|
||||
case QNetworkReply::ContentReSendError: return "ContentReSendError";
|
||||
case QNetworkReply::UnknownContentError: return "UnknownContentError";
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
return "ContentAccessDenied";
|
||||
case QNetworkReply::ContentOperationNotPermittedError:
|
||||
return "ContentOperationNotPermittedError";
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
return "ContentNotFoundError";
|
||||
case QNetworkReply::AuthenticationRequiredError:
|
||||
return "AuthenticationRequiredError";
|
||||
case QNetworkReply::ContentReSendError:
|
||||
return "ContentReSendError";
|
||||
case QNetworkReply::UnknownContentError:
|
||||
return "UnknownContentError";
|
||||
|
||||
case QNetworkReply::ProtocolUnknownError: return "ProtocolUnknownError";
|
||||
case QNetworkReply::ProtocolInvalidOperationError: return "ProtocolInvalidOperationError";
|
||||
case QNetworkReply::ProtocolFailure: return "ProtocolFailure";
|
||||
case QNetworkReply::ProtocolUnknownError:
|
||||
return "ProtocolUnknownError";
|
||||
case QNetworkReply::ProtocolInvalidOperationError:
|
||||
return "ProtocolInvalidOperationError";
|
||||
case QNetworkReply::ProtocolFailure:
|
||||
return "ProtocolFailure";
|
||||
};
|
||||
|
||||
return "UnknownErrorCode";
|
||||
@@ -496,15 +531,13 @@ qint64 RicHoloLensRestClient::getCurrentTimeStamp_ms()
|
||||
#if QT_VERSION >= 0x040700
|
||||
const qint64 timeStamp_ms = QDateTime::currentMSecsSinceEpoch();
|
||||
return timeStamp_ms;
|
||||
#elif defined(__linux__)
|
||||
#elif defined( __linux__ )
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
||||
if ( clock_gettime( CLOCK_MONOTONIC, &ts ) == 0 )
|
||||
{
|
||||
return static_cast<qint64>(ts.tv_sec*1000 + ts.tv_nsec/1000000);
|
||||
return static_cast<qint64>( ts.tv_sec * 1000 + ts.tv_nsec / 1000000 );
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
|
||||
|
||||
#include <QObject>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -34,14 +31,14 @@ class RicHoloLensRestResponseHandler
|
||||
{
|
||||
public:
|
||||
virtual void handleSuccessfulCreateSession() = 0;
|
||||
virtual void handleFailedCreateSession() = 0;
|
||||
virtual void handleFailedCreateSession() = 0;
|
||||
|
||||
virtual void handleSuccessfulSendMetaData(int metaDataSequenceNumber, const QByteArray& jsonServerResponseString) = 0;
|
||||
virtual void handleSuccessfulSendMetaData( int metaDataSequenceNumber,
|
||||
const QByteArray& jsonServerResponseString ) = 0;
|
||||
|
||||
virtual void handleError(const QString& errMsg, const QString& url, const QString& serverData) = 0;
|
||||
virtual void handleError( const QString& errMsg, const QString& url, const QString& serverData ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -52,39 +49,40 @@ class RicHoloLensRestClient : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RicHoloLensRestClient(QString serverUrl, QString sessionName, RicHoloLensRestResponseHandler* responseHandler);
|
||||
RicHoloLensRestClient( QString serverUrl, QString sessionName, RicHoloLensRestResponseHandler* responseHandler );
|
||||
|
||||
void clearResponseHandler();
|
||||
void clearResponseHandler();
|
||||
|
||||
void dbgDisableCertificateVerification();
|
||||
void dbgDisableCertificateVerification();
|
||||
|
||||
void createSession(const QByteArray& sessionPinCode);
|
||||
void deleteSession();
|
||||
void sendMetaData(int metaDataSequenceNumber, const QString& jsonMetaDataString);
|
||||
void sendBinaryData(const QByteArray& binaryDataArr, QByteArray dbgTagString);
|
||||
void createSession( const QByteArray& sessionPinCode );
|
||||
void deleteSession();
|
||||
void sendMetaData( int metaDataSequenceNumber, const QString& jsonMetaDataString );
|
||||
void sendBinaryData( const QByteArray& binaryDataArr, QByteArray dbgTagString );
|
||||
|
||||
private:
|
||||
void addBearerAuthenticationHeaderToRequest(QNetworkRequest* request) const;
|
||||
bool detectAndHandleErrorReply(QString operationName, QNetworkReply* reply);
|
||||
static QString networkErrorCodeAsString(QNetworkReply::NetworkError nwErr);
|
||||
static qint64 getCurrentTimeStamp_ms();
|
||||
void addBearerAuthenticationHeaderToRequest( QNetworkRequest* request ) const;
|
||||
bool detectAndHandleErrorReply( QString operationName, QNetworkReply* reply );
|
||||
static QString networkErrorCodeAsString( QNetworkReply::NetworkError nwErr );
|
||||
static qint64 getCurrentTimeStamp_ms();
|
||||
|
||||
private slots:
|
||||
void slotCreateSessionFinished();
|
||||
void slotDeleteSessionFinished();
|
||||
void slotSendMetaDataFinished();
|
||||
void slotSendBinaryDataFinished();
|
||||
void slotDbgUploadProgress(qint64 bytesSent, qint64 bytesTotal);
|
||||
void slotCreateSessionFinished();
|
||||
void slotDeleteSessionFinished();
|
||||
void slotSendMetaDataFinished();
|
||||
void slotSendBinaryDataFinished();
|
||||
void slotDbgUploadProgress( qint64 bytesSent, qint64 bytesTotal );
|
||||
|
||||
void slotSslErrors(const QList<QSslError>& errors);
|
||||
void slotSslErrors( const QList<QSslError>& errors );
|
||||
|
||||
private:
|
||||
QNetworkAccessManager m_accessManager;
|
||||
QString m_serverUrl;
|
||||
QString m_sessionName;
|
||||
RicHoloLensRestResponseHandler* m_responseHandler;
|
||||
QNetworkAccessManager m_accessManager;
|
||||
QString m_serverUrl;
|
||||
QString m_sessionName;
|
||||
RicHoloLensRestResponseHandler* m_responseHandler;
|
||||
|
||||
bool m_dbgDisableCertificateVerification; // Debug option to disable certificate verification. Needed in order to work with self-signed certifiactes
|
||||
bool m_dbgDisableCertificateVerification; // Debug option to disable certificate verification. Needed in order to
|
||||
// work with self-signed certifiactes
|
||||
|
||||
QByteArray m_bearerToken;
|
||||
QByteArray m_bearerToken;
|
||||
};
|
||||
@@ -18,24 +18,22 @@
|
||||
|
||||
#include "RicHoloLensServerSettings.h"
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicHoloLensServerSettings, "RicHoloLensServerSettings");
|
||||
CAF_PDM_SOURCE_INIT( RicHoloLensServerSettings, "RicHoloLensServerSettings" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensServerSettings::RicHoloLensServerSettings()
|
||||
{
|
||||
CAF_PDM_InitObject("HoloLens Server Settings", "", "", "");
|
||||
CAF_PDM_InitObject( "HoloLens Server Settings", "", "", "" );
|
||||
|
||||
CAF_PDM_InitField(&m_serverAddress, "ServerAddress", QString(), "Server Address", "", "", "");
|
||||
CAF_PDM_InitField( &m_serverAddress, "ServerAddress", QString(), "Server Address", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicHoloLensServerSettings::serverUrl() const
|
||||
{
|
||||
return m_serverAddress;
|
||||
}
|
||||
|
||||
@@ -36,5 +36,5 @@ public:
|
||||
QString serverUrl() const;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_serverAddress;
|
||||
caf::PdmField<QString> m_serverAddress;
|
||||
};
|
||||
@@ -22,10 +22,10 @@
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "VdeVizDataExtractor.h"
|
||||
#include "VdeArrayDataPacket.h"
|
||||
#include "VdeFileExporter.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
#include "VdeArrayDataPacket.h"
|
||||
#include "VdeVizDataExtractor.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
#include "cvfTimer.h"
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -45,9 +44,9 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensSession::RicHoloLensSession()
|
||||
: m_isSessionValid(false),
|
||||
m_lastExtractionMetaDataSequenceNumber(-1),
|
||||
m_sessionObserver(nullptr)
|
||||
: m_isSessionValid( false )
|
||||
, m_lastExtractionMetaDataSequenceNumber( -1 )
|
||||
, m_sessionObserver( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,27 +61,30 @@ RicHoloLensSession::~RicHoloLensSession()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensSession* RicHoloLensSession::createSession(const QString& serverUrl, const QString& sessionName, const QByteArray& sessionPinCode, RicHoloLensSessionObserver* sessionObserver)
|
||||
RicHoloLensSession* RicHoloLensSession::createSession( const QString& serverUrl,
|
||||
const QString& sessionName,
|
||||
const QByteArray& sessionPinCode,
|
||||
RicHoloLensSessionObserver* sessionObserver )
|
||||
{
|
||||
RicHoloLensSession* newSession = new RicHoloLensSession;
|
||||
|
||||
newSession->m_restClient = new RicHoloLensRestClient(serverUrl, sessionName, newSession);
|
||||
|
||||
if (RiaApplication::instance()->preferences()->holoLensDisableCertificateVerification())
|
||||
newSession->m_restClient = new RicHoloLensRestClient( serverUrl, sessionName, newSession );
|
||||
|
||||
if ( RiaApplication::instance()->preferences()->holoLensDisableCertificateVerification() )
|
||||
{
|
||||
RiaLogging::warning("HoloLens: Disabling certificate verification for HTTPS connections");
|
||||
RiaLogging::warning( "HoloLens: Disabling certificate verification for HTTPS connections" );
|
||||
newSession->m_restClient->dbgDisableCertificateVerification();
|
||||
}
|
||||
|
||||
newSession->m_restClient->createSession(sessionPinCode);
|
||||
|
||||
newSession->m_restClient->createSession( sessionPinCode );
|
||||
|
||||
newSession->m_sessionObserver = sessionObserver;
|
||||
|
||||
const QString dbgExportFolder = RiaApplication::instance()->preferences()->holoLensExportFolder();
|
||||
if (!dbgExportFolder.isEmpty())
|
||||
if ( !dbgExportFolder.isEmpty() )
|
||||
{
|
||||
newSession->m_dbgFileExportDestinationFolder = dbgExportFolder;
|
||||
RiaLogging::info(QString("HoloLens: Debug file export will be written to folder: %1").arg(dbgExportFolder));
|
||||
RiaLogging::info( QString( "HoloLens: Debug file export will be written to folder: %1" ).arg( dbgExportFolder ) );
|
||||
}
|
||||
|
||||
return newSession;
|
||||
@@ -107,9 +109,9 @@ RicHoloLensSession* RicHoloLensSession::createDummyFileBackedSession()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::destroySession()
|
||||
{
|
||||
if (m_restClient)
|
||||
if ( m_restClient )
|
||||
{
|
||||
if (m_isSessionValid)
|
||||
if ( m_isSessionValid )
|
||||
{
|
||||
m_restClient->deleteSession();
|
||||
}
|
||||
@@ -137,165 +139,177 @@ bool RicHoloLensSession::isSessionValid() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::updateSessionDataFromView(const RimGridView& activeView)
|
||||
void RicHoloLensSession::updateSessionDataFromView( const RimGridView& activeView )
|
||||
{
|
||||
RiaLogging::info("HoloLens: Updating visualization data");
|
||||
RiaLogging::info( "HoloLens: Updating visualization data" );
|
||||
|
||||
// Grab the current max ID as an easy way to detect if new IDs have been added for debugging purposes
|
||||
const int dbgMaxAssignedIdBeforeExtraction = m_cachingIdFactory.lastAssignedId();
|
||||
|
||||
// Note that we pass the caching ID factory on the constructor which will try and detect data payloads that
|
||||
// are equal, and will then "recycle" the array IDs for these
|
||||
VdeVizDataExtractor extractor(activeView, &m_cachingIdFactory);
|
||||
VdeVizDataExtractor extractor( activeView, &m_cachingIdFactory );
|
||||
|
||||
QString modelMetaJsonStr;
|
||||
QString modelMetaJsonStr;
|
||||
std::vector<int> allReferencedPacketIds;
|
||||
extractor.extractViewContents(&modelMetaJsonStr, &allReferencedPacketIds, &m_packetDirectory);
|
||||
extractor.extractViewContents( &modelMetaJsonStr, &allReferencedPacketIds, &m_packetDirectory );
|
||||
|
||||
// Note!
|
||||
// The packet directory should now contain all the packets that are being actively referenced.
|
||||
// We now prune out any packets that are no longer being referenced. This means we do no caching of actual packet
|
||||
// We now prune out any packets that are no longer being referenced. This means we do no caching of actual packet
|
||||
// data over time and that we assume that the server will ask for data packets/arrays right after having received updated meta data
|
||||
m_packetDirectory.pruneUnreferencedPackets(allReferencedPacketIds);
|
||||
m_packetDirectory.pruneUnreferencedPackets( allReferencedPacketIds );
|
||||
|
||||
m_lastExtractionMetaDataSequenceNumber++;
|
||||
m_lastExtractionAllReferencedPacketIdsArr = allReferencedPacketIds;
|
||||
|
||||
|
||||
if (m_restClient)
|
||||
if ( m_restClient )
|
||||
{
|
||||
RiaLogging::info(QString("HoloLens: Sending updated meta data to sharing server (sequenceNumber=%1)").arg(m_lastExtractionMetaDataSequenceNumber));
|
||||
m_restClient->sendMetaData(m_lastExtractionMetaDataSequenceNumber, modelMetaJsonStr);
|
||||
RiaLogging::info( QString( "HoloLens: Sending updated meta data to sharing server (sequenceNumber=%1)" )
|
||||
.arg( m_lastExtractionMetaDataSequenceNumber ) );
|
||||
m_restClient->sendMetaData( m_lastExtractionMetaDataSequenceNumber, modelMetaJsonStr );
|
||||
}
|
||||
|
||||
|
||||
// Debug export to file
|
||||
if (!m_dbgFileExportDestinationFolder.isEmpty())
|
||||
if ( !m_dbgFileExportDestinationFolder.isEmpty() )
|
||||
{
|
||||
const QDir outputDir(m_dbgFileExportDestinationFolder);
|
||||
const QDir outputDir( m_dbgFileExportDestinationFolder );
|
||||
const QString absOutputFolder = outputDir.absolutePath();
|
||||
|
||||
if (!outputDir.mkpath("."))
|
||||
if ( !outputDir.mkpath( "." ) )
|
||||
{
|
||||
RiaLogging::error(QString("HoloLens: Could not create debug file export folder: %1").arg(absOutputFolder));
|
||||
RiaLogging::error(
|
||||
QString( "HoloLens: Could not create debug file export folder: %1" ).arg( absOutputFolder ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// For debugging, write only the new packets to file
|
||||
// Determine which packets are new by comparing the IDs to the max known ID before extraction
|
||||
std::vector<int> packetIdsToWrite;
|
||||
for (int packetId : allReferencedPacketIds)
|
||||
for ( int packetId : allReferencedPacketIds )
|
||||
{
|
||||
if (packetId > dbgMaxAssignedIdBeforeExtraction)
|
||||
if ( packetId > dbgMaxAssignedIdBeforeExtraction )
|
||||
{
|
||||
packetIdsToWrite.push_back(packetId);
|
||||
packetIdsToWrite.push_back( packetId );
|
||||
}
|
||||
}
|
||||
|
||||
// This will write all packets seen in this extraction to file
|
||||
//packetIdsToWrite = allReferencedPacketIds;
|
||||
// packetIdsToWrite = allReferencedPacketIds;
|
||||
|
||||
RiaLogging::info(QString("HoloLens: Doing debug export of data (%1 packets) to folder: %2").arg(packetIdsToWrite.size()).arg(absOutputFolder));
|
||||
VdeFileExporter fileExporter(absOutputFolder);
|
||||
if (!fileExporter.exportToFile(modelMetaJsonStr, m_packetDirectory, packetIdsToWrite))
|
||||
RiaLogging::info( QString( "HoloLens: Doing debug export of data (%1 packets) to folder: %2" )
|
||||
.arg( packetIdsToWrite.size() )
|
||||
.arg( absOutputFolder ) );
|
||||
VdeFileExporter fileExporter( absOutputFolder );
|
||||
if ( !fileExporter.exportToFile( modelMetaJsonStr, m_packetDirectory, packetIdsToWrite ) )
|
||||
{
|
||||
RiaLogging::error("HoloLens: Error exporting debug data to folder");
|
||||
RiaLogging::error( "HoloLens: Error exporting debug data to folder" );
|
||||
}
|
||||
|
||||
RiaLogging::info("HoloLens: Done exporting debug data");
|
||||
RiaLogging::info( "HoloLens: Done exporting debug data" );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::handleSuccessfulCreateSession()
|
||||
{
|
||||
RiaLogging::info("HoloLens: Session successfully created");
|
||||
RiaLogging::info( "HoloLens: Session successfully created" );
|
||||
m_isSessionValid = true;
|
||||
|
||||
notifyObserver(RicHoloLensSessionObserver::CreateSessionSucceeded);
|
||||
notifyObserver( RicHoloLensSessionObserver::CreateSessionSucceeded );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::handleFailedCreateSession()
|
||||
{
|
||||
RiaLogging::error("HoloLens: Failed to create session");
|
||||
RiaLogging::error( "HoloLens: Failed to create session" );
|
||||
m_isSessionValid = false;
|
||||
|
||||
notifyObserver(RicHoloLensSessionObserver::CreateSessionFailed);
|
||||
notifyObserver( RicHoloLensSessionObserver::CreateSessionFailed );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Handle the server response we receive after sending new meta data
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::handleSuccessfulSendMetaData(int metaDataSequenceNumber, const QByteArray& jsonServerResponseString)
|
||||
void RicHoloLensSession::handleSuccessfulSendMetaData( int metaDataSequenceNumber,
|
||||
const QByteArray& jsonServerResponseString )
|
||||
{
|
||||
cvf::Timer tim;
|
||||
|
||||
RiaLogging::info(QString("HoloLens: Processing server response (meta data sequenceNumber=%1)").arg(metaDataSequenceNumber));
|
||||
RiaLogging::info(
|
||||
QString( "HoloLens: Processing server response (meta data sequenceNumber=%1)" ).arg( metaDataSequenceNumber ) );
|
||||
|
||||
if (m_lastExtractionMetaDataSequenceNumber != metaDataSequenceNumber)
|
||||
if ( m_lastExtractionMetaDataSequenceNumber != metaDataSequenceNumber )
|
||||
{
|
||||
RiaLogging::warning(QString("HoloLens: Ignoring server response, the meta data sequenceNumber(%1) has been superseded").arg(metaDataSequenceNumber));
|
||||
RiaLogging::warning(
|
||||
QString( "HoloLens: Ignoring server response, the meta data sequenceNumber(%1) has been superseded" )
|
||||
.arg( metaDataSequenceNumber ) );
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<int> arrayIdsToSend;
|
||||
|
||||
//cvf::Trace::show("Raw JSON response from server: '%s'", jsonServerResponseString.data());
|
||||
// cvf::Trace::show("Raw JSON response from server: '%s'", jsonServerResponseString.data());
|
||||
QByteArray trimmedServerResponseString = jsonServerResponseString.trimmed();
|
||||
if (trimmedServerResponseString.size() > 0)
|
||||
if ( trimmedServerResponseString.size() > 0 )
|
||||
{
|
||||
if (!parseJsonIntegerArray(trimmedServerResponseString, &arrayIdsToSend))
|
||||
if ( !parseJsonIntegerArray( trimmedServerResponseString, &arrayIdsToSend ) )
|
||||
{
|
||||
RiaLogging::error("HoloLens: Error parsing array server response with array Ids, no data will be sent to server");
|
||||
RiaLogging::error(
|
||||
"HoloLens: Error parsing array server response with array Ids, no data will be sent to server" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// An empty server response means we should send all array referenced by the last sent meta data
|
||||
if (m_lastExtractionAllReferencedPacketIdsArr.size() > 0)
|
||||
if ( m_lastExtractionAllReferencedPacketIdsArr.size() > 0 )
|
||||
{
|
||||
arrayIdsToSend = m_lastExtractionAllReferencedPacketIdsArr;
|
||||
RiaLogging::info("HoloLens: Empty server response, sending all arrays referenced by last meta data");
|
||||
RiaLogging::info( "HoloLens: Empty server response, sending all arrays referenced by last meta data" );
|
||||
}
|
||||
}
|
||||
|
||||
if (arrayIdsToSend.size() ==0)
|
||||
if ( arrayIdsToSend.size() == 0 )
|
||||
{
|
||||
RiaLogging::info("HoloLens: Nothing to do, no data requested by server");
|
||||
RiaLogging::info( "HoloLens: Nothing to do, no data requested by server" );
|
||||
return;
|
||||
}
|
||||
|
||||
RiaLogging::info(QString("HoloLens: Start sending data to server, %1 data arrays have been requested").arg(arrayIdsToSend.size()));
|
||||
RiaLogging::info( QString( "HoloLens: Start sending data to server, %1 data arrays have been requested" )
|
||||
.arg( arrayIdsToSend.size() ) );
|
||||
|
||||
size_t totalBytesSent = 0;
|
||||
size_t totalBytesSent = 0;
|
||||
size_t totalNumArraysSent = 0;
|
||||
|
||||
const bool sendAsIndividualPackets = false;
|
||||
|
||||
// Sending data packets one by one
|
||||
if (sendAsIndividualPackets)
|
||||
if ( sendAsIndividualPackets )
|
||||
{
|
||||
for (size_t i = 0; i < arrayIdsToSend.size(); i++)
|
||||
for ( size_t i = 0; i < arrayIdsToSend.size(); i++ )
|
||||
{
|
||||
const int arrayId = arrayIdsToSend[i];
|
||||
const VdeArrayDataPacket* packet = m_packetDirectory.lookupPacket(arrayId);
|
||||
if (!packet)
|
||||
const int arrayId = arrayIdsToSend[i];
|
||||
const VdeArrayDataPacket* packet = m_packetDirectory.lookupPacket( arrayId );
|
||||
if ( !packet )
|
||||
{
|
||||
RiaLogging::warning(QString("HoloLens: Could not get the requested data from cache, array id: %1 ").arg(arrayId));
|
||||
RiaLogging::warning(
|
||||
QString( "HoloLens: Could not get the requested data from cache, array id: %1 " ).arg( arrayId ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
QByteArray packetByteArr(packet->fullPacketRawPtr(), static_cast<int>(packet->fullPacketSize()));
|
||||
|
||||
RiaLogging::info(QString("HoloLens: sending array id: %1, %2KB (%3 bytes)").arg(arrayId).arg(packetByteArr.size()/1024.0, 0, 'f', 2).arg(packetByteArr.size()));
|
||||
QByteArray packetByteArr( packet->fullPacketRawPtr(), static_cast<int>( packet->fullPacketSize() ) );
|
||||
|
||||
m_restClient->sendBinaryData(packetByteArr, "arrId" + QByteArray::number(arrayId));
|
||||
RiaLogging::info( QString( "HoloLens: sending array id: %1, %2KB (%3 bytes)" )
|
||||
.arg( arrayId )
|
||||
.arg( packetByteArr.size() / 1024.0, 0, 'f', 2 )
|
||||
.arg( packetByteArr.size() ) );
|
||||
|
||||
m_restClient->sendBinaryData( packetByteArr, "arrId" + QByteArray::number( arrayId ) );
|
||||
|
||||
totalNumArraysSent++;
|
||||
totalBytesSent += packetByteArr.size();
|
||||
@@ -305,91 +319,96 @@ void RicHoloLensSession::handleSuccessfulSendMetaData(int metaDataSequenceNumber
|
||||
else
|
||||
{
|
||||
QByteArray combinedPacketArr;
|
||||
if (!m_packetDirectory.getPacketsAsCombinedBuffer(arrayIdsToSend, &combinedPacketArr))
|
||||
if ( !m_packetDirectory.getPacketsAsCombinedBuffer( arrayIdsToSend, &combinedPacketArr ) )
|
||||
{
|
||||
RiaLogging::warning("HoloLens: Error gathering the requested arrays, no data will be sent");
|
||||
RiaLogging::warning( "HoloLens: Error gathering the requested arrays, no data will be sent" );
|
||||
return;
|
||||
}
|
||||
|
||||
totalNumArraysSent = arrayIdsToSend.size();
|
||||
totalBytesSent = combinedPacketArr.size();
|
||||
totalBytesSent = combinedPacketArr.size();
|
||||
|
||||
RiaLogging::info(QString("HoloLens: Sending data to server (%1 arrays combined), %2KB (%3 bytes)").arg(totalNumArraysSent).arg(totalBytesSent/1024.0, 0, 'f', 2).arg(totalBytesSent));
|
||||
RiaLogging::info( QString( "HoloLens: Sending data to server (%1 arrays combined), %2KB (%3 bytes)" )
|
||||
.arg( totalNumArraysSent )
|
||||
.arg( totalBytesSent / 1024.0, 0, 'f', 2 )
|
||||
.arg( totalBytesSent ) );
|
||||
|
||||
m_restClient->sendBinaryData(combinedPacketArr, "metaSeqNum" + QByteArray::number(metaDataSequenceNumber));
|
||||
m_restClient->sendBinaryData( combinedPacketArr, "metaSeqNum" + QByteArray::number( metaDataSequenceNumber ) );
|
||||
}
|
||||
|
||||
const double totalMb = totalBytesSent/(1024.0*1024.0);
|
||||
RiaLogging::info(QString("HoloLens: Finished sending data to server, %1 arrays, total %2MB (%3 bytes) in %4ms").arg(totalNumArraysSent).arg(totalMb, 0, 'f', 2).arg(totalBytesSent).arg(static_cast<int>(tim.time()*1000)));
|
||||
const double totalMb = totalBytesSent / ( 1024.0 * 1024.0 );
|
||||
RiaLogging::info( QString( "HoloLens: Finished sending data to server, %1 arrays, total %2MB (%3 bytes) in %4ms" )
|
||||
.arg( totalNumArraysSent )
|
||||
.arg( totalMb, 0, 'f', 2 )
|
||||
.arg( totalBytesSent )
|
||||
.arg( static_cast<int>( tim.time() * 1000 ) ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensSession::parseJsonIntegerArray(const QByteArray& jsonString, std::vector<int>* integerArr)
|
||||
bool RicHoloLensSession::parseJsonIntegerArray( const QByteArray& jsonString, std::vector<int>* integerArr )
|
||||
{
|
||||
//cvf::Trace::show("jsonString: '%s'", jsonString.data());
|
||||
// cvf::Trace::show("jsonString: '%s'", jsonString.data());
|
||||
|
||||
const int openBraceIdx = jsonString.indexOf('[');
|
||||
const int closeBraceIdx = jsonString.lastIndexOf(']');
|
||||
if (openBraceIdx < 0 || closeBraceIdx < 0)
|
||||
const int openBraceIdx = jsonString.indexOf( '[' );
|
||||
const int closeBraceIdx = jsonString.lastIndexOf( ']' );
|
||||
if ( openBraceIdx < 0 || closeBraceIdx < 0 )
|
||||
{
|
||||
RiaLogging::debug("Error parsing JSON array, could not find opening or closing braces");
|
||||
RiaLogging::debug( "Error parsing JSON array, could not find opening or closing braces" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if (closeBraceIdx <= openBraceIdx)
|
||||
if ( closeBraceIdx <= openBraceIdx )
|
||||
{
|
||||
RiaLogging::debug("Error parsing JSON array, wrong placement of braces");
|
||||
RiaLogging::debug( "Error parsing JSON array, wrong placement of braces" );
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray arrayContents = jsonString.mid(openBraceIdx + 1, closeBraceIdx - openBraceIdx - 1).trimmed();
|
||||
//cvf::Trace::show("arrayContents: '%s'", arrayContents.data());
|
||||
QByteArray arrayContents = jsonString.mid( openBraceIdx + 1, closeBraceIdx - openBraceIdx - 1 ).trimmed();
|
||||
// cvf::Trace::show("arrayContents: '%s'", arrayContents.data());
|
||||
|
||||
QList<QByteArray> stringList = arrayContents.split(',');
|
||||
for (const QByteArray& entry : stringList)
|
||||
QList<QByteArray> stringList = arrayContents.split( ',' );
|
||||
for ( const QByteArray& entry : stringList )
|
||||
{
|
||||
bool convertOk = false;
|
||||
const int intVal = entry.toInt(&convertOk);
|
||||
if (convertOk)
|
||||
bool convertOk = false;
|
||||
const int intVal = entry.toInt( &convertOk );
|
||||
if ( convertOk )
|
||||
{
|
||||
integerArr->push_back(intVal);
|
||||
integerArr->push_back( intVal );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::handleError(const QString& errMsg, const QString& url, const QString& serverData)
|
||||
void RicHoloLensSession::handleError( const QString& errMsg, const QString& url, const QString& serverData )
|
||||
{
|
||||
QString fullMsg = "HoloLens communication error: " + errMsg;
|
||||
|
||||
if (!serverData.isEmpty())
|
||||
if ( !serverData.isEmpty() )
|
||||
{
|
||||
fullMsg += "\n serverMsg: " + serverData;
|
||||
}
|
||||
|
||||
fullMsg += "\n url: " + url;
|
||||
|
||||
RiaLogging::error(fullMsg);
|
||||
RiaLogging::error( fullMsg );
|
||||
|
||||
// It is probably not correct to always consider an error a state change, but for now
|
||||
notifyObserver(RicHoloLensSessionObserver::GeneralError);
|
||||
notifyObserver( RicHoloLensSessionObserver::GeneralError );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSession::notifyObserver(RicHoloLensSessionObserver::Notification notification)
|
||||
void RicHoloLensSession::notifyObserver( RicHoloLensSessionObserver::Notification notification )
|
||||
{
|
||||
if (m_sessionObserver)
|
||||
if ( m_sessionObserver )
|
||||
{
|
||||
m_sessionObserver->handleSessionNotification(this, notification);
|
||||
m_sessionObserver->handleSessionNotification( this, notification );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RicHoloLensSessionObserver.h"
|
||||
#include "RicHoloLensRestClient.h"
|
||||
#include "RicHoloLensSessionObserver.h"
|
||||
|
||||
#include "VdePacketDirectory.h"
|
||||
#include "VdeCachingHashedIdFactory.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RimGridView;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -42,36 +41,39 @@ class RicHoloLensSession : public QObject, private RicHoloLensRestResponseHandle
|
||||
public:
|
||||
~RicHoloLensSession() override;
|
||||
|
||||
static RicHoloLensSession* createSession(const QString& serverUrl, const QString& sessionName, const QByteArray& sessionPinCode, RicHoloLensSessionObserver* sessionObserver);
|
||||
static RicHoloLensSession* createDummyFileBackedSession();
|
||||
void destroySession();
|
||||
static RicHoloLensSession* createSession( const QString& serverUrl,
|
||||
const QString& sessionName,
|
||||
const QByteArray& sessionPinCode,
|
||||
RicHoloLensSessionObserver* sessionObserver );
|
||||
static RicHoloLensSession* createDummyFileBackedSession();
|
||||
void destroySession();
|
||||
|
||||
bool isSessionValid() const;
|
||||
bool isSessionValid() const;
|
||||
|
||||
void updateSessionDataFromView(const RimGridView& activeView);
|
||||
void updateSessionDataFromView( const RimGridView& activeView );
|
||||
|
||||
private:
|
||||
RicHoloLensSession();
|
||||
|
||||
void handleSuccessfulCreateSession() override;
|
||||
void handleFailedCreateSession() override;
|
||||
void handleSuccessfulSendMetaData(int metaDataSequenceNumber, const QByteArray& jsonServerResponseString) override;
|
||||
void handleError(const QString& errMsg, const QString& url, const QString& serverData) override;
|
||||
void handleSuccessfulCreateSession() override;
|
||||
void handleFailedCreateSession() override;
|
||||
void handleSuccessfulSendMetaData( int metaDataSequenceNumber, const QByteArray& jsonServerResponseString ) override;
|
||||
void handleError( const QString& errMsg, const QString& url, const QString& serverData ) override;
|
||||
|
||||
static bool parseJsonIntegerArray(const QByteArray& jsonString, std::vector<int>* integerArr);
|
||||
static bool parseJsonIntegerArray( const QByteArray& jsonString, std::vector<int>* integerArr );
|
||||
|
||||
void notifyObserver(RicHoloLensSessionObserver::Notification notification);
|
||||
void notifyObserver( RicHoloLensSessionObserver::Notification notification );
|
||||
|
||||
private:
|
||||
bool m_isSessionValid;
|
||||
QPointer<RicHoloLensRestClient> m_restClient;
|
||||
|
||||
int m_lastExtractionMetaDataSequenceNumber;
|
||||
std::vector<int> m_lastExtractionAllReferencedPacketIdsArr;
|
||||
VdeCachingHashedIdFactory m_cachingIdFactory;
|
||||
VdePacketDirectory m_packetDirectory;
|
||||
int m_lastExtractionMetaDataSequenceNumber;
|
||||
std::vector<int> m_lastExtractionAllReferencedPacketIdsArr;
|
||||
VdeCachingHashedIdFactory m_cachingIdFactory;
|
||||
VdePacketDirectory m_packetDirectory;
|
||||
|
||||
RicHoloLensSessionObserver* m_sessionObserver;
|
||||
RicHoloLensSessionObserver* m_sessionObserver;
|
||||
|
||||
QString m_dbgFileExportDestinationFolder;
|
||||
QString m_dbgFileExportDestinationFolder;
|
||||
};
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
#include "cafCmdFeatureManager.h"
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -34,9 +32,7 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensSessionManager::RicHoloLensSessionManager()
|
||||
{
|
||||
}
|
||||
RicHoloLensSessionManager::RicHoloLensSessionManager() {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -50,16 +46,21 @@ RicHoloLensSessionManager* RicHoloLensSessionManager::instance()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensSessionManager::createSession(const QString& serverUrl, const QString& sessionName, const QString& sessionPinCode)
|
||||
bool RicHoloLensSessionManager::createSession( const QString& serverUrl,
|
||||
const QString& sessionName,
|
||||
const QString& sessionPinCode )
|
||||
{
|
||||
if (m_session)
|
||||
if ( m_session )
|
||||
{
|
||||
RiaLogging::error("Terminate existing session before creating a new session");
|
||||
RiaLogging::error( "Terminate existing session before creating a new session" );
|
||||
return false;
|
||||
}
|
||||
|
||||
RiaLogging::info(QString("Creating HoloLens session: '%1' with pin code: %2, server url: %3").arg(sessionName).arg(sessionPinCode).arg(serverUrl));
|
||||
m_session = RicHoloLensSession::createSession(serverUrl, sessionName, sessionPinCode.toLatin1(), this);
|
||||
RiaLogging::info( QString( "Creating HoloLens session: '%1' with pin code: %2, server url: %3" )
|
||||
.arg( sessionName )
|
||||
.arg( sessionPinCode )
|
||||
.arg( serverUrl ) );
|
||||
m_session = RicHoloLensSession::createSession( serverUrl, sessionName, sessionPinCode.toLatin1(), this );
|
||||
|
||||
refreshToolbarState();
|
||||
|
||||
@@ -71,14 +72,14 @@ bool RicHoloLensSessionManager::createSession(const QString& serverUrl, const QS
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicHoloLensSessionManager::createDummyFileBackedSession()
|
||||
{
|
||||
if (m_session)
|
||||
if ( m_session )
|
||||
{
|
||||
RiaLogging::error("Terminate existing session before creating a new session");
|
||||
RiaLogging::error( "Terminate existing session before creating a new session" );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_session = RicHoloLensSession::createDummyFileBackedSession();
|
||||
RiaLogging::info("Created dummy file-backed HoloLens session");
|
||||
RiaLogging::info( "Created dummy file-backed HoloLens session" );
|
||||
|
||||
refreshToolbarState();
|
||||
|
||||
@@ -90,13 +91,13 @@ bool RicHoloLensSessionManager::createDummyFileBackedSession()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSessionManager::terminateSession()
|
||||
{
|
||||
if (!m_session)
|
||||
if ( !m_session )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RiaLogging::info("Terminating HoloLens session");
|
||||
|
||||
RiaLogging::info( "Terminating HoloLens session" );
|
||||
|
||||
RicHoloLensSession* sessionToDelete = m_session;
|
||||
m_session->destroySession();
|
||||
m_session = nullptr;
|
||||
@@ -107,7 +108,7 @@ void RicHoloLensSessionManager::terminateSession()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicHoloLensSession* RicHoloLensSessionManager::session()
|
||||
{
|
||||
@@ -115,7 +116,7 @@ RicHoloLensSession* RicHoloLensSessionManager::session()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSessionManager::refreshToolbarState()
|
||||
{
|
||||
@@ -126,22 +127,20 @@ void RicHoloLensSessionManager::refreshToolbarState()
|
||||
commandIds << "RicHoloLensAutoExportToSharingServerFeature";
|
||||
commandIds << "RicHoloLensTerminateSessionFeature";
|
||||
|
||||
caf::CmdFeatureManager::instance()->refreshStates(commandIds);
|
||||
caf::CmdFeatureManager::instance()->refreshStates( commandIds );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensSessionManager::handleSessionNotification(const RicHoloLensSession* session, Notification notification)
|
||||
void RicHoloLensSessionManager::handleSessionNotification( const RicHoloLensSession* session, Notification notification )
|
||||
{
|
||||
if (notification == RicHoloLensSessionObserver::CreateSessionFailed)
|
||||
if ( notification == RicHoloLensSessionObserver::CreateSessionFailed )
|
||||
{
|
||||
if (m_session && m_session == session)
|
||||
terminateSession();
|
||||
if ( m_session && m_session == session ) terminateSession();
|
||||
}
|
||||
else
|
||||
{
|
||||
refreshToolbarState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
class RicHoloLensSession;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -35,21 +34,20 @@ class RicHoloLensSessionManager : private RicHoloLensSessionObserver
|
||||
public:
|
||||
static RicHoloLensSessionManager* instance();
|
||||
|
||||
bool createSession(const QString& serverUrl, const QString& sessionName, const QString& sessionPinCode);
|
||||
bool createDummyFileBackedSession();
|
||||
void terminateSession();
|
||||
bool createSession( const QString& serverUrl, const QString& sessionName, const QString& sessionPinCode );
|
||||
bool createDummyFileBackedSession();
|
||||
void terminateSession();
|
||||
|
||||
RicHoloLensSession* session();
|
||||
|
||||
static void refreshToolbarState();
|
||||
static void refreshToolbarState();
|
||||
|
||||
private:
|
||||
void handleSessionNotification(const RicHoloLensSession* session, Notification notification) override;
|
||||
void handleSessionNotification( const RicHoloLensSession* session, Notification notification ) override;
|
||||
|
||||
private:
|
||||
RicHoloLensSessionManager();
|
||||
|
||||
private:
|
||||
QPointer<RicHoloLensSession> m_session;
|
||||
QPointer<RicHoloLensSession> m_session;
|
||||
};
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
|
||||
class RicHoloLensSession;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicHoloLensSessionObserver
|
||||
@@ -39,5 +37,5 @@ public:
|
||||
|
||||
public:
|
||||
virtual ~RicHoloLensSessionObserver() {}
|
||||
virtual void handleSessionNotification(const RicHoloLensSession* session, Notification notification) = 0;
|
||||
virtual void handleSessionNotification( const RicHoloLensSession* session, Notification notification ) = 0;
|
||||
};
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicHoloLensTerminateSessionFeature, "RicHoloLensTerminateSessionFeature");
|
||||
CAF_CMD_SOURCE_INIT( RicHoloLensTerminateSessionFeature, "RicHoloLensTerminateSessionFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -40,13 +40,13 @@ bool RicHoloLensTerminateSessionFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensTerminateSessionFeature::onActionTriggered(bool isChecked)
|
||||
void RicHoloLensTerminateSessionFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
auto* cmdFeature = dynamic_cast<RicHoloLensAutoExportToSharingServerFeature*>(
|
||||
caf::CmdFeatureManager::instance()->getCommandFeature("RicHoloLensAutoExportToSharingServerFeature"));
|
||||
if (cmdFeature)
|
||||
caf::CmdFeatureManager::instance()->getCommandFeature( "RicHoloLensAutoExportToSharingServerFeature" ) );
|
||||
if ( cmdFeature )
|
||||
{
|
||||
cmdFeature->setActive(false);
|
||||
cmdFeature->setActive( false );
|
||||
}
|
||||
|
||||
RicHoloLensSessionManager::instance()->terminateSession();
|
||||
@@ -57,9 +57,9 @@ void RicHoloLensTerminateSessionFeature::onActionTriggered(bool isChecked)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHoloLensTerminateSessionFeature::setupActionLook(QAction* actionToSetup)
|
||||
void RicHoloLensTerminateSessionFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/HoloLensDisconnect24x24.png"));
|
||||
actionToSetup->setIcon( QIcon( ":/HoloLensDisconnect24x24.png" ) );
|
||||
|
||||
actionToSetup->setText("Disconnect from HoloLens server");
|
||||
actionToSetup->setText( "Disconnect from HoloLens server" );
|
||||
}
|
||||
@@ -29,6 +29,6 @@ class RicHoloLensTerminateSessionFeature : public caf::CmdFeature
|
||||
|
||||
private:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered(bool isChecked) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
@@ -21,8 +21,6 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -40,32 +38,30 @@
|
||||
// imageHeight: 2 bytes :
|
||||
// arrayData: ...
|
||||
|
||||
|
||||
// Header offsets in bytes
|
||||
static const size_t VDE_BYTEOFFSET_PACKET_VERSION = 0;
|
||||
static const size_t VDE_BYTEOFFSET_ARRAY_ID = 2;
|
||||
static const size_t VDE_BYTEOFFSET_ELEMENT_COUNT = 6;
|
||||
static const size_t VDE_BYTEOFFSET_ELEMENT_TYPE = 10;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT= 11;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_WIDTH = 12;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_HEIGHT = 14;
|
||||
static const size_t VDE_BYTEOFFSET_PACKET_VERSION = 0;
|
||||
static const size_t VDE_BYTEOFFSET_ARRAY_ID = 2;
|
||||
static const size_t VDE_BYTEOFFSET_ELEMENT_COUNT = 6;
|
||||
static const size_t VDE_BYTEOFFSET_ELEMENT_TYPE = 10;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT = 11;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_WIDTH = 12;
|
||||
static const size_t VDE_BYTEOFFSET_IMAGE_HEIGHT = 14;
|
||||
|
||||
// Header size in bytes
|
||||
static const size_t VDE_HEADER_SIZE = 2 + 4 + 4 + 1 + 1 + 2 + 2;
|
||||
|
||||
static const size_t VDE_PACKET_VERSION = 1;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeArrayDataPacket::VdeArrayDataPacket()
|
||||
: m_arrayId(-1),
|
||||
m_elementType(Unknown),
|
||||
m_elementCount(0),
|
||||
m_imageWidth(0),
|
||||
m_imageHeight(0),
|
||||
m_imageComponentCount(0)
|
||||
: m_arrayId( -1 )
|
||||
, m_elementType( Unknown )
|
||||
, m_elementCount( 0 )
|
||||
, m_imageWidth( 0 )
|
||||
, m_imageHeight( 0 )
|
||||
, m_imageComponentCount( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -74,9 +70,7 @@ VdeArrayDataPacket::VdeArrayDataPacket()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeArrayDataPacket::isValid() const
|
||||
{
|
||||
if (m_elementType != Unknown &&
|
||||
m_packetBytes.size() >= VDE_HEADER_SIZE &&
|
||||
m_arrayId >= 0)
|
||||
if ( m_elementType != Unknown && m_packetBytes.size() >= VDE_HEADER_SIZE && m_arrayId >= 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -84,7 +78,6 @@ bool VdeArrayDataPacket::isValid() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -108,20 +101,24 @@ VdeArrayDataPacket::ElementType VdeArrayDataPacket::elementType() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t VdeArrayDataPacket::elementSize() const
|
||||
{
|
||||
return sizeOfElement(m_elementType);
|
||||
return sizeOfElement( m_elementType );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Size of specified element type in bytes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t VdeArrayDataPacket::sizeOfElement(ElementType elementType)
|
||||
size_t VdeArrayDataPacket::sizeOfElement( ElementType elementType )
|
||||
{
|
||||
switch (elementType)
|
||||
switch ( elementType )
|
||||
{
|
||||
case Unknown: return 0;
|
||||
case Float32: return sizeof(float);
|
||||
case Uint32: return sizeof(unsigned int);
|
||||
case Uint8: return sizeof(unsigned char);
|
||||
case Unknown:
|
||||
return 0;
|
||||
case Float32:
|
||||
return sizeof( float );
|
||||
case Uint32:
|
||||
return sizeof( unsigned int );
|
||||
case Uint8:
|
||||
return sizeof( unsigned char );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -140,7 +137,7 @@ size_t VdeArrayDataPacket::elementCount() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const char* VdeArrayDataPacket::arrayData() const
|
||||
{
|
||||
if (m_packetBytes.size() > VDE_HEADER_SIZE)
|
||||
if ( m_packetBytes.size() > VDE_HEADER_SIZE )
|
||||
{
|
||||
const char* ptr = m_packetBytes.data();
|
||||
return ptr + VDE_HEADER_SIZE;
|
||||
@@ -178,78 +175,85 @@ unsigned char VdeArrayDataPacket::imageComponentCount() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<VdeArrayDataPacket> VdeArrayDataPacket::fromFloat32Arr(int arrayId, const float* srcArr, size_t srcArrElementCount)
|
||||
std::unique_ptr<VdeArrayDataPacket>
|
||||
VdeArrayDataPacket::fromFloat32Arr( int arrayId, const float* srcArr, size_t srcArrElementCount )
|
||||
{
|
||||
size_t payloadByteCount = srcArrElementCount*sizeof(float);
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>(srcArr);
|
||||
size_t payloadByteCount = srcArrElementCount * sizeof( float );
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>( srcArr );
|
||||
|
||||
std::unique_ptr<VdeArrayDataPacket> packet(new VdeArrayDataPacket);
|
||||
packet->assign(arrayId, Float32, srcArrElementCount, 0, 0, 0, rawSrcPtr, payloadByteCount);
|
||||
std::unique_ptr<VdeArrayDataPacket> packet( new VdeArrayDataPacket );
|
||||
packet->assign( arrayId, Float32, srcArrElementCount, 0, 0, 0, rawSrcPtr, payloadByteCount );
|
||||
return packet;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<VdeArrayDataPacket> VdeArrayDataPacket::fromUint32Arr(int arrayId, const unsigned int* srcArr, size_t srcArrElementCount)
|
||||
std::unique_ptr<VdeArrayDataPacket>
|
||||
VdeArrayDataPacket::fromUint32Arr( int arrayId, const unsigned int* srcArr, size_t srcArrElementCount )
|
||||
{
|
||||
size_t payloadByteCount = srcArrElementCount*sizeof(unsigned int);
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>(srcArr);
|
||||
size_t payloadByteCount = srcArrElementCount * sizeof( unsigned int );
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>( srcArr );
|
||||
|
||||
std::unique_ptr<VdeArrayDataPacket> packet(new VdeArrayDataPacket);
|
||||
packet->assign(arrayId, Uint32, srcArrElementCount, 0, 0, 0, rawSrcPtr, payloadByteCount);
|
||||
std::unique_ptr<VdeArrayDataPacket> packet( new VdeArrayDataPacket );
|
||||
packet->assign( arrayId, Uint32, srcArrElementCount, 0, 0, 0, rawSrcPtr, payloadByteCount );
|
||||
return packet;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<VdeArrayDataPacket> VdeArrayDataPacket::fromUint8ImageRGBArr(int arrayId, unsigned short imageWidth, unsigned short imageHeight, const unsigned char* srcArr, size_t srcArrElementCount)
|
||||
std::unique_ptr<VdeArrayDataPacket> VdeArrayDataPacket::fromUint8ImageRGBArr( int arrayId,
|
||||
unsigned short imageWidth,
|
||||
unsigned short imageHeight,
|
||||
const unsigned char* srcArr,
|
||||
size_t srcArrElementCount )
|
||||
{
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>(srcArr);
|
||||
const char* rawSrcPtr = reinterpret_cast<const char*>( srcArr );
|
||||
|
||||
assert(3*imageWidth*imageHeight == srcArrElementCount);
|
||||
assert( 3 * imageWidth * imageHeight == srcArrElementCount );
|
||||
|
||||
std::unique_ptr<VdeArrayDataPacket> packet(new VdeArrayDataPacket);
|
||||
packet->assign(arrayId, Uint8, srcArrElementCount, imageWidth, imageHeight, 3, rawSrcPtr, srcArrElementCount);
|
||||
std::unique_ptr<VdeArrayDataPacket> packet( new VdeArrayDataPacket );
|
||||
packet->assign( arrayId, Uint8, srcArrElementCount, imageWidth, imageHeight, 3, rawSrcPtr, srcArrElementCount );
|
||||
return packet;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeArrayDataPacket VdeArrayDataPacket::fromRawPacketBuffer(const char* rawPacketBuffer, size_t bufferSize, std::string* errString)
|
||||
VdeArrayDataPacket
|
||||
VdeArrayDataPacket::fromRawPacketBuffer( const char* rawPacketBuffer, size_t bufferSize, std::string* errString )
|
||||
{
|
||||
if (bufferSize < VDE_HEADER_SIZE)
|
||||
if ( bufferSize < VDE_HEADER_SIZE )
|
||||
{
|
||||
if (errString) *errString = "Buffer size is less than fixed header size";
|
||||
if ( errString ) *errString = "Buffer size is less than fixed header size";
|
||||
return VdeArrayDataPacket();
|
||||
}
|
||||
|
||||
VdeBufferReader bufferReader(rawPacketBuffer, bufferSize);
|
||||
const unsigned short packetVersion = bufferReader.getUint16(VDE_BYTEOFFSET_PACKET_VERSION);
|
||||
if (packetVersion != VDE_PACKET_VERSION)
|
||||
VdeBufferReader bufferReader( rawPacketBuffer, bufferSize );
|
||||
const unsigned short packetVersion = bufferReader.getUint16( VDE_BYTEOFFSET_PACKET_VERSION );
|
||||
if ( packetVersion != VDE_PACKET_VERSION )
|
||||
{
|
||||
if (errString) *errString = "Wrong packet version";
|
||||
if ( errString ) *errString = "Wrong packet version";
|
||||
return VdeArrayDataPacket();
|
||||
}
|
||||
|
||||
const int packetId = bufferReader.getUint32(VDE_BYTEOFFSET_ARRAY_ID);
|
||||
const ElementType elementType = static_cast<ElementType>(bufferReader.getUint8(VDE_BYTEOFFSET_ELEMENT_TYPE));
|
||||
const size_t elementCount = bufferReader.getUint32(VDE_BYTEOFFSET_ELEMENT_COUNT);
|
||||
const int packetId = bufferReader.getUint32( VDE_BYTEOFFSET_ARRAY_ID );
|
||||
const ElementType elementType = static_cast<ElementType>( bufferReader.getUint8( VDE_BYTEOFFSET_ELEMENT_TYPE ) );
|
||||
const size_t elementCount = bufferReader.getUint32( VDE_BYTEOFFSET_ELEMENT_COUNT );
|
||||
|
||||
const unsigned char imageCompCount = bufferReader.getUint8(VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT);
|
||||
const unsigned short imageWidth = bufferReader.getUint16(VDE_BYTEOFFSET_IMAGE_WIDTH);
|
||||
const unsigned short imageHeight = bufferReader.getUint16(VDE_BYTEOFFSET_IMAGE_HEIGHT);
|
||||
const unsigned char imageCompCount = bufferReader.getUint8( VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT );
|
||||
const unsigned short imageWidth = bufferReader.getUint16( VDE_BYTEOFFSET_IMAGE_WIDTH );
|
||||
const unsigned short imageHeight = bufferReader.getUint16( VDE_BYTEOFFSET_IMAGE_HEIGHT );
|
||||
|
||||
const char* payloadPtr = rawPacketBuffer + VDE_HEADER_SIZE;
|
||||
const char* payloadPtr = rawPacketBuffer + VDE_HEADER_SIZE;
|
||||
const size_t payloadSizeInBytes = bufferSize - VDE_HEADER_SIZE;
|
||||
|
||||
const size_t payloadSizeInBytesFromPacketFields = elementCount*sizeOfElement(elementType);
|
||||
assert(payloadSizeInBytes == payloadSizeInBytesFromPacketFields);
|
||||
const size_t payloadSizeInBytesFromPacketFields = elementCount * sizeOfElement( elementType );
|
||||
assert( payloadSizeInBytes == payloadSizeInBytesFromPacketFields );
|
||||
|
||||
VdeArrayDataPacket packet;
|
||||
packet.assign(packetId, elementType, elementCount, imageWidth, imageHeight, imageCompCount, payloadPtr, payloadSizeInBytes);
|
||||
packet.assign( packetId, elementType, elementCount, imageWidth, imageHeight, imageCompCount, payloadPtr, payloadSizeInBytes );
|
||||
|
||||
return packet;
|
||||
}
|
||||
@@ -257,35 +261,42 @@ VdeArrayDataPacket VdeArrayDataPacket::fromRawPacketBuffer(const char* rawPacket
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeArrayDataPacket::assign(int arrayId, ElementType elementType, size_t elementCount, unsigned short imageWidth, unsigned short imageHeight, unsigned char imageCompCount, const char* arrayDataPtr, size_t arrayDataSizeInBytes)
|
||||
bool VdeArrayDataPacket::assign( int arrayId,
|
||||
ElementType elementType,
|
||||
size_t elementCount,
|
||||
unsigned short imageWidth,
|
||||
unsigned short imageHeight,
|
||||
unsigned char imageCompCount,
|
||||
const char* arrayDataPtr,
|
||||
size_t arrayDataSizeInBytes )
|
||||
{
|
||||
assert(arrayDataSizeInBytes > 0);
|
||||
assert( arrayDataSizeInBytes > 0 );
|
||||
|
||||
const size_t totalSizeBytes = VDE_HEADER_SIZE + arrayDataSizeInBytes;
|
||||
m_packetBytes.resize(totalSizeBytes);
|
||||
m_packetBytes.resize( totalSizeBytes );
|
||||
|
||||
VdeBufferWriter bufferWriter(m_packetBytes.data(), m_packetBytes.size());
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_PACKET_VERSION, VDE_PACKET_VERSION);
|
||||
bufferWriter.setUint32(VDE_BYTEOFFSET_ARRAY_ID, arrayId);
|
||||
bufferWriter.setUint32(VDE_BYTEOFFSET_ELEMENT_COUNT, static_cast<unsigned int>(elementCount));
|
||||
bufferWriter.setUint8( VDE_BYTEOFFSET_ELEMENT_TYPE, static_cast<unsigned char>(elementType));
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT, imageCompCount);
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_IMAGE_WIDTH, imageWidth);
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_IMAGE_HEIGHT, imageHeight);
|
||||
VdeBufferWriter bufferWriter( m_packetBytes.data(), m_packetBytes.size() );
|
||||
bufferWriter.setUint16( VDE_BYTEOFFSET_PACKET_VERSION, VDE_PACKET_VERSION );
|
||||
bufferWriter.setUint32( VDE_BYTEOFFSET_ARRAY_ID, arrayId );
|
||||
bufferWriter.setUint32( VDE_BYTEOFFSET_ELEMENT_COUNT, static_cast<unsigned int>( elementCount ) );
|
||||
bufferWriter.setUint8( VDE_BYTEOFFSET_ELEMENT_TYPE, static_cast<unsigned char>( elementType ) );
|
||||
bufferWriter.setUint16( VDE_BYTEOFFSET_IMAGE_COMPONENT_COUNT, imageCompCount );
|
||||
bufferWriter.setUint16( VDE_BYTEOFFSET_IMAGE_WIDTH, imageWidth );
|
||||
bufferWriter.setUint16( VDE_BYTEOFFSET_IMAGE_HEIGHT, imageHeight );
|
||||
|
||||
const size_t calcArraySizeInBytes = elementCount*sizeOfElement(elementType);
|
||||
assert(arrayDataSizeInBytes == calcArraySizeInBytes);
|
||||
const size_t calcArraySizeInBytes = elementCount * sizeOfElement( elementType );
|
||||
assert( arrayDataSizeInBytes == calcArraySizeInBytes );
|
||||
|
||||
std::copy(arrayDataPtr, arrayDataPtr + arrayDataSizeInBytes, m_packetBytes.begin() + VDE_HEADER_SIZE);
|
||||
assert(m_packetBytes.size() == totalSizeBytes);
|
||||
std::copy( arrayDataPtr, arrayDataPtr + arrayDataSizeInBytes, m_packetBytes.begin() + VDE_HEADER_SIZE );
|
||||
assert( m_packetBytes.size() == totalSizeBytes );
|
||||
|
||||
m_arrayId = arrayId;
|
||||
m_elementType = elementType;
|
||||
m_arrayId = arrayId;
|
||||
m_elementType = elementType;
|
||||
m_elementCount = elementCount;
|
||||
|
||||
m_imageComponentCount = imageCompCount;
|
||||
m_imageWidth = imageWidth;
|
||||
m_imageHeight = imageHeight;
|
||||
m_imageWidth = imageWidth;
|
||||
m_imageHeight = imageHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -306,8 +317,6 @@ const char* VdeArrayDataPacket::fullPacketRawPtr() const
|
||||
return m_packetBytes.data();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -317,20 +326,20 @@ const char* VdeArrayDataPacket::fullPacketRawPtr() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeBufferReader::VdeBufferReader(const char* buffer, size_t bufferSize)
|
||||
: m_buffer(buffer),
|
||||
m_bufferSize(bufferSize)
|
||||
VdeBufferReader::VdeBufferReader( const char* buffer, size_t bufferSize )
|
||||
: m_buffer( buffer )
|
||||
, m_bufferSize( bufferSize )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
unsigned int VdeBufferReader::getUint32(size_t byteOffset) const
|
||||
unsigned int VdeBufferReader::getUint32( size_t byteOffset ) const
|
||||
{
|
||||
if (byteOffset + sizeof(unsigned int) <= m_bufferSize)
|
||||
if ( byteOffset + sizeof( unsigned int ) <= m_bufferSize )
|
||||
{
|
||||
return *reinterpret_cast<const unsigned int*>(&m_buffer[byteOffset]);
|
||||
return *reinterpret_cast<const unsigned int*>( &m_buffer[byteOffset] );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -339,11 +348,11 @@ unsigned int VdeBufferReader::getUint32(size_t byteOffset) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
unsigned short VdeBufferReader::getUint16(size_t byteOffset) const
|
||||
unsigned short VdeBufferReader::getUint16( size_t byteOffset ) const
|
||||
{
|
||||
if (byteOffset + sizeof(unsigned short) <= m_bufferSize)
|
||||
if ( byteOffset + sizeof( unsigned short ) <= m_bufferSize )
|
||||
{
|
||||
return *reinterpret_cast<const unsigned short*>(&m_buffer[byteOffset]);
|
||||
return *reinterpret_cast<const unsigned short*>( &m_buffer[byteOffset] );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -352,18 +361,16 @@ unsigned short VdeBufferReader::getUint16(size_t byteOffset) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
unsigned char VdeBufferReader::getUint8(size_t byteOffset) const
|
||||
unsigned char VdeBufferReader::getUint8( size_t byteOffset ) const
|
||||
{
|
||||
if (byteOffset + 1 <= m_bufferSize)
|
||||
if ( byteOffset + 1 <= m_bufferSize )
|
||||
{
|
||||
return *reinterpret_cast<const unsigned char*>(&m_buffer[byteOffset]);
|
||||
return *reinterpret_cast<const unsigned char*>( &m_buffer[byteOffset] );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -373,42 +380,41 @@ unsigned char VdeBufferReader::getUint8(size_t byteOffset) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeBufferWriter::VdeBufferWriter(char* buffer, size_t bufferSize)
|
||||
: m_buffer(buffer),
|
||||
m_bufferSize(bufferSize)
|
||||
VdeBufferWriter::VdeBufferWriter( char* buffer, size_t bufferSize )
|
||||
: m_buffer( buffer )
|
||||
, m_bufferSize( bufferSize )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeBufferWriter::setUint32(size_t byteOffset, unsigned int val)
|
||||
void VdeBufferWriter::setUint32( size_t byteOffset, unsigned int val )
|
||||
{
|
||||
if (byteOffset + sizeof(unsigned int) <= m_bufferSize)
|
||||
if ( byteOffset + sizeof( unsigned int ) <= m_bufferSize )
|
||||
{
|
||||
*reinterpret_cast<unsigned int*>(&m_buffer[byteOffset]) = val;
|
||||
*reinterpret_cast<unsigned int*>( &m_buffer[byteOffset] ) = val;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeBufferWriter::setUint16(size_t byteOffset, unsigned short val)
|
||||
void VdeBufferWriter::setUint16( size_t byteOffset, unsigned short val )
|
||||
{
|
||||
if (byteOffset + sizeof(unsigned short) <= m_bufferSize)
|
||||
if ( byteOffset + sizeof( unsigned short ) <= m_bufferSize )
|
||||
{
|
||||
*reinterpret_cast<unsigned short*>(&m_buffer[byteOffset]) = val;
|
||||
*reinterpret_cast<unsigned short*>( &m_buffer[byteOffset] ) = val;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeBufferWriter::setUint8(size_t byteOffset, unsigned char val)
|
||||
void VdeBufferWriter::setUint8( size_t byteOffset, unsigned char val )
|
||||
{
|
||||
if (byteOffset + 1 <= m_bufferSize)
|
||||
if ( byteOffset + 1 <= m_bufferSize )
|
||||
{
|
||||
*reinterpret_cast<unsigned char*>(&m_buffer[byteOffset]) = val;
|
||||
*reinterpret_cast<unsigned char*>( &m_buffer[byteOffset] ) = val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -43,45 +42,56 @@ public:
|
||||
public:
|
||||
VdeArrayDataPacket();
|
||||
|
||||
bool isValid() const;
|
||||
int arrayId() const;
|
||||
bool isValid() const;
|
||||
int arrayId() const;
|
||||
|
||||
ElementType elementType() const;
|
||||
size_t elementSize() const;
|
||||
size_t elementCount() const;
|
||||
const char* arrayData() const;
|
||||
ElementType elementType() const;
|
||||
size_t elementSize() const;
|
||||
size_t elementCount() const;
|
||||
const char* arrayData() const;
|
||||
|
||||
unsigned short imageWidth() const;
|
||||
unsigned short imageHeight() const;
|
||||
unsigned char imageComponentCount() const;
|
||||
unsigned short imageWidth() const;
|
||||
unsigned short imageHeight() const;
|
||||
unsigned char imageComponentCount() const;
|
||||
|
||||
size_t fullPacketSize() const;
|
||||
const char* fullPacketRawPtr() const;
|
||||
size_t fullPacketSize() const;
|
||||
const char* fullPacketRawPtr() const;
|
||||
|
||||
static std::unique_ptr<VdeArrayDataPacket> fromFloat32Arr(int arrayId, const float* srcArr, size_t srcArrElementCount);
|
||||
static std::unique_ptr<VdeArrayDataPacket> fromUint32Arr(int arrayId, const unsigned int* srcArr, size_t srcArrElementCount);
|
||||
static std::unique_ptr<VdeArrayDataPacket> fromUint8ImageRGBArr(int arrayId, unsigned short imageWidth, unsigned short imageHeight, const unsigned char* srcArr, size_t srcArrElementCount);
|
||||
static std::unique_ptr<VdeArrayDataPacket>
|
||||
fromFloat32Arr( int arrayId, const float* srcArr, size_t srcArrElementCount );
|
||||
static std::unique_ptr<VdeArrayDataPacket>
|
||||
fromUint32Arr( int arrayId, const unsigned int* srcArr, size_t srcArrElementCount );
|
||||
static std::unique_ptr<VdeArrayDataPacket> fromUint8ImageRGBArr( int arrayId,
|
||||
unsigned short imageWidth,
|
||||
unsigned short imageHeight,
|
||||
const unsigned char* srcArr,
|
||||
size_t srcArrElementCount );
|
||||
|
||||
static VdeArrayDataPacket fromRawPacketBuffer(const char* rawPacketBuffer, size_t bufferSize, std::string* errString);
|
||||
static VdeArrayDataPacket fromRawPacketBuffer( const char* rawPacketBuffer, size_t bufferSize, std::string* errString );
|
||||
|
||||
private:
|
||||
bool assign(int arrayId, ElementType elementType, size_t elementCount, unsigned short imageWidth, unsigned short imageHeight, unsigned char imageCompCount, const char* arrayDataPtr, size_t arrayDataSizeInBytes);
|
||||
static size_t sizeOfElement(ElementType elementType);
|
||||
bool assign( int arrayId,
|
||||
ElementType elementType,
|
||||
size_t elementCount,
|
||||
unsigned short imageWidth,
|
||||
unsigned short imageHeight,
|
||||
unsigned char imageCompCount,
|
||||
const char* arrayDataPtr,
|
||||
size_t arrayDataSizeInBytes );
|
||||
static size_t sizeOfElement( ElementType elementType );
|
||||
|
||||
private:
|
||||
int m_arrayId;
|
||||
ElementType m_elementType;
|
||||
size_t m_elementCount;
|
||||
int m_arrayId;
|
||||
ElementType m_elementType;
|
||||
size_t m_elementCount;
|
||||
|
||||
unsigned short m_imageWidth;
|
||||
unsigned short m_imageHeight;
|
||||
unsigned char m_imageComponentCount;
|
||||
unsigned short m_imageWidth;
|
||||
unsigned short m_imageHeight;
|
||||
unsigned char m_imageComponentCount;
|
||||
|
||||
std::vector<char> m_packetBytes;
|
||||
std::vector<char> m_packetBytes;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -90,18 +100,17 @@ private:
|
||||
class VdeBufferReader
|
||||
{
|
||||
public:
|
||||
VdeBufferReader(const char* buffer, size_t bufferSize);
|
||||
VdeBufferReader( const char* buffer, size_t bufferSize );
|
||||
|
||||
unsigned int getUint32(size_t byteOffset) const;
|
||||
unsigned short getUint16(size_t byteOffset) const;
|
||||
unsigned char getUint8(size_t byteOffset) const;
|
||||
unsigned int getUint32( size_t byteOffset ) const;
|
||||
unsigned short getUint16( size_t byteOffset ) const;
|
||||
unsigned char getUint8( size_t byteOffset ) const;
|
||||
|
||||
private:
|
||||
const char* m_buffer;
|
||||
const size_t m_bufferSize;
|
||||
const char* m_buffer;
|
||||
const size_t m_bufferSize;
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -110,14 +119,13 @@ private:
|
||||
class VdeBufferWriter
|
||||
{
|
||||
public:
|
||||
VdeBufferWriter(char* buffer, size_t bufferSize);
|
||||
VdeBufferWriter( char* buffer, size_t bufferSize );
|
||||
|
||||
void setUint32(size_t byteOffset, unsigned int val);
|
||||
void setUint16(size_t byteOffset, unsigned short val);
|
||||
void setUint8(size_t byteOffset, unsigned char val);
|
||||
void setUint32( size_t byteOffset, unsigned int val );
|
||||
void setUint16( size_t byteOffset, unsigned short val );
|
||||
void setUint8( size_t byteOffset, unsigned char val );
|
||||
|
||||
private:
|
||||
char* m_buffer;
|
||||
const size_t m_bufferSize;
|
||||
char* m_buffer;
|
||||
const size_t m_bufferSize;
|
||||
};
|
||||
|
||||
@@ -23,31 +23,27 @@
|
||||
#include "farmhash/farmhash.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4267 4307 4319 4244 4456)
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4267 4307 4319 4244 4456 )
|
||||
#endif
|
||||
|
||||
#include "farmhash/farmhash.cc"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class Checksum
|
||||
{
|
||||
public:
|
||||
static unsigned int crc(const void* data, size_t numBytes);
|
||||
static unsigned int crc( const void* data, size_t numBytes );
|
||||
};
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -57,17 +53,17 @@ public:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeCachingHashedIdFactory::Key::operator<(const Key& other) const
|
||||
bool VdeCachingHashedIdFactory::Key::operator<( const Key& other ) const
|
||||
{
|
||||
if (hashVal != other.hashVal)
|
||||
if ( hashVal != other.hashVal )
|
||||
{
|
||||
return hashVal < other.hashVal;
|
||||
}
|
||||
else if (role != other.role)
|
||||
else if ( role != other.role )
|
||||
{
|
||||
return role < other.role;
|
||||
}
|
||||
else if (elementType != other.elementType)
|
||||
else if ( elementType != other.elementType )
|
||||
{
|
||||
return elementType < other.elementType;
|
||||
}
|
||||
@@ -81,32 +77,36 @@ bool VdeCachingHashedIdFactory::Key::operator<(const Key& other) const
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeCachingHashedIdFactory::VdeCachingHashedIdFactory()
|
||||
: m_lastUsedId(-1)
|
||||
: m_lastUsedId( -1 )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForFloatArr(ArrayRole arrayRole, const void* floatArr, size_t elementCount)
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForFloatArr( ArrayRole arrayRole, const void* floatArr, size_t elementCount )
|
||||
{
|
||||
return getOrCreateIdForArrOfType(arrayRole, Float32, sizeof(float), floatArr, elementCount);
|
||||
return getOrCreateIdForArrOfType( arrayRole, Float32, sizeof( float ), floatArr, elementCount );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForUint32Arr(ArrayRole arrayRole, const unsigned int* uint32Arr, size_t elementCount)
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForUint32Arr( ArrayRole arrayRole,
|
||||
const unsigned int* uint32Arr,
|
||||
size_t elementCount )
|
||||
{
|
||||
return getOrCreateIdForArrOfType(arrayRole, Uint32, sizeof(unsigned int), uint32Arr, elementCount);
|
||||
return getOrCreateIdForArrOfType( arrayRole, Uint32, sizeof( unsigned int ), uint32Arr, elementCount );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForUint8Arr(ArrayRole arrayRole, const unsigned char* uint8Arr, size_t elementCount)
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForUint8Arr( ArrayRole arrayRole,
|
||||
const unsigned char* uint8Arr,
|
||||
size_t elementCount )
|
||||
{
|
||||
return getOrCreateIdForArrOfType(arrayRole, Uint8, sizeof(unsigned char), uint8Arr, elementCount);
|
||||
return getOrCreateIdForArrOfType( arrayRole, Uint8, sizeof( unsigned char ), uint8Arr, elementCount );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -120,22 +120,23 @@ int VdeCachingHashedIdFactory::lastAssignedId() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForArrOfType(ArrayRole arrayRole, ElementType elementType, size_t elementSizeInBytes, const void* data, size_t elementCount)
|
||||
int VdeCachingHashedIdFactory::getOrCreateIdForArrOfType(
|
||||
ArrayRole arrayRole, ElementType elementType, size_t elementSizeInBytes, const void* data, size_t elementCount )
|
||||
{
|
||||
Key key;
|
||||
key.elementType = elementType;
|
||||
key.role = arrayRole;
|
||||
key.elementType = elementType;
|
||||
key.role = arrayRole;
|
||||
key.elementCount = elementCount;
|
||||
|
||||
const size_t arraySizeInBytes = elementCount*elementSizeInBytes;
|
||||
//key.hashVal = Checksum::crc(data, arraySizeInBytes);
|
||||
//key.hashVal = farmhash::Hash32(static_cast<const char*>(data), arraySizeInBytes);
|
||||
//key.hashVal = farmhash::Hash64(static_cast<const char*>(data), arraySizeInBytes);
|
||||
//key.hashVal = farmhash::Hash128to64(farmhash::Hash128(static_cast<const char*>(data), arraySizeInBytes));
|
||||
key.hashVal = farmhash::Hash128(static_cast<const char*>(data), arraySizeInBytes);
|
||||
const size_t arraySizeInBytes = elementCount * elementSizeInBytes;
|
||||
// key.hashVal = Checksum::crc(data, arraySizeInBytes);
|
||||
// key.hashVal = farmhash::Hash32(static_cast<const char*>(data), arraySizeInBytes);
|
||||
// key.hashVal = farmhash::Hash64(static_cast<const char*>(data), arraySizeInBytes);
|
||||
// key.hashVal = farmhash::Hash128to64(farmhash::Hash128(static_cast<const char*>(data), arraySizeInBytes));
|
||||
key.hashVal = farmhash::Hash128( static_cast<const char*>( data ), arraySizeInBytes );
|
||||
|
||||
std::map<Key, int>::iterator it = m_keyToIdMap.find(key);
|
||||
if (it != m_keyToIdMap.end())
|
||||
std::map<Key, int>::iterator it = m_keyToIdMap.find( key );
|
||||
if ( it != m_keyToIdMap.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
@@ -146,103 +147,64 @@ int VdeCachingHashedIdFactory::getOrCreateIdForArrOfType(ArrayRole arrayRole, El
|
||||
|
||||
return newId;
|
||||
|
||||
//const int newId = ++m_lastUsedId;
|
||||
//return newId;
|
||||
// const int newId = ++m_lastUsedId;
|
||||
// return newId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// CRC Stuff
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
static const unsigned int crc_table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
||||
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
||||
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
|
||||
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
|
||||
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
|
||||
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
|
||||
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
|
||||
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
|
||||
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
||||
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
|
||||
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
|
||||
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
||||
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
|
||||
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
|
||||
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
|
||||
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
|
||||
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
|
||||
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
|
||||
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
||||
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
|
||||
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
|
||||
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
static const unsigned int crc_table[256] =
|
||||
{0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832,
|
||||
0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a,
|
||||
0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
||||
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab,
|
||||
0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4,
|
||||
0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074,
|
||||
0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525,
|
||||
0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
||||
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76,
|
||||
0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6,
|
||||
0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7,
|
||||
0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7,
|
||||
0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
||||
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330,
|
||||
0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
unsigned int Checksum::crc(const void* data, size_t numBytes)
|
||||
unsigned int Checksum::crc( const void* data, size_t numBytes )
|
||||
{
|
||||
unsigned int sum = 0xffffffff;
|
||||
|
||||
const unsigned char* p = reinterpret_cast<const unsigned char*>(data);
|
||||
const unsigned char* p = reinterpret_cast<const unsigned char*>( data );
|
||||
|
||||
// Compute crc
|
||||
{
|
||||
unsigned int tbl_idx;
|
||||
|
||||
while (numBytes--) {
|
||||
tbl_idx = (sum ^ *p) & 0xff;
|
||||
sum = (crc_table[tbl_idx] ^ (sum >> 8)) & 0xffffffff;
|
||||
while ( numBytes-- )
|
||||
{
|
||||
tbl_idx = ( sum ^ *p ) & 0xff;
|
||||
sum = ( crc_table[tbl_idx] ^ ( sum >> 8 ) ) & 0xffffffff;
|
||||
|
||||
p++;
|
||||
}
|
||||
@@ -252,6 +214,3 @@ unsigned int Checksum::crc(const void* data, size_t numBytes)
|
||||
|
||||
return sum ^ 0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -40,11 +39,11 @@ public:
|
||||
public:
|
||||
VdeCachingHashedIdFactory();
|
||||
|
||||
int getOrCreateIdForFloatArr(ArrayRole arrayRole, const void* floatArr, size_t elementCount);
|
||||
int getOrCreateIdForUint32Arr(ArrayRole arrayRole, const unsigned int* uint32Arr, size_t elementCount);
|
||||
int getOrCreateIdForUint8Arr(ArrayRole arrayRole, const unsigned char* uint8Arr, size_t elementCount);
|
||||
int getOrCreateIdForFloatArr( ArrayRole arrayRole, const void* floatArr, size_t elementCount );
|
||||
int getOrCreateIdForUint32Arr( ArrayRole arrayRole, const unsigned int* uint32Arr, size_t elementCount );
|
||||
int getOrCreateIdForUint8Arr( ArrayRole arrayRole, const unsigned char* uint8Arr, size_t elementCount );
|
||||
|
||||
int lastAssignedId() const;
|
||||
int lastAssignedId() const;
|
||||
|
||||
private:
|
||||
enum ElementType
|
||||
@@ -56,18 +55,19 @@ private:
|
||||
|
||||
struct Key
|
||||
{
|
||||
std::pair<uint64_t, uint64_t> hashVal;
|
||||
ArrayRole role;
|
||||
ElementType elementType;
|
||||
size_t elementCount;
|
||||
std::pair<uint64_t, uint64_t> hashVal;
|
||||
ArrayRole role;
|
||||
ElementType elementType;
|
||||
size_t elementCount;
|
||||
|
||||
bool operator<(const Key& other) const;
|
||||
bool operator<( const Key& other ) const;
|
||||
};
|
||||
|
||||
private:
|
||||
int getOrCreateIdForArrOfType(ArrayRole arrayRole, ElementType elementType, size_t elementSizeInBytes, const void* data, size_t elementCount);
|
||||
int getOrCreateIdForArrOfType(
|
||||
ArrayRole arrayRole, ElementType elementType, size_t elementSizeInBytes, const void* data, size_t elementCount );
|
||||
|
||||
private:
|
||||
std::map<Key, int> m_keyToIdMap;
|
||||
int m_lastUsedId;
|
||||
std::map<Key, int> m_keyToIdMap;
|
||||
int m_lastUsedId;
|
||||
};
|
||||
@@ -21,22 +21,22 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeExportPart::VdeExportPart(cvf::Part* part)
|
||||
: m_part(part)
|
||||
, m_sourceObjectName("Unnamed Object")
|
||||
, m_sourceObjectType(OBJ_TYPE_UNKNOWN)
|
||||
, m_color(cvf::Color3f::MAGENTA)
|
||||
, m_opacity(1.0)
|
||||
, m_winding(COUNTERCLOCKWISE)
|
||||
, m_cullFace(CF_NONE)
|
||||
, m_role(GEOMETRY)
|
||||
VdeExportPart::VdeExportPart( cvf::Part* part )
|
||||
: m_part( part )
|
||||
, m_sourceObjectName( "Unnamed Object" )
|
||||
, m_sourceObjectType( OBJ_TYPE_UNKNOWN )
|
||||
, m_color( cvf::Color3f::MAGENTA )
|
||||
, m_opacity( 1.0 )
|
||||
, m_winding( COUNTERCLOCKWISE )
|
||||
, m_cullFace( CF_NONE )
|
||||
, m_role( GEOMETRY )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setTextureImage(const cvf::TextureImage* textureImage)
|
||||
void VdeExportPart::setTextureImage( const cvf::TextureImage* textureImage )
|
||||
{
|
||||
m_textureImage = textureImage;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ void VdeExportPart::setTextureImage(const cvf::TextureImage* textureImage)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setSourceObjectType(SourceObjectType sourceObjectType)
|
||||
void VdeExportPart::setSourceObjectType( SourceObjectType sourceObjectType )
|
||||
{
|
||||
m_sourceObjectType = sourceObjectType;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void VdeExportPart::setSourceObjectType(SourceObjectType sourceObjectType)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setSourceObjectName(const QString& sourceObjectName)
|
||||
void VdeExportPart::setSourceObjectName( const QString& sourceObjectName )
|
||||
{
|
||||
m_sourceObjectName = sourceObjectName;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ void VdeExportPart::setSourceObjectName(const QString& sourceObjectName)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setSourceObjectCellSetType(const QString& sourceObjectCellSetType)
|
||||
void VdeExportPart::setSourceObjectCellSetType( const QString& sourceObjectCellSetType )
|
||||
{
|
||||
m_sourceObjectCellSetType = sourceObjectCellSetType;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ void VdeExportPart::setSourceObjectCellSetType(const QString& sourceObjectCellSe
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setColor(const cvf::Color3f& color)
|
||||
void VdeExportPart::setColor( const cvf::Color3f& color )
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ void VdeExportPart::setColor(const cvf::Color3f& color)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setOpacity(float opacity)
|
||||
void VdeExportPart::setOpacity( float opacity )
|
||||
{
|
||||
m_opacity = opacity;
|
||||
}
|
||||
@@ -84,23 +84,23 @@ void VdeExportPart::setOpacity(float opacity)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setWinding(Winding winding)
|
||||
void VdeExportPart::setWinding( Winding winding )
|
||||
{
|
||||
m_winding = winding;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setCullFace(CullFace cullFace)
|
||||
void VdeExportPart::setCullFace( CullFace cullFace )
|
||||
{
|
||||
m_cullFace = cullFace;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeExportPart::setRole(Role role)
|
||||
void VdeExportPart::setRole( Role role )
|
||||
{
|
||||
m_role = role;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ const cvf::Part* VdeExportPart::part() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const cvf::TextureImage* VdeExportPart::textureImage() const
|
||||
{
|
||||
@@ -162,7 +162,7 @@ float VdeExportPart::opacity() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeExportPart::Winding VdeExportPart::winding() const
|
||||
{
|
||||
@@ -170,7 +170,7 @@ VdeExportPart::Winding VdeExportPart::winding() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeExportPart::CullFace VdeExportPart::cullFace() const
|
||||
{
|
||||
@@ -178,7 +178,7 @@ VdeExportPart::CullFace VdeExportPart::cullFace() const
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeExportPart::Role VdeExportPart::role() const
|
||||
{
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "cvfObject.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfTextureImage.h"
|
||||
@@ -58,17 +57,17 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
VdeExportPart(cvf::Part* part);
|
||||
VdeExportPart( cvf::Part* part );
|
||||
|
||||
void setTextureImage(const cvf::TextureImage* textureImage);
|
||||
void setSourceObjectType(SourceObjectType sourceObjectType);
|
||||
void setSourceObjectName(const QString& sourceObjectName);
|
||||
void setSourceObjectCellSetType(const QString& sourceObjectCellSetType);
|
||||
void setColor(const cvf::Color3f& color);
|
||||
void setOpacity(float opacity);
|
||||
void setWinding(Winding winding);
|
||||
void setCullFace(CullFace cullFace);
|
||||
void setRole(Role role);
|
||||
void setTextureImage( const cvf::TextureImage* textureImage );
|
||||
void setSourceObjectType( SourceObjectType sourceObjectType );
|
||||
void setSourceObjectName( const QString& sourceObjectName );
|
||||
void setSourceObjectCellSetType( const QString& sourceObjectCellSetType );
|
||||
void setColor( const cvf::Color3f& color );
|
||||
void setOpacity( float opacity );
|
||||
void setWinding( Winding winding );
|
||||
void setCullFace( CullFace cullFace );
|
||||
void setRole( Role role );
|
||||
|
||||
const cvf::Part* part() const;
|
||||
const cvf::TextureImage* textureImage() const;
|
||||
|
||||
@@ -18,16 +18,14 @@
|
||||
|
||||
#include "VdeFileExporter.h"
|
||||
#include "VdeArrayDataPacket.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
#include "VdeCachingHashedIdFactory.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
|
||||
#include "cvfTrace.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -37,43 +35,47 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeFileExporter::VdeFileExporter(QString absOutputFolder)
|
||||
: m_absOutputFolder(absOutputFolder)
|
||||
VdeFileExporter::VdeFileExporter( QString absOutputFolder )
|
||||
: m_absOutputFolder( absOutputFolder )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeFileExporter::exportToFile(const QString& modelMetaJsonStr, const VdePacketDirectory& packetDirectory, const std::vector<int>& packetIdsToExport)
|
||||
bool VdeFileExporter::exportToFile( const QString& modelMetaJsonStr,
|
||||
const VdePacketDirectory& packetDirectory,
|
||||
const std::vector<int>& packetIdsToExport )
|
||||
{
|
||||
cvf::Trace::show("Exporting to folder: %s", m_absOutputFolder.toLatin1().constData());
|
||||
cvf::Trace::show( "Exporting to folder: %s", m_absOutputFolder.toLatin1().constData() );
|
||||
|
||||
QString jsonFileName = m_absOutputFolder + "/modelMeta.json";
|
||||
if (!writeModelMetaJsonFile(modelMetaJsonStr, jsonFileName))
|
||||
if ( !writeModelMetaJsonFile( modelMetaJsonStr, jsonFileName ) )
|
||||
{
|
||||
cvf::Trace::show("Error writing: %s", jsonFileName.toLatin1().constData());
|
||||
cvf::Trace::show( "Error writing: %s", jsonFileName.toLatin1().constData() );
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const int packetArrayId : packetIdsToExport)
|
||||
for ( const int packetArrayId : packetIdsToExport )
|
||||
{
|
||||
const VdeArrayDataPacket* dataPacket = packetDirectory.lookupPacket(packetArrayId);
|
||||
if (!dataPacket)
|
||||
const VdeArrayDataPacket* dataPacket = packetDirectory.lookupPacket( packetArrayId );
|
||||
if ( !dataPacket )
|
||||
{
|
||||
cvf::Trace::show("Error during export, no data for arrayId %d", packetArrayId);
|
||||
cvf::Trace::show( "Error during export, no data for arrayId %d", packetArrayId );
|
||||
return false;
|
||||
}
|
||||
|
||||
CVF_ASSERT(packetArrayId == dataPacket->arrayId());
|
||||
if (!writeDataPacketToFile(dataPacket->arrayId(), *dataPacket))
|
||||
CVF_ASSERT( packetArrayId == dataPacket->arrayId() );
|
||||
if ( !writeDataPacketToFile( dataPacket->arrayId(), *dataPacket ) )
|
||||
{
|
||||
cvf::Trace::show("Error writing packet data to file, arrayId %d", packetArrayId);
|
||||
cvf::Trace::show( "Error writing packet data to file, arrayId %d", packetArrayId );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cvf::Trace::show("Data exported (%d packets) to folder: %s", packetIdsToExport.size(), m_absOutputFolder.toLatin1().constData());
|
||||
cvf::Trace::show( "Data exported (%d packets) to folder: %s",
|
||||
packetIdsToExport.size(),
|
||||
m_absOutputFolder.toLatin1().constData() );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -81,17 +83,17 @@ bool VdeFileExporter::exportToFile(const QString& modelMetaJsonStr, const VdePac
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||
bool VdeFileExporter::exportViewContents( const RimGridView& view )
|
||||
{
|
||||
VdeCachingHashedIdFactory localIdFactory;
|
||||
VdeVizDataExtractor extractor(view, &localIdFactory);
|
||||
VdeVizDataExtractor extractor( view, &localIdFactory );
|
||||
|
||||
QString modelMetaJsonStr;
|
||||
std::vector<int> allReferencedArrayIds;
|
||||
QString modelMetaJsonStr;
|
||||
std::vector<int> allReferencedArrayIds;
|
||||
VdePacketDirectory packetDirectory;
|
||||
extractor.extractViewContents(&modelMetaJsonStr, &allReferencedArrayIds, &packetDirectory);
|
||||
extractor.extractViewContents( &modelMetaJsonStr, &allReferencedArrayIds, &packetDirectory );
|
||||
|
||||
if (!exportToFile(modelMetaJsonStr, packetDirectory, allReferencedArrayIds))
|
||||
if ( !exportToFile( modelMetaJsonStr, packetDirectory, allReferencedArrayIds ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -102,17 +104,17 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeFileExporter::writeDataPacketToFile(int arrayId, const VdeArrayDataPacket& packet) const
|
||||
bool VdeFileExporter::writeDataPacketToFile( int arrayId, const VdeArrayDataPacket& packet ) const
|
||||
{
|
||||
const QString fileName = m_absOutputFolder + QString("/arrayData_%1.bin").arg(arrayId);
|
||||
const QString fileName = m_absOutputFolder + QString( "/arrayData_%1.bin" ).arg( arrayId );
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
QFile file( fileName );
|
||||
if ( !file.open( QIODevice::WriteOnly ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.write(packet.fullPacketRawPtr(), packet.fullPacketSize()) == -1)
|
||||
if ( file.write( packet.fullPacketRawPtr(), packet.fullPacketSize() ) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -123,21 +125,20 @@ bool VdeFileExporter::writeDataPacketToFile(int arrayId, const VdeArrayDataPacke
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeFileExporter::writeModelMetaJsonFile(const QString& modelMetaJsonStr, QString fileName)
|
||||
bool VdeFileExporter::writeModelMetaJsonFile( const QString& modelMetaJsonStr, QString fileName )
|
||||
{
|
||||
const QByteArray jsonByteArr = modelMetaJsonStr.toLatin1();
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
QFile file( fileName );
|
||||
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.write(jsonByteArr) == -1)
|
||||
if ( file.write( jsonByteArr ) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ class VdePacketDirectory;
|
||||
|
||||
class RimGridView;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -37,16 +35,17 @@ class RimGridView;
|
||||
class VdeFileExporter
|
||||
{
|
||||
public:
|
||||
VdeFileExporter(QString absOutputFolder);
|
||||
VdeFileExporter( QString absOutputFolder );
|
||||
|
||||
bool exportToFile(const QString& modelMetaJsonStr, const VdePacketDirectory& packetDirectory, const std::vector<int>& packetIdsToExport);
|
||||
bool exportViewContents(const RimGridView& view);
|
||||
bool exportToFile( const QString& modelMetaJsonStr,
|
||||
const VdePacketDirectory& packetDirectory,
|
||||
const std::vector<int>& packetIdsToExport );
|
||||
bool exportViewContents( const RimGridView& view );
|
||||
|
||||
private:
|
||||
static bool writeModelMetaJsonFile(const QString& modelMetaJsonStr, QString fileName);
|
||||
bool writeDataPacketToFile(int arrayId, const VdeArrayDataPacket& packet) const;
|
||||
static bool writeModelMetaJsonFile( const QString& modelMetaJsonStr, QString fileName );
|
||||
bool writeDataPacketToFile( int arrayId, const VdeArrayDataPacket& packet ) const;
|
||||
|
||||
private:
|
||||
QString m_absOutputFolder;
|
||||
|
||||
QString m_absOutputFolder;
|
||||
};
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -30,26 +29,24 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdePacketDirectory::VdePacketDirectory()
|
||||
VdePacketDirectory::VdePacketDirectory() {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdePacketDirectory::addPacket( std::unique_ptr<VdeArrayDataPacket> packet )
|
||||
{
|
||||
const int id = packet->arrayId();
|
||||
m_idToPacketMap[id] = std::move( packet );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdePacketDirectory::addPacket(std::unique_ptr<VdeArrayDataPacket> packet)
|
||||
const VdeArrayDataPacket* VdePacketDirectory::lookupPacket( int arrayId ) const
|
||||
{
|
||||
const int id = packet->arrayId();
|
||||
m_idToPacketMap[id] = std::move(packet);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const VdeArrayDataPacket* VdePacketDirectory::lookupPacket(int arrayId) const
|
||||
{
|
||||
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find(arrayId);
|
||||
if (it == m_idToPacketMap.end())
|
||||
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find( arrayId );
|
||||
if ( it == m_idToPacketMap.end() )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -68,18 +65,18 @@ void VdePacketDirectory::clear()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdePacketDirectory::pruneUnreferencedPackets(const std::vector<int>& packetIdsInUseArr)
|
||||
void VdePacketDirectory::pruneUnreferencedPackets( const std::vector<int>& packetIdsInUseArr )
|
||||
{
|
||||
std::vector<int> sortedPacketsIdsInUse(packetIdsInUseArr);
|
||||
std::sort(sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end());
|
||||
std::vector<int> sortedPacketsIdsInUse( packetIdsInUseArr );
|
||||
std::sort( sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end() );
|
||||
|
||||
IdToPacketMap_T::const_iterator it = m_idToPacketMap.cbegin();
|
||||
while (it != m_idToPacketMap.cend())
|
||||
while ( it != m_idToPacketMap.cend() )
|
||||
{
|
||||
const int packetId = it->first;
|
||||
if (!std::binary_search(sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end(), packetId))
|
||||
if ( !std::binary_search( sortedPacketsIdsInUse.begin(), sortedPacketsIdsInUse.end(), packetId ) )
|
||||
{
|
||||
it = m_idToPacketMap.erase(it);
|
||||
it = m_idToPacketMap.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -91,21 +88,21 @@ void VdePacketDirectory::pruneUnreferencedPackets(const std::vector<int>& packet
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdePacketDirectory::getPacketsAsCombinedBuffer(const std::vector<int>& packetIdsToGet, QByteArray* combinedPacketArr) const
|
||||
bool VdePacketDirectory::getPacketsAsCombinedBuffer( const std::vector<int>& packetIdsToGet,
|
||||
QByteArray* combinedPacketArr ) const
|
||||
{
|
||||
for (const int arrayId : packetIdsToGet)
|
||||
for ( const int arrayId : packetIdsToGet )
|
||||
{
|
||||
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find(arrayId);
|
||||
if (it == m_idToPacketMap.end())
|
||||
IdToPacketMap_T::const_iterator it = m_idToPacketMap.find( arrayId );
|
||||
if ( it == m_idToPacketMap.end() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const VdeArrayDataPacket& packet = *it->second;
|
||||
*combinedPacketArr += QByteArray::fromRawData(packet.fullPacketRawPtr(), static_cast<int>(packet.fullPacketSize()));
|
||||
*combinedPacketArr += QByteArray::fromRawData( packet.fullPacketRawPtr(),
|
||||
static_cast<int>( packet.fullPacketSize() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -36,17 +35,16 @@ class VdePacketDirectory
|
||||
public:
|
||||
VdePacketDirectory();
|
||||
|
||||
void addPacket(std::unique_ptr<VdeArrayDataPacket> packet);
|
||||
const VdeArrayDataPacket* lookupPacket(int arrayId) const;
|
||||
void addPacket( std::unique_ptr<VdeArrayDataPacket> packet );
|
||||
const VdeArrayDataPacket* lookupPacket( int arrayId ) const;
|
||||
|
||||
void clear();
|
||||
void pruneUnreferencedPackets(const std::vector<int>& packetIdsInUseArr);
|
||||
void clear();
|
||||
void pruneUnreferencedPackets( const std::vector<int>& packetIdsInUseArr );
|
||||
|
||||
bool getPacketsAsCombinedBuffer(const std::vector<int>& packetIdsToGet, QByteArray* combinedPacketArr) const;
|
||||
bool getPacketsAsCombinedBuffer( const std::vector<int>& packetIdsToGet, QByteArray* combinedPacketArr ) const;
|
||||
|
||||
private:
|
||||
typedef std::map<int, std::unique_ptr<VdeArrayDataPacket>> IdToPacketMap_T;
|
||||
|
||||
IdToPacketMap_T m_idToPacketMap;
|
||||
};
|
||||
typedef std::map<int, std::unique_ptr<VdeArrayDataPacket>> IdToPacketMap_T;
|
||||
|
||||
IdToPacketMap_T m_idToPacketMap;
|
||||
};
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include "VdeVizDataExtractor.h"
|
||||
#include "VdeArrayDataPacket.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
#include "VdeCachingHashedIdFactory.h"
|
||||
#include "VdePacketDirectory.h"
|
||||
|
||||
#include "RicHoloLensExportImpl.h"
|
||||
|
||||
@@ -27,15 +27,12 @@
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfPrimitiveSet.h"
|
||||
#include "cvfTransform.h"
|
||||
#include "cvfAssert.h"
|
||||
#include "cvfTimer.h"
|
||||
#include "cvfTrace.h"
|
||||
|
||||
|
||||
|
||||
#include "cvfTransform.h"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -46,152 +43,188 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
VdeVizDataExtractor::VdeVizDataExtractor(const RimGridView& view, VdeCachingHashedIdFactory* cachingIdFactory)
|
||||
: m_view(view),
|
||||
m_cachingIdFactory(cachingIdFactory)
|
||||
VdeVizDataExtractor::VdeVizDataExtractor( const RimGridView& view, VdeCachingHashedIdFactory* cachingIdFactory )
|
||||
: m_view( view )
|
||||
, m_cachingIdFactory( cachingIdFactory )
|
||||
{
|
||||
CVF_ASSERT(m_cachingIdFactory);
|
||||
CVF_ASSERT( m_cachingIdFactory );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeVizDataExtractor::extractViewContents(QString* modelMetaJsonStr, std::vector<int>* allReferencedArrayIds, VdePacketDirectory* packetDirectory)
|
||||
void VdeVizDataExtractor::extractViewContents( QString* modelMetaJsonStr,
|
||||
std::vector<int>* allReferencedArrayIds,
|
||||
VdePacketDirectory* packetDirectory )
|
||||
{
|
||||
cvf::Timer tim;
|
||||
|
||||
// First extract the parts (cvfPart + info) to be exported from from the ResInsight view
|
||||
const std::vector<VdeExportPart> exportPartsArr = RicHoloLensExportImpl::partsForExport(m_view);
|
||||
const std::vector<VdeExportPart> exportPartsArr = RicHoloLensExportImpl::partsForExport( m_view );
|
||||
|
||||
// Convert this to an array of export ready meshes
|
||||
const std::vector<std::unique_ptr<VdeMesh> > meshArr = buildMeshArray(exportPartsArr);
|
||||
const int buildMeshes_ms = static_cast<int>(tim.lapTime()*1000);
|
||||
|
||||
const std::vector<std::unique_ptr<VdeMesh>> meshArr = buildMeshArray( exportPartsArr );
|
||||
const int buildMeshes_ms = static_cast<int>( tim.lapTime() * 1000 );
|
||||
|
||||
const size_t meshCount = meshArr.size();
|
||||
cvf::Trace::show("Analyzing and generating array packet data for %d meshes", meshCount);
|
||||
cvf::Trace::show( "Analyzing and generating array packet data for %d meshes", meshCount );
|
||||
|
||||
std::vector<VdeMeshArrayIds> allMeshesArrayIdsArr;
|
||||
size_t totNumPrimitives = 0;
|
||||
for (size_t i = 0; i < meshCount; i++)
|
||||
size_t totNumPrimitives = 0;
|
||||
for ( size_t i = 0; i < meshCount; i++ )
|
||||
{
|
||||
const VdeMesh* mesh = meshArr[i].get();
|
||||
|
||||
const size_t primCount = mesh->connArr.size()/mesh->verticesPerPrimitive;
|
||||
const size_t primCount = mesh->connArr.size() / mesh->verticesPerPrimitive;
|
||||
totNumPrimitives += primCount;
|
||||
cvf::Trace::show(" mesh %2d: primCount=%d vertsPerPrim=%d meshSourceObjName='%s' meshSourceObjType='%s'", i, primCount, mesh->verticesPerPrimitive, mesh->meshSourceObjName.toLatin1().constData(), mesh->meshSourceObjTypeStr.toLatin1().constData());
|
||||
cvf::Trace::show( " mesh %2d: primCount=%d vertsPerPrim=%d meshSourceObjName='%s' meshSourceObjType='%s'",
|
||||
i,
|
||||
primCount,
|
||||
mesh->verticesPerPrimitive,
|
||||
mesh->meshSourceObjName.toLatin1().constData(),
|
||||
mesh->meshSourceObjTypeStr.toLatin1().constData() );
|
||||
|
||||
VdeMeshArrayIds arrayIdsThisMesh;
|
||||
|
||||
{
|
||||
const float* floatArr = reinterpret_cast<const float*>(mesh->vertexArr->ptr());
|
||||
const size_t arrElementCount = 3*mesh->vertexArr->size();
|
||||
arrayIdsThisMesh.vertexArrId = m_cachingIdFactory->getOrCreateIdForFloatArr(VdeCachingHashedIdFactory::VertexArr, floatArr, arrElementCount);
|
||||
const float* floatArr = reinterpret_cast<const float*>( mesh->vertexArr->ptr() );
|
||||
const size_t arrElementCount = 3 * mesh->vertexArr->size();
|
||||
arrayIdsThisMesh.vertexArrId = m_cachingIdFactory->getOrCreateIdForFloatArr( VdeCachingHashedIdFactory::VertexArr,
|
||||
floatArr,
|
||||
arrElementCount );
|
||||
|
||||
if (!packetDirectory->lookupPacket(arrayIdsThisMesh.vertexArrId))
|
||||
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.vertexArrId ) )
|
||||
{
|
||||
cvf::Trace::show(" generating vertices, arrayId=%d", arrayIdsThisMesh.vertexArrId);
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromFloat32Arr(arrayIdsThisMesh.vertexArrId, floatArr, arrElementCount);
|
||||
cvf::Trace::show( " generating vertices, arrayId=%d", arrayIdsThisMesh.vertexArrId );
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
||||
VdeArrayDataPacket::fromFloat32Arr( arrayIdsThisMesh.vertexArrId, floatArr, arrElementCount );
|
||||
|
||||
// Debug testing of decoding
|
||||
//debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(), nullptr));
|
||||
// debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
||||
// dataPacket->fullPacketSize(), nullptr));
|
||||
|
||||
packetDirectory->addPacket(std::move(dataPacket));
|
||||
packetDirectory->addPacket( std::move( dataPacket ) );
|
||||
}
|
||||
}
|
||||
{
|
||||
const unsigned int* uintArr = mesh->connArr.data();
|
||||
const size_t arrElementCount = mesh->connArr.size();
|
||||
arrayIdsThisMesh.connArrId = m_cachingIdFactory->getOrCreateIdForUint32Arr(VdeCachingHashedIdFactory::ConnArr, uintArr, arrElementCount);
|
||||
const unsigned int* uintArr = mesh->connArr.data();
|
||||
const size_t arrElementCount = mesh->connArr.size();
|
||||
arrayIdsThisMesh.connArrId = m_cachingIdFactory->getOrCreateIdForUint32Arr( VdeCachingHashedIdFactory::ConnArr,
|
||||
uintArr,
|
||||
arrElementCount );
|
||||
|
||||
if (!packetDirectory->lookupPacket(arrayIdsThisMesh.connArrId))
|
||||
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.connArrId ) )
|
||||
{
|
||||
cvf::Trace::show(" generating connectivities, arrayId=%d", arrayIdsThisMesh.connArrId);
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromUint32Arr(arrayIdsThisMesh.connArrId, uintArr, arrElementCount);
|
||||
cvf::Trace::show( " generating connectivities, arrayId=%d", arrayIdsThisMesh.connArrId );
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromUint32Arr( arrayIdsThisMesh.connArrId,
|
||||
uintArr,
|
||||
arrElementCount );
|
||||
|
||||
// Debug testing of decoding
|
||||
//debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(), nullptr));
|
||||
// debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
||||
// dataPacket->fullPacketSize(), nullptr));
|
||||
|
||||
packetDirectory->addPacket(std::move(dataPacket));
|
||||
packetDirectory->addPacket( std::move( dataPacket ) );
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh->texCoordArr.notNull() && mesh->texImage.notNull())
|
||||
if ( mesh->texCoordArr.notNull() && mesh->texImage.notNull() )
|
||||
{
|
||||
{
|
||||
const float* floatArr = reinterpret_cast<const float*>(mesh->texCoordArr->ptr());
|
||||
const size_t arrElementCount = 2*mesh->texCoordArr->size();
|
||||
arrayIdsThisMesh.texCoordsArrId = m_cachingIdFactory->getOrCreateIdForFloatArr(VdeCachingHashedIdFactory::TexCoordsArr, floatArr, arrElementCount);
|
||||
const float* floatArr = reinterpret_cast<const float*>( mesh->texCoordArr->ptr() );
|
||||
const size_t arrElementCount = 2 * mesh->texCoordArr->size();
|
||||
arrayIdsThisMesh.texCoordsArrId = m_cachingIdFactory
|
||||
->getOrCreateIdForFloatArr( VdeCachingHashedIdFactory::TexCoordsArr,
|
||||
floatArr,
|
||||
arrElementCount );
|
||||
|
||||
if (!packetDirectory->lookupPacket(arrayIdsThisMesh.texCoordsArrId))
|
||||
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.texCoordsArrId ) )
|
||||
{
|
||||
cvf::Trace::show(" generating texture coords, arrayId=%d", arrayIdsThisMesh.texCoordsArrId);
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromFloat32Arr(arrayIdsThisMesh.texCoordsArrId, floatArr, arrElementCount);
|
||||
cvf::Trace::show( " generating texture coords, arrayId=%d", arrayIdsThisMesh.texCoordsArrId );
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
||||
VdeArrayDataPacket::fromFloat32Arr( arrayIdsThisMesh.texCoordsArrId, floatArr, arrElementCount );
|
||||
|
||||
// Debug testing of decoding
|
||||
//debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(), nullptr));
|
||||
// debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
||||
// dataPacket->fullPacketSize(), nullptr));
|
||||
|
||||
packetDirectory->addPacket(std::move(dataPacket));
|
||||
packetDirectory->addPacket( std::move( dataPacket ) );
|
||||
}
|
||||
}
|
||||
{
|
||||
cvf::ref<cvf::UByteArray> byteArr = mesh->texImage->toRgb();
|
||||
arrayIdsThisMesh.texImageArrId = m_cachingIdFactory->getOrCreateIdForUint8Arr(VdeCachingHashedIdFactory::TexImage, byteArr->ptr(), byteArr->size());
|
||||
arrayIdsThisMesh.texImageArrId = m_cachingIdFactory
|
||||
->getOrCreateIdForUint8Arr( VdeCachingHashedIdFactory::TexImage,
|
||||
byteArr->ptr(),
|
||||
byteArr->size() );
|
||||
|
||||
if (!packetDirectory->lookupPacket(arrayIdsThisMesh.texImageArrId))
|
||||
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.texImageArrId ) )
|
||||
{
|
||||
cvf::Trace::show(" generating texture image, arrayId=%d", arrayIdsThisMesh.texImageArrId);
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromUint8ImageRGBArr(arrayIdsThisMesh.texImageArrId, mesh->texImage->width(), mesh->texImage->height(), byteArr->ptr(), byteArr->size());
|
||||
cvf::Trace::show( " generating texture image, arrayId=%d", arrayIdsThisMesh.texImageArrId );
|
||||
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
||||
VdeArrayDataPacket::fromUint8ImageRGBArr( arrayIdsThisMesh.texImageArrId,
|
||||
mesh->texImage->width(),
|
||||
mesh->texImage->height(),
|
||||
byteArr->ptr(),
|
||||
byteArr->size() );
|
||||
|
||||
// Debug testing of decoding
|
||||
//debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(), nullptr));
|
||||
// debugComparePackets(*dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
||||
// dataPacket->fullPacketSize(), nullptr));
|
||||
|
||||
packetDirectory->addPacket(std::move(dataPacket));
|
||||
packetDirectory->addPacket( std::move( dataPacket ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allMeshesArrayIdsArr.push_back(arrayIdsThisMesh);
|
||||
allMeshesArrayIdsArr.push_back( arrayIdsThisMesh );
|
||||
}
|
||||
|
||||
const int fillPacketDir_ms = static_cast<int>(tim.lapTime()*1000);
|
||||
|
||||
const int fillPacketDir_ms = static_cast<int>( tim.lapTime() * 1000 );
|
||||
|
||||
// Extract any exportable labels present in the view
|
||||
const std::vector<std::pair<cvf::Vec3f, cvf::String>> labelAndPositionsArr = RicHoloLensExportImpl::labelsForExport(m_view);
|
||||
const std::vector<std::pair<cvf::Vec3f, cvf::String>> labelAndPositionsArr = RicHoloLensExportImpl::labelsForExport(
|
||||
m_view );
|
||||
|
||||
// Actually create the JSON containing model meta data
|
||||
*modelMetaJsonStr = createModelMetaJsonString(meshArr, allMeshesArrayIdsArr, labelAndPositionsArr);
|
||||
*modelMetaJsonStr = createModelMetaJsonString( meshArr, allMeshesArrayIdsArr, labelAndPositionsArr );
|
||||
|
||||
// Find all unique packet array IDs referenced
|
||||
// Find all unique packet array IDs referenced
|
||||
std::set<int> referencedIdsSet;
|
||||
for (const VdeMeshArrayIds& meshArrayIds : allMeshesArrayIdsArr)
|
||||
for ( const VdeMeshArrayIds& meshArrayIds : allMeshesArrayIdsArr )
|
||||
{
|
||||
if (meshArrayIds.vertexArrId != -1) referencedIdsSet.insert(meshArrayIds.vertexArrId);
|
||||
if (meshArrayIds.connArrId != -1) referencedIdsSet.insert(meshArrayIds.connArrId);
|
||||
if (meshArrayIds.texImageArrId != -1) referencedIdsSet.insert(meshArrayIds.texImageArrId);
|
||||
if (meshArrayIds.texCoordsArrId != -1) referencedIdsSet.insert(meshArrayIds.texCoordsArrId);
|
||||
if ( meshArrayIds.vertexArrId != -1 ) referencedIdsSet.insert( meshArrayIds.vertexArrId );
|
||||
if ( meshArrayIds.connArrId != -1 ) referencedIdsSet.insert( meshArrayIds.connArrId );
|
||||
if ( meshArrayIds.texImageArrId != -1 ) referencedIdsSet.insert( meshArrayIds.texImageArrId );
|
||||
if ( meshArrayIds.texCoordsArrId != -1 ) referencedIdsSet.insert( meshArrayIds.texCoordsArrId );
|
||||
}
|
||||
|
||||
allReferencedArrayIds->assign(referencedIdsSet.begin(), referencedIdsSet.end());
|
||||
allReferencedArrayIds->assign( referencedIdsSet.begin(), referencedIdsSet.end() );
|
||||
|
||||
RiaLogging::debug(QString("HoloLens: Extracted %1 meshes (total of %2 primitives) in %3ms (buildMeshes=%4ms, fillPacketDir=%5ms)").arg(meshCount).arg(totNumPrimitives).arg(static_cast<int>(tim.time()*1000)).arg(buildMeshes_ms).arg(fillPacketDir_ms));
|
||||
RiaLogging::debug(
|
||||
QString(
|
||||
"HoloLens: Extracted %1 meshes (total of %2 primitives) in %3ms (buildMeshes=%4ms, fillPacketDir=%5ms)" )
|
||||
.arg( meshCount )
|
||||
.arg( totNumPrimitives )
|
||||
.arg( static_cast<int>( tim.time() * 1000 ) )
|
||||
.arg( buildMeshes_ms )
|
||||
.arg( fillPacketDir_ms ) );
|
||||
|
||||
//cvf::Trace::show("Total number of primitives extracted: %d in %dms", totNumPrimitives, static_cast<int>(tim.time()*1000));
|
||||
// cvf::Trace::show("Total number of primitives extracted: %d in %dms", totNumPrimitives, static_cast<int>(tim.time()*1000));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::unique_ptr<VdeMesh> > VdeVizDataExtractor::buildMeshArray(const std::vector<VdeExportPart>& exportPartsArr)
|
||||
std::vector<std::unique_ptr<VdeMesh>> VdeVizDataExtractor::buildMeshArray( const std::vector<VdeExportPart>& exportPartsArr )
|
||||
{
|
||||
std::vector<std::unique_ptr<VdeMesh> > meshArr;
|
||||
for (const VdeExportPart& exportPart : exportPartsArr)
|
||||
std::vector<std::unique_ptr<VdeMesh>> meshArr;
|
||||
for ( const VdeExportPart& exportPart : exportPartsArr )
|
||||
{
|
||||
std::unique_ptr<VdeMesh> mesh = createMeshFromExportPart(exportPart);
|
||||
if (mesh)
|
||||
std::unique_ptr<VdeMesh> mesh = createMeshFromExportPart( exportPart );
|
||||
if ( mesh )
|
||||
{
|
||||
meshArr.push_back(std::move(mesh));
|
||||
meshArr.push_back( std::move( mesh ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,54 +234,55 @@ std::vector<std::unique_ptr<VdeMesh> > VdeVizDataExtractor::buildMeshArray(const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<VdeMesh> VdeVizDataExtractor::createMeshFromExportPart(const VdeExportPart& exportPart)
|
||||
std::unique_ptr<VdeMesh> VdeVizDataExtractor::createMeshFromExportPart( const VdeExportPart& exportPart )
|
||||
{
|
||||
//cvf::Timer tim;
|
||||
// cvf::Timer tim;
|
||||
|
||||
const cvf::Part* cvfPart = exportPart.part();
|
||||
const cvf::DrawableGeo* geo = dynamic_cast<const cvf::DrawableGeo*>(cvfPart ? cvfPart->drawable() : nullptr);
|
||||
if (!geo)
|
||||
const cvf::Part* cvfPart = exportPart.part();
|
||||
const cvf::DrawableGeo* geo = dynamic_cast<const cvf::DrawableGeo*>( cvfPart ? cvfPart->drawable() : nullptr );
|
||||
if ( !geo )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (geo->primitiveSetCount() != 1)
|
||||
if ( geo->primitiveSetCount() != 1 )
|
||||
{
|
||||
RiaLogging::debug("Only geometries with exactly one primitive set is supported");
|
||||
RiaLogging::debug( "Only geometries with exactly one primitive set is supported" );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const cvf::Vec3fArray* vertexArr = geo->vertexArray();
|
||||
const cvf::PrimitiveSet* primSet = geo->primitiveSet(0);
|
||||
if (!vertexArr || !primSet || primSet->faceCount() == 0)
|
||||
const cvf::Vec3fArray* vertexArr = geo->vertexArray();
|
||||
const cvf::PrimitiveSet* primSet = geo->primitiveSet( 0 );
|
||||
if ( !vertexArr || !primSet || primSet->faceCount() == 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Support 2 or 3 vertices per primitive
|
||||
const cvf::PrimitiveType primType = primSet->primitiveType();
|
||||
if (primType != cvf::PT_TRIANGLES && primType != cvf::PT_LINES)
|
||||
if ( primType != cvf::PT_TRIANGLES && primType != cvf::PT_LINES )
|
||||
{
|
||||
RiaLogging::debug(QString("Currently only triangle and line primitive sets are supported (saw primitive type: %1)").arg(primType));
|
||||
RiaLogging::debug(
|
||||
QString( "Currently only triangle and line primitive sets are supported (saw primitive type: %1)" )
|
||||
.arg( primType ) );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int vertsPerPrimitive = (primType == cvf::PT_TRIANGLES) ? 3 : 2;
|
||||
const int vertsPerPrimitive = ( primType == cvf::PT_TRIANGLES ) ? 3 : 2;
|
||||
|
||||
std::unique_ptr<VdeMesh> mesh(new VdeMesh);
|
||||
std::unique_ptr<VdeMesh> mesh( new VdeMesh );
|
||||
mesh->verticesPerPrimitive = vertsPerPrimitive;
|
||||
|
||||
// Possibly transform the vertices
|
||||
if (cvfPart->transform())
|
||||
if ( cvfPart->transform() )
|
||||
{
|
||||
const cvf::Mat4f m = cvf::Mat4f(cvfPart->transform()->worldTransform());
|
||||
const cvf::Mat4f m = cvf::Mat4f( cvfPart->transform()->worldTransform() );
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> transVertexArr = new cvf::Vec3fArray(*vertexArr);
|
||||
const size_t vertexCount = transVertexArr->size();
|
||||
for (size_t i = 0; i < vertexCount; i++)
|
||||
cvf::ref<cvf::Vec3fArray> transVertexArr = new cvf::Vec3fArray( *vertexArr );
|
||||
const size_t vertexCount = transVertexArr->size();
|
||||
for ( size_t i = 0; i < vertexCount; i++ )
|
||||
{
|
||||
transVertexArr->ptr(i)->transformPoint(m);
|
||||
transVertexArr->ptr( i )->transformPoint( m );
|
||||
}
|
||||
|
||||
mesh->vertexArr = transVertexArr.p();
|
||||
@@ -258,60 +292,62 @@ std::unique_ptr<VdeMesh> VdeVizDataExtractor::createMeshFromExportPart(const Vde
|
||||
mesh->vertexArr = vertexArr;
|
||||
}
|
||||
|
||||
|
||||
// Fetch connectivities
|
||||
// Using getFaceIndices() allows us to access strips and fans in the same way as triangles
|
||||
// Note that HoloLens visualization wants triangles in clockwise order so we try and fix the winding
|
||||
// This point might be moot if the HoloLens visualization always has to use two-sided lighting to get good results
|
||||
const size_t faceCount = primSet->faceCount();
|
||||
mesh->connArr.reserve(faceCount*vertsPerPrimitive);
|
||||
mesh->connArr.reserve( faceCount * vertsPerPrimitive );
|
||||
|
||||
cvf::UIntArray faceConn;
|
||||
for (size_t iface = 0; iface < faceCount; iface++)
|
||||
for ( size_t iface = 0; iface < faceCount; iface++ )
|
||||
{
|
||||
primSet->getFaceIndices(iface, &faceConn);
|
||||
primSet->getFaceIndices( iface, &faceConn );
|
||||
|
||||
if (vertsPerPrimitive == 3 && exportPart.winding() == VdeExportPart::COUNTERCLOCKWISE)
|
||||
if ( vertsPerPrimitive == 3 && exportPart.winding() == VdeExportPart::COUNTERCLOCKWISE )
|
||||
{
|
||||
// Reverse the winding
|
||||
const size_t numConn = faceConn.size();
|
||||
for (size_t i = 0; i < numConn; i++)
|
||||
for ( size_t i = 0; i < numConn; i++ )
|
||||
{
|
||||
mesh->connArr.push_back(faceConn[numConn - i - 1]);
|
||||
mesh->connArr.push_back( faceConn[numConn - i - 1] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh->connArr.insert(mesh->connArr.end(), faceConn.begin(), faceConn.end());
|
||||
mesh->connArr.insert( mesh->connArr.end(), faceConn.begin(), faceConn.end() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (exportPart.textureImage() && geo->textureCoordArray())
|
||||
if ( exportPart.textureImage() && geo->textureCoordArray() )
|
||||
{
|
||||
mesh->texCoordArr = geo->textureCoordArray();
|
||||
mesh->texImage = exportPart.textureImage();
|
||||
mesh->texImage = exportPart.textureImage();
|
||||
}
|
||||
|
||||
|
||||
QString srcObjType = "unknown";
|
||||
if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_GRID) srcObjType = "grid";
|
||||
else if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_PIPE) srcObjType = "pipe";
|
||||
if ( exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_GRID )
|
||||
srcObjType = "grid";
|
||||
else if ( exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_PIPE )
|
||||
srcObjType = "pipe";
|
||||
mesh->meshSourceObjTypeStr = srcObjType;
|
||||
|
||||
mesh->meshSourceObjName = exportPart.sourceObjectName();
|
||||
|
||||
mesh->color = exportPart.color();
|
||||
mesh->color = exportPart.color();
|
||||
mesh->opacity = exportPart.opacity();
|
||||
|
||||
if (exportPart.cullFace() != VdeExportPart::CF_NONE)
|
||||
if ( exportPart.cullFace() != VdeExportPart::CF_NONE )
|
||||
{
|
||||
if (exportPart.cullFace() == VdeExportPart::CF_FRONT) mesh->cullFaceModeStr = "front";
|
||||
else if (exportPart.cullFace() == VdeExportPart::CF_BACK) mesh->cullFaceModeStr = "back";
|
||||
else mesh->cullFaceModeStr = "none";
|
||||
if ( exportPart.cullFace() == VdeExportPart::CF_FRONT )
|
||||
mesh->cullFaceModeStr = "front";
|
||||
else if ( exportPart.cullFace() == VdeExportPart::CF_BACK )
|
||||
mesh->cullFaceModeStr = "back";
|
||||
else
|
||||
mesh->cullFaceModeStr = "none";
|
||||
}
|
||||
|
||||
//cvf::Trace::show("createMeshFromExportPart(): numFaces=%d, time=%dms", faceCount, static_cast<int>(tim.time()*1000));
|
||||
// cvf::Trace::show("createMeshFromExportPart(): numFaces=%d, time=%dms", faceCount, static_cast<int>(tim.time()*1000));
|
||||
|
||||
return mesh;
|
||||
}
|
||||
@@ -319,12 +355,15 @@ std::unique_ptr<VdeMesh> VdeVizDataExtractor::createMeshFromExportPart(const Vde
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString VdeVizDataExtractor::createModelMetaJsonString(const std::vector<std::unique_ptr<VdeMesh> >& meshArr, const std::vector<VdeMeshArrayIds>& meshContentIdsArr, const std::vector<std::pair<cvf::Vec3f, cvf::String> >& labelAndPositionsArr)
|
||||
QString VdeVizDataExtractor::createModelMetaJsonString(
|
||||
const std::vector<std::unique_ptr<VdeMesh>>& meshArr,
|
||||
const std::vector<VdeMeshArrayIds>& meshContentIdsArr,
|
||||
const std::vector<std::pair<cvf::Vec3f, cvf::String>>& labelAndPositionsArr )
|
||||
{
|
||||
QVariantList jsonMeshMetaList;
|
||||
for (size_t i = 0; i < meshArr.size(); i++)
|
||||
for ( size_t i = 0; i < meshArr.size(); i++ )
|
||||
{
|
||||
const VdeMesh* mesh = meshArr[i].get();
|
||||
const VdeMesh* mesh = meshArr[i].get();
|
||||
const VdeMeshArrayIds& meshIds = meshContentIdsArr[i];
|
||||
|
||||
QMap<QString, QVariant> jsonMeshMeta;
|
||||
@@ -332,13 +371,13 @@ QString VdeVizDataExtractor::createModelMetaJsonString(const std::vector<std::un
|
||||
jsonMeshMeta["meshSourceObjName"] = mesh->meshSourceObjName;
|
||||
|
||||
jsonMeshMeta["verticesPerPrimitive"] = mesh->verticesPerPrimitive;
|
||||
jsonMeshMeta["vertexArrId"] = meshIds.vertexArrId;
|
||||
jsonMeshMeta["connArrId"] = meshIds.connArrId;
|
||||
jsonMeshMeta["vertexArrId"] = meshIds.vertexArrId;
|
||||
jsonMeshMeta["connArrId"] = meshIds.connArrId;
|
||||
|
||||
if (meshIds.texCoordsArrId >= 0 && meshIds.texImageArrId >= 0)
|
||||
if ( meshIds.texCoordsArrId >= 0 && meshIds.texImageArrId >= 0 )
|
||||
{
|
||||
jsonMeshMeta["texCoordsArrId"] = meshIds.texCoordsArrId;
|
||||
jsonMeshMeta["texImageArrId"] = meshIds.texImageArrId;
|
||||
jsonMeshMeta["texImageArrId"] = meshIds.texImageArrId;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -352,19 +391,18 @@ QString VdeVizDataExtractor::createModelMetaJsonString(const std::vector<std::un
|
||||
|
||||
jsonMeshMeta["opacity"] = mesh->opacity;
|
||||
|
||||
if (!mesh->cullFaceModeStr.isEmpty())
|
||||
if ( !mesh->cullFaceModeStr.isEmpty() )
|
||||
{
|
||||
jsonMeshMeta["cullFaceMode"] = mesh->cullFaceModeStr;
|
||||
}
|
||||
|
||||
jsonMeshMetaList.push_back(jsonMeshMeta);
|
||||
jsonMeshMetaList.push_back( jsonMeshMeta );
|
||||
}
|
||||
|
||||
|
||||
QVariantList jsonLabelList;
|
||||
for (size_t i = 0; i < labelAndPositionsArr.size(); i++)
|
||||
for ( size_t i = 0; i < labelAndPositionsArr.size(); i++ )
|
||||
{
|
||||
const cvf::Vec3f& pos = labelAndPositionsArr[i].first;
|
||||
const cvf::Vec3f& pos = labelAndPositionsArr[i].first;
|
||||
const cvf::String& txt = labelAndPositionsArr[i].second;
|
||||
|
||||
QMap<QString, QVariant> jsonPos;
|
||||
@@ -374,37 +412,35 @@ QString VdeVizDataExtractor::createModelMetaJsonString(const std::vector<std::un
|
||||
|
||||
QMap<QString, QVariant> jsonLabelEntry;
|
||||
jsonLabelEntry["position"] = jsonPos;
|
||||
jsonLabelEntry["text"] = txt.toAscii().ptr();
|
||||
jsonLabelEntry["text"] = txt.toAscii().ptr();
|
||||
|
||||
jsonLabelList.push_back(jsonLabelEntry);
|
||||
jsonLabelList.push_back( jsonLabelEntry );
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> jsonModelMeta;
|
||||
jsonModelMeta["modelName"] = "ResInsightExport";
|
||||
jsonModelMeta["meshArr"] = jsonMeshMetaList;
|
||||
jsonModelMeta["meshArr"] = jsonMeshMetaList;
|
||||
jsonModelMeta["labelsArr"] = jsonLabelList;
|
||||
|
||||
ResInsightInternalJson::Json jsonCodec;
|
||||
const bool prettifyJson = true;
|
||||
QString jsonStr = jsonCodec.encode(jsonModelMeta, prettifyJson);
|
||||
const bool prettifyJson = true;
|
||||
QString jsonStr = jsonCodec.encode( jsonModelMeta, prettifyJson );
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void VdeVizDataExtractor::debugComparePackets(const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB)
|
||||
void VdeVizDataExtractor::debugComparePackets( const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB )
|
||||
{
|
||||
CVF_ASSERT(packetA.elementCount() == packetB.elementCount());
|
||||
CVF_ASSERT(packetA.elementSize() == packetB.elementSize());
|
||||
CVF_ASSERT(packetA.elementType() == packetB.elementType());
|
||||
CVF_ASSERT( packetA.elementCount() == packetB.elementCount() );
|
||||
CVF_ASSERT( packetA.elementSize() == packetB.elementSize() );
|
||||
CVF_ASSERT( packetA.elementType() == packetB.elementType() );
|
||||
|
||||
const char* arrA = packetA.arrayData();
|
||||
const char* arrB = packetB.arrayData();
|
||||
for (size_t i = 0; i < packetA.elementCount(); i++)
|
||||
for ( size_t i = 0; i < packetA.elementCount(); i++ )
|
||||
{
|
||||
CVF_ASSERT(arrA[i] == arrB[i]);
|
||||
CVF_ASSERT( arrA[i] == arrB[i] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "cvfColor3.h"
|
||||
#include "cvfArray.h"
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfColor3.h"
|
||||
#include "cvfString.h"
|
||||
#include "cvfTextureImage.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
@@ -36,8 +35,6 @@ class VdeCachingHashedIdFactory;
|
||||
|
||||
class RimGridView;
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -45,27 +42,27 @@ class RimGridView;
|
||||
//==================================================================================================
|
||||
struct VdeMesh
|
||||
{
|
||||
QString meshSourceObjTypeStr;
|
||||
QString meshSourceObjName;
|
||||
QString meshSourceObjTypeStr;
|
||||
QString meshSourceObjName;
|
||||
|
||||
cvf::Color3f color;
|
||||
float opacity;
|
||||
QString cullFaceModeStr; // front, back or none (or empty)
|
||||
cvf::Color3f color;
|
||||
float opacity;
|
||||
QString cullFaceModeStr; // front, back or none (or empty)
|
||||
|
||||
int verticesPerPrimitive;
|
||||
cvf::cref<cvf::Vec3fArray> vertexArr;
|
||||
cvf::cref<cvf::Vec2fArray> texCoordArr;
|
||||
std::vector<cvf::uint> connArr;
|
||||
cvf::cref<cvf::TextureImage> texImage;
|
||||
int verticesPerPrimitive;
|
||||
cvf::cref<cvf::Vec3fArray> vertexArr;
|
||||
cvf::cref<cvf::Vec2fArray> texCoordArr;
|
||||
std::vector<cvf::uint> connArr;
|
||||
cvf::cref<cvf::TextureImage> texImage;
|
||||
|
||||
VdeMesh()
|
||||
: color(1,1,1),
|
||||
opacity(1),
|
||||
verticesPerPrimitive(-1)
|
||||
{}
|
||||
: color( 1, 1, 1 )
|
||||
, opacity( 1 )
|
||||
, verticesPerPrimitive( -1 )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// The set of array IDs that are needed for a mesh
|
||||
@@ -79,14 +76,14 @@ struct VdeMeshArrayIds
|
||||
int texCoordsArrId;
|
||||
|
||||
VdeMeshArrayIds()
|
||||
: vertexArrId(-1),
|
||||
connArrId(-1),
|
||||
texImageArrId(-1),
|
||||
texCoordsArrId(-1)
|
||||
{}
|
||||
: vertexArrId( -1 )
|
||||
, connArrId( -1 )
|
||||
, texImageArrId( -1 )
|
||||
, texCoordsArrId( -1 )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -95,17 +92,21 @@ struct VdeMeshArrayIds
|
||||
class VdeVizDataExtractor
|
||||
{
|
||||
public:
|
||||
VdeVizDataExtractor(const RimGridView& view, VdeCachingHashedIdFactory* cachingIdFactory);
|
||||
VdeVizDataExtractor( const RimGridView& view, VdeCachingHashedIdFactory* cachingIdFactory );
|
||||
|
||||
void extractViewContents(QString* modelMetaJsonStr, std::vector<int>* allReferencedArrayIds, VdePacketDirectory* packetDirectory);
|
||||
void extractViewContents( QString* modelMetaJsonStr,
|
||||
std::vector<int>* allReferencedArrayIds,
|
||||
VdePacketDirectory* packetDirectory );
|
||||
|
||||
private:
|
||||
static std::vector<std::unique_ptr<VdeMesh> > buildMeshArray(const std::vector<VdeExportPart>& exportPartsArr);
|
||||
static std::unique_ptr<VdeMesh> createMeshFromExportPart(const VdeExportPart& exportPart);
|
||||
static QString createModelMetaJsonString(const std::vector<std::unique_ptr<VdeMesh> >& meshArr, const std::vector<VdeMeshArrayIds>& meshContentIdsArr, const std::vector<std::pair<cvf::Vec3f, cvf::String> >& labelAndPositionsArr);
|
||||
static void debugComparePackets(const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB);
|
||||
static std::vector<std::unique_ptr<VdeMesh>> buildMeshArray( const std::vector<VdeExportPart>& exportPartsArr );
|
||||
static std::unique_ptr<VdeMesh> createMeshFromExportPart( const VdeExportPart& exportPart );
|
||||
static QString createModelMetaJsonString( const std::vector<std::unique_ptr<VdeMesh>>& meshArr,
|
||||
const std::vector<VdeMeshArrayIds>& meshContentIdsArr,
|
||||
const std::vector<std::pair<cvf::Vec3f, cvf::String>>& labelAndPositionsArr );
|
||||
static void debugComparePackets( const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB );
|
||||
|
||||
private:
|
||||
const RimGridView& m_view;
|
||||
VdeCachingHashedIdFactory* m_cachingIdFactory;
|
||||
const RimGridView& m_view;
|
||||
VdeCachingHashedIdFactory* m_cachingIdFactory;
|
||||
};
|
||||
@@ -46,84 +46,94 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memcpy and memset
|
||||
#include <string.h> // for memcpy and memset
|
||||
#include <utility>
|
||||
|
||||
#ifndef NAMESPACE_FOR_HASH_FUNCTIONS
|
||||
#define NAMESPACE_FOR_HASH_FUNCTIONS util
|
||||
#endif
|
||||
|
||||
namespace NAMESPACE_FOR_HASH_FUNCTIONS {
|
||||
|
||||
#if defined(FARMHASH_UINT128_T_DEFINED)
|
||||
#if defined(__clang__)
|
||||
#if !defined(uint128_t)
|
||||
namespace NAMESPACE_FOR_HASH_FUNCTIONS
|
||||
{
|
||||
#if defined( FARMHASH_UINT128_T_DEFINED )
|
||||
#if defined( __clang__ )
|
||||
#if !defined( uint128_t )
|
||||
#define uint128_t __uint128_t
|
||||
#endif
|
||||
#endif
|
||||
inline uint64_t Uint128Low64(const uint128_t x) {
|
||||
return static_cast<uint64_t>(x);
|
||||
inline uint64_t Uint128Low64( const uint128_t x )
|
||||
{
|
||||
return static_cast<uint64_t>( x );
|
||||
}
|
||||
inline uint64_t Uint128High64(const uint128_t x) {
|
||||
return static_cast<uint64_t>(x >> 64);
|
||||
inline uint64_t Uint128High64( const uint128_t x )
|
||||
{
|
||||
return static_cast<uint64_t>( x >> 64 );
|
||||
}
|
||||
inline uint128_t Uint128(uint64_t lo, uint64_t hi) {
|
||||
return lo + (((uint128_t)hi) << 64);
|
||||
inline uint128_t Uint128( uint64_t lo, uint64_t hi )
|
||||
{
|
||||
return lo + ( ( (uint128_t)hi ) << 64 );
|
||||
}
|
||||
#else
|
||||
typedef std::pair<uint64_t, uint64_t> uint128_t;
|
||||
inline uint64_t Uint128Low64(const uint128_t x) { return x.first; }
|
||||
inline uint64_t Uint128High64(const uint128_t x) { return x.second; }
|
||||
inline uint128_t Uint128(uint64_t lo, uint64_t hi) { return uint128_t(lo, hi); }
|
||||
inline uint64_t Uint128Low64( const uint128_t x )
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
inline uint64_t Uint128High64( const uint128_t x )
|
||||
{
|
||||
return x.second;
|
||||
}
|
||||
inline uint128_t Uint128( uint64_t lo, uint64_t hi )
|
||||
{
|
||||
return uint128_t( lo, hi );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// BASIC STRING HASHING
|
||||
|
||||
// Hash function for a byte array.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
size_t Hash(const char* s, size_t len);
|
||||
size_t Hash( const char* s, size_t len );
|
||||
|
||||
// Hash function for a byte array. Most useful in 32-bit binaries.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint32_t Hash32(const char* s, size_t len);
|
||||
uint32_t Hash32( const char* s, size_t len );
|
||||
|
||||
// Hash function for a byte array. For convenience, a 32-bit seed is also
|
||||
// hashed into the result.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint32_t Hash32WithSeed(const char* s, size_t len, uint32_t seed);
|
||||
uint32_t Hash32WithSeed( const char* s, size_t len, uint32_t seed );
|
||||
|
||||
// Hash function for a byte array.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint64_t Hash64(const char* s, size_t len);
|
||||
uint64_t Hash64( const char* s, size_t len );
|
||||
|
||||
// Hash function for a byte array. For convenience, a 64-bit seed is also
|
||||
// hashed into the result.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint64_t Hash64WithSeed(const char* s, size_t len, uint64_t seed);
|
||||
uint64_t Hash64WithSeed( const char* s, size_t len, uint64_t seed );
|
||||
|
||||
// Hash function for a byte array. For convenience, two seeds are also
|
||||
// hashed into the result.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint64_t Hash64WithSeeds(const char* s, size_t len,
|
||||
uint64_t seed0, uint64_t seed1);
|
||||
uint64_t Hash64WithSeeds( const char* s, size_t len, uint64_t seed0, uint64_t seed1 );
|
||||
|
||||
// Hash function for a byte array.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint128_t Hash128(const char* s, size_t len);
|
||||
uint128_t Hash128( const char* s, size_t len );
|
||||
|
||||
// Hash function for a byte array. For convenience, a 128-bit seed is also
|
||||
// hashed into the result.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
uint128_t Hash128WithSeed(const char* s, size_t len, uint128_t seed);
|
||||
uint128_t Hash128WithSeed( const char* s, size_t len, uint128_t seed );
|
||||
|
||||
// BASIC NON-STRING HASHING
|
||||
|
||||
@@ -131,53 +141,56 @@ uint128_t Hash128WithSeed(const char* s, size_t len, uint128_t seed);
|
||||
// This is intended to be a reasonably good hash function.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
inline uint64_t Hash128to64(uint128_t x) {
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
|
||||
a ^= (a >> 47);
|
||||
uint64_t b = (Uint128High64(x) ^ a) * kMul;
|
||||
b ^= (b >> 47);
|
||||
b *= kMul;
|
||||
return b;
|
||||
inline uint64_t Hash128to64( uint128_t x )
|
||||
{
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t a = ( Uint128Low64( x ) ^ Uint128High64( x ) ) * kMul;
|
||||
a ^= ( a >> 47 );
|
||||
uint64_t b = ( Uint128High64( x ) ^ a ) * kMul;
|
||||
b ^= ( b >> 47 );
|
||||
b *= kMul;
|
||||
return b;
|
||||
}
|
||||
|
||||
// FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
|
||||
|
||||
// Fingerprint function for a byte array. Most useful in 32-bit binaries.
|
||||
uint32_t Fingerprint32(const char* s, size_t len);
|
||||
uint32_t Fingerprint32( const char* s, size_t len );
|
||||
|
||||
// Fingerprint function for a byte array.
|
||||
uint64_t Fingerprint64(const char* s, size_t len);
|
||||
uint64_t Fingerprint64( const char* s, size_t len );
|
||||
|
||||
// Fingerprint function for a byte array.
|
||||
uint128_t Fingerprint128(const char* s, size_t len);
|
||||
uint128_t Fingerprint128( const char* s, size_t len );
|
||||
|
||||
// This is intended to be a good fingerprinting primitive.
|
||||
// See below for more overloads.
|
||||
inline uint64_t Fingerprint(uint128_t x) {
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
|
||||
a ^= (a >> 47);
|
||||
uint64_t b = (Uint128High64(x) ^ a) * kMul;
|
||||
b ^= (b >> 44);
|
||||
b *= kMul;
|
||||
b ^= (b >> 41);
|
||||
b *= kMul;
|
||||
return b;
|
||||
inline uint64_t Fingerprint( uint128_t x )
|
||||
{
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t a = ( Uint128Low64( x ) ^ Uint128High64( x ) ) * kMul;
|
||||
a ^= ( a >> 47 );
|
||||
uint64_t b = ( Uint128High64( x ) ^ a ) * kMul;
|
||||
b ^= ( b >> 44 );
|
||||
b *= kMul;
|
||||
b ^= ( b >> 41 );
|
||||
b *= kMul;
|
||||
return b;
|
||||
}
|
||||
|
||||
// This is intended to be a good fingerprinting primitive.
|
||||
inline uint64_t Fingerprint(uint64_t x) {
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t b = x * kMul;
|
||||
b ^= (b >> 44);
|
||||
b *= kMul;
|
||||
b ^= (b >> 41);
|
||||
b *= kMul;
|
||||
return b;
|
||||
inline uint64_t Fingerprint( uint64_t x )
|
||||
{
|
||||
// Murmur-inspired hashing.
|
||||
const uint64_t kMul = 0x9ddfea08eb382d69ULL;
|
||||
uint64_t b = x * kMul;
|
||||
b ^= ( b >> 44 );
|
||||
b *= kMul;
|
||||
b ^= ( b >> 41 );
|
||||
b *= kMul;
|
||||
return b;
|
||||
}
|
||||
|
||||
#ifndef FARMHASH_NO_CXX_STRING
|
||||
@@ -191,18 +204,20 @@ inline uint64_t Fingerprint(uint64_t x) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline size_t Hash(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash(s.data(), s.length());
|
||||
inline size_t Hash( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Hash function for a byte array. Most useful in 32-bit binaries.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint32_t Hash32(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash32(s.data(), s.length());
|
||||
inline uint32_t Hash32( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash32( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Hash function for a byte array. For convenience, a 32-bit seed is also
|
||||
@@ -210,9 +225,10 @@ inline uint32_t Hash32(const Str& s) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint32_t Hash32WithSeed(const Str& s, uint32_t seed) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash32WithSeed(s.data(), s.length(), seed);
|
||||
inline uint32_t Hash32WithSeed( const Str& s, uint32_t seed )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash32WithSeed( s.data(), s.length(), seed );
|
||||
}
|
||||
|
||||
// Hash 128 input bits down to 64 bits of output.
|
||||
@@ -220,9 +236,10 @@ inline uint32_t Hash32WithSeed(const Str& s, uint32_t seed) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint64_t Hash64(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash64(s.data(), s.length());
|
||||
inline uint64_t Hash64( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash64( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Hash function for a byte array. For convenience, a 64-bit seed is also
|
||||
@@ -230,9 +247,10 @@ inline uint64_t Hash64(const Str& s) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint64_t Hash64WithSeed(const Str& s, uint64_t seed) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash64WithSeed(s.data(), s.length(), seed);
|
||||
inline uint64_t Hash64WithSeed( const Str& s, uint64_t seed )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash64WithSeed( s.data(), s.length(), seed );
|
||||
}
|
||||
|
||||
// Hash function for a byte array. For convenience, two seeds are also
|
||||
@@ -240,18 +258,20 @@ inline uint64_t Hash64WithSeed(const Str& s, uint64_t seed) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint64_t Hash64WithSeeds(const Str& s, uint64_t seed0, uint64_t seed1) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash64WithSeeds(s.data(), s.length(), seed0, seed1);
|
||||
inline uint64_t Hash64WithSeeds( const Str& s, uint64_t seed0, uint64_t seed1 )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash64WithSeeds( s.data(), s.length(), seed0, seed1 );
|
||||
}
|
||||
|
||||
// Hash function for a byte array.
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint128_t Hash128(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash128(s.data(), s.length());
|
||||
inline uint128_t Hash128( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash128( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Hash function for a byte array. For convenience, a 128-bit seed is also
|
||||
@@ -259,70 +279,75 @@ inline uint128_t Hash128(const Str& s) {
|
||||
// May change from time to time, may differ on different platforms, may differ
|
||||
// depending on NDEBUG.
|
||||
template <typename Str>
|
||||
inline uint128_t Hash128WithSeed(const Str& s, uint128_t seed) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Hash128(s.data(), s.length(), seed);
|
||||
inline uint128_t Hash128WithSeed( const Str& s, uint128_t seed )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Hash128( s.data(), s.length(), seed );
|
||||
}
|
||||
|
||||
// FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
|
||||
|
||||
// Fingerprint function for a byte array. Most useful in 32-bit binaries.
|
||||
template <typename Str>
|
||||
inline uint32_t Fingerprint32(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Fingerprint32(s.data(), s.length());
|
||||
inline uint32_t Fingerprint32( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Fingerprint32( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Fingerprint 128 input bits down to 64 bits of output.
|
||||
// Fingerprint function for a byte array.
|
||||
template <typename Str>
|
||||
inline uint64_t Fingerprint64(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Fingerprint64(s.data(), s.length());
|
||||
inline uint64_t Fingerprint64( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Fingerprint64( s.data(), s.length() );
|
||||
}
|
||||
|
||||
// Fingerprint function for a byte array.
|
||||
template <typename Str>
|
||||
inline uint128_t Fingerprint128(const Str& s) {
|
||||
assert(sizeof(s[0]) == 1);
|
||||
return Fingerprint128(s.data(), s.length());
|
||||
inline uint128_t Fingerprint128( const Str& s )
|
||||
{
|
||||
assert( sizeof( s[0] ) == 1 );
|
||||
return Fingerprint128( s.data(), s.length() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace NAMESPACE_FOR_HASH_FUNCTIONS
|
||||
} // namespace NAMESPACE_FOR_HASH_FUNCTIONS
|
||||
|
||||
/* gently define FARMHASH_BIG_ENDIAN when detected big-endian machine */
|
||||
#if defined(__BIG_ENDIAN__)
|
||||
#if !defined(FARMHASH_BIG_ENDIAN)
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#elif defined(__LITTLE_ENDIAN__)
|
||||
#if defined( __BIG_ENDIAN__ )
|
||||
#if !defined( FARMHASH_BIG_ENDIAN )
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#elif defined( __LITTLE_ENDIAN__ )
|
||||
// nothing for little-endian
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER == __ORDER_LITTLE_ENDIAN__)
|
||||
#elif defined( __BYTE_ORDER__ ) && defined( __ORDER_LITTLE_ENDIAN__ ) && ( __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ )
|
||||
// nothing for little-endian
|
||||
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER == __ORDER_BIG_ENDIAN__)
|
||||
#if !defined(FARMHASH_BIG_ENDIAN)
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#elif defined(__linux__) || defined(__CYGWIN__) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
|
||||
#include <endian.h> // libc6-dev, GLIBC
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#if !defined(FARMHASH_BIG_ENDIAN)
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__s390x__)
|
||||
#include <sys/endian.h>
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#if !defined(FARMHASH_BIG_ENDIAN)
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(_WIN32)
|
||||
#elif defined( __BYTE_ORDER__ ) && defined( __ORDER_BIG_ENDIAN__ ) && ( __BYTE_ORDER == __ORDER_BIG_ENDIAN__ )
|
||||
#if !defined( FARMHASH_BIG_ENDIAN )
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#elif defined( __linux__ ) || defined( __CYGWIN__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
|
||||
#include <endian.h> // libc6-dev, GLIBC
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#if !defined( FARMHASH_BIG_ENDIAN )
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#elif defined( __OpenBSD__ ) || defined( __NetBSD__ ) || defined( __FreeBSD__ ) || defined( __DragonFly__ ) || \
|
||||
defined( __s390x__ )
|
||||
#include <sys/endian.h>
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#if !defined( FARMHASH_BIG_ENDIAN )
|
||||
#define FARMHASH_BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#elif defined( _WIN32 )
|
||||
// Windows is (currently) little-endian
|
||||
#else
|
||||
#error "Unable to determine endianness!"
|
||||
#error "Unable to determine endianness!"
|
||||
#endif /* __BIG_ENDIAN__ */
|
||||
|
||||
#endif // FARM_HASH_H_
|
||||
#endif // FARM_HASH_H_
|
||||
Reference in new issue
Block a user