void OSBGeometryElement::preWrite(FieldContainer * const fc) { OSG_OSB_LOG(("OSBGeometryElement::preWrite\n")); OSBRootElement *root = editRoot(); UInt32 fieldCount = fc->getType().getNumFieldDescs(); UInt8 quanResPositions = root->getOptions().quantizePositions(); UInt8 quanResNormals = root->getOptions().quantizeNormals (); UInt8 quanResTexCoords = root->getOptions().quantizeTexCoords(); bool packIndices = root->getOptions().packIndices (); // go through all fields and find those refering to other FCs for(UInt32 fieldId = 1; fieldId <= fieldCount; ++fieldId) { const FieldDescriptionBase *fieldDesc = fc->getFieldDescription(fieldId); const FieldType &fieldType = fieldDesc->getFieldType(); const std::string &fieldName = fieldDesc->getName (); // skip internal fields if(fieldDesc->isInternal()) { OSG_OSB_LOG(("OSBGeometryElement::preWrite: " "Skipping internal field: [%s]\n", fieldName.c_str())); continue; } if(fieldName == "properties") { // "properties" might be quantized FieldContainerPtrMFieldBase::GetHandlePtr fP = boost::dynamic_pointer_cast< FieldContainerPtrMFieldBase::GetHandle>( getContainer()->getField(fieldId)); if(fP == NULL || fP->isValid() == false) continue; FieldContainerPtrMFieldBase::const_iterator fieldIt = (*fP)->begin(); FieldContainerPtrMFieldBase::const_iterator fieldEnd = (*fP)->end (); for(UInt32 i = 0; fieldIt != fieldEnd; ++fieldIt, ++i) { FieldContainer *refedFC = *fieldIt; if(refedFC == NULL) continue; UInt32 refedId = refedFC->getId (); const std::string typeName = refedFC->getType().getName(); // only schedule a container once if(root->getIdSet().count(refedId) > 0) continue; OSBElementBase *elem = OSBElementFactory::the()->acquire(typeName, root); OSBGeoVectorPropertyElement *propElem = dynamic_cast<OSBGeoVectorPropertyElement *>(elem); if((propElem != 0) && (i == Geometry::PositionsIndex)) { propElem->setQuantizeResolution(quanResPositions); } else if((propElem != 0) && (i == Geometry::NormalsIndex)) { propElem->setQuantizeResolution(quanResNormals); } else if((propElem != 0) && (i >= Geometry::TexCoordsIndex) && (i <= Geometry::TexCoords7Index) ) { propElem->setQuantizeResolution(quanResTexCoords); } root->editIdSet ().insert (refedId); root->editElementList().push_back(elem ); elem->setContainer(refedFC); elem->preWrite (refedFC); } } else if(fieldName == "propIndices") { // "propIndices" might be packed FieldContainerPtrMFieldBase::GetHandlePtr fP = boost::dynamic_pointer_cast< FieldContainerPtrMFieldBase::GetHandle>( getContainer()->getField(fieldId)); if(fP == NULL || fP->isValid() == false) continue; FieldContainerPtrMFieldBase::const_iterator fieldIt = (*fP)->begin(); FieldContainerPtrMFieldBase::const_iterator fieldEnd = (*fP)->end (); for(UInt32 i = 0; fieldIt != fieldEnd; ++fieldIt, ++i) { FieldContainer *refedFC = *fieldIt; if(refedFC == NULL) continue; UInt32 refedId = refedFC->getId (); const std::string typeName = refedFC->getType().getName(); // only schedule a container once if(root->getIdSet().count(refedId) > 0) continue; OSBElementBase *elem = OSBElementFactory::the()->acquire(typeName, root); OSBGeoIntegralPropertyElement *propElem = dynamic_cast<OSBGeoIntegralPropertyElement *>(elem); if((propElem != 0) && (packIndices == true)) { propElem->setPackData(true); } root->editIdSet ().insert (refedId); root->editElementList().push_back(elem ); elem->setContainer(refedFC); elem->preWrite (refedFC); } } else if(fieldName == "attachments") { preWriteAttachmentMapField(fieldId); } else { // check if field refers to another FC, i.e. its a field holding // FieldContainerPtr or an FieldContainerAttachmentMap if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getType()) == true) { if(fieldType.getCardinality() == FieldType::SingleField) { preWritePtrSingleField(fieldId); } else if(fieldType.getCardinality() == FieldType::MultiField) { preWritePtrMultiField(fieldId); } } } } }
/*! Visits the given container \a fc during preWrite and creates elements for all containers reachable from this (except for those refered to by fields whose names are in \a excludeFields). The excludeFields string has the format: "'name1' 'name2' 'name3'", the spaces between the "'" are mandatory. \param[in] fc Container this element shall visit. \param[in] excludeFields Field names that are not to be considered when determining reachable containers. */ void OSBCommonElement::preWriteFieldContainer( FieldContainer *fc, const std::string &excludeFields) { OSG_OSB_LOG(("OSBCommonElement::preWriteFieldContainer: >> type [%s] " "excludeFields: [%s]\n", fc->getType().getName().c_str(), excludeFields.c_str())); UInt32 fieldCount = fc->getType().getNumFieldDescs(); // go through all fields and find those refering to other FCs for(UInt32 fieldId = 1; fieldId <= fieldCount; ++fieldId) { const FieldDescriptionBase *fieldDesc = fc->getFieldDescription(fieldId); const FieldType &fieldType = fieldDesc->getFieldType(); const std::string &fieldName = fieldDesc->getName (); OSG_OSB_LOG(("OSBCommonElement::preWriteFieldContainer: " "fieldName: [%s] fieldId: [%u]\n", fieldName.c_str(), fieldId)); // skip internal fields if(fieldDesc->isInternal()) { OSG_OSB_LOG(("OSBCommonElement::preWriteFieldContainer: " "Skipping internal field: [%s]\n", fieldName.c_str())); continue; } // skip excluded fields if((!excludeFields.empty() ) && (excludeFields.find("'" + fieldName + "'") != std::string::npos) ) { OSG_OSB_LOG(("OSBCommonElement::preWriteFieldContainer: " "Skipping excluded field: [%s]\n", fieldName.c_str())); continue; } // check if field refers to another FC, i.e. its a field holding // FieldContainerPtr or an FieldContainerAttachmentMap if(fieldType.getContentType().isDerivedFrom( FieldTraits<AttachmentMap>::getType()) == true) { preWriteAttachmentMapField(fieldId); } else if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getMapType()) == true) { preWriteMapField(fieldId); } else if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getType()) == true) { if(fieldType.getCardinality() == FieldType::SingleField) { preWritePtrSingleField(fieldId); } else if(fieldType.getCardinality() == FieldType::MultiField) { preWritePtrMultiField(fieldId); } } } OSG_OSB_LOG(("OSBCommonElement::preWriteFieldContainer: << type [%s] " "excludeFields: [%s]\n", fc->getType().getName().c_str(), excludeFields.c_str())); }