]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ViewShowNPoints.cxx
b5ed682a8c1aafaf4da5d19d909f2657e11084ab
[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     ratioRadio                  = 0;
12 }
13 //----------------------------------------------------------------------
14
15 ViewShowNPoints::~ViewShowNPoints()
16 {
17 }
18
19
20 //------------------------------------------------------------------------
21
22 void ViewShowNPoints::RefreshPoint(int id)
23 {
24     double spc[3];
25     double x,y,z;
26     GetModelShowNPoints()->GetIdPoint(id,&x,&y,&z);
27     GetModelShowNPoints()->GetImage()->GetSpacing(spc);
28     std::string label     = GetModelShowNPoints()->GetIdLabel(id);
29     double radio          = GetModelShowNPoints()->GetRadio()  * ratioRadio;
30     lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
31     lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
32     lstSourceSphere[id]->SetRadius( radio );
33     lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
34 //EED 2017-01-01 Migration VTK7
35 #if VTK_MAJOR_VERSION <= 5
36     // ..
37 #else
38     lstSourceSphere[id]->Update();
39 #endif
40     lstActorsText[id]->SetInput( label.c_str()  );
41     lstActorsText[id]->SetPosition(  radio+spc[0]*x , spc[1]*y , spc[2]*z );
42 }
43
44 //------------------------------------------------------------------------
45 void ViewShowNPoints::RefreshEachPoint()
46 {
47     int id,size=lstActorsSphere.size();
48     for (id=0;id<size;id++)
49     {
50         RefreshPoint(id);
51     } // for
52 }
53
54 //------------------------------------------------------------------------
55 void ViewShowNPoints::RefreshPoints()
56 {
57     RefreshEachPoint();
58     renderer->GetRenderWindow()->Render();
59 }
60
61 //------------------------------------------------------------------------
62 void ViewShowNPoints::AddVtkPoint()
63 {
64     // Sphere
65     vtkSphereSource *vtksphere = vtkSphereSource::New();
66     vtksphere->SetThetaResolution (8);
67     vtksphere->SetPhiResolution (8);
68     vtksphere->SetRadius( 1 );
69     //NTU: For updating points
70     lstSourceSphere.push_back(vtksphere);
71     vtkPolyDataMapper *sphereMapper    = vtkPolyDataMapper::New();
72
73 //EED 2017-01-01 Migration VTK7
74 #if VTK_MAJOR_VERSION <= 5
75     sphereMapper->SetInput( vtksphere->GetOutput() );
76 #else
77     vtksphere->Update();
78     sphereMapper->SetInputData( vtksphere->GetOutput() );
79 #endif
80
81     vtkActor *sphereActor    = vtkActor::New();
82     sphereActor->SetMapper(sphereMapper);
83     sphereActor->SetOrigin(0, 0, 0);
84     lstActorsSphere.push_back(sphereActor);
85     
86     if(renderer==NULL){
87     // EED 2022-05-19
88     //    wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
89     //    dialog.ShowModal();
90         printf("EED ShowNPoints Warning: Renderer Not Set\n");
91         return;
92     }
93
94     lstActorAdded.push_back(true);
95     renderer->AddActor( sphereActor );
96     // Actor
97     vtkTextActor3D *textActor = vtkTextActor3D::New();
98 //    textActor->SetInput( strLabel.c_str()  );
99     renderer->AddActor( textActor );
100     lstActorsText.push_back(textActor);
101 }
102
103 //------------------------------------------------------------------------
104 void ViewShowNPoints::AddPoint()
105 {
106     AddVtkPoint();
107     RefreshPoint(lstActorsSphere.size()-1);
108 }
109
110 //------------------------------------------------------------------------
111 void ViewShowNPoints::Render()
112 {
113     renderer->GetRenderWindow()->Render();
114 }
115
116 //------------------------------------------------------------------------
117 void ViewShowNPoints::ErasePoint(int id)
118 {
119     if (this->renderer!=NULL)
120     {
121         if (id>=0)
122         {
123             renderer->RemoveActor( lstActorsSphere[id] );
124             renderer->RemoveActor( lstActorsText[id] );
125             lstActorsSphere[id]->Delete();
126             lstActorsText[id]->Delete();
127             lstSourceSphere[id]->Delete();
128             lstActorsSphere.erase( lstActorsSphere.begin()+id );
129             lstActorsText.erase( lstActorsText.begin()+id );
130             lstSourceSphere.erase( lstSourceSphere.begin()+id );
131             lstActorAdded.erase( lstActorAdded.begin()+id );
132         } // if id
133     } // if renderer
134 }
135
136 //------------------------------------------------------------------------
137 ModelShowNPoints* ViewShowNPoints::GetModelShowNPoints()
138 {
139     return mmodelShowNPoints;
140 }
141
142 //------------------------------------------------------------------------
143 void ViewShowNPoints::SetModelShowNPoints( ModelShowNPoints*  modelShowNPoints)
144 {
145     mmodelShowNPoints = modelShowNPoints;
146 }
147
148 //------------------------------------------------------------------------
149 void ViewShowNPoints::TryToShowActorInRender( int id, bool show )
150 {
151     if (show==false)  // try to remove actor to render
152     {
153         if (lstActorAdded[id]==true)
154         {
155             lstActorAdded[id]=false;
156             renderer->RemoveActor( lstActorsSphere[id] );
157             renderer->RemoveActor( lstActorsText[id] );
158         } // if lstActorAdded  true
159     } else { // try to add actor to render
160         if (lstActorAdded[id]==false)
161         {
162             lstActorAdded[id]=true;
163             renderer->AddActor( lstActorsSphere[id] );
164             renderer->AddActor( lstActorsText[id] );
165         } // if lstActorAdded  false
166     } // if show
167 }
168
169 //------------------------------------------------------------------------
170 void ViewShowNPoints::TryToShowActorsInRender( bool show )
171 {
172     int id,size=lstActorsSphere.size();
173     for (id=0;id<size;id++)
174     {
175         TryToShowActorInRender( id, show );
176     } // for id
177 }