00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <vrs/sg/interactiontechnique.h>
00023 #include <vrs/image/avimaker.h>
00024
00025 #ifndef VRS_SG_CAMERAPATHEDITOR_H
00026 #define VRS_SG_CAMERAPATHEDITOR_H
00027
00028 namespace VRS {
00029
00030 class Callback;
00031 class CameraPathRecorder;
00032
00033 class KeyFrame;
00034
00040
00047 class VRS_CORE_API CameraPathEditor : public InteractionTechnique {
00048 public:
00049
00062 CameraPathEditor(
00063 SO<CameraPathRecorder> recorder,
00064 const std::string& cameraPathFileName = "cameraPath.txt",
00065 const std::string& imageSequenceDirectory = "video/",
00066 unsigned int imageSequenceWidth = 768,
00067 unsigned int imageSequenceHeight = 576,
00068 unsigned int imageSequenceFramesPerSecond = 25
00069 );
00070
00072 static const Vector UpVector;
00073
00075 static const KeyFunctionID AppendKeyFrame;
00076 static const KeyFunctionID AppendKeyFrameAbsolute;
00077 static const KeyFunctionID AppendKeyFrameAtEnd;
00078 static const KeyFunctionID NextKeyFrame;
00079 static const KeyFunctionID PrevKeyFrame;
00080 static const KeyFunctionID ClearAll;
00081 static const KeyFunctionID CursorToStartKeyFrame;
00082 static const KeyFunctionID CursorToEndStartKeyFrame;
00083 static const KeyFunctionID GotoKeyFrame;
00084 static const KeyFunctionID OverwriteKeyFrame;
00085 static const KeyFunctionID OverwriteKeyFrameAbsolute;
00086 static const KeyFunctionID DeleteKeyFrame;
00087 static const KeyFunctionID RenameKeyFrame;
00088 static const KeyFunctionID LoadKeyFrames;
00089 static const KeyFunctionID SaveKeyFrames;
00090 static const KeyFunctionID MarkAsCircleKeyFrame;
00091 static const KeyFunctionID PlayFromCursor;
00092 static const KeyFunctionID StopPlaying;
00093 static const KeyFunctionID SetPathTime;
00094 static const KeyFunctionID SetDefaultSpeed;
00095 static const KeyFunctionID SetSpeedMark;
00096 static const KeyFunctionID ExportCameraPathRecorderFile;
00097 static const KeyFunctionID ExportImageSequence;
00098 static const KeyFunctionID PrintKeyAssignments;
00099 static const KeyFunctionID PrintLookAt;
00100
00101
00106 void appendKeyFrame(const Vector& from, const Vector& dirOrTo, bool isLookTo = false);
00107
00109 int keyFrames() const;
00110
00115 int keyFrameCursor() const;
00116 void setKeyFrameCursor(int pos);
00117
00119 void gotoKeyFrame();
00120
00122 void overwriteKeyFrame(const Vector& from, const Vector& dirOrTo, bool isLookTo = false);
00123
00125 void deleteKeyFrame();
00126 void clear();
00127
00129 void renameKeyFrame(const std::string& name);
00130
00132 std::string getKeyFrameName();
00133
00136 void setKeyFrameFile(const std::string& name);
00137 std::string getKeyFrameFile() const;
00138 void loadKeyFrames();
00139 void saveKeyFrames() const;
00140
00142 void setImageSequenceDirectory(const std::string& name);
00143 std::string getImageSequenceDirectory() const;
00144 void setImageSequenceSize(unsigned int width, unsigned int height);
00145 unsigned int getImageSequenceWidth() const;
00146 unsigned int getImageSequenceHeight() const;
00148 void setImageSequenceFramerate(unsigned int fps);
00149 unsigned int getImageSequenceFramerate() const;
00150
00158 void markAsCircleKeyFrame(const Vector& target, int minimumRotations = 0);
00159 void unmarkCircleKeyFrame();
00160
00165 void playFromCursor();
00166
00168 void stopPlaying();
00169
00171 bool isActive();
00172
00176 void setDefaultSpeed(double speed);
00177 double getDefaultSpeed() const;
00178
00189 void setSpeedMark(double speedFactor, bool startSpeedChange, double relativeAcceleration);
00190 void removeSpeedMark();
00191
00193 virtual void onKey(SO<VRS::KeyEvent> event, KeyFunctionID id);
00194
00196 void printKeyAssignments() const;
00197
00199 virtual void onTimer(SO<TimeEvent> event, double secondsSinceLastTimeEvent);
00200
00201
00202
00203 virtual void onEventPassive(SO<Event> e, bool modeActive);
00204
00208 void createCameraPath() const;
00209
00212 double getPathLength() const;
00213
00215 double getPathDuration() const;
00216
00217 void recordCameraPath();
00218
00219 void recordVideo(const std::string& filename, unsigned int sizeX, unsigned int sizeY, int framesPerSecond, bool highQuality = false, VRS::VideoCompressor* compressor = NULL);
00220
00221
00222 void recordVideo(const std::string& targetFilename, const std::string& targetDirectory, const std::string& targetFormat,
00223 unsigned int sizeX, unsigned int sizeY, int framesPerSecond, VRS::VideoCompressor* compressor = NULL);
00224
00226 void setPathDuration(double targetTime);
00227
00229 int getCircleTurns(unsigned int index);
00230
00231
00232 struct VRS_CORE_API CameraPoint {
00233 Vector lookFrom;
00234 Vector lookTo;
00235 Vector lookUp;
00236
00237 double summedDistance;
00238 bool isKeyframe;
00239 VRS_SERIALIZABLE_NO_SO_CLASS(CameraPoint);
00240 };
00241
00242
00243 struct VRS_CORE_API KeyFrame {
00244 KeyFrame(const Vector& from, const Vector& dir);
00245 KeyFrame();
00246 Vector m_from;
00247 Vector m_dir;
00248 bool m_isSpeedMark;
00249 double m_relativeSpeed;
00250 bool m_startSpeedChange;
00251 double m_relativeAcceleration;
00252 bool m_isCircleEntry;
00253 Vector m_circleMidpoint;
00254 int m_circlePasses;
00255 std::string m_name;
00256 bool m_dirIsLookTo;
00257 VRS_SERIALIZABLE_NO_SO_CLASS(KeyFrame);
00258 };
00259
00261 SO<Array<KeyFrame>> keyFramesList(){return m_keyFrames;}
00262
00264 KeyFrame* keyFrame(unsigned int id);
00265
00267 void pathNotValid(){m_pathValid = false; }
00268
00270 CameraPoint getKeyFrame(unsigned int id);
00271
00274 virtual void registerPathStoppedCallback(VRS::SO<VRS::Callback> callback);
00275 virtual void unregisterPathStoppedCallback(VRS::SO<VRS::Callback> callback);
00276
00277 VRS_TYPEINFO(CameraPathEditor, InteractionTechnique);
00278 VRS_SERIALIZABLE(CameraPathEditor);
00279 private:
00280
00281 CameraPathEditor();
00282
00283
00284
00285 SO<Array<KeyFrame> > m_keyFrames;
00286 int m_currentKeyFrame;
00287 SO<CameraPathRecorder> m_recorder;
00288 std::string m_keyFrameFile;
00289 std::string m_imageSequenceDirectory;
00290 unsigned int m_imageSequenceWidth;
00291 unsigned int m_imageSequenceHeight;
00292 unsigned int m_imageSequenceFramerate;
00293 double m_defaultSpeed;
00294
00295
00296
00297 bool m_playing;
00298 double m_elapsedTime;
00299 double startTime_;
00300 unsigned int renderedFrames_;
00301 std::string m_cameraPathFile;
00302
00303
00304 mutable SO<Iterator<double> > m_keyFrame2Time;
00305 mutable double m_pathLength;
00306 mutable bool m_pathValid;
00307
00308 void printKey(KeyFunctionID id, const std::string& text) const;
00309
00310 SO<Iterator<double> > computeTimeStamps(SO<Iterator<CameraPoint> > cpoints);
00311
00312 VRS::SO<VRS::Array<VRS::SO<VRS::Callback> > > m_pathStoppedCallbacks;
00313 };
00314
00315
00316
00317
00318 }
00319
00320 #endif // VRS_SG_CAMERAPATHEDITOR_H