GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ContourMeshContainer.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 __ContourMeshContainer_h
36 #define __ContourMeshContainer_h
37 
38 #include <QObject>
39 
40 #include "ContourMeshStructure.h"
41 #include "StructureHelper.h"
42 
43 #include "TraceContainerBase.h"
44 
45 #include "boost/multi_index_container.hpp"
46 #include "boost/multi_index/member.hpp"
47 #include "boost/multi_index/hashed_index.hpp"
48 #include "boost/multi_index/ordered_index.hpp"
49 #include "boost/numeric/conversion/cast.hpp"
50 #include "boost/lexical_cast.hpp"
51 
52 #include "vtkProperty.h"
53 #include "vtkPolyData.h"
54 #include "vtkActor.h"
55 #include "vtkMapper.h"
56 #include "QGoImageView3D.h"
57 
58 #include "vtkLookupTableManager.h"
59 #include "QGoGUILibConfigure.h"
60 
66 //-----------------------------------------------------------------------------
68 {
69  change_collectionID(const unsigned int& iCollectionID):collectionID(iCollectionID){}
70 
71  void operator()(ContourMeshStructure& iStructure)
72  {
73  iStructure.ModifyCollectionID(collectionID);
74  }
75 
76 private:
77  unsigned int collectionID;
78 };
79 //-----------------------------------------------------------------------------
80 
81 namespace boost
82 {
83 typedef multi_index::multi_index_container<
85  boost::multi_index::indexed_by<
86  boost::multi_index::ordered_non_unique<
87  boost::multi_index::tag< TCoord >,
88  BOOST_MULTI_INDEX_MEMBER(ContourMeshStructure, unsigned int, TCoord)
89  >,
90  boost::multi_index::ordered_unique<
91  boost::multi_index::tag< TraceID >,
92  BOOST_MULTI_INDEX_MEMBER(TraceStructure, unsigned int, TraceID)
93  >,
94  boost::multi_index::ordered_non_unique<
95  boost::multi_index::tag< CollectionID >,
96  BOOST_MULTI_INDEX_MEMBER(TraceStructure, unsigned int, CollectionID)
97  >,
98  boost::multi_index::ordered_non_unique<
99  boost::multi_index::tag< Highlighted >,
100  BOOST_MULTI_INDEX_MEMBER(TraceStructure, bool, Highlighted)
101  >,
102  boost::multi_index::ordered_non_unique<
103  boost::multi_index::tag< Visible >,
104  BOOST_MULTI_INDEX_MEMBER(TraceStructure, bool, Visible)
105  >
106  >
108 }
109 
117 class QGOGUILIB_EXPORT ContourMeshContainer:
118  public TraceContainerBase< boost::MultiIndexContourMeshContainer >
119 {
120  Q_OBJECT
121 public:
122 
125 
126  typedef MultiIndexContainerType::index< TCoord >::type::iterator
128 
129  //------------------------------------------------------------------------
130 
132  explicit ContourMeshContainer(QObject *iParent,
133  QGoImageView3D *iView);
134 
136  virtual ~ContourMeshContainer();
137 
139  void SetTimePoint(const unsigned int & iT);
140 
144  void ShowActorsWithGivenTimePoint(const unsigned int & iT);
145 
152  void
153  ChangeActorsVisibility(
156  const bool & iVisibility);
157 
167  void UpdateCurrentElementFromVisu(std::vector< vtkActor * >& iActors,
168  vtkPolyData *iNodes,
169  const unsigned int & iT,
170  const bool & iHighlighted,
171  const bool & iVisible);
172 
177  void RemoveActorsWithGivenTimePoint(const unsigned int & iT);
178 
182  void AddActorsWithGivenTimePoint(const unsigned int & iT);
183 
193  static
194  int
195  ComputeDirectionFromContour(vtkPolyData *iContour)
196  {
197  double bounds[6];
198 
199  iContour->GetBounds(bounds);
200 
201  return ComputeDirectionFromBounds< double >(bounds);
202  }
203 
211  template< typename T >
212  static
213  int
215  {
216  int oDir = -1;
217 
218  for ( int i = 0; i < 3; i++ )
219  {
220  if ( iBounds[2 * i] == iBounds[2 * i + 1] )
221  {
222  oDir = 2 - i;
223  }
224  }
225 
226  return oDir;
227  }
228 
229  template< typename T >
230  static
231  int
232  ComputeDirectionFromBounds(const std::vector< T > & iBounds)
233  {
234  int oDir = -1;
235 
236  if ( iBounds.size() == 6 )
237  {
238  for ( int i = 0; i < 3; ++i )
239  {
240  if ( iBounds[2 * i] == iBounds[2 * i + 1] )
241  {
242  oDir = 2 - i;
243  }
244  }
245  }
246 
247  return oDir;
248  }
249 
256  void UpdateElementHighlighting(unsigned int TraceId)
257  {
258  Qt::CheckState state;
259  Superclass::UpdateElementHighlightingWithTraceID(TraceId, state );
260  emit TracePicked(TraceId, state);
261  }
262 
270  void UpdateElementVisibility(unsigned int iTraceID, bool iState)
271  {
272  Superclass::UpdateElementVisibilityWithTraceID(iTraceID, iState);
273  if(iState)
274  {
275  emit TraceVisibilityChanged(iTraceID, Qt::Checked );
276  return;
277  }
278  emit TraceVisibilityChanged(iTraceID, Qt::Unchecked );
279  }
280 
281  //-------------------------------------------------------------------------
282 
293  bool DeleteElement(const unsigned int & iId);
294 
298  bool DeleteElement(MultiIndexContainerTraceIDIterator iIter);
299 
303  std::list< unsigned int > DeleteAllHighlightedElements();
304 
308  void Clear();
309 
313  void Clear( const std::list<unsigned int>& iTraceIDs);
314 
319  std::list< unsigned int > GetElementsTraceIDForGivenTimePoint(unsigned int iTimePoint);
320 
321 
322  /*
323  * \brief Returns the meshes positions
324  * \param[in] iMeshID IDs of the meshes of interest
325  * \return map containing the coordinates of the meshes of interest
326  */
327  std::map< unsigned int, double* > GetMeshesPoints( std::list< unsigned int> iMeshID );
328 
336  template< class TIndex >
338  typename MultiIndexContainerType::template index< TIndex >::type::iterator iBegin,
339  typename MultiIndexContainerType::template index< TIndex >::type::iterator iEnd,
340  const bool & iVisibility)
341  {
342  typename MultiIndexContainerType::template index< TIndex >::type::iterator
343  it = iBegin;
344 
345  typedef void ( QGoImageView3D::*ImageViewMember )(const int &, vtkActor *);
346  ImageViewMember f;
347 
348  if ( iVisibility )
349  {
351  }
352  else
353  {
355  }
356 
357  while ( it != iEnd )
358  {
359  if ( it->Visible != iVisibility )
360  {
361  it->SetActorVisibility( iVisibility );
362 
363  if( m_ImageView )
364  {
365  if ( it->ActorXY )
366  {
367  ( m_ImageView->*f )(0, it->ActorXY);
368  }
369  if ( it->ActorXZ )
370  {
371  ( m_ImageView->*f )(1, it->ActorXZ);
372  }
373  if ( it->ActorYZ )
374  {
375  ( m_ImageView->*f )(2, it->ActorYZ);
376  }
377  if ( it->ActorXYZ )
378  {
379  ( m_ImageView->*f )(3, it->ActorXYZ);
380  }
381  }
382 
383  bool visible = iVisibility;
384  m_Container.get< TIndex >().
385  modify( it , change_visible<ContourMeshStructure>(visible) );
386 
387  Qt::CheckState State;
388 
389  if ( iVisibility )
390  {
391  State = Qt::Checked;
392  }
393  else
394  {
395  State = Qt::Unchecked;
396  }
397 
398  emit TraceVisibilityChanged( it->TraceID, State );
399  }
400  ++it;
401  }
402  }
403 
404  void AssignToGivenCollection(unsigned int iCollection,
405  std::list< unsigned int > iToBeAssigned);
406 
407  std::list< unsigned int > GetHighlightedElementsTCoord();
408 
409 public slots:
410 
416  void UpdateElementHighlightingWithGivenTraceIDs( const QStringList& iList,
417  const Qt::CheckState& iCheck );
418 
424  void UpdateElementVisibilityWithGivenTraceIDs( const QStringList& iList,
425  const Qt::CheckState& iCheck );
426 
427 signals:
429  void TracePicked(unsigned int, Qt::CheckState);
430 
432  void TraceVisibilityChanged(unsigned int, Qt::CheckState);
433 
434 protected:
435  unsigned int m_TCoord;
436 
437 private:
438  Q_DISABLE_COPY(ContourMeshContainer);
439 };
440 
441 #endif // CONTOURMESHCONTAINER_H
virtual std::list< unsigned int > DeleteAllHighlightedElements()=0
Delete all highlighted elements.
void UpdateElementVisibility(unsigned int iTraceID, bool iState)
Update highlighting property of one element given one actor.
void ChangeActorsVisibility(typename MultiIndexContainerType::template index< TIndex >::type::iterator iBegin, typename MultiIndexContainerType::template index< TIndex >::type::iterator iEnd, const bool &iVisibility)
Change element visibility in the scene.
boost::MultiIndexContourMeshContainer MultiIndexContainerType
void ModifyCollectionID(unsigned int iCollectionID)
void UpdateElementHighlighting(unsigned int TraceId)
Update highlighting property of one element given one actor.
class for the visualization of 3D Image represented by one vtkImageData*.
virtual void RemoveActor(const int &iId, vtkActor *iActor)
static int ComputeDirectionFromContour(vtkPolyData *iContour)
Returns the direction of a given contour vtkPolyData. This static method is supposed to be used when ...
change_collectionID(const unsigned int &iCollectionID)
Generic interface for trace container. More specific container should inherit from this class and get...
virtual bool DeleteElement(const unsigned int &iId)=0
Remove the element which TraceId = iId.
Wraps a boost::multi_index_container of ContourMeshStructure. This class intends to synchronize Conto...
Superclass::MultiIndexContainerType MultiIndexContainerType
virtual void AddActor(const int &iId, vtkActor *iActor)
static int ComputeDirectionFromBounds(const std::vector< T > &iBounds)
TraceContainerBase< boost::MultiIndexContourMeshContainer > Superclass
Structure which represent a contour or a mesh, and used for interaction between Visualization and Tab...
multi_index::multi_index_container< ContourMeshStructure, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< TCoord >, >, boost::multi_index::ordered_unique< boost::multi_index::tag< TraceID >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< CollectionID >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< Highlighted >, >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< Visible >, > >> MultiIndexContourMeshContainer
void operator()(ContourMeshStructure &iStructure)
MultiIndexContainerType::index< TCoord >::type::iterator MultiIndexContainerTCoordIterator
static int ComputeDirectionFromBounds(T *iBounds)
Returns the direction of a given element given its bounding box. This static method is supposed to be...
Structure which represent a trace (contour, mesh, track, lineage), and used for interaction between V...