コード例 #1
0
    void FillInstance(DcmDirectoryRecord& record,
                      DcmItem& dicom,
                      DcmMetaInfo& metaInfo,
                      const char* path)
    {
      // cf. "DicomDirInterface::buildImageRecord()"

      /* copy attribute values from dataset to image record */
      copyElementType1(dicom, DCM_InstanceNumber, record);
      //copyElementType1C(dicom, DCM_ImageType, record);
      copyElementType1C(dicom, DCM_ReferencedImageSequence, record);

      OFString tmp;

      DcmElement* item = record.remove(DCM_ReferencedImageSequence);
      if (item != NULL)
      {
        delete item;
      }

      if (record.putAndInsertString(DCM_ReferencedFileID, path).bad() ||
          dicom.findAndGetOFStringArray(DCM_SOPClassUID, tmp).bad() ||
          record.putAndInsertString(DCM_ReferencedSOPClassUIDInFile, tmp.c_str()).bad() ||
          dicom.findAndGetOFStringArray(DCM_SOPInstanceUID, tmp).bad() ||
          record.putAndInsertString(DCM_ReferencedSOPInstanceUIDInFile, tmp.c_str()).bad() ||
          metaInfo.findAndGetOFStringArray(DCM_TransferSyntaxUID, tmp).bad() ||
          record.putAndInsertString(DCM_ReferencedTransferSyntaxUIDInFile, tmp.c_str()).bad())
      {
        throw OrthancException(ErrorCode_BadFileFormat);
      }
    }
コード例 #2
0
 // copy optional string value from dataset to directory record
 static void copyStringWithDefault(DcmItem& dataset,
                                   const DcmTagKey &key,
                                   DcmDirectoryRecord& record,
                                   const char *defaultValue,
                                   const OFBool printWarning)
 {
     OFCondition status;
     if (dataset.tagExistsWithValue(key))
     {
       OFString stringValue;
       /* retrieve string value from source dataset and put it into the destination dataset */
       status = dataset.findAndGetOFStringArray(key, stringValue);
       if (status.good())
         status = record.putAndInsertString(key, stringValue.c_str());
     } else {
       if (printWarning && (defaultValue != NULL))
       {
         /* create warning message */
         LOG(WARNING) << "DICOMDIR: " << DcmTag(key).getTagName() << " "
                      << key << " missing, using alternative: " << defaultValue;
       }
       /* put default value */
       status = record.putAndInsertString(key, defaultValue);
     }
 }
コード例 #3
0
 // copy element from dataset to directory record
 static void copyElement(DcmItem& dataset,
                         const DcmTagKey &key,
                         DcmDirectoryRecord& record,
                         const OFBool optional,
                         const OFBool copyEmpty)
 {
   /* check whether tag exists in source dataset (if optional) */
   if (!optional || (copyEmpty && dataset.tagExists(key)) || dataset.tagExistsWithValue(key))
   {
     DcmElement *delem = NULL;
     /* get copy of element from source dataset */
     OFCondition status = dataset.findAndGetElement(key, delem, OFFalse /*searchIntoSub*/, OFTrue /*createCopy*/);
     if (status.good())
     {
       /* ... and insert it into the destination dataset (record) */
       status = record.insert(delem, OFTrue /*replaceOld*/);
       if (status.good())
       {
         DcmTag tag(key);
         /* check for correct VR in the dataset */
         if (delem->getVR() != tag.getEVR())
         {
           /* create warning message */
           LOG(WARNING) << "DICOMDIR: possibly wrong VR: "
                        << tag.getTagName() << " " << key << " with "
                        << DcmVR(delem->getVR()).getVRName() << " found, expected "
                        << tag.getVRName() << " instead";
         }
       } else
         delete delem;
     } else if (status == EC_TagNotFound)
       status = record.insertEmptyElement(key);
     printAttributeErrorMessage(key, status, "insert");
   }
 }
コード例 #4
0
ファイル: Dose.cpp プロジェクト: guptaabhishek1983/MPR
Dose::Dose( RTDcmtkDicomInterface* rtDoseDicom, Plan* rtPlan)
{
	d = new DoseData();
	d->m_dcmGeometry = vtkSmartPointer<DCMGeometry>::New();
	d->m_resampledDoseCuboid = NULL;
	d->m_resampled_dcm_geometry = NULL;
	DcmItem *ditem = NULL;
	const char * refPlanUID = NULL;
	this->frameRefUID = string(rtDoseDicom->Get_FRAME_OF_REFER_UID());
	this->sopUID = string(rtDoseDicom->Get_SOP_INSTANCE_UID());
	this->studyUID = string(rtDoseDicom->Get_STUDY_INSTANCE_UID());
	this->seriesUID = string(rtDoseDicom->Get_SERIES_INSTANCE_UID());
	
	this->height = rtDoseDicom->Get_ROW();
	this->width = rtDoseDicom->Get_COLOUMN();

	double image_orientation[6] = { 0, 0, 0, 0, 0, 0 };
	string imageOrientation = string(rtDoseDicom->Get_IMAGE_ORIENTATION());
	vector<string> _imageOrientation;
	tokenize(imageOrientation, _imageOrientation, "\\", true);
	for (int i = 0; i<_imageOrientation.size(); i++)
	{
		image_orientation[i] = convert_to_double(_imageOrientation.at(i).c_str());
	}

	double xorient[3] = { image_orientation[0], image_orientation[1], image_orientation [2]};
	double yorient[3] = { image_orientation[3], image_orientation[4], image_orientation [5]};


	double firstImagePosition[3] = { 0, 0, 0};
	double lastImagePosition[3] = { 0, 0, 0};
	string imagePosition = string(rtDoseDicom->Get_IMAGE_POSITION());
	vector<string> _imagePosition;
	tokenize(imagePosition, _imagePosition, "\\", true);
	for (int i = 0; i<_imagePosition.size(); i++)
	{
		firstImagePosition[i] = convert_to_double(_imagePosition.at(i).c_str());
		lastImagePosition[i] = convert_to_double(_imagePosition.at(i).c_str());
	}

	rtDoseDicom->getMinMaxPixelValue(this->minDosePixelValue, this->maxDosePixelValue);// MinMax pixel value

	this->doseGridScaling = convert_to_double(rtDoseDicom->Get_DOSEGRID_SCALING());

	OFString _gridFrameOffsetVector;
	vector<string> temp;
	if (rtDoseDicom->dataset->findAndGetOFStringArray(DCM_GridFrameOffsetVector, _gridFrameOffsetVector).bad())
	{
		isMultiframe = false;
		//		return;
	}
	else
	{
		isMultiframe = true;
		tokenize(_gridFrameOffsetVector.c_str(), temp, "\\", true);
		// Convert offset vector points from string to float and store permanently.
		for (int i = 0; i<temp.size(); i++)
		{
			this->doseGridOffsetVector.push_back(atof(temp.at(i).c_str()));
		}
	}

	if (isMultiframe)
		lastImagePosition[2] += doseGridOffsetVector.at(doseGridOffsetVector.size() - 1);
	else
		lastImagePosition[2] += 0;

	double spacing[3] = { 0, 0, 0 };
	const char* _pixelSpacing = rtDoseDicom->Get_PIXEL_SPACING();
	vector<string> temp1;
	tokenize(_pixelSpacing, temp1, "\\", true);
	spacing[0] = convert_to_double(temp1.at(0).c_str());
	spacing[1] = convert_to_double(temp1.at(1).c_str());
	if (isMultiframe)
	{
		spacing[2] = this->doseGridOffsetVector.at(1) - this->doseGridOffsetVector.at(0);// hardcoded.
	}
	else
	{
		//this->pixelSpacing[0] = 0;
		//this->pixelSpacing[1] = 0;
		spacing[2] = 0;
	}

	int numberOfFrames = convert_to_int(rtDoseDicom->Get_NO_OF_FRAMES());
	int dim[3] = { this->width, this->height, numberOfFrames };

	
	d->m_dcmGeometry->SetImageGeometry(firstImagePosition, spacing, dim, xorient, yorient);

	//Populate frame wise pixel data in map<int,void*> framePixelData;
	int noOfBytes = rtDoseDicom->Get_BITS_ALLOCATED() / 8;
	DJDecoderRegistration::registerCodecs();
	DcmRLEDecoderRegistration::registerCodecs();

	DicomImage * dicomImage = new DicomImage(&rtDoseDicom->file_format, rtDoseDicom->file_format.getDataset()->getOriginalXfer(),
		CIF_UsePartialAccessToPixelData, 0, 1 /* fcount */);

	DJDecoderRegistration::cleanup();
	DcmRLEDecoderRegistration::cleanup();

	

	do{
		const DiPixel* diPixel = dicomImage->getInterData();
		doseFrameData* dfData = new doseFrameData();
		dfData->frameNumber = dicomImage->getFirstFrame();
		dfData->cols = rtDoseDicom->Get_COLOUMN();
		dfData->rows = rtDoseDicom->Get_ROW();

		// create a vtkImage
		vtkImageData* image = vtkImageData::New();

		image->SetDimensions(dfData->cols, dfData->rows, 1);
		image->SetSpacing(spacing[0], spacing[1], 1);
		image->Initialize();

		vtkDataArray* scalars = 0;

		switch (diPixel->getRepresentation())
		{
			case EPR_Uint8:
				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(U8DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(U8DataType));
				dfData->ORG_DicomDataType = TYPE_U8Data;*/

				scalars = vtkUnsignedCharArray::New();
				((vtkUnsignedCharArray*)(scalars))->SetArray((unsigned char*)diPixel->getData(), diPixel->getCount(), 1);
				break;

			case EPR_Sint8:

				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(S8DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(S8DataType));
				dfData->ORG_DicomDataType = TYPE_S8Data;*/

				scalars = vtkSignedCharArray::New();
				((vtkSignedCharArray*)(scalars))->SetArray((signed char*)diPixel->getData(), diPixel->getCount(), 1);
				break;

			case EPR_Uint16:
				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(U16DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(U16DataType));
				dfData->ORG_DicomDataType = TYPE_U16Data;*/

				scalars = vtkUnsignedShortArray::New();
				((vtkUnsignedShortArray*)(scalars))->SetArray((unsigned short*)diPixel->getData(), diPixel->getCount(), 1);
				break;

			case EPR_Sint16:

				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(S16DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(S16DataType));
				dfData->ORG_DicomDataType = TYPE_S16Data;*/

				scalars = vtkShortArray::New();
				((vtkShortArray*)(scalars))->SetArray((short*)diPixel->getData(), diPixel->getCount(), 1);
				break;

			case EPR_Uint32:
				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(U32DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(U32DataType));
				dfData->ORG_DicomDataType = TYPE_U32Data;*/

				scalars = vtkUnsignedIntArray::New();
				((vtkUnsignedIntArray*)(scalars))->SetArray((unsigned int*)diPixel->getData(), diPixel->getCount(), 1);

				break;

			case EPR_Sint32:
				/*dfData->ORG_pixelData = calloc(diPixel->getCount(),sizeof(S32DataType));
				memcpy(dfData->ORG_pixelData,diPixel->getData(),diPixel->getCount()*sizeof(S32DataType));
				dfData->ORG_DicomDataType = TYPE_S32Data;*/

				scalars = vtkIntArray::New();
				((vtkIntArray*)(scalars))->SetArray((int*)diPixel->getData(), diPixel->getCount(), 1);
				break;
			default:
				RAD_LOG_CRITICAL("DCMTK EP_Representation type:" << diPixel->getRepresentation() << " not supported");
		}

		scalars->SetNumberOfComponents(1);
		image->SetDimensions(dfData->cols, dfData->rows, 1);

		image->SetSpacing(spacing[0], spacing[1], 1.0);

		image->GetPointData()->SetScalars(scalars);
		image->GetPointData()->GetScalars()->SetName("DICOMImage");
		//image->Update();
		double bounds[6];
		image->GetBounds(bounds);

		// type cast all images to unsigned int32
		vtkImageCast* imageCast = vtkImageCast::New();
		imageCast->SetInputData(image);
		imageCast->SetOutputScalarTypeToFloat();
		imageCast->Update();

		dfData->pixelData = calloc(diPixel->getCount(), sizeof(U32DataType));
		dfData->dicomDataType = TYPE_U32Data;
		RAD_LOG_INFO("MEMCPY pixel data for frame:" << dicomImage->getFirstFrame())

			memcpy(dfData->pixelData, imageCast->GetOutput()->GetPointData()->GetScalars()->GetVoidPointer(0),
			imageCast->GetOutput()->GetPointData()->GetScalars()->GetSize()*sizeof(float));

		imageCast->Delete();
		scalars->Delete();
		image->Delete();

		this->allFrameDoseData.push_back(dfData);

	} while (dicomImage->processNextFrames());

	/// compute cuboid

	// get first dose frame data
	doseFrameData* dfData = allFrameDoseData.at(0);

	// create VTK Cuboid
	int dimension[3] = { dfData->cols, dfData->rows, allFrameDoseData.size() };
	long dicomSliceSize = dimension[0] * dimension[1];
	long dicomDataSize = dimension[0] * dimension[1] * dimension[2];
	long dicomDataIdx = dicomSliceSize;

	void* dicomData = rad_get_memory(dicomDataSize * sizeof(float));
#ifdef ULTA
	for (int i = allFrameDoseData.size() - 1; i >= 0; i--)
#else
	for (int i = 0;i< allFrameDoseData.size();i++)
#endif
	{
		float* dicomData2 = static_cast<float*>(dicomData);
		dicomData2 += dicomDataSize;
		memcpy(dicomData2 - dicomDataIdx, allFrameDoseData.at(i)->pixelData, dicomSliceSize*sizeof(float));
		dicomDataIdx += dicomSliceSize;
	}

	vtkDataArray* scalars = 0;
	scalars = vtkFloatArray::New();
	((vtkFloatArray*)(scalars))->SetArray((float*)dicomData, dicomDataSize, 1);
	scalars->SetNumberOfComponents(1);

	d->m_doseCuboid = vtkImageData::New();
	d->m_doseCuboid->SetDimensions(dimension);
	d->m_doseCuboid->SetSpacing(spacing);

	//double lip[3] = { 0, 0, 0 };
	//d->m_dcmGeometry->GetLastImagePosition(lip);
	//d->m_doseCuboid->SetOrigin(firstImagePosition);

	d->m_doseCuboid->GetPointData()->SetScalars(scalars);
	d->m_doseCuboid->GetPointData()->GetScalars()->SetName("Dose Cuboid");
	d->m_doseCuboid->Modified();



	rxDose = rtPlan->getTargetPrescribedDose();
	int dosemax = int(this->maxDosePixelValue * this->doseGridScaling * 10000 / rxDose);
	// ISODOSE LEVEL(s) READY
	this->isodoses.push_back(new isodose(dosemax, 120, 0, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(102, 170, 0, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(100, 238, 69, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(98, 255, 65, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(95, 255, 255, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(90, 0, 255, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(80, 0, 139, 0, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(70, 0, 255, 255, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(50, 0, 0, 255, "", false, 0, 0, "Built-In"));
	this->isodoses.push_back(new isodose(30, 0, 0, 128, "", false, 0, 0, "Built-In"));
	// Calculate cGy Value and append to names.
	for (int i = 0; i<this->isodoses.size(); i++)
	{
		isodose* iso = this->isodoses.at(i);
		iso->cGyValue = (int)(iso->level * rxDose / 100);
		iso->name.append(convert_to_string(iso->level));
		iso->name.append("% - ");
		iso->name.append(convert_to_string(iso->cGyValue));
		iso->name.append(" cGy");
		iso->pixelIntensity = iso->level * rxDose / (this->doseGridScaling * 10000);
	}

	// load DV data
	DcmItem *dvhItem = NULL;
	signed long dvhCount = 0;
	while (rtDoseDicom->dataset->findAndGetSequenceItem(DCM_DVHSequence, dvhItem, dvhCount++).good())
	{
		DVH* dh = new DVH();

		DcmItem *dvhRefROISequenceItem = NULL;

		// ROI Number
		const char * RoiNumber = NULL;
		if (dvhItem->findAndGetSequenceItem(DCM_DVHReferencedROISequence, dvhRefROISequenceItem, 0).good())
		{
			OFCondition status = dvhItem->findAndGetString(DCM_ReferencedROINumber, RoiNumber, true);
			dh->setROINumber(convert_to_uint(RoiNumber));
		}

		// DVH Data
		string fNm = "D:\\DVH_DICOM_";
		fNm.append(convert_to_string(dvhCount));
		fNm.append(".csv");
		//ofstream Morison_File(fNm.c_str());

		const char * dvhdata = NULL;
		dvhItem->findAndGetString(DCM_DVHData, dvhdata);

		vector<string> dvhdataListTemp;
		tokenize(dvhdata, dvhdataListTemp, "\\");
		for (int i = 0; i < dvhdataListTemp.size(); i++)
		{
			i++;
			string volume = dvhdataListTemp.at(i);
			if (0 > int(atof(volume.c_str())))
				volume = "0";
			dh->dvhDataList.push_back(convert_to_double(volume.c_str()));
	//		Morison_File << volume.c_str() << endl;
		}
		//Morison_File.close();

		//convert volume information in dvhDataList from abosulte to percentage.
		dh->setMaxDVHValue(*std::max_element(dh->dvhDataList.begin(), dh->dvhDataList.end()));

		/*std::transform(dh->dvhDataList.begin(), dh->dvhDataList.end(),
			dh->dvhDataList.begin(), std::bind2nd(std::divides<double>(), dh->getMaxDVHValue()));

		std::transform(dh->dvhDataList.begin(), dh->dvhDataList.end(),
			dh->dvhDataList.begin(), std::bind2nd(std::multiplies<double>(), 100));*/


		// DVH Mini Dose
		const char * dvhMinDose = NULL;
		if (dvhItem->findAndGetString(DCM_DVHMinimumDose, dvhMinDose).good())
			dh->setDVHMiniDose(convert_to_double(dvhMinDose));

		//DVH Max Dose
		const char * dvhMaxDose = NULL;
		if (dvhItem->findAndGetString(DCM_DVHMaximumDose, dvhMaxDose).good())
			dh->setDVHMaxDose(convert_to_double(dvhMaxDose));

		//DVH Mean Dose
		const char * dvhMeanDose = NULL;
		if (dvhItem->findAndGetString(DCM_DVHMeanDose, dvhMeanDose).good())
			dh->setDVHMeanDose(convert_to_double(dvhMeanDose));

		// Structureset ref SOPUID
		DcmItem *dvhRefStructureSet = NULL;
		const char * structSetRefSOPUID = NULL;
		if (rtDoseDicom->dataset->findAndGetSequenceItem(DCM_ReferencedStructureSetSequence, dvhRefStructureSet).good())
		{
			if (dvhRefStructureSet->findAndGetString(DCM_ReferencedSOPInstanceUID, structSetRefSOPUID, true).good())
			dh->setStrucSetRefSopUID(string(structSetRefSOPUID));
		}
		this->dh.push_back(dh);
	}
}
コード例 #5
0
ファイル: Dose.cpp プロジェクト: guptaabhishek1983/MPR
// --------------------------------------------------------------
// ------------------- Plan 
Plan::Plan(RTDcmtkDicomInterface* rtPlanDicom)
{
	this->rxDose = 0.0;
	// Plan dose reference sequence
	DcmItem* doseRefSeqItem = NULL;
	int doseRefSeqItemCount = 0;
	this->studyUID = string(rtPlanDicom->Get_STUDY_INSTANCE_UID());
	if (rtPlanDicom->Get_FRAME_OF_REFER_UID() != NULL)
		this->frameRefUID = string(rtPlanDicom->Get_FRAME_OF_REFER_UID());
	this->sopUID = string(rtPlanDicom->Get_SOP_INSTANCE_UID());
	this->rtPlanLabel = string(rtPlanDicom->Get_RT_PLAN_LABEL());


	while (rtPlanDicom->dataset->findAndGetSequenceItem(DCM_DoseReferenceSequence, doseRefSeqItem, doseRefSeqItemCount++).good())
	{
		RAD_LOG_INFO(">>RT PLAN DOSE REF SEQUENCE:#" << doseRefSeqItemCount);
		const char* structType = NULL;
		doseRefSeqItem->findAndGetString(DCM_DoseReferenceStructureType, structType);
		bool _isSupported = false;
		if (strcmp(structType, "SITE") == 0 || strcmp(structType, "VOLUME") == 0)
		{
			_isSupported = true;
		}
		if (_isSupported)
		{

			DoseReferenceSequence* _rtplanDoseRef = new DoseReferenceSequence();
			_rtplanDoseRef->p_structureType = structType;

			const char* num = NULL;
			doseRefSeqItem->findAndGetString(DCM_DoseReferenceNumber, num);
			if (num != NULL)
			{
				_rtplanDoseRef->p_uniqueNumber = atoi(num);
			}
			doseRefSeqItem->findAndGetString(DCM_DoseReferenceDescription, _rtplanDoseRef->p_description);
			num = NULL;
			doseRefSeqItem->findAndGetString(DCM_TargetPrescriptionDose, num);
			if (num != NULL)
			{
				int rxdose = convert_to_double(num) * 100;
				if (rxdose > this->rxDose)
					this->rxDose = rxdose;
				_rtplanDoseRef->p_targetPrescriptionDose = atof(num);
			}
			doseRefSeqItem->findAndGetString(DCM_DoseReferenceType, _rtplanDoseRef->p_type);
			doseRefSeqItem->findAndGetString(DCM_DoseReferenceUID, _rtplanDoseRef->p_UID);
			//_rtplanDoseRef->p_uniqueNumber=
			this->DoseReferenceSequences.push_back(_rtplanDoseRef);


		}
		else
			RAD_LOG_CRITICAL("Dose structure type:" << structType << " is not supported");
	}

	DcmItem* fractionGroupSequence = NULL;
	int fractionGroupSequenceItemCount = 0;
	// RXDose not found in dose refernece sequence. Let's calculate dose from FractionSequence
	if (this->rxDose == 0.0 && rtPlanDicom->dataset->findAndGetSequenceItem(DCM_FractionGroupSequence, fractionGroupSequence, fractionGroupSequenceItemCount++).good())
	{
		// find the number of fractions planned.
		const char* numberOfFractionsPlanned = NULL;
		if (fractionGroupSequence->findAndGetString(DCM_NumberOfFractionsPlanned, numberOfFractionsPlanned).good())
		{
			// get referenced beam sequences.
			DcmItem* referencedBeamSequence = NULL;
			int referencedBeamSequenceItemCount = 0;
			// iterate over refernced beam sequences.
			while (fractionGroupSequence->findAndGetSequenceItem(DCM_ReferencedBeamSequence, referencedBeamSequence, referencedBeamSequenceItemCount++).good())
			{
				//find dose beam value
				const char* beamDose = NULL;
				if (referencedBeamSequence->findAndGetString(DCM_BeamDose, beamDose).good())
				{
					this->rxDose += convert_to_double(beamDose)* convert_to_int(numberOfFractionsPlanned) * 100; // formula taken from DICOMPyler code base.
				}
			}
		}
		else
		{
			RAD_LOG_CRITICAL("Tag: DCM_NumberOfFractionsPlanned not present in Fraction Group Sequence.");
			RAD_LOG_CRITICAL("RxDose is set to 0.00cGy");
		}

	}
}
コード例 #6
0
ファイル: imageinstance.cpp プロジェクト: lonelycoder/DROC
void ImageInstance::initImage(const QString &file)
{
    DcmFileFormat dcmFile;
    OFCondition result;

    result = dcmFile.loadFile(file.toLocal8Bit());
    DcmDataset *dset = dcmFile.getDataset();

    if (result.good()) {
        //patient information
        const char *value = NULL;
        result = dset->findAndGetString(DCM_PatientID, value);
        patientID = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_PatientName, value);
        patientName = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_PatientAge, value);
        patientAge = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_PatientBirthDate, value);
        patientBirth = QDate::fromString(QString::fromLocal8Bit(value),
                                         DATE_DICOM_FORMAT);

        result = dset->findAndGetString(DCM_PatientSex, value);
        patientSex = QString::fromLocal8Bit(value);

        //study information
        result = dset->findAndGetString(DCM_StudyInstanceUID, value);
        studyUid = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_StudyDate, value);
        studyTime.setDate(QDate::fromString(QString::fromLocal8Bit(value),
                                            DATE_DICOM_FORMAT));

        result = dset->findAndGetString(DCM_StudyTime, value);
        studyTime.setTime(formatDicomTime(QString::fromLatin1(value)));

        result = dset->findAndGetString(DCM_StudyDescription, value);
        studyDes = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_ProtocolName, value);
        procId = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_BodyPartExamined, value);
        bodyPart = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_Manufacturer, value);
        manufacturer = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_Modality, value);
        modality = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_StationName, value);
        stationName = QString::fromLocal8Bit(value);

        //series information
        result = dset->findAndGetString(DCM_SeriesInstanceUID, value);
        seriesUid = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_SeriesNumber, value);
        seriesNumber = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_SeriesDescription, value);
        seriesDes = QString::fromLocal8Bit(value);

        //instance information
        result = dset->findAndGetString(DCM_SOPClassUID, value);
        sopClassUid = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_SOPInstanceUID, value);
        instanceUid = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_InstanceNumber, value);
        instanceNumber = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_InstitutionName, value);
        institution = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_AcquisitionDate, value);
        if (value==NULL) result = dset->findAndGetString(DCM_ContentDate, value);
        acquisitionTime.setDate(QDate::fromString(QString::fromLatin1(value),
                                                  DATE_DICOM_FORMAT));

        result = dset->findAndGetString(DCM_AcquisitionTime, value);
        if (value==NULL) result = dset->findAndGetString(DCM_ContentTime, value);
        acquisitionTime.setTime(formatDicomTime(QString::fromLatin1(value)));

        result = dset->findAndGetString(DCM_PatientPosition, value);
        patientPostion = QString::fromLatin1(value);

        result = dset->findAndGetString(DCM_RequestingPhysician, value);
        reqPhysician = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_PerformingPhysicianName, value);
        perPhysician = QString::fromLocal8Bit(value);

        result = dset->findAndGetString(DCM_AccessionNumber, value);
        accessionNumber = QString::fromLatin1(value);

        result = dset->findAndGetFloat64(DCM_PixelSpacing, pixelSpacingY, 0);
        result = dset->findAndGetFloat64(DCM_PixelSpacing, pixelSpacingX, 1);

        result = dset->findAndGetString(DCM_KVP, value);
        kvp = QString::fromLatin1(value).toDouble();
        result = dset->findAndGetString(DCM_Exposure, value);
        mAs = QString::fromLatin1(value).toInt();

        result = dset->findAndGetFloat64(DCM_WindowWidth, winWidth);
        result = dset->findAndGetFloat64(DCM_WindowCenter, winCenter);
        defCenter = winCenter;
        defWidth = winWidth;

        if (UID_DigitalXRayImageStorageForPresentation == sopClassUid) {
            DcmItem *refItem;
            const char *refImageUid;
            dset->findAndGetSequenceItem(DCM_ReferencedImageSequence, refItem);
            if (refItem && refItem->findAndGetString(DCM_ReferencedSOPInstanceUID, refImageUid).good()) {
                QString dirName = file.left(file.lastIndexOf('/'));
                rawFile = QString("%1/%2_%3.dcm").arg(dirName, RAW_IMAGE_PREFIX, refImageUid);
                rawCenter = winCenter;
                rawWidth = winWidth;
            }
        }
    }

    dcmImage = new DicomImage(dset, dset->getOriginalXfer());
    if (dcmImage->getStatus() == EIS_Normal) {
        //dcmImage->getWindow(winCenter, winWidth);
        getPixmap(cachedPixmap);
    }
}