[Insight-developers] FEM Smart Pointers
Luis Ibanez
luis.ibanez at kitware.com
Mon Feb 21 18:08:59 EST 2011
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(Element2DC0LinearLineStress)
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
>
>
More information about the Insight-developers
mailing list