** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: ctndicom.cpp,v 1.6 2001/03/05 21:59:55 kevin Exp $
+** $Id: ctndicom.cpp,v 1.7 2001/03/07 16:34:47 kevin Exp $
**
** 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
}
}
- DCM_ELEMENT elemPixelData = {DCM_PXLPIXELDATA, DCM_OT, "", 1, 0, NULL};
+ char szRescaleSlope[17];
+ 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};
+ 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");
+ }
+ if (DCM_ParseObject (&m_pFile, &elemRescaleIntercept, 1, NULL, 0, NULL) == DCM_NORMAL) {
+ if (sscanf (szRescaleIntercept, "%lf", &dRescaleIntercept) != 1)
+ sys_error (ERR_SEVERE, "Error parsing rescale intercept");
+ }
+ 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;
unsigned char cV1 = pRawPixels[lBase];
unsigned char cV2 = pRawPixels[lBase+1] & iMask;
int iV = cV1 + (cV2 << 8);
- v[ix][iy] = iV / dScale;
+ v[ix][iy] = iV * dRescaleSlope + dRescaleIntercept;
}
}
}
DicomImporter::~DicomImporter()
{
- DCM_CloseObject (&m_pFile);
+ if (m_pFile)
+ DCM_CloseObject (&m_pFile);
+}
+
+
+DicomExporter::DicomExporter (ImageFile* pImageFile)
+: m_pImageFile(pImageFile), m_pObject(NULL)
+{
+ DCM_Debug (FALSE);
+ if (! pImageFile) {
+ m_bFail = true;
+ m_strFailMessage = "Initialized DicomExported with NULL imagefile";
+ return;
+ }
+ m_bFail = ! createDicomObject();
+}
+
+DicomExporter::~DicomExporter ()
+{
+ if (m_pObject)
+ DCM_CloseObject (&m_pObject);
+}
+
+bool
+DicomExporter::writeFile (const char* const pszFilename)
+{
+ if (! m_pObject)
+ return false;
+
+ m_strFilename = pszFilename;
+
+ CONDITION cond = DCM_WriteFile (&m_pObject, DCM_ORDERLITTLEENDIAN, pszFilename);
+ if (cond != DCM_NORMAL) {
+ m_bFail = true;
+ m_strFailMessage = "Error writing DICOM file ";
+ m_strFailMessage += pszFilename;
+ return false;
+ }
+
+ return true;
+}
+
+bool
+DicomExporter::createDicomObject()
+{
+ CONDITION cond = DCM_CreateObject (&m_pObject, 0);
+ if (cond != DCM_NORMAL) {
+ m_bFail = true;
+ m_strFailMessage = "Error creating DICOM object";
+ return false;
+ }
+
+ double dMin, dMax;
+ m_pImageFile->getMinMax (dMin, dMax);
+ double dWidth = dMax - dMin;
+ if (dWidth == 0.)
+ dWidth = 1E-7;
+ double dScale = 65535. / dWidth;
+
+ double dRescaleIntercept = -dMin;
+ double dRescaleSlope = 1 / dScale;
+ char szRescaleIntercept[17];
+ char szRescaleSlope[17];
+ snprintf (szRescaleIntercept, sizeof(szRescaleIntercept), "%e", dRescaleIntercept);
+ snprintf (szRescaleSlope, sizeof(szRescaleIntercept), "%e", dRescaleSlope);
+
+ char szModality[] = "CT";
+ char szSOPClassUID[65] = "1.2.840.10008.5.4.1.1.2";
+ char szImgPhotometricInterp[] = "MONOCHROME2";
+ char szPixelSpacing[33] = "0\\0";
+ char szRelImageOrientationPatient[100] = "1\\0\\0\\0\\1\\0";
+ char szRelImagePositionPatient[49] = "0\\0\\0";
+ char szAcqKvp[] = "0";
+ char szRelAcquisitionNumber[] = "1";
+ char szRelImageNumber[] = "1";
+ char szIDSOPInstanceUID[] = "";
+ char szIDManufacturer[] = "CTSim";
+ char szRelPositionRefIndicator[] = "0";
+ char szRelFrameOfReferenceUID[] = "";
+ char szRelSeriesNumber[] = "1";
+ char szIDAccessionNumber[] = "0";
+ char szRelStudyID[] = "1";
+ char szIDReferringPhysician[] = "NONE";
+ char szIDStudyTime[] = "000000.0";
+ char szIDStudyDate[] = "00000000";
+ char szRelStudyInstanceUID[] = "";
+ char szPatSex[] = "O";
+ char szPatBirthdate[] = "0000000";
+ char szPatID[] = "NONE";
+ char szPatName[] = "NONE";
+ char szIDImageType[] = "ORIGINAL";
+ char szIDManufacturerModel[65] = "";
+
+#ifdef VERSION
+ snprintf (szIDManufacturerModel, sizeof(szIDManufacturerModel), "VERSION %s", VERSION);
+#endif
+ snprintf (szPixelSpacing, sizeof(szPixelSpacing), "%e\\%e", m_pImageFile->axisIncrementX(), m_pImageFile->axisIncrementY());
+ double minX, maxX, minY, maxY;
+ if (m_pImageFile->getAxisExtent(minX, maxX, minY, maxY)) {
+ minX += m_pImageFile->axisIncrementX() / 2;
+ minY += m_pImageFile->axisIncrementY() / 2;
+ snprintf(szRelImagePositionPatient, sizeof(szRelImagePositionPatient), "%e\\%e\\0", minX, minY);
+ }
+
+ unsigned short iNRows = m_pImageFile->ny();
+ unsigned short iNCols = m_pImageFile->nx();
+ unsigned short iBitsAllocated = 16;
+ unsigned short iBitsStored = 16;
+ unsigned short iHighBit = 15;
+ unsigned short iPixRep = 0;
+ unsigned short iSamplesPerPixel = 1;
+ DCM_ELEMENT aElemRequired[] = {
+ {DCM_IMGROWS, DCM_US, "", 1, sizeof(iNRows), reinterpret_cast<char*>(&iNRows)},
+ {DCM_IMGCOLUMNS, DCM_US, "", 1, sizeof(iNCols), reinterpret_cast<char*>(&iNCols)},
+ {DCM_IMGBITSALLOCATED, DCM_US, "", 1, sizeof(iBitsAllocated), reinterpret_cast<char*>(&iBitsAllocated)},
+ {DCM_IMGBITSSTORED, DCM_US, "", 1, sizeof(iBitsStored), reinterpret_cast<char*>(&iBitsStored)},
+ {DCM_IMGHIGHBIT, DCM_US, "", 1, sizeof(iHighBit), reinterpret_cast<char*>(&iHighBit)},
+ {DCM_IMGPIXELREPRESENTATION, DCM_US, "", 1, sizeof(iPixRep), reinterpret_cast<char*>(&iPixRep)},
+ {DCM_IMGSAMPLESPERPIXEL, DCM_US, "", 1, sizeof(iSamplesPerPixel), reinterpret_cast<char*>(&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},
+ };
+ 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};
+
+ 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 = iNRows - 1; iy >= 0; iy--) {
+ for (int ix = 0; ix < iNCols; ix++) {
+ unsigned long lBase = (iy * iNRows + ix) * 2;
+ unsigned int iValue = nearest<int>(dScale * (v[ix][iy] - dMin));
+ pRawPixels[lBase] = iValue & 0xFF;
+ pRawPixels[lBase+1] = (iValue & 0xFF00) >> 8;
+ }
+ }
+ cond = DCM_ModifyElements (&m_pObject, &elemPixelData, 1, NULL, 0, &iUpdateCount);
+ delete pRawPixels;
+
+ if (cond != DCM_NORMAL || iUpdateCount != 1) {
+ m_bFail = true;
+ m_strFailMessage = "Error modifying pixel data";
+ return false;
+ }
+
+ return true;
}
#endif // HAVE_CTN_DICOM
+
--------------------Configuration: libctsim - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11A.tmp" with contents
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD4.tmp" with contents
[
-/nologo /G6 /MTd /W3 /Gm /Gi /GR /GX /Zi /Od /Gy /I "..\..\..\wx2.2.5\src\png" /I "..\..\..\wx2.2.5\src\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2.2.5\include" /I "\dicom\ctn\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "HAVE_CTN_DICOM" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
+/nologo /G6 /MTd /W3 /Gm /Gi /GR /GX /Zi /Od /Gy /I "..\..\..\wx2.2.5\src\png" /I "..\..\..\wx2.2.5\src\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2.2.5\include" /I "\dicom\ctn\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "HAVE_CTN_DICOM" /D VERSION=\"3.1.0\" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
+"C:\ctsim\libctsim\backprojectors.cpp"
+"C:\ctsim\libctsupport\clip.cpp"
+"C:\ctsim\libctsupport\consoleio.cpp"
"C:\ctsim\libctsim\ctndicom.cpp"
+"C:\ctsim\libctgraphics\dlgezplot.cpp"
+"C:\ctsim\libctgraphics\ezplot.cpp"
+"C:\ctsim\libctgraphics\ezset.cpp"
+"C:\ctsim\libctgraphics\ezsupport.cpp"
+"C:\ctsim\libctsim\filter.cpp"
+"C:\ctsim\libctsupport\fnetorderstream.cpp"
+"C:\ctsim\libctsim\fourier.cpp"
+"C:\ctsim\getopt\getopt.c"
+"C:\ctsim\getopt\getopt1.c"
+"C:\ctsim\libctsim\globalvars.cpp"
+"C:\ctsim\libctsupport\hashtable.cpp"
+"C:\ctsim\libctsim\imagefile.cpp"
+"C:\ctsim\libctsupport\interpolator.cpp"
+"C:\ctsim\libctsupport\mathfuncs.cpp"
+"C:\ctsim\libctsim\phantom.cpp"
+"C:\ctsim\libctsupport\plotfile.cpp"
+"C:\ctsim\libctgraphics\pol.cpp"
+"C:\ctsim\libctsim\procsignal.cpp"
+"C:\ctsim\libctsim\projections.cpp"
+"C:\ctsim\libctsim\reconstruct.cpp"
+"C:\ctsim\libctsim\scanner.cpp"
+"C:\ctsim\libctgraphics\sgp.cpp"
+"C:\ctsim\libctsupport\strfuncs.cpp"
+"C:\ctsim\libctsupport\syserror.cpp"
+"C:\ctsim\libctsim\trace.cpp"
+"C:\ctsim\libctgraphics\transformmatrix.cpp"
+"C:\ctsim\libctsupport\xform.cpp"
]
-Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11A.tmp"
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11B.tmp" with contents
+Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD4.tmp"
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD5.tmp" with contents
[
/nologo /out:"Debug\libctsim.lib"
.\Debug\array2dfile.obj
.\Debug\transformmatrix.obj
.\Debug\xform.obj
]
-Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11B.tmp"
+Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD5.tmp"
<h3>Output Window</h3>
Compiling...
+backprojectors.cpp
+clip.cpp
+consoleio.cpp
ctndicom.cpp
+dlgezplot.cpp
+ezplot.cpp
+ezset.cpp
+ezsupport.cpp
+filter.cpp
+fnetorderstream.cpp
+fourier.cpp
+getopt.c
+getopt1.c
+C:\ctsim\getopt\getopt1.c(73) : warning C4028: formal parameter 2 different from declaration
+C:\ctsim\getopt\getopt1.c(73) : warning C4028: formal parameter 3 different from declaration
+C:\ctsim\getopt\getopt1.c(73) : warning C4028: formal parameter 4 different from declaration
+C:\ctsim\getopt\getopt1.c(89) : warning C4028: formal parameter 2 different from declaration
+C:\ctsim\getopt\getopt1.c(89) : warning C4028: formal parameter 3 different from declaration
+C:\ctsim\getopt\getopt1.c(89) : warning C4028: formal parameter 4 different from declaration
+globalvars.cpp
+hashtable.cpp
+imagefile.cpp
+interpolator.cpp
+mathfuncs.cpp
+phantom.cpp
+plotfile.cpp
+pol.cpp
+procsignal.cpp
+projections.cpp
+reconstruct.cpp
+scanner.cpp
+sgp.cpp
+strfuncs.cpp
+syserror.cpp
+trace.cpp
+transformmatrix.cpp
+xform.cpp
Creating library...
<h3>
--------------------Configuration: ctsim - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11C.tmp" with contents
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD6.tmp" with contents
[
winmm.lib rpcrt4.lib ws2_32.lib ../libctsim/Debug/libctsim.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib wxd.lib xpmd.lib tiffd.lib zlibd.lib pngd.lib comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib htmlhelp.lib ctn_lib.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"\wx2.2.5\lib" /libpath:"\dicom\ctn\winctn\ctn_lib\Debug"
.\Debug\backgroundmgr.obj
\wx2.2.5\lib\zlibd.lib
\wx2.2.5\lib\tiffd.lib
]
-Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP11C.tmp"
+Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSPD6.tmp"
<h3>Output Window</h3>
Linking...
<h3>Results</h3>
-ctsim.exe - 0 error(s), 0 warning(s)
+ctsim.exe - 0 error(s), 6 warning(s)
</pre>
</body>
</html>