[Insight-developers] FEM Smart Pointers
M Stauffer (V)
mstauff at verizon.net
Thu Mar 17 20:36:50 EDT 2011
You can use the new itkSimpleNewMacro() to define only New(). Then
you're free to overload CreateAnother(). See itkMacro.h.
Cheers,
Michael
>-----Original Message-----
>From: insight-developers-bounces at itk.org
>[mailto:insight-developers-bounces at itk.org] On Behalf Of
>Magnotta, Vincent A
>Sent: Thursday, March 17, 2011 3:46 PM
>To: Luis Ibanez; Magnotta, Vincent A
>Cc: insight-developers at itk.org
>Subject: Re: [Insight-developers] FEM Smart Pointers
>
>I have made the changes required to use ITK smart pointers for the FEM
>framework. I was going to clean up the code based on Luis's
>suggestions.
>He mentioned that itkNewMacro() will handle allowing the registered
>factories to run. However, since we need to define our own
>version of the
>CreateAnother() method, we cannot use this macro. Is this behavior of
>itkNewMacro() intentional?
>
>Vince
>
>
>
>On 2/21/11 6:08 PM, "Luis Ibanez" <luis.ibanez at kitware.com> wrote:
>
>>Hi Vincent,
>>
>>Thanks for fixing this code.
>>
>>The code:
>>
>>> virtual Baseclass::Pointer Clone() const \
>>> { Pointer o=New(); /*new Self(*this);*/ \
>>> o->SetReferenceCount(1); \
>>> return o.GetPointer(); }
>>
>>can just be:
>>
>>> virtual Baseclass::Pointer Clone() const \
>>> { Pointer o=New(); /*new Self(*this);*/ \
>>> return o.GetPointer(); }
>>
>>
>>Since now you are using "Pointer" (a smart pointer),
>>the manual increment of the reference count is no
>>longer needed.
>>
>>
>>Note however, that here, there is no real cloning.
>>The new object is not yet copying all the content
>>from the current one.
>>
>>
>>To be ITK compliant, these classes should
>>implement the "CreateAnother()" method,
>>as it is done for the Transforms.
>>
>>----
>>
>>
>>The second code snippet:
>>
>>> static Baseclass::Pointer NewB() \
>>> { return New().GetPointer(); } \
>>
>>
>>Looks good.
>>
>>Although, in retrospective, this method
>>should not be necessary.
>>
>>The NewB method is only called in lines 205-209,
>>
>>#define FEM_CLASS_REGISTER(thisClass) \
>> int thisClass::CLID(void) \
>> { static const int CLID_ =
>>FEMObjectFactory<thisClass::Baseclass>::Register( thisClass::NewB,
>>#thisClass); \
>> return CLID_; }
>>
>>
>>and this method itself should never be needed,
>>since the "itkNewMacro()" already takes care
>>of giving a chance to registered factories to run.
>>
>>
>>This macro is currently called at the end of the
>> .cxx files such as in:
>>
>>itkFEMElement2DC0LinearLineStress.cxx:FEM_CLASS_REGISTER(Eleme
>nt2DC0Linear
>>LineStress)
>>
>>and should not be necessary, once the itkNewMacro()
>>is used in these classes.
>>
>>
>>These factory registrations should be removed.
>>
>>
>> Luis
>>
>>
>>-----------------------------------
>>On Mon, Feb 21, 2011 at 11:07 AM, Magnotta, Vincent A
>><vincent-magnotta at uiowa.edu> wrote:
>>> I have started to make a pass through the FEM framework to
>enable Smart
>>> Pointers. This address a bug report 0011527. Based on the
>bugs that I am
>>> finding in the macros it appears that it has been a long
>time since this
>>> worked. What I did was to uncomment the the line
>>> in ITK/Code/Numerics/FEM/itkFEMMacro.h to enable smart
>pointers. After I
>>> added a couple of semicolons to get the basic syntax of the macros
>>>correct I
>>> get several compiler errors related to incorrect casting. To resolve
>>>several
>>> of the problems, I had to add the GetPointer() to method
>several smart
>>> pointer variables. For example, lines 168-171 of itkFEMMacro.h were
>>> modified to
>>> virtual Baseclass::Pointer Clone() const \
>>> { Pointer o=New(); /*new Self(*this);*/ \
>>> o->SetReferenceCount(1); \
>>> return o.GetPointer(); } \
>>> and lines 175-176 were modified to
>>> static Baseclass::Pointer NewB() \
>>> { return New().GetPointer(); } \
>>> I have made several other changes to the CXX files that are similar.
>>>Before
>>> I go any further, I was wondering if this is the right
>think to do or if
>>> there is a better way to solve this problem.
>>> Thanks,
>>> Vince
>>>
>>> --
>>> Associate Professor
>>> Department of Radiology
>>> 0453-D JCP
>>> 200 Hawkins Drive
>>> Iowa City, IA 52242
>>> E-mail: vincent-magnotta at uiowa.edu
>>> Phone: 319-356-8255 Fax: 319-353-6275
>>> Website: http://www.healthcare.uiowa.edu/Radiology
>>>
>>>
>>> ________________________________
>>> Notice: This UI Health Care e-mail (including attachments)
>is covered
>>>by the
>>> Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is
>>>confidential
>>> and may be legally privileged. If you are not the intended
>recipient,
>>>you
>>> are hereby notified that any retention, dissemination,
>distribution, or
>>> copying of this communication is strictly prohibited.
>Please reply to
>>>the
>>> sender that you have received the message in error, then delete it.
>>>Thank
>>> you.
>>> ________________________________
>>> _______________________________________________
>>> 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://kitware.com/products/protraining.html
>>>
>>> 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://www.itk.org/mailman/listinfo/insight-developers
>>>
>>>
>
>
>
>________________________________
>Notice: This UI Health Care e-mail (including attachments) is
>covered by the Electronic Communications Privacy Act, 18
>U.S.C. 2510-2521, is confidential and may be legally
>privileged. If you are not the intended recipient, you are
>hereby notified that any retention, dissemination,
>distribution, or copying of this communication is strictly
>prohibited. Please reply to the sender that you have received
>the message in error, then delete it. Thank you.
>________________________________
>_______________________________________________
>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://kitware.com/products/protraining.html
>
>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://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list