[vtkusers] Some problems with visualizing vectors

David Doria daviddoria+vtk at gmail.com
Thu Nov 5 11:45:51 EST 2009


On Thu, Nov 5, 2009 at 11:38 AM, Luca Pamparana
<luca.pamparana at gmail.com> wrote:
> Hello,
>
> Following the suggestion by the community, I tried to visualize a
> plane and a vector incident on it. However, I am seeing something a
> bit unusual.
>
> So, I have a plane in 2D with the center of gravity at (0, 0, -2.5)
> and I want to draw a line from the center of gravity to (0, 0, 0). So
> when I just run the application, I was hoping to see a line being
> drawn. I can see the line but only when I interact with the plane and
> rotate it... Something weird is going on...
>
> Here is the code that I had tried.
>
> #include "vtkPoints.h"
> #include "vtkCellArray.h"
> #include "vtkPolyData.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkRenderer.h"
> #include "vtkProperty.h"
> #include "vtkSmartPointer.h"
> #include "vtkLineSource.h"
>
>
> int main()
> {
>    vtkSmartPointer<vtkPolyData> geometry = vtkSmartPointer<vtkPolyData>::New();
>    vtkSmartPointer<vtkPoints> testPoints = vtkSmartPointer<vtkPoints>::New();
>    testPoints->Allocate(4);
>    vtkSmartPointer<vtkCellArray> testPolys =
> vtkSmartPointer<vtkCellArray>::New();
>    testPolys->Allocate(testPolys->EstimateSize(1,4));
>    double x[3];
>    vtkIdType pts[4];
>    x[0] = -2.5;
>    x[1] = -2.5;
>    x[2] = -2.5;
>    testPoints->InsertNextPoint(x);
>    x[0] = 2.5;
>    x[1] = -2.5;
>    x[2] = -2.5;
>    testPoints->InsertNextPoint(x);
>    x[0] = -2.5;
>    x[1] = 2.5;
>    x[2] = -2.5;
>    testPoints->InsertNextPoint(x);
>    x[0] = 2.5;
>    x[1] = 2.5;
>    x[2] = -2.5;
>    testPoints->InsertNextPoint(x);
>
>    pts[0] = 0; pts[1] = 1; pts[2] = 3; pts[3] = 2;
>    testPolys->InsertNextCell(4,pts);
>    geometry->SetPoints(testPoints);
>    testPolys->Squeeze();
>    geometry->SetPolys(testPolys);
>
>    vtkSmartPointer<vtkLineSource> lineSource =
> vtkSmartPointer<vtkLineSource>::New();
>    lineSource->SetPoint1(0, 0, -2.5);
>    lineSource->SetPoint2(0, 0, 0);
>    vtkSmartPointer<vtkPolyDataMapper> lineMapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>    lineMapper->SetInput(lineSource->GetOutput());
>
>    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
>    vtkSmartPointer<vtkRenderWindow> renWin =
> vtkSmartPointer<vtkRenderWindow>::New();
>    renWin->AddRenderer(renderer);
>    vtkSmartPointer<vtkRenderWindowInteractor> iren =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>    iren->SetRenderWindow(renWin);
>
>    vtkSmartPointer<vtkPolyDataMapper> testMapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>    testMapper->SetInput(geometry);
>
>    vtkSmartPointer<vtkActor> testActor = vtkSmartPointer<vtkActor>::New();
>    testActor->SetMapper(testMapper);
>    testActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
>
>    vtkSmartPointer<vtkActor> lineActor = vtkSmartPointer<vtkActor>::New();
>    lineActor->SetMapper(lineMapper);
>    lineActor->GetProperty()->SetColor(1, 1, 1);
>
>    renderer->AddActor(testActor);
>    renderer->AddActor(lineActor);
>    renderer->SetBackground(1,1,1);
>    renWin->SetSize(300,300);
>
>    renWin->Render();
>
>    iren->Start();
>
>    return 0;
> }
>
> Any thoughts?
>
> Luca

It works fine for me. What I think you are expecting is a different
kind of interaction. Here is an example of how to change to the mode
that I'd guess you are expecting:
http://www.vtk.org/Wiki/%22Trackball%22_mode

I would suggest you change the line color or the background color so
they are not both white.

If this isn't the issue, can you explain what you mean by " something
a bit unusual"?

Thanks,

David



More information about the vtkusers mailing list