fixed crash in enabling shading for polydata widgets
This commit is contained in:
parent
e478d6b1e9
commit
d591bd875b
@ -313,7 +313,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
cell_array->Squeeze();
|
||||
polydata->SetStrips(cell_array);
|
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetScalarModeToUsePointData();
|
||||
mapper->ImmediateModeRenderingOff();
|
||||
VtkUtils::SetInputData(mapper, polydata);
|
||||
|
@ -220,6 +220,22 @@ namespace cv
|
||||
scalars->SetArray(color_data->val, size * 3, 0);
|
||||
return scalars;
|
||||
}
|
||||
|
||||
static vtkSmartPointer<vtkPolyData> ComputeNormals(vtkSmartPointer<vtkPolyData> polydata)
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataNormals> normals_generator = vtkSmartPointer<vtkPolyDataNormals>::New();
|
||||
normals_generator->ComputePointNormalsOn();
|
||||
normals_generator->ComputeCellNormalsOff();
|
||||
normals_generator->SetFeatureAngle(0.1);
|
||||
normals_generator->SetSplitting(0);
|
||||
normals_generator->SetConsistency(1);
|
||||
normals_generator->SetAutoOrientNormals(0);
|
||||
normals_generator->SetFlipNormals(0);
|
||||
normals_generator->SetNonManifoldTraversal(1);
|
||||
VtkUtils::SetInputData(normals_generator, polydata);
|
||||
normals_generator->Update();
|
||||
return normals_generator->GetOutput();
|
||||
}
|
||||
};
|
||||
|
||||
inline vtkSmartPointer<vtkMatrix4x4> vtkmatrix(const cv::Matx44d &matrix)
|
||||
|
@ -285,21 +285,9 @@ void cv::viz::writeTrajectory(InputArray _traj, const String& files_format, int
|
||||
void cv::viz::computeNormals(const Mesh3d& mesh, OutputArray _normals)
|
||||
{
|
||||
vtkSmartPointer<vtkPolyData> polydata = getPolyData(WMesh(mesh));
|
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(polydata);
|
||||
|
||||
vtkSmartPointer<vtkPolyDataNormals> normal_generator = vtkSmartPointer<vtkPolyDataNormals>::New();
|
||||
normal_generator->SetInputConnection(polydata->GetProducerPort());
|
||||
normal_generator->ComputePointNormalsOn();
|
||||
normal_generator->ComputeCellNormalsOff();
|
||||
|
||||
normal_generator->SetFeatureAngle(0.1);
|
||||
normal_generator->SetSplitting(0);
|
||||
normal_generator->SetConsistency(1);
|
||||
normal_generator->SetAutoOrientNormals(0);
|
||||
normal_generator->SetFlipNormals(0);
|
||||
normal_generator->SetNonManifoldTraversal(1);
|
||||
normal_generator->Update();
|
||||
|
||||
vtkSmartPointer<vtkDataArray> generic_normals = normal_generator->GetOutput()->GetPointData()->GetNormals();
|
||||
vtkSmartPointer<vtkDataArray> generic_normals = with_normals->GetPointData()->GetNormals();
|
||||
if(generic_normals)
|
||||
{
|
||||
Mat normals(1, generic_normals->GetNumberOfTuples(), CV_64FC3);
|
||||
|
@ -141,10 +141,10 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals())
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
|
||||
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
|
||||
VtkUtils::SetInputData(normals, mapper->GetInput());
|
||||
normals->Update();
|
||||
VtkUtils::SetInputData(mapper, normals->GetOutput());
|
||||
CV_Assert("Can't set shading property for such type of widget" && mapper);
|
||||
|
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(mapper->GetInput());
|
||||
VtkUtils::SetInputData(mapper, with_normals);
|
||||
}
|
||||
actor->GetProperty()->SetInterpolationToGouraud();
|
||||
break;
|
||||
@ -154,10 +154,10 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals())
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
|
||||
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
|
||||
VtkUtils::SetInputData(normals, mapper->GetInput());
|
||||
normals->Update();
|
||||
VtkUtils::SetInputData(mapper, normals->GetOutput());
|
||||
CV_Assert("Can't set shading property for such type of widget" && mapper);
|
||||
|
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(mapper->GetInput());
|
||||
VtkUtils::SetInputData(mapper, with_normals);
|
||||
}
|
||||
actor->GetProperty()->SetInterpolationToPhong();
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user