The addPlane() method for visualizing a plane either puts the plane in "some random location" or at a particular location if the user provides x,y,z value. However the size cannot be set/controlled by the user.
I can successfully add planes to my visualizer, however the size is extremely small. (note the other clouds are in millimeters). I saw related threads on PCL-users mailing list which suggest modifying the underlying VTK function.
For instance: the resulting plane in the attached figure is in white while other point-clouds are in red and blue.

Is there a way to control the size of the planes? Thanks!
Plane visualization in PCL is rudimentary at best. Unfortunately it's not possible to specify neither size nor "shape" of the plane.
Thanks @taketwo ! Any suggestions on how to modify the method to specify size, before I close this issue?
Under the hood, addPlane() creates a VTK data source object, generates a VTK dataset, and adds it to the visualizer. You can implement these steps yourself and have full control over the generated dataset.
Specifically, create a data source (vtkPlaneSource in this case):
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
Then you need to configure the source. See the available functions here. You'll need to change normal and center to position the plane and point1/point2 to scale it along axes. Finally, you need to generate data and add it to the visualizer:
plane->Update ();
visualizer.addModelFromPolyData (plane->GetOutput (), "actor-id");
Thanks again @taketwo, I managed to configure the addPlane() and the source as you suggested.
bool addPlane (const pcl::ModelCoefficients &coefficients, double x, double y, double z, double *point1, double *point2, const std::string &id = "plane", int viewport = 0);
vtkSmartPointer<vtkDataSet> pcl::visualization::createPlane(const pcl::ModelCoefficients &coefficients, double x, double y, double z, double *point1, double *point2)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
double norm_sqr = 1.0 / (coefficients.values[0] * coefficients.values[0] +
coefficients.values[1] * coefficients.values[1] +
coefficients.values[2] * coefficients.values[2]);
plane->SetNormal(coefficients.values[0], coefficients.values[1], coefficients.values[2]);
double t = x * coefficients.values[0] + y * coefficients.values[1] + z * coefficients.values[2] + coefficients.values[3];
x -= coefficients.values[0] * t * norm_sqr;
y -= coefficients.values[1] * t * norm_sqr;
z -= coefficients.values[2] * t * norm_sqr;
plane->SetOrigin(x, y, z);
plane->SetPoint1(point1);
plane->SetPoint2(point2);
plane->Update();
return (plane->GetOutput());
}
I'm not sure how to specify the point1 and point2 accordingly to scale the plane.
Disclaimer: I've never actually used this plane data source. I'd suggest to look at the default values of these points (specified here):
this->Point1[0] = 0.5;
this->Point1[1] = -0.5;
this->Point1[2] = 0.0;
this->Point2[0] = -0.5;
this->Point2[1] = 0.5;
this->Point2[2] = 0.0;
and try to play around with them.
Got it working! Thanks. :rocket:
Please share your code, this will be useful for others!
Hi @themightyoarfish, the related code is described here: https://github.com/PointCloudLibrary/pcl/issues/2938#issuecomment-474863560
So you simply used larger values for the Point1 and Point2 properties and that scales the plane? I suppose that could be merged to PCL then.
As far as I remember, yes.
Thanks for the code provided @prajval10, but how is it exactly used? Can I somehow add this externally, without modifying the pcl source code?
No you'll need to modify PCL code. I tried adding the changes to the functions creatig the Plane, but it didn't seem to have any effect. I probably did something wrong.
On 28 July 2020 17:01:43 CEST, "Evin P谋nar 脰rnek" notifications@github.com wrote:
Thanks for the code provided @prajval10, but how is it exactly used?
Can I somehow add this externally, without modifying the pcl source
code?--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/PointCloudLibrary/pcl/issues/2938#issuecomment-665092986
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
In case it's helpful to anyone, @Marcus-Davi has written a function that does it all in one go. I didn't need to edit PCL source code. He has commented out some parts but I tried them and it works great - https://github.com/Marcus-Davi/Cpp-PCL/blob/243b6d494d424677dfa3319ab2bb37a7d5572e21/src/plane.cpp

Most helpful comment
Under the hood,
addPlane()creates a VTK data source object, generates a VTK dataset, and adds it to the visualizer. You can implement these steps yourself and have full control over the generated dataset.Specifically, create a data source (
vtkPlaneSourcein this case):Then you need to configure the source. See the available functions here. You'll need to change normal and center to position the plane and point1/point2 to scale it along axes. Finally, you need to generate data and add it to the visualizer: