comparison OrthancStone/Sources/Toolbox/DicomStructureSet.cpp @ 1895:14c8f339d480

removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Jan 2022 14:51:55 +0100
parents 90b5e116a5f9
children b3c08e607d9f
comparison
equal deleted inserted replaced
1894:438071a29f77 1895:14c8f339d480
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 **/ 21 **/
22 22
23 23
24 #include "DicomStructureSet.h" 24 #include "DicomStructureSet.h"
25 #include "DicomStructureSetUtils.h" 25 #include "DicomStructureSetUtils.h" // TODO REMOVE
26 26
27 #include "BucketAccumulator2D.h"
28 #include "GenericToolbox.h"
27 #include "GeometryToolbox.h" 29 #include "GeometryToolbox.h"
28 #include "GenericToolbox.h"
29
30 #include "OrthancDatasets/DicomDatasetReader.h" 30 #include "OrthancDatasets/DicomDatasetReader.h"
31
32 #include "BucketAccumulator2D.h"
33 31
34 #include <Logging.h> 32 #include <Logging.h>
35 #include <OrthancException.h> 33 #include <OrthancException.h>
36 #include <Toolbox.h> 34 #include <Toolbox.h>
37 35
39 # pragma warning(push) 37 # pragma warning(push)
40 # pragma warning(disable:4244) 38 # pragma warning(disable:4244)
41 #endif 39 #endif
42 40
43 #if STONE_TIME_BLOCKING_OPS 41 #if STONE_TIME_BLOCKING_OPS
44 # include <boost/date_time/posix_time/posix_time.hpp> 42 # include <boost/date_time/posix_time/posix_time.hpp>
45 #endif 43 #endif
46 44
47 #include <limits> 45 #include <limits>
48 #include <stdio.h> 46 #include <stdio.h>
49 #include <boost/math/constants/constants.hpp> 47 #include <boost/math/constants/constants.hpp>
59 #if ORTHANC_ENABLE_DCMTK == 1 57 #if ORTHANC_ENABLE_DCMTK == 1
60 # include "ParsedDicomDataset.h" 58 # include "ParsedDicomDataset.h"
61 #endif 59 #endif
62 60
63 61
64 typedef boost::geometry::model::d2::point_xy<double> BoostPoint; 62 typedef boost::geometry::model::d2::point_xy<double> BoostPoint;
65 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon; 63 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon;
66 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon; 64 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon;
67 65
68 66
69 static void Union(BoostMultiPolygon& output, 67 static void Union(BoostMultiPolygon& output,
831 } 829 }
832 } 830 }
833 831
834 bool DicomStructureSet::ProjectStructure( 832 bool DicomStructureSet::ProjectStructure(
835 #if USE_BOOST_UNION_FOR_POLYGONS == 1 833 #if USE_BOOST_UNION_FOR_POLYGONS == 1
836 std::vector< std::vector<Point2D> >& polygons, 834 std::vector< std::vector<ScenePoint2D> >& polygons,
837 #else 835 #else
838 std::vector< std::pair<Point2D, Point2D> >& segments, 836 std::vector< std::pair<ScenePoint2D, ScenePoint2D> >& segments,
839 #endif 837 #endif
840 const Structure& structure, 838 const Structure& structure,
841 const CoordinateSystem3D& sourceSlice) const 839 const CoordinateSystem3D& sourceSlice) const
842 { 840 {
843 const CoordinateSystem3D slice = CoordinateSystem3D::NormalizeCuttingPlane(sourceSlice); 841 const CoordinateSystem3D slice = CoordinateSystem3D::NormalizeCuttingPlane(sourceSlice);
859 polygon != structure.polygons_.end(); ++polygon) 857 polygon != structure.polygons_.end(); ++polygon)
860 { 858 {
861 if (polygon->IsOnSlice(slice)) 859 if (polygon->IsOnSlice(slice))
862 { 860 {
863 #if USE_BOOST_UNION_FOR_POLYGONS == 1 861 #if USE_BOOST_UNION_FOR_POLYGONS == 1
864 polygons.push_back(std::vector<Point2D>()); 862 polygons.push_back(std::vector<ScenePoint2D>());
865 863
866 for (Points::const_iterator p = polygon->GetPoints().begin(); 864 for (Points::const_iterator p = polygon->GetPoints().begin();
867 p != polygon->GetPoints().end(); ++p) 865 p != polygon->GetPoints().end(); ++p)
868 { 866 {
869 double x, y; 867 double x, y;
870 slice.ProjectPoint2(x, y, *p); 868 slice.ProjectPoint2(x, y, *p);
871 polygons.back().push_back(Point2D(x, y)); 869 polygons.back().push_back(ScenePoint2D(x, y));
872 } 870 }
873 #else 871 #else
874 // we need to add all the segments corresponding to this polygon 872 // we need to add all the segments corresponding to this polygon
875 const std::vector<Vector>& points3D = polygon->GetPoints(); 873 const std::vector<Vector>& points3D = polygon->GetPoints();
876 if (points3D.size() >= 3) 874 if (points3D.size() >= 3)
877 { 875 {
878 Point2D prev2D; 876 ScenePoint2D prev2D;
879 { 877 {
880 Vector prev = points3D[0]; 878 Vector prev = points3D[0];
881 double prevX, prevY; 879 double prevX, prevY;
882 slice.ProjectPoint2(prevX, prevY, prev); 880 slice.ProjectPoint2(prevX, prevY, prev);
883 prev2D = Point2D(prevX, prevY); 881 prev2D = ScenePoint2D(prevX, prevY);
884 } 882 }
885 883
886 size_t pointCount = points3D.size(); 884 size_t pointCount = points3D.size();
887 for (size_t ipt = 1; ipt < pointCount; ++ipt) 885 for (size_t ipt = 1; ipt < pointCount; ++ipt)
888 { 886 {
889 Vector next = points3D[ipt]; 887 Vector next = points3D[ipt];
890 double nextX, nextY; 888 double nextX, nextY;
891 slice.ProjectPoint2(nextX, nextY, next); 889 slice.ProjectPoint2(nextX, nextY, next);
892 Point2D next2D(nextX, nextY); 890 ScenePoint2D next2D(nextX, nextY);
893 segments.push_back(std::pair<Point2D, Point2D>(prev2D, next2D)); 891 segments.push_back(std::pair<ScenePoint2D, ScenePoint2D>(prev2D, next2D));
894 prev2D = next2D; 892 prev2D = next2D;
895 } 893 }
896 } 894 }
897 else 895 else
898 { 896 {
1010 const std::vector<BoostPoint>& outer = merged[i].outer(); 1008 const std::vector<BoostPoint>& outer = merged[i].outer();
1011 1009
1012 polygons[i].resize(outer.size()); 1010 polygons[i].resize(outer.size());
1013 for (size_t j = 0; j < outer.size(); j++) 1011 for (size_t j = 0; j < outer.size(); j++)
1014 { 1012 {
1015 polygons[i][j] = Point2D(outer[j].x(), outer[j].y()); 1013 polygons[i][j] = ScenePoint2D(outer[j].x(), outer[j].y());
1016 } 1014 }
1017 } 1015 }
1018 #endif 1016 #endif
1019 1017
1020 #else 1018 #else
1022 polygon != structure.polygons_.end(); ++polygon) 1020 polygon != structure.polygons_.end(); ++polygon)
1023 { 1021 {
1024 double x1, y1, x2, y2; 1022 double x1, y1, x2, y2;
1025 if (polygon->Project(x1, y1, x2, y2, slice)) 1023 if (polygon->Project(x1, y1, x2, y2, slice))
1026 { 1024 {
1027 std::vector<Point2D> p(4); 1025 std::vector<ScenePoint2D> p(4);
1028 p[0] = std::make_pair(x1, y1); 1026 p[0] = std::make_pair(x1, y1);
1029 p[1] = std::make_pair(x2, y1); 1027 p[1] = std::make_pair(x2, y1);
1030 p[2] = std::make_pair(x2, y2); 1028 p[2] = std::make_pair(x2, y2);
1031 p[3] = std::make_pair(x1, y2); 1029 p[3] = std::make_pair(x1, y2);
1032 polygons.push_back(p); 1030 polygons.push_back(p);
1047 const CoordinateSystem3D& plane, 1045 const CoordinateSystem3D& plane,
1048 size_t structureIndex, 1046 size_t structureIndex,
1049 const Color& color) const 1047 const Color& color) const
1050 { 1048 {
1051 #if USE_BOOST_UNION_FOR_POLYGONS == 1 1049 #if USE_BOOST_UNION_FOR_POLYGONS == 1
1052 std::vector< std::vector<Point2D> > polygons; 1050 std::vector< std::vector<ScenePoint2D> > polygons;
1053 if (ProjectStructure(polygons, structureIndex, plane)) 1051 if (ProjectStructure(polygons, structureIndex, plane))
1054 { 1052 {
1055 for (size_t j = 0; j < polygons.size(); j++) 1053 for (size_t j = 0; j < polygons.size(); j++)
1056 { 1054 {
1057 std::vector<ScenePoint2D> chain; 1055 std::vector<ScenePoint2D> chain;
1065 layer.AddChain(chain, true, color.GetRed(), color.GetGreen(), color.GetBlue()); 1063 layer.AddChain(chain, true, color.GetRed(), color.GetGreen(), color.GetBlue());
1066 } 1064 }
1067 } 1065 }
1068 1066
1069 #else 1067 #else
1070 std::vector< std::pair<Point2D, Point2D> > segments; 1068 std::vector< std::pair<ScenePoint2D, ScenePoint2D> > segments;
1071 1069
1072 if (ProjectStructure(segments, structureIndex, plane)) 1070 if (ProjectStructure(segments, structureIndex, plane))
1073 { 1071 {
1074 for (size_t j = 0; j < segments.size(); j++) 1072 for (size_t j = 0; j < segments.size(); j++)
1075 { 1073 {
1076 std::vector<ScenePoint2D> chain(2); 1074 std::vector<ScenePoint2D> chain(2);
1077 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y); 1075 chain[0] = ScenePoint2D(segments[j].first.GetX(), segments[j].first.GetY());
1078 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y); 1076 chain[1] = ScenePoint2D(segments[j].second.GetX(), segments[j].second.GetY());
1079 layer.AddChain(chain, false, color.GetRed(), color.GetGreen(), color.GetBlue()); 1077 layer.AddChain(chain, false, color.GetRed(), color.GetGreen(), color.GetBlue());
1080 } 1078 }
1081 } 1079 }
1082 #endif 1080 #endif
1083 } 1081 }