<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">I compiled your code and it works! I
      also measured my image with another program and your results seem
      to be correct. Can you explain why you think they're wrong?<br>
      One small mistake in the loop again: it should be i &lt; num - 1;<br>
      <br>
      On 09.08.2012 20:27, Concetta Piazzese wrote:<br>
    </div>
    <blockquote cite="mid:DUB107-W28DC01806535F1BB3754AF97CC0@phx.gbl"
      type="cite">
      <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
      <div dir="ltr">
        Oh sorry about the discussion list.<br>
        <br>
        Here is the code.<br>
        <br>
        <br>
        class vtkSeedCallback : public vtkCommand<br>
        {<br>
        public:<br>
        &nbsp;&nbsp;&nbsp; static vtkSeedCallback *New()<br>
        &nbsp;&nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return new vtkSeedCallback; <br>
        &nbsp;&nbsp;&nbsp; }<br>
        &nbsp;&nbsp;&nbsp; vtkSeedCallback() {}<br>
        &nbsp;&nbsp;&nbsp; virtual void Execute(vtkObject*, unsigned long event, void
        *calldata)<br>
        &nbsp;&nbsp;&nbsp; {<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(event == vtkCommand::PlacePointEvent)<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i=SeedRepresentation-&gt;GetNumberOfSeeds();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double pos[3];<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        this-&gt;SeedRepresentation-&gt;GetSeedWorldPosition(i-1, pos);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(pos);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
        &nbsp;&nbsp;&nbsp; }<br>
        <br>
        &nbsp;&nbsp;&nbsp; void
        SetRepresentation(vtkSmartPointer&lt;vtkSeedRepresentation&gt;
        rep)<br>
        &nbsp;&nbsp;&nbsp; {<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;SeedRepresentation = rep;<br>
        &nbsp;&nbsp;&nbsp; }<br>
        private:<br>
        &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkSeedRepresentation&gt;
        SeedRepresentation;<br>
        &nbsp;&nbsp;&nbsp; vtkSeedWidget* SeedWidget;<br>
        };<br>
        <br>
        <br>
        void Seed()<br>
        {&nbsp; <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetInput(reader-&gt;GetOutput());<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetSlice(20);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetColorLevel(127);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetColorWindow(255);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkRenderWindowInteractor *iren =
        vtkRenderWindowInteractor::New();<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* Create the representation*/<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPointHandleRepresentation3D&gt;
        handle =
        vtkSmartPointer&lt;vtkPointHandleRepresentation3D&gt;::New();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; handle-&gt;GetProperty()-&gt;SetColor(1,0,0);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkSeedRepresentation&gt; rep =
        vtkSmartPointer&lt;vtkSeedRepresentation&gt;::New();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rep-&gt;SetHandleRepresentation(handle);<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* Seed widget*/<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkSeedWidget&gt; seedWidget =
        vtkSmartPointer&lt;vtkSeedWidget&gt;::New();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seedWidget-&gt;SetInteractor(iren);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seedWidget-&gt;SetRepresentation(rep);<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkSeedCallback&gt; seedCallback =
        vtkSmartPointer&lt;vtkSeedCallback&gt;::New();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seedCallback-&gt;SetRepresentation(rep);<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        seedWidget-&gt;AddObserver(vtkCommand::PlacePointEvent,seedCallback);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        seedWidget-&gt;AddObserver(vtkCommand::InteractionEvent,seedCallback);<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetupInteractor(iren);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;GetRenderWindow()-&gt;SetSize(512, 512);<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;GetRenderer()-&gt;ResetCamera();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imageViewer-&gt;SetSliceOrientationToXY();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iren-&gt;Initialize();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seedWidget-&gt;On();<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iren-&gt;Start();<br>
        <br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iren-&gt;Delete();<br>
        <br>
        &nbsp;&nbsp;&nbsp; imageViewer-&gt;Delete();<br>
        <br>
        &nbsp;&nbsp;&nbsp; return;<br>
        }<br>
        <br>
        <div>
          <hr id="stopSpelling">Date: Thu, 9 Aug 2012 20:16:34 +0200<br>
          From: <a class="moz-txt-link-abbreviated" href="mailto:dominique@toepfer-web.de">dominique@toepfer-web.de</a><br>
          To: <a class="moz-txt-link-abbreviated" href="mailto:aliens30586@hotmail.it">aliens30586@hotmail.it</a>; <a class="moz-txt-link-abbreviated" href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
          Subject: Re: [vtkusers] Distance between 2 points in
          millimeters (mm)<br>
          <br>
          <div class="ecxmoz-cite-prefix">Please keep the discussion on
            the list.<br>
            <br>
            vtkDistanceWidget with the default representation also uses
            sqrt(vtkMath::Distance2BetweenPoints(p1,p2)). Did you check
            your points coordinates? Can you provide the rest of your
            code?<br>
            <br>
            On 09.08.2012 19:48, Concetta Piazzese wrote:<br>
          </div>
          <blockquote
            cite="mid:DUB107-W59BBA8CC38474F7AAA561297CC0@phx.gbl">
            <style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

--></style>
            <div dir="ltr"> Yeah, I considered that. But I still got
              wrong numbers. When the user places a seed, the
              vtkSeedCallback stores the point world position
              (this-&gt;SeedRepresentation-&gt;GetSeedWorldPosition(i,
              pos);). Do you know how vtkDistanceWidget computes
              distance in millimeters? <br>
              <br>
              <div>
                <hr id="ecxstopSpelling">Date: Thu, 9 Aug 2012 19:25:48
                +0200<br>
                From: <a moz-do-not-send="true"
                  class="ecxmoz-txt-link-abbreviated"
                  href="mailto:dominique@toepfer-web.de">dominique@toepfer-web.de</a><br>
                To: <a moz-do-not-send="true"
                  class="ecxmoz-txt-link-abbreviated"
                  href="mailto:aliens30586@hotmail.it">aliens30586@hotmail.it</a>;
                <a moz-do-not-send="true"
                  class="ecxmoz-txt-link-abbreviated"
                  href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
                Subject: Re: [vtkusers] Distance between 2 points in
                millimeters (mm)<br>
                <br>
                <div class="ecxmoz-cite-prefix">I agree, the loop should
                  work now. But then the error seems to be in Seed(). Is
                  it possible, that the order of points provided by the
                  user is different from the order in your vtkPoints
                  object? Did you consider the image spacing?<br>
                  <br>
                  On 09.08.2012 18:52, Concetta Piazzese wrote:<br>
                </div>
                <blockquote
                  cite="mid:DUB107-W216B4F0AFF05B8AA9EF70197CC0@phx.gbl">
                  <style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

--></style>
                  <div dir="ltr"> You're right but the problem isn't
                    fixed. I still got wrong distances. The loop was
                    wrong but I think the problem is not in the loop.
                    Now the loop is:<br>
                    for (int i=0; i&lt;num; i++)<br>
                    &nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp; <br>
                    &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(i,punto);<br>
                    &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(i+1,punto2);<br>
                    <br>
                    &nbsp;&nbsp;&nbsp; double squaredDistance;<br>
                    &nbsp;&nbsp;&nbsp; double dist;<br>
                    <br>
                    &nbsp;&nbsp;&nbsp; // Distance<br>
                    &nbsp;&nbsp;&nbsp; squaredDistance =
                    vtkMath::Distance2BetweenPoints(punto, punto2);<br>
                    &nbsp;&nbsp;&nbsp; dist=sqrt(squaredDistance);<br>
                    &nbsp;&nbsp;&nbsp; <br>
                    &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Distance " &lt;&lt; dist
                    &lt;&lt; std::endl;<br>
                    &nbsp;<br>
                    &nbsp;&nbsp;&nbsp; }<br>
                    <br>
                    <div>
                      <hr id="ecxstopSpelling">Date: Thu, 9 Aug 2012
                      18:47:08 +0200<br>
                      From: <a moz-do-not-send="true"
                        class="ecxmoz-txt-link-abbreviated"
                        href="mailto:dominique@toepfer-web.de">dominique@toepfer-web.de</a><br>
                      To: <a moz-do-not-send="true"
                        class="ecxmoz-txt-link-abbreviated"
                        href="mailto:aliens30586@hotmail.it">aliens30586@hotmail.it</a><br>
                      CC: <a moz-do-not-send="true"
                        class="ecxmoz-txt-link-abbreviated"
                        href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
                      Subject: Re: [vtkusers] Distance between 2 points
                      in millimeters (mm)<br>
                      <br>
                      <div class="ecxmoz-cite-prefix">Hi,<br>
                        <br>
                        I think these lines in the for-loop are wrong:<br>
                        <br>
                        &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(num-1,punto);<br>
                        &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(num,punto2);<br>
                        <br>
                        You seem to calculate the distance between the
                        same two points in every iteration. You need to
                        use i instead of num here.<br>
                        <br>
                        Regards,<br>
                        Dominique<br>
                        <br>
                        <br>
                        On 09.08.2012 18:34, Concetta Piazzese wrote:<br>
                      </div>
                      <blockquote
                        cite="mid:DUB107-W49D915FDCD00B5B7CAB16597CC0@phx.gbl">
                        <style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

--></style>
                        <div dir="ltr"> Hy everyone. I hope somebody can
                          help me!<br>
                          I need to find the distance between 2 points
                          in millimeters like the vtkDistanceWidget
                          does. An user places 10 points and then the
                          program compute the distances. The problem is
                          that I have an array of vtkPoints and I can't
                          use vtkDistanceWidget to find the distances.
                          How I can find the distance? The points
                          positions are inglobal coordinate values. The
                          distance I got are totally wrong. Here is my
                          code: <br>
                          <br>
                          int main(int argc, char *argv[])<br>
                          {<br>
                          &nbsp;&nbsp;&nbsp;
reader-&gt;SetFileName("C:/Tesi/DistanceBetween2Points_build/Debug/Data/Plaque_08.mhd");<br>
                          &nbsp;&nbsp;&nbsp; reader-&gt;Update(); <br>
                          <br>
                          &nbsp;&nbsp;&nbsp; imgconn=reader-&gt;GetOutput();<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; //Points Placement with vtkSeedWidget.
                          Poins are stored in a vtkPoints called
                          "points"<br>
                          &nbsp;&nbsp;&nbsp; Seed();<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; double punto[3];<br>
                          &nbsp;&nbsp;&nbsp; double punto2[3];<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; int num=points-&gt;GetNumberOfPoints();<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; for (int i=0; i&lt;num; i++)<br>
                          &nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp; <br>
                          &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(num-1,punto);<br>
                          &nbsp;&nbsp;&nbsp; points-&gt;GetPoint(num,punto2);<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; double squaredDistance;<br>
                          &nbsp;&nbsp;&nbsp; double dist;<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; // Distance<br>
                          &nbsp;&nbsp;&nbsp; squaredDistance =
                          vtkMath::Distance2BetweenPoints(punto,
                          punto2);<br>
                          &nbsp;&nbsp;&nbsp; dist=sqrt(squaredDistance);<br>
                          &nbsp;&nbsp;&nbsp; <br>
                          &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Distance " &lt;&lt;
                          dist &lt;&lt; std::endl;<br>
                          &nbsp;<br>
                          &nbsp;&nbsp;&nbsp; }<br>
                          <br>
                          &nbsp;&nbsp;&nbsp; return EXIT_SUCCESS;<br>
                          }<br>
                          <br>
                          What's the problem? vtkDistanceWidget computes
                          distances using
                          vtkMath::Distance2BetweenPoints. So what am I
                          doing wrong?<br>
                          Thank you!<br>
                        </div>
                        <br>
                        <fieldset class="ecxmimeAttachmentHeader"></fieldset>
                        <br>
                        <pre>_______________________________________________
Powered by <a moz-do-not-send="true" class="ecxmoz-txt-link-abbreviated" href="http://www.kitware.com" target="_blank">www.kitware.com</a>

Visit other Kitware open-source projects at <a moz-do-not-send="true" class="ecxmoz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the VTK FAQ at: <a moz-do-not-send="true" class="ecxmoz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a moz-do-not-send="true" class="ecxmoz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a>
</pre>
                      </blockquote>
                      <br>
                      <br>
                      <pre class="ecxmoz-signature">-- 
Dominique T&ouml;pfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
                    </div>
                  </div>
                </blockquote>
                <br>
                <br>
                <pre class="ecxmoz-signature">-- 
Dominique T&ouml;pfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
              </div>
            </div>
          </blockquote>
          <br>
          <br>
          <pre class="ecxmoz-signature">-- 
Dominique T&ouml;pfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Dominique T&ouml;pfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen</pre>
  </body>
</html>