<div dir="ltr">Hi all,<div><br><div>I am preparing a ruler widget that will measure props3d. Now I would like the ruler to follow the prop if the prop is applied a vtkTransform T. </div><div>T comes from:</div><div><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">vtkTransform</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">New</span><span style="color:rgb(0,0,0)">();</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">SetMatrix</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,0)">picker</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="font-style:italic;color:rgb(0,0,0)">GetProp3D</span><span style="color:rgb(0,0,0)">()-&gt;</span><span style="font-style:italic;color:rgb(0,0,0)">GetMatrix</span><span style="color:rgb(0,0,0)">());</span><span style="color:rgb(192,192,192)"> </span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">PostMultiply</span><span style="color:rgb(0,0,0)">();</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Translate</span><span style="color:rgb(0,0,0)">(-</span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">2</span><span style="color:rgb(0,0,0)">]);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Concatenate</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,0)">rotMtx</span><span style="color:rgb(0,0,0)">);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Translate</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">cellC</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">2</span><span style="color:rgb(0,0,0)">]);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(128,0,0)">t</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Translate</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">deltaVector</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">deltaVector</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">],</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">deltaVector</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">2</span><span style="color:rgb(0,0,0)">]);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial">Then what I was trying is to apply the same transform T to the ruler through an callback, every time the prop is moved. The problem is that if the prop was already transformed before placing the ruler, then the ruler is transformed with T as the whole prop transform from the beginning instead of just the &quot;last&quot; transform that was applied to the prop.</span><br>
</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial">So my solution was to copy T the first time the ruler is set, and then whenever a transformation is applied to the prop, I would cancel the former transformations by post - multiplying the inverse of the copy of T I made when setting the ruler. The code looks like this</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">inverseOriginal</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">vtkTransform</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">New</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">localMatrix</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">vtkTransform</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">New</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">inverseOriginal</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">DeepCopy</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">rep</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="font-style:italic;color:rgb(0,0,0)">GetInitialTransformMatrix</span><span style="color:rgb(0,0,0)">());</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">localMatrix</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">DeepCopy</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">matrix</span><span style="color:rgb(0,0,0)">); // where matrix is the current T transform</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">inverseOriginal</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="font-style:italic;color:rgb(0,0,0)">Inverse</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">inverseOriginal</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Update</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">localMatrix</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Concatenate</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">inverseOriginal</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(192,192,192)">    </span><span style="font-family:arial;color:rgb(0,0,0)">localMatrix</span><span style="font-family:arial;color:rgb(0,0,0)">-&gt;</span><span style="font-family:arial;color:rgb(0,0,0)">PostMultiply</span><span style="font-family:arial;color:rgb(0,0,0)">();</span><br>
</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">localMatrix</span><span style="color:rgb(0,0,0)">-&gt;</span><span style="color:rgb(0,0,0)">Update</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(192,192,192)">    </span><span style="font-family:arial;color:rgb(128,0,0)">WidgetRep</span><span style="font-family:arial;color:rgb(0,0,0)">-&gt;</span><span style="font-family:arial;font-style:italic;color:rgb(0,0,0)">UpdateMatrix</span><span style="font-family:arial;color:rgb(0,0,0)">(</span><span style="font-family:arial;color:rgb(0,0,0)">localMatrix</span><span style="font-family:arial;color:rgb(0,0,0)">);</span><br>
</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)">The problem is that the results are the opposite. When I move it upwards, the ruler moves down and viceversa. The rotations are handled ok.</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)">What could be the mistake??</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)">Thank you very much</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;color:rgb(0,0,0)">Ignacio Prieto</span></pre>
</pre></div><div><div><br></div><div><br></div>-- <br>José Ignacio Prieto
</div><div>Software Engineer</div><div>Biomedical Imaging Center</div><div>Pontificia Universidad Catolica de Chile</div></div></div>