Refactored ODB results metadata

Added private class RifOdbResultKey which is now used as a map key and
as a parameter in results related methods.
This commit is contained in:
Stein Dale 2015-06-04 11:14:12 +02:00
parent e347249526
commit be1759835e
2 changed files with 82 additions and 57 deletions

View File

@ -39,6 +39,8 @@
#include <QString> #include <QString>
size_t RifOdbReader::sm_instanceCount = 0; size_t RifOdbReader::sm_instanceCount = 0;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -195,11 +197,11 @@ bool RifOdbReader::buildMetaData()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::map< RifOdbReader::ResPos, std::map<std::string, std::vector<std::string> > > RifOdbReader::resultsMetaData(odb_Odb* odb) std::map< RifOdbReader::RifOdbResultKey, std::vector<std::string> > RifOdbReader::resultsMetaData(odb_Odb* odb)
{ {
CVF_ASSERT(odb != NULL); CVF_ASSERT(odb != NULL);
std::map< ResPos, std::map<std::string, std::vector<std::string> > > resultsMap; std::map< RifOdbResultKey, std::vector<std::string> > resultsMap;
const odb_StepRepository& stepRepository = odb->steps(); const odb_StepRepository& stepRepository = odb->steps();
odb_StepRepositoryIT stepIt(stepRepository); odb_StepRepositoryIT stepIt(stepRepository);
@ -239,16 +241,16 @@ std::map< RifOdbReader::ResPos, std::map<std::string, std::vector<std::string> >
switch (fieldLocation.position()) switch (fieldLocation.position())
{ {
case odb_Enum::NODAL: case odb_Enum::NODAL:
resultsMap[NODAL][fieldName] = compVec; resultsMap[RifOdbResultKey(RifOdbResultKey::NODAL, fieldName)] = compVec;
break; break;
case odb_Enum::ELEMENT_NODAL: case odb_Enum::ELEMENT_NODAL:
resultsMap[ELEMENT_NODAL][fieldName] = compVec; resultsMap[RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName)] = compVec;
break; break;
case odb_Enum::INTEGRATION_POINT: case odb_Enum::INTEGRATION_POINT:
resultsMap[INTEGRATION_POINT][fieldName] = compVec; resultsMap[RifOdbResultKey(RifOdbResultKey::INTEGRATION_POINT, fieldName)] = compVec;
resultsMap[ELEMENT_NODAL][fieldName] = compVec; resultsMap[RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName)] = compVec;
break; break;
default: default:
@ -416,7 +418,7 @@ std::vector<double> RifOdbReader::frameTimes(int stepIndex)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::map<std::string, std::vector<std::string> > RifOdbReader::scalarNodeFieldAndComponentNames() std::map<std::string, std::vector<std::string> > RifOdbReader::scalarNodeFieldAndComponentNames()
{ {
return fieldAndComponentNames(NODAL); return fieldAndComponentNames(RifOdbResultKey::NODAL);
} }
@ -425,7 +427,7 @@ std::map<std::string, std::vector<std::string> > RifOdbReader::scalarNodeFieldAn
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::map<std::string, std::vector<std::string> > RifOdbReader::scalarElementNodeFieldAndComponentNames() std::map<std::string, std::vector<std::string> > RifOdbReader::scalarElementNodeFieldAndComponentNames()
{ {
return fieldAndComponentNames(ELEMENT_NODAL); return fieldAndComponentNames(RifOdbResultKey::ELEMENT_NODAL);
} }
@ -434,7 +436,7 @@ std::map<std::string, std::vector<std::string> > RifOdbReader::scalarElementNode
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::map<std::string, std::vector<std::string> > RifOdbReader::scalarIntegrationPointFieldAndComponentNames() std::map<std::string, std::vector<std::string> > RifOdbReader::scalarIntegrationPointFieldAndComponentNames()
{ {
return fieldAndComponentNames(INTEGRATION_POINT); return fieldAndComponentNames(RifOdbResultKey::INTEGRATION_POINT);
} }
@ -507,9 +509,9 @@ size_t RifOdbReader::resultItemCount(const std::string& fieldName, int partIndex
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
int RifOdbReader::componentIndex(ResPos position, const std::string& fieldName, const std::string& componentName) const int RifOdbReader::componentIndex(const RifOdbResultKey& result, const std::string& componentName) const
{ {
std::vector<std::string> compNames = componentNames(position, fieldName); std::vector<std::string> compNames = componentNames(result);
for (size_t i = 0; i < compNames.size(); i++) for (size_t i = 0; i < compNames.size(); i++)
{ {
@ -526,18 +528,14 @@ int RifOdbReader::componentIndex(ResPos position, const std::string& fieldName,
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<std::string> RifOdbReader::componentNames(ResPos position, const std::string& fieldName) const std::vector<std::string> RifOdbReader::componentNames(const RifOdbResultKey& result) const
{ {
std::vector<std::string> compNames; std::vector<std::string> compNames;
std::map< ResPos, std::map<std::string, std::vector<std::string> > >::const_iterator posMapIt = m_resultsMetaData.find(position); std::map< RifOdbResultKey, std::vector<std::string> >::const_iterator resMapIt = m_resultsMetaData.find(result);
if (posMapIt != m_resultsMetaData.end()) if (resMapIt != m_resultsMetaData.end())
{ {
std::map<std::string, std::vector<std::string> >::const_iterator fieldNameMapIt = posMapIt->second.find(fieldName); compNames = resMapIt->second;
if (fieldNameMapIt != posMapIt->second.end())
{
compNames = fieldNameMapIt->second;
}
} }
return compNames; return compNames;
@ -547,14 +545,25 @@ std::vector<std::string> RifOdbReader::componentNames(ResPos position, const std
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::map<std::string, std::vector<std::string> > RifOdbReader::fieldAndComponentNames(ResPos position) std::map<std::string, std::vector<std::string> > RifOdbReader::fieldAndComponentNames(RifOdbResultKey::ResultPosition position)
{ {
if (m_resultsMetaData.empty()) if (m_resultsMetaData.empty())
{ {
buildMetaData(); buildMetaData();
} }
return m_resultsMetaData[position]; std::map<std::string, std::vector<std::string> > fieldsAndComponents;
std::map< RifOdbResultKey, std::vector<std::string> >::const_iterator resMapIt;
for (resMapIt = m_resultsMetaData.begin(); resMapIt != m_resultsMetaData.end(); resMapIt++)
{
if (resMapIt->first.resultPostion == position)
{
fieldsAndComponents[resMapIt->first.fieldName] = resMapIt->second;
}
}
return fieldsAndComponents;
} }
@ -575,7 +584,7 @@ void RifOdbReader::readScalarNodeField(const std::string& fieldName, const std::
resultValues->resize(dataSize); resultValues->resize(dataSize);
resultValues->assign(dataSize, std::numeric_limits<float>::infinity()); resultValues->assign(dataSize, std::numeric_limits<float>::infinity());
int compIndex = componentIndex(NODAL, fieldName, componentName); int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::NODAL, fieldName), componentName);
CVF_ASSERT(compIndex >= 0); CVF_ASSERT(compIndex >= 0);
const odb_Frame& frame = stepFrame(stepIndex, frameIndex); const odb_Frame& frame = stepFrame(stepIndex, frameIndex);
@ -622,7 +631,7 @@ void RifOdbReader::readScalarElementNodeField(const std::string& fieldName, cons
resultValues->assign(dataSize, std::numeric_limits<float>::infinity()); resultValues->assign(dataSize, std::numeric_limits<float>::infinity());
} }
int compIndex = componentIndex(ELEMENT_NODAL, fieldName, componentName); int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName), componentName);
CVF_ASSERT(compIndex >= 0); CVF_ASSERT(compIndex >= 0);
const odb_Frame& frame = stepFrame(stepIndex, frameIndex); const odb_Frame& frame = stepFrame(stepIndex, frameIndex);
@ -680,7 +689,7 @@ void RifOdbReader::readScalarIntegrationPointField(const std::string& fieldName,
resultValues->assign(dataSize, std::numeric_limits<float>::infinity()); resultValues->assign(dataSize, std::numeric_limits<float>::infinity());
} }
int compIndex = componentIndex(INTEGRATION_POINT, fieldName, componentName); int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::INTEGRATION_POINT, fieldName), componentName);
CVF_ASSERT(compIndex >= 0); CVF_ASSERT(compIndex >= 0);
const odb_Frame& frame = stepFrame(stepIndex, frameIndex); const odb_Frame& frame = stepFrame(stepIndex, frameIndex);

View File

@ -29,7 +29,6 @@ class odb_Odb;
class odb_Frame; class odb_Frame;
class odb_Instance; class odb_Instance;
//================================================================================================== //==================================================================================================
// //
// Data interface base class // Data interface base class
@ -37,7 +36,6 @@ class odb_Instance;
//================================================================================================== //==================================================================================================
class RifOdbReader : public RifGeoMechReaderInterface class RifOdbReader : public RifGeoMechReaderInterface
{ {
public: public:
RifOdbReader(); RifOdbReader();
virtual ~RifOdbReader(); virtual ~RifOdbReader();
@ -58,29 +56,47 @@ public:
virtual void readDisplacements(int partIndex, int stepIndex, int frameIndex, std::vector<cvf::Vec3f>* displacements); virtual void readDisplacements(int partIndex, int stepIndex, int frameIndex, std::vector<cvf::Vec3f>* displacements);
private: private:
class RifOdbResultKey
enum ResPos {
public:
enum ResultPosition
{ {
NODAL, NODAL,
ELEMENT_NODAL, ELEMENT_NODAL,
INTEGRATION_POINT INTEGRATION_POINT
}; };
RifOdbResultKey(ResultPosition aResultPostion, const std::string& aFieldName)
: resultPostion(aResultPostion), fieldName(aFieldName) {};
ResultPosition resultPostion;
std::string fieldName;
bool operator< (const RifOdbResultKey& other) const
{
if (resultPostion != other.resultPostion)
{
return (resultPostion < other.resultPostion);
}
return (fieldName < other.fieldName);
}
};
bool buildMetaData(); bool buildMetaData();
void close(); void close();
size_t resultItemCount(const std::string& fieldName, int partIndex, int stepIndex, int frameIndex); size_t resultItemCount(const std::string& fieldName, int partIndex, int stepIndex, int frameIndex);
const odb_Frame& stepFrame(int stepIndex, int frameIndex) const; const odb_Frame& stepFrame(int stepIndex, int frameIndex) const;
odb_Instance* instance(int instanceIndex); odb_Instance* instance(int instanceIndex);
int componentIndex(ResPos position, const std::string& fieldName, const std::string& componentName) const; int componentIndex(const RifOdbResultKey& result, const std::string& componentName) const;
std::vector<std::string> componentNames(ResPos position, const std::string& fieldName) const; std::vector<std::string> componentNames(const RifOdbResultKey& result) const;
std::map<std::string, std::vector<std::string> > fieldAndComponentNames(ResPos position); std::map< std::string, std::vector<std::string> > fieldAndComponentNames(RifOdbResultKey::ResultPosition position);
std::map< RifOdbReader::ResPos, std::map<std::string, std::vector<std::string> > > resultsMetaData(odb_Odb* odb); std::map< RifOdbResultKey, std::vector<std::string> > resultsMetaData(odb_Odb* odb);
private: private:
odb_Odb* m_odb; odb_Odb* m_odb;
std::map< ResPos, std::map<std::string, std::vector<std::string> > > m_resultsMetaData; std::map< RifOdbResultKey, std::vector<std::string> > m_resultsMetaData;
std::vector< std::map<int, int> > m_nodeIdToIdxMaps; std::vector< std::map<int, int> > m_nodeIdToIdxMaps;
std::vector< std::map<int, int> > m_elementIdToIdxMaps; std::vector< std::map<int, int> > m_elementIdToIdxMaps;
static size_t sm_instanceCount; static size_t sm_instanceCount;
}; };