1 | |
---|
2 | #include "LBBCKMeansClusterSerializer.h" |
---|
3 | |
---|
4 | namespace LBBC { |
---|
5 | |
---|
6 | KMeansClusterSerializer::KMeansClusterSerializer() { |
---|
7 | } |
---|
8 | |
---|
9 | KMeansClusterSerializer::~KMeansClusterSerializer() { |
---|
10 | } |
---|
11 | |
---|
12 | void KMeansClusterSerializer::readBillboardCloud(TiXmlDocument *document, bool groupedBillboards) |
---|
13 | { |
---|
14 | TiXmlNode *billboardCloudNode = document->FirstChild("billboardCloud"); |
---|
15 | TiXmlNode *billboardGroupsNode = billboardCloudNode->FirstChild("billboardGroups"); |
---|
16 | |
---|
17 | unsigned int numBillboardGroups = Ogre::StringConverter::parseInt(billboardGroupsNode->ToElement()->Attribute("count")); |
---|
18 | |
---|
19 | unsigned int iBillboardGroup = 0; |
---|
20 | for (TiXmlNode *billboardGroupNode = billboardGroupsNode->FirstChild("billboardGroup"); billboardGroupNode; billboardGroupNode = billboardGroupNode->NextSibling() ) |
---|
21 | { |
---|
22 | unsigned int numBillboards = Ogre::StringConverter::parseInt(billboardGroupNode->ToElement()->Attribute("count")); |
---|
23 | |
---|
24 | if (!groupedBillboards)
|
---|
25 | {
|
---|
26 | for (TiXmlNode *billboardNode = billboardGroupNode->FirstChild("billboard"); billboardNode; billboardNode = billboardNode->NextSibling() ) |
---|
27 | {
|
---|
28 | BBC::BillboardPtr billboard = BBC::BillboardPtr( new BBC::Billboard() );
|
---|
29 | BBC::BillboardClusterDataPtr billboardClusterData = BBC::BillboardClusterDataPtr( new BillboardKMeansClusterData() );
|
---|
30 | mBillboardCloud->addBillboard(billboard);
|
---|
31 | billboard->setBillboardClusterData(billboardClusterData);
|
---|
32 | billboard->getBillboardClusterData()->readBillboardClusterData(billboardNode, -1);
|
---|
33 | }
|
---|
34 | } |
---|
35 | else |
---|
36 | { |
---|
37 | BBC::BillboardGroupPtr billboardGroup = BBC::BillboardGroupPtr( new BBC::BillboardGroup() ); |
---|
38 | mBillboardCloud->addBillboardGroup(billboardGroup); |
---|
39 | |
---|
40 | for (TiXmlNode *billboardNode = billboardGroupNode->FirstChild("billboard"); billboardNode; billboardNode = billboardNode->NextSibling() ) |
---|
41 | {
|
---|
42 | BBC::BillboardPtr billboard = BBC::BillboardPtr( new BBC::Billboard() );
|
---|
43 | BBC::BillboardClusterDataPtr billboardClusterData = BBC::BillboardClusterDataPtr( new BillboardKMeansClusterData() );
|
---|
44 | mBillboardCloud->addBillboard(billboard);
|
---|
45 | billboard->setBillboardClusterData(billboardClusterData);
|
---|
46 | billboard->getBillboardClusterData()->readBillboardClusterData(billboardNode, iBillboardGroup); |
---|
47 | billboardGroup->addBillboardHandle(billboard->getBillboardHandle()); |
---|
48 | } |
---|
49 | } |
---|
50 | iBillboardGroup++; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | void KMeansClusterSerializer::writeBillboardCloud(TiXmlDocument *document, bool groupedBillboards)
|
---|
55 | {
|
---|
56 | TiXmlNode *billboardCloudNode = document->InsertEndChild(TiXmlElement("billboardCloud"))->ToElement();
|
---|
57 |
|
---|
58 | TiXmlNode *billboardGroupsNode = billboardCloudNode->InsertEndChild(TiXmlElement("billboardGroups"))->ToElement(); |
---|
59 |
|
---|
60 | if (!groupedBillboards)
|
---|
61 | {
|
---|
62 | billboardGroupsNode->ToElement()->SetAttribute("count",Ogre::StringConverter::toString(1));
|
---|
63 | TiXmlNode *billboardGroupNode = billboardGroupsNode->InsertEndChild(TiXmlElement("billboardGroup"))->ToElement();
|
---|
64 |
|
---|
65 | unsigned int numSerializedBillboards = 0;
|
---|
66 | unsigned int numSerializedEntities = 0;
|
---|
67 | for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getNumBillboards(); iBillboard++)
|
---|
68 | {
|
---|
69 | BBC::BillboardPtr billboard = mBillboardCloud->getBillboard(iBillboard); |
---|
70 | BBC::EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster();
|
---|
71 |
|
---|
72 | // If the Billboard has Entities...
|
---|
73 | if (entityCluster->getNumEntitiesClusterData() > 0)
|
---|
74 | {
|
---|
75 | BillboardKMeansClusterData *billboardKMeansClusterData = (BillboardKMeansClusterData*)billboard->getBillboardClusterData().get();
|
---|
76 | billboardKMeansClusterData->writeBillboardClusterData(billboardGroupNode, -1);
|
---|
77 | numSerializedBillboards++;
|
---|
78 | numSerializedEntities = numSerializedEntities + entityCluster->getNumEntitiesClusterData();
|
---|
79 | }
|
---|
80 | } |
---|
81 | billboardGroupNode->ToElement()->SetAttribute("count",Ogre::StringConverter::toString(numSerializedBillboards)); |
---|
82 | Ogre::LogManager::getSingleton().logMessage("Num.Serialized Billboards:" + Ogre::StringConverter::toString(numSerializedBillboards) + " with " + Ogre::StringConverter::toString(numSerializedEntities) + " Entities"); |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | billboardGroupsNode->ToElement()->SetAttribute("count",Ogre::StringConverter::toString(mBillboardCloud->getNumBillboardGroups())); |
---|
87 | |
---|
88 | unsigned int numSerializedBillboards = 0;
|
---|
89 | unsigned int numSerializedEntities = 0;
|
---|
90 | |
---|
91 | for (unsigned int iBillboardGroup = 0; iBillboardGroup < mBillboardCloud->getNumBillboardGroups(); iBillboardGroup++) |
---|
92 | { |
---|
93 | TiXmlNode *billboardGroupNode = billboardGroupsNode->InsertEndChild(TiXmlElement("billboardGroup"))->ToElement(); |
---|
94 | |
---|
95 | for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getBillboardGroup(iBillboardGroup)->getNumBillboards(); iBillboard++) |
---|
96 | { |
---|
97 | BBC::BillboardPtr billboard = mBillboardCloud->getBillboard(mBillboardCloud->getBillboardGroup(iBillboardGroup)->getBillboardHandle(iBillboard)); |
---|
98 | BBC::EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster();
|
---|
99 |
|
---|
100 | // If the Billboard has Entities...
|
---|
101 | if (entityCluster->getNumEntitiesClusterData() > 0)
|
---|
102 | {
|
---|
103 | BillboardKMeansClusterData *billboardKMeansClusterData = (BillboardKMeansClusterData*)billboard->getBillboardClusterData().get();
|
---|
104 | billboardKMeansClusterData->writeBillboardClusterData(billboardGroupNode, iBillboardGroup);
|
---|
105 | numSerializedBillboards++;
|
---|
106 | numSerializedEntities = numSerializedEntities + entityCluster->getNumEntitiesClusterData();
|
---|
107 | } |
---|
108 | } |
---|
109 | billboardGroupNode->ToElement()->SetAttribute("count",Ogre::StringConverter::toString(mBillboardCloud->getBillboardGroup(iBillboardGroup)->getNumBillboards())); |
---|
110 | } |
---|
111 | |
---|
112 | Ogre::LogManager::getSingleton().logMessage("Num.Serialized Billboards:" + Ogre::StringConverter::toString(numSerializedBillboards) + " with " + Ogre::StringConverter::toString(numSerializedEntities) + " Entities"); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|