GDCM: GetSequenceUltrasound.cxx

GDCM 3.2.10

GetSequenceUltrasound.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#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[] )
{
// Controllo del numero di argomenti introdotti da riga di comando
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 );
//std::cout << squr << std::endl;
const gdcm::SequenceOfItems *sqi = squr. GetValueAsSQ();
if( !sqi || !sqi->GetNumberOfItems() )
{
return false;
}
//std::cout << sqi << std::endl;
const gdcm::Item & item = sqi->GetItem(1);
//std::cout << item << std::endl;
const gdcm::DataSet& nestedds = item. GetNestedDataSet();
//std::cout << nestedds << std::endl;
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 );
//std::cout << deX0 << std::endl << deY0 << std::endl << deX1 << std::endl << deY1 << std::endl;
//const gdcm::ByteValue *bvX0 = deX0.GetByteValue();
//const gdcm::ByteValue *bvY0 = deY0.GetByteValue();
//const gdcm::ByteValue *bvX1 = deX1.GetByteValue();
//const gdcm::ByteValue *bvY1 = deY1.GetByteValue();
//std::cout << bvX0 << std::endl << bvY0 << std::endl << bvX1 << std::endl << bvY1 << std::endl;
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 );
uint32_t X0 = atX0. GetValue();
uint32_t Y0 = atY0.GetValue();
uint32_t X1 = atX1.GetValue();
uint32_t Y1 = atY1.GetValue();
std::cout << X0 << std::endl << Y0 << std::endl << X1 << std::endl << Y1 << std::endl;
*X_min = static_cast<unsigned int>(X0);
*Y_min = static_cast<unsigned int>(Y0);
*X_max = static_cast<unsigned int>(X1);
*Y_max = static_cast<unsigned int>(Y1);
//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;
return true;
}
gdcm::Attribute
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
gdcm::Attribute::GetValue
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:154
gdcm::Attribute::SetFromDataElement
void SetFromDataElement(DataElement const &de)
Definition gdcmAttribute.h:206
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetValueAsSQ
SmartPointer< SequenceOfItems > GetValueAsSQ() const
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements).
Definition gdcmDataSet.h:56
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::DataSet::FindDataElement
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Item::GetNestedDataSet
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::Read
virtual bool Read()
Main function to read a file.
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::SequenceOfItems
Class to represent a Sequence Of Items.
Definition gdcmSequenceOfItems.h:40
gdcm::SequenceOfItems::GetNumberOfItems
SizeType GetNumberOfItems() const
Definition gdcmSequenceOfItems.h:86
gdcm::SequenceOfItems::GetItem
const Item & GetItem(SizeType position) const
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmAttribute.h
gdcmReader.h