]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxe3D.cxx
9d65ade80712dd580a5db61edbd0472ae07bd1a9
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuDrawAxe3D.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 #include "bbmaracasvisuDrawAxe3D.h"
27 #include "bbcreaMaracasVisuPackage.h"
28
29 #include "vtkImageData.h"
30 #include "vtkActor.h"
31 #include "vtkPoints.h"
32 #include "vtkCellArray.h"
33 #include "vtkProperty.h"
34
35 #include "vtkLinearTransform.h"
36 namespace bbcreaMaracasVisu
37 {
38
39 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxe3D)
40 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxe3D,bbtk::AtomicBlackBox);
41 void DrawAxe3D::Process()
42 {
43         std::vector< double > vectx = bbGetInputlstPointX();
44         std::vector< double > vecty = bbGetInputlstPointY();
45         std::vector< double > vectz = bbGetInputlstPointZ();    
46
47 //      vtkImageData* img = bbGetInputImage();  
48         unsigned int i;
49         double spc[3];  
50 //      img->GetSpacing(spc);
51         spc[0]=1;
52         spc[1]=1;
53         spc[2]=1;
54
55         if(!vectx.empty()&&!vecty.empty()&&!vectz.empty()){
56                 vtkPoints* allPoints = vtkPoints::New( );
57                 vtkCellArray* allTopology = vtkCellArray::New( );
58                 allTopology->InsertNextCell( vectx.size() );
59
60                 for( i = 0; i < vectx.size( ); i++) {   
61                         //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
62                         //hay parametro dicom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
63                         allPoints->InsertNextPoint( vectx[i]*spc[0],  vecty[i]*spc[1], vectz[i]*spc[2] );
64                         allTopology->InsertCellPoint( i );
65                 } // rof
66                 mallData->SetPoints( allPoints );
67                 mallData->SetLines( allTopology );
68                 allPoints->Delete();
69                 allTopology->Delete();  
70         }
71
72         mvtkactor->GetProperty()->SetColor( bbGetInputColour()[0],  
73                                 bbGetInputColour()[1], 
74                                 bbGetInputColour()[2] );
75         //EC Axe Opacity property added
76         ///Default Values
77         double opacity=bbGetInputOpacity();
78         mvtkactor->GetProperty()->SetOpacity( opacity );
79         if ( bbGetInputTransform()!=NULL )
80         {
81                 mvtkactor->SetUserTransform( bbGetInputTransform() );
82         }
83
84      // Interface Update
85      if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
86      {
87                 firsttime=false;
88             bbGetInputRenderer()->AddActor( mvtkactor );
89      }
90 }
91
92 void DrawAxe3D::bbUserSetDefaultValues()
93 {
94         firsttime        = true;
95         mallData         = NULL;
96         polydatamapper   = NULL;
97         mvtkactor        = NULL;
98
99     std::vector<double> colour;
100     colour.push_back(1.0);
101     colour.push_back(0.0);
102     colour.push_back(0.0);
103     bbSetInputColour(colour);
104     bbSetInputOpacity(1.0);
105 }
106
107
108
109         //-----------------------------------------------------------------     
110         void DrawAxe3D::bbUserInitializeProcessing()
111         {
112                 mallData       = vtkPolyData::New( );
113                 polydatamapper = vtkPolyDataMapper::New();
114                 mvtkactor      = vtkActor::New();
115                 
116                 polydatamapper->SetInput(mallData);
117                 mvtkactor->SetMapper(polydatamapper);
118                 bbSetOutputOut(mvtkactor);
119         }
120
121         //-----------------------------------------------------------------     
122         void DrawAxe3D::bbUserFinalizeProcessing()
123         {
124                 if (mallData!=NULL)
125                 {
126                         mallData->Delete();
127                         mallData=NULL;
128                 }
129                 
130                 if (polydatamapper!=NULL)
131                 {
132                         polydatamapper->Delete();
133                         polydatamapper=NULL;
134                 }
135                 
136                 if (mvtkactor!=NULL)
137                 {
138                         mvtkactor->Delete();
139                         mvtkactor=NULL;
140                 }
141         }
142
143         //-----------------------------------------------------------------     
144 }
145
146 // EO namespace bbcreaMaracasVisu
147
148