]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ViewShowNPoints.cxx
#3485 ShowNPionts for Multiple Groups
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ViewShowNPoints.cxx
1
2
3 #include "ViewShowNPoints.h"
4
5
6 //----------------------------------------------------------------------
7 ViewShowNPoints::ViewShowNPoints(ModelShowNPoints* modelShowNPoints)
8 {
9     renderer                    = NULL;
10     mmodelShowNPoints=modelShowNPoints;
11 }
12 //----------------------------------------------------------------------
13
14 ViewShowNPoints::~ViewShowNPoints()
15 {
16 }
17
18
19 //------------------------------------------------------------------------
20     
21 void ViewShowNPoints::RefreshPoint(int id)
22 {
23     double spc[3];
24     int x,y,z;
25     GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
26     GetModelShowNPoints()->GetImage()->GetSpacing(spc);
27     std::string label     = GetModelShowNPoints()->GetIdLabel(id);
28     double radio         = GetModelShowNPoints()->GetRadio();
29     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
30     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
31     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
32     lstSourceSphere[id]->SetRadius( radio );
33 //EED 2017-01-01 Migration VTK7
34 #if VTK_MAJOR_VERSION <= 5
35     // ..
36 #else
37     lstSourceSphere[id]->Update();
38 #endif
39     lstActorsText[id]->SetInput( label.c_str()  );
40     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
41 }
42
43 //------------------------------------------------------------------------
44 void ViewShowNPoints::RefreshPoints()
45 {
46     int id,size=lstActorsSphere.size();
47     for (id=0;id<size;id++)
48     {
49         RefreshPoint(id);
50     } // for
51     renderer->GetRenderWindow()->Render();
52 }
53
54 //------------------------------------------------------------------------
55 void ViewShowNPoints::AddVtkPoint()
56 {
57     // Sphere
58     vtkSphereSource *vtksphere = vtkSphereSource::New();
59     vtksphere->SetThetaResolution (20);
60     vtksphere->SetPhiResolution (20);
61     vtksphere->SetRadius( 1 );
62     //NTU: For updating points
63     lstSourceSphere.push_back(vtksphere);
64     vtkPolyDataMapper *sphereMapper    = vtkPolyDataMapper::New();
65
66 //EED 2017-01-01 Migration VTK7
67 #if VTK_MAJOR_VERSION <= 5
68     sphereMapper->SetInput( vtksphere->GetOutput() );
69 #else
70     vtksphere->Update();
71     sphereMapper->SetInputData( vtksphere->GetOutput() );
72 #endif
73
74     vtkActor *sphereActor    = vtkActor::New();
75     sphereActor->SetMapper(sphereMapper);
76     sphereActor->SetOrigin(0, 0, 0);
77
78     lstActorsSphere.push_back(sphereActor);
79     
80     if(renderer==NULL){
81     // EED 2022-05-19
82     //    wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
83     //    dialog.ShowModal();
84         printf("EED ShowNPoints Warning: Renderer Not Set\n");
85         return;
86     }
87     
88     renderer->AddActor( sphereActor );
89     // Actor
90     vtkTextActor3D *textActor = vtkTextActor3D::New();
91 //    textActor->SetInput( strLabel.c_str()  );
92     renderer->AddActor( textActor );
93     lstActorsText.push_back(textActor);
94 }
95
96 //------------------------------------------------------------------------
97 void ViewShowNPoints::AddPoint()
98 {
99     AddVtkPoint();
100     RefreshPoint(lstActorsSphere.size()-1);
101 }
102
103 //------------------------------------------------------------------------
104 void ViewShowNPoints::Render()
105 {
106     renderer->GetRenderWindow()->Render();
107 }
108
109 //------------------------------------------------------------------------
110 void ViewShowNPoints::ErasePoint(int id)
111 {
112     if (this->renderer!=NULL)
113     {
114         if (id>=0)
115         {
116             renderer->RemoveActor( lstActorsSphere[id] );
117             renderer->RemoveActor( lstActorsText[id] );
118             lstActorsSphere[id]->Delete();
119             lstActorsText[id]->Delete();
120             lstSourceSphere[id]->Delete();
121             lstActorsSphere.erase( lstActorsSphere.begin()+id );
122             lstActorsText.erase( lstActorsText.begin()+id );
123             lstSourceSphere.erase( lstSourceSphere.begin()+id );
124         } // if id
125     } // if renderer
126 }
127
128 //------------------------------------------------------------------------
129 ModelShowNPoints* ViewShowNPoints::GetModelShowNPoints()
130 {
131     return mmodelShowNPoints;
132 }
133
134 //------------------------------------------------------------------------
135 void ViewShowNPoints::SetModelShowNPoints( ModelShowNPoints*  modelShowNPoints)
136 {
137     mmodelShowNPoints=modelShowNPoints;
138 }