Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: refactoring of the code base #226

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
d45f860
WIP: refactoring of the multiframe conversion implementation
fedorov Mar 10, 2017
9266df0
BUG: initialize modality from the source dataset
fedorov Mar 11, 2017
5fbb7f1
ENH: a different shot at refactoring
fedorov Mar 14, 2017
65f336f
ENH: adding functionality - temp commit
fedorov Mar 16, 2017
7a84538
ENH: more updates
fedorov Mar 21, 2017
c531da9
ENH: checkpointing updates to the branch
fedorov Apr 8, 2017
90fa8d8
BUG: fix API typo fixed in dcmtk
fedorov May 5, 2017
d852e12
BUG: add docker_entry removed by accident in ff52820
fedorov May 5, 2017
e8c04ca
BUG: return value
fedorov May 5, 2017
13e805b
ENH: checkpoint commit
fedorov May 14, 2017
c092ec5
checkpoint
fedorov May 22, 2017
18d6d8d
ENH: fix compile errors, initialize common instance module
fedorov Jun 22, 2017
46d567b
ENH: fixing issues identified by tests
fedorov Jun 22, 2017
1ea1416
circle_ci another dummy
fedorov Jun 23, 2017
92745e3
ENH: fix more issues
fedorov Jun 23, 2017
2ba7583
BUG: fixing wrong initialization of DPMParametricMapIOD
che85 Jun 27, 2017
04fe695
ENH: adding refactored code for paramap from DCM to itk
che85 Jun 28, 2017
426fd9f
ENH: added region and origin to ImageVolumeGeometry getITKRepresentation
che85 Jun 28, 2017
01f8e5d
ENH: initialize meta information from DCM into internal data structure
che85 Jun 28, 2017
88ac52e
ENH: complete initialization of meta information from DCM
che85 Jun 28, 2017
2e46ce3
ENH: adaption to changes in https://github.com/QIICR/dcmqi/pull/271
che85 Jun 29, 2017
7937ed4
ENH: added initialization of derivation image FG
fedorov Jun 30, 2017
abdeb77
ENH: added initialization of the frame content
fedorov Jun 30, 2017
65eeb7e
ENH: fix initialization of the composite context
fedorov Jun 30, 2017
6baea74
ENH: add RWVM FG
fedorov Jun 30, 2017
1796e80
ENH: fix RWVM FG segfault
fedorov Jun 30, 2017
5a1a721
ENH: replace temporary codes with standard ones
fedorov Jun 30, 2017
f0997cd
ENH: fix initialization of PM
fedorov Jun 30, 2017
f3c29d5
BUG: fix initialization of the ITK PM output geometry
fedorov Jun 30, 2017
634e88c
ENH: added reminder comment to revisit modality initialization
fedorov Jun 30, 2017
685a4a8
BUG: initialize modality from the source dataset
fedorov Mar 11, 2017
6797a00
ENH: adding refactored code for paramap from DCM to itk
che85 Jun 28, 2017
97317bc
ENH: added first step for segmentation dcm to itk
che85 Jun 29, 2017
44d6ee3
ENH: reading segmentAttributes into metadata
che85 Jun 29, 2017
0796fc6
ENH: ctests for dcm segmentation 2 itk succeed
che85 Jun 30, 2017
97ba967
ENH: extraction of more methods
che85 Jun 30, 2017
759607e
STYLE: and uncommented code
che85 Jun 30, 2017
7fa1185
BUG: updates to account for standard updates
fedorov Jul 3, 2017
1ec643f
BUG: initialize origin from ITK image
fedorov Jul 3, 2017
3d206ac
BUG: fix initialization of ReferencedSeriesSequence
fedorov Jul 3, 2017
f5bef13
BUG: pass the initialized derivation FG to addFrame()
fedorov Jul 3, 2017
2043c7e
ENH: initialize DerivationCode from input JSON
fedorov Jul 3, 2017
7c0303a
BUG: initialize series-specific attributes from JSON
fedorov Jul 5, 2017
f4d0ca4
BUG: fix initialization of DerivationImageSequence
fedorov Jul 5, 2017
49ed047
touch to trigger circleci build
fedorov Jul 5, 2017
e4e4b11
ENH: add codecov badge
fedorov Jul 7, 2017
e74ed7a
BUG: do not cache codecov build directory
fedorov Jul 10, 2017
da677e5
ENH: switch to 3-clause BSD license
fedorov Jul 14, 2017
7b9431a
ENH: update license wording in README
fedorov Jul 14, 2017
f2be20e
STYLE: fix typo
fedorov Jul 14, 2017
150d32f
ENH: further simplify mentioning of the license
fedorov Jul 14, 2017
a51201f
WIP: adding attribute to link segmentAttributes sub-arrays to specifi…
fedorov Jul 17, 2017
7846113
ENH: make mkdir happy if the directory exists
fedorov Jul 18, 2017
a9a76be
BUG: reduce intensity tolerance test parameter
fedorov Jul 18, 2017
53ce662
ENH: finalize file order mapping
fedorov Jul 18, 2017
3012939
BUG: add segmentAttributesFileMapping
fedorov Jul 18, 2017
735be00
BUG: fix duplicate test name
fedorov Jul 18, 2017
261ad20
ENH: updated dcmtk version
che85 Jul 20, 2017
5753ee4
WIP: refactoring of the multiframe conversion implementation
fedorov Mar 10, 2017
882e54d
ENH: fixed extent computation for both paramap and seg (issue #275)
che85 Jul 7, 2017
c3ba545
ENH: reusing initializeVolumeGeometry and reorganizing
che85 Jul 7, 2017
a06b391
ENH: added comment for computation of extent including reference
che85 Jul 7, 2017
4cc12cf
ENH: separated matching frames with segmentId/slice and writing segme…
che85 Jul 11, 2017
6f582f3
ENH: renamed method, removed some comments and simplified
che85 Jul 11, 2017
78c404c
ENH: added method for creating CodeSequenceMacro from metadata attribute
che85 Jul 11, 2017
0b7878a
ENH: fixed type and renamed type ShortImageType to ShortITKImageType
che85 Jul 11, 2017
92e56c2
ENH: added missing type change
che85 Jul 11, 2017
b740f93
ENH: factored out creation of itkimage from frames
che85 Jul 12, 2017
1f440f0
ENH: started initialization from itk to DICOM for segmentations
che85 Jul 28, 2017
e702155
ENH: proceeding with further extraction and generalizing code
che85 Jul 28, 2017
86013eb
WIP: refactoring of the multiframe conversion implementation
fedorov Mar 10, 2017
9340926
BUG: initialize modality from the source dataset
fedorov Mar 11, 2017
ab76d22
ENH: a different shot at refactoring
fedorov Mar 14, 2017
ad10310
ENH: adding functionality - temp commit
fedorov Mar 16, 2017
92df603
ENH: more updates
fedorov Mar 21, 2017
4a6c043
ENH: checkpointing updates to the branch
fedorov Apr 8, 2017
cf43663
BUG: fix API typo fixed in dcmtk
fedorov May 5, 2017
01d38ee
BUG: add docker_entry removed by accident in ff52820
fedorov May 5, 2017
ad1dbea
BUG: return value
fedorov May 5, 2017
b20726a
ENH: checkpoint commit
fedorov May 14, 2017
d1ed723
checkpoint
fedorov May 22, 2017
a58ab73
ENH: fix compile errors, initialize common instance module
fedorov Jun 22, 2017
a2b5dfb
ENH: fixing issues identified by tests
fedorov Jun 22, 2017
8a27285
circle_ci another dummy
fedorov Jun 23, 2017
5a33a86
ENH: fix more issues
fedorov Jun 23, 2017
c524783
BUG: fixing wrong initialization of DPMParametricMapIOD
che85 Jun 27, 2017
ee8832e
ENH: adding refactored code for paramap from DCM to itk
che85 Jun 28, 2017
8944b6c
ENH: added region and origin to ImageVolumeGeometry getITKRepresentation
che85 Jun 28, 2017
1682bd0
ENH: initialize meta information from DCM into internal data structure
che85 Jun 28, 2017
49b676f
ENH: complete initialization of meta information from DCM
che85 Jun 28, 2017
e396019
ENH: adaption to changes in https://github.com/QIICR/dcmqi/pull/271
che85 Jun 29, 2017
d420bab
ENH: added initialization of derivation image FG
fedorov Jun 30, 2017
3448569
ENH: added initialization of the frame content
fedorov Jun 30, 2017
9a6d06c
ENH: fix initialization of the composite context
fedorov Jun 30, 2017
4091f63
ENH: add RWVM FG
fedorov Jun 30, 2017
7a27b02
ENH: fix RWVM FG segfault
fedorov Jun 30, 2017
53e7d68
ENH: replace temporary codes with standard ones
fedorov Jun 30, 2017
9648bde
ENH: fix initialization of PM
fedorov Jun 30, 2017
5391f64
BUG: fix initialization of the ITK PM output geometry
fedorov Jun 30, 2017
69308f6
ENH: added reminder comment to revisit modality initialization
fedorov Jun 30, 2017
08e5464
BUG: initialize modality from the source dataset
fedorov Mar 11, 2017
d500882
ENH: adding refactored code for paramap from DCM to itk
che85 Jun 28, 2017
51d45c7
ENH: added first step for segmentation dcm to itk
che85 Jun 29, 2017
ae28c47
ENH: reading segmentAttributes into metadata
che85 Jun 29, 2017
672ac9f
ENH: ctests for dcm segmentation 2 itk succeed
che85 Jun 30, 2017
7c6ec67
ENH: extraction of more methods
che85 Jun 30, 2017
4faeb3f
STYLE: and uncommented code
che85 Jun 30, 2017
c6732a3
BUG: updates to account for standard updates
fedorov Jul 3, 2017
e2d95ef
BUG: initialize origin from ITK image
fedorov Jul 3, 2017
02564da
BUG: fix initialization of ReferencedSeriesSequence
fedorov Jul 3, 2017
4006d1b
BUG: pass the initialized derivation FG to addFrame()
fedorov Jul 3, 2017
855cdbf
ENH: initialize DerivationCode from input JSON
fedorov Jul 3, 2017
0dc80e0
BUG: initialize series-specific attributes from JSON
fedorov Jul 5, 2017
6c48bb0
BUG: fix initialization of DerivationImageSequence
fedorov Jul 5, 2017
ec36add
touch to trigger circleci build
fedorov Jul 5, 2017
d2b2711
Merge branch 'frame-handling-refactoring' into rebased-frame-handling…
che85 Jul 28, 2017
5fd0a5d
Merge pull request #5 from che85/rebased-frame-handling-refactoring
fedorov Jul 30, 2017
6ccf62d
ENH: ignore node_modules
fedorov Jul 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ CMakeLists.txt.user*
__pycache__/
*.py[cod]
*$py.class

node_modules
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

[![OpenHub](https://www.openhub.net/p/dcmqi/widgets/project_thin_badge.gif)](https://www.openhub.net/p/dcmqi) [![codecov](https://codecov.io/gh/QIICR/dcmqi/branch/master/graph/badge.svg)](https://codecov.io/gh/QIICR/dcmqi) [![Join the chat at https://gitter.im/QIICR/dcmqi](https://badges.gitter.im/QIICR/dcmqi.svg)](https://gitter.im/QIICR/dcmqi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


[![OpenHub](https://www.openhub.net/p/dcmqi/widgets/project_thin_badge.gif)](https://www.openhub.net/p/dcmqi) [![codecov](https://codecov.io/gh/QIICR/dcmqi/branch/master/graph/badge.svg)](https://codecov.io/gh/QIICR/dcmqi) [![Join the chat at https://gitter.im/QIICR/dcmqi](https://badges.gitter.im/QIICR/dcmqi.svg)](https://gitter.im/QIICR/dcmqi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

| Docker | [![](https://images.microbadger.com/badges/version/qiicr/dcmqi:v1.0.5.svg)](https://microbadger.com/images/qiicr/dcmqi:v1.0.5) | [![](https://images.microbadger.com/badges/version/qiicr/dcmqi.svg)](https://microbadger.com/images/qiicr/dcmqi) |
|--------|--------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
Expand Down
4 changes: 2 additions & 2 deletions apps/paramaps/itkimage2paramap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// DCMQI includes
#undef HAVE_SSTREAM // Avoid redefinition warning
#include "dcmqi/ParaMapConverter.h"
#include "dcmqi/ParametricMapConverter.h"
#include "dcmqi/internal/VersionConfigure.h"


Expand Down Expand Up @@ -44,7 +44,7 @@ int main(int argc, char *argv[])
std::string metadata( (std::istreambuf_iterator<char>(metainfoStream) ),
(std::istreambuf_iterator<char>()));

DcmDataset* result = dcmqi::ParaMapConverter::itkimage2paramap(parametricMapImage, dcmDatasets, metadata);
DcmDataset* result = dcmqi::itkimage2paramapReplacement(parametricMapImage, dcmDatasets, metadata);

if (result == NULL) {
return EXIT_FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions apps/paramaps/paramap2itkimage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// DCMQI includes
#undef HAVE_SSTREAM // Avoid redefinition warning
#include "dcmqi/ParaMapConverter.h"
#include "dcmqi/ParametricMapConverter.h"
#include "dcmqi/internal/VersionConfigure.h"


Expand All @@ -25,7 +25,7 @@ int main(int argc, char *argv[])
CHECK_COND(sliceFF.loadFile(inputFileName.c_str()));
DcmDataset* dataset = sliceFF.getDataset();

pair <FloatImageType::Pointer, string> result = dcmqi::ParaMapConverter::paramap2itkimage(dataset);
pair <FloatImageType::Pointer, string> result = dcmqi::paramap2itkimageReplacement(dataset);

string fileExtension = helper::getFileExtensionFromType(outputType);

Expand Down
4 changes: 2 additions & 2 deletions apps/seg/itkimage2segimage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// DCMQI includes
#undef HAVE_SSTREAM // Avoid redefinition warning
#include "dcmqi/ImageSEGConverter.h"
#include "dcmqi/SegmentationImageConverter.h"
#include "dcmqi/internal/VersionConfigure.h"

typedef dcmqi::Helper helper;
Expand Down Expand Up @@ -91,7 +91,7 @@ int main(int argc, char *argv[])
segmentations = segmentationsReordered;
}

DcmDataset* result = dcmqi::ImageSEGConverter::itkimage2dcmSegmentation(dcmDatasets, segmentations, metadata, skipEmptySlices);
DcmDataset* result = dcmqi::SegmentationImageConverter::itkimage2dcmSegmentation(dcmDatasets, segmentations, metadata, skipEmptySlices);

if (result == NULL){
return EXIT_FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions apps/seg/segimage2itkimage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// DCMQI includes
#undef HAVE_SSTREAM // Avoid redefinition warning
#include "dcmqi/ImageSEGConverter.h"
#include "dcmqi/SegmentationImageConverter.h"
#include "dcmqi/internal/VersionConfigure.h"


Expand All @@ -24,7 +24,7 @@ int main(int argc, char *argv[])
CHECK_COND(sliceFF.loadFile(inputSEGFileName.c_str()));
DcmDataset* dataset = sliceFF.getDataset();

pair <map<unsigned,ShortImageType::Pointer>, string> result = dcmqi::ImageSEGConverter::dcmSegmentation2itkimage(dataset);
pair <map<unsigned,ShortImageType::Pointer>, string> result = dcmqi::dcmSegmentation2itkimageReplacement(dataset);

string outputPrefix = prefix.empty() ? "" : prefix + "-";

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/pm-example-float.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"CodeMeaning": "m2/s"
},
"MeasurementMethodCode": {
"CodeValue": "DWMPxxxx10",
"CodingSchemeDesignator": "99QIICR",
"CodeValue": "113290",
"CodingSchemeDesignator": "DCM",
"CodeMeaning": "Mono-exponential diffusion model"
},
"SourceImageDiffusionBValues": ["0","1400"],
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/pm-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"CodeMeaning": "um2/s"
},
"MeasurementMethodCode": {
"CodeValue": "DWMPxxxx10",
"CodingSchemeDesignator": "99QIICR",
"CodeValue": "113290",
"CodingSchemeDesignator": "DCM",
"CodeMeaning": "Mono-exponential diffusion model"
},
"SourceImageDiffusionBValues": ["0","1400"],
Expand Down
104 changes: 104 additions & 0 deletions include/dcmqi/DICOMFrame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// Created by Andrey Fedorov on 3/9/17.
//

#ifndef DCMQI_DICOMFRAME_H
#define DCMQI_DICOMFRAME_H

#include <dcmtk/dcmdata/dcdatset.h>
#include <dcmtk/dcmdata/dctk.h>
#include "ImageVolumeGeometry.h"
#include "Exceptions.h"

namespace dcmqi {

// Describe input/output frames for the purposes of sorting and associating with the
// slices of the ITK volume
class DICOMFrame {
public:
// distinguish between the frames from the legacy data and enhanced multiframe objects
enum {
LegacyInstanceFrame = 0,
EnhancedInstanceFrame
};

DICOMFrame(DcmDataset *dataset, int number=0) :
frameNumber(number),
frameDataset(dataset) {

Uint32 numFrames;
if(dataset->findAndGetUint32(DCM_NumberOfFrames, numFrames).good()){
frameType = EnhancedInstanceFrame;
if(!number){
std::cerr << "ERROR: DICOMFrame object for an enhanced frame is initialized with frame 0!" << std::endl;
}
} else {
frameType = LegacyInstanceFrame;
initializeFrameGeometryFromLegacyInstance();
}

OFString seriesUIDOF, instanceUIDOF, classUIDOF;
if(dataset->findAndGetOFString(DCM_SeriesInstanceUID, seriesUIDOF).good()){
seriesUID = seriesUIDOF.c_str();
}
if(dataset->findAndGetOFString(DCM_SOPInstanceUID, instanceUIDOF).good()){
instanceUID = instanceUIDOF.c_str();
}
if(dataset->findAndGetOFString(DCM_SOPClassUID, classUIDOF).good()){
classUID = classUIDOF.c_str();
}

};

int getFrameNumber() const {
return frameNumber; // 0 for legacy datasets, 1 or above for enhanced objects
};

vnl_vector<double> getFrameIPP(){
return frameIPP;
};

string getSeriesUID() const {
return seriesUID;
}

string getInstanceUID() const{
return instanceUID;
}

string getClassUID() const {
return classUID;
}

DcmDataset* getDataset() const {
return frameDataset;
}

private:

int initializeFrameGeometryFromLegacyInstance();
int initializeFrameGeometryFromEnhancedInstance();

int frameType;
DcmDataset *frameDataset;
int frameNumber;
vnl_vector<double> frameIPP;

string seriesUID, instanceUID, classUID;

ImageVolumeGeometry frameGeometry;

};

struct DICOMFrame_compare {
bool operator() (const DICOMFrame& lhs, const DICOMFrame& rhs) const{
std::stringstream s1,s2;
s1 << lhs.getInstanceUID();
s2 << rhs.getInstanceUID();
return (s1.str() < s2.str()) && (lhs.getFrameNumber() < rhs.getFrameNumber());
}
};

}

#endif //DCMQI_DICOMFRAME_H
14 changes: 13 additions & 1 deletion include/dcmqi/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
// DCMQI includes
#include "dcmqi/Exceptions.h"

using namespace std;
#include <json/json.h>

using namespace std;

namespace dcmqi {

Expand Down Expand Up @@ -60,10 +61,21 @@ namespace dcmqi {

static CodeSequenceMacro stringToCodeSequenceMacro(string str);
static DSRCodedEntryValue stringToDSRCodedEntryValue(string str);
static string codeSequenceMacroToString(CodeSequenceMacro);

static CodeSequenceMacro jsonToCodeSequenceMacro(Json::Value);

static void checkValidityOfFirstSrcImage(DcmSegmentation *segdoc);

static CodeSequenceMacro* createNewCodeSequence(const string& code, const string& designator, const string& meaning);

static OFString generateUID();
static OFString getTagAsOFString(DcmDataset*, DcmTagKey);

static string getCodeSequenceValue(CodeSequenceMacro &codeSequence);
static string getCodeSequenceDesignator(CodeSequenceMacro &codeSequence);
static string getCodeSequenceMeaning(CodeSequenceMacro &codeSequence);
static Json::Value codeSequence2Json(CodeSequenceMacro &codeSequence);
};

}
Expand Down
74 changes: 74 additions & 0 deletions include/dcmqi/ImageVolume.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Created by Andrey Fedorov on 3/9/17.
//

#ifndef DCMQI_IMAGEVOLUME_H
#define DCMQI_IMAGEVOLUME_H

#include <vnl/vnl_vector.h>
#include <dcmtk/dcmfg/fginterface.h>
#include <dcmtk/dcmiod/modfloatingpointimagepixel.h>

#include <itkImage.h>

namespace dcmqi {

// Maintain properties of the image volume
// Attributes ara parallel to those of itkImageData, but limited to what we need for the task of conversion,
// and the class is not templated over the pixel type, since we may not know the pixel type
// at the time class is instantiated.
//
// Initially, limit implementation and support to just Float32 used by the original PM converter.

class ImageVolume {
public:
// pixel types that are relevant for the types of objects we want to support
enum {
FLOAT32 = 0, // PM
FLOAT64, // PM
UINT16 // PM or SEG
};

typedef IODFloatingPointImagePixelModule::value_type Float32PixelType;
typedef itk::Image<Float32PixelType, 3> Float32ITKImageType;

ImageVolume(){
rowDirection.set_size(3);
columnDirection.set_size(3);
sliceDirection.set_size(3);
origin.set_size(3);
spacing.set_size(3);
pixelData = NULL;
}

// while going from DICOM PM/SEG, we get volume information from FGInterface
int initializeFromDICOM(FGInterface&);
int initializeFromITK(Float32ITKImageType::Pointer);

// TODO - inherited class? or separate segments before passing to this one?
// int initializeFromSegment(FGInterface&, unsigned);

protected:
int initializeDirections(FGInterface &);
int initializeExtent(FGInterface &);
bool getDeclaredSliceSpacing(FGInterface&);
bool getCalculatedSliceSpacing();

int setDirections(vnl_vector<double> rowDirection, vnl_vector<double> columnDirection, vnl_vector<double> sliceDirection);
int setOrigin(vnl_vector<double>);

private:

// use vnl_vector to simplify support of vector calculations
vnl_vector<double> rowDirection, columnDirection, sliceDirection;
vnl_vector<double> origin;
unsigned sliceExtent;
vnl_vector<double> spacing;
void* pixelData;
int pixelDataType;
};

};


#endif //DCMQI_IMAGEVOLUME_H
Loading