showLine implementation
This commit is contained in:
parent
b387581d4f
commit
26a6823207
modules/viz
@ -31,6 +31,8 @@ namespace temp_viz
|
|||||||
void showPointCloud(const String& id, InputArray cloud, const Color& color, const Affine3f& pose = Affine3f::Identity());
|
void showPointCloud(const String& id, InputArray cloud, const Color& color, const Affine3f& pose = Affine3f::Identity());
|
||||||
|
|
||||||
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud");
|
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, const String &id = "plane");
|
||||||
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
|
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
|
||||||
|
@ -137,9 +137,10 @@ public:
|
|||||||
// This tends to close the window...
|
// This tends to close the window...
|
||||||
interactor_->TerminateApp ();
|
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 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, 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 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 ¢er, float radius, const Color& color, const std::string &id = "sphere");
|
bool addSphere (const cv::Point3f ¢er, float radius, const Color& color, const std::string &id = "sphere");
|
||||||
|
@ -78,6 +78,11 @@ void temp_viz::Viz3d::spinOnce (int time, bool force_redraw)
|
|||||||
impl_->spinOnce(time, 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)
|
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, const String &id)
|
||||||
{
|
{
|
||||||
return impl_->addPlane(coefficients, id);
|
return impl_->addPlane(coefficients, id);
|
||||||
|
@ -266,33 +266,42 @@ bool temp_viz::Viz3d::VizImpl::addPointCloudNormals (const cv::Mat &cloud, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
void temp_viz::Viz3d::VizImpl::showLine (const String &id, const cv::Point3f &pt1, const cv::Point3f &pt2, const Color &color)
|
||||||
bool temp_viz::Viz3d::VizImpl::addLine (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, const std::string &id)
|
|
||||||
{
|
{
|
||||||
// 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);
|
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
|
||||||
if (am_it != shape_actor_map_->end ())
|
bool exists = (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;
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
vtkSmartPointer<vtkDataSet> data = createLine (pt1, pt2);
|
// Create an Actor
|
||||||
|
vtkSmartPointer<vtkLODActor> actor;
|
||||||
|
createActorFromVTKDataSet (data, actor);
|
||||||
|
actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||||
|
|
||||||
// Create an Actor
|
Color c = vtkcolor(color);
|
||||||
vtkSmartPointer<vtkLODActor> actor;
|
actor->GetProperty ()->SetColor (c.val);
|
||||||
createActorFromVTKDataSet (data, actor);
|
actor->GetMapper ()->ScalarVisibilityOff ();
|
||||||
actor->GetProperty ()->SetRepresentationToWireframe ();
|
renderer_->AddActor (actor);
|
||||||
|
|
||||||
Color c = vtkcolor(color);
|
// Save the pointer/ID pair to the global actor map
|
||||||
actor->GetProperty ()->SetColor (c.val);
|
(*shape_actor_map_)[id] = actor;
|
||||||
actor->GetMapper ()->ScalarVisibilityOff ();
|
}
|
||||||
renderer_->AddActor (actor);
|
|
||||||
|
|
||||||
// Save the pointer/ID pair to the global actor map
|
|
||||||
(*shape_actor_map_)[id] = actor;
|
|
||||||
return (true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool temp_viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id)
|
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 ());
|
CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
|
||||||
|
@ -86,18 +86,19 @@ TEST(Viz_viz3d, accuracy)
|
|||||||
float pos_x = 0.0f;
|
float pos_x = 0.0f;
|
||||||
float pos_y = 0.0f;
|
float pos_y = 0.0f;
|
||||||
float pos_z = 0.0f;
|
float pos_z = 0.0f;
|
||||||
temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("d:/horse.ply");
|
// temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("d:/horse.ply");
|
||||||
v.addPolygonMesh(*mesh, "pq");
|
// v.addPolygonMesh(*mesh, "pq");
|
||||||
|
|
||||||
int col_blue = 0;
|
int col_blue = 0;
|
||||||
int col_green = 0;
|
int col_green = 0;
|
||||||
int col_red = 0;
|
int col_red = 0;
|
||||||
|
|
||||||
while(!v.wasStopped())
|
while(!v.wasStopped())
|
||||||
{
|
{
|
||||||
// Creating new point cloud with id cloud1
|
// Creating new point cloud with id cloud1
|
||||||
cv::Affine3f cloudPosition(angle_x, angle_y, angle_z, cv::Vec3f(pos_x, pos_y, pos_z));
|
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.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_x += 0.1f;
|
||||||
angle_y -= 0.1f;
|
angle_y -= 0.1f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user