grid widget implementation

This commit is contained in:
ozantonkal 2013-07-10 15:34:19 +02:00
parent 71c76aecc9
commit e185900270
3 changed files with 50 additions and 4 deletions

View File

@ -115,6 +115,12 @@ namespace temp_viz
struct CopyImpl;
};
class CV_EXPORTS GridWidget : public Widget3D
{
public:
GridWidget(Vec2i dimensions, Vec2d spacing, const Color &color = Color::white());
};
class CV_EXPORTS TextWidget : public Widget2D
{
public:
@ -154,6 +160,7 @@ namespace temp_viz
template<> CV_EXPORTS CubeWidget Widget::cast<CubeWidget>();
template<> CV_EXPORTS CoordinateSystemWidget Widget::cast<CoordinateSystemWidget>();
template<> CV_EXPORTS PolyLineWidget Widget::cast<PolyLineWidget>();
template<> CV_EXPORTS GridWidget Widget::cast<GridWidget>();
template<> CV_EXPORTS TextWidget Widget::cast<TextWidget>();
template<> CV_EXPORTS CloudWidget Widget::cast<CloudWidget>();
template<> CV_EXPORTS CloudNormalsWidget Widget::cast<CloudNormalsWidget>();

View File

@ -418,6 +418,38 @@ template<> temp_viz::PolyLineWidget temp_viz::Widget::cast<temp_viz::PolyLineWid
return static_cast<PolyLineWidget&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// grid widget implementation
temp_viz::GridWidget::GridWidget(Vec2i dimensions, Vec2d spacing, const Color &color)
{
// Create the grid using image data
vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();
// Add 1 to dimensions because in ImageData dimensions is the number of lines
// - however here it means number of cells
grid->SetDimensions(dimensions[0]+1, dimensions[1]+1, 1);
grid->SetSpacing(spacing[0], spacing[1], 0.);
// Set origin of the grid to be the middle of the grid
grid->SetOrigin(dimensions[0] * spacing[0] * (-0.5), dimensions[1] * spacing[1] * (-0.5), 0);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(grid);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Show it as wireframe
actor->GetProperty ()->SetRepresentationToWireframe ();
WidgetAccessor::setProp(*this, actor);
}
template<> temp_viz::GridWidget temp_viz::Widget::cast<temp_viz::GridWidget>()
{
Widget3D widget = this->cast<Widget3D>();
return static_cast<GridWidget&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// text widget implementation

View File

@ -136,8 +136,13 @@ TEST(Viz_viz3d, accuracy)
points = points.reshape(0, 2);
temp_viz::PolyLineWidget plw(points);
v.showWidget("polyline",plw);
lw = v.getWidget("polyline").cast<temp_viz::LineWidget>();
// v.showWidget("polyline",plw);
// lw = v.getWidget("polyline").cast<temp_viz::LineWidget>();
temp_viz::GridWidget gw(temp_viz::Vec2i(10,10), temp_viz::Vec2d(0.1,0.1));
v.showWidget("grid", gw);
lw = v.getWidget("grid").cast<temp_viz::LineWidget>();
// float grid_x_angle = 0.0;
while(!v.wasStopped())
{
@ -145,8 +150,8 @@ TEST(Viz_viz3d, accuracy)
cv::Affine3f cloudPosition(angle_x, angle_y, angle_z, cv::Vec3f(pos_x, pos_y, pos_z));
cv::Affine3f cloudPosition2(angle_x, angle_y, angle_z, cv::Vec3f(pos_x+0.2, pos_y+0.2, pos_z+0.2));
// lw2.setColor(temp_viz::Color(col_blue, col_green, col_red));
lw.setLineWidth(pos_x * 10);
lw.setColor(temp_viz::Color(col_blue, col_green, col_red));
// lw.setLineWidth(pos_x * 10);
plw.setColor(temp_viz::Color(col_blue, col_green, col_red));
@ -167,6 +172,8 @@ TEST(Viz_viz3d, accuracy)
cnw.setColor(temp_viz::Color(col_blue, col_green, col_red));
pcw2.setColor(temp_viz::Color(col_blue, col_green, col_red));
gw.updatePose(temp_viz::Affine3f(0.0, 0.1, 0.0, cv::Vec3f(0.0,0.0,0.0)));
angle_x += 0.1f;
angle_y -= 0.1f;
angle_z += 0.1f;