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: 8504 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-09 15:24:06 +0100 (Di, 09. Feb 2010) $                   *
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     _object = 0;
00089     return false;
00090   }
00091 
00092   BaseObject* object = objectRoot()->childExists( _identifier );
00093   _object = dynamic_cast< TriMeshObject* >(object);
00094   return ( _object != 0 );
00095 }
00096 
00097 // ===============================================================================
00098 // ===============================================================================
00099 
00100 
00101 bool getMesh(  int _identifier , TriMesh*& _mesh ) {
00102 
00103   if ( _identifier == -1 ) {
00104     _mesh = 0;
00105     return false;
00106   }
00107 
00108   BaseObject* object = objectRoot()->childExists( _identifier );
00109 
00110   // Unable to find object
00111   if ( object == 0)
00112     return false;
00113 
00114   TriMeshObject* triangleMeshObject = dynamic_cast< TriMeshObject* > (object);
00115 
00116   // Object is not a triangle mesh
00117   if ( triangleMeshObject == 0)
00118     return false;
00119 
00120   _mesh = triangleMeshObject->mesh();
00121   return true;
00122 }
00123 
00124 
00125 // ===============================================================================
00126 // Getting data from objects and casting between them
00127 // ===============================================================================
00128 
00129 TriMesh* triMesh( BaseObjectData* _object ) {
00130   
00131   if ( _object == 0 )
00132     return 0;
00133 
00134   if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
00135     TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
00136     return object->mesh();
00137   } else
00138     return 0;
00139 }
00140 
00141 TriMeshObject* triMeshObject( BaseObjectData* _object ) {
00142   if ( _object == 0 )
00143     return 0;
00144 
00145   if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
00146     return 0;
00147   return dynamic_cast< TriMeshObject* >( _object );
00148 }
00149 
00150 
00151 TriMeshObject* triMeshObject( int _objectId ) {
00152   if  (_objectId == -1)
00153     return 0;
00154   
00155   BaseObject* object = objectRoot()->childExists( _objectId );
00156   
00157   if ( object == 0 )
00158     return 0;
00159   
00160   TriMeshObject* meshObject = dynamic_cast< TriMeshObject* >(object);
00161   
00162   return meshObject;
00163 }
00164 
00165 
00166 }

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