#include "zxRotateRepresentation.h"
#include "vtkActor.h"
#include "vtkAssemblyPath.h"
#include "vtkBox.h"
#include "vtkCallbackCommand.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkCellPicker.h"
#include "vtkDoubleArray.h"
#include "vtkEventData.h"
#include "vtkInteractorObserver.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPickingManager.h"
#include "vtkPlane.h"
#include "vtkPlanes.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkQuaternion.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include <vtkRegularPolygonSource.h>
#include "vtkTransform.h"
#include "vtkVectorOperators.h"
#include "vtkWindow.h"
#include <assert.h>
//----------------------------------------------------------------------------
zxRotateRepresentation::zxRotateRepresentation() {
// The initial state
this->InteractionState = zxRotateRepresentation::Outside;
// Handle size is in pixels for this widget
this->HandleSize = 5.0;
// Control orientation of normals
this->InsideOut = 0;
// Set up the initial properties
this->CreateDefaultProperties();
// Construct initial points
this->Points = vtkPoints::New(VTK_DOUBLE);
this->Points->SetNumberOfPoints(15); // 8 corners; 6 faces; 1 center
// Construct connectivity for the faces. These are used to perform
// the picking.
int i;
const double units0 = -660.;
// Create the outline for the hex
this->LinePolyData = vtkPolyData::New();
this->LinePolyData->SetPoints(this->Points);
this->LineMapper = vtkPolyDataMapper::New();
this->LineMapper->SetInputData(this->LinePolyData);
this->LineMapper->SetResolveCoincidentTopologyToPolygonOffset();
this->LineMapper->SetRelativeCoincidentTopologyLineOffsetParameters(0, units0);
this->LineMapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(0, units0);
this->LineMapper->SetRelativeCoincidentTopologyPointOffsetParameter(units0);
this->LineActor = vtkActor::New();
this->LineActor->SetMapper(this->LineMapper);
this->LineActor->SetProperty(this->OutlineProperty);
vtkCellArray* cells = vtkCellArray::New();
cells->AllocateEstimate(3, 2);
this->LinePolyData->SetLines(cells);
cells->Delete();
// Create the outline
this->GenerateOutline();
// Create the Circles
for (i = 0; i < 3; i++)
{
XDirection[i] = 0.0;
YDirection[i] = 0.0;
ZDirection[i] = 0.0;
ViewDirection[i] = 0.0;
}
XDirection[0] = YDirection[1] = ZDirection[2] = 1.0;
this->CircleActor = new vtkActor * [4];
this->CircleMapper = new vtkPolyDataMapper * [4];
this->CircleGeometry = new vtkPolyData * [4];
for (i = 0; i < 4; i++) {
this->CircleGeometry[i] = vtkPolyData::New();
this->CircleMapper[i] = vtkPolyDataMapper::New();
this->CircleMapper[i]->SetInputData(this->CircleGeometry[i]);
this->CircleMapper[i]->SetResolveCoincidentTopologyToPolygonOffset();
this->CircleMapper[i]->SetRelativeCoincidentTopologyLineOffsetParameters(0, units0);
this->CircleMapper[i]->SetRelativeCoincidentTopologyPolygonOffsetParameters(0, units0);
this->CircleMapper[i]->SetRelativeCoincidentTopologyPointOffsetParameter(units0);
this->CircleActor[i] = vtkActor::New();
this->CircleActor[i]->SetMapper(this->CircleMapper[i]);
if(i==0)
this->CircleActor[i]->SetProperty(this->YZCircleProperty);
else if(i==1)
this->CircleActor[i]->SetProperty(this->XZCircleProperty);
else if (i == 2)
this->CircleActor[i]->SetProperty(this->XYCircleProperty);
else if (i == 3)
this->CircleActor[i]->SetProperty(this->ViewCircleProperty);
}
GenerateRotateCircle();
// Create the handles
this->HandleGeometry = vtkSphereSource::New();
this->HandleGeometry->SetOutputPointsPrecision(vtkAlgorithm::DOUBLE_PRECISION);
this->HandleGeometry->SetThetaResolution(16);
this->HandleGeometry->SetPhiResolution(8);
this->HandleGeometry->SetRadius(1.0);
this->HandleMapper = vtkPolyDataMapper::New();
this->HandleMapper->SetInputConnection(this->HandleGeometry->GetOutputPort());
this->Handle = vtkActor::New();
this->Handle->SetMapper(this->HandleMapper);
this->Handle->SetProperty(this->HandleProperty);
// Define the point coordinates
double bounds[6];
bounds[0] = -0.5;
bounds[1] = 0.5;
bounds[2] = -0.5;
bounds[3] = 0.5;
bounds[4] = -0.5;
bounds[5] = 0.5;
// Points 8-14 are down by PositionHandles();
this->BoundingBox = vtkBox::New();
this->PlaceWidget(bounds);
// Manage the picking stuff
this->CirclePicker = vtkCellPicker::New();
this->CirclePicker->SetTolerance(0.001);
for (i = 0; i < 4; i++)
{
this->CirclePicker->AddPickList(this->CircleActor[i]);
}
this->CirclePicker->PickFromListOn();
this->HandlePicker = vtkCellPicker::New();
this->HandlePicker->SetTolerance(0.001);
this->HandlePicker->AddPickList(this->Handle);
this->HandlePicker->PickFromListOn();
this->LinePicker = vtkCellPicker::New();
this->LinePicker->SetTolerance(0.001);
this->LinePicker->AddPickList(LineActor);
this->LinePicker->PickFromListOn();
this->CurrentHandle = nullptr;
// Internal data members for performance
this->Transform = vtkTransform::New();
this->PlanePoints = vtkPoints::New(VTK_DOUBLE);
this->PlanePoints->SetNumberOfPoints(6);
this->PlaneNormals = vtkDoubleArray::New();
this->PlaneNormals->SetNumberOfComponents(3);
this->PlaneNormals->SetNumberOfTuples(6);
this->Matrix = vtkMatrix4x4::New();
}
//----------------------------------------------------------------------------
zxRotateRepresentation::~zxRotateRepresentation() {
this->Points->Delete();
this->LineActor->Delete();
this->LineMapper->Delete();
this->LinePolyData->Delete();
for (int i = 0; i < 4; i++) {
this->CircleGeometry[i]->Delete();
this->CircleMapper[i]->Delete();
this->CircleActor[i]->Delete();
}
delete[] this->CircleActor;
delete[] this->CircleMapper;
delete[] this->CircleGeometry;
this->HandleGeometry->Delete();
this->HandleMapper->Delete();
this->Handle->Delete();
this->CirclePicker->Delete();
this->HandlePicker->Delete();
this->LinePicker->Delete();
this->Transform->Delete();
this->BoundingBox->Delete();
this->PlanePoints->Delete();
this->PlaneNormals->Delete();
this->Matrix->Delete();
this->YZCircleProperty ->Delete();
this->XZCircleProperty ->Delete();
this->XYCircleProperty ->Delete();
this->ViewCircleProperty ->Delete();
this->SelectedYZCircleProperty->Delete();
this->SelectedXZCircleProperty->Delete();
this->SelectedXYCircleProperty->Delete();
this->SelectedViewCircleProperty->Delete();
this->HandleProperty->Delete();
this->SelectedHandleProperty->Delete();
this->FaceProperty->Delete();
this->SelectedFaceProperty->Delete();
this->OutlineProperty->Delete();
this->SelectedOutlineProperty->Delete();
}
//----------------------------------------------------------------------
void zxRotateRepresentation::StartWidgetInteraction(double e[2]) {
// Store the start position
this->StartEventPosition[0] = e[0];
this->StartEventPosition[1] = e[1];
this->StartEventPosition[2] = 0.0;
// Store the start position
this->LastEventPosition[0] = e[0];
this->LastEventPosition[1] = e[1];
this->LastEventPosition[2] = 0.0;
没有合适的资源?快使用搜索试试~ 我知道了~
基于VTK实现旋转功能
共4个文件
h:2个
cpp:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 4 下载量 194 浏览量
2023-09-20
14:34:53
上传
评论
收藏 12KB ZIP 举报
温馨提示
基于VTK实现旋转功能,实现效果见博客:https://blog.csdn.net/qq_40041064/article/details/130636319 已按VTK中Widget和Representation进行封装,简单易用!
资源推荐
资源详情
资源评论
收起资源包目录
RotateWidget&RotateRepresentation.zip (4个子文件)
zxRotateRepresentation.cpp 45KB
zxRotateWidget.h 3KB
zxRotateWidget.cpp 7KB
zxRotateRepresentation.h 8KB
共 4 条
- 1
资源评论
- yy17732239092023-12-11资源内容详细,总结地很全面,与描述的内容一致,对我启发很大,学习了。
- weixin_378330652024-01-23资源很不错,内容和描述一致,值得借鉴,赶紧学起来!
- qq_319672812023-09-29资源内容详细全面,与描述一致,对我很有用,有一定的使用价值。
- 2301_774853122023-12-13总算找到了想要的资源,搞定遇到的大问题,赞赞赞!
雪易
- 粉丝: 8629
- 资源: 52
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功