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

Method UpdatePolygonCoords

Rendering/Image/vtkImageResliceMapper.cxx:1200–1466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1198#define VTK_IRM_MAX_VERTS 32
1199#define VTK_IRM_MAX_COORDS 96
1200void vtkImageResliceMapper::UpdatePolygonCoords(vtkRenderer* ren)
1201{
1202 // Get the projection matrix
1203 double aspect = ren->GetTiledAspectRatio();
1204 vtkCamera* camera = ren->GetActiveCamera();
1205 vtkMatrix4x4* viewMatrix = camera->GetViewTransformMatrix();
1206 vtkMatrix4x4* projMatrix = camera->GetProjectionTransformMatrix(aspect, 0, 1);
1207
1208 // Compute other useful matrices
1209 double worldToView[16];
1210 double viewToWorld[16];
1211 vtkMatrix4x4::Multiply4x4(*projMatrix->Element, *viewMatrix->Element, worldToView);
1212 vtkMatrix4x4::Invert(worldToView, viewToWorld);
1213
1214 // Get slice plane in world coords by passing null as the matrix
1215 double plane[4];
1216 this->GetSlicePlaneInDataCoords(nullptr, plane);
1217
1218 // Check whether normal is facing towards camera, the "ndop" is
1219 // the negative of the direction of projection for the camera
1220 double* ndop = viewMatrix->Element[2];
1221 if (vtkMath::Dot(ndop, plane) < 0)
1222 {
1223 plane[0] = -plane[0];
1224 plane[1] = -plane[1];
1225 plane[2] = -plane[2];
1226 plane[3] = -plane[3];
1227 }
1228
1229 // Get the z position of the slice in slice coords
1230 // (requires plane to be normalized by GetSlicePlaneInDataCoords)
1231 double z = (plane[2] - 2.0) * plane[3];
1232
1233 // Generate a tolerance based on the screen pixel size
1234 double fpoint[4];
1235 camera->GetFocalPoint(fpoint);
1236 fpoint[3] = 1.0;
1237 vtkMatrix4x4::MultiplyPoint(worldToView, fpoint, fpoint);
1238 fpoint[0] /= fpoint[3];
1239 fpoint[1] /= fpoint[3];
1240 fpoint[2] /= fpoint[3];
1241 fpoint[3] = 1.0;
1242
1243 double topOfScreen[4], botOfScreen[4];
1244 fpoint[1] -= 1.0;
1245 vtkMatrix4x4::MultiplyPoint(viewToWorld, fpoint, topOfScreen);
1246 fpoint[1] += 2.0;
1247 vtkMatrix4x4::MultiplyPoint(viewToWorld, fpoint, botOfScreen);
1248
1249 topOfScreen[0] /= topOfScreen[3];
1250 topOfScreen[1] /= topOfScreen[3];
1251 topOfScreen[2] /= topOfScreen[3];
1252 topOfScreen[3] = 1.0;
1253
1254 botOfScreen[0] /= botOfScreen[3];
1255 botOfScreen[1] /= botOfScreen[3];
1256 botOfScreen[2] /= botOfScreen[3];
1257 botOfScreen[3] = 1.0;

Callers 1

ProcessRequestMethod · 0.95

Calls 15

GetTiledAspectRatioMethod · 0.80
GetActiveCameraMethod · 0.80
DeleteMethod · 0.65
InvertFunction · 0.50
DotFunction · 0.50
MultiplyPointFunction · 0.50
sqrtFunction · 0.50
AddFunction · 0.50
NewFunction · 0.50

Tested by

no test coverage detected