10 #include <OGRE/OgreMaterialManager.h> 11 #include <OGRE/OgreTextureManager.h> 12 #include <OGRE/OgreTechnique.h> 14 #include <OGRE/OgreVector3.h> 15 #include <OGRE/OgreSceneNode.h> 16 #include <OGRE/OgreSceneManager.h> 17 #include <OGRE/OgreManualObject.h> 32 frameNode_ = parentNode->createChildSceneNode();
43 Ogre::MaterialManager::getSingleton().remove(
material_->getName());
57 bool flatColor,
bool noColor, Ogre::ColourValue meshColor,
bool mapLayerColor,
58 std::string colorLayer,
bool useRainbow,
bool invertRainbow,
59 Ogre::ColourValue minColor, Ogre::ColourValue maxColor,
60 bool autocomputeIntensity,
float minIntensity,
float maxIntensity)
63 ROS_DEBUG(
"Unable to visualize grid map, no map data. Use setMessage() first!");
69 if (layerNames.size() < 1) {
70 ROS_DEBUG(
"Unable to visualize grid map, map must contain at least one layer.");
73 if ((!flatTerrain && !
map_.
exists(heightLayer)) || (!noColor && !flatColor && !
map_.
exists(colorLayer))) {
74 ROS_DEBUG(
"Unable to visualize grid map, requested layer(s) not available.");
84 if (rows < 2 || cols < 2) {
85 ROS_DEBUG(
"GridMap has not enough cells.");
94 static uint32_t count = 0;
96 ss <<
"Mesh" << count++;
104 material_->getTechnique(0)->setLightingEnabled(
true);
105 material_->setCullingMode(Ogre::CULL_NONE);
109 size_t nVertices = 4 + 6 * (cols * rows - cols - rows);
119 size_t nLines = 2 * (rows * (cols - 1) + cols * (rows - 1));
124 if (autocomputeIntensity && !flatColor && !mapLayerColor) {
125 minIntensity = colorData.minCoeffOfFinites();
126 maxIntensity = colorData.maxCoeffOfFinites();
132 for (
size_t i = 0; i < rows - 1; ++i) {
133 for (
size_t j = 0; j < cols - 1; ++j) {
134 std::vector<Ogre::Vector3> vertices;
135 std::vector<Ogre::ColourValue> colors;
136 for (
size_t k = 0; k < 2; k++) {
137 for (
size_t l = 0; l < 2; l++) {
143 float height = heightData(index(0), index(1));
144 vertices.push_back(Ogre::Vector3(position(0), position(1), flatTerrain ? 0.0 : height));
146 float color = colorData(index(0), index(1));
147 Ogre::ColourValue colorValue;
149 Eigen::Vector3f colorVectorRGB;
151 colorValue = Ogre::ColourValue(colorVectorRGB(0), colorVectorRGB(1), colorVectorRGB(2));
158 colors.push_back(colorValue);
164 if (vertices.size() > 2) {
165 Ogre::Vector3 normal = vertices.size() == 4
166 ? (vertices[3] - vertices[0]).crossProduct(vertices[2] -vertices[1])
167 : (vertices[2] - vertices[1]).crossProduct(vertices[1] - vertices[0]);
171 for (
size_t m = 1; m < vertices.size() - 1; m++) {
174 Ogre::ColourValue color = flatColor ? meshColor : colors[m-1];
179 color = flatColor ? meshColor : colors[m];
184 color = flatColor ? meshColor : colors[m+1];
195 if (vertices.size() == 3) {
218 material_->getTechnique(0)->setLightingEnabled(
false);
220 if (alpha < 0.9998) {
221 material_->getTechnique(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
222 material_->getTechnique(0)->setDepthWriteEnabled(
false);
224 material_->getTechnique(0)->setSceneBlending(Ogre::SBT_REPLACE);
225 material_->getTechnique(0)->setDepthWriteEnabled(
true);
247 intensity = std::min(intensity, max_intensity);
248 intensity = std::max(intensity, min_intensity);
249 intensity = (intensity - min_intensity) / (max_intensity - min_intensity);
255 intensity = std::min(intensity, 1.0
f);
256 intensity = std::max(intensity, 0.0
f);
258 float h = intensity * 5.0f + 1.0f;
261 if (!(i & 1)) f = 1 - f;
264 Ogre::ColourValue color;
265 if (i <= 1) color[0] = n, color[1] = 0, color[2] = 1;
266 else if (i == 2) color[0] = 0, color[1] = n, color[2] = 1;
267 else if (i == 3) color[0] = 0, color[1] = 1, color[2] = n;
268 else if (i == 4) color[0] = n, color[1] = 1, color[2] = 0;
269 else if (i >= 5) color[0] = 1, color[1] = n, color[2] = 0;
276 Ogre::ColourValue max_color)
278 intensity = std::min(intensity, 1.0
f);
279 intensity = std::max(intensity, 0.0
f);
281 Ogre::ColourValue color;
282 color.r = intensity * (max_color.r - min_color.r) + min_color.r;
283 color.g = intensity * (max_color.g - min_color.g) + min_color.g;
284 color.b = intensity * (max_color.b - min_color.b) + min_color.b;
boost::shared_ptr< rviz::BillboardLine > meshLines_
Ogre::SceneManager * sceneManager_
bool getPosition(const Index &index, Position &position) const
void setBasicLayers(const std::vector< std::string > &basicLayers)
void setFramePosition(const Ogre::Vector3 &position)
void computeVisualization(float alpha, bool showGridLines, bool flatTerrain, std::string heightLayer, bool flatColor, bool noColor, Ogre::ColourValue meshColor, bool mapLayerColor, std::string colorLayer, bool useRainbow, bool invertRainbow, Ogre::ColourValue minColor, Ogre::ColourValue maxColor, bool autocomputeIntensity, float minIntensity, float maxIntensity)
void normalizeIntensity(float &intensity, float minIntensity, float maxIntensity)
Ogre::MaterialPtr material_
Ogre::ColourValue getRainbowColor(float intensity)
void convertToDefaultStartIndex()
bool isValid(const Index &index) const
bool exists(const std::string &layer) const
Ogre::ManualObject * manualObject_
static bool fromMessage(const grid_map_msgs::GridMap &message, grid_map::GridMap &gridMap)
Ogre::ColourValue getInterpolatedColor(float intensity, Ogre::ColourValue minColor, Ogre::ColourValue maxColor)
double getResolution() const
const std::vector< std::string > & getLayers() const
std::vector< std::string > getLayerNames()
GridMapVisual(Ogre::SceneManager *sceneManager, Ogre::SceneNode *parentNode)
std::string materialName_
bool hasBasicLayers() const
void setFrameOrientation(const Ogre::Quaternion &orientation)
bool colorValueToVector(const unsigned long &colorValue, Eigen::Vector3i &colorVector)
Ogre::SceneNode * frameNode_
const Size & getSize() const
void setMessage(const grid_map_msgs::GridMap::ConstPtr &msg)