PluginFunctionsTriangleMesh.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 7468 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-19 09:45:05 +0200 (Mo, 19. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  Plugin Functions
00049 //
00050 //=============================================================================
00051 
00052 #include <OpenFlipper/common/Types.hh>
00053 
00054 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
00055 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00056 
00057 namespace PluginFunctions {
00058 
00059 bool getSourceMeshes( std::vector<TriMesh*>& _meshes  ) {
00060   _meshes.clear();
00061 
00062   for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
00063     if (! o_it->source() )
00064       continue;
00065     _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
00066   }
00067 
00068   return (_meshes.size() > 0 );
00069 }
00070 
00071 bool getTargetMeshes( std::vector<TriMesh*>& _meshes  ) {
00072   _meshes.clear();
00073 
00074   for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
00075     if (! o_it->target() )
00076       continue;
00077     if ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() )
00078       _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
00079   }
00080 
00081   return (_meshes.size() > 0 );
00082 }
00083 
00084 
00085 bool getObject(  int _identifier , TriMeshObject*& _object ) {
00086 
00087   if ( _identifier == -1 )
00088     return false;
00089 
00090   BaseObject* object = objectRoot()->childExists( _identifier );
00091   _object = dynamic_cast< TriMeshObject* >(object);
00092   return ( _object != 0 );
00093 }
00094 
00095 // ===============================================================================
00096 // ===============================================================================
00097 
00098 
00099 bool getMesh(  int _identifier , TriMesh*& _mesh ) {
00100 
00101   if ( _identifier == -1 )
00102     return false;
00103 
00104   BaseObject* object = objectRoot()->childExists( _identifier );
00105 
00106   // Unable to find object
00107   if ( object == 0)
00108     return false;
00109 
00110   TriMeshObject* triangleMeshObject = dynamic_cast< TriMeshObject* > (object);
00111 
00112   // Object is not a triangle mesh
00113   if ( triangleMeshObject == 0)
00114     return false;
00115 
00116   _mesh = triangleMeshObject->mesh();
00117   return true;
00118 }
00119 
00120 
00121 // ===============================================================================
00122 // Getting data from objects and casting between them
00123 // ===============================================================================
00124 
00125 TriMesh* triMesh( BaseObjectData* _object ) {
00126   if ( _object == 0 )
00127     return 0;
00128 
00129   if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
00130     TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
00131     return object->mesh();
00132   } else
00133     return NULL;
00134 }
00135 
00136 TriMeshObject* triMeshObject( BaseObjectData* _object ) {
00137   if ( _object == 0 )
00138     return 0;
00139 
00140   if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
00141     return NULL;
00142   return dynamic_cast< TriMeshObject* >( _object );
00143 }
00144 
00145 
00146 TriMeshObject* triMeshObject( int _objectId ) {
00147   if  (_objectId == -1)
00148     return 0;
00149   
00150   BaseObject* object = objectRoot()->childExists( _objectId );
00151   
00152   if ( object == 0 )
00153     return 0;
00154   
00155   TriMeshObject* meshObject = dynamic_cast< TriMeshObject* >(object);
00156   
00157   return meshObject;
00158 }
00159 
00160 
00161 }

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .