国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

這篇具有很好參考價值的文章主要介紹了VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

程序示例精選

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

如需安裝運行環(huán)境或遠(yuǎn)程調(diào)試,見文章底部個人QQ名片,由專業(yè)技術(shù)人員遠(yuǎn)程協(xié)助!

前言

這篇博客針對<<VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序>>編寫代碼,代碼整潔,規(guī)則,易讀。 學(xué)習(xí)與應(yīng)用推薦首選。

功能:讀取三維網(wǎng)格數(shù)據(jù),包括*.obj、*.stl、*.off,通過單擊網(wǎng)格表面高亮顯示單個頂點和多個頂點以及單個面和面法線,顯示帶/不帶線框的網(wǎng)格數(shù)據(jù),顯示點數(shù)、面數(shù)和邊數(shù),ICP算法與半自動分割算法的實現(xiàn)。


文章目錄

一、所需工具軟件

二、使用步驟

????????1. 引入庫

????????2. 代碼實現(xiàn)

? ? ? ? 3. 運行結(jié)果

三、在線協(xié)助

一、所需工具軟件

1. VS, Qt

2. VTK

二、使用步驟

1.引入庫

#include <QtCore/QStringList>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>

#include <vtkAppendPolyData.h>
#include <vtkCellData.h>
#include <vtkExtractEdges.h>
#include <vtkIdTypeArray.h>
#include <vtkMath.h>
#include <vtkLineSource.h>
#include <vtkLookupTable.h>
#include <vtkMatrix4x4.h>
#include <vtkNew.h>
#include <vtkOBJReader.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkScalarBarActor.h>
#include <vtkSphereSource.h>
#include <vtkSTLReader.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>

#include <iomanip>
#include <sstream>

#include "icp_algorithm.h"
#include "mesh_operation.h"
#include "mesh_segmenter.h"
#include "vtkOFFReader.h"

2. 代碼實現(xiàn)

代碼如下:

void MeshProcessing::OnWireframeMode() {
	bool isChecked = this->wireframe_mode_action_->isChecked();
	for (auto actor : this->mesh_processing_data_model_->wireframe_actor_vec_)
		actor->SetVisibility(isChecked);
	this->vtk_widget_->update();
}

void MeshProcessing::OnObserveMode() {
	this->removeVertexActors();
	this->removeFaceActors();
	this->removeMultiVertexActors();
	this->removeFillRegionFaceActors();
	this->mesh_processing_data_model_->pick_mode_ = MeshProcessingDataModel::OBSERVE;
	this->vtk_widget_->updateTopText();
}

void MeshProcessing::OnVertexMode() {
	this->removeFaceActors();
	this->removeMultiVertexActors();
	this->removeFillRegionFaceActors();
	this->mesh_processing_data_model_->pick_mode_ = MeshProcessingDataModel::VERTEX;
	this->vtk_widget_->updateTopText();
}

void MeshProcessing::OnFaceMode() {
	this->removeVertexActors();
	this->removeMultiVertexActors();
	this->removeFillRegionFaceActors();
	this->mesh_processing_data_model_->pick_mode_ = MeshProcessingDataModel::FACE;
	this->vtk_widget_->updateTopText();
}

void MeshProcessing::OnMultiVertexMode() {
	this->removeVertexActors();
	this->removeFaceActors();
	this->removeFillRegionFaceActors();
	this->mesh_processing_data_model_->pick_mode_ = MeshProcessingDataModel::MULTI_VERTEX;
	this->vtk_widget_->updateTopText();
}

void MeshProcessing::OnDisplayNormal() {
	if (this->mesh_processing_data_model_->pick_mode_ != MeshProcessingDataModel::FACE ||
		this->mesh_processing_data_model_->selected_face_id_ == -1) {
		QMessageBox::warning(this, QString::fromLocal8Bit("警告"), QString::fromLocal8Bit("請在面拾取模式中選取一個面片!"));
		return;
	}

	int cellId = this->mesh_processing_data_model_->selected_face_id_;
	vtkCell * cell = this->mesh_processing_data_model_->combined_mesh_->GetCell(cellId);

	double p0[3], p1[3], p2[3];
	this->mesh_processing_data_model_->combined_mesh_->GetPoint(cell->GetPointId(0), p0);
	this->mesh_processing_data_model_->combined_mesh_->GetPoint(cell->GetPointId(1), p1);
	this->mesh_processing_data_model_->combined_mesh_->GetPoint(cell->GetPointId(2), p2);

	double c[3];
	for (int i = 0; i < 3; ++i) c[i] = (p0[i] + p1[i] + p2[i]) / 3;

	double p0p1[3], p0p2[3];
	vtkMath::Subtract(p1, p0, p0p1);
	vtkMath::Subtract(p2, p0, p0p2);

	double normal[3];
	vtkMath::Cross(p0p1, p0p2, normal);
	vtkMath::Normalize(normal);

	double constant = (
		std::sqrt(vtkMath::Distance2BetweenPoints(p0, p1)) +
		std::sqrt(vtkMath::Distance2BetweenPoints(p1, p2)) +
		std::sqrt(vtkMath::Distance2BetweenPoints(p2, p0))
	);
	double e[3];
	for (int i = 0; i < 3; ++i) e[i] = c[i] + constant * normal[i];

	vtkSmartPointer<vtkLineSource> lineSource =
		vtkSmartPointer<vtkLineSource>::New();
	lineSource->SetPoint1(c);
	lineSource->SetPoint2(e);
	lineSource->Update();

	this->mesh_processing_data_model_->selected_face_normal_actor_ = this->vtk_widget_->addActor(lineSource->GetOutput());
	this->mesh_processing_data_model_->selected_face_normal_actor_->GetProperty()->SetColor(.8, .8, .2);
	this->mesh_processing_data_model_->selected_face_normal_actor_->GetProperty()->SetLineWidth(5);

	this->vtk_widget_->update();
}

void MeshProcessing::OnDefaultMode() {
	this->mesh_processing_data_model_->display_mode_ = MeshProcessingDataModel::DEFAULT;
	if (this->mesh_processing_data_model_->highlight_vec_[0] == 1)
		this->vtk_widget_->highlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	else
		this->vtk_widget_->unhighlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	this->vtk_widget_->update();
}

void MeshProcessing::OnDiscreteMode() {
	if (this->mesh_processing_data_model_->actor_vec_.size() != 1) {
		QMessageBox::critical(this, QString::fromLocal8Bit("錯誤"), QString::fromLocal8Bit("請檢查目前讀入的網(wǎng)格數(shù)是否為1!"));
		return;
	}

	this->mesh_processing_data_model_->display_mode_ = MeshProcessingDataModel::DISCRETE;
	this->mesh_processing_data_model_->mesh_vec_[0] = this->color_table_handler_->turnToDiscrete();

	this->mesh_processing_data_model_->hueLut = vtkSmartPointer<vtkLookupTable>::New();
	this->mesh_processing_data_model_->hueLut->SetNumberOfTableValues(this->color_table_handler_->maxScalar() - this->color_table_handler_->minScalar() + 1);
	this->mesh_processing_data_model_->hueLut->Build();

	for (int i = 0; i < this->color_table_handler_->maxScalar() - this->color_table_handler_->minScalar() + 1; ++i) {
		double hue = i * 1.0 / (this->color_table_handler_->maxScalar() - this->color_table_handler_->minScalar() + 1);
		double r, g, b;
		vtkMath::HSVToRGB(hue, 1.0, 1.0, &r, &g, &b);
		this->mesh_processing_data_model_->hueLut->SetTableValue(i, r, g, b, 1);
	}

	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetScalarRange(0, this->color_table_handler_->maxScalar() - this->color_table_handler_->minScalar() + 1);
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetScalarModeToUseCellData();
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetColorModeToMapScalars();
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetLookupTable(this->mesh_processing_data_model_->hueLut);

	if (this->mesh_processing_data_model_->highlight_vec_[0] == 1)
		this->vtk_widget_->highlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	else
		this->vtk_widget_->unhighlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	this->vtk_widget_->update();
}

void MeshProcessing::OnContinuousMode() {
	if (this->mesh_processing_data_model_->actor_vec_.size() != 1) {
		QMessageBox::critical(this, QString::fromLocal8Bit("錯誤"), QString::fromLocal8Bit("請檢查目前讀入的網(wǎng)格數(shù)是否為1!"));
		return;
	}

	this->mesh_processing_data_model_->display_mode_ = MeshProcessingDataModel::CONTINUOUS;
	this->mesh_processing_data_model_->mesh_vec_[0] = this->color_table_handler_->turnToContinuous();

	this->mesh_processing_data_model_->hueLut = vtkSmartPointer<vtkLookupTable>::New();
	this->mesh_processing_data_model_->hueLut->SetTableRange(this->color_table_handler_->minScalar(), this->color_table_handler_->maxScalar() + 1);
	this->mesh_processing_data_model_->hueLut->SetHueRange(0, 1);
	this->mesh_processing_data_model_->hueLut->SetSaturationRange(1, 1);
	this->mesh_processing_data_model_->hueLut->SetValueRange(1, 1);
	this->mesh_processing_data_model_->hueLut->Build();

	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetScalarRange(this->color_table_handler_->minScalar(), this->color_table_handler_->maxScalar() + 1);
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetScalarModeToUseCellData();
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetColorModeToMapScalars();
	this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->SetLookupTable(this->mesh_processing_data_model_->hueLut);

	if (this->mesh_processing_data_model_->highlight_vec_[0] == 1)
		this->vtk_widget_->highlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	else
		this->vtk_widget_->unhighlightMesh(this->mesh_processing_data_model_->actor_vec_[0]);
	this->vtk_widget_->update();
}

void MeshProcessing::OnICPRegistration() {
	std::vector<int> active_ids;
	for (int i = 0; i < this->mesh_processing_data_model_->highlight_vec_.size(); ++i) {
		if (this->mesh_processing_data_model_->highlight_vec_[i])
			active_ids.push_back(i);
	}

	if (active_ids.size() != 2) {
		QMessageBox::warning(this, QString::fromLocal8Bit("警告"), QString::fromLocal8Bit("請檢查目前選中的網(wǎng)格數(shù)是否為2!"));
		return;
	}

	this->wireframe_mode_action_->setChecked(false);
	OnWireframeMode();
	this->disableAllActions();
	this->OnObserveMode();
	this->register_scroll_area_->setVisible(true);

	this->mesh_processing_data_model_->source_id = active_ids.front();
	this->mesh_processing_data_model_->target_id = active_ids.back();

	this->mesh_processing_data_model_->actor_vec_[this->mesh_processing_data_model_->target_id]->GetProperty()->SetColor(.8, .2, .2);
	this->vtk_widget_->update();

	this->tab_widget_->setTabEnabled(0, false);
	this->tab_widget_->setTabEnabled(1, true);
	this->tab_widget_->setCurrentIndex(1);
}

void MeshProcessing::OnSegment() {
	if (this->mesh_processing_data_model_->mesh_vec_.size() != 1) {
		QMessageBox::critical(this, QString::fromLocal8Bit("錯誤"), QString::fromLocal8Bit("請檢查目前讀入的網(wǎng)格數(shù)是否為1!"));
		return;
	}

	this->wireframe_mode_action_->setChecked(false);
	OnWireframeMode();
	this->disableAllActions();
	this->OnObserveMode();

	if (this->color_table_handler_ != nullptr) {
		this->default_mode_action_->setEnabled(false);
		this->discrete_mode_action_->setEnabled(false);
		this->continuous_mode_action_->setEnabled(false);
		this->OnDefaultMode();
	}

	this->segment_scroll_area_->setVisible(true);
	this->cluster_num_slider_->setEnabled(false);

	this->mesh_processing_data_model_->segment_id = 0;

	this->tab_widget_->setTabEnabled(0, false);
	this->tab_widget_->setTabEnabled(1, true);
	this->tab_widget_->setCurrentIndex(1);
}

void MeshProcessing::OnFillRegionThreeVertices() {
	this->removeFillRegionFaceActors();

	for (int i = 0; i < this->mesh_processing_data_model_->combined_mesh_->GetNumberOfCells(); ++i) {
		vtkSmartPointer<vtkIdList> ptIds =
			vtkSmartPointer<vtkIdList>::New();
		this->mesh_processing_data_model_->combined_mesh_->GetCellPoints(i, ptIds);

		int validNum = 0;
		for (int k = 0; k < 3; ++k)
			validNum += this->mesh_processing_data_model_->selected_multi_vertex_set_.find(ptIds->GetId(k)) != this->mesh_processing_data_model_->selected_multi_vertex_set_.end() ? 1 : 0;

		if (validNum == 3) {
			this->mesh_processing_data_model_->fill_region_face_actor_vec_.push_back(this->vtk_widget_->highlightFace(this->mesh_processing_data_model_->combined_mesh_, i));
			this->mesh_processing_data_model_->fill_region_face_actor_vec_.back()->GetProperty()->SetColor(.8, .8, .2);
		}
	}

	this->vtk_widget_->update();
}

void MeshProcessing::OnFillRegionTwoVertices() {
	this->removeFillRegionFaceActors();

	for (int i = 0; i < this->mesh_processing_data_model_->combined_mesh_->GetNumberOfCells(); ++i) {
		vtkSmartPointer<vtkIdList> ptIds =
			vtkSmartPointer<vtkIdList>::New();
		this->mesh_processing_data_model_->combined_mesh_->GetCellPoints(i, ptIds);

		int validNum = 0;
		for (int k = 0; k < 3; ++k)
			validNum += this->mesh_processing_data_model_->selected_multi_vertex_set_.find(ptIds->GetId(k)) != this->mesh_processing_data_model_->selected_multi_vertex_set_.end() ? 1 : 0;

		if (validNum >= 2) {
			this->mesh_processing_data_model_->fill_region_face_actor_vec_.push_back(this->vtk_widget_->highlightFace(this->mesh_processing_data_model_->combined_mesh_, i));
			this->mesh_processing_data_model_->fill_region_face_actor_vec_.back()->GetProperty()->SetColor(.8, .8, .2);
		}
	}

	this->vtk_widget_->update();
}

void MeshProcessing::OnListWidgetModelItemChanged(QListWidgetItem * item) {
	int row_id = this->list_widget_model_->row(item);

	if (item->checkState() == Qt::Unchecked) {
		this->vtk_widget_->unhighlightMesh(this->mesh_processing_data_model_->actor_vec_[row_id]);
		this->mesh_processing_data_model_->highlight_vec_[row_id] = 0;
	} else {
		this->vtk_widget_->highlightMesh(this->mesh_processing_data_model_->actor_vec_[row_id]);
		this->mesh_processing_data_model_->highlight_vec_[row_id] = 1;
	}

	this->resetParameters();

	this->vtk_widget_->update();
}

void MeshProcessing::OnRunICP() {
	ICPAlgorithm icp;
	icp.setSource(this->mesh_processing_data_model_->mesh_vec_[this->mesh_processing_data_model_->source_id]);
	icp.setTarget(this->mesh_processing_data_model_->mesh_vec_[this->mesh_processing_data_model_->target_id]);
	if (this->move_center_radio_button_->isChecked())
		icp.moveCenterOn();
	else
		icp.moveCenterOff();
	icp.setMaxIter(this->max_iter_spin_box_->value());
	icp.setMinError(this->min_error_double_spin_box_->value());
	icp.registration();

	vtkMatrix4x4 * transform_matrix = icp.getTransformMatrix();
	
	std::ostringstream oss;
	oss << setprecision(2);
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) oss << transform_matrix->GetElement(i, j) << "\t";
		oss << std::endl;
	}

	this->iter_num_label_->setText(QString::number(icp.getIterNum()));
	this->error_label_->setText(QString::number(icp.getError()));
	this->matrix_label_->setText(QString::fromStdString(oss.str()));

	vtkSmartPointer<vtkTransform> transform =
		vtkSmartPointer<vtkTransform>::New();
	transform->SetMatrix(transform_matrix);
	transform->Update();

	vtkNew<vtkTransformPolyDataFilter> transformFilter;
	transformFilter->SetInputData(this->mesh_processing_data_model_->mesh_vec_[0]);
	transformFilter->SetTransform(transform);
	transformFilter->Update();

	vtkPolyDataMapper * mapper = vtkPolyDataMapper::SafeDownCast(this->mesh_processing_data_model_->actor_vec_[0]->GetMapper());
	mapper->SetInputData(transformFilter->GetOutput());

	this->vtk_widget_->resetCamera();
	this->vtk_widget_->update();
}

void MeshProcessing::OnExitICP() {
	this->tab_widget_->setTabEnabled(0, true);
	this->tab_widget_->setTabEnabled(1, false);
	this->tab_widget_->setCurrentIndex(0);

	this->iter_num_label_->setText("");
	this->error_label_->setText("");
	this->matrix_label_->setText("");

	this->enableAllActions();

	this->mesh_processing_data_model_->mesh_vec_[0]->DeepCopy(this->mesh_processing_data_model_->actor_vec_[0]->GetMapper()->GetInput());
	this->mesh_processing_data_model_->actor_vec_[this->mesh_processing_data_model_->target_id]->GetProperty()->SetColor(.0, .5, 1.);
	this->vtk_widget_->update();

	this->register_scroll_area_->setVisible(false);
	this->resetParameters();
}

void MeshProcessing::OnCancelICP() {
	this->tab_widget_->setTabEnabled(0, true);
	this->tab_widget_->setTabEnabled(1, false);
	this->tab_widget_->setCurrentIndex(0);

	this->iter_num_label_->setText("");
	this->error_label_->setText("");
	this->matrix_label_->setText("");

	this->enableAllActions();

	vtkPolyDataMapper * mapper = vtkPolyDataMapper::SafeDownCast(this->mesh_processing_data_model_->actor_vec_[0]->GetMapper());
	mapper->SetInputData(this->mesh_processing_data_model_->mesh_vec_[0]);

	this->mesh_processing_data_model_->actor_vec_[this->mesh_processing_data_model_->target_id]->GetProperty()->SetColor(.0, .5, 1.);
	this->vtk_widget_->update();

	this->register_scroll_area_->setVisible(false);
	this->resetParameters();
}

void MeshProcessing::OnClusterNumChanged(int n) {
	using std::vector;

	this->color_table_handler_ = new ColorTableHandler;
	this->color_table_handler_->setMesh(this->mesh_processing_data_model_->mesh_vec_[this->mesh_processing_data_model_->segment_id]);

	vector<double> color_value_vec;
	vtkSmartPointer<vtkDoubleArray> scalars = this->mesh_processing_data_model_->mesh_segmenter_->getSegmentScalar(n);
	this->mesh_processing_data_model_->mesh_vec_[this->mesh_processing_data_model_->segment_id]->GetCellData()->SetScalars(scalars);
	for (int i = 0; i < scalars->GetNumberOfValues(); ++i)
		color_value_vec.push_back(scalars->GetValue(i));
	this->color_table_handler_->readColorValueVec(color_value_vec);

	this->OnDiscreteMode();
}

void MeshProcessing::OnRunSegment() {
	this->mesh_processing_data_model_->mesh_segmenter_ = new MeshSegmenter(this->seed_num_spin_box_->value(), this->phy_ratio_double_spin_box_->value());
	this->mesh_processing_data_model_->mesh_segmenter_->vtk_widget_ = this->vtk_widget_;
	this->mesh_processing_data_model_->mesh_segmenter_->setMesh(this->mesh_processing_data_model_->mesh_vec_[this->mesh_processing_data_model_->segment_id]);
	this->mesh_processing_data_model_->mesh_segmenter_->segment();

	this->cluster_num_slider_->setEnabled(true);
	this->cluster_num_slider_->setValue(2);
	this->OnClusterNumChanged(2);

	this->cluster_num_slider_->setMinimum(2);
	this->cluster_num_slider_->setMaximum(this->seed_num_spin_box_->value());
}

void MeshProcessing::OnExitSegment() {
	using std::vector;

	this->tab_widget_->setTabEnabled(0, true);
	this->tab_widget_->setTabEnabled(1, false);
	this->tab_widget_->setCurrentIndex(0);

	this->iter_num_label_->setText("");
	this->error_label_->setText("");
	this->matrix_label_->setText("");

	this->enableAllActions();

	this->default_mode_action_->setEnabled(true);
	this->discrete_mode_action_->setEnabled(true);
	this->continuous_mode_action_->setEnabled(true);

	this->segment_scroll_area_->setVisible(false);
	this->resetParameters();
}

void MeshProcessing::OnCancelSegment() {
	this->tab_widget_->setTabEnabled(0, true);
	this->tab_widget_->setTabEnabled(1, false);
	this->tab_widget_->setCurrentIndex(0);

	this->iter_num_label_->setText("");
	this->error_label_->setText("");
	this->matrix_label_->setText("");

	this->enableAllActions();

	this->default_mode_action_->setEnabled(false);
	this->discrete_mode_action_->setEnabled(false);
	this->continuous_mode_action_->setEnabled(false);

	this->mesh_processing_data_model_->combined_mesh_->GetCellData()->SetScalars(nullptr);
	this->mesh_processing_data_model_->actor_vec_[this->mesh_processing_data_model_->segment_id]->GetProperty()->SetColor(.0, .5, 1.);
	this->mesh_processing_data_model_->actor_vec_[this->mesh_processing_data_model_->segment_id]->GetMapper()->ScalarVisibilityOff();
	this->vtk_widget_->update();

	this->segment_scroll_area_->setVisible(false);
	this->resetParameters();
}

void MeshProcessing::OnSelectVertex(vtkIdType id) {
	if (id == -1) return;

	this->removeVertexActors();

	this->mesh_processing_data_model_->selected_vertex_actor_ = this->vtk_widget_->highlightVertex(this->mesh_processing_data_model_->combined_mesh_, id);
	this->mesh_processing_data_model_->selected_vertex_actor_->GetProperty()->SetInterpolationToGouraud();
	this->mesh_processing_data_model_->selected_vertex_actor_->GetProperty()->SetColor(.8, .2, .2);

	auto neighborVertexIds = MeshOperation::getConnectedVertices(this->mesh_processing_data_model_->combined_mesh_, id);
	for (const auto & neighbor : neighborVertexIds) {
		this->mesh_processing_data_model_->neighbor_vertex_actor_vec_.push_back(this->vtk_widget_->highlightVertex(this->mesh_processing_data_model_->combined_mesh_, neighbor));
		this->mesh_processing_data_model_->neighbor_vertex_actor_vec_.back()->GetProperty()->SetInterpolationToGouraud();
		this->mesh_processing_data_model_->neighbor_vertex_actor_vec_.back()->GetProperty()->SetColor(.8, .8, .2);
	}

	auto neighborFaceIds = MeshOperation::getVertexConnectedFaces(this->mesh_processing_data_model_->combined_mesh_, id);
	for (const auto & neighbor : neighborFaceIds) {
		this->mesh_processing_data_model_->neighbor_face_actor_vec_.push_back(this->vtk_widget_->highlightFace(this->mesh_processing_data_model_->combined_mesh_, neighbor));
		this->mesh_processing_data_model_->neighbor_face_actor_vec_.back()->GetProperty()->SetColor(.8, .5, .2);
	}

	this->vtk_widget_->update();
}

void MeshProcessing::OnSelectFace(vtkIdType id) {
	if (id == -1) return;

	this->removeFaceActors();

	this->mesh_processing_data_model_->selected_face_actor_ = this->vtk_widget_->highlightFace(this->mesh_processing_data_model_->combined_mesh_, id);
	this->mesh_processing_data_model_->selected_face_actor_->GetProperty()->SetColor(.8, .2, .2);

	auto neighborFaceIds = MeshOperation::getFaceConnectedFaces(this->mesh_processing_data_model_->combined_mesh_, id);
	for (const auto & neighbor : neighborFaceIds) {
		this->mesh_processing_data_model_->neighbor_face2_actor_vec_.push_back(this->vtk_widget_->highlightFace(this->mesh_processing_data_model_->combined_mesh_, neighbor));
		this->mesh_processing_data_model_->neighbor_face2_actor_vec_.back()->GetProperty()->SetColor(.8, .8, .2);
	}

	this->mesh_processing_data_model_->selected_face_id_ = id;

	this->vtk_widget_->update();
}

void MeshProcessing::OnSelectMultiVertex(const std::vector<vtkIdType>& ids) {
	this->removeMultiVertexActors();

	this->mesh_processing_data_model_->selected_multi_vertex_set_.clear();
	for (const auto & id : ids) {
		this->mesh_processing_data_model_->selected_multi_vertex_actor_vec_.push_back(this->vtk_widget_->highlightVertex(this->mesh_processing_data_model_->combined_mesh_, id));
		this->mesh_processing_data_model_->selected_multi_vertex_actor_vec_.back()->GetProperty()->SetInterpolationToGouraud();
		this->mesh_processing_data_model_->selected_multi_vertex_actor_vec_.back()->GetProperty()->SetColor(.8, .2, .2);

		this->mesh_processing_data_model_->selected_multi_vertex_set_.insert(id);
	}

	this->vtk_widget_->update();
}

void MeshProcessing::resetParameters() {
	vtkSmartPointer<vtkAppendPolyData> appendFilter =
		vtkSmartPointer<vtkAppendPolyData>::New();
	int cnt = 0;
	int num_edges = 0;
	for (int i = 0; i < this->mesh_processing_data_model_->highlight_vec_.size(); ++i) {
		if (this->mesh_processing_data_model_->highlight_vec_[i]) {
			appendFilter->AddInputData(this->mesh_processing_data_model_->mesh_vec_[i]);
			num_edges += this->mesh_processing_data_model_->mesh_edge_vec_[i]->GetNumberOfLines();
			++cnt;
		}
	}
	if (cnt > 0) {
		appendFilter->Update();
		this->mesh_processing_data_model_->combined_mesh_ =
			vtkSmartPointer<vtkPolyData>::New();
		this->mesh_processing_data_model_->combined_mesh_->DeepCopy(appendFilter->GetOutput());

		vtkSmartPointer<vtkIdTypeArray> numberScalarArray =
			vtkSmartPointer<vtkIdTypeArray>::New();
		numberScalarArray->SetNumberOfComponents(1);
		numberScalarArray->SetName("number");
		numberScalarArray->SetNumberOfValues(this->mesh_processing_data_model_->combined_mesh_->GetNumberOfPoints());
		for (int i = 0; i < this->mesh_processing_data_model_->combined_mesh_->GetNumberOfPoints(); ++i)
			numberScalarArray->SetValue(i, i);

		this->mesh_processing_data_model_->combined_mesh_->GetPointData()->AddArray(numberScalarArray);

		int edge_count = 0;
		this->mesh_processing_data_model_->mean_edge_length = 0.0;
		for (int i = 0; i < this->mesh_processing_data_model_->highlight_vec_.size(); ++i) {
			if (this->mesh_processing_data_model_->highlight_vec_[i]) {
				this->mesh_processing_data_model_->mean_edge_length +=
					this->mesh_processing_data_model_->mesh_edge_vec_[i]->GetNumberOfLines() * this->mesh_processing_data_model_->mean_edge_length_vec_[i];
				edge_count += this->mesh_processing_data_model_->mesh_edge_vec_[i]->GetNumberOfLines();
			}
		}
		this->mesh_processing_data_model_->mean_edge_length /= edge_count;

		this->vtk_widget_->updateBottomText(
			this->mesh_processing_data_model_->combined_mesh_->GetNumberOfPoints(),
			this->mesh_processing_data_model_->combined_mesh_->GetNumberOfCells(),
			num_edges
		);
	} else {
		this->mesh_processing_data_model_->combined_mesh_ = nullptr;
		this->mesh_processing_data_model_->mean_edge_length = 0.0;
		this->vtk_widget_->updateBottomText(
			0, 0, 0
		);
	}
}

3. 運行結(jié)果

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

面選擇?

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

法線顯示?

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

?多點選擇

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

配準(zhǔn)?

VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序

三、在線協(xié)助:

如需安裝運行環(huán)境或遠(yuǎn)程調(diào)試,見文章底部個人 QQ 名片,由專業(yè)技術(shù)人員遠(yuǎn)程協(xié)助!
1)遠(yuǎn)程安裝運行環(huán)境,代碼調(diào)試
2)Qt, C++, Python入門指導(dǎo)
3)界面美化
4)軟件制作

當(dāng)前文章連接:Python+Qt桌面端與網(wǎng)頁端人工客服溝通工具_(dá)alicema1111的博客-CSDN博客

博主推薦文章:python人臉識別統(tǒng)計人數(shù)qt窗體-CSDN博客

博主推薦文章:Python Yolov5火焰煙霧識別源碼分享-CSDN博客

? ? ? ? ? ? ? ? ? ? ? ? ?Python OpenCV識別行人入口進出人數(shù)統(tǒng)計_python識別人數(shù)-CSDN博客

個人博客主頁:alicema1111的博客_CSDN博客-Python,C++,網(wǎng)頁領(lǐng)域博主

博主所有文章點這里alicema1111的博客_CSDN博客-Python,C++,網(wǎng)頁領(lǐng)域博主文章來源地址http://www.zghlxwxcb.cn/news/detail-498403.html

到了這里,關(guān)于VS+QT+VTK三維網(wǎng)格顯示-點面選擇-法線法向量顯示-配準(zhǔn)-分割窗體程序的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • VS+QT+VTK treeView樹型結(jié)構(gòu)模型加載隱藏實例

    VS+QT+VTK treeView樹型結(jié)構(gòu)模型加載隱藏實例

    程序示例精選 VS+QT+VTK treeView樹型結(jié)構(gòu)模型加載隱藏實例 如需安裝運行環(huán)境或遠(yuǎn)程調(diào)試,見文章底部個人 QQ 名片,由專業(yè)技術(shù)人員遠(yuǎn)程協(xié)助! 這篇博客針對VS+QT+VTK treeView樹型結(jié)構(gòu)模型加載隱藏實例編寫代碼,代碼整潔,規(guī)則,易讀。 學(xué)習(xí)與應(yīng)用推薦首選。 一、所需工具軟件

    2024年02月14日
    瀏覽(25)
  • QT5.14.2 + VS2019 + VTK8.2.0配置環(huán)境

    QT5.14.2 + VS2019 + VTK8.2.0配置環(huán)境

    1.1.1 軟件下載地址:Index of /archive/qt 1.1.2 安裝的時候需要注意: 安裝時候至少把MSVC2017 64bit選擇上。 用VS2019時候,打開Qt Creator,點擊工具-選項,構(gòu)建套件中可能會顯示黃色或者紅色感嘆號,這個時候就需要額外的配置。 ?打開VS2019,點擊頂部工具 - 獲取工具和功能 - 在跳出的

    2024年02月06日
    瀏覽(34)
  • 【VTK】VTK 顯示小球例子,在 Windows 上使用 Visual Studio 配合 Qt 構(gòu)建 VTK

    【VTK】VTK 顯示小球例子,在 Windows 上使用 Visual Studio 配合 Qt 構(gòu)建 VTK

    知識不是單獨的,一定是成體系的。更多我的個人總結(jié)和相關(guān)經(jīng)驗可查閱這個專欄:Visual Studio。 編號 內(nèi)容 1 【Visual Studio】在 Windows 上使用 Visual Studio 構(gòu)建 VTK 2 【Visual Studio】在 Windows 上使用 Visual Studio 配合 Qt 構(gòu)建 VTK 3 【VTK】VTK 顯示小球例子,在 Windows 上使用 Visual Studio 配

    2024年02月17日
    瀏覽(36)
  • Qt通過QVTKWidget顯示VTK交互窗口

    Qt通過QVTKWidget顯示VTK交互窗口

    ??項目需要將一個基于控制臺的VTK程序合并到Qt界面中通過QVTKWidget顯示,由于第一次接觸VTK,很多東西不懂,網(wǎng)上關(guān)于VTK和Qt合并的資料又比較少,比較亂,折磨了兩天實現(xiàn)了合并,現(xiàn)總結(jié)如下。 ??首先CMake編譯vtk源碼,我的環(huán)境VS2019社區(qū)版+VTK8.2.0+Qt5.12.0,完全按照這個

    2023年04月08日
    瀏覽(19)
  • 【VTK】讀取一個 STL 文件,并使用 Qt 顯示出來,在 Windows 上使用 Visual Studio 配合 Qt 構(gòu)建 VTK

    【VTK】讀取一個 STL 文件,并使用 Qt 顯示出來,在 Windows 上使用 Visual Studio 配合 Qt 構(gòu)建 VTK

    知識不是單獨的,一定是成體系的。更多我的個人總結(jié)和相關(guān)經(jīng)驗可查閱這個專欄:Visual Studio。 直接先把效果放出來,有需要就往下看。 骷髏3D打印3D模型

    2024年02月14日
    瀏覽(28)
  • pcl+vtk(三)QT中使用QVTKOpenGLNativeWidget的簡單教程以及案例,利用PCLVisualizer顯示點云

    pcl+vtk(三)QT中使用QVTKOpenGLNativeWidget的簡單教程以及案例,利用PCLVisualizer顯示點云

    先添加一個帶有ui的QT應(yīng)用程序。 先拖出來一個QOpenGLWidget控件 修改布局如下: 然后將QOpenGLWidget控件提升為QVTKOpenGLNativeWidget控件,步驟如下: 右擊QOpenGLWidget窗口,選擇【提示為...】 ?輸入提升的類名稱為QVTKOpenGLNativeWidget ?此時需要把自動生成的qvtkopenglnativewidget.h修改為QV

    2024年01月25日
    瀏覽(40)
  • Unity中實時獲取網(wǎng)格上點的位置,還有對應(yīng)的面和法線

    Unity中實時獲取網(wǎng)格上點的位置,還有對應(yīng)的面和法線

    在Unity中,可以使用Mesh類來獲取一個網(wǎng)格上點的位置以及對應(yīng)的面和法線。以下是具體步驟: 在腳本中,需要先獲取要操作的網(wǎng)格對象。可以使用以下代碼: Mesh mesh = GetComponentMeshFilter().mesh; 其中,GetComponentMeshFilter()用于獲取該游戲?qū)ο笊系腗eshFilter組件,mesh屬性用于獲取該

    2024年02月08日
    瀏覽(21)
  • 【Unity】為網(wǎng)格生成頂點法線(Mesh.RecalculateNormals計算異常的解決方案)

    【Unity】為網(wǎng)格生成頂點法線(Mesh.RecalculateNormals計算異常的解決方案)

    我們通過代碼動態(tài)創(chuàng)建的網(wǎng)格,因為沒有法線,不會接收到光照。 正常情況下調(diào)用Mesh.RecalculateNormals方法,重新生成法線即可。 但特定情況下通過此方法計算出的頂點發(fā)現(xiàn)都是(0, 0,0),這種情況下只能手動生成法線了 如下圖,左邊物體有正確的法線,可以接收光照信息,

    2024年02月13日
    瀏覽(20)
  • Qt 5.15.2 三維顯示功能

    Qt 5.15.2 三維顯示功能

    Qt 5.15.2 三維顯示功能 三維顯示效果: .pro項目文件 Scene.h scene.cpp 本blog地址:https://blog.csdn.net/hsg77

    2024年02月04日
    瀏覽(17)
  • python VTK PyQt5 VTK環(huán)境搭建 創(chuàng)建 渲染窗口及三維模型,包含 三維模型交互;

    python VTK PyQt5 VTK環(huán)境搭建 創(chuàng)建 渲染窗口及三維模型,包含 三維模型交互;

    ? 目錄 Part1. VTK 介紹 Part2. PyQt5 VTK環(huán)境搭建 安裝Anaconda 自帶Python Anaconda下載 安裝PyQt5 安裝 VTK Part3 :PyQt VTK 結(jié)合樣例: Part1. VTK 介紹 VTK(visualization toolkit)是一個開源的免費軟件系統(tǒng),主要用于三維計算機圖形學(xué)、圖像處理和可視化。Vtk 是在面向?qū)ο笤淼幕A(chǔ)上設(shè)計和實現(xiàn)的

    2024年02月11日
    瀏覽(54)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包