File: BrainModelSurfacePointProjector.h

package info (click to toggle)
caret 5.6.4~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 31,904 kB
  • ctags: 28,901
  • sloc: cpp: 378,050; python: 6,718; ansic: 5,507; makefile: 333; sh: 46
file content (142 lines) | stat: -rw-r--r-- 5,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*LICENSE_START*/
/*
 *  Copyright 1995-2002 Washington University School of Medicine
 *
 *  http://brainmap.wustl.edu
 *
 *  This file is part of CARET.
 *
 *  CARET is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  CARET is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CARET; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*LICENSE_END*/



#ifndef __VE_BRAIN_MODEL_SURFACE_POINT_PROJECTOR_H__
#define __VE_BRAIN_MODEL_SURFACE_POINT_PROJECTOR_H__

#include <set>

class BrainModelSurface;
class BrainModelSurfacePointLocator;
class CoordinateFile;
class TopologyFile;
class TopologyHelper;

/// This class is used to project points onto a BrainModelSurface.  It can project to
/// the nearest node or to a barycentric position in a tile.
class BrainModelSurfacePointProjector {
   public:
      
      /// Surface type hint passed to constructor
      enum SURFACE_TYPE_HINT {
         SURFACE_TYPE_HINT_FLAT,
         SURFACE_TYPE_HINT_SPHERE,
         SURFACE_TYPE_HINT_OTHER
      };
      
      /// Constructor
      BrainModelSurfacePointProjector(const BrainModelSurface* bmsIn,
                                      const SURFACE_TYPE_HINT surfaceTypeHintIn,
                                      const bool surfaceMayHaveNodesAddedToIt);
                                      
      /// Destructor
      ~BrainModelSurfacePointProjector();
      
      /// project to nearest node
      int projectToNearestNode(const float xyz[3]);
      
      /// barycentric projection (returns tile node projects to else negative)
      int projectBarycentric(const float xyz[3], int& nearestNodeNumberOut,
                             int tileNodesOut[3], float barycentricOut[3],
                             const bool checkNeighbors = true);
      
      /// barycentric projection to nearest tile but may not be within the tile
      int projectBarycentricNearestTile(const float xyz[3], int& nearestTileNumberOut,
                                        int tileNodesOut[3], float barycentricOut[3],
                                        float& signedDistanceOut, float& distanceToTile,
                                        float distanceComponents[3]);
      
      /// barycentric projection to the "best" tile (2D only) 
      int projectBarycentricBestTile2D(const float xyz[3], 
                                       int& nearestTileNumberOut,
                                       int tileNodesOut[3], 
                                       float barycentricOut[3]);
                                     
      /// unproject using the specified coordinate file
      static void unprojectPoint(const int tileNodes[3], const float tileAreas[3],
                                 const CoordinateFile* cf, float xyzOut[3]);
   
   private:
      
      /// Status of the search (degenerate is on an edge, vertex, or "just" outside the tile)
      enum SEARCH_STATUS {
         TILE_NOT_FOUND,
         TILE_FOUND,
         TILE_FOUND_DEGENERATE
      };
      
      /// see if a point is in any of the files used by a node.
      void checkPointInNodesTiles(const TopologyHelper* topologyHelper, const int nodeNumber);
                                  
      /// see if the point "xyz" is within the tile "tileNumber"
      void checkPointInTile(const int tileNumber);      
      
      /// compute areas formed by assuming xyz is within the triangle formed by p1, p2, p3
      int triangleAreas(const float* p1, const float* p2, const float* p3,
                        const float* normal, const float* xyz,
                        float& area1, float& area2, float& area3);
                         
      /// point locator for BrainModelSurface
      BrainModelSurfacePointLocator* pointLocator;
      
      /// coordinate file
      const CoordinateFile* coordinateFile;
      
      /// topology file
      const TopologyFile* topologyFile;
      
      /// the surface type hint
      SURFACE_TYPE_HINT surfaceTypeHint;
      
      /// inside triangle tolerance
      float tileAreaTolerance;
      
      /// "on" the node tolerance
      float nearestNodeToleranceSquared;
      
      /// tiles that have been searched in barycentric mode
      std::set<int> barycentricSearchedTiles;
      
      /// the search status (used in barycentric searching)
      SEARCH_STATUS barycentricSearchStatus;
      
      /// tile found in barycentric mode
      int barycentricTile;
      
      /// nodes of tile found in barycentric mode
      int barycentricNodes[3];
      
      /// barycentric areas of tile found in barycentric mode
      float barycentricAreas[3];
      
      /// the query point for barycentric mode
      float barycentricQueryPoint[3];
      
};

#endif  // __VE_BRAIN_MODEL_SURFACE_POINT_PROJECTOR_H__