Common scaffolding shared by every writer-test seg: 3-slice geometry, a single label with the metadata Validate requires, foreground voxels so dcmqi sees non-empty frames, and optionally the strict-mode identity-tag set. No source-image relation is attached here; callers layer that on top per the case they exercise. withTracking / withSegProperty toggle the per-label DICOM Type 3 / Type 1 metadat
| 95 | // withTracking / withSegProperty toggle the per-label DICOM Type 3 / Type 1 |
| 96 | // metadata so individual tests can exercise the writer's absence paths. |
| 97 | mitk::MultiLabelSegmentation::Pointer BuildBaseSeg(bool stampIdentity = true, |
| 98 | unsigned char labelValue = 1, |
| 99 | bool withTracking = true, |
| 100 | bool withSegProperty = true) |
| 101 | { |
| 102 | auto geometryImage = mitk::Image::New(); |
| 103 | unsigned int dim[3] = {4u, 4u, 3u}; |
| 104 | geometryImage->Initialize(mitk::MakeScalarPixelType<mitk::Label::PixelType>(), 3, dim); |
| 105 | |
| 106 | auto seg = mitk::MultiLabelSegmentation::New(); |
| 107 | seg->Initialize(geometryImage); |
| 108 | |
| 109 | auto label = mitk::Label::New(); |
| 110 | label->SetName("L"); |
| 111 | label->SetValue(labelValue); |
| 112 | label->SetAlgorithmType(mitk::Label::AlgorithmType::MANUAL); |
| 113 | label->SetAlgorithmName("WriterTest"); |
| 114 | if (withSegProperty) |
| 115 | { |
| 116 | label->SetSegmentedPropertyCategory(mitk::DICOMCodeSequence("T-D0050", "SRT", "Tissue")); |
| 117 | label->SetSegmentedPropertyType(mitk::DICOMCodeSequenceWithModifiers("T-D0050", "SRT", "Tissue")); |
| 118 | } |
| 119 | if (withTracking) |
| 120 | { |
| 121 | label->SetTrackingID("track-id"); |
| 122 | label->SetTrackingUID("track-uid"); |
| 123 | } |
| 124 | seg->AddLabel(label, 0, true, true); |
| 125 | |
| 126 | // dcmqi skips empty slices and produces no DICOM SEG if every slice is |
| 127 | // empty. Stamp a small foreground voxel block so each slice carries |
| 128 | // the declared label value and the resulting SEG has frames. |
| 129 | { |
| 130 | auto groupImage = seg->GetGroupImage(0); |
| 131 | mitk::ImageWriteAccessor writeAccessor(groupImage); |
| 132 | auto *pixels = static_cast<mitk::Label::PixelType *>(writeAccessor.GetData()); |
| 133 | const auto dims = groupImage->GetDimensions(); |
| 134 | const auto sliceSize = static_cast<std::size_t>(dims[0]) * dims[1]; |
| 135 | for (unsigned int z = 0; z < dims[2]; ++z) |
| 136 | { |
| 137 | pixels[z * sliceSize + 0] = labelValue; |
| 138 | pixels[z * sliceSize + 1] = labelValue; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (stampIdentity) |
| 143 | StampIdentityTags(seg); |
| 144 | |
| 145 | return seg; |
| 146 | } |
| 147 | |
| 148 | // Attach a full DICOM-flavoured rule connection to seg with per-slice |
| 149 | // source SOPInstance + class UIDs. Matches the source-image-relation |
no test coverage detected