[vtkusers] How to orient faces of a polydata?

Majid Mohammad sadeghi majid.msadeghi at yahoo.com
Wed Jan 3 04:17:03 EST 2018


This code should work to create the mesh. I have also attached the produced mesh in .stl and .off format for possible evaluation.
    double tube_radious = 2.5;
    double MaxToppt[3];
    MaxToppt[2]=15;
    double center1[3] = { 0, 0, 0 };

    double CornerPt1[3];
    double CornerPt2[3];
    double CornerPt3[3];
    double CornerPt4[3];
    double CornerPt5[3];
    double CornerPt6[3];

    CornerPt2[0] = center1[0] + tube_radious + 1;
    CornerPt2[1] = center1[1] - 10;
    CornerPt1[0] = center1[0] - tube_radious - 1; ;
    CornerPt1[1] = center1[1] - 10;
    CornerPt3[0] = center1[0] + tube_radious + 1;
    CornerPt3[1] = center1[1];
    CornerPt4[0] = center1[0] + tube_radious;
    CornerPt4[1] = center1[1] + MaxToppt[2] + 10;
    CornerPt5[0] = center1[0] - tube_radious - (MaxToppt[2] + 10) * 0.7;
    CornerPt5[1] = center1[1] + (MaxToppt[2] + 10) * 0.7;
    CornerPt6[0] = center1[0] - tube_radious - 1;
    CornerPt6[1] = center1[1];
    CornerPt1[2] = 0;
    CornerPt2[2] = 0;
    CornerPt3[2] = 0;
    CornerPt4[2] = 0;
    CornerPt5[2] = 0;
    CornerPt6[2] = 0;

    vtkSmartPointer<vtkPoints> pointsImp_first = vtkSmartPointer<vtkPoints>::New();
    pointsImp_first->InsertNextPoint(CornerPt1);
    pointsImp_first->InsertNextPoint(CornerPt2);
    pointsImp_first->InsertNextPoint(CornerPt3);
    pointsImp_first->InsertNextPoint(CornerPt4);
    pointsImp_first->InsertNextPoint(CornerPt5);
    pointsImp_first->InsertNextPoint(CornerPt6);

    vtkSmartPointer<vtkCellArray> polygonsImp_first = vtkSmartPointer<vtkCellArray>::New();// Add the polygon to a list of polygons
    polygonsImp_first->Allocate(4, 6);
    polygonsImp_first->InsertNextCell(3);
    polygonsImp_first->InsertCellPoint(0);
    polygonsImp_first->InsertCellPoint(1);
    polygonsImp_first->InsertCellPoint(2);
    polygonsImp_first->InsertNextCell(3);
    polygonsImp_first->InsertCellPoint(0);
    polygonsImp_first->InsertCellPoint(2);
    polygonsImp_first->InsertCellPoint(5);
    polygonsImp_first->InsertNextCell(3);
    polygonsImp_first->InsertCellPoint(2);
    polygonsImp_first->InsertCellPoint(3);
    polygonsImp_first->InsertCellPoint(5);
    polygonsImp_first->InsertNextCell(3);
    polygonsImp_first->InsertCellPoint(3);
    polygonsImp_first->InsertCellPoint(4);
    polygonsImp_first->InsertCellPoint(5);

    vtkSmartPointer<vtkPolyData> polygonPolyImp_first = vtkSmartPointer<vtkPolyData>::New();
    polygonPolyImp_first->Initialize();
    polygonPolyImp_first->SetPoints(pointsImp_first);
    polygonPolyImp_first->SetPolys(polygonsImp_first);

    //****************************************** Transform 
    vtkSmartPointer<vtkTransform> RotatetwicetranslateTransform = vtkSmartPointer<vtkTransform>::New();
    RotatetwicetranslateTransform->RotateWXYZ(90, 0, 1, 0);//rotate around y(0,1,0) axis
    RotatetwicetranslateTransform->RotateWXYZ(90, 0, 0, 1);
    RotatetwicetranslateTransform->Translate(0, 0, 8);
    vtkSmartPointer<vtkTransformPolyDataFilter> RotatetwiceFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
    RotatetwiceFilter->SetInputData(polygonPolyImp_first);
    RotatetwiceFilter->SetTransform(RotatetwicetranslateTransform);
    RotatetwiceFilter->Update();

    vtkSmartPointer<vtkPolyData> allpolygonestransformed = vtkSmartPointer<vtkPolyData>::New();
    allpolygonestransformed = RotatetwiceFilter->GetOutput();

    // Show transformed polygon
    //vtkSmartPointer<vtkPolyDataMapper> trandformedmapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    //trandformedmapper->SetInputData(allpolygonestransformed);
    //vtkSmartPointer<vtkActor> transformedactor = vtkSmartPointer<vtkActor>::New();
    //transformedactor->SetMapper(trandformedmapper);
    //transformedactor->GetProperty()->SetColor(1, 0, 0);
    //
    //renderer->AddActor(transformedactor);
    //this->ui.qvtkWidget->GetRenderWindow()->Render();

    //**********************************************************
    // Extrude the contour along the normal to the plane which the contour lies on.
    vtkSmartPointer<vtkLinearExtrusionFilter> extrudeFilter4 = vtkSmartPointer<vtkLinearExtrusionFilter>::New();
    extrudeFilter4->SetInputData(allpolygonestransformed);
    extrudeFilter4->SetScaleFactor(-18);
    extrudeFilter4->SetExtrusionTypeToNormalExtrusion();
    extrudeFilter4->SetVector(1, 0, 0);
    extrudeFilter4->Update();

    vtkSmartPointer<vtkTriangleFilter> ExtrudedTri = vtkSmartPointer<vtkTriangleFilter>::New();
    ExtrudedTri->SetInputConnection(extrudeFilter4->GetOutputPort());
    ExtrudedTri->Update();

    vtkSmartPointer<vtkPolyData> extruded = vtkSmartPointer<vtkPolyData>::New();
    extruded = ExtrudedTri->GetOutput();

    vtkSmartPointer<vtkCleanPolyData> Clean = vtkSmartPointer<vtkCleanPolyData>::New();
    Clean->SetInputData(extruded);
    Clean->SetTolerance(0.0);
    Clean->PointMergingOn();
    Clean->ConvertLinesToPointsOn();
    Clean->ConvertPolysToLinesOn();
    Clean->ConvertStripsToPolysOn();
    Clean->Update();
    
    vtkSmartPointer<vtkPolyData> alltriclean = vtkSmartPointer<vtkPolyData>::New();
    alltriclean = Clean->GetOutput();
    
    vtkSmartPointer<vtkSTLWriter> stlWriter0 = vtkSmartPointer<vtkSTLWriter>::New();
    stlWriter0->SetFileName("C:\\alltricleansubdividedsASCII.stl");
    stlWriter0->SetFileTypeToASCII();
    stlWriter0->SetInputData(alltriclean);
    stlWriter0->Update();
    stlWriter0->Write();



Thank you so much.

 

    On Tuesday, January 2, 2018, 6:47:45 PM GMT+2, Bill Lorensen <bill.lorensen at gmail.com> wrote:  
 
 Can you post a small, compilable example that illustrates the problem?

On Tue, Jan 2, 2018 at 7:28 AM, Majid Mohammad sadeghi via vtkusers
<vtkusers at vtk.org> wrote:
> Dear All,
>
> I am exrtuding a 2D polygon using vtkLinearExtrusionFilter, the resulting
> polydata has misoriented faces on the mesh, meaning that for a closed mesh,
> faces inside and outside direction is mixed up. (for example when I open the
> data with meshlab and look at the normals, some are pointing in and some
> outwards)
>
> How is it possible to orient order of each triangle vertices in a mesh so
> that there is a consistancy betwwen all faces?
>
> Thanks for the help.
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180103/0012b1ab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alltricleansubdividedsASCII.stl
Type: application/octet-stream
Size: 2671 bytes
Desc: not available
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180103/0012b1ab/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alltricleansubdividedsASCII_OpenMesh.off
Type: application/octet-stream
Size: 626 bytes
Desc: not available
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180103/0012b1ab/attachment-0001.obj>


More information about the vtkusers mailing list