[vtkusers] Create cylinder whose cross section is ellipse

arwtyxouymz arw.tyx-ouy_mz at ezweb.ne.jp
Wed Jul 26 04:02:54 EDT 2017


Hi,

I'm a newer of VTK, and use VTK-8.0.0 by C++.

I want to create a cylinder whose cross section is ellipse.

Firstly I create 2d ellipse, then I extrude the ellipse along z axis.
I could create 2d ellipse, and render it.
But I have applied vtkLinearExtrusionFilter, my code crash with exit code
11.
What shoud i do?

please help me.

This is my code.

```
#include "vtkPoints.h"
#include "vtkSmartPointer.h"
#include "vtkLinearExtrusionFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"

int main(int argc, char *argv[])
{

    double angle = 0;
    double r1, r2;
    int id = 0;
    int CenterX, CenterY;
    r1 = 50;
    r2 = 30;

    vtkSmartPointer<vtkPoints> points =
            vtkSmartPointer<vtkPoints>::New();
    points->SetNumberOfPoints(31);
    while (angle <= 2.0 * vtkMath::Pi() + (vtkMath::Pi() / 60.0))
    {
        points->InsertPoint(id, r1 * cos(angle) + CenterX, r2 * sin(angle) +
CenterY, 0);
        angle = angle + (vtkMath::Pi() / 60.0);
        id++;
    }

    vtkSmartPointer<vtkCellArray> lines =
            vtkSmartPointer<vtkCellArray>::New();
    lines->Allocate(1, 1);
    lines->InsertNextCell(id);
    lines->SetNumberOfCells(id);
    for (int k = 0; k < id; ++k) {
        lines->InsertCellPoint(k);
    }

    vtkSmartPointer<vtkPolyData> polyData =
            vtkSmartPointer<vtkPolyData>::New();
    polyData->GlobalReleaseDataFlagOff();
    polyData->Allocate(1, 1);
    polyData->SetPoints(points);
    polyData->SetLines(lines);

    vtkSmartPointer<vtkLinearExtrusionFilter> extrude =
            vtkSmartPointer<vtkLinearExtrusionFilter>::New();
    extrude->SetInputData(polyData);
    extrude->SetExtrusionTypeToNormalExtrusion();
    extrude->SetVector(0, 0, 30.0);
    extrude->SetScaleFactor(0.5);
    extrude->Update();

    vtkSmartPointer<vtkPolyDataMapper> mapper =
            vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(extrude->GetOutputPort());

    vtkSmartPointer<vtkActor> actor =
            vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(0.8900, 0.8100, 0.3400);

    vtkSmartPointer<vtkRenderer> ren =
            vtkSmartPointer<vtkRenderer>::New();
    ren->SetBackground(.4, .5, .7);
    ren->AddActor(actor);


    vtkSmartPointer<vtkRenderWindow> renWin =
            vtkSmartPointer<vtkRenderWindow>::New();
    renWin->AddRenderer(ren);
    renWin->SetSize(600, 600);

    vtkSmartPointer<vtkRenderWindowInteractor> iren =
            vtkSmartPointer<vtkRenderWindowInteractor>::New();
    iren->SetRenderWindow(renWin);

    vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
            vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    iren->SetInteractorStyle(style);

    renWin->Render();
    iren->Initialize();
    iren->Start();

    return EXIT_SUCCESS;
}
```



--
View this message in context: http://vtk.1045678.n5.nabble.com/Create-cylinder-whose-cross-section-is-ellipse-tp5744148.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list