Merge pull request #237 from frederikaalund/master
Added support for heterogenous metadata on aiNodepull/246/head
commit
331158e410
|
@ -760,48 +760,33 @@ private:
|
||||||
aiMetadata* data = new aiMetadata();
|
aiMetadata* data = new aiMetadata();
|
||||||
data->mNumProperties = unparsedProperties.size() + numStaticMetaData;
|
data->mNumProperties = unparsedProperties.size() + numStaticMetaData;
|
||||||
data->mKeys = new aiString[data->mNumProperties]();
|
data->mKeys = new aiString[data->mNumProperties]();
|
||||||
data->mValues = new aiString[data->mNumProperties]();
|
data->mValues = new aiMetadataEntry[data->mNumProperties]();
|
||||||
nd.mMetaData = data;
|
nd.mMetaData = data;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// find user defined properties (3ds Max)
|
// find user defined properties (3ds Max)
|
||||||
data->mKeys[index].Set("UserProperties");
|
data->Set(index++, "UserProperties", aiString(PropertyGet<std::string>(props, "UDP3DSMAX", "")));
|
||||||
data->mValues[index].Set(PropertyGet<std::string>(props, "UDP3DSMAX", ""));
|
|
||||||
++index;
|
|
||||||
|
|
||||||
// preserve the info that a node was marked as Null node in the original file.
|
// preserve the info that a node was marked as Null node in the original file.
|
||||||
data->mKeys[index].Set("IsNull");
|
data->Set(index++, "IsNull", model.IsNull() ? true : false);
|
||||||
data->mValues[index].Set(model.IsNull() ? "true" : "false");
|
|
||||||
++index;
|
|
||||||
|
|
||||||
// add unparsed properties to the node's metadata
|
// add unparsed properties to the node's metadata
|
||||||
BOOST_FOREACH(const DirectPropertyMap::value_type& prop, unparsedProperties) {
|
BOOST_FOREACH(const DirectPropertyMap::value_type& prop, unparsedProperties) {
|
||||||
|
|
||||||
// all values are converted to strings using the following stringstream
|
|
||||||
std::stringstream ss;
|
|
||||||
bool parse_succeeded = false;
|
|
||||||
|
|
||||||
// Interpret the property as a concrete type
|
// Interpret the property as a concrete type
|
||||||
if (const TypedProperty<std::string>* interpreted = prop.second->As<TypedProperty<std::string> >())
|
if (const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >())
|
||||||
ss << interpreted->Value();
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
else if (const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >())
|
|
||||||
ss << interpreted->Value();
|
|
||||||
else if (const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >())
|
else if (const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >())
|
||||||
ss << interpreted->Value();
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
else if (const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >())
|
else if (const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >())
|
||||||
ss << interpreted->Value();
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
else if (const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >())
|
else if (const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >())
|
||||||
ss << interpreted->Value();
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
|
else if (const TypedProperty<aiString>* interpreted = prop.second->As<TypedProperty<aiString> >())
|
||||||
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
else if (const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >())
|
else if (const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >())
|
||||||
{
|
data->Set(index++, prop.first, interpreted->Value());
|
||||||
aiVector3D v = interpreted->Value();
|
else
|
||||||
ss << v.x << ";" << v.y << ";" << v.z;
|
assert(false);
|
||||||
}
|
|
||||||
|
|
||||||
// add property to meta data
|
|
||||||
data->mKeys[index].Set(prop.first);
|
|
||||||
data->mValues[index].Set(ss.str());
|
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -726,16 +726,12 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion
|
||||||
aiMetadata* data = new aiMetadata();
|
aiMetadata* data = new aiMetadata();
|
||||||
data->mNumProperties = properties.size();
|
data->mNumProperties = properties.size();
|
||||||
data->mKeys = new aiString[data->mNumProperties]();
|
data->mKeys = new aiString[data->mNumProperties]();
|
||||||
data->mValues = new aiString[data->mNumProperties]();
|
data->mValues = new aiMetadataEntry[data->mNumProperties]();
|
||||||
|
|
||||||
|
unsigned int index = 0;
|
||||||
|
BOOST_FOREACH(const Metadata::value_type& kv, properties)
|
||||||
|
data->Set(index++, kv.first, aiString(kv.second));
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
BOOST_FOREACH(const Metadata::value_type& kv, properties) {
|
|
||||||
data->mKeys[i].Set(kv.first);
|
|
||||||
if (kv.second.length() > 0) {
|
|
||||||
data->mValues[i].Set(kv.second);
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
nd->mMetaData = data;
|
nd->mMetaData = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,69 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef __AI_METADATA_H_INC__
|
#ifndef __AI_METADATA_H_INC__
|
||||||
#define __AI_METADATA_H_INC__
|
#define __AI_METADATA_H_INC__
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Enum used to distinguish data types
|
||||||
|
*/
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
enum aiMetadataType
|
||||||
|
{
|
||||||
|
AI_BOOL = 0,
|
||||||
|
AI_INT = 1,
|
||||||
|
AI_UINT64 = 2,
|
||||||
|
AI_FLOAT = 3,
|
||||||
|
AI_AISTRING = 4,
|
||||||
|
AI_AIVECTOR3D = 5,
|
||||||
|
|
||||||
|
FORCE_32BIT = INT_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Metadata entry
|
||||||
|
*
|
||||||
|
* The type field uniquely identifies the underlying type of the data field
|
||||||
|
*/
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
struct aiMetadataEntry
|
||||||
|
{
|
||||||
|
aiMetadataType mType;
|
||||||
|
void* mData;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Helper functions to get the aiType enum entry for a type
|
||||||
|
*/
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
|
||||||
|
inline aiMetadataType GetAiType( int ) { return AI_INT; }
|
||||||
|
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
|
||||||
|
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
|
||||||
|
inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; }
|
||||||
|
inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Container for holding metadata.
|
* Container for holding metadata.
|
||||||
|
@ -66,18 +125,17 @@ struct aiMetadata
|
||||||
|
|
||||||
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
||||||
* corresponding property key has no assigned value. */
|
* corresponding property key has no assigned value. */
|
||||||
C_STRUCT aiString* mValues;
|
C_STRUCT aiMetadataEntry* mValues;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
aiMetadata()
|
aiMetadata()
|
||||||
{
|
|
||||||
// set all members to zero by default
|
// set all members to zero by default
|
||||||
mKeys = NULL;
|
: mNumProperties(0)
|
||||||
mValues = NULL;
|
, mKeys(NULL)
|
||||||
mNumProperties = 0;
|
, mValues(NULL)
|
||||||
}
|
{}
|
||||||
|
|
||||||
|
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
|
@ -86,27 +144,94 @@ struct aiMetadata
|
||||||
if (mKeys)
|
if (mKeys)
|
||||||
delete [] mKeys;
|
delete [] mKeys;
|
||||||
if (mValues)
|
if (mValues)
|
||||||
|
{
|
||||||
|
// Delete each metadata entry
|
||||||
|
for (unsigned i=0; i<mNumProperties; ++i)
|
||||||
|
{
|
||||||
|
void* data = mValues[i].mData;
|
||||||
|
switch (mValues[i].mType)
|
||||||
|
{
|
||||||
|
case AI_BOOL:
|
||||||
|
delete static_cast<bool*>(data);
|
||||||
|
break;
|
||||||
|
case AI_INT:
|
||||||
|
delete static_cast<int*>(data);
|
||||||
|
break;
|
||||||
|
case AI_UINT64:
|
||||||
|
delete static_cast<uint64_t*>(data);
|
||||||
|
break;
|
||||||
|
case AI_FLOAT:
|
||||||
|
delete static_cast<float*>(data);
|
||||||
|
break;
|
||||||
|
case AI_AISTRING:
|
||||||
|
delete static_cast<aiString*>(data);
|
||||||
|
break;
|
||||||
|
case AI_AIVECTOR3D:
|
||||||
|
delete static_cast<aiVector3D*>(data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the metadata array
|
||||||
delete [] mValues;
|
delete [] mValues;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Get(const aiString& key, aiString& value)
|
|
||||||
|
template<typename T>
|
||||||
|
inline void Set( unsigned index, const std::string& key, const T& value )
|
||||||
{
|
{
|
||||||
for (unsigned i=0; i<mNumProperties; ++i) {
|
// In range assertion
|
||||||
if (mKeys[i]==key) {
|
assert(index < mNumProperties);
|
||||||
value=mValues[i];
|
|
||||||
return true;
|
// Set metadata key
|
||||||
}
|
mKeys[index] = key;
|
||||||
}
|
|
||||||
|
// Set metadata type
|
||||||
|
mValues[index].mType = GetAiType(value);
|
||||||
|
// Copy the given value to the dynamic storage
|
||||||
|
mValues[index].mData = new T(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Get( unsigned index, T& value )
|
||||||
|
{
|
||||||
|
// In range assertion
|
||||||
|
assert(index < mNumProperties);
|
||||||
|
|
||||||
|
// Return false if the output data type does
|
||||||
|
// not match the found value's data type
|
||||||
|
if (GetAiType(value) != mValues[index].mType)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Otherwise, output the found value and
|
||||||
|
// return true
|
||||||
|
value = *static_cast<T*>(mValues[index].mData);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Get( const aiString& key, T& value )
|
||||||
|
{
|
||||||
|
// Search for the given key
|
||||||
|
for (unsigned i=0; i<mNumProperties; ++i)
|
||||||
|
if (mKeys[i]==key)
|
||||||
|
return Get(i, value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool Get( const std::string& key, T& value )
|
||||||
|
{ return Get(aiString(key), value); }
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} //extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __AI_METADATA_H_INC__
|
#endif // __AI_METADATA_H_INC__
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue