资源简介
VTK三维球体测量实例,【不带环境配置】,可交互测量
代码片段和文件信息
// Cylinder.cpp : 定义控制台应用程序的入口点。
//
#include “iostring“//what
#include “stdafx.h“
#include
#include
#include “vtkActor.h“
#include
#include “vtkCommand.h“
#include “vtkDICOMImageReader.h“
#include
#include
#include
#include “vtkInteractorEventRecorder.h“
#include “vtkLineWidget.h“
#include “vtkRenderWindowInteractor.h“
#include
#include
#include
#include
#include
#include
#include
using namespace std;
vtkLineWidget *lineWidget1;
vtkLineWidget *lineWidget2;
//定义角度测量的回调函数
class vtkLWCallback : public vtkCommand
{
public:
static vtkLWCallback *New()
{ return new vtkLWCallback; }
virtual void Execute(vtkobject *caller unsigned long void*)
{
vtkLineWidget *lineWidget = reinterpret_cast(caller);
double O[3]A[3]B[3];
lineWidget->GetPoint1 (O);
lineWidget1->SetPoint1 (O);
lineWidget2->SetPoint1 (O);
lineWidget1->GetPoint2 (A);
lineWidget2->GetPoint2 (B);
double OAOBAB;
AB=sqrt((A[0]-B[0])*(A[0]-B[0])+(A[1]-B[1])*(A[1]-B[1])+(A[2]-B[2])*(A[2]-B[2]));
OA=sqrt((A[0]-O[0])*(A[0]-O[0])+(A[1]-O[1])*(A[1]-O[1])+(A[2]-O[2])*(A[2]-O[2]));
OB=sqrt((O[0]-B[0])*(O[0]-B[0])+(O[1]-B[1])*(O[1]-B[1])+(O[2]-B[2])*(O[2]-B[2]));
double cosAOB=(OA*OA+OB*OB-AB*AB)/(2*OA*OB);
double angle;
angle=acos(cosAOB)*180/3.14159;
char cAct[100];
sprintf((char *)cAct“%.4f“angle);
this->Text->SetInput (cAct);
}
vtkLWCallback():Text(0) {}
vtkTextMapper *Text;
};
//定义测量lineWidget直线长度的回调函数
class vtkLLWCallback:public vtkCommand
{
public:
static vtkLLWCallback *New()
{return new vtkLLWCallback;}
virtual void Execute(vtkobject *callerunsigned longvoid*)
{
vtkLineWidget *lineWidget = reinterpret_cast(caller);
double A[3]B[3];
lineWidget->GetPoint1(A);
lineWidget->GetPoint2(B);
double length;
length=sqrt((A[0]-B[0])*(A[0]-B[0])+(A[1]-B[1])*(A[1]-B[1])+(A[2]-B[2])*(A[2]-B[2]));
char cMct[100];
sprintf((char*)cMct“%.3f“length);
this->lengthText->SetInput(cMct);
}
vtkLLWCallback():lengthText(0)lineWidget(0) {};
vtkTextMapper *lengthText;
vtkLineWidget *lineWidget;
};
int _tmain(int argc _TCHAR* argv[])
{
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetThetaResolution(12);
sphere->SetPhiResolution(12);
sphere->SetRadius(100);
vtkPolyDataMapper *innerMapper = vtkPolyDataMapper::New();
innerMapper->SetInput(sphere->GetOutput());
vtkActor *innerSphere = vtkActor::New();
innerSphere->SetMapper(innerMapper);
innerSphere->GetProperty()->SetColor (111);
innerSphere->GetProperty()->SetOpacity (0.5);
vtkTextMapper *textMapper=vtkTextMapper::New();
textMapp
评论
共有 条评论