[vtkusers] VTK 6.3 OpenGL2 - vtkTextActor blurred text when used with vtkFixedPointVolumeRayCastMapper

Simon ESNEAULT simon.esneault at gmail.com
Mon Nov 16 11:12:58 EST 2015


Hello Aashish,

Thanks !
After doing some test, I realized the patch I've just sent is not the
correct fix at all, because the text is not rendered properly when we don't
use a vtkFixedPointVolumeRayCastMapper anymore.

I believe the problem is probably larger than this and probably has nothing
to do with the freetype text generation, but more with the
vtkTexturedActor2D rendering part used together with a
vtkFixedPointVolumeRayCastMapper on the new rendering backend, when the
texture has some transparent pixel in it ...

Attached there is a new example that demonstrate that a vtkTextActor AND
a vtkTexturedButtonRepresentation2D are not correctly drawn in that case :
- OpenGL1 backend
<http://picpaste.com/pics/OGL1-Texture-okay.1447690100.png> : Transparent
pixel in Texture are correctly drawn
- OpenGL2 backend
<http://picpaste.com/pics/OGL2-Texture-not-okay.1447690272.png> :
Transparent pixel in Texture are not correctly drawn (clamped to white ?)

The example is more simple than the previous one and does not need any
additional data.

Hope that helps !
-Simon

2015-11-16 16:11 GMT+01:00 Aashish Chaudhary <aashish.chaudhary at kitware.com>
:

> Simon,
>
> Thanks for the report. I will follow up with other developers on this bug.
>
> - Aashish
>
>
> On Mon, Nov 16, 2015 at 6:08 AM, Simon ESNEAULT <simon.esneault at gmail.com>
> wrote:
>
>> Hello,
>>
>> Trying to solve this problem, I found out that if one call
>> "vtkFreeTypeTools::GetInstance()->DebugTexturesOn();" before to render a
>> string with a vtkTextActor, the text is properly rendered with a yellow dot
>> at the anchor point, and with a transparent gray background.
>> - DebugTexturesOn : http://picpaste.com/pics/Blurred.1447668943.PNG
>> - DebugTexturesOff : http://picpaste.com/pics/Not-Blurred.1447669009.PNG
>>
>> Now digging into the code in vtkFreeTypeTools.cxx, I suspect this is a
>> blending problem. When we activate Texture Debugging, a gray background is
>> first drawn, and after that in the method RenderCharacter( ... ) line 1887;
>> we either blend the rendered text with the background or not.
>>
>> Attached is a diff file that solves the problem for me. I do not really
>> understand why, so maybe a developer with more VTK's knowledge can
>> integrate this properly :)
>>
>> Thanks,
>> Simon
>>
>>
>>
>> 2015-11-13 16:43 GMT+01:00 Simon ESNEAULT <simon.esneault at gmail.com>:
>>
>>> 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
>>> ------------------------------------------------------------------
>>>
>>
>>
>>
>> --
>> ------------------------------------------------------------------
>> Simon Esneault
>> Rennes, France
>> ------------------------------------------------------------------
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
>
> --
>
>
>
> *| Aashish Chaudhary | Technical Leader         | Kitware Inc.            *
> *| http://www.kitware.com/company/team/chaudhary.html
> <http://www.kitware.com/company/team/chaudhary.html>*
>



-- 
------------------------------------------------------------------
Simon Esneault
Rennes, France
------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151116/fcde642a/attachment.html>
-------------- next part --------------
#include "vtkButtonWidget.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkImageCanvasSource2D.h"
#include "vtkImageData.h"
#include "vtkInteractorStyle.h"
#include "vtkPNGReader.h"
#include "vtkPNGReader.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkTexture.h"
#include "vtkTexturedActor2D.h"
#include "vtkTexturedButtonRepresentation2D.h"
#include "vtkVolume.h"

int main( int argc, char *argv[] ){

	// Generate an image data, filled with 0 value
	int l_image_size = 100;
	vtkImageData* l_image = vtkImageData::New();
	l_image->SetExtent( 0, l_image_size - 1, 0, l_image_size - 1, 0, l_image_size - 1 );
	l_image->AllocateScalars( VTK_SHORT, 1 );
	memset( l_image->GetScalarPointer(), 0, pow( l_image_size, 3 ) );

	// Setup a basic rendering pipeline
	vtkRenderer* l_renderer = vtkRenderer::New();
	l_renderer->SetBackground( 0.3, 0.3, 0.3 );

	int l_window_size = 300;
	vtkRenderWindow* l_render_windows = vtkRenderWindow::New();
	l_render_windows->AddRenderer( l_renderer );
	l_render_windows->SetSize( l_window_size, l_window_size );

	vtkRenderWindowInteractor* l_iren = vtkRenderWindowInteractor::New();
	l_iren->SetRenderWindow( l_render_windows );
	l_iren->GetInteractorStyle()->SetDefaultRenderer( l_renderer );

	// Setup a volume mapper
	//vtkGPUVolumeRayCastMapper* l_mapper = vtkGPUVolumeRayCastMapper::New();
	vtkFixedPointVolumeRayCastMapper* l_mapper = vtkFixedPointVolumeRayCastMapper::New();
	l_mapper->SetNumberOfThreads( 1 );
	l_mapper->SetInputData( l_image );

	// and a volume
	vtkVolume* l_volume = vtkVolume::New();
	l_volume->SetMapper( l_mapper );



	// setup a text actor :
	vtkTextActor* l_text_actor = vtkTextActor::New();
	l_text_actor->GetTextProperty()->SetFontSize( 20 );
#ifdef VTK_WAS_BUILT_WITH_OPENGL2
	l_text_actor->SetInput( "Some Text, OpenGL2 !??" );
#else
	l_text_actor->SetInput( "Some Text, OpenGL1 !??" );
#endif


	// Create a transparent image, with only a red circle
	int l_texture_size = 100;
	vtkImageCanvasSource2D* l_2d_image = vtkImageCanvasSource2D::New();
	l_2d_image->SetScalarTypeToUnsignedChar();
	l_2d_image->SetNumberOfScalarComponents( 4 );
	l_2d_image->SetExtent( 0, l_texture_size, 0, l_texture_size, 0, 0 );
	l_2d_image->SetDrawColor( 255, 255, 255, 0 ); // <- here with the new backend it does not respect the 0 alpha value, somewhat get clamp to something else
	l_2d_image->FillBox( 0, l_texture_size, 0, l_texture_size );
	l_2d_image->SetDrawColor( 255, 0, 0, 255 );
	l_2d_image->DrawCircle( l_texture_size / 2, l_texture_size / 2, l_texture_size / 2 - 3 );
	l_2d_image->Update();

	// Create the button widget and its representation
	vtkTexturedButtonRepresentation2D* l_button_rep = vtkTexturedButtonRepresentation2D::New();
	l_button_rep->SetNumberOfStates( 2 );
	l_button_rep->SetButtonTexture( 0, l_2d_image->GetOutput() );
	l_button_rep->SetButtonTexture( 1, l_2d_image->GetOutput() );

	vtkButtonWidget* l_button_widget = vtkButtonWidget::New();
	l_button_widget->SetInteractor( l_render_windows->GetInteractor() );
	l_button_widget->SetRepresentation( l_button_rep );

	// place it on top right border, with a small margin
	double l_bounds[ 6 ];
	l_bounds[ 0 ] = l_window_size - l_texture_size - 10;
	l_bounds[ 1 ] = l_window_size - 10;
	l_bounds[ 2 ] = l_window_size - l_texture_size - 10;
	l_bounds[ 3 ] = l_window_size - 10;
	l_bounds[ 4 ] = l_bounds[ 5 ] = 0.0;

	l_button_rep->SetPlaceFactor( 1 );
	l_button_rep->PlaceWidget( l_bounds );

	l_button_widget->On();

	l_renderer->AddActor( l_text_actor );
	l_renderer->AddVolume( l_volume );

	// Render once !
	l_render_windows->Render();

	// Go rendering !
	l_iren->Start();

	// Memory cleanup
	l_image->Delete();
	l_renderer->Delete();
	l_render_windows->Delete();
	l_iren->Delete();
	l_mapper->Delete();
	l_volume->Delete();
	l_text_actor->Delete();
	l_2d_image->Delete();
	l_button_rep->Delete();
	l_button_widget->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