I don’t know the difference between center and origin in vtkPlane when I use it in my project for the first time.
I thought the center of the plane is its origin until today, it’s the reason why I could not get a correct rectangle when I tried to set origin at (0.5, 0.5, 0), p1 at (0, 1, 0) and p2 at (1, 0, 0).
If we want to draw a rectangle with vtkPlaneSource, we have two methods to do it as I know.

The first one is to set center (0.5, 0.5, 0) for vtkPlaneSource object firstly, then calculate the normal (0, 0, 1) and set it. If we want to change its size, just to use an actor to scale and move position. The details can be found in my previous article’s second part Create A Big Plane By Center And Normal: Use vtkPlaneSource.
The other way is to define three important points, the origin, point1, and point2 for the vtkPlaneSource object, after that the size of the rectangle can also be defined.
Here are the implementation details for it.

int main()
{
    setbuf( stdout, nullptr );

    vtkSmartPointer<vtkPlaneSource> planeSource =
            vtkSmartPointer<vtkPlaneSource>::New();
    planeSource->SetOrigin( 0, 0, 0 );
    planeSource->SetPoint1( 0, 1, 0 );
    planeSource->SetPoint2( 1, 0, 0 );
    planeSource->Update();

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

    vtkSmartPointer<vtkActor> actor =
            vtkSmartPointer<vtkActor>::New();
    actor->SetMapper( mapper );

    vtkSmartPointer<vtkAxesActor> axesActor =
            vtkSmartPointer<vtkAxesActor>::New();

    vtkSmartPointer<vtkRenderer> renderer =
            vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor( actor );
    renderer->AddActor( axesActor );

    renderer->SetBackground( 0, 0, 0 );

    vtkSmartPointer<vtkRenderWindow> renderWindow =
            vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer( renderer );

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
            vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow( renderWindow );

    renderer->ResetCamera();
    renderWindow->Render();

    renderWindowInteractor->Start();
    return 0;
}
Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x