showPlane implementation
This commit is contained in:
parent
26a6823207
commit
f94c2414e6
@ -33,6 +33,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);
|
||||
void showPlane(const String &id, const Vec4f &coefs);
|
||||
void showPlane(const String &id, const Vec4f &coefs, const Point3f &pt);
|
||||
|
||||
bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane");
|
||||
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
|
||||
|
@ -139,6 +139,8 @@ 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);
|
||||
void showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt);
|
||||
|
||||
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");
|
||||
@ -178,28 +180,6 @@ public:
|
||||
*/
|
||||
bool addCylinder (const temp_viz::ModelCoefficients &coefficients, const std::string &id = "cylinder");
|
||||
|
||||
/** \brief Add a plane from a set of given model coefficients
|
||||
* \param[in] coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
|
||||
* \param[in] id the plane id/name (default: "plane")
|
||||
*
|
||||
* \code
|
||||
* // The following are given (or computed using sample consensus techniques)
|
||||
* // See SampleConsensusModelPlane for more information
|
||||
|
||||
*
|
||||
* temp_viz::ModelCoefficients plane_coeff;
|
||||
* plane_coeff.values.resize (4); // We need 4 values
|
||||
* plane_coeff.values[0] = plane_parameters.x ();
|
||||
* plane_coeff.values[1] = plane_parameters.y ();
|
||||
* plane_coeff.values[2] = plane_parameters.z ();
|
||||
* plane_coeff.values[3] = plane_parameters.w ();
|
||||
*
|
||||
* addPlane (plane_coeff);
|
||||
* \endcode
|
||||
*/
|
||||
bool addPlane (const temp_viz::ModelCoefficients &coefficients, const std::string &id = "plane");
|
||||
bool addPlane (const temp_viz::ModelCoefficients &coefficients, double x, double y, double z, const std::string &id = "plane");
|
||||
|
||||
/** \brief Add a circle from a set of given model coefficients
|
||||
* \param[in] coefficients the model coefficients (x, y, radius)
|
||||
* \param[in] id the circle id/name (default: "circle")
|
||||
|
@ -83,14 +83,14 @@ void temp_viz::Viz3d::showLine(const String &id, const Point3f &pt1, const Point
|
||||
impl_->showLine(id, pt1, pt2, color);
|
||||
}
|
||||
|
||||
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, const String &id)
|
||||
void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs)
|
||||
{
|
||||
return impl_->addPlane(coefficients, id);
|
||||
impl_->showPlane(id, coefs);
|
||||
}
|
||||
|
||||
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String& id)
|
||||
void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs, const Point3f &pt)
|
||||
{
|
||||
return impl_->addPlane(coefficients, x, y, z, id);
|
||||
impl_->showPlane(id, coefs, pt);
|
||||
}
|
||||
|
||||
bool temp_viz::Viz3d::removeCoordinateSystem (const String &id)
|
||||
|
@ -302,6 +302,69 @@ void temp_viz::Viz3d::VizImpl::showLine (const String &id, const cv::Point3f &pt
|
||||
}
|
||||
}
|
||||
|
||||
void temp_viz::Viz3d::VizImpl::showPlane (const String &id, const cv::Vec4f &coefs)
|
||||
{
|
||||
// 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(createPlane(coefs));
|
||||
actor->Modified ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a plane
|
||||
vtkSmartPointer<vtkDataSet> data = createPlane (coefs);
|
||||
|
||||
// Create an Actor
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
createActorFromVTKDataSet (data, actor);
|
||||
// actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||
actor->GetProperty ()->SetRepresentationToSurface ();
|
||||
actor->GetProperty ()->SetLighting (false);
|
||||
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 &coefs, const cv::Point3f &pt)
|
||||
{
|
||||
// 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(createPlane(coefs, pt));
|
||||
actor->Modified ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a plane
|
||||
vtkSmartPointer<vtkDataSet> data = createPlane (coefs, pt);
|
||||
|
||||
// Create an Actor
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
createActorFromVTKDataSet (data, actor);
|
||||
// actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||
actor->GetProperty ()->SetRepresentationToSurface ();
|
||||
actor->GetProperty ()->SetLighting (false);
|
||||
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)
|
||||
{
|
||||
CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
|
||||
|
@ -1088,62 +1088,6 @@ bool temp_viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename,
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** \brief Add a plane from a set of given model coefficients
|
||||
* \param coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
|
||||
* \param id the plane id/name (default: "plane")
|
||||
* \param viewport (optional) the id of the new viewport (default: 0)
|
||||
*/
|
||||
bool temp_viz::Viz3d::VizImpl::addPlane (const temp_viz::ModelCoefficients &coefficients, const std::string &id)
|
||||
{
|
||||
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
|
||||
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
|
||||
if (am_it != shape_actor_map_->end ())
|
||||
{
|
||||
std::cout << "[addPlane] A shape with id <"<<id<<"> already exists! Please choose a different id and retry." << std::endl;
|
||||
return (false);
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkDataSet> data = createPlane (coefficients);
|
||||
|
||||
// Create an Actor
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
createActorFromVTKDataSet (data, actor);
|
||||
// actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||
actor->GetProperty ()->SetRepresentationToSurface ();
|
||||
actor->GetProperty ()->SetLighting (false);
|
||||
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::addPlane (const temp_viz::ModelCoefficients &coefficients, double x, double y, double z, const std::string &id)
|
||||
{
|
||||
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
|
||||
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
|
||||
if (am_it != shape_actor_map_->end ())
|
||||
{
|
||||
std::cout << "[addPlane] A shape with id <" << id << "> already exists! Please choose a different id and retry.\n" << std::endl;
|
||||
return (false);
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkDataSet> data = createPlane (coefficients, x, y, z);
|
||||
|
||||
// Create an Actor
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
createActorFromVTKDataSet (data, actor);
|
||||
actor->GetProperty ()->SetRepresentationToWireframe ();
|
||||
actor->GetProperty ()->SetLighting (false);
|
||||
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::addCircle (const temp_viz::ModelCoefficients &coefficients, const std::string &id)
|
||||
{
|
||||
|
@ -93,19 +93,25 @@ TEST(Viz_viz3d, accuracy)
|
||||
int col_green = 0;
|
||||
int col_red = 0;
|
||||
|
||||
v.showPlane("plane1", cv::Vec4f(1.0f,1.0f,1.0f,1.0f));
|
||||
|
||||
while(!v.wasStopped())
|
||||
{
|
||||
// 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));
|
||||
|
||||
v.showLine("line2", cv::Point3f(0.0,0.0,0.0), cv::Point3f(1.0f-pos_x, pos_y, pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
|
||||
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));
|
||||
|
||||
angle_x += 0.1f;
|
||||
angle_y -= 0.1f;
|
||||
angle_z += 0.1f;
|
||||
pos_x = std::sin(angle_x);
|
||||
pos_y = std::sin(angle_x);
|
||||
pos_z = std::sin(angle_x);
|
||||
pos_y = std::sin(angle_y);
|
||||
pos_z = std::sin(angle_z);
|
||||
col_blue = int(angle_x * 10) % 256;
|
||||
col_green = int(angle_x * 20) % 256;
|
||||
col_red = int(angle_x * 30) % 256;
|
||||
|
Loading…
x
Reference in New Issue
Block a user