Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: handle string attributes #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/houio/HouGeo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ namespace houio
virtual void getPacking( std::vector<int> &packing )const;
virtual int getNumElements()const;
virtual std::string getString( int index )const;
virtual std::string getUniqueString( int index )const;
virtual int getStringIndex( int index )const;
virtual std::vector<std::string> getUniqueStrings()const;
virtual std::vector<int> getStringIndices()const;



virtual RawPointer::Ptr getRawPointer();

//int addV4f(math::V4f value);
Expand All @@ -44,8 +51,9 @@ namespace houio
Storage m_storage;
Type m_type;
//std::vector<char> data;
std::vector<std::string> strings; // used in case of type==string
int numElements;
std::vector<std::string> strings; // used in case of type==string
std::vector<int> stringsIdxs; // used in case of type==string
int numElements;

Attribute::Ptr m_attr; // primitives::Attribute
};
Expand Down
4 changes: 4 additions & 0 deletions include/houio/HouGeoAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ namespace houio
virtual int getNumElements()const;
virtual RawPointer::Ptr getRawPointer();
virtual std::string getString( int index )const=0;
virtual std::string getUniqueString( int index )const=0;
virtual int getStringIndex( int index )const=0;
virtual std::vector<std::string> getUniqueStrings()const=0;
virtual std::vector<int> getStringIndices()const=0;
static Type type( const std::string &typeName );
static Storage storage( const std::string &storageName );
static int storageSize( Storage storage );
Expand Down
67 changes: 54 additions & 13 deletions src/HouGeo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,43 @@ namespace houio
m_type = ATTR_TYPE_STRING;
//attr->storage = attrStorage;
tupleSize = 1;

// TODO : handle indices
return numElements++;
}

std::string HouGeo::HouAttribute::getString( int index )const
std::string HouGeo::HouAttribute::getUniqueString( int index )const
{
if(strings.size() < index)
throw std::runtime_error("HouGeo::getString Index is out of strings range.");
return strings[index];
}

std::string HouGeo::HouAttribute::getString( int index )const
{
if(stringsIdxs.size() < index)
throw std::runtime_error("HouGeo::getString Index is out of strings range.");
const int string_index = stringsIdxs[index];
return strings[string_index];
}

int HouGeo::HouAttribute::getStringIndex( int index )const
{
if(stringsIdxs.size() < index)
throw std::runtime_error("HouGeo::getStringIndex Index is out of stringsIdx range.");
return stringsIdxs[index];
}

std::vector<std::string> HouGeo::HouAttribute::getUniqueStrings()const
{
return strings;
}

std::vector<int> HouGeo::HouAttribute::getStringIndices()const
{
return stringsIdxs;
}




Expand Down Expand Up @@ -390,13 +419,12 @@ namespace houio
json::ArrayPtr entries = o->getArray("sharedprimitivedata");

int numEntries = (int)entries->size()/2;
int index = 0;
for( int i=0;i<numEntries;++i )
{
int index = i*2;
std::string type_questionmark = entries->get<std::string>(index);
index = i*2;
json::ArrayPtr entry = entries->getArray(index+1);

std::string type2_questionmark = entry->get<std::string>(0);
std::string id = entry->get<std::string>(1);
json::ArrayPtr data = entry->getArray(2);

Expand Down Expand Up @@ -583,22 +611,35 @@ namespace houio
}else
if( attrType == AttributeAdapter::ATTR_TYPE_STRING )
{
attr->m_name = attrName;
attr->m_type = attrType;
attr->tupleSize = 1;

if( attrData->hasKey("strings") )
{
json::ArrayPtr stringsArray = attrData->getArray("strings");
int numElements = stringsArray->size();
std::string stringValue = "";
for( int i=0;i<numElements;++i )
{
std::string string = stringsArray->get<std::string>( i );
attr->strings.push_back(string);
//qDebug() << QString::fromStdString(string);
stringValue = stringsArray->get<std::string>( i );
attr->strings.push_back(stringValue);
}
attr->numElements = numElements;
}

attr->m_name = attrName;
attr->m_type = attrType;
//attr->storage = attrStorage;
attr->tupleSize = 1;
if( attrData->hasKey("indices") )
{
json::ObjectPtr indicesObject = toObject(attrData->getArray("indices"));
json::ArrayPtr indices = indicesObject->getArray("rawpagedata");
int numElements = indices->size();
int index = 0;
for( int i=0;i<numElements;++i )
{
index = indices->get<int>(i);
attr->stringsIdxs.push_back(index);
}
attr->numElements = numElements;
}
}

Expand Down Expand Up @@ -886,7 +927,7 @@ namespace houio
{
return field->sample(i, j, k);
}

math::Vec3i HouGeo::HouVolume::getResolution()const
{
return field->getResolution();
Expand Down Expand Up @@ -994,7 +1035,7 @@ namespace houio







Expand Down