Changeset 1344


Ignore:
Timestamp:
09/12/06 17:39:08 (18 years ago)
Author:
mattausch
Message:

worked on triangle processing. logical units will be created by grouping objects
using their visibility definitions.

Location:
GTP/trunk/Lib/Vis
Files:
2 added
36 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchy.h

    r1320 r1344  
    282282                        virtual void _updateBounds(bool recurse = true) = 0; 
    283283                         
    284                         /** bounding box of the node**/ 
     284                        /** bounding box of the node 
     285                        */ 
    285286                        AxisAlignedBox mAABB; 
    286287 
    287                         /** mounding box of all objects inside the node */ 
     288                        /** bounding box of all objects inside the node  
     289                        */ 
    288290                        AxisAlignedBox mWorldAABB; 
     291 
     292 
    289293                protected: 
    290294                        BvHierarchy * mOwner; 
     
    387391                { 
    388392                public: 
    389                         Leaf(BvHierarchy * owner, int level, AxisAlignedBox& aabb, Branch * parent): 
     393                        Leaf(BvHierarchy * owner, int level, AxisAlignedBox& aabb, Branch *parent): 
    390394                        Node(owner, level, aabb, parent)  
    391395                        {}; 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchy.cpp

    r1320 r1344  
    874874 
    875875/************************************************************************/ 
    876 /* BvHierarchy build functions                                               */ 
     876/*                BvHierarchy build functions                           */ 
    877877/************************************************************************/ 
    878878 
     
    11421142} 
    11431143 
    1144 BvHierarchy::Node * BvHierarchy::pqBuild(BvhPlaneEventList& events, int nObjects, AxisAlignedBox& aabb, BvHierarchy::Branch * parent) 
     1144BvHierarchy::Node * BvHierarchy::pqBuild(BvhPlaneEventList& events,  
     1145                                                                                 int nObjects, AxisAlignedBox& aabb,  
     1146                                                                                 BvHierarchy::Branch * parent) 
    11451147{ 
    11461148        SplitCandidatePQ pqueue; 
     
    13961398} 
    13971399 
     1400 
     1401 
    13981402/************************************************************************/ 
    1399 /* BvHierarchy rendering functions                                           */ 
     1403/*               BvHierarchy rendering functions                        */ 
    14001404/************************************************************************/ 
     1405 
    14011406 
    14021407//------------------------------------------------------------------------- 
     
    15601565} 
    15611566 
     1567 
    15621568void BvHierarchy::recFindNodesIn(const Sphere &sphere, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full) 
    15631569{ 
     
    15651571} 
    15661572 
     1573 
    15671574void BvHierarchy::recFindNodesIn(const PlaneBoundedVolume &volume, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full) 
    15681575{ 
     
    15701577} 
    15711578 
     1579 
    15721580void BvHierarchy::recFindNodesIn(const Ray &ray, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full) 
    15731581{ 
     
    15751583} 
    15761584 
     1585 
    15771586/************************************************************************/ 
    1578 /* BvHierarchy debug & helper functions                                      */ 
     1587/*              BvHierarchy debug & helper functions                    */ 
    15791588/************************************************************************/ 
    15801589 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp

    r1320 r1344  
    13911391} 
    13921392 
     1393 
     1394 
    13931395/************************************************************************/ 
    1394 /* KdTree rendering functions                                           */ 
     1396/*           KdTree rendering functions                                 */ 
    13951397/************************************************************************/ 
    13961398 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1323 r1344  
    10851085{ 
    10861086        VssRay::NewMail(); 
    1087          
    10881087        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    10891088 
     
    10931092        { 
    10941093                Intersectable *obj = *oit; 
    1095                  
    10961094                VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 
    10971095 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h

    r1184 r1344  
    1818class Mesh; 
    1919class KdLeaf; 
     20class Vector3; 
    2021 
    2122struct IndexedBoundingBox; 
     
    3233 
    3334/** Container for Mesh pointers primarily for the use within the kDTree and 
    34     BSP hierarchies */ 
     35    BSP hierarchies  
     36*/ 
    3537typedef vector<Intersectable *> ObjectContainer; 
    3638 
    3739/** Container for ViewCell pointers primarily for the use within the kDTree and 
    38     BSP hierarchies */ 
    39  
     40    BSP hierarchies  
     41*/ 
    4042typedef vector<ViewCell *> ViewCellContainer; 
    4143 
    4244/** Container for HierarchyNodes pointers primarily for the use within the kDTree and 
    4345    BSP hierarchies  
    44         */ 
     46*/ 
    4547typedef vector<HierarchyNode *> NodeContainer; 
    4648 
     
    5759 
    5860/** Container for ViewCell pointers primarily for the use within the kDTree and 
    59     BSP hierarchies */ 
    60  
     61    BSP hierarchies  
     62*/ 
    6163typedef vector<KdLeaf *> KdLeafContainer; 
    6264 
     65typedef std::map<int, Intersectable *> ObjectMap; 
    6366 
    64 typedef std::map<int, Intersectable *> ObjectMap; 
     67/// default vertex container for Mesh 
     68typedef std::vector<Vector3> VertexContainer; 
     69 
     70/// vertex index container 
     71//typedef std::vector<short> VertexIndexContainer; 
     72typedef std::vector<int> VertexIndexContainer; 
    6573 
    6674} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r1315 r1344  
    55#include "IntersectableWrapper.h" 
    66#include "BvHierarchy.h" 
     7#include "Triangle3.h" 
     8#include "Polygon3.h" 
    79 
    810 
     
    152154 
    153155 
    154 } 
     156void Exporter::ExportIntersectable(Intersectable *object) 
     157{ 
     158        switch (object->Type())  
     159        { 
     160        case Intersectable::MESH_INSTANCE: 
     161                ExportMeshInstance((MeshInstance *)object); 
     162                break; 
     163        case Intersectable::TRANSFORMED_MESH_INSTANCE: 
     164                ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object)); 
     165                break; 
     166        case Intersectable::VIEW_CELL: 
     167                ExportViewCell(dynamic_cast<ViewCell *>(object)); 
     168                break; 
     169        case Intersectable::KD_INTERSECTABLE: 
     170                ExportKdIntersectable(*(dynamic_cast<KdIntersectable *>(object))); 
     171                break; 
     172        case Intersectable::TRIANGLE_INTERSECTABLE: 
     173                { 
     174                        const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem(); 
     175 
     176                        VertexContainer vertices; 
     177                        vertices.push_back(triangle.mVertices[0]); 
     178                        vertices.push_back(triangle.mVertices[1]); 
     179                        vertices.push_back(triangle.mVertices[2]); 
     180 
     181                        Polygon3 poly(vertices); 
     182                        ExportPolygon(&poly); 
     183                        break; 
     184                } 
     185        default: 
     186                cerr << "Sorry the export for object type " << Intersectable::GetTypeName(object) << " is not available yet" << endl; 
     187                break; 
     188        } 
     189} 
     190 
     191void Exporter::ExportMeshInstance(MeshInstance *object) 
     192{ 
     193        // $$JB$$ 
     194        // in the future check whether the mesh was not already exported 
     195        // and use a reference to the that mesh instead 
     196        ExportMesh(object->GetMesh()); 
     197} 
     198 
     199 
     200void Exporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi) 
     201{ 
     202        Mesh mesh(*mi->GetMesh()); 
     203 
     204        Matrix4x4 m; 
     205        mi->GetWorldTransform(m); 
     206        mesh.ApplyTransformation(m); 
     207 
     208        ExportMesh(&mesh); 
     209} 
     210 
     211 
     212void Exporter::ExportViewCells(const ViewCellContainer &viewCells) 
     213{ 
     214        ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
     215 
     216        for (it = viewCells.begin(); it != it_end; ++ it) 
     217        { 
     218                ExportViewCell(*it); 
     219        } 
     220} 
     221 
     222 
     223 
     224} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h

    r1287 r1344  
    3030class KdIntersectable; 
    3131class BvHierarchy; 
     32class TransformedMeshInstance; 
     33 
    3234 
    3335class Exporter 
     
    9597 
    9698  virtual void  
    97   ExportViewCells(const ViewCellContainer &viewCells) = 0; 
     99  ExportViewCells(const ViewCellContainer &viewCells); 
     100   
    98101  virtual void  
    99102  ExportViewCell(ViewCell *viewCell) = 0; 
     103 
    100104  virtual void 
    101   ExportIntersectable(Intersectable *object) = 0; 
     105  ExportIntersectable(Intersectable *object); 
    102106 
    103107  virtual void  
     
    150154  void ExportKdIntersectable(const KdIntersectable &kdObj); 
    151155  bool ExportBvHierarchy(const BvHierarchy &bvHierarchy, const int maxPvs); 
     156 
     157  virtual void ExportMeshInstance(MeshInstance *mi); 
     158 
     159  virtual void 
     160  ExportTransformedMeshInstance(TransformedMeshInstance *mi); 
     161 
     162  virtual void ExportPolygon(Polygon3 *poly) = 0; 
    152163}; 
    153164  
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1329 r1344  
    450450                return mOspTree && mOspTree->GetRoot(); 
    451451        case BV_BASED_OBJ_SUBDIV: 
    452                 return mBvHierarchy && mOspTree->GetRoot(); 
     452                return mBvHierarchy && mBvHierarchy->GetRoot(); 
    453453        default: 
    454454        return false; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1328 r1344  
    1616struct Face; 
    1717 
     18 
    1819struct FaceParentInfo { 
    19   // intersectable 
    20   Intersectable *mObject; 
    21   // face index 
    22   int mFaceIndex; 
    23    
    24   FaceParentInfo(Intersectable *obj, 
    25                                  const int fi): 
    26         mObject(obj), 
    27         mFaceIndex(fi) 
    28   {} 
     20        /// intersectable 
     21        Intersectable *mObject; 
     22        /// face index 
     23        int mFaceIndex; 
     24 
     25        FaceParentInfo(Intersectable *obj, const int fi): 
     26        mObject(obj), mFaceIndex(fi) 
     27        {} 
    2928}; 
     29 
    3030 
    3131class Intersectable { 
     
    147147                } 
    148148        } 
     149 
     150        /** returns normal from the face with the specified index. 
     151                PROBLEM: Does not fit to all intersectable types (e.g., spheres) 
     152        */ 
     153        virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); } 
    149154}; 
    150155 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1328 r1344  
    99AxisAlignedBox3 TriangleIntersectable::GetBox() const 
    1010{        
    11         return mItem->GetBoundingBox(); 
     11        return mItem.GetBoundingBox(); 
    1212} 
    1313 
    1414 
    1515int TriangleIntersectable::CastRay(Ray &ray) 
    16 {       // TODO matt 
     16{        
     17        float nearestT = MAX_FLOAT; 
     18        float t; 
     19        Vector3 nearestNormal; 
     20 
     21        if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 
     22                nearestT = ray.intersections[0].mT; 
     23 
     24        const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal); 
     25 
     26        nearestT = t; 
     27 
     28        if ((hitCode == Ray::INTERSECTION) && (ray.GetType() == Ray::LOCAL_RAY)) 
     29        { 
     30                if (!ray.intersections.empty()) 
     31                { 
     32                        ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal, this, 0); 
     33                } 
     34                else 
     35                { 
     36                        ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal, this, 0)); 
     37                } 
     38                 
     39                return 1; 
     40        } 
     41 
    1742        return 0; 
    1843} 
     
    2348        return 1; 
    2449} 
    25    
    2650 
     51 
     52Vector3 TriangleIntersectable::GetNormal(const int idx) const 
     53{ 
     54        return mItem.GetNormal(); 
    2755} 
     56 
     57  
     58} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1328 r1344  
    44#include "AxisAlignedBox3.h" 
    55#include "Intersectable.h" 
     6#include "Triangle3.h" 
    67 
    78 
    89namespace GtpVisibilityPreprocessor { 
     10 
    911 
    1012struct VssRayContainer; 
     
    2426{ 
    2527public: 
    26         IntersectableWrapper(T *item); 
     28        IntersectableWrapper(T item); 
    2729 
    2830        /** Returns node associated with this instance.  
    2931        */ 
    30         T *GetItem() const; 
     32        T GetItem() const; 
    3133 
    3234        /** See get. 
    3335        */ 
    34         void SetItem(T *item); 
     36        void SetItem(T item); 
    3537 
     38 
     39        ///////////////////////////////////////////// 
    3640        //-- inherited functions from Intersectable 
    3741 
     
    4549   
    4650        int NumberOfFaces() const; 
    47         //int Type() const; 
    48  
     51         
    4952        int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,  
    5053                                                          GtpVisibilityPreprocessor::Vector3 &normal); 
     
    6063protected: 
    6164         
    62         T *mItem; 
     65        T mItem; 
    6366}; 
    6467 
    6568 
    6669template<typename T> 
    67 IntersectableWrapper<T>::IntersectableWrapper(T *item): 
     70IntersectableWrapper<T>::IntersectableWrapper(T item): 
    6871Intersectable(), mItem(item) 
    6972{ 
     
    7174 
    7275template<typename T> 
    73 void IntersectableWrapper<T>::SetItem(T *item) 
     76void IntersectableWrapper<T>::SetItem(T item) 
    7477{ 
    7578        mItem = item; 
     
    7780 
    7881template<typename T> 
    79 T *IntersectableWrapper<T>::GetItem() const 
     82T IntersectableWrapper<T>::GetItem() const 
    8083{  
    8184        return mItem;  
     
    120123template<typename T> 
    121124int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point, 
    122                                                                                                 Vector3 &normal) 
     125                                                                                                   Vector3 &normal) 
    123126{ 
    124127        return 0; 
     
    127130template<typename T> 
    128131int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point, 
    129                                                                                                            Vector3 &normal, 
    130                                                                                                            const Vector3 &viewpoint, 
    131                                                                                                            const int maxTries) 
     132                                                                                                                  Vector3 &normal, 
     133                                                                                                                  const Vector3 &viewpoint, 
     134                                                                                                                  const int maxTries) 
    132135{ 
    133136        return 0; 
     
    142145 
    143146 
    144 class KdIntersectable: public IntersectableWrapper<KdNode> 
     147class KdIntersectable: public IntersectableWrapper<KdNode *> 
    145148{ 
    146149public: 
    147150        KdIntersectable(KdNode *item): 
    148         IntersectableWrapper<KdNode>(item) {} 
     151        IntersectableWrapper<KdNode *>(item) {} 
    149152 
    150153        int Type() const 
     
    155158 
    156159 
    157 class BvhIntersectable: public IntersectableWrapper<BvhNode> 
     160class BvhIntersectable: public IntersectableWrapper<BvhNode *> 
    158161{ 
    159162public: 
    160163        BvhIntersectable(BvhNode *item): 
    161         IntersectableWrapper<BvhNode>(item) {} 
     164        IntersectableWrapper<BvhNode *>(item) {} 
    162165 
    163166        int Type() const 
     
    167170}; 
    168171 
     172 
    169173class TriangleIntersectable: public IntersectableWrapper<Triangle3> 
    170174{ 
    171175public: 
    172         TriangleIntersectable(Triangle3 *item): 
     176        TriangleIntersectable(Triangle3 item): 
    173177        IntersectableWrapper<Triangle3>(item) {} 
    174178 
    175179        int CastRay(Ray &ray); 
    176180        AxisAlignedBox3 GetBox() const; 
    177  
    178181        int NumberOfFaces() const; 
     182        Vector3 GetNormal(const int idx) const; 
    179183 
    180184        int Type() const 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1286 r1344  
    654654 
    655655                  if (MeshDebug) { 
    656                         if (ray.intersections.size())  
     656                        if (!ray.intersections.empty())  
    657657                        cout<<"nearest t="<<ray.intersections[0].mT<<endl; 
    658658                  else 
    659659                        cout<<"nearest t=-INF"<<endl; 
    660                   } 
    661                    
     660                  }        
    662661                } 
    663662          } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1328 r1344  
    726726 
    727727 
     728Vector3 MeshInstance::GetNormal(const int idx) const 
     729{ 
     730        return mMesh->GetFacePlane(idx).mNormal; 
     731} 
     732 
     733 
     734 
    728735/*************************************************************/ 
    729736/*           TransformedMeshInstance implementation          */ 
    730737/*************************************************************/ 
     738 
    731739 
    732740TransformedMeshInstance::TransformedMeshInstance(Mesh *mesh):  
     
    756764} 
    757765 
     766 
    758767int TransformedMeshInstance::CastRay(Ray &ray, const vector<int> &faces) 
    759768{ 
     
    799808 
    800809 
    801 } 
     810Vector3 TransformedMeshInstance::GetNormal(const int idx) const 
     811{ 
     812        Mesh mesh; 
     813        GetTransformedMesh(mesh); 
     814        return mesh.GetFacePlane(idx).mNormal; 
     815} 
     816 
     817} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r1328 r1344  
    2020class MeshKdTree; 
    2121 
    22 /// default vertex container for Mesh 
    23 typedef std::vector<Vector3> VertexContainer; 
    24  
    25 /// vertex index container 
    26 //typedef std::vector<short> VertexIndexContainer; 
    27 typedef std::vector<int> VertexIndexContainer; 
    28  
    29 /** Patch used as an element of the mesh */ 
     22 
     23/** Patch used as an element of the mesh  
     24*/ 
    3025struct Face { 
    3126 
     
    284279        Material *GetMaterial() const; 
    285280 
     281        virtual Vector3 GetNormal(const int idx) const; 
     282 
    286283protected: 
    287284 
     
    329326  void GetTransformedMesh(Mesh &transformedMesh) const; 
    330327 
     328  Vector3 GetNormal(const int idx) const; 
     329 
    331330protected: 
    332331 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r1328 r1344  
    1919namespace GtpVisibilityPreprocessor { 
    2020 
    21 #define CONNECT_SEQUENTIAL_FACES 1 
     21#define CONNECT_SEQUENTIAL_FACES 0 
    2222#define ROTATE_SCENE 0 
    2323 
     
    3636} 
    3737 
     38 
    3839struct ltstr 
    3940{ 
     
    4344        } 
    4445}; 
    45  
    46 //const static int nMaxFaces = 6; 
    4746 
    4847 
     
    7170 
    7271 
    73 static Triangle3 *LoadTriangle(char *str,  
    74                                                            const VertexContainer &vertices,  
    75                                                            map<int, Vector3> &hashTable) 
     72static Triangle3 LoadTriangle(char *str,  
     73                                                          const VertexContainer &vertices,  
     74                                                          map<int, Vector3> &hashTable) 
    7675{ 
    7776        char *pch = strtok(str + 1, " "); 
     
    9291        //if (indices.size() > 4) return NULL; 
    9392 
    94         return new Triangle3(indices[0], indices[1], indices[2]);  
     93    return Triangle3(vertices[indices[0]], vertices[indices[1]], vertices[indices[2]]);  
    9594} 
    9695 
     
    143142                                                                           vector<FaceParentInfo> &parents) 
    144143{ 
    145   Mesh *mesh = mi->GetMesh(); 
    146    
    147   FaceContainer::const_iterator fit, fit_end = mesh->mFaces.end(); 
    148   int i = 0; 
    149   for (fit = mesh->mFaces.begin(); fit != fit_end; ++ fit, i++) 
    150         { 
    151           parents.push_back(FaceParentInfo(mi, i)); 
     144        Mesh *mesh = mi->GetMesh(); 
     145 
     146        FaceContainer::const_iterator fit, fit_end = mesh->mFaces.end(); 
     147        int i = 0; 
     148        for (fit = mesh->mFaces.begin(); fit != fit_end; ++ fit, i++) 
     149        { 
     150                parents.push_back(FaceParentInfo(mi, i)); 
    152151        } 
    153152} 
     
    160159{ 
    161160        Mesh *mesh = CreateMesh(faces, hashTable); 
    162  
    163161        // make an instance of this mesh 
    164162        MeshInstance *mi = new MeshInstance(mesh); 
     
    178176 
    179177bool ObjParser::ParseFile(const string filename, 
    180                                                   SceneGraphNode **proot, 
     178                                                  SceneGraphNode *root, 
    181179                                                  const bool loadPolygonsAsMeshes, 
    182180                                                  vector<FaceParentInfo> *parents) 
     
    184182        FILE *file; 
    185183        if ((file = fopen(filename.c_str(), "rt")) == NULL) 
     184        {        
    186185                return false; 
    187         cout << "here2" << endl; 
     186        } 
     187 
    188188        map<int, Vector3> hashTable; // table associating indices with vectors 
    189          
    190189        VertexContainer vertices; // table for vertices 
    191190        FaceContainer faces; 
    192  
    193         SceneGraphNode *root = new SceneGraphNode; 
    194191 
    195192        char str[100]; 
     
    203200                switch (str[0])  
    204201                { 
    205                 case 'v': 
     202                case 'v': // vertex  
    206203                        { 
    207                                 float x,y,z; //cout << "v"; 
    208                                  
    209                                 // vertex  
     204                                float x, y, z; //cout << "v";    
    210205                                sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    211206                                vertices.push_back(Vector3(x,y,z)); 
     
    219214                                Face *face = LoadFace(str, vertices, hashTable); 
    220215                                if (!face) break; 
    221  
     216         
    222217                                faces.push_back(face); 
    223218 
     
    227222                                } 
    228223#else 
     224                                Triangle3 triangle = LoadTriangle(str, vertices, hashTable); 
    229225                                 
    230                                 Triangle3 *triangle = LoadTriangle(str, vertices, hashTable); 
    231                                 root->mGeometry.push_back(new TriangleIntersectable(triangle)); 
     226                                TriangleIntersectable *obj = new TriangleIntersectable(triangle); 
     227                                root->mGeometry.push_back(obj); 
     228 
     229                                // matt: we don't really need to keep an additional data structure 
     230                                // if working with triangles => remove this 
     231                                if (parents)  
     232                                { 
     233                                        FaceParentInfo info(obj, 0); 
     234                                        parents->push_back(info); 
     235                                } 
    232236#endif 
    233237                                break; 
     
    245249        } 
    246250#endif 
    247  
     251        // reset tables 
     252        hashTable.clear(); 
     253        faces.clear(); 
    248254        fclose(file); 
    249         *proot = root; 
    250  
     255         
    251256        return true; 
    252257} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h

    r1281 r1344  
    1616   
    1717  virtual bool ParseFile(const std::string filename,  
    18                                                  SceneGraphNode **root,  
     18                                                 SceneGraphNode *root, 
    1919                                                 const bool loadPolygonsAsMeshes = false, 
    2020                                                 vector<FaceParentInfo> *parents = NULL); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h

    r1281 r1344  
    1818  Parser() {} 
    1919 
    20   virtual bool ParseFile(const std::string filename,  
    21                                                  SceneGraphNode **root,  
     20  virtual bool ParseFile(const std::string filename, 
     21                                                 SceneGraphNode *root, 
    2222                                                 const bool loadPolygonsAsMeshes = false, 
    2323                                                 std::vector<FaceParentInfo> *parents = NULL)  
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp

    r1281 r1344  
    259259bool 
    260260PlyParser::ParseFile(const string filename, 
    261                                          SceneGraphNode **root, 
     261                                         SceneGraphNode *root, 
    262262                                         const bool loadPolygonsAsMeshes, 
    263263                                         vector<FaceParentInfo> *parents) 
     
    283283        filelist.push_back(filename); 
    284284 
    285   *root = new SceneGraphNode; 
    286  
    287285  for (int i=0; i < filelist.size(); i++) { 
    288         if (!ParseSingleFile(filelist[i], *root)) { 
     286        if (!ParseSingleFile(filelist[i], root)) { 
    289287          cerr<<"Ply parse error. Quiting ...\n"; 
    290288          exit(1); 
    291289        } 
    292290  } 
     291 
    293292  return true; 
    294293} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h

    r1281 r1344  
    1515   
    1616  bool ParseFile(const string filename, 
    17                                  SceneGraphNode **root, 
     17                                 SceneGraphNode *root, 
    1818                                 const bool loadPolygonsAsMeshes = false, 
    1919                                 vector<FaceParentInfo> *parents = NULL); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp

    r1328 r1344  
    1010 
    1111Polygon3::Polygon3():  
    12 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
     12mMaterial(NULL),  
     13mParent(NULL),  
     14mPiercingRays(0) 
    1315, mPlane(NULL) 
    1416{ 
    15         // mostly there will be triangles 
    16         //mVertices.reserve(3); 
    1717} 
    1818 
    1919Polygon3::Polygon3(const VertexContainer &vertices):  
    20 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
     20mMaterial(NULL),  
     21mParent(NULL),  
     22mPiercingRays(0) 
    2123, mPlane(NULL) 
    2224{ 
     
    2729 
    2830Polygon3::Polygon3(MeshInstance *parent):  
    29 mMaterial(NULL), mParent(parent), mPiercingRays(0) 
     31mMaterial(NULL),  
     32mParent(parent),  
     33mPiercingRays(0) 
    3034, mPlane(NULL) 
    3135{} 
     
    3337 
    3438Polygon3::Polygon3(Face *face, Mesh *parentMesh): 
    35 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    36 , mPlane(NULL) 
     39mMaterial(NULL),  
     40mParent(NULL),  
     41mPiercingRays(0),  
     42mPlane(NULL) 
    3743{        
    3844        mVertices.reserve(face->mVertexIndices.size()); 
    3945         
    40         VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 
    41         for (; it != face->mVertexIndices.end();  ++it) 
     46        VertexIndexContainer::iterator it, it_end = face->mVertexIndices.end(); 
     47 
     48        for (it = face->mVertexIndices.begin(); it != it_end;  ++ it) 
    4249        { 
    4350                mVertices.push_back(parentMesh->mVertices[*it]); 
     
    5461#else 
    5562        if (!mPlane) 
     63        { 
    5664                mPlane = new Plane3(mVertices[0], mVertices[1], mVertices[2]); 
     65        } 
     66 
    5767        return *mPlane; 
    5868#endif 
     
    6575                                                           mVertices[0] - mVertices[1])); 
    6676} 
     77 
    6778 
    6879void Polygon3::Split(const Plane3 &partition,  
     
    7283{ 
    7384        Vector3 ptA = mVertices.back(); 
    74          
    7585        int sideA = partition.Side(ptA, epsilon); 
    76          
    77         VertexContainer::const_iterator it; 
    78          
    79         Vector3 lastSplit; 
    80  
    8186        bool foundSplit = false; 
    82  
     87    Vector3 lastSplit; 
     88                 
    8389        //-- find line - plane intersections 
    84         for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
     90 
     91        VertexContainer::const_iterator it, it_end = mVertices.end(); 
     92 
     93        for (it = mVertices.begin(); it != it_end; ++ it) 
    8594        { 
    8695                Vector3 ptB = *it; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1328 r1344  
    162162        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 
    163163        Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl; 
     164 
     165        if (mRayCastMethod == 0) 
     166                cout << "ray cast method: internal" << endl; 
     167        else 
     168                cout << "ray cast method: intel" << endl; 
    164169} 
    165170 
     
    231236        cout << "number of input files: " << files << endl; 
    232237        bool result = false; 
     238 
     239        // root for different files 
     240        mSceneGraph->SetRoot(new SceneGraphNode()); 
     241 
    233242        if (files == 1) { 
    234243                 
     
    245254                cout << filename << endl; 
    246255 
    247                 SceneGraphNode *sroot = mSceneGraph->GetRoot(); 
    248  
    249256                if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    250                 { cout << "here5800" << endl; 
     257                {  
    251258                        result = parser->ParseFile( 
    252259                                filename,  
    253                                 &sroot, 
     260                                mSceneGraph->GetRoot(), 
    254261                                mLoadPolygonsAsMeshes, 
    255262                                &mFaceParents); 
    256263                } 
    257264                else 
    258                 { cout << "here776645" << endl; 
    259                         result = parser->ParseFile(filename, &sroot, mLoadPolygonsAsMeshes); 
     265                {  
     266                        result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadPolygonsAsMeshes); 
    260267                } 
    261                  cout << "here98809845" << endl; 
     268                 
    262269                delete parser; 
    263270 
    264271        } else { 
    265                 // root for different files 
    266                 mSceneGraph->SetRoot(new SceneGraphNode()); 
     272                 
    267273                for (int i= 0; i < filenames.size(); i++) { 
    268274                  if (strstr(filenames[i].c_str(), ".x3d")) 
     
    271277                        parser = new UnigraphicsParser; 
    272278                   
    273                   SceneGraphNode *node; 
     279                  SceneGraphNode *node = new SceneGraphNode(); 
    274280                  bool success; 
    275281                   
    276282                  if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    277                   { cout << "here4500" << endl; 
     283                  {  
    278284                          success = parser->ParseFile( 
    279285                                  filename,  
    280                                   &node, 
     286                                  node, 
    281287                                  mLoadPolygonsAsMeshes, 
    282288                                  &mFaceParents); 
     
    284290                  else 
    285291                  { 
    286                           cout << "here45" << endl; 
    287                           success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 
     292                          success = parser->ParseFile(filename, node, mLoadPolygonsAsMeshes); 
    288293                  } 
    289294 
    290295                  if (success)  
    291                   { cout << "here4509999" << endl; 
     296                  {  
    292297                          mSceneGraph->GetRoot()->mChildren.push_back(node); 
    293                           // at least one file parsed 
    294                           result = true; 
     298                          result = true; // at least one file parsed 
    295299                  } 
    296300                   
     
    298302                } 
    299303        } 
    300          cout << "here8888" << endl; 
    301  
     304         
    302305        if (result)  
    303         { cout << "here199" << endl; 
     306        {  
    304307                // HACK  
    305308                if (ADDITIONAL_GEOMETRY_HACK) 
     
    307310 
    308311                mSceneGraph->AssignObjectIds(); 
    309  cout << "here99" << endl; 
     312  
    310313                int intersectables, faces; 
    311314                mSceneGraph->GetStatistics(intersectables, faces); 
    312  cout << "here999" << endl; 
     315  
    313316                cout<<filename<<" parsed successfully."<<endl; 
    314317                cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
     
    316319                mSceneGraph->CollectObjects(&mObjects); 
    317320                mSceneGraph->GetRoot()->UpdateBox(); 
    318  cout << "here9999" << endl; 
     321  
    319322                if (0) 
    320323                { 
     
    369372{ 
    370373  mKdTree = new KdTree; 
     374 
    371375  // add mesh instances of the scene graph to the root of the tree 
    372376  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); 
    373         cout << "here3.95" << endl; 
     377         
    374378  mSceneGraph->CollectObjects(&root->mObjects); 
    375         cout << "here3.97" << endl; 
     379   
    376380  long startTime = GetTime(); 
    377  
    378381  cout << "building kd tree ... " << endl; 
     382 
    379383  mKdTree->Construct(); 
     384 
    380385  cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl; 
     386 
    381387  return true; 
    382388} 
     
    847853        case INTEL_RAYCASTER: 
    848854#ifdef GTP_INTERNAL 
    849           cout<<"Ray Cast file: "<<externKdTree<<endl; 
     855          cout<<"Ray Cast file: " << externKdTree << endl; 
    850856          return mlrtaLoadAS(externKdTree.c_str()); 
    851857#endif 
     
    868874{ 
    869875#ifdef GTP_INTERNAL 
     876        //cout << "intel ray" << endl; 
    870877        VssRay *vssRay  = NULL; 
    871878        int hits = 0; 
     
    875882        Intersectable *objectA = NULL, *objectB = NULL; 
    876883        float dist; 
    877          
    878884        double normal[3]; 
    879885 
    880886        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
    881                                                                    &direction.x, 
    882                                                                    normal, 
    883                                                                    dist); 
    884  
    885         if (hittriangle !=-1 ) { 
    886           if (hittriangle >= mFaceParents.size()) 
    887                 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    888           else { 
    889                 objectA = mFaceParents[hittriangle].mObject; 
    890                 normalA = Vector3(normal[0], normal[1], normal[2]); 
    891                 // Get the normal of that face 
    892                 //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    893                 //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    894                 //-rays[index+i].mDirection; // $$ temporary 
    895                 pointA = viewPoint + direction*dist; 
    896           } 
    897         } 
    898  
    899          
     887                &direction.x, 
     888                normal, 
     889                dist); 
     890 
     891        if (hittriangle != -1 ) { 
     892                if (hittriangle >= mFaceParents.size()) 
     893                        cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
     894                else { 
     895                        objectA = mFaceParents[hittriangle].mObject; 
     896                        normalA = Vector3(normal[0], normal[1], normal[2]); 
     897                        // Get the normal of that face 
     898                        //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
     899                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     900                        //-rays[index+i].mDirection; // $$ temporary 
     901                        pointA = viewPoint + direction*dist; 
     902                } 
     903        } 
     904 
     905 
    900906        Vector3 dir = -direction; 
    901907        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
    902                                                                    &dir.x, 
    903                                                                    normal, 
    904                                                                    dist); 
    905  
    906         if (hittriangle !=-1 ) { 
    907           if (hittriangle >= mFaceParents.size()) 
    908                 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
    909           else { 
    910                 objectB = mFaceParents[hittriangle].mObject; 
    911                 normalB = Vector3(normal[0], normal[1], normal[2]); 
    912                 // Get the normal of that face 
    913                 //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    914                 //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    915                 //-rays[index+i].mDirection; // $$ temporary 
    916                 pointB = viewPoint + dir*dist; 
    917         } 
     908                &dir.x, 
     909                normal, 
     910                dist); 
     911 
     912        if (hittriangle != -1 ) { 
     913                if (hittriangle >= mFaceParents.size()) 
     914                        cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
     915                else { 
     916                        objectB = mFaceParents[hittriangle].mObject; 
     917                        normalB = Vector3(normal[0], normal[1], normal[2]); 
     918                        // Get the normal of that face 
     919                        //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
     920                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     921                        //-rays[index+i].mDirection; // $$ temporary 
     922                        pointB = viewPoint + dir * dist; 
     923                } 
    918924        } 
    919925 
    920926        return ProcessRay(viewPoint, 
    921                                           direction, 
    922                                           objectA, pointA, normalA, 
    923                                           objectB, pointB, normalB, 
    924                                           probability, 
    925                                           vssRays, 
    926                                           box 
    927                                           ); 
     927                direction, 
     928                objectA, pointA, normalA, 
     929                objectB, pointB, normalB, 
     930                probability, 
     931                vssRays, 
     932                box 
     933                ); 
    928934#else 
    929935        return -1; 
     
    971977        else { 
    972978          if (hittriangle >= mFaceParents.size()) { 
    973                 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     979                cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    974980                return NULL; 
    975981          } 
     
    989995#endif 
    990996 
    991          
    992          
    993997} 
    994998 
     
    10021006                                                                  ) 
    10031007{ 
    1004  
     1008  cout << "internal ray" << endl; 
    10051009  int hits = 0; 
    10061010  static Ray ray; 
     
    10091013 
    10101014  //  AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox()); 
    1011    
    1012  
    10131015  AxisAlignedBox3 sbox = box; 
    10141016  sbox.Enlarge(Vector3(-Limits::Small)); 
     
    10421044  } 
    10431045 
    1044    
    10451046  SetupRay(ray, viewPoint, -direction); 
    10461047  ray.mFlags &= ~Ray::CULL_BACKFACES; 
     
    10761077                                                  ); 
    10771078          vssRays.push_back(vssRay); 
     1079          //cout << "ray: " << *vssRay << endl; 
    10781080          hits ++; 
    10791081        } 
     
    10881090                                                  ); 
    10891091          vssRays.push_back(vssRay); 
     1092          //cout << "ray: " << *vssRay << endl; 
    10901093          hits ++; 
    10911094        } 
     
    11721175                                                  ); 
    11731176          vssRays.push_back(vssRay); 
     1177          //cout << "ray: " << *vssRay << endl; 
    11741178          hits ++; 
    11751179        } 
     
    11841188                                                  ); 
    11851189          vssRays.push_back(vssRay); 
     1190          //cout << "ray: " << *vssRay << endl; 
    11861191          hits ++; 
    11871192        } 
     
    11991204{ 
    12001205  int i; 
    1201   int num = 16; 
     1206  const int num = 16; 
    12021207 
    12031208#if DEBUG_RAYCAST 
     
    12141219 
    12151220 
    1216    
    1217  
    12181221  Vector3 min = sbox.Min(); 
    12191222  Vector3 max = sbox.Max(); 
     1223   
    12201224  for (i=0; i < num; i++) { 
    12211225        mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, 
     
    12231227                                          i); 
    12241228  } 
    1225    
    12261229   
    12271230  mlrtaTraverseGroupAS16(&min.x, 
     
    12371240  } 
    12381241   
    1239    
    12401242  mlrtaTraverseGroupAS16(&min.x, 
    12411243                                                 &max.x, 
     
    12441246   
    12451247 
    1246  
    12471248  for (i=0; i < num; i++) { 
    12481249        Intersectable *objectA = NULL, *objectB = NULL; 
     
    12501251        Vector3 normalA, normalB; 
    12511252 
    1252  
    1253    
    1254         if (forward_hit_triangles[i] !=-1 ) { 
     1253        if (forward_hit_triangles[i] != -1 ) { 
    12551254          if (forward_hit_triangles[i] >= mFaceParents.size()) 
    1256                 cerr<<"Warning: traingle index out of range! "<<forward_hit_triangles[i]<<endl; 
    1257           else { 
     1255                cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 
     1256          else {  
    12581257                objectA = mFaceParents[forward_hit_triangles[i]].mObject; 
    12591258                // Get the normal of that face 
    1260                 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    1261                 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     1259                normalA = objectA->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
    12621260                //-rays[index+i].mDirection; // $$ temporary 
    12631261                pointA = rays[index+i].Extrap(forward_dist[i]); 
    12641262          } 
    12651263        } 
    1266          
     1264          
    12671265        if (backward_hit_triangles[i]!=-1) { 
    12681266          if (backward_hit_triangles[i] >= mFaceParents.size()) 
    1269                 cerr<<"Warning: traingle index out of range! "<<backward_hit_triangles[i]<<endl; 
    1270           else { 
     1267                cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl; 
     1268          else {  
    12711269                objectB = mFaceParents[backward_hit_triangles[i]].mObject; 
    1272                 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    1273                  
    1274                 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 
    1275                  
    1276                 //        normalB = rays[index+i].mDirection; // $$ temporary 
     1270                normalB = objectB->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
     1271                 
     1272                // normalB = rays[index+i].mDirection; // $$ temporary 
    12771273                pointB = rays[index+i].Extrap(-backward_dist[i]); 
    12781274          } 
    12791275        } 
    1280  
     1276  
    12811277        ProcessRay(rays[index+i].mOrigin, 
    12821278                           rays[index+i].mDirection, 
     
    12881284                           ); 
    12891285  } 
     1286   
    12901287#endif 
    12911288   
     
    13121309{ 
    13131310  long t1 = GetTime(); 
    1314   for (int i=0; i < rays.size(); ) { 
    1315         if (i + 16 < rays.size()) { 
     1311   
     1312  for (int i = 0; i < (int)rays.size(); ) { 
     1313          // method only available for intel raycaster yet 
     1314        if (i + 16 < (int)rays.size()) { 
     1315 
    13161316          CastRays16( 
    13171317                                 i, 
     
    13211321          i += 16; 
    13221322        } else { 
    1323  
    13241323          CastRay(rays[i].mOrigin, 
    13251324                          rays[i].mDirection, 
     
    13271326                          vssRays, 
    13281327                          mViewCellsManager->GetViewSpaceBox()); 
    1329  
    13301328          i++; 
    13311329        } 
     
    13351333 
    13361334  long t2 = GetTime(); 
    1337    
    13381335  cout<<2*rays.size()/(1e3*TimeDiff(t1, t2))<<"M rays/s"<<endl; 
    13391336} 
     
    13541351          
    13551352          int hittriangle; 
    1356            
    13571353 
    13581354#ifdef GTP_INTERNAL 
     
    13671363           if (hittriangle !=-1 ) { 
    13681364                if (hittriangle >= mFaceParents.size()) 
    1369                   cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     1365                  cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    13701366                else { 
    13711367                  result = mFaceParents[hittriangle].mObject; 
     
    13751371          } 
    13761372#else 
    1377         hittriangle = -1; 
     1373          hittriangle = -1; 
    13781374#endif 
    13791375 
    1380           
    13811376          break; 
    13821377        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp

    r1328 r1344  
    3131{ 
    3232        CLEAR_CONTAINER(mGeometry); 
    33          
    3433        // recursivly delete all children 
    3534        CLEAR_CONTAINER(mChildren); 
     
    7877                SceneGraphNode *node = nodeStack.top(); 
    7978                nodeStack.pop(); 
    80                 cout << "here3.958" << endl;cout << "here3.9587654" << endl; 
    81                 ObjectContainer::const_iterator mi = node->mGeometry.begin();   cout << "here3.958" << endl; 
     79                 
     80                ObjectContainer::const_iterator mi = node->mGeometry.begin(); 
    8281                for (; mi != node->mGeometry.end(); mi++) 
    8382                { 
    84                         cout << "here3.9886" << endl; 
    8583                        instances->push_back(*mi); 
    8684                } 
    87                 cout << "here3.969999" << endl; 
     85         
    8886                SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
    8987                for (; ni != node->mChildren.end(); ni++) { 
    90                         nodeStack.push(*ni);    cout << "here3.959" << endl; 
     88                        nodeStack.push(*ni);     
    9189                        number++; 
    9290                } 
    93                 cout << "here3.96" << endl; 
    9491        } 
     92 
    9593        return number; 
    9694} 
     
    104102   
    105103  nodeStack.push(mRoot); 
    106    
     104 
    107105  while (!nodeStack.empty()) { 
    108106    SceneGraphNode *node = nodeStack.top(); 
     
    111109    ObjectContainer::iterator mi = node->mGeometry.begin(); 
    112110    for (; mi != node->mGeometry.end(); mi++) { 
    113           // $$ JB remove object id=2601 (for debugging purposes in atlanta scene) 
    114           if (1) //id != 2601) 
    115                 (*mi)->SetId(id++); 
    116           else { 
    117                 node->mGeometry.erase(mi); 
    118                 --mi; 
    119                 id++; 
    120           } 
     111                (*mi)->SetId(id++); 
    121112        } 
    122113     
     
    126117    } 
    127118  } 
    128         // return max id 
     119   
     120  // return max id 
    129121  return id; 
    130122} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r1292 r1344  
    187187                                Name="VCCLCompilerTool" 
    188188                                Optimization="3" 
     189                                GlobalOptimizations="TRUE" 
     190                                InlineFunctionExpansion="2" 
     191                                FavorSizeOrSpeed="1" 
     192                                EnableFiberSafeOptimizations="TRUE" 
     193                                OptimizeForProcessor="3" 
     194                                OptimizeForWindowsApplication="TRUE" 
    189195                                AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces" 
    190196                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r1328 r1344  
    22#include "Ray.h" 
    33#include "AxisAlignedBox3.h" 
     4#include "Containers.h" 
     5#include "Polygon3.h" 
    46 
    57 
     
    1820        mVertices[1] = b; 
    1921        mVertices[2] = c; 
    20  
    2122} 
    2223 
     
    2829 
    2930 
    30 int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT) const 
     31int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const 
    3132{ 
     33        /*VertexContainer vertices; 
     34        vertices.push_back(mVertices[0]); 
     35        vertices.push_back(mVertices[1]); 
     36        vertices.push_back(mVertices[2]); 
     37 
     38        Polygon3 poly(vertices); 
     39         
     40        int dummy = poly.CastRay(ray, t, nearestT); 
     41 
     42         cout << "polyversion code: " << dummy << " t: " << t << " nearestT: " << nearestT << endl; 
     43return dummy;*/ 
     44        ///////////////////////////////////////////// 
     45        // specialised ray casting version 
     46 
     47        //-- calc ray-plane intersection 
     48         
    3249        // get triangle edge vectors and plane normal 
    33         const Vector3 u = mVertices[1] - mVertices[0]; 
    34     const Vector3 v = mVertices[2] - mVertices[0]; 
     50        const Vector3 u = mVertices[0] - mVertices[1]; 
     51    const Vector3 v = mVertices[2] - mVertices[1]; 
    3552 
    36     const Vector3 n = u * v; // cross product 
     53    normal = Normalize(CrossProd(v, u)); // cross product 
    3754 
    38     const Vector3 dir = ray.GetDir();           // ray direction vector 
    39     const Vector3 w0 = ray.GetLoc() - mVertices[0]; 
     55    const Vector3 dir = ray.GetDir(); // ray direction vector 
     56    const Vector3 w0 = ray.GetLoc() - mVertices[1]; 
    4057 
    4158        // params to calc ray-plane intersect 
    42     const float a = - DotProd(n, w0); 
    43     const float b = DotProd(n, dir); 
     59    const float a = -DotProd(normal, w0); 
     60    const float b = DotProd(normal, dir); 
    4461 
     62        // check for division by zero 
    4563        if (fabs(b) < Limits::Small)  
    4664        {    
     
    5674    } 
    5775 
    58     // get intersect point of ray with triangle plane 
     76    // distance from origin of ray to plane 
    5977    t = a / b; 
    6078 
    6179    if (t < 0.0) // ray goes away from triangle 
    6280        { 
    63         return Ray::NO_INTERSECTION; // => no intersect 
     81                return Ray::NO_INTERSECTION; // => no intersect 
     82        } 
     83        // already found nearer intersection 
     84        else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) 
     85        { 
     86                return Ray::NO_INTERSECTION; 
    6487        } 
    6588 
    66     // for a segment, also test if (r > 1.0) => no intersect 
     89        /////////////////////////////////////////////// 
     90    //-- found intersection point 
     91        //-- check if it is inside triangle 
     92   
     93        const Vector3 pt = ray.GetLoc() + t * dir;  
    6794 
    68         // intersect point of ray and plane 
    69     const Vector3 pt = ray.GetLoc() + t * dir;  
    70  
    71  
    72         /////////////////////////////////////////////// 
    73     //-- is point inside triangle? 
    74     
    75         const Vector3 w = pt - mVertices[0]; 
     95        const Vector3 w = pt - mVertices[1]; 
    7696 
    7797        const float uu = DotProd(u, u); 
     
    86106    const float s = (uv * wv - vv * wu) / D; 
    87107 
    88     if (s < 0.0 || s > 1.0) // pt is outside triangle 
    89         { 
     108    if ((s < 0.0) || (s > 1.0)) // pt is outside triangle 
     109        {        
    90110        return Ray::NO_INTERSECTION; 
    91111        } 
     
    93113        const float s2 = (uv * wu - uu * wv) / D; 
    94114 
    95     if (s2 < 0.0 || (s + s2) > 1.0) // pt is outside triangle 
    96         { 
     115    if ((s2 < 0.0) || ((s + s2) > 1.0)) // pt is outside triangle 
     116        {        
    97117        return Ray::NO_INTERSECTION; 
    98118        } 
     
    118138{ 
    119139        const Vector3 v1 = mVertices[0] - mVertices[1]; 
    120         const Vector3 v2 = mVertices[2]-mVertices[1]; 
     140        const Vector3 v2 = mVertices[2] - mVertices[1]; 
    121141 
    122142        return Normalize(CrossProd(v2, v1)); 
     
    132152float Triangle3::GetArea() const  
    133153{ 
    134         Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 
     154        Vector3 v1 = mVertices[0] - mVertices[1], v2=mVertices[2] - mVertices[1]; 
    135155        return 0.5f * Magnitude(CrossProd(v2, v1)); 
    136156} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h

    r1328 r1344  
    3030 
    3131        /// Casts ray into this triangle. Returns hit 
    32         int CastRay(const Ray &ray, float &t, const float nearestT) const; 
     32        int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const; 
    3333 
    34         ////////////////////////////// 
     34         friend ostream& operator<< (ostream &s, const Triangle3 &A); 
     35         friend istream& operator>> (istream &s, Triangle3 &A); 
    3536 
    36         /// the triangle vertices 
    37         Vector3 mVertices[3]; 
     37 
     38         ////////////////////////////// 
     39         /// the triangle vertices 
     40         Vector3 mVertices[3]; 
    3841}; 
     42 
     43 
     44// Overload << operator for C++-style output 
     45inline ostream& 
     46operator<< (ostream &s, const Triangle3 &A) 
     47{ 
     48  return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")"; 
     49} 
     50 
     51// Overload >> operator for C++-style input 
     52inline istream& 
     53operator>> (istream &s, Triangle3 &A) 
     54{ 
     55  char a; 
     56  // read "(x, y, z)" 
     57  return s >> a >> A.mVertices[0] >> a >> A.mVertices[1] >> a >> A.mVertices[2] >> a; 
     58} 
     59 
    3960 
    4061} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r1281 r1344  
    4343bool 
    4444UnigraphicsParser::ParseFile(const string filename, 
    45                                                          SceneGraphNode **proot, 
     45                                                         SceneGraphNode *root, 
    4646                                                         const bool loadPolygonsAsMeshes, 
    4747                                                         vector<FaceParentInfo> *parents) 
     
    6161    return false; 
    6262 
    63   SceneGraphNode *root = new SceneGraphNode; 
    6463  Mesh *currentMesh = MeshManager::GetSingleton()->CreateResource(); 
    6564 
     
    186185   
    187186  fclose(file); 
    188    
    189   *proot = root; 
    190  
    191187  return true; 
    192188} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h

    r1281 r1344  
    1616   
    1717  virtual bool ParseFile(const std::string filename,  
    18                                                  SceneGraphNode **root,  
     18                                                 SceneGraphNode *root,  
    1919                                                 const bool loadPolygonsAsMeshes = false, 
    2020                                                 vector<FaceParentInfo> *parents = NULL); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1315 r1344  
    276276{ 
    277277        SimpleRayContainer simpleRays; 
    278  
    279278        const long startTime = GetTime(); 
    280279 
    281280        mPreprocessor->GenerateRays(samplesPerPass, sampleType, simpleRays); 
    282  
    283281        Debug << "generated " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    284282 
    285283        // shoot simple ray and add it to importance samples 
    286284        mPreprocessor->CastRays(simpleRays, passSamples); 
    287  
    288285        Debug << "cast " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    289286 
     
    53595356 
    53605357 
     5358        ////////////////////////////////////////////////////////////// 
    53615359        //-- export bounding boxes 
    53625360 
    53635361        stream << "<BoundingBoxes>" << endl; 
    5364  
    53655362        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    53665363 
    53675364        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    53685365        { 
    5369                         MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 
    5370                         const AxisAlignedBox3 box = mi->GetBox(); 
     5366                        const AxisAlignedBox3 box = (*oit)->GetBox(); 
    53715367 
    53725368                        //-- the bounding boxes 
    5373                         stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 
     5369                        stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
    53745370                                   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    53755371                                   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     
    53785374        stream << "</BoundingBoxes>" << endl; 
    53795375 
    5380  
     5376        //////////////////////////////////////////////////////////////// 
    53815377        //-- export the view cells and the pvs 
    53825378 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h

    r1221 r1344  
    1717  ViewCellsParser():Parser() {} 
    1818   
    19   //bool ParseFile(const string filename, ViewCellsManager &viewCells); 
    20   bool ParseViewCellsFile(const string filename,  
     19  bool ParseViewCellsFile( 
     20          const string filename,  
    2121          ViewCellsManager **viewCells, 
    2222          ObjectContainer *objects, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1315 r1344  
    1515#include "Beam.h" 
    1616#include "IntersectableWrapper.h" 
     17#include "Triangle3.h" 
    1718 
    1819 
     
    2021 
    2122 
    22 VrmlExporter::VrmlExporter(const string filename):Exporter(filename) 
     23VrmlExporter::VrmlExporter(const string filename): Exporter(filename) 
    2324{ 
    2425        stream.open(mFilename.c_str()); 
     
    159160   
    160161        stream<<"</Group>"<<endl; 
    161 } 
    162  
    163  
    164 void VrmlExporter::ExportIntersectable(Intersectable *object) 
    165 { 
    166         switch (object->Type())  
    167         { 
    168         case Intersectable::MESH_INSTANCE: 
    169                 ExportMeshInstance((MeshInstance *)object); 
    170                 break; 
    171         case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    172                 ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object)); 
    173                 break; 
    174         case Intersectable::VIEW_CELL: 
    175                 ExportViewCell(dynamic_cast<ViewCell *>(object)); 
    176                 break; 
    177         case Intersectable::KD_INTERSECTABLE: 
    178                 ExportKdIntersectable(*(dynamic_cast<KdIntersectable *>(object))); 
    179                 break; 
    180         default: 
    181                 cerr << "Sorry the export for object type " << Intersectable::GetTypeName(object) << " is not available yet" << endl; 
    182                 break; 
    183         } 
    184 } 
    185  
    186  
    187 void VrmlExporter::ExportMeshInstance(MeshInstance *object) 
    188 { 
    189         // $$JB$$ 
    190         // in the future check whether the mesh was not already exported 
    191         // and use a reference to the that mesh instead 
    192         ExportMesh(object->GetMesh()); 
    193 } 
    194  
    195  
    196 void VrmlExporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi) 
    197 { 
    198         Mesh mesh(*mi->GetMesh()); 
    199  
    200         Matrix4x4 m; 
    201         mi->GetWorldTransform(m); 
    202         mesh.ApplyTransformation(m); 
    203  
    204         ExportMesh(&mesh); 
    205 } 
    206  
    207  
    208 void VrmlExporter::ExportViewCells(const ViewCellContainer &viewCells) 
    209 { 
    210         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    211  
    212         for (it = viewCells.begin(); it != it_end; ++ it) 
    213         { 
    214                 ExportViewCell(*it); 
    215         } 
    216162} 
    217163 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h

    r1197 r1344  
    8484 
    8585  virtual void 
    86   ExportMeshInstance(MeshInstance *mi); 
    87  
    88   virtual void 
    89   ExportTransformedMeshInstance(TransformedMeshInstance *mi); 
    90  
    91   virtual void 
    92   ExportIntersectable(Intersectable *object); 
    93  
    94   virtual void 
    9586  ExportMesh(Mesh *mesh); 
    9687 
    9788  virtual void 
    9889  ExportViewCell(ViewCell *viewCell); 
    99  
    100   virtual void 
    101   ExportViewCells(const ViewCellContainer &viewCells); 
    10290 
    10391  virtual void 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r1233 r1344  
    200200 
    201201} 
    202 void 
    203 X3dExporter::ExportIntersectable(Intersectable *object) 
    204 { 
    205         switch (object->Type())  
    206         { 
    207         case Intersectable::MESH_INSTANCE: 
    208                 ExportMeshInstance((MeshInstance *)object); 
    209                 break; 
    210         case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    211                 ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object)); 
    212                 break; 
    213         case Intersectable::VIEW_CELL: 
    214                 ExportViewCell((ViewCell *)object); 
    215                 break; 
    216         default: 
    217                 cerr << "Sorry the export for object not yet defined" << endl; 
    218                 break; 
    219         } 
    220 } 
    221  
    222  
    223 void 
    224 X3dExporter::ExportMeshInstance(MeshInstance *object) 
    225 { 
    226   // $$JB$$ 
    227   // in the future check whether the mesh was not already exported 
    228   // and use a reference to the that mesh instead 
    229   ExportMesh(object->GetMesh()); 
    230 } 
    231  
    232  
    233 void 
    234 X3dExporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi) 
    235 { 
    236         Mesh mesh(*mi->GetMesh()); 
    237  
    238         Matrix4x4 m; 
    239         mi->GetWorldTransform(m); 
    240         mesh.ApplyTransformation(m); 
    241  
    242         ExportMesh(&mesh); 
    243 } 
    244  
    245  
    246 void  
    247 X3dExporter::ExportViewCells(const ViewCellContainer &viewCells) 
    248 { 
    249         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    250  
    251         for (it = viewCells.begin(); it != it_end; ++ it) 
    252                 ExportViewCell(*it); 
    253 } 
    254202 
    255203 
     
    303251                                mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
    304252                        } 
    305  
    306253                        ExportPolygons(cell->GetPolys()); 
    307                 } 
    308                  
     254                }                
    309255                DEL_PTR(cell); 
    310256        } 
     
    315261{ 
    316262        if (viewCell->GetMesh()) 
     263        { 
    317264                ExportMesh(viewCell->GetMesh()); 
     265        } 
    318266} 
    319267 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h

    r1221 r1344  
    8181 
    8282  virtual void 
    83   ExportMeshInstance(MeshInstance *mi); 
    84  
    85   virtual void 
    86   ExportTransformedMeshInstance(TransformedMeshInstance *mi); 
    87  
    88   virtual void 
    89   ExportIntersectable(Intersectable *object); 
    90  
    91   virtual void 
    9283  ExportMesh(Mesh *mesh); 
    9384 
    9485  virtual void 
    9586  ExportViewCell(ViewCell *viewCell); 
    96  
    97   virtual void 
    98   ExportViewCells(const ViewCellContainer &viewCells); 
    9987 
    10088  virtual void 
     
    10593                         const float length=1000, 
    10694                         const RgbColor &color = RgbColor(1,1,1)); 
     95 
    10796  bool 
    10897  ExportRays(const VssRayContainer &rays, 
     
    121110  ExportBspLeaves(const BspTree &tree, const int maxPvs = 0); 
    122111 
    123  
    124112  virtual void 
    125113  ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 
     
    132120 
    133121protected: 
    134  
    135122 
    136123  virtual void 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r1281 r1344  
    649649/*******************+*****************************************************/ 
    650650 
    651 X3dParser::X3dParser(): 
    652 mViewCellHeight(DEFAULT_VIEWCELL_HEIGHT)  
     651X3dParser::X3dParser(): mViewCellHeight(DEFAULT_VIEWCELL_HEIGHT)  
    653652{} 
     653 
    654654 
    655655bool 
    656656X3dParser::ParseFile(const string filename, 
    657                                          SceneGraphNode **root, 
     657                                         SceneGraphNode *root, 
    658658                                         const bool loadPolygonsAsMeshes, 
    659659                                         vector<FaceParentInfo> *parents) 
     
    689689  //  to do. 
    690690  // 
    691   *root = new SceneGraphNode; 
    692   X3dParseHandlers handler(*root, loadPolygonsAsMeshes); 
     691  X3dParseHandlers handler(root, loadPolygonsAsMeshes); 
    693692  parser->setDocumentHandler(&handler); 
    694693  parser->setErrorHandler(&handler); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h

    r1281 r1344  
    1717        bool ParseFile( 
    1818                                   const string filename,  
    19                                    SceneGraphNode **root,  
     19                                   SceneGraphNode *root,  
    2020                                   const bool loadPolygonsAsMeshes = false, 
    2121                                   vector<FaceParentInfo> *parents = NULL); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1328 r1344  
    214214                exit(1); 
    215215        } 
    216         cout << "here3.9" << endl; 
     216 
    217217        //-- build kd tree from scene geometry 
    218218        preprocessor->BuildKdTree(); 
    219219        preprocessor->KdTreeStatistics(cout); 
    220         cout << "here3" << endl; 
     220 
    221221        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 
    222222        MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 
     
    242242 
    243243        DEL_PTR(kdTree2); 
    244 */cout << "here4" << endl; 
     244*/ 
    245245        // parse view cells related options 
    246246        preprocessor->PrepareViewCells(); 
     
    251251                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);      
    252252        } 
    253 cout << "here5" << endl; 
     253 
    254254        // create a preprocessor thread (note: capsulates calls to boost fuctions!) 
    255255        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor); 
     
    260260        bool guiSupported = false; 
    261261        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) 
    262           { 
     262        { 
    263263                cout << "using gl widget" << endl; 
    264264                // create and run the preprocessor application in a parallel thread 
     
    267267#endif 
    268268                //pt.RunThread(); 
    269                  
     269 
    270270                // display the render widget 
    271                 if (!rendererWidget) { 
    272  
     271                if (!rendererWidget)  
     272                { 
    273273#if !USE_QT 
    274                   guiSupported = LoadMyDll(); 
     274                        guiSupported = LoadMyDll(); 
    275275#else 
    276                   rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph, 
    277                                                                                                   preprocessor->mViewCellsManager, 
    278                                                                                                   preprocessor->mKdTree); 
     276                        rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph, 
     277                                preprocessor->mViewCellsManager, 
     278                                preprocessor->mKdTree); 
    279279#endif 
    280280                } 
    281                  
    282           } 
     281 
     282        } 
    283283         
    284284        if (!guiSupported) { 
Note: See TracChangeset for help on using the changeset viewer.