GDCM: LargeVRDSExplicit.cxx

GDCM 3.2.10

LargeVRDSExplicit.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 "gdcmWriter.h"
#include "gdcmAttribute.h"
#include "gdcmFileExplicitFilter.h"
#include "gdcmSequenceOfItems.h"
bool interpolate(const double * pts, size_t npts, std::vector<double> &out )
{
out.clear();
for(size_t i = 0; i < 2*npts; ++i )
{
const size_t j = i / 2;
if( i % 2 )
{
if( j != npts - 1 )
{
gdcm_assert( 3*j+5 < 3*npts );
const double midpointx = (pts[3*j+0] + pts[3*j+3]) / 2;
const double midpointy = (pts[3*j+1] + pts[3*j+4]) / 2;
const double midpointz = (pts[3*j+2] + pts[3*j+5]) / 2;
out.push_back( midpointx );
out.push_back( midpointy );
out.push_back( midpointz );
}
}
else
{
gdcm_assert( j < npts );
out.push_back( pts[3*j+0] );
out.push_back( pts[3*j+1] );
out.push_back( pts[3*j+2] );
}
}
gdcm_assert( out.size() == 2 * npts * 3 - 3 );
return true;
}
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
gdcm::Reader reader;
reader. SetFileName( filename );
if( !reader. Read() )
{
return 1;
}
gdcm::File &file = reader. GetFile();
gdcm::DataSet &ds = file. GetDataSet();
gdcm::FileExplicitFilter fef;
//fef.SetChangePrivateTags( changeprivatetags );
fef. SetFile( reader.GetFile() );
if( !fef. Change() )
{
std::cerr << "Failed to change: " << filename << std::endl;
return 1;
}
// (3006,0039) SQ (Sequence with undefined length #=4) # u/l, 1 ROIContourSequence
gdcm::Tag tag(0x3006,0x0039);
const gdcm::DataElement &roicsq = ds. GetDataElement( tag );
gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = roicsq. GetValueAsSQ();
//sqi->SetNumberOfItems( 1 );
const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
const gdcm::DataSet& nestedds = item. GetNestedDataSet();
gdcm::Tag tcsq(0x3006,0x0040);
if( !nestedds. FindDataElement( tcsq ) )
{
return 0;
}
const gdcm::DataElement& csq = nestedds.GetDataElement( tcsq );
gdcm::SmartPointer<gdcm::SequenceOfItems> sqi2 = csq.GetValueAsSQ();
if( !sqi2 || !sqi2->GetNumberOfItems() )
{
return 0;
}
//unsigned int nitems = sqi2->GetNumberOfItems();
gdcm::Item & item2 = sqi2->GetItem(1); // Item start at #1
gdcm::DataSet& nestedds2 = item2.GetNestedDataSet();
//item2.SetVLToUndefined();
//std::cout << nestedds2 << std::endl;
// (3006,0050) DS [43.57636\65.52504\-10.0\46.043102\62.564945\-10.0\49.126537\60.714... # 398,48 ContourData
gdcm::Tag tcontourdata(0x3006,0x0050);
const gdcm::DataElement & contourdata = nestedds2.GetDataElement( tcontourdata );
//std::cout << contourdata << std::endl;
//const gdcm::ByteValue *bv = contourdata.GetByteValue();
gdcm::Attribute<0x3006,0x0046> ncontourpoints;
ncontourpoints. Set( nestedds2 );
gdcm::Attribute<0x3006,0x0050> at;
at. SetFromDataElement( contourdata );
const double* pts = at. GetValues();
unsigned int npts = at. GetNumberOfValues() / 3;
std::vector<double> out( pts, pts + npts * 3 );
std::vector<double> out2;
//const unsigned int niter = 7;
const unsigned int niter = 8;
for( unsigned int i = 0; i < niter; ++i)
{
//bool b =
interpolate(out.data(), out.size() / 3, out2);
//const double *pout = &out[0];
out = out2;
out2.clear();
}
gdcm_assert( out.size() % 3 == 0 );
gdcm::Attribute<0x3006,0x0050> at_interpolate;
at_interpolate.SetNumberOfValues( (unsigned int)(out.size() / 3) );
at_interpolate. SetValues( out.data(), (uint32_t)out.size() );
ncontourpoints. SetValue( at_interpolate.GetNumberOfValues() / 3 );
nestedds2. Replace( at_interpolate. GetAsDataElement() );
nestedds2.Replace( ncontourpoints.GetAsDataElement() );
//gdcm_assert(0);
// Let's take item one and subdivide it
gdcm::TransferSyntax ts = gdcm::TransferSyntax::ImplicitVRLittleEndian;
ts = gdcm::TransferSyntax::ExplicitVRLittleEndian;
gdcm::FileMetaInformation &fmi = file. GetHeader();
const char *tsuid = gdcm::TransferSyntax::GetTSString( ts );
// const char * is ok since padding is \0 anyway...
gdcm::DataElement de( gdcm::Tag(0x0002,0x0010) );
de.SetByteValue( tsuid, (uint32_t)strlen(tsuid) );
de.SetVR( gdcm::Attribute<0x0002, 0x0010>::GetVR() );
fmi. Replace( de );
fmi. Remove( gdcm::Tag(0x0002,0x0012) ); // will be regenerated
fmi.Remove( gdcm::Tag(0x0002,0x0013) ); // ' ' '
fmi. SetDataSetTransferSyntax(ts);
gdcm::Writer w;
w. SetFile( file );
w. SetFileName( outfilename );
if (!w. Write() )
{
return 1;
}
return 0;
}
gdcm::Attribute
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
gdcm::Attribute::GetVR
static VR GetVR()
Definition gdcmAttribute.h:99
gdcm::Attribute::SetValue
void SetValue(ArrayType v, unsigned int idx=0)
Definition gdcmAttribute.h:169
gdcm::Attribute::GetValues
const ArrayType * GetValues() const
Definition gdcmAttribute.h:178
gdcm::Attribute::SetValues
void SetValues(const ArrayType *array, unsigned int numel=VMType)
Definition gdcmAttribute.h:173
gdcm::Attribute::Set
void Set(DataSet const &ds)
Definition gdcmAttribute.h:226
gdcm::Attribute::SetFromDataElement
void SetFromDataElement(DataElement const &de)
Definition gdcmAttribute.h:206
gdcm::Attribute::GetAsDataElement
DataElement GetAsDataElement() const
Definition gdcmAttribute.h:183
gdcm::Attribute::GetNumberOfValues
unsigned int GetNumberOfValues() const
Definition gdcmAttribute.h:111
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::DataSet::Remove
SizeType Remove(const Tag &tag)
Completely remove a dataelement from the dataset.
Definition gdcmDataSet.h:172
gdcm::DataSet::Replace
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
gdcm::FileExplicitFilter
FileExplicitFilter class.
Definition gdcmFileExplicitFilter.h:39
gdcm::FileExplicitFilter::SetFile
void SetFile(const File &f)
Set/Get File.
Definition gdcmFileExplicitFilter.h:60
gdcm::FileExplicitFilter::Change
bool Change()
Set FMI Transfer Syntax.
gdcm::FileMetaInformation
Class to represent a File Meta Information.
Definition gdcmFileMetaInformation.h:41
gdcm::FileMetaInformation::SetDataSetTransferSyntax
void SetDataSetTransferSyntax(const TransferSyntax &ts)
gdcm::FileMetaInformation::Replace
void Replace(const DataElement &de)
Definition gdcmFileMetaInformation.h:68
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::File::GetHeader
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
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::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::TransferSyntax
Class to manipulate Transfer Syntax.
Definition gdcmTransferSyntax.h:40
gdcm::TransferSyntax::GetTSString
static const char * GetTSString(TSType ts)
gdcm::TransferSyntax::ExplicitVRLittleEndian
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
gdcm::TransferSyntax::ImplicitVRLittleEndian
@ ImplicitVRLittleEndian
Definition gdcmTransferSyntax.h:62
gdcm::Writer
Writer ala DOM (Document Object Model).
Definition gdcmWriter.h:49
gdcm::Writer::Write
virtual bool Write()
Main function to tell the writer to write.
gdcm::Writer::SetFile
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header).
Definition gdcmWriter.h:66
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmAttribute.h
gdcm_assert
#define gdcm_assert(cond)
Definition gdcmException.h:104
gdcmFileExplicitFilter.h
gdcmReader.h
gdcmSequenceOfItems.h
gdcmWriter.h