How to draw a line?

Feel free to ask any question here
Post Reply
Eiji Kurihara
Posts: 24
Joined: Mon Mar 14, 2016 1:35 am

How to draw a line?

Post by Eiji Kurihara »

I would like to draw 3D line. But first I try to draw 2D line. In the void qMyPlugin::doAction() function,
I inserted the following sentences.
QCPPainter *painter = new QCPPainter() ;
QColor red(255,0,0) ;
painter->setPen(red) ;
painter->drawLine( QLineF(0, 0, 1000, 100) ) ;
m_app->redrawAll(true) ;
But the line is not appeared on the CloudCompare viewer scrren.
After that I Put
m_app->dispToConsole("[qMyPlugin] My plugin is here") ;
This message is appeared in Console window.
Probably, my sentences are something lack.
Please give me a good advice.
daniel
Site Admin
Posts: 7721
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to draw a line?

Post by daniel »

CloudCompare's 3D views are not 'standard' Qt widgets with a painter. You have to display things with OpenGL.

In effect CloudCompare (via the qCC_db library) has several entities to simplify your life. For instance you can display 2D and 3D lines with the 'ccPolyline' entity.

To display an entity you have to first add it to main database or to the 3D view's local database. Then you have to explicitly set in which 3D view the entity should be displayed (with 'setDisplay').

It would be easier for you to look at other plugins and methods and see how they work.

What do you want to do exactly?
Daniel, CloudCompare admin
Eiji Kurihara
Posts: 24
Joined: Mon Mar 14, 2016 1:35 am

Re: How to draw a line?

Post by Eiji Kurihara »

I am just practicing how to program your CloudCompare, and drawing a line seems to me fundamental.
I put a code
ccGLWindow* win = MainWindow::GetActiveGLWindow() ;
ccColor::Rgb red = ccColor::red ;
CCVector3 vec0( 0, 0, 0 ), vec1( 1000, 200, 0 ) ;
ccPointCloud *ptCloud = new ccPointCloud("2 Points");
ptCloud->addPoint( vec0 ) ;
ptCloud->addPoint( vec1 ) ;
ccPolyline *poly = new ccPolyline( ptCloud ) ;
poly->setColor( red ) ;
poly->setDisplay( (ccGenericGLDisplay*) win ) ;
under the ccGLTest.cpp file in QCC_GL_LIB.
I succeed to build in QCC_GL_LIB.
However, calling this function from qMyPlugin.cpp, I cannot build QMY_PLUGIN with the message
"unresolved MainWindow::GetActiveGLWindow(void) "
I thought I should add some "*.lib" in the linker of QMY_PLUGIN. But I cannot succeed it yet.
I am grateful if you give me some advice.
Sincerely,
daniel
Site Admin
Posts: 7721
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to draw a line?

Post by daniel »

Hi,

The CloudCompare project is an executable and therefore you can't use its code or functions in another component.

This is why plugins cn only use the code from the libraries of the project (CC_CORE_LIB, qCC_db, qCC_gl, qCC_io, etc.). But plugins can also access to some of the functionalities of the main application (CloudCompare) dynamically. You can do this through the 'm_app' member of all plugins.

The 'm_app' class is 'ccMainAppInterface'. You can look at its methods here:
https://github.com/cloudcompare/trunk/b ... nterface.h

So instead of calling 'MainWindow::GetActiveGLWindow()', you should call 'm_app->getActiveGLWindow()'.

And to make your example work, you'll have to add:
  • 'poly->addPointIndex(0, 2);' --> to tell the polyline object to connect the two first points of the associated cloud
  • 'win->addToOwnDB(poly);' --> to tell the window to display the polyline (alternatively you can add the polyline to the main database - with 'm_app->addToDB(poly);' in which case it will be automatically displayed in the window you set with 'setDisplay').
Daniel, CloudCompare admin
Eiji Kurihara
Posts: 24
Joined: Mon Mar 14, 2016 1:35 am

Re: How to draw a line?

Post by Eiji Kurihara »

Thank you for your advice. By fixing as you told, there is an error message about GenericChunkedArray.h Line:425
Assert(m_count < m_capacity) . Hence before adding ptCloud->addPoint( vec0 ) ;
by inserting ptCloud->reserve(3) ;
I can get the line segment on the CloudCompare screen window.
I cannot use my debug version according to "the viewer id = 2 is not supported", so I cannot pursue the program.
But finally, I can draw a line. Thank you for your help.
My company's boss Yamamoto told me to donate to your CloudCompare in near future.
Sincerely,
daniel
Site Admin
Posts: 7721
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to draw a line?

Post by daniel »

Indeed, you have to reserve the memory for storing the points/vertices.

I'm not sure what is this "the viewer id = 2 is not supported" error? Is it an error from CloudCompare?

Anyway don't hesitate to ask me for more information anytime.
Daniel, CloudCompare admin
Post Reply