[vtkusers] Some problems with visualizing vectors
    Luca Pamparana 
    luca.pamparana at gmail.com
       
    Thu Nov  5 11:38:18 EST 2009
    
    
  
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
    
    
More information about the vtkusers
mailing list