GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TraceStructure.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #include "TraceStructure.h"
36 
37 #include <iostream>
38 #include "vtkPolyData.h"
39 #include "vtkCellArray.h"
40 #include "vtkActor.h"
41 #include "vtkMapper.h"
42 #include "vtkDoubleArray.h"
43 #include "vtkPointData.h"
44 #include "vtkLookupTable.h"
45 
46 //--------------------------------------------------------------------------
47 TraceStructure::TraceStructure() : TraceID(0), CollectionID(0),
48  ActorXY(NULL), ActorXZ(NULL), ActorYZ(NULL), ActorXYZ(NULL), Nodes(NULL),
49  Highlighted(false), Visible(false)
50 {
51  this->rgba[0] = 1.;
52  this->rgba[1] = 1.;
53  this->rgba[2] = 1.;
54  this->rgba[3] = 1.;
55 }
56 
57 //--------------------------------------------------------------------------
58 
59 //--------------------------------------------------------------------------
61  const unsigned int & iTraceID,
62  const unsigned int & iCollectionID,
63  std::vector< vtkActor * > iActors,
64  vtkPolyData *iNodes,
65  const bool & iHighlighted,
66  const bool & iVisible,
67  const double & r,
68  const double & g,
69  const double & b,
70  const double & alpha) :
71  TraceID(iTraceID), CollectionID(iCollectionID),
72  Nodes(iNodes), Highlighted(iHighlighted), Visible(iVisible)
73 {
74  if ( iActors.size() == 4 )
75  {
76  ActorXY = iActors[0];
77  ActorXZ = iActors[1];
78  ActorYZ = iActors[2];
79  ActorXYZ = iActors[3];
80  }
81  else
82  {
83  std::cerr << "iActors.size() != 4" << std::endl;
84  return;
85  }
86  this->rgba[0] = r;
87  this->rgba[1] = g;
88  this->rgba[2] = b;
89  this->rgba[3] = alpha;
90 }
91 
92 //--------------------------------------------------------------------------
93 
94 //--------------------------------------------------------------------------
95 TraceStructure::TraceStructure(const unsigned int & iTraceID,
96  const unsigned int & iCollectionID,
97  std::vector< vtkActor * > iActors,
98  vtkPolyData *iNodes,
99  const bool & iHighlighted,
100  const bool & iVisible,
101  double iRgba[4]) :
102  TraceID(iTraceID), CollectionID(iCollectionID),
103  Nodes(iNodes), Highlighted(iHighlighted), Visible(iVisible)
104 {
105  if ( iActors.size() == 4 )
106  {
107  ActorXY = iActors[0];
108  ActorXZ = iActors[1];
109  ActorYZ = iActors[2];
110  ActorXYZ = iActors[3];
111  }
112  else
113  {
114  std::cout << "iActors.size() != 4" << std::endl;
115  return;
116  }
117  this->rgba[0] = iRgba[0];
118  this->rgba[1] = iRgba[1];
119  this->rgba[2] = iRgba[2];
120  this->rgba[3] = iRgba[3];
121 }
122 
123 //--------------------------------------------------------------------------
124 
125 //--------------------------------------------------------------------------
126 TraceStructure::TraceStructure(const unsigned int & iTraceID,
127  const unsigned int & iCollectionID,
128  vtkActor *iActorXY,
129  vtkActor *iActorYZ,
130  vtkActor *iActorXZ,
131  vtkActor *iActorXYZ,
132  vtkPolyData *iNodes,
133  const bool & iHighlighted,
134  const bool & iVisible,
135  const double & r,
136  const double & g,
137  const double & b,
138  const double & alpha) :
139  TraceID(iTraceID), CollectionID(iCollectionID),
140  ActorXY(iActorXY), ActorXZ(iActorXZ),
141  ActorYZ(iActorYZ), ActorXYZ(iActorXYZ), Nodes(iNodes),
142  Highlighted(iHighlighted), Visible(iVisible)
143 {
144  this->rgba[0] = r;
145  this->rgba[1] = g;
146  this->rgba[2] = b;
147  this->rgba[3] = alpha;
148 }
149 
150 //--------------------------------------------------------------------------
151 
152 //--------------------------------------------------------------------------
154  TraceID(iE.TraceID), CollectionID(iE.CollectionID), ActorXY(iE.ActorXY),
155  ActorXZ(iE.ActorXZ), ActorYZ(iE.ActorYZ), ActorXYZ(iE.ActorXYZ),
156  Nodes(iE.Nodes), Highlighted(iE.Highlighted), Visible(iE.Visible)
157 {
158  for ( int i = 0; i < 4; i++ )
159  {
160  this->rgba[i] = iE.rgba[i];
161  }
162 }
163 
164 //--------------------------------------------------------------------------
165 
166 //--------------------------------------------------------------------------
169 {
170 }
171 
172 //--------------------------------------------------------------------------
173 
174 //--------------------------------------------------------------------------
175 void TraceStructure::SetActorProperties(vtkProperty *iProperty) const
176 {
177  if ( iProperty )
178  {
179  if ( this->ActorXY )
180  {
181  this->ActorXY->SetProperty(iProperty);
182  }
183  if ( this->ActorXZ )
184  {
185  this->ActorXZ->SetProperty(iProperty);
186  }
187  if ( this->ActorYZ )
188  {
189  this->ActorYZ->SetProperty(iProperty);
190  }
191  if ( this->ActorXYZ )
192  {
193  this->ActorXYZ->SetProperty(iProperty);
194  }
195  }
196 }
197 
198 //--------------------------------------------------------------------------
199 
200 //--------------------------------------------------------------------------
201 void TraceStructure::SetActorVisibility(const bool & iVisible) const
202 {
203  if ( this->ActorXY )
204  {
205  this->ActorXY->SetVisibility(iVisible);
206  }
207  if ( this->ActorXZ )
208  {
209  this->ActorXZ->SetVisibility(iVisible);
210  }
211  if ( this->ActorYZ )
212  {
213  this->ActorYZ->SetVisibility(iVisible);
214  }
215  if ( this->ActorXYZ )
216  {
217  this->ActorXYZ->SetVisibility(iVisible);
218  }
219 }
220 
221 //--------------------------------------------------------------------------
222 void
223 TraceStructure::SetScalarData(const std::string & iName,
224  const double & iValue) const
225 {
226  if ( this->Nodes )
227  {
228  vtkIdType NbOfPoints = this->Nodes->GetNumberOfPoints();
229  vtkSmartPointer<vtkDoubleArray> data =
230  vtkSmartPointer<vtkDoubleArray>::New();
231  data->SetNumberOfComponents(1);
232  data->SetName( iName.c_str() );
233 
234  for ( vtkIdType i = 0; i < NbOfPoints; ++i )
235  {
236  data->InsertNextValue(iValue);
237  }
238 
239  this->Nodes->GetPointData()->SetScalars(data);
240  this->Nodes->GetPointData()->SetActiveScalars( iName.c_str() );
241  }
242 }
243 
244 //--------------------------------------------------------------------------
245 
246 //--------------------------------------------------------------------------
247 void
248 TraceStructure::SetScalarRange(const double & iMin, const double & iMax) const
249 {
250  if ( this->ActorXY )
251  {
252  this->ActorXY->GetMapper()->SetScalarRange(iMin, iMax);
253  this->ActorXY->GetMapper()->SetScalarVisibility(true);
254  }
255  if ( this->ActorXZ )
256  {
257  this->ActorXZ->GetMapper()->SetScalarRange(iMin, iMax);
258  this->ActorXZ->GetMapper()->SetScalarVisibility(true);
259  }
260  if ( this->ActorYZ )
261  {
262  this->ActorYZ->GetMapper()->SetScalarRange(iMin, iMax);
263  this->ActorYZ->GetMapper()->SetScalarVisibility(true);
264  }
265  if ( this->ActorXYZ )
266  {
267  this->ActorXYZ->GetMapper()->SetScalarRange(iMin, iMax);
268  this->ActorXYZ->GetMapper()->SetScalarVisibility(true);
269  }
270 }
271 
272 //--------------------------------------------------------------------------
273 
274 //--------------------------------------------------------------------------
275 void
277 {
278  if ( this->Nodes )
279  {
280  this->Nodes->GetPointData()->SetActiveScalars(NULL);
281  }
282 
283  if ( this->ActorXY )
284  {
285  this->ActorXY->GetMapper()->SetScalarVisibility(false);
286  }
287  if ( this->ActorXZ )
288  {
289  this->ActorXZ->GetMapper()->SetScalarVisibility(false);
290  }
291  if ( this->ActorYZ )
292  {
293  this->ActorYZ->GetMapper()->SetScalarVisibility(false);
294  }
295  if ( this->ActorXYZ )
296  {
297  this->ActorXYZ->GetMapper()->SetScalarVisibility(false);
298  }
299 }
300 
301 //--------------------------------------------------------------------------
302 
303 //--------------------------------------------------------------------------
304 void
305 TraceStructure::SetLookupTable(const vtkLookupTable *iLut) const
306 {
307  if ( iLut )
308  {
309  if ( this->ActorXY )
310  {
311  this->ActorXY->GetMapper()->SetLookupTable(
312  const_cast<vtkLookupTable*>(iLut));
313  }
314  if ( this->ActorXZ )
315  {
316  this->ActorXZ->GetMapper()->SetLookupTable(
317  const_cast<vtkLookupTable*>(iLut));
318  }
319  if ( this->ActorYZ )
320  {
321  this->ActorYZ->GetMapper()->SetLookupTable(
322  const_cast<vtkLookupTable*>(iLut));
323  }
324  if ( this->ActorXYZ )
325  {
326  this->ActorXYZ->GetMapper()->SetLookupTable(
327  const_cast<vtkLookupTable*>(iLut));
328  }
329  }
330 }
331 
332 //--------------------------------------------------------------------------
333 
334 //--------------------------------------------------------------------------
335 void
337 {
338  if ( this->ActorXY )
339  {
340  this->ActorXY->Delete();
341  }
342  if ( this->ActorXZ )
343  {
344  this->ActorXZ->Delete();
345  }
346  if ( this->ActorYZ )
347  {
348  this->ActorYZ->Delete();
349  }
350  if ( this->ActorXYZ )
351  {
352  this->ActorXYZ->Delete();
353  }
354  if ( this->Nodes )
355  {
356  this->Nodes->Delete();
357  }
358 }
359 
360 //--------------------------------------------------------------------------
361 
362 //--------------------------------------------------------------------------
363 void
365 {
366  if ( this->Nodes )
367  {
368  if ( this->Nodes->GetPointData() )
369  {
370  this->Nodes->GetPointData()->Reset();
371  }
372  if ( this->Nodes->GetPoints() )
373  {
374  this->Nodes->GetPoints()->Reset();
375  }
376  if ( this->Nodes->GetLines() )
377  {
378  this->Nodes->GetLines()->Reset();
379  }
380  if ( this->Nodes )
381  {
382  this->Nodes->Reset();
383  }
384  }
385 }
void SetActorVisibility(const bool &iVisible) const
Set Visibility for all actors.
virtual void ReleaseData() const
virtual ~TraceStructure()
void SetLookupTable(const vtkLookupTable *iLut) const
Set the lookup table.
vtkActor * ActorXYZ
void SetActorProperties(vtkProperty *iProperty) const
Set Property for all actors.
void SetScalarRange(const double &iMin, const double &iMax) const
Set the scalar range (use for color coding)
void ResetNodes() const
vtkActor * ActorYZ
vtkPolyData * Nodes
vtkActor * ActorXY
vtkActor * ActorXZ
void SetScalarData(const std::string &iName, const double &iValue) const
Set Scalar Data associated to the elements (use for color coding)
double rgba[4]
void RenderWithOriginalColors() const
Render with original colors (Remove the active scalars data).
Structure which represent a trace (contour, mesh, track, lineage), and used for interaction between V...