概述
本教程提供了Render SDK渲染精度示例设置的使用教程,可通过该教程了解渲染精度示例的设置
前置条件
如果未初始化SDK,需要通过以下代码初始化
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(RenderAccuracySample)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
add_definitions(-DUSE_AMCAX_KERNEL)
set(AMCAX_components AMCAXCommon AMCAXPart AMCAXStep AMCAXOCCTIO)
find_package(AMCAXCommon REQUIRED)
find_package(AMCAXStep REQUIRED)
find_package(AMCAXPart REQUIRED)
find_package(AMCAXOCCTIO REQUIRED)
list(APPEND CMAKE_PREFIX_PATH ${AMCAXRender_PATH})
find_package(AMCAXRender )
find_package(Qt6 COMPONENTS Widgets Core Gui REQUIRED)
set(PROJECT_FILES
main.cpp
Mainwindow.cpp
Mainwindow.h
RenderSetting.ui
)
set(STEP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../../resources/accuracy_sample.step")
add_executable(${PROJECT_NAME} ${PROJECT_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)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${STEP_FILE} $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
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 <QMainWindow>
#include <QWidget>
namespace Ui {
class MainWindow;
}
class Mainwindow : public QMainWindow
{
Q_OBJECT
public:
Mainwindow(QWidget* parent = nullptr);
~Mainwindow();
private:
Ui::MainWindow* ui = nullptr;
std::shared_ptr<AMCAXRender::IRenderComponent> mRenderComponent;
std::shared_ptr<AMCAXRender::CBasicRender> mRender;
private slots:
void onDoubleSpinBoxValueChanged(double value);
};
Mainwindow.cpp
#include "Mainwindow.h"
#include "ui_RenderSetting.h"
#include <iostream>
#include <QDebug>
#include <QCoreApplication>
#include <QDir>
#ifdef USE_AMCAX_KERNEL
#include <step/StepReader.hpp>
#include <step/StepDataTool.hpp>
#include <step/StepData.hpp>
#endif
#include <fstream>
Mainwindow::Mainwindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
mRender = mRenderComponent->CreateBasicRender();
ui->leftLayout->addWidget(mRender->widget);
ui->doubleSpinBox->setRange(0, 1.0);
ui->doubleSpinBox->setDecimals(1);
ui->doubleSpinBox->setValue(1.0);
ui->doubleSpinBox->setSingleStep(0.1);
connect(ui->doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Mainwindow::onDoubleSpinBoxValueChanged);
QString setpPath = QCoreApplication::applicationDirPath() + "/accuracy_sample.STEP";
std::ifstream ifs(std::filesystem::u8path(setpPath.toStdString()));
AMCAX::STEP::StepReader reader(ifs);
if (!reader.Read())
return;
auto products = AMCAX::STEP::StepDataTool::Flatten(reader.GetShapes());
for (std::shared_ptr<AMCAX::STEP::StepData> product : products)
{
for (const AMCAX::TopoShape& shape : product->Shapes())
{
if (!shape.IsNull())
{
auto entity = mRender->entityFactory->FromShape(shape);
mRender->entityManage->AddEntity(entity);
}
}
}
mRender->cameraManage->ResetCamera();
}
Mainwindow::~Mainwindow()
{
delete ui;
}
void Mainwindow::onDoubleSpinBoxValueChanged(double value)
{
qDebug() << "value :" << value;
mRender->interactionCenter->UseAccuracy(true);
mRender->interactionCenter->SetAccuracy(value, [this]() {
qDebug() << "Rendering accuracy complete!";
}
);
}
RenderSetting.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
<item>
<layout class="QVBoxLayout" name="leftLayout"/>
</item>
<item>
<layout class="QVBoxLayout" name="rightLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>RenderSetting</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>21</x>
<y>30</y>
<width>53</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>accuracy:</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="geometry">
<rect>
<x>80</x>
<y>30</y>
<width>53</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
渲染精度预览