1.qSlicerCreateModelsModule.h
1 #ifndef __qSlicerllshCreateNewModelsModule_h
2 #define __qSlicerllshCreateNewModelsModule_h
3
4 // SlicerQt includes
5 #include "qSlicerLoadableModule.h"
6
7 #include "qSlicerllshCreateNewModelsModuleExport.h"
8
9 class qSlicerllshCreateNewModelsModulePrivate;//文件之间类相互引用(前向类引用)
10 /// ingroup Slicer_QtModules_ExtensionTemplate
11 class Q_SLICER_QTMODULES_LLSHCREATENEWMODELS_EXPORT qSlicerllshCreateNewModelsModule :
12 public qSlicerLoadableModule
13 {
14 Q_OBJECT//使用Qt_Widget
15 Q_INTERFACES(qSlicerLoadableModule);//Plug-in插件接口
16
17 public:
18
19 typedef qSlicerLoadableModule Superclass;
20 explicit qSlicerllshCreateNewModelsModule(QObject *parent=0);
21 virtual ~qSlicerllshCreateNewModelsModule();
22
23 qSlicerGetTitleMacro(QTMODULE_TITLE);
24
25 virtual QString helpText()const;
26 virtual QString acknowledgementText()const;
27 virtual QStringList contributors()const;
28
29 /// Return a custom icon for the module
30 virtual QIcon icon()const;
31
32 virtual QStringList categories()const;
33 virtual QStringList dependencies() const;
34
35 protected:
36
37 /// Initialize the module. Register the volumes reader/writer
38 virtual void setup();
39
40 /// Create and return the widget representation associated to this module
41 virtual qSlicerAbstractModuleRepresentation * createWidgetRepresentation();
42
43 /// Create and return the logic associated to this module
44 virtual vtkMRMLAbstractLogic* createLogic();
45
46 protected:
47 QScopedPointer<qSlicerllshCreateNewModelsModulePrivate> d_ptr;
48
49 private:
50 Q_DECLARE_PRIVATE(qSlicerllshCreateNewModelsModule);
51 Q_DISABLE_COPY(qSlicerllshCreateNewModelsModule);
52
53 };
54
55 #endif
2.qSlicerCreateModelsModule.cpp
1 // Qt includes
2 #include <QtPlugin>//QT插件机制
3
4 // ExtensionTemplate Logic includes
5 #include <vtkSlicerllshCreateNewModelsLogic.h>//核心逻辑控制头文件
6
7 // ExtensionTemplate includes
8 #include "qSlicerllshCreateNewModelsModule.h"//模块控制头文件
9 #include "qSlicerllshCreateNewModelsModuleWidget.h"//模块主控模板设计头文件
10
11 //-----------------------------------------------------------------------------
12 Q_EXPORT_PLUGIN2(qSlicerllshCreateNewModelsModule, qSlicerllshCreateNewModelsModule);
13
14 //-----------------------------------------------------------------------------
15 /// ingroup Slicer_QtModules_ExtensionTemplate
16 class qSlicerllshCreateNewModelsModulePrivate
17 {
18 public:
19 qSlicerllshCreateNewModelsModulePrivate();
20 };
21
22 //-----------------------------------------------------------------------------
23 // qSlicerllshCreateNewModelsModulePrivate methods
24
25 //-----------------------------------------------------------------------------
26 qSlicerllshCreateNewModelsModulePrivate::qSlicerllshCreateNewModelsModulePrivate()
27 {
28 }
29
30 //-----------------------------------------------------------------------------
31 // qSlicerllshCreateNewModelsModule methods
32
33 //-----------------------------------------------------------------------------
34 qSlicerllshCreateNewModelsModule::qSlicerllshCreateNewModelsModule(QObject* _parent)
35 : Superclass(_parent)
36 , d_ptr(new qSlicerllshCreateNewModelsModulePrivate)
37 {
38 }
39
40 //-----------------------------------------------------------------------------
41 qSlicerllshCreateNewModelsModule::~qSlicerllshCreateNewModelsModule()
42 {
43 }
44
45 //-----------------------------------------------------------------------------
46 QString qSlicerllshCreateNewModelsModule::helpText()const
47 {
48 return "For help on how to use this module visit: <a href='http://www.slicerigt.org
49 '>SlicerIGT</a>";
50 }
51
52 //-----------------------------------------------------------------------------
53 QString qSlicerllshCreateNewModelsModule::acknowledgementText()const
54 {
55 return "This work was was funded by Cancer Care Ontario and the Ontario Consortium for Adaptive Interventions in Radiation Oncology (OCAIRO)";
56 }
57
58 //-----------------------------------------------------------------------------
59 QStringList qSlicerllshCreateNewModelsModule::contributors()const
60 {
61 QStringList moduleContributors;
62 moduleContributors << QString( "Tamas Ungi (Queen's University)" );
63 return moduleContributors;
64 }
65
66 //-----------------------------------------------------------------------------
67 QIcon qSlicerllshCreateNewModelsModule::icon()const
68 {
69 return QIcon(":/Icons/llshCreateNewModels.png");
70 }
71
72 //-----------------------------------------------------------------------------
73 QStringList qSlicerllshCreateNewModelsModule::categories() const
74 {
75 return QStringList() << "TsinghuaMed";
76 }
77
78 //-----------------------------------------------------------------------------
79 QStringList qSlicerllshCreateNewModelsModule::dependencies() const
80 {
81 return QStringList();
82 }
83
84 //-----------------------------------------------------------------------------
85 void qSlicerllshCreateNewModelsModule::setup()
86 {
87 this->Superclass::setup();
88 }
89
90 //-----------------------------------------------------------------------------
91 qSlicerAbstractModuleRepresentation * qSlicerllshCreateNewModelsModule::createWidgetRepresentation()
92 {
93 return new qSlicerllshCreateNewModelsModuleWidget;
94 }
95
96 //-----------------------------------------------------------------------------
97 vtkMRMLAbstractLogic* qSlicerllshCreateNewModelsModule::createLogic()
98 {
99 return vtkSlicerllshCreateNewModelsLogic::New();
100 }
3.qSlicerCreateModelsModuleWidget.h
1 #ifndef __qSlicerllshCreateNewModelsModuleWidget_h
2 #define __qSlicerllshCreateNewModelsModuleWidget_h
3
4 // SlicerQt includes
5 #include "qSlicerAbstractModuleWidget.h"
6
7 #include "qSlicerllshCreateNewModelsModuleExport.h"
8
9 class qSlicerllshCreateNewModelsModuleWidgetPrivate;
10 class vtkMRMLNode; //文件之间类相互引用,必须进行声明
11
12 /// ingroup Slicer_QtModules_ExtensionTemplate
13 class Q_SLICER_QTMODULES_LLSHCREATENEWMODELS_EXPORT qSlicerllshCreateNewModelsModuleWidget :
14 public qSlicerAbstractModuleWidget
15 {
16 Q_OBJECT
17
18 public:
19
20 typedef qSlicerAbstractModuleWidget Superclass;
21 qSlicerllshCreateNewModelsModuleWidget(QWidget *parent=0);//隐式的构造函数
22 virtual ~qSlicerllshCreateNewModelsModuleWidget();
23
24 public slots:
25
26 void OnCreateNeedleClicked();//创建针模型按钮
27 void OnCreateCubeClicked(); //创建立方体模型按钮
28 void OnCreateCylinderClicked();//创建圆锥体模型按钮
29 void OnCreateSphereClicked();//创建球体按钮
30 void OnCreateCoordinateClicked();//创建坐标系按钮
31
32
33 protected:
34 QScopedPointer<qSlicerllshCreateNewModelsModuleWidgetPrivate> d_ptr;//智能指针
35
36 virtual void setup();
37
38 private:
39 Q_DECLARE_PRIVATE(qSlicerllshCreateNewModelsModuleWidget);
40 Q_DISABLE_COPY(qSlicerllshCreateNewModelsModuleWidget);
41 };
42
43 #endif
4.qSlicerCreateModelsModuleWidget.cpp
1 // Qt includes
2 #include <QDebug>
3 #include <QtGui>
4
5 // SlicerQt includes
6 #include "qSlicerCreateModelsModuleWidget.h"
7 #include "ui_qSlicerCreateModelsModule.h" //我们可以利用QtCreator进行设计
8
9 #include "vtkSlicerCreateModelsLogic.h" //Slicer的逻辑类用于创建简单模型
10 //-----------------------------------------------------------------------------
11 /// ingroup Slicer_QtModules_ExtensionTemplate
12 class qSlicerCreateModelsModuleWidgetPrivate: public Ui_qSlicerCreateModelsModule
13 {
14 Q_DECLARE_PUBLIC( qSlicerCreateModelsModuleWidget );
15 protected:
16 qSlicerCreateModelsModuleWidget* const q_ptr;
17 public:
18 qSlicerCreateModelsModuleWidgetPrivate( qSlicerCreateModelsModuleWidget& object );
19 vtkSlicerCreateModelsLogic* logic() const;
20 };
21
22 //-----------------------------------------------------------------------------
23 // qSlicerCreateModelsModuleWidgetPrivate methods
24
25 qSlicerCreateModelsModuleWidgetPrivate::qSlicerCreateModelsModuleWidgetPrivate( qSlicerCreateModelsModuleWidget& object )
26 : q_ptr( &object )
27 {
28 }
29
30
31 vtkSlicerCreateModelsLogic* qSlicerCreateModelsModuleWidgetPrivate::logic() const
32 {
33 Q_Q( const qSlicerCreateModelsModuleWidget );
34 return vtkSlicerCreateModelsLogic::SafeDownCast( q->logic() );
35 }
36
37 //-----------------------------------------------------------------------------
38 // qSlicerCreateModelsModuleWidget methods
39 //-----------------------------------------------------------------------------
40 qSlicerCreateModelsModuleWidget::qSlicerCreateModelsModuleWidget(QWidget* _parent): Superclass( _parent )
41 , d_ptr( new qSlicerCreateModelsModuleWidgetPrivate( *this ) )
42 {
43 }
44
45 //-----------------------------------------------------------------------------
46 qSlicerCreateModelsModuleWidget::~qSlicerCreateModelsModuleWidget()
47 {
48 }
49 void qSlicerCreateModelsModuleWidget::OnCreateNeedleClicked()
50 {
51 Q_D(qSlicerCreateModelsModuleWidget);
52 d->logic()->CreateNeedle( d->NeedleLength->value(), d->NeedleRadius->value(), d->NeedleTipRadius->value(), d->markersCheckBox->isChecked() );
53 }
54
55 void qSlicerCreateModelsModuleWidget::OnCreateCubeClicked()
56 {
57 Q_D(qSlicerCreateModelsModuleWidget);
58 d->logic()->CreateCube( d->CubeRLength->value(), d->CubeALength->value(), d->CubeSLength->value() );
59 }
60
61 void qSlicerCreateModelsModuleWidget::OnCreateCylinderClicked()
62 {
63 Q_D(qSlicerCreateModelsModuleWidget);
64 d->logic()->CreateCylinder( d->CylinderHeight->value(), d->CylinderRadius->value() );
65 }
66
67 void qSlicerCreateModelsModuleWidget::OnCreateSphereClicked()
68 {
69 Q_D(qSlicerCreateModelsModuleWidget);
70 d->logic()->CreateSphere( d->SphereRadius->value() );
71 }
72
73 void qSlicerCreateModelsModuleWidget::OnCreateCoordinateClicked()
74 {
75 Q_D( qSlicerCreateModelsModuleWidget );
76 d->logic()->CreateCoordinate( d->CAxisLengthSpinBox->value(), d->CAxisThicknessSpinBox->value() );
77 }
78
79 void qSlicerCreateModelsModuleWidget::setup()//信号槽~
80 {
81 Q_D(qSlicerCreateModelsModuleWidget);
82 d->setupUi(this);
83 this->Superclass::setup();
84
85 connect( d->CreateNeedleButton, SIGNAL( clicked() ), this, SLOT( OnCreateNeedleClicked() ) );
86 connect( d->CreateCubeButton, SIGNAL( clicked() ), this, SLOT( OnCreateCubeClicked() ) );
87 connect( d->CreateCylinderButton, SIGNAL( clicked() ), this, SLOT( OnCreateCylinderClicked() ) );
88 connect( d->CreateSphereButton, SIGNAL( clicked() ), this, SLOT( OnCreateSphereClicked() ) );
89 connect( d->CreateCoordinateButton, SIGNAL( clicked() ), this, SLOT( OnCreateCoordinateClicked() ) );
90 }
5.qSlicerCreateModelsModuleLogic.h
1 #ifndef __vtkSlicerllshCreateNewModelsLogic_h
2 #define __vtkSlicerllshCreateNewModelsLogic_h
3
4 // Slicer includes
5 #include "vtkSlicerModuleLogic.h"//逻辑基类
6
7 #include "vtkSlicerllshCreateNewModelsModuleLogicExport.h"
8
9 class vtkMRMLModelNode;
10 class vtkPolyData;
11
12 /// ingroup Slicer_QtModules_ExtensionTemplate
13 class VTK_SLICER_LLSHCREATENEWMODELS_MODULE_LOGIC_EXPORT vtkSlicerllshCreateNewModelsLogic :
14 public vtkSlicerModuleLogic
15 {
16 public:
17
18 static vtkSlicerllshCreateNewModelsLogic *New();//动态分配内存 创建对象
19 vtkTypeMacro(vtkSlicerllshCreateNewModelsLogic, vtkSlicerModuleLogic);
20 void PrintSelf(ostream& os, vtkIndent indent);
21
22 vtkMRMLModelNode* CreateNeedle( double length, double radius, double tipRadius, bool markers );
23 vtkMRMLModelNode* CreateCube( double x, double y, double z );
24 vtkMRMLModelNode* CreateCylinder( double height, double radius );
25 vtkMRMLModelNode* CreateSphere( double radius );
26 vtkMRMLModelNode* CreateCoordinate( double axisLength, double axisRadius );
27
28 protected:
29 vtkSlicerllshCreateNewModelsLogic();
30 virtual ~vtkSlicerllshCreateNewModelsLogic();
31
32 private:
33
34 void CreateCylinderData( vtkPolyData* polyData, double height, double radius );
35 void CreateConeData( vtkPolyData* polyData, double height, double radius );
36
37 vtkSlicerllshCreateNewModelsLogic(const vtkSlicerllshCreateNewModelsLogic&); // Not implemented
38 void operator=(const vtkSlicerllshCreateNewModelsLogic&); // Not implemented
39
40 };
41
42 #endif
6.qSlicerCreateModelsModuleLogic.cpp