ReferenceTestSetGenerator.cpp
Go to the documentation of this file.
1 
19 
21 
23  TestSetGenerator(pEvaluator, pFullyMeshedTopology, pObjectTypes)
24 { }
25 
27 { }
28 
29 std::vector<boost::shared_ptr<TestSet>> ReferenceTestSetGenerator::generateRandomSets(std::vector<boost::shared_ptr<ISM::ObjectSet>> pExamplesList, unsigned int pTestSetCount)
30 {
31  TestSetGenerator::mPrintHelper.printAsHeader("Generating " + boost::lexical_cast<std::string>(pTestSetCount) + " random test sets.");
32 
33  std::random_device rd;
34  boost::mt19937 eng; // Mersenne Twister
35  eng.seed(rd());
36  boost::uniform_int<> dist(0,RAND_MAX); // Normal Distribution
37  boost::variate_generator<boost::mt19937,boost::uniform_int<>> gen(eng,dist); // Variate generator
38 
39  ROS_INFO_STREAM("Found " << TestSetGenerator::mTypes.size() << " object types.");
40 
41  std::vector<boost::shared_ptr<TestSet>> testSets(pTestSetCount);
42 
43  for (unsigned int i = 0; i < pTestSetCount; i++)
44  {
45  // pick random reference:
46  unsigned int randomTimestep = gen() % pExamplesList.size();
47  unsigned int randomObjectIndex = gen() % pExamplesList[randomTimestep]->objects.size();
48  ISM::ObjectPtr referenceObject(new ISM::Object(*pExamplesList[randomTimestep]->objects[randomObjectIndex])); // deep copy the object
49 
50  testSets[i].reset(new TestSet());
51  testSets[i]->mObjectSet->insert(referenceObject);
52 
53  for (std::string objectType: mTypes)
54  {
55  if (objectType != referenceObject->type)
56  {
57  ISM::ObjectPtr object;
58 
59  unsigned int counter = 0;
60  while (!object && counter < pExamplesList.size()) // does not iterate over all timesteps; using example list size to scale
61  {
62  unsigned int newRandomTimestep = gen() % pExamplesList.size();
63  for (ISM::ObjectPtr currentObject: pExamplesList[newRandomTimestep]->objects)
64  {
65  if (currentObject->type == objectType)
66  {
67  object = ISM::ObjectPtr(new ISM::Object(*currentObject)); // deep copy the object.
68  break;
69  }
70  }
71  counter++;
72  }
73 
74  if (!object)
75  throw std::runtime_error("In TestSetGenerator::generateTestSets(): Failed to find object of type " + objectType + " in evidence list.");
76  setPoseOfObjectRelativeToReference(object, referenceObject);
77  testSets[i]->mObjectSet->insert(object);
78  }
79  }
80  }
81 
82  return testSets;
83 }
84 
85 }
void setPoseOfObjectRelativeToReference(ISM::ObjectPtr pObject, ISM::ObjectPtr pReference)
virtual std::vector< boost::shared_ptr< TestSet > > generateRandomSets(std::vector< boost::shared_ptr< ISM::ObjectSet >> pExamplesList, unsigned int pTestSetCount)
ReferenceTestSetGenerator(boost::shared_ptr< AbstractTopologyEvaluator > pEvaluator, boost::shared_ptr< SceneModel::Topology > pFullyMeshedTopology, const std::vector< std::string > &pObjectTypes)
#define ROS_INFO_STREAM(args)
std::vector< std::string > testSets


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54