7 #include "fwDataTools/helper/PointList.hpp" 9 #include <fwDataTools/helper/Array.hpp> 10 #include <fwDataTools/TransformationMatrix3D.hpp> 12 #include <fwData/Point.hpp> 13 #include <fwData/PointList.hpp> 15 #include <glm/geometric.hpp> 16 #include <glm/vec3.hpp> 41 ::fwData::PointList::sptr _pointList2)
43 SLM_ASSERT(
"the 2 pointLists must have the same number of points",
44 _pointList1->getPoints().size() == _pointList2->getPoints().size() );
46 const ::fwData::PointList::PointListContainer points1 = _pointList1->getPoints();
47 const ::fwData::PointList::PointListContainer points2 = _pointList2->getPoints();
48 const size_t size = points1.size();
50 ::fwData::Array::sptr outputArray = ::fwData::Array::New();
52 arraySize.push_back(size);
53 outputArray->resize(
"double", arraySize, 1,
true);
55 double* distanceArray = arrayHelper.
begin<
double>();
57 for (
size_t i = 0; i < size; ++i)
59 const ::fwData::Point::PointCoordArrayType tmp1 = points1[i]->getCoord();
60 const ::fwData::Point::PointCoordArrayType tmp2 = points2[i]->getCoord();
61 const ::glm::dvec3 pt1 = ::glm::dvec3(tmp1[0], tmp1[1], tmp1[2]);
62 const ::glm::dvec3 pt2 = ::glm::dvec3(tmp2[0], tmp2[1], tmp2[2]);
63 distanceArray[i] = ::glm::distance(pt1, pt2);
72 const ::fwData::TransformationMatrix3D::csptr& _matrix)
74 ::fwData::PointList::PointListContainer points = _pointList->getPoints();
75 const size_t size = points.size();
77 for(
size_t i = 0; i < size; ++i)
79 ::fwData::Point::sptr& pt = points[i];
89 ::fwData::PointList::sptr _pointList2)
91 SLM_ASSERT(
"the 2 pointLists must have the same number of points",
92 _pointList1->getPoints().size() == _pointList2->getPoints().size() );
94 ::fwData::PointList::PointListContainer points1 = _pointList1->getPoints();
95 ::fwData::PointList::PointListContainer points2 = _pointList2->getPoints();
97 const size_t size = points1.size();
100 std::vector< ::glm::dvec3 > vec1;
103 std::list< ::glm::dvec3 > list2;
105 for(
size_t i = 0; i < size; ++i)
107 const ::fwData::Point::PointCoordArrayType tmp1 = points1[i]->getCoord();
108 const ::fwData::Point::PointCoordArrayType tmp2 = points2[i]->getCoord();
111 vec1.push_back(::glm::dvec3( tmp1[0], tmp1[1], tmp1[2]));
112 list2.push_back(::glm::dvec3( tmp2[0], tmp2[1], tmp2[2]));
116 for(
auto point1 : vec1)
119 double distanceMin = std::numeric_limits<double>::max();
120 std::list< ::glm::dvec3 >::iterator itClosestPoint;
122 std::list< ::glm::dvec3 >::iterator it2 = list2.begin();
123 for(; it2 != list2.end(); it2++)
125 const ::glm::dvec3 point2 = *it2;
126 const double distance = ::glm::distance(point1, point2);
127 if(distance < distanceMin)
129 distanceMin = distance;
130 itClosestPoint = it2;
134 ::fwData::Point::PointCoordArrayType pointCoord;
135 pointCoord[0] = itClosestPoint->x;
136 pointCoord[1] = itClosestPoint->y;
137 pointCoord[2] = itClosestPoint->z;
139 ::fwData::Point::sptr pt = points2[index];
140 pt->setCoord(pointCoord);
144 list2.erase(itClosestPoint);
151 const ::fwData::Point::sptr& _point,
float _delta)
154 const auto& list = _pointList->getPoints();
157 const auto& coord1 = _point->getCoord();
158 const ::glm::vec3 p1{coord1[0], coord1[1], coord1[2]};
161 float closest = std::numeric_limits<float>::max();
162 ::fwData::Point::sptr
point =
nullptr;
166 for(
size_t i = 0; i < list.size(); ++i)
168 const auto& coord2 = list[i]->getCoord();
169 const ::glm::vec3 p2{coord2[0], coord2[1], coord2[2]};
172 if((tempClosest = ::glm::distance(p1, p2)) < _delta && tempClosest < closest)
174 closest = tempClosest;
184 _pointList->remove(index);
std::vector< size_t > SizeType
Array size type.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...