[Bf-blender-cvs] [74aec79] alembic_pointcache: Utility class for mapping Blender frames to a generic time scale. This is used by writers and readers to convert frame numbers into time values for the Alembic time sampling methods.

Lukas Tönne noreply at git.blender.org
Thu Oct 16 16:53:43 CEST 2014


Commit: 74aec79e0a63f24f558d19b7aec1b501e4537443
Author: Lukas Tönne
Date:   Fri Nov 29 13:47:54 2013 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB74aec79e0a63f24f558d19b7aec1b501e4537443

Utility class for mapping Blender frames to a generic time scale.
This is used by writers and readers to convert frame numbers into time
values for the Alembic time sampling methods.

===================================================================

M	source/blender/pointcache/CMakeLists.txt
M	source/blender/pointcache/intern/reader.cpp
M	source/blender/pointcache/intern/reader.h
M	source/blender/pointcache/intern/writer.cpp
M	source/blender/pointcache/intern/writer.h
A	source/blender/pointcache/util/util_frame_mapper.cpp
A	source/blender/pointcache/util/util_frame_mapper.h

===================================================================

diff --git a/source/blender/pointcache/CMakeLists.txt b/source/blender/pointcache/CMakeLists.txt
index 78753e6..b0681c6 100644
--- a/source/blender/pointcache/CMakeLists.txt
+++ b/source/blender/pointcache/CMakeLists.txt
@@ -37,6 +37,8 @@ set(INC_SYS
 )
 
 set(SRC
+	util/util_frame_mapper.h
+	util/util_frame_mapper.cpp
 	util/util_path.h
 	util/util_path.cpp
 
diff --git a/source/blender/pointcache/intern/reader.cpp b/source/blender/pointcache/intern/reader.cpp
index c5c29e2..ad6c9bb 100644
--- a/source/blender/pointcache/intern/reader.cpp
+++ b/source/blender/pointcache/intern/reader.cpp
@@ -30,6 +30,7 @@ namespace PTC {
 using namespace Abc;
 
 Reader::Reader(const std::string &filename, Scene *scene) :
+    FrameMapper(scene),
     m_scene(scene)
 {
 	m_archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, ErrorHandler::kThrowPolicy);
@@ -41,14 +42,11 @@ Reader::~Reader()
 
 void Reader::get_frame_range(int &start_frame, int &end_frame)
 {
-	if (m_scene->r.frs_sec_base == 0.0f) {
-		/* Should never happen, just to be safe */
-		start_frame = end_frame = 1;
-		return;
-	}
-	
 	double start_time, end_time;
 	GetArchiveStartAndEndTime(m_archive, start_time, end_time);
+	start_frame = time_to_frame(start_time);
+	end_frame = time_to_frame(end_time);
+}
 	
 	double fps = (double)m_scene->r.frs_sec / (double)m_scene->r.frs_sec_base;
 	start_frame = start_time * fps;
diff --git a/source/blender/pointcache/intern/reader.h b/source/blender/pointcache/intern/reader.h
index 61c39a9..69ae954 100644
--- a/source/blender/pointcache/intern/reader.h
+++ b/source/blender/pointcache/intern/reader.h
@@ -23,13 +23,15 @@
 
 #include <Alembic/Abc/IArchive.h>
 
+#include "util/util_frame_mapper.h"
+
 struct Scene;
 
 namespace PTC {
 
 using namespace Alembic;
 
-class Reader {
+class Reader : public FrameMapper {
 public:
 	Reader(const std::string &filename, Scene *scene);
 	virtual ~Reader();
diff --git a/source/blender/pointcache/intern/writer.cpp b/source/blender/pointcache/intern/writer.cpp
index 2d298ec..972d516 100644
--- a/source/blender/pointcache/intern/writer.cpp
+++ b/source/blender/pointcache/intern/writer.cpp
@@ -40,6 +40,7 @@ static void ensure_directory(const char *filename)
 }
 
 Writer::Writer(const std::string &filename, Scene *scene) :
+    FrameMapper(scene),
     m_scene(scene)
 {
 	ensure_directory(filename.c_str());
@@ -52,14 +53,7 @@ Writer::~Writer()
 
 uint32_t Writer::add_frame_sampling()
 {
-	if (m_scene->r.frs_sec == 0.0f) {
-		/* Should never happen, just to be safe
-		 * Index 0 is the default time sampling with a step of 1.0
-		 */
-		return 0;
-	}
-	
-	chrono_t cycle_time = (double)m_scene->r.frs_sec_base / (double)m_scene->r.frs_sec;
+	chrono_t cycle_time = seconds_per_frame();
 	chrono_t start_time = 0.0f;
 	return m_archive.addTimeSampling(TimeSampling(cycle_time, start_time));
 }
diff --git a/source/blender/pointcache/intern/writer.h b/source/blender/pointcache/intern/writer.h
index b502fab..3066e16 100644
--- a/source/blender/pointcache/intern/writer.h
+++ b/source/blender/pointcache/intern/writer.h
@@ -23,13 +23,15 @@
 
 #include <Alembic/Abc/OArchive.h>
 
+#include "util/util_frame_mapper.h"
+
 struct Scene;
 
 namespace PTC {
 
 using namespace Alembic;
 
-class Writer {
+class Writer : public FrameMapper {
 public:
 	Writer(const std::string &filename, Scene *scene);
 	virtual ~Writer();
diff --git a/source/blender/pointcache/intern/writer.h b/source/blender/pointcache/util/util_frame_mapper.cpp
similarity index 53%
copy from source/blender/pointcache/intern/writer.h
copy to source/blender/pointcache/util/util_frame_mapper.cpp
index b502fab..132390c 100644
--- a/source/blender/pointcache/intern/writer.h
+++ b/source/blender/pointcache/util/util_frame_mapper.cpp
@@ -16,34 +16,36 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef PTC_WRITER_H
-#define PTC_WRITER_H
+#include "util_frame_mapper.h"
 
-#include <string>
+extern "C" {
+#include "DNA_scene_types.h"
+}
 
-#include <Alembic/Abc/OArchive.h>
+namespace PTC {
 
-struct Scene;
+using Alembic::AbcCoreAbstract::chrono_t;
 
-namespace PTC {
+FrameMapper::FrameMapper(double fps)
+{
+	m_frames_per_sec = fps;
+	m_sec_per_frame = (fps == 0.0 ? 0.0 : 1.0/fps);
+}
 
-using namespace Alembic;
-
-class Writer {
-public:
-	Writer(const std::string &filename, Scene *scene);
-	virtual ~Writer();
-	
-	uint32_t add_frame_sampling();
-	
-	virtual void write_sample() = 0;
-	
-protected:
-	Abc::OArchive m_archive;
-	
-	Scene *m_scene;
-};
+FrameMapper::FrameMapper(Scene *scene)
+{
+	m_frames_per_sec = (scene->r.frs_sec_base == 0.0f ? 0.0 : (double)scene->r.frs_sec / (double)scene->r.frs_sec_base);
+	m_sec_per_frame = (scene->r.frs_sec == 0.0f ? 0.0 : (double)scene->r.frs_sec_base / (double)scene->r.frs_sec);
+}
 
-} /* namespace PTC */
+chrono_t FrameMapper::frame_to_time(float frame) const
+{
+	return (double)(frame - 1.0f) * m_sec_per_frame;
+}
 
-#endif  /* PTC_WRITER_H */
+float FrameMapper::time_to_frame(chrono_t time) const
+{
+	return (float)(time * m_frames_per_sec) + 1.0f;
+}
+
+} /* namespace PTC */
diff --git a/source/blender/pointcache/intern/reader.h b/source/blender/pointcache/util/util_frame_mapper.h
similarity index 61%
copy from source/blender/pointcache/intern/reader.h
copy to source/blender/pointcache/util/util_frame_mapper.h
index 61c39a9..1c6bca0 100644
--- a/source/blender/pointcache/intern/reader.h
+++ b/source/blender/pointcache/util/util_frame_mapper.h
@@ -16,34 +16,32 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef PTC_READER_H
-#define PTC_READER_H
+#ifndef PTC_UTIL_FRAME_MAPPER_H
+#define PTC_UTIL_FRAME_MAPPER_H
 
-#include <string>
-
-#include <Alembic/Abc/IArchive.h>
+#include <Alembic/AbcCoreAbstract/Foundation.h>
 
 struct Scene;
 
 namespace PTC {
 
-using namespace Alembic;
+using Alembic::AbcCoreAbstract::chrono_t;
 
-class Reader {
+class FrameMapper {
 public:
-	Reader(const std::string &filename, Scene *scene);
-	virtual ~Reader();
-	
-	void get_frame_range(int &start_frame, int &end_frame);
+	FrameMapper(double fps);
+	FrameMapper(Scene *scene);
 	
-	virtual void read_sample() = 0;
+	double frames_per_second() const { return m_frames_per_sec; }
+	double seconds_per_frame() const { return m_sec_per_frame; }
 	
-protected:
-	Abc::IArchive m_archive;
+	chrono_t frame_to_time(float frame) const;
+	float time_to_frame(chrono_t time) const;
 	
-	Scene *m_scene;
+private:
+	double m_frames_per_sec, m_sec_per_frame;
 };
 
 } /* namespace PTC */
 
-#endif  /* PTC_READER_H */
+#endif  /* PTC_UTIL_FRAME_MAPPER_H */




More information about the Bf-blender-cvs mailing list