]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
Feature #1774
[bbtk.git] / packages / vtk / src / bbvtkSphereList.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 #include "bbvtkSphereList.h"
29 #include "bbvtkPackage.h"
30
31 #include <vtkPolyDataMapper.h>
32 #include <vtkProperty.h>
33 #include <vtkRenderWindow.h>
34
35 namespace bbvtk
36 {
37
38 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SphereList)
39 BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
40
41 void SphereList::Process()
42 {
43
44     int iMin, iMax;
45         double px = 0.0;
46         double py = 0.0;
47         double pz = 0.0;
48         double radio;
49         double spc[3];
50  
51         int last_valid_color_index = 0;
52
53         if (bbGetInputRenderer()!=NULL)
54         {
55                 if (bbGetInputSpacing().size()==3)
56                 {
57                         spc[0]=bbGetInputSpacing()[0];
58                         spc[1]=bbGetInputSpacing()[1];
59                         spc[2]=bbGetInputSpacing()[2];
60                 } else {
61                         spc[0]=spc[1]=spc[2]=1;
62                 }
63
64                 iMin=0;
65                 iMax=bbGetInputlstPointX().size();
66                 printf("EED SphereList::Process   iMax=%d \n", iMax);
67                 // If the vector Y or respectively the vector Z has a different size from the vector X, the position value py or respectively pz is set to 0.
68                 for ( int i=iMin ; i<iMax ; i=i+1 )
69                 {
70                         px = bbGetInputlstPointX()[i]*spc[0];
71                         if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
72                         {
73                             py = bbGetInputlstPointY()[i]*spc[1];
74                         }
75                         if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
76                         {                       
77                             pz = bbGetInputlstPointZ()[i]*spc[2];
78                         }
79
80                         // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
81                         if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
82                           {
83                             radio = bbGetInputlstRadio()[i];
84                           }
85                         else
86                           {
87                             if  (bbGetInputlstRadio().size()>=1){
88                                radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
89                                 } else {
90                                         radio = 1.0;
91                                 }
92                           }
93
94                         // Sphere
95                         vtkSphereSource * newSphere =  vtkSphereSource::New();
96                         vtkSphere.push_back(newSphere);
97
98                         newSphere -> SetThetaResolution(20);
99                         newSphere -> SetPhiResolution(20);
100                         newSphere -> SetRadius(radio); 
101
102                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
103                         sphereMapper.push_back(newMapper);
104                         newMapper -> SetInput( newSphere -> GetOutput() );
105         
106                         vtkActor * newActor = vtkActor::New();
107                         sphereActor.push_back(newActor);
108                         newActor -> SetMapper(newMapper);
109                         newActor -> SetOrigin(0, 0, 0);
110                         
111                         unsigned int j = 3*i +2;
112                         if (j < bbGetInputColour().size() )
113                           {
114                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
115                             last_valid_color_index = 3*i;
116                           }
117                         else
118                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
119
120                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
121                         newActor -> SetPosition( px,py,pz );
122         
123                         if ( bbGetInputTransform()!=NULL )
124                         {
125                                 newActor->SetUserTransform( bbGetInputTransform() );
126                         }
127         
128
129                         if (bbGetInputRenderer()!=NULL)
130                           {
131                             bbGetInputRenderer() -> AddActor( newActor );
132                           }
133
134                 } // for
135
136                 if (sphereActor.size() != 0)
137                   {
138                     // Sets the output.
139                     bbSetOutputActorList(sphereActor);
140                   }
141
142         } // if (bbGetInputRenderer()!=NULL)
143
144
145 }
146
147 void SphereList::bbUserSetDefaultValues()
148 {
149  
150   bbSetInputRenderer(NULL);
151   bbSetInputTransform(NULL);
152  
153   // Sets default radio to 1.
154   std::vector<double> radio;
155   radio.push_back(1.0);
156   bbSetInputlstRadio(radio);
157
158   // Sets default colour to red.
159   std::vector<double> colour;
160   colour.push_back(1.0);
161   colour.push_back(0.0);
162   colour.push_back(0.0);
163   bbSetInputColour(colour);
164         
165         // Sets default spacing.
166         std::vector<double> spacing;
167         spacing.push_back(1.0);
168         spacing.push_back(1.0);
169         spacing.push_back(1.0);
170         bbSetInputSpacing(spacing);
171         
172   bbSetInputOpacity(1.0);
173
174 }
175
176 void SphereList::bbUserInitializeProcessing()
177 {
178  
179 }
180
181 void SphereList::bbUserFinalizeProcessing()
182 {
183   
184 }
185 }
186 // EO namespace bbvtk
187
188