$search
00001 /* 00002 * Copyright (c) 2011, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #include "rviz_interaction_tools/mesh_object_switcher.h" 00031 #include "rviz_interaction_tools/mesh_object.h" 00032 00033 #include <OGRE/OgreMaterialManager.h> 00034 #include <OGRE/OgreTechnique.h> 00035 #include <OGRE/OgrePass.h> 00036 #include <OGRE/OgreEdgeListBuilder.h> 00037 00038 00039 namespace rviz_interaction_tools 00040 { 00041 00042 MeshObjectSwitcher::MeshObjectSwitcher( std::string valid_mat_name, 00043 std::string valid_sel_mat_name, 00044 std::string invalid_mat_name, 00045 std::string invalid_sel_mat_name ) : 00046 visible_mesh_(-1), 00047 valid_(true), 00048 selected_(false), 00049 valid_mat_name_(valid_mat_name), 00050 valid_sel_mat_name_(valid_sel_mat_name), 00051 invalid_mat_name_(invalid_mat_name), 00052 invalid_sel_mat_name_(invalid_sel_mat_name) 00053 { 00054 } 00055 00056 00057 MeshObjectSwitcher::~MeshObjectSwitcher() 00058 { 00059 } 00060 00061 00062 void MeshObjectSwitcher::addObject( MeshObject* mesh_object ) 00063 { 00064 mesh_object->setVisible(false); 00065 mesh_objects_.push_back( boost::shared_ptr<MeshObject>( mesh_object ) ); 00066 updateMaterials(); 00067 } 00068 00069 00070 void MeshObjectSwitcher::setSelected( bool selected ) 00071 { 00072 selected_ = selected; 00073 updateMaterials(); 00074 } 00075 00076 void MeshObjectSwitcher::setValid( bool valid ) 00077 { 00078 valid_ = valid; 00079 updateMaterials(); 00080 } 00081 00082 00083 void MeshObjectSwitcher::setVisible( unsigned index ) 00084 { 00085 if ( visible_mesh_ < mesh_objects_.size() ) 00086 { 00087 ROS_INFO_STREAM( "Hiding mesh " << visible_mesh_ ); 00088 mesh_objects_[visible_mesh_]->setVisible(false); 00089 } 00090 00091 if ( index < mesh_objects_.size() ) 00092 { 00093 ROS_INFO_STREAM( "Showing mesh " << index << "." 00094 << " Entity: " << mesh_objects_[index]->getEntity()->getName() 00095 << " Mesh: " << mesh_objects_[index]->getEntity()->getMesh()->getName() 00096 << " Triangles: " << mesh_objects_[index]->getEntity()->getMesh()->getEdgeList()->triangles.size() 00097 ); 00098 mesh_objects_[index]->setVisible(true); 00099 } 00100 00101 visible_mesh_ = index; 00102 } 00103 00104 void MeshObjectSwitcher::next() 00105 { 00106 setVisible( (visible_mesh_ + 1) % mesh_objects_.size() ); 00107 } 00108 00109 void MeshObjectSwitcher::updateMaterials() 00110 { 00111 for ( unsigned i=0; i<mesh_objects_.size(); ++i ) 00112 { 00113 if ( valid_ && selected_ ) 00114 { 00115 mesh_objects_[i]->setMaterialName( valid_sel_mat_name_ ); 00116 } 00117 else if ( valid_ ) 00118 { 00119 mesh_objects_[i]->setMaterialName( valid_mat_name_ ); 00120 } 00121 else if ( selected_ ) 00122 { 00123 mesh_objects_[i]->setMaterialName( invalid_sel_mat_name_ ); 00124 } 00125 else 00126 { 00127 mesh_objects_[i]->setMaterialName( invalid_mat_name_ ); 00128 } 00129 } 00130 } 00131 00132 }