Mercurial > hg > orthanc-stone
comparison UnitTestsSources/TestStructureSet.cpp @ 1019:29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
default being ALL structures displayed) + the loader maintains a list of
structure display state, that can be modified continuously + the cache now takes
the initial list of structure into account for computing the entry + added methods
to change the loaded structure visibility + disabled the alternate loaders
(DicomStructureSetLoader2 and friends) + disabled corresponding tests
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 27 Sep 2019 13:32:05 +0200 |
parents | 050f01d7951b |
children | 1533cccb5c43 11b7785dd01b |
comparison
equal
deleted
inserted
replaced
1018:58eed6bbcabb | 1019:29f5f2031310 |
---|---|
4281 return result; | 4281 return result; |
4282 } | 4282 } |
4283 | 4283 |
4284 #define STONE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | 4284 #define STONE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
4285 | 4285 |
4286 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4287 | |
4286 static void CheckGroundTruth( | 4288 static void CheckGroundTruth( |
4287 const std::vector<OrthancStone::DicomStructure2>& structures, | 4289 const std::vector<OrthancStone::DicomStructure2>& structures, |
4288 const size_t structureIndex, | 4290 const size_t structureIndex, |
4289 const size_t sliceIndex, | 4291 const size_t sliceIndex, |
4290 std::vector<double> groundTruth) | 4292 std::vector<double> groundTruth) |
4293 const DicomStructurePolygon2& polygon = polygonsForThisStruct.at(sliceIndex); | 4295 const DicomStructurePolygon2& polygon = polygonsForThisStruct.at(sliceIndex); |
4294 | 4296 |
4295 //double groundTruth[] = { 7.657838, 108.2725, 304.01, 6.826687, 107.4413, 304.01, 6.152492, 106.4785, 304.01, 5.655735, 105.4132, 304.01, 5.351513, 104.2778, 304.01, 5.249068, 103.1069, 304.01, 5.351513, 101.9359, 304.01, 5.655735, 100.8005, 304.01, 6.152492, 99.73524, 304.01, 6.826687, 98.77239, 304.01, 7.657838, 97.94124, 304.01, 8.620689, 97.26704, 304.01, 9.685987, 96.77029, 304.01, 10.82136, 96.46606, 304.01, 11.99231, 96.36362, 304.01, 13.16326, 96.46606, 304.01, 14.29864, 96.77029, 304.01, 15.36393, 97.26704, 304.01, 16.32678, 97.94124, 304.01, 17.15794, 98.77239, 304.01, 17.83213, 99.73524, 304.01, 18.32889, 100.8005, 304.01, 18.63311, 101.9359, 304.01, 18.73555, 103.1069, 304.01, 18.63311, 104.2778, 304.01, 18.32889, 105.4132, 304.01, 17.83213, 106.4785, 304.01, 17.15794, 107.4413, 304.01, 16.32678, 108.2725, 304.01, 15.36393, 108.9467, 304.01, 14.29864, 109.4434, 304.01, 13.16326, 109.7477, 304.01, 11.99231, 109.8501, 304.01, 10.82136, 109.7477, 304.01, 9.685987, 109.4434, 304.01, 8.620689, 108.9467, 304.01 }; | 4297 //double groundTruth[] = { 7.657838, 108.2725, 304.01, 6.826687, 107.4413, 304.01, 6.152492, 106.4785, 304.01, 5.655735, 105.4132, 304.01, 5.351513, 104.2778, 304.01, 5.249068, 103.1069, 304.01, 5.351513, 101.9359, 304.01, 5.655735, 100.8005, 304.01, 6.152492, 99.73524, 304.01, 6.826687, 98.77239, 304.01, 7.657838, 97.94124, 304.01, 8.620689, 97.26704, 304.01, 9.685987, 96.77029, 304.01, 10.82136, 96.46606, 304.01, 11.99231, 96.36362, 304.01, 13.16326, 96.46606, 304.01, 14.29864, 96.77029, 304.01, 15.36393, 97.26704, 304.01, 16.32678, 97.94124, 304.01, 17.15794, 98.77239, 304.01, 17.83213, 99.73524, 304.01, 18.32889, 100.8005, 304.01, 18.63311, 101.9359, 304.01, 18.73555, 103.1069, 304.01, 18.63311, 104.2778, 304.01, 18.32889, 105.4132, 304.01, 17.83213, 106.4785, 304.01, 17.15794, 107.4413, 304.01, 16.32678, 108.2725, 304.01, 15.36393, 108.9467, 304.01, 14.29864, 109.4434, 304.01, 13.16326, 109.7477, 304.01, 11.99231, 109.8501, 304.01, 10.82136, 109.7477, 304.01, 9.685987, 109.4434, 304.01, 8.620689, 108.9467, 304.01 }; |
4296 size_t groundTruthItems = groundTruth.size(); | 4298 size_t groundTruthItems = groundTruth.size(); |
4297 | 4299 |
4298 EXPECT_EQ(groundTruthItems, 3 * polygon.GetPointCount()); | 4300 size_t pointCount = 3 * polygon.GetPointCount(); |
4301 | |
4302 EXPECT_EQ(groundTruthItems, pointCount); | |
4299 | 4303 |
4300 for (size_t i = 0; i < polygon.GetPointCount(); ++i) | 4304 for (size_t i = 0; i < polygon.GetPointCount(); ++i) |
4301 { | 4305 { |
4302 const Point3D& point = polygon.GetPoint(i); | 4306 const Point3D& point = polygon.GetPoint(i); |
4303 | 4307 |
4309 bool isNear = LinearAlgebra::IsNear(groundTruth[index], point[j]); | 4313 bool isNear = LinearAlgebra::IsNear(groundTruth[index], point[j]); |
4310 EXPECT_TRUE(isNear); | 4314 EXPECT_TRUE(isNear); |
4311 } | 4315 } |
4312 } | 4316 } |
4313 } | 4317 } |
4314 | |
4315 | 4318 |
4316 | 4319 |
4317 TEST(StructureSet, ReadFromJsonThatsAll) | 4320 TEST(StructureSet, ReadFromJsonThatsAll) |
4318 { | 4321 { |
4319 DicomStructureSet2 structureSet; | 4322 DicomStructureSet2 structureSet; |
4429 EXPECT_EQ(358u * 3, groundTruth.size()); | 4432 EXPECT_EQ(358u * 3, groundTruth.size()); |
4430 CheckGroundTruth(structures, 5, 8, groundTruth); | 4433 CheckGroundTruth(structures, 5, 8, groundTruth); |
4431 } | 4434 } |
4432 } | 4435 } |
4433 | 4436 |
4437 #endif | |
4438 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4439 | |
4434 #if 0 | 4440 #if 0 |
4435 | 4441 |
4436 TEST(StructureSet, ReadFromJsonAndCompute1) | 4442 TEST(StructureSet, ReadFromJsonAndCompute1) |
4437 { | 4443 { |
4438 DicomStructureSet2 structureSet; | 4444 DicomStructureSet2 structureSet; |
4455 structureSet.Clear(); | 4461 structureSet.Clear(); |
4456 | 4462 |
4457 structureSet.SetContents(dicom); | 4463 structureSet.SetContents(dicom); |
4458 } | 4464 } |
4459 #endif | 4465 #endif |
4466 | |
4467 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4460 | 4468 |
4461 static bool CutStructureWithPlane( | 4469 static bool CutStructureWithPlane( |
4462 std::vector< std::pair<Point2D, Point2D> >& segments, | 4470 std::vector< std::pair<Point2D, Point2D> >& segments, |
4463 const DicomStructure2& structure, | 4471 const DicomStructure2& structure, |
4464 const double originX, const double originY, const double originZ, | 4472 const double originX, const double originY, const double originZ, |
4477 // compute intersection | 4485 // compute intersection |
4478 bool ok = structure.Project(segments, cuttingPlane); | 4486 bool ok = structure.Project(segments, cuttingPlane); |
4479 return ok; | 4487 return ok; |
4480 } | 4488 } |
4481 | 4489 |
4490 #endif | |
4491 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4492 | |
4482 static double pointsCoord1[] = { 2, 2, 3, 3, 6, 8, 8, 7, 8, 8, 6 }; | 4493 static double pointsCoord1[] = { 2, 2, 3, 3, 6, 8, 8, 7, 8, 8, 6 }; |
4483 static double pointsCoord2[] = { 2, 6, 8, 10, 12, 10, 8, 6, 4, 2, 4 }; | 4494 static double pointsCoord2[] = { 2, 6, 8, 10, 12, 10, 8, 6, 4, 2, 4 }; |
4484 static const size_t pointsCoord1Count = STONE_ARRAY_SIZE(pointsCoord1); | 4495 static const size_t pointsCoord1Count = STONE_ARRAY_SIZE(pointsCoord1); |
4485 static const size_t pointsCoord2Count = STONE_ARRAY_SIZE(pointsCoord2); | 4496 static const size_t pointsCoord2Count = STONE_ARRAY_SIZE(pointsCoord2); |
4486 const size_t POLYGON_POINT_COUNT = pointsCoord1Count; | 4497 const size_t POLYGON_POINT_COUNT = pointsCoord1Count; |
4498 | |
4499 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4487 | 4500 |
4488 static void CreateBasicStructure(DicomStructure2& structure) | 4501 static void CreateBasicStructure(DicomStructure2& structure) |
4489 { | 4502 { |
4490 // see https://www.dropbox.com/s/1o1vg53hsbvx4cc/test-rtstruct-polygons.jpg?dl=0 | 4503 // see https://www.dropbox.com/s/1o1vg53hsbvx4cc/test-rtstruct-polygons.jpg?dl=0 |
4491 EXPECT_EQ(pointsCoord1Count, pointsCoord2Count); | 4504 EXPECT_EQ(pointsCoord1Count, pointsCoord2Count); |
4689 } | 4702 } |
4690 } | 4703 } |
4691 EXPECT_EQ(8, numberOfVeryShortSegments); | 4704 EXPECT_EQ(8, numberOfVeryShortSegments); |
4692 } | 4705 } |
4693 | 4706 |
4707 #endif | |
4708 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4709 | |
4710 | |
4694 TEST(DisjointDataSet, BasicTest) | 4711 TEST(DisjointDataSet, BasicTest) |
4695 { | 4712 { |
4696 const size_t ITEM_COUNT = 10; | 4713 const size_t ITEM_COUNT = 10; |
4697 DisjointDataSet ds(ITEM_COUNT); | 4714 DisjointDataSet ds(ITEM_COUNT); |
4698 | 4715 |
4749 { | 4766 { |
4750 EXPECT_EQ(ds.Find(0), ds.Find(i)); | 4767 EXPECT_EQ(ds.Find(0), ds.Find(i)); |
4751 } | 4768 } |
4752 } | 4769 } |
4753 | 4770 |
4771 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4754 | 4772 |
4755 TEST(StructureSet, CutSagittalInsideClose) | 4773 TEST(StructureSet, CutSagittalInsideClose) |
4756 { | 4774 { |
4757 DicomStructure2 structure; | 4775 DicomStructure2 structure; |
4758 CreateBasicStructure(structure); | 4776 CreateBasicStructure(structure); |
4767 | 4785 |
4768 // compute intersection | 4786 // compute intersection |
4769 bool ok = structure.Project(segments, cuttingPlane); | 4787 bool ok = structure.Project(segments, cuttingPlane); |
4770 EXPECT_TRUE(ok); | 4788 EXPECT_TRUE(ok); |
4771 } | 4789 } |
4790 | |
4791 #endif | |
4792 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
4793 | |
4772 | 4794 |
4773 static size_t ConvertListOfSlabsToSegments_Add(RtStructRectanglesInSlab& rectangles, int row, double xmin, double xmax) | 4795 static size_t ConvertListOfSlabsToSegments_Add(RtStructRectanglesInSlab& rectangles, int row, double xmin, double xmax) |
4774 { | 4796 { |
4775 double ymin = static_cast<double>(row) * 5.0; | 4797 double ymin = static_cast<double>(row) * 5.0; |
4776 double ymax = static_cast<double>(row + 1) * 5.0; | 4798 double ymax = static_cast<double>(row + 1) * 5.0; |
5353 ASSERT_NEAR(segments[i].first.y, 30.000000000000000, DELTA_MAX); | 5375 ASSERT_NEAR(segments[i].first.y, 30.000000000000000, DELTA_MAX); |
5354 ASSERT_NEAR(segments[i].second.x, 95.000000000000000, DELTA_MAX); | 5376 ASSERT_NEAR(segments[i].second.x, 95.000000000000000, DELTA_MAX); |
5355 ASSERT_NEAR(segments[i].second.y, 30.000000000000000, DELTA_MAX); | 5377 ASSERT_NEAR(segments[i].second.y, 30.000000000000000, DELTA_MAX); |
5356 } | 5378 } |
5357 | 5379 |
5380 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 | |
5381 | |
5358 TEST(StructureSet, ReadFromJsonPart2) | 5382 TEST(StructureSet, ReadFromJsonPart2) |
5359 { | 5383 { |
5360 DicomStructureSet2 structureSet; | 5384 DicomStructureSet2 structureSet; |
5361 std::string jsonText; | 5385 std::string jsonText; |
5362 | 5386 |
5371 | 5395 |
5372 const std::vector<DicomStructure2>& structures = structureSet.structures_; | 5396 const std::vector<DicomStructure2>& structures = structureSet.structures_; |
5373 } | 5397 } |
5374 | 5398 |
5375 | 5399 |
5376 | 5400 #endif |
5377 | 5401 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 |
5402 | |
5403 |