ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qAnimationDlg.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // ##########################################################################
11 // # #
12 // # CloudViewer PLUGIN: qAnimation #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 or later of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Ryan Wicks, 2G Robotics Inc., 2015 #
24 // # #
25 // ##########################################################################
26 
27 // CV_DB_LIB
28 #include <ecvViewportParameters.h>
29 
30 // Qt
31 #include <QDialog>
32 
33 // System
34 #include <QProgressDialog>
35 #include <vector>
36 
37 #include "ui_animationDlg.h"
38 
39 class ccMesh;
40 class ccPolyline;
41 class cc2DViewportObject;
42 class QListWidgetItem;
43 #ifdef QFFMPEG_SUPPORT
44 class QVideoEncoder;
45 #endif
46 
48 class qAnimationDlg : public QDialog, public Ui::AnimationDialog {
49  Q_OBJECT
50 
51 public:
53  qAnimationDlg(QWidget* view3d, QWidget* parent = nullptr);
54 
56  virtual ~qAnimationDlg();
57 
59  bool init(const std::vector<cc2DViewportObject*>& viewports,
60  const std::vector<ccMesh*>& meshes);
61 
64  bool updateTextures() const;
65 
66 protected:
67  void onFPSChanged(int);
68  void onTotalTimeChanged(double);
69  void onStepTimeChanged(double);
70  void onLoopToggled(bool);
71  void onCurrentStepChanged(int);
72  void onBrowseButtonClicked();
74  void onAutoStepsDurationToggled(bool);
75  void onSmoothTrajectoryToggled(bool);
76  void onSmoothRatioChanged(double);
77 
78  void preview();
79  void renderAnimation() { render(false); }
80  void renderFrames() { render(true); }
81  void onAccept();
82  void onReject();
83 
84  void onItemChanged(QListWidgetItem*);
85 
86 protected: // methods
87  int getCurrentStepIndex();
88  size_t countEnabledSteps() const;
89 
90  bool smoothModeEnabled() const;
91 
92  int countFrames(size_t startIndex = 0);
93 
94  void applyViewport(const ecvViewportParameters& viewportParameters);
95 
96  double computeTotalTime();
97 
99  void updateTotalDuration();
100  bool updateCameraTrajectory();
102 
103  bool getNextSegment(size_t& vp1, size_t& vp2) const;
104 
105  void render(bool asSeparateFrames);
106 
107  bool smoothTrajectory(double ratio, unsigned iterationCount);
108 
110  struct Step {
115  double duration_sec = 0.0;
116  double length = 0.0;
118  };
119 
120  typedef std::vector<Step> Trajectory;
121  typedef std::vector<ccMesh*> MeshList;
122 
123  bool getCompressedTrajectory(Trajectory& compressedTrajectory) const;
124 
126 
127 protected: // members
133 
135  QWidget* m_view3d;
136  void textureAnimationPreview(const QStringList& texture_files,
137  QProgressDialog& progressDialog);
138  bool textureAnimationRender(const QStringList& texture_files,
139  QProgressDialog& progressDialog,
140  bool asSeparateFrames
141 #ifdef QFFMPEG_SUPPORT
142  ,
143  QScopedPointer<QVideoEncoder>& encoder
144 #endif
145  );
146 };
qAnimationDlg::Step::cameraCenter
CCVector3d cameraCenter
Definition: qAnimationDlg.h:114
qAnimationDlg::updateSmoothTrajectoryDurations
void updateSmoothTrajectoryDurations()
Definition: qAnimationDlg.cpp:412
qAnimationDlg::render
void render(bool asSeparateFrames)
Definition: qAnimationDlg.cpp:1358
qAnimationDlg::countEnabledSteps
size_t countEnabledSteps() const
Definition: qAnimationDlg.cpp:898
qAnimationDlg::renderFrames
void renderFrames()
Definition: qAnimationDlg.h:80
qAnimationDlg::onSmoothTrajectoryToggled
void onSmoothTrajectoryToggled(bool)
Definition: qAnimationDlg.cpp:711
qAnimationDlg::Step::viewportParams
ecvViewportParameters viewportParams
Definition: qAnimationDlg.h:112
qAnimationDlg::smoothTrajectory
bool smoothTrajectory(double ratio, unsigned iterationCount)
Definition: qAnimationDlg.cpp:459
qAnimationDlg::onBrowseButtonClicked
void onBrowseButtonClicked()
Definition: qAnimationDlg.cpp:864
qAnimationDlg::onBrowseTexturesButtonClicked
void onBrowseTexturesButtonClicked()
Definition: qAnimationDlg.cpp:882
qAnimationDlg::textureAnimationPreview
void textureAnimationPreview(const QStringList &texture_files, QProgressDialog &progressDialog)
Definition: qAnimationDlg.cpp:1203
qAnimationDlg::Step::length
double length
Definition: qAnimationDlg.h:116
qAnimationDlg::Step::duration_sec
double duration_sec
Definition: qAnimationDlg.h:115
ecvViewportParameters
Standard parameters for GL displays/viewports.
Definition: ecvViewportParameters.h:18
qAnimationDlg::updateTotalDuration
void updateTotalDuration()
Definition: qAnimationDlg.cpp:1644
qAnimationDlg::onCurrentStepChanged
void onCurrentStepChanged(int)
Definition: qAnimationDlg.cpp:1667
qAnimationDlg::Step::indexInSmoothTrajectory
int indexInSmoothTrajectory
Definition: qAnimationDlg.h:117
qAnimationDlg::countFrames
int countFrames(size_t startIndex=0)
Definition: qAnimationDlg.cpp:961
qAnimationDlg::applyViewport
void applyViewport(const ecvViewportParameters &viewportParameters)
Definition: qAnimationDlg.cpp:754
qAnimationDlg::onSmoothRatioChanged
void onSmoothRatioChanged(double)
Definition: qAnimationDlg.cpp:719
qAnimationDlg::~qAnimationDlg
virtual ~qAnimationDlg()
Destrcuctor.
Definition: qAnimationDlg.cpp:236
qAnimationDlg::Step::indexInOriginalTrajectory
int indexInOriginalTrajectory
Definition: qAnimationDlg.h:113
qAnimationDlg::m_smoothVideoSteps
Trajectory m_smoothVideoSteps
Smoothed animation.
Definition: qAnimationDlg.h:131
qAnimationDlg::MeshList
std::vector< ccMesh * > MeshList
Definition: qAnimationDlg.h:121
qAnimationDlg::updateCurrentStepDuration
void updateCurrentStepDuration()
Definition: qAnimationDlg.cpp:1652
qAnimationDlg::exportTrajectoryOnExit
bool exportTrajectoryOnExit()
Definition: qAnimationDlg.cpp:730
qAnimationDlg::onLoopToggled
void onLoopToggled(bool)
Definition: qAnimationDlg.cpp:1693
Vector3Tpl< double >
qAnimationDlg::Trajectory
std::vector< Step > Trajectory
Definition: qAnimationDlg.h:120
qAnimationDlg::computeTotalTime
double computeTotalTime()
Definition: qAnimationDlg.cpp:734
qAnimationDlg::m_view3d
QWidget * m_view3d
Associated 3D view.
Definition: qAnimationDlg.h:135
cc2DViewportObject
2D viewport object
Definition: ecv2DViewportObject.h:15
ecvViewportParameters.h
qAnimationDlg::getCompressedTrajectory
bool getCompressedTrajectory(Trajectory &compressedTrajectory) const
Definition: qAnimationDlg.cpp:987
qAnimationDlg::onFPSChanged
void onFPSChanged(int)
Definition: qAnimationDlg.cpp:762
qAnimationDlg::Step::viewport
cc2DViewportObject * viewport
Definition: qAnimationDlg.h:111
qAnimationDlg
Dialog for qAnimation plugin.
Definition: qAnimationDlg.h:48
qAnimationDlg::renderAnimation
void renderAnimation()
Definition: qAnimationDlg.h:79
qAnimationDlg::updateTextures
bool updateTextures() const
Definition: qAnimationDlg.cpp:242
qAnimationDlg::onItemChanged
void onItemChanged(QListWidgetItem *)
Definition: qAnimationDlg.cpp:1661
qAnimationDlg::preview
void preview()
Definition: qAnimationDlg.cpp:1011
qAnimationDlg::onAccept
void onAccept()
Definition: qAnimationDlg.cpp:325
qAnimationDlg::getTrajectory
ccPolyline * getTrajectory()
Definition: qAnimationDlg.cpp:725
qAnimationDlg::onTotalTimeChanged
void onTotalTimeChanged(double)
Definition: qAnimationDlg.cpp:766
qAnimationDlg::m_videoSteps
Trajectory m_videoSteps
Animation.
Definition: qAnimationDlg.h:129
qAnimationDlg::onStepTimeChanged
void onStepTimeChanged(double)
Definition: qAnimationDlg.cpp:849
qAnimationDlg::qAnimationDlg
qAnimationDlg(QWidget *view3d, QWidget *parent=nullptr)
Default constructor.
Definition: qAnimationDlg.cpp:82
qAnimationDlg::init
bool init(const std::vector< cc2DViewportObject * > &viewports, const std::vector< ccMesh * > &meshes)
Initialize the dialog with a set of viewports.
Definition: qAnimationDlg.cpp:246
qAnimationDlg::updateCameraTrajectory
bool updateCameraTrajectory()
Definition: qAnimationDlg.cpp:367
ccMesh
Triangular mesh.
Definition: ecvMesh.h:35
qAnimationDlg::getNextSegment
bool getNextSegment(size_t &vp1, size_t &vp2) const
Definition: qAnimationDlg.cpp:910
qAnimationDlg::Step
Simple step (viewport + time)
Definition: qAnimationDlg.h:110
qAnimationDlg::onAutoStepsDurationToggled
void onAutoStepsDurationToggled(bool)
Definition: qAnimationDlg.cpp:621
qAnimationDlg::onReject
void onReject()
Definition: qAnimationDlg.cpp:323
qAnimationDlg::updateSmoothCameraTrajectory
bool updateSmoothCameraTrajectory()
Definition: qAnimationDlg.cpp:590
qAnimationDlg::textureAnimationRender
bool textureAnimationRender(const QStringList &texture_files, QProgressDialog &progressDialog, bool asSeparateFrames)
Definition: qAnimationDlg.cpp:1258
qAnimationDlg::getCurrentStepIndex
int getCurrentStepIndex()
Definition: qAnimationDlg.cpp:750
qAnimationDlg::m_mesh_list
MeshList m_mesh_list
Definition: qAnimationDlg.h:132
qAnimationDlg::smoothModeEnabled
bool smoothModeEnabled() const
Definition: qAnimationDlg.cpp:238
ccPolyline
Colored polyline.
Definition: ecvPolyline.h:23