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

Method ComputeMatrices

Rendering/Volume/vtkFixedPointVolumeRayCastMapper.cxx:2267–2331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2265}
2266
2267void vtkFixedPointVolumeRayCastMapper::ComputeMatrices(double inputOrigin[3],
2268 double inputSpacing[3], int inputExtent[6], vtkRenderer* ren, vtkVolume* vol)
2269{
2270 // Get the camera from the renderer
2271 vtkCamera* cam = ren->GetActiveCamera();
2272
2273 // Get the aspect ratio from the renderer. This is needed for the
2274 // computation of the perspective matrix
2275 ren->ComputeAspect();
2276 double* aspect = ren->GetAspect();
2277
2278 // Keep track of the projection matrix - we'll need it in a couple of places
2279 // Get the projection matrix. The method is called perspective, but
2280 // the matrix is valid for perspective and parallel viewing transforms.
2281 // Don't replace this with the GetCompositePerspectiveTransformMatrix
2282 // because that turns off stereo rendering!!!
2283 this->PerspectiveTransform->Identity();
2284 this->PerspectiveTransform->Concatenate(
2285 cam->GetProjectionTransformMatrix(aspect[0] / aspect[1], 0.0, 1.0));
2286 this->PerspectiveTransform->Concatenate(cam->GetViewTransformMatrix());
2287 this->PerspectiveMatrix->DeepCopy(this->PerspectiveTransform->GetMatrix());
2288
2289 // Compute the origin of the extent the volume origin is at voxel (0,0,0)
2290 // but we want to consider (0,0,0) in voxels to be at
2291 // (inputExtent[0], inputExtent[2], inputExtent[4]).
2292 double extentOrigin[3];
2293 extentOrigin[0] = inputOrigin[0] + inputExtent[0] * inputSpacing[0];
2294 extentOrigin[1] = inputOrigin[1] + inputExtent[2] * inputSpacing[1];
2295 extentOrigin[2] = inputOrigin[2] + inputExtent[4] * inputSpacing[2];
2296
2297 // Get the volume matrix. This is a volume to world matrix right now.
2298 // We'll need to invert it, translate by the origin and scale by the
2299 // spacing to change it to a world to voxels matrix.
2300 vol->GetModelToWorldMatrix(this->VolumeMatrix);
2301
2302 this->VoxelsToViewTransform->SetMatrix(this->VolumeMatrix);
2303
2304 // Create a transform that will account for the scaling and translation of
2305 // the scalar data. The is the volume to voxels matrix.
2306 this->VoxelsTransform->Identity();
2307 this->VoxelsTransform->Translate(extentOrigin[0], extentOrigin[1], extentOrigin[2]);
2308
2309 this->VoxelsTransform->Scale(inputSpacing[0], inputSpacing[1], inputSpacing[2]);
2310
2311 // Now concatenate the volume's matrix with this scalar data matrix
2312 this->VoxelsToViewTransform->PreMultiply();
2313 this->VoxelsToViewTransform->Concatenate(this->VoxelsTransform->GetMatrix());
2314
2315 // Now we actually have the world to voxels matrix - copy it out
2316 this->WorldToVoxelsMatrix->DeepCopy(this->VoxelsToViewTransform->GetMatrix());
2317 this->WorldToVoxelsMatrix->Invert();
2318
2319 // We also want to invert this to get voxels to world
2320 this->VoxelsToWorldMatrix->DeepCopy(this->VoxelsToViewTransform->GetMatrix());
2321
2322 // Compute the voxels to view transform by concatenating the
2323 // voxels to world matrix with the projection matrix (world to view)
2324 this->VoxelsToViewTransform->PostMultiply();

Callers 2

Calls 13

GetActiveCameraMethod · 0.80
ComputeAspectMethod · 0.80
GetModelToWorldMatrixMethod · 0.80
IdentityMethod · 0.45
ConcatenateMethod · 0.45
DeepCopyMethod · 0.45
GetMatrixMethod · 0.45
SetMatrixMethod · 0.45
TranslateMethod · 0.45
ScaleMethod · 0.45

Tested by

no test coverage detected