GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoLSMImageProcessor.cxx
Go to the documentation of this file.
1 
2 /*=========================================================================
3  Authors: The GoFigure Dev. Team.
4  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
5 
6  Copyright (c) 2009-11, President and Fellows of Harvard College.
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions are met:
11 
12  Redistributions of source code must retain the above copyright notice,
13  this list of conditions and the following disclaimer.
14  Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17  Neither the name of the President and Fellows of Harvard College
18  nor the names of its contributors may be used to endorse or promote
19  products derived from this software without specific prior written
20  permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
26  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 =========================================================================*/
35 
36 #include "GoLSMImageProcessor.h"
37 
38 #include "vtkMath.h"
39 
40 //--------------------------------------------------------------------------
41 void
44 {
45  m_LSMReader = iReader;
46 
47  // update general parameters
48  //--------------------
49  int numberOfTimePoints = m_LSMReader->GetNumberOfTimePoints();
50  m_BoundsTime[0] = 0;
51  m_BoundsTime[1] = numberOfTimePoints -1;
52 
53  int numberOfChannels = m_LSMReader->GetNumberOfChannels();
54  m_BoundsChannel[0] = 0;
55  m_BoundsChannel[1] = numberOfChannels -1;
56 
57  m_TimeInterval = m_LSMReader->GetTimeInterval();
58 }
59 //--------------------------------------------------------------------------
60 
61 //--------------------------------------------------------------------------
62 void
64 initTimePoint(const unsigned int& iTime)
65 {
66  if( iTime != this->m_CurrentTimePoint )
67  {
68  //check if time point exists
69  if(iTime >= m_BoundsTime[0] && iTime <= m_BoundsTime[1])
70  {
71  m_MegaImageContainer.clear();
72  }
73  else
74  {
75  return;
76  }
77  this->m_CurrentTimePoint = iTime;
78 
79  // update the container
80  // Get Number of channels from reader
81  int numberOfChannels = this->getNumberOfChannels();
82 
83  #ifdef HAS_OPENMP
84  #pragma omp for
85  #endif
86  for( int i = 0; i < numberOfChannels; i++ )
87  {
88  vtkSmartPointer<vtkLSMReader> reader =
89  vtkSmartPointer<vtkLSMReader>::New();
90  reader->SetFileName(m_LSMReader->GetFileName());
91  reader->SetUpdateChannel( i );
92  reader->SetUpdateTimePoint(iTime);
93  reader->Update();
94 
95  // get image
96  vtkSmartPointer<vtkImageData> image = reader->GetOutput();
97 
98  // capacity of image -> rescale in multichannelmode
99  int type = image->GetScalarSize();
100  double threshold = pow((double)2, (int)8*type) - 1;
101  m_MaxImage = threshold;
102  // max pixel in image
103  double range = image->GetScalarRange()[1];
104  if(m_MaxThreshold < range)
105  {
106  m_MaxThreshold = range;
107  }
108 
109  // Get Color
110  double random1 = reader->
111  GetChannelColorComponent(i, 0);
112  double value1 = random1;
113 
114  double random2 = reader->
115  GetChannelColorComponent(i, 1);
116  double value2 = random2;
117 
118  double random3 = reader->
119  GetChannelColorComponent(i, 2);
120  double value3 = random3;
121 
122  std::vector<double> color( 4 );
123  color[0] = value1;
124  color[1] = value2;
125  color[2] = value3;
126  color[3] = 255;
127 
128  // Create LUT
129  vtkSmartPointer<vtkLookupTable> lut = createLUT(color[0],
130  color[1],
131  color[2],
132  color[3]);
133  // create name...
134  std::stringstream channelName;
135  channelName << "Channel ";
136  channelName << i;
137 
138  // Update the MegaImageStructure
139  // image, LUT, channel, time point
141  lut,
142  image,
143  color,
144  true,
145  channelName.str()));
146  }
147  }
148 }
149 //--------------------------------------------------------------------------
150 
151 //--------------------------------------------------------------------------
152 void
154 setTimePoint(const unsigned int& iTime)
155 {
156  if( iTime != this->m_CurrentTimePoint )
157  {
158  //check if time point exists
159  if(iTime < m_BoundsTime[0] && iTime <= m_BoundsTime[1])
160  {
161  return;
162  }
163 
164  this->m_CurrentTimePoint = iTime;
165 
166  // update the container
167  // Get Number of channels from reader
168  int numberOfChannels = this->getNumberOfChannels();
169 
170  #ifdef HAS_OPENMP
171  #pragma omp for
172  #endif
173  for( int i = 0; i < numberOfChannels; i++ )
174  {
175  vtkSmartPointer<vtkLSMReader> reader =
176  vtkSmartPointer<vtkLSMReader>::New();
177  reader->SetFileName(m_LSMReader->GetFileName());
178  reader->SetUpdateChannel( i );
179  reader->SetUpdateTimePoint(iTime);
180  reader->Update();
181 
182  // get image
183  vtkSmartPointer<vtkImageData> image = reader->GetOutput();
184 
185  // could iterate on sth else...
186  GoMegaImageStructureMultiIndexContainer::index<Index>::type::iterator it =
187  m_MegaImageContainer.get< Index >().find( i );
188 
189  if(it!=m_MegaImageContainer.get< Index >().end())
190  {
191  m_MegaImageContainer.get< Index >().modify( it , set_image(image) );
192  }
193  }
194  }
195 }
196 //--------------------------------------------------------------------------
197 
198 //--------------------------------------------------------------------------
199 void
201 setDoppler(const unsigned int& iTime, const unsigned int& iPrevious)
202 {
203  //to optimize doppler view later on
204  (void) iPrevious;
205 
206  //check if time point exists
207  if(iTime >= m_BoundsTime[0] && iTime <= m_BoundsTime[1])
208  {
209  }
210  else
211  {
212  return;
213  }
214 
215  std::vector<int> dopplerTime = getDopplerTime(iTime);
216 
217  int dopplerSize = static_cast<int>(this->getDopplerSize());
218 
219 #ifdef HAS_OPENMP
220 #pragma omp for
221 #endif
222  for(int i=0; i < dopplerSize; ++i)
223  {
224  if(dopplerTime[i] >= 0)
225  {
226  vtkSmartPointer<vtkLSMReader> reader =
227  vtkSmartPointer<vtkLSMReader>::New();
228  reader->SetFileName(m_LSMReader->GetFileName());
229  reader->SetUpdateChannel(m_DopplerChannel);
230  reader->SetUpdateTimePoint(dopplerTime[i]);
231  reader->Update();
232 
233  // get image
234  vtkSmartPointer<vtkImageData> image = reader->GetOutput();
235 
236  // hue: 0 to 0.7
237  double* rgb = vtkMath::HSVToRGB(
238  static_cast<double>(i)/static_cast<double>(dopplerSize),1,1);
239 
240  // color from red to blue
241  std::vector<double> color;
242  color.push_back(rgb[0]*255);
243  color.push_back(rgb[1]*255);
244  color.push_back(rgb[2]*255);
245  color.push_back(255);
246 
247  // Create LUT
248  vtkSmartPointer<vtkLookupTable> lut = createLUT(color[0],
249  color[1],
250  color[2],
251  color[3]);
252 
253  // channel name
254  std::stringstream channelName;
255  //channelName << "t: ";
256  channelName << dopplerTime[i];
257 
258  // Update the MegaImageStructure
259  // image, LUT, channel, time point
260  m_MegaImageContainer.insert(GoMegaImageStructure(dopplerTime[i],
261  lut,
262  image,
263  color,
264  true,
265  channelName.str()));
266  }
267  }
268 }
269 //--------------------------------------------------------------------------
void setReader(vtkLSMReader *iReader)
Set the reader.
unsigned int m_CurrentTimePoint
std::vector< int > getDopplerTime(unsigned int iTime)
change visibility of given structure
unsigned int m_BoundsTime[2]
Convenience structure to store visible image.
unsigned int getDopplerSize()
unsigned int getNumberOfChannels()
unsigned int m_DopplerChannel
unsigned int m_BoundsChannel[2]
virtual void setDoppler(const unsigned int &iTime, const unsigned int &iPrevious)
load all time points of the given channel into the GoMegaImageStructure. Called Doppler View...
virtual void initTimePoint(const unsigned int &iTime)
load all the channels for the given time point into the GoMegaImageStructure
int GetNumberOfTimePoints()
int GetNumberOfChannels()
GoMegaImageStructureMultiIndexContainer m_MegaImageContainer
virtual void setTimePoint(const unsigned int &iTime)
update images from the current GoMegaImageStructure
unsigned int m_TimeInterval
vtkSmartPointer< vtkLookupTable > createLUT(const double &iRed, const double &iGreen, const double &iBlue, const double &iAlpha)
create a lookuptable (LUT) given r, g, b, a and range LUT will go from black to the color...
vtkLSMReader * m_LSMReader