How do I use the DCMTK libraries in my own applica

Here's an example for the Windows platform (MSVC):

Create DCMTK project files with CMake (for demonstration purposes switch all external libraries off).
Open the main project file "dcmtk.dsw" or "dcmtk.sln" in Visual Studio.
Select target ALL_BUILD and compile the complete DCMTK.
Select INSTALL in order to install the DCMTK files to the directory specified using CMake.
Create a new directory "testapp" somewhere on your harddisk with the following files.
Example program "testapp.cxx" from the dcmdata documentation:


Code:
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"

int main()
{
  DcmFileFormat fileformat;
  OFCondition status = fileformat.loadFile("test.dcm");
  if (status.good())
  {
    OFString patientsName;
    if (fileformat.getDataset()->findAndGetOFString(DCM_PatientsName, patientsName).good())
    {
      cout << "Patient's Name: " << patientsName << endl;
    } else
      cerr << "Error: cannot access Patient's Name!" << endl;
  } else
    cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
  return 0;
}

 

Add minimum CMakeLists.txt file for MSVC6 and adjust path to installed DCMTK (if required):

 

Code:
PROJECT(testapp)

SET(DCMTK_DIR /dicom/dcmtk-3.5.4-win32-i386)

# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")

ADD_DEFINITIONS(-D_REENTRANT)

INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)

ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)


Finally, create the project files for the test application using CMake and compile it using MSVC.

 

 

你可能感兴趣的:(DCMTK)