I wanted to explore vtkPlaneSource’s interfaces SetPoint1 and SetPoint2 with visible 3D Axes.
It’s awkward to find that it’s difficult to control plane’s shape by interfaces SetPoint1 and SetPoint2 directly. So I used vtkAxesActor to show three axes in the world coordinate system.
#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkLight.h>
#include <vtkCamera.h>
#include <vtkActor2D.h>
#include <vtkPlaneSource.h>
#include <vtkAxesActor.h>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>
using namespace std;
int main()
{
vtkSmartPointer<vtkPlaneSource> source =
vtkSmartPointer<vtkPlaneSource>::New();
source->SetCenter( 0, 0, 0 );
source->SetPoint1( 0.5, -0.5, 0 );
source->SetPoint2( -0.5, 0.5, 0 );
source->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection( source->GetOutputPort() );
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper( mapper );
double *center = source->GetCenter();
double *pt1 = source->GetPoint1();
double *pt2 = source->GetPoint2();
printf( "center: (%lf, %lf, %lf)\n", center[0], center[1], center[2] );
printf( "pt1: (%lf, %lf, %lf)\n", pt1[0], pt1[1], pt1[2] );
printf( "pt2: (%lf, %lf, %lf)\n", pt2[0], pt2[1], pt2[2] );
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;
}
output:
center: (0.000000, 0.000000, 0.000000)
pt1: (0.500000, -0.500000, 0.000000)
pt2: (-0.500000, 0.500000, 0.000000)