XdmfTopology.cpp 1.79 KB
Newer Older
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
1
/*
2
 * XdmfTopology.cpp
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
3 4 5 6 7
 *
 *  Created on: Jan 29, 2010
 *      Author: kleiter
 */

8
#include <sstream>
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
9
#include "XdmfTopology.hpp"
10
#include "XdmfTopologyType.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
11

12 13 14 15 16 17
boost::shared_ptr<XdmfTopology> XdmfTopology::New()
{
	boost::shared_ptr<XdmfTopology> p(new XdmfTopology());
	return p;
}

18
XdmfTopology::XdmfTopology() :
19
	mTopologyType(XdmfTopologyType::NoTopologyType())
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
20 21 22 23 24 25 26
{
}

XdmfTopology::~XdmfTopology()
{
}

27
const std::string XdmfTopology::ItemTag = "Topology";
28

29 30
std::string XdmfTopology::getItemTag() const
{
31
	return ItemTag;
32 33
}

34 35 36
std::map<std::string, std::string> XdmfTopology::getItemProperties() const
{
	std::map<std::string, std::string> topologyProperties;
37
	mTopologyType->getProperties(topologyProperties);
38 39 40 41 42 43
	if(mTopologyType != XdmfTopologyType::Polyvertex())
	{
		std::stringstream numElements;
		numElements << this->getNumberElements();
		topologyProperties["Dimensions"] = numElements.str();
	}
44 45 46
	return topologyProperties;
}

47
unsigned int XdmfTopology::getNumberElements() const
48
{
49
	if(mTopologyType->getNodesPerElement() == 0)
50 51 52
	{
		return 0;
	}
53
	return this->size() / mTopologyType->getNodesPerElement();
54 55
}

56
boost::shared_ptr<const XdmfTopologyType> XdmfTopology::getType() const
57
{
58
	return mTopologyType;
59 60
}

61 62 63
void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
	mTopologyType = XdmfTopologyType::New(itemProperties);
64 65 66 67 68 69 70 71
	for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
	{
		if(boost::shared_ptr<XdmfArray> array = boost::shared_dynamic_cast<XdmfArray>(*iter))
		{
			this->swap(array);
		}
		// TODO: If multiple dataitems.
	}
72 73
}

74
void XdmfTopology::setType(const boost::shared_ptr<const XdmfTopologyType> topologyType)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
75
{
76
	mTopologyType = topologyType;
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
77
}