Skip to content

Commit

Permalink
Gui: add support of selection context
Browse files Browse the repository at this point in the history
The patch implements context-aware selection and rendering in 3D view.

Please check [here](https://git.io/fjiY5) for more details, including
the following 'Render Caching' section.

The patch also includes modification of View3DInventorViewer to support
always-on-top selection rendering using the secondary selection context
and the new coin node SoFCPathAnnotation.

Another small change in SoQtQuarterAdaptor for more responsive frame
rate display. The original implementation reports skewed frame rate
in the presence of long idle period.
  • Loading branch information
realthunder authored and wwmayer committed Aug 17, 2019
1 parent 49b6944 commit c744157
Show file tree
Hide file tree
Showing 25 changed files with 3,476 additions and 933 deletions.
2 changes: 2 additions & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -1022,6 +1022,7 @@ SET(Inventor_CPP_SRCS
SoFCOffscreenRenderer.cpp
SoFCSelection.cpp
SoFCUnifiedSelection.cpp
SoFCSelectionContext.cpp
SoFCSelectionAction.cpp
SoFCVectorizeSVGAction.cpp
SoFCVectorizeU3DAction.cpp
Expand All @@ -1047,6 +1048,7 @@ SET(Inventor_SRCS
SoFCOffscreenRenderer.h
SoFCSelection.h
SoFCUnifiedSelection.h
SoFCSelectionContext.h
SoFCSelectionAction.h
SoFCVectorizeSVGAction.h
SoFCVectorizeU3DAction.h
Expand Down
33 changes: 33 additions & 0 deletions src/Gui/DlgSettings3DView.ui
Expand Up @@ -145,6 +145,39 @@ will be shown at the lower left in opened files</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="renderCacheLabel">
<property name="text">
<string>Render cache</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="renderCache">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Auto</string>
</property>
</item>
<item>
<property name="text">
<string>Distributed</string>
</property>
</item>
<item>
<property name="text">
<string>Centralized</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_UseAutoRotation">
<property name="enabled">
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/DlgSettings3DViewImp.cpp
Expand Up @@ -88,6 +88,9 @@ void DlgSettings3DViewImp::saveSettings()
index = this->naviCubeCorner->currentIndex();
hGrp->SetInt("CornerNaviCube", index);

index = this->renderCache->currentIndex();
hGrp->SetInt("RenderCache", index);

QVariant const &vBoxMarkerSize = this->boxMarkerSize->itemData(this->boxMarkerSize->currentIndex());
hGrp->SetInt("MarkerSize", vBoxMarkerSize.toInt());

Expand Down Expand Up @@ -158,6 +161,9 @@ void DlgSettings3DViewImp::loadSettings()
index = hGrp->GetInt("CornerNaviCube", 1);
naviCubeCorner->setCurrentIndex(index);

index = hGrp->GetInt("RenderCache", 0);
renderCache->setCurrentIndex(index);

int const current = hGrp->GetInt("MarkerSize", 9L);
this->boxMarkerSize->addItem(tr("5px"), QVariant(5));
this->boxMarkerSize->addItem(tr("7px"), QVariant(7));
Expand Down
29 changes: 17 additions & 12 deletions src/Gui/Quarter/SoQTQuarterAdaptor.cpp
Expand Up @@ -714,32 +714,37 @@ bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::processSoEvent(const SoEvent* eve
*/
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent(QPaintEvent* event)
{
double start = SbTime::getTimeOfDay().getValue();
QuarterWidget::paintEvent(event);

this->framesPerSecond = addFrametime(SbTime::getTimeOfDay().getValue());
this->framesPerSecond = addFrametime(start);
}

void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetFrameCounter(void)
{
this->framecount = 0;
this->frames.assign(100, 0.0f);
this->totaldraw = 0.0f;
this->frametime = 0.0f;
this->drawtime = 0.0f;
this->starttime = SbTime::getTimeOfDay().getValue();
this->framesPerSecond = SbVec2f(0, 0);
}

SbVec2f SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFrametime(double timeofday)
SbVec2f SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFrametime(double starttime)
{
int framearray_size = 100;
this->framecount++;

int arrayptr = (this->framecount - 1) % framearray_size;
double timeofday = SbTime::getTimeOfDay().getValue();

// draw time is the actual time spent on rendering
double drawtime = timeofday - starttime;
#define FPS_FACTOR 0.7
this->drawtime = (drawtime*FPS_FACTOR) + this->drawtime*(1.0-FPS_FACTOR);

double renderTime = timeofday - this->starttime;
this->totaldraw += (float(renderTime) - this->frames[arrayptr]);
float drawfps = this->totaldraw / std::min<int>(this->framecount, framearray_size);
// frame time is the time spent since the last frame. There could an
// indefinite pause between the last frame because the scene is not
// changing. So we limit the skew to 5 second.
double frametime = std::min(timeofday-this->starttime, std::max(drawtime,5000.0));
this->frametime = (frametime*FPS_FACTOR) + this->frametime*(1.0-FPS_FACTOR);

this->frames[arrayptr] = static_cast<float>(renderTime);
this->starttime = timeofday;
return SbVec2f(1000 * drawfps, 1.0f / drawfps);
return SbVec2f(1000 * this->drawtime, 1.0f / this->frametime);
}
5 changes: 2 additions & 3 deletions src/Gui/Quarter/SoQTQuarterAdaptor.h
Expand Up @@ -117,9 +117,8 @@ class QUARTER_DLL_API SoQTQuarterAdaptor : public QuarterWidget {
SoCallbackList m_interactionStartCallback;
SoCallbackList m_interactionEndCallback;

// Keep track of the frames-per-second counter.
std::vector<float> frames;
float totaldraw;
double frametime;
double drawtime;
double starttime;
int framecount;

Expand Down
20 changes: 15 additions & 5 deletions src/Gui/SceneInspector.cpp
Expand Up @@ -25,6 +25,7 @@
#ifndef _PreComp_
# include <Inventor/nodes/SoSeparator.h>
# include <QHeaderView>
# include <QTextStream>
#endif

#include "SceneInspector.h"
Expand Down Expand Up @@ -102,12 +103,21 @@ void SceneModel::setNode(QModelIndex index, SoNode* node)
setNode(this->index(i, 0, index), child);

QHash<SoNode*, QString>::iterator it = nodeNames.find(child);
if (it != nodeNames.end()) {
this->setData(this->index(i, 1, index), QVariant(it.value()));
}
else {
this->setData(this->index(i, 1, index), QVariant(QString::fromLatin1(child->getName())));
QString name;
QTextStream stream(&name);
stream << child << ", ";
if(child->isOfType(SoSwitch::getClassTypeId())) {
auto pcSwitch = static_cast<SoSwitch*>(child);
stream << pcSwitch->whichChild.getValue() << ", ";
} else if (child->isOfType(SoSeparator::getClassTypeId())) {
auto pcSeparator = static_cast<SoSeparator*>(child);
stream << pcSeparator->renderCaching.getValue() << ", ";
}
if (it != nodeNames.end())
stream << it.value();
else
stream << child->getName();
this->setData(this->index(i, 1, index), QVariant(name));
}
}
// insert icon
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/SoFCDB.cpp
Expand Up @@ -122,6 +122,9 @@ void Gui::SoFCDB::init()
MarkerBitmaps ::initClass();
SoFCCSysDragger ::initClass();
SmSwitchboard ::initClass();
SoFCSeparator ::initClass();
SoFCSelectionRoot ::initClass();
SoFCPathAnnotation ::initClass();

PropertyItem ::init();
PropertySeparatorItem ::init();
Expand Down Expand Up @@ -203,6 +206,9 @@ void Gui::SoFCDB::finish()
SoFCSelectionColorAction ::finish();
SoUpdateVBOAction ::finish();
SoFCHighlightColorAction ::finish();
SoFCSeparator ::finish();
SoFCSelectionRoot ::finish();
SoFCPathAnnotation ::finish();

storage->unref();
storage = nullptr;
Expand Down
11 changes: 11 additions & 0 deletions src/Gui/SoFCInteractiveElement.cpp
Expand Up @@ -23,6 +23,7 @@

#include "PreCompiled.h"

#include <Inventor/elements/SoOverrideElement.h>
#include "SoFCInteractiveElement.h"

using namespace Gui;
Expand Down Expand Up @@ -248,6 +249,16 @@ void SoGLVBOActivatedElement::get(SoState * state, SbBool& active)
const SoGLVBOActivatedElement* self = static_cast<const SoGLVBOActivatedElement *>
(SoElement::getConstElement(state, classStackIndex));
active = self->active;
if(active) {
uint32_t flags = SoOverrideElement::getFlags(state);
if(flags & (SoOverrideElement::COLOR_INDEX|
SoOverrideElement::DIFFUSE_COLOR|
SoOverrideElement::MATERIAL_BINDING|
SoOverrideElement::TRANSPARENCY|
SoOverrideElement::NORMAL_VECTOR|
SoOverrideElement::NORMAL_BINDING))
active = false;
}
}

void SoGLVBOActivatedElement::push(SoState * state)
Expand Down

0 comments on commit c744157

Please sign in to comment.