What you need to keep in mind is the idea of restrictive versus non-restrictive clauses, which translates to "necessary" versus "helpful but non-essential."
In a sentence such as "The company that invented the microchip we use invited us to a demonstration," the word "that" is relative to "company." There are thousands of companies in the world, but it is important to know the "company that invented the microchip" is specifically the one holding the demonstration. In that sense, the relative clause beginning with 'that' would be considered restrictive, since it is an essential piece of information that identifies the company. You would not write "The company which invented the microchip invited us to a demonstration." in formal writing.
'Which' could be used in a similar sentence constructed this way: "Widgets Incorporated, which invented the microchip we use, has officially declared bankruptcy." In this sentence, the relative clause 'which invented the microchip we use' is separated by commas. The information about the microchip is useful, but not essential to the main idea of the sentence. It could be removed and the sentence would still make sense. If the relative clause can be removed without changing the sentence's meaning, it would be considered non-restrictive.
"The storage building that once stood on the corner has collapsed," would be correct, since the relative clause 'that once stood on the corner' is restrictive and essential. The information about the building's location is essential, so it would need a restrictive clause beginning with "that." A correct sentence using "which" would read like this: "The Olsen building, which stood on the corner of 12th and Vine Streets, has been torn down." The sentence could still be understood without the non-restrictive clause beginning with 'which'.
In short, whenever the information is essential to identifying the subject, the proper pronoun to use is 'that'. If the information is not essential, or can be set apart with commas, then the pronoun 'which' is more likely to be correct.
If the meaning of the sentence would be lost without the information, then it is most likely restrictive and 'that' would be the proper pronoun to use.
Sadly, 'Thinking capacity' is no longer a criterion for reliably distinguishing humans from chimpanzees. Correct grammar will always stand the test of time in that regard.