#include "gdcmReader.h"
#include "gdcmAttribute.h"
bool Region ( char* nomefile, unsigned int* X_min, unsigned int* Y_min, unsigned int* X_max, unsigned int* Y_max );
int main(int argc, char* argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile " << std::endl;
return EXIT_FAILURE;
}
unsigned int x_min = 1;
unsigned int y_min = 1;
unsigned int x_max = 1;
unsigned int y_max = 1;
if( Region ( argv[1], &x_min, &y_min, &x_max, &y_max ) )
{
std::cout << "x_min = " << x_min << std::endl;
std::cout << "y_min = " << y_min << std::endl;
std::cout << "x_max = " << x_max << std::endl;
std::cout << "y_max = " << y_max << std::endl;
}
else
{
std::cout << "no\n";
}
}
bool Region ( char* nomefile, unsigned int* X_min, unsigned int* Y_min, unsigned int* X_max, unsigned int* Y_max )
{
gdcm::Reader reader;
reader.SetFileName( nomefile );
if( !reader.Read() )
{
std::cerr << "Could not read: " << nomefile << std::endl;
return false;
}
gdcm::File &file = reader.GetFile();
gdcm::DataSet &ds = file.GetDataSet();
gdcm::Tag tsqur(0x0018,0x6011);
if( !ds.FindDataElement( tsqur ) )
{
return false;
}
const gdcm::DataElement &squr= ds.GetDataElement( tsqur );
const gdcm::SequenceOfItems *sqi = squr.GetValueAsSQ();
if( !sqi || !sqi->GetNumberOfItems() )
{
return false;
}
const gdcm::Item & item = sqi->GetItem(1);
const gdcm::DataSet& nestedds = item.GetNestedDataSet();
gdcm::Tag tX0(0x0018,0x6018);
gdcm::Tag tY0(0x0018,0x601a);
gdcm::Tag tX1(0x0018,0x601c);
gdcm::Tag tY1(0x0018,0x601e);
if( (!nestedds.FindDataElement( tX0 ))||(!nestedds.FindDataElement( tY0 ))||(!nestedds.FindDataElement( tX1 ))||(!nestedds.FindDataElement( tY1 )) )
{
return false;
}
const gdcm::DataElement& deX0 = nestedds.GetDataElement( tX0 );
const gdcm::DataElement& deY0 = nestedds.GetDataElement( tY0 );
const gdcm::DataElement& deX1 = nestedds.GetDataElement( tX1 );
const gdcm::DataElement& deY1 = nestedds.GetDataElement( tY1 );
gdcm::Attribute<0x0018,0x6018> atX0;
gdcm::Attribute<0x0018,0x601a> atY0;
gdcm::Attribute<0x0018,0x601c> atX1;
gdcm::Attribute<0x0018,0x601e> atY1;
atX0.SetFromDataElement( deX0 );
atY0.SetFromDataElement( deY0 );
atX1.SetFromDataElement( deX1 );
atY1.SetFromDataElement( deY1 );
const uint32_t* X0 = atX0.GetValues();
const uint32_t* Y0 = atY0.GetValues();
const uint32_t* X1 = atX1.GetValues();
const uint32_t* Y1 = atY1.GetValues();
std::cout << X0 << std::endl << Y0 << std::endl << X1 << std::endl << Y1 << std::endl;
*X_min = static_cast<unsigned int>(X0[0]);
*Y_min = static_cast<unsigned int>(Y0[0]);
*X_max = static_cast<unsigned int>(X1[0]);
*Y_max = static_cast<unsigned int>(Y1[0]);
return true;
}