31 #include <boost/filesystem.hpp> 32 #include <boost/filesystem/path.hpp> 33 #include <boost/thread.hpp> 34 #include <boost/functional/hash.hpp> 35 #include <boost/random.hpp> 36 #include <boost/random/variate_generator.hpp> 37 #include <boost/random/uniform_real.hpp> 38 #include <boost/random/mersenne_twister.hpp> 39 #include <boost/random/normal_distribution.hpp> 50 LogHelper::logMessage(
"Generating " + std::to_string(testSetCount) +
" test sets for pattern " + patternName +
":");
52 std::vector<ObjectSetPtr> validTestSets;
53 std::vector<ObjectSetPtr> invalidTestSets;
57 std::random_device rd;
60 DIST dist(0,RAND_MAX);
65 for (
unsigned int i = 0; i < testSetCount; ++i)
71 validTestSets.push_back(randomObjectSet);
75 invalidTestSets.push_back(randomObjectSet);
83 +
" contain " + std::to_string(validTestSets.size())
84 +
" valid and " + std::to_string(invalidTestSets.size())
85 +
" invalid object sets.\n");
87 return std::make_pair(validTestSets, invalidTestSets);
92 const std::string& pattern,
GEN &gen)
97 unsigned int tries = 0;
98 const unsigned int maxTries = (allTracks->tracks.size() + allTracks->tracks[0]->objects.size()) * 100;
99 while(!referenceObject && tries < maxTries)
101 unsigned randomRefTrack = gen() % allTracks->tracks.size();
102 unsigned randomRefPos = gen() % allTracks->tracks[randomRefTrack]->objects.size();
103 referenceObject = allTracks->tracks[randomRefTrack]->objects[randomRefPos];
108 std::cerr <<
"TestSetGenerator::generateTestSetsIterative couldnt find referenceObject. Increase maxTries?" << std::endl;
109 throw std::runtime_error(
"TestSetGenerator::generateTestSetsIterative couldnt find referenceObject. Increase maxTries?");
112 randomObjectSet->insert(referenceObject);
114 for (std::vector<TrackPtr>::iterator track = allTracks->tracks.begin(); track != allTracks->tracks.end(); ++track)
116 if ((*track)->type == referenceObject->type && (*track)->observedId == referenceObject->observedId)
122 for (
const std::pair<unsigned int, ObjectRelationPtr>& relation : allRelations)
124 if ( (relation.second->getVotesFromAForReferencePoseB().size() > 0
125 || relation.second->getVotesFromBForReferencePoseA().size() > 0)
126 && relation.second->containsObject(referenceObject->type, referenceObject->observedId) ==
true 127 && relation.second->containsObject((*track)->type, (*track)->observedId) ==
true)
132 if (relation.second->getVotesFromBForReferencePoseA().size() > 0 &&
133 relation.second->getObjectTypeA() == referenceObject->type &&
134 relation.second->getObjectIdA() == referenceObject->observedId)
136 unsigned randomTimeStep = gen() % relation.second->getVotesFromBForReferencePoseA().size();
137 VoteSpecifierPtr randomVote = relation.second->getVotesFromBForReferencePoseA()[randomTimeStep];
141 else if(relation.second->getVotesFromAForReferencePoseB().size() > 0)
143 unsigned randomTimeStep = gen() % relation.second->getVotesFromAForReferencePoseB().size();
144 VoteSpecifierPtr randomVote = relation.second->getVotesFromAForReferencePoseB()[randomTimeStep];
148 ObjectPtr fittingObject(
new Object((*track)->type, randomRelativePose, (*track)->observedId));
149 randomObjectSet->insert(fittingObject);
155 return randomObjectSet;
const std::map< std::string, ISM::ObjectRelations > mAllObjectRelationsPerPattern
boost::shared_ptr< Point > PointPtr
static void displayProgress(double progress)
static void logMessage(const std::string &message, LogLevel logLevel=LOG_INFO, const char *logColor=LOG_COLOR_DEFAULT)
std::map< unsigned int, ISM::ObjectRelationPtr, std::less< unsigned > > ObjectRelations
boost::shared_ptr< ImplicitShapeModel > IsmPtr
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
boost::shared_ptr< ObjectSet > ObjectSetPtr
boost::shared_ptr< Tracks > TracksPtr
boost::shared_ptr< Pose > PosePtr
ISM::ObjectSetValidatorPtr mObjectSetValidator
static PointPtr getSourcePoint(const PosePtr &refPose, const QuaternionPtr &refToObjectQuat, double radius)
static PosePtr getSourcePose(const PosePtr &reference, const PointPtr &sourcePoint, const QuaternionPtr &refToObjectPoseQuat)
this namespace contains all generally usable classes.
ObjectSetPtr generateRandomObjectSetFromTracks(const ISM::TracksPtr &allTracks, const std::string &pattern, GEN &gen)
std::pair< std::vector< ObjectSetPtr >, std::vector< ObjectSetPtr > > generateTestSets(const std::string &patternName, const TracksPtr &tracks, const IsmPtr ism, unsigned int testSetCount)
boost::shared_ptr< Object > ObjectPtr
boost::variate_generator< ENG, DIST > GEN