[vtkusers] Create cylinder whose cross section is ellipse

Bill Lorensen bill.lorensen at gmail.com
Wed Jul 26 10:24:37 EDT 2017


I just added an example based on your code...
https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/EllipticalCylinder/


On Wed, Jul 26, 2017 at 9:05 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> Your creation of the polydata was flawed.
> This works:
> #include "vtkPoints.h"
> #include "vtkPolyLine.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<vtkPolyLine> line =
>     vtkSmartPointer<vtkPolyLine>::New();
>   line->GetPointIds()->SetNumberOfIds(id);
>   for(unsigned int i = 0; i < id; i++)
>   {
>     line->GetPointIds()->SetId(i,i);
>   }
>
>   vtkSmartPointer<vtkCellArray> lines =
>     vtkSmartPointer<vtkCellArray>::New();
>   lines->InsertNextCell(line);
>
>   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;
> }
>
> On Wed, Jul 26, 2017 at 4:02 AM, arwtyxouymz <arw.tyx-ouy_mz at ezweb.ne.jp> wrote:
>> 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.
>> _______________________________________________
>> 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:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list