diff --git a/include/houio/HouGeo.h b/include/houio/HouGeo.h index 7849855..67b5af6 100644 --- a/include/houio/HouGeo.h +++ b/include/houio/HouGeo.h @@ -34,6 +34,13 @@ namespace houio virtual void getPacking( std::vector &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 getUniqueStrings()const; + virtual std::vector getStringIndices()const; + + + virtual RawPointer::Ptr getRawPointer(); //int addV4f(math::V4f value); @@ -44,8 +51,9 @@ namespace houio Storage m_storage; Type m_type; //std::vector data; - std::vector strings; // used in case of type==string - int numElements; + std::vector strings; // used in case of type==string + std::vector stringsIdxs; // used in case of type==string + int numElements; Attribute::Ptr m_attr; // primitives::Attribute }; diff --git a/include/houio/HouGeoAdapter.h b/include/houio/HouGeoAdapter.h index ce506ba..20ad4a1 100644 --- a/include/houio/HouGeoAdapter.h +++ b/include/houio/HouGeoAdapter.h @@ -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 getUniqueStrings()const=0; + virtual std::vector getStringIndices()const=0; static Type type( const std::string &typeName ); static Storage storage( const std::string &storageName ); static int storageSize( Storage storage ); diff --git a/src/HouGeo.cpp b/src/HouGeo.cpp index 1dcba53..5e291ac 100644 --- a/src/HouGeo.cpp +++ b/src/HouGeo.cpp @@ -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 HouGeo::HouAttribute::getUniqueStrings()const + { + return strings; + } + + std::vector HouGeo::HouAttribute::getStringIndices()const + { + return stringsIdxs; + } + @@ -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;iget(index); + index = i*2; json::ArrayPtr entry = entries->getArray(index+1); - std::string type2_questionmark = entry->get(0); std::string id = entry->get(1); json::ArrayPtr data = entry->getArray(2); @@ -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;iget( i ); - attr->strings.push_back(string); - //qDebug() << QString::fromStdString(string); + stringValue = stringsArray->get( 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;iget(i); + attr->stringsIdxs.push_back(index); + } + attr->numElements = numElements; } } @@ -886,7 +927,7 @@ namespace houio { return field->sample(i, j, k); } - + math::Vec3i HouGeo::HouVolume::getResolution()const { return field->getResolution(); @@ -994,7 +1035,7 @@ namespace houio - +