Skip to content

Commit

Permalink
Re #21: Shows what type of linear object is being collected in automa…
Browse files Browse the repository at this point in the history
…tic collection mode.
  • Loading branch information
matthewsholden committed May 12, 2014
1 parent f4a9fc0 commit 50d8777
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
36 changes: 26 additions & 10 deletions MRML/vtkLORPositionBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,33 @@ ::CovarianceMatrix( std::vector<double> centroid )
vnl_matrix<double> *cov = new vnl_matrix<double>( 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<double> 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;
Expand All @@ -183,13 +188,19 @@ ::CalculateCentroid()
{
// Calculate the centroid
std::vector<double> 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();
Expand All @@ -202,6 +213,11 @@ ::CalculateCentroid()
int vtkLORPositionBuffer
::GetDOF( double noiseThreshold )
{
if ( this->Size() == 0 )
{
return LORConstants::UNKNOWN_DOF;
}

std::vector<double> centroid = this->CalculateCentroid();
vnl_matrix<double>* cov = this->CovarianceMatrix( centroid );

Expand Down
24 changes: 24 additions & 0 deletions Utilities/LORConstants.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions Utilities/LORConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
15 changes: 14 additions & 1 deletion Widgets/Resources/UI/qSlicerLORAutomaticWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
Expand All @@ -42,6 +42,19 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LinearObjectTypeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>()</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
6 changes: 6 additions & 0 deletions Widgets/qSlicerLORAutomaticWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}

0 comments on commit 50d8777

Please sign in to comment.