Results 1 to 2 of 2

Thread: Find the shortest path between 2 points in a mesh

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Find the shortest path between 2 points in a mesh

    Good morning,
    premising that I am completely new to 3d programming the only knowledge I have are the studies I did at university more than 20 years ago..
    I would like to develop a basic app able to import 3d mesh data from ply files and, after taking 2 points on the surface, should be able to find the shortest path between them.

    I started modifying the basicshapes-cpp Qt demo to import the polygon data from an external ply file instead of creating the shapes from coding.
    The basic app compile and run successfully, but when I load a shape from the files I have, I can not see it centered or I see it too small.

    Here the code I've used (code modified from basichapes-cpp demo):

    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication app(argc, argv);
    4. Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
    5. view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
    6. QWidget *container = QWidget::createWindowContainer(view);
    7. QSize screenSize = view->screen()->size();
    8. container->setMinimumSize(QSize(200, 100));
    9. container->setMaximumSize(screenSize);
    10.  
    11. QWidget *widget = new QWidget;
    12. QHBoxLayout *hLayout = new QHBoxLayout(widget);
    13. QVBoxLayout *vLayout = new QVBoxLayout();
    14. vLayout->setAlignment(Qt::AlignTop);
    15. hLayout->addWidget(container, 1);
    16. hLayout->addLayout(vLayout);
    17.  
    18. widget->setWindowTitle(QStringLiteral("Basic Mesh Viewer"));
    19.  
    20. Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
    21. view->registerAspect(input);
    22.  
    23. // Root entity
    24. Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
    25.  
    26. // Camera
    27. Qt3DRender::QCamera *cameraEntity = view->camera();
    28.  
    29. cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    30. cameraEntity->setPosition(QVector3D(0, 0, -1.0f));
    31. cameraEntity->setUpVector(QVector3D(0, 1, 0));
    32. cameraEntity->setViewCenter(QVector3D(0, 0, 0));
    33.  
    34. Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    35. Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    36. light->setColor("white");
    37. light->setIntensity(1);
    38. lightEntity->addComponent(light);
    39.  
    40. Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    41. lightTransform->setTranslation(cameraEntity->position());
    42. lightEntity->addComponent(lightTransform);
    43.  
    44. // Loading .ply data
    45. QUrl data = QUrl::fromLocalFile("monster.ply");
    46.  
    47. Qt3DRender::QMesh *bodyMesh = new Qt3DRender::QMesh();
    48. bodyMesh->setMeshName("bodyMesh");
    49. bodyMesh->setSource(data);
    50.  
    51. Qt3DCore::QTransform *bodyTransform = new Qt3DCore::QTransform;
    52. bodyTransform->setScale3D(QVector3D(10.0, 10.0, 10.0));
    53.  
    54. Qt3DExtras::QPhongMaterial *bodyMaterial = new Qt3DExtras::QPhongMaterial();
    55. bodyMaterial->setDiffuse(QColor(QRgb(0x928327)));
    56.  
    57. Qt3DCore::QEntity *plyEntity = new Qt3DCore::QEntity(rootEntity);
    58. plyEntity->addComponent(bodyMesh);
    59. plyEntity->addComponent(bodyMaterial);
    60. plyEntity->addComponent(bodyTransform);
    61.  
    62. // Set root object of the scene
    63. view->setRootEntity(rootEntity);
    64.  
    65. // Show window
    66. widget->show();
    67. widget->resize(1200, 800);
    68.  
    69. return app.exec();
    70. }
    To copy to clipboard, switch view to plain text mode 

    I would like to have the following help:
    * Understand why I see the shape infinitely small and how to fix it
    * Understand how I can center the shape in the screen and big enough so I can see it well
    * Understand how to add mouse interaction so I can zoom/move the scene
    * After a mouse left click, understand how I can get the coordinates of a specific polygon so that a shortest path algorithm can be applied.
    Thank you very much
    Franco Amato

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Find the shortest path between 2 points in a mesh

    I would look at the coordinates of the object you are trying to import and see how those compare with the coordinates you have set for your camera's front and back planes and camera position. Either the imported object's dimensions are tiny or it is in the far distance in the viewing frustrum compared to the camera location.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. text path points
    By amitpatel22 in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2011, 14:38
  2. add points/path to QGraphicsView
    By szisziszilvi in forum Qt Programming
    Replies: 6
    Last Post: 13th January 2011, 14:35
  3. Replies: 1
    Last Post: 21st December 2010, 23:04
  4. Problem to find file path
    By phillip_Qt in forum Qt Programming
    Replies: 14
    Last Post: 28th April 2008, 11:06
  5. Find users home path
    By zyrotron in forum Newbie
    Replies: 2
    Last Post: 21st March 2007, 21:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.