mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
showCube implementation
This commit is contained in:
parent
93fe2f6e4d
commit
55683e7b3b
@ -35,6 +35,7 @@ namespace temp_viz
|
||||
void showLine(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color);
|
||||
void showPlane(const String &id, const Vec4f &coefs, const Color &color);
|
||||
void showPlane(const String &id, const Vec4f &coefs, const Point3f &pt, const Color &color);
|
||||
void showCube(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");
|
||||
|
@ -141,6 +141,7 @@ public:
|
||||
void showLine (const String &id, const cv::Point3f &pt1, const cv::Point3f &pt2, const Color &color);
|
||||
void showPlane (const String &id, const cv::Vec4f &coefs, const Color &color);
|
||||
void showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt, const Color &color);
|
||||
void showCube (const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color);
|
||||
|
||||
bool addPolygon(const cv::Mat& cloud, const Color& color, const std::string &id = "polygon");
|
||||
bool addArrow (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, bool display_length, const std::string &id = "arrow");
|
||||
|
@ -93,6 +93,11 @@ void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs, const Poin
|
||||
impl_->showPlane(id, coefs, pt, color);
|
||||
}
|
||||
|
||||
void temp_viz::Viz3d::showCube(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color)
|
||||
{
|
||||
impl_->showCube(id, pt1, pt2, color);
|
||||
}
|
||||
|
||||
bool temp_viz::Viz3d::removeCoordinateSystem (const String &id)
|
||||
{
|
||||
return impl_->removeCoordinateSystem(id);
|
||||
|
@ -372,6 +372,41 @@ void temp_viz::Viz3d::VizImpl::showPlane (const String &id ,const cv::Vec4f &coe
|
||||
}
|
||||
}
|
||||
|
||||
void temp_viz::Viz3d::VizImpl::showCube (const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color)
|
||||
{
|
||||
// Check if this Id already exists
|
||||
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
|
||||
bool exists = (am_it != shape_actor_map_->end());
|
||||
Color c = vtkcolor(color);
|
||||
// If it exists just update
|
||||
if (exists)
|
||||
{
|
||||
vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast (am_it->second);
|
||||
reinterpret_cast<vtkDataSetMapper*>(actor->GetMapper ())->SetInput(createCube(pt1, pt2));
|
||||
actor->GetProperty ()->SetColor (c.val);
|
||||
actor->GetMapper ()->ScalarVisibilityOff ();
|
||||
actor->Modified ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a plane
|
||||
vtkSmartPointer<vtkDataSet> data = createCube (pt1, pt2);
|
||||
|
||||
// Create an Actor
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
createActorFromVTKDataSet (data, actor);
|
||||
// actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||
actor->GetProperty ()->SetRepresentationToSurface ();
|
||||
actor->GetProperty ()->SetLighting (false);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool temp_viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id)
|
||||
{
|
||||
|
@ -103,6 +103,7 @@ TEST(Viz_viz3d, accuracy)
|
||||
v.showLine("line3", cv::Point3f(0.0,0.0,0.0), cv::Point3f(pos_x, 1.0f-pos_y, pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
|
||||
v.showLine("line4", cv::Point3f(0.0,0.0,0.0), cv::Point3f(pos_x, pos_y, 1.0f-pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
|
||||
v.showPlane("plane1", cv::Vec4f(pos_x*pos_y,pos_y,pos_z,pos_x+pos_y*pos_z), temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
|
||||
v.showCube("cube1", cv::Point3f(pos_x, pos_y, pos_z), cv::Point3f(pos_x+0.5, pos_y+0.5, pos_z+0.5), temp_viz::Color(255,150,50));
|
||||
|
||||
angle_x += 0.1f;
|
||||
angle_y -= 0.1f;
|
||||
|
Loading…
Reference in New Issue
Block a user