Howto: Create GSPS object with multiple image references
Here's an example that shows how to create a GSPS object with annotations and multiple image references:
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmpstat/dvpstat.h"
#include "dcmtk/dcmpstat/dvpsgr.h"
int main(int argc, char *argv[])
{
if (argc < 2)
{
COUT << "syntax usage: tstgsps <gsps-output> <image-input> ..." << OFendl;
return 1;
}
DcmFileFormat imageFile;
DVPresentationState pstate;
/* load and process image input files */
for (int i = 2; i < argc; i++)
{
if (imageFile.loadFile(argv[i]).good())
{
if (i == 2)
{
/* create default GSPS object from first image */
if (pstate.createFromImage(*imageFile.getDataset()).bad())
CERR << "Error: cannot create GSPS object from first image" << OFendl;
/* attach the first image (required for graphical annotations!)*/
if (pstate.attachImage(imageFile.getDataset(), OFFalse).bad())
CERR << "Error: cannot attach first image to GSPS object" << OFendl;
}
/* add further image references to GSPS object */
else if (pstate.addImageReference(*imageFile.getDataset()).bad())
CERR << "Error: cannot add image reference #" << (i -1) << OFendl;
} else
CERR << "Error: cannot load file '" << argv[i] << "'" << OFendl;
}
/* add graphical annotation, create a new layer first ... */
if (pstate.addGraphicLayer("MEASUREMENT").good())
{
/* ... and then a graphic object */
DVPSGraphicObject *graphic = pstate.addGraphicObject(pstate.getGraphicLayerIndex("MEASUREMENT"));
if (graphic != NULL)
{
const Float32 data[] = {100, 100, 250, 250};
graphic->setGraphicType(DVPST_polyline);
graphic->setData(2, data, DVPSA_pixels);
} else
CERR << "Error: cannot create graphic object" << OFendl;
} else
CERR << "Error: cannot add graphic layer" << OFendl;
DcmFileFormat gspsFile;
/* save GSPS object first to a DICOM data set ... */
if (pstate.write(*gspsFile.getDataset(), OFTrue).good())
{
/* ... and then to a DICOM file */
if (gspsFile.saveFile(argv[1], EXS_LittleEndianExplicit).bad())
CERR << "Error: cannot save file '" << argv[1] << "'" << OFendl;
} else
CERR << "Error: cannot write GSPS object to data set" << OFendl;
return 0;
}
------------------------------------------------------------------
柳北风儿
http://qimo601.iteye.com
转载:http://support.dcmtk.org/wiki/dcmtk/howto/gspsannotations