渲染SDK 0.1.2
载入中...
搜索中...
未找到
拾取示例

概述

本教程提供了Render SDK拾取相关设置的使用教程。

前置条件

如果未初始化SDK,需要通过以下代码初始化

//创建sdk组件
auto mRenderComponent = AMCAXRender::CreateRenderComponent(this);
//创建实体Render
auto mRender = mRenderComponent->CreateBasicRender();
AMCAX_RENDER_API std::shared_ptr< IRenderComponent > CreateRenderComponent(QWidget *parent)
Create Render Component

示例代码

以下代码展示了拾取相关设置的使用方法。

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(PickSample)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
add_definitions(-DUSE_AMCAX_KERNEL)
list(APPEND CMAKE_PREFIX_PATH ${AMCAXRender_PATH})
find_package(AMCAXRender )
find_package(Qt6 COMPONENTS Widgets Core Gui REQUIRED)
list(APPEND CMAKE_PREFIX_PATH ${Json_PATH})
find_package(nlohmann_json 3.11.3 REQUIRED)
file(GLOB ALL_UI_FILES *.ui)
file(GLOB ALL_FILES *.cpp *.h)
add_executable(${PROJECT_NAME} ${ALL_UI_FILES} ${ALL_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${AMCAX_components})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets)
target_link_libraries(${PROJECT_NAME} PRIVATE AMCAXRender::AMCAXRender)

main.cpp

#include <QApplication>
#include "Mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Mainwindow w;
w.show();
return a.exec();
}

Mainwindow.h

#pragma once
#include <QWidget>
#include "ui_Mainwindow.h"
#include <AMCAXRender.h>
class Mainwindow : public QWidget
{
Q_OBJECT
public:
Mainwindow(QWidget *parent = nullptr);
~Mainwindow();
private:
Ui::MainwindowClass ui;
std::shared_ptr<AMCAXRender::IRenderComponent> mRenderComponent;
std::shared_ptr<AMCAXRender::CBasicRender> mRender;
};
Component Creation

Mainwindow.cpp

#include "Mainwindow.h"
Mainwindow::Mainwindow(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//初始化
mRenderComponent = AMCAXRender::CreateRenderComponent(this);
mRender = mRenderComponent->CreateBasicRender();
//窗口布局
ui.gridLayout->addWidget(mRender->widget);
//设置拾取的类型
mRender->interactionCenter->PickEventFilter(AMCAXRender::PickType::face);
mRender->interactionCenter->PickEventFilter(AMCAXRender::PickType::edge);
mRender->interactionCenter->PickEventFilter(AMCAXRender::PickType::point);
mRender->interactionCenter->PickEventFilter(AMCAXRender::PickType::all);
//设置拾取颜色
double c[3] = { 1,0,0 };
mRender->interactionCenter->SetPickColor(c);
//注册拾取事件
mRender->interactionCenter->RegisterPickEvent(AMCAXRender::EventType::mouse_click,
[&](AMCAXRender::EntityId parentId, AMCAXRender::EntityId entityId, AMCAXRender::PickType type, int subIndex, int* pos) {
});
//根据事件Id注销拾取事件
mRender->interactionCenter->UnregisterPickEvent(2);
//根据事件类型注销拾取事件
mRender->interactionCenter->UnregisterPickEvent(AMCAXRender::EventType::mouse_click);
//设置拾取的线宽
mRender->interactionCenter->SetPickLineWidth(2);
//注册拾取事件(从shape生成的实体)
mRender->interactionCenter->RegisterPickEventfromShape(AMCAXRender::EventType::mouse_click,
[&](AMCAXRender::EntityId parentId, AMCAXRender::EntityId entityId, AMCAXRender::PickType type, const AMCAX::TopoShape& shape, int* pos) {
});
//根据事件Id注销拾取事件(从shape生成的实体)
mRender->interactionCenter->UnregisterPickEventfromShape(2);
//根据事件类型注销拾取事件(从shape生成的实体)
mRender->interactionCenter->UnregisterPickEventfromShape(AMCAXRender::EventType::mouse_click);
mRender->cameraManage->ResetCamera();
mRender->entityManage->DoRepaint();
}
Mainwindow::~Mainwindow()
{
}
PickType
Pick Type
定义 Constants.h:99
@ edge
Edge Pick
定义 Constants.h:103
@ point
Point Pick
定义 Constants.h:102
@ all
All Pick
定义 Constants.h:106
@ face
Face Pick
定义 Constants.h:104
@ mouse_click
Left Click
定义 Constants.h:84

Mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainwindowClass</class>
<widget class="QWidget" name="MainwindowClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Mainwindow</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout"/>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

拾取预览

更多

更多拾取设置请参考 InteractionCenter.h