ID3DX10Mesh::CloneMesh - c++

I'm trying to copy mesh in DirectX10. I wrote this:
HR(mesh->CloneMesh(mesh->GetFlags(),data.GetPosSemantic(),data.GetInputElementDesc(),
data.GetDescCount(),&mMesh));
but when i try to render the mesh nothing appers on the screen.
when i write
mMesh = mesh;
There are no problems with the rendering(unless when I release "mesh" ).
Thanks in advance.

If you want to duplicate the mesh without any changes, you should use the second approach and call then mMesh->AddRef() to declare the data is owned by two pointers (better idea is to use some kind of smart pointers - COM or boost::shared_ptr adapted to COM-like objects).
But the first case should work too - what is the data object about?

Related

Loading Box2D b2World from .Dump() file

I am trying to save and load the state of b2World in order to resume a simulation at a later time, but with the states of the Collision Manager, etc being exactly maintained. What is the best way to do this (without getting into library internals, and having to use boost serialize while monitoring public/private members of every class)? Is there a way to repurpose the log file from b2World.dump function to construct the object again?
I think parsing Dump as-is is a dead end.
First, the output of Dump seems to be executable C++ code:
b2ChainShape chainShape;
b2Vec2 vertices[] = {b2Vec2(-5,0), b2Vec2(5,0), b2Vec2(5,5), b2Vec2(4,1), b2Vec2(-4,1), b2Vec2(-5,5)};
chainShape.CreateLoop(vertices, 6);
b2FixtureDef groundFixtureDef;
groundFixtureDef.density = 0;
groundFixtureDef.shape = &chainShape;
Secondly, there is the problem of dumping floating point values with enough precision to recreate the original object.
Finally, some objects don't seem to support Dumping at all.
Some alternatives:
Hack box2d and add your own state-preserving dumping mechanism
Keep all box2d objects in a specific memory area and use memory snapshotting and/or checkpointing techniques to restore that memory again on load. One such library I know of is Ken, but I'm sure there are other implementations.

Unexpected/weird results using OLE clipboard and classic clipboard, or do I miss something?

I'm trying to do the following trick:
I have IDataObject* to be set into the clipboard, so I'm using OleSetClipboard() to set it into the clipboard.
I have another CLIPFORMAT I want to add to the clipboard, but I can't do it with OleSetClipboard() because the IDataObject* I receive does not implement SetData() method. So, to overcome this limitation I OpenClipboard() with GetClipboardOwner(), this way, I can SetClipboardData() to the clipboard without EmptyClipboard() first.
Now, it all works well, but what happens is that OleGetClipboard() does not return the data I placed in the clipboard using SetClipboardData(), but I can using GetClipboardData().
I can imagine why this happens (It just returns the IDataObject*), so I tried to OleFlushClipboard() to delete the IDataObject*, and OleGetClipboard() again to let the OS rebuild a new IDataObject*, and it still didn't contain the CLIPFORMAT added by SetClipboardData().
Does anyone have any idea how to overcome this issue? or a different trick? or even explain why it works this way? Thanks
I just tried this (on Windows 7) and it appears to work but only cross-process:
In a different process to the clipboard owner, OleGetClipboard returns a data object that contains all of the formats (i.e. the original formats from the data object and the extra ones added to the clipboard).
In the same process, OleGetClipboard always returns a data object that does not contain the extra clipboard formats.
In both cases, calling OleFlushClipboard makes no difference.
Anyway, this doesn't seem like a terribly robust solution. What you can do instead is create your own data object that responds to the formats it knows about and delegates other formats to the original data object. The EnumFormatEtc method would combine formats from both objects, and so on. This article has the skeleton of a simple data object you could extend.

What is the correct way of creating a small list of cv::Mat and iterating over it?

I am new to C++ and I am trying to create a list of cv::Mat.
This could allocate quite a lot of memory, but I only have around ten small Mat's to load in the list.
I made this code, but not sure why it is not working.
void Utils::getFramesFromVideo(std::string file,std::list<cv::Mat>& listMatOutput) {
cv::VideoCapture* videoCapture = new cv::VideoCapture(file);
bool hasImage = false;
cvNamedWindow("WhileReading", 1);
do {
cv::Mat frame;
hasImage = videoCapture->read(frame);
if (hasImage) {
listMatOutput.push_back(frame);
imshow("WhileReading", frame);
waitKey(0);//give some time to see the frame (debug)
}
} while (hasImage);
cvNamedWindow("AfterReading", 2);
for (std::list<Mat>::const_iterator iterator = listMatOutput.begin();
iterator != listMatOutput.end(); iterator++) {
imshow("AfterReading", *iterator);
waitKey(0);//give some time to see the frame (debug)
}
videoCapture->release();
}
The first loading is displaying the frames correctly, but in the second window (AfterReading) the image is black with red stripes.
Could someone please give some advice?
The list format is an STL container, meaning that you've got some things to keep in mind to work with it. push_back() is the preferred method of adding instances to the container, much like using an iterator is the preferred method of accessing the elements of the list. If you try to directly set an element of the list to a cv::Mat() you're working on, then a) you need to know exactly what sort of wrapping the list is doing to each instance, so you can do it properly yourself, and b) you're defeating the purpose of using an STL container in the first place, which is to abstract away the details of the list.
You don't necessarily need to use the frame.clone() call in your code, as this creates a deep copy of the image and takes up precious resources. I know that I've used std::vector<cv::Mat> in the past without having to make deep copies for each element in the vector, so I assume that you should be able to pass the Mat itself to a list. Consult the C++ documentation on STL lists.
Another thing you might consider, if low memory usage and speed of access through the list is a concern, and your number of images is low, is a list of image pointers. Keep your images stored as individual cv::Mat instances, and make your list of type std::list<cv::Mat*>, passing the handle of the image to the push_back() call. Of course, with this method, your images will not be 'thread safe' because they will be stored in one place, but called and worked on from another. I hope this shed a little light on your inquiry.
I tried all sort of things, like changing to pointers or vectors and checking for code optimizations on GCC. Then after trying to clone cv::Mat it worked:
listMatOutput.push_back(frame.clone());
Would be glad if anyone could tell me why and suggest a better way of doing, so I can choose a better answer then my own.

c++ use new to Image gdi+

im using gdi+ to output my images.
i tried to use the keyword new but it didn't work.
shot(L"image name") = new Image;
that didn't work any other ideas how to make it work
Something like this seems a lot more likely:
Image *image_object = new Image(L"Image Name");
Except that there's a pretty decent chance you don't want to allocate the Image object dynamically at all -- unless you really do, you generally want to just define an object with automatic storage duration:
Image image_object(L"Image Name");
The GDI+ Image class is not default constructible. You have to supply some parameters to the constructor in order to create one - see here.
You may well be better off using Gdiplus::Bitmap, which derives from Image. That seems more likely if you're trying to output it.

Draw a multiple lines set with VTK

Can somebody point me in the right direction of how to draw a multiple lines that seem connected? I found vtkLine and its SetPoint1 and SetPoint2 functions. Then I found vtkPolyLine, but there doesn't seem to be any add, insert or set function for this. Same for vtkPolyVertex.
Is there a basic function that allows me to just push some point at the end of its internal data and the simply render it? Or if there's no such function/object, what is the way to go here?
On a related topic: I don't like vtk too much. Is there a visualization toolkit, maybe with limited functionality, that is easier to use?
Thanks in advance
For drawing multiple lines, you should first create a vtkPoints class that contains all the points, and then add in connectivity info for the points you would like connected into lines through either vtkPolyData or vtkUnstructuredGrid (which is your vtkDataSet class; a vtkDataSet class contains vtkPoints as well as the connectivity information for these points). Once your vtkDataSet is constructued, you can take the normal route to render it (mapper->actor->renderer...)
For example:
vtkPoints *pts = vtkPoints::New();
pts->InsertNextPoint(1,1,1);
...
pts->InsertNextPoint(5,5,5);
vtkPolyData *polydata = vtkPolyData::New();
polydata->Allocate();
vtkIdType connectivity[2];
connectivity[0] = 0;
connectivity[1] = 3;
polydata->InsertNextCell(VTK_LINE,2,connectivity); //Connects the first and fourth point we inserted into a line
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInput(polydata);
// And so on, need actor and renderer now
There are plenty of examples on the documentation site for all the classes
Here is vtkPoints : http://www.vtk.org/doc/release/5.4/html/a01250.html
If you click on the vtkPoints (Tests) link, you can see the tests associated with the class. It provides a bunch of different sample code.
Also, the vtk mailing list is probably going to be much more useful than stack overflow.