20 #define GPU_INFO MITK_INFO("mapper.vr")
21 #define GPU_WARN MITK_WARN("mapper.vr")
23 #include "vtkCamera.h"
24 #include "vtkColorTransferFunction.h"
25 #include "vtkDataArray.h"
26 #include "vtkImageData.h"
28 #include "vtkMatrix4x4.h"
29 #include "vtkPiecewiseFunction.h"
30 #include "vtkPointData.h"
31 #include "vtkRenderer.h"
32 #include "vtkVolume.h"
33 #include "vtkVolumeProperty.h"
120 double focalPoint[4], position[4];
122 vtkCamera *camera = ren->GetActiveCamera();
124 camera->GetPosition(position);
125 camera->GetFocalPoint(focalPoint);
138 vol->GetMatrix(matrix);
140 matrix->MultiplyPoint(position, position);
141 matrix->MultiplyPoint(focalPoint, focalPoint);
146 position[0] /= position[3];
147 position[1] /= position[3];
148 position[2] /= position[3];
153 focalPoint[0] /= focalPoint[3];
154 focalPoint[1] /= focalPoint[3];
155 focalPoint[2] /= focalPoint[3];
159 plane[0] = focalPoint[0] - position[0];
160 plane[1] = focalPoint[1] - position[1];
161 plane[2] = focalPoint[2] - position[2];
165 plane[3] = -(plane[0] * position[0] + plane[1] * position[1] + plane[2] * position[2]);
168 double minDistance = VTK_DOUBLE_MAX;
169 double maxDistance = VTK_DOUBLE_MIN;
175 this->GetInput()->GetBounds(volBounds);
178 bounds[0] = (inBounds[0] > volBounds[0]) ? (inBounds[0]) : (volBounds[0]);
179 bounds[1] = (inBounds[1] < volBounds[1]) ? (inBounds[1]) : (volBounds[1]);
180 bounds[2] = (inBounds[2] > volBounds[2]) ? (inBounds[2]) : (volBounds[2]);
181 bounds[3] = (inBounds[3] < volBounds[3]) ? (inBounds[3]) : (volBounds[3]);
182 bounds[4] = (inBounds[4] > volBounds[4]) ? (inBounds[4]) : (volBounds[4]);
183 bounds[5] = (inBounds[5] < volBounds[5]) ? (inBounds[5]) : (volBounds[5]);
187 double vertices[8][3];
191 for (k = 0; k < 2; k++)
193 for (j = 0; j < 2; j++)
195 for (i = 0; i < 2; i++)
197 vertices[idx][2] = bounds[4 + k];
198 vertices[idx][1] = bounds[2 + j];
199 vertices[idx][0] = bounds[i];
201 double d = plane[0] * vertices[idx][0] + plane[1] * vertices[idx][1] + plane[2] * vertices[idx][2] + plane[3];
206 minDistance = (d < minDistance) ? (d) : (minDistance);
207 maxDistance = (d > maxDistance) ? (d) : (maxDistance);
213 this->GetVolumeDimensions(dim);
215 float tCoordOffset[3], tCoordScale[3];
217 tCoordOffset[0] = 0.5 / dim[0];
218 tCoordOffset[1] = 0.5 / dim[1];
219 tCoordOffset[2] = 0.5 / dim[2];
221 tCoordScale[0] = (dim[0] - 1) / static_cast<float>(dim[0]);
222 tCoordScale[1] = (dim[1] - 1) / static_cast<float>(dim[1]);
223 tCoordScale[2] = (dim[2] - 1) / static_cast<float>(dim[2]);
226 this->GetVolumeSpacing(spacing);
228 double offset = 0.333 * 0.5 * (spacing[0] + spacing[1] + spacing[2]);
230 minDistance += 0.1 *
offset;
231 maxDistance -= 0.1 *
offset;
233 minDistance = (minDistance <
offset) ? (offset) : (minDistance);
238 int numPolys =
static_cast<int>((maxDistance - minDistance) / static_cast<double>(stepSize));
255 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}};
259 for (i = 0; i < 12; i++)
263 line[0] = vertices[lines[i][1]][0] - vertices[lines[i][0]][0];
264 line[1] = vertices[lines[i][1]][1] - vertices[lines[i][0]][1];
265 line[2] = vertices[lines[i][1]][2] - vertices[lines[i][0]][2];
267 double d = maxDistance;
271 double planeDotLineOrigin = vtkMath::Dot(plane, vertices[lines[i][0]]);
272 double planeDotLine = vtkMath::Dot(plane, line);
276 if (planeDotLine != 0.0)
278 t = (d - planeDotLineOrigin - plane[3]) / planeDotLine;
279 increment = -stepSize / planeDotLine;
287 for (j = 0; j < numPolys; j++)
289 *iptr = (t > 0.0 && t < 1.0) ? (t) : (-1.0);
297 int neighborLines[12][6] = {{1, 2, 3, 4, 8, 9},
299 {0, 1, 3, 6, 10, 11},
303 {2, 4, 5, 7, 10, 11},
308 {2, 3, 6, 7, 8, 10}};
310 float tCoord[12][4] = {{0, 0, 0, 0},
326 low[0] = (bounds[0] - volBounds[0]) / (volBounds[1] - volBounds[0]);
327 high[0] = (bounds[1] - volBounds[0]) / (volBounds[1] - volBounds[0]);
328 low[1] = (bounds[2] - volBounds[2]) / (volBounds[3] - volBounds[2]);
329 high[1] = (bounds[3] - volBounds[2]) / (volBounds[3] - volBounds[2]);
330 low[2] = (bounds[4] - volBounds[4]) / (volBounds[5] - volBounds[4]);
331 high[2] = (bounds[5] - volBounds[4]) / (volBounds[5] - volBounds[4]);
333 for (i = 0; i < 12; i++)
335 tCoord[i][0] = (tCoord[i][0]) ? (high[0]) : (low[0]);
336 tCoord[i][1] = (tCoord[i][1]) ? (high[1]) : (low[1]);
337 tCoord[i][2] = (tCoord[i][2]) ? (high[2]) : (low[2]);
343 for (i = 0; i < numPolys; i++)
348 while (start < 12 && iptr[start] == -1.0)
365 while (idx < 6 && !errFlag && (idx == 0 || current != start))
367 double t = iptr[current];
369 *(pptr + idx * 6) = tCoord[current][0] * tCoordScale[0] + tCoordOffset[0];
370 *(pptr + idx * 6 + 1) = tCoord[current][1] * tCoordScale[1] + tCoordOffset[1];
371 *(pptr + idx * 6 + 2) = tCoord[current][2] * tCoordScale[2] + tCoordOffset[2];
373 int coord =
static_cast<int>(tCoord[current][3]);
374 *(pptr + idx * 6 + coord) =
375 (low[coord] + t * (high[coord] - low[coord])) * tCoordScale[coord] + tCoordOffset[coord];
377 *(pptr + idx * 6 + 3) = static_cast<float>(
378 vertices[lines[current][0]][0] + t * (vertices[lines[current][1]][0] - vertices[lines[current][0]][0]));
380 *(pptr + idx * 6 + 4) = static_cast<float>(
381 vertices[lines[current][0]][1] + t * (vertices[lines[current][1]][1] - vertices[lines[current][0]][1]));
383 *(pptr + idx * 6 + 5) = static_cast<float>(
384 vertices[lines[current][0]][2] + t * (vertices[lines[current][1]][2] - vertices[lines[current][0]][2]));
390 while (j < 6 && (*(this->
IntersectionBuffer + i * 12 + neighborLines[current][j]) < 0 ||
391 neighborLines[current][j] == previous))
403 current = neighborLines[current][j];
409 *(pptr + idx * 6) = -1;
428 int needToUpdate = 0;
431 vtkImageData *input = this->GetInput();
445 if (vol->GetAllocatedRenderTime() < 1.0)
448 this->GetVolumeSpacing(spacing);
450 0.333 * (
static_cast<double>(spacing[0]) + static_cast<double>(spacing[1]) +
static_cast<double>(spacing[2]));
454 int components = input->GetNumberOfScalarComponents();
462 vtkColorTransferFunction *rgbFunc =
nullptr;
463 vtkPiecewiseFunction *grayFunc =
nullptr;
466 int colorChannels = vol->GetProperty()->GetColorChannels(0);
478 if (colorChannels == 3)
480 rgbFunc = vol->GetProperty()->GetRGBTransferFunction(0);
489 if (colorChannels == 1)
491 grayFunc = vol->GetProperty()->GetGrayTransferFunction(0);
500 vtkPiecewiseFunction *scalarOpacityFunc = vol->GetProperty()->GetScalarOpacity(0);
508 vtkPiecewiseFunction *gradientOpacityFunc = vol->GetProperty()->GetGradientOpacity(0);
515 double scalarOpacityDistance = vol->GetProperty()->GetScalarOpacityUnitDistance(0);
539 double scalarRange[2];
540 input->GetPointData()->GetScalars()->GetRange(scalarRange, components - 1);
547 if (colorChannels == 1)
549 grayFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->
TempArray1);
553 rgbFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->
TempArray1);
557 scalarOpacityFunc->GetTable(scalarRange[0], scalarRange[1], arraySizeNeeded, this->
TempArray2);
560 gradientOpacityFunc->GetTable(0, (scalarRange[1] - scalarRange[0]) * 0.25, 256, goArray);
567 for (i = 0; i < arraySizeNeeded; i++)
571 *fptr2 = 1.0 - pow(static_cast<double>(1.0 - (*fptr2)), factor);
577 unsigned char *ptr, *rgbptr, *aptr;
585 for (goLoop = 0; goLoop < 256; goLoop++)
589 if (colorChannels == 1)
591 for (i = 0; i < arraySizeNeeded; i++)
593 *(ptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
594 *(ptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
595 *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
596 *(ptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
601 for (i = 0; i < arraySizeNeeded; i++)
603 *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
604 *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
605 *(ptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
606 *(ptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
626 if (colorChannels == 1)
628 for (i = 0; i < arraySizeNeeded; i++)
632 for (goLoop = 0; goLoop < 256; goLoop++)
634 *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
635 *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
636 *(rgbptr++) = static_cast<unsigned char>(*(fptr1++) * 255.0 + 0.5);
637 *(aptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
645 for (i = 0; i < arraySizeNeeded; i++)
647 for (goLoop = 0; goLoop < 256; goLoop++)
649 *(rgbptr++) = static_cast<unsigned char>(*(fptr1)*255.0 + 0.5);
650 *(rgbptr++) = static_cast<unsigned char>(*(fptr1 + 1) * 255.0 + 0.5);
651 *(rgbptr++) = static_cast<unsigned char>(*(fptr1 + 2) * 255.0 + 0.5);
652 *(aptr++) = static_cast<unsigned char>(*(fptr2)*goArray[goLoop] * 255.0 + 0.5);
661 for (goLoop = 0; goLoop < 256; goLoop++)
676 for (goLoop = 0; goLoop < 256; goLoop++)
679 for (i = 0; i < arraySizeNeeded; i++)
681 *(aptr++) = static_cast<unsigned char>(*(fptr2++) * goArray[goLoop] * 255.0 + 0.5);
698 this->Superclass::PrintSelf(os, indent);
700 os << indent <<
"Sample Distance: " << this->
SampleDistance << endl;
bool SupportsNonPowerOfTwoTextures
vtkTimeStamp SavedParametersMTime
static void Update(vtkPolyData *)
float ActualSampleDistance
vtkColorTransferFunction * SavedRGBFunction
void ComputePolygons(vtkRenderer *ren, vtkVolume *vol, double bounds[6])
~vtkMitkVolumeTextureMapper3D()
float TempArray1[3 *4096]
vtkImageData * SavedTextureInput
vtkTimeStamp SavedTextureMTime
vtkMitkVolumeTextureMapper3D()
vtkPiecewiseFunction * SavedGrayFunction
vtkInstantiatorNewMacro(vtkMitkVolumeTextureMapper3D)
int UpdateColorLookup(vtkVolume *)
float SavedScalarOpacityDistance
float * IntersectionBuffer
unsigned char ColorLookup[65536 *4]
void Normalize(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer im2, mitk::Image::Pointer mask1, std::string output)
bool UseCompressedTexture
vtkImageData * SavedParametersInput
unsigned char AlphaLookup[65536]
vtkPiecewiseFunction * SavedGradientOpacityFunction
vtkPiecewiseFunction * SavedScalarOpacityFunction
void PrintSelf(ostream &os, vtkIndent indent) override
float SavedSampleDistance
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.