165 lines
4.5 KiB
C++
165 lines
4.5 KiB
C++
#include "itkImageProcessorHelpers.h"
|
|
#include <gdcmReader.h>
|
|
#include <stdio.h>
|
|
|
|
namespace itk {
|
|
|
|
|
|
TransformType::Pointer
|
|
MapTransformToNewOrigin(
|
|
ImageType3D::PointType m_COR, // Center of rotation for the proj geometry. this is my new origin.
|
|
ImageType3D::PointType m_Translations,
|
|
ImageType3D::PointType m_Rotations
|
|
){
|
|
|
|
TransformType::Pointer InputTransform = TransformType::New();
|
|
InputTransform->SetComputeZYX(true);
|
|
InputTransform->SetIdentity();
|
|
|
|
TransformType::OutputVectorType translation;
|
|
translation[0] = m_Translations[0];
|
|
translation[1] = m_Translations[1];
|
|
translation[2] = m_Translations[2];
|
|
|
|
InputTransform->SetTranslation(translation);
|
|
|
|
const double dtr = (atan(1.0) * 4.0) / 180.0;
|
|
InputTransform->SetRotation(
|
|
dtr * m_Rotations[0],
|
|
dtr * m_Rotations[1],
|
|
dtr * m_Rotations[2]);
|
|
|
|
ImageType3D::PointType m_TransformOrigin;
|
|
m_TransformOrigin.Fill(0.);
|
|
InputTransform->SetCenter(
|
|
m_TransformOrigin );
|
|
|
|
ImageType3D::PointType NewOriginTranslations =
|
|
InputTransform->TransformPoint(m_COR);
|
|
|
|
ImageType3D::PointType DeltaNewOrigin =
|
|
NewOriginTranslations - m_COR;
|
|
|
|
|
|
TransformType::Pointer m_OutputTransform =
|
|
TransformType::New();
|
|
m_OutputTransform ->SetComputeZYX(true);
|
|
m_OutputTransform ->SetIdentity();
|
|
|
|
translation[0] = DeltaNewOrigin[0];
|
|
translation[1] = DeltaNewOrigin[1];
|
|
translation[2] = DeltaNewOrigin[2];
|
|
|
|
m_OutputTransform->SetTranslation(translation);
|
|
m_OutputTransform->SetRotation(
|
|
dtr * m_Rotations[0],
|
|
dtr * m_Rotations[1],
|
|
dtr * m_Rotations[2]);
|
|
|
|
m_OutputTransform->SetCenter(m_COR);
|
|
|
|
InputTransform = NULL;
|
|
|
|
return m_OutputTransform;
|
|
}
|
|
|
|
TransformType::Pointer
|
|
CalculateInternalTransformV3(
|
|
ImageType3D::PointType m_Translation, //IEC
|
|
ImageType3D::PointType m_Rotation, //IEC
|
|
ImageType3D::PointType m_CalibratedProjectionCenter, //LPS
|
|
ImageType3D::PointType m_RTIsocenter, //LPS
|
|
InternalImageType::DirectionType m_IECtoLPSDirections
|
|
)
|
|
{
|
|
|
|
//Convert all inputs into LPS
|
|
|
|
ImageType3D::PointType m_TLPS =
|
|
m_IECtoLPSDirections * m_Translation;
|
|
|
|
ImageType3D::PointType m_RLPS =
|
|
m_IECtoLPSDirections * m_Rotation;
|
|
|
|
// Map offset to the projection center
|
|
TransformType::Pointer m_outputTransform =
|
|
MapTransformToNewOrigin (
|
|
m_CalibratedProjectionCenter - m_RTIsocenter,
|
|
m_TLPS,
|
|
m_RLPS
|
|
);
|
|
|
|
m_outputTransform->SetCenter(m_CalibratedProjectionCenter);
|
|
|
|
return m_outputTransform;
|
|
|
|
}
|
|
|
|
const char* queryStationName(const char* pcFName){
|
|
|
|
static std::string buffer;
|
|
buffer.clear();
|
|
|
|
/* Check if we can open the file */
|
|
gdcm::Reader R;
|
|
R.SetFileName(pcFName);
|
|
if(!R.Read())
|
|
{std::cerr<<"ERROR: cannot read file: "<<pcFName<<std::endl;
|
|
return "\n";
|
|
}
|
|
|
|
const gdcm::File &file = R.GetFile();
|
|
const gdcm::DataSet &ds = file.GetDataSet();
|
|
|
|
std::string s(gGetStringValueFromTag(gdcm::Tag(0x0008,0x1010), ds));
|
|
std::copy(s.begin(), s.end(), buffer.begin());
|
|
|
|
return buffer.c_str();
|
|
|
|
}
|
|
|
|
int query2DimageReconstructionDiameter(const char *pcFName){
|
|
|
|
/* Check if we can open the file */
|
|
gdcm::Reader R;
|
|
R.SetFileName(pcFName);
|
|
if(!R.Read())
|
|
{std::cerr<<"ERROR: cannot read file: "<<pcFName<<std::endl;
|
|
return -1;
|
|
}
|
|
|
|
const gdcm::File &file = R.GetFile();
|
|
const gdcm::DataSet &ds = file.GetDataSet();
|
|
|
|
std::string buffer;
|
|
|
|
std::string s(gGetStringValueFromTag(gdcm::Tag(0x0018,0x1100), ds));
|
|
std::copy(s.begin(), s.end(), buffer.begin());
|
|
|
|
return std::stoi(buffer);
|
|
}
|
|
|
|
|
|
//FUNCTION DECLARATION NECESSARY FOR COPY/PASTE FROM vtkGDCMImageReader
|
|
// const char *gGetStringValueFromTag(const gdcm::Tag& t, const gdcm::DataSet& ds);
|
|
|
|
const char *gGetStringValueFromTag(const gdcm::Tag& t, const gdcm::DataSet& ds)
|
|
{
|
|
static std::string buffer;
|
|
buffer = ""; // cleanup previous call
|
|
if( ds.FindDataElement( t ) )
|
|
{
|
|
const gdcm::DataElement& de = ds.GetDataElement( t );
|
|
const gdcm::ByteValue *bv = de.GetByteValue();
|
|
if( bv ) // Can be Type 2
|
|
{
|
|
buffer = std::string( bv->GetPointer(), bv->GetLength() );
|
|
// Will be padded with at least one \0
|
|
}
|
|
}
|
|
// Since return is a const char* the very first \0 will be considered
|
|
return buffer.c_str();
|
|
}
|
|
|
|
}
|