1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | public : mepp_component_CGAL_Example_plugin() : mepp_component_plugin_interface() {} ~mepp_component_CGAL_Example_plugin() { delete actionStep_1; delete actionStep_2; delete actionStep_3; delete actionStep_4; delete actionStep_5; delete actionStep_6; delete actionStep_7; delete actionStep_8; delete actionStep_9; } void init(mainwindow* mainWindow, QList<QMdiSubWindow *> lw) { this ->mw = mainWindow; this ->lwindow = lw; this ->mPluginName = this ->metaObject()->className(); // choice: menuTools, menuDistance_Quality_measure, menuAnalysis_Filtering, menuSegmentation, menuRemeshing_Subdivision, menuCompression, menuWatermaking, menuExamples mParentMenu = mainWindow->menuExamples; // begin --- actions --- actionStep_1 = new QAction(tr( "Triangulate And Random Color Facets" ), this ); if (actionStep_1) connect(actionStep_1, SIGNAL(triggered()), this , SLOT(step1())); actionStep_2 = new QAction(tr( "Create Center Vertex" ), this ); if (actionStep_2) connect(actionStep_2, SIGNAL(triggered()), this , SLOT(step2())); actionStep_3 = new QAction(tr( "Show Black And White Facets" ), this ); if (actionStep_3) connect(actionStep_3, SIGNAL(triggered()), this , SLOT(step3())); actionStep_4 = new QAction(tr( "Draw Connections" ), this ); if (actionStep_4) connect(actionStep_4, SIGNAL(triggered()), this , SLOT(step4())); actionStep_5 = new QAction(tr( "Set Position And Orientation" ), this ); if (actionStep_5) connect(actionStep_5, SIGNAL(triggered()), this , SLOT(step5())); actionStep_6 = new QAction(tr( "New/Add Polyhedron" ), this ); if (actionStep_6) connect(actionStep_6, SIGNAL(triggered()), this , SLOT(step6())); actionStep_7 = new QAction(tr( "Load File From Component" ), this ); if (actionStep_7) connect(actionStep_7, SIGNAL(triggered()), this , SLOT(step7())); actionStep_8 = new QAction(tr( "Save File From Component" ), this ); if (actionStep_8) connect(actionStep_8, SIGNAL(triggered()), this , SLOT(step8())); actionStep_9 = new QAction(tr( "Sample to use Curvature component from this component" ), this ); if (actionStep_9) connect(actionStep_9, SIGNAL(triggered()), this , SLOT(step9())); // end --- actions --- } QList<QAction*> actions() const { return QList<QAction*>() << actionStep_1 << actionStep_2 << actionStep_3 << NULL // menu separator << actionStep_4 << actionStep_5 << NULL // menu separator << actionStep_6 << NULL // menu separator << actionStep_7 << actionStep_8 << NULL // menu separator << actionStep_9; } |
1 2 3 4 | // we want to use Curvature component #include "../../../Analysis/Curvature/src/Curvature_Component.h" typedef boost::shared_ptr<Curvature_Component> Curvature_ComponentPtr; // we want to use Curvature component |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | void mepp_component_CGAL_Example_plugin::step9() { // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); QApplication::setOverrideCursor(Qt::WaitCursor); // we use CGAL_Example component here (as usual) CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); component_ptr->TriangulateAndRandomColorFacets(polyhedron_ptr); component_ptr->set_init(2); // we use CGAL_Example component here (as usual) // we use Curvature component here bool IsGeo; double radius; Curvature_ComponentPtr component_ptr_curvature = findOrCreateComponentForViewer<Curvature_ComponentPtr, Curvature_Component>(viewer, polyhedron_ptr); // params radius = 0.001; IsGeo= true ; mw->statusBar()->showMessage(tr( "Curvature..." )); component_ptr_curvature->principal_curvature(polyhedron_ptr,IsGeo,radius); mw->statusBar()->showMessage(tr( "Curvature is done" )); component_ptr_curvature->set_init(2); component_ptr_curvature->ConstructColorMap(polyhedron_ptr,1); viewer->recreateListsAndUpdateGL(); // we use Curvature component here } QApplication::restoreOverrideCursor(); } |
1 2 | componentName = "CGAL_Example_Component" ; init = 1; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | void CGAL_Example_Component::TriangulateAndRandomColorFacets(PolyhedronPtr pMesh) { pMesh->triangulate(); //(1) srand ((unsigned) time (NULL)); Facet_iterator pFacet = NULL; //(2) for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { float rand255r = ( float ) rand () / ( float ) RAND_MAX; float rand255g = ( float ) rand () / ( float ) RAND_MAX; float rand255b = ( float ) rand () / ( float ) RAND_MAX; pFacet->color(rand255r, rand255g, rand255b); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | void mepp_component_CGAL_Example_plugin::step1() { QApplication::setOverrideCursor(Qt::WaitCursor); //(3) // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); //(4) CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); //(5) component_ptr->TriangulateAndRandomColorFacets(polyhedron_ptr); //(6) component_ptr->set_init(2); //(7) viewer->recreateListsAndUpdateGL(); } QApplication::restoreOverrideCursor(); //(8) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | void CGAL_Example_Component::CreateCenterVertex(PolyhedronPtr pMesh) { CSubdivider_sqrt3<Polyhedron,Enriched_kernel> subdivider; long dist, maxdist=0, mindist=ColourDistance(0, 0, 0, 255, 255, 255), mindist_pct; Facet_iterator pFacet = NULL; //(1) for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { pFacet->tag(0); dist = ColourDistance((unsigned char )round(color(0)*255.), (unsigned char )round(color(1)*255.), (unsigned char )round(color(2)*255.), (unsigned char )round(pFacet->color(0)*255.), (unsigned char )round(pFacet->color(1)*255.), (unsigned char )round(pFacet->color(2)*255.)); if (dist < mindist) mindist = dist; if (dist > maxdist) maxdist = dist; } int pct=3; mindist_pct=((maxdist-mindist)*pct/100)+mindist; //(2) int cpt = 1; for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { if (pFacet->tag()==0) { dist = ColourDistance((unsigned char )round(color(0)*255.), (unsigned char )round(color(1)*255.), (unsigned char )round(color(2)*255.), (unsigned char )round(pFacet->color(0)*255.), (unsigned char )round(pFacet->color(1)*255.), (unsigned char )round(pFacet->color(2)*255.)); if ((dist >= mindist) && (dist <= mindist_pct)) { pFacet->tag(1); Vertex_handle hVertex = subdivider.create_center_vertex(*pMesh, pFacet)->vertex(); //(3) float rand255r = ( float ) rand () / ( float ) RAND_MAX; float rand255g = ( float ) rand () / ( float ) RAND_MAX; float rand255b = ( float ) rand () / ( float ) RAND_MAX; hVertex->color(rand255r, rand255g, rand255b); } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | void mepp_component_CGAL_Example_plugin::step2() { // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); //(4) CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); //(5) QColor current_color( int (component_ptr->color(0)*255.), int (component_ptr->color(1)*255.), int (component_ptr->color(2)*255.)); QColor new_color = QColorDialog::getColor(current_color, viewer); //(6) if (new_color.isValid()) { component_ptr->color( float (new_color.red())/255., float (new_color.green())/255., float (new_color.blue())/255.); SettingsDialog_CGAL_Example dial; if (dial.exec() == QDialog::Accepted) //(7) { QApplication::setOverrideCursor(Qt::WaitCursor); int iteration = dial.Iteration->value(); mw->statusBar()->showMessage(tr( "Create center vertex..." )); //(8) for ( int p=0; p<viewer->getScenePtr()->get_nb_polyhedrons(); p++) //(9) for ( int i=0; i<iteration; i++) component_ptr->CreateCenterVertex(viewer->getScenePtr()->get_polyhedron(p), false ); mw->statusBar()->showMessage(tr( "Create center vertex...done" )); viewer->recreateListsAndUpdateGL(); QApplication::restoreOverrideCursor(); return ; } } mw->statusBar()->showMessage(tr( "Create center vertex...canceled" )); } QApplication::restoreOverrideCursor(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | void CGAL_Example_Component::ShowBlackAndWhiteFacets(PolyhedronPtr pMesh) { Facet_iterator pFacet = NULL; //(1) for (pFacet = pMesh->facets_begin(); pFacet != pMesh->facets_end(); pFacet++) { int all_tags_are_one; if (pFacet->tag()==1) { // circulate around facet Halfedge_around_facet_circulator he, end; he = end = pFacet->facet_begin(); all_tags_are_one=1; CGAL_For_all(he, end) //(2) { if (he->opposite()->face() != NULL) { if (he->opposite()->face()->tag()==0) //(3) { he->opposite()->face()->color(1., 1., 1.); all_tags_are_one=0; } } } if (all_tags_are_one) //(4) pFacet->color(0., 0., 0.); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | void mepp_component_CGAL_Example_plugin::step3() { QApplication::setOverrideCursor(Qt::WaitCursor); // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); component_ptr->ShowBlackAndWhiteFacets(polyhedron_ptr); //(5) viewer->recreateListsAndUpdateGL(); } QApplication::restoreOverrideCursor(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | void mepp_component_CGAL_Example_plugin::step4() { QApplication::setOverrideCursor(Qt::WaitCursor); // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); component_ptr->set_init(3); //(1) viewer->updateGL(); } QApplication::restoreOverrideCursor(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | void mepp_component_CGAL_Example_plugin::post_draw_all_scene() { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); if (doesExistComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr)) // important !!! { CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); if (component_ptr->get_init() == 3) //(2) { int nbMesh = qMin(viewer->getScenePtr()->get_nb_polyhedrons(), viewer->get_nb_frames()); if (nbMesh == 2) { glPushMatrix(); draw_connections(viewer, 0, 1); // link between first and second mesh (first and second frame) //(3) glPopMatrix(); } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | void mepp_component_CGAL_Example_plugin::step5() { QApplication::setOverrideCursor(Qt::WaitCursor); // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); Vec pw(2, 0, 0); viewer->frame(viewer->getScenePtr()->get_current_polyhedron())->setPosition(pw); // position in world coordinate system //(1) Quaternion qw(0, 0, 0, 1); // identity quaternion (i.e., no rotation) viewer->frame(viewer->getScenePtr()->get_current_polyhedron())->setOrientation(qw); // rotation in world coordinate system //(2) viewer->updateGL(); //(3) } QApplication::restoreOverrideCursor(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | void mepp_component_CGAL_Example_plugin::step6() { QApplication::setOverrideCursor(Qt::WaitCursor); // active viewer if (mw->activeMdiChild() != 0) //(1) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); // step 6a : begin emit(mw->get_actionAddEmpty()->trigger()); //(2) int nb_polyhedrons = viewer->getScenePtr()->get_nb_polyhedrons(); //(3) polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(nb_polyhedrons-1); component_ptr->CreateTetrahedron(polyhedron_ptr); viewer->getScenePtr()->setcurrentFile(tr( "internal mesh sample from empty" )); //(4) viewer->setDynTitle(); viewer->recreateListsAndUpdateGL(); //(5) // step 6a : end } else { // step 6b : begin emit(mw->get_actionNewEmpty()->trigger()); //(6) for ( int i=0; i<lwindow.size(); i++) // all viewers { Viewer* viewer = (Viewer *)qobject_cast<QWidget *>(lwindow[i]->widget()); if (viewer->getScenePtr()->get_polyhedron()->empty()) //(7) { PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); component_ptr->CreateTetrahedron(polyhedron_ptr); //(8) viewer->showAllScene(); //(9) viewer->getScenePtr()->setcurrentFile(tr( "internal mesh sample from empty" )); //(10) viewer->setDynTitle(); } } // step 6b : end } QApplication::restoreOverrideCursor(); } |
1 2 3 4 | void mepp_component_CGAL_Example_plugin::step7() { emit(mw->get_mainwindowActionOpen()->doSendParamsOpen(tr( "Open Mesh File(s) - from CGAL_Example" ), tr( "OFF files (*.off)" ), Normal, mepp_component_plugin_interface::load_file_from_component)); //(1) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | int mepp_component_plugin_interface::load_file_from_component(PolyhedronPtr polyhedron_ptr, QString filename, Viewer* viewer) { mepp_component_CGAL_Example_plugin *mepp_component_plugin = NULL; for ( int i=0; i<viewer->lplugin.size(); ++i) { if ( dynamic_cast <mepp_component_CGAL_Example_plugin*>(viewer->lplugin[i]) != 0) { mepp_component_plugin = dynamic_cast <mepp_component_CGAL_Example_plugin*>(viewer->lplugin[i]); //(2) } } int res; if (mepp_component_plugin) { CGAL_Example_ComponentPtr component_ptr = mepp_component_plugin->findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); //(3) res = polyhedron_ptr->load_mesh_off(filename.toStdString()); //(4) } else res=-1; return res; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | void mepp_component_CGAL_Example_plugin::step9() { // active viewer if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); QApplication::setOverrideCursor(Qt::WaitCursor); // we use CGAL_Example component here (as usual) //(1) CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); component_ptr->TriangulateAndRandomColorFacets(polyhedron_ptr); component_ptr->set_init(2); // we use CGAL_Example component here (as usual) // we use Curvature component here //(2) bool IsGeo; double radius; Curvature_ComponentPtr component_ptr_curvature = findOrCreateComponentForViewer<Curvature_ComponentPtr, Curvature_Component>(viewer, polyhedron_ptr); // params radius = 0.001; IsGeo= true ; mw->statusBar()->showMessage(tr( "Curvature..." )); component_ptr_curvature->principal_curvature(polyhedron_ptr,IsGeo,radius); mw->statusBar()->showMessage(tr( "Curvature is done" )); component_ptr_curvature->set_init(2); component_ptr_curvature->ConstructColorMap(polyhedron_ptr,1); viewer->recreateListsAndUpdateGL(); // we use Curvature component here } QApplication::restoreOverrideCursor(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | void CGAL_Example_Component::GetClickedVertices(PolyhedronPtr pMesh, double x, double y, int tolerance) { GLdouble *model ; GLdouble *proj ; GLint *view; view= new int [4096]; model= new double [4096]; proj= new double [4096]; glGetIntegerv (GL_VIEWPORT, view); //(1) glGetDoublev (GL_MODELVIEW_MATRIX, model); glGetDoublev (GL_PROJECTION_MATRIX, proj); y=view[3]-y; GLdouble wx ; GLdouble wy ; GLdouble wz; int vertexID=0; for (Vertex_iterator pVertex = pMesh->vertices_begin(); pVertex!= pMesh->vertices_end(); pVertex++) { gluProject (pVertex->point().x(),pVertex->point().y(),pVertex->point().z(), model, proj, view, &wx, &wy, &wz); // projection //(2) if (wz>0. && wz<1) if (x> floor (wx)-tolerance && x< floor (wx)+tolerance) if (y> floor (wy)-tolerance && y< floor (wy)+tolerance) // we set a small tolerance (2 * 5 pixels for example) for selection //(3) { pVertex->color(1., 0., 0.); //(4) } vertexID++; } delete []view; delete []model; delete []proj; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | void mepp_component_CGAL_Example_plugin::OnMouseLeftDown(QMouseEvent *event) { if (mw->activeMdiChild() != 0) { Viewer* viewer = (Viewer *)mw->activeMdiChild(); PolyhedronPtr polyhedron_ptr = viewer->getScenePtr()->get_polyhedron(); if (doesExistComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr)) // important !!! //(5) { mw->statusBar()->showMessage(tr( "mepp_component_CGAL_Example_plugin: OnMouseLeftDown" ), 1000); //(6) CGAL_Example_ComponentPtr component_ptr = findOrCreateComponentForViewer<CGAL_Example_ComponentPtr, CGAL_Example_Component>(viewer, polyhedron_ptr); if (viewer->getScenePtr()->get_loadType() == Normal) { component_ptr->GetClickedVertices(viewer->getScenePtr()->get_polyhedron(), event->x(), event->y(), 10); //(7) viewer->recreateListsAndUpdateGL(); } } } } |
1 2 3 4 5 | SettingsDialog_Votre_Composant dial; if (dial.exec() == QDialog::Accepted) { int iteration = dial.Iteration->value(); // 'Iteration' is a widget name (see above step) ... |
1 2 3 4 5 | SettingsDialogFunction_Your_Component dialFunction; if (dialFunction.exec() == QDialog::Accepted) { int iteration = dialFunction.Iteration->value(); ... |