- fbx: add utility functions to get object connections in sequential (i.e. insertion) order.

pull/14/head
Alexander Gessler 2012-07-03 17:57:21 +02:00
parent fd451f7ba6
commit 8a12b179a6
2 changed files with 53 additions and 0 deletions

View File

@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
#include <functional>
#include "FBXParser.h"
#include "FBXDocument.h"
#include "FBXUtil.h"
@ -612,6 +614,42 @@ LazyObject* Document::GetObject(uint64_t id) const
return it == objects.end() ? NULL : (*it).second;
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
{
std::vector<const Connection*> temp;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
ConnectionsBySource().equal_range(source);
temp.reserve(std::distance(range.first,range.second));
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
temp.push_back((*it).second);
}
std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::CompareTo));
return temp; // NRVO should handle this
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const
{
std::vector<const Connection*> temp;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
ConnectionsByDestination().equal_range(dest);
temp.reserve(std::distance(range.first,range.second));
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
temp.push_back((*it).second);
}
std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::CompareTo));
return temp; // NRVO should handle this
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc)

View File

@ -358,6 +358,17 @@ public:
return insertionOrder;
}
int CompareTo(const Connection* c) const {
// note: can't subtract because this would overflow uint64_t
if(InsertionOrder() > c->InsertionOrder()) {
return 1;
}
else if(InsertionOrder() < c->InsertionOrder()) {
return -1;
}
return 0;
}
public:
uint64_t insertionOrder;
@ -379,6 +390,7 @@ public:
typedef std::multimap<uint64_t, const Connection*> ConnectionMap;
/** DOM root for a FBX file */
class Document
{
@ -411,6 +423,9 @@ public:
return dest_connections;
}
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source) const;
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest) const;
private:
void ReadObjects();