forked from QIICR/dcmqi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: a different shot at refactoring
- Loading branch information
Showing
16 changed files
with
544 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Created by Andrey Fedorov on 3/11/17. | ||
// | ||
|
||
#ifndef DCMQI_IMAGEVOLUMEGEOMETRY_H | ||
#define DCMQI_IMAGEVOLUMEGEOMETRY_H | ||
|
||
|
||
#include <vnl/vnl_vector.h> | ||
#include <itkVector.h> | ||
#include <itkSize.h> | ||
#include <itkImage.h> | ||
|
||
class ImageVolumeGeometry { | ||
|
||
friend class MultiframeObject; | ||
friend class ParametricMapObject; | ||
|
||
public: | ||
typedef itk::Vector<double,3> DoubleVectorType; | ||
typedef itk::Size<3> SizeType; | ||
|
||
// implementation of the image volume geometry | ||
// NB: duplicated from MultiframeObject! | ||
typedef unsigned char DummyPixelType; | ||
typedef itk::Image<DummyPixelType, 3> DummyImageType; | ||
typedef DummyImageType::PointType PointType; | ||
typedef DummyImageType::DirectionType DirectionType; | ||
|
||
ImageVolumeGeometry(); | ||
|
||
int setSpacing(DoubleVectorType); | ||
int setOrigin(PointType); | ||
int setExtent(SizeType); | ||
int setDirections(DirectionType); | ||
|
||
protected: | ||
// use vnl_vector to simplify support of vector calculations | ||
vnl_vector<double> rowDirection, columnDirection, sliceDirection; | ||
vnl_vector<double> origin; | ||
vnl_vector<unsigned> extent; | ||
vnl_vector<double> spacing; | ||
|
||
}; | ||
|
||
|
||
#endif //DCMQI_IMAGEVOLUMEGEOMETRY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ namespace dcmqi { | |
void readSegmentAttributes(); | ||
|
||
Json::Value createAndGetSegmentAttributes(); | ||
|
||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// Created by Andrey Fedorov on 3/11/17. | ||
// | ||
|
||
#ifndef DCMQI_MULTIFRAMEOBJECT_H | ||
#define DCMQI_MULTIFRAMEOBJECT_H | ||
|
||
|
||
#include <dcmtk/dcmfg/fgpixmsr.h> | ||
#include <dcmtk/dcmfg/fgplanor.h> | ||
#include <dcmtk/dcmfg/fgplanpo.h> | ||
#include <dcmtk/dcmfg/fgfracon.h> | ||
#include <dcmtk/dcmfg/fgderimg.h> | ||
#include <dcmtk/dcmiod/modfloatingpointimagepixel.h> | ||
|
||
#include <itkImage.h> | ||
#include <json/json.h> | ||
|
||
#include <vector> | ||
#include <dcmtk/dcmiod/modequipment.h> | ||
#include <dcmtk/dcmiod/modenhequipment.h> | ||
#include <dcmtk/dcmiod/modmultiframedimension.h> | ||
|
||
#include "dcmqi/Exceptions.h" | ||
#include "dcmqi/ImageVolumeGeometry.h" | ||
|
||
using namespace std; | ||
/* | ||
* Class to support conversion between DICOM and ITK representations | ||
* of multiframe objects | ||
* | ||
* | ||
*/ | ||
class MultiframeObject { | ||
|
||
public: | ||
|
||
// initialization from DICOM is always from the dataset(s) | ||
// that encode DICOM representation, optionally augmented by the | ||
// derivation datasets that potentially can be helpful in some | ||
// situations. | ||
int initializeFromDICOM(std::vector<DcmDataset*> sourceDataset); | ||
int initializeFromDICOM(std::vector<DcmDataset*> sourceDatasets, | ||
std::vector<DcmDataset*> derivationDatasets); | ||
|
||
// initialization from ITK will be specific to the derived types, | ||
// although there will be some common initialization of the metadata | ||
|
||
// Output is always a single DcmDataset, since this is a multiframe | ||
// object | ||
DcmDataset* getDcmDataset() const; | ||
Json::Value getMetaDataJson() const; | ||
|
||
// get ITK representation will be specific to the derived classes, | ||
// since the type of the ITK image and the number of ITK images is | ||
// different between PM and SEG | ||
|
||
protected: | ||
|
||
// Helpers to convert to dummy image type to support common | ||
// implementation of the image volume geometry | ||
typedef unsigned char DummyPixelType; | ||
typedef itk::Image<DummyPixelType, 3> DummyImageType; | ||
typedef DummyImageType::PointType PointType; | ||
typedef DummyImageType::DirectionType DirectionType; | ||
|
||
int initializeMetaDataFromString(const std::string&); | ||
// what this function does depends on whether we are coming from | ||
// DICOM or from ITK. No parameters, since all it does is exchange | ||
// between DICOM and MetaData | ||
int initializeEquipmentInfo(); | ||
int initializeContentIdentification(); | ||
|
||
// from ITK | ||
int initializeVolumeGeometryFromITK(DummyImageType::Pointer); | ||
|
||
virtual int initializeCompositeContext(); | ||
virtual bool metaDataIsComplete(); | ||
|
||
// List of tags, and FGs they belong to, for initializing dimensions module | ||
int initializeDimensions(IODMultiframeDimensionModule&, std::vector<std::pair<DcmTag, DcmTag> >); | ||
|
||
// constants to describe original representation of the data being converted | ||
enum { | ||
DICOM_REPR = 0, | ||
ITK_REPR | ||
}; | ||
int sourceRepresentationType; | ||
|
||
// TODO: abstract this into a different class, which would help with: | ||
// - checking for presence of attributes | ||
// - handling of defaults (in the future, initialized from the schema?) | ||
// - simplifying common access patterns (access to the Code tuples) | ||
Json::Value metaDataJson; | ||
|
||
// Multiframe DICOM object representation | ||
DcmDataset* dcmRepresentation; | ||
|
||
ImageVolumeGeometry volumeGeometry; | ||
|
||
// DcmDataset(s) that hold the original representation of the | ||
// object, when the sourceRepresentationType == DICOM_REPR | ||
OFVector<DcmDataset*> sourceDcmDatasets; | ||
|
||
// Common components present in the derived classes | ||
// TODO: check whether both PM and SEG use Enh module or not, refactor based on that | ||
IODEnhGeneralEquipmentModule::EquipmentInfo equipmentInfoModule; | ||
ContentIdentificationMacro contentIdentificationMacro; | ||
IODMultiframeDimensionModule dimensionsModule; | ||
|
||
// DcmDataset(s) that were used to derive the object | ||
// Probably will only be populated when sourceRepresentationType == ITK_REPR | ||
// Purpose of those: | ||
// 1) initialize derivation derivationImageFG (ITK->) | ||
// 2) initialize CommonInstanceReferenceModule (ITK->) | ||
// 3) initialize common attributes (ITK->) | ||
OFVector<DcmDataset*> derivationDcmDatasets; | ||
|
||
// Functional groups common to all MF objects: | ||
// - Shared | ||
FGPixelMeasures pixelMeasuresFG; | ||
FGPlaneOrientationPatient planeOrientationPatientFG; | ||
// - Per-frame | ||
OFVector<FGPlanePosPatient> planePosPatientFGList; | ||
OFVector<FGFrameContent> frameContentFGList; | ||
OFVector<FGDerivationImage> derivationImageFGList; | ||
|
||
}; | ||
|
||
|
||
#endif //DCMQI_MULTIFRAMEOBJECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Created by Andrey Fedorov on 3/11/17. | ||
// | ||
|
||
#ifndef DCMQI_PARAMETRICMAPOBJECT_H | ||
#define DCMQI_PARAMETRICMAPOBJECT_H | ||
|
||
|
||
#include <dcmtk/dcmfg/fgframeanatomy.h> | ||
#include <dcmtk/dcmfg/fgidentpixeltransform.h> | ||
#include <dcmtk/dcmfg/fgparametricmapframetype.h> | ||
#include <dcmtk/dcmfg/fgrealworldvaluemapping.h> | ||
#include <dcmtk/dcmpmap/dpmparametricmapiod.h> | ||
#include <itkCastImageFilter.h> | ||
|
||
#include "MultiframeObject.h" | ||
|
||
/* | ||
* | ||
*/ | ||
class ParametricMapObject : public MultiframeObject { | ||
public: | ||
typedef IODFloatingPointImagePixelModule::value_type Float32PixelType; | ||
typedef itk::Image<Float32PixelType, 3> Float32ITKImageType; | ||
|
||
// metadata is mandatory, since not all of the attributes can be present | ||
// in the derivation DcmDataset(s) | ||
int initializeFromITK(Float32ITKImageType::Pointer, const string&); | ||
// metadata is mandatory, optionally, derivation DcmDataset(s) can | ||
// help | ||
int initializeFromITK(Float32ITKImageType::Pointer, const string&, | ||
std::vector<DcmDataset*>); | ||
|
||
int updateMetaDataFromDICOM(std::vector<DcmDataset*>); | ||
|
||
protected: | ||
typedef itk::CastImageFilter<Float32ITKImageType,DummyImageType> | ||
Float32ToDummyCasterType; | ||
|
||
int initializeVolumeGeometry(); | ||
int createParametricMap(); | ||
int initializeDimensionsModule(); | ||
int initializeCompositeContext(); | ||
|
||
// Functional groups initialization | ||
|
||
// Functional groups specific to PM: | ||
// - Shared | ||
FGFrameAnatomy frameAnatomyFG; | ||
FGIdentityPixelValueTransformation identityPixelValueTransformationFG; | ||
FGParametricMapFrameType parametricMapFrameTypeFG; | ||
FGRealWorldValueMapping rwvmFG; | ||
|
||
// Data containers specific to this object | ||
Float32ITKImageType::Pointer itkImage; | ||
|
||
private: | ||
DPMParametricMapIOD* parametricMap; | ||
}; | ||
|
||
|
||
#endif //DCMQI_PARAMETRICMAPOBJECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Created by Andrey Fedorov on 3/11/17. | ||
// | ||
|
||
#ifndef DCMQI_SEGMENTATIONIMAGEOBJECT_H | ||
#define DCMQI_SEGMENTATIONIMAGEOBJECT_H | ||
|
||
|
||
#include "MultiframeObject.h" | ||
|
||
class SegmentationImageObject : public MultiframeObject { | ||
|
||
}; | ||
|
||
|
||
#endif //DCMQI_SEGMENTATIONIMAGEOBJECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.