⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itkweightedcentroidkdtreegenerator.txx

📁 DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.
💻 TXX
字号:
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkWeightedCentroidKdTreeGenerator.txx,v $
  Language:  C++
  Date:      $Date: 2008-04-29 23:00:08 $
  Version:   $Revision: 1.9 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkWeightedCentroidKdTreeGenerator_txx
#define __itkWeightedCentroidKdTreeGenerator_txx

namespace itk{
namespace Statistics{

template< class TSample >
WeightedCentroidKdTreeGenerator< TSample >
::WeightedCentroidKdTreeGenerator()
{
}

template< class TSample >
void
WeightedCentroidKdTreeGenerator< TSample >
::PrintSelf(std::ostream& os, Indent indent) const
{
  Superclass::PrintSelf(os,indent);
}

template< class TSample >
inline typename WeightedCentroidKdTreeGenerator< TSample >::KdTreeNodeType*
WeightedCentroidKdTreeGenerator< TSample >
::GenerateNonterminalNode(unsigned int beginIndex,
                          unsigned int endIndex,
                          MeasurementVectorType &lowerBound,
                          MeasurementVectorType &upperBound,
                          unsigned int level)
{
  MeasurementType dimensionLowerBound;
  MeasurementType dimensionUpperBound;
  MeasurementType partitionValue;
  unsigned int partitionDimension = 0;
  unsigned int i;
  unsigned int j;
  MeasurementType spread;
  MeasurementType maxSpread;
  unsigned int medianIndex;

  SubsamplePointer subsample = this->GetSubsample();

  // Sanity check. Verify that the subsample has measurement vectors of the
  // same length as the sample generated by the tree.
  if( this->GetMeasurementVectorSize() != subsample->GetMeasurementVectorSize() )
    {
    itkExceptionMacro( << "Measurement Vector Length mismatch" );
    }

  // calculates the weighted centroid which is the vector sum
  // of all the associated instances.
  typename KdTreeNodeType::CentroidType weightedCentroid;
  MeasurementVectorTraits::SetLength( weightedCentroid, this->GetMeasurementVectorSize() );
  MeasurementVectorType tempVector;
  weightedCentroid.Fill(NumericTraits< MeasurementType >::Zero);

  for (i = beginIndex; i < endIndex; i++)
    {
    tempVector = subsample->GetMeasurementVectorByIndex(i);
    for(j = 0; j < this->GetMeasurementVectorSize(); j++)
      {
      weightedCentroid[j] += tempVector[j];
      }
    }

  // find most widely spread dimension
  FindSampleBoundAndMean< SubsampleType >(this->GetSubsample(),
                                          beginIndex, endIndex,
                                          m_TempLowerBound, m_TempUpperBound,
                                          m_TempMean);

  maxSpread = NumericTraits< MeasurementType >::NonpositiveMin();
  for (i = 0; i < this->GetMeasurementVectorSize(); i++)
    {
    spread = m_TempUpperBound[i] - m_TempLowerBound[i];
    if (spread >= maxSpread)
      {
      maxSpread = spread;
      partitionDimension = i;
      }
    }


  medianIndex = (endIndex - beginIndex) / 2;

  //
  // Find the medial element by using the QuickSelect algorithm
  // based on its description on the Wikipedia:
  // http://en.wikipedia.org/wiki/Selection_algorithm
  //
  partitionValue =
    QuickSelect< SubsampleType >(this->GetSubsample(),
                                 partitionDimension,
                                 beginIndex, endIndex, 
                                 medianIndex,
                                 m_TempMean[partitionDimension]);
             
  medianIndex += beginIndex;

  // save bounds for cutting dimension
  dimensionLowerBound = lowerBound[partitionDimension];
  dimensionUpperBound = upperBound[partitionDimension];

  upperBound[partitionDimension] = partitionValue;
  const unsigned int beginLeftIndex = beginIndex;
  const unsigned int endLeftIndex   = medianIndex;
  KdTreeNodeType* left = GenerateTreeLoop(beginLeftIndex, endLeftIndex, lowerBound, upperBound, level + 1);
  upperBound[partitionDimension] = dimensionUpperBound;

  lowerBound[partitionDimension] = partitionValue;
  const unsigned int beginRightIndex = medianIndex+1;
  const unsigned int endRighIndex    = endIndex;
  KdTreeNodeType* right = GenerateTreeLoop(beginRightIndex, endRighIndex, lowerBound, upperBound, level + 1);
  lowerBound[partitionDimension] = dimensionLowerBound;


  typedef KdTreeWeightedCentroidNonterminalNode< TSample >  KdTreeNonterminalNodeType;

  KdTreeNonterminalNodeType * nonTerminalNode =
    new KdTreeNonterminalNodeType( partitionDimension, 
                                   partitionValue,
                                   left, right,
                                   weightedCentroid,
                                   endIndex - beginIndex);

  nonTerminalNode->AddInstanceIdentifier(
    subsample->GetInstanceIdentifier( medianIndex ) );

  return nonTerminalNode;
}

} // end of namespace Statistics
} // end of namespace itk

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -