GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoImageProcessor.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 GoImageProcessor_H
36 #define GoImageProcessor_H
37 
38 // Required for dynamic libs on Windows (QGoIOExport)
39 #include "QGoIOConfigure.h"
40 
41 // external library include
42 // VTK
43 #include "vtkSmartPointer.h"
44 // ITK
45 #include "itkInvertIntensityImageFilter.h"
46 // BOOST
47 #include <boost/multi_index_container.hpp>
48 #include <boost/multi_index/member.hpp>
49 #include <boost/multi_index/ordered_index.hpp>
50 #include <boost/multi_index/hashed_index.hpp>
51 
52 // include project
53 #include "GoMegaImageStructure.h"
54 
55 // external include
56 class vtkLookupTable;
57 class vtkImageData;
58 class vtkImageAccumulate;
59 
60 class QString;
61 
62 //-----------------------------------------------------------------------------
63 
64 //-----------------------------------------------------------------------------
71 {
72  set_visibility(bool iVisibility):visibility(iVisibility){}
73 
74  void operator()(GoMegaImageStructure& iStructure)
75  {
76  iStructure.setVisibility(visibility);
77  }
78 
79 private:
80  bool visibility;
81 };
82 //-----------------------------------------------------------------------------
83 
84 //-----------------------------------------------------------------------------
90 struct set_color
91 {
92  set_color(std::vector<double> iColor):color(iColor){}
93 
94  void operator()(GoMegaImageStructure& iStructure)
95  {
96  iStructure.setColor(color);
97  }
98 
99 private:
100  std::vector<double> color;
101 };
102 //-----------------------------------------------------------------------------
103 
104 //-----------------------------------------------------------------------------
111 {
112  set_LUT_Parameters(int iGamma, int iMin, int iMax):
113  gamma(iGamma), min(iMin), max(iMax){}
114 
116  {
117  iStructure.setLUTParameters(gamma, min, max);
118  }
119 
120 private:
121  int gamma;
122  int min;
123  int max;
124 };
125 //-----------------------------------------------------------------------------
126 
127 //-----------------------------------------------------------------------------
133 struct set_image
134 {
135  set_image(vtkImageData* iImage):image(iImage){}
136 
138  {
139  iStructure.setImage(image);
140  }
141 
142 private:
143  vtkImageData* image;
144 };
145 //-----------------------------------------------------------------------------
146 
147 //-----------------------------------------------------------------------------
154 {
155  set_PointsAlpha(std::map< unsigned int, unsigned int> iPoints):points(iPoints){}
156 
158  {
159  iStructure.set_PointsAlpha(points);
160  }
161 
162 private:
163  std::map< unsigned int, unsigned int> points;
164 };
165 //-----------------------------------------------------------------------------
166 
167 //-----------------------------------------------------------------------------
168 /* tags for accessing the corresponding indices of GoMegaImageStructure */
169 
170 struct Index{};
171 struct Visibility{};
172 struct Name{};
173 
174 /* Define a multi_index_container of images with following indices:
175  * - a non-unique index sorted by GoMegaImageStructure::Index,
176  * - a non-unique index sorted by GoMegaImageStructure::Visibility,
177  * - a non-unique index sorted by GoMegaImageStructure::Channel,
178  */
179 
180 typedef boost::multi_index_container<
182  boost::multi_index::indexed_by<
183  boost::multi_index::ordered_non_unique<
184  boost::multi_index::tag<Index>,
185  BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure,unsigned int,Index)>,
186  boost::multi_index::ordered_non_unique<
187  boost::multi_index::tag<Visibility>,
188  BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure,bool,Visibility)>,
189  boost::multi_index::hashed_non_unique<
190  boost::multi_index::tag<Name>,
191  BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure,std::string,Name)> >
193 
194 //-----------------------------------------------------------------------------
195 
205 class QGOIO_EXPORT GoImageProcessor
206 {
207 public:
208 
211 
213  GoImageProcessor( const GoImageProcessor& iE );
214 
216  virtual ~GoImageProcessor();
217 
219  friend std::ostream & operator<<
220  (std::ostream & os, const GoImageProcessor & c)
221  {
222  //os << "TraceID " << c.TraceID << std::endl;
223  return os;
224  }
225 
226  // LUT
227  //---------------------------------------------------------------------------
228 
238  vtkSmartPointer<vtkLookupTable> createLUT(const double& iRed,
239  const double& iGreen,
240  const double& iBlue,
241  const double& iAlpha);
242 
249  vtkSmartPointer<vtkLookupTable> getLookuptable(const std::string& iName) const;
250 
257  vtkSmartPointer<vtkLookupTable> getLookuptable() const;
258 
259  // opacity transfer functions
260  //---------------------------------------------------------------------------
268  vtkSmartPointer<vtkPiecewiseFunction>
269  getOpacityTransferFunction(const std::string& iName) const;
270 
276  std::vector<vtkPiecewiseFunction*> getOpacityTransferFunctions();
277 
278  // colors
279  //---------------------------------------------------------------------------
286  std::vector<double> getColor(const std::string& iName) const;
287 
288  void setColor(const std::string& iName, std::vector<double>& iColor);
289 
290  void setLUTParameters(const std::string& iName, int iGamma, int iMin, int iMax);
291 
292  std::vector<int> getLUTParameters(const std::string& iName);
293 
300  std::map<unsigned int, unsigned int> getAlpha(
301  const std::string& iName) const;
302 
308  void updatePoints(std::string iChannel,
309  std::map< unsigned int, unsigned int> iPointsAlpha);
310 
316  vtkSmartPointer< vtkImageAccumulate>
317  getHistogram(const std::string& iName) const;
318 
324  virtual void initTimePoint(const unsigned int& iTime) = 0;
325 
330  virtual void setTimePoint(const unsigned int& iTime) = 0;
331 
340  virtual void setDoppler(const unsigned int& iTime,
341  const unsigned int& iPrevious) = 0;
342 
343  // images
344  //---------------------------------------------------------------------------
345 
352  vtkSmartPointer<vtkImageData> getImageBW(const std::string& iName);
353  vtkSmartPointer<vtkImageData> getImageBW(const unsigned int& iIndex);
354 
360  vtkSmartPointer<vtkImageData> getImageBW();
361 
367  std::string getChannelName(const unsigned int& iIndex);
368 
373  std::vector<vtkImageData*> getColoredImages();
374 
379  template< class PixelType, const unsigned int VImageDimension >
380  typename itk::Image< PixelType, VImageDimension >::Pointer
381  getImageITK(std::string iIndex, bool iIsInverted = false)
382  {
383  GoMegaImageStructureMultiIndexContainer::index<Name>::type::iterator it =
384  m_MegaImageContainer.get< Name >().find(iIndex);
385 
386  assert(it!=m_MegaImageContainer.get< Name >().end());
387 
388  if(iIsInverted)
389  {
390  //get image and invert it
391  typedef itk::Image<PixelType, VImageDimension> ImageType;
392  typedef itk::InvertIntensityImageFilter <ImageType> InvertFilterType;
393  typename InvertFilterType::Pointer invertFilter = InvertFilterType::New();
394  invertFilter->SetInput( it->Convert2ITK<PixelType, VImageDimension>() );
395  invertFilter->Update();
396 
397  typename ImageType::Pointer itkImage = invertFilter->GetOutput();
398  itkImage->DisconnectPipeline();
399 
400  return itkImage;
401  }
402  else
403  {
404  return it->Convert2ITK<PixelType, VImageDimension>();
405  }
406  return NULL;
407  }
408 
414  vtkSmartPointer<vtkImageData> getVisibleImages();
415 
416  // Image parameters
417  //---------------------------------------------------------------------------
418  unsigned int* getBoundsTime();
419  unsigned int* getBoundsChannel();
420 
421  int* getExtent();
422 
423  unsigned int getNumberOfTimePoints();
424  unsigned int getNumberOfChannels();
425 
426  unsigned int getTimeInterval() const;
427 
428  // Doppler parameters
429  //---------------------------------------------------------------------------
430  unsigned int getDopplerStep();
431  void setDopplerStep(unsigned int iStep);
432  std::vector<int> getDopplerTime(unsigned int iTime);
433  void setDopplerMode(const bool& iEnable, const unsigned int& iChannel);
434  bool getDopplerMode();
435  unsigned int getDopplerChannel();
436  void setDopplerSize(int iSize);
437  unsigned int getDopplerSize();
438 
444  void visibilityChanged(std::string iName, bool iVisibility);
445 
450  unsigned int getNumberOfVisibleChannels();
451 
452  int getMaxThreshold();
453 
454  int getMaxImage();
455 
456 protected:
457  /*
458  * \brief Color an image given the original image and a lookuptable (LUT)
459  * \param[in] iImage image to be colored
460  * \param[in] iLUT LUT to be applied to the image
461  * \return colored image
462  */
463  vtkSmartPointer<vtkImageData> colorImage(vtkSmartPointer<vtkImageData> iImage,
464  vtkSmartPointer<vtkLookupTable> iLUT);
465 
467  vtkSmartPointer<vtkImageData> m_Output;
468 
469  unsigned int m_CurrentTimePoint;
470 
471  // Image parameters
472  //--------------------
473  unsigned int m_BoundsTime[2];
474  unsigned int m_BoundsChannel[2];
475  int m_Extent[6];
476  unsigned int m_TimeInterval;
479  //--------------------
480 
481  // Doppler view parameters
482  //--------------------
484  unsigned int m_DopplerStep;
485  std::vector<int> m_DopplerTime;
486  unsigned int m_DopplerChannel;
487  unsigned int m_DopplerSize;
488  //--------------------
489 
490 private:
491  // overload "=" operator
493  {
494  // Only do assignment if RHS is a different object from this.
495  if (this != &rhs)
496  {
497  this->m_MegaImageContainer = rhs.m_MegaImageContainer;
498  this->m_BoundsTime[0] = rhs.m_BoundsTime[0];
499  this->m_BoundsTime[1] = rhs.m_BoundsTime[1];
500  this->m_BoundsChannel[0] = rhs.m_BoundsChannel[0];
501  this->m_BoundsChannel[1] = rhs.m_BoundsChannel[1];
502  this->m_Extent[0] = rhs.m_Extent[0];
503  this->m_Extent[1] = rhs.m_Extent[1];
504  this->m_Extent[2] = rhs.m_Extent[2];
505  this->m_Extent[3] = rhs.m_Extent[3];
506  this->m_Extent[4] = rhs.m_Extent[4];
507  this->m_Extent[5] = rhs.m_Extent[5];
508  this->m_TimeInterval = rhs.m_TimeInterval;
509  this->m_MaxThreshold = rhs.m_MaxThreshold;
510  this->m_DopplerMode = rhs.m_DopplerMode;
511  this->m_DopplerStep = rhs.m_DopplerStep;
512  this->m_DopplerTime = rhs.m_DopplerTime;
513  this->m_DopplerChannel = rhs.m_DopplerChannel;
514  }
515  return *this;
516  }
517 
518 };
519 
520 #endif // GoImageProcessor_H
void setImage(vtkImageData *iImage)
std::vector< double > color
change color of given structure
boost::multi_index_container< GoMegaImageStructure, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< Index >, BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure, unsigned int, Index)>, boost::multi_index::ordered_non_unique< boost::multi_index::tag< Visibility >, BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure, bool, Visibility)>, boost::multi_index::hashed_non_unique< boost::multi_index::tag< Name >, BOOST_MULTI_INDEX_MEMBER(GoMegaImageStructure, std::string, Name)> >> GoMegaImageStructureMultiIndexContainer
set_visibility(bool iVisibility)
void operator()(GoMegaImageStructure &iStructure)
unsigned int m_CurrentTimePoint
unsigned int m_DopplerSize
GoImageProcessor & operator=(const GoImageProcessor &rhs)
change visibility of given structure
unsigned int m_BoundsTime[2]
set_LUT_Parameters(int iGamma, int iMin, int iMax)
void operator()(GoMegaImageStructure &iStructure)
itk::Image< PixelType, VImageDimension >::Pointer getImageITK(std::string iIndex, bool iIsInverted=false)
get an ITK image (vs vtkImageData) given its index
Convenience structure to store visible image.
void setLUTParameters(int iGamma, int iMin, int iMax)
set_image(vtkImageData *iImage)
unsigned int m_DopplerChannel
unsigned int m_BoundsChannel[2]
unsigned int m_DopplerStep
void set_PointsAlpha(std::map< unsigned int, unsigned int > iAlpha)
GoMegaImageStructureMultiIndexContainer m_MegaImageContainer
vtkImageData * image
void setVisibility(bool iVisibility)
unsigned int m_TimeInterval
set_PointsAlpha(std::map< unsigned int, unsigned int > iPoints)
set_color(std::vector< double > iColor)
void setColor(std::vector< double > iColor)
change parameters of LUT
std::vector< int > m_DopplerTime
std::map< unsigned int, unsigned int > points
Interface between image reader and vtkImageData.
void operator()(GoMegaImageStructure &iStructure)
vtkSmartPointer< vtkImageData > m_Output
change visibility of given structure
void operator()(GoMegaImageStructure &iStructure)
void operator()(GoMegaImageStructure &iStructure)