VR-Forces 4.0.4 Class Documentation
include/vrvCore/DtIntersector.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 2008 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 /******************************************************************************
00006 ** $RCSfile: DtIntersector.h,v $ $Revision: 1.9 $ $State: Exp $
00007 ******************************************************************************/
00008 
00013 
00014 #pragma once
00015 #include <vrvCore/vrvCore.h>
00016 #include <vrvCore/DtUniqueID.h>
00017 #include <vrvUtil/DtVirtualBaseClass.h>
00018 #include <boost/unordered_map.hpp>
00019 #include <vector>
00020 
00021 namespace makVrv
00022 {   
00023    class DtDe;
00024    class DtChannel;
00025 
00028    class DT_DLL_VRVCORE DtIntersectorResult
00029    {
00030    public:
00031       // For this purpose, a triangle is described as 9 doubles; x0, y0, z0,
00032       // x1, x2, etc...
00033       typedef std::vector<double> DtIntersectTriangle;
00034 
00035    public:
00037       DtIntersectorResult();
00038 
00040       DtIntersectorResult( double x, double y, double z, 
00041          double normalX, double normalY, double normalZ, const DtUniqueID& id);
00042 
00044       DtIntersectorResult( const DtIntersectorResult& orig );
00045 
00047       DtIntersectorResult& operator=( const DtIntersectorResult& orig );
00048 
00050       bool operator==(const DtIntersectorResult&) const;
00051 
00053       bool operator!=(const DtIntersectorResult& rhs) const
00054       {
00055          return !(*this == rhs);
00056       }
00057 
00058    public:
00059 
00061       double x;
00062 
00064       double y;
00065 
00067       double z;
00068 
00071       double normalX;
00072 
00075       double normalY;
00076 
00079       double normalZ;
00080      
00082       DtUniqueID id;
00083 
00085       DtIntersectTriangle isectTriangle;
00086    };
00087 
00091    class DT_DLL_VRVCORE DtIntersector
00092    {
00093    public:
00094 
00097       enum IntersectProperties 
00098       {
00099          AllNodes = 0,
00100          PickableNodes = 1,
00101          SupportNodes = 2,
00102          NodesThatReceivesShadows = 4,
00103          NodesThatCastsShadows = 8
00104       };
00105 
00107       typedef std::vector<DtIntersectorResult> DtIntersections;
00108 
00110       DtIntersector( DtDe& de );
00111 
00113       virtual ~DtIntersector();
00114 
00129       virtual bool findNearestIntersectionToPoint(double x, double y, double z,
00130          double vx, double vy, double vz, DtIntersectorResult& intersection,
00131          IntersectProperties properties = AllNodes, 
00132          std::vector<DtElementID>* ignoreList = 0, bool returnTriangle = false,
00133          double maxIsectorLength = -1., bool useHighLod = false ) = 0;
00134 
00142       virtual bool findAllIntersectionsThroughPoint( double x, double y, double z,
00143          double vx, double vy, double vz, DtIntersections& intersections, 
00144          IntersectProperties properties = AllNodes, 
00145          std::vector<DtElementID>* ignoreList = 0, bool sort = true, 
00146          bool useHighLod = false ) = 0;
00147 
00154       virtual bool findFirstIntersectWithLineSegment( 
00155          double x, double y, double z, double end_x, double end_y, double end_z,
00156          DtIntersectorResult& intersection, 
00157          IntersectProperties properties=AllNodes, 
00158          std::vector<DtElementID>* ignoreList=0, 
00159          bool useHighLod = false) = 0;
00160 
00167       virtual bool findAllIntersectWithLineSegment( 
00168          double x, double y, double z, double end_x, double end_y, double end_z,
00169          DtIntersections& intersections, 
00170          IntersectProperties properties=AllNodes, 
00171          std::vector<DtElementID>* ignoreList=0, bool sort=true, 
00172          bool useHighLod = false ) = 0;
00173 
00179       virtual bool pick( DtChannel& channel, double mx, double my, 
00180          DtIntersectorResult& intersection, 
00181          IntersectProperties properties=AllNodes, 
00182          std::vector<DtElementID>* ignoreList=0) = 0;
00183 
00188       virtual bool pickAll( DtChannel* channel, double mx, double my, 
00189          DtIntersections& intersections, 
00190          IntersectProperties properties=AllNodes, 
00191          std::vector<DtElementID>* ignoreList=0) = 0;
00192 
00193    protected:
00194       DtDe& myDe;
00195 
00198       struct CachedPick
00199       {
00200          CachedPick()
00201          : simTime(0.0)
00202          , channel(0)
00203          , mx(0)
00204          , my(0)
00205          , properties(DtIntersector::AllNodes)
00206          , ignoreList(0)
00207          {
00208          }
00209 
00210          bool operator==(const CachedPick& b)
00211          {
00212             return simTime == b.simTime &&
00213                channel == b.channel &&
00214                mx == b.mx &&
00215                my == b.my &&
00216                properties == b.properties &&
00217                ignoreList == b.ignoreList;
00218          }
00219 
00220          double simTime;
00221          DtChannel* channel;
00222          double mx; 
00223          double my;
00224          IntersectProperties properties;
00225          std::vector<DtElementID>* ignoreList;
00226       };
00227 
00228       CachedPick myLastPick;
00229       bool myLastPickSucceeded;
00230       DtIntersectorResult myLastResult;
00231 
00232    };
00233 
00236    class DT_DLL_VRVCORE DtIntersectorManager : public DtVirtualBaseClass
00237    {
00238    public:
00239 
00242       static DtIntersectorManager& instance(DtDe& de);
00243 
00245       static void registerInstance(DtDe& de, DtIntersectorManager* anInstance);     
00246 
00248       DtIntersector& modelSetIntersector(int modelSet);
00249 
00250    protected:
00251       DtIntersectorManager(DtDe& de);
00252 
00253    protected:
00254       typedef boost::unordered_map<int, DtIntersector*> IntersectorMap;
00255       DtDe& myDe;
00256       IntersectorMap myIntersectors;
00257    };
00258 
00261    class DT_DLL_VRVCORE DtIntersectorCreator : public DtVirtualBaseClass
00262    {
00263    public:
00264 
00267       static DtIntersectorCreator& instance(DtDe& de);
00268 
00270       static void registerInstance(DtDe& de, DtIntersectorCreator* anInstance);     
00271 
00273       virtual DtIntersector* create( DtDe& de, int modelSet ) = 0;
00274    };
00275 }

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)