Page 1 of 1

How to draw a line?

Posted: Thu Mar 24, 2016 9:18 am
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.

Re: How to draw a line?

Posted: Thu Mar 24, 2016 11:02 am
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?

Re: How to draw a line?

Posted: Sat Mar 26, 2016 1:58 am
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,

Re: How to draw a line?

Posted: Sat Mar 26, 2016 8:17 pm
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').

Re: How to draw a line?

Posted: Tue Mar 29, 2016 7:09 am
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,

Re: How to draw a line?

Posted: Tue Mar 29, 2016 9:39 am
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.