[Bf-blender-cvs] [5ca4b18] alembic: Implemented alembic archive info as a stream callback and disabled popup and clipboard output.
Lukas Tönne
noreply at git.blender.org
Fri Apr 10 13:50:16 CEST 2015
Commit: 5ca4b182eb3ad1dfa5456084f348a9928b0c670a
Author: Lukas Tönne
Date: Fri Apr 10 13:48:46 2015 +0200
Branches: alembic
https://developer.blender.org/rB5ca4b182eb3ad1dfa5456084f348a9928b0c670a
Implemented alembic archive info as a stream callback and disabled
popup and clipboard output.
For a production-size archive the info string can become really large,
and putting it into a buffer takes a long time. As a debugging tool the
stdout printing is sufficient for now and can be done as a stringstream.
===================================================================
M source/blender/editors/io/io_cache_library.c
M source/blender/pointcache/PTC_api.cpp
M source/blender/pointcache/PTC_api.h
M source/blender/pointcache/alembic/abc_info.cpp
M source/blender/pointcache/alembic/abc_reader.cpp
M source/blender/pointcache/alembic/abc_reader.h
M source/blender/pointcache/alembic/alembic.h
M source/blender/pointcache/intern/reader.h
===================================================================
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index bae986b..4d0aa07 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -518,7 +518,7 @@ static void archive_info_labels(uiLayout *layout, const char *info)
ui_item_nlabel(layout, cur, linelen);
}
-static uiBlock *archive_info_popup_create(bContext *C, ARegion *ar, void *arg)
+static uiBlock *UNUSED_FUNCTION(archive_info_popup_create)(bContext *C, ARegion *ar, void *arg)
{
const char *info = arg;
uiBlock *block;
@@ -538,6 +538,11 @@ static uiBlock *archive_info_popup_create(bContext *C, ARegion *ar, void *arg)
return block;
}
+static void print_stream(void *UNUSED(userdata), const char *s)
+{
+ printf("%s", s);
+}
+
static int cache_library_archive_info_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
@@ -550,7 +555,6 @@ static int cache_library_archive_info_exec(bContext *C, wmOperator *op)
char filepath[FILE_MAX], filename[FILE_MAX];
struct PTCReaderArchive *archive;
- char *info;
RNA_string_get(op->ptr, "filepath", filepath);
if (filepath[0] == '\0')
@@ -563,25 +567,20 @@ static int cache_library_archive_info_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- info = PTC_get_archive_info(archive);
- PTC_close_reader_archive(archive);
+ if (use_stdout) {
+ PTC_get_archive_info(archive, print_stream, NULL);
+ }
- if (info) {
- if (use_stdout) {
- printf("%s", info);
- }
-
- if (use_popup) {
- UI_popup_block_invoke(C, archive_info_popup_create, info);
- }
-
- if (use_clipboard) {
- WM_clipboard_text_set(info, false);
- }
-
- MEM_freeN(info);
+ if (use_popup) {
+// UI_popup_block_invoke(C, archive_info_popup_create, info);
}
+ if (use_clipboard) {
+// WM_clipboard_text_set(info, false);
+ }
+
+ PTC_close_reader_archive(archive);
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 82346c1..6317455 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -235,12 +235,10 @@ PTCReadSampleResult PTC_test_sample(PTCReader *_reader, float frame)
return reader->test_sample(frame);
}
-char *PTC_get_archive_info(PTCReaderArchive *_archive)
+void PTC_get_archive_info(PTCReaderArchive *_archive, void (*stream)(void *, const char *), void *userdata)
{
PTC::ReaderArchive *archive = (PTC::ReaderArchive *)_archive;
-
- std::string info = archive->get_info();
- return BLI_sprintfN("%s", info.c_str());
+ archive->get_info(stream, userdata);
}
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 661dbcf..fe90241 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -80,7 +80,7 @@ bool PTC_reader_get_frame_range(struct PTCReader *reader, int *start_frame, int
PTCReadSampleResult PTC_read_sample(struct PTCReader *reader, float frame);
PTCReadSampleResult PTC_test_sample(struct PTCReader *reader, float frame);
-char *PTC_get_archive_info(struct PTCReaderArchive *archive);
+void PTC_get_archive_info(struct PTCReaderArchive *archive, void (*stream)(void *, const char *), void *userdata);
struct PTCWriter *PTC_writer_dupligroup(const char *name, struct EvaluationContext *eval_ctx, struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib);
struct PTCWriter *PTC_writer_duplicache(const char *name, struct Group *group, struct DupliCache *dupcache, int datatypes, bool do_sim_debug);
diff --git a/source/blender/pointcache/alembic/abc_info.cpp b/source/blender/pointcache/alembic/abc_info.cpp
index 7fe81bb..63e688a 100644
--- a/source/blender/pointcache/alembic/abc_info.cpp
+++ b/source/blender/pointcache/alembic/abc_info.cpp
@@ -70,12 +70,35 @@ using namespace ::Alembic::AbcGeom;
namespace PTC {
+struct stringstream {
+ stringstream(void (*cb)(void *, const char *), void *userdata) :
+ cb(cb)
+ {
+ }
+
+ void (*cb)(void *, const char *);
+ void *userdata;
+
+ template <typename T>
+ friend stringstream& operator << (stringstream &stream, T s);
+};
+
+template <typename T>
+stringstream& operator << (stringstream &stream, T s)
+{
+ std::stringstream ss;
+ ss << s;
+ stream.cb(stream.userdata, ss.str().c_str());
+ return stream;
+}
+
static const std::string g_sep(";");
+static const std::string g_endl("\n");
-static void visitProperties(std::stringstream &ss, ICompoundProperty, std::string &);
+static void visitProperties(stringstream &ss, ICompoundProperty, std::string &);
template <class PROP>
-static void visitSimpleArrayProperty(std::stringstream &ss, PROP iProp, const std::string &iIndent)
+static void visitSimpleArrayProperty(stringstream &ss, PROP iProp, const std::string &iIndent)
{
std::string ptype = "ArrayProperty ";
size_t asize = 0;
@@ -106,11 +129,11 @@ static void visitSimpleArrayProperty(std::stringstream &ss, PROP iProp, const st
ss << iIndent << " " << ptype << "name=" << iProp.getName()
<< g_sep << mdstring << g_sep << "numsamps="
- << iProp.getNumSamples() << std::endl;
+ << iProp.getNumSamples() << g_endl;
}
template <class PROP>
-static void visitSimpleScalarProperty(std::stringstream &ss, PROP iProp, const std::string &iIndent)
+static void visitSimpleScalarProperty(stringstream &ss, PROP iProp, const std::string &iIndent)
{
std::string ptype = "ScalarProperty ";
size_t asize = 0;
@@ -144,10 +167,10 @@ static void visitSimpleScalarProperty(std::stringstream &ss, PROP iProp, const s
ss << iIndent << " " << ptype << "name=" << iProp.getName()
<< g_sep << mdstring << g_sep << "numsamps="
- << iProp.getNumSamples() << std::endl;
+ << iProp.getNumSamples() << g_endl;
}
-static void visitCompoundProperty(std::stringstream &ss, ICompoundProperty iProp, std::string &ioIndent)
+static void visitCompoundProperty(stringstream &ss, ICompoundProperty iProp, std::string &ioIndent)
{
std::string oldIndent = ioIndent;
ioIndent += " ";
@@ -156,14 +179,14 @@ static void visitCompoundProperty(std::stringstream &ss, ICompoundProperty iProp
interp += iProp.getMetaData().get("schema");
ss << ioIndent << "CompoundProperty " << "name=" << iProp.getName()
- << g_sep << interp << std::endl;
+ << g_sep << interp << g_endl;
visitProperties(ss, iProp, ioIndent);
ioIndent = oldIndent;
}
-static void visitProperties(std::stringstream &ss, ICompoundProperty iParent, std::string &ioIndent )
+static void visitProperties(stringstream &ss, ICompoundProperty iParent, std::string &ioIndent )
{
std::string oldIndent = ioIndent;
for (size_t i = 0 ; i < iParent.getNumProperties() ; i++) {
@@ -184,7 +207,7 @@ static void visitProperties(std::stringstream &ss, ICompoundProperty iParent, st
ioIndent = oldIndent;
}
-static void visitObject(std::stringstream &ss, IObject iObj, std::string iIndent)
+static void visitObject(stringstream &ss, IObject iObj, std::string iIndent)
{
// Object has a name, a full name, some meta data,
// and then it has a compound property full of properties.
@@ -194,7 +217,7 @@ static void visitObject(std::stringstream &ss, IObject iObj, std::string iIndent
if (path != "/") {
ss << "Object " << "name=" << path
<< " [Instance " << iObj.instanceSourcePath() << "]"
- << std::endl;
+ << g_endl;
}
}
else if (iObj.isInstanceDescendant()) {
@@ -203,7 +226,7 @@ static void visitObject(std::stringstream &ss, IObject iObj, std::string iIndent
}
else {
if (path != "/") {
- ss << "Object " << "name=" << path << std::endl;
+ ss << "Object " << "name=" << path << g_endl;
}
// Get the properties.
@@ -217,13 +240,13 @@ static void visitObject(std::stringstream &ss, IObject iObj, std::string iIndent
}
}
-std::string abc_archive_info(IArchive &archive)
+void abc_archive_info(IArchive &archive, void (*stream)(void *, const char *), void *userdata)
{
- std::stringstream ss;
+ stringstream ss(stream, userdata);
ss << "Alembic Archive Info for "
<< Alembic::AbcCoreAbstract::GetLibraryVersion()
- << std::endl;;
+ << g_endl;
std::string appName;
std::string libraryVersionString;
@@ -238,22 +261,20 @@ std::string abc_archive_info(IArchive &archive)
userDescription);
if (appName != "") {
- ss << " file written by: " << appName << std::endl;
- ss << " using Alembic : " << libraryVersionString << std::endl;
- ss << " written on : " << whenWritten << std::endl;
- ss << " user description : " << userDescription << std::endl;
- ss << std::endl;
+ ss << " file written by: " << appName << g_endl;
+ ss << " using Alembic : " << libraryVersionString << g_endl;
+ ss << " written on : " << whenWritten << g_endl;
+ ss << " user description : " << userDescription << g_endl;
+ ss << g_endl;
}
else {
-// ss << argv[1] << std::endl;
+// ss << argv[1] << g_endl;
ss << " (file doesn't have any ArchiveInfo)"
- << std::endl;
- ss << std::endl;
+ << g_endl;
+ ss << g_endl;
}
visitObject(ss, archive.getTop(), "");
-
- return ss.str();
}
} /* namespace PTC */
diff --git a/source/blender/pointcache/alembic/abc_reader.cpp b/source/blender/pointcache/alembic/abc_reader.cpp
index 9f9f126..8729448 100644
--- a/source/blender/pointcache/alembic/abc_reader.cpp
+++ b/source/blender/pointcache/alembic/abc_reader.cpp
@@ -104,12 +104,10 @@ bool AbcReaderArchive::get_frame_range(int &start_frame, int &end_frame)
}
}
-std::string AbcReaderArchive::get_info()
+void AbcReaderArchive::get_info(void (*stream)(void *, const char *), void *userdata)
{
if (m_abc_archive)
- return abc_archive_info(m_abc_archive);
- else
- return "";
+ abc_archive_info(m_abc_archive, stream, userdata);
}
ISampleSelector AbcReaderArchive::get_frame_sample_selector(float frame)
diff --git a/source/blender/pointcache/alembic/abc_reader.h b/source/blender/pointcache/alembic/abc_reader.h
index be64893..83865a5 100644
--- a/source/blender/pointcache/alembic/abc_reader.h
+++ b/source/blender/pointcache/alembic/abc_reader.h
@@ -55,7 +55,7 @@ public:
bool get_frame_range(int &star
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list