X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fctndicom.cpp;h=156cebe2e342130f0fe139d5dcf4f1b874931765;hp=4a96d02bd1470bc097dcb2c9bf57e000b52a48f6;hb=1a050c98763fbbc0662731b0b76953acede6f5d7;hpb=874ff14b6732f19fdd27e4d4b37553a222f5a1b2 diff --git a/libctsim/ctndicom.cpp b/libctsim/ctndicom.cpp index 4a96d02..156cebe 100644 --- a/libctsim/ctndicom.cpp +++ b/libctsim/ctndicom.cpp @@ -1,15 +1,15 @@ /***************************************************************************** ** FILE IDENTIFICATION ** -** Name: ctndicomp.cpp +** Name: ctndicomp.cpp ** Purpose: Interface to CTN Dicom classes -** Programmer: Kevin Rosenberg -** Date Started: March 2001 +** Programmer: Kevin Rosenberg +** Date Started: March 2001 ** ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: ctndicom.cpp,v 1.14 2002/05/08 08:55:45 kevin Exp $ +** $Id$ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -31,14 +31,14 @@ #ifdef HAVE_CTN_DICOM -#include "ctndicom.h" +#include "ctndicom.h" #include "imagefile.h" #include "projections.h" DicomImporter::DicomImporter (const char* const pszFile) - : m_pFile(NULL), m_strFilename(pszFile), m_bFail(false), m_iContents(DICOM_CONTENTS_INVALID), - m_pImageFile(NULL), m_pProjections(NULL) + : m_strFilename(pszFile), m_bFail(false), m_iContents(DICOM_CONTENTS_INVALID), + m_pImageFile(NULL), m_pProjections(NULL), m_pFile(NULL) { unsigned long lOptions = DCM_ORDERLITTLEENDIAN | DCM_FORMATCONVERSION; DCM_Debug (FALSE); @@ -46,7 +46,7 @@ DicomImporter::DicomImporter (const char* const pszFile) CONDITION cond = DCM_OpenFile (pszFile, lOptions, &m_pFile); if (cond != DCM_NORMAL) { m_bFail = true; - char textbuf [2048]; + char textbuf [2048]; CONDITION cond2 = COND_TopCondition (&cond, textbuf, sizeof(textbuf)); cond2 = DCM_NORMAL; // testing if (cond2 != DCM_NORMAL) { @@ -60,12 +60,18 @@ DicomImporter::DicomImporter (const char* const pszFile) unsigned short iNRows, iNCols, iBitsAllocated, iBitsStored, iHighBit, iPixRep; DCM_ELEMENT aElemRequired[] = { - {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNRows), reinterpret_cast(&iNRows)}, - {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNCols), reinterpret_cast(&iNCols)}, - {DCM_IMGBITSALLOCATED, DCM_US, "", 1, sizeof(iBitsAllocated), reinterpret_cast(&iBitsAllocated)}, - {DCM_IMGBITSSTORED, DCM_US, "", 1, sizeof(iBitsStored), reinterpret_cast(&iBitsStored)}, - {DCM_IMGHIGHBIT, DCM_US, "", 1, sizeof(iHighBit), reinterpret_cast(&iHighBit)}, - {DCM_IMGPIXELREPRESENTATION, DCM_US, "", 1, sizeof(iPixRep), reinterpret_cast(&iPixRep)} + {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNRows), + {reinterpret_cast(&iNRows)}}, + {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNCols), + {reinterpret_cast(&iNCols)}}, + {DCM_IMGBITSALLOCATED, DCM_US, "", 1, sizeof(iBitsAllocated), + {reinterpret_cast(&iBitsAllocated)}}, + {DCM_IMGBITSSTORED, DCM_US, "", 1, sizeof(iBitsStored), + {reinterpret_cast(&iBitsStored)}}, + {DCM_IMGHIGHBIT, DCM_US, "", 1, sizeof(iHighBit), + {reinterpret_cast(&iHighBit)}}, + {DCM_IMGPIXELREPRESENTATION, DCM_US, "", 1, sizeof(iPixRep), + {reinterpret_cast(&iPixRep)}}, }; int nElemRequired = sizeof (aElemRequired) / sizeof(DCM_ELEMENT); @@ -73,23 +79,25 @@ DicomImporter::DicomImporter (const char* const pszFile) loadImage (iNRows, iNCols, iBitsAllocated, iBitsStored, iHighBit, iPixRep); return; } - unsigned long lRtnLength; + U32 lRtnLength; DCM_TAG somatomTag = DCM_MAKETAG(TAG_GROUP_SOMATOM, TAG_MEMBER_SOMATOM_DATA); if (DCM_GetElementSize (&m_pFile, somatomTag, &lRtnLength) == DCM_NORMAL) loadProjections(); } void -DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned short iBitsAllocated, +DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned short iBitsAllocated, unsigned short iBitsStored, unsigned short iHighBit, unsigned short iPixRep) { - unsigned long lRtnLength; + U32 lRtnLength; unsigned short iSamplesPerPixel, iPlanarConfig; - - DCM_ELEMENT elemPlanarConfig = {DCM_IMGPLANARCONFIGURATION, DCM_US, "", 1, sizeof(iPlanarConfig), - reinterpret_cast(&iPlanarConfig)}; - DCM_ELEMENT elemSamplesPerPixel = {DCM_IMGSAMPLESPERPIXEL, DCM_US, "", 1, - sizeof(iSamplesPerPixel), reinterpret_cast(&iSamplesPerPixel)}; + + DCM_ELEMENT elemPlanarConfig = + {DCM_IMGPLANARCONFIGURATION, DCM_US, "", 1, sizeof(iPlanarConfig), + {reinterpret_cast(&iPlanarConfig)}}; + DCM_ELEMENT elemSamplesPerPixel = + {DCM_IMGSAMPLESPERPIXEL, DCM_US, "", 1, + sizeof(iSamplesPerPixel), {reinterpret_cast(&iSamplesPerPixel)}}; if (DCM_ParseObject (&m_pFile, &elemSamplesPerPixel, 1, NULL, 0, NULL) != DCM_NORMAL) iSamplesPerPixel = 1; // default value @@ -106,8 +114,12 @@ DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned char szRescaleIntercept[17]; double dRescaleSlope = 1; double dRescaleIntercept = 0; - DCM_ELEMENT elemRescaleSlope = {DCM_IMGRESCALESLOPE, DCM_DS, "", 1, strlen(szRescaleSlope), szRescaleSlope}; - DCM_ELEMENT elemRescaleIntercept = {DCM_IMGRESCALEINTERCEPT, DCM_DS, "", 1, strlen(szRescaleIntercept), szRescaleIntercept}; + DCM_ELEMENT elemRescaleSlope = + {DCM_IMGRESCALESLOPE, DCM_DS, "", 1, strlen(szRescaleSlope), + {szRescaleSlope}}; + DCM_ELEMENT elemRescaleIntercept = + {DCM_IMGRESCALEINTERCEPT, DCM_DS, "", 1, strlen(szRescaleIntercept), + {szRescaleIntercept}}; if (DCM_ParseObject (&m_pFile, &elemRescaleSlope, 1, NULL, 0, NULL) == DCM_NORMAL) { if (sscanf (szRescaleSlope, "%lf", &dRescaleSlope) != 1) sys_error (ERR_SEVERE, "Error parsing rescale slope"); @@ -117,7 +129,7 @@ DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned sys_error (ERR_SEVERE, "Error parsing rescale intercept"); } - DCM_ELEMENT elemPixelData = {DCM_PXLPIXELDATA, DCM_OT, "", 1, 0, NULL}; + DCM_ELEMENT elemPixelData = {DCM_PXLPIXELDATA, DCM_OT, "", 1, 0, {NULL}}; // Get the actual pixel data (the only other required element) if (DCM_GetElementSize (&m_pFile, elemPixelData.tag, &lRtnLength) != DCM_NORMAL) { m_bFail = true; @@ -140,7 +152,7 @@ DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned unsigned char* pRawPixels = new unsigned char [lCheckLengthInBytes]; elemPixelData.length = lCheckLengthInBytes; elemPixelData.d.ot = pRawPixels; - + void* ctx = NULL; CONDITION cond = DCM_GetElementValue (&m_pFile, &elemPixelData, &lRtnLength, &ctx); if ((cond != DCM_NORMAL) && (cond != DCM_GETINCOMPLETE)) { @@ -150,7 +162,7 @@ DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned return; } if ((lCheckLengthInBytes < lRealLength) && (cond != DCM_GETINCOMPLETE)) { - m_bFail; + m_bFail = true; m_strFailMessage = "Should have gooten incomplete message reading pixel data"; delete pRawPixels; return; @@ -183,13 +195,15 @@ DicomImporter::loadImage(unsigned short iNRows, unsigned short iNCols, unsigned void DicomImporter::loadProjections() { - unsigned long lRtnLength; + U32 lRtnLength; void* ctx = NULL; unsigned short iNViews, iNDets; DCM_ELEMENT aElemRequired[] = { - {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNViews), reinterpret_cast(&iNViews)}, - {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNDets), reinterpret_cast(&iNDets)}, + {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNViews), + {reinterpret_cast(&iNViews)}}, + {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNDets), + {reinterpret_cast(&iNDets)}}, }; int nElemRequired = sizeof (aElemRequired) / sizeof(DCM_ELEMENT); @@ -200,7 +214,7 @@ DicomImporter::loadProjections() } DCM_TAG somatomTag = DCM_MAKETAG(TAG_GROUP_SOMATOM, TAG_MEMBER_SOMATOM_DATA); - DCM_ELEMENT elemProjections = {somatomTag, DCM_UN, "", 1, 0, NULL}; + DCM_ELEMENT elemProjections = {somatomTag, DCM_UN, "", 1, 0, {NULL}}; if (DCM_GetElementSize (&m_pFile, elemProjections.tag, &lRtnLength) != DCM_NORMAL) { m_bFail = true; m_strFailMessage = "Can't find projection data"; @@ -210,7 +224,7 @@ DicomImporter::loadProjections() unsigned char* pRawProjections = new unsigned char [lRtnLength]; elemProjections.length = lRtnLength; elemProjections.d.ot = pRawProjections; - + ctx = NULL; CONDITION cond = DCM_GetElementValue (&m_pFile, &elemProjections, &lRtnLength, &ctx); if ((cond != DCM_NORMAL) && (cond != DCM_GETINCOMPLETE)) { @@ -356,58 +370,84 @@ DicomExporter::createDicomObject() unsigned short iPixRep = 0; unsigned short iSamplesPerPixel = 1; DCM_ELEMENT aElemRequired[] = { - {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNRows), reinterpret_cast(&iNRows)}, - {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNCols), reinterpret_cast(&iNCols)}, - {DCM_IMGBITSALLOCATED, DCM_US, "", 1, sizeof(iBitsAllocated), reinterpret_cast(&iBitsAllocated)}, - {DCM_IMGBITSSTORED, DCM_US, "", 1, sizeof(iBitsStored), reinterpret_cast(&iBitsStored)}, - {DCM_IMGHIGHBIT, DCM_US, "", 1, sizeof(iHighBit), reinterpret_cast(&iHighBit)}, - {DCM_IMGPIXELREPRESENTATION, DCM_US, "", 1, sizeof(iPixRep), reinterpret_cast(&iPixRep)}, - {DCM_IMGSAMPLESPERPIXEL, DCM_US, "", 1, sizeof(iSamplesPerPixel), reinterpret_cast(&iSamplesPerPixel)}, - {DCM_IMGRESCALESLOPE, DCM_DS, "", 1, strlen(szRescaleSlope), szRescaleSlope}, - {DCM_IMGRESCALEINTERCEPT, DCM_DS, "", 1, strlen(szRescaleIntercept), szRescaleIntercept}, - {DCM_IMGPHOTOMETRICINTERP, DCM_CS, "", 1, strlen(szImgPhotometricInterp), szImgPhotometricInterp}, - {DCM_IMGPIXELSPACING, DCM_DS, "", 1, strlen(szPixelSpacing), szPixelSpacing}, - {DCM_RELIMAGEORIENTATIONPATIENT, DCM_DS, "", 1, strlen(szRelImageOrientationPatient), szRelImageOrientationPatient}, - {DCM_RELIMAGEPOSITIONPATIENT, DCM_DS, "", 1, strlen(szRelImagePositionPatient), szRelImagePositionPatient}, - {DCM_ACQKVP, DCM_DS, "", 1, strlen(szAcqKvp), szAcqKvp}, - {DCM_RELACQUISITIONNUMBER, DCM_IS, "", 1, strlen(szRelAcquisitionNumber), szRelAcquisitionNumber}, - {DCM_ACQSLICETHICKNESS, DCM_DS, "", 1, strlen(szRelAcquisitionNumber), szRelAcquisitionNumber}, - {DCM_RELIMAGENUMBER, DCM_IS, "", 1, strlen(szRelImageNumber), szRelImageNumber}, - {DCM_IDSOPINSTANCEUID, DCM_UI, "", 1, strlen(szIDSOPInstanceUID), szIDSOPInstanceUID}, - {DCM_IDMANUFACTURER, DCM_LO, "", 1, strlen(szIDManufacturer), szIDManufacturer}, - {DCM_RELPOSITIONREFINDICATOR, DCM_LO, "", 1, strlen(szRelPositionRefIndicator), szRelPositionRefIndicator}, - {DCM_RELFRAMEOFREFERENCEUID, DCM_UI, "", 1, strlen(szRelFrameOfReferenceUID), szRelFrameOfReferenceUID}, - {DCM_RELSERIESNUMBER, DCM_IS, "", 1, strlen(szRelSeriesNumber), szRelSeriesNumber}, - {DCM_RELSERIESINSTANCEUID, DCM_UI, "", 1, strlen(szIDAccessionNumber), szIDAccessionNumber}, - {DCM_IDACCESSIONNUMBER, DCM_SH, "", 1, strlen(szIDAccessionNumber), szIDAccessionNumber}, - {DCM_RELSTUDYID, DCM_SH, "", 1, strlen(szRelStudyID), szRelStudyID}, - {DCM_IDREFERRINGPHYSICIAN, DCM_PN, "", 1, strlen(szIDReferringPhysician), szIDReferringPhysician}, - {DCM_IDSTUDYTIME, DCM_TM, "", 1, strlen(szIDStudyTime), szIDStudyTime}, - {DCM_IDSTUDYDATE, DCM_DA, "", 1, strlen(szIDStudyDate), szIDStudyDate}, - {DCM_RELSTUDYINSTANCEUID, DCM_UI, "", 1, strlen(szRelStudyInstanceUID), szRelStudyInstanceUID}, - {DCM_PATSEX, DCM_CS, "", 1, strlen(szPatSex), szPatSex}, - {DCM_PATBIRTHDATE, DCM_DA, "", 1, strlen(szPatBirthdate), szPatBirthdate}, - {DCM_PATID, DCM_LO, "", 1, strlen(szPatID), szPatID}, - {DCM_PATNAME, DCM_PN, "", 1, strlen(szPatName), szPatName}, - {DCM_IDIMAGETYPE, DCM_CS, "", 1, strlen(szIDImageType), szIDImageType}, - {DCM_IDMODALITY, DCM_CS, "", 1, strlen(szModality), szModality}, - {DCM_IDSOPCLASSUID, DCM_UI, "", 1, strlen(szSOPClassUID), szSOPClassUID}, - {DCM_IDMANUFACTURERMODEL, DCM_LO, "", 1, strlen(szIDManufacturerModel), szIDManufacturerModel}, - {DCM_PATCOMMENTS, DCM_LT, "", 1, strlen(pszPatComments), pszPatComments}, + {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNRows), + {reinterpret_cast(&iNRows)}}, + {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNCols), + {reinterpret_cast(&iNCols)}}, + {DCM_IMGBITSALLOCATED, DCM_US, "", 1, sizeof(iBitsAllocated), + {reinterpret_cast(&iBitsAllocated)}}, + {DCM_IMGBITSSTORED, DCM_US, "", 1, sizeof(iBitsStored), + {reinterpret_cast(&iBitsStored)}}, + {DCM_IMGHIGHBIT, DCM_US, "", 1, sizeof(iHighBit), + {reinterpret_cast(&iHighBit)}}, + {DCM_IMGPIXELREPRESENTATION, DCM_US, "", 1, sizeof(iPixRep), + {reinterpret_cast(&iPixRep)}}, + {DCM_IMGSAMPLESPERPIXEL, DCM_US, "", 1, sizeof(iSamplesPerPixel), + {reinterpret_cast(&iSamplesPerPixel)}}, + {DCM_IMGRESCALESLOPE, DCM_DS, "", 1, strlen(szRescaleSlope), + {szRescaleSlope}}, + {DCM_IMGRESCALEINTERCEPT, DCM_DS, "", 1, strlen(szRescaleIntercept), + {szRescaleIntercept}}, + {DCM_IMGPHOTOMETRICINTERP, DCM_CS, "", 1, strlen(szImgPhotometricInterp), + {szImgPhotometricInterp}}, + {DCM_IMGPIXELSPACING, DCM_DS, "", 1, strlen(szPixelSpacing), + {szPixelSpacing}}, + {DCM_RELIMAGEORIENTATIONPATIENT, DCM_DS, "", 1, + strlen(szRelImageOrientationPatient), {szRelImageOrientationPatient}}, + {DCM_RELIMAGEPOSITIONPATIENT, DCM_DS, "", 1, + strlen(szRelImagePositionPatient), {szRelImagePositionPatient}}, + {DCM_ACQKVP, DCM_DS, "", 1, strlen(szAcqKvp), {szAcqKvp}}, + {DCM_RELACQUISITIONNUMBER, DCM_IS, "", 1, strlen(szRelAcquisitionNumber), + {szRelAcquisitionNumber}}, + {DCM_ACQSLICETHICKNESS, DCM_DS, "", 1, strlen(szRelAcquisitionNumber), + {szRelAcquisitionNumber}}, + {DCM_RELIMAGENUMBER, DCM_IS, "", 1, strlen(szRelImageNumber), + {szRelImageNumber}}, + {DCM_IDSOPINSTANCEUID, DCM_UI, "", 1, strlen(szIDSOPInstanceUID), + {szIDSOPInstanceUID}}, + {DCM_IDMANUFACTURER, DCM_LO, "", 1, strlen(szIDManufacturer), + {szIDManufacturer}}, + {DCM_RELPOSITIONREFINDICATOR, DCM_LO, "", 1, + strlen(szRelPositionRefIndicator), {szRelPositionRefIndicator}}, + {DCM_RELFRAMEOFREFERENCEUID, DCM_UI, "", 1, + strlen(szRelFrameOfReferenceUID), {szRelFrameOfReferenceUID}}, + {DCM_RELSERIESNUMBER, DCM_IS, "", 1, strlen(szRelSeriesNumber), + {szRelSeriesNumber}}, + {DCM_RELSERIESINSTANCEUID, DCM_UI, "", 1, strlen(szIDAccessionNumber), + {szIDAccessionNumber}}, + {DCM_IDACCESSIONNUMBER, DCM_SH, "", 1, strlen(szIDAccessionNumber), + {szIDAccessionNumber}}, + {DCM_RELSTUDYID, DCM_SH, "", 1, strlen(szRelStudyID), {szRelStudyID}}, + {DCM_IDREFERRINGPHYSICIAN, DCM_PN, "", 1, strlen(szIDReferringPhysician), + {szIDReferringPhysician}}, + {DCM_IDSTUDYTIME, DCM_TM, "", 1, strlen(szIDStudyTime), {szIDStudyTime}}, + {DCM_IDSTUDYDATE, DCM_DA, "", 1, strlen(szIDStudyDate), {szIDStudyDate}}, + {DCM_RELSTUDYINSTANCEUID, DCM_UI, "", 1, strlen(szRelStudyInstanceUID), + {szRelStudyInstanceUID}}, + {DCM_PATSEX, DCM_CS, "", 1, strlen(szPatSex), {szPatSex}}, + {DCM_PATBIRTHDATE, DCM_DA, "", 1, strlen(szPatBirthdate), {szPatBirthdate}}, + {DCM_PATID, DCM_LO, "", 1, strlen(szPatID), {szPatID}}, + {DCM_PATNAME, DCM_PN, "", 1, strlen(szPatName), {szPatName}}, + {DCM_IDIMAGETYPE, DCM_CS, "", 1, strlen(szIDImageType), {szIDImageType}}, + {DCM_IDMODALITY, DCM_CS, "", 1, strlen(szModality), {szModality}}, + {DCM_IDSOPCLASSUID, DCM_UI, "", 1, strlen(szSOPClassUID), {szSOPClassUID}}, + {DCM_IDMANUFACTURERMODEL, DCM_LO, "", 1, strlen(szIDManufacturerModel), + {szIDManufacturerModel}}, + {DCM_PATCOMMENTS, DCM_LT, "", 1, strlen(pszPatComments), {pszPatComments}}, }; int nElemRequired = sizeof (aElemRequired) / sizeof(DCM_ELEMENT); int iUpdateCount; cond = DCM_ModifyElements (&m_pObject, aElemRequired, nElemRequired, NULL, 0, &iUpdateCount); - DCM_ELEMENT elemPixelData = {DCM_PXLPIXELDATA, DCM_OT, "", 1, 0, NULL}; + DCM_ELEMENT elemPixelData = {DCM_PXLPIXELDATA, DCM_OT, "", 1, 0, {NULL}}; unsigned long lRealLength = 2 * m_pImageFile->nx() * m_pImageFile->ny(); unsigned char* pRawPixels = new unsigned char [lRealLength]; elemPixelData.length = lRealLength; elemPixelData.d.ot = pRawPixels; - + ImageFileArray v = m_pImageFile->getArray(); for (int iy = 0; iy < iNRows; iy++) { for (int ix = 0; ix < iNCols; ix++) {