[vtkusers] rescaling glyphs..??

David Gobbi david.gobbi at gmail.com
Tue Feb 9 08:06:40 EST 2010


The callback should be called on the Renderer's StartEvent, as I said
before.  No render is needed, because when the callback is called, the
render will already be underway.

   David


On Tue, Feb 9, 2010 at 5:46 AM, Rakesh Patil <rakeshthp at in.com> wrote:
>
> Hey,
>
> Thanks. It's working fine. A small verification.. Where should be the
> callback command called??
>
> In Renderer's start event or in wxWindowRenderInteractor's
> EndInteractorEvent?? And after setting the
> scale to glyphs, do i need to refresh or render them again??
>
> And depth is to be calculated as difference of objects position and camera
> position right?? Coz in my case all glyphs are at same depth
>
> Thanks
>
> ---------- Original message ----------
> From:David Gobbi< david.gobbi at gmail.com >
> Date: 09 Feb 10 17:33:58
> Subject: Re: [vtkusers] rescaling glyphs..??
> To: Rakesh Patil
>
> Hi Rakesh,
>
> The only thing that you should be doing in the callback is setting the
> scale. You should only add the glyphs to the renderer once (and the
> callback is not the place to do that). The reason that things are
> slowing down is that you are creating new glyphs and adding them to
> the rende rer each time, so after the callback has been called N times
> there will be N copies of all your glyphs in the renderer. After you
> fix this, calling the callback on every render should not be a problem
> at all.
>
> What I mean by "depth" is distance from the camera. The further an
> object is from the camera, the smaller it will look. So, the further
> it is from the camera, the more you have to scale it to make it "look"
> the same size.
>
> Actually depth isn't exactly the distance from the camera. The depth
> is the dot product of the camera's direction-of-projection with the
> vector from the camera's position to the object's position. So to
> scale objects so that they always look the same size, you will need to
> compute the depth for each object and then use the depth to compute
> the scale factor. Store these scale factors in an array of scalars
> (i.e. a vtkFloatArray with the same length as your list of points) and
> then store these sc alars with your point data. Then you can tell
> Glyph3D to use these scalars to scale the glyphs.
>
> David
>
>
> On Tue, Feb 9, 2010 at 4:40 AM, Rakesh Patil wrote:
>>
>> Well,
>>
>> I guess, its working fine.. But the scaling isn't working properly...
>> As told by you, i hooked an observer in the renderer's start event. But by
>> doing so,
>> the performance of the application became very slow. So, i hooked an
>> observer to
>> the vtkRenderWindowInteractor's EndInteractionEvent.
>>
>> And then in my command callback, i call the following two functions,
>>
>> ComputeScale();
>> DisplayVectors();
>>
>> DisplayVectors contains the code to display vector arrays. as
>>
>> glyphs->SetScaleFactor(_scale);
>>
>> glyphMapper = vtkPolyDataMapper::New();
>> glyphMapper->SetInputConnection(glyphs->GetOutputPort());
>>
>> glyphAc tor = vtkActor::New();
>> glyphActor->SetMapper(glyphMapper);
>>
>> pRenderer->AddActor(glyphActor);
>>
>> The above code is executed again and again.. And thats why the performance
>> of the application
>> goes down..
>>
>> So, what i want to know is whether what i did is correct or not??
>> Secondly,
>> is t here any faster method to display the scaled output??
>>
>> Thanks
>>
>> ---------- Original message ----------
>> From:"Rakesh Patil"< rakeshthp at in.com >
>> Date: 09 Feb 10 12:50:37
>> Subject: Re: [vtkusers] rescaling glyphs..??
>> To: "David Gobbi"
>>
>> Hello sir,
>>
>> Well, I dont know what you exactly mean by "at the same depth" in regards
>> to
>> collection of glyph?
>> Actually, each nodes are at different depths (say range from 0 to 3000 for
>> example). And I display
>> glyphs at these nodes. So, does it mean that my glyphs are not at same
>> depth..??
>>
>> Thanks
>>
>>
>>
>> ---------- Original message ----------
>> From:David Gobbi< david.gobbi at gmail.com >
>> Date: 08 Feb 10 19:06:27
>> Subject: Re: [vtkusers] rescaling glyphs..??
>> To: Rakesh Patil
>>
>> Hi Rakesh,
>>
>> The "ViewPort" is not what you think. It has nothing to do with the
>> problem you are working on.
>>
>> The "position" in that code means world coordinates of whatever object
>> object you want to scale. When the camera is doing a perspective
>> projection (this is the default), then the scale of an object depends
>> on its depth within the scene. The position is used to compute the
>> depth.
>>
>> If you have a collection of glyphs that a re all at approximately the
>> same depth, you can compute the centroid and use that as the position.
>> Setting a different scale for each glyph is p ossible, too, but is
>> more complicated.
>>
>> David
>>
>>
>> On Sun, Feb 7, 2010 at 10:58 PM, Rakesh Patil wrote:
>>> Hello,
>>>
>>> I have to scale my vector arrows (glyphs) in such a way that when it is
>>> zoomed in, the arrow size must become small and as I zoom out, it should
>>> grow up.. As my senior instructed me here,
>>>
>>> http://www.vtk.org/pipermail/vtkusers/2010-January/105915.html
>>>
>>> I tried my best and did this..
>>>
>>> class vtkMyCallback : public vtkCommand
>>> {
>>> public:
>>> static vtkMyCallback *New(){
>>> return new vtkMyCallback;
>>> }
>>>
>>> virtual void Execute(vtkObject *callee, unsigned long, void *)
>>> {
>>> vt kRenderer *ren derer = reint erpret_cast(callee);
>>> computeSomething(renderer->GetActiveCamera()->GetPosition(), renderer);
>>> }
>>> };
>>>
>>> Here is a code for computeSomething()
>>>
>>> computeSomething( const double position[3], vtkRenderer *renderer)
>>> {
>>> double vp[4];
>>> renderer->GetViewPort(vp);
>>> cout << vp[0] << vp[1] << vp[2] << vp[3];
>>> }
>>>
>>> It is invoked as
>>>
>>> vtkMyCallback * mo = vtkMyCallback::New();
>>> pRenderer->AddObserver(vtkCommand::StartEvent, mo);
>>>
>>>
>>> When i run this code, I get the viewport as
>>>
>>> 0011
>>>
>>> It remains same throughout. Even after zooming in and out...
>>>
>>> after that I tried the code which was suggested to me by one of the
>>> senior
>>> developer here
>>>
>>> The scale which it returns is 0. as the position i'm passing in
>>> computeSomething is s ame as the camera position in else part. Actually,
>>> now
>>> i need to find the scale. So in order to do that, what position do i need
>>> to
>>> pass as a parameter for this function.? what is difference between,
>>> position
>>> and camera position??
>>>
>>> Thanks in advance
>>> Rakesh Patil
>>>
>>> Dear vtkusers ! Get Yourself a cool, short @in.com Email ID now!
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep m essages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wik i/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>



More information about the vtkusers mailing list