[vtkusers] Distance between 2 points in millimeters (mm)
Concetta Piazzese
aliens30586 at hotmail.it
Thu Aug 9 18:47:16 EDT 2012
I solved it. The problem was vtkSeedRepresentation. I used
vtkPointHandleRepresentation3D instead of using
vtkPointHandleRepresentation2D that gives the right point position. Damn!
Thank you for your support! =D
Date: Thu, 9 Aug 2012 21:11:02 +0200
From: dominique at toepfer-web.de
To: aliens30586 at hotmail.it
CC: vtkusers at vtk.org
Subject: Re: [vtkusers] Distance between 2 points in millimeters (mm)
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?
One small mistake in the loop again: it should be i < num - 1;
On 09.08.2012 20:27, Concetta Piazzese wrote:
Oh sorry about the discussion list.
Here is the code.
class vtkSeedCallback : public vtkCommand
{
public:
static vtkSeedCallback *New()
{
return new vtkSeedCallback;
}
vtkSeedCallback() {}
virtual void Execute(vtkObject*, unsigned long event, void
*calldata)
{
if(event == vtkCommand::PlacePointEvent)
{
int i=SeedRepresentation->GetNumberOfSeeds();
double pos[3];
this->SeedRepresentation->GetSeedWorldPosition(i-1, pos);
points->InsertNextPoint(pos);
}
}
void
SetRepresentation(vtkSmartPointer<vtkSeedRepresentation>
rep)
{
this->SeedRepresentation = rep;
}
private:
vtkSmartPointer<vtkSeedRepresentation>
SeedRepresentation;
vtkSeedWidget* SeedWidget;
};
void Seed()
{
imageViewer->SetInput(reader->GetOutput());
imageViewer->SetSlice(20);
imageViewer->SetColorLevel(127);
imageViewer->SetColorWindow(255);
vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
/* Create the representation*/
vtkSmartPointer<vtkPointHandleRepresentation3D>
handle =
vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
handle->GetProperty()->SetColor(1,0,0);
vtkSmartPointer<vtkSeedRepresentation> rep =
vtkSmartPointer<vtkSeedRepresentation>::New();
rep->SetHandleRepresentation(handle);
/* Seed widget*/
vtkSmartPointer<vtkSeedWidget> seedWidget =
vtkSmartPointer<vtkSeedWidget>::New();
seedWidget->SetInteractor(iren);
seedWidget->SetRepresentation(rep);
vtkSmartPointer<vtkSeedCallback> seedCallback =
vtkSmartPointer<vtkSeedCallback>::New();
seedCallback->SetRepresentation(rep);
seedWidget->AddObserver(vtkCommand::PlacePointEvent,seedCallback);
seedWidget->AddObserver(vtkCommand::InteractionEvent,seedCallback);
imageViewer->SetupInteractor(iren);
imageViewer->GetRenderWindow()->SetSize(512, 512);
imageViewer->GetRenderer()->ResetCamera();
imageViewer->SetSliceOrientationToXY();
iren->Initialize();
seedWidget->On();
iren->Start();
iren->Delete();
imageViewer->Delete();
return;
}
Date: Thu, 9 Aug 2012 20:16:34 +0200
From: dominique at toepfer-web.de
To: aliens30586 at hotmail.it; vtkusers at vtk.org
Subject: Re: [vtkusers] Distance between 2 points in
millimeters (mm)
Please keep the discussion on
the list.
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?
On 09.08.2012 19:48, Concetta Piazzese wrote:
Yeah, I considered that. But I still got
wrong numbers. When the user places a seed, the
vtkSeedCallback stores the point world position
(this->SeedRepresentation->GetSeedWorldPosition(i,
pos);). Do you know how vtkDistanceWidget computes
distance in millimeters?
Date: Thu, 9 Aug 2012 19:25:48
+0200
From: dominique at toepfer-web.de
To: aliens30586 at hotmail.it;
vtkusers at vtk.org
Subject: Re: [vtkusers] Distance between 2 points in
millimeters (mm)
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?
On 09.08.2012 18:52, Concetta Piazzese wrote:
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:
for (int i=0; i<num; i++)
{
points->GetPoint(i,punto);
points->GetPoint(i+1,punto2);
double squaredDistance;
double dist;
// Distance
squaredDistance =
vtkMath::Distance2BetweenPoints(punto, punto2);
dist=sqrt(squaredDistance);
std::cout << "Distance " << dist
<< std::endl;
}
Date: Thu, 9 Aug 2012
18:47:08 +0200
From: dominique at toepfer-web.de
To: aliens30586 at hotmail.it
CC: vtkusers at vtk.org
Subject: Re: [vtkusers] Distance between 2 points
in millimeters (mm)
Hi,
I think these lines in the for-loop are wrong:
points->GetPoint(num-1,punto);
points->GetPoint(num,punto2);
You seem to calculate the distance between the
same two points in every iteration. You need to
use i instead of num here.
Regards,
Dominique
On 09.08.2012 18:34, Concetta Piazzese wrote:
Hy everyone. I hope somebody can
help me!
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:
int main(int argc, char *argv[])
{
reader->SetFileName("C:/Tesi/DistanceBetween2Points_build/Debug/Data/Plaque_08.mhd");
reader->Update();
imgconn=reader->GetOutput();
//Points Placement with vtkSeedWidget.
Poins are stored in a vtkPoints called
"points"
Seed();
double punto[3];
double punto2[3];
int num=points->GetNumberOfPoints();
for (int i=0; i<num; i++)
{
points->GetPoint(num-1,punto);
points->GetPoint(num,punto2);
double squaredDistance;
double dist;
// Distance
squaredDistance =
vtkMath::Distance2BetweenPoints(punto,
punto2);
dist=sqrt(squaredDistance);
std::cout << "Distance " <<
dist << std::endl;
}
return EXIT_SUCCESS;
}
What's the problem? vtkDistanceWidget computes
distances using
vtkMath::Distance2BetweenPoints. So what am I
doing wrong?
Thank you!
_______________________________________________
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
--
Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen
--
Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen
--
Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen
--
Dominique Töpfer, Dipl.-Inform.
Institute of Medical Physics
University of Erlangen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120810/bfbfdd07/attachment.htm>
More information about the vtkusers
mailing list