/* Main method */ int main(int argc, char *argv[]){ /* Check to make sure there are no additional cmdline args */ if(argc < 2){ /* Initialize double values X and Y that will store the point values returned from the call to Data Points */ double X, Y; /* Initialize double values A and B that represent the coefficients for the line of best fit. Passed into ComputeCoefficients by refence */ double A, B; /* Variable that represents the index of the last element added to Payload */ /* Initialize variable for Dynamic Array */ DArray array; /* Call CreateDArray to initialize array */ CreateDArray(&array, INITIAL_CAPACITY); /* Gather X and Y values while DataPoints() supplies values */ while (DataPoints(&X, &Y)==1){ /* Initialize Data Object With values from DataPoints function */ Data point; point.X=X; point.Y=Y; /* Send the data point to the dynamic array */ PushToDArray(&array, &point); } /* Compute the coefficients (Stores both A AND B) */ ComputeCoefficients(&A, &B, &array); /* Produce Output */ printf("\nThe line is: Y = %f * X + %f\n", A, B); printf("There were %d points in the data set\n\n", array.EntriesUsed); /* Destroy the DArray object, and free associated memory */ DestroyDArray(&array); }else{ /* Improper amount of cmdline args entered, alert user */ printf("\nUsage: %s\n\n", argv[0]); } /* End Cmdline args check */ /* Return 1 to the operating system */ return 1; }
typename PointMatcher<T>::ErrorMinimizer::ErrorElements& PointMatcher<T>::ErrorMinimizer::getMatchedPoints( const DataPoints& requestedPts, const DataPoints& sourcePts, const Matches& matches, const OutlierWeights& outlierWeights) { typedef typename Matches::Ids Ids; typedef typename Matches::Dists Dists; assert(matches.ids.rows() > 0); assert(matches.ids.cols() > 0); assert(matches.ids.cols() == requestedPts.features.cols()); //nbpts assert(outlierWeights.rows() == matches.ids.rows()); // knn const int knn = outlierWeights.rows(); const int dimFeat = requestedPts.features.rows(); const int dimReqDesc = requestedPts.descriptors.rows(); // Count points with no weights const int pointsCount = (outlierWeights.array() != 0.0).count(); if (pointsCount == 0) throw ConvergenceError("ErrorMnimizer: no point to minimize"); Matrix keptFeat(dimFeat, pointsCount); Matrix keptDesc; if(dimReqDesc > 0) keptDesc = Matrix(dimReqDesc, pointsCount); Matches keptMatches (Dists(1,pointsCount), Ids(1, pointsCount)); OutlierWeights keptWeights(1, pointsCount); int j = 0; int rejectedMatchCount = 0; int rejectedPointCount = 0; bool matchExist = false; this->weightedPointUsedRatio = 0; for (int i = 0; i < requestedPts.features.cols(); ++i) //nb pts { matchExist = false; for(int k = 0; k < knn; k++) // knn { if (outlierWeights(k,i) != 0.0) { if(dimReqDesc > 0) keptDesc.col(j) = requestedPts.descriptors.col(i); keptFeat.col(j) = requestedPts.features.col(i); keptMatches.ids(0, j) = matches.ids(k, i); keptMatches.dists(0, j) = matches.dists(k, i); keptWeights(0,j) = outlierWeights(k,i); ++j; this->weightedPointUsedRatio += outlierWeights(k,i); matchExist = true; } else { rejectedMatchCount++; } } if(matchExist == false) { rejectedPointCount++; } } assert(j == pointsCount); this->pointUsedRatio = double(j)/double(knn*requestedPts.features.cols()); this->weightedPointUsedRatio /= double(knn*requestedPts.features.cols()); assert(dimFeat == sourcePts.features.rows()); const int dimSourDesc = sourcePts.descriptors.rows(); Matrix associatedFeat(dimFeat, pointsCount); Matrix associatedDesc; if(dimSourDesc > 0) associatedDesc = Matrix(dimSourDesc, pointsCount); // Fetch matched points for (int i = 0; i < pointsCount; ++i) { const int refIndex(keptMatches.ids(i)); associatedFeat.col(i) = sourcePts.features.block(0, refIndex, dimFeat, 1); if(dimSourDesc > 0) associatedDesc.col(i) = sourcePts.descriptors.block(0, refIndex, dimSourDesc, 1); } this->lastErrorElements.reading = DataPoints( keptFeat, requestedPts.featureLabels, keptDesc, requestedPts.descriptorLabels ); this->lastErrorElements.reference = DataPoints( associatedFeat, sourcePts.featureLabels, associatedDesc, sourcePts.descriptorLabels ); this->lastErrorElements.weights = keptWeights; this->lastErrorElements.matches = keptMatches; this->lastErrorElements.nbRejectedMatches = rejectedMatchCount; this->lastErrorElements.nbRejectedPoints = rejectedPointCount; return this->lastErrorElements; }