[ITK-users] [ITK] STL methods and ITK
Bradley Lowekamp
blowekamp at mail.nih.gov
Wed Jan 28 10:47:50 EST 2015
Hello Emily,
This has recently been fixed in ITK:
https://github.com/InsightSoftwareConsortium/ITK/commit/240b5568b641bb995ba01cbc338ddadffd95d5fa
The return for GetTransformList is now a constant pointer:
const TransformListType * GetTransformList()
Truthfully I am not sure why this method is returning a pointer and not a reference.
So the return should not be modified, which is your issue. The pointer is to an STL list managed by the reader.
The list is of itk::SmartPointers, so doing a copy should be light weight. So you should do something like:
TransformListType m_TransformList;
this->m_TransformList = *(reader->GetTranformList());
Brad
On Jan 28, 2015, at 10:36 AM, Hammond, Emily M <emily-hammond at uiowa.edu> wrote:
> Hello all,
>
> I am trying to wrap some functionality into a class. I am trying to write a function that reads in a transform file, however, I want it to take the list of transform pointers that it reads in and merge/insert them into an already existing list. Here is the relevant code with more details below it:
>
> #include "itkTransform.h"
> #include "itkTransformFileReader.h"
>
> public:
> typedef itk::TransformFileReaderTemplate< double >
> TransformReaderType;
> typedef TransformReaderType::TransformListType
> TransformListType;
>
> void ReadTransformFile( const char * transformFilename );
>
> protected:
> LandmarkAnalysis()
> {
> TransformListType * m_TransformList = 0;
> TransformListType * m_TransformListTemporary = 0;
> }
>
> private:
> TransformListType * m_TransformList;
> TransformListType * m_TransformListTemporary;
> };
>
>
> .hxx file
> void LandmarkAnalysis::ReadTransformFile( const char * transformFilename )
> {
> TransformReaderType::Pointer reader = TransformReaderType::New();
> reader->SetFileName( transformFilename );
> reader->Update();
>
> // put output into member variable
> m_TransformListTemporary = reader->GetTransformList();
> //(*m_TransformList).merge( *m_TransformListTemporary );
> // print out to prove that it was completed
> TransformListType::const_iterator tempIt = m_TransformListTemporary->begin();
> TransformListType::iterator it = m_TransformList->begin(); ***CODE BREAKS AT THIS LINE***
>
> for(; tempIt !=m_TransformListTemporary->end(); tempIt++)
> {
> std::cout << (*tempIt) << std::endl;
> (*m_TransformList).insert(it, (*tempIt));
> }
>
> std::cout << transformFilename << " has been read in." << std::endl;
> return;
> }
>
> Here is my problem: I know that at the base level both m_TransformListTemporary and m_TransformList are lists of transform pointers. However, I cannot use any of the c++ stl list member functions such as merge or insert (I get runtime errors.) Is there some fundamental concept that I do not understand with how ITK interacts with the STL? In addition, through debugging, the line shown above instantiating an iterator for m_TransformList breaks the code, even though the previous line (which, to my understanding, does the same thing, but with a different list) works fine.
>
> Any help would be very much appreciated.
>
> Emily Hammond
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150128/8b93f8a9/attachment-0001.html>
More information about the Insight-users
mailing list