28 ROS_INFO_STREAM(
"Could not find ROS parameter conditional_probability_algorithm. Using standard method of using the minimum (value=\"minimum\").");
46 for(boost::property_tree::ptree::value_type &v: pPt.get_child(
"shape.root"))
49 if(!std::strcmp(v.first.c_str(),
"child"))
54 std::vector<boost::shared_ptr<HierarchicalShapeModelNode>> nodesToVisit;
56 nodesToVisit.push_back(child);
58 std::vector<boost::shared_ptr<HierarchicalShapeModelNode>> references;
59 std::map<unsigned int, boost::shared_ptr<HierarchicalShapeModelNode>> nonReferencesById;
60 while(!nodesToVisit.empty())
64 nodesToVisit.erase(nodesToVisit.begin());
66 unsigned int referenceTo;
67 bool isReference = currentNode->isReference(referenceTo);
70 nonReferencesById[referenceTo] = currentNode;
72 nodesToVisit.push_back(child);
76 references.push_back(currentNode);
82 unsigned int referenceTo;
83 if (!currentReference->isReference(referenceTo))
throw std::runtime_error(
"Trying to make a non-reference node a reference.");
85 currentReference->setReferencedNode(nonReferencesById[referenceTo]);
95 for(
unsigned int i = 0; i <
mChildren.size(); i++)
107 if(pAssignments[0] > 0)
112 unsigned int slotId = 0;
116 mAbsolutePose.reset(
new ISM::Pose(*pEvidenceList[pAssignments[0] - 1].pose));
122 result *= rootResult;
125 std::vector<boost::shared_ptr<ConditionalProbability>> conditionalProbabilities(pAssignments.size());
128 for (
unsigned int i = 0; i < conditionalProbabilities.size(); i++)
131 for (
unsigned int i = 0; i < conditionalProbabilities.size(); i++)
134 for (
unsigned int i = 0; i < conditionalProbabilities.size(); i++)
137 for (
unsigned int i = 0; i < conditionalProbabilities.size(); i++)
139 else throw std::runtime_error(
"In HierarchicalShapeModel::calculateProbabilityForHypothesis(): conditional probability algorithm type " 143 conditionalProbabilities[0]->setProbability(
"Root", rootResult);
148 child->setParentObjectType(
mVisualizer->getSceneObjectName());
155 result *= child->calculateProbabilityForHypothesis(pEvidenceList, pAssignments, slotId, pAssignments[0] == 0, conditionalProbabilities);
158 double slotProduct = 1.0;
160 double slotProbability = cP->getProbability();
162 slotProduct *= slotProbability;
167 result = slotProduct;
181 std::string name =
mVisualizer->getSceneObjectName();
184 for(
unsigned int i = 0; i < pEvidenceList.size(); i++)
187 if(name.compare(pEvidenceList[i].type) == 0)
196 for(
unsigned int i = 0; i <
mChildren.size(); i++)
202 for(
unsigned int i = 0; i <
mChildren.size(); i++)
208 unsigned int result = 1;
213 result += child->getNumberOfNodes();
void initializeVisualizer(boost::shared_ptr< Visualization::ProbabilisticPrimarySceneObjectVisualization > mSuperior)
double calculateProbabilityForHypothesis(std::vector< ISM::Object > pEvidenceList, std::vector< unsigned int > pAssignments)
boost::shared_ptr< Visualization::ProbabilisticPrimarySceneObjectVisualization > mVisualizer
void visualize(std::vector< ISM::Object > pEvidenceList)
std::vector< boost::shared_ptr< HierarchicalShapeModelNode > > mChildren
void load(boost::property_tree::ptree &pPt)
boost::shared_ptr< ISM::Pose > mAbsolutePose
unsigned int getNumberOfNodes()
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
~HierarchicalShapeModel()
std::string mConditionalProbabilityAlgorithm