MCPcopy Create free account
hub / github.com/Kitware/VTK / IsCameraInside

Method IsCameraInside

Rendering/VolumeOpenGL2/vtkOpenGLGPUVolumeRayCastMapper.cxx:1015–1067  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1013
1014//------------------------------------------------------------------------------
1015bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::IsCameraInside(
1016 vtkRenderer* ren, vtkVolume* vol, double geometry[24])
1017{
1018 vtkNew<vtkMatrix4x4> dataToWorld;
1019 vol->GetModelToWorldMatrix(dataToWorld);
1020
1021 vtkCamera* cam = ren->GetActiveCamera();
1022
1023 double planes[24];
1024 cam->GetFrustumPlanes(ren->GetTiledAspectRatio(), planes);
1025
1026 // convert geometry to world then compare to frustum planes
1027 double in[4];
1028 in[3] = 1.0;
1029 double out[4];
1030 double worldGeometry[24];
1031 for (int i = 0; i < 8; ++i)
1032 {
1033 in[0] = geometry[i * 3];
1034 in[1] = geometry[i * 3 + 1];
1035 in[2] = geometry[i * 3 + 2];
1036 dataToWorld->MultiplyPoint(in, out);
1037 worldGeometry[i * 3] = out[0] / out[3];
1038 worldGeometry[i * 3 + 1] = out[1] / out[3];
1039 worldGeometry[i * 3 + 2] = out[2] / out[3];
1040 }
1041
1042 // does the front clipping plane intersect the volume?
1043 // true if points are on both sides of the plane
1044 bool hasPositive = false;
1045 bool hasNegative = false;
1046 bool hasZero = false;
1047 for (int i = 0; i < 8; ++i)
1048 {
1049 double val = planes[4 * 4] * worldGeometry[i * 3] +
1050 planes[4 * 4 + 1] * worldGeometry[i * 3 + 1] + planes[4 * 4 + 2] * worldGeometry[i * 3 + 2] +
1051 planes[4 * 4 + 3];
1052 if (val < 0)
1053 {
1054 hasNegative = true;
1055 }
1056 else if (val > 0)
1057 {
1058 hasPositive = true;
1059 }
1060 else
1061 {
1062 hasZero = true;
1063 }
1064 }
1065
1066 return hasZero || (hasNegative && hasPositive);
1067}
1068
1069//------------------------------------------------------------------------------
1070bool vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::IsGeometryUpdateRequired(

Callers 2

RenderVolumeGeometryMethod · 0.95

Calls 5

GetModelToWorldMatrixMethod · 0.80
GetActiveCameraMethod · 0.80
GetFrustumPlanesMethod · 0.80
GetTiledAspectRatioMethod · 0.80
MultiplyPointMethod · 0.45

Tested by

no test coverage detected