Skip to content

Commit

Permalink
PERF: point-based distances in neighborhood search
Browse files Browse the repository at this point in the history
  • Loading branch information
stnava committed Nov 25, 2023
1 parent fe3a0e3 commit d87f266
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions Utilities/itkSurfaceImageCurvature.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SurfaceImageCurvature final : public SurfaceCurvatureBase<TSurface, 3>
};
typedef Image<PixelType, itkGetStaticConstMacro(ImageDimension)> ImageType;
typedef typename ImageType::IndexType IndexType;
typedef typename ImageType::SpacingType SpacingType;
typedef typename ImageType::SizeType SizeType;
typedef ImageRegionIteratorWithIndex<ImageType> ImageIteratorType;
/** Image dimension. */
Expand Down Expand Up @@ -89,7 +90,7 @@ class SurfaceImageCurvature final : public SurfaceCurvatureBase<TSurface, 3>
* mean shift algorithm to find the best neighborhood.
*/
void
FindNeighborhood(unsigned int numMeanShifts = 0) override;
FindNeighborhood(unsigned int numMeanShifts = 2) override;

void
FindEuclideanNeighborhood(PointType p);
Expand Down Expand Up @@ -173,11 +174,10 @@ class SurfaceImageCurvature final : public SurfaceCurvatureBase<TSurface, 3>
CurvatureAtIndex(IndexType index)
{
PointType p;

for (unsigned int k = 0; k < ImageDimension; k++)
{
p[k] = (RealType)index[k];
}
this->m_FunctionImage->TransformIndexToPhysicalPoint(index, p);
// for (unsigned int k = 0; k < ImageDimension; k++) {
// p[k] = (RealType)index[k];
// }
this->SetOrigin(p);
this->EstimateFrameFromGradient(index);
this->FindNeighborhood();
Expand Down Expand Up @@ -272,6 +272,7 @@ class SurfaceImageCurvature final : public SurfaceCurvatureBase<TSurface, 3>
float m_Area;
RealType m_MinSpacing;
typename VectorInterpolatorType::Pointer m_Vinterp;
SpacingType m_Spacing;
};
} // namespace itk

Expand Down
13 changes: 7 additions & 6 deletions Utilities/itkSurfaceImageCurvature.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ SurfaceImageCurvature<TSurface>::FindEuclideanNeighborhood(
this->m_FunctionImage->TransformPhysicalPointToIndex(tempp, oindex);
for (unsigned int i = 0; i < ImageDimension; i++)
{
rad[i] = (long)(m_NeighborhoodRadius);
rad[i] = (long)(m_NeighborhoodRadius/this->m_Spacing[i]+0.5);
}
m_ti.SetLocation(oindex);
unsigned int temp = 0;
Expand All @@ -190,7 +190,8 @@ SurfaceImageCurvature<TSurface>::FindEuclideanNeighborhood(
isorigin = false;
}
p[k] = ipt[k];
RealType delt = static_cast<RealType>(oindex[k]) - static_cast<RealType>(index[k]);
RealType delt = rootpoint[k] - ipt[k];
// RealType delt = static_cast<RealType>(oindex[k]) - static_cast<RealType>(index[k]);
dist += delt * delt;
}
dist = sqrt(dist);
Expand Down Expand Up @@ -419,6 +420,7 @@ void
SurfaceImageCurvature<TSurface>::EstimateNormalsFromGradient()
{
typename ImageType::Pointer image = GetInput();
this->m_Spacing = image->GetSpacing();

if (!image)
{
Expand Down Expand Up @@ -748,9 +750,9 @@ SurfaceImageCurvature<TSurface>::ComputeSurfaceArea()

RealType area = 0.0;
this->m_TotalArea = 0.0;
unsigned long ct = 0;

ti.GoToBegin();
unsigned int ct = 0;
while (!ti.IsAtEnd())
{
index = ti.GetIndex();
Expand Down Expand Up @@ -847,6 +849,7 @@ SurfaceImageCurvature<TSurface>::IntegrateFunctionOverSurface(bool norm)

this->m_ti.Initialize(rad, this->GetInput(), image->GetLargestPossibleRegion());
this->m_ti2.Initialize(rad2, this->GetInput(), image->GetLargestPossibleRegion());
unsigned long ct = 0;

IndexType index;

Expand All @@ -855,8 +858,6 @@ SurfaceImageCurvature<TSurface>::IntegrateFunctionOverSurface(bool norm)
// std::cout << " begin integrate ";

ti.GoToBegin();
unsigned int ct = 0;
// std::cout << " begin while " << std::endl;
while (!ti.IsAtEnd())
{
index = ti.GetIndex();
Expand Down Expand Up @@ -1039,9 +1040,9 @@ SurfaceImageCurvature<TSurface>::ComputeFrameOverDomain(unsigned int which)
unsigned int ct = 1;
unsigned long ct2 = 0;
RealType kpix = 0;

double thresh = 0.0;


ti.GoToBegin();
while (!ti.IsAtEnd())
{
Expand Down

0 comments on commit d87f266

Please sign in to comment.