ImFusion SDK 4.3
DicomExtensionExample.cpp
#include <ImFusion/Base/DataComponentList.h>
#include <ImFusion/Base/SharedImageSet.h>
#include <ImFusion/Dicom/DicomElement.h>
#include <ImFusion/Dicom/DicomIOD.h>
#include <ImFusion/Dicom/Extension.h>
#include <dcmtk/dcmdata/dctk.h>
using namespace ImFusion;
class ExampleDataComponent : public DataComponent<ExampleDataComponent>
{
public:
ExampleDataComponent() = default;
ExampleDataComponent(const ExampleDataComponent& other) = default;
ExampleDataComponent& operator=(const ExampleDataComponent& other) = default;
bool operator==(const ExampleDataComponent& other) const
{
return other.xrayTubeCurrent == xrayTubeCurrent && other.convolutionKernel == convolutionKernel;
}
std::string id() const override { return ""; }
void configure(const Properties* p) override {};
void configuration(Properties* p) const override {};
int xrayTubeCurrent = 0;
std::string convolutionKernel = "";
};
class ExtensionExample : public Dicom::Extension
{
public:
std::unique_ptr<Extension> clone() const override { return std::make_unique<ExtensionExample>(*this); };
std::string name() const override { return "Extension Example"; }
std::vector<std::unique_ptr<Data>> load(const Dicom::FrameDescriptor& frame, SharedImageSet& sis) const override
{
// In this example we load the tags once for the complete SharedImageSet.
// Therefore, we only perform the loading on the very first frame.
// Of course you could also load different metadata for different frames.
if (frame.sharedImageIndex != 0 || frame.sliceIndex != 0)
return {};
// Instead of using Dicom::Element, you can also use the DcmItem through `frame.iod->item()` directly.
Dicom::Element<int> xrayTubeCurrent(*frame.iod, DCM_XRayTubeCurrent);
Dicom::Element<std::string> convolutionKernel(*frame.iod, DCM_ConvolutionKernel);
auto& dc = sis.components().getOrCreate<ExampleDataComponent>();
if (xrayTubeCurrent.isValid())
dc.xrayTubeCurrent = xrayTubeCurrent.value();
if (convolutionKernel.isValid())
dc.convolutionKernel = convolutionKernel.value();
return {}; // If you loaded some additional data e.g. from private tags, you can return it here.
}
void save(const Dicom::FrameDescriptor& frame, const SharedImageSet& sis) const override {}
};
Main specialization of DataComponentBase for regular types.
Definition DataComponent.h:109
T & getOrCreate(Args &&... ctorArgs)
Returns the DataComponent exactly matching the given type.
Definition DataComponentList.h:231
Interface for adding custom functionality to DicomLoader and DicomWriter An Extension might be called...
Definition Extension.h:26
Storage container for serialization of arbitrary types, internally backed by strings.
Definition Properties.h:50
const DataComponentList & components() const
Returns the list of DataComponents for this data.
Definition Data.h:179
T make_unique(T... args)
Mesh * load(const char *buffer, size_t bufferLength, const std::string &sourceFilename="", Progress *progressBar=nullptr, bool log=false)
Loads a mesh from a memory buffer.
void save(const char *filename, const std::vector< mat4 > &matrices, bool rigidPars=false)
Save matrices or its rigid pose parameters to a text file.
Namespace of the ImFusion SDK.
Definition Assert.h:7
IOD * iod
Parent IOD that loaded the frame. Never nullptr and must not be re-assigned.
Definition DicomIOD.h:52
int sharedImageIndex
index of the SharedImage in the SharedImageSet
Definition DicomIOD.h:59
int sliceIndex
slice index of the frame in the volume (or 0 for 2D images)
Definition DicomIOD.h:60
Search Tab / S to search, Esc to close