mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
GridImpl structure to shorten grid widget implementation
This commit is contained in:
parent
6e5a712f6e
commit
952029a47b
@ -126,6 +126,9 @@ namespace cv
|
|||||||
GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
|
GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
|
||||||
GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
|
GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct GridImpl;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS Text3DWidget : public Widget3D
|
class CV_EXPORTS Text3DWidget : public Widget3D
|
||||||
|
@ -440,7 +440,9 @@ template<> cv::viz::PolyLineWidget cv::viz::Widget::cast<cv::viz::PolyLineWidget
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// grid widget implementation
|
/// grid widget implementation
|
||||||
|
|
||||||
cv::viz::GridWidget::GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color)
|
struct cv::viz::GridWidget::GridImpl
|
||||||
|
{
|
||||||
|
static vtkSmartPointer<vtkPolyData> createGrid(const Vec2i &dimensions, const Vec2d &spacing)
|
||||||
{
|
{
|
||||||
// Create the grid using image data
|
// Create the grid using image data
|
||||||
vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();
|
vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();
|
||||||
@ -457,9 +459,16 @@ cv::viz::GridWidget::GridWidget(const Vec2i &dimensions, const Vec2d &spacing, c
|
|||||||
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
|
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
|
||||||
filter->SetInputConnection(grid->GetProducerPort());
|
filter->SetInputConnection(grid->GetProducerPort());
|
||||||
filter->Update();
|
filter->Update();
|
||||||
|
return filter->GetOutput();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cv::viz::GridWidget::GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color)
|
||||||
|
{
|
||||||
|
vtkSmartPointer<vtkPolyData> grid = GridImpl::createGrid(dimensions, spacing);
|
||||||
|
|
||||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||||
mapper->SetInput(filter->GetOutput());
|
mapper->SetInputConnection(grid->GetProducerPort());
|
||||||
|
|
||||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||||
actor->SetMapper(mapper);
|
actor->SetMapper(mapper);
|
||||||
@ -470,21 +479,7 @@ cv::viz::GridWidget::GridWidget(const Vec2i &dimensions, const Vec2d &spacing, c
|
|||||||
|
|
||||||
cv::viz::GridWidget::GridWidget(const Vec4f &coefs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color)
|
cv::viz::GridWidget::GridWidget(const Vec4f &coefs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color)
|
||||||
{
|
{
|
||||||
// Create the grid using image data
|
vtkSmartPointer<vtkPolyData> grid = GridImpl::createGrid(dimensions, spacing);
|
||||||
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.0f);
|
|
||||||
|
|
||||||
// Extract the edges so we have the grid
|
|
||||||
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
|
|
||||||
filter->SetInputConnection(grid->GetProducerPort());
|
|
||||||
filter->Update();
|
|
||||||
|
|
||||||
// Estimate the transform to set the normal based on the coefficients
|
// Estimate the transform to set the normal based on the coefficients
|
||||||
Vec3f normal(coefs[0], coefs[1], coefs[2]);
|
Vec3f normal(coefs[0], coefs[1], coefs[2]);
|
||||||
@ -518,11 +513,11 @@ cv::viz::GridWidget::GridWidget(const Vec4f &coefs, const Vec2i &dimensions, con
|
|||||||
|
|
||||||
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
||||||
transform_filter->SetTransform(transform);
|
transform_filter->SetTransform(transform);
|
||||||
transform_filter->SetInputConnection(filter->GetOutputPort());
|
transform_filter->SetInputConnection(grid->GetProducerPort());
|
||||||
transform_filter->Update();
|
transform_filter->Update();
|
||||||
|
|
||||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||||
mapper->SetInput(transform_filter->GetOutput());
|
mapper->SetInputConnection(transform_filter->GetOutputPort());
|
||||||
|
|
||||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||||
actor->SetMapper(mapper);
|
actor->SetMapper(mapper);
|
||||||
|
Loading…
Reference in New Issue
Block a user