[vtkusers] reset camera
Rodrigo Valiña Gutiérrez
rodrigo.valina at usc.es
Mon May 10 04:02:37 EDT 2010
Hi André.
I managed to get it work, now it resets completely the camera.
First I reset the camera and then I align the vector
FocalPoint->Position with the Z axis.
####
renderer.ResetCamera()
fp = ren.GetActiveCamera().GetFocalPoint()
p = ren.GetActiveCamera().GetPosition()
dist = math.sqrt( (p[0]-fp[0])**2 + (p[1]-fp[1])**2 + (p[2]-fp[2])**2 )
renderer.GetActiveCamera().SetPosition(fp[0], fp[1], fp[2]+dist)
renderer.GetActiveCamera().SetViewUp(0.0, 1.0, 0.0)
####
--
Rodrigo
On Fri, May 7, 2010 at 2:17 PM, André Prins <a.h.prins at gmail.com> wrote:
> Hi Rodrigo,
>
> You are right, the focal point is what you should have 'centered' in
> your view. The view-up is ordinarily (0, 1, 0).
> The position then determines from which 'point' you view the focal
> point. And the resetcamera uses the focal-point together with the
> 'current viewplanenormal' and the size of the objects to specify a new
> position. And the current viewplanenormal appears to be missing in our
> previous discussion, sorry for that one.
>
> If you look in vtkRenderer.cxx (with Vtk 5.4.2 on line 1005), it gets
> the current viewplanenormal with
> this->ActiveCamera->GetViewPlaneNormal(vn);
>
> and then on line 1057 specifies a new position with
>
> this->ActiveCamera->SetPosition(center[0]+distance*vn[0],
> center[1]+distance*vn[1],
> center[2]+distance*vn[2]);
>
> My best guess in your case: calculate your own camera Position (for a
> suitable 'initial view-direction'), with the FocalPoint at the center
> of the scene boundingbox.
>
> Regards,
> André
>
>
> On Fri, May 7, 2010 at 1:59 PM, Rodrigo Valiña Gutiérrez
> <rodrigo.valina at usc.es> wrote:
>> Hi André,
>>
>> It seems not to work for me, because the number of objects/actors may
>> have changed, and the initial position and orientation may not be
>> valid.
>>
>> About your code:
>>
>> - The focal point can be the center of the bounding box, and is
>> calculated by ResetCamera().
>>
>> - The view up can be always (0,1,0)
>>
>> - It remains the position, that, I think, depends on the focal point
>> and the size of the objects.
>>
>> Rodrigo
>>
>> On Fri, May 7, 2010 at 1:43 PM, André Prins <a.h.prins at gmail.com> wrote:
>>> Hi Rodrigo,
>>>
>>> As far as I know, the interactorstyle should not matter at all for
>>> resetting the camera.
>>>
>>> You are right that the ResetCamera sets the focalpoint and changes the
>>> position, but it calculates 'suitable' defaults for them, based on the
>>> current viewdirection. It simply tries to fit all the objects in your
>>> scene in the view by moving the camera along the viewdirection
>>> (without changing this viewdirection). If your viewdireection is
>>> wrong, it will stay wrong.
>>>
>>> If you want to reset your camera to a specific position and
>>> viewdirection, then it is maybe better to do this yourself. Keep track
>>> of you 'initial' camera position and orientation and use those to
>>> 'reset' the camera. E.g. in my own code I have a method which resets a
>>> camera to a specified 'camera-position', looking to the origin of my
>>> world:
>>>
>>> void MyClass:resetcamera( double c[3] )
>>> {
>>> this->getRenderer( )->GetActiveCamera( )->SetViewUp( 0, 1, 0 );
>>> this->getRenderer( )->GetActiveCamera( )->SetFocalPoint( 0.0, 0.0, 0.0 );
>>> this->getRenderer( )->GetActiveCamera( )->SetPosition( c[0], c[1], c[2] );
>>> }
>>>
>>> I hope this helps.
>>>
>>> Regards,
>>> André
>>>
>>>
>>> On Fri, May 7, 2010 at 1:04 PM, Rodrigo Valiña Gutiérrez
>>> <rodrigo.valina at usc.es> wrote:
>>>> Hi André.
>>>>
>>>> I tryed before and after reseting the camera, and it does not work, it
>>>> only moves the object a bit.
>>>>
>>>> This way:
>>>>
>>>> renderer.GetActiveCamera().SetViewUp(0.0, 1.0, 0.0)
>>>> renderer.ResetCamera()
>>>> #renderer.GetActiveCamera().SetViewUp(0.0, 1.0, 0.0)
>>>>
>>>> It seems that ResetCameta() only resets FocalPoint, and changes the
>>>> position but not reset it.
>>>>
>>>> I do the following. It matters?
>>>>
>>>> self.widget.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
>>>>
>>>> Any idea?
>>>>
>>>> Rodrigo
>>>>
>>>> On Fri, May 7, 2010 at 12:17 PM, André Prins <a.h.prins at gmail.com> wrote:
>>>>> Hi Rodrigo,
>>>>>
>>>>> Unfortunately the ResetCamera() resets the viewdirection (using
>>>>> SetPosition() and SetFocalPoint()) but not the viewup vector.
>>>>> To reset the orientation as well, reset it before reseting the camera: E.g.
>>>>>
>>>>> renderer->SetViewUp( 0, 1, 0 ); // assuming this is your initial
>>>>> viewup-vector
>>>>> renderer->ResetCamer( );
>>>>>
>>>>> Regards,
>>>>> André
>>>>>
>>>>> On Fri, May 7, 2010 at 10:20 AM, Rodrigo Valiña Gutiérrez
>>>>> <rodrigo.valina at usc.es> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I want to reset the camera, and I am using:
>>>>>>
>>>>>> renderer.ResetCamera().
>>>>>>
>>>>>> That resets the position and size, but not the rotation of the object.
>>>>>> I wanted to place it in the default orientation (like initial
>>>>>> orientation), but I don't find any method that works.
>>>>>>
>>>>>> I can not use the saved position of the camera because in my scene,
>>>>>> the number of objects may have changed, and thus the center and size.
>>>>>>
>>>>>> Is there any form of reseting the camera rotation which works for any
>>>>>> scene configuration ?
>>>>>>
>>>>>> --
>>>>>> Rodrigo
>>>>>> _______________________________________________
>>>>>> 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
>>>>>
>>>> _______________________________________________
>>>> 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