GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LineageContainer.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 "LineageContainer.h"
36 #include "itkMacro.h"
37 
38 //-------------------------------------------------------------------------
40 LineageContainer(QObject *iParent,QGoImageView3D *iView):Superclass(iParent, iView)
41 {}
42 //-------------------------------------------------------------------------
43 
44 //-------------------------------------------------------------------------
47 {
48  MultiIndexContainerType::iterator it = m_Container.begin();
49 
50  while ( it != m_Container.end() )
51  {
52  it->ReleaseData();
53  ++it;
54  }
55 }
56 //-------------------------------------------------------------------------
57 
58 //-------------------------------------------------------------------------
60 InsertNewLineage(const unsigned int& iLineageID,
61  double irgba[4], const unsigned int& iTrackIDRoot,
62  const bool& IsVisible)
63 {
65  NewElement.TraceID = iLineageID;
66  NewElement.rgba[0] = irgba[0];
67  NewElement.rgba[1] = irgba[1];
68  NewElement.rgba[2] = irgba[2];
69  NewElement.rgba[3] = irgba[3];
70  NewElement.TrackRootID = iTrackIDRoot;
71  NewElement.Visible = IsVisible;
72  this->Insert(NewElement);
73 }
74 //-------------------------------------------------------------------------
75 
76 //-------------------------------------------------------------------------
77 bool LineageContainer::DeleteElement(const unsigned int & iId)
78 {
80  it = m_Container.get< TraceID >().find(iId);
81 
82  if( it != m_Container.get< TraceID >().end() )
83  {
84  return DeleteElement(it);
85  }
86  return false;
87 }
88 //-------------------------------------------------------------------------
89 
90 //-------------------------------------------------------------------------
92 {
93  assert(iIter != m_Container.get< TraceID >().end() );
94  m_Container.get< TraceID >().erase(iIter);
95  return true;
96 }
97 //-------------------------------------------------------------------------
98 
99 //-------------------------------------------------------------------------
101 {
102  assert ( this->m_ImageView );
103 
105 
106  boost::tuples::tie(it0, it1) =
107  m_Container.get< Highlighted >().equal_range(true);
108 
109  std::list< unsigned int > oList;
110 
111  while ( it0 != it1 )
112  {
113  oList.push_back(it0->TraceID);
114 
115  // to delete the divisions of the lineage in the track container
116  // signals connected in the QGoDBLineageManager
117  //emit DeleteLineage(it0->TrackRootID);
118 
119  it_t = it0;
120  ++it0;
121  m_Container.get< Highlighted >().erase(it_t);
122  }
123 
125 
126  return oList;
127 }
128 //-------------------------------------------------------------------------
129 
130 //-------------------------------------------------------------------------
131 std::vector< vtkActor* > LineageContainer::AddTrace( vtkPolyData* , vtkProperty* )
132 {
133  return std::vector< vtkActor* >();
134 }
135 //-------------------------------------------------------------------------
136 
137 //-------------------------------------------------------------------------
139 {
140  std::list<unsigned int> listOfTrackIDs;
141 
143  it = m_Container.get< TraceID >().begin();
144 
145  while( it != m_Container.get< TraceID >().end() )
146  {
147  listOfTrackIDs.push_back(it->TrackRootID);
148  ++it;
149  }
150 
151  return listOfTrackIDs;
152 }
153 //-------------------------------------------------------------------------
154 
155 //-------------------------------------------------------------------------
156 std::list<unsigned int> LineageContainer::GetListOfLineageIDs()
157 {
158  std::list<unsigned int> listOfLineageIDs;
159 
161  it = m_Container.get< TraceID >().begin();
162 
163  while( it != m_Container.get< TraceID >().end() )
164  {
165  listOfLineageIDs.push_back(it->TraceID);
166  ++it;
167  }
168 
169  return listOfLineageIDs;
170 }
171 //-------------------------------------------------------------------------
172 
173 //-------------------------------------------------------------------------
174 unsigned int LineageContainer::GetLineageTrackRootID( const unsigned int& iTraceID )
175 {
177  it = m_Container.get< TraceID >().find( iTraceID );
178 
179  /*
180  \todo Nicolas-shouldnt have to check it - sth has to be found here or bug somewhere
181  */
182  if( it != m_Container.get< TraceID >().end() )
183  {
184  return it->TrackRootID;
185  }
186  else
187  {
188  itkGenericExceptionMacro( <<"iTraceId is not in this container" );
189  return 0;
190  }
191 }
192 //-------------------------------------------------------------------------
193 
194 //-------------------------------------------------------------------------
195 unsigned int LineageContainer::GetTraceIDFromTrackRootID( const unsigned int& iTraceID )
196 {
198  it = m_Container.get< TrackRootID >().find( iTraceID );
199 
200 /*
201  \todo Nicolas-shouldnt have to check it - sth has to be found here or bug somewhere
202  */
203  if( it != m_Container.get< TrackRootID >().end() )
204  {
205  return it->TraceID;
206  }
207  else
208  {
209  itkGenericExceptionMacro( <<"trackroot id is not in this container" );
210  return 0;
211  }
212 }
213 //-------------------------------------------------------------------------
214 
215 //-------------------------------------------------------------------------
216 bool LineageContainer::GetLineageVisibile( const unsigned int& iTraceID )
217 {
219  it = m_Container.get< TraceID >().find( iTraceID );
220 
221  if( it != m_Container.get< TraceID >().end() )
222  {
223  return it->Visible;
224  }
225  else
226  {
227  itkGenericExceptionMacro( <<"iTraceId is not in this container" );
228  return false;
229  }
230 }
231 //-------------------------------------------------------------------------
232 
233 //-------------------------------------------------------------------------
234 bool LineageContainer::GetLineageHighlighted( const unsigned int& iTraceID )
235 {
237  it = m_Container.get< TraceID >().find( iTraceID );
238 
239  if( it != m_Container.get< TraceID >().end() )
240  {
241  return it->Highlighted;
242  }
243  else
244  {
245  itkGenericExceptionMacro( <<"iTraceId is not in this container" );
246  return false;
247  }
248 }
249 //-------------------------------------------------------------------------
250 
251 //-------------------------------------------------------------------------
252 double*
254 GetLineageColor( const unsigned int& iTraceID )
255 {
257  it = m_Container.get< TraceID >().find( iTraceID );
258 
259  double* color = NULL;
260 
261  if( it != m_Container.get< TraceID >().end() )
262  {
263  color = const_cast<double*>(it->rgba);
264  }
265 
266  return color;
267 }
268 //-------------------------------------------------------------------------
269 
270 //-------------------------------------------------------------------------
271 void
274  const Qt::CheckState & iCheck)
275 {
276  // emit signal for each lineage to be highlighted
277  // signal contains the trackIDroot and the state
278  if ( !iList.empty() )
279  {
281  QStringList::const_iterator constIterator = iList.begin();
282 
283  bool highlighted = iCheck;
284 
285  while ( constIterator != iList.end() )
286  {
287  it = m_Container.get< TraceID >().find( ( *constIterator ).toUInt() );
288 
289  if ( it != m_Container.get< TraceID >().end() )
290  {
291  // modify the structure highlight
292  m_Container.get< TraceID >().
293  modify( it , change_highlighted<MultiIndexContainerElementType>(highlighted) );
294  //send signal to track container
295  emit HighlightLineage(it->TrackRootID, highlighted);
296  }
297  ++constIterator;
298  }
299  }
300 }
301 
302 //-------------------------------------------------------------------------
303 
304 //-------------------------------------------------------------------------
305 void
307  const Qt::CheckState & iCheck)
308 {
309  // emit signal for each lineage to be shown/hidden
310  // signal contains the trackIDroot and the state
311 
312  if ( !iList.empty() )
313  {
315  QStringList::const_iterator constIterator = iList.begin();
316 
317  bool visible = iCheck;
318 
319  while ( constIterator != iList.end() )
320  {
321  it = m_Container.get< TraceID >().find( ( *constIterator ).toUInt() );
322 
323  if ( it != m_Container.get< TraceID >().end() )
324  {
325  //modify the structure visibility
326  m_Container.get< TraceID >().
327  modify( it , change_visible<MultiIndexContainerElementType>(visible) );
328  //send signal to track container
329  emit ShowLineage(it->TrackRootID, visible);
330  }
331  ++constIterator;
332  }
333  }
334 }
335 //-------------------------------------------------------------------------
MultiIndexContainerType::value_type MultiIndexContainerElementType
std::list< unsigned int > DeleteAllHighlightedElements()
Delete all highlighted elements.
bool GetLineageHighlighted(const unsigned int &iTraceID)
void UpdateRenderWindows()
Update only the visualization.
MultiIndexContainerType::template index< TraceID >::type::iterator MultiIndexContainerTraceIDIterator
MultiIndexContainerType m_Container
Trace Contaienr.
void Insert(const MultiIndexContainerElementType &iE)
Insert one element in the container.
MultiIndexContainerType::index< TrackRootID >::type::iterator MultiIndexContainerTrackRootIDIterator
LineageContainer(QObject *iParent, QGoImageView3D *iView)
Constructor.
std::list< unsigned int > GetListOfTrackRootIDs()
MultiIndexContainerType::template index< Highlighted >::type::iterator MultiIndexContainerHighlightedIterator
void ShowLineage(const unsigned int &, const bool &)
bool empty() const
class for the visualization of 3D Image represented by one vtkImageData*.
std::list< unsigned int > GetListOfLineageIDs()
unsigned int GetTraceIDFromTrackRootID(const unsigned int &iTraceID)
virtual ~LineageContainer()
Destructor.
bool DeleteElement(const unsigned int &iId)
bool GetLineageVisibile(const unsigned int &iTraceID)
iterator end()
virtual void UpdateElementHighlightingWithGivenTraceIDs(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements highlighting property given a list of TraceIDs and the new status.
std::vector< vtkActor * > AddTrace(vtkPolyData *, vtkProperty *)
QGoImageView3D * m_ImageView
Link to the visualization.
void InsertNewLineage(const unsigned int &iLineageID, double irgba[4], const unsigned int &iTrackIDRoot, const bool &IsVisible=false)
insert a new element in the container with all the info needed
unsigned int GetLineageTrackRootID(const unsigned int &iTraceID)
void HighlightLineage(const unsigned int &, const bool &)
iterator begin()
virtual void UpdateElementVisibilityWithGivenTraceIDs(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements visibility property given a list of TraceIDs and the new status.
double * GetLineageColor(const unsigned int &iTraceID)