]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ViewShowNPoints.cxx
008f5cf8cac887c8c36b1d2cf052bd6bceaab47f
[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     double 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::RefreshEachPoint()
45 {
46     int id,size=lstActorsSphere.size();
47     for (id=0;id<size;id++)
48     {
49         RefreshPoint(id);
50     } // for
51 }
52
53 //------------------------------------------------------------------------
54 void ViewShowNPoints::RefreshPoints()
55 {
56     RefreshEachPoint();
57     renderer->GetRenderWindow()->Render();
58 }
59
60 //------------------------------------------------------------------------
61 void ViewShowNPoints::AddVtkPoint()
62 {
63     // Sphere
64     vtkSphereSource *vtksphere = vtkSphereSource::New();
65     vtksphere->SetThetaResolution (10);
66     vtksphere->SetPhiResolution (10);
67     vtksphere->SetRadius( 1 );
68     //NTU: For updating points
69     lstSourceSphere.push_back(vtksphere);
70     vtkPolyDataMapper *sphereMapper    = vtkPolyDataMapper::New();
71
72 //EED 2017-01-01 Migration VTK7
73 #if VTK_MAJOR_VERSION <= 5
74     sphereMapper->SetInput( vtksphere->GetOutput() );
75 #else
76     vtksphere->Update();
77     sphereMapper->SetInputData( vtksphere->GetOutput() );
78 #endif
79
80     vtkActor *sphereActor    = vtkActor::New();
81     sphereActor->SetMapper(sphereMapper);
82     sphereActor->SetOrigin(0, 0, 0);
83
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     renderer->AddActor( sphereActor );
95     // Actor
96     vtkTextActor3D *textActor = vtkTextActor3D::New();
97 //    textActor->SetInput( strLabel.c_str()  );
98     renderer->AddActor( textActor );
99     lstActorsText.push_back(textActor);
100 }
101
102 //------------------------------------------------------------------------
103 void ViewShowNPoints::AddPoint()
104 {
105     AddVtkPoint();
106     RefreshPoint(lstActorsSphere.size()-1);
107 }
108
109 //------------------------------------------------------------------------
110 void ViewShowNPoints::Render()
111 {
112     renderer->GetRenderWindow()->Render();
113 }
114
115 //------------------------------------------------------------------------
116 void ViewShowNPoints::ErasePoint(int id)
117 {
118     if (this->renderer!=NULL)
119     {
120         if (id>=0)
121         {
122             renderer->RemoveActor( lstActorsSphere[id] );
123             renderer->RemoveActor( lstActorsText[id] );
124             lstActorsSphere[id]->Delete();
125             lstActorsText[id]->Delete();
126             lstSourceSphere[id]->Delete();
127             lstActorsSphere.erase( lstActorsSphere.begin()+id );
128             lstActorsText.erase( lstActorsText.begin()+id );
129             lstSourceSphere.erase( lstSourceSphere.begin()+id );
130         } // if id
131     } // if renderer
132 }
133
134 //------------------------------------------------------------------------
135 ModelShowNPoints* ViewShowNPoints::GetModelShowNPoints()
136 {
137     return mmodelShowNPoints;
138 }
139
140 //------------------------------------------------------------------------
141 void ViewShowNPoints::SetModelShowNPoints( ModelShowNPoints*  modelShowNPoints)
142 {
143     mmodelShowNPoints = modelShowNPoints;
144 }