Skip to content

Commit

Permalink
STYLE: Manually syncronize trivial fixes from VTK to ITK
Browse files Browse the repository at this point in the history
Compare files from VTK/Utilities/DICOMParser with ITK
versions to manually make trivial changes that minimize
the code bases.
  • Loading branch information
hjmjohnson committed Feb 27, 2022
1 parent c7ae377 commit ddc0a37
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 109 deletions.
22 changes: 7 additions & 15 deletions Modules/ThirdParty/DICOMParser/src/DICOMParser/CMakeLists.txt
Expand Up @@ -31,25 +31,17 @@ project(${DICOMPARSER_NAMESPACE})
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})

if(WIN32)
if(BUILD_SHARED_LIBS)
if (WIN32)
if (BUILD_SHARED_LIBS)
set(DICOM_DLL 1)
else()
else ()
set(DICOM_STATIC 1)
endif()
endif()

if(ITK_SOURCE_DIR)
# Inside ITK, use its setting.
set(DICOM_ANSI_STDLIB 1)
else()
# Not inside ITK, use ANSI streams.
set(DICOM_ANSI_STDLIB 1)
endif()
endif ()
endif ()
set(DICOM_ANSI_STDLIB 1)

include(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake)
set(DICOM_NO_STD_NAMESPACE ${CMAKE_NO_STD_NAMESPACE})

include(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake)

configure_file(${PROJECT_SOURCE_DIR}/DICOMCMakeConfig.h.in
${PROJECT_BINARY_DIR}/DICOMCMakeConfig.h)
Expand Down
96 changes: 48 additions & 48 deletions Modules/ThirdParty/DICOMParser/src/DICOMParser/DICOMAppHelper.cxx
Expand Up @@ -101,35 +101,35 @@ class DICOMAppHelperImplementation

struct lt_pair_int_string
{
bool operator()(const dicom_stl::pair<int, dicom_stl::string> s1,
const dicom_stl::pair<int, dicom_stl::string> s2) const
bool operator()(const dicom_stl::pair<int, dicom_stl::string>& s1,
const dicom_stl::pair<int, dicom_stl::string>& s2) const
{
return s1.first < s2.first;
}
};

struct lt_pair_float_string
{
bool operator()(const dicom_stl::pair<float, dicom_stl::string> s1,
const dicom_stl::pair<float, dicom_stl::string> s2) const
bool operator()(const dicom_stl::pair<float, dicom_stl::string>& s1,
const dicom_stl::pair<float, dicom_stl::string>& s2) const
{
return s1.first < s2.first;
}
};

struct gt_pair_int_string
{
bool operator()(const dicom_stl::pair<int, dicom_stl::string> s1,
const dicom_stl::pair<int, dicom_stl::string> s2) const
bool operator()(const dicom_stl::pair<int, dicom_stl::string>& s1,
const dicom_stl::pair<int, dicom_stl::string>& s2) const
{
return s1.first > s2.first;
}
};

struct gt_pair_float_string
{
bool operator()(const dicom_stl::pair<float, dicom_stl::string> s1,
const dicom_stl::pair<float, dicom_stl::string> s2) const
bool operator()(const dicom_stl::pair<float, dicom_stl::string>& s1,
const dicom_stl::pair<float, dicom_stl::string>& s2) const
{
return s1.first > s2.first;
}
Expand All @@ -140,16 +140,16 @@ DICOMAppHelper::DICOMAppHelper()
this->FileCount = 0;
this->BitsAllocated = 8;
this->ByteSwapData = false;
this->PixelSpacing[0] = this->PixelSpacing[1] = this->PixelSpacing[2] = 1.0f;
this->PixelSpacing[0] = this->PixelSpacing[1] = this->PixelSpacing[2] = 1.0;
this->Dimensions[0] = this->Dimensions[1] = 0;
this->Width = this->Height = 0;
this->PhotometricInterpretation = NULL;
this->TransferSyntaxUID = NULL;
this->PhotometricInterpretation = nullptr;
this->TransferSyntaxUID = nullptr;
this->CurrentSeriesUID = "";
this->InstanceUID = "";
this->RescaleOffset = 0.0f;
this->RescaleSlope = 1.0f;
this->ImageData = NULL;
this->RescaleOffset = 0.0;
this->RescaleSlope = 1.0;
this->ImageData = nullptr;
this->ImageDataLengthInBytes = 0;

// Initialize the arrays
Expand Down Expand Up @@ -600,7 +600,7 @@ void DICOMAppHelper::ContourImageSequenceCallback(
}

void DICOMAppHelper::SeriesUIDCallback(
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
DICOMParser* parser, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
if (len == 0)
{
Expand Down Expand Up @@ -771,8 +771,8 @@ void DICOMAppHelper::ArrayCallback(DICOMParser* parser, doublebyte group, double
int t2 = int((0x0000FF00 & datatype) >> 8);
int t1 = int((0x000000FF & datatype));

char ct2(t2);
char ct1(t1);
char ct2 = static_cast<char>(t2);
char ct1 = static_cast<char>(t1);

HeaderFile << "(0x";

Expand Down Expand Up @@ -868,7 +868,7 @@ void DICOMAppHelper::ArrayCallback(DICOMParser* parser, doublebyte group, double
}

void DICOMAppHelper::SliceNumberCallback(
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
DICOMParser* parser, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
// Look for the current instance UID in the map of slice ordering data
DICOMAppHelperImplementation::InstanceUIDToSliceOrderingMapType::iterator it;
Expand Down Expand Up @@ -936,7 +936,7 @@ void DICOMAppHelper::SliceLocationCallback(
}

void DICOMAppHelper::ImagePositionPatientCallback(
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte)
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
// Look for the current instance UID in the map of slice ordering data
DICOMAppHelperImplementation::InstanceUIDToSliceOrderingMapType::iterator it;
Expand All @@ -954,9 +954,9 @@ void DICOMAppHelper::ImagePositionPatientCallback(
else
{
// no actual position specified, default to the origin
ord.ImagePositionPatient[0] = 0.0f;
ord.ImagePositionPatient[1] = 0.0f;
ord.ImagePositionPatient[2] = 0.0f;
ord.ImagePositionPatient[0] = 0.0;
ord.ImagePositionPatient[1] = 0.0;
ord.ImagePositionPatient[2] = 0.0;
}

// insert into the map
Expand All @@ -977,9 +977,9 @@ void DICOMAppHelper::ImagePositionPatientCallback(
else
{
// no actual position specified, default to the origin
(*it).second.ImagePositionPatient[0] = 0.0f;
(*it).second.ImagePositionPatient[1] = 0.0f;
(*it).second.ImagePositionPatient[2] = 0.0f;
(*it).second.ImagePositionPatient[0] = 0.0;
(*it).second.ImagePositionPatient[1] = 0.0;
(*it).second.ImagePositionPatient[2] = 0.0;
}

// cache the value
Expand All @@ -988,7 +988,7 @@ void DICOMAppHelper::ImagePositionPatientCallback(
}

void DICOMAppHelper::ImageOrientationPatientCallback(
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte)
DICOMParser*, doublebyte, doublebyte, DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
// Look for the current instance UID in the map of slice ordering data
DICOMAppHelperImplementation::InstanceUIDToSliceOrderingMapType::iterator it;
Expand All @@ -1007,12 +1007,12 @@ void DICOMAppHelper::ImageOrientationPatientCallback(
else
{
// no orientation defined, default to an standard axial orientation
ord.ImageOrientationPatient[0] = 1.0f;
ord.ImageOrientationPatient[1] = 0.0f;
ord.ImageOrientationPatient[2] = 0.0f;
ord.ImageOrientationPatient[3] = 0.0f;
ord.ImageOrientationPatient[4] = 1.0f;
ord.ImageOrientationPatient[5] = 0.0f;
ord.ImageOrientationPatient[0] = 1.0;
ord.ImageOrientationPatient[1] = 0.0;
ord.ImageOrientationPatient[2] = 0.0;
ord.ImageOrientationPatient[3] = 0.0;
ord.ImageOrientationPatient[4] = 1.0;
ord.ImageOrientationPatient[5] = 0.0;
}

// insert into the map
Expand All @@ -1032,12 +1032,12 @@ void DICOMAppHelper::ImageOrientationPatientCallback(
else
{
// no orientation defined, default to an standard axial orientation
(*it).second.ImageOrientationPatient[0] = 1.0f;
(*it).second.ImageOrientationPatient[1] = 0.0f;
(*it).second.ImageOrientationPatient[2] = 0.0f;
(*it).second.ImageOrientationPatient[3] = 0.0f;
(*it).second.ImageOrientationPatient[4] = 1.0f;
(*it).second.ImageOrientationPatient[5] = 0.0f;
(*it).second.ImageOrientationPatient[0] = 1.0;
(*it).second.ImageOrientationPatient[1] = 0.0;
(*it).second.ImageOrientationPatient[2] = 0.0;
(*it).second.ImageOrientationPatient[3] = 0.0;
(*it).second.ImageOrientationPatient[4] = 1.0;
(*it).second.ImageOrientationPatient[5] = 0.0;
}
}
}
Expand All @@ -1058,7 +1058,7 @@ void DICOMAppHelper::TransferSyntaxCallback(
static const char* TRANSFER_UID_EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";

// Only add the ToggleSwapBytes callback when we need it.
if (strcmp(TRANSFER_UID_EXPLICIT_BIG_ENDIAN, (char*)val) == 0)
if (strcmp(TRANSFER_UID_EXPLICIT_BIG_ENDIAN, reinterpret_cast<char*>(val)) == 0)
{
this->ByteSwapData = true;
parser->AddDICOMTagCallback(0x0800, 0x0000, DICOMParser::VR_UNKNOWN, ToggleSwapBytesCB);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ void DICOMAppHelper::PixelSpacingCallback(DICOMParser* parser, doublebyte group,

if (group == 0x0028 && element == 0x0030)
{
float fval = 1.0f; // defaul of 1mm
float fval = 1.0; // defaul of 1mm
if (len > 0)
{
fval = DICOMFile::ReturnAsFloat(val, parser->GetDICOMFile()->GetPlatformIsBigEndian());
Expand All @@ -1151,7 +1151,7 @@ void DICOMAppHelper::PixelSpacingCallback(DICOMParser* parser, doublebyte group,
}
else if (group == 0x0018 && element == 0x0050)
{
float fval = 1.0f; // defaul of 1mm
float fval = 1.0; // defaul of 1mm
if (len > 0)
{
fval = DICOMFile::ReturnAsFloat(val, parser->GetDICOMFile()->GetPlatformIsBigEndian());
Expand Down Expand Up @@ -1229,7 +1229,7 @@ void DICOMAppHelper::PhotometricInterpretationCallback(
}
else
{
this->PhotometricInterpretation = NULL;
this->PhotometricInterpretation = nullptr;
}
}

Expand Down Expand Up @@ -1263,7 +1263,7 @@ void DICOMAppHelper::PixelDataCallback(
unsigned char* ucharInputData = data;
short* shortInputData = reinterpret_cast<short*>(data);

float* floatOutputData; // = NULL;
float* floatOutputData; // = nullptr;

bool isFloat = this->RescaledImageDataIsFloat();

Expand Down Expand Up @@ -1444,13 +1444,13 @@ void DICOMAppHelper::ContourDataCallback(
{
sscanf((char*)(tPtr), "%f", &p);
contour[i] = p;
tPtr = (unsigned char*)strtok(NULL, "\\");
tPtr = (unsigned char*)strtok(nullptr, "\\");
sscanf((char*)(tPtr), "%f", &p);
contour[i + 1] = p;
tPtr = (unsigned char*)strtok(NULL, "\\");
tPtr = (unsigned char*)strtok(nullptr, "\\");
sscanf((char*)(tPtr), "%f", &p);
contour[i + 2] = p;
tPtr = (unsigned char*)strtok(NULL, "\\");
tPtr = (unsigned char*)strtok(nullptr, "\\");
}

delete[] tdata;
Expand Down Expand Up @@ -1561,7 +1561,7 @@ const char* DICOMAppHelper::TransferSyntaxUIDDescription(const char* uid)
void DICOMAppHelper::RescaleOffsetCallback(DICOMParser* parser, doublebyte, doublebyte,
DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
float fval = 0.0f;
float fval = 0.0;

if (len > 0)
{
Expand All @@ -1577,7 +1577,7 @@ void DICOMAppHelper::RescaleOffsetCallback(DICOMParser* parser, doublebyte, doub
void DICOMAppHelper::RescaleSlopeCallback(DICOMParser* parser, doublebyte, doublebyte,
DICOMParser::VRTypes, unsigned char* val, quadbyte len)
{
float fval = 1.0f;
float fval = 1.0;

if (len > 0)
{
Expand Down
25 changes: 14 additions & 11 deletions Modules/ThirdParty/DICOMParser/src/DICOMParser/DICOMAppHelper.h
Expand Up @@ -38,7 +38,10 @@ class DICOMParser;
struct ltstdstr
{
ltstdstr() {}
bool operator()(const dicom_stl::string s1, const dicom_stl::string s2) const { return s1 < s2; }
bool operator()(const dicom_stl::string& s1, const dicom_stl::string& s2) const
{
return s1 < s2;
}
};

// Helper structure for DICOM elements
Expand All @@ -59,16 +62,16 @@ class DICOM_EXPORT DICOMOrderingElements
{
// Default values to something "valid"
SliceNumber = -1;
SliceLocation = 0.0f;
ImagePositionPatient[0] = 0.0f;
ImagePositionPatient[1] = 0.0f;
ImagePositionPatient[2] = 0.0f;
ImageOrientationPatient[0] = 1.0f;
ImageOrientationPatient[1] = 0.0f;
ImageOrientationPatient[2] = 0.0f;
ImageOrientationPatient[3] = 0.0f;
ImageOrientationPatient[4] = 1.0f;
ImageOrientationPatient[5] = 0.0f;
SliceLocation = 0.0;
ImagePositionPatient[0] = 0.0;
ImagePositionPatient[1] = 0.0;
ImagePositionPatient[2] = 0.0;
ImageOrientationPatient[0] = 1.0;
ImageOrientationPatient[1] = 0.0;
ImageOrientationPatient[2] = 0.0;
ImageOrientationPatient[3] = 0.0;
ImageOrientationPatient[4] = 1.0;
ImageOrientationPatient[5] = 0.0;
}

int SliceNumber;
Expand Down
Expand Up @@ -45,10 +45,10 @@ namespace DICOMPARSER_NAMESPACE
class DICOM_EXPORT DICOMCallback
{
public:
virtual ~DICOMCallback() {}
virtual void Execute(DICOMParser* parser, doublebyte group, doublebyte element,
DICOMParser::VRTypes type, unsigned char* val, quadbyte len) = 0;
DICOMCallback() {}
virtual ~DICOMCallback() {}
};

//
Expand Down Expand Up @@ -76,7 +76,7 @@ class DICOMMemberCallback : public DICOMCallback
// Execute method implementation from DICOMCallback.
//
void Execute(DICOMParser* parser, doublebyte group, doublebyte element, DICOMParser::VRTypes type,
unsigned char* val, quadbyte len)
unsigned char* val, quadbyte len) override
{
if (MemberFunction)
{
Expand Down
8 changes: 4 additions & 4 deletions Modules/ThirdParty/DICOMParser/src/DICOMParser/DICOMFile.cxx
Expand Up @@ -20,12 +20,12 @@
#pragma warning(push, 3)
#endif

#include "DICOMFile.h"
#include "DICOMConfig.h"

#include <stdio.h>
#include <string>

#include "DICOMConfig.h"
#include "DICOMFile.h"

namespace DICOMPARSER_NAMESPACE
{
DICOMFile::DICOMFile()
Expand Down Expand Up @@ -119,7 +119,7 @@ void DICOMFile::SkipToStart()

void DICOMFile::Read(void* ptr, long nbytes)
{
InputStream.read((char*)ptr, nbytes);
InputStream.read(static_cast<char*>(ptr), nbytes);
// dicom_stream::cout << "DICOMFile::Read " << (char*) ptr << dicom_stream::endl;
}
} // namespace DICOMPARSER_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/DICOMParser/src/DICOMParser/DICOMFile.h
Expand Up @@ -27,8 +27,8 @@
#include <string>

#include "DICOMConfig.h"
#include "DICOMSource.h"
#include "DICOMTypes.h"
#include "DICOMSource.h"

namespace DICOMPARSER_NAMESPACE
{
Expand Down

0 comments on commit ddc0a37

Please sign in to comment.