<div dir="ltr">It may not be wrong . <div>I think what you have done is taken ellipse and extruded it to form cylinder shape.</div><div>If you observe points in your polydata, they are only at the edge of cylinder shape. </div><div><br></div><div>SO normals are drawn only in that region. </div><div><br></div><div>You have done too much scaling and hence "arrows" are mixing up to see that graphics that you see there. I modified your code and you can see normals drawn correctly. There is output image attached. </div><div><br></div><div><img src="cid:ii_15d872c8e60b90a3" alt="Inline images 1" width="472" height="256"><img src="cid:ii_15d872c910a0ce19" alt="Inline images 2" width="472" height="256"><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 28 July 2017 at 08:15, arwtyxouymz <span dir="ltr"><<a href="mailto:arw.tyx-ouy_mz@ezweb.ne.jp" target="_blank">arw.tyx-ouy_mz@ezweb.ne.jp</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you Girish Lande!<br>
<br>
I tried to implement your code, but result is something wrong.<br>
Why?<br>
My code is below and the result is in an attachment picture.<br>
I want to calculat normal vectors on the side of the cylinder.<br>
<br>
please help!<br>
<br>
result.png <<a href="http://vtk.1045678.n5.nabble.com/file/n5744183/result.png" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.<wbr>com/file/n5744183/result.png</a>><br>
<span class=""><br>
#include "vtkPoints.h"<br>
#include "vtkSmartPointer.h"<br>
#include "vtkLinearExtrusionFilter.h"<br>
#include "vtkDataSetMapper.h"<br>
#include "vtkPolyDataMapper.h"<br>
#include "vtkActor.h"<br>
#include "vtkProperty.h"<br>
#include "vtkCamera.h"<br>
#include "vtkRenderer.h"<br>
#include "vtkRenderWindow.h"<br>
#include "vtkRenderWindowInteractor.h"<br>
#include "<wbr>vtkInteractorStyleTrackballCam<wbr>era.h"<br>
#include "vtkPolyLine.h"<br>
</span>#include "vtkLineSource.h"<br>
<br>
<br>
#include "vtkSphereSource.h"<br>
#include "vtkDoubleArray.h"<br>
#include "vtkFloatArray.h"<br>
#include "vtkCellData.h"<br>
#include "vtkPolyDataNormals.h"<br>
#include "vtkPointData.h"<br>
#include "vtkBrownianPoints.h"<br>
#include "vtkArrowSource.h"<br>
#include "vtkGlyph3D.h"<br>
<br>
<br>
bool GetPointNormals(vtkPolyData* polydata);<br>
void TestPointNormals(vtkPolyData* polydata);<br>
<span class=""><br>
int main(int argc, char *argv[])<br>
{<br>
</span>    // 2次元楕円<br>
<span class="">    double angle = 0;<br>
    double r1, r2;<br>
    int id = 0;<br>
</span>    double CenterX, CenterY;<br>
<span class="">    r1 = 50;<br>
    r2 = 30;<br>
</span>    double z_length = 50.0;<br>
    CenterX = 0.0; CenterY = 0.0;<br>
<span class=""><br>
    vtkSmartPointer<vtkPoints> points =<br>
            vtkSmartPointer<vtkPoints>::<wbr>New();<br>
</span>    points->SetNumberOfPoints(720)<wbr>;<br>
<span class="">    while (angle <= 2.0 * vtkMath::Pi() + (vtkMath::Pi() / 360.0))<br>
    {<br>
        points->InsertPoint(id, r1 * cos(angle) + CenterX, r2 * sin(angle) +<br>
CenterY, 0);<br>
        angle = angle + (vtkMath::Pi() / 360.0);<br>
        id++;<br>
    }<br>
<br>
<br>
    vtkSmartPointer<vtkPolyLine> line =<br>
            vtkSmartPointer<vtkPolyLine>::<wbr>New();<br>
    line->GetPointIds()-><wbr>SetNumberOfIds(id);<br>
    for (int k = 0; k < id; ++k) {<br>
        line->GetPointIds()->SetId(k, k);<br>
    }<br>
<br>
    vtkSmartPointer<vtkCellArray> lines =<br>
            vtkSmartPointer<vtkCellArray>:<wbr>:New();<br>
    lines->InsertNextCell(line);<br>
<br>
    vtkSmartPointer<vtkPolyData> polyData =<br>
            vtkSmartPointer<vtkPolyData>::<wbr>New();<br>
    polyData-><wbr>GlobalReleaseDataFlagOff();<br>
    polyData->Allocate(1, 1);<br>
    polyData->SetPoints(points);<br>
    polyData->SetLines(lines);<br>
<br>
</span>    // 3次元化<br>
<span class="">    vtkSmartPointer<<wbr>vtkLinearExtrusionFilter> extrude =<br>
            vtkSmartPointer<<wbr>vtkLinearExtrusionFilter>::<wbr>New();<br>
    extrude->SetInputData(<wbr>polyData);<br>
    extrude-><wbr>SetExtrusionTypeToNormalExtrus<wbr>ion();<br>
</span>    extrude->SetVector(0, 0, -z_length);<br>
    extrude->SetScaleFactor(1.0);<br>
    extrude->Update();<br>
<br>
    vtkSmartPointer<<wbr>vtkPolyDataMapper> elliptic_mapper =<br>
            vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();<br>
    elliptic_mapper-><wbr>SetInputConnection(extrude-><wbr>GetOutputPort());<br>
<br>
    vtkSmartPointer<vtkActor> elliptic_actor =<br>
            vtkSmartPointer<vtkActor>::<wbr>New();<br>
    elliptic_actor->SetMapper(<wbr>elliptic_mapper);<br>
    elliptic_actor->GetProperty()-<wbr>>SetColor(0.8900, 0.8100, 0.3400);<br>
<br>
    // 法線ベクトル<br>
    vtkPolyData* elliptic_cylinder = extrude->GetOutput();<br>
    TestPointNormals(elliptic_<wbr>cylinder);<br>
<br>
    vtkMath::RandomSeed(100);<br>
    vtkSmartPointer<<wbr>vtkBrownianPoints> brownianPoints =<br>
            vtkSmartPointer<<wbr>vtkBrownianPoints>::New();<br>
    brownianPoints-><wbr>SetInputConnection(extrude-><wbr>GetOutputPort());<br>
<br>
    vtkSmartPointer<<wbr>vtkArrowSource> arrowSource =<br>
            vtkSmartPointer<<wbr>vtkArrowSource>::New();<br>
    vtkSmartPointer<vtkGlyph3D> glyph3D =<br>
            vtkSmartPointer<vtkGlyph3D>::<wbr>New();<br>
    glyph3D->SetSourceConnection(<wbr>arrowSource->GetOutputPort());<br>
    glyph3D->SetInputConnection(<wbr>brownianPoints->GetOutputPort(<wbr>));<br>
    glyph3D-><wbr>SetVectorModeToUseNormal();<br>
    glyph3D->SetScaleFactor(10.0);<br>
<br>
    vtkSmartPointer<<wbr>vtkPolyDataMapper> glyphMapper =<br>
            vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();<br>
    glyphMapper-><wbr>SetInputConnection(glyph3D-><wbr>GetOutputPort());<br>
<br>
    vtkSmartPointer<vtkActor> glyphActor =<br>
            vtkSmartPointer<vtkActor>::<wbr>New();<br>
    glyphActor->GetProperty()-><wbr>SetColor(.0, 1.0, .0);<br>
    glyphActor->SetMapper(<wbr>glyphMapper);<br>
<br>
<br>
    // 腫瘍<br>
    double TARGET_X, TARGET_Y, TARGET_Z;<br>
    TARGET_X = -sqrt(pow(r1, 2.0) - pow(r2, 2.0));<br>
    TARGET_Y = 0.0;<br>
    TARGET_Z = -z_length/2.0;<br>
<br>
    vtkSmartPointer<<wbr>vtkSphereSource> target =<br>
            vtkSmartPointer<<wbr>vtkSphereSource>::New();<br>
    target->SetRadius(1.0);<br>
    target->SetCenter(TARGET_X, TARGET_Y, TARGET_Z);<br>
<br>
    vtkSmartPointer<<wbr>vtkPolyDataMapper> target_mapper =<br>
            vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();<br>
    target_mapper-><wbr>SetInputConnection(target-><wbr>GetOutputPort());<br>
<br>
    vtkSmartPointer<vtkActor> target_actor =<br>
            vtkSmartPointer<vtkActor>::<wbr>New();<br>
    target_actor->SetMapper(<wbr>target_mapper);<br>
    target_actor->GetProperty()-><wbr>SetColor(1.0, 0.0, 0.0);<br>
<br>
    // ベクトル<br>
    for (vtkIdType id= 0; id <= 720; id++)<br>
    {<br>
        double p[3];<br>
        points->GetPoint(id, p);<br>
        // 方向ベクトル<br>
        vtkVector3d v(p[0] - TARGET_X,<br>
                      p[1] - TARGET_Y,<br>
                      p[2] - TARGET_Z);<br>
    }<br>
<br>
    // 直線<br>
    vtkSmartPointer<vtkLineSource> lineSource =<br>
            vtkSmartPointer<vtkLineSource><wbr>::New();<br>
    lineSource->SetPoint1(TARGET_<wbr>X, TARGET_Y, TARGET_Z);<br>
    lineSource->SetPoint2(0.0, 0.0, 0.0);<br>
    lineSource->Update();<br>
<br>
    vtkSmartPointer<<wbr>vtkPolyDataMapper> line_mapper =<br>
            vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();<br>
    line_mapper->SetInputData(<wbr>lineSource->GetOutput());<br>
<br>
    vtkSmartPointer<vtkActor> line_actor =<br>
            vtkSmartPointer<vtkActor>::<wbr>New();<br>
    line_actor->SetMapper(line_<wbr>mapper);<br>
    line_actor->GetProperty()-><wbr>SetLineWidth(0.5);<br>
<br>
<br>
    // 描画<br>
<span class="">    vtkSmartPointer<vtkRenderer> ren =<br>
            vtkSmartPointer<vtkRenderer>::<wbr>New();<br>
</span><span class="">    vtkSmartPointer<<wbr>vtkRenderWindow> renWin =<br>
            vtkSmartPointer<<wbr>vtkRenderWindow>::New();<br>
    renWin->AddRenderer(ren);<br>
    renWin->SetSize(600, 600);<br>
<br>
    vtkSmartPointer<<wbr>vtkRenderWindowInteractor> iren =<br>
            vtkSmartPointer<<wbr>vtkRenderWindowInteractor>::<wbr>New();<br>
    iren->SetRenderWindow(renWin);<br>
<br>
</span>    //ren->AddActor(line_actor);<br>
    //ren->AddActor(target_actor);<br>
    ren->AddActor(glyphActor);<br>
    ren->AddActor(elliptic_actor);<br>
    ren->SetBackground(.3, .6, .3);<br>
<span class=""><br>
    vtkSmartPointer<<wbr>vtkInteractorStyleTrackballCam<wbr>era> style =<br>
            vtkSmartPointer<<wbr>vtkInteractorStyleTrackballCam<wbr>era>::New();<br>
    iren->SetInteractorStyle(<wbr>style);<br>
<br>
    renWin->Render();<br>
    iren->Initialize();<br>
    iren->Start();<br>
<br>
    return EXIT_SUCCESS;<br>
}<br>
<br>
</span>bool GetPointNormals(vtkPolyData* polydata)<br>
{<br>
    std::cout << "In GetPointNormals: " << polydata <<<br>
polydata->GetNumberOfPoints() << std::endl;<br>
    std::cout << "Looking for point normals..." << std::endl;<br>
<br>
    vtkIdType numPoints = polydata->GetNumberOfPoints();<br>
    std::cout << "There are " << numPoints << " points." << std::endl;<br>
<br>
    vtkIdType numPolys = polydata->GetNumberOfPolys();<br>
    std::cout << "There are " << numPolys << " polys." << std::endl;<br>
<br>
    // Double normals in an array<br>
    vtkDoubleArray* normalDataDouble =<br>
<br>
vtkDoubleArray::SafeDownCast(<wbr>polydata->GetPointData()-><wbr>GetArray("Normals"));<br>
<br>
    if (normalDataDouble)<br>
    {<br>
        vtkIdType nc = normalDataDouble-><wbr>GetNumberOfTuples();<br>
        std::cout << "There are " << nc << " components in normalDataDouble"<br>
<< std::endl;<br>
        return true;<br>
    }<br>
<br>
    // Float normals in an array<br>
    vtkFloatArray* normalDataFloat =<br>
<br>
vtkFloatArray::SafeDownCast(<wbr>polydata->GetPointData()-><wbr>GetArray("Normals"));<br>
<br>
    if (normalDataFloat)<br>
    {<br>
        vtkIdType nc = normalDataFloat-><wbr>GetNumberOfTuples();<br>
        std::cout << "There are " << nc << " components in normalDataFloat"<br>
<< std::endl;<br>
        return true;<br>
    }<br>
<br>
    // Point normals<br>
    vtkDoubleArray* normalsDouble =<br>
<br>
vtkDoubleArray::SafeDownCast(<wbr>polydata->GetPointData()-><wbr>GetNormals());<br>
<br>
    if (normalsDouble)<br>
    {<br>
        std::cout << "There are " << normalsDouble-><wbr>GetNumberOfComponents()<br>
                  << " components in normalsDouble" << std::endl;<br>
        return true;<br>
    }<br>
<br>
    // Point normals<br>
    vtkFloatArray* normalsFloat =<br>
<br>
vtkFloatArray::SafeDownCast(<wbr>polydata->GetPointData()-><wbr>GetNormals());<br>
<br>
    if (normalsFloat)<br>
    {<br>
        std::cout << "There are " << normalsFloat-><wbr>GetNumberOfComponents()<br>
                  << " components in normalsFloat" << std::endl;<br>
        return true;<br>
    }<br>
<br>
    // Generic type point normals<br>
    vtkDataArray* normalsGeneric = polydata->GetPointData()-><wbr>GetNormals();<br>
<br>
    if (normalsGeneric)<br>
    {<br>
        std::cout << "There are " << normalsGeneric-><wbr>GetNumberOfTuples()<br>
                  << " normals in normalsGeneric" << std::endl;<br>
<br>
        double testDouble[3];<br>
        normalsGeneric->GetTuple(0, testDouble);<br>
<br>
        std::cout << "Double: " << testDouble[0] << " "<br>
                 << testDouble[1] << " " << testDouble[2] << std::endl;<br>
        return true;<br>
    }<br>
<br>
    std::cout << "Normals not found!" << std::endl;<br>
    return false;<br>
}<br>
<br>
<br>
void TestPointNormals(vtkPolyData* polydata)<br>
{<br>
    std::cout << "In TestPointNormals: " << polydata->GetNumberOfPoints() <<<br>
std::endl;<br>
    bool hasPointNormals = GetPointNormals(polydata);<br>
<br>
    if (!hasPointNormals)<br>
    {<br>
        std::cout << "No point normals were found. Computing normals..." <<<br>
std::endl;<br>
<br>
        vtkSmartPointer<<wbr>vtkPolyDataNormals> normalGenerator =<br>
                vtkSmartPointer<<wbr>vtkPolyDataNormals>::New();<br>
        normalGenerator->SetInputData(<wbr>polydata);<br>
        normalGenerator-><wbr>ComputePointNormalsOn();<br>
        normalGenerator->Update();<br>
<br>
        polydata = normalGenerator->GetOutput();<br>
        hasPointNormals = GetPointNormals(polydata);<br>
<br>
        std::cout << "On the second try, has point normals? "<br>
                  << hasPointNormals << std::endl;<br>
    }<br>
    else<br>
    {<br>
        std::cout << "Point normals were found!" << std::endl;<br>
    }<br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/Normal-vector-of-the-surface-of-ellipstic-cylinder-tp5744171p5744183.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.<wbr>com/Normal-vector-of-the-<wbr>surface-of-ellipstic-cylinder-<wbr>tp5744171p5744183.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the VTK - Users mailing list archive at Nabble.com.<br>
______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">thanks & regards,<div>Girish</div><div><br></div></div></div>
</div>

<br>
<font size="2">------------------------------</font><font size="2"><wbr>------------------------------</font><font size="2"><wbr>------------------------------</font><font size="2"><wbr>------------------------------</font><font size="2"><wbr>-<br><font face="Arial"><u><b>Disclaimer:</b></u> This email message including any attachments is confidential, and may be privileged and proprietary to Agiliad. If you are not the intended recipient, please notify us immediately by replying to this message and destroy all copies of this message including any attachments. You are NOT authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. Thank you.</font><br>------------------------------</font><font size="2"><wbr>------------------------------</font><font size="2"><wbr>------------------------------</font><font size="2"><wbr>------------------------------</font>