Skip to content

Commit

Permalink
Merge branch 'devel' into qopengl
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/CMakeLists.txt
#	src/vcglib
  • Loading branch information
alemuntoni committed Aug 30, 2023
2 parents 9d1a56c + 12ea457 commit 6ec645b
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ markComment: >
limitPerRun: 10

# Limit to only `issues` or `pulls`
# only: issues
only: issues

# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
# pulls:
Expand Down
207 changes: 206 additions & 1 deletion src/meshlab/layerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,31 @@ LayerDialog::LayerDialog(QWidget *parent )
// The following connection is used to associate the click with the switch between raster and mesh view.
connect(ui->rasterTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem * , int )) , this, SLOT(rasterItemClicked(QTreeWidgetItem * , int ) ) );

// state buttons
// state and animation buttons
isRecording = false;
viewState[0] = viewState[1] = viewState[2] = viewState[3] = "";
connect(ui->bW1, SIGNAL(clicked()), this, SLOT(clickW1()));
connect(ui->bW2, SIGNAL(clicked()), this, SLOT(clickW2()));
connect(ui->bW3, SIGNAL(clicked()), this, SLOT(clickW3()));
connect(ui->bW4, SIGNAL(clicked()), this, SLOT(clickW4()));
connect(ui->animSlower, SIGNAL(clicked()), this, SLOT(clickAnimSlower()));
connect(ui->animStepBackward, SIGNAL(clicked()), this, SLOT(clickAnimStepBackward()));
connect(ui->animPlay, SIGNAL(clicked()), this, SLOT(clickAnimPlay()));
connect(ui->animStepForward, SIGNAL(clicked()), this, SLOT(clickAnimStepForward()));
connect(ui->animFaster, SIGNAL(clicked()), this, SLOT(clickAnimFaster()));
connect(ui->bV1, SIGNAL(clicked()), this, SLOT(clickV1()));
connect(ui->bV2, SIGNAL(clicked()), this, SLOT(clickV2()));
connect(ui->bV3, SIGNAL(clicked()), this, SLOT(clickV3()));
connect(ui->bV4, SIGNAL(clicked()), this, SLOT(clickV4()));

animIndex = -1;
animMsecDelay = 500;
animTimer = new QTimer(this);
resetAnim();
connect(animTimer, SIGNAL(timeout()), this, SLOT(updateAnim()));
// Make wide enough to accommodate alternate text ("||") from clickAnimPlay()
ui->animPlay->setMinimumSize(ui->animPlay->size().width() + 6, ui->animPlay->size().height());

this->setContextMenuPolicy(Qt::CustomContextMenu);
ui->meshTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->rasterTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
Expand Down Expand Up @@ -218,6 +231,61 @@ void LayerDialog::clickW4()
mw->meshDoc()->Log.log(0, "No View to Restore");
}

void LayerDialog::clickAnimSlower()
{
if (animMsecDelay < 3000)
{
animMsecDelay = int(animMsecDelay * 1.2);
}
}

void LayerDialog::clickAnimStepBackward()
{
pauseAnim();
stepAnim(-1);
}

void LayerDialog::clickAnimPlay()
{
if (!animTimer->isActive() && startAnim())
{
ui->animPlay->setText(tr("||"));
ui->animPlay->setToolTip(tr("Pause animation"));
stepAnim(1);
animTimer->start(animMsecDelay);
}
else
{
pauseAnim();
}
}

void LayerDialog::clickAnimStepForward()
{
pauseAnim();
stepAnim(1);
}

void LayerDialog::clickAnimFaster()
{
if (animMsecDelay > 10)
{
animMsecDelay = int(animMsecDelay / 1.2f);
}
}

void LayerDialog::updateAnim()
{
if (stepAnim(1) > 1)
{
animTimer->start(animMsecDelay); // Restart in case animMsecDelay changed
}
else
{
pauseAnim();
}
}

void LayerDialog::clickV1()
{
MeshDocument *md = mw->meshDoc();
Expand Down Expand Up @@ -405,6 +473,13 @@ void LayerDialog::meshItemClicked (QTreeWidgetItem * item , int col)
mw->GLA()->meshSetVisibility(*md->getMesh(clickedId), !md->getMesh(clickedId)->isVisible());
}
updatePerMeshItemVisibility();

// If not animating, or a mesh in the animation set was clicked, reset the animation
if (!ui->animPlay->isChecked() ||
std::find(animMeshIDs.begin(), animMeshIDs.end(), clickedId) != animMeshIDs.end())
{
resetAnim();
}
} break;
case 1 :

Expand Down Expand Up @@ -675,6 +750,28 @@ void LayerDialog::updateTable(const MLSceneGLSharedDataContext::PerMeshRendering
}
_docitem->addChildren(itms);

// Delete any animation IDs no longer in the layer dialog
for (auto animIter = animMeshIDs.begin(); animIter != animMeshIDs.end(); )
{
bool foundInMeshList = false;
for(MeshModel& m : md->meshIterator())
{
if (m.id() == *animIter)
{
foundInMeshList = true;
break;
}
}
if (foundInMeshList)
{
++animIter;
}
else
{
animIter = animMeshIDs.erase(animIter);
}
}

updateTreeWidgetSizes(ui->meshTreeWidget);
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
Expand Down Expand Up @@ -860,6 +957,114 @@ void LayerDialog::actionActivated(MLRenderingAction* ract)
_tabw->switchTab(ract->meshId(),ract->text());
}

bool LayerDialog::startAnim()
{
if (animMeshIDs.size() > 1)
{
return true;
}

MeshDocument *md = mw->meshDoc();
bool canAnimate = md->meshNumber() > 1;

if (canAnimate)
{
int visibleCount = 0;
for(MeshModel& m : md->meshIterator())
{
if (m.isVisible())
{
++visibleCount;
}
}
// If fewer than two meshes were visible select all meshes, else select only the visible ones
animIndex = -1;
animMeshIDs.clear();
for(MeshModel& m : md->meshIterator())
{
if (m.isVisible() && animIndex < 0)
{
animIndex = animMeshIDs.size(); // Remember first visible mesh
}
if (m.isVisible() || visibleCount < 2)
{
animMeshIDs.push_back(m.id());
}
}
if (animIndex >= 0)
{
--animIndex;
}
ui->animStepBackward->setEnabled(true);
ui->animStepForward->setEnabled(true);
}
return canAnimate;
}

// Advance the animation by the specified offset (1 = forward, -1 = backward)
int LayerDialog::stepAnim(int offset)
{
bool foundVisible = false;
int animatingCount = 0;
MeshDocument *md = mw->meshDoc();

if (md->meshNumber() > 1)
{
MeshModel* lastMP = nullptr;

while (!foundVisible && animMeshIDs.size() > 1)
{
animIndex = (animMeshIDs.size() + animIndex + offset) % animMeshIDs.size();
animatingCount = 0;
for (const auto& id : animMeshIDs)
{
for(MeshModel& m : md->meshIterator())
{
if (m.id() == id)
{
bool makeVisible = m.id() == animMeshIDs[animIndex];
mw->GLA()->meshSetVisibility(m, makeVisible);
foundVisible |= makeVisible;
++animatingCount;
lastMP = &m;
}
}
}
if (!foundVisible)
{
// The mesh being animated to was deleted; remove it from the list and try again
animMeshIDs.erase(animMeshIDs.begin() + animIndex);
animIndex -= offset;
}
}
if (animMeshIDs.size() == 1 && lastMP != nullptr)
{
mw->GLA()->meshSetVisibility(*lastMP, true);
}
updatePerMeshItemVisibility();
updatePerMeshItemSelectionStatus();
mw->GLA()->update();
}
return animatingCount;
}

void LayerDialog::pauseAnim()
{
animTimer->stop();
ui->animPlay->setChecked(false);
ui->animPlay->setText(tr(">"));
ui->animPlay->setToolTip(tr("Resume animation"));
}

void LayerDialog::resetAnim()
{
pauseAnim();
animMeshIDs.clear();
ui->animStepBackward->setEnabled(false);
ui->animStepForward->setEnabled(false);
ui->animPlay->setToolTip(tr("Animate visible meshes, or all if < 2 are visible"));
}

LayerDialog::~LayerDialog()
{
delete ui;
Expand Down
17 changes: 17 additions & 0 deletions src/meshlab/layerDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QTabWidget>
#include <QGroupBox>
#include <QCheckBox>
#include <QTimer>
#include <common/parameters/rich_parameter_list.h>
#include <common/ml_shared_data_context/ml_shared_data_context.h>
#include "ml_render_gui.h"
Expand Down Expand Up @@ -140,6 +141,12 @@ public slots:
void clickW2();
void clickW3();
void clickW4();
void clickAnimSlower();
void clickAnimStepBackward();
void clickAnimPlay();
void clickAnimStepForward();
void clickAnimFaster();
void updateAnim();
void clickV1();
void clickV2();
void clickV3();
Expand Down Expand Up @@ -177,6 +184,16 @@ private slots:
QString viewState[4];
QMap<int, bool> visibilityState[4];

int animIndex;
std::vector<int> animMeshIDs;
int animMsecDelay;
QTimer* animTimer;

bool startAnim();
int stepAnim(int offset);
void pauseAnim();
void resetAnim();

QTreeWidgetItem* _docitem;
int _previd;
QGroupBox* _renderingtabcontainer;
Expand Down
Loading

0 comments on commit 6ec645b

Please sign in to comment.