Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/DicomStructurePolygon2.cpp @ 1641:df4fd96c5706
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:58:27 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
comparison
equal
deleted
inserted
replaced
1640:52b8b96cb55f | 1641:df4fd96c5706 |
---|---|
191 // [ (y1 ,x1) , (y2,x2), (y1 ,x2) ] or | 191 // [ (y1 ,x1) , (y2,x2), (y1 ,x2) ] or |
192 // [ (x1 ,y1) , (x2,y2), (x1 ,y2) ] | 192 // [ (x1 ,y1) , (x2,y2), (x1 ,y2) ] |
193 | 193 |
194 /* | 194 /* |
195 void CoordinateSystem3D::ProjectPoint(double& offsetX, | 195 void CoordinateSystem3D::ProjectPoint(double& offsetX, |
196 double& offsetY, | 196 double& offsetY, |
197 const Vector& point) const | 197 const Vector& point) const |
198 */ | 198 */ |
199 double alpha = (v2 - planeV) / (v2 - v1); | 199 double alpha = (v2 - planeV) / (v2 - v1); |
200 | 200 |
201 // get rid of numerical oddities | 201 // get rid of numerical oddities |
202 if (alpha < 0.0) | 202 if (alpha < 0.0) |
239 { | 239 { |
240 LOG(ERROR) << "This polygon has " << pointCount << " vertices, which is less than 3 --> skipping"; | 240 LOG(ERROR) << "This polygon has " << pointCount << " vertices, which is less than 3 --> skipping"; |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 void OrthancStone::DicomStructurePolygon2::ProjectOnParallelPlane( | 244 void DicomStructurePolygon2::ProjectOnParallelPlane( |
245 std::vector< std::pair<Point2D, Point2D> >& segments, | 245 std::vector< std::pair<Point2D, Point2D> >& segments, |
246 const CoordinateSystem3D& plane) const | 246 const CoordinateSystem3D& plane) const |
247 { | |
248 if (points_.size() < 3) | |
249 return; | |
250 | |
251 // the plane is horizontal | |
252 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[0], 0.0)); | |
253 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[1], 0.0)); | |
254 | |
255 segments.clear(); | |
256 segments.reserve(points_.size()); | |
257 // since the returned values need to be expressed in the supplied coordinate | |
258 // system, we need to subtract origin_ from the returned points | |
259 | |
260 double planeOriginX = plane.GetOrigin()[0]; | |
261 double planeOriginY = plane.GetOrigin()[1]; | |
262 | |
263 // precondition: points_.size() >= 3 | |
264 for (size_t j = 0; j < points_.size()-1; ++j) | |
265 { | 247 { |
266 // segment between point j and j+1 | 248 if (points_.size() < 3) |
267 | 249 return; |
268 const Point3D& point0 = GetPoint(j); | 250 |
251 // the plane is horizontal | |
252 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[0], 0.0)); | |
253 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[1], 0.0)); | |
254 | |
255 segments.clear(); | |
256 segments.reserve(points_.size()); | |
257 // since the returned values need to be expressed in the supplied coordinate | |
258 // system, we need to subtract origin_ from the returned points | |
259 | |
260 double planeOriginX = plane.GetOrigin()[0]; | |
261 double planeOriginY = plane.GetOrigin()[1]; | |
262 | |
263 // precondition: points_.size() >= 3 | |
264 for (size_t j = 0; j < points_.size()-1; ++j) | |
265 { | |
266 // segment between point j and j+1 | |
267 | |
268 const Point3D& point0 = GetPoint(j); | |
269 // subtract plane origin x and y | |
270 Point2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY); | |
271 | |
272 const Point3D& point1 = GetPoint(j+1); | |
273 // subtract plane origin x and y | |
274 Point2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY); | |
275 | |
276 segments.push_back(std::pair<Point2D, Point2D>(p0,p1)); | |
277 } | |
278 | |
279 | |
280 // final segment | |
281 | |
282 const Point3D& point0 = GetPoint(points_.size() - 1); | |
269 // subtract plane origin x and y | 283 // subtract plane origin x and y |
270 Point2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY); | 284 Point2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY); |
271 | 285 |
272 const Point3D& point1 = GetPoint(j+1); | 286 const Point3D& point1 = GetPoint(0); |
273 // subtract plane origin x and y | 287 // subtract plane origin x and y |
274 Point2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY); | 288 Point2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY); |
275 | 289 |
276 segments.push_back(std::pair<Point2D, Point2D>(p0,p1)); | 290 segments.push_back(std::pair<Point2D, Point2D>(p0, p1)); |
277 } | 291 } |
278 | 292 |
279 | 293 double DicomStructurePolygon2::GetZ() const |
280 // final segment | 294 { |
281 | 295 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[0], 0.0)); |
282 const Point3D& point0 = GetPoint(points_.size() - 1); | 296 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[1], 0.0)); |
283 // subtract plane origin x and y | 297 ORTHANC_ASSERT(LinearAlgebra::IsNear(minZ_, maxZ_)); |
284 Point2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY); | 298 return minZ_; |
285 | 299 } |
286 const Point3D& point1 = GetPoint(0); | |
287 // subtract plane origin x and y | |
288 Point2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY); | |
289 | |
290 segments.push_back(std::pair<Point2D, Point2D>(p0, p1)); | |
291 } | |
292 | |
293 double OrthancStone::DicomStructurePolygon2::GetZ() const | |
294 { | |
295 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[0], 0.0)); | |
296 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[1], 0.0)); | |
297 ORTHANC_ASSERT(LinearAlgebra::IsNear(minZ_, maxZ_)); | |
298 return minZ_; | |
299 } | |
300 | |
301 | |
302 } | 300 } |
303 | 301 |
304 #endif | 302 #endif |
305 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | 303 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 |
306 | 304 |