From 50d87778c2fa30b6c5e9d0c0c4aa54f0453fb066 Mon Sep 17 00:00:00 2001 From: mholden8 Date: Mon, 12 May 2014 13:51:53 -0400 Subject: [PATCH] Re #21: Shows what type of linear object is being collected in automatic collection mode. --- MRML/vtkLORPositionBuffer.cxx | 36 +++++++++++++------ Utilities/LORConstants.cxx | 24 +++++++++++++ Utilities/LORConstants.h | 1 + .../Resources/UI/qSlicerLORAutomaticWidget.ui | 15 +++++++- Widgets/qSlicerLORAutomaticWidget.cxx | 6 ++++ 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/MRML/vtkLORPositionBuffer.cxx b/MRML/vtkLORPositionBuffer.cxx index 1ef9839..7f106f2 100644 --- a/MRML/vtkLORPositionBuffer.cxx +++ b/MRML/vtkLORPositionBuffer.cxx @@ -149,28 +149,33 @@ ::CovarianceMatrix( std::vector centroid ) vnl_matrix *cov = new vnl_matrix( vtkLORPosition::SIZE, vtkLORPosition::SIZE ); cov->fill( 0.0 ); + if ( this->Size() == 0 ) + { + return cov; + } + // Subtract the mean from each Position for ( int i = 0; i < this->Size(); i++ ) { vtkSmartPointer< vtkLORPosition > newPosition = vtkSmartPointer< vtkLORPosition >::New(); std::vector newPositionVector = LORMath::Subtract( this->GetPosition(i)->GetPositionVector(), centroid ); newPosition->SetPositionVector( newPositionVector ); - zeroMeanBuffer->AddPosition( newPosition ); + zeroMeanBuffer->AddPosition( newPosition ); } // Pick two dimensions, and find their covariance for ( int d1 = 0; d1 < vtkLORPosition::SIZE; d1++ ) { for ( int d2 = 0; d2 < vtkLORPosition::SIZE; d2++ ) - { - // Iterate over all times - for ( int i = 0; i < zeroMeanBuffer->Size(); i++ ) { - cov->put( d1, d2, cov->get( d1, d2 ) + zeroMeanBuffer->GetPosition(i)->GetPositionVector().at(d1) * zeroMeanBuffer->GetPosition(i)->GetPositionVector().at(d2) ); + // Iterate over all times + for ( int i = 0; i < zeroMeanBuffer->Size(); i++ ) + { + cov->put( d1, d2, cov->get( d1, d2 ) + zeroMeanBuffer->GetPosition(i)->GetPositionVector().at(d1) * zeroMeanBuffer->GetPosition(i)->GetPositionVector().at(d2) ); + } + // Divide by the number of records + cov->put( d1, d2, cov->get( d1, d2 ) / zeroMeanBuffer->Size() ); } - // Divide by the number of records - cov->put( d1, d2, cov->get( d1, d2 ) / zeroMeanBuffer->Size() ); - } } return cov; @@ -183,13 +188,19 @@ ::CalculateCentroid() { // Calculate the centroid std::vector centroid( vtkLORPosition::SIZE, 0.0 ); + if ( this->Size() == 0 ) + { + return centroid; + } + for ( int i = 0; i < this->Size(); i++ ) { for ( int d = 0; d < vtkLORPosition::SIZE; d++ ) - { + { centroid.at(d) = centroid.at(d) + this->GetPosition(i)->GetPositionVector().at(d); - } + } } + for ( int d = 0; d < vtkLORPosition::SIZE; d++ ) { centroid.at(d) = centroid.at(d) / this->Size(); @@ -202,6 +213,11 @@ ::CalculateCentroid() int vtkLORPositionBuffer ::GetDOF( double noiseThreshold ) { + if ( this->Size() == 0 ) + { + return LORConstants::UNKNOWN_DOF; + } + std::vector centroid = this->CalculateCentroid(); vnl_matrix* cov = this->CovarianceMatrix( centroid ); diff --git a/Utilities/LORConstants.cxx b/Utilities/LORConstants.cxx index aed4641..bb0ae92 100644 --- a/Utilities/LORConstants.cxx +++ b/Utilities/LORConstants.cxx @@ -85,6 +85,30 @@ ::DOF_TO_COLLECT_STATE( int d ) } +std::string LORConstants +::DOF_TO_STRING( int d ) +{ + if ( d == REFERENCE_DOF ) + { + return REFERENCE_STRING; + } + if ( d == POINT_DOF ) + { + return POINT_STRING; + } + if ( d == LINE_DOF ) + { + return LINE_STRING; + } + if ( d == PLANE_DOF ) + { + return PLANE_STRING; + } + + return ""; +} + + int LORConstants ::DOF_TO_SPINNER_INDEX( int d ) { diff --git a/Utilities/LORConstants.h b/Utilities/LORConstants.h index fbf0261..bbceb95 100644 --- a/Utilities/LORConstants.h +++ b/Utilities/LORConstants.h @@ -57,6 +57,7 @@ namespace LORConstants // Conversion functions VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT int COLLECT_STATE_TO_DOF( std::string s ); VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT std::string DOF_TO_COLLECT_STATE( int d ); + VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT std::string DOF_TO_STRING( int d ); VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT int DOF_TO_SPINNER_INDEX( int d ); VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT int SPINNER_INDEX_TO_DOF( int i ); VTK_SLICER_LINEAROBJECTREGISTRATION_MODULE_UTILITIES_EXPORT int STRING_TO_SPINNER_INDEX( std::string s ); diff --git a/Widgets/Resources/UI/qSlicerLORAutomaticWidget.ui b/Widgets/Resources/UI/qSlicerLORAutomaticWidget.ui index f04be9d..4e52952 100644 --- a/Widgets/Resources/UI/qSlicerLORAutomaticWidget.ui +++ b/Widgets/Resources/UI/qSlicerLORAutomaticWidget.ui @@ -19,7 +19,7 @@ Form - + 0 @@ -42,6 +42,19 @@ + + + + + 0 + 0 + + + + () + + + diff --git a/Widgets/qSlicerLORAutomaticWidget.cxx b/Widgets/qSlicerLORAutomaticWidget.cxx index 8462959..411b204 100644 --- a/Widgets/qSlicerLORAutomaticWidget.cxx +++ b/Widgets/qSlicerLORAutomaticWidget.cxx @@ -177,4 +177,10 @@ ::updateWidget() } d->CollectProgressBar->setValue( int( 100 * this->LORNode->GetActivePositionBuffer()->Size() / this->LORNode->GetMinimumCollectionPositions() ) ); + + std::stringstream typeString; + typeString << "("; + typeString << LORConstants::DOF_TO_STRING( this->LORNode->GetActivePositionBuffer()->GetDOF( this->LORNode->GetNoiseThreshold() ) ); + typeString << ")"; + d->LinearObjectTypeLabel->setText( QString::fromStdString( typeString.str() ) ); }