Vtk renders another windows apart from the qvtkwidget - qt

I have a little problem that i think it's easy so get a solution, but i've come to the point of trying everything and still not working. I'm sure it something simple, so i'm asking help as i can't figure it out on my own.
I have a qvtkwidget on the centralwidget and it has no problem.
the problem is that every time i run the program it rends another box apart from the interface.
here's the part of my code that matters for this issue.
// Create renderer
ren= vtkRenderer::New();
ren->AddActor(outlineActor);
ren->SetBackground(0.1,0.1,0.3);
// Drawing some X,Y,Z axes
axes= vtkCubeAxesActor2D::New();
//more stuff
ren->AddViewProp(axes);
ren->ResetCamera();
// Create a window for the renderer
renWin= vtkRenderWindow::New();
renWin->AddRenderer(ren);
// Set an user interface interactor for the render window
iren= vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
style = vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
// Create a inicial camera view
vtkCamera *inicam= ren->GetActiveCamera();
inicam->Zoom(1);
inicam->SetViewUp(0, 0, 0);
inicam->Azimuth(45);
ren->ResetCameraClippingRange();
// Start the initialization and rendering
renWin->Render();
// Assign the rendering window to the qvtkwidget
ui->qvtkWidget->SetRenderWindow(renWin);
if someone as any idea about this i would appreciate.

QVTKWidget already has an interactor. So use that one instead:
auto interactorStyle = vtkSmartPointer<TestInteractorStyle>::New();
QVTKInteractor* interactor = widget->GetInteractor();
interactor->SetInteractorStyle(interactorStyle);

after seeing the example i got it to work.
ui->qvtkWidget->GetRenderWindow()->AddRenderer(ren);

Related

UIImageOrientation/UIImagePickerController

I am using the Camera to take pictures in an IOS app.
It works, the only issue I have is when I try to figure out how the user was holding the device when taking the picture.
It would be much better if I could display the images in a proper way, not upside down or rotated 90 degrees.
Looking for a solution leads me to the fact that I should use the imageOrientation of UIImage but in reality:
theImage.imageOrientation is always equal to UIImageOrientationUp
What am I missing?
I did various research and experiment but nothing changes.
I am not showing any more code at this point, for the simple reason, I do not know which part to show to help find the problem.
Since I was able to find a solution on my own. I put it here, in case it may be useful to someone else.
Looking at the value of the "imageOrientation" field on the saved image (like I was doing), indeed for some reason always shows up as UIImageOrientationUp.
On the other hand looking at it inside the imagePickerController:didFinishPickingMediaWithInfo: is much more meaningful.
After some more research and trials, I ended up with a method looking like that:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
……
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
……
if ((image.imageOrientation==UIImageOrientationLeft)||
(image.imageOrientation==UIImageOrientationRight)||
(image.imageOrientation==UIImageOrientationDown)) {
UIGraphicsBeginImageContext(image.size);
[image drawAtPoint:CGPointMake(0.0, 0.0)];
image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
NSData *mediaData = UIImagePNGRepresentation(image);
……
}
And then my picture shows properly oriented, when I want to use it later in my app.

UIGestureRecognizer on multiple view

There is several examples on here about how to get multiple views recognized by a single UIGestureRecognizer. I have this code, and i've tried varies ways to get it work but unfortunately doesn't seem to work. I would appreciate it if one can shed some light on this.
the only way that i was able to get it to work if I create several (IBAction) functions but i have up to 100 views that need to be moved around so that would require to have 100 different functions. I read an example here where tag can be used to do just that but i tried it and unfortunately it does not work. I'm using XCode 4.6.1 if that helps. Here's the code below.
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
UIView *player=recognizer.view;
int tag=player.tag;
[player addGestureRecognizer:recognizer];
if (tag!=0) {
CGPoint translation =[recognizer translationInView:self.view];
player.center=CGPointMake(player.center.x+translation.x, player.center.y+translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:player.superview];
}
}
It seems to me that you are adding the same gesture recognizer to the view that already has it. You could use a loop using the tag to add the UIPanGestureRecognizer to all your views and then in the method handlePan:(UIPanGestureRecognizer *)recognizer check which view is currently being panned and continue from there.

How can I change the paper size for Qt QPrinter?

I'm trying to print PDFs with Qt and it's working fine. However, in certain cases I'd like to change the size of the paper AFTER I know how much will really be printed.
I'm trying to change the paper size of the device attached to my QPainter object, but it doesn't impact the actual output.
Here's what I'm doing in pseudo code:
printer = new QPrinter(...);
printer->setPaperSize(...); /* eg. A4 */
painter = new QPainter();
painter->begin(printer);
determine_page_size_by_trial_rendering(frame, printer, *painter);
printer->setPaperSize(....); /* eg. A5 */
real_rendering(frame, printer, *painter)
Unfortunately I don't seem to be able to get this going. I feel like the QPainter object somehow keeps the page size somewhere and I'm not able to reset it.
Ok - i figured it out already believe it or not. I had been looking for more than a day, but it turned out to be simple - i just destroyed the Painter objected and then opened a new one:
painter->end();
painter = new QPainter(printer);
That solved it...

Double clicking a google earth treeview node does not 'flyto' the placemark

I am using the plugin in a desktop application (Visual Studio C#). I am creating a placemark using the following code:
// Create a new coordinate object based on the lat/lon of the device
// TODO :: add lat/lon once data is available
FC.GEPluginCtrls.Geo.Coordinate Coord =
new FC.GEPluginCtrls.Geo.Coordinate(0, 0, 0, AltitudeMode.RelativeToGround);
// Create a placemark and put it in the tree.
kmlTreeView.ParseKmlObject(KmlHelpers.CreatePlacemark(
ge,
Coord,
((Device)DeviceList[i]).sSerialNum, // ID
((Device)DeviceList[i]).sNickname, // Name - shown in tree
((Device)DeviceList[i]).sName)); // Description - shown in bubble
In the TreeView the new nodes show up and when I double-click on them the bubble pops up with information in it but the view does not change. I attempted to verify the property "public bool FlyToOnDoubleClickNode" as shown in the documentation but that property apparently does not exist in the version I am using (1.010).
When I was loading a KML file the double click worked as expected but ever since I've been manually adding the placemarks it does not work.
Any thoughts?
Thanks!
Have you tried manually assigning a <LookAt> or <Camera> ?
That should work
Edit: Well the FlyToOnDoubleClickNode is turned on by default, so your problems lie elsewhere
I do not know why you are having troubles with setting multiple LookAts. Have you tried assigning 'ids' to your LookAt ? Depending on what you are actually doing, that might help.
Otherwise, have you seen setFlyToView()
I am not sure that will help you though, since it relates to KMLs loaded via NetworkLinks
Thats about me for ideas - good luck!
It appears that the coordinates 0,0 are somehow significant. If the coordinates are changed to something else the "FlyTo" works (0.1 and 0.1 work).

Qt: read video dimension without creating a video player

I need to read the dimensions of a given video file (its width and height), without constructing a video player, like Phonon, e.g. My question is which class I should use to get access to this data. I have already tried using QPixmap and QMovie, but niether of them supports *.mov.
Thank you!
Pavlo, you can try this:
QMediaContent media("myMovie.mov");
QSize resolution = media.canonicalResource().resolution();
The code uses QMediaResource class from Qt Mobility project. I haven't tried it yet and I suppose you need at least a correct backend (plugin that is capable of reading MOV format). I'm giving this answer only from API overview.
Hope this helps.
I finally solved my problem and I thought I'd share my solution with everybody else.
In the class constructor I initialize the following two variables:
media = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget;
I connect a signal of media to a slot in my class:
connect(media,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(videoState(Phonon::State,Phonon::State)));
I let the user choose a video file:
QString filename = QFileDialog::getOpenFileName(this,tr("Choose video file"),QDir().homePath(),tr("Video files (*.mov *.mpg *.avi)"));
And apply this file to the media object:
media->setCurrentSource(filename);
Phonon::createPath(media,videoWidget);
Because media object is already connected to a slot, every change in media can be monitored with its help.
void VideoModuleDialog::videoState(Phonon::State newState, Phonon::State oldState)
{
if(newState == Phonon::PlayingState || newState == Phonon::StoppedState)
{
width->setText(QString().number(videoWidget->sizeHint().width()));
height->setText(QString().number(videoWidget->sizeHint().height()));
}
if(newState == Phonon::ErrorState)
{
QMessageBox::critical(this,tr("Video file error!"),
tr("Video file error: ") + media->errorString(),QMessageBox::Ok);
}
}
I must admit, however, that this code seems to me to be quite slow. Phonon library is used in my program only in one place, and this is here, in a dialog window where user can choose a video clip to embed, and i want the video dimensions to be read from file. It takes some time until this dialog window opens, so I guess, this solution is a bit too harsh for my problem. However, I was not able to find another solution. If there are different opinions as to the subject of this post, I'd be glad to hear them.

Resources