Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!

Brother Bob

Member Since 26 Nov 2001
Offline Last Active Yesterday, 05:59 PM

#5039105 "const wchar_t" is incompatible with parameter of type "LPCSTR"

Posted by Brother Bob on 04 March 2013 - 12:38 PM

Sounds like your program simply isn't consistent with what character set it uses. Proper text handling of almost any kind is not trivial as soon as different encodings comes into play. It seems like your code consists of a mix of narrow and wide characters/strings, and mixing text encodings can be a real problem.


Decide on one single encoding for your entire program, and stick with it everywhere. If you need to handle text in different encodings, then make helper functions that converts text between the proper encoding and your program's encoding. But ultimately, your core program should not handle more than one encoding.

#5039088 "const wchar_t" is incompatible with parameter of type "LPCSTR"

Posted by Brother Bob on 04 March 2013 - 11:34 AM

Select Properties in the Project menu. Then, under Configuration Properties and General, change the parameter Character Set to Use Unicode Character Set.

#5038404 Basic question

Posted by Brother Bob on 02 March 2013 - 06:41 AM

Store the words in a map of <string, int>. the first time you insert a word, store 1. If the word is already in the map, increment the integer.

It's even easier that that, because you don't even need special logic to handle the first insert. The map value constructs its content if the key is not present, and integers value initializes to zero, so just go ahead and increment at all times. Thus, just use the [] operator and increment it; if the key doesn't exist it is value initialized to zero before proceeding to increment it to one and everything is fine.

#5038380 passing 2D array to struct

Posted by Brother Bob on 02 March 2013 - 05:39 AM

Declare your filenames field as follows:

struct myStruct {
    char (*filenames)[48];

#5036477 What is the purpose of std::array?

Posted by Brother Bob on 25 February 2013 - 04:04 PM

Try passing int a[10] to a function and getting its size wink.png
You can do something like this:

template <typename T>
void printAll(const T& v)
    for (auto& value : v)
        std::cout << value << std::endl;
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!
Edit: Also, check out this article

You may want to reconsider that example. The array is passed by reference and for for-each statement works with array types, so you can in fact pass an array and have it print all its values.

#5036392 Matrix inversion

Posted by Brother Bob on 25 February 2013 - 12:13 PM

Your matrix is very badly conditioned and will be extremely sensitive to numerical errors. If you want the same results as Matlab, then you're simply going to have to do the same calculations as Matlab.


As far as I remember, the Gauss-Jordan method is one of the worst general matrix inversion algorithms when it comes to numerical precision. You really need to feed it well-conditioned matrices for it to work.

#5035360 Searching closest color using manhattan distance on RGB

Posted by Brother Bob on 22 February 2013 - 05:16 AM

The solution is the surface of a symmetric diamond-shape centered at the origin with size d. Have two nested for-loops for the first two coordinates, let's call them A, and B, and solve A+B+C=d for the third coordinate C. That will give you the points on the diamond-shaped solution for one octant in 3D-space. Then apply all eight negation permutations to obtain the points for the remaining octants.

for(int A=0; A<=d; ++A)
    for(int B=0; B<=d-A; ++B)
        add solution ( A,  B,  d-A-B)
        add solution ( A,  B, -d-A-B)
        add solution ( A, -B,  d-A-B)
        add solution ( A, -B, -d-A-B)
        add solution (-A,  B,  d-A-B)
        add solution (-A,  B, -d-A-B)
        add solution (-A, -B,  d-A-B)
        add solution (-A, -B, -d-A-B)

Hope I got the math correct here, it may be off by one somewhere. You may also need to adjust the loops to eliminate duplicates at the end of the loop ranges, since, for example, A=-A when A=0 and so half the points will be the same for that iteration.

#5034743 glreadpixels don't work

Posted by Brother Bob on 20 February 2013 - 04:04 PM

Thanks for your reply.

I don't need to specify the size of the cvMat.The default constructor allocates enough space.

I will set the manification filter. Don't you see any other problem ?

I don't see anything obvious, no.

I write to write glreadpixels to a file, it only writes when it is specified as GLRGBA, and doesnt work with GLRGB...

Is the shader is a problem ? Should I disable it before glreadpixesl ?

The shaders do not affect glReadPixels.

#5034627 Check My Normal Calculations functions? Please?

Posted by Brother Bob on 20 February 2013 - 11:24 AM

Yes, that will make two vectors from a to b and c, respectively. The cross product looks to be all right as well.

#5034617 Check My Normal Calculations functions? Please?

Posted by Brother Bob on 20 February 2013 - 11:06 AM

The vector from a to b is b-a, but you're calculating a-b. Similarly for a and c. This will result in a negated normal.

#5034609 A question on style regarding includes (C++)

Posted by Brother Bob on 20 February 2013 - 10:37 AM

Instead of having using-statements in the header file, use the fully qualified name. That is, do this:

#include <vector>
void myFunc(std::vector<myClass> const &);

and not this:

#include <vector>
using namespace std;
void myFunc(vector<myClass> const &);

#5034608 glreadpixels don't work

Posted by Brother Bob on 20 February 2013 - 10:34 AM

Don't you have to specify the size and the format of the image before passing its pointer to glReadPixels, or does the cv::Mat class default constructor allocate enough storage space to acomodate a 1024x1024 RGB image? Also, if you're creating a new texture object, then you need to set the minification filter to a non-mipmap filter or generate all mipmap levels, or you will have an incomplete texture object.

#5034596 A question on style regarding includes (C++)

Posted by Brother Bob on 20 February 2013 - 09:55 AM

You shouldn't have any using-statements at file-scope in a header file at all. Either limit the scope so that the using-statement does not extend into the full scope of the translation unit, or fully qualify any name in the header file.

#5034307 A question on style regarding includes (C++)

Posted by Brother Bob on 19 February 2013 - 04:35 PM

If he meant, "MainDialog.h includes BaseWidget.h, but not SpecificWidget.h, and MainDialog.cpp would include SpecificWidget.h, which in-turn includes BaseWidget.h", that makes sense. But SpecificWidget.h must include BaseWidget.h if it inherits it, afaik.

That's correct. MainDialog only depends on SpecificWidget, so there is no reason why MainDialog should include anything else. If SpecificWidget itself has to include something to work is not MainDialog's problem. For what it's worth, there may not even be a BaseWidget header but that SpecificWidget defines it itself. Either way, MainDialog has no reason to care how exactly SpecificWidget defines itself, only that it is defined.


That is the "one level of indirection"; only include the direct dependencies, and let the dependencies sort out their own dependencies themselves.

#5033808 Help with getting the change in x,y,z coordinate in 3d space!

Posted by Brother Bob on 18 February 2013 - 10:53 AM

You should get familiar with linear algebra. This becomes a fairly trivial with vectors and matrices.


Each bone can simply be defined as having location in the coordinate frame of its parent bone and a transformation that this bone applies. That will uniquely define the entire bone structure. In addition to that, you can add any information you want to the bones, of course.


Your choice of bone names is a little bit off for the sake of explaining the situation and to extend the explanation to more bones, so let's say instead that bone A is the first bone, bone B is attached to bone A, and bone C is attached to bone B, and so on. Each bone has a position p (a vector) and an orientation R (a rotation matrix). Let's say that each bone also has a translation matrix T that simply corresponds to a translation matrix by its position p. For example, A.R is the rotation matrix of bone A, and B.T is the translation matrix for bone B, and so on.


At this point, finding the orientation and location of any bone in an arbitrary chain of bones becomes fairly trivial. To determine a bone's parent transformations, you simply multiply all its parent transformations.

  • The bone A is the parent bone and is thus not subject to any prior transformations. Its location is A.p and its orientation is A.R, so you can use these matrices to draw the bone itself.
  • The bone B has the bone A as its parent. Its location is B.p in A's coordinate frame, and so its location becomes (A.T * A.R) * B.p.
  • The bone C has the bone B as its parent. Its location is C.p in B's coordinate frame, and so its location becomes ((A.T * A.R) * B.T * B.R) * C.p.
  • The bone D has the bone C as its parent. Its location is D.p in C's coordinate frame, and so its location becomes (((A.T * A.R) * B.T * B.R) * C.T * C.R) * D.p.
  • And so on...

In your case, you would have defined the bones as follows:

  1. A.p = (0,0,30)
  2. A.R = rotation matrix of 45 degrees
  3. B.p = (0,0,15)
  4. B.R = rotation matrix of 0 degrees

Note that bone B (which is bone A in your picture) does not have any rotation on its own; its rotation comes from its parent bone A (bone B in your picture).


Note that, depending on which conventions you choose for your linear algebra, you may have to change the order of the translation and the rotation matrices, multiply child bones on the left side, and/or multiply the position vector on the left side instead.