Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
vtkMitkVolumeTextureMapper3D.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "vtkMitkVolumeTextureMapper3D.h"
14 #include "mitkCommon.h"
15 
16 #define GPU_INFO MITK_INFO("mapper.vr")
17 #define GPU_WARN MITK_WARN("mapper.vr")
18 
19 #include "vtkCamera.h"
20 #include "vtkColorTransferFunction.h"
21 #include "vtkDataArray.h"
22 #include "vtkImageData.h"
23 #include "vtkMath.h"
24 #include "vtkMatrix4x4.h"
25 #include "vtkPiecewiseFunction.h"
26 #include "vtkPointData.h"
27 #include "vtkRenderer.h"
28 #include "vtkVolume.h"
29 #include "vtkVolumeProperty.h"
30 //#include "vtkVolumeRenderingFactory.h" //VTK6_TODO
31 
32 //----------------------------------------------------------------------------
33 // Needed when we don't use the vtkStandardNewMacro.
34 vtkInstantiatorNewMacro(vtkMitkVolumeTextureMapper3D);
35 //----------------------------------------------------------------------------
36 
37 //-----------------------------------------------------------------------------
38 vtkMitkVolumeTextureMapper3D::vtkMitkVolumeTextureMapper3D()
39 {
40  // GPU_INFO << "vtkMitkVolumeTextureMapper3D";
41 
42  this->PolygonBuffer = nullptr;
43  this->IntersectionBuffer = nullptr;
44  this->NumberOfPolygons = 0;
45  this->BufferSize = 0;
46 
47  // The input used when creating the textures
48  this->SavedTextureInput = nullptr;
49 
50  // The input used when creating the color tables
51  this->SavedParametersInput = nullptr;
52 
53  this->SavedRGBFunction = nullptr;
54  this->SavedGrayFunction = nullptr;
55  this->SavedScalarOpacityFunction = nullptr;
56  this->SavedGradientOpacityFunction = nullptr;
57  this->SavedColorChannels = 0;
58  this->SavedSampleDistance = 0;
59  this->SavedScalarOpacityDistance = 0;
60 
61  /*
62  this->Volume1 = nullptr;
63  this->Volume2 = nullptr;
64  this->Volume3 = nullptr;
65  */
66  /*
67  this->VolumeSize = 0;
68  this->VolumeComponents = 0;
69  */
70 
71  this->VolumeSpacing[0] = this->VolumeSpacing[1] = this->VolumeSpacing[2] = 0;
72  this->VolumeDimensions[0] = 0;
73  this->VolumeDimensions[1] = 0;
74  this->VolumeDimensions[2] = 0;
75 
76  this->SampleDistance = 1.0;
77  this->ActualSampleDistance = 1.0;
78 
79  this->UseCompressedTexture = false;
80  this->SupportsNonPowerOfTwoTextures = false;
81 
82  // GPU_INFO << "np2: " << (this->SupportsNonPowerOfTwoTextures?1:0);
83 }
84 
85 //-----------------------------------------------------------------------------
86 vtkMitkVolumeTextureMapper3D::~vtkMitkVolumeTextureMapper3D()
87 {
88  // GPU_INFO << "~vtkMitkVolumeTextureMapper3D";
89 
90  delete[] this->PolygonBuffer;
91  delete[] this->IntersectionBuffer;
92  /*
93  delete [] this->Volume1;
94  delete [] this->Volume2;
95  delete [] this->Volume3;
96  */
97 }
98 
99 //-----------------------------------------------------------------------------
100 // vtkMitkVolumeTextureMapper3D *vtkMitkVolumeTextureMapper3D::New() //VTK6_TODO
101 //{
102 // //GPU_INFO << "New";
103 
104 // // First try to create the object from the vtkObjectFactory
105 // vtkObject* ret =
106 // vtkVolumeRenderingFactory::CreateInstance("vtkMitkVolumeTextureMapper3D");
107 // return static_cast<vtkMitkVolumeTextureMapper3D *>(ret);
108 //}
109 
110 //-----------------------------------------------------------------------------
111 void vtkMitkVolumeTextureMapper3D::ComputePolygons(vtkRenderer *ren, vtkVolume *vol, double inBounds[6])
112 {
113  // GPU_INFO << "ComputePolygons";
114 
115  // Get the camera position and focal point
116  double focalPoint[4], position[4];
117  double plane[4];
118  vtkCamera *camera = ren->GetActiveCamera();
119 
120  camera->GetPosition(position);
121  camera->GetFocalPoint(focalPoint);
122 
123  position[3] = 1.0;
124  focalPoint[3] = 1.0;
125 
126  // Pass the focal point and position through the inverse of the
127  // volume's matrix to map back into the data coordinates. We
128  // are going to compute these polygons in the coordinate system
129  // of the input data - this is easiest since this data must be
130  // axis aligned. Then we'll use OpenGL to transform these polygons
131  // into the world coordinate system through the use of the
132  // volume's matrix.
133  vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
134  vol->GetMatrix(matrix);
135  matrix->Invert();
136  matrix->MultiplyPoint(position, position);
137  matrix->MultiplyPoint(focalPoint, focalPoint);
138  matrix->Delete();
139 
140  if (position[3])
141  {
142  position[0] /= position[3];
143  position[1] /= position[3];
144  position[2] /= position[3];
145  }
146 
147  if (focalPoint[3])
148  {
149  focalPoint[0] /= focalPoint[3];
150  focalPoint[1] /= focalPoint[3];
151  focalPoint[2] /= focalPoint[3];
152  }
153 
154  // Create a plane equation using the direction and position of the camera
155  plane[0] = focalPoint[0] - position[0];
156  plane[1] = focalPoint[1] - position[1];
157  plane[2] = focalPoint[2] - position[2];
158 
159  vtkMath::Normalize(plane);
160 
161  plane[3] = -(plane[0] * position[0] + plane[1] * position[1] + plane[2] * position[2]);
162 
163  // Find the min and max distances of the boundary points of the volume
164  double minDistance = VTK_DOUBLE_MAX;
165  double maxDistance = VTK_DOUBLE_MIN;
166 
167  // The inBounds parameter is the bounds we are using for clipping the
168  // texture planes against. First we need to clip these against the bounds
169  // of the volume to make sure they don't exceed it.
170  double volBounds[6];
171  this->GetInput()->GetBounds(volBounds);
172 
173  double bounds[6];
174  bounds[0] = (inBounds[0] > volBounds[0]) ? (inBounds[0]) : (volBounds[0]);
175  bounds[1] = (inBounds[1] < volBounds[1]) ? (inBounds[1]) : (volBounds[1]);
176  bounds[2] = (inBounds[2] > volBounds[2]) ? (inBounds[2]) : (volBounds[2]);
177  bounds[3] = (inBounds[3] < volBounds[3]) ? (inBounds[3]) : (volBounds[3]);
178  bounds[4] = (inBounds[4] > volBounds[4]) ? (inBounds[4]) : (volBounds[4]);
179  bounds[5] = (inBounds[5] < volBounds[5]) ? (inBounds[5]) : (volBounds[5]);
180 
181  // Create 8 vertices for the bounding box we are rendering
182  int i, j, k;
183  double vertices[8][3];
184 
185  int idx = 0;
186 
187  for (k = 0; k < 2; k++)
188  {
189  for (j = 0; j < 2; j++)
190  {
191  for (i = 0; i < 2; i++)
192  {
193  vertices[idx][2] = bounds[4 + k];
194  vertices[idx][1] = bounds[2 + j];
195  vertices[idx][0] = bounds[i];
196 
197  double d = plane[0] * vertices[idx][0] + plane[1] * vertices[idx][1] + plane[2] * vertices[idx][2] + plane[3];
198 
199  idx++;
200 
201  // Keep track of closest and farthest point
202  minDistance = (d < minDistance) ? (d) : (minDistance);
203  maxDistance = (d > maxDistance) ? (d) : (maxDistance);
204  }
205  }
206  }
207 
208  int dim[6];
209  this->GetVolumeDimensions(dim);
210 
211  float tCoordOffset[3], tCoordScale[3];
212 
213  tCoordOffset[0] = 0.5 / dim[0];
214  tCoordOffset[1] = 0.5 / dim[1];
215  tCoordOffset[2] = 0.5 / dim[2];
216 
217  tCoordScale[0] = (dim[0] - 1) / static_cast<float>(dim[0]);
218  tCoordScale[1] = (dim[1] - 1) / static_cast<float>(dim[1]);
219  tCoordScale[2] = (dim[2] - 1) / static_cast<float>(dim[2]);
220 
221  float spacing[3];
222  this->GetVolumeSpacing(spacing);
223 
224  double offset = 0.333 * 0.5 * (spacing[0] + spacing[1] + spacing[2]);
225 
226  minDistance += 0.1 * offset;
227  maxDistance -= 0.1 * offset;
228 
229  minDistance = (minDistance < offset) ? (offset) : (minDistance);
230 
231  double stepSize = this->ActualSampleDistance;
232 
233  // Determine the number of polygons
234  int numPolys = static_cast<int>((maxDistance - minDistance) / static_cast<double>(stepSize));
235 
236  // Check if we have space, free old space only if it is too small
237  if (this->BufferSize < numPolys)
238  {
239  delete[] this->PolygonBuffer;
240  delete[] this->IntersectionBuffer;
241 
242  this->BufferSize = numPolys;
243 
244  this->PolygonBuffer = new float[36 * this->BufferSize];
245  this->IntersectionBuffer = new float[12 * this->BufferSize];
246  }
247 
248  this->NumberOfPolygons = numPolys;
249 
250  // Compute the intersection points for each edge of the volume
251  int lines[12][2] = {{0, 1}, {1, 3}, {2, 3}, {0, 2}, {4, 5}, {5, 7}, {6, 7}, {4, 6}, {0, 4}, {1, 5}, {3, 7}, {2, 6}};
252 
253  float *iptr, *pptr;
254 
255  for (i = 0; i < 12; i++)
256  {
257  double line[3];
258 
259  line[0] = vertices[lines[i][1]][0] - vertices[lines[i][0]][0];
260  line[1] = vertices[lines[i][1]][1] - vertices[lines[i][0]][1];
261  line[2] = vertices[lines[i][1]][2] - vertices[lines[i][0]][2];
262 
263  double d = maxDistance;
264 
265  iptr = this->IntersectionBuffer + i;
266 
267  double planeDotLineOrigin = vtkMath::Dot(plane, vertices[lines[i][0]]);
268  double planeDotLine = vtkMath::Dot(plane, line);
269 
270  double t, increment;
271 
272  if (planeDotLine != 0.0)
273  {
274  t = (d - planeDotLineOrigin - plane[3]) / planeDotLine;
275  increment = -stepSize / planeDotLine;
276  }
277  else
278  {
279  t = -1.0;
280  increment = 0.0;
281  }
282 
283  for (j = 0; j < numPolys; j++)
284  {
285  *iptr = (t > 0.0 && t < 1.0) ? (t) : (-1.0);
286 
287  t += increment;
288  iptr += 12;
289  }
290  }
291 
292  // Compute the polygons by determining which edges were intersected
293  int neighborLines[12][6] = {{1, 2, 3, 4, 8, 9},
294  {0, 2, 3, 5, 9, 10},
295  {0, 1, 3, 6, 10, 11},
296  {0, 1, 2, 7, 8, 11},
297  {0, 5, 6, 7, 8, 9},
298  {1, 4, 6, 7, 9, 10},
299  {2, 4, 5, 7, 10, 11},
300  {3, 4, 5, 6, 8, 11},
301  {0, 3, 4, 7, 9, 11},
302  {0, 1, 4, 5, 8, 10},
303  {1, 2, 5, 6, 9, 11},
304  {2, 3, 6, 7, 8, 10}};
305 
306  float tCoord[12][4] = {{0, 0, 0, 0},
307  {1, 0, 0, 1},
308  {0, 1, 0, 0},
309  {0, 0, 0, 1},
310  {0, 0, 1, 0},
311  {1, 0, 1, 1},
312  {0, 1, 1, 0},
313  {0, 0, 1, 1},
314  {0, 0, 0, 2},
315  {1, 0, 0, 2},
316  {1, 1, 0, 2},
317  {0, 1, 0, 2}};
318 
319  double low[3];
320  double high[3];
321 
322  low[0] = (bounds[0] - volBounds[0]) / (volBounds[1] - volBounds[0]);
323  high[0] = (bounds[1] - volBounds[0]) / (volBounds[1] - volBounds[0]);
324  low[1] = (bounds[2] - volBounds[2]) / (volBounds[3] - volBounds[2]);
325  high[1] = (bounds[3] - volBounds[2]) / (volBounds[3] - volBounds[2]);
326  low[2] = (bounds[4] - volBounds[4]) / (volBounds[5] - volBounds[4]);
327  high[2] = (bounds[5] - volBounds[4]) / (volBounds[5] - volBounds[4]);
328 
329  for (i = 0; i < 12; i++)
330  {
331  tCoord[i][0] = (tCoord[i][0]) ? (high[0]) : (low[0]);
332  tCoord[i][1] = (tCoord[i][1]) ? (high[1]) : (low[1]);
333  tCoord[i][2] = (tCoord[i][2]) ? (high[2]) : (low[2]);
334  }
335 
336  iptr = this->IntersectionBuffer;
337  pptr = this->PolygonBuffer;
338 
339  for (i = 0; i < numPolys; i++)
340  {
341  // Look for a starting point
342  int start = 0;
343 
344  while (start < 12 && iptr[start] == -1.0)
345  {
346  start++;
347  }
348 
349  if (start == 12)
350  {
351  pptr[0] = -1.0;
352  }
353  else
354  {
355  int current = start;
356  int previous = -1;
357  int errFlag = 0;
358 
359  idx = 0;
360 
361  while (idx < 6 && !errFlag && (idx == 0 || current != start))
362  {
363  double t = iptr[current];
364 
365  *(pptr + idx * 6) = tCoord[current][0] * tCoordScale[0] + tCoordOffset[0];
366  *(pptr + idx * 6 + 1) = tCoord[current][1] * tCoordScale[1] + tCoordOffset[1];
367  *(pptr + idx * 6 + 2) = tCoord[current][2] * tCoordScale[2] + tCoordOffset[2];
368 
369  int coord = static_cast<int>(tCoord[current][3]);
370  *(pptr + idx * 6 + coord) =
371  (low[coord] + t * (high[coord] - low[coord])) * tCoordScale[coord] + tCoordOffset[coord];
372 
373  *(pptr + idx * 6 + 3) = static_cast<float>(
374  vertices[lines[current][0]][0] + t * (vertices[lines[current][1]][0] - vertices[lines[current][0]][0]));
375 
376  *(pptr + idx * 6 + 4) = static_cast<float>(
377  vertices[lines[current][0]][1] + t * (vertices[lines[current][1]][1] - vertices[lines[current][0]][1]));
378 
379  *(pptr + idx * 6 + 5) = static_cast<float>(
380  vertices[lines[current][0]][2] + t * (vertices[lines[current][1]][2] - vertices[lines[current][0]][2]));
381 
382  idx++;
383 
384  j = 0;
385 
386  while (j < 6 && (*(this->IntersectionBuffer + i * 12 + neighborLines[current][j]) < 0 ||
387  neighborLines[current][j] == previous))
388  {
389  j++;
390  }
391 
392  if (j >= 6)
393  {
394  errFlag = 1;
395  }
396  else
397  {
398  previous = current;
399  current = neighborLines[current][j];
400  }
401  }
402 
403  if (idx < 6)
404  {
405  *(pptr + idx * 6) = -1;
406  }
407  }
408 
409  iptr += 12;
410  pptr += 36;
411  }
412 }
413 
414 void vtkMitkVolumeTextureMapper3D::UpdateMTime()
415 {
416  this->SavedTextureMTime.Modified();
417 }
418 
419 //-----------------------------------------------------------------------------
420 int vtkMitkVolumeTextureMapper3D::UpdateColorLookup(vtkVolume *vol)
421 {
422  // GPU_INFO << "UpdateColorLookup";
423 
424  int needToUpdate = 0;
425 
426  // Get the image data
427  vtkImageData *input = this->GetInput();
428  Update();
429 
430  // Has the volume changed in some way?
431  if (this->SavedParametersInput != input || this->SavedParametersMTime.GetMTime() < input->GetMTime())
432  {
433  needToUpdate = 1;
434  }
435 
436  // What sample distance are we going to use for rendering? If we
437  // have to render quickly according to our allocated render time,
438  // don't necessary obey the sample distance requested by the user.
439  // Instead set the sample distance to the average spacing.
440  this->ActualSampleDistance = this->SampleDistance;
441  if (vol->GetAllocatedRenderTime() < 1.0)
442  {
443  float spacing[3];
444  this->GetVolumeSpacing(spacing);
445  this->ActualSampleDistance =
446  0.333 * (static_cast<double>(spacing[0]) + static_cast<double>(spacing[1]) + static_cast<double>(spacing[2]));
447  }
448 
449  // How many components?
450  int components = input->GetNumberOfScalarComponents();
451 
452  // Has the sample distance changed?
453  if (this->SavedSampleDistance != this->ActualSampleDistance)
454  {
455  needToUpdate = 1;
456  }
457 
458  vtkColorTransferFunction *rgbFunc = nullptr;
459  vtkPiecewiseFunction *grayFunc = nullptr;
460 
461  // How many color channels for this component?
462  int colorChannels = vol->GetProperty()->GetColorChannels(0);
463 
464  if (components < 3)
465  {
466  // Has the number of color channels changed?
467  if (this->SavedColorChannels != colorChannels)
468  {
469  needToUpdate = 1;
470  }
471 
472  // Has the color transfer function changed in some way,
473  // and we are using it?
474  if (colorChannels == 3)
475  {
476  rgbFunc = vol->GetProperty()->GetRGBTransferFunction(0);
477  if (this->SavedRGBFunction != rgbFunc || this->SavedParametersMTime.GetMTime() < rgbFunc->GetMTime())
478  {
479  needToUpdate = 1;
480  }
481  }
482 
483  // Has the gray transfer function changed in some way,
484  // and we are using it?
485  if (colorChannels == 1)
486  {
487  grayFunc = vol->GetProperty()->GetGrayTransferFunction(0);
488  if (this->SavedGrayFunction != grayFunc || this->SavedParametersMTime.GetMTime() < grayFunc->GetMTime())
489  {
490  needToUpdate = 1;
491  }
492  }
493  }
494 
495  // Has the scalar opacity transfer function changed in some way?
496  vtkPiecewiseFunction *scalarOpacityFunc = vol->GetProperty()->GetScalarOpacity(0);
497  if (this->SavedScalarOpacityFunction != scalarOpacityFunc ||
498  this->SavedParametersMTime.GetMTime() < scalarOpacityFunc->GetMTime())
499  {
500  needToUpdate = 1;
501  }
502 
503  // Has the gradient opacity transfer function changed in some way?
504  vtkPiecewiseFunction *gradientOpacityFunc = vol->GetProperty()->GetGradientOpacity(0);
505  if (this->SavedGradientOpacityFunction != gradientOpacityFunc ||
506  this->SavedParametersMTime.GetMTime() < gradientOpacityFunc->GetMTime())
507  {
508  needToUpdate = 1;
509  }
510 
511  double scalarOpacityDistance = vol->GetProperty()->GetScalarOpacityUnitDistance(0);
512  if (this->SavedScalarOpacityDistance != scalarOpacityDistance)
513  {
514  needToUpdate = 1;
515  }
516 
517  // If we have not found any need to update, return now
518  if (!needToUpdate)
519  {
520  return 0;
521  }
522 
523  this->SavedRGBFunction = rgbFunc;
524  this->SavedGrayFunction = grayFunc;
525  this->SavedScalarOpacityFunction = scalarOpacityFunc;
526  this->SavedGradientOpacityFunction = gradientOpacityFunc;
527  this->SavedColorChannels = colorChannels;
528  this->SavedSampleDistance = this->ActualSampleDistance;
529  this->SavedScalarOpacityDistance = scalarOpacityDistance;
530  this->SavedParametersInput = input;
531 
532  this->SavedParametersMTime.Modified();
533 
534  // Find the scalar range
535  double scalarRange[2];
536  input->GetPointData()->GetScalars()->GetRange(scalarRange, components - 1);
537 
538  int arraySizeNeeded = this->ColorTableSize;
539 
540  if (components < 3)
541  {
542  // Sample the transfer functions between the min and max.
543  if (colorChannels == 1)
544  {
545  grayFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->TempArray1);
546  }
547  else
548  {
549  rgbFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->TempArray1);
550  }
551  }
552 
553  scalarOpacityFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->TempArray2);
554 
555  float goArray[256];
556  gradientOpacityFunc->GetTable(0, (scalarRange[1] - scalarRange[0]) * 0.25, 256, goArray);
557 
558  // Correct the opacity array for the spacing between the planes.
559  int i;
560 
561  float *fptr2 = this->TempArray2;
562  double factor = this->ActualSampleDistance / scalarOpacityDistance;
563  for (i = 0; i < arraySizeNeeded; i++)
564  {
565  if (*fptr2 > 0.0001)
566  {
567  *fptr2 = 1.0 - pow(static_cast<double>(1.0 - (*fptr2)), factor);
568  }
569  fptr2++;
570  }
571 
572  int goLoop;
573  unsigned char *ptr, *rgbptr, *aptr;
574  float *fptr1;
575 
576  switch (components)
577  {
578  case 1:
579  // Move the two temp float arrays into one RGBA unsigned char array
580  ptr = this->ColorLookup;
581  for (goLoop = 0; goLoop < 256; goLoop++)
582  {
583  fptr1 = this->TempArray1;
584  fptr2 = this->TempArray2;
585  if (colorChannels == 1)
586  {
587  for (i = 0; i < arraySizeNeeded; i++)
588  {
589  *(ptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
590  *(ptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
591  *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
592  *(ptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
593  }
594  }
595  else
596  {
597  for (i = 0; i < arraySizeNeeded; i++)
598  {
599  *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
600  *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
601  *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
602  *(ptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
603  }
604  }
605 
606  for (; i < 256; i++)
607  {
608  *(ptr++) = 0;
609  *(ptr++) = 0;
610  *(ptr++) = 0;
611  *(ptr++) = 0;
612  }
613  }
614  break;
615 
616  case 2:
617  // Move the two temp float arrays into one RGB unsigned char array and
618  // one alpha array.
619  rgbptr = this->ColorLookup;
620  aptr = this->AlphaLookup;
621 
622  if (colorChannels == 1)
623  {
624  for (i = 0; i < arraySizeNeeded; i++)
625  {
626  fptr1 = this->TempArray1;
627  fptr2 = this->TempArray2;
628  for (goLoop = 0; goLoop < 256; goLoop++)
629  {
630  *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
631  *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
632  *(rgbptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
633  *(aptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
634  }
635  }
636  }
637  else
638  {
639  fptr1 = this->TempArray1;
640  fptr2 = this->TempArray2;
641  for (i = 0; i < arraySizeNeeded; i++)
642  {
643  for (goLoop = 0; goLoop < 256; goLoop++)
644  {
645  *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
646  *(rgbptr++) = static_cast<unsigned char>(*(fptr1 + 1) * 255.0 + 0.5);
647  *(rgbptr++) = static_cast<unsigned char>(*(fptr1 + 2) * 255.0 + 0.5);
648  *(aptr++) = static_cast<unsigned char>(*(fptr2)*goArray[goLoop] * 255.0 + 0.5);
649  }
650  fptr1 += 3;
651  fptr2++;
652  }
653  }
654 
655  for (; i < 256; i++)
656  {
657  for (goLoop = 0; goLoop < 256; goLoop++)
658  {
659  *(rgbptr++) = 0;
660  *(rgbptr++) = 0;
661  *(rgbptr++) = 0;
662  *(aptr++) = 0;
663  }
664  }
665  break;
666 
667  case 3:
668  case 4:
669  // Move the two temp float arrays into one alpha array
670  aptr = this->AlphaLookup;
671 
672  for (goLoop = 0; goLoop < 256; goLoop++)
673  {
674  fptr2 = this->TempArray2;
675  for (i = 0; i < arraySizeNeeded; i++)
676  {
677  *(aptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
678  }
679  for (; i < 256; i++)
680  {
681  *(aptr++) = 0;
682  }
683  }
684 
685  break;
686  }
687  return 1;
688 }
689 
690 //-----------------------------------------------------------------------------
691 // Print the vtkMitkVolumeTextureMapper3D
692 void vtkMitkVolumeTextureMapper3D::PrintSelf(ostream &os, vtkIndent indent)
693 {
694  this->Superclass::PrintSelf(os, indent);
695 
696  os << indent << "Sample Distance: " << this->SampleDistance << endl;
697  os << indent << "NumberOfPolygons: " << this->NumberOfPolygons << endl;
698  os << indent << "ActualSampleDistance: " << this->ActualSampleDistance << endl;
699  os << indent << "VolumeDimensions: " << this->VolumeDimensions[0] << " " << this->VolumeDimensions[1] << " "
700  << this->VolumeDimensions[2] << endl;
701  os << indent << "VolumeSpacing: " << this->VolumeSpacing[0] << " " << this->VolumeSpacing[1] << " "
702  << this->VolumeSpacing[2] << endl;
703 
704  os << indent << "UseCompressedTexture: " << this->UseCompressedTexture << endl;
705 }
static char * line
Definition: svm.cpp:2870
float k(1.0)
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:31
static Vector3D offset
vtkInstantiatorNewMacro(vtkMitkVolumeTextureMapper3D)
void Normalize(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer im2, mitk::Image::Pointer mask1, std::string output)
Definition: CLBrainMask.cpp:36