Registered Member
|
Hi, I am trying to use a MatrixBase addons/plugin header to add class-cast operators which will automatically convert a Vector3f, etc, to a float * when necessary. This function works just fine:
but if I try to add the const version:
and call it in either of the following ways
I get the following error (with MSVC2005 and eigen 2.current):
My hunch is that it's not working because of Eigen's cleverness in avoiding temporaries. I tried to stick in eval() but it made no difference. I can explicitly make a copy and use the non-const version, but then I have to change every call to glVertex/glNormal. Is there a way to do it in the operator? (I have been using eigen for a few days, and it is excellent - thank you!) |
Moderator
|
Hi Ryan,
small world Indeed, as you guessed the problem is that v1+v2 is on an expression of the addition, and so you have to evaluate it before sending it to opengl. I see two options: 1 - you explicitly call eval: glVertex3fv((v1+v2).eval()); 2 - you define new functions glVertex, glNormal, etc. taking Eigen's objects as arguments such that you would write: glVertex(v1+v2); See the attachment for a piece of code doing that for you. I'm thinking that I should clean/extend it to make it a new OpenGL module... |
Registered Member
|
Hi Gael! (Hope I'm not distracting you from any siggraph projects =)
OK, I don't like option 1) because I will have to change at least a thousand lines of code =) So, option 2) - I tried to include your header but got this:
This is what I am including:
Am I missing something? cheers, -RMS |
Moderator
|
indeed, actually this file comes from a copy/paste of a larger one. So you have to put it in the Eigen namespace. You probably also have to remove the short int specialization since it is not supported by default. If you need short ints then let me know, I'll send you the respective NumTraits specialization.
Finally if you don't want to change a single line of code you can extend this file with stuff like this: _WRAP_EIGEN_XPR(glVertex2fv) inline void glVertex2f(const Eigen::Matrix<float,2,1> & p) { glVertex2fv((const GLfloat*)p.data());} _WRAP_EIGEN_XPR(glVertex3fv) inline void glVertex3f(const Eigen::Matrix<float,3,1> & p) { glVertex3fv((const GLfloat*)p.data());} _WRAP_EIGEN_XPR(glVertex4fv) inline void glVertex4f(const Eigen::Matrix<float,4,1> & p) { glVertex4fv((const GLfloat*)p.data());} etc. |
Registered Member
|
RMS? For a while I thought, hey, we managed to convert Richard Stallman to C++...
Anyway, I'm based in Toronto too, so hi. (Just making a mental note of the Eigen users community in Toronto).
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
OK, I managed to get it to work by just adding overrides of glVertex3fv, etc.
I could not add the _WRAP_EIGEN_XPR(glVertex3fv) lines, because they caused errors in your glVertex() functions that called glVertex3fv. I'm totally clear on what _WRAP_EIGEN_XPR is for...will leaving it out cause any problems? Also, if I added _WRAP_EIGEN_XPR(glVertex3fv) and also renamed your glVertex3f function to glVertex3fv, I got an infinite recursion =) Anyway, I have what I need for now. I would offer to help you add an opengl wrapper (after siggraph deadline) but I'm not sure I know enough about C++ templates. Thanks for your help! bjacob: nope, not *that* RMS. I am at UofT CS, in the Bahen building. I have only been an eigen user for a few days, but I am a convert =) |
Registered Member
|
Great, I'm at the math dept so Bahen/Fields and my office is actually in ES.
Here's a talk I gave last year on Eigen at the CS dept: http://download.tuxfamily.org/eigen/sli ... n-2009.pdf
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]