GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ContourMeshContainer.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 "ContourMeshContainer.h"
36 #include "StructureHelper.h"
37 
38 #include "vtkActor.h"
39 
40 //-------------------------------------------------------------------------
42  QGoImageView3D *iView) :
43  Superclass(iParent, iView),
44  m_TCoord( std::numeric_limits< unsigned int >::max() )
45 {
46 }
47 
48 //-------------------------------------------------------------------------
49 
50 //-------------------------------------------------------------------------
53 {
54  MultiIndexContainerType::iterator it = m_Container.begin();
55 
56  while ( it != m_Container.end() )
57  {
58  if ( it->Nodes )
59  {
60  it->Nodes->Delete();
61  }
62  if ( it->ActorXY )
63  {
64  it->ActorXY->Delete();
65  }
66  if ( it->ActorXZ )
67  {
68  it->ActorXZ->Delete();
69  }
70  if ( it->ActorYZ )
71  {
72  it->ActorYZ->Delete();
73  }
74  if ( it->ActorXYZ )
75  {
76  it->ActorXYZ->Delete();
77  }
78 
79  ++it;
80  }
81 }
82 
83 //-------------------------------------------------------------------------
84 
85 //-------------------------------------------------------------------------
86 void
87 ContourMeshContainer::SetTimePoint(const unsigned int & iT)
88 {
89  this->m_TCoord = iT;
90 }
91 
92 //-------------------------------------------------------------------------
93 
94 //-------------------------------------------------------------------------
95 void
96 ContourMeshContainer::UpdateCurrentElementFromVisu(std::vector< vtkActor * >& iActors,
97  vtkPolyData *iNodes,
98  const unsigned int & iT,
99  const bool & iHighlighted,
100  const bool & iVisible)
101 {
102  this->m_CurrentElement.TCoord = iT;
103  this->UpdateCurrentElementFromVisuBase(iActors, iNodes,
104  iHighlighted, iVisible);
105 }
106 
107 //-------------------------------------------------------------------------
108 
109 //-------------------------------------------------------------------------
110 void
112 {
114 
115  boost::tuples::tie(it0, it1) = m_Container.get< TCoord >().equal_range(iT);
116 
117  ChangeActorsVisibility< TCoord >(it0, it1, false);
118 
119  if ( m_ImageView )
120  {
122  }
123 }
124 
125 //-------------------------------------------------------------------------
126 
127 //-------------------------------------------------------------------------
128 void
130 {
131  if ( iT != m_TCoord )
132  {
134 
135  boost::tuples::tie(it0, it1) = m_Container.get< TCoord >().equal_range(iT);
136 
137  ChangeActorsVisibility< TCoord >(m_Container.get< TCoord >().begin(), it0, false);
138  ChangeActorsVisibility< TCoord >(it0, it1, true);
139  ChangeActorsVisibility< TCoord >(it1, m_Container.get< TCoord >().end(), false);
140 
141  m_TCoord = iT;
142  }
143 }
144 
145 //-------------------------------------------------------------------------
146 
147 //-------------------------------------------------------------------------
148 void
150 {
152 
153  boost::tuples::tie(it0, it1) = m_Container.get< TCoord >().equal_range(iT);
154 
155  ChangeActorsVisibility< TCoord >(it0, it1, true);
156 
157  if ( m_ImageView )
158  {
160  }
161 }
162 
163 //-------------------------------------------------------------------------
164 
165 //-------------------------------------------------------------------------
166 void
168  const Qt::CheckState & iCheck)
169 {
171  iCheck);
172 }
173 
174 //-------------------------------------------------------------------------
175 
176 //-------------------------------------------------------------------------
177 void
179  const Qt::CheckState & iCheck)
180 {
182 }
183 
184 //-------------------------------------------------------------------------
185 
186 //-------------------------------------------------------------------------
187 bool
188 ContourMeshContainer::DeleteElement(const unsigned int & iId)
189 {
191  it = m_Container.get< TraceID >().find(iId);
192 
193  return DeleteElement(it);
194 }
195 
196 //-------------------------------------------------------------------------
197 
198 //-------------------------------------------------------------------------
199 bool
201 {
202  if ( iIter != m_Container.get< TraceID >().end() )
203  {
204  if ( iIter->ActorXY )
205  {
206  if ( m_ImageView )
207  {
208  this->m_ImageView->RemoveActor(0, iIter->ActorXY);
209  }
210  iIter->ActorXY->Delete();
211  }
212  if ( iIter->ActorXZ )
213  {
214  if ( m_ImageView )
215  {
216  this->m_ImageView->RemoveActor(1, iIter->ActorXZ);
217  }
218  iIter->ActorXZ->Delete();
219  }
220  if ( iIter->ActorYZ )
221  {
222  if ( m_ImageView )
223  {
224  this->m_ImageView->RemoveActor(2, iIter->ActorYZ);
225  }
226  iIter->ActorYZ->Delete();
227  }
228  if ( iIter->ActorXYZ )
229  {
230  if ( m_ImageView )
231  {
232  this->m_ImageView->RemoveActor(3, iIter->ActorXYZ);
233  }
234  iIter->ActorXYZ->Delete();
235  }
236 
237  if ( iIter->Nodes )
238  {
239  iIter->Nodes->Delete();
240  }
241 
242  m_Container.get< TraceID >().erase(iIter);
243 
244  return true;
245  }
246  return false;
247 }
248 
249 //-------------------------------------------------------------------------
250 
251 //-------------------------------------------------------------------------
252 std::list< unsigned int >
254 {
256 
257  boost::tuples::tie(it0, it1) =
258  m_Container.get< Highlighted >().equal_range(true);
259 
260  std::list< unsigned int > oList;
261 
262  while ( it0 != it1 )
263  {
264  oList.push_back(it0->TraceID);
265  if ( it0->ActorXY )
266  {
267  if ( m_ImageView )
268  {
269  this->m_ImageView->RemoveActor(0, it0->ActorXY);
270  }
271  it0->ActorXY->Delete();
272  }
273  if ( it0->ActorXZ )
274  {
275  if ( m_ImageView )
276  {
277  this->m_ImageView->RemoveActor(1, it0->ActorXZ);
278  }
279  it0->ActorXZ->Delete();
280  }
281  if ( it0->ActorYZ )
282  {
283  if ( m_ImageView )
284  {
285  this->m_ImageView->RemoveActor(2, it0->ActorYZ);
286  }
287  it0->ActorYZ->Delete();
288  }
289  if ( it0->ActorXYZ )
290  {
291  if ( m_ImageView )
292  {
293  this->m_ImageView->RemoveActor(3, it0->ActorXYZ);
294  }
295  it0->ActorXYZ->Delete();
296  }
297  if ( it0->Nodes )
298  {
299  it0->Nodes->Delete();
300  }
301 
302  it_t = it0;
303  ++it0;
304 
305  m_Container.get< Highlighted >().erase(it_t);
306  }
307 
308  if ( m_ImageView )
309  {
311  }
312 
313  return oList;
314 }
315 
316 //-------------------------------------------------------------------------
317 
318 //-------------------------------------------------------------------------
319 std::list< unsigned int >
321 {
323 
324  boost::tuples::tie(it0, it1) =
325  m_Container.get< TCoord >().equal_range(iTimePoint);
326 
327  std::list< unsigned int > oList;
328  while ( it0 != it1 )
329  {
330  oList.push_back(it0->TraceID);
331  ++it0;
332  }
333  return oList;
334 }
335 
336 //-------------------------------------------------------------------------
337 
338 //-------------------------------------------------------------------------
339 std::map< unsigned int, double * >
340 ContourMeshContainer::GetMeshesPoints(std::list< unsigned int > iMeshID)
341 {
342  std::map< unsigned int, double * > meshPosition;
343  std::list< unsigned int >::iterator listIt = iMeshID.begin();
345 
346  while ( listIt != iMeshID.end() )
347  {
348  containerIt = m_Container.get< TraceID >().find(*listIt);
349 
350  //if element found
351  if ( containerIt != m_Container.get< TraceID >().end() )
352  {
353  unsigned int time = containerIt->TCoord;
354  double * point = new double[3];
355 
356  double bounds[6];
357  containerIt->Nodes->GetBounds(bounds);
358 
359  for ( int i = 0; i < 3; ++i )
360  {
361  point[i] = ( bounds[2 * i] + bounds[2 * i + 1] ) / 2;
362  }
363 
364  meshPosition.insert( std::pair< unsigned int, double * >(time, point) );
365  }
366  ++listIt;
367  }
368 
369  return meshPosition;
370 }
371 //-------------------------------------------------------------------------
372 
373 //-------------------------------------------------------------------------
374 void
377 {
378  MultiIndexContainerTraceIDIterator it = m_Container.get< TraceID >().begin();
379  while ( it != m_Container.get< TraceID >().end() )
380  {
381  DeleteElement(it);
382  ++it;
383  }
384 
385  assert ( m_ImageView );
387 }
388 //-------------------------------------------------------------------------
389 
390 //-------------------------------------------------------------------------
391 void
393 Clear( const std::list<unsigned int>& iTraceIDs)
394 {
395  std::list<unsigned int>::const_iterator it = iTraceIDs.begin();
396  while(it!= iTraceIDs.end())
397  {
398  DeleteElement(*it);
399  ++it;
400  }
401 
402  assert ( m_ImageView );
404 }
405 //-------------------------------------------------------------------------
406 // move up
407 //-------------------------------------------------------------------------
408 void
410 AssignToGivenCollection(unsigned int iCollection,
411  std::list< unsigned int > iToBeAssigned)
412 {
413  std::list< unsigned int >::iterator listIt = iToBeAssigned.begin();
415 
416  while ( listIt != iToBeAssigned.end() )
417  {
418  containerIt = m_Container.get< TraceID >().find(*listIt);
419 
420  //if element found
421  if ( containerIt != m_Container.get< TraceID >().end() )
422  {
423  m_Container.get< TraceID >().modify(
424  containerIt, change_collectionID(iCollection));
425  }
426  ++listIt;
427  }
428 }
429 //-------------------------------------------------------------------------
430 
431 //-------------------------------------------------------------------------
432 std::list< unsigned int >
434 {
436 
437  using boost::multi_index:: get;
438 
439  boost::tuples::tie(it0, it1) =
440  m_Container.get< Highlighted >().equal_range(true);
441 
442  std::list< unsigned int > oList;
443  while ( it0 != it1 )
444  {
445  oList.push_back(it0->TCoord);
446  ++it0;
447  }
448  return oList;
449 }
450 //-------------------------------------------------------------------------
void UpdateElementVisibilityWithGivenTraceIDs(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements visibility property given a list of TraceIDs and the new status.
bool DeleteElement(const unsigned int &iId)
Remove the element which TraceId = iId.
std::list< unsigned int > DeleteAllHighlightedElements()
Delete all highlighted elements.
std::map< unsigned int, double * > GetMeshesPoints(std::list< unsigned int > iMeshID)
void UpdateRenderWindows()
Update only the visualization.
MultiIndexContainerType::template index< TraceID >::type::iterator MultiIndexContainerTraceIDIterator
MultiIndexContainerType m_Container
Trace Contaienr.
virtual void UpdateElementHighlightingWithGivenTraceIDsBase(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements highlighting property given a list of TraceIDs and the new status.
void AssignToGivenCollection(unsigned int iCollection, std::list< unsigned int > iToBeAssigned)
std::list< unsigned int > GetElementsTraceIDForGivenTimePoint(unsigned int iTimePoint)
MultiIndexContainerType::template index< Highlighted >::type::iterator MultiIndexContainerHighlightedIterator
void UpdateElementHighlightingWithGivenTraceIDs(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements highlighting property given a list of TraceIDs and the new status.
class for the visualization of 3D Image represented by one vtkImageData*.
virtual void RemoveActor(const int &iId, vtkActor *iActor)
std::list< unsigned int > GetHighlightedElementsTCoord()
void ShowActorsWithGivenTimePoint(const unsigned int &iT)
Display all elements for a given time point.
virtual void UpdateElementVisibilityWithGivenTraceIDsBase(const QStringList &iList, const Qt::CheckState &iCheck)
Change elements visibility property given a list of TraceIDs and the new status.
void RemoveActorsWithGivenTimePoint(const unsigned int &iT)
Remove all actors (elements) from the scene for a given time point.
QGoImageView3D * m_ImageView
Link to the visualization.
void SetTimePoint(const unsigned int &iT)
Set the Current Time Point.
MultiIndexContainerElementType m_CurrentElement
Current Element of the trace type.
ContourMeshContainer(QObject *iParent, QGoImageView3D *iView)
Constructor.
void UpdateCurrentElementFromVisuBase(std::vector< vtkActor * > &iActors, vtkPolyData *iNodes, const bool &iHighlighted, const bool &iVisible)
void AddActorsWithGivenTimePoint(const unsigned int &iT)
Add all actors (elements) from the scene for a given time point.
void Clear()
Delete all elements from the container.
virtual ~ContourMeshContainer()
Destructor.
void UpdateCurrentElementFromVisu(std::vector< vtkActor * > &iActors, vtkPolyData *iNodes, const unsigned int &iT, const bool &iHighlighted, const bool &iVisible)
Update Current Element by providing all required informations from the visualization.
MultiIndexContainerType::index< TCoord >::type::iterator MultiIndexContainerTCoordIterator