DeformableShape.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __DEFORMABLESHAPE_H__
00030 #define __DEFORMABLESHAPE_H__
00031 
00032 #include "X3DShapeNode.h"
00033 #include "Coordinate.h"
00034 #include "X3DComposedGeometryNode.h"
00035 #include "H3DCoordinateDeformerNode.h"
00036 
00037 namespace H3D {
00038 
00063   
00064   class H3DAPI_API DeformableShape : public X3DShapeNode {
00065   public:
00066     typedef TypedSFNode< Coordinate > SFCoordinateNode;
00067     typedef TypedSFNode< H3DCoordinateDeformerNode > SFCoordinateDeformer;
00068     
00071     class SFGeometryNode: public X3DShapeNode::SFGeometryNode {
00072 
00077       ~SFGeometryNode() {
00078         value = NULL;
00079       }
00080 
00081       virtual void onAdd( Node *n ) {
00082         X3DComposedGeometryNode *cg = 
00083           dynamic_cast< X3DComposedGeometryNode * >( n );
00084         if( !cg ) {
00085           stringstream s;
00086           s << "Expecting X3DComposedGeometryNode";
00087           throw InvalidNodeType( n->getTypeName(),
00088                                  s.str(),
00089                                  H3D_FULL_LOCATION );
00090         }
00091         
00092         X3DShapeNode::SFGeometryNode::onAdd( n );
00093         DeformableShape *dg = 
00094           static_cast< DeformableShape * >( getOwner() );
00095         if( n  ) {
00096           Coordinate *cg_coord = 
00097             dynamic_cast< Coordinate * >( cg->coord->getValue() ); 
00098           Coordinate *dg_orig_coord = dg->origCoord->getValue(); 
00099           Coordinate *dg_deformed_coord = dg->deformedCoord->getValue(); 
00100           Coordinate *dg_resting_coord = dg->restingCoord->getValue(); 
00101           if( cg_coord ) {
00102             if( dg_orig_coord ) {
00103               dg_orig_coord->point->setValue( cg_coord->point->getValue() ); 
00104             }
00105             if( dg_deformed_coord ) {
00106               dg_deformed_coord->point->setValue( cg_coord->point->getValue() ); 
00107             }
00108             if( dg_resting_coord ) {
00109               dg_resting_coord->point->setValue( cg_coord->point->getValue() ); 
00110             }
00111           }
00112         }
00113       }
00114     };
00115 
00117     DeformableShape( Inst< SFAppearanceNode > _appearance     = 0,
00118                      Inst< SFGeometryNode   > _geometry       = 0,
00119                      Inst< SFHapticGeometry > _hapticGeometry = 0,
00120                      Inst< SFNode           > _metadata       = 0,
00121                      Inst< SFBound          > _bound          = 0,
00122                      Inst< SFVec3f          > _bboxCenter     = 0,
00123                      Inst< SFVec3f          > _bboxSize       = 0,
00124                      Inst< SFCoordinateNode > _origCoord      = 0,
00125                      Inst< SFCoordinateNode > _restingCoord   = 0,
00126                      Inst< SFCoordinateNode > _deformedCoor   = 0,
00127                      Inst< SFCoordinateDeformer > _deformer   = 0 );
00128 
00129 #ifdef USE_HAPTICS
00132     virtual void traverseSG( TraverseInfo &ti );
00133 #endif
00134 
00141     auto_ptr< SFCoordinateNode > origCoord;
00142 
00148     auto_ptr< SFCoordinateNode > restingCoord;
00149 
00155     auto_ptr< SFCoordinateNode > deformedCoord;   
00156 
00160     auto_ptr< SFCoordinateDeformer > deformer;   
00161 
00163     static H3DNodeDatabase database;
00164   };
00165 }
00166 
00167 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5