[vtkusers] vtkProjectedTexture example
Kilgus, Thomas
t.kilgus at dkfz-heidelberg.de
Tue Jul 14 05:31:40 EDT 2015
Hi there,
I used this class to project an RGB texture of a camera onto a CT surface. I figured it was working very well but not very straight forward to use. The documentation was insufficient for me (and two students), so we just did the math and solved everything more or by trial and error. The class produces very nice texture coordinates to map an image onto a polydata. Unfortunately, this was almost two years ago and I fear I don't remember details.
Here is my code anyway (I removed parts from our own toolkit and added comments):
vtkSmartPointer<vtkProjectedTexture> projectedTexture = vtkSmartPointer<vtkProjectedTexture>::New();
mitk::Surface* surfaceToComputeTextureOn = dynamic_cast<mitk::Surface*>(surfaceNodeToComputeTexture->GetData());
mitk::Surface* surfaceToPutTextureOn = dynamic_cast<mitk::Surface*>(surfaceNodeToPutTextureOn->GetData());
//Settings for vtkProjectedTexture
projectedTexture->SetPosition(0,0,0);
projectedTexture->SetFocalPoint(0,0,1);
projectedTexture->SetUp(0,1,0);
//RGB camera intrinsics. Width and Height are the resolution of the camera. See intrinsic camera calibration in literature
projectedTexture->SetAspectRatio( -d->m_width, d->m_height, d->m_CameraIntrinsics->GetFocalLengthX() );
float dx = ( (d->m_width/2.0f) - d->m_CameraIntrinsics->GetPrincipalPointX() ) / -d->m_width;
float dy = ( (d->m_height/2.0f) - d->m_CameraIntrinsics->GetPrincipalPointY() ) / -d->m_height;
projectedTexture->SetSRange(dx, 1+dx);
projectedTexture->SetTRange(dy, 1+dy);
projectedTexture->SetInputData( polyDataToComputeTextureOn ); //this can be the same as the one to project on
projectedTexture->Update();
//Map Texture on Surface
polyDataToPutTextureOn->GetPointData()->SetTCoords(projectedTexture->GetOutput()->GetPointData()->GetTCoords()); //can be a different surface or the same
//here is what you need in addition:
vtkSmartPointer<vtkTexture> vtkTxture = vtkSmartPointer<vtkTexture>::New();
vtkTxture->SetInputData( someVtkImageData ); //in my case an RGB camera image
actor->SetTexture(vtkTxture); //your polydata actor
Bottom line the class works really well and I failed to submit an additional example or documentation to improve the usability. I hope this helps!
Regards,
Thomas Kilgus
German Cancer Research Center (DKFZ)
Div. Medical and Biological Informatics
Junior group: Computer-assisted Interventions (E131)
Im Neuenheimer Feld 280
69120 Heidelberg, Germany
Phone: +49(0) 6221-42-3545
-----Ursprüngliche Nachricht-----
Von: vtkusers [mailto:vtkusers-bounces at vtk.org] Im Auftrag von audialc
Gesendet: Montag, 13. Juli 2015 20:13
An: vtkusers at vtk.org
Betreff: Re: [vtkusers] vtkProjectedTexture example
Hi,
I'm very interested too. I'm looking for an example that show me how to use this class, but I didn't find it. Have you ever used this class? Can you post here an example? Every language is ok. Thank you
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkProjectedTexture-example-tp5723907p5732867.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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
Search the list archives at: http://markmail.org/search/?q=vtkusers
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list