ITK/Examples/Statistics/ListSample: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(Wrong signature for main.) |
Daviddoria (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
ListSample is the class to hold "measurements" for most of the Statistics classes. | |||
==ListSample.cxx== | ==ListSample.cxx== | ||
<source lang="cpp"> | <source lang="cpp"> | ||
Line 6: | Line 8: | ||
int main(int, char *[]) | int main(int, char *[]) | ||
{ | { | ||
typedef itk::Vector< float, 3 > MeasurementVectorType ; | typedef itk::Vector<float, 3> MeasurementVectorType; | ||
typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType ; | typedef itk::Statistics::ListSample<MeasurementVectorType> SampleType; | ||
SampleType::Pointer sample = SampleType::New() ; | SampleType::Pointer sample = SampleType::New(); | ||
MeasurementVectorType mv ; | MeasurementVectorType mv; | ||
mv[0] = 1.0 ; | mv[0] = 1.0; | ||
mv[1] = 2.0 ; | mv[1] = 2.0; | ||
mv[2] = 4.0 ; | mv[2] = 4.0; | ||
sample->PushBack(mv) ; | sample->PushBack(mv); | ||
sample->Resize(3) ; | sample->Resize(3); | ||
mv[0] = 2.0 ; | mv[0] = 2.0; | ||
mv[1] = 4.0 ; | mv[1] = 4.0; | ||
mv[2] = 5.0 ; | mv[2] = 5.0; | ||
sample->SetMeasurementVector(1, mv) ; | sample->SetMeasurementVector(1, mv); | ||
mv[0] = 3.0 ; | mv[0] = 3.0; | ||
mv[1] = 8.0 ; | mv[1] = 8.0; | ||
mv[2] = 6.0 ; | mv[2] = 6.0; | ||
sample->SetMeasurementVector(2, mv) ; | sample->SetMeasurementVector(2, mv); | ||
for ( unsigned long i = 0 ; i < sample->Size() ; ++i ) | for(unsigned long i = 0; i < sample->Size(); ++i) | ||
{ | { | ||
std::cout << "id = " << i | std::cout << "id = " << i | ||
Line 36: | Line 38: | ||
<< "\t frequency = " | << "\t frequency = " | ||
<< sample->GetFrequency(i) | << sample->GetFrequency(i) | ||
<< std::endl ; | << std::endl; | ||
} | } | ||
SampleType::Iterator iter = sample->Begin() ; | SampleType::Iterator iter = sample->Begin(); | ||
while( iter != sample->End() ) | while( iter != sample->End() ) | ||
Line 48: | Line 50: | ||
<< "\t frequency = " | << "\t frequency = " | ||
<< iter.GetFrequency() | << iter.GetFrequency() | ||
<< std::endl ; | << std::endl; | ||
++iter ; | ++iter; | ||
} | } | ||
std::cout << "Size = " << sample->Size() << std::endl ; | std::cout << "Size = " << sample->Size() << std::endl; | ||
std::cout << "Total frequency = " | std::cout << "Total frequency = " | ||
<< sample->GetTotalFrequency() << std::endl ; | << sample->GetTotalFrequency() << std::endl; | ||
return EXIT_SUCCESS; | return EXIT_SUCCESS; |
Revision as of 17:49, 20 November 2010
ListSample is the class to hold "measurements" for most of the Statistics classes.
ListSample.cxx
<source lang="cpp">
- include "itkListSample.h"
- include "itkVector.h"
int main(int, char *[]) {
typedef itk::Vector<float, 3> MeasurementVectorType; typedef itk::Statistics::ListSample<MeasurementVectorType> SampleType; SampleType::Pointer sample = SampleType::New();
MeasurementVectorType mv; mv[0] = 1.0; mv[1] = 2.0; mv[2] = 4.0;
sample->PushBack(mv);
sample->Resize(3);
mv[0] = 2.0; mv[1] = 4.0; mv[2] = 5.0; sample->SetMeasurementVector(1, mv);
mv[0] = 3.0; mv[1] = 8.0; mv[2] = 6.0; sample->SetMeasurementVector(2, mv);
for(unsigned long i = 0; i < sample->Size(); ++i) { std::cout << "id = " << i << "\t measurement vector = " << sample->GetMeasurementVector(i) << "\t frequency = " << sample->GetFrequency(i) << std::endl; }
SampleType::Iterator iter = sample->Begin();
while( iter != sample->End() ) { std::cout << "id = " << iter.GetInstanceIdentifier() << "\t measurement vector = " << iter.GetMeasurementVector() << "\t frequency = " << iter.GetFrequency() << std::endl; ++iter; }
std::cout << "Size = " << sample->Size() << std::endl; std::cout << "Total frequency = " << sample->GetTotalFrequency() << std::endl; return EXIT_SUCCESS;
} </source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(ListSample)
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(ListSample ListSample.cxx) TARGET_LINK_LIBRARIES(ListSample ITKBasicFilters ITKCommon ITKIO)
</source>