Skip to content

Commit

Permalink
Implemented loading and saving of a sequence 3D points.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-cox-ci2cv committed Jul 18, 2013
1 parent b270709 commit 460b411
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/utils/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,63 @@ vectorise_points(const std::vector<cv::Point_<double> > &points)

return rv;
}

// Points 3D
std::vector<cv::Point3_<double> >
load_points3(const char *pathname)
{
int i,n;
char str[256];
char c;

std::fstream file(pathname, std::ios::in);
if (!file.is_open())
throw make_runtime_error("Unable to open pts file '%s'", pathname);

file.exceptions(std::ios::badbit | std::ios::failbit);

// read the number of points
while (!file.eof()) {
file >> str;
if (strncmp(str,"n_points:",9) == 0)
break;
}

file >> n;

std::vector<cv::Point3_<double> > shape(n);

// find the opening {
while (!file.eof()) {
file >> c;
if(c == '{')
break;
}

for (i = 0; i < n; i++)
file >> shape[i].x >> shape[i].y >> shape[i].z;

file.close();

return shape;
}

void
save_points3(const char *pathname, const std::vector<cv::Point3_<double> > &points)
{
std::fstream file(pathname, std::ios::out);
if (!file.is_open())
throw make_runtime_error("Unable to open file '%s' for writing!", pathname);

file.exceptions(std::ios::badbit | std::ios::failbit);

file << "n_points: " << points.size() << "\n{\n";
for (size_t i = 0; i < points.size(); i++)
file << points[i].x << " " << points[i].y << " " << points[i].z << "\n";

file << "}\n";

file.close();

return;
}
3 changes: 3 additions & 0 deletions src/utils/points.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ typedef std::vector<cv::Point_<double> > PointVector;
std::vector<cv::Point_<double> > load_points(const char *pathname);
void save_points(const char *pathname, const std::vector<cv::Point_<double> > &points);

std::vector<cv::Point3_<double> > load_points3(const char *pathname);
void save_points3(const char *pathname, const std::vector<cv::Point3_<double> > &points);

cv::Mat_<double> vectorise_points(const std::vector<cv::Point_<double> > &points);

#endif

0 comments on commit 460b411

Please sign in to comment.