当前位置:网站首页>利用 vtk 的控件画圆和矩形
利用 vtk 的控件画圆和矩形
2022-07-20 21:25:00 【peanut_wu】
代码改造了vtkAffineReprentation2D, 使其在2d平面上可以画圆,和矩形。vtkAffineReprentation2D虽然也能画圆和矩形,但是不能放大缩小,也不能移动。本人改造了vtk代码使其可以放大缩小,更可以移动。
关键代码如下:
圆:
void vtkEllipseRepresent2D::BuildRepresentation()
{
if (this->GetMTime() > this->BuildTime ||
(this->Renderer && this->Renderer->GetVTKWindow() &&
this->Renderer->GetVTKWindow()->GetMTime() > this->BuildTime))
{
vtkInteractorObserver::ComputeWorldToDisplay(
this->Renderer, this->Origin[0], this->Origin[1], this->Origin[2], this->DisplayOrigin);
int* size = this->Renderer->GetRenderWindow()->GetSize();
this->CurrentWidth = this->CircleWidth;
this->CurrentWidth /= 2.0;
double p1[3], p2[3], p3[3], p4[3];
p1[0] = this->DisplayOrigin[0] - this->CurrentWidth;
p1[1] = this->DisplayOrigin[1] - this->CurrentWidth;
p1[2] = 0.0;
p2[0] = this->DisplayOrigin[0] + this->CurrentWidth;
p2[1] = this->DisplayOrigin[1] - this->CurrentWidth;
p2[2] = 0.0;
p3[0] = this->DisplayOrigin[0] + this->CurrentWidth;
p3[1] = this->DisplayOrigin[1] + this->CurrentWidth;
p3[2] = 0.0;
p4[0] = this->DisplayOrigin[0] - this->CurrentWidth;
p4[1] = this->DisplayOrigin[1] + this->CurrentWidth;
p4[2] = 0.0;
this->HBoxPoints->SetPoint(0, p1);
this->HBoxPoints->SetPoint(1, p2);
this->HBoxPoints->SetPoint(2, p3);
this->HBoxPoints->SetPoint(3, p4);
this->HBoxPoints->Modified();
// draw the circle
int i;
double theta, delTheta = 2.0 * vtkMath::Pi() / VTK_CIRCLE_RESOLUTION;
this->CurrentRadius = this->CurrentWidth ;//* 0.75
this->CircleCellArray->Reset();
this->CirclePoints->Reset();
this->CirclePoints->SetNumberOfPoints(VTK_CIRCLE_RESOLUTION);
//this->CircleCellArray->AllocateEstimate(1, VTK_CIRCLE_RESOLUTION + 1);
this->CircleCellArray->InsertNextCell(VTK_CIRCLE_RESOLUTION + 1);
for (i = 0; i < VTK_CIRCLE_RESOLUTION; i++)
{
theta = i * delTheta;
p1[0] = this->DisplayOrigin[0] + this->CurrentRadius * cos(theta);
p1[1] = this->DisplayOrigin[1] + this->CurrentRadius * sin(theta);
this->CirclePoints->SetPoint(i, p1);
this->CircleCellArray->InsertCellPoint(i);
}
this->CircleCellArray->InsertCellPoint(0);
this->CircleCellArray->Modified();
if (this->DisplayText)
{
char str[256];
int maxValue, minValue;
srand((unsigned)time(NULL));
for (int i = 0; i < 10; i++)
{
maxValue += rand();
minValue = rand();
}
maxValue = maxValue % 255;
minValue = minValue % 50;
if (maxValue < minValue)
maxValue += 180;
snprintf(str, sizeof(str), "max:%d\n, mean:%d\n, min:%d",
maxValue, (maxValue + minValue) / 2, minValue);
double eventPos[2] = { this->DisplayOrigin[0] + this->CurrentRadius ,this->DisplayOrigin[1] };
this->UpdateText(str, eventPos);
}
// draw the translation axes
this->CurrentAxesWidth = this->CurrentWidth * this->AxesWidth / this->CircleWidth;
p1[0] = this->DisplayOrigin[0] - this->CurrentAxesWidth;
p1[1] = this->DisplayOrigin[1];
this->XAxis->GetPositionCoordinate()->SetValue(p1);
p2[0] = this->DisplayOrigin[0] + this->CurrentAxesWidth;
p2[1] = this->DisplayOrigin[1];
this->XAxis->GetPosition2Coordinate()->SetValue(p2);
p1[0] = this->DisplayOrigin[0];
p1[1] = this->DisplayOrigin[1] - this->CurrentAxesWidth;
this->YAxis->GetPositionCoordinate()->SetValue(p1);
p2[0] = this->DisplayOrigin[0];
p2[1] = this->DisplayOrigin[1] + this->CurrentAxesWidth;
this->YAxis->GetPosition2Coordinate()->SetValue(p2);
this->BuildTime.Modified();
}
}
边栏推荐
猜你喜欢
小程序毕设作品之微信疫苗预约小程序毕业设计(7)中期检查报告
ESP8266-NodeMCU——使用U8g2库点亮OLED
CAN物理层介绍
Web应用程序漏洞-X-Forwarded-For注入
Section 15 of Chapter 2: basic operation of dictionary
8 月亚马逊云科技培训与认证课程,精彩不容错过!
伦敦银实时行情能够给人们带来哪方面的信息
Section 12 of Chapter 2: set set
asp. Net -gridview's own delete line item hyperlink usage (deletebutton)
Common web security problems in interview
随机推荐
Oracle一条语句实现更新or新增
PHP人才招聘網站源碼
sha256为什么不可逆,sha256的安全性如何
通过TPT的FUSION平台实现联合测试
Lambda表达式
Can physical layer introduction
CentOS 7上集群化部署Apache Druid 0.22实时分析数据库
VSS中上传一个文件夹(包括子文件夹和文件)
开发人员使用Klocwork进行软件安全的五大原因
VR live broadcast is born at the right time, so the marketing effect can be seen
offer - 52. The first common node of two linked lists
根据圆心角求离心角
脸书将缩减新闻产品 相关资源侧重元宇宙和短视频内容创造
Common web security problems in interview
小程序毕设作品之微信疫苗预约小程序毕业设计(1)开发概要
C语言三大结构
未来旅游新方式,VR云游足不出户拥抱诗和远方
【JS】动态渲染页面
墨家巡逻兵 源码
深入理解完美哈希