[Insight-developers] PathIterator choosing a step size that is too small?

Matt McCormick matt.mccormick at kitware.com
Sat Feb 25 14:22:12 EST 2012


Hi Ho,

Very good detective work, and thanks for the report.  Here are a
couple of patches that should hopefully fix the problem:

  http://review.source.kitware.com/#/c/4395/
  http://review.source.kitware.com/#/c/4396/

To try them, go to the second patch, paste the git checkout line into
your ITK git clone of the source tree, then rebuild ITK.  Please let
us know if it does the job.

This is based off the documentation here:

  http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm

But it looks like he is updating his blog sometime soon here:

  http://randomascii.wordpress.com/category/floating-point/

So, we will see if the FloatAlmostEquals can use some improvement
based on that post.

-----

Unrelated-- you may want to consider using:

  http://www.itk.org/Doxygen/html/classitk_1_1CompensatedSummation.html

Instead of 'double' for your sum_of_vesselness_values variable.


Hope this helps,
Matt



On Fri, Feb 24, 2012 at 11:29 PM, Ho Cheung <hocheung20 at gmail.com> wrote:
> It seems that using == to compare FP numbers for equality leads to disaster.
> Also, compounding the problem is that FP behavior apparently deviates
> between RelWithDebInfo and Debug modes. The previous message that I sent was
> run in RelWithDebInfo.
>
> Here is the Debug call stack:
>
>      msvcp90d.dll!std::_Debug_message(const wchar_t *
> message=0x000000014159a668, const wchar_t * file=0x000000014159a6b0,
> unsigned int line=779)  Line 24    C++
>
> MicrogliaRegionTracer.exe!std::vector<itk::ContinuousIndex<double,3>,std::allocator<itk::ContinuousIndex<double,3>
>> >::operator[](unsigned __int64 _Pos=2)  Line 780    C++
>      MicrogliaRegionTracer.exe!itk::VectorContainer<unsigned
> int,itk::ContinuousIndex<double,3> >::ElementAt(unsigned int id=2)  Line
> 41    C++  <--Array location 2 doesn't exist because I only have 2 vertices
>
> MicrogliaRegionTracer.exe!itk::PolyLineParametricPath<3>::Evaluate(const
> double & input=0.99999999999999989)  Line 44 + 0x37 bytes    C++
>      MicrogliaRegionTracer.exe!itk::ParametricPath<3>::EvaluateToIndex(const
> double & input=0.99999999999999989)  Line 43 + 0x26 bytes    C++
>      MicrogliaRegionTracer.exe!itk::ParametricPath<3>::IncrementInput(double
> & input=0.79999999999999993)  Line 87 + 0x44 bytes    C++
>
> MicrogliaRegionTracer.exe!itk::PathConstIterator<itk::Image<float,3>,itk::PolyLineParametricPath<3>
>>::operator++()  Line 94 + 0x49 bytes    C++
>      ...
>
> RelWithDebInfo:
>
> ...
>      MicrogliaRegionTracer.exe!itk::VectorContainer<unsigned
> int,itk::ContinuousIndex<double,3> >::ElementAt(unsigned int id=1309149262)
> Line 40 + 0x2e bytes    C++
>
> MicrogliaRegionTracer.exe!itk::PolyLineParametricPath<3>::Evaluate(const
> double & input=)  Line 44 + 0x1d bytes    C++
>      MicrogliaRegionTracer.exe!itk::ParametricPath<3>::EvaluateToIndex(const
> double & input=9.851802020072e-315#DEN)  Line 43 + 0x11 bytes    C++
>      MicrogliaRegionTracer.exe!itk::ParametricPath<3>::IncrementInput(double
> & input=2.658998863925e-314#DEN)  Line 87 + 0x2b bytes    C++ <-- DEN
> results in ElementAt getting a nonsensical number
>
> MicrogliaRegionTracer.exe!itk::PathConstIterator<itk::Image<float,3>,itk::PolyLineParametricPath<3>
>>::operator++()  Line 94 + 0x19 bytes    C++
> ...
>
> The problem is that at itkPolyLineParametricPath.hxx:38: The input was
> 0.99999999999999989, which should have become 1 and then the check at 38 to
> see if this was the last vertex should have gone through and returned the
> last index.
>
> I believe the fix is to change line 38 from this:
>
>   if ( input  >=  InputType(m_VertexList->Size() - 1) )
>
> to this:
>
>   if ( input  >=  InputType(m_VertexList->Size() - 1) - 0.0001 ) //Basically
> 0.0001 needs to be significantly bigger than the precision of InputType not
> so large to introduce errors into the check.
>
>
> Regards,
>
>
> Ho Cheung
> Research Assistant
> Bio-Image Analytics Lab - University of Houston
> hocheung20 at gmail.com
> Cell: (832) 215-6347
>
>
> On Fri, Feb 24, 2012 at 3:59 PM, Ho Cheung <hocheung20 at gmail.com> wrote:
>>
>> Hi all,
>>
>> I am currently using a PathIterator to try to move through some pixels
>> between two indices. My iterator moves successfully most of the way and then
>> decides to calculate a very small step size, so small that it becomes #DEN
>> when I look at it with the debugger.
>> Here is the relevant code:
>>
>>
>>     ImageType::IndexType node1 = cell->critical_points_queue[node_from];
>>     ImageType::IndexType node2 = cell->critical_points_queue[node_to];
>>
>>     typedef itk::PolyLineParametricPath< 3 > PathType;
>>     PathType::Pointer path = PathType::New();
>>     path->Initialize();
>>
>>     std::cout << "Start Index: " << start_index << " " << "End Index: " <<
>> end_index << std::endl;
>>
>>     path->AddVertex(node1);
>>     path->AddVertex(node2);
>>
>>     typedef itk::PathConstIterator< VesselnessImageType, PathType >
>> PathIteratorType;
>>     PathIteratorType path_iter(cell->vesselness_image, path);
>>
>>     double sum_of_vesselness_values = 0;
>>     itk::uint64_t path_length = 0;
>>     path_iter.GoToBegin();
>>     while (!path_iter.IsAtEnd())
>>     {
>>         std::cout << "Path iterator position: " <<
>> path_iter.GetPathPosition() << std::endl;
>>         std::cout << "Path iterator index: " << path_iter.GetIndex() <<
>> std::endl;
>>         sum_of_vesselness_values += path_iter.Get();
>>         ++path_iter;
>>     }
>>
>>
>> And here is the relevant output:
>>
>> Start Index: [100, 81, 17] End Index: [114, 81, 17]
>> Path iterator position: 0
>> Path iterator index: [100, 81, 17]
>> Path iterator position: 0.0888889
>> Path iterator index: [101, 81, 17]
>> Path iterator position: 0.177778
>> Path iterator index: [102, 81, 17]
>> Path iterator position: 0.237037
>> Path iterator index: [103, 81, 17]
>> Path iterator position: 0.296296
>> Path iterator index: [104, 81, 17]
>> Path iterator position: 0.385185
>> Path iterator index: [105, 81, 17]
>> Path iterator position: 0.444444
>> Path iterator index: [106, 81, 17]
>> Path iterator position: 0.533333
>> Path iterator index: [107, 81, 17]
>> Path iterator position: 0.592593
>> Path iterator index: [108, 81, 17]
>> Path iterator position: 0.651852
>> Path iterator index: [109, 81, 17]
>> Path iterator position: 0.740741
>> Path iterator index: [110, 81, 17]
>> Path iterator position: 0.8
>> Path iterator index: [111, 81, 17]
>> <Crash>
>>
>> Thanks,
>>
>> Ho Cheung
>> Research Assistant
>> Bio-Image Analytics Lab - University of Houston
>> hocheung20 at gmail.com
>> Cell: (832) 215-6347
>
>
>
> _______________________________________________
> 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