[vtkusers] 2D mapping very slow
Dirk Schmedding
dirk.schmedding at zn-ag.com
Thu May 6 05:40:16 EDT 2004
Hi at all,
I have a problem using 2D mapping.
A volume with 3 axis-oriented planes are each mapped to 2D view renderer.
One rendering process takes averaged 2sec at all.
Much too slow for in my opinion.
If I remove the 2D renderer parts the rendering process only takes 0.1 sec.
After some tests I located the problem in the 2D mapping.
I don't know how to optimize the mechanism.
Any suggestions?
greets & thanks
dirk
<snipp>
[...]
//define plane 1
ZNfloat plane1OriginL[3] = { xMinM, yMaxM, zMinM };
ZNfloat plane1Point1L[3] = { xMaxM, yMaxM, zMinM };
ZNfloat plane1Point2L[3] = { xMinM, yMinM, zMinM };
plane1SourceM = vtkPlaneSource::New();
plane1SourceM->SetOrigin(plane1OriginL);
plane1SourceM->SetPoint1(plane1Point1L);
plane1SourceM->SetPoint2(plane1Point2L);
//transform object for reslicer (needed to update texture if plane is
moved)
resliceTransformPlane1M = vtkTransform::New();
resliceTransformPlane1M->Identity();
//Reslicer for plane 1
plane1ReslicerM = vtkImageReslice::New();
plane1ReslicerM->SetInput(imageDataM);
plane1ReslicerM->WrapOff();
plane1ReslicerM->SetOutputDimensionality(2);
plane1ReslicerM->SetResliceTransform(resliceTransformPlane1M);
plane1ReslicerM->SetInterpolationModeToCubic();
plane1ReslicerM->SetResliceAxesDirectionCosines( 1, 0, 0,
0, -1, 0,
0, 0, -1);
plane1ReslicerM->SetResliceAxesOrigin( xMinM, yMaxM, zMinM );
plane1ReslicerM->SetOutputExtent(0, xRangeM, 0, yRangeM, 0, 0);
plane1ReslicerM->SetOutputOrigin(0,0,0);
plane1ReslicerM->SetOutputSpacing(1,1,1);
//transform object for plane 1 (needed to move the plane)
transformPlane1M = vtkTransform::New();
transformPlane1M->Identity();
//transform filter for plane 1 (needed to apply transform to plane)
transformFilterPlane1M = vtkTransformPolyDataFilter::New();
transformFilterPlane1M->SetInput(plane1SourceM->GetOutput());
transformFilterPlane1M->SetTransform(transformPlane1M);
//Outline arround plane
outlineFilterPlane1M = vtkOutlineFilter::New();
outlineFilterPlane1M->SetInput(transformFilterPlane1M->GetOutput());
outlineMapperPlane1M = vtkPolyDataMapper::New();
outlineMapperPlane1M->SetInput(outlineFilterPlane1M->GetOutput());
outlineActorPlane1M = vtkActor::New();
outlineActorPlane1M->SetMapper( outlineMapperPlane1M );
outlineActorPlane1M->GetProperty()->SetColor( color1M );
//create texture which will be mapped to plane
vtkTexture* plane1TextureL = vtkTexture::New();
plane1TextureL->SetInput(plane1ReslicerM->GetOutput());
plane1TextureL->SetLookupTable(windowLevelLookupTableM);
plane1TextureL->InterpolateOn();
//3D mapper for plane 1
vtkPolyDataMapper* plane1MapperL = vtkPolyDataMapper::New();
plane1MapperL->SetInput(transformFilterPlane1M->GetOutput());
plane1MapperL->SetLookupTable(windowLevelLookupTableM);
//3D actor for plane 1
vtkActor* plane1actorL = vtkActor::New();
plane1actorL->SetMapper(plane1MapperL);
plane1actorL->SetTexture(plane1TextureL);
plane1actorL->GetProperty()->SetOpacity(1.0);
//scale image to match to 2d view
vtkImageResample* plane1ResampleM = vtkImageResample::New();
plane1ResampleM->SetInput(plane1ReslicerM->GetOutput());
plane1ResampleM->SetDimensionality(2);
plane1ResampleM->SetAxisMagnificationFactor(0,planeScaleFactorM);
plane1ResampleM->SetAxisMagnificationFactor(1,planeScaleFactorM);
plane1ResampleM->SetInterpolationModeToCubic();
//create mapper which knows how to render plane in 2D view
plane1ImageMapperM = vtkImageMapper::New();
plane1ImageMapperM->SetInput(plane1ResampleM->GetOutput());
plane1ImageMapperM->SetColorLevel ( windowLevelM );
plane1ImageMapperM->SetColorWindow ( windowWidthM );
//create actor for 2D view
plane1ImageActorM = vtkActor2D::New();
plane1ImageActorM->SetMapper(plane1ImageMapperM);
//Outline arround 2D image
plane1OutlineSource2DM = vtkOutlineSource::New();
plane1OutlineSource2DM->SetBounds(0,viewportSizeM-1,0,viewportSizeM-1,0,0);
plane1OutlineMapper2DM = vtkPolyDataMapper2D::New();
plane1OutlineMapper2DM->SetInput(plane1OutlineSource2DM->GetOutput());
plane1OutlineActor2DM = vtkActor2D::New();
plane1OutlineActor2DM->SetMapper( plane1OutlineMapper2DM );
plane1OutlineActor2DM->GetProperty()->SetColor( color1M );
//add 2D actor to 2D renderer
plane1RendererM = vtkRenderer::New();
plane1RendererM->SetViewport(0.5, 0.5, 1.0, 1.0);
plane1RendererM->SetBackground( color1M );
plane1RendererM->InteractiveOff();
plane1RendererM->AddActor(plane1ImageActorM);
plane1RendererM->AddActor2D(plane1OutlineActor2DM);
[...]
//connect all renderers to rendererwindow
rendererWindowM->AddRenderer(rendererM);
rendererWindowM->AddRenderer(plane1RendererM);
rendererWindowM->AddRenderer(plane2RendererM);
rendererWindowM->AddRenderer(plane3RendererM);
[...]
</snapp>
More information about the vtkusers
mailing list