Commit 59acccfa authored by Anatoly Baksheev's avatar Anatoly Baksheev

Merge pull request #4 from ozantonkal/implementing_addPointCloud

showPointCloud initial implementation together with test
parents ace0933b d11d07aa
......@@ -26,22 +26,15 @@ namespace temp_viz
void setBackgroundColor(const Color& color = Color::black());
void addCoordinateSystem(double scale, const Affine3f& t, const String &id = "coordinate");
void addPointCloud(const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
void showPointCloud(const std::string& id, cv::InputArray cloud, cv::InputArray colors, const cv::Affine3f& pose = cv::Affine3f::Identity());
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud");
bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane");
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
bool removeCoordinateSystem (const String &id = "coordinate");
bool updatePointCloud (const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
bool addPolygonMesh (const Mesh3d& mesh, const String &id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const String &id = "polygon");
......
......@@ -96,8 +96,14 @@ public:
bool addText3D (const std::string &text, const cv::Point3f &position, const Color& color, double textScale = 1.0, const std::string &id = "");
bool addPointCloudNormals (const cv::Mat &cloud, const cv::Mat& normals, int level = 100, float scale = 0.02f, const std::string &id = "cloud");
void addPointCloud(const cv::Mat& cloud, const cv::Mat& colors, const std::string& id = "cloud", const cv::Mat& mask = cv::Mat());
bool updatePointCloud (const cv::Mat& cloud, const cv::Mat& colors, const std::string& id = "cloud", const cv::Mat& mask = cv::Mat());
/** \brief If the id exists, updates the point cloud; otherwise, adds a new point cloud to the scene
* \param[in] id a variable to identify the point cloud
* \param[in] cloud cloud input in x,y,z coordinates
* \param[in] colors color input in the same order of the points or single uniform color
* \param[in] pose transform to be applied on the point cloud
*/
void showPointCloud(const std::string& id, cv::InputArray cloud, cv::InputArray colors, const cv::Affine3f& pose = cv::Affine3f::Identity());
bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const std::string &id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const std::string &id = "polygon");
......
......@@ -23,9 +23,9 @@ void temp_viz::Viz3d::addCoordinateSystem(double scale, const Affine3f& t, const
impl_->addCoordinateSystem(scale, t, id);
}
void temp_viz::Viz3d::addPointCloud(const Mat& cloud, const Mat& colors, const String& id, const Mat& mask)
void temp_viz::Viz3d::showPointCloud(const std::string& id, cv::InputArray cloud, cv::InputArray colors, const cv::Affine3f& pose)
{
impl_->addPointCloud(cloud, colors, id, mask);
impl_->showPointCloud(id, cloud, colors, pose);
}
bool temp_viz::Viz3d::addPointCloudNormals (const Mat &cloud, const Mat& normals, int level, float scale, const String& id)
......@@ -33,11 +33,6 @@ bool temp_viz::Viz3d::addPointCloudNormals (const Mat &cloud, const Mat& normals
return impl_->addPointCloudNormals(cloud, normals, level, scale, id);
}
bool temp_viz::Viz3d::updatePointCloud(const Mat& cloud, const Mat& colors, const String& id, const Mat& mask)
{
return impl_->updatePointCloud(cloud, colors, id, mask);
}
bool temp_viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String &id)
{
return impl_->addPolygonMesh(mesh, Mat(), id);
......
This diff is collapsed.
......@@ -78,56 +78,80 @@ TEST(Viz_viz3d, accuracy)
cv::Mat cloud = cvcloud_load();
cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0));
v.addPointCloud(cloud, colors);
cv::Mat normals(cloud.size(), CV_32FC3, cv::Scalar(0, 10, 0));
v.addPointCloudNormals(cloud, normals, 100, 0.02, "n");
temp_viz::ModelCoefficients mc;
mc.values.resize(4);
mc.values[0] = mc.values[1] = mc.values[2] = mc.values[3] = 1;
v.addPlane(mc);
float angle_x = 0.0f;
float angle_y = 0.0f;
float angle_z = 0.0f;
float pos_x = 0.0f;
float pos_y = 0.0f;
float pos_z = 0.0f;
temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("d:/horse.ply");
v.addPolygonMesh(*mesh, "pq");
v.spinOnce(1000, true);
v.removeCoordinateSystem();
for(int i = 0; i < mesh->cloud.cols; ++i)
mesh->cloud.ptr<cv::Point3f>()[i] += cv::Point3f(1, 1, 1);
v.updatePolygonMesh(*mesh, "pq");
for(int i = 0; i < mesh->cloud.cols; ++i)
mesh->cloud.ptr<cv::Point3f>()[i] -= cv::Point3f(2, 2, 2);
v.addPolylineFromPolygonMesh(*mesh);
v.addText("===Abd sadfljsadlk", 100, 100, cv::Scalar(255, 0, 0), 15);
for(int i = 0; i < cloud.cols; ++i)
cloud.ptr<cv::Point3f>()[i].x *=2;
colors.setTo(cv::Scalar(255, 0, 0));
v.addSphere(cv::Point3f(0, 0, 0), 0.3, temp_viz::Color::blue());
cv::Mat cvpoly(1, 5, CV_32FC3);
cv::Point3f* pdata = cvpoly.ptr<cv::Point3f>();
pdata[0] = cv::Point3f(0, 0, 0);
pdata[1] = cv::Point3f(0, 1, 1);
pdata[2] = cv::Point3f(3, 1, 2);
pdata[3] = cv::Point3f(0, 2, 4);
pdata[4] = cv::Point3f(7, 2, 3);
v.addPolygon(cvpoly, temp_viz::Color::white());
v.updatePointCloud(cloud, colors);
v.spin();
while(1)
{
// Creating new point cloud with id cloud1
cv::Affine3f cloudPosition(angle_x, angle_y, angle_z, cv::Vec3f(pos_x, pos_y, pos_z));
v.showPointCloud("cloud1", cloud, colors, cloudPosition);
angle_x += 0.1;
angle_y -= 0.1;
angle_z += 0.1;
pos_x = std::sin(angle_x);
pos_y = std::sin(angle_x);
pos_z = std::sin(angle_x);
v.spinOnce(1,true);
}
// cv::Mat normals(cloud.size(), CV_32FC3, cv::Scalar(0, 10, 0));
//
// v.addPointCloudNormals(cloud, normals, 100, 0.02, "n");
//
//
// temp_viz::ModelCoefficients mc;
// mc.values.resize(4);
// mc.values[0] = mc.values[1] = mc.values[2] = mc.values[3] = 1;
// v.addPlane(mc);
//
//
// temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("horse.ply");
// v.addPolygonMesh(*mesh, "pq");
//
// v.spinOnce(1000, true);
//
// v.removeCoordinateSystem();
//
// for(int i = 0; i < mesh->cloud.cols; ++i)
// mesh->cloud.ptr<cv::Point3f>()[i] += cv::Point3f(1, 1, 1);
//
// v.updatePolygonMesh(*mesh, "pq");
//
//
// for(int i = 0; i < mesh->cloud.cols; ++i)
// mesh->cloud.ptr<cv::Point3f>()[i] -= cv::Point3f(2, 2, 2);
// v.addPolylineFromPolygonMesh(*mesh);
//
//
// v.addText("===Abd sadfljsadlk", 100, 100, cv::Scalar(255, 0, 0), 15);
// for(int i = 0; i < cloud.cols; ++i)
// cloud.ptr<cv::Point3f>()[i].x *=2;
//
// colors.setTo(cv::Scalar(255, 0, 0));
//
// v.addSphere(cv::Point3f(0, 0, 0), 0.3, temp_viz::Color::blue());
//
// cv::Mat cvpoly(1, 5, CV_32FC3);
// cv::Point3f* pdata = cvpoly.ptr<cv::Point3f>();
// pdata[0] = cv::Point3f(0, 0, 0);
// pdata[1] = cv::Point3f(0, 1, 1);
// pdata[2] = cv::Point3f(3, 1, 2);
// pdata[3] = cv::Point3f(0, 2, 4);
// pdata[4] = cv::Point3f(7, 2, 3);
// v.addPolygon(cvpoly, temp_viz::Color::white());
//
// // Updating cloud1
// v.showPointCloud("cloud1", cloud, colors);
// v.spin();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment