[vtkusers] Drawing objects interactively in VTK..??
Darshan Pai
darshanpai at gmail.com
Wed Apr 7 19:25:02 EDT 2010
replied too fast . The displaytoview() and viewToWorld does not take points
as input.
But you can use the vtkCoordinate . Try this particular snippet of code.
vtkCamera *camera = renderer->GetActiveCamera();
double *n = new double[2];
n = camera->GetClippingRange();
vtkSmartPointer<vtkCoordinate> coordinate =
vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToDisplay();
coordinate->SetValue(x,y); // display coordinates
double *pt = new double[3];
pt = coordinate->GetComputedWorldValue(renderer);
cout << pt[0] << " " <<pt[1] << " " << pt[2] << endl;
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(pt[0],pt[1],pt[2]*-1*n[0]);
sphereSource->SetRadius(1.0);
sphereSource->Update();
depth is assumed to be 1 and n[0] is the near clip..
On Wed, Apr 7, 2010 at 6:26 PM, Darshan Pai <darshanpai at gmail.com> wrote:
> I don't know how to get the matrices defined . Maybe someone can help .
> But vtkRenderer has some functions like DisplayToView() and ViewToWorld()
> which can get you the world coordinate for that point.
> The default camera has the clipping information . You provide the depth of
> the point
> The world point will be <x*depth, y*depth, depth*-1*nearclipplane>
>
> See if it works .
>
> Regards
> Darshan
>
> On Wed, Apr 7, 2010 at 4:37 AM, Rakesh Patil <rakeshthp at in.com> wrote:
>
>>
>> Hi David,
>>
>> That is exactly what i want.. But how can i get the points or lines which
>> are traced..?? And also it should work without any actor..
>> I mean this class works only for some actors. But i need for with actor
>> and without actor..
>>
>> Thanks
>>
>> Regards
>> Rakesh Patil
>>
>>
>> ---------- Original message ----------
>> From:David Doria< daviddoria+vtk at gmail.com <daviddoria%2Bvtk at gmail.com> >
>> Date: 06 Apr 10 17:59:52
>> Subject: Re: [vtkusers] Drawing objects interactively in VTK..??
>> To: Rakesh Patil
>>
>> On Tue, Apr 6, 2010 at 5:13 AM, Rakesh Patil wrote:
>> > Hello,
>> >
>> > I am trying to draw a polyline interactively (with help of mouse). What
>> i'm
>> > doing is at every left button down event, i get the mouse position and
>> store
>> > it is a vector list. Later using this points am displaying on the
>> rendering
>> > window.
>> >
>> > But when i do this, i noticed the following:
>> >
>> > The mouse position values are totally different from the the points
>> which
>> > are displayed.. I mean, i click at one location, and it is displayed at
>> far
>> > end another location..
>> >
>> > I tried changing the coordinate system also.. Still the result is
>> > unchanged..
>> >
>> > Any suggestions how it is to be done..??
>> >
>> > Thanks
>> > Rakesh Patil
>> >
>>
>> Sounds like you may need a coordinate system conversion in there
>> somewhere, check out:
>> http://vtk.org/Wiki/VTK/Examples/Coordinate
>>
>> It also sounds like you are trying to duplicate already working code in:
>> http://vtk.org/Wiki/VTK/Examples/Widgets/ImageTracerWidget
>>
>> Thanks,
>>
>> David
>>
>>
>>
>> Get Yourself a cool, short *@in.com* Email ID now!<http://mail.in.com/mails/new_reg.php?utm_source=invite&utm_medium=outgoing>
>>
>> _______________________________________________
>> 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/20100407/6d068b3a/attachment.htm>
More information about the vtkusers
mailing list