8#ifndef META_OCEAN_TRACKING_DATABASE_H
9#define META_OCEAN_TRACKING_DATABASE_H
79 static inline Vector3 invalidObjectPoint();
128 inline Index32 imagePointId()
const;
134 inline void setImagePointId(
const Index32 imagePointId);
159 inline Index32 objectPointId()
const;
165 inline void setObjectPointId(
const Index32 objectPointId);
196 inline void setPoseId(
const Index32 poseId);
261 template <
bool tThreadSafe>
278 size_t size()
const override;
285 const Vector2& operator[](
const size_t& index)
const override;
300 template <
bool tThreadSafe>
317 size_t size()
const override;
324 const Vector2& operator[](
const size_t& index)
const override;
339 template <
bool tThreadSafe>
356 size_t size()
const override;
363 const Vector3& operator[](
const size_t& index)
const override;
378 template <
bool tThreadSafe>
395 size_t size()
const override;
417 template <
bool tThreadSafe>
434 size_t size()
const override;
478 inline const Vector2& point()
const;
490 inline Index32 objectPointId()
const;
496 inline void setPoint(
const Vector2& point);
502 inline void setPoseId(
const Index32 poseId);
508 inline void setObjectPointId(
const Index32 objectPointId);
533 inline const IndexSet32& imagePointIds()
const;
539 inline void registerImagePoint(
const Index32 imagePointId);
545 inline void unregisterImagePoint(
const Index32 imagePointId);
577 inline Scalar fov()
const;
589 inline void setFov(
const Scalar fov);
618 inline const Vector3& point()
const;
624 inline Scalar priority()
const;
630 inline void setPoint(
const Vector3& point);
636 inline void setPriority(
const Scalar priority);
702 template <
bool tThreadSafe>
703 inline bool isEmpty()
const;
709 template <
bool tThreadSafe>
710 inline size_t poseNumber()
const;
716 template <
bool tThreadSafe>
717 inline size_t objectPointNumber()
const;
723 template <
bool tThreadSafe>
724 inline size_t imagePointNumber()
const;
733 template <
bool tThreadSafe>
734 inline const Vector2& imagePoint(
const Index32 imagePointId)
const;
742 template <
bool tThreadSafe>
751 template <
bool tThreadSafe>
763 template <
bool tThreadSafe>
773 template <
bool tThreadSafe>
774 inline const Vector3& objectPoint(
const Index32 objectPointId)
const;
784 template <
bool tThreadSafe>
785 inline const Vector3& objectPoint(
const Index32 objectPointId,
Scalar& objectPointPriority)
const;
794 template <
bool tThreadSafe>
795 inline Scalar objectPointPriority(
const Index32 objectPointId)
const;
802 template <
bool tThreadSafe>
803 inline Vectors3 objectPoints()
const;
815 template <
bool tThreadSafe,
bool tMatchPosition>
824 template <
bool tThreadSafe>
835 template <
bool tThreadSafe>
846 template <
bool tThreadSafe>
858 template <
bool tThreadSafe>
870 template <
bool tThreadSafe,
bool tMatchPose>
881 template <
bool tThreadSafe>
893 template <
bool tThreadSafe,
bool tMatchPose>
905 template <
bool tThreadSafe>
906 inline bool poseBorders(
Index32& lowerPoseId,
Index32& upperPoseId)
const;
917 template <
bool tThreadSafe>
918 inline bool validPoseBorders(
Index32& rangeLowerPoseId,
Index32& rangeUpperPoseId)
const;
931 template <
bool tThreadSafe>
944 template <
bool tThreadSafe>
945 inline bool largestValidPoseRange(
const Index32 lowerPoseId,
const Index32 upperPoseId,
Index32& rangeLowerPoseId,
Index32& rangeUpperPoseId)
const;
960 template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
961 inline bool poseWithMostCorrespondences(
const Index32 lowerPoseId,
const Index32 upperPoseId,
Index32* poseId =
nullptr,
unsigned int* correspondences =
nullptr,
const Vector3& referenceObjectPoint = invalidObjectPoint())
const;
975 template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
976 inline bool poseWithLeastCorrespondences(
const Index32 lowerPoseId,
const Index32 upperPoseId,
Index32* poseId =
nullptr,
unsigned int* correspondences =
nullptr,
const Vector3& referenceObjectPoint = invalidObjectPoint())
const;
991 template <
bool tThreadSafe>
1001 template <
bool tThreadSafe>
1002 inline unsigned int numberObservations(
const Index32 poseId,
const Indices32& objectPointIds)
const;
1014 template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
1015 inline unsigned int numberCorrespondences(
const Index32 poseId,
const Vector3& referenceObjectPoint,
const Scalar minimalPriority =
Scalar(-1))
const;
1029 template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
1039 template <
bool tThreadSafe>
1040 inline bool hasImagePoint(
const Index32 imagePointId,
Vector2* imagePoint =
nullptr)
const;
1048 template <
bool tThreadSafe>
1057 template <
bool tThreadSafe>
1058 inline void removeImagePoint(
const Index32 imagePointId);
1067 template <
bool tThreadSafe>
1068 inline bool hasObjectPoint(
const Index32 objectPointId,
Vector3* objectPoint =
nullptr)
const;
1079 template <
bool tThreadSafe>
1093 template <
bool tThreadSafe>
1109 inline Index32 addObjectPointFromDatabase(
const Database& secondDatabase,
const Index32 secondDatabaseObjectPointId,
const SquareMatrix3& imagePointTransformation =
SquareMatrix3(
true),
const Index32 newObjectPointId = invalidId,
const Index32 secondDatabaseLowerPoseId = invalidId,
const Index32 secondDatabaseUpperPoseId = invalidId,
const bool forExistingPosesOnly =
false);
1117 template <
bool tThreadSafe>
1118 inline void removeObjectPoint(
const Index32 objectPointId);
1125 template <
bool tThreadSafe>
1126 void removeObjectPointAndAttachedImagePoints(
const Index32 objectPointId);
1135 template <
bool tThreadSafe>
1136 inline void renameObjectPoint(
const Index32 oldObjectPointId,
const Index32 newObjectPointId);
1147 template <
bool tThreadSafe>
1148 inline void mergeObjectPoints(
const Index32 remainingObjectPointId,
const Index32 removingObjectPointId,
const Vector3& newPoint,
const Scalar newPriority);
1157 template <
bool tThreadSafe>
1168 template <
bool tThreadSafe>
1177 template <
bool tThreadSafe>
1178 inline void removePose(
const Index32 poseId);
1188 template <
bool tThreadSafe>
1189 inline Index32 poseFromImagePoint(
const Index32 imagePointId)
const;
1197 template <
bool tThreadSafe>
1198 inline size_t numberImagePointsFromObjectPoint(
const Index32 objectPointId)
const;
1208 template <
bool tThreadSafe>
1220 template <
bool tThreadSafe>
1231 template <
bool tThreadSafe>
1232 inline Index32 objectPointFromImagePoint(
const Index32 imagePointId)
const;
1241 template <
bool tThreadSafe>
1251 template <
bool tThreadSafe>
1252 inline const IndexSet32& imagePointsFromObjectPoint(
const Index32 objectPointId)
const;
1260 template <
bool tThreadSafe>
1269 template <
bool tThreadSafe>
1270 inline void attachImagePointToObjectPoint(
const Index32 imagePointId,
const Index32 objectPointId);
1276 template <
bool tThreadSafe>
1277 inline void detachImagePointFromObjectPoint(
const Index32 imagePointId);
1285 template <
bool tThreadSafe>
1286 inline void attachImagePointToPose(
const Index32 imagePointId,
const Index32 poseId);
1292 template <
bool tThreadSafe>
1293 inline void detachImagePointFromPose(
const Index32 imagePointId);
1301 template <
bool tThreadSafe>
1302 inline void setImagePoint(
const Index32 imagePointId,
const Vector2& imagePoint);
1311 template <
bool tThreadSafe>
1312 inline void setObjectPoint(
const Index32 objectPointId,
const Vector3& objectPoint);
1322 template <
bool tThreadSafe>
1323 inline void setObjectPoints(
const Index32* objectPointIds,
const Vector3* objectPoints,
const size_t number);
1334 template <
bool tThreadSafe>
1335 inline void setObjectPoints(
const Index32* objectPointIds,
const size_t number,
const Vector3& referenceObjectPoint);
1343 template <
bool tThreadSafe>
1344 inline void setObjectPoints(
const Vector3& objectPoint = invalidObjectPoint());
1353 template <
bool tThreadSafe>
1354 inline void setObjectPoint(
const Index32 objectPointId,
const Vector3& objectPoint,
const Scalar priority);
1362 template <
bool tThreadSafe>
1363 inline void setObjectPointPriority(
const Index32 objectPointId,
const Scalar priority);
1371 template <
bool tThreadSafe>
1382 template <
bool tThreadSafe>
1391 template <
bool tThreadSafe>
1400 template <
bool tThreadSafe>
1409 template <
bool tThreadSafe>
1419 template <
bool tThreadSafe>
1429 template <
bool tThreadSafe>
1438 template <
bool tThreadSafe>
1448 template <
bool tThreadSafe>
1457 template <
bool tThreadSafe>
1466 template <
bool tThreadSafe>
1479 template <
bool tThreadSafe,
bool tMatchPosition>
1492 template <
bool tThreadSafe,
bool tMatchPosition>
1505 template <
bool tThreadSafe,
bool tMatchPosition>
1515 template <
bool tThreadSafe>
1528 template <
bool tThreadSafe,
bool tMatchPosition>
1538 template <
bool tThreadSafe>
1554 template <
bool tThreadSafe,
bool tMatchPosition,
bool tVisibleInAllPoses>
1569 template <
bool tThreadSafe,
bool tMatchPosition,
bool tVisibleInAllPoses>
1580 template <
bool tThreadSafe>
1593 template <
bool tThreadSafe>
1607 template <
bool tThreadSafe>
1622 template <
bool tThreadSafe>
1633 template <
bool tThreadSafe>
1645 template <
bool tThreadSafe>
1646 IdIdPointPairsMap imagePoints(
const Index32 poseId,
const bool previous,
const size_t minimalObservations = 2,
const size_t maximalObservations = 0)
const;
1657 template <
bool tThreadSafe>
1672 template <
bool tThreadSafe,
bool tMatchPosition>
1673 void imagePointsObjectPoints(
const Index32 poseId,
Vectors2& imagePoints,
Vectors3& objectPoints,
const Vector3& referencePosition = invalidObjectPoint(),
const size_t minimalObservations = 0,
Indices32* imagePointIds =
nullptr,
Indices32* objectPointIds =
nullptr)
const;
1694 template <
bool tThreadSafe,
bool tMatchPosition>
1695 void imagePointsObjectPoints(
const Index32 poseId,
const IndexSet32& priorityIds,
Vectors2& priorityImagePoints,
Vectors3& priorityObjectPoints,
Vectors2& remainingImagePoints,
Vectors3& remainingObjectPoints,
const Vector3& referencePosition = invalidObjectPoint(),
const size_t minimalObservations = 0,
Indices32* priorityImagePointIds =
nullptr,
Indices32* priorityObjectPointIds =
nullptr,
Indices32* remainingImagePointIds =
nullptr,
Indices32* remainingObjectPointIds =
nullptr)
const;
1710 template <
bool tThreadSafe,
bool tMatchPose>
1719 template <
bool tThreadSafe>
1726 template <
bool tThreadSafe>
1727 inline void clear();
1736 template <
bool tThreadSafe>
1754 template <
typename T,
bool tThreadSafe>
1755 void reset(
const size_t numberPoses,
const Index32* poseIds,
const HomogenousMatrixT4<T>* poses,
const size_t numberObjectPoints,
const Index32* objectPointIds,
const VectorT3<T>* objectPoints,
const T* objectPointPriorities,
const size_t numberImagePoints,
const Index32* imagePointIds,
const VectorT2<T>* imagePoints,
const Index32* topologyPoseIds,
const Index32* topologyObjectPointIds);
1787 static inline Indices32 reliableObjectPoints(
const TopologyTriples& topologyTriples,
const unsigned int minimalObservations);
1815 explicit inline operator bool()
const;
1830 template <
bool tMatchPosition,
bool tNeedVal
idPose>
1831 void numberCorrespondencesSubset(
const Index32 lowerPoseId,
const Vector3* referenceObjectPoint,
const Scalar minimalPriority,
unsigned int* correspondences,
const unsigned int firstPose,
const unsigned int numberPoses)
const;
1845 template <
bool tMatchPosition>
1846 void objectPointIdsWithNumberOfObservationsSubset(
const Index32* objectPointIds,
const Vector3* referencePosition,
const Scalar minimalPriority,
IndexPairs32* pairs,
Lock* lock,
const unsigned int firstObjectPoint,
const unsigned int numberObjectPoints)
const;
1854 inline unsigned int numberValidPoses(
const Index32 objectPointId,
const IndexSet32& imagePointIds)
const;
1893 unsigned int poses_ = 0u;
1910template <
bool tThreadSafe>
1912 database_(database),
1913 imagePointIds_(imagePointIds)
1918template <
bool tThreadSafe>
1921 return imagePointIds_.size();
1924template <
bool tThreadSafe>
1927 ocean_assert(index < imagePointIds_.size());
1928 return database_.imagePoint<tThreadSafe>(imagePointIds_[index]);
1931template <
bool tThreadSafe>
1933 database_(database),
1939template <
bool tThreadSafe>
1942 return topology_.size();
1945template <
bool tThreadSafe>
1948 ocean_assert(index < topology_.size());
1949 return database_.imagePoint<tThreadSafe>(topology_[index].imagePointId());
1952template <
bool tThreadSafe>
1954 database_(database),
1960template <
bool tThreadSafe>
1963 return objectPointIds_.size();
1966template <
bool tThreadSafe>
1969 ocean_assert(index < objectPointIds_.size());
1970 return database_.objectPoint<tThreadSafe>(objectPointIds_[index]);
1973template <
bool tThreadSafe>
1975 database_(database),
1981template <
bool tThreadSafe>
1984 return poseIds_.size();
1987template <
bool tThreadSafe>
1990 ocean_assert(index < poseIds_.size());
1991 return database_.pose<tThreadSafe>(poseIds_[index]);
1994template <
bool tThreadSafe>
1996 database_(database),
2002template <
bool tThreadSafe>
2005 return topology_.size();
2008template <
bool tThreadSafe>
2011 ocean_assert(index < topology_.size());
2012 return database_.pose<tThreadSafe>(topology_[index].poseId());
2016 imagePointId_(imagePointId)
2023 return imagePointId_;
2028 imagePointId_ = imagePointId;
2032 objectPointId_(objectPointId)
2039 return objectPointId_;
2044 objectPointId_ = objectPointId;
2081 objectPointId_(objectPointId)
2098 return objectPointId_;
2113 objectPointId_ = objectPointId;
2118 return imagePointIds_;
2123 ocean_assert(imagePointIds_.find(imagePointId) == imagePointIds_.end());
2124 imagePointIds_.insert(imagePointId);
2129 ocean_assert(imagePointIds_.find(imagePointId) != imagePointIds_.end());
2130 imagePointIds_.erase(imagePointId);
2134 world_T_camera_(world_T_camera),
2142 return world_T_camera_;
2152 world_T_camera_ = world_T_camera;
2184 priority_ = priority;
2200 poseMap_(std::move(database.poseMap_)),
2201 objectPointMap_(std::move(database.objectPointMap_)),
2202 imagePointMap_(std::move(database.imagePointMap_)),
2203 poseObjectPointMap_(std::move(database.poseObjectPointMap_)),
2204 poses_(database.poses_),
2205 objectPointIdCounter_(database.objectPointIdCounter_),
2206 imagePointIdCounter_(database.imagePointIdCounter_)
2208 database.poses_ = 0u;
2209 database.objectPointIdCounter_ = invalidId;
2210 database.imagePointIdCounter_ = invalidId;
2218template <
bool tThreadSafe>
2226template <
bool tThreadSafe>
2234template <
bool tThreadSafe>
2242template <
bool tThreadSafe>
2250template <
bool tThreadSafe>
2253 ocean_assert(imagePointId !=
invalidId);
2261template <
bool tThreadSafe>
2271 ocean_assert(imagePointId !=
invalidId);
2280template <
bool tThreadSafe>
2290 ocean_assert(imagePointId !=
invalidId);
2299template <
bool tThreadSafe>
2313 if (!point && !pointId)
2318 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(iPoseObjectPoint->second);
2321 if (point !=
nullptr)
2323 *point = iImagePoint->second.point();
2326 if (pointId !=
nullptr)
2328 *pointId = iImagePoint->first;
2334template <
bool tThreadSafe>
2337 ocean_assert(objectPointId !=
invalidId);
2345template <
bool tThreadSafe>
2348 ocean_assert(objectPointId !=
invalidId);
2352 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
2356 return iObjectPoint->second.point();
2359template <
bool tThreadSafe>
2362 ocean_assert(objectPointId !=
invalidId);
2370template <
bool tThreadSafe>
2386template <
bool tThreadSafe,
bool tMatchPosition>
2403 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
2414 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
2424template <
bool tThreadSafe>
2434 ocean_assert(objectPointId !=
invalidId);
2443template <
bool tThreadSafe>
2451 return poseMap_.find(poseId)->second.pose();
2454template <
bool tThreadSafe>
2457 ocean_assert(
poseIds !=
nullptr && size != 0);
2462 result.reserve(size);
2464 for (
size_t n = 0; n < size; ++n)
2473template <
bool tThreadSafe>
2476 ocean_assert(
poseIds !=
nullptr && size != 0);
2481 result.reserve(size);
2483 for (
size_t n = 0; n < size; ++n)
2496template <
bool tThreadSafe,
bool tMatchPose>
2511 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
2513 if ((tMatchPose && iPose->second.pose() == referencePose) || (!tMatchPose && iPose->second.pose() != referencePose))
2515 poses.push_back(iPose->second.pose());
2516 poseIds->push_back(iPose->first);
2522 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
2524 if ((tMatchPose && iPose->second.pose() == referencePose) || (!tMatchPose && iPose->second.pose() != referencePose))
2526 poses.push_back(iPose->second.pose());
2534template <
bool tThreadSafe>
2537 ocean_assert(lowerPoseId <= upperPoseId);
2542 poses.reserve(upperPoseId - lowerPoseId + 1u);
2544 for (
unsigned int n = lowerPoseId; n <= upperPoseId; ++n)
2547 PoseMap::const_iterator iPose =
poseMap_.find(n);
2550 poses.push_back(iPose->second.pose());
2561template <
bool tThreadSafe,
bool tMatchPose>
2571 if (
poses !=
nullptr)
2576 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
2578 if ((tMatchPose && iPose->second.pose() == referencePose) || (!tMatchPose && iPose->second.pose() != referencePose))
2580 poseIds.push_back(iPose->first);
2581 poses->push_back(iPose->second.pose());
2587 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
2589 if ((tMatchPose && iPose->second.pose() == referencePose) || (!tMatchPose && iPose->second.pose() != referencePose))
2591 poseIds.push_back(iPose->first);
2599template <
bool tThreadSafe>
2609 lowerPoseId =
poseMap_.begin()->first;
2610 upperPoseId =
poseMap_.rbegin()->first;
2615template <
bool tThreadSafe>
2628 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
2630 if (iPose->second.pose().isValid())
2632 rangeLowerPoseId = iPose->first;
2642 for (PoseMap::const_reverse_iterator iPose =
poseMap_.rbegin(); iPose !=
poseMap_.rend(); ++iPose)
2644 if (iPose->second.pose().isValid())
2646 rangeUpperPoseId = iPose->first;
2651 ocean_assert(rangeLowerPoseId <= rangeUpperPoseId);
2655template <
bool tThreadSafe>
2659 ocean_assert(lowerPoseId <= startPoseId && startPoseId <= upperPoseId);
2663 PoseMap::const_iterator iPose =
poseMap_.find(startPoseId);
2664 if (iPose ==
poseMap_.end() || !(iPose->second.pose().isValid()))
2669 rangeLowerPoseId = startPoseId;
2670 rangeUpperPoseId = startPoseId;
2672 for (
unsigned int id = startPoseId - 1;
id != (
unsigned int)(-1) &&
id >= lowerPoseId; --id)
2676 if (iPose ==
poseMap_.end() || !(iPose->second.pose().isValid()))
2681 rangeLowerPoseId = id;
2684 for (
unsigned int id = startPoseId + 1u;
id <= upperPoseId; ++id)
2688 if (iPose ==
poseMap_.end() || !(iPose->second.pose().isValid()))
2693 rangeUpperPoseId = id;
2699template <
bool tThreadSafe>
2702 ocean_assert(lowerPoseId <= upperPoseId);
2704 if (lowerPoseId > upperPoseId)
2713 unsigned int bestRangeSize = 0u;
2714 unsigned int firstIndex = (
unsigned int)(-1);
2716 for (
unsigned int n = 0u; n < rangePoses.size(); ++n)
2720 if (rangePoses[n].isValid())
2725 else if (!rangePoses[n].isValid())
2727 const unsigned int lastIndex = n - 1u;
2728 ocean_assert(
firstIndex >= 0u && lastIndex < (
unsigned int)rangePoses.size());
2730 const unsigned int rangeSize = lastIndex -
firstIndex + 1u;
2732 if (rangeSize > bestRangeSize)
2734 bestRangeSize = rangeSize;
2736 rangeUpperPoseId = lastIndex + lowerPoseId;
2739 if (rangePoses.size() - n < bestRangeSize)
2751 return bestRangeSize != 0u;
2754 const unsigned int lastIndex = (
unsigned int)rangePoses.size() - 1u;
2755 ocean_assert(
firstIndex >= 0u && lastIndex < (
unsigned int)rangePoses.size());
2757 const unsigned int rangeSize = lastIndex -
firstIndex + 1u;
2758 if (rangeSize > bestRangeSize)
2761 rangeUpperPoseId = lastIndex + lowerPoseId;
2763 bestRangeSize = rangeSize;
2766 ocean_assert(bestRangeSize != 0u);
2770template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
2774 ocean_assert(lowerPoseId <= upperPoseId);
2779 unsigned int bestCorrespondences = 0u;
2781 for (
unsigned int id = lowerPoseId;
id <= upperPoseId; ++id)
2783 const unsigned int value = numberCorrespondences<false, tMatchPosition, tNeedValidPose>(
id, referenceObjectPoint);
2784 if (value > bestCorrespondences)
2786 bestCorrespondences = value;
2791 if (poseId !=
nullptr)
2793 *poseId = bestPoseId;
2796 if (correspondences !=
nullptr)
2798 *correspondences = bestCorrespondences;
2801 return bestCorrespondences != 0u;
2804template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
2808 ocean_assert(lowerPoseId <= upperPoseId);
2813 unsigned int worstCorrespondences = (
unsigned int)(-1);
2817 for (
unsigned int id = lowerPoseId;
id <= upperPoseId; ++id)
2819 if (tNeedValidPose && (!hasPose<false>(
id, &
pose) || !
pose.
isValid()))
2824 const unsigned int value = numberCorrespondences<false, tMatchPosition, false>(
id, referenceObjectPoint);
2825 if (value < worstCorrespondences)
2827 worstCorrespondences = value;
2832 if (poseId !=
nullptr)
2834 *poseId = worstPoseId;
2837 if (correspondences !=
nullptr)
2839 *correspondences = worstCorrespondences;
2842 return worstCorrespondences != (
unsigned int)(-1);
2845template <
bool tThreadSafe>
2848 ocean_assert(!poseCandidates.empty());
2849 ocean_assert(!majorObjectPointIds.empty());
2851 if (majorObjectPointIds.empty())
2858 unsigned int bestMajorCount = 0u;
2859 unsigned int bestMinorCount = 0u;
2863 for (
const Index32 poseCandidate : poseCandidates)
2865 const Index32 poseId = poseCandidate;
2867 unsigned int majorCount = 0u;
2868 unsigned int remaining = (
unsigned int)majorObjectPointIds.size();
2870 for (IndexSet32::const_iterator iId = majorObjectPointIds.begin(); majorCount + remaining >= bestMajorCount && iId != majorObjectPointIds.end(); ++iId)
2880 if (majorCount >= bestMajorCount)
2882 unsigned int minorCount = 0u;
2883 remaining = (
unsigned int)minorObjectPointIds.size();
2885 for (IndexSet32::const_iterator iId = minorObjectPointIds.begin(); minorCount + remaining >= bestMinorCount && iId != minorObjectPointIds.end(); ++iId)
2895 if (majorCount > bestMajorCount || minorCount > bestMinorCount)
2897 bestPoseId = poseId;
2898 bestMajorCount = majorCount;
2899 bestMinorCount = minorCount;
2911 if (visibleMajorObjectPointIds !=
nullptr)
2913 ocean_assert(visibleMajorObjectPointIds->empty());
2914 visibleMajorObjectPointIds->clear();
2915 visibleMajorObjectPointIds->reserve(bestMajorCount);
2917 for (
const Index32 majorObjectPointId : majorObjectPointIds)
2921 visibleMajorObjectPointIds->push_back(majorObjectPointId);
2925 ocean_assert(bestMajorCount == visibleMajorObjectPointIds->size());
2928 if (visibleMinorObjectPointIds !=
nullptr)
2930 ocean_assert(visibleMinorObjectPointIds->empty());
2931 visibleMinorObjectPointIds->clear();
2932 visibleMinorObjectPointIds->reserve(minorObjectPointIds.size());
2934 for (
const Index32 minorObjectPointId : minorObjectPointIds)
2938 visibleMinorObjectPointIds->push_back(minorObjectPointId);
2942 ocean_assert(bestMinorCount == visibleMinorObjectPointIds->size());
2948template <
bool tThreadSafe>
2955 unsigned int number = 0u;
2968template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
2975 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
2976 if (iPose ==
poseMap_.end() || (tNeedValidPose && !(iPose->second.pose().isValid())))
2981 unsigned int count = 0u;
2986 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
2989 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(iImagePoint->second.objectPointId());
2992 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referenceObjectPoint) || (!tMatchPosition && iObjectPoint->second.point() != referenceObjectPoint)))
3001template <
bool tThreadSafe,
bool tMatchPosition,
bool tNeedVal
idPose>
3004 ocean_assert(lowerPoseId <= upperPoseId);
3006 const unsigned int frames = upperPoseId - lowerPoseId + 1u;
3012 if (worker && frames >= 20u)
3014 result.resize(frames);
3016 worker->
executeFunction(
Worker::Function::create(*
this, &Database::numberCorrespondencesSubset<tMatchPosition, tNeedValidPose>, lowerPoseId, &referenceObjectPoint, minimalPriority, result.
data(), 0u, 0u), 0u, frames);
3020 result.reserve(frames);
3022 for (
unsigned int n = lowerPoseId; n <= upperPoseId; ++n)
3024 result.push_back(numberCorrespondences<false, tMatchPosition, tNeedValidPose>(n, referenceObjectPoint, minimalPriority));
3031template <
bool tThreadSafe>
3036 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
3051template <
bool tThreadSafe>
3060template <
bool tThreadSafe>
3063 ocean_assert(imagePointId !=
invalidId);
3067 const ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3076 ocean_assert(iPose !=
poseMap_.end());
3078 iPose->second.unregisterImagePoint(imagePointId);
3086 iObjectPoint->second.unregisterImagePoint(imagePointId);
3092template <
bool tThreadSafe>
3097 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3112template <
bool tThreadSafe>
3123template <
bool tThreadSafe>
3136 ocean_assert(secondDatabase.
hasObjectPoint<
false>(secondDatabaseObjectPointId));
3137 ocean_assert(!imagePointTransformation.
isSingular());
3138 ocean_assert(secondDatabaseLowerPoseId ==
invalidId || secondDatabaseUpperPoseId ==
invalidId || secondDatabaseLowerPoseId <= secondDatabaseUpperPoseId);
3148 ocean_assert(newObjectPointId ==
invalidId || hasObjectPoint<false>(newObjectPointId) ==
false);
3151 if (hasObjectPoint<false>(newObjectPointId))
3157 thisDatabaseObjectPointId = newObjectPointId;
3168 for (IndexSet32::const_iterator iId = secondDatabaseImagePointIds.cbegin(); iId != secondDatabaseImagePointIds.cend(); ++iId)
3170 const Index32& secondDatabaseImagePointId = *iId;
3178 if ((secondDatabaseLowerPoseId !=
invalidId && poseId < secondDatabaseLowerPoseId)
3179 || (secondDatabaseUpperPoseId !=
invalidId && poseId > secondDatabaseUpperPoseId))
3185 if (!hasPose<false>(poseId))
3187 if (forExistingPosesOnly)
3197 const bool addPoseResult = addPose<false>(poseId,
pose);
3198 ocean_assert_and_suppress_unused(addPoseResult, addPoseResult);
3207 const Index32 thisDatabaseImagePointId = addImagePoint<false>(imagePointTransformation *
imagePoint);
3209 attachImagePointToObjectPoint<false>(thisDatabaseImagePointId, thisDatabaseObjectPointId);
3210 attachImagePointToPose<false>(thisDatabaseImagePointId, poseId);
3213 return thisDatabaseObjectPointId;
3216template <
bool tThreadSafe>
3219 ocean_assert(objectPointId !=
invalidId);
3223 const ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3232 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3235 if (iImagePoint->second.poseId() !=
invalidId)
3241 iImagePoint->second.setObjectPointId(
invalidId);
3247template <
bool tThreadSafe>
3250 ocean_assert(objectPointId !=
invalidId);
3254 const ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3263 const ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3266 const Index32 poseId = iImagePoint->second.poseId();
3273 const PoseMap::iterator iPose =
poseMap_.find(poseId);
3274 ocean_assert(iPose !=
poseMap_.cend());
3276 iPose->second.unregisterImagePoint(imagePointId);
3285template <
bool tThreadSafe>
3294 ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(oldObjectPointId);
3301 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3304 ocean_assert(iImagePoint->second.objectPointId() == oldObjectPointId);
3305 iImagePoint->second.setObjectPointId(newObjectPointId);
3307 if (iImagePoint->second.poseId() !=
invalidId)
3309 const Index64 oldPoseObjectPointId =
index64(iImagePoint->second.poseId(), oldObjectPointId);
3314 const Index64 newPoseObjectPointId =
index64(iImagePoint->second.poseId(), newObjectPointId);
3321 objectPointMap_.insert(std::make_pair(newObjectPointId, std::move(iObjectPoint->second)));
3325template <
bool tThreadSafe>
3328 ocean_assert(remainingObjectPointId !=
invalidId && removingObjectPointId !=
invalidId && remainingObjectPointId != removingObjectPointId);
3332 ObjectPointMap::iterator iObjectPointRemaining =
objectPointMap_.find(remainingObjectPointId);
3335 ObjectPointMap::const_iterator iObjectPointRemoving =
objectPointMap_.find(removingObjectPointId);
3339 const IndexSet32 debugPoseIdsRemaining = posesFromObjectPoint<false>(remainingObjectPointId);
3340 const IndexSet32 debugPoseIdsRemoving = posesFromObjectPoint<false>(removingObjectPointId);
3344 for (
const Index32& imagePointIdRemoving : iObjectPointRemoving->second.imagePointIds())
3346 iObjectPointRemaining->second.registerImagePoint(imagePointIdRemoving);
3348 ImagePointMap::iterator iImagePointRemoving =
imagePointMap_.find(imagePointIdRemoving);
3351 const Index32 poseIdRemoving = iImagePointRemoving->second.poseId();
3359 iImagePointRemoving->second.setObjectPointId(remainingObjectPointId);
3362 iObjectPointRemaining->second.setPoint(newPoint);
3363 iObjectPointRemaining->second.setPriority(newPriority);
3368template <
bool tThreadSafe>
3375 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
3381 if (
pose !=
nullptr)
3383 *
pose = iPose->second.pose();
3389template <
bool tThreadSafe>
3394 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
3397 ocean_assert(
false &&
"Invalid pose id!");
3408template <
bool tThreadSafe>
3415 const PoseMap::iterator iPose =
poseMap_.find(poseId);
3416 ocean_assert(iPose !=
poseMap_.end());
3420 const PoseData& data = iPose->second;
3424 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3427 iImagePoint->second.setPoseId(
invalidId);
3433template <
bool tThreadSafe>
3436 ocean_assert(imagePointId !=
invalidId);
3440 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
3443 return iImagePoint->second.poseId();
3446template <
bool tThreadSafe>
3449 ocean_assert(objectPointId !=
invalidId);
3453 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3456 const IndexSet32& ids = iObjectPoint->second.imagePointIds();
3461template <
bool tThreadSafe>
3464 ocean_assert(objectPointId !=
invalidId);
3470 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3473 const IndexSet32& ids = iObjectPoint->second.imagePointIds();
3485 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(
id);
3488 if (iImagePoint->second.poseId() !=
invalidId)
3490 poseIds.push_back(iImagePoint->second.poseId());
3495 imagePoints->push_back(iImagePoint->second.point());
3501template <
bool tThreadSafe>
3504 ocean_assert(objectPointId !=
invalidId);
3505 ocean_assert(!poseIdCandidates.empty() && validPoseIndices.empty());
3512 for (
size_t n = 0; n < poseIdCandidates.size(); ++n)
3514 const Index32 poseId = poseIdCandidates[n];
3520 validPoseIndices.push_back((
unsigned int)n);
3536template <
bool tThreadSafe>
3539 ocean_assert(imagePointId !=
invalidId);
3543 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
3546 return iImagePoint->second.objectPointId();
3549template <
bool tThreadSafe>
3556 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
3557 ocean_assert(iPose !=
poseMap_.end());
3559 return iPose->second.imagePointIds();
3562template <
bool tThreadSafe>
3565 ocean_assert(objectPointId !=
invalidId);
3569 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3572 return iObjectPoint->second.imagePointIds();
3575template <
bool tThreadSafe>
3578 ocean_assert(objectPointId !=
invalidId);
3582 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3587 for (
const Index32& imagePointId : iObjectPoint->second.imagePointIds())
3589 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
3592 result.emplace(iImagePoint->second.poseId());
3598template <
bool tThreadSafe>
3605 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3607 ocean_assert(iImagePoint->second.objectPointId() ==
invalidId);
3609 iImagePoint->second.setObjectPointId(objectPointId);
3611 ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3614 iObjectPoint->second.registerImagePoint(imagePointId);
3616 if (iImagePoint->second.poseId() !=
invalidId)
3618 const Index64 poseObjectPointId(
index64(iImagePoint->second.poseId(), objectPointId));
3625template <
bool tThreadSafe>
3628 ocean_assert(imagePointId !=
invalidId);
3632 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3635 const Index32 objectPointId = iImagePoint->second.objectPointId();
3636 ocean_assert(objectPointId !=
invalidId);
3638 iImagePoint->second.setObjectPointId(
invalidId);
3640 ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3643 iObjectPoint->second.unregisterImagePoint(imagePointId);
3645 if (iImagePoint->second.poseId() !=
invalidId)
3647 const Index64 poseObjectPointId(
index64(iImagePoint->second.poseId(), objectPointId));
3654template <
bool tThreadSafe>
3661 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3663 ocean_assert(iImagePoint->second.poseId() ==
invalidId);
3665 iImagePoint->second.setPoseId(poseId);
3667 PoseMap::iterator iPose =
poseMap_.find(poseId);
3668 ocean_assert(iPose !=
poseMap_.end());
3670 iPose->second.registerImagePoint(imagePointId);
3672 if (iImagePoint->second.objectPointId() !=
invalidId)
3674 const Index64 poseObjectPointId(
index64(poseId, iImagePoint->second.objectPointId()));
3681template <
bool tThreadSafe>
3684 ocean_assert(imagePointId !=
invalidId);
3688 ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3691 const Index32 poseId = iImagePoint->second.poseId();
3694 iImagePoint->second.setPoseId(
invalidId);
3696 PoseMap::iterator iPose =
poseMap_.find(poseId);
3697 ocean_assert(iPose !=
poseMap_.end());
3699 iPose->second.unregisterImagePoint(imagePointId);
3701 if (iImagePoint->second.objectPointId() !=
invalidId)
3703 const Index64 poseObjectPointId(
index64(poseId, iImagePoint->second.objectPointId()));
3710template <
bool tThreadSafe>
3713 ocean_assert(imagePointId !=
invalidId);
3717 const ImagePointMap::iterator iImagePoint =
imagePointMap_.find(imagePointId);
3723template <
bool tThreadSafe>
3726 ocean_assert(objectPointId !=
invalidId);
3730 const ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3736template <
bool tThreadSafe>
3743 for (
size_t n = 0; n < number; ++ n)
3752template <
bool tThreadSafe>
3759 for (
size_t n = 0; n < number; ++ n)
3764 iObjectPoint->second.setPoint(referenceObjectPoint);
3768template <
bool tThreadSafe>
3779template <
bool tThreadSafe>
3782 ocean_assert(objectPointId !=
invalidId);
3786 const ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3790 iObjectPoint->second.setPriority(priority);
3793template <
bool tThreadSafe>
3796 ocean_assert(objectPointId !=
invalidId);
3800 const ObjectPointMap::iterator iObjectPoint =
objectPointMap_.find(objectPointId);
3803 iObjectPoint->second.setPriority(priority);
3806template <
bool tThreadSafe>
3813 const PoseMap::iterator iPose =
poseMap_.find(poseId);
3814 ocean_assert(iPose !=
poseMap_.end());
3816 iPose->second.setPose(
pose);
3819template <
bool tThreadSafe>
3826 for (
size_t n = 0; n < number; ++n)
3829 ocean_assert(iPose !=
poseMap_.end());
3831 iPose->second.setPose(
poses[n]);
3835template <
bool tThreadSafe>
3842 ocean_assert(n >= 0);
3843 const unsigned int poseId = (
unsigned int)n;
3845 const PoseMap::iterator iPose =
poseMap_.find(poseId);
3846 ocean_assert(iPose !=
poseMap_.end());
3848 iPose->second.setPose(
poses[n]);
3852template <
bool tThreadSafe>
3857 for (PoseMap::iterator iPose =
poseMap_.begin(); iPose !=
poseMap_.end(); ++iPose)
3859 iPose->second.setPose(
pose);
3863template <
bool tThreadSafe>
3870 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
3871 ocean_assert(iPose !=
poseMap_.end());
3873 return iPose->second.imagePointIds();
3876template <
bool tThreadSafe>
3898 ids.push_back(iPoseObjectPoint->second);
3899 validObjectPointIds.push_back(objectPointId);
3907template <
bool tThreadSafe>
3919 result.emplace_back(iImagePoint->first);
3921 imagePoints->emplace_back(iImagePoint->second.point());
3928 result.emplace_back(iImagePoint->first);
3935template <
bool tThreadSafe>
3950 result.emplace_back(iObjectPoint->first);
3952 objectPoints->emplace_back(iObjectPoint->second.point());
3959 result.emplace_back(iObjectPoint->first);
3963 if (priorities !=
nullptr)
3965 priorities->clear();
3970 priorities->emplace_back(iObjectPoint->second.priority());
3977template <
bool tThreadSafe>
3980 if (outlierObjectPointIds.empty())
3982 return objectPointIds<tThreadSafe>();
3992 if (outlierObjectPointIds.find(iObjectPoint->first) == outlierObjectPointIds.end())
3994 result.push_back(iObjectPoint->first);
4001template <
bool tThreadSafe>
4009 if (world_T_cameras !=
nullptr)
4011 world_T_cameras->clear();
4012 world_T_cameras->reserve(
poseMap_.size());
4014 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
4016 result.emplace_back(iPose->first);
4018 world_T_cameras->emplace_back(iPose->second.pose());
4023 for (PoseMap::const_iterator iPose =
poseMap_.cbegin(); iPose !=
poseMap_.cend(); ++iPose)
4025 result.emplace_back(iPose->first);
4032template <
bool tThreadSafe>
4040 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4041 ocean_assert(iPose !=
poseMap_.end());
4044 result.reserve(iPose->second.imagePointIds().size());
4048 imagePointIds->reserve(iPose->second.imagePointIds().size());
4051 for (
const Index32 imagePointId : iPose->second.imagePointIds())
4053 ocean_assert(imagePointId !=
invalidId);
4055 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4058 result.push_back(iImagePoint->second.point());
4069template <
bool tThreadSafe,
bool tMatchPosition>
4083 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4094 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4104template <
bool tThreadSafe,
bool tMatchPosition>
4118 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition))
4119 && outlierObjectPointIds.find(iObjectPoint->first) == outlierObjectPointIds.end())
4130 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition))
4131 && outlierObjectPointIds.find(iObjectPoint->first) == outlierObjectPointIds.end())
4141template <
bool tThreadSafe,
bool tMatchPosition>
4157 if (worker !=
nullptr)
4160 worker->
executeFunction(
Worker::Function::create(*
this, &Database::objectPointIdsWithNumberOfObservationsSubset<tMatchPosition>, (
const Index32*)
objectPointIds.data(), &referencePosition, minimalPriority, &result, &
lock, 0u, 0u), 0u, (
unsigned int)
objectPointIds.size());
4164 objectPointIdsWithNumberOfObservationsSubset<tMatchPosition>((
const Index32*)
objectPointIds.data(), &referencePosition, minimalPriority, &result,
nullptr, 0u, (
unsigned int)
objectPointIds.size());
4170template <
bool tThreadSafe>
4178 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4179 ocean_assert(iPose !=
poseMap_.end());
4193 ocean_assert(imagePointId !=
invalidId);
4195 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4198 const Index32 objectPointId = iImagePoint->second.objectPointId();
4202 result.push_back(objectPointId);
4206 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4214 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4219template <
bool tThreadSafe,
bool tMatchPosition>
4227 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4228 ocean_assert(iPose !=
poseMap_.end());
4242 ocean_assert(imagePointId !=
invalidId);
4244 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4247 const Index32 objectPointId = iImagePoint->second.objectPointId();
4251 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4256 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition &&
objectPoint == referencePosition) || (!tMatchPosition &&
objectPoint != referencePosition)))
4258 result.push_back(objectPointId);
4268 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4273template <
bool tThreadSafe>
4276 ocean_assert(!
poseIds.empty());
4285 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4286 ocean_assert(iPose !=
poseMap_.end());
4294 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(*iId);
4297 const Index32 objectPointId = iImagePoint->second.objectPointId();
4317 result.push_back(*iId);
4329template <
bool tThreadSafe,
bool tMatchPosition,
bool tVisibleInAllPoses>
4332 ocean_assert(lowerPoseId <= upperPoseId);
4337 if constexpr (tVisibleInAllPoses)
4341 const PoseMap::const_iterator iPose =
poseMap_.find(lowerPoseId);
4353 ocean_assert(imagePointId !=
invalidId);
4355 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4358 const Index32 objectPointId = iImagePoint->second.objectPointId();
4362 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4365 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4367 bool visibleInAllPoses =
true;
4368 for (
unsigned int n = lowerPoseId + 1u; visibleInAllPoses && n <= upperPoseId; ++n)
4373 if (visibleInAllPoses)
4375 result.push_back(objectPointId);
4386 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4396 for (
unsigned int n = lowerPoseId; n <= upperPoseId; ++n)
4398 const PoseMap::const_iterator iPose =
poseMap_.find(n);
4406 ocean_assert(imagePointId !=
invalidId);
4408 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4411 const Index32 objectPointId = iImagePoint->second.objectPointId();
4417 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4420 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4422 result.push_back(objectPointId);
4434 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4441template <
bool tThreadSafe,
bool tMatchPosition,
bool tVisibleInAllPoses>
4454 if constexpr (tVisibleInAllPoses)
4470 ocean_assert(imagePointId !=
invalidId);
4472 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4475 const Index32 objectPointId = iImagePoint->second.objectPointId();
4479 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4482 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4484 bool visibleInAllPoses =
true;
4485 for (
size_t n = 1; visibleInAllPoses && n <
poseIds.size(); ++n)
4490 if (visibleInAllPoses)
4492 result.push_back(objectPointId);
4503 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4513 for (
size_t n = 0; n <
poseIds.size(); ++n)
4523 ocean_assert(imagePointId !=
invalidId);
4525 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4528 const Index32 objectPointId = iImagePoint->second.objectPointId();
4534 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4537 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)))
4539 result.push_back(objectPointId);
4551 ocean_assert(
IndexSet32(result.begin(), result.end()).size() == result.size());
4558template <
bool tThreadSafe>
4565 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4567 ocean_assert(iPose !=
poseMap_.end());
4584 ocean_assert(imagePointId !=
invalidId);
4586 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4589 if (iImagePoint->second.objectPointId() !=
invalidId)
4591 result.push_back(iImagePoint->second.point());
4601template <
bool tThreadSafe>
4622 ocean_assert(iPoseObjectPoint->second !=
invalidId);
4623 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(iPoseObjectPoint->second);
4626 points.push_back(iImagePoint->second.point());
4627 validObjectPointIds.push_back(objectPointId);
4640template <
bool tThreadSafe>
4650template <
bool tThreadSafe>
4660 points.reserve(numberObjectPointIds);
4662 for (
size_t n = 0; n < numberObjectPointIds; ++n)
4670 ocean_assert(iPoseObjectPoint->second !=
invalidId);
4671 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(iPoseObjectPoint->second);
4674 points.push_back(iImagePoint->second.point());
4675 validIndices.push_back((
unsigned int)n);
4687template <
bool tThreadSafe>
4690 ocean_assert(!
poseIds.empty());
4706 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4709 if (iImagePoint->second.objectPointId() !=
invalidId)
4711 intermediate[iImagePoint->second.objectPointId()].push_back(iImagePoint->second.point());
4718 for (ImagePointsMap::iterator iImagePoints = intermediate.begin(); iImagePoints != intermediate.end(); ++iImagePoints)
4720 if (iImagePoints->second.size() ==
poseIds.size())
4724 for (
size_t n = 0; n <
poseIds.size(); ++n)
4726 result[n].push_back(iImagePoints->second[n]);
4734template <
bool tThreadSafe>
4738 ocean_assert(maximalObservations == 0 || minimalObservations <= maximalObservations);
4744 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4745 ocean_assert(iPose !=
poseMap_.end());
4747 const PoseData& poseData = iPose->second;
4751 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4754 const Index32 objectPointId = iImagePoint->second.objectPointId();
4759 imagePointPairs.emplace_back(imagePointId, iImagePoint->second.point());
4764 while (((previous && pId-- != 0u) || (!previous && ++pId <
poses_)) && (maximalObservations == 0 || imagePointPairs.size() < maximalObservations))
4773 const ImagePointMap::const_iterator iOtherImagePoint =
imagePointMap_.find(iPoseObjectPoint->second);
4776 imagePointPairs.emplace_back(iPoseObjectPoint->second, iOtherImagePoint->second.point());
4779 if (minimalObservations == 0 || imagePointPairs.size() >= minimalObservations)
4781 result[objectPointId] = imagePointPairs;
4789template <
bool tThreadSafe>
4793 ocean_assert(pose0 != pose1);
4795 ocean_assert(points0.size() == points1.size());
4799 const PoseMap::const_iterator iPose0 =
poseMap_.find(pose0);
4800 ocean_assert(iPose0 !=
poseMap_.end());
4802 const PoseData& poseData0 = iPose0->second;
4806 const ImagePointMap::const_iterator iImagePoint0 =
imagePointMap_.find(imagePointId);
4809 ocean_assert(iImagePoint0->second.poseId() == pose0);
4810 if (iImagePoint0->second.objectPointId() !=
invalidId)
4812 const Index64To32Map::const_iterator iPoseObjectPoint =
poseObjectPointMap_.find(
index64(pose1, iImagePoint0->second.objectPointId()));
4816 const ImagePointMap::const_iterator iImagePoint1 =
imagePointMap_.find(iPoseObjectPoint->second);
4819 points0.push_back(iImagePoint0->second.point());
4820 points1.push_back(iImagePoint1->second.point());
4831template <
bool tThreadSafe,
bool tMatchPosition>
4842 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4843 ocean_assert(iPose !=
poseMap_.end());
4845 const PoseData& poseData = iPose->second;
4862 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4865 if (iImagePoint->second.objectPointId() !=
invalidId)
4867 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(iImagePoint->second.objectPointId());
4870 if (((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)) && (minimalObservations == 0 || iObjectPoint->second.imagePointIds().size() >= minimalObservations))
4872 imagePoints.push_back(iImagePoint->second.point());
4889template <
bool tThreadSafe,
bool tMatchPosition>
4890void Database::imagePointsObjectPoints(
const Index32 poseId,
const IndexSet32& priorityIds,
Vectors2& priorityImagePoints,
Vectors3& priorityObjectPoints,
Vectors2& remainingImagePoints,
Vectors3& remainingObjectPoints,
const Vector3& referencePosition,
const size_t minimalObservations,
Indices32* priorityImagePointIds,
Indices32* priorityObjectPointIds,
Indices32* remainingImagePointIds,
Indices32* remainingObjectPointIds)
const
4893 ocean_assert(priorityImagePoints.empty() && priorityObjectPoints.empty());
4894 ocean_assert(remainingImagePoints.empty() && remainingObjectPoints.empty());
4896 ocean_assert(priorityImagePointIds ==
nullptr || priorityImagePointIds->empty());
4897 ocean_assert(priorityObjectPointIds ==
nullptr || priorityObjectPointIds->empty());
4898 ocean_assert(remainingImagePointIds ==
nullptr || remainingImagePointIds->empty());
4899 ocean_assert(remainingObjectPointIds ==
nullptr || remainingObjectPointIds->empty());
4901 ocean_assert(!priorityIds.empty());
4905 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
4906 ocean_assert(iPose !=
poseMap_.end());
4908 const PoseData& poseData = iPose->second;
4910 priorityImagePoints.reserve(poseData.
imagePointIds().size());
4911 priorityObjectPoints.reserve(poseData.
imagePointIds().size());
4913 remainingImagePoints.reserve(poseData.
imagePointIds().size());
4914 remainingObjectPoints.reserve(poseData.
imagePointIds().size());
4916 if (priorityImagePointIds !=
nullptr)
4918 priorityImagePointIds->reserve(poseData.
imagePointIds().size());
4921 if (priorityObjectPointIds !=
nullptr)
4923 priorityObjectPointIds->reserve(poseData.
imagePointIds().size());
4926 if (remainingImagePointIds !=
nullptr)
4928 remainingImagePointIds->reserve(poseData.
imagePointIds().size());
4931 if (remainingObjectPointIds !=
nullptr)
4933 remainingObjectPointIds->reserve(poseData.
imagePointIds().size());
4938 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
4941 if (iImagePoint->second.objectPointId() !=
invalidId)
4943 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(iImagePoint->second.objectPointId());
4946 if (((tMatchPosition && iObjectPoint->second.point() == referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != referencePosition)) && (minimalObservations == 0 || iObjectPoint->second.imagePointIds().size() >= minimalObservations))
4948 ocean_assert(iObjectPoint->first == iImagePoint->second.objectPointId());
4950 if (priorityIds.find(iObjectPoint->first) != priorityIds.end())
4952 priorityImagePoints.push_back(iImagePoint->second.point());
4953 priorityObjectPoints.push_back(iObjectPoint->second.point());
4955 if (priorityImagePointIds !=
nullptr)
4957 priorityImagePointIds->push_back(iImagePoint->first);
4960 if (priorityObjectPointIds !=
nullptr)
4962 priorityObjectPointIds->push_back(iImagePoint->second.objectPointId());
4967 remainingImagePoints.push_back(iImagePoint->second.point());
4968 remainingObjectPoints.push_back(iObjectPoint->second.point());
4970 if (remainingImagePointIds !=
nullptr)
4972 remainingImagePointIds->push_back(iImagePoint->first);
4975 if (remainingObjectPointIds !=
nullptr)
4977 remainingObjectPointIds->push_back(iImagePoint->second.objectPointId());
4985template <
bool tThreadSafe,
bool tMatchPose>
4988 ocean_assert(objectPointId !=
invalidId);
4996 const ObjectPointMap::const_iterator iObjectPoint =
objectPointMap_.find(objectPointId);
4999 const IndexSet32& imagePointCandidateIds = iObjectPoint->second.imagePointIds();
5001 poses.reserve(imagePointCandidateIds.size());
5002 imagePoints.reserve(imagePointCandidateIds.size());
5006 poseIds->reserve(imagePointCandidateIds.size());
5014 for (
const Index32 imagePointCandidateId : imagePointCandidateIds)
5016 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointCandidateId);
5020 const Index32 poseId = iImagePoint->second.poseId();
5022 if (poseId ==
invalidId || (lowerPoseId !=
invalidId && poseId < lowerPoseId) || (upperPoseId !=
invalidId && poseId > upperPoseId))
5027 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
5028 ocean_assert(iPose !=
poseMap_.end());
5032 if ((tMatchPose &&
pose == referencePose) || (!tMatchPose &&
pose != referencePose))
5052template <
bool tThreadSafe>
5055 ocean_assert(!
poseIds.empty());
5063 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
5064 ocean_assert(iPose !=
poseMap_.end());
5066 const IndexSet32& poseImagePoints = iPose->second.imagePointIds();
5068 for (IndexSet32::const_iterator iId = poseImagePoints.cbegin(); iId != poseImagePoints.cend(); ++iId)
5070 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(*iId);
5073 const Index32 objectPointId = iImagePoint->second.objectPointId();
5085template <
bool tThreadSafe>
5101template <
bool tThreadSafe>
5108 iObjectPoint->second.setPoint(referenceObjectPoint);
5111 for (PoseMap::iterator iPose =
poseMap_.begin(); iPose !=
poseMap_.end(); ++iPose)
5113 iPose->second.setPose(referencePose);
5117template <
typename T,
bool tThreadSafe>
5118void Database::reset(
const size_t numberPoses,
const Index32* poseIds,
const HomogenousMatrixT4<T>* poses,
const size_t numberObjectPoints,
const Index32* objectPointIds,
const VectorT3<T>* objectPoints,
const T* objectPointPriorities,
const size_t numberImagePoints,
const Index32* imagePointIds,
const VectorT2<T>* imagePoints,
const Index32* topologyPoseIds,
const Index32* topologyObjectPointIds)
5128 for (
size_t n = 0; n < numberPoses; ++n)
5142 for (
size_t n = 0; n < numberObjectPoints; ++n)
5159 ocean_assert(objectPointId !=
invalidId);
5166 for (
size_t n = 0; n < numberImagePoints; ++n)
5171 const Index32& topologyPoseId = topologyPoseIds[n];
5172 const Index32& topologyObjectPointId = topologyObjectPointIds[n];
5184 poseMap_[topologyPoseId].registerImagePoint(imagePointId);
5187 objectPointMap_[topologyObjectPointId].registerImagePoint(imagePointId);
5190 ocean_assert(imagePointId !=
invalidId);
5197 ocean_assert(!
poseIds.empty());
5206 result.push_back(n);
5224 result.push_back(n);
5242 result.push_back(n);
5256 ocean_assert(iTopology->objectPointId() !=
invalidId);
5257 objectPointCounterMap[iTopology->objectPointId()]++;
5263 for (Index32To32Map::const_iterator iCounter = objectPointCounterMap.cbegin(); iCounter != objectPointCounterMap.cend(); ++iCounter)
5265 if (iCounter->second >= minimalObservations)
5276 if (
this != &database)
5293 if (
this != &database)
5295 poseMap_ = std::move(database.poseMap_);
5296 objectPointMap_ = std::move(database.objectPointMap_);
5297 imagePointMap_ = std::move(database.imagePointMap_);
5298 poseObjectPointMap_ = std::move(database.poseObjectPointMap_);
5300 poses_ = database.poses_;
5301 objectPointIdCounter_ = database.objectPointIdCounter_;
5302 imagePointIdCounter_ = database.imagePointIdCounter_;
5304 database.poses_ = 0u;
5305 database.objectPointIdCounter_ = invalidId;
5306 database.imagePointIdCounter_ = invalidId;
5312inline Database::operator bool()
const
5314 return !isEmpty<false>();
5317template <
bool tMatchPosition,
bool tNeedVal
idPose>
5320 ocean_assert(numberPoses >= 1u);
5321 ocean_assert(referenceObjectPoint && correspondences);
5323 for (
unsigned int n = firstPose; n < firstPose + numberPoses; ++n)
5325 correspondences[n] = numberCorrespondences<false, tMatchPosition, tNeedValidPose>(lowerPoseId + n, *referenceObjectPoint, minimalPriority);
5329template <
bool tMatchPosition>
5335 localPairs.reserve(numberObjectPoints);
5337 for (
unsigned int n = firstObjectPoint; n < firstObjectPoint + numberObjectPoints; ++n)
5340 if (iObjectPoint->second.priority() >= minimalPriority && ((tMatchPosition && iObjectPoint->second.point() == *referencePosition) || (!tMatchPosition && iObjectPoint->second.point() != *referencePosition)))
5342 localPairs.emplace_back(iObjectPoint->first,
numberValidPoses(iObjectPoint->first, iObjectPoint->second.imagePointIds()));
5346 if (
lock !=
nullptr)
5349 pairs->insert(pairs->end(), localPairs.begin(), localPairs.end());
5353 *pairs = std::move(localPairs);
5359 ocean_assert_and_suppress_unused(objectPointId !=
invalidId, objectPointId);
5364 unsigned int validPoses = 0u;
5368 const ImagePointMap::const_iterator iImagePoint =
imagePointMap_.find(imagePointId);
5371 const Index32 poseId = iImagePoint->second.poseId();
5373 const PoseMap::const_iterator iPose =
poseMap_.find(poseId);
5374 ocean_assert(iPose !=
poseMap_.end());
5389 return Index32(index & 0xFFFFFFFFull);
static Caller< void > create(CT &object, typename MemberFunctionPointerMaker< CT, void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a member function with no function parameter.
Definition Caller.h:3024
This class implements a base class for all indexed-based accessors allowing a constant reference acce...
Definition Accessor.h:241
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition HomogenousMatrix4.h:1487
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition HomogenousMatrix4.h:1375
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
This class implements a recursive lock object.
Definition Lock.h:31
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T minValue()
Returns the min scalar value.
Definition Numeric.h:3259
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:147
This class implements a vector with shifted elements.
Definition ShiftVector.h:27
std::ptrdiff_t Index
Definition of an element index.
Definition ShiftVector.h:38
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition SquareMatrix3.h:1342
static bool hasIntersectingElement(const TIterator &firstA, const TIterator &endA, const TIterator &firstB, const TIterator &endB)
Determines whether two (ordered) sets have at least one intersecting element.
Definition Subset.h:1036
This class implements a recursive scoped lock object that is activated by a boolean template paramete...
Definition Lock.h:190
This class implements an accessor object for image points based on a set of image point ids.
Definition Database.h:263
const Database & database_
The reference to the database holding the individual image points.
Definition Database.h:290
ConstImagePointAccessorIds(const Database &database, const Indices32 &imagePointIds)
Creates a new accessor object by providing the references of the database and the image point ids.
Definition Database.h:1911
const Indices32 & imagePointIds_
The reference to the image point ids.
Definition Database.h:293
const Vector2 & operator[](const size_t &index) const override
Returns a specific image point identified by the index within from the specified image point ids.
Definition Database.h:1925
size_t size() const override
Returns the number of image points of this accessor.
Definition Database.h:1919
This class implements an accessor object for image points based on a topology between poses and image...
Definition Database.h:302
const PoseImagePointTopology & topology_
The topology between poses and image points.
Definition Database.h:332
const Database & database_
The reference to the database holding the individual image points.
Definition Database.h:329
size_t size() const override
Returns the number of image points of this accessor.
Definition Database.h:1940
ConstImagePointAccessorTopology(const Database &database, const PoseImagePointTopology &topology)
Creates a new accessor object by providing the references of the database and the topology.
Definition Database.h:1932
const Vector2 & operator[](const size_t &index) const override
Returns a specific image point identified by the index within from the specified topology.
Definition Database.h:1946
This class implements an accessor object for object points based on a set of object point ids.
Definition Database.h:341
ConstObjectPointAccessorIds(const Database &database, const Indices32 &objectPointIds)
Creates a new accessor object by providing the references of the database and the object point ids.
Definition Database.h:1953
const Indices32 & objectPointIds_
The reference to the object point ids.
Definition Database.h:371
size_t size() const override
Returns the number of object points of this accessor.
Definition Database.h:1961
const Vector3 & operator[](const size_t &index) const override
Returns a specific object point identified by the index within from the specified object point ids.
Definition Database.h:1967
const Database & database_
The reference to the database holding the individual object points.
Definition Database.h:368
This class implements an accessor object for poses based on a set of pose ids.
Definition Database.h:380
const Indices32 & poseIds_
The reference to the pose ids.
Definition Database.h:410
const Database & database_
The reference to the database holding the individual object points.
Definition Database.h:407
const HomogenousMatrix4 & operator[](const size_t &index) const override
Returns a specific pose identified by the index within from the specified pose ids.
Definition Database.h:1988
size_t size() const override
Returns the number of poses of this accessor.
Definition Database.h:1982
ConstPoseAccessorIds(const Database &database, const Indices32 &poseIds)
Creates a new accessor object by providing the references of the database and the pose ids.
Definition Database.h:1974
This class implements an accessor object for poses based on a topology between poses and image points...
Definition Database.h:419
const Database & database_
The reference to the database holding the individual image points.
Definition Database.h:446
ConstPoseAccessorTopology(const Database &database, const PoseImagePointTopology &topology)
Creates a new accessor object by providing the references of the database and the topology.
Definition Database.h:1995
size_t size() const override
Returns the number of poses of this accessor.
Definition Database.h:2003
const HomogenousMatrix4 & operator[](const size_t &index) const override
Returns a specific pose identified by the index within from the specified topology.
Definition Database.h:2009
const PoseImagePointTopology & topology_
The topology between poses and image points.
Definition Database.h:449
The base class for all data object storing a set of image point ids.
Definition Database.h:526
const IndexSet32 & imagePointIds() const
Returns the image point ids of this object.
Definition Database.h:2116
IndexSet32 imagePointIds_
The set of registered image point ids of this object.
Definition Database.h:550
void registerImagePoint(const Index32 imagePointId)
Registers (adds) a new image point id at this data object.
Definition Database.h:2121
void unregisterImagePoint(const Index32 imagePointId)
Unregisters (removes) an image point id from this data object.
Definition Database.h:2127
This class implements a data object storing the information connected with an id of an image point.
Definition Database.h:458
Index32 poseId() const
Returns the id of the pose which belongs to the image point of this object.
Definition Database.h:2091
ImagePointData()=default
Creates a default object.
void setPoint(const Vector2 &point)
Sets the location of the image point of this object.
Definition Database.h:2101
Index32 objectPointId() const
Returns the ids of the 3D object point which belongs to the image point of this object.
Definition Database.h:2096
void setPoseId(const Index32 poseId)
Sets the id of the pose belonging to this image point object.
Definition Database.h:2106
void setObjectPointId(const Index32 objectPointId)
Sets the id of the object point belonging to this image point object.
Definition Database.h:2111
const Vector2 & point() const
Returns the 2D location of the image point of this object.
Definition Database.h:2086
This class implements an object storing an id of an image point.
Definition Database.h:115
ImagePointObject(const Index32 imagePointId=invalidId)
Creates a new object.
Definition Database.h:2015
void setImagePointId(const Index32 imagePointId)
Sets or changes the id of the image point of this object.
Definition Database.h:2026
Index32 imagePointId() const
Returns the id of the image point of this object.
Definition Database.h:2021
The data object encapsulating a 3D object point.
Definition Database.h:604
void setPoint(const Vector3 &point)
Sets (changes) the 3D object point of this object.
Definition Database.h:2177
ObjectPointData(const Vector3 &point=invalidObjectPoint(), const Scalar priority=-1)
Creates an object with invalid object point.
Definition Database.h:2160
void setPriority(const Scalar priority)
Sets (changes) the priority value of this object.
Definition Database.h:2182
Scalar priority() const
Returns the priority value of this object.
Definition Database.h:2172
const Vector3 & point() const
Returns the 3D object point of this object.
Definition Database.h:2167
This class implements an object storing an id of an object point.
Definition Database.h:146
Index32 objectPointId() const
Returns the id of the object point of this object.
Definition Database.h:2037
ObjectPointObject(const Index32 objectPointId=invalidId)
Creates a new object.
Definition Database.h:2031
void setObjectPointId(const Index32 objectPointId)
Sets or changes the id of the object point of this object.
Definition Database.h:2042
The data object encapsulating a 6DOF camera pose.
Definition Database.h:557
PoseData(const HomogenousMatrix4 &world_T_camera=HomogenousMatrix4(false), const Scalar fov=-1)
Creates a new object with specified pose.
Definition Database.h:2133
void setPose(const HomogenousMatrix4 &world_T_camera)
Sets (changes) the pose of this object.
Definition Database.h:2150
const HomogenousMatrix4 & pose() const
Returns the pose of this object.
Definition Database.h:2140
void setFov(const Scalar fov)
Sets (changes) the field of view value of this object.
Definition Database.h:2155
Scalar fov() const
Returns the field of view value of this object.
Definition Database.h:2145
This class stores a pair of pose id and image point id.
Definition Database.h:231
PoseImagePointPair(const Index32 poseId=invalidId, const Index32 imagePointId=invalidId)
Creates a new pair object.
Definition Database.h:2071
This class implements an object storing an id of an pose object.
Definition Database.h:177
PoseObject(const Index32 poseId=invalidId)
Creates a new object.
Definition Database.h:2047
void setPoseId(const Index32 poseId)
Sets or changes the id of the camera pose of this object.
Definition Database.h:2058
Index32 poseId() const
Returns the id of the camera pose of this object.
Definition Database.h:2053
This class defines the topology between a camera pose id, an object point id and an image point id.
Definition Database.h:213
TopologyTriple(const Index32 poseId=invalidId, const Index32 objectPointId=invalidId, const Index32 imagePointId=invalidId)
Creates a new topology object.
Definition Database.h:2063
This class implements a database for 3D object points, 2D image points and 6DOF camera poses.
Definition Database.h:67
bool hasObjectPoint(const Index32 objectPointId, Vector3 *objectPoint=nullptr) const
Returns whether this database holds a specified object point.
Definition Database.h:3093
bool hasObservation(const Index32 poseId, const Index32 objectPointId, Vector2 *point=nullptr, Index32 *pointId=nullptr) const
Returns whether an object point is visible in a specified frame, and optional the location and id of ...
Definition Database.h:2300
unsigned int numberCorrespondences(const Index32 poseId, const Vector3 &referenceObjectPoint, const Scalar minimalPriority=Scalar(-1)) const
Counts the number of correspondences (e.g., valid or invalid) between image and object points for a s...
Definition Database.h:2969
void numberCorrespondencesSubset(const Index32 lowerPoseId, const Vector3 *referenceObjectPoint, const Scalar minimalPriority, unsigned int *correspondences, const unsigned int firstPose, const unsigned int numberPoses) const
Counts the number of valid correspondences between image and object points for a subset of several po...
Definition Database.h:5318
std::unordered_map< Index32, ImagePointData > ImagePointMap
Definition of an (unordered) map mapping image point ids to image point data objects.
Definition Database.h:660
void renameObjectPoint(const Index32 oldObjectPointId, const Index32 newObjectPointId)
Renames an object point, changes the id of the object point respectively.
Definition Database.h:3286
void setObjectPoint(const Index32 objectPointId, const Vector3 &objectPoint)
Sets (changes) an object point without modifying the priority value of the object point.
Definition Database.h:3724
void setObjectPoints(const Index32 *objectPointIds, const Vector3 *objectPoints, const size_t number)
Sets (changes) a set of object points without modifying the priority value of the object points.
Definition Database.h:3737
void removeObjectPoint(const Index32 objectPointId)
Removes an object point from this database.
Definition Database.h:3217
std::unordered_map< Index64, Index32 > Index64To32Map
Definition of an (unordered) map mapping 64 bit ids to 32 bit ids.
Definition Database.h:670
std::vector< Vectors2 > ImagePointGroups
Definition of a vector holding 2D vectors.
Definition Database.h:109
std::map< Index32, PoseData > PoseMap
Definition of an (ordered) map mapping pose ids to pose data objects, we use an ordered map as poses ...
Definition Database.h:650
Indices32 objectPointIds(Vectors3 *objectPoints=nullptr, Scalars *priorities=nullptr) const
Returns the ids of all object points that are part of this database.
Definition Database.h:3936
const IndexSet32 & imagePointIds(const Index32 poseId) const
Returns the ids of all image points visible in a specified camera pose (camera frame).
Definition Database.h:3864
void clear()
Clears the database including all camera poses, object points, image points and any topology.
Definition Database.h:5086
IndexPairs32 objectPointIdsWithNumberOfObservations(const Vector3 &referencePosition, const Scalar minimalPriority=Scalar(-1), Worker *worker=nullptr) const
Returns pairs of object point ids combined with counts of valid observations.
Definition Database.h:4142
void attachImagePointToPose(const Index32 imagePointId, const Index32 poseId)
Attaches an existing image point to an existing camera pose (defines the topology between an image po...
Definition Database.h:3655
Lock lock_
The lock for the entire database.
Definition Database.h:1902
void detachImagePointFromObjectPoint(const Index32 imagePointId)
Detaches an image point from an object point (withdraws the topology).
Definition Database.h:3626
Vectors2 imagePointsFromObjectPoints(const Index32 poseId, Indices32 &objectPointIds, Indices32 *imagePointIds=nullptr) const
Returns all image points which are located in a specified frame and which are projections of a set of...
Definition Database.h:4602
bool hasImagePoint(const Index32 imagePointId, Vector2 *imagePoint=nullptr) const
Returns whether this database holds a specified image point.
Definition Database.h:3032
ObjectPointMap objectPointMap_
The map mapping unique object point ids to object point data instances.
Definition Database.h:1884
std::vector< PoseImagePointPair > PoseImagePointTopology
Definition of a vector holding several pairs of pose and image point ids.
Definition Database.h:245
TopologyTriples topologyTriples(const Indices32 &poseIds) const
Returns topology triples with valid image points ids, object points ids and pose ids for a set of giv...
Definition Database.h:5053
const Vector2 & imagePoint(const Index32 imagePointId) const
Returns the location of an image point which is specified by the id of the image point.
Definition Database.h:2251
static Index64 index64(const Index32 first, const Index32 second)
Returns the 64 bit index composed of two 32 bit indices.
Definition Database.h:5397
std::map< Index32, Vectors2 > ImagePointsMap
Definition of a map mapping ids to 2D vectors.
Definition Database.h:104
size_t numberImagePointsFromObjectPoint(const Index32 objectPointId) const
Returns the number of image point observations which belong to a given object point.
Definition Database.h:3447
void setObjectPointPriority(const Index32 objectPointId, const Scalar priority)
Sets (changes) the priority value of an object point.
Definition Database.h:3794
HomogenousMatrices4 poses(const Index32 *poseIds, const size_t size) const
Returns the 6DOF pose values for all specified pose ids.
Definition Database.h:2455
void imagePointsObjectPoints(const Index32 poseId, Vectors2 &imagePoints, Vectors3 &objectPoints, const Vector3 &referencePosition=invalidObjectPoint(), const size_t minimalObservations=0, Indices32 *imagePointIds=nullptr, Indices32 *objectPointIds=nullptr) const
Returns corresponding object points and image points for a given camera pose.
Definition Database.h:4832
static Indices32 filterTopologyTriplesObjectPoints(const TopologyTriples &topologyTriples, const IndexSet32 &objectPointIds)
Filters a set of given topology triples due to a set of given object point ids.
Definition Database.h:5213
std::map< Index32, Vector2 > IdPointMap
Definition of a map mapping ids to 2D image point object.
Definition Database.h:84
const IndexSet32 & imagePointsFromPose(const Index32 poseId) const
Returns all image points which belong to a given camera pose.
Definition Database.h:3550
Indices32 poseIds(const HomogenousMatrix4 &referencePose, HomogenousMatrices4 *poses=nullptr) const
Returns the ids of specific 6DOF poses.
Definition Database.h:2562
std::vector< std::pair< Index32, PoseImagePointTopology > > PoseImagePointTopologyGroups
Definition of a vector holding several groups of pairs of pose and image point ids.
Definition Database.h:250
static const Index32 invalidId
Definition of an invalid id.
Definition Database.h:73
void removePose(const Index32 poseId)
Removes a pose from this database.
Definition Database.h:3409
void removeImagePoint(const Index32 imagePointId)
Removes an image point from this database.
Definition Database.h:3061
unsigned int numberObservations(const Index32 poseId, const Indices32 &objectPointIds) const
Counts the number of observations of a given set of object point ids for a specific camera frame.
Definition Database.h:2949
const HomogenousMatrix4 & pose(const Index32 poseId) const
Returns the 6DOF pose of a camera frame which is specified by the id of the pose.
Definition Database.h:2444
std::pair< Index32, Vector2 > IdPointPair
Definition of a pair of ids and 2D image points.
Definition Database.h:89
bool hasPose(const Index32 poseId, HomogenousMatrix4 *pose=nullptr) const
Returns whether this database holds a specified camera pose.
Definition Database.h:3369
void removeObjectPointAndAttachedImagePoints(const Index32 objectPointId)
Removes an object point from this database and also removes all image points attached to the object p...
Definition Database.h:3248
bool validPoseBorders(Index32 &rangeLowerPoseId, Index32 &rangeUpperPoseId) const
Returns the smallest id (the id of the lower frame border) and the largest id (the id of the upper fr...
Definition Database.h:2616
static Index32 secondIndex(const Index64 index)
Returns the second 32 bit index of a 64 bit index.
Definition Database.h:5392
bool largestValidPoseRange(const Index32 lowerPoseId, const Index32 upperPoseId, Index32 &rangeLowerPoseId, Index32 &rangeUpperPoseId) const
Determines the largest pose id range for which the database holds valid poses.
Definition Database.h:2700
void observationsFromObjectPoint(const Index32 objectPointId, Indices32 &poseIds, Indices32 &imagePointIds, Vectors2 *imagePoints=nullptr) const
Returns all observations (combination of poses and image points) which belong to a given object point...
Definition Database.h:3462
void attachImagePointToObjectPoint(const Index32 imagePointId, const Index32 objectPointId)
Attaches an existing image point to an existing object points (defines the topology between an image ...
Definition Database.h:3599
Database & operator=(const Database &database)
Assign operator copying a second database to this database object.
Definition Database.h:5274
size_t imagePointNumber() const
Returns the number of image point ids in this database.
Definition Database.h:2243
std::map< Index32, IdPointPairs > IdIdPointPairsMap
Definition of a map mapping ids to 2D image point id pairs.
Definition Database.h:99
SquareMatrices3 rotationalPoses(const Index32 *poseIds, const size_t size) const
Returns the 3DOF rotational part of the 6DOF pose values for all specified pose ids.
Definition Database.h:2474
Index32 addObjectPoint(const Vector3 &objectPoint, const Scalar priority=Scalar(-1))
Adds a new 3D object point to this database.
Definition Database.h:3113
const Vector3 & objectPoint(const Index32 objectPointId) const
Returns the location of an object point which is specified by the id of the object point.
Definition Database.h:2335
void reset(const Vector3 &referenceObjectPoint=invalidObjectPoint(), const HomogenousMatrix4 &referencePose=HomogenousMatrix4(false))
Resets the geometric information of this database for 3D object points and 6DOF camera poses.
Definition Database.h:5102
void setImagePoint(const Index32 imagePointId, const Vector2 &imagePoint)
Sets (changes) an image point.
Definition Database.h:3711
std::unordered_map< Index32, Index32 > Index32To32Map
Definition of an (unordered) map mapping 32 bit ids to 32 bit ids.
Definition Database.h:665
std::unordered_map< Index32, ObjectPointData > ObjectPointMap
Definition of an (unordered) map mapping object point ids to object point data objects.
Definition Database.h:655
const IndexSet32 & imagePointsFromObjectPoint(const Index32 objectPointId) const
Returns all image points which belong to a given object point.
Definition Database.h:3563
Vectors3 objectPoints() const
Returns the positions of all 3D object points.
Definition Database.h:2371
Index32 addImagePoint(const Vector2 &imagePoint)
Adds a new 2D image point to this database.
Definition Database.h:3052
ImagePointMap imagePointMap_
The map mapping unique image points ids to image point data instances.
Definition Database.h:1887
unsigned int numberValidPoses(const Index32 objectPointId, const IndexSet32 &imagePointIds) const
Counts the number of valid poses of a given object point.
Definition Database.h:5357
bool poseWithLeastCorrespondences(const Index32 lowerPoseId, const Index32 upperPoseId, Index32 *poseId=nullptr, unsigned int *correspondences=nullptr, const Vector3 &referenceObjectPoint=invalidObjectPoint()) const
Determines the pose id for which the database holds the least number of point correspondences (betwee...
Definition Database.h:2805
bool addPose(const Index32 poseId, const HomogenousMatrix4 &pose=HomogenousMatrix4(false))
Adds a new camera pose by specifying the unique id of the new pose.
Definition Database.h:3390
unsigned int poses_
The number of poses.
Definition Database.h:1893
void setPoses(const Index32 *poseIds, const HomogenousMatrix4 *poses, const size_t number)
Sets (changes) a set of poses.
Definition Database.h:3820
Index32 imagePointIdCounter_
The counter for unique image point ids.
Definition Database.h:1899
Index32 objectPointFromImagePoint(const Index32 imagePointId) const
Returns the object point which belongs to a given image point.
Definition Database.h:3537
bool isEmpty() const
Returns whether this database holds at least one image point, one object point or one camera pose.
Definition Database.h:2219
IndexSet32 posesFromObjectPoint(const Index32 objectPointId) const
Returns all poses which belong to a given object point.
Definition Database.h:3576
PoseMap poseMap_
The map mapping unique pose ids to pose data instances.
Definition Database.h:1881
Index32 objectPointIdCounter_
The counter for unique object point ids.
Definition Database.h:1896
std::vector< IdPointPair > IdPointPairs
Definition of a vector holding pairs of ids and 2D image points.
Definition Database.h:94
void objectPointIdsWithNumberOfObservationsSubset(const Index32 *objectPointIds, const Vector3 *referencePosition, const Scalar minimalPriority, IndexPairs32 *pairs, Lock *lock, const unsigned int firstObjectPoint, const unsigned int numberObjectPoints) const
Returns pairs of object point ids combined with counts of valid observations.
Definition Database.h:5330
bool poseWithMostObservations(const IndexSet32 &poseCandidates, const IndexSet32 &majorObjectPointIds, const IndexSet32 &minorObjectPointIds, Index32 &poseId, Indices32 *visibleMajorObjectPointIds=nullptr, Indices32 *visibleMinorObjectPointIds=nullptr) const
Determines the pose id from a set of given pose id candidates for which the database holds the most o...
Definition Database.h:2846
size_t poseNumber() const
Returns the number of poses of this database.
Definition Database.h:2227
Database()=default
Creates a new empty database object.
void setPose(const Index32 poseId, const HomogenousMatrix4 &pose)
Sets (changes) a pose.
Definition Database.h:3807
std::vector< TopologyTriple > TopologyTriples
Definition of a vector holding object of topology triple.
Definition Database.h:255
Index64To32Map poseObjectPointMap_
The map mapping a pair of pose id and object point id to image point ids.
Definition Database.h:1890
Lock & lock()
Returns a reference to the lock object of this database object.
Definition Database.h:2213
void posesImagePoints(const Index32 objectPointId, HomogenousMatrices4 &poses, Vectors2 &imagePoints, const HomogenousMatrix4 &referencePose=HomogenousMatrix4(false), Indices32 *poseIds=nullptr, Indices32 *imagePointIds=nullptr, const Index32 lowerPoseId=invalidId, const Index32 upperPoseId=invalidId) const
Returns corresponding poses and image points for a given object point from the entire range of possib...
Definition Database.h:4986
bool poseWithMostCorrespondences(const Index32 lowerPoseId, const Index32 upperPoseId, Index32 *poseId=nullptr, unsigned int *correspondences=nullptr, const Vector3 &referenceObjectPoint=invalidObjectPoint()) const
Determines the pose id for which the database holds the most number of point correspondences (between...
Definition Database.h:2771
static Index32 firstIndex(const Index64 index)
Returns the first 32 bit index of a 64 bit index.
Definition Database.h:5387
static Indices32 reliableObjectPoints(const TopologyTriples &topologyTriples, const unsigned int minimalObservations)
Determines reliable object points from a set of given topology triples (by determining all object poi...
Definition Database.h:5249
Scalar objectPointPriority(const Index32 objectPointId) const
Returns the priority of an object point which is specified by the id of the object point.
Definition Database.h:2360
bool poseBorders(Index32 &lowerPoseId, Index32 &upperPoseId) const
Returns the smallest id (the id of the lower frame border) and the largest id (the id of the upper fr...
Definition Database.h:2600
static Vector3 invalidObjectPoint()
Returns an invalid object point.
Definition Database.h:1905
size_t objectPointNumber() const
Returns the number of object point ids in this database.
Definition Database.h:2235
void detachImagePointFromPose(const Index32 imagePointId)
Detaches an image point from a camera pose (withdraws the topology).
Definition Database.h:3682
Index32 poseFromImagePoint(const Index32 imagePointId) const
Determines the camera pose (camera frame) in which a specified image point is visible (to which the i...
Definition Database.h:3434
static PoseImagePointTopologyGroups objectPointTopology(const TopologyTriples &topologyTriples, const Indices32 *indices=nullptr)
Converts the set of topology triples into a representation which is forced/oriented by object points ...
bool validPoseRange(const Index32 lowerPoseId, const Index32 startPoseId, const Index32 upperPoseId, Index32 &rangeLowerPoseId, Index32 &rangeUpperPoseId) const
Determines the pose id range (around a specified start frame) for which the database holds valid pose...
Definition Database.h:2656
Index32 addObjectPointFromDatabase(const Database &secondDatabase, const Index32 secondDatabaseObjectPointId, const SquareMatrix3 &imagePointTransformation=SquareMatrix3(true), const Index32 newObjectPointId=invalidId, const Index32 secondDatabaseLowerPoseId=invalidId, const Index32 secondDatabaseUpperPoseId=invalidId, const bool forExistingPosesOnly=false)
Adds an object point from another database, adds all connected image points, registers unknown poses,...
Definition Database.h:3134
ImagePointGroups imagePointGroups(const Indices32 poseIds, Indices32 &objectPointIds) const
Determines the groups of image points matching to unique object points in individual camera poses.
Definition Database.h:4688
Vectors2 imagePoints(const Indices32 &imagePointIds) const
Returns the positions of 2D image points specified by the ids of the image points.
Definition Database.h:2262
static Indices32 filterTopologyTriplesPoses(const TopologyTriples &topologyTriples, const IndexSet32 &poseIds)
Filters a set of given topology triples due to a set of given pose ids.
Definition Database.h:5195
void mergeObjectPoints(const Index32 remainingObjectPointId, const Index32 removingObjectPointId, const Vector3 &newPoint, const Scalar newPriority)
Merges two object points together, afterwards one object point will be removed.
Definition Database.h:3326
Vectors2 imagePointsWithObjectPoints(const Index32 poseId, Indices32 &objectPointIds) const
Returns all image points which are located in a specified frame and are projections of object points.
Definition Database.h:4559
static Indices32 filterTopologyTriplesImagePoints(const TopologyTriples &topologyTriples, const IndexSet32 &imagePointIds)
Filters a set of given topology triples due to a set of given image point ids.
Definition Database.h:5231
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector3.h:858
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector3.h:846
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
std::vector< IndexPair32 > IndexPairs32
Definition of a vector holding 32 bit index pairs.
Definition Base.h:144
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
uint64_t Index64
Definition of a 64 bit index value.
Definition Base.h:90
std::set< Index32 > IndexSet32
Definition of a set holding 32 bit indices.
Definition Base.h:114
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition SquareMatrix3.h:72
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
The namespace covering the entire Ocean framework.
Definition Accessor.h:15