Open3D (C++ API)
ViewControlWithCustomAnimation.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
32 
33 namespace open3d {
34 namespace visualization {
35 
37 public:
39  FreeMode = 0,
41  PlayMode = 2,
42  };
43 
44 public:
45  void Reset() override;
46  void ChangeFieldOfView(double step) override;
47  void Scale(double scale) override;
48  void Rotate(double x, double y, double xo, double yo) override;
49  void Translate(double x, double y, double xo, double yo) override;
50 
52  void AddKeyFrame();
53  void UpdateKeyFrame();
54  void DeleteKeyFrame();
55  void AddSpinKeyFrames(int num_of_key_frames = 20);
57  size_t NumOfKeyFrames() const {
58  return view_trajectory_.view_status_.size();
59  }
60  size_t NumOfFrames() const { return view_trajectory_.NumOfFrames(); }
62  if (animation_mode_ == AnimationMode::FreeMode) {
64  }
65  }
66  void ChangeTrajectoryInterval(int change) {
67  if (animation_mode_ == AnimationMode::FreeMode) {
69  }
70  }
72  std::string GetStatusString() const;
73  void Step(double change);
74  void GoToFirst();
75  void GoToLast();
76  bool CaptureTrajectory(const std::string &filename = "");
77  bool LoadTrajectoryFromJsonFile(const std::string &filename);
79  const camera::PinholeCameraTrajectory &camera_trajectory);
80  bool IsPreviewing() {
81  return animation_mode_ == AnimationMode::PreviewMode;
82  }
83  bool IsPlaying() { return animation_mode_ == AnimationMode::PlayMode; }
84  bool IsPlayingEnd(size_t num) {
85  return (IsPlaying() && num >= view_trajectory_.NumOfFrames());
86  }
87  bool IsValidPinholeCameraTrajectory() const;
88 
89 protected:
90  size_t CurrentFrame() const { return (size_t)round(current_frame_); }
91  size_t CurrentKeyframe() const { return (size_t)round(current_keyframe_); }
92  double RegularizeFrameIndex(double current_frame,
93  size_t num_of_frames,
94  bool is_loop);
96 
97 protected:
98  AnimationMode animation_mode_ = AnimationMode::FreeMode;
100  double current_frame_ = 0.0;
101  double current_keyframe_ = 0.0;
102 };
103 
104 } // namespace visualization
105 } // namespace open3d
AnimationMode
Definition: ViewControlWithCustomAnimation.h:38
bool IsValidPinholeCameraTrajectory() const
Definition: ViewControlWithCustomAnimation.cpp:286
void SetViewControlFromTrajectory()
Definition: ViewControlWithCustomAnimation.cpp:326
Definition: ViewTrajectory.h:39
void AddSpinKeyFrames(int num_of_key_frames=20)
Definition: ViewControlWithCustomAnimation.cpp:142
double current_frame_
Definition: ViewControlWithCustomAnimation.h:100
bool IsPlayingEnd(size_t num)
Definition: ViewControlWithCustomAnimation.h:84
void ChangeTrajectoryInterval(int change)
Definition: ViewControlWithCustomAnimation.h:66
void ChangeInterval(int change)
Definition: ViewTrajectory.h:61
bool is_loop_
Definition: ViewTrajectory.h:90
void ClearAllKeyFrames()
Definition: ViewControlWithCustomAnimation.h:56
std::vector< ViewParameters > view_status_
Definition: ViewTrajectory.h:89
size_t NumOfKeyFrames() const
Definition: ViewControlWithCustomAnimation.h:57
void Reset() override
Definition: ViewControlWithCustomAnimation.cpp:34
void ChangeFieldOfView(double step) override
Definition: ViewControlWithCustomAnimation.cpp:40
Definition: ViewControlWithCustomAnimation.h:41
Definition: ViewControl.h:38
Definition: ViewControlWithCustomAnimation.h:40
int GetTrajectoryInterval() const
Definition: ViewControlWithCustomAnimation.h:71
Definition: PinholeCameraTrajectory.h:37
AnimationMode animation_mode_
Definition: ViewControlWithCustomAnimation.h:98
void AddKeyFrame()
Definition: ViewControlWithCustomAnimation.cpp:104
bool CaptureTrajectory(const std::string &filename="")
Definition: ViewControlWithCustomAnimation.cpp:231
std::string GetStatusString() const
Definition: ViewControlWithCustomAnimation.cpp:153
void Scale(double scale) override
Definition: ViewControlWithCustomAnimation.cpp:62
bool LoadTrajectoryFromCameraTrajectory(const camera::PinholeCameraTrajectory &camera_trajectory)
Definition: ViewControlWithCustomAnimation.cpp:258
double RegularizeFrameIndex(double current_frame, size_t num_of_frames, bool is_loop)
Definition: ViewControlWithCustomAnimation.cpp:302
void Rotate(double x, double y, double xo, double yo) override
Definition: ViewControlWithCustomAnimation.cpp:68
ViewTrajectory view_trajectory_
Definition: ViewControlWithCustomAnimation.h:99
void GoToLast()
Definition: ViewControlWithCustomAnimation.cpp:219
bool LoadTrajectoryFromJsonFile(const std::string &filename)
Definition: ViewControlWithCustomAnimation.cpp:246
int interval_
Definition: ViewTrajectory.h:91
void GoToFirst()
Definition: ViewControlWithCustomAnimation.cpp:207
Definition: ViewControlWithCustomAnimation.h:36
double current_keyframe_
Definition: ViewControlWithCustomAnimation.h:101
Definition: PinholeCameraIntrinsic.cpp:34
void UpdateKeyFrame()
Definition: ViewControlWithCustomAnimation.cpp:121
size_t CurrentFrame() const
Definition: ViewControlWithCustomAnimation.h:90
void Step(double change)
Definition: ViewControlWithCustomAnimation.cpp:189
size_t NumOfFrames() const
Definition: ViewTrajectory.h:68
void Translate(double x, double y, double xo, double yo) override
Definition: ViewControlWithCustomAnimation.cpp:77
void ToggleTrajectoryLoop()
Definition: ViewControlWithCustomAnimation.h:61
size_t NumOfFrames() const
Definition: ViewControlWithCustomAnimation.h:60
bool IsPreviewing()
Definition: ViewControlWithCustomAnimation.h:80
void DeleteKeyFrame()
Definition: ViewControlWithCustomAnimation.cpp:129
bool IsPlaying()
Definition: ViewControlWithCustomAnimation.h:83
void SetAnimationMode(AnimationMode mode)
Definition: ViewControlWithCustomAnimation.cpp:86
size_t CurrentKeyframe() const
Definition: ViewControlWithCustomAnimation.h:91
Definition: ViewControlWithCustomAnimation.h:39