]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkTensorsVisu.cpp
#2501 creaVtk Bug New Normal - Clean events in Vectors and Tensors visu widgets...
[creaVtk.git] / lib / creaVtk / vtkTensorsVisu.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
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 "vtkTensorsVisu.h"
29
30 #include "vtkProperty.h"
31
32 //------------------------------------------------------------------------
33 vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase()
34 {
35         ss                                      = vtkSphereSource::New();
36         superquadratic  = vtkSuperquadricSource::New();
37         cs                                      = vtkCubeSource::New(); 
38         tg                                      = vtkTensorGlyph::New();
39         pdn                                     = vtkPolyDataNormals::New();
40         pd                                      = vtkPolyData::New();
41         pod                                     = vtkPointData::New();
42 }
43
44 //------------------------------------------------------------------------
45 vtkTensorsVisu::~vtkTensorsVisu()
46 {
47 }
48
49
50 //------------------------------------------------------------------------
51 void vtkTensorsVisu::Process()
52 {
53 printf("EED vtkTensorsVisu::Process Start\n");
54
55   if (_active==true)
56   {
57         if(GetTypeForm()==2)                                                            // source superquadratic
58         {
59                 superquadratic->SetThetaResolution(20);
60                 superquadratic->SetPhiResolution(20);
61                 tg->SetSource(superquadratic->GetOutput());
62         } else if(GetTypeForm()==1) {                                   // source sphere
63                 tg->SetSource(ss->GetOutput());
64         } else {                                                                                                // source cube
65                 tg->SetSource(cs->GetOutput());         
66         }
67
68
69         tg->SetInput( GetDataObject() );
70         //              tg->ScalingOn();
71         //              tg->SetScaling(25);
72         //if(isfromcal)
73         tg->SetScaleFactor( GetScaleFactor() );
74         tg->ScalingOn(  );      
75         //else
76         //      //tg->SetScaleFactor(2);
77         //      tg->SetScaleFactor(scale_factor);
78 //EED   tg->Update();
79
80         //The normals are needed to generate the right colors and if
81         // not used some of the glyphs are black.
82         pdn->SetInput(tg->GetOutput());
83 //EED   pdn->Update();
84
85
86         //EED================================
87         //pdm->SetInput( tg->GetOutput());
88         //pdm->SetScalarRange( range );
89
90         //vtkPolyData           *pd                     = tg->GetOutput();
91         //vtkPointData  *pointdata      = pd->GetPointData();
92         //vtkDataArray  *da                     = pointdata->GetVectors();
93
94         //vtkDataArray *nda = vtkFloatArray::New();
95         //nda->DeepCopy(da);
96
97         //pointdata->AddArray( nda );
98         //reader->GetOutput()->GetPointData()->AddArray( nda );
99
100         //pdm->SetInput(pdn->GetOutput());
101         //pdm->ScalarVisibilityOn();
102         //pdm->SetLookupTable(vLutEED);
103         //pdm->SetColorModeToMapScalars();
104         //pdm->SelectColorArray("color");
105         //pdm->SetScalarModeToUsePointFieldData();
106         //pdm->ImmediateModeRenderingOn();
107         //=====================================
108
109         _pdm->SetInput( pdn->GetOutput() );
110         _pdm->ImmediateModeRenderingOn();
111
112    _pdm->ScalarVisibilityOn();
113    _pdm->SetScalarModeToUsePointFieldData();
114
115
116 //EED   _pdm->Update();
117
118         _actor->SetMapper( _pdm );
119    _actor->GetProperty()->SetOpacity( GetOpacity() );
120
121         tg->ColorGlyphsOn();
122 //      tg->ExtractEigenvaluesOn();
123         tg->SetColorModeToEigenvalues();
124
125         _pdm->SetLookupTable( _LutEED );
126    _pdm->SelectColorArray( "Normals" );
127
128
129         //int tcg = tg->GetColorGlyphs();
130 //      tg->SetColorGlyphs(10);
131 //      tg->SetColorModeToScalars();
132         //tg->ThreeGlyphsOn();
133
134
135         //vtkDataArray* da = vtkDataArray::New();
136         pd = tg->GetOutput();
137         pd->Update();
138         pod = pd->GetPointData();
139         pod->Update();
140 //EED1  if(pod->GetScalars())
141 //EED1  {
142 //EED1          _pdm->SetScalarRange(pod->GetScalars()->GetRange());
143 //EED1  }
144         //pdm->SelectColorArray("GlyphVector");
145
146 //EED   _pdm->Update(); 
147
148
149 //EED1                  tg->Print( std::cout );
150 //EED1          printf("EED vtkTensorsVisu::Process  ------------------------------------------\n");
151 //EED1                  pd->Print( std::cout );
152
153
154         tg->Update();
155                         vtkPolyData     *pd             = pdn->GetOutput();
156                         vtkPointData    *pointdata      = pd->GetPointData();
157
158
159 //EED1          printf("EED vtkTensorsVisu::Process  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx\n");
160 //EED1                  pointdata->Print( std::cout );
161                         
162
163                         int aa = pd->GetNumberOfPieces ();
164                         int bb = pd->GetNumberOfVerts ();
165                         int cc = pd->GetNumberOfLines ();
166                         int dd = pd->GetNumberOfPolys ();
167                         int ee = pd->GetNumberOfStrips ();
168                         int ff = pd->GetNumberOfCells();
169
170                 printf("EED vtkTensorsVisu::Process  %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff);
171
172                         vtkPolyData *ttt = (vtkPolyData *)GetDataObject();
173                         int numPnts = ttt->GetNumberOfPoints();
174                         printf("EED vtkTensorsVisu::Process  numPnts %d \n", numPnts );
175
176
177                         vtkIdType numSourcePts, numSourceCells;
178                         vtkPoints *sourcePts;
179                         sourcePts = tg->GetSource()->GetPoints();
180                         numSourcePts = sourcePts->GetNumberOfPoints();
181                         numSourceCells = tg->GetSource()->GetNumberOfCells();
182                         printf("EED vtkTensorsVisu::Process  numSourcePts %d   numSourceCells %d\n", numSourcePts, numSourceCells);
183
184
185
186                         int i,sizeDa = pointdata->GetNumberOfArrays();
187                         printf("EED vtkTensorsVisu::Process  sizeDa %d \n", sizeDa );
188                         for (i=0;i<sizeDa;i++)
189                         {
190                                 int faces = pointdata->GetArray(i)->GetSize() / numPnts;
191                                 printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d   %d \n", i, pointdata->GetArrayName(i) , pointdata->GetArray(i)->GetSize(), faces );
192                         }
193
194
195
196
197   } // _active
198
199     VisibilityActor(); 
200
201 printf("EED vtkTensorsVisu::Process End.\n");
202 }
203