[vtkusers] Normal vector of the surface of ellipstic cylinder

arwtyxouymz arw.tyx-ouy_mz at ezweb.ne.jp
Thu Jul 27 03:51:32 EDT 2017


I want to make normal vector of the surface of ellipstic cylinder.
To each surface point, I want to render normal vector, and get surface
point.
The current code is this.

#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"
#include "vtkPolyLine.h"


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

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

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

    vtkSmartPointer<vtkPolyLine> line =
            vtkSmartPointer<vtkPolyLine>::New();
    line->GetPointIds()->SetNumberOfIds(id);
    for (int k = 0; k < id; ++k) {
        line->GetPointIds()->SetId(k, k);
    }

    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, 100.0);
    extrude->SetScaleFactor(0.5);
    extrude->Update();

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

    /*
    vtkSmartPointer<vtkCylinderSource> cylinder =
            vtkSmartPointer<vtkCylinderSource>::New();
    cylinder->SetRadius(5.0);
    cylinder->SetHeight(10.0);
    cylinder->SetResolution(100);

    vtkSmartPointer<vtkPolyDataMapper> mapper =
            vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(cylinder->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;
}

please help me!



--
View this message in context: http://vtk.1045678.n5.nabble.com/Normal-vector-of-the-surface-of-ellipstic-cylinder-tp5744171.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list