remove ModelCoefficients, remove showShape methods from viz3d

pull/1453/head
ozantonkal 12 years ago
parent 5bb95c4110
commit 4c3d1d583a
  1. 7
      modules/viz/include/opencv2/viz/types.hpp
  2. 25
      modules/viz/include/opencv2/viz/viz3d.hpp
  3. 47
      modules/viz/src/q/viz3d_impl.hpp
  4. 60
      modules/viz/src/viz3d.cpp
  5. 303
      modules/viz/src/viz3d_impl.cpp
  6. 65
      modules/viz/src/viz_main.cpp

@ -35,13 +35,6 @@ namespace temp_viz
using cv::DataDepth;
using cv::DataType;
struct CV_EXPORTS ModelCoefficients
{
std::vector<float> values;
};
class CV_EXPORTS Color : public Scalar
{
public:

@ -26,43 +26,18 @@ namespace temp_viz
void setBackgroundColor(const Color& color = Color::black());
void addCoordinateSystem(double scale, const Affine3f& t, const String& id = "coordinate");
void showPointCloud(const String& id, InputArray cloud, InputArray colors, 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");
void showLine(const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coeffs, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coeffs, const Point3f& pt, const Color& color = Color::white());
void showCube(const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color = Color::white());
void showCylinder(const String& id, const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int num_sides, const Color& color = Color::white());
void showCircle(const String& id, const Point3f& pt, double radius, const Color& color = Color::white());
void showSphere(const String& id, const Point3f& pt, double radius, const Color& color = Color::white());
void showArrow(const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color = Color::white());
Affine3f getShapePose(const String& id);
void setShapePose(const String& id, const Affine3f &pose);
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 addPolygonMesh (const Mesh3d& mesh, const String& id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const String& id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
bool addText (const String &text, int xpos, int ypos, const Color& color, int fontsize = 10, const String& id = "");
bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon");
bool addSphere (const Point3f &center, double radius, const Color& color, const String& id = "sphere");
void spin ();
void spinOnce (int time = 1, bool force_redraw = false);

@ -38,41 +38,6 @@ public:
void spin ();
void spinOnce (int time = 1, bool force_redraw = false);
/** \brief Adds 3D axes describing a coordinate system to screen at x, y, z, Roll,Pitch,Yaw
*
* \param[in] scale the scale of the axes (default: 1)
* \param[in] t transformation matrix
*
* RPY Angles
* Rotate the reference frame by the angle roll about axis x
* Rotate the reference frame by the angle pitch about axis y
* Rotate the reference frame by the angle yaw about axis z
*
* Description:
* Sets the orientation of the Prop3D. Orientation is specified as
* X,Y and Z rotations in that order, but they are performed as
* RotateZ, RotateX, and finally RotateY.
*
* All axies use right hand rule. x=red axis, y=green axis, z=blue axis
* z direction is point into the screen.
* z
* \
* \
* \
* -----------> x
* |
* |
* |
* |
* |
* |
* y
*/
void addCoordinateSystem (double scale, const Affine3f& t, const String& id = "coordinate");
/** \brief Removes a previously added 3D axes (coordinate system)
*/
bool removeCoordinateSystem (const String& id = "coordinate");
bool removePointCloud (const String& id = "cloud");
inline bool removePolygonMesh (const String& id = "polygon")
{
@ -138,18 +103,6 @@ public:
interactor_->TerminateApp ();
}
void showLine (const String& id, const Point3f& pt1, const 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 Point3f& pt, const Color& color);
void showCube (const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color);
void showCylinder (const String& id, const Point3f& pt_on_axis, const Point3f &axis_direction, double radius, int num_sides, const Color& color);
void showCircle (const String& id, const Point3f& pt, double radius, const Color& color);
void showSphere (const String& id, const Point3f& pt, double radius, const Color& color);
void showArrow (const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color);
Affine3f getShapePose (const String& id);
void setShapePose (const String& id, const Affine3f& pose);
bool addPolygon(const cv::Mat& cloud, const Color& color, const String& id = "polygon");
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color, bool display_length, const String& id = "arrow");
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color_line, const Color& color_text, const String& id = "arrow");

@ -17,11 +17,6 @@ void temp_viz::Viz3d::setBackgroundColor(const Color& color)
impl_->setBackgroundColor(color);
}
void temp_viz::Viz3d::addCoordinateSystem(double scale, const Affine3f& t, const String& id)
{
impl_->addCoordinateSystem(scale, t, id);
}
void temp_viz::Viz3d::showPointCloud(const String& id, InputArray cloud, InputArray colors, const Affine3f& pose)
{
impl_->showPointCloud(id, cloud, colors, pose);
@ -72,61 +67,6 @@ 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);
}
void temp_viz::Viz3d::showPlane(const String& id, const Vec4f &coeffs, const Color& color)
{
impl_->showPlane(id, coeffs, color);
}
void temp_viz::Viz3d::showPlane(const String& id, const Vec4f &coeffs, const Point3f& pt, const Color& color)
{
impl_->showPlane(id, coeffs, 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);
}
void temp_viz::Viz3d::showCylinder(const String& id, const Point3f& pt_on_axis, const Point3f &axis_direction, double radius, int num_sides, const Color& color)
{
impl_->showCylinder(id, pt_on_axis, axis_direction, radius, num_sides, color);
}
void temp_viz::Viz3d::showCircle(const String& id, const Point3f& pt, double radius, const Color& color)
{
impl_->showCircle(id, pt, radius, color);
}
void temp_viz::Viz3d::showSphere (const String& id, const Point3f& pt, double radius, const Color& color)
{
impl_->showSphere(id, pt, radius, color);
}
void temp_viz::Viz3d::showArrow (const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color)
{
impl_->showArrow(id,pt1,pt2,color);
}
cv::Affine3f temp_viz::Viz3d::getShapePose(const String& id)
{
return impl_->getShapePose(id);
}
void temp_viz::Viz3d::setShapePose(const String& id, const Affine3f &pose)
{
impl_->setShapePose(id, pose);
}
bool temp_viz::Viz3d::removeCoordinateSystem (const String& id)
{
return impl_->removeCoordinateSystem(id);
}
void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie)
{
impl_->registerKeyboardCallback(callback, cookie);

@ -379,309 +379,6 @@ bool temp_viz::Viz3d::VizImpl::addPointCloudNormals (const cv::Mat &cloud, const
return (true);
}
void temp_viz::Viz3d::VizImpl::showLine (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();
// 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 ();
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;
}
}
void temp_viz::Viz3d::VizImpl::showPlane (const String& id, const cv::Vec4f &coeffs, 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(createPlane(coeffs));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = createPlane (coeffs);
// 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;
}
}
void temp_viz::Viz3d::VizImpl::showPlane (const String& id ,const cv::Vec4f &coeffs, const Point3f& pt, 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(createPlane(coeffs, pt));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = createPlane (coeffs, pt);
// 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;
}
}
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;
}
}
void temp_viz::Viz3d::VizImpl::showCylinder (const String& id, const Point3f& pt_on_axis, const Point3f &axis_direction, double radius, int num_sides, 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(createCylinder(pt_on_axis, axis_direction, radius, num_sides));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = createCylinder(pt_on_axis, axis_direction, radius, num_sides);
// 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;
}
}
void temp_viz::Viz3d::VizImpl::showCircle (const String& id, const Point3f& pt, double radius, 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(create2DCircle(pt, radius));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = create2DCircle(pt, radius);
// 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;
}
}
void temp_viz::Viz3d::VizImpl::showSphere (const String& id, const Point3f& pt, double radius, 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(createSphere(pt, radius));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = createSphere(pt, radius);
// 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;
}
}
void temp_viz::Viz3d::VizImpl::showArrow (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(createArrow(pt1,pt2));
actor->GetProperty ()->SetColor (c.val);
actor->GetMapper ()->ScalarVisibilityOff ();
actor->Modified ();
}
else
{
// Create a plane
vtkSmartPointer<vtkDataSet> data = createArrow(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;
}
}
cv::Affine3f temp_viz::Viz3d::VizImpl::getShapePose (const String& id)
{
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
CV_Assert(am_it != shape_actor_map_->end());
vtkLODActor* actor = vtkLODActor::SafeDownCast(am_it->second);
return Affine3f(convertToMatx(actor->GetUserMatrix()));
}
void temp_viz::Viz3d::VizImpl::setShapePose (const String& id, const Affine3f &pose)
{
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
CV_Assert(am_it != shape_actor_map_->end());
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
actor->SetUserMatrix (matrix);
actor->Modified ();
}
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 ());

@ -139,71 +139,6 @@ void temp_viz::Viz3d::VizImpl::spinOnce (int time, bool force_redraw)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::Viz3d::VizImpl::addCoordinateSystem (double scale, const cv::Affine3f& affine, const std::string &id)
{
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New ();
axes->SetOrigin (0, 0, 0);
axes->SetScaleFactor (scale);
vtkSmartPointer<vtkFloatArray> axes_colors = vtkSmartPointer<vtkFloatArray>::New ();
axes_colors->Allocate (6);
axes_colors->InsertNextValue (0.0);
axes_colors->InsertNextValue (0.0);
axes_colors->InsertNextValue (0.5);
axes_colors->InsertNextValue (0.5);
axes_colors->InsertNextValue (1.0);
axes_colors->InsertNextValue (1.0);
vtkSmartPointer<vtkPolyData> axes_data = axes->GetOutput ();
axes_data->Update ();
axes_data->GetPointData ()->SetScalars (axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New ();
axes_tubes->SetInput (axes_data);
axes_tubes->SetRadius (axes->GetScaleFactor () / 50.0);
axes_tubes->SetNumberOfSides (6);
vtkSmartPointer<vtkPolyDataMapper> axes_mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
axes_mapper->SetScalarModeToUsePointData ();
axes_mapper->SetInput (axes_tubes->GetOutput ());
vtkSmartPointer<vtkLODActor> axes_actor = vtkSmartPointer<vtkLODActor>::New ();
axes_actor->SetMapper (axes_mapper);
cv::Vec3d t = affine.translation();
axes_actor->SetPosition (t[0], t[1], t[2]);
cv::Matx33f m = affine.rotation();
cv::Vec3f rvec;
cv::Rodrigues(m, rvec);
float r_angle = cv::norm(rvec);
rvec *= 1.f/r_angle;
axes_actor->SetOrientation(0,0,0);
axes_actor->RotateWXYZ(r_angle*180/CV_PI,rvec[0], rvec[1], rvec[2]);
renderer_->AddActor (axes_actor);
(*shape_actor_map_)[id] = axes_actor;
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool temp_viz::Viz3d::VizImpl::removeCoordinateSystem (const std::string &id)
{
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
if (am_it == shape_actor_map_->end ())
return false;
// Remove it from all renderers
if (!removeActorFromRenderer(am_it->second))
return false;
shape_actor_map_->erase(am_it);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool temp_viz::Viz3d::VizImpl::removePointCloud (const std::string &id)
{

Loading…
Cancel
Save