GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TraceContainerBase.h
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 #ifndef __TraceContainerBase_h
36 #define __TraceContainerBase_h
37 
38 #include <Qt>
39 #include <QObject>
40 #include "QGoImageView3D.h"
41 
42 #include "vtkProperty.h"
43 #include "StructureHelper.h"
44 #include "QGoGUILibConfigure.h"
45 
46 #include "vtkIntArray.h"
47 #include "vtkActor.h"
48 #include "vtkMapper.h"
49 #include "vtkDataSet.h"
50 #include "vtkPointData.h"
51 
52 #include "TraceStructure.h"
53 
54 #include "boost/multi_index_container.hpp"
55 #include "boost/multi_index/member.hpp"
56 #include "boost/multi_index/hashed_index.hpp"
57 #include "boost/multi_index/ordered_index.hpp"
58 #include "boost/numeric/conversion/cast.hpp"
59 #include "boost/lexical_cast.hpp"
60 
61 
62 //-----------------------------------------------------------------------------
63 
64 template <class T> struct change_highlighted
65 {
66  change_highlighted(bool& iHighlight):highlighted(iHighlight){}
67 
68  void operator()(T& iStructure)
69  {
70  iStructure.Highlighted = highlighted;
71  }
72 
73 private:
75 };
76 
77 //-----------------------------------------------------------------------------
78 
79 //-----------------------------------------------------------------------------
80 
81 template <class T> struct change_visible
82 {
83  change_visible(const bool& iVisibile):visible(iVisibile){}
84 
85  void operator()(T& iStructure)
86  {
87  iStructure.Visible = visible;
88  }
89 
90 private:
91  bool visible;
92 };
93 
94 //-----------------------------------------------------------------------------
95 
96 //-----------------------------------------------------------------------------
97 
98 template <class T> struct change_actors
99 {
100  change_actors(std::vector<vtkActor*>& iActors):actor(iActors){}
101 
102  void operator()(T& iStructure)
103  {
104  iStructure.ActorXY = actor[0];
105  iStructure.ActorXZ = actor[1];
106  iStructure.ActorYZ = actor[2];
107  iStructure.ActorXYZ = actor[3];
108  }
109 
110 private:
111  std::vector<vtkActor*> actor;
112 };
113 
114 //-----------------------------------------------------------------------------
115 
116 //-----------------------------------------------------------------------------
117 
118 template <class T> struct change_color
119 {
120  change_color(QColor iColor):color(iColor){}
121 
122  void operator()(T& iStructure)
123  {
124  iStructure.rgba[0] = color.redF();
125  iStructure.rgba[1] = color.greenF();
126  iStructure.rgba[2] = color.blueF();
127  iStructure.rgba[3] = color.alphaF();
128  }
129 
130 private:
132 };
133 
134 //-----------------------------------------------------------------------------
135 
143 template< class TContainer >
145 {
146 public:
147  typedef TContainer MultiIndexContainerType;
148  typedef typename MultiIndexContainerType::value_type MultiIndexContainerElementType;
149 
150  typedef typename MultiIndexContainerType::template index< TraceID >::type::iterator
152 
153  typedef typename MultiIndexContainerType::template index< CollectionID >::type::iterator
155 
156  typedef typename MultiIndexContainerType::template index< Highlighted >::type::iterator
158 
159  typedef typename MultiIndexContainerType::template index< Visible >::type::iterator
161 
166  explicit TraceContainerBase( QObject* iParent, QGoImageView3D* iView );
167 
169  virtual ~TraceContainerBase();
170 
173 
176 
179 
180  // ----------------------------------------------------------------------
181 
186  template< class TIterator >
187  void Print(TIterator iBegin, TIterator iEnd)
188  {
189  TIterator it = iBegin;
190 
191  while ( it != iEnd )
192  {
193  std::cout << *it;
194  std::cout << "***" << std::endl;
195  std::cout << std::endl;
196  ++it;
197  }
198  }
199 
205  template< class TIndex >
206  void Print()
207  {
208  using boost::multi_index::get;
209 
210  this->Print( this->m_Container.get< TIndex >().begin(),
211  this->m_Container.get< TIndex >().end() );
212  }
213 
215  void Print();
216 
217  // ----------------------------------------------------------------------
218 
223  void SetHighlightedProperty(vtkProperty *iProperty);
224 
228  vtkProperty * GetHighlightedProperty();
229 
231  unsigned int GetCollectionIDOfGivenTraceID( unsigned int iTraceID);
232 
238  template< class TList >
240  {
241  using boost::multi_index::get;
242 
243  typename TList::iterator it = iList.begin();
244 
245  while ( it != iList.end() )
246  {
248  m_Container.get< TraceID >().find( static_cast< unsigned int >( *it ) );
249 
250  if ( id_it != m_Container.get< TraceID >().end() )
251  {
252  bool test = false;
253  m_Container.get< TraceID >().
254  modify( id_it , change_visible<MultiIndexContainerElementType>(test) );
255  m_Container.get< TraceID >().
257 
258  vtkProperty *tproperty = vtkProperty::New();
259  tproperty->SetColor(id_it->rgba[0], id_it->rgba[1], id_it->rgba[2]);
260  tproperty->SetOpacity(id_it->rgba[3]);
261  tproperty->SetLineWidth( this->m_IntersectionLineWidth );
262 
263  if ( id_it->Nodes )
264  {
265  bool test2 = id_it->Visible;
266  m_Container.get< TraceID >().
267  modify( id_it , change_visible<MultiIndexContainerElementType>( test2 ) );
268 
269  std::vector< vtkActor * > actor =
270  this->m_ImageView->AddContour( id_it->Nodes, tproperty );
271 
272  m_Container.get< TraceID >().
273  modify( id_it , change_actors<MultiIndexContainerElementType>( actor ) );
274 
275  typedef void ( QGoImageView3D::*ImageViewMember )(const int &, vtkActor *);
276  ImageViewMember f;
277 
278  if ( id_it->Visible )
279  {
281  }
282  else
283  {
285  }
286 
287  assert( m_ImageView );
288  for ( int i = 0; i < 4; i++ )
289  {
290  ( m_ImageView->*f )(i, actor[i]);
291  }
292  }
293  else
294  {
295  m_Container.get< TraceID >().
296  modify( id_it , change_visible<MultiIndexContainerElementType>(test) );
297  }
298  }
299  ++it;
300  }
301  }
302 
312  template< class TIndex >
314  typename MultiIndexContainerType::template index< TIndex >::type::iterator& iIt,
315  std::vector< vtkActor * > iActors,
316  const bool & iHighlighted,
317  const bool & iVisible)
318  {
319 
320  using boost::multi_index::get;
321 
322  if ( iActors.size() == 4 )
323  {
324  m_Container.get< TIndex >().
325  modify( iIt , change_actors<MultiIndexContainerElementType>(iActors) );
326  }
327  bool highlighted = iHighlighted;
328  bool visible = iVisible;
329  m_Container.get< TIndex >().
330  modify( iIt , change_visible<MultiIndexContainerElementType>(visible) );
331  m_Container.get< TIndex >().
332  modify( iIt , change_highlighted<MultiIndexContainerElementType>(highlighted) );
333 
334  typedef void ( QGoImageView3D::*ImageViewMember )(const int &, vtkActor *);
335  ImageViewMember f;
336 
337  if ( iVisible )
338  {
340  }
341  else
342  {
344  }
345 
346  assert( m_ImageView );
347  for ( int i = 0; i < 4; i++ )
348  {
349  ( m_ImageView->*f )(i, iActors[i]);
350  }
351  }
352 
357  void Insert(const MultiIndexContainerElementType & iE);
358 
360  void InsertCurrentElement();
361 
363  void ResetCurrentElement();
364 
371  void UpdateCurrentElementFromDB(unsigned int iTraceID, double irgba[4],
372  bool IsVisible = false);
373 
374  void UpdateCurrentElementCollection(unsigned int iCollectionID);
375 
380  vtkPolyData* GetCurrentElementNodes();
381 
386  double* GetCurrentElementColor();
387 
388  std::vector<vtkActor*> GetActorGivenTraceID( unsigned int iTraceID );
389 
396  bool UpdateCurrentElementFromExistingOne(unsigned int iTraceID, bool iErase = true);
397 
399  template< class TIndex >
401  typename MultiIndexContainerType::template index< TIndex >::type::iterator iIt )
402  {
403  using boost::multi_index::get;
404 
405  // update current element
406  this->m_CurrentElement = *iIt;
407 
408  // clean the container but don't erase the pointers since we still have the
409  // adresses in the m_CurrentElement
410  m_Container.get< TIndex >().erase( iIt );
411 
412  return true;
413  }
414 
421  bool UpdateElementVisibilityWithGivenTraceID(const unsigned int & iId);
422 
423  //-------------------------------------------------------------------------
424 
430  bool
432  const unsigned int & iId);
433 
439  bool UpdateElementHighlightingWithGivenTraceID(const unsigned int & iId);
440 
441  //-------------------------------------------------------------------------
442 
446  std::list< unsigned int > GetHighlightedElementsTraceID();
447 
448  std::list< unsigned int > GetHighlightedElementsCollectionID();
449 
454  std::list< vtkPolyData* > GetHighlightedElements();
455 
466  virtual bool DeleteElement(const unsigned int & iId) = 0;
467 
471  virtual bool DeleteElement(MultiIndexContainerTraceIDIterator iIter) = 0;
472 
476  virtual std::list< unsigned int > DeleteAllHighlightedElements() = 0;
477 
484  std::list< unsigned int > UpdateAllHighlightedElementsWithGivenColor(
485  QColor iColor);
486 
495  void SetColorCode( const std::string& iColumnName,
496  const std::map< unsigned int, std::string >& iValues );
497 
507  template< typename TValue >
508  void SetColorCode( const std::string& iColumnName,
509  const std::map< unsigned int, TValue >& iValues )
510  {
511  typedef TValue ValueType;
512  typedef typename std::map< unsigned int, ValueType > MapType;
513  typedef typename MapType::const_iterator MapConstIterator;
514 
515  using boost::multi_index::get;
516 
517  if( iColumnName.empty() || iValues.empty() )
518  {
520  return;
521  }
522 
523  MapConstIterator it = iValues.begin();
524 
525  double temp = 0.;
526  try
527  {
528  temp = boost::numeric_cast< double >( it->second );
529  }
530  catch( boost::numeric::bad_numeric_cast& e )
531  {
532  std::cout << e.what() <<std::endl;
533  return;
534  }
535 
536  double min_value = temp;
537  double max_value = temp;
538 
539  while( it != iValues.end() )
540  {
542  trace_it = this->m_Container.get<TraceID>().find( it->first );
543 
544  if( trace_it != this->m_Container.get<TraceID>().end() )
545  {
546  if (trace_it->Nodes) //make sure the trace has points !!!
547  {
548  // Here let's make sure you are not passing crazy values!
549  try
550  {
551  temp = boost::numeric_cast< double >( it->second );
552  }
553  catch( boost::numeric::bad_numeric_cast& e )
554  {
555  std::cout << e.what() <<std::endl;
556  return;
557  }
558 
559  if( temp > max_value )
560  {
561  max_value = temp;
562  }
563  if( temp < min_value )
564  {
565  min_value = temp;
566  }
567 
568  trace_it->SetScalarData( iColumnName, temp );
569  }
570  } //end make sure the trace has points !!!
571  ++it;
572  }
573 
574  SetScalarRangeForAllElements( min_value, max_value );
575 
576  if( m_ImageView )
577  {
579  }
580  }
581 
582  void SetRandomColor( const std::string& iColumnName,
583  const std::map< unsigned int, unsigned int >& iIds );
584 
585  void SetRandomColor( const std::string& iColumnName,
586  const std::map< unsigned int, std::string >& iValues );
587 
590  void SetLookupTableForColorCoding( vtkLookupTable* iLut );
591 
592  void SetIntersectionLineWidth( const float& iWidth );
593 
594 
595 protected:
596  vtkProperty *m_HighlightedProperty;
598 
604  const Qt::CheckState& iCheck );
605 
611  const Qt::CheckState& iCheck );
612 
613 
616 
618  void SetScalarRangeForAllElements(const double& iMin, const double& iMax );
619 
620  void UpdateCurrentElementFromVisuBase( std::vector< vtkActor* >& iActors,
621  vtkPolyData* iNodes,
622  const bool& iHighlighted,
623  const bool& iVisible );
624 
634  const unsigned int& oTraceId,
635  Qt::CheckState& oState )
636  {
637  using boost::multi_index::get;
638 
639  typedef typename MultiIndexContainerType::template index< TraceID >::type::iterator
640  IteratorType;
641  IteratorType it = m_Container.get< TraceID >().find(oTraceId);
642 
643  vtkProperty *temp_property = vtkProperty::New();
644 
645  assert ( it != m_Container.get< TraceID >().end() );
646 
647  if ( it->Highlighted )
648  {
649  temp_property->SetColor(it->rgba[0],
650  it->rgba[1],
651  it->rgba[2]);
652  temp_property->SetOpacity(it->rgba[3]);
653  temp_property->SetLineWidth( this->m_IntersectionLineWidth );
654  }
655  else
656  {
657  temp_property->DeepCopy(this->m_HighlightedProperty);
658  }
659 
660  it->SetActorProperties( temp_property );
661 
662  temp_property->Delete();
663 
664  // Note: it->Highlighted is the status before picking the actor
665  bool checked = false;
666  if ( !it->Highlighted )
667  {
668  oState = Qt::Checked;
669  checked = true;
670  }
671  else
672  {
673  oState = Qt::Unchecked;
674  }
675 
676  m_Container.get< TraceID >().
678 
679  assert( m_ImageView );
680 
682  }
683 
685  const unsigned int& oTraceId,
686  const bool& iState)
687  {
688  using boost::multi_index::get;
689 
690  typedef typename MultiIndexContainerType::template index< TraceID >::type::iterator
691  IteratorType;
692  IteratorType it = m_Container.get< TraceID >().find(oTraceId);
693 
694  assert ( it != m_Container.get< TraceID >().end() );
695 
696  if ( it->Visible != iState )
697  {
698  it->SetActorVisibility( iState );
699  m_Container.get< TraceID >().
700  modify( it , change_visible<MultiIndexContainerElementType>(iState) );
701  }
702  }
703 };
704 
705 #include "TraceContainerBase.txx"
706 
707 #endif // __TraceContainerBase_h
MultiIndexContainerType::value_type MultiIndexContainerElementType
vtkPolyData * GetCurrentElementNodes()
Get the polydata representing the current element track.
std::list< unsigned int > GetHighlightedElementsCollectionID()
void Print()
Print the container content in the application output according to the template parameter.
virtual std::list< unsigned int > DeleteAllHighlightedElements()=0
Delete all highlighted elements.
void SetColorCode(const std::string &iColumnName, const std::map< unsigned int, std::string > &iValues)
Color code contour / mesh according to values provided.
qreal alphaF() const
void operator()(T &iStructure)
void UpdateElementVisibilityWithTraceID(const unsigned int &oTraceId, const bool &iState)
std::vector< vtkActor * > actor
qreal redF() const
void UpdateRenderWindows()
Update only the visualization.
double * GetCurrentElementColor()
Get the color of the current element track.
void UpdateCurrentElementFromDB(unsigned int iTraceID, double irgba[4], bool IsVisible=false)
Update Current Element from te database.
bool UpdateCurrentElementFromExistingOne(unsigned int iTraceID, bool iErase=true)
put the information of the existing element into m_CurrentElement and remove the existing element fro...
qreal blueF() const
std::list< unsigned int > UpdateAllHighlightedElementsWithGivenColor(QColor iColor)
Update all highlighted elements in the container with a given color.
MultiIndexContainerType::template index< TraceID >::type::iterator MultiIndexContainerTraceIDIterator
change_highlighted(bool &iHighlight)
MultiIndexContainerType m_Container
Trace Contaienr.
bool RemoveElementFromVisualizationWithGivenTraceID(const unsigned int &iId)
Remove element from visualization.
virtual void UpdateElementHighlightingWithGivenTraceIDsBase(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements highlighting property given a list of TraceIDs and the new status.
unsigned int GetCollectionIDOfGivenTraceID(unsigned int iTraceID)
Get the CollectionID given a TraceID.
void SetScalarRangeForAllElements(const double &iMin, const double &iMax)
Set the scalar range.
std::vector< vtkActor * > AddContour(vtkPolyData *iDataset, vtkProperty *iProperty=NULL)
Add contour with given property into the visualization.
void Insert(const MultiIndexContainerElementType &iE)
Insert one element in the container.
change_visible(const bool &iVisibile)
TContainer MultiIndexContainerType
void UpdateVisualizationForGivenIDs(TList iList)
Update Visualization of the given TraceIDs.
virtual ~TraceContainerBase()
Destructor.
vtkProperty * m_HighlightedProperty
std::vector< vtkActor * > GetActorGivenTraceID(unsigned int iTraceID)
vtkProperty * GetHighlightedProperty()
Get property for highlighted traces.
MultiIndexContainerType::template index< Highlighted >::type::iterator MultiIndexContainerHighlightedIterator
class for the visualization of 3D Image represented by one vtkImageData*.
virtual void RemoveActor(const int &iId, vtkActor *iActor)
std::list< unsigned int > GetHighlightedElementsTraceID()
Get the list of highlighted elements TraceID.
void UpdateCurrentElementCollection(unsigned int iCollectionID)
void operator()(T &iStructure)
qreal greenF() const
Generic interface for trace container. More specific container should inherit from this class and get...
void UpdateVisualizationForGivenElement(typename MultiIndexContainerType::template index< TIndex >::type::iterator &iIt, std::vector< vtkActor * > iActors, const bool &iHighlighted, const bool &iVisible)
Update Actors, Highlighted, Visibility (properties) of given a element.
bool UpdateElementVisibilityWithGivenTraceID(const unsigned int &iId)
Update element visibility given it TraceId.
virtual bool DeleteElement(const unsigned int &iId)=0
Remove the element which TraceId = iId.
bool UpdateCurrentElementFromExistingOne(typename MultiIndexContainerType::template index< TIndex >::type::iterator iIt)
virtual void UpdateElementVisibilityWithGivenTraceIDsBase(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements visibility property given a list of TraceIDs and the new status.
MultiIndexContainerType::template index< Visible >::type::iterator MultiIndexContainerVisibleIterator
virtual void AddActor(const int &iId, vtkActor *iActor)
void operator()(T &iStructure)
QGoImageView3D * m_ImageView
Link to the visualization.
void Print(TIterator iBegin, TIterator iEnd)
Print the container content in the application output.
void ResetCurrentElement()
Reset Current Element to a default state.
MultiIndexContainerElementType m_CurrentElement
Current Element of the trace type.
void SetHighlightedProperty(vtkProperty *iProperty)
Set property whenever the trace is highlighted.
MultiIndexContainerType::template index< CollectionID >::type::iterator MultiIndexContainerCollectionIDIterator
change_actors(std::vector< vtkActor * > &iActors)
void SetIntersectionLineWidth(const float &iWidth)
TraceContainerBase(QObject *iParent, QGoImageView3D *iView)
Constructor.
void UpdateCurrentElementFromVisuBase(std::vector< vtkActor * > &iActors, vtkPolyData *iNodes, const bool &iHighlighted, const bool &iVisible)
void SetLookupTableForColorCoding(vtkLookupTable *iLut)
Apply the given lookup table to all traces in the container.
void UpdateElementHighlightingWithTraceID(const unsigned int &oTraceId, Qt::CheckState &oState)
Update highlighting property of one element given one actor.
void operator()(T &iStructure)
void RenderAllElementsWithOriginalColors()
Render with original colors.
void SetColorCode(const std::string &iColumnName, const std::map< unsigned int, TValue > &iValues)
Color code contour / mesh according to values provided.
std::list< vtkPolyData * > GetHighlightedElements()
Get all highlighted elements by pair&lt;ID, Polydata&gt;.
void SetRandomColor(const std::string &iColumnName, const std::map< unsigned int, unsigned int > &iIds)
change_color(QColor iColor)
void InsertCurrentElement()
Insert Current Element in the container.
bool UpdateElementHighlightingWithGivenTraceID(const unsigned int &iId)
Update element highlighting given it TraceId.