]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlaneDirectionManager.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / PlaneDirectionManager.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #include "PlaneDirectionManager.h"
28
29 /********************************************************************************************
30 ** Start of data viewmanagerData
31 *********************************************************************************************/
32
33 PlaneDirectionManager::PlaneDirectionManager(int radio, double colour[3] , int opacity){        
34         _radio = radio;
35         _colour = colour;
36         _opacity = opacity;
37 }
38
39
40 PlaneDirectionManager::~PlaneDirectionManager(){
41         RemoveAllActorsFromIndex();
42 }
43
44 void PlaneDirectionManager::SetRenderer(vtkRenderer* render){
45     _render = render;
46 }
47 void PlaneDirectionManager::SetVectors( std::vector<double> lstPointsx, std::vector<double> lstPointsy, std::vector<double> lstPointsz){        
48
49         _lstPointsx = lstPointsx;
50         _lstPointsy = lstPointsy;
51         _lstPointsz = lstPointsz;
52 }
53
54 void PlaneDirectionManager::UpdateDirections() throw (std::exception){  
55         UpdateVectors();
56         UpdateActors();
57         AddActors();
58
59 }
60
61 void PlaneDirectionManager::AddActors(){
62         int i;
63     for(i = 0; i < (int)_vectdata.size();i++){
64                 _render->AddViewProp (_vectdata[i]->GetActor());                
65         }
66 }
67
68 void PlaneDirectionManager::RemoveAllActorsFromIndex(int n)throw (std::exception){
69         /*due to incompleate set of points to create the plane
70         */                              
71         if(_render==NULL){
72                 throw std::exception();
73         }
74         for(int i = _vectdata.size()-1; i >= n;i--){
75                 _render->RemoveViewProp(_vectdata[i]->GetActor());
76                 delete _vectdata[i];
77                 _vectdata.pop_back();
78         }       
79 }
80 void PlaneDirectionManager::UpdateVectors()throw (std::exception){
81         PlaneDirectionManagerData* temp;
82         bool deletelast = false;
83         int currentdata = 0;
84         int i;
85         for(i = 0; i < (int)_lstPointsx.size();i++){
86                 if(i % 3 == 0){ 
87                         if((int)_vectdata.size()>currentdata){
88                                 temp = _vectdata[currentdata];
89                         }else{
90                                 temp = new PlaneDirectionManagerData(_radio, _colour, _opacity);
91                                 _vectdata.push_back(temp);
92                         }
93                         temp->setPoint0(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);
94                         deletelast = true;
95                 }else if(i % 3 == 1){
96             temp->setPoint1(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);                      
97                 }else if(i % 3 == 2){
98                         temp->setPoint2(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);                                          
99                         currentdata++;
100                         deletelast = false;
101                 }
102         }
103         RemoveAllActorsFromIndex(currentdata);
104 }
105
106 void PlaneDirectionManager::UpdateActors()
107 {
108         int i;
109     for(i = 0; i < (int)_vectdata.size();i++)
110         {
111                 _vectdata[i]->UpdateActor();
112         }
113 }
114
115 void PlaneDirectionManager::addRemoveActor(int index, bool addremove)
116 {
117         if(index < (int)_vectdata.size()){
118                 if(addremove){
119                         _render->AddViewProp (_vectdata[index]->GetActor());
120                 }else{
121                         _render->RemoveViewProp (_vectdata[index]->GetActor());
122                 }       
123         }       
124 }
125
126 void PlaneDirectionManager::changeColor(int index,double r,double g,double b)
127 {
128     GetPlaneDirectionManagerData(index)->ChangeColour(r,g,b);
129 }
130
131 PlaneDirectionManagerData* PlaneDirectionManager::GetPlaneDirectionManagerData(int id) 
132 {
133         return _vectdata[id];
134 }
135
136 void PlaneDirectionManager::WriteInformation(std::string  filename, double* spc){
137         FILE *ff;       
138         ff = fopen( filename.c_str() , "w+" );
139         if(spc ==NULL){
140                 spc = new double[3];
141                 spc[0] = 1;
142                 spc[1] = 1;
143                 spc[2] = 1;
144         }
145         if (ff!=NULL)
146         {           
147                 int i;
148                 for(i = 0; i < (int)_vectdata.size();i++){
149
150                         double* p0 = _vectdata[i]->getPoint0();
151                         double* p1 = _vectdata[i]->getPoint1();
152                         double* p2 = _vectdata[i]->getPoint2();
153                         double* dir = _vectdata[i]->GetDirection();
154
155                         double p0x = p0[0]/spc[0];
156                         double p0y = p0[1]/spc[1];
157                         double p0z = p0[2]/spc[2];
158
159                         double p1x = p1[0]/spc[0];
160                         double p1y = p1[1]/spc[1];
161                         double p1z = p1[2]/spc[2];
162
163                         double p2x = p2[0]/spc[0];
164                         double p2y = p2[1]/spc[1];
165                         double p2z = p2[2]/spc[2];
166
167                         double dirx = dir[0]/spc[0];
168                         double diry = dir[1]/spc[1];
169                         double dirz = dir[2]/spc[2];
170
171                         fprintf(ff,"Dir%d\n",i);
172             fprintf(ff,"\tP0[%f, %f, %f]\tP1[%f, %f, %f]\tP2[%f, %f, %f]\tDir[%f, %f, %f] \n",
173                                                         p0x,p0y,p0z,    p1x,p1y,p1z,    p2x,p2y,p2z,    dirx,diry,dirz);
174                 }                       
175                 fclose(ff);
176         } else {   // else ff
177                 printf("PlaneDirectionManager::WriteInformation  ...Error... creating file");
178         } //ff  
179 }
180
181 void  PlaneDirectionManager::SetArrowSize(int arrowsize){
182     _radio = arrowsize;
183 }