[vtkusers] Problem with vtkActor->SetOrigin()

Anant Vemuri ajar108 at gmail.com
Fri May 28 15:04:51 EDT 2010


I think I have an idea where the problem is. SetScale on the actor changes
the origin. So when I was applying SetScale it was shifting. So I have to
apply the Scale using a base transform. However, this base transform
overrides the SetOrigin. So I did the same thing computeMatrix was doing in
vtkActor but this time with my transform. The problem is not entirely fixed
but I now need to apply another transform to get it to position correctly in
the scene. Anyway thanks for your help.

However, if I can here request the usage of SetOrigin, SetScale, SetPosition
and SetOrientation with UserTransform for the actor be clarified with some
examples and explanations.  If I figure it out clearly, I will try to do the
same.

Anant.


On Wed, May 26, 2010 at 9:13 PM, 王君臣 <wangjunchen at gmail.com> wrote:

> from the code snippet, I can't figure out why the translation happened in
> your screenshot.
> but I also tested the setorigin function, it indeed un-affected the
> original position if no rotation and scale.
> is it possible, something about m_actor happened anywhere alse ? Check it
> carefully or debug it to trace the ComputerMatrix function of the actor.
> 2010/5/26 Anant Vemuri <ajar108 at gmail.com>
>
>> Honestly, I am not doing much... Here is my buildPipeline() function. I
>> load my transforms in another function. I know they are working properly,
>> because the movement of the object is as predicted. However, I want to apply
>> the transform with respect to a point different from the default origin so I
>> want to use SetOrigin.
>>
>> There is one other thing. I am getting the polyData from another source. I
>> make a copy of it in a member variable of my class m_polydata, and I use it
>> to build my pipeline, I first run buildPipeline and when I actually load my
>> object model I run updateMesh. But I believe this should not be a problem.
>>
>> void updateMesh( TriangularMesh::sptr mesh  )
>> {
>>     m_polyData = toVTKMesh(mesh);
>>     m_mapper->SetInput( m_polyData );
>>     this->setVtkPipelineModified();
>> }
>>
>>
>> //----------------------------------------------------------------------------------------------------------
>>
>> void TriangularMesh::buildPipeline( )
>> {
>>     m_actor->GetProperty()->SetColor( m_color->red() , m_color->green() ,
>> m_color->blue() );
>>
>>     m_actor->SetMapper( m_mapper );
>>     if ( m_configuration->hasAttribute( "origin" ) )
>>     {
>>         m_actor->SetOrigin( -0.443477, -0.285047, 10.1173 );
>>         //m_actor->SetPosition( -4.43477, -2.85047, 101.173 );
>>         //m_defaultTrf->Translate( -4.43477, -2.85047, 101.173 );
>>     }
>>
>>     if (m_scale>1)
>>     {
>>         m_actor->SetScale( m_scale, m_scale, m_scale );    /// This is
>> the only other thing I dont know if it is affecting anything. But I turned
>> this off to check, and got same result
>>     }
>>
>>     if( !this->getTransformId().empty() ) /// I read the transform from a
>> file, and check if it exists
>>
>>     {
>>         m_defaultTrf->PostMultiply();
>>         m_defaultTrf->Concatenate( this->getTransform() );
>>     }
>>
>>
>> //////////////////////////////////////////////////////////////////////////////////////////
>>     if ( m_configuration->hasAttribute( "concatTransform" ) )   /// In
>> this particular case this is not being used. So this particular part is not
>> executed.
>>     {
>>         std::string vtktrfID( m_configuration->getAttributeValue(
>> "concatTransform" ) );
>>         vtkTransform *concatTrf = vtkTransform::New();
>>         concatTrf->SetInput( vtkTransform::SafeDownCast(
>> this->getVtkObject( vtktrfID ) ) );
>>         concatTrf->Inverse();
>>         m_defaultTrf->Concatenate( concatTrf );
>>     }
>>
>>     /// USER TRANSFORM
>>
>>     m_actor->SetUserTransform( m_defaultTrf );
>>     this->setVtkPipelineModified();
>> }
>>
>> Thank you for your help.
>>
>> Best regards,
>> Anant.
>>
>>
>> -----------
>> Anant S. Vemuri
>> email: ajar108 at gmail.com
>>
>>
>>
>>   On Wed, May 26, 2010 at 7:17 PM, 王君臣 <wangjunchen at gmail.com> wrote:
>>
>>> it seems strange...
>>> if you only set the origin by SetOrigin and keep others 0 or identity,
>>> it should take no effect...
>>> please notice the setposition, in your test, is it (0, 0, 0) ?
>>> if everything is paid enough attention, could you please post your code
>>> snippet?
>>>
>>>
>>>
>>> 2010/5/26 Anant Vemuri <ajar108 at gmail.com>
>>>
>>>> Thank you Wang. I went through the file and also the documentation. Here
>>>> are the steps I did to test,
>>>>
>>>> 1. I applied nothing, no SetOrigin(), no SetUserTransform() and put my
>>>> object in the scene. - image name = nothing_applied.jpg
>>>> 2. The I apply SetOrigin(-0.443477, -0.285047, 10.1173), and no
>>>> SetUserTransform() this gives me result shown in image =
>>>> setOrigin_applied.jpg
>>>>
>>>> From what I read in your email and the documentation, this should not
>>>> happen, right? Or am I interpreting it wrong. If not, then this is what is
>>>> baffling me.
>>>>
>>>> Best regards,
>>>> Anant.
>>>>
>>>>
>>>> -----------
>>>> Anant S. Vemuri
>>>> email: ajar108 at gmail.com
>>>>
>>>>
>>>>
>>>> 2010/5/26 王君臣 <wangjunchen at gmail.com>
>>>>
>>>>
>>>>> Hi, sorry for my uncompleted explanation. Now let's study the
>>>>> underlying mechanism of "SetOrigin etc." together.
>>>>> here is the source code of vtkProp3D::ComputeMatrix (vtk 5.4)
>>>>>
>>>>> void vtkProp3D::ComputeMatrix()
>>>>> {
>>>>>   if (this->IsIdentity)
>>>>>     {
>>>>>     return;
>>>>>     }
>>>>>   // check whether or not need to rebuild the matrix
>>>>>   if ( this->GetMTime() > this->MatrixMTime )
>>>>>     {
>>>>>     this->GetOrientation();
>>>>>     this->Transform->Push();
>>>>>     this->Transform->Identity();
>>>>>     this->Transform->PostMultiply();
>>>>>      //* Notice This Code segment*
>>>>>     // begin {
>>>>>     // shift back to actor's origin
>>>>>     this->Transform->Translate(-this->Origin[0],
>>>>>                               -this->Origin[1],
>>>>>                               -this->Origin[2]);
>>>>>     // scale
>>>>>     this->Transform->Scale(this->Scale[0],
>>>>>                           this->Scale[1],
>>>>>                           this->Scale[2]);
>>>>>     // rotate
>>>>>     this->Transform->RotateY(this->Orientation[1]);
>>>>>     this->Transform->RotateX(this->Orientation[0]);
>>>>>     this->Transform->RotateZ(this->Orientation[2]);
>>>>>     // move back from origin and translate
>>>>>     this->Transform->Translate(this->Origin[0] + this->Position[0],
>>>>>                               this->Origin[1] + this->Position[1],
>>>>>                               this->Origin[2] + this->Position[2]);
>>>>>     //}end ==> it means: at first, the actor frame is an identity (same
>>>>> with the world frame), then you have a chance to rotate or/and scale
>>>>> the identity frame with respect to a point (specified by setorigin) in the
>>>>> world frame. after that, the usermatrix takes efforts.
>>>>>     // apply user defined transform last if there is one
>>>>>     if (this->UserTransform)
>>>>>       {
>>>>>       this->Transform->Concatenate(this->UserTransform->GetMatrix());
>>>>>       }
>>>>>     this->Transform->PreMultiply();
>>>>>     this->Transform->GetMatrix(this->Matrix);
>>>>>     this->MatrixMTime.Modified();
>>>>>     this->Transform->Pop();
>>>>>     }
>>>>> }
>>>>> 2010/5/26 Anant Vemuri <ajar108 at gmail.com>
>>>>>
>>>>> Hi,
>>>>>>
>>>>>> I had posted a problem a few days back that I am still having with
>>>>>> using vtkActor->SetOrigin(). The documentation of vtkProp3D says that
>>>>>> SetOrigin(pos) function sets the point of rotation to the point specified by
>>>>>> pos. However, when I apply SetOrigin(pos), my actor moves in the scene such
>>>>>> that his point is at the world origin. For example, if I do SetOrigin(100,
>>>>>> 100, 100), the actor moves such that the previous (100,100,100) is now at
>>>>>> (0,0,0) initially before I apply any other transform to it. The effect is
>>>>>> similar to when I do
>>>>>>
>>>>>> m_transform->Translate( -100,-100,-100 );
>>>>>> m_actor->SetUserTransform( m_transform );
>>>>>>
>>>>>>
>>>>>> Is this what is expected? Becase from the documentation, I understood
>>>>>> that it should do translate(-newOrigin) [rotations, scaling etc]
>>>>>> translate(newOrigin). Should I expect that when I do
>>>>>> vtkActor->SetOrigin(newOrigin), the newOrigin moves to the world (0,0,0).
>>>>>> Can someone explain this to me?
>>>>>>
>>>>>> Thank you.
>>>>>> Anant.
>>>>>>
>>>>>>
>>>>>> On Mon, May 24, 2010 at 11:27 PM, Anant Vemuri <ajar108 at gmail.com>wrote:
>>>>>>
>>>>>>> Thanks... But doesn't SetUserTransform() do that already... the vtk
>>>>>>> documentation says as below...
>>>>>>>
>>>>>>> I think I understand the problem, but not sure how to correct it... I
>>>>>>> am attaching a transform as the base transform which means that all
>>>>>>> the other operations such as SetOrigin(), SetScale() get overridden.
>>>>>>>
>>>>>>>
>>>>>>> On 5/24/10, 王君臣 <wangjunchen at gmail.com> wrote:
>>>>>>> > what you need is a multiplication (PostMultiply) of m_defaultTrf to
>>>>>>> the
>>>>>>> > current actor transform not a replacement.
>>>>>>> >
>>>>>>> >
>>>>>>> > 2010/5/24 Anant Vemuri <ajar108 at gmail.com>
>>>>>>> >
>>>>>>> >> Hi,
>>>>>>> >>
>>>>>>> >> I am trying to use myVtkActor->SetOrigin(origin) to set the origin
>>>>>>> so that
>>>>>>> >> any rotations I apply is done about this point. This is what I do
>>>>>>> to build
>>>>>>> >> the pipeline
>>>>>>> >>
>>>>>>> >>
>>>>>>> >> void buildPipeline( )
>>>>>>> >> {
>>>>>>> >>     m_actor->SetMapper( m_mapper );
>>>>>>> >>     m_actor->SetOrigin( 100, 100, 100 );
>>>>>>> >>     m_defaultTrf->Scale(m_scale, m_scale, m_scale);
>>>>>>> >>     m_defaultTrf->PostMultiply();
>>>>>>> >>     m_defaultTrf->Concatenate( this->getTransform() );
>>>>>>> >>     /// I add some more things to the m_defaultTrf
>>>>>>> >>     .
>>>>>>> >>     .
>>>>>>> >>     .
>>>>>>> >>     m_actor->SetUserTransform( m_defaultTrf );
>>>>>>> >>     }
>>>>>>> >>     std::cout << "\n\n\nOrigin = [" << m_actor->GetOrigin()[0] <<
>>>>>>> ", " <<
>>>>>>> >> m_actor->GetOrigin()[1] << ", " << m_actor->GetOrigin()[2] <<
>>>>>>> "]\n\n\n";
>>>>>>> >> }
>>>>>>> >>
>>>>>>> >> But when I apply the transform in the scene, it is not being about
>>>>>>> some
>>>>>>> >> other point entirely. I noticed that this is the same point when I
>>>>>>> remove
>>>>>>> >> the SetOrigin() line. But in the last line it gives me the origin
>>>>>>> as the
>>>>>>> >> one
>>>>>>> >> that I set a few line earlier. I am not able to figure out what is
>>>>>>> the
>>>>>>> >> mistake. Can anyone help me?
>>>>>>> >>
>>>>>>> >> Thank you.
>>>>>>> >> Anant.
>>>>>>> >>
>>>>>>> >> _______________________________________________
>>>>>>> >> 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
>>>>>>> >>
>>>>>>> >>
>>>>>>> >
>>>>>>> >
>>>>>>> > --
>>>>>>> >
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> -----------
>>>>>>> Anant S. Vemuri
>>>>>>> email: ajar108 at gmail.com
>>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> 人生就像一个刷牙缸,你可以认为它是杯具,也可以认为它是洗具
>>>
>>
>>
>
>
> --
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100529/c786afd9/attachment.htm>


More information about the vtkusers mailing list