void Ui::openComponentDialog() { addComponentDialog = new QDialog(this); // set as child of Ui, to be sure that it will be deleted in the end. QVBoxLayout *dialogLayout = new QVBoxLayout; // create vertical layout QVTKWidget *dialogVisualizer = new QVTKWidget; // create qvtk widget dialogViewer = new pcl::visualization::PCLVisualizer("Dialog Viewer", false); dialogVisualizer->SetRenderWindow(dialogViewer->getRenderWindow()); // set as render window the render window of the dialog visualizer dialogViewer->setupInteractor(dialogVisualizer->GetInteractor(), dialogVisualizer->GetRenderWindow()); // tells the visualizer what interactor is using now and for what window dialogViewer->getInteractorStyle()->setKeyboardModifier(pcl::visualization::INTERACTOR_KB_MOD_SHIFT); // ripristina input system of original visualizer (shift+click for points) pcl::PointCloud<pcl::PointXYZRGB>::Ptr temp = motor->getTargetCloud(); pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(temp); dialogViewer->addPointCloud<pcl::PointXYZRGB>(temp, rgb, "cloud"); dialogViewer->setBackgroundColor(0.5, 0.5, 0.5); dialogViewer->initCameraParameters(); dialogViewer->resetCamera(); componentCallbackConnection = dialogViewer->registerPointPickingCallback(&pointPickCallback, this); // callback standard non segmenta nulla QLineEdit *addComponentDialogName = new QLineEdit("Insert Component Name"); addComponentDialogName->setObjectName("componentname"); QHBoxLayout *dialogControlsLayout = new QHBoxLayout; QVBoxLayout *buttonsBox = new QVBoxLayout; QPushButton *selectPointButton = new QPushButton("Select Component"); connect(selectPointButton, SIGNAL(clicked()), this, SLOT(setComponentDialogCallback())); QPushButton *resetButton = new QPushButton("Reset Selection"); connect(resetButton, SIGNAL(clicked()), this, SLOT(resetComponentDialogCallback())); buttonsBox->addWidget(selectPointButton); buttonsBox->addWidget(resetButton); QVBoxLayout *numbersBox = new QVBoxLayout; QColor *selectedColor = new QColor(0, 0, 0, 255); // initialize color at black QPushButton *colorBox = new QPushButton("+-100"); colorBox->setObjectName("colorbox"); colorBox->setStyleSheet(colorToStyleSheet(selectedColor)); colorBox->setMaximumWidth(50); QLineEdit *clusterBox = new QLineEdit("1"); clusterBox->setReadOnly(true); clusterBox->setObjectName("clusterbox"); clusterBox->setMaxLength(5); clusterBox->setMaximumWidth(50); numbersBox->addWidget(clusterBox); numbersBox->addWidget(colorBox); QVBoxLayout *slidersBox = new QVBoxLayout; QSlider *setCluThresholdBar = new QSlider(Qt::Horizontal); setCluThresholdBar->setRange(0,5000); setCluThresholdBar->setValue(1000); motor->setClusterSegThreshold(1000); setCluThresholdBar->setObjectName("sliderCluster"); connect(setCluThresholdBar, SIGNAL(sliderReleased()), this, SLOT(setClusterThreshold())); QSlider *setColThresholdBar = new QSlider(Qt::Horizontal); setColThresholdBar->setRange(0,255); setColThresholdBar->setValue(100); motor->setColorSegThreshold(100); setColThresholdBar->setObjectName("sliderColor"); connect(setColThresholdBar, SIGNAL(sliderReleased()), this, SLOT(setColorThreshold())); slidersBox->addWidget(setCluThresholdBar); slidersBox->addWidget(setColThresholdBar); QPushButton *showSegButton = new QPushButton("Segment!"); connect(showSegButton, SIGNAL(clicked()), this, SLOT(segmentComponent())); dialogControlsLayout->addLayout(buttonsBox); dialogControlsLayout->addLayout(numbersBox); dialogControlsLayout->addLayout(slidersBox); dialogControlsLayout->addWidget(showSegButton); QPushButton *saveComponent = new QPushButton("Save to component list"); saveComponent->setDefault(true); // default button, pressed if enter is pressed connect(saveComponent, SIGNAL(clicked()), this, SLOT(saveComponent())); dialogLayout->addWidget(dialogVisualizer); dialogLayout->addWidget(addComponentDialogName); dialogLayout->addLayout(dialogControlsLayout); dialogLayout->addWidget(saveComponent); addComponentDialog->setLayout(dialogLayout); // DIALOG EXECUTION // addComponentDialog->deleteLater(); // delete dialog when the control returns to the event loop from which deleteLater() was called (after exec i guess) // causa seg fault se viene attivata la callback dialogLayout->deleteLater(); // delete dialog layout when the control returns to the event loop from which deleteLater() was called (after exec i guess) addComponentDialog->resize(800,600); addComponentDialog->exec(); componentCallbackConnection.disconnect(); // disconnect the callback function from the viewer delete dialogViewer; // finita l'esecuzione, deallocare il viewer (deallocare altra eventuale memoria non indirizzata nel QObject tree). }
void Ui::openDiffDialog() { diffDialog = new QDialog(this); // set as child of Ui, to be sure that it will be deleted in the end. QVBoxLayout *diffDialogLayout = new QVBoxLayout; // create vertical layout QVTKWidget *dialogVisualizer = new QVTKWidget; // create qvtk widget dialogViewer = new pcl::visualization::PCLVisualizer("Dialog Viewer", false); dialogVisualizer->SetRenderWindow(dialogViewer->getRenderWindow()); // set as render window the render window of the dialog visualizer dialogViewer->setupInteractor(dialogVisualizer->GetInteractor(), dialogVisualizer->GetRenderWindow()); // tells the visualizer what interactor is using now and for what window dialogViewer->getInteractorStyle()->setKeyboardModifier(pcl::visualization::INTERACTOR_KB_MOD_SHIFT); // ripristina input system of original visualizer (shift+click for points) pcl::PointCloud<pcl::PointXYZRGB>::Ptr regCloud = motor->getRegisteredCloud(); pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(regCloud); pcl::PointCloud<pcl::PointXYZRGB>::Ptr diffCloud = motor->getSourceDiffCloud(); pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> green(diffCloud, 0, 255, 0); pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> red(diffCloud, 255, 0, 0); int v1(0); int v2(0); dialogViewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1); dialogViewer->setBackgroundColor(0.5, 0.5, 0.5, v1); dialogViewer->addText("TARGET CLOUD", 30, 20,"TARGET CLOUD",v1); dialogViewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2); dialogViewer->setBackgroundColor(0.5, 0.5, 0.5, v2); dialogViewer->addText("SOURCE CLOUD", 30, 20,"SOURCE CLOUD",v2); dialogViewer->addPointCloud<pcl::PointXYZRGB>(motor->getTargetCloud(), rgb, "targetCloud", v1); dialogViewer->addPointCloud<pcl::PointXYZRGB>(diffCloud, red, "targetDiffCloud", v1); dialogViewer->addPointCloud<pcl::PointXYZRGB>(regCloud, rgb, "sourceCloud", v2); dialogViewer->addPointCloud<pcl::PointXYZRGB>(diffCloud, green, "sourceDiffCloud", v2); dialogViewer->initCameraParameters(); dialogViewer->resetCamera(); componentCallbackConnection = dialogViewer->registerPointPickingCallback(&pointPickCallback, this); // callback standard non segmenta nulla QHBoxLayout *dialogControlsLayout = new QHBoxLayout; QVBoxLayout *numbersBox = new QVBoxLayout; QLineEdit *segDiffBox = new QLineEdit("0.5"); segDiffBox->setReadOnly(true); segDiffBox->setObjectName("segdiffbox"); segDiffBox->setMaxLength(5); segDiffBox->setMaximumWidth(50); numbersBox->addWidget(segDiffBox); QVBoxLayout *slidersBox = new QVBoxLayout; QSlider *setSegDiffThresholdBar = new QSlider(Qt::Horizontal); setSegDiffThresholdBar->setRange(0, 5000); setSegDiffThresholdBar->setValue(500); motor->setSegDiffThreshold(500); setSegDiffThresholdBar->setObjectName("sliderSegDiff"); connect(setSegDiffThresholdBar, SIGNAL(sliderReleased()), this, SLOT(setSegDiffThreshold())); slidersBox->addWidget(setSegDiffThresholdBar); dialogControlsLayout->addLayout(numbersBox); dialogControlsLayout->addLayout(slidersBox); QPushButton *segmentDiffButton = new QPushButton("Segment differences"); segmentDiffButton->setDefault(true); // default button, pressed if enter is pressed connect(segmentDiffButton, SIGNAL(clicked()), this, SLOT(segmentDiff())); diffDialogLayout->addWidget(dialogVisualizer); diffDialogLayout->addLayout(dialogControlsLayout); diffDialogLayout->addWidget(segmentDiffButton); diffDialog->setLayout(diffDialogLayout); diffDialogLayout->deleteLater(); // delete dialog layout when the control returns to the event loop from which deleteLater() was called (after exec i guess) diffDialog->resize(800,600); diffDialog->exec(); componentCallbackConnection.disconnect(); // disconnect the callback function from the viewer delete dialogViewer; // finita l'esecuzione, deallocare il viewer (deallocare altra eventuale memoria non indirizzata nel QObject tree). }