The Queen has opened Cardiff University's new £44m Brain Research Imaging Centre (Cubric).
It has been called the "most significant advance in brain imaging in Europe in the last 10 years".
The Maindy Park building brings together four hi-tech scanners under one roof.
One of them, described as the "Hubble space telescope of neuroscience". is the first outside the United States.
The Queen and the Duke of Edinburgh were given a tour of the Cubric centre, which is the biggest of its kind in Europe and one of the best equipped in the world.
Although not the largest, the most sophisticated at the centre is the Connectom scanner. It is six times more powerful than a conventional hospital MRI scanner.
The Queen asked: "Strokes vary the brain, is that correct?"
Prof Derek Jones, director of Cubric, agreed and said one of the machine's functions would be to research how a damaged brain's behaviour could be studied to improve rehabilitation.
The Queen, who described the technology as "fascinating, said: "To know what goes on in the brain is extraordinary, I think."
Earlier, the royal couple watched children playing mind games with one another.
The Duke watched two youngsters engaged in a gaming battle, using only electrical brain signals picked up by sensors on their heads, to move a ball suspended in the air.
He put his fists up like a prize-fighter to the duelling children, earning smiles.
Philip also got a laugh from tattooed neuroscientist Mark Drakesmith, pointing to his inked arms and saying: "After undergoing all that, I'm surprised you can feel anything."
And he quipped to a group of school pupils "you must have really good brains to speak Welsh" as the royals were shown around.
There has already been interest from across Europe, China and America from scientists who want to use the facility.
The brain relies on exchanging information being passed along tiny wires - forming what is called white matter.
These fibres have an internal diameter about 25 times thinner than a strand of human hair.
Prof Jones said it would help provide "precision medicine" so scientists can examine the brain's connections in detail.
"For a long time we've wanted to zoom in and start to look at the inner diameter of these fibres," he said.
"If we can see differences in these, we can explain differences in how quickly the brain can process information and what goes wrong in a range of disorders including multiple sclerosis, dementia, psychosis and depression."
As well as studying causes of disease, the centre hopes it will help our understanding of the healthy brain and what makes some people perform better than others.
The Queen visited the university after opening the fifth Welsh Assembly at the Senedd in Cardiff Bay.
ANALYSIS by Owain Clarke, BBC Wales health correspondent
Arguably the best equipped brain imaging centre in the world is now located in the Welsh capital.
The "jewel in the crown" is undoubtedly the Connectom scanner, which allows scientists to study the movement of water molecules in brain cells to create the most accurate picture possible of the biology behind how the brain is wired together.
It is hoped it and the other state of the art scanners and equipment will help researchers develop new and precise treatment and therapies for diseases like dementia, multiple sclerosis, psychosis and depression.
But it is not only the technology inside that is impressive but also the new building's design.
The scanners weigh up to 40 tonnes.
If any of them become superseded by more advanced models (not expected to happen for at least a decade) then the walls have been built so they can be removed easily to make room for newer technology.
Although patients will not be coming here for diagnosis and will still go to hospital, many will be asked to come here to take part in research projects.
The space has been made appealing and comfortable for those taking part in trials and studies. This was also a key consideration in the building's design. Along with beds and consulting rooms for patients, there is even a children's play area.
The £44m centre is biggest investment in a single project in Cardiff University's history - paid for not only by the university itself but also by tens of millions of pounds of grants from medical research bodies and the Welsh Government.
Deciding to commit so much money to a single project is in one sense is a gamble.
Other departments in the university may lose out.
Also it is one thing to have some of the most sophisticated brain scanners in the world at your disposal - it is another to make sure they are used to their full potential.
In that respect the team in Cardiff wants to encourage more people to take part in the research at Cubric. The more volunteers, it is argued, the better the chance of making a big breakthrough that could help unlock the secrets of the brain.