[vtkusers] VTK 6.3 OpenGL2 - vtkTextActor blurred text when used with vtkFixedPointVolumeRayCastMapper
Simon ESNEAULT
simon.esneault at gmail.com
Fri Nov 13 10:43:38 EST 2015
Hi All,
All vtkTextActor are rendered blurred when using with
vtkFixedPointVolumeRayCastMapper in the same renderer in vtk 6.3 with the
new rendering backend.
Here are some snapshots :
- OpenGL1 <http://picpaste.com/pics/OGL1-not-blurred.1447428990.png>
- OpenGL2 <http://picpaste.com/pics/OGL2-blurred.1447429027.png>
Attached some code that reproduces the problem, to be used with this
<https://www.dropbox.com/s/ptqwi0ebv75kt35/volume.zip> volume. Visible on
OSX and Windows to our knowledge, probably on more OS.
The text is rendered properly when used with the old backend or when using
a vtkGPUVolumeRayCastMapper instead of the vtkFixedPointVolumeRayCastMapper.
Shall I feel a bug, is this a known issue ?
Thanks,
Simon
--
------------------------------------------------------------------
Simon Esneault
Rennes, France
------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151113/954732cb/attachment.html>
-------------- next part --------------
#include "vtkCallbackCommand.h"
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkImageData.h"
#include "vtkImageResample.h"
#include "vtkInteractorStyle.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkMath.h"
#include "vtkMetaImageReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
int main( int argc, char *argv[] ){
// Read volume
vtkMetaImageReader* l_reader = vtkMetaImageReader::New();
l_reader->SetFileName( "volume.mhd" );
l_reader->Update();
// reduce to 10 Megavoxels
double l_ratio = std::pow( 10000000. / l_reader->GetOutput()->GetNumberOfPoints(), 1. / 3. );
vtkImageResample* l_resample = vtkImageResample::New();
l_resample->SetInputConnection( l_reader->GetOutputPort() );
l_resample->SetInterpolationModeToLinear();
for( int i = 0; i < 3; i++ )
l_resample->SetAxisMagnificationFactor( i, l_ratio );
// Setup rendering stuff
vtkRenderer* l_renderer = vtkRenderer::New();
l_renderer->SetBackground( 0.3, 0.3, 0.3 );
vtkRenderWindow* l_render_windows = vtkRenderWindow::New();
l_render_windows->AddRenderer( l_renderer );
l_render_windows->SetSize( 900, 900 );
vtkInteractorStyleTrackballCamera* l_trackball = vtkInteractorStyleTrackballCamera::New();
vtkRenderWindowInteractor* l_iren = vtkRenderWindowInteractor::New();
l_iren->SetInteractorStyle( l_trackball );
l_iren->SetRenderWindow( l_render_windows );
l_iren->GetInteractorStyle()->SetDefaultRenderer( l_renderer );
// Make sure we have an opengl context
l_render_windows->Render();
// Setup GPU volume raycast mapper
vtkFixedPointVolumeRayCastMapper* l_gpu_mapper = vtkFixedPointVolumeRayCastMapper::New();
l_gpu_mapper->SetInputConnection( l_resample->GetOutputPort() );
// Setup Volume property
double wl = 260;
double ww = 270;
// Color function
vtkColorTransferFunction* l_color = vtkColorTransferFunction::New();
l_color->SetColorSpaceToRGB();
l_color->AddRGBPoint( wl - ww / 2, 0, 0, 0 );
l_color->AddRGBPoint( wl - ww / 2 + 94 * ( ww / 255.0 ), 1., 21. / 255.0, 27. / 255.0 );
l_color->AddRGBPoint( wl - ww / 2 + 147 * ( ww / 255.0 ), 1., 176. / 255.0, 9. / 255.0 );
l_color->AddRGBPoint( wl - ww / 2 + 201 * ( ww / 255.0 ), 1., 241. / 255.0, 39. / 255.0 );
l_color->AddRGBPoint( wl - ww / 2 + 255 * ( ww / 255.0 ), 1, 1, 1. );
l_color->Build();
// Opacity function
vtkPiecewiseFunction* l_opacity = vtkPiecewiseFunction::New();
l_opacity->AddPoint( wl - ww / 2, 0 );
l_opacity->AddPoint( wl + ww / 2, 1 );
// Volume property, light, shading
vtkVolumeProperty* l_volume_property = vtkVolumeProperty::New();
l_volume_property->SetColor( l_color );
l_volume_property->SetScalarOpacity( l_opacity );
l_volume_property->SetInterpolationTypeToLinear();
l_volume_property->ShadeOn();
l_volume_property->SetDiffuse( 0.8 );
// Put everything together
vtkVolume* l_volume = vtkVolume::New();
l_volume->SetProperty( l_volume_property );
l_volume->SetMapper( l_gpu_mapper );
// setup text actor :
vtkTextActor* l_text_actor = vtkTextActor::New();
l_text_actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
l_text_actor->GetPositionCoordinate()->SetValue( 0.01, 0.99 );
l_text_actor->GetTextProperty()->SetJustificationToLeft();
l_text_actor->GetTextProperty()->SetVerticalJustificationToTop();
l_text_actor->GetTextProperty()->SetFontSize( 30 );
#ifdef VTK_WAS_BUILT_WITH_OPENGL2
l_text_actor->SetInput( "OpenGL2 !!!!" );
#else
l_text_actor->SetInput( "OpenGL1 !!!!" );
#endif
l_renderer->AddActor( l_text_actor );
l_renderer->AddVolume( l_volume );
// Adjust camera position
l_renderer->GetActiveCamera()->SetViewUp( 0, 0, 1 );
double l_distance = 1000;
double l_center[ 3 ], l_pos[ 3 ];
l_reader->GetOutput()->GetCenter( l_center );
l_reader->GetOutput()->GetCenter( l_pos );
l_pos[ 1 ] -= l_distance;
double l_cam_angle = atan( ( l_center[ 2 ] * 2. ) / ( l_distance * 2. ) ) * 360.0 / vtkMath::Pi();
l_renderer->GetActiveCamera()->SetFocalPoint( l_center );
l_renderer->GetActiveCamera()->SetPosition( l_pos );
l_renderer->GetActiveCamera()->SetViewAngle( l_cam_angle + 1 );
l_renderer->GetActiveCamera()->SetClippingRange( 0.01, 10000 );
// Go rendering !
l_iren->Start();
// Memory cleanup
l_reader->Delete();
l_resample->Delete();
l_renderer->Delete();
l_render_windows->Delete();
l_trackball->Delete();
l_iren->Delete();
l_gpu_mapper->Delete();
l_color->Delete();
l_opacity->Delete();
l_volume_property->Delete();
l_volume->Delete();
l_text_actor->Delete();
}
-------------- next part --------------
cmake_minimum_required( VERSION 2.8.5 FATAL_ERROR )
project( BlurredText )
find_package( VTK REQUIRED )
include( ${VTK_USE_FILE} )
if( VTK_RENDERING_BACKEND STREQUAL "OpenGL2" )
message( STATUS "Using new OpenGL2 backend" )
add_definitions( -DVTK_WAS_BUILT_WITH_OPENGL2 )
else()
message( STATUS "Using old OpenGL1 backend" )
endif()
add_executable( BlurredText MACOSX_BUNDLE BlurredText.cxx )
target_link_libraries( BlurredText ${VTK_LIBRARIES} )
More information about the vtkusers
mailing list