[vtkusers] set caption leader color?
Alex Malyushytskyy
alexmalvtk at gmail.com
Fri Aug 17 21:20:38 EDT 2012
I just tried to test vtkCaptionActor2D with the code below and vtk-5.10.0.
line
captionActor->GetProperty()->SetColor (1, 0.5, 0);
does change the color of leader and border, the same as text.
So problem might be in the vtk version you are using.
Regards,
Alex
#include <vtkAbstractPicker.h>
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkCaptionActor2D.h>
#include <vtkCoordinate.h>
#include <vtkFollower.h>
#include <vtkImageActor.h>
#include <vtkImageMapper3D.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkCoordinate.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkPolyDataMapper2D.h>
#include <vtkInteractorStyleImage.h>
#include <vtkMath.h>
#include <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkProperty2D.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkSmartPointer.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>
#include <vtkVectorText.h>
#include <sstream>
class MyStyle : public vtkInteractorStyleImage
{
public:
static MyStyle* New();
vtkTypeMacro(MyStyle, vtkInteractorStyleImage);
std::vector<vtkActor2D*> Numbers;
void OnLeftButtonDown()
{
//std::cout << "Picking pixel: " <<
this->Interactor->GetEventPosition()[0] << " " <<
this->Interactor->GetEventPosition()[1] << std::endl;
this->Interactor->GetPicker()->Pick(this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1],
0, // always zero.
//this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
this->CurrentRenderer );
double picked[3];
this->Interactor->GetPicker()->GetPickPosition(picked);
//std::cout << "Picked point with coordinate: " << picked[0] <<
" " << picked[1] << " " << picked[2] << std::endl;
this->AddNumber(picked);
// Forward events
vtkInteractorStyleImage::OnLeftButtonDown();
//this->Interactor->GetRenderWindow()->Render();
this->Interactor->Render();
}
void AddNumber(double p[3])
{
std::cout << "Adding marker at " << p[0] << " " << p[1] ;//<< std::endl;
// normally, with an image you would do
// double* s = image->GetSpacing();
// double* o = image->GetOrigin();
// p[0] = static_cast<int>( (p[0] - o[0]) / s[0] + 0.5 );
p[0] = static_cast<int>( p[0] + 0.5 );
p[1] = static_cast<int>( p[1] + 0.5 );
std::cout << " -> " << p[0] << " " << p[1] << std::endl;
// Convert the current number to a string
std::stringstream ss;
ss << Numbers.size();
std::cout << "Adding number: " << ss.str() << std::endl;
// Create an actor for the text
vtkSmartPointer<vtkCaptionActor2D> captionActor =
vtkSmartPointer<vtkCaptionActor2D>::New();
captionActor->SetCaption( ss.str().c_str() );
captionActor->SetAttachmentPoint(p);
captionActor->BorderOff();
// captionActor->BorderOn();
captionActor->GetCaptionTextProperty()->BoldOff();
captionActor->GetCaptionTextProperty()->ItalicOff();
captionActor->GetCaptionTextProperty()->ShadowOff();
captionActor->ThreeDimensionalLeaderOff();
captionActor->LeaderOn();
// captionActor->LeaderOff();
captionActor->SetLeaderGlyphSize( 100. );
// captionActor->SetPadding( 100 );
captionActor->GetProperty()->SetColor (1, 0.5, 0);
// captionActor->ThreeDimensionalLeaderOn();
//
captionActor->SetMaximumLeaderGlyphSize(1000);
this->CurrentRenderer->AddViewProp( captionActor );
this->Numbers.push_back(captionActor);
}
};
vtkStandardNewMacro(MyStyle);
int main (int, char *[])
{
// Create a blank, black image
vtkSmartPointer<vtkImageCanvasSource2D> drawing =
vtkSmartPointer<vtkImageCanvasSource2D>::New();
drawing->SetScalarTypeToUnsignedChar();
drawing->SetNumberOfScalarComponents(3);
drawing->SetDrawColor(255, 255, 255, 0);
drawing->SetExtent(0, 20, 0, 50, 0, 0);
drawing->FillBox(0,20,0,50);
// Draw a red circle of radius 5 centered at (9,10)
drawing->SetDrawColor(255, 255, 255, 0);
drawing->DrawCircle(9, 10, 5);
drawing->Update();
vtkSmartPointer<vtkImageActor> actor = vtkSmartPointer<vtkImageActor>::New();
actor->GetMapper()->SetInputConnection(drawing->GetOutputPort());
actor->InterpolateOff();
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(0,0,0); // Background color white
renderer->GradientBackgroundOn();
renderer->SetBackground2(0,0,1); // Background 2 color blue
renderWindow->Render();
vtkSmartPointer<MyStyle> style = vtkSmartPointer<MyStyle>::New();
renderWindowInteractor->SetInteractorStyle( style );
style->SetDefaultRenderer( renderer );
style->SetCurrentRenderer( renderer );
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
On Fri, Aug 17, 2012 at 4:28 PM, Maxwell, Thomas P.
(GSFC-606.2)[SCIENCE SYSTEMS AND APPLICATIONS INC]
<thomas.maxwell at nasa.gov> wrote:
> The 3D leader does not show up at all in my scene. The leader color is always white. If it was the same color as text then there would be no problem- I can set the text color. The only solution I can see at this point is to create my own custom CaptionActor in python and correct the problem there. I was hoping to avoid this, as it is a lot of coding to fix one small oversight.
>
> -- Tom
> ________________________________________
> From: vtkusers-bounces at vtk.org [vtkusers-bounces at vtk.org] On Behalf Of Alex Malyushytskyy [alexmalvtk at gmail.com]
> Sent: Friday, August 17, 2012 5:53 PM
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] set caption leader color?
>
> I have not used this class, but it seems does not provide access (keep
> private and has no access methods) to LeaderActor2D or LeaderActor3D.
> this probably means that you can't specify it.
> At the same vtkAxesActor and vtkLegendBoxActor provide such access.
>
> It looks like it supposed to be always colored with the same color as text.
> If leader has different color, this is probably a bug and should be reported.
>
> Have you tried to use vtkCaptionActor2D with 3D leader?
> Does 2D and 3D leader have the same colors?
>
> Alex
>
>
>
> On Thu, Aug 16, 2012 at 8:31 AM, Maxwell, Thomas P.
> (GSFC-606.2)[SCIENCE SYSTEMS AND APPLICATIONS INC]
> <thomas.maxwell at nasa.gov> wrote:
>> The vtkCaptionActor2D consists of a vtkTextActor with a border and an adjustable arrow attached to the border which is supposed to point at the feature that the caption refers to. This arrow consists of a single line, referred to as the "leader" in the vtk source code, with a glyph used as the leader "head". vtkCaptionActor2D extends vtkActor2D. The (internal) leader actor is also a vtkActor2D.
>>
>> -- Tom
>> ________________________________________
>> From: vtkusers-bounces at vtk.org [vtkusers-bounces at vtk.org] On Behalf Of Alex Malyushytskyy [alexmalvtk at gmail.com]
>> Sent: Wednesday, August 15, 2012 9:34 PM
>> To: vtkusers at vtk.org
>> Subject: Re: [vtkusers] set caption leader color?
>>
>> Just to avoid further confusion, could you clarify what is a leader
>> you are talking about.
>> If it is part of vtkAxesActor , my advice below is correct.
>>
>> Alex
>>
>> On Wed, Aug 15, 2012 at 6:29 PM, Alex Malyushytskyy
>> <alexmalvtk at gmail.com> wrote:
>>> I misread, but if you want to setup color for "leader",
>>> I assume you are talking about something like vtkAxesActor
>>>
>>> In this case you can do it as
>>>
>>>
>>> axesActor->GetXAxisShaftProperty ()->SetColor (0, 0, 0);
>>>
>>> // tip is a 'leader"
>>> axesActor->GetXAxisTipProperty ()->SetColor (0, 0, 0);
>>>
>>>
>>>
>>> Hope this helps.
>>>
>>>
>>> Alex
>>>
>>>
>>> On Wed, Aug 15, 2012 at 5:40 PM, Maxwell, Thomas P.
>>> (GSFC-606.2)[SCIENCE SYSTEMS AND APPLICATIONS INC]
>>> <thomas.maxwell at nasa.gov> wrote:
>>>> Thanks, Alex, but I tried this and it only sets the properties of the
>>>> caption text- it does not affect the border and the leader. I also tried
>>>> setting the attributes of the BorderProperty associated with the
>>>> vtkCaptionRepresentation, but that seems to have no effect.
>>>>
>>>> -- Tom
>>>>
>>>>
>>>>
>>>> On 8/15/12 7:25 PM, "Alex Malyushytskyy" <alexmalvtk at gmail.com> wrote:
>>>>
>>>>> vtkSmartPointer<vtkTextProperty> textprop =
>>>>>vtkSmartPointer<vtkTextProperty>::New();
>>>>> textprop->BoldOff();
>>>>> textprop->SetFontSize( 18 );
>>>>> textprop->SetFontFamilyToTimes();
>>>>> textprop->SetColor(0, 0, 0);
>>>>>
>>>>>aptionActor2D()->SetCaptionTextProperty( textprop );
>>>>>
>>>>
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list