7 #include "PlusConfigure.h" 10 #include "igsioCommon.h" 20 for (
unsigned int i = 0;
i < this->
Size();
i++ )
22 delete this->observations.at(
i );
24 this->observations.clear();
31 return this->observations.size();
38 return this->observations.at( index );
45 this->observations.push_back( newObservation );
52 this->observations.clear();
59 for (
unsigned int i = 0;
i < this->
Size();
i++ )
70 const double CONDITION_THRESHOLD = 1e-3;
81 for (
unsigned int i = 0;
i < this->
Size();
i++ )
89 vnl_svd<double>* SVDMatrix =
new vnl_svd<double>( *DataMatrix, 0.0 );
90 if ( SVDMatrix->well_condition() < CONDITION_THRESHOLD )
92 LOG_ERROR(
"Failed - spherical registration is ill-conditioned!" );
95 return new vnl_matrix<double>( SVDMatrix->V() * SVDMatrix->U().transpose() );
108 toMatrix->put(
i, 0, toCentroid.at(
i ) );
109 fromMatrix->put(
i, 0, fromCentroid.at(
i ) );
112 return new vnl_matrix<double>( ( *toMatrix ) - ( *rotation ) * ( *fromMatrix ) );
119 std::vector<double> centroid = this->CalculateCentroid();
120 vnl_matrix<double>* cov = this->CovarianceMatrix( centroid );
125 vnl_symmetric_eigensystem_compute( *cov, eigenvectors, eigenvalues );
133 Eigenvector1.at( 0 ) = eigenvectors.get( 0, 0 );
134 Eigenvector1.at( 1 ) = eigenvectors.get( 1, 0 );
135 Eigenvector1.at( 2 ) = eigenvectors.get( 2, 0 );
137 Eigenvector2.at( 0 ) = eigenvectors.get( 0, 1 );
138 Eigenvector2.at( 1 ) = eigenvectors.get( 1, 1 );
139 Eigenvector2.at( 2 ) = eigenvectors.get( 2, 1 );
141 Eigenvector3.at( 0 ) = eigenvectors.get( 0, 2 );
142 Eigenvector3.at( 1 ) = eigenvectors.get( 1, 2 );
143 Eigenvector3.at( 2 ) = eigenvectors.get( 2, 2 );
148 return new Point( centroid );
168 const int THRESHOLD = 1e-3;
174 double meanDistance = 0;
178 for (
unsigned int i = 0;
i < this->
Size();
i++ )
180 distances.at(
i ) =
object->DistanceToVector( this->
GetObservation(
i )->Observation );
181 meanDistance = meanDistance +
distances.at(
i );
184 meanDistance = meanDistance / this->
Size();
185 stdev = stdev / this->
Size();
186 stdev = sqrt( stdev - meanDistance * meanDistance );
189 std::vector<PointObservation*> newObservations;
190 for (
unsigned int i = 0;
i < this->
Size();
i++ )
192 if ( distances.at(
i ) < filterWidth * stdev ||
distances.at(
i ) < THRESHOLD )
198 if ( newObservations.size() < this->
Size() )
207 this->observations = newObservations;
217 std::ostringstream xmlstring;
219 for (
unsigned int i = 0;
i < this->
Size();
i++ )
224 return xmlstring.str();
232 this->observations = std::vector<PointObservation*>( 0, blankObservation );
234 int numElements = element->GetNumberOfNestedElements();
236 for (
int i = 0;
i < numElements;
i++ )
238 vtkXMLDataElement* noteElement = element->GetNestedElement(
i );
250 vnl_matrix<double>* PointObservationBuffer::CovarianceMatrix( std::vector<double> centroid )
258 for (
unsigned int i = 0;
i < this->
Size();
i++ )
274 for (
unsigned int i = 0;
i < this->
Size();
i++ )
279 cov->put( d1, d2, cov->get( d1, d2 ) / this->
Size() );
289 std::vector<double> PointObservationBuffer::CalculateCentroid()
293 for (
unsigned int i = 0;
i < this->
Size();
i++ )
302 centroid.at( d ) = centroid.at( d ) / this->
Size();
313 int TEST_INTERVAL = 21;
316 int currStartIndex, currEndIndex;
317 bool collecting =
false;
319 std::vector<PointObservationBuffer*> linearObjects;
322 for (
unsigned int i = 0;
i < this->
Size() - TEST_INTERVAL;
i++ )
326 for (
unsigned int j =
i; j <
i + TEST_INTERVAL; j++ )
332 std::vector<double> centroid = tempBuffer->CalculateCentroid();
333 vnl_matrix<double>* cov = tempBuffer->CovarianceMatrix( centroid );
338 vnl_symmetric_eigensystem_compute( *cov, eigenvectors, eigenvalues );
341 std::vector<double> eigen( 3, 0.0 );
342 eigen.at( 0 ) = eigenvalues.get( 0 );
343 eigen.at( 1 ) = eigenvalues.get( 1 );
344 eigen.at( 2 ) = eigenvalues.get( 2 );
352 if ( eigenvalues.get( 0 ) < extractionThreshold )
362 if ( currEndIndex - currStartIndex < collectionFrames )
372 std::vector<int> dofInterval;
373 dofInterval.push_back( currStartIndex );
374 for (
int j = currStartIndex; j < currEndIndex; j++ )
378 dofInterval.push_back( j );
381 dofInterval.push_back( currEndIndex );
384 int maxIntervalLength = 0;
385 int maxIntervalIndex = 0;
386 for (
unsigned int j = 0; j < dofInterval.size() - 1; j++ )
388 if ( dofInterval.at( j + 1 ) - dofInterval.at( j ) > maxIntervalLength )
390 maxIntervalLength = dofInterval.at( j + 1 ) - dofInterval.at( j );
391 maxIntervalIndex = j;
396 if ( maxIntervalLength < collectionFrames )
403 for (
int j = dofInterval.at( maxIntervalIndex ); j < dofInterval.at( maxIntervalIndex + 1 ); j++ )
408 linearObjects.push_back( foundBuffer );
414 return linearObjects;
void Translate(std::vector< double > translation)
void Filter(LinearObject *object, int filterWidth)
static std::vector< double > Add(std::vector< double > v1, std::vector< double > v2)
vnl_matrix< double > * SphericalRegistration(PointObservationBuffer *fromPoints)
LinearObject * LeastSquaresLinearObject(int dof)
std::string ToXMLString() const
void AddObservation(PointObservation *newObservation)
void FromXMLElement(vtkXMLDataElement *element)
std::vector< double > Observation
PointObservation * GetObservation(int index) const
std::string ToXMLString()
void Translate(std::vector< double > translation)
void FromXMLElement(vtkXMLDataElement *element)
PointObservationVector::size_type Size() const
std::vector< PointObservationBuffer * > ExtractLinearObjects(int collectionFrames, double extractionThreshold, std::vector< int > *dof)
vnl_matrix< double > * TranslationalRegistration(std::vector< double > toCentroid, std::vector< double > fromCentroid, vnl_matrix< double > *rotation)
~PointObservationBuffer()