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. <br>
<br>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.<br>
<br>Anant.<br>
<br><br><div class="gmail_quote">On Wed, May 26, 2010 at 9:13 PM, 王å›è‡£ <span dir="ltr"><<a href="mailto:wangjunchen@gmail.com">wangjunchen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>from the code snippet, I can't figure out why the translation happened in your screenshot.</div>
<div>but I also tested the setorigin function, it indeed un-affected the original position if no rotation and scale.</div>
<div>is it possible, something about m_actor happened anywhere alse ? Check it carefully or debug it to trace the ComputerMatrix function of the actor.<br></div><div><div></div><div class="h5">
<div class="gmail_quote">2010/5/26 Anant Vemuri <span dir="ltr"><<a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a>></span><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;" class="gmail_quote">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. <br>
<br>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.<br>
<br>void updateMesh( TriangularMesh::sptr mesh )<br>{<br>   m_polyData = toVTKMesh(mesh);<br>   m_mapper->SetInput( m_polyData );<br>   this->setVtkPipelineModified();<br>}<br><br>//----------------------------------------------------------------------------------------------------------<br>
<br>void TriangularMesh::buildPipeline( )<br>{<br>Â Â Â m_actor->GetProperty()->SetColor( m_color->red() , m_color->green() , m_color->blue() );
<div><br>Â Â Â m_actor->SetMapper( m_mapper );<br></div>Â Â Â if ( m_configuration->hasAttribute( "origin" ) )<br>Â Â Â {<br>Â Â Â Â Â Â m_actor->SetOrigin( -0.443477, -0.285047, 10.1173 );<br>Â Â Â Â Â Â //m_actor->SetPosition( -4.43477, -2.85047, 101.173 );<br>
      //m_defaultTrf->Translate( -4.43477, -2.85047, 101.173 );<br>   }<br><br>   if (m_scale>1)<br>   {<br>      m_actor->SetScale( m_scale, m_scale, m_scale );   /// <span style="color: rgb(255, 0, 0);">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</span><br>
   }<br><br>   if( !this->getTransformId().empty() ) /// <span style="color: rgb(255, 0, 0);">I read the transform from a file, and check if it exists</span>
<div><br>Â Â Â {<br>Â Â Â Â Â m_defaultTrf->PostMultiply();<br>Â Â Â Â Â Â m_defaultTrf->Concatenate( this->getTransform() );<br>Â Â Â }<br><br></div>Â Â Â //////////////////////////////////////////////////////////////////////////////////////////<br>
   if ( m_configuration->hasAttribute( "concatTransform" ) )  /// <span style="color: rgb(51, 51, 255);">In this particular case this is not being used. So this particular part is not executed.</span><br>   {<br>
      std::string vtktrfID( m_configuration->getAttributeValue( "concatTransform" ) );<br>      vtkTransform *concatTrf = vtkTransform::New();<br>      concatTrf->SetInput( vtkTransform::SafeDownCast( this->getVtkObject( vtktrfID ) ) );<br>
      concatTrf->Inverse();<br>      m_defaultTrf->Concatenate( concatTrf );<br>   }<br>   <br>   /// <span style="color: rgb(255, 0, 0);">USER TRANSFORM</span>
<div><br>Â Â Â m_actor->SetUserTransform( m_defaultTrf );<br></div>Â Â Â this->setVtkPipelineModified();<br>}<br><br>Thank you for your help. <br>
<div><br>Best regards,<br>Anant.<br><br><br clear="all">-----------<br>Anant S. Vemuri<br>email: <a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a><br><br><br><br></div>
<div>
<div></div>
<div>
<div class="gmail_quote">On Wed, May 26, 2010 at 7:17 PM, 王å›è‡£ <span dir="ltr"><<a href="mailto:wangjunchen@gmail.com" target="_blank">wangjunchen@gmail.com</a>></span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<div>it seems strange...</div>
<div>if you only set the origin by <font color="#ff0000">SetOrigin</font> and keep others 0 or identity, it should take no effect...</div>
<div>please notice the setposition, in your test, is it (0, 0, 0) ?</div>
<div>if everything is paid enough attention, could you please post your code snippet?</div>
<div>
<div></div>
<div>
<div><br><br>Â </div>
<div class="gmail_quote">2010/5/26 Anant Vemuri <span dir="ltr"><<a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a>></span><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;" class="gmail_quote">Thank you Wang. I went through the file and also the documentation. Here are the steps I did to test,<br>
<br>1. I applied nothing, no SetOrigin(), no SetUserTransform() and put my object in the scene. - image name = nothing_applied.jpg<br>2. The I apply SetOrigin(-0.443477, -0.285047, 10.1173), and no SetUserTransform() this gives me result shown in image = setOrigin_applied.jpg<br>
<br>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.<br><br>Best regards,<br>Anant.
<div><br><br clear="all">-----------<br>Anant S. Vemuri<br>email: <a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a><br><br><br><br></div>
<div class="gmail_quote">2010/5/26 王å›è‡£ <span dir="ltr"><<a href="mailto:wangjunchen@gmail.com" target="_blank">wangjunchen@gmail.com</a>></span>
<div>
<div></div>
<div><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<div><br>Hi, sorry for my uncompleted explanation. Now let's study the underlying mechanism of "SetOrigin etc." together.</div>
<div>here is the source code of vtkProp3D::ComputeMatrix (vtk 5.4)</div>
<div>Â </div>
<div>void vtkProp3D::ComputeMatrix()<br>{<br>Â if (this->IsIdentity)<br>Â Â Â {<br>Â Â Â return;<br>Â Â Â }</div>
<div>Â // check whether or not need to rebuild the matrix<br>Â if ( this->GetMTime() > this->MatrixMTime )<br>Â Â Â {<br>Â Â Â this->GetOrientation();<br>Â Â Â this->Transform->Push();<br>Â Â Â this->Transform->Identity();<br>
   this->Transform->PostMultiply();</div>
<div>Â Â Â Â //<b><i><u><font color="#ff0000" size="6"> <font size="4">Notice This Code segment</font></font></u></i></b></div>
<div><font color="#ff0000" size="4">Â Â Â // begin {</font></div>
<div>Â Â Â // shift back to actor's origin<br>Â Â Â this->Transform->Translate(-this->Origin[0],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -this->Origin[1],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -this->Origin[2]);</div>
<div>Â Â Â // scale<br>Â Â Â this->Transform->Scale(this->Scale[0],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â this->Scale[1],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â this->Scale[2]);</div>
<div>Â Â Â // rotate<br>Â Â Â this->Transform->RotateY(this->Orientation[1]);<br>Â Â Â this->Transform->RotateX(this->Orientation[0]);<br>Â Â Â this->Transform->RotateZ(this->Orientation[2]);</div>
<div>Â Â Â // move back from origin and translate<br>Â Â Â this->Transform->Translate(this->Origin[0] + this->Position[0],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â this->Origin[1] + this->Position[1],<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â this->Origin[2] + this->Position[2]);</div>
<div>   //<font color="#ff0000" size="4">}end ==> it means: at first, the actor frame is an<font color="#66ff99"> </font><font color="#3333ff">identity (<font color="#ff0000">same with the world frame</font>)</font>, 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,</font><font color="#ff0000" size="4"> the usermatrix takes efforts.</font></div>
<div>Â Â Â // apply user defined transform last if there is one<br>Â Â Â if (this->UserTransform)<br>Â Â Â Â Â {<br>Â Â Â Â Â this->Transform->Concatenate(this->UserTransform->GetMatrix());<br>Â Â Â Â Â }</div>
<div>Â Â Â this->Transform->PreMultiply();<br>Â Â Â this->Transform->GetMatrix(this->Matrix);<br>Â Â Â this->MatrixMTime.Modified();<br>Â Â Â this->Transform->Pop();<br>Â Â Â }<br>}<br></div>
<div class="gmail_quote">2010/5/26 Anant Vemuri <span dir="ltr"><<a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a>></span>
<div>
<div></div>
<div><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;" class="gmail_quote">Hi,<br><br>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<br>
<br>m_transform->Translate( -100,-100,-100 );<br>m_actor->SetUserTransform( m_transform );<br><br><br>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?<br>
<br>Thank you.<br>Anant.<br><br><br>
<div class="gmail_quote">On Mon, May 24, 2010 at 11:27 PM, Anant Vemuri <span dir="ltr"><<a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a>></span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">Thanks... But doesn't SetUserTransform() do that already... the vtk<br>documentation says as below...<br>
<br>I think I understand the problem, but not sure how to correct it... I<br>am attaching a transform as the base transform which means that all<br>the other operations such as SetOrigin(), SetScale() get overridden.<br>
<div>
<div></div>
<div><br><br>On 5/24/10, 王å›è‡£ <<a href="mailto:wangjunchen@gmail.com" target="_blank">wangjunchen@gmail.com</a>> wrote:<br>> what you need is a multiplication (PostMultiply) of m_defaultTrf to the<br>> current actor transform not a replacement.<br>
><br>><br>> 2010/5/24 Anant Vemuri <<a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a>><br>><br>>> Hi,<br>>><br>>> I am trying to use myVtkActor->SetOrigin(origin) to set the origin so that<br>
>> any rotations I apply is done about this point. This is what I do to build<br>>> the pipeline<br>>><br>>><br>>> void buildPipeline( )<br>>> {<br>>> Â Â m_actor->SetMapper( m_mapper );<br>
>> Â Â m_actor->SetOrigin( 100, 100, 100 );<br>>> Â Â m_defaultTrf->Scale(m_scale, m_scale, m_scale);<br>>> Â Â m_defaultTrf->PostMultiply();<br>>> Â Â m_defaultTrf->Concatenate( this->getTransform() );<br>
>> Â Â /// I add some more things to the m_defaultTrf<br>>> Â Â .<br>>> Â Â .<br>>> Â Â .<br>>> Â Â m_actor->SetUserTransform( m_defaultTrf );<br>>> Â Â }<br>>> Â Â std::cout << "\n\n\nOrigin = [" << m_actor->GetOrigin()[0] << ", " <<<br>
>> m_actor->GetOrigin()[1] << ", " << m_actor->GetOrigin()[2] << "]\n\n\n";<br>>> }<br>>><br>>> But when I apply the transform in the scene, it is not being about some<br>
>> other point entirely. I noticed that this is the same point when I remove<br>>> the SetOrigin() line. But in the last line it gives me the origin as the<br>>> one<br>>> that I set a few line earlier. I am not able to figure out what is the<br>
>> mistake. Can anyone help me?<br>>><br>>> Thank you.<br>>> Anant.<br>>><br>>> _______________________________________________<br>>> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
>><br>>> Visit other Kitware open-source projects at<br>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>>><br>
>> Please keep messages on-topic and check the VTK FAQ at:<br>>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>>><br>>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>>><br>>><br>><br>><br>> --<br>><br><br><br></div></div><font color="#888888">--<br>
-----------<br>Anant S. Vemuri<br>email: <a href="mailto:ajar108@gmail.com" target="_blank">ajar108@gmail.com</a><br></font></blockquote></div><br><br>_______________________________________________<br>Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
<br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br></blockquote></div></div></div><br><br clear="all">
<br>-- <br><br></blockquote></div></div></div><br></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>人生就åƒä¸€ä¸ªåˆ·ç‰™ç¼¸ï¼Œä½ å¯ä»¥è®¤ä¸ºå®ƒæ˜¯æ¯å…·ï¼Œä¹Ÿå¯ä»¥è®¤ä¸ºå®ƒæ˜¯æ´—å…·<br></font></blockquote></div><br></div></div></blockquote>
</div><br><br clear="all"><br></div></div>-- <br><br>
</blockquote></div><br>