資源簡介
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
評論
共有 條評論