vtkDelaunay2D

I have created a surface using the vtkDelaunay2D class, but due to different data, it often causes surface distortion
imagelike this ,How should I make these surfaces smoother? By the way, I have used several smoothing functions included in vtk, but the results are not ideal,Thank you for your suggestion

Hello,

To smooth out such artifacts, you can refine the mesh while interpolating the finer triangles. You can try either vtkLinearSubdivisionFilter or vtkButterflySubdivisionFilter classes.

https://vtk.org/doc/nightly/html/classvtkLinearSubdivisionFilter.html

https://vtk.org/doc/nightly/html/classvtkButterflySubdivisionFilter.html

take care,

PC

Actually, this picture I haved used class vtkLinearSubdivisionFilter to create it, tried class vtkButterflySubdivisionFilter, too,But it didn’t work. Thanks for the advice anyway,If you have any better suggestions, I’d appreciate it

Dear @Frankenstein ,

If you can deal with the CGAL’s GPLv3 license, I would recommand you to have a look at the vespa project.
As presented in this blog, this VTK module (and ParaView plugin) expose CGAL smoothing methods, as well as isotropic remeshing, alpha wrapping, boolean operations …

Don’t give up so early. Those algorithms have lots of parameters. Have you tried them all?

No, I haven’t. Why don’t you post the code you used before dismissing the algorithms?

My Bad. Here’s my code

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#endif
#include
#define pi 3.1415926535
#include <vtkDelaunay2D.h>
#include <vtkLoopSubdivisionFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include
#include <vtkButterflySubdivisionFilter.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkLookupTable.h>
#include <vtkLinearSubdivisionFilter.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkLine.h>
#include <vtkPolyData.h>
#include <vtkScalarBarActor.h>
#include <vtkAlgorithm.h>
int main() {

std::ifstream ifs_p1;
ifs_p1.open("C:/Users/15409/Desktop/ver1/result_p1.txt");
std::vector<std::vector<double>>pp1;
std::vector<double> pp1_tmp;
double tmp;
for(int i=0;i<72+1;i++)
{
    for(int j=0;j<36+1;j++)
    {
    ifs_p1>>tmp;
    pp1_tmp.push_back(tmp);
    }
    pp1.push_back(pp1_tmp);
    pp1_tmp.clear();
}
std::vector<std::vector<double>>XX,XX1;
std::vector<double> X;
std::vector<std::vector<double>>YY,YY1;
std::vector<double> Y;
std::vector<std::vector<double>>ZZ;
std::vector<double> Z;
double wzj=150;double r=40;
int m=73;int n=37;double B=32;

for(int i=0;i<37;i++)
{
for(int j=0;j<73;j++)
{
X.push_back(cos(((180-wzj)/2+180+wzj*j/(m-1))pi/180)(r+pp1[j][i]500));
Y.push_back(sin(((180-wzj)/2+180+wzj
j/(m-1))pi/180)(r+pp1[j][i]500));
Z.push_back(i
B/(n-1)-(B/2));
}
XX.push_back(X);
YY.push_back(Y);
ZZ.push_back(Z);
Z.clear();
X.clear();
Y.clear();
}

vtkSmartPointer<vtkPoints> pts =vtkSmartPointer<vtkPoints>::New();
for(int i=0;i<37;i++)
{
    for(int j=0;j<73;j++)
    {
       pts->InsertNextPoint(ZZ[i][j],XX[i][j],YY[i][j]);
    }
}
for(int i=0;i<37;i++)
{
    for(int j=0 ;j<73;j++)
    {
       X.push_back(i);
       Y.push_back(j);
    }
    XX1.push_back(X);
    YY1.push_back(Y);
    X.clear();
    Y.clear();
}

vtkSmartPointer<vtkPoints> pts_surf =vtkSmartPointer<vtkPoints>::New();
for(int i=0;i<37;i++)
{
    for(int j=0;j<73;j++)
    {
       pts_surf->InsertNextPoint(XX1[i][j],YY1[i][j],pp1[j][i]*500);
    }
}

vtkSmartPointer<vtkPolyData> poly_surf = vtkSmartPointer<vtkPolyData>::New();
        poly_surf->SetPoints(pts_surf);
vtkSmartPointer<vtkDelaunay2D>Delaunay_surf =vtkSmartPointer<vtkDelaunay2D>::New();
    Delaunay_surf->SetInputData(poly_surf);
    Delaunay_surf->Update();

vtkSmartPointer<vtkLinearSubdivisionFilter> subdiv_surf = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
    subdiv_surf->SetInputConnection(Delaunay_surf->GetOutputPort());
    subdiv_surf->SetNumberOfSubdivisions(3);
    subdiv_surf->Update();

vtkSmartPointer<vtkPolyDataMapper> mapper_surf = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper_surf->SetInputConnection(Delaunay_surf ->GetOutputPort());
vtkSmartPointer<vtkActor> actor_surf = vtkSmartPointer<vtkActor>::New();
actor_surf->SetMapper(mapper_surf);

vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
        poly->SetPoints(pts);
vtkSmartPointer<vtkDelaunay2D>Delaunay =vtkSmartPointer<vtkDelaunay2D>::New();
    Delaunay->SetInputData(poly);
    Delaunay->Update();

vtkSmartPointer<vtkLinearSubdivisionFilter> subdiv = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
    subdiv->SetInputConnection(Delaunay->GetOutputPort());
    subdiv->SetNumberOfSubdivisions(3);
    subdiv->Update();

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(subdiv ->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

vtkSmartPointer<vtkRenderer> leftRenderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> rightRenderer = vtkSmartPointer<vtkRenderer>::New();
leftRenderer->AddActor(actor);
leftRenderer->SetBackground(0.53, 0.64, 0.89);
leftRenderer->SetViewport(0, 0, 0.5, 1.0);
rightRenderer->AddActor(actor_surf);
rightRenderer->SetViewport(0.5, 0, 1.0, 1.0);

vtkSmartPointer<vtkRenderWindow> window = vtkSmartPointer<vtkRenderWindow>::New();
window->AddRenderer(leftRenderer);
window->AddRenderer(rightRenderer);
window->SetSize(640, 480);
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(window);
interactor->Initialize();
interactor->Start();

return 0;

}
the result is here
image


I already know that I can control the parameter input here to improve the smoothness of the surface, but it takes too much time. Maybe I should change the computer

Well, looks like the output if fine for me. I assume the second image is what you need.

regards,

PC