[Insight-users] Mean Curvature Calculation in Level Set
Luis Ibanez
luis . ibanez at kitware . com
Mon, 24 Nov 2003 08:10:27 -0500
Hi Sah,
1) Yes, this is legal C++,
and what is better, it is accepted by all
the compilers in the ITK dashboard.
2) Yes, you can still declare the function
as in MyFuntion(int,int, int c).
in this case the compiler only verify
the type of the arguments not the variable-name
assigned to them.
In a function declaration, the names assigned to
function arguments is irrelevant to the compiler.
They are only used as documentation for human readers.
Regards,
Luis
------------------
Sah Rayman wrote:
> Lius,
>
> Thanks for the help. Yeah, the design of the level set
> function are elegant for me. When I want my own
> curvature function, I can just write it in my own
> class and everything is set.
>
> But I still have this C++ question. In my
> understanding, the situation could be simplified like
> this:
>
> int MyFunction(int a, int b, int c);
>
> int main() {
> MyFunction( 1, 2, 3);
> return 0;
> }
>
> int MyFunction(int , int, int c) {
> // don't use a and b
> return c;
> }
>
> So, you mean:
> 1. MyFunction(int , int, int c) is leagal in C++?
> 2. Despite the declaration "int MyFunction(int a, int
> b, int c)" and calling "MyFunction( 1, 2, 3)" we can
> still implement MyFunction like this?
>
> Thanks.
> Sah
>
>
> --- Luis Ibanez <luis . ibanez at kitware . com> wrote:
>
>>Hi Sah,
>>
>>The ITK macro itkNotUsed() is converted to an
>>empty string in most platforms.
>>
>>A method declaration/implementation like
>>
>> myMethod( int & itkNotUsed( x ) )
>>
>>is equivalent to
>>
>> myMethod( int & )
>>
>>this second expression is valid C++.
>>
>>---
>>
>>ComputeMeanCurvature() is a virtual function.
>>
>>This means that it is declared in a base class
>>and it is intended to be overloaded in derived
>>classes. When a method in the base class
>>(itkLevelSet) invokes "ComputeMeanCurvature()"
>>the execution will be delegated to the
>>"ComputeMeanCurvature()" as defined in the derived
>>class.
>>
>>The elegance of the LevelSetFunction implementation
>>that Josh did in ITK is that the generic
>>computations
>>are done at the top level in the base class, while
>>the details of the specific type of partial
>>differential
>>equation to use are defined in the derived classes.
>>
>>In this way the common functionality is factorized
>>in a central location at the level of the base class
>>and the code doesn't have to be repeated for every
>>new
>>level set approach. If you look at the derived
>>classes
>>of SegmentationLevelSet:
>>
>
>
http://www . itk . org/Insight/Doxygen/html/classitk_1_1SegmentationLevelSetFunction . html
>
>>it becomes more evident how poweful this
>>implementation is.
>>
>>
>>Note for example that all this 8 different levelSet
>>methods
>>are sharing the basic math and only changing the way
>>in
>>which the actual components of the equation are
>>computed.
>>
>>
>>You may want to look at a good C++ textbook and
>>check on the description of polymorphism, virtual
>>functions, and abstract functions. That will give
>>you
>>a better background for following the implementation
>>in ITK.
>>
>>
>>Please let us know if you have further questions.
>>
>>
>>Regards,
>>
>>
>> Luis
>>
>>
>>-------------------
>>Sah Rayman wrote:
>>
>>>Hi Lius,
>>>
>>>Sorry I am still confused.
>>>
>>>First, I also don't use "neighborhood" or "offset"
>>
>>in
>>
>>>my implementation.
>>>
>>>If we take a look at itkLevelSetFunction.txx, Line
>>>158-162:
>>>template <class TImageType>
>>>typename
>>
>>LevelSetFunction<TImageType>::ScalarValueType
>>
>>LevelSetFunction<TImageType>::ComputeMeanCurvature(
>>
>>> const NeighborhoodType
>>
>>&itkNotUsed(neighborhood),
>>
>>> const FloatOffsetType &itkNotUsed(offset),
>>>GlobalDataStruct *gd)
>>>{ ...
>>>}
>>>
>>>Does it euqavalent to the following? (just replace
>>>itkNotUsed(AnyThing) to EMPTY)
>>>template <class TImageType>
>>>typename
>>
>>LevelSetFunction<TImageType>::ScalarValueType
>>
>>LevelSetFunction<TImageType>::ComputeMeanCurvature(
>>
>>> const NeighborhoodType &,
>>> const FloatOffsetType &, GlobalDataStruct *gd)
>>>{ ...
>>>}
>>>
>>>Is the above a leagal C++ function implementation?
>>>
>>>Also, in the same file, function
>>>ComputeCurvatureTerm() calls
>>>ComputeMeanCurvature(neighborhood, offset, gd),
>>
>>then
>>
>>>where is it implemented?
>>>
>>>I never used those "advanced" C++ feature before.
>>>Sorry if it's a naive qustions.
>>>
>>>Thanks.
>>>Sah
>>>
>>>
>>>--- Luis Ibanez <luis . ibanez at kitware . com> wrote:
>>>
>>>
>>>>Hi Sah,
>>>>
>>>>The itkNotUse() macro was used to make some
>>>>compilers
>>>>happy and avoid the warnings for "non used
>>>
>>variable"
>>
>>>>in the cases where the arguments were not used in
>>>
>>a
>>
>>>>method. This typically happens in virtual
>>>
>>functions
>>
>>>>when in order to respect the API, a number of
>>>>arguments
>>>>are present, but not used inside the method.
>>>>
>>>>If your implementation of the method is actually
>>>>using
>>>>the argument of the function, you must then remove
>>>>the
>>>>itkNotUse() macro, otherwise the argument is not
>>>>declared
>>>>at all.
>>>>
>>>>The reason why there are not errors in
>>>>itkLevelSetFunction
>>>>is because the argument "neighbor" is not used in
>>>>the
>>>>ComputeMeanCurvature, so the signature could be as
>>>>well:
>>>>
>>>> ComputeMeanCurvature( const NeighborhoodType &
>>>
>>)
>>
>>>>
>>>>
>>>>Regards,
>>>>
>>>>
>>>>
>>>> Luis
>>>>
>>>>
>>>>
>>>
>>>
> --------------------------------------------------------
>
>>>>Sah Rayman wrote:
>>>>
>>>>
>>>>>A related question: when I implement
>>>>>ComputeMeanCurvature() in class
>>>>
>>>>MyLevelSetFunction.txx
>>>>
>>>>
>>>>>If I write as
>>>>>ComputeMeanCurvature(const NeighborhoodType
>>>>>&itkNotUse(neighborhood), ...)
>>>>>as it is in itkLevelSetFunction.txx, I will get a
>>>>
>>>>lot
>>>>
>>>>
>>>>>syntax error (VC 6.0), and I have to write as
>>>>>ComputeMeanCurvature(const NeighborhoodType
>>>>>&neighborhood, ...)
>>>>>
>>>>>I checked the definition of itkNotUse(x), it is a
>>>>>macro to nothing, (#define itkNotUse(x) )
>>>>>
>>>>>Then how come in itkLevelSetFunction.txx there is
>>>>
>>>>no
>>>>
>>>>
>>>>>syntax error?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>--- Sah Rayman <sahrayman at yahoo . com> wrote:
>>>>>
>>>>>
>>>>>
>>>>>>I am now 90% sure that this is a bug of
>>>>>>itkLevelSetFunction.txx as of ITK 1.4.
>>>>>>
>>>>>>I rewrote my ComputeMeanCurvature() in my
>>>>>
>>derived
>>
>>>>>>LevelSetFunction class, and the segmentation
>>>>>
>>>>result
>>>>
>>>>
>>>>>>makes more sense.
>>>>>>
>>>>>>My fix:
>>>>>>move line "curvature_term -= gd->m_dx[i] *
>>>>>>gd->m_dx[j]
>>>>>>* gd->m_dxy[i][j];"
>>>>>>to the inner of "if( j!=i) ".
>>>>>>
>>>>>>Author of the file, if you're interested in more
>>>>>>details, please write to me.
>>>>>>
>>>>>>
>>>>>>
>>>>>>--- Sah Rayman <sahrayman at yahoo . com> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I am looking at function:
>>>>>>>
>>>>>>>template <class TImageType>
>>>>>>>typename
>>>>>>>LevelSetFunction<TImageType>::ScalarValueType
>>>>>>>
>>>>>>
>>>>LevelSetFunction<TImageType>::ComputeMeanCurvature()
>>>>
>>>>>>>in itkLevelSetFunction.txx, line 158 (ITK 1.4)
>>>>>>>
>>>>>>>When I compared that to Sethian's "Level Set
>>>>>>
>>>>>>Methods
>>>>>>
>>>>>>
>>>>>>
>>>>>>>and Fast Marching Methods", 2ndEd, pp. 70, Eq.
>>>>>>
>>>>>>6.36,
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I
>>>>>>>found that the C++ implementation contain some
>>>>>>
>>>>>>extra
>>>>>>
>>>>>>
>>>>>>
>>>>>>>terms in nominator:
>>>>>>>
>>>>>>
>>>>>>-dx[0]*dx[0]*dxy[0][0]-dx[1]*dx[1]*dxy[1][1]-...
>>>>>>
>>>>>>>Can someone tell me what are these additional
>>>>>>
>>>>>>terms
>>>>>>
>>>>>>
>>>>>>
>>>>>>>for? Is the result still mean curvature? Any
>>>>>>>reference
>>>>>>>for that?
>>>>>>>
>>>>>>>
>>>>>>>__________________________________
>>>>>>>Do you Yahoo!?
>>>>>>>Protect your identity with Yahoo! Mail
>>>>>>
>>>>>>AddressGuard
>>>>>>
>>>>>>
>>>>>>
>>>>>>>http://antispam . yahoo . com/whatsnewfree
>>>>>>>_______________________________________________
>>>>>>>Insight-users mailing list
>>>>>>>Insight-users at itk . org
>>>>>>
>>>>>>http://www . itk . org/mailman/listinfo/insight-users
>>>>>>
>>>>>>
>>>>>>__________________________________
>>>>>>Do you Yahoo!?
>>>>>>Protect your identity with Yahoo! Mail
>>>>>
>>>>AddressGuard
>>>>
>>>>
>>>>>>http://antispam . yahoo . com/whatsnewfree
>>>>>>_______________________________________________
>>>>>>Insight-users mailing list
>>>>>>Insight-users at itk . org
>>>>>
>>>>>http://www . itk . org/mailman/listinfo/insight-users
>>>>>
>>>>>
>>>>>
>>>>>__________________________________
>>>>>Do you Yahoo!?
>>>>>Protect your identity with Yahoo! Mail
>>>>
>>>>AddressGuard
>>>>
>>>>
>>>>>http://antispam . yahoo . com/whatsnewfree
>>>>>_______________________________________________
>>>>>Insight-users mailing list
>>>>>Insight-users at itk . org
>>>>>http://www . itk . org/mailman/listinfo/insight-users
>>>>>
>>>>
>>>>
>>>>
>>>>_______________________________________________
>>>>Insight-users mailing list
>>>>Insight-users at itk . org
>>>>http://www . itk . org/mailman/listinfo/insight-users
>>>
>>>
>>>
>>>__________________________________
>>>Do you Yahoo!?
>>>Free Pop-Up Blocker - Get it now
>>>http://companion . yahoo . com/
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk . org
>>>http://www . itk . org/mailman/listinfo/insight-users
>>>
>>
>>
>>
>
>
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion . yahoo . com/
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>