]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
95f14ad5ae3eca0e2b886b662eb689e1331497bd
[bbtk.git] / packages / vtk / src / bbvtkSphereList.cxx
1 #include "bbvtkSphereList.h"
2 #include "bbvtkPackage.h"
3
4 #include <vtkPolyDataMapper.h>
5 #include <vtkProperty.h>
6 #include <vtkRenderWindow.h>
7
8 namespace bbvtk
9 {
10
11 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SphereList)
12 BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
13
14 void SphereList::Process()
15 {
16
17     int iMin, iMax;
18         double px = 0.0;
19         double py = 0.0;
20         double pz = 0.0;
21         double radio;
22         double spc[3];
23  
24         int last_valid_color_index = 0;
25
26         if (bbGetInputRenderer()!=NULL)
27         {
28                 if (bbGetInputSpacing().size()==3)
29                 {
30                         spc[0]=bbGetInputSpacing()[0];
31                         spc[1]=bbGetInputSpacing()[1];
32                         spc[2]=bbGetInputSpacing()[2];
33                 } else {
34                         spc[0]=spc[1]=spc[2]=1;
35                 }
36
37                 iMin=0;
38                 iMax=bbGetInputlstPointX().size();
39                 printf("EED SphereList::Process   iMax=%d \n", iMax);
40                 // 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.
41                 for ( int i=iMin ; i<iMax ; i=i+1 )
42                 {
43                         px = bbGetInputlstPointX()[i]*spc[0];
44                         if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
45                         {
46                             py = bbGetInputlstPointY()[i]*spc[1];
47                         }
48                         if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
49                         {                       
50                             pz = bbGetInputlstPointZ()[i]*spc[2];
51                         }
52
53                         // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
54                         if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
55                           {
56                             radio = bbGetInputlstRadio()[i];
57                           }
58                         else
59                           {
60                             if  (bbGetInputlstRadio().size()>=1){
61                                radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
62                                 } else {
63                                         radio = 1.0;
64                                 }
65                           }
66
67                         // Sphere
68                         vtkSphereSource * newSphere =  vtkSphereSource::New();
69                         vtkSphere.push_back(newSphere);
70
71                         newSphere -> SetThetaResolution(20);
72                         newSphere -> SetPhiResolution(20);
73                         newSphere -> SetRadius(radio); 
74
75                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
76                         sphereMapper.push_back(newMapper);
77                         newMapper -> SetInput( newSphere -> GetOutput() );
78         
79                         vtkActor * newActor = vtkActor::New();
80                         sphereActor.push_back(newActor);
81                         newActor -> SetMapper(newMapper);
82                         newActor -> SetOrigin(0, 0, 0);
83                         
84                         unsigned int j = 3*i +2;
85                         if (j < bbGetInputColour().size() )
86                           {
87                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
88                             last_valid_color_index = 3*i;
89                           }
90                         else
91                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
92
93                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
94                         newActor -> SetPosition( px,py,pz );
95         
96                         if ( bbGetInputTransform()!=NULL )
97                         {
98                                 newActor->SetUserTransform( bbGetInputTransform() );
99                         }
100         
101
102                         if (bbGetInputRenderer()!=NULL)
103                           {
104                             bbGetInputRenderer() -> AddActor( newActor );
105                           }
106
107                 } // for
108
109                 if (sphereActor.size() != 0)
110                   {
111                     // Sets the output.
112                     bbSetOutputActorList(sphereActor);
113                   }
114
115         } // if (bbGetInputRenderer()!=NULL)
116
117
118 }
119
120 void SphereList::bbUserSetDefaultValues()
121 {
122  
123   bbSetInputRenderer(NULL);
124   bbSetInputTransform(NULL);
125  
126   // Sets default radio to 1.
127   std::vector<double> radio;
128   radio.push_back(1.0);
129   bbSetInputlstRadio(radio);
130
131   // Sets default colour to red.
132   std::vector<double> colour;
133   colour.push_back(1.0);
134   colour.push_back(0.0);
135   colour.push_back(0.0);
136   bbSetInputColour(colour);
137         
138         // Sets default spacing.
139         std::vector<double> spacing;
140         spacing.push_back(1.0);
141         spacing.push_back(1.0);
142         spacing.push_back(1.0);
143         bbSetInputSpacing(spacing);
144         
145   bbSetInputOpacity(1.0);
146
147 }
148
149 void SphereList::bbUserInitializeProcessing()
150 {
151  
152 }
153
154 void SphereList::bbUserFinalizeProcessing()
155 {
156   
157 }
158 }
159 // EO namespace bbvtk
160
161