showLine implementation

This commit is contained in:
ozantonkal 2013-06-21 12:48:27 +02:00
parent b387581d4f
commit 26a6823207
5 changed files with 42 additions and 24 deletions

View File

@ -32,6 +32,8 @@ namespace temp_viz
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud");
void showLine(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color);
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");

View File

@ -138,8 +138,9 @@ public:
interactor_->TerminateApp ();
}
void showLine (const String &id, const cv::Point3f &pt1, const cv::Point3f &pt2, const Color &color);
bool addPolygon(const cv::Mat& cloud, const Color& color, const std::string &id = "polygon");
bool addLine (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, const std::string &id = "line");
bool addArrow (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, bool display_length, const std::string &id = "arrow");
bool addArrow (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color_line, const Color& color_text, const std::string &id = "arrow");
bool addSphere (const cv::Point3f &center, float radius, const Color& color, const std::string &id = "sphere");

View File

@ -78,6 +78,11 @@ void temp_viz::Viz3d::spinOnce (int time, bool force_redraw)
impl_->spinOnce(time, force_redraw);
}
void temp_viz::Viz3d::showLine(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color)
{
impl_->showLine(id, pt1, pt2, color);
}
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, const String &id)
{
return impl_->addPlane(coefficients, id);

View File

@ -266,33 +266,42 @@ bool temp_viz::Viz3d::VizImpl::addPointCloudNormals (const cv::Mat &cloud, const
}
////////////////////////////////////////////////////////////////////////////////////////////
bool temp_viz::Viz3d::VizImpl::addLine (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, const std::string &id)
void temp_viz::Viz3d::VizImpl::showLine (const String &id, const cv::Point3f &pt1, const cv::Point3f &pt2, const Color &color)
{
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
// Check if this Id already exists
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
if (am_it != shape_actor_map_->end ())
return std::cout << "[addLine] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl, false;
bool exists = (am_it != shape_actor_map_->end());
vtkSmartPointer<vtkDataSet> data = createLine (pt1, pt2);
// If it exists just update
if (exists)
{
vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast (am_it->second);
reinterpret_cast<vtkDataSetMapper*>(actor->GetMapper ())->SetInput(createLine(pt1,pt2));
Color c = vtkcolor(color);
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create new line
vtkSmartPointer<vtkDataSet> data = createLine (pt1, pt2);
// Create an Actor
vtkSmartPointer<vtkLODActor> actor;
createActorFromVTKDataSet (data, actor);
actor->GetProperty ()->SetRepresentationToWireframe ();
// Create an Actor
vtkSmartPointer<vtkLODActor> actor;
createActorFromVTKDataSet (data, actor);
actor->GetProperty ()->SetRepresentationToWireframe ();
Color c = vtkcolor(color);
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
renderer_->AddActor (actor);
Color c = vtkcolor(color);
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
renderer_->AddActor (actor);
// Save the pointer/ID pair to the global actor map
(*shape_actor_map_)[id] = actor;
return (true);
// Save the pointer/ID pair to the global actor map
(*shape_actor_map_)[id] = actor;
}
}
bool temp_viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id)
{
CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());

View File

@ -86,8 +86,8 @@ TEST(Viz_viz3d, accuracy)
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");
// temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("d:/horse.ply");
// v.addPolygonMesh(*mesh, "pq");
int col_blue = 0;
int col_green = 0;
@ -98,6 +98,7 @@ TEST(Viz_viz3d, accuracy)
// 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, temp_viz::Color(col_blue, col_green, col_red), cloudPosition);
v.showLine("line1", cv::Point3f(0.0,0.0,0.0), cv::Point3f(pos_x, pos_y, pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
angle_x += 0.1f;
angle_y -= 0.1f;