Cocos3D - Take various screenshots in the background - cocos3d

Using Cocos3D, is it possible to take screenshot of the 3D model in the background without the user knowing it?
For pre-processing purpose and other usage, I want to take screenshots of the 3D model at various angles. Following the Render-To-Texture capability, I noticed when my scene is not visible, the drawSceneContentWithVisitor: method only execute once rather than at every rendering cycle. For obvious reason, the CC3GLFramebuffer* won't get updated with new data, hence, I'm only able to take the initial screenshot.
Thanks.

In Cocos3D, you can render your 3D scene to an off-screen surface. See the CC3DemoMashUp addTelevision and drawSceneContentWithVisitor: methods for an example of how to do this.
What is important is that the 3D drawing environment has been established when you perform your drawing. The safest place to do this is inside your drawSceneContentWithVisitor: method. But if you want to render somewhere else, you need to invoke the CC3Scene open3DWithVisitor: and CC3Scene close3DWithVisitor: methods before and after rendering. See the implementations of the CC3Scene processInitializeScene and open methods for examples of how to do that.
To render your scene from multiple viewpoints, you need to add multiple cameras to your scene, and set the camera property of your drawing visitor appropriately to select a camera before rendering. See how this is done in the CC3DemoMashUpScene addTelevision and drawToTVScreen methods. The drawToTVScreen method also shows how to handle clearing the color and depth buffers of your surface.

Related

Qt custom widget update big overhead

We are trying to use Qt 4.8.5 for some Linux-based embedded devices in our company. I use Qt embedded without X server. I need to plot measured data and update them very often (20-30fps, but only a small portion of the widget). The system is ARM based, 400Mhz, have no GPU and no FPU. I subclassed QWidget and overridden the paintEvent(). I have WA_OpaquePaintEvent and WA_StaticContents set. For testing, my paint event is empty, and I call the update() function of the widget form a timer set to 50ms. My problem is that the empty update is eating up 30% of the CPU. The amount varies with the area of the update, so I think QT may redraw something in the background. I have read many posts but I cannot find the solution for my problem. If I comment out the update call, the CPU usage drops to ~1% (even if I generate a sine in the timer for testing the widget, which should be much more complex than an empty function call). My widget is rectangular, is not transparent and I want to handle the full drawing procedure from the paint event.
Is it possible to reduce this overhead, and handle the whole painting process by my own?
The "empty update" is not empty - it repaints the whole window :)
Have you read the below?
To rapidly update custom widgets with simple background colors, such as real-time plotting or graphing widgets, it is better to define a suitable background color (using setBackgroundRole() with the QPalette::Window role), set the autoFillBackground property, and only implement the necessary drawing functionality in the widget's paintEvent().
You should also be using QWidget::scroll(), since internally it does scroll the backing store of the window, and that's much more efficient than repainting the entire thing if only a tiny slice is added to it.

QGraphicScene redraw on QGraphicItem move

I'm trying to fiddle a bit with a Qt example regarding 2D Graphics.
Basically it is a small diagram editor. In the example, the author explains that the tracknodes() function is used to update the line's endpoints, when the user drags a connected node into a different position.
This actually does not happen. After looking at the code, I have the feeling it's because there is no event being called after moving the node QGraphicItem, in order to update the link's rendering.
I figured I have to find out where and how the QGraphicItem's movement is handled in order to send a wasDropped signal (or something like that) to a slot that re-renders the link. Does this make sense?
I'm pretty new to Qt/C++ in general, so I don't have a very clear idea on how to achieve this, does anyone have any pointers he/she could share?
He seems to be using the QGraphicsItem::itemChange virtual function to call the tracknodes() function which draws the lines. ItemChange should be called every time a node is moved. It's called in other cases as well but he only uses it for tracking the movement of the QGraphicsItem.

Setting Polygon ROI with mouse in Qt

Anyone have any idea how I can implement this? I'd like to have a function basically exactly like impoly in matlab or the "polygon sections" tool in imageJ, where you click to form a polygonal section and then each node can be adjusted, etc. I'd also like to have access to this function from Qt since I'm trying to make a gui for a small program I wrote.
Also, I'd like to avoid making calls to the matlab function because it's part of the image processing toolbox which isnt free. Thanks.
I think the best way to implement this is using the Qt Graphics View framework. Create a scene with an Item displaying your image in the back and add draggable Items on top representing the corners of your polygon.
Your selection tool should probably be a subclass of QGraphicsObject hosting the polygon corners as child items and a QGraphicsPolygonItem below the corners being updated whenever the user readjusts the selection. As QGraphicsObject inherits QObject, you can emit signals with a QPolygonF or QPolygon argument whenever the selection changes, informing other parts of your application
This demo should be a good example of the corner-adjust functionality you need.
Qt Pathstroke Demo
(uh well, the example implements the drawing and dragging of the control points from scratch.. I'm sure you can do it by using QGraphicsEllipseItem instead and react on their position changes)
I think you would need to code this yourself. There is an excellent example in the C++ GUI Programming with Qt 4 book (there's a PDF copy floating around online; I think it's legal) where they show you how to create a diagram with nodes and links. The chapter is called "Item-based rendering with Graphics View".
The basic idea is that you have some draggable nodes, which are QGraphicsItems with the ItemIsMovable flag set to true, and then some links that connect them, which are QGraphicsLineItems. All of these would go into a composite QGraphicsItem representing the ROI, and all of those would go into a QGraphicsScene, which would be displayed by a QGraphicsView.
Bottom line: there isn't a built-in copy of the MATLAB function, but all the tools are there for you.

interactive (adding listeners to) DAE model in flex + papervision

I have a DAE model that is parsed into several parts. I am able to deal with them separately, such as changing their material or colour but I am having problems adding click or hover listeners over the children.
For example, lets say I have a model of a kitty where each facial feature is a child. I want to be able to hover or click the features and have a window pop up explaining the feature.
I've tried parsing the model and adding listeners but it doesn't seem to work.
Thanks in advance!
L
Hard to pin point the problem from your description, but you could check the following:
Make sure your viewport is interactive
Make sure the material your material is interactive
Make sure the DisplayObject3D you assign the listener to is not null.
Point 3, with collada objects, you can have nested objects, make sure you add a listener to an object that has geometry, not an empty(no geometry) container. With points 1,2, both viewport and material have a Boolean property called interactive which must be set to true for mouse events.
HTH

Right Control for Showing Animation?

I need help on the selecting right control in the QT for animation.
i need to show the animation in my QT application. The animation is in real time. i will get data from my hardware for every 5msec, every 100msec i need to update the animation.
The animation nothing but drawing the line based on the my hardware input, and also i need to implement zooming and Click Event in the animation.
please suggest which is the best control to use this? and please give some rough idea to implement this.
For the graphics part QGraphicsView is the best solution. Have a look at the graphics view framework overview for more information. Animation can be achieved in different ways. Either by redrawing the view every 100 msec, and keep track of the properties of the animating parts yourself, or use the infrastructure provided by Qt's animation framework, which will probably be the easiest approach. In particular, have a look at QGraphicsItemAnimation.

Resources